IPNReceiver: Add intents to connect and disconnect VPN (#84)

* IPNReceiver: Add intents to connect and disconnect VPN

Added a new class IPNReceiver to listen to intents silently and connect and disconnect the VPN
Also removed unneeded comment

Fixes: https://github.com/tailscale/tailscale/issues/3547

Signed-off-by: Brett Jenkins <brett@brettjenkins.co.uk>
pull/85/head
Brett Jenkins 1 year ago committed by GitHub
parent 7245e72dcf
commit 51a53e5472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,6 +55,13 @@
<data android:mimeType="video/*" />
</intent-filter>
</activity>
<receiver android:name="IPNReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.tailscale.ipn.CONNECT_VPN" />
<action android:name="com.tailscale.ipn.DISCONNECT_VPN" />
</intent-filter>
</receiver>
<service android:name=".IPNService"
android:permission="android.permission.BIND_VPN_SERVICE"
android:exported="false">

@ -0,0 +1,20 @@
package com.tailscale.ipn;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class IPNReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == "com.tailscale.ipn.CONNECT_VPN") {
connect();
} else if (intent.getAction() == "com.tailscale.ipn.DISCONNECT_VPN") {
disconnect();
}
}
private native void connect();
private native void disconnect();
}

@ -102,6 +102,16 @@ func Java_com_tailscale_ipn_IPNService_disconnect(env *C.JNIEnv, this C.jobject)
onDisconnect <- jni.NewGlobalRef(jenv, jni.Object(this))
}
//export Java_com_tailscale_ipn_IPNReceiver_connect
func Java_com_tailscale_ipn_IPNReceiver_connect(env *C.JNIEnv, this C.jobject) {
requestBackend(ConnectEvent{Enable: true})
}
//export Java_com_tailscale_ipn_IPNReceiver_disconnect
func Java_com_tailscale_ipn_IPNReceiver_disconnect(env *C.JNIEnv, this C.jobject) {
requestBackend(ConnectEvent{Enable: false})
}
//export Java_com_tailscale_ipn_App_onConnectivityChanged
func Java_com_tailscale_ipn_App_onConnectivityChanged(env *C.JNIEnv, cls C.jclass, connected C.jboolean) {
select {

Loading…
Cancel
Save