Commit dadeffa9 authored by Mygod's avatar Mygod

Rename System to JniHelper to rename naming conflicts with

`java.lang.System`
parent 04e0cb02
...@@ -6,7 +6,7 @@ version := "4.0.0" ...@@ -6,7 +6,7 @@ version := "4.0.0"
versionCode := Some(175) versionCode := Some(175)
proguardOptions ++= proguardOptions ++=
"-keep class com.github.shadowsocks.System { *; }" :: "-keep class com.github.shadowsocks.JniHelper { *; }" ::
"-dontwarn com.google.android.gms.internal.**" :: "-dontwarn com.google.android.gms.internal.**" ::
"-dontwarn com.j256.ormlite.**" :: "-dontwarn com.j256.ormlite.**" ::
"-dontwarn okio.**" :: "-dontwarn okio.**" ::
......
...@@ -38,12 +38,12 @@ ...@@ -38,12 +38,12 @@
package com.github.shadowsocks; package com.github.shadowsocks;
public class System { public class JniHelper {
static { static {
java.lang.System.loadLibrary("system"); System.loadLibrary("jni-helper");
} }
public static native int exec(String cmd); public static native int exec(String cmd);
public static native int sendfd(int fd, String path); public static native int sendFd(int fd, String path);
public static native void jniclose(int fd); public static native void close(int fd);
} }
...@@ -388,16 +388,16 @@ LOCAL_LDLIBS := -llog ...@@ -388,16 +388,16 @@ LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_EXECUTABLE) include $(BUILD_SHARED_EXECUTABLE)
######################################################## ########################################################
## system ## jni-helper
######################################################## ########################################################
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE:= system LOCAL_MODULE:= jni-helper
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/libancillary LOCAL_C_INCLUDES:= $(LOCAL_PATH)/libancillary
LOCAL_SRC_FILES:= system.cpp LOCAL_SRC_FILES:= jni-helper.cpp
LOCAL_LDLIBS := -ldl -llog LOCAL_LDLIBS := -ldl -llog
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define LOGW(...) do { __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__); } while(0) #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) #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); const char *cmd_str = env->GetStringUTFChars(cmd, 0);
pid_t pid; pid_t pid;
...@@ -40,11 +40,11 @@ jint Java_com_github_shadowsocks_system_exec(JNIEnv *env, jobject thiz, jstring ...@@ -40,11 +40,11 @@ jint Java_com_github_shadowsocks_system_exec(JNIEnv *env, jobject thiz, jstring
return 1; 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); 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; int fd;
struct sockaddr_un addr; struct sockaddr_un addr;
const char *sock_str = env->GetStringUTFChars(path, 0); 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 ...@@ -75,15 +75,15 @@ jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint t
return 0; return 0;
} }
static const char *classPathName = "com/github/shadowsocks/System"; static const char *classPathName = "com/github/shadowsocks/JniHelper";
static JNINativeMethod method_table[] = { static JNINativeMethod method_table[] = {
{ "jniclose", "(I)V", { "close", "(I)V",
(void*) Java_com_github_shadowsocks_system_jniclose }, (void*) Java_com_github_shadowsocks_jnihelper_close },
{ "sendfd", "(ILjava/lang/String;)I", { "sendFd", "(ILjava/lang/String;)I",
(void*) Java_com_github_shadowsocks_system_sendfd }, (void*) Java_com_github_shadowsocks_jnihelper_sendfd },
{ "exec", "(Ljava/lang/String;)I", { "exec", "(Ljava/lang/String;)I",
(void*) Java_com_github_shadowsocks_system_exec } (void*) Java_com_github_shadowsocks_jnihelper_exec }
}; };
......
...@@ -291,7 +291,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -291,7 +291,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
var tries = 1 var tries = 1
while (tries < 5) { while (tries < 5) {
Thread.sleep(1000 * tries) 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 return true
} }
tries += 1 tries += 1
......
...@@ -92,7 +92,7 @@ class ShadowsocksVpnThread(service: ShadowsocksVpnService) extends Thread { ...@@ -92,7 +92,7 @@ class ShadowsocksVpnThread(service: ShadowsocksVpnService) extends Thread {
val ret = service.protect(fd) val ret = service.protect(fd)
// Trick to close file decriptor // Trick to close file decriptor
System.jniclose(fd) JniHelper.close(fd)
if (ret) { if (ret) {
output.write(0) output.write(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment