commit 2eaa192c72efa47f322a92bbd7a2032b069fbc81 Author: n8fr8 nathan@guardianproject.info Date: Mon Aug 24 16:02:23 2020 -0400
a few more checks to handle null intents --- .../torproject/android/service/OrbotService.java | 19 +++--- .../android/service/vpn/OrbotVpnManager.java | 67 +++++++++++----------- 2 files changed, 40 insertions(+), 46 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 61404632..8d98d40e 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java @@ -375,14 +375,15 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
String action = mIntent.getAction();
- if (action != null) { + if (!TextUtils.isEmpty(action)) { if (action.equals(ACTION_START) || action.equals(ACTION_START_ON_BOOT)) { startTor(); replyWithStatus(mIntent);
if (Prefs.useVpn()) { - if (!mVpnManager.isStarted()) { + if (mVpnManager != null + && (!mVpnManager.isStarted())) { //start VPN here Intent vpnIntent = VpnService.prepare(OrbotService.this); if (vpnIntent == null) //then we can run the VPN @@ -398,7 +399,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
} else if (action.equals(ACTION_START_VPN)) { - if (!mVpnManager.isStarted()) { + if (mVpnManager != null && (!mVpnManager.isStarted())) { //start VPN here Intent vpnIntent = VpnService.prepare(OrbotService.this); if (vpnIntent == null) //then we can run the VPN @@ -415,7 +416,8 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
} else if (action.equals(ACTION_STOP_VPN)) { - mVpnManager.handleIntent(new Builder(),mIntent); + if (mVpnManager != null) + mVpnManager.handleIntent(new Builder(),mIntent); } else if (action.equals(ACTION_STATUS)) { replyWithStatus(mIntent); @@ -1978,7 +1980,7 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb @Override public IBinder onBind(Intent intent) { Log.e( TAG, "onBind" ); - handleIntent(intent); + //do nothing here return super.onBind(intent); // invoking super class will call onRevoke() when appropriate }
@@ -1991,13 +1993,6 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_STOP_VPN)); }
- private void handleIntent( Intent intent ) { - if( intent != null && intent.getAction() != null ) { - Log.e( TAG, intent.getAction()); - } - } - - private void setExitNode (String newExits) { SharedPreferences prefs = Prefs.getSharedPrefs(getApplicationContext()); 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 5194e5c3..3dd315fd 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 @@ -27,6 +27,7 @@ import android.os.Build; import android.os.Handler; import android.os.Message; import android.os.ParcelFileDescriptor; +import android.text.TextUtils; import android.util.Log; import android.widget.Toast; import com.runjva.sourceforge.jsocks.protocol.ProxyServer; @@ -95,52 +96,50 @@ public class OrbotVpnManager implements Handler.Callback { public int handleIntent(VpnService.Builder builder, Intent intent) { if (intent != null) { String action = intent.getAction(); - - if (action.equals(ACTION_START_VPN)||action.equals(ACTION_START)) { - Log.d(TAG,"starting VPN");
- isStarted = true; + if (!TextUtils.isEmpty(action)) { + if (action.equals(ACTION_START_VPN) || action.equals(ACTION_START)) { + Log.d(TAG, "starting VPN");
- // Stop the previous session by interrupting the thread. - if (mThreadVPN != null && mThreadVPN.isAlive()) - stopVPN(); + isStarted = true;
- if (mTorSocks != -1) - { - if (!mIsLollipop) - { - startSocksBypass(); + // Stop the previous session by interrupting the thread. + if (mThreadVPN != null && mThreadVPN.isAlive()) + stopVPN(); + + if (mTorSocks != -1) { + if (!mIsLollipop) { + startSocksBypass(); + } + + setupTun2Socks(builder); }
- setupTun2Socks(builder); - } + } else if (action.equals(ACTION_STOP_VPN)) { + isStarted = false;
- } - else if (action.equals(ACTION_STOP_VPN)) { - isStarted = false; + Log.d(TAG, "stopping VPN");
- Log.d(TAG,"stopping VPN"); - - stopVPN(); - } - else if (action.equals(TorServiceConstants.LOCAL_ACTION_PORTS)) { - Log.d(TAG,"setting VPN ports"); + stopVPN(); + } else if (action.equals(TorServiceConstants.LOCAL_ACTION_PORTS)) { + Log.d(TAG, "setting VPN ports");
- int torSocks = intent.getIntExtra(OrbotService.EXTRA_SOCKS_PROXY_PORT,-1); - int torDns = intent.getIntExtra(OrbotService.EXTRA_DNS_PORT,-1); + int torSocks = intent.getIntExtra(OrbotService.EXTRA_SOCKS_PROXY_PORT, -1); + int torDns = intent.getIntExtra(OrbotService.EXTRA_DNS_PORT, -1);
- //if running, we need to restart - if ((torSocks != mTorSocks || torDns != mTorDns)) { + //if running, we need to restart + if ((torSocks != mTorSocks || torDns != mTorDns)) {
- mTorSocks = torSocks; - mTorDns = torDns; + mTorSocks = torSocks; + mTorDns = torDns;
- if (!mIsLollipop) { - stopSocksBypass(); - startSocksBypass(); - } + if (!mIsLollipop) { + stopSocksBypass(); + startSocksBypass(); + }
- setupTun2Socks(builder); + setupTun2Socks(builder); + } } }
tor-commits@lists.torproject.org