commit 39ce7f1b22153a3a7058110a0ee6cb6ace287a53
Author: Nathan Freitas <[email protected]>
Date:   Fri Apr 3 00:20:30 2015 -0400

    improved clean-up, shutdown of Tun2Socks and VPN service
---
 res/values/strings.xml                             |    2 +
 src/org/torproject/android/OrbotMainActivity.java  |   15 ++++-
 .../torproject/android/vpn/OrbotVpnService.java    |   65 +++++++++-----------
 3 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/res/values/strings.xml b/res/values/strings.xml
index a93126c..92e1e35 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -330,4 +330,6 @@
   <string name="apps_mode">Apps Mode</string>
   
   <string 
name="you_can_enable_all_apps_on_your_device_to_run_through_the_tor_network_using_the_vpn_feature_of_android_">You
 can enable all apps on your device to run through the Tor network using the 
VPN feature of Android.\n\n*WARNING* This is a new, experimental feature and in 
some cases may not start automatically, or may stop. It should NOT be used for 
anonymity, and ONLY used for getting through firewalls and filters.</string>
+  
+  <string name="send_email">Send Email</string>
 </resources>
diff --git a/src/org/torproject/android/OrbotMainActivity.java 
b/src/org/torproject/android/OrbotMainActivity.java
index 088f7fb..be05d69 100644
--- a/src/org/torproject/android/OrbotMainActivity.java
+++ b/src/org/torproject/android/OrbotMainActivity.java
@@ -245,8 +245,8 @@ public class OrbotMainActivity extends Activity implements 
OrbotConstants, OnLon
                                
                        }
 
-                       
                });
+               
                mBtnBrowser.setEnabled(false);
                
                mBtnVPN = (ToggleButton)findViewById(R.id.btnVPN);
@@ -910,7 +910,7 @@ public class OrbotMainActivity extends Activity implements 
OrbotConstants, OnLon
                intent.putExtra(Intent.EXTRA_EMAIL  , new 
String[]{"[email protected]"});
        intent.putExtra(Intent.EXTRA_SUBJECT, "Tor Bridge Request");
 
-       startActivity(Intent.createChooser(intent, "Send Email"));
+       startActivity(Intent.createChooser(intent, 
getString(R.string.send_email)));
     }
     
     private void enableBridges (boolean enable)
@@ -940,6 +940,8 @@ public class OrbotMainActivity extends Activity implements 
OrbotConstants, OnLon
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                                
+                               mPrefs.edit().putBoolean("pref_vpn", 
true).commit();
+                       
                                startVpnService();
                                
                        }
@@ -997,6 +999,15 @@ public class OrbotMainActivity extends Activity implements 
OrbotConstants, OnLon
     protected void onResume() {
         super.onResume();
 
+        if (mPrefs != null)
+        {
+               boolean useVPN = mPrefs.getBoolean("pref_vpn", false);
+                       mBtnVPN.setChecked(useVPN);
+                       
+                       boolean useBridges = 
mPrefs.getBoolean("pref_bridges_enabled", false);
+                       mBtnBridges.setChecked(useBridges);
+        }
+        
         mHandler.postDelayed(new Runnable ()
         {
             public void run ()
diff --git a/src/org/torproject/android/vpn/OrbotVpnService.java 
b/src/org/torproject/android/vpn/OrbotVpnService.java
index ec841cb..2127562 100644
--- a/src/org/torproject/android/vpn/OrbotVpnService.java
+++ b/src/org/torproject/android/vpn/OrbotVpnService.java
@@ -20,19 +20,18 @@ import java.net.InetAddress;
 import java.util.Locale;
 
 import org.torproject.android.service.TorServiceConstants;
+import org.torproject.android.service.TorServiceUtils;
 
 import android.annotation.TargetApi;
 import android.app.PendingIntent;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.net.VpnService;
 import android.os.Build;
 import android.os.Handler;
-import android.os.IBinder;
 import android.os.Message;
-import android.os.Parcel;
 import android.os.ParcelFileDescriptor;
-import android.os.RemoteException;
 import android.util.Log;
 import android.widget.Toast;
 
@@ -124,20 +123,31 @@ public class OrbotVpnService extends VpnService 
implements Handler.Callback {
     
     private void stopVPN ()
     {
+
+        Tun2Socks.Stop();
+        
         if (mSocksProxyServer != null){
             mSocksProxyServer.stop();
             mSocksProxyServer = null;
         }
         
-        /*
-        if (mHttpProxyServer != null)
-        {
-               mHttpProxyServer.closeSocket();
-        }*/
-        
         if (mInterface != null){
-            onRevoke();
-            
+            try
+            {
+               Log.d(TAG,"closing interface, destroying VPN interface");
+                
+                       mInterface.close();
+                       mInterface = null;
+               
+            }
+            catch (Exception e)
+            {
+                Log.d(TAG,"error stopping tun2socks",e);
+            }
+            catch (Error e)
+            {
+                Log.d(TAG,"error stopping tun2socks",e);
+            }   
         }
     }
 
@@ -169,9 +179,6 @@ public class OrbotVpnService extends VpnService implements 
Handler.Callback {
                                    // (i.e., Farsi and Arabic).^M
                                        Locale.setDefault(new Locale("en"));
                                        
-                                       boolean isLollipop = 
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
-                                       
-                                       
                                        //String localhost = 
InetAddress.getLocalHost().getHostAddress();
                                        
                                        String vpnName = "OrbotVPN";
@@ -190,15 +197,16 @@ public class OrbotVpnService extends VpnService 
implements Handler.Callback {
                                        builder.addRoute("0.0.0.0",0);   
                                      //  builder.addDnsServer("8.8.8.8");
                                        
-                                       if (isLollipop)
+                                       if (Build.VERSION.SDK_INT >= 
Build.VERSION_CODES.LOLLIPOP)
+                                       {
                                                doLollipopAppRouting(builder);
+                                       }
                                        
                                         // Create a new interface using the 
builder and save the parameters.
                                        mInterface = 
builder.setSession(mSessionName)
                                                
.setConfigureIntent(mConfigureIntent)
                                                .establish();
                                                    
-                                       
                                        Tun2Socks.Start(mInterface, VPN_MTU, 
virtualIP, virtualNetMask, localSocks , localDNS , true);
                                }
                                catch (Exception e)
@@ -225,27 +233,10 @@ public class OrbotVpnService extends VpnService 
implements Handler.Callback {
     @Override
     public void onRevoke() {
     
-        try
-        {
-               Log.d(TAG,"closing interface, destroying VPN interface");
-            
-               //Tun2Socks.Stop();
-               
-               if (mInterface != null)
-            {
-                       mInterface.close();
-                       mInterface = null;
-            }
-               
-        }
-        catch (Exception e)
-        {
-            Log.d(TAG,"error stopping tun2socks",e);
-        }
-        catch (Error e)
-        {
-            Log.d(TAG,"error stopping tun2socks",e);
-        }
+       SharedPreferences prefs = 
TorServiceUtils.getSharedPrefs(getApplicationContext()); 
+        prefs.edit().putBoolean("pref_vpn", false).commit();
+        
+       stopVPN();
 
         super.onRevoke();
     }



_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to