mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-26 08:02:47 +00:00
Native stop with clear
This commit is contained in:
parent
e0d80a248a
commit
333747185a
2 changed files with 20 additions and 20 deletions
|
@ -61,8 +61,6 @@ import android.util.Log;
|
|||
import android.util.TypedValue;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
@ -117,9 +115,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
|
||||
private native void jni_start(int tun);
|
||||
|
||||
private native void jni_stop(int tun);
|
||||
|
||||
private native void jni_reload(int tun);
|
||||
private native void jni_stop(int tun, boolean clear);
|
||||
|
||||
static {
|
||||
System.loadLibrary("netguard");
|
||||
|
@ -275,15 +271,16 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
if (vpn == null)
|
||||
throw new IllegalStateException("Handover failed");
|
||||
}
|
||||
jni_stop(vpn.getFd(), false);
|
||||
if (prefs.getBoolean("log", false))
|
||||
jni_reload(vpn.getFd());
|
||||
jni_start(vpn.getFd());
|
||||
if (prev != null)
|
||||
stopVPN(prev);
|
||||
break;
|
||||
|
||||
case stop:
|
||||
if (vpn != null) {
|
||||
jni_stop(vpn.getFd());
|
||||
jni_stop(vpn.getFd(), true);
|
||||
stopVPN(vpn);
|
||||
vpn = null;
|
||||
}
|
||||
|
@ -996,7 +993,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
}
|
||||
|
||||
if (vpn != null) {
|
||||
jni_stop(vpn.getFd());
|
||||
jni_stop(vpn.getFd(), true);
|
||||
stopVPN(vpn);
|
||||
vpn = null;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,8 @@ Java_eu_faircode_netguard_SinkholeService_jni_1init(JNIEnv *env, jobject instanc
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_eu_faircode_netguard_SinkholeService_jni_1start(JNIEnv *env, jobject instance, jint tun) {
|
||||
Java_eu_faircode_netguard_SinkholeService_jni_1start(JNIEnv *env, jobject instance,
|
||||
jint tun) {
|
||||
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Starting tun=%d", tun);
|
||||
|
||||
if (pthread_kill(thread_id, 0) == 0)
|
||||
|
@ -113,8 +114,9 @@ Java_eu_faircode_netguard_SinkholeService_jni_1start(JNIEnv *env, jobject instan
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_eu_faircode_netguard_SinkholeService_jni_1stop(JNIEnv *env, jobject instance, jint tun) {
|
||||
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Stop thread %u", thread_id);
|
||||
Java_eu_faircode_netguard_SinkholeService_jni_1stop(JNIEnv *env, jobject instance,
|
||||
jint tun, jboolean clear) {
|
||||
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Stop tun %d clear %d", tun, clear);
|
||||
if (pthread_kill(thread_id, 0) == 0) {
|
||||
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Kill thread %u", thread_id);
|
||||
int err = pthread_kill(thread_id, SIGUSR1);
|
||||
|
@ -128,20 +130,20 @@ Java_eu_faircode_netguard_SinkholeService_jni_1stop(JNIEnv *env, jobject instanc
|
|||
__android_log_print(ANDROID_LOG_WARN, TAG, "pthread_join error %d: %s",
|
||||
err, strerror(err));
|
||||
}
|
||||
// TODO: clear sessions (not reload)
|
||||
if (clear) {
|
||||
struct session *s = session;
|
||||
while (s != NULL) {
|
||||
struct session *p = s;
|
||||
s = s->next;
|
||||
free(p);
|
||||
}
|
||||
session = NULL;
|
||||
}
|
||||
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Stopped");
|
||||
} else
|
||||
__android_log_print(ANDROID_LOG_WARN, TAG, "Not running");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_eu_faircode_netguard_SinkholeService_jni_1reload(JNIEnv *env, jobject instance, jint tun) {
|
||||
// TODO seamless handover
|
||||
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Reload tun=%d", tun);
|
||||
Java_eu_faircode_netguard_SinkholeService_jni_1stop(env, instance, tun);
|
||||
Java_eu_faircode_netguard_SinkholeService_jni_1start(env, instance, tun);
|
||||
}
|
||||
|
||||
// Private functions
|
||||
|
||||
void sig_handler(int sig, siginfo_t *info, void *context) {
|
||||
|
@ -1127,3 +1129,4 @@ char *hex(const u_int8_t *data, const u_int16_t len) {
|
|||
}
|
||||
return hexout;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue