Prevent connecting loops when using connect intent more than once (#95)

* startvpnworker.java: prevent connecting loops

If start intent called more than once.

Turns out there were still some cases where the bug would occur, also it turns out checking the status of a VPN connection isn't foolproof in android, so this is a safer way to fix it, we just ensure that the autoConnect var is set to false when disconnecting.

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

Signed-off-by: Brett Jenkins <brett@brettjenkins.co.uk>
bradfitz/authkey_intent
Brett Jenkins 11 months ago committed by GitHub
parent 8e748afc47
commit 6348bb254a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -106,9 +106,6 @@ public class App extends Application {
NetworkInfo active = cMgr.getActiveNetworkInfo();
// https://developer.android.com/training/monitoring-device-state/connectivity-status-type
boolean isConnected = active != null && active.isConnectedOrConnecting();
if (isConnected) {
((App)getApplicationContext()).autoConnect = false;
}
onConnectivityChanged(isConnected);
}

@ -22,6 +22,7 @@ public class IPNService extends VpnService {
@Override public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null && ACTION_DISCONNECT.equals(intent.getAction())) {
((App)getApplicationContext()).autoConnect = false;
close();
return START_NOT_STICKY;
}

@ -4,16 +4,16 @@
package com.tailscale.ipn;
import androidx.work.Worker;
import android.content.Context;
import androidx.work.WorkerParameters;
import android.net.VpnService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.VpnService;
import android.os.Build;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
public final class StartVPNWorker extends Worker {
@ -24,8 +24,9 @@ public final class StartVPNWorker extends Worker {
}
@Override public Result doWork() {
// We will start the VPN from the background
App app = ((App)getApplicationContext());
// We will start the VPN from the background
app.autoConnect = true;
// We need to make sure we prepare the VPN Service, just in case it isn't prepared.

Loading…
Cancel
Save