improved clean-up, shutdown of Tun2Socks and VPN service
This commit is contained in:
parent
b1d46e2291
commit
39ce7f1b22
|
@ -330,4 +330,6 @@
|
||||||
<string name="apps_mode">Apps Mode</string>
|
<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="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>
|
</resources>
|
||||||
|
|
|
@ -245,8 +245,8 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mBtnBrowser.setEnabled(false);
|
mBtnBrowser.setEnabled(false);
|
||||||
|
|
||||||
mBtnVPN = (ToggleButton)findViewById(R.id.btnVPN);
|
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[]{"bridges@torproject.org"});
|
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"bridges@torproject.org"});
|
||||||
intent.putExtra(Intent.EXTRA_SUBJECT, "Tor Bridge Request");
|
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)
|
private void enableBridges (boolean enable)
|
||||||
|
@ -940,6 +940,8 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
|
||||||
|
mPrefs.edit().putBoolean("pref_vpn", true).commit();
|
||||||
|
|
||||||
startVpnService();
|
startVpnService();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -997,6 +999,15 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.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 ()
|
mHandler.postDelayed(new Runnable ()
|
||||||
{
|
{
|
||||||
public void run ()
|
public void run ()
|
||||||
|
|
|
@ -20,19 +20,18 @@ import java.net.InetAddress;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.torproject.android.service.TorServiceConstants;
|
import org.torproject.android.service.TorServiceConstants;
|
||||||
|
import org.torproject.android.service.TorServiceUtils;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.net.VpnService;
|
import android.net.VpnService;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -124,20 +123,31 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
|
||||||
|
|
||||||
private void stopVPN ()
|
private void stopVPN ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Tun2Socks.Stop();
|
||||||
|
|
||||||
if (mSocksProxyServer != null){
|
if (mSocksProxyServer != null){
|
||||||
mSocksProxyServer.stop();
|
mSocksProxyServer.stop();
|
||||||
mSocksProxyServer = null;
|
mSocksProxyServer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (mHttpProxyServer != null)
|
|
||||||
{
|
|
||||||
mHttpProxyServer.closeSocket();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (mInterface != null){
|
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
|
// (i.e., Farsi and Arabic).^M
|
||||||
Locale.setDefault(new Locale("en"));
|
Locale.setDefault(new Locale("en"));
|
||||||
|
|
||||||
boolean isLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
|
||||||
|
|
||||||
|
|
||||||
//String localhost = InetAddress.getLocalHost().getHostAddress();
|
//String localhost = InetAddress.getLocalHost().getHostAddress();
|
||||||
|
|
||||||
String vpnName = "OrbotVPN";
|
String vpnName = "OrbotVPN";
|
||||||
|
@ -190,15 +197,16 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
|
||||||
builder.addRoute("0.0.0.0",0);
|
builder.addRoute("0.0.0.0",0);
|
||||||
// builder.addDnsServer("8.8.8.8");
|
// builder.addDnsServer("8.8.8.8");
|
||||||
|
|
||||||
if (isLollipop)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
{
|
||||||
doLollipopAppRouting(builder);
|
doLollipopAppRouting(builder);
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new interface using the builder and save the parameters.
|
// Create a new interface using the builder and save the parameters.
|
||||||
mInterface = builder.setSession(mSessionName)
|
mInterface = builder.setSession(mSessionName)
|
||||||
.setConfigureIntent(mConfigureIntent)
|
.setConfigureIntent(mConfigureIntent)
|
||||||
.establish();
|
.establish();
|
||||||
|
|
||||||
|
|
||||||
Tun2Socks.Start(mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , localDNS , true);
|
Tun2Socks.Start(mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , localDNS , true);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -225,27 +233,10 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
|
||||||
@Override
|
@Override
|
||||||
public void onRevoke() {
|
public void onRevoke() {
|
||||||
|
|
||||||
try
|
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
|
||||||
{
|
prefs.edit().putBoolean("pref_vpn", false).commit();
|
||||||
Log.d(TAG,"closing interface, destroying VPN interface");
|
|
||||||
|
stopVPN();
|
||||||
//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);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onRevoke();
|
super.onRevoke();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue