Doesn't work yet.

always-on
Denton Gentry 4 years ago
parent 76df742662
commit b151204424

@ -24,7 +24,15 @@ public class IPNService extends VpnService {
if (intent != null && ACTION_DISCONNECT.equals(intent.getAction())) { if (intent != null && ACTION_DISCONNECT.equals(intent.getAction())) {
close(); close();
return START_NOT_STICKY; return START_NOT_STICKY;
} else if (intent != null && ACTION_CONNECT.equals(intent.getAction())) {
connect();
return START_STICKY;
} else if (intent != null) {
// we're being started due to Always-on VPN
connectAtBoot();
return START_STICKY;
} }
// dunno what this is.
connect(); connect();
return START_STICKY; return START_STICKY;
} }
@ -87,4 +95,5 @@ public class IPNService extends VpnService {
private native void connect(); private native void connect();
private native void disconnect(); private native void disconnect();
private native void connectAtBoot();
} }

@ -7,6 +7,7 @@ package main
// JNI implementations of Java native callback methods. // JNI implementations of Java native callback methods.
import ( import (
"log"
"unsafe" "unsafe"
"github.com/tailscale/tailscale-android/jni" "github.com/tailscale/tailscale-android/jni"
@ -81,12 +82,14 @@ func notifyVPNClosed() {
//export Java_com_tailscale_ipn_IPNService_connect //export Java_com_tailscale_ipn_IPNService_connect
func Java_com_tailscale_ipn_IPNService_connect(env *C.JNIEnv, this C.jobject) { func Java_com_tailscale_ipn_IPNService_connect(env *C.JNIEnv, this C.jobject) {
log.Printf("Java_com_tailscale_ipn_IPNService_connect")
jenv := (*jni.Env)(unsafe.Pointer(env)) jenv := (*jni.Env)(unsafe.Pointer(env))
onConnect <- jni.NewGlobalRef(jenv, jni.Object(this)) onConnect <- jni.NewGlobalRef(jenv, jni.Object(this))
} }
//export Java_com_tailscale_ipn_IPNService_disconnect //export Java_com_tailscale_ipn_IPNService_disconnect
func Java_com_tailscale_ipn_IPNService_disconnect(env *C.JNIEnv, this C.jobject) { func Java_com_tailscale_ipn_IPNService_disconnect(env *C.JNIEnv, this C.jobject) {
log.Printf("Java_com_tailscale_ipn_IPNService_disconnect")
jenv := (*jni.Env)(unsafe.Pointer(env)) jenv := (*jni.Env)(unsafe.Pointer(env))
onDisconnect <- jni.NewGlobalRef(jenv, jni.Object(this)) onDisconnect <- jni.NewGlobalRef(jenv, jni.Object(this))
} }
@ -174,3 +177,10 @@ func Java_com_tailscale_ipn_App_onShareIntent(env *C.JNIEnv, cls C.jclass, nfile
} }
onFileShare <- files onFileShare <- files
} }
//export Java_com_tailscale_ipn_IPNService_connectAtBoot
func Java_com_tailscale_ipn_IPNService_connectAtBoot(env *C.JNIEnv, cls C.jclass) {
log.Printf("Java_com_tailscale_ipn_IPNService_connectAtBoot")
requestBackend(WantRunningEvent{})
requestBackend(ConnectEvent{Enable: true})
}

@ -181,6 +181,7 @@ type (
GoogleAuthEvent struct{} GoogleAuthEvent struct{}
LogoutEvent struct{} LogoutEvent struct{}
FileTargetsEvent struct{} FileTargetsEvent struct{}
WantRunningEvent struct{}
) )
// serverOAuthID is the OAuth ID of the tailscale-android server, used // serverOAuthID is the OAuth ID of the tailscale-android server, used
@ -412,6 +413,10 @@ func (a *App) runBackend() error {
go b.backend.SetPrefs(state.Prefs) go b.backend.SetPrefs(state.Prefs)
state.updateExitNodes() state.updateExitNodes()
a.notify(state) a.notify(state)
case WantRunningEvent:
state.Prefs.WantRunning = true
go b.backend.SetPrefs(state.Prefs)
a.notify(state)
} }
case s := <-onConnect: case s := <-onConnect:
jni.Do(a.jvm, func(env *jni.Env) error { jni.Do(a.jvm, func(env *jni.Env) error {

Loading…
Cancel
Save