mirror of https://github.com/M66B/NetGuard.git
Android N compatibility: get system properties
http://developer.android.com/preview/behavior-changes.html#ndk
This commit is contained in:
parent
140a4441be
commit
5c5d016bd6
|
@ -297,8 +297,8 @@ JNIEXPORT jstring JNICALL
|
|||
Java_eu_faircode_netguard_Util_jni_1getprop(JNIEnv *env, jclass type, jstring name_) {
|
||||
const char *name = (*env)->GetStringUTFChars(env, name_, 0);
|
||||
|
||||
char value[250] = "";
|
||||
__system_property_get(env, name, value);
|
||||
char value[PROP_VALUE_MAX + 1] = "";
|
||||
__system_property_get(name, value);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, name_, name);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <netinet/icmp6.h>
|
||||
|
||||
#include <android/log.h>
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
#define TAG "NetGuard.JNI"
|
||||
|
||||
|
@ -55,8 +56,6 @@
|
|||
#define UID_DELAYTRY 10 // milliseconds
|
||||
#define UID_MAXTRY 3
|
||||
|
||||
#define RTLD_NOLOAD 4
|
||||
|
||||
struct arguments {
|
||||
JNIEnv *env;
|
||||
jobject instance;
|
||||
|
@ -463,8 +462,6 @@ int jniCheckException(JNIEnv *env);
|
|||
|
||||
int sdk_int(JNIEnv *env);
|
||||
|
||||
int __system_property_get(JNIEnv *env, const char *name, char *value);
|
||||
|
||||
void log_android(int prio, const char *fmt, ...);
|
||||
|
||||
void log_packet(const struct arguments *args, jobject jpacket);
|
||||
|
|
|
@ -60,24 +60,6 @@ int sdk_int(JNIEnv *env) {
|
|||
return (*env)->GetStaticIntField(env, clsVersion, fid);
|
||||
}
|
||||
|
||||
typedef int (*PFN_SYS_PROP_GET)(const char *, char *);
|
||||
|
||||
int __system_property_get(JNIEnv *env, const char *name, char *value) {
|
||||
static PFN_SYS_PROP_GET __real_system_property_get = NULL;
|
||||
if (!__real_system_property_get) {
|
||||
void *handle = dlopen("libc.so", sdk_int(env) >= 21 ? RTLD_NOLOAD : 0);
|
||||
if (!handle)
|
||||
log_android(ANDROID_LOG_ERROR, "dlopen(libc.so): %s", dlerror());
|
||||
else {
|
||||
__real_system_property_get = (PFN_SYS_PROP_GET) dlsym(
|
||||
handle, "__system_property_get");
|
||||
if (!__real_system_property_get)
|
||||
log_android(ANDROID_LOG_ERROR, "dlsym(__system_property_get()): %s", dlerror());
|
||||
}
|
||||
}
|
||||
return (*__real_system_property_get)(name, value);
|
||||
}
|
||||
|
||||
void log_android(int prio, const char *fmt, ...) {
|
||||
if (prio >= loglevel) {
|
||||
char line[1024];
|
||||
|
|
Loading…
Reference in New Issue