2 * Copyright 2011, The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #define LOG_TAG "NMST_QTagUidNative"
18 #include <utils/Log.h>
23 #include <utils/misc.h>
24 #include <cutils/qtaguid.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
33 static jint QTagUid_tagSocketFd(JNIEnv* env, jclass,
34 jobject fileDescriptor,
35 jint tagNum, jint uid) {
36 int userFd = jniGetFDFromFileDescriptor(env, fileDescriptor);
38 if (env->ExceptionCheck()) {
39 ALOGE("Can't get FileDescriptor num");
43 int res = qtaguid_tagSocket(userFd, tagNum, uid);
50 static jint QTagUid_untagSocketFd(JNIEnv* env, jclass,
51 jobject fileDescriptor) {
52 int userFd = jniGetFDFromFileDescriptor(env, fileDescriptor);
54 if (env->ExceptionCheck()) {
55 ALOGE("Can't get FileDescriptor num");
59 int res = qtaguid_untagSocket(userFd);
66 static jint QTagUid_setCounterSet(JNIEnv* env, jclass,
67 jint setNum, jint uid) {
69 int res = qtaguid_setCounterSet(setNum, uid);
76 static jint QTagUid_deleteTagData(JNIEnv* env, jclass,
77 jint tagNum, jint uid) {
79 int res = qtaguid_deleteTagData(tagNum, uid);
86 static const JNINativeMethod gQTagUidMethods[] = {
87 { "native_tagSocketFd", "(Ljava/io/FileDescriptor;II)I", (void*)QTagUid_tagSocketFd},
88 { "native_untagSocketFd", "(Ljava/io/FileDescriptor;)I", (void*)QTagUid_untagSocketFd},
89 { "native_setCounterSet", "(II)I", (void*)QTagUid_setCounterSet},
90 { "native_deleteTagData", "(II)I", (void*)QTagUid_deleteTagData},
93 int register_android_server_NetworkManagementSocketTagger(JNIEnv* env) {
94 return jniRegisterNativeMethods(env, "com/android/server/NetworkManagementSocketTagger", gQTagUidMethods, NELEM(gQTagUidMethods));