[tor-commits] [orbot/master] When the VPN is disconnected through another app using VpnService or manually by the user

n8fr8 at torproject.org n8fr8 at torproject.org
Mon Aug 24 21:02:51 UTC 2020


commit 992b31087edb4fdacd66db5d89a4a0752558f0fa
Author: bim <dsnake at protonmail.com>
Date:   Tue Jul 21 02:06:16 2020 -0400

    When the VPN is disconnected through another app using VpnService or manually by the user
    turn off the VPN toggle within Orbot
---
 .../java/org/torproject/android/OrbotMainActivity.java    |  4 ++++
 .../java/org/torproject/android/service/OrbotService.java | 15 ++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 3687e9cc..199a5177 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -274,6 +274,10 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
 
                     break;
                 }
+                case ACTION_STOP_VPN: {
+                    mBtnVPN.setChecked(false);
+                    break;
+                }
             }
         }
     };
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 294259a5..7bf6ade0 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java
@@ -1913,13 +1913,22 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb
     @Override
     public IBinder onBind(Intent intent) {
         Log.e( TAG, "onBind" );
-        handleIntent( intent );
-        return null;
+        handleIntent(intent);
+        return super.onBind(intent); // invoking super class will call onRevoke() when appropriate
+    }
+
+    // system calls this method when VPN disconnects (either by the user or another VPN app)
+    @Override
+    public void onRevoke() {
+        Prefs.putUseVpn(false);
+        mVpnManager.handleIntent(new Builder(), new Intent(ACTION_STOP_VPN));
+        // tell UI, if it's open, to update immediately (don't wait for onResume() in Activity...)
+        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().toString() );
+            Log.e( TAG, intent.getAction());
         }
     }
 





More information about the tor-commits mailing list