Fixes Android quick settings tile - issue #2646 (#143)

* quicksettings - move to use intents com.tailscale.ipn.CONNECT_VPN and com.tailscale.ipn.DICONNECT_VPN - Fixes #2646

Signed-off-by: Nicola Beghin <nicolabeghin@gmail.com>

* cleanup imports - Fixes #2646

Signed-off-by: Nicola Beghin <nicolabeghin@gmail.com>

---------

Signed-off-by: Nicola Beghin <nicolabeghin@gmail.com>
pull/157/head
Nicola Beghin 10 months ago committed by GitHub
parent 915e4e3394
commit df9c75136b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -12,14 +12,17 @@ import androidx.work.OneTimeWorkRequest;
public class IPNReceiver extends BroadcastReceiver {
public static final String INTENT_CONNECT_VPN = "com.tailscale.ipn.CONNECT_VPN";
public static final String INTENT_DISCONNECT_VPN = "com.tailscale.ipn.DISCONNECT_VPN";
@Override
public void onReceive(Context context, Intent intent) {
WorkManager workManager = WorkManager.getInstance(context);
// On the relevant action, start the relevant worker, which can stay active for longer than this receiver can.
if (intent.getAction() == "com.tailscale.ipn.CONNECT_VPN") {
if (intent.getAction() == INTENT_CONNECT_VPN) {
workManager.enqueue(new OneTimeWorkRequest.Builder(StartVPNWorker.class).build());
} else if (intent.getAction() == "com.tailscale.ipn.DISCONNECT_VPN") {
} else if (intent.getAction() == INTENT_DISCONNECT_VPN) {
workManager.enqueue(new OneTimeWorkRequest.Builder(StopVPNWorker.class).build());
}
}

@ -5,14 +5,10 @@
package com.tailscale.ipn;
import android.content.Context;
import android.content.ComponentName;
import android.content.Intent;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicBoolean;
public class QuickToggleService extends TileService {
// lock protects the static fields below it.
private static Object lock = new Object();
@ -79,5 +75,14 @@ public class QuickToggleService extends TileService {
updateTile();
}
private static native void onTileClick();
private void onTileClick() {
boolean act;
synchronized (lock) {
act = active && ready;
}
Intent i = new Intent(act ? IPNReceiver.INTENT_DISCONNECT_VPN : IPNReceiver.INTENT_CONNECT_VPN);
i.setPackage(getPackageName());
i.setClass(getApplicationContext(), com.tailscale.ipn.IPNReceiver.class);
sendBroadcast(i);
}
}

@ -117,11 +117,6 @@ func Java_com_tailscale_ipn_StopVPNWorker_disconnect(env *C.JNIEnv, this C.jobje
requestBackend(ConnectEvent{Enable: false})
}
//export Java_com_tailscale_ipn_QuickToggleService_onTileClick
func Java_com_tailscale_ipn_QuickToggleService_onTileClick(env *C.JNIEnv, cls C.jclass) {
requestBackend(ToggleEvent{})
}
//export Java_com_tailscale_ipn_Peer_onActivityResult0
func Java_com_tailscale_ipn_Peer_onActivityResult0(env *C.JNIEnv, cls C.jclass, act C.jobject, reqCode, resCode C.jint) {
switch reqCode {

Loading…
Cancel
Save