Commit aae95df4 authored by Max Lv's avatar Max Lv

add abi helper function

parent af6fcf0e
......@@ -44,4 +44,5 @@ public class System {
}
public static native void exec(String cmd);
public static native String getABI();
}
......@@ -136,6 +136,8 @@ LOCAL_SRC_FILES:= \
LOCAL_LDLIBS := -ldl -llog
LOCAL_STATIC_LIBRARIES := cpufeatures
include $(BUILD_SHARED_LIBRARY)
########################################################
......@@ -241,3 +243,5 @@ iptables_subdirs := $(addprefix $(LOCAL_PATH)/iptables/,$(addsuffix /Android.mk,
))
include $(iptables_subdirs)
# Import cpufeatures
$(call import-module,android/cpufeatures)
\ No newline at end of file
......@@ -5,12 +5,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <cpu-features.h>
#define LOGI(...) do { __android_log_print(ANDROID_LOG_INFO, 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)
void Java_com_github_shadowsocks_Node_exec(JNIEnv *env, jobject thiz, jstring cmd) {
jstring Java_com_github_shadowsocks_system_getabi(JNIEnv *env, jobject thiz) {
AndroidCpuFamily family = android_getCpuFamily();
const char *abi;
if (family == ANDROID_CPU_FAMILY_X86) {
abi = "x86";
} else if (family == ANDROID_CPU_FAMILY_MIPS) {
abi = "mips";
} else if (family == ANDROID_CPU_FAMILY_ARM) {
abi = "arm";
}
return env->NewStringUTF(abi);
}
void Java_com_github_shadowsocks_system_exec(JNIEnv *env, jobject thiz, jstring cmd) {
const char *str = env->GetStringUTFChars(cmd, 0);
setenv("LD_LIBRARY_PATH", "/vendor/lib:/system/lib", 1);
setegid(getgid());
......@@ -23,7 +38,9 @@ static const char *classPathName = "com/github/shadowsocks/System";
static JNINativeMethod method_table[] = {
{ "exec", "(Ljava/lang/String;)V",
(void*) Java_com_github_shadowsocks_Node_exec }
(void*) Java_com_github_shadowsocks_system_exec },
{ "getABI", "()Ljava/lang/String;",
(void*) Java_com_github_shadowsocks_system_getabi }
};
/*
......
......@@ -800,7 +800,7 @@ class Shadowsocks
def reset() {
crash_recovery()
copyAssets(Utils.getABI)
copyAssets(System.getABI)
Utils.runCommand("chmod 755 /data/data/com.github.shadowsocks/iptables\n"
+ "chmod 755 /data/data/com.github.shadowsocks/redsocks\n"
+ "chmod 755 /data/data/com.github.shadowsocks/pdnsd\n"
......
......@@ -282,31 +282,6 @@ object Utils {
false
}
/**
* Get the ABI of the device
* @return The ABI of the device, or ARM_ABI if not found
*/
def getABI: String = {
val prop = getSystemProperty(ABI_PROP)
prop match {
case abi if abi.toLowerCase.contains(ARM_ABI) => ARM_ABI
case abi if abi.toLowerCase.contains(X86_ABI) => X86_ABI
case _ => ARM_ABI
}
}
/**
* Returns a SystemProperty
*
* @param propName The Property to retrieve
* @return The Property, or NULL if not found
*/
def getSystemProperty(propName: String): String = {
val p: Process = Runtime.getRuntime.exec("getprop " + propName)
val lines = scala.io.Source.fromInputStream(p.getInputStream).getLines()
if (lines.hasNext) lines.next() else null
}
/**
* Check the system's iptables
* Default to use the app's iptables
......
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