commit cabf328b52ea7ed105c15952902cc0cc66baa1d6 Author: n8fr8 nathan@guardianproject.info Date: Mon May 4 11:13:53 2020 -0400
don't start tun2socks/VPN if it is already running --- .../torproject/android/service/OrbotService.java | 33 ++++++++++++++-------- .../android/service/vpn/OrbotVpnManager.java | 13 ++++++--- 2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java index 596771cf..9ecd9c96 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java @@ -373,27 +373,36 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
if (Prefs.useVpn()) { + if (!mVpnManager.isStarted()) { + //start VPN here + Intent vpnIntent = VpnService.prepare(OrbotService.this); + if (vpnIntent == null) //then we can run the VPN + { + mVpnManager.handleIntent(new Builder(), mIntent); + + } + } + + if (mPortSOCKS != -1 && mPortHTTP != -1) + sendCallbackPorts(mPortSOCKS, mPortHTTP, mPortDns, mPortTrans); + } + + } + else if (action.equals(ACTION_START_VPN)) { + if (!mVpnManager.isStarted()) { //start VPN here Intent vpnIntent = VpnService.prepare(OrbotService.this); if (vpnIntent == null) //then we can run the VPN { mVpnManager.handleIntent(new Builder(), mIntent); - if (mPortSOCKS != -1 && mPortHTTP != -1) - sendCallbackPorts(mPortSOCKS, mPortHTTP, mPortDns, mPortTrans); + + } }
- } - else if (action.equals(ACTION_START_VPN)) { - //start VPN here - Intent vpnIntent = VpnService.prepare(OrbotService.this); - if (vpnIntent == null) //then we can run the VPN - { - mVpnManager.handleIntent(new Builder(), mIntent); + if (mPortSOCKS != -1 && mPortHTTP != -1) + sendCallbackPorts(mPortSOCKS, mPortHTTP, mPortDns, mPortTrans);
- if (mPortSOCKS != -1 && mPortHTTP != -1) - sendCallbackPorts(mPortSOCKS, mPortHTTP, mPortDns, mPortTrans); - }
} else if (action.equals(ACTION_STOP_VPN)) { diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java index f5a3e8a9..81e8f1a0 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java +++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java @@ -236,8 +236,10 @@ public class OrbotVpnManager implements Handler.Callback { { if (mIsLollipop) stopSocksBypass (); - - if (mInterface != null){ + + Tun2Socks.Stop(); + + if (mInterface != null){ try { Log.d(TAG,"closing interface, destroying VPN interface"); @@ -256,9 +258,8 @@ public class OrbotVpnManager implements Handler.Callback { } }
+ stopDns(); - - Tun2Socks.Stop();
mThreadVPN = null;
@@ -493,6 +494,10 @@ public class OrbotVpnManager implements Handler.Callback { return fPid; }
+ public boolean isStarted () + { + return isStarted; + }
}