|
|
|
|
@ -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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|