Lorenzo Colitti | 81b707f | 2022-01-29 21:07:33 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include <android/file_descriptor_jni.h> |
| 18 | #include <android/multinetwork.h> |
| 19 | #include <nativehelper/JNIHelp.h> |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | static jint tagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor, jint tag, jint uid) { |
| 24 | int fd = AFileDescriptor_getFd(env, fileDescriptor); |
| 25 | if (fd == -1) return -EBADF; |
| 26 | return android_tag_socket_with_uid(fd, tag, uid); |
| 27 | } |
| 28 | |
| 29 | static jint untagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor) { |
| 30 | int fd = AFileDescriptor_getFd(env, fileDescriptor); |
| 31 | if (fd == -1) return -EBADF; |
| 32 | return android_untag_socket(fd); |
| 33 | } |
| 34 | |
| 35 | static const JNINativeMethod gMethods[] = { |
| 36 | /* name, signature, funcPtr */ |
| 37 | { "native_tagSocketFd", "(Ljava/io/FileDescriptor;II)I", (void*) tagSocketFd }, |
| 38 | { "native_untagSocketFd", "(Ljava/io/FileDescriptor;)I", (void*) untagSocketFd }, |
| 39 | }; |
| 40 | |
| 41 | int register_android_net_TrafficStats(JNIEnv* env) { |
| 42 | return jniRegisterNativeMethods(env, "android/net/TrafficStats", gMethods, NELEM(gMethods)); |
| 43 | } |
| 44 | |
| 45 | }; // namespace android |
| 46 | |