diff --git a/mobile/build.sbt b/mobile/build.sbt index 9ee9f4a8..ce4f4c03 100644 --- a/mobile/build.sbt +++ b/mobile/build.sbt @@ -6,7 +6,7 @@ version := "4.0.0" versionCode := Some(175) proguardOptions ++= - "-keep class com.github.shadowsocks.System { *; }" :: + "-keep class com.github.shadowsocks.JniHelper { *; }" :: "-dontwarn com.google.android.gms.internal.**" :: "-dontwarn com.j256.ormlite.**" :: "-dontwarn okio.**" :: diff --git a/mobile/src/main/java/com/github/shadowsocks/System.java b/mobile/src/main/java/com/github/shadowsocks/JniHelper.java similarity index 91% rename from mobile/src/main/java/com/github/shadowsocks/System.java rename to mobile/src/main/java/com/github/shadowsocks/JniHelper.java index ab167c27..a042a9f2 100755 --- a/mobile/src/main/java/com/github/shadowsocks/System.java +++ b/mobile/src/main/java/com/github/shadowsocks/JniHelper.java @@ -38,12 +38,12 @@ package com.github.shadowsocks; -public class System { +public class JniHelper { static { - java.lang.System.loadLibrary("system"); + System.loadLibrary("jni-helper"); } public static native int exec(String cmd); - public static native int sendfd(int fd, String path); - public static native void jniclose(int fd); + public static native int sendFd(int fd, String path); + public static native void close(int fd); } diff --git a/mobile/src/main/jni/Android.mk b/mobile/src/main/jni/Android.mk index 6fbec5fc..45d3b96d 100755 --- a/mobile/src/main/jni/Android.mk +++ b/mobile/src/main/jni/Android.mk @@ -388,16 +388,16 @@ LOCAL_LDLIBS := -llog include $(BUILD_SHARED_EXECUTABLE) ######################################################## -## system +## jni-helper ######################################################## include $(CLEAR_VARS) -LOCAL_MODULE:= system +LOCAL_MODULE:= jni-helper LOCAL_C_INCLUDES:= $(LOCAL_PATH)/libancillary -LOCAL_SRC_FILES:= system.cpp +LOCAL_SRC_FILES:= jni-helper.cpp LOCAL_LDLIBS := -ldl -llog diff --git a/mobile/src/main/jni/system.cpp b/mobile/src/main/jni/jni-helper.cpp similarity index 85% rename from mobile/src/main/jni/system.cpp rename to mobile/src/main/jni/jni-helper.cpp index c5e2bc8c..30b118f5 100644 --- a/mobile/src/main/jni/system.cpp +++ b/mobile/src/main/jni/jni-helper.cpp @@ -17,7 +17,7 @@ #define LOGW(...) do { __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__); } while(0) #define LOGE(...) do { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__); } while(0) -jint Java_com_github_shadowsocks_system_exec(JNIEnv *env, jobject thiz, jstring cmd) { +jint Java_com_github_shadowsocks_jnihelper_exec(JNIEnv *env, jobject thiz, jstring cmd) { const char *cmd_str = env->GetStringUTFChars(cmd, 0); pid_t pid; @@ -40,11 +40,11 @@ jint Java_com_github_shadowsocks_system_exec(JNIEnv *env, jobject thiz, jstring return 1; } -void Java_com_github_shadowsocks_system_jniclose(JNIEnv *env, jobject thiz, jint fd) { +void Java_com_github_shadowsocks_jnihelper_close(JNIEnv *env, jobject thiz, jint fd) { close(fd); } -jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint tun_fd, jstring path) { +jint Java_com_github_shadowsocks_jnihelper_sendfd(JNIEnv *env, jobject thiz, jint tun_fd, jstring path) { int fd; struct sockaddr_un addr; const char *sock_str = env->GetStringUTFChars(path, 0); @@ -75,15 +75,15 @@ jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint t return 0; } -static const char *classPathName = "com/github/shadowsocks/System"; +static const char *classPathName = "com/github/shadowsocks/JniHelper"; static JNINativeMethod method_table[] = { - { "jniclose", "(I)V", - (void*) Java_com_github_shadowsocks_system_jniclose }, - { "sendfd", "(ILjava/lang/String;)I", - (void*) Java_com_github_shadowsocks_system_sendfd }, + { "close", "(I)V", + (void*) Java_com_github_shadowsocks_jnihelper_close }, + { "sendFd", "(ILjava/lang/String;)I", + (void*) Java_com_github_shadowsocks_jnihelper_sendfd }, { "exec", "(Ljava/lang/String;)I", - (void*) Java_com_github_shadowsocks_system_exec } + (void*) Java_com_github_shadowsocks_jnihelper_exec } }; diff --git a/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala b/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala index d8d37808..dcdf80be 100644 --- a/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala +++ b/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala @@ -291,7 +291,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { var tries = 1 while (tries < 5) { Thread.sleep(1000 * tries) - if (System.sendfd(fd, new File(getFilesDir, "sock_path").getAbsolutePath) != -1) { + if (JniHelper.sendFd(fd, new File(getFilesDir, "sock_path").getAbsolutePath) != -1) { return true } tries += 1 diff --git a/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala b/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala index d34a60c0..42eddfd7 100644 --- a/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala +++ b/mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala @@ -92,7 +92,7 @@ class ShadowsocksVpnThread(service: ShadowsocksVpnService) extends Thread { val ret = service.protect(fd) // Trick to close file decriptor - System.jniclose(fd) + JniHelper.close(fd) if (ret) { output.write(0)