Home | History | Annotate | Download | only in native
      1 /*
      2  * Copyright 2016 Google Inc.
      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.  Google designates this
      7  * particular file as subject to the "Classpath" exception as provided
      8  * by Google in the LICENSE file that accompanied this code.
      9  *
     10  * This code is distributed in the hope that it will be useful, but WITHOUT
     11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     13  * version 2 for more details (a copy is included in the LICENSE file that
     14  * accompanied this code).
     15  *
     16  * You should have received a copy of the GNU General Public License version
     17  * 2 along with this work; if not, write to the Free Software Foundation,
     18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     19  */
     20 
     21 #include <nativehelper/JNIHelp.h>
     22 #include <nativehelper/JniConstants.h>
     23 
     24 extern "C" {
     25 
     26 int tagSocket(JNIEnv* env, int fd) {
     27     if (env->ExceptionOccurred()) { return fd; }
     28     jmethodID get = env->GetStaticMethodID(JniConstants::socketTaggerClass,
     29                                            "get", "()Ldalvik/system/SocketTagger;");
     30     jobject socketTagger =
     31         env->CallStaticObjectMethod(JniConstants::socketTaggerClass, get);
     32     jmethodID tag = env->GetMethodID(JniConstants::socketTaggerClass,
     33                                      "tag", "(Ljava/io/FileDescriptor;)V");
     34 
     35     jobject fileDescriptor = jniCreateFileDescriptor(env, fd);
     36     env->CallVoidMethod(socketTagger, tag, fileDescriptor);
     37     return fd;
     38 }
     39 
     40 }
     41