• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * This code is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.  The Android Open Source
7  * Project designates this particular file as subject to the "Classpath"
8  * exception as provided by The Android Open Source Project in the LICENSE
9  * file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #include <nativehelper/JNIPlatformHelp.h>
23 #include <nativehelper/ScopedLocalRef.h>
24 
25 #include "JniConstants.h"
26 
tagSocket(JNIEnv * env,int fd)27 extern "C" int tagSocket(JNIEnv* env, int fd) {
28     if (env->ExceptionOccurred()) {
29       return fd;
30     }
31 
32     jobject fileDescriptor = jniCreateFileDescriptor(env, fd);
33     if (fileDescriptor == nullptr) {
34       return fd;
35     }
36 
37     jclass socketTaggerClass = JniConstants::GetSocketTaggerClass(env);
38     jmethodID get = env->GetStaticMethodID(socketTaggerClass,
39                                            "get",
40                                            "()Ldalvik/system/SocketTagger;");
41     jobject socketTagger = env->CallStaticObjectMethod(socketTaggerClass, get);
42     jmethodID tag = env->GetMethodID(socketTaggerClass, "tag", "(Ljava/io/FileDescriptor;)V");
43 
44     env->CallVoidMethod(socketTagger, tag, fileDescriptor);
45     return fd;
46 }
47