commit 1b6126e3d0b5941b98cbd6db866b6e68cafb2118 Author: Nathan Freitas nathan@freitas.net Date: Thu Jun 25 10:48:50 2015 -0400
Enable support for app selection to work with VPN mode on Lollipop+ For now we will re-use/overload the app selection transproxy UI in Settings --- res/xml/preferences.xml | 3 -- src/org/torproject/android/OrbotMainActivity.java | 2 +- .../android/settings/SettingsPreferences.java | 31 +++++++++++++++----- .../torproject/android/vpn/OrbotVpnService.java | 31 +++++++++++++++++--- 4 files changed, 51 insertions(+), 16 deletions(-)
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index e1e1828..f34548e 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -50,7 +50,6 @@ android:defaultValue="false" android:key="pref_transparent" android:title="@string/pref_trans_proxy_title" android:summary="@string/pref_trans_proxy_summary" -android:dependency="has_root" android:enabled="true"/>
<CheckBoxPreference @@ -58,7 +57,6 @@ android:defaultValue="false" android:key="pref_transparent_all" android:summary="@string/pref_transparent_all_summary" android:enabled="true" -android:dependency="has_root" android:title="@string/pref_transparent_all_title"/>
<Preference @@ -66,7 +64,6 @@ android:defaultValue="" android:key="pref_transparent_app_list" android:title="@string/pref_select_apps" android:summary="@string/pref_select_apps_summary" -android:dependency="has_root" android:enabled="true"/>
<CheckBoxPreference diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java index d4ed148..7ff6068 100644 --- a/src/org/torproject/android/OrbotMainActivity.java +++ b/src/org/torproject/android/OrbotMainActivity.java @@ -965,7 +965,7 @@ public class OrbotMainActivity extends Activity
}) - .setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener () + .setNegativeButton(R.string.btn_cancel, new Dialog.OnClickListener () {
@Override diff --git a/src/org/torproject/android/settings/SettingsPreferences.java b/src/org/torproject/android/settings/SettingsPreferences.java index 5c02d2b..d7a976f 100644 --- a/src/org/torproject/android/settings/SettingsPreferences.java +++ b/src/org/torproject/android/settings/SettingsPreferences.java @@ -6,6 +6,7 @@ package org.torproject.android.settings; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; @@ -21,6 +22,7 @@ import info.guardianproject.util.Languages; import org.sufficientlysecure.rootcommands.RootCommands; import org.sufficientlysecure.rootcommands.Shell; import org.torproject.android.OrbotApp; +import org.torproject.android.Prefs; import org.torproject.android.R; import org.torproject.android.service.TorServiceUtils;
@@ -97,21 +99,33 @@ public class SettingsPreferences
});
+ prefTransProxyApps = findPreference("pref_transparent_app_list"); prefTransProxyApps.setOnPreferenceClickListener(this); - prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() - && (!prefcBTransProxyAll.isChecked())); - prefCBTransProxy.setOnPreferenceClickListener(this); prefcBTransProxyAll.setOnPreferenceClickListener(this); - prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked()); - prefHiddenServices = (CheckBoxPreference) findPreference("pref_hs_enable"); prefHiddenServices.setOnPreferenceClickListener(this); - prefHiddenServicesPorts = (EditTextPreference) findPreference("pref_hs_ports"); - prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked()); prefHiddenServicesHostname = (EditTextPreference) findPreference("pref_hs_hostname"); + + + prefCBTransProxy.setEnabled(prefRequestRoot.isChecked()); + + prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked()); + + if (prefCBTransProxy.isChecked()) + prefTransProxyApps.setEnabled((!prefcBTransProxyAll.isChecked())); + + prefHiddenServicesPorts = (EditTextPreference) findPreference("pref_hs_ports"); prefHiddenServicesHostname.setEnabled(prefHiddenServices.isChecked()); + prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked()); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + { + prefTransProxyApps.setEnabled(true); + } + + }
public boolean onPreferenceClick(Preference preference) { @@ -134,7 +148,8 @@ public class SettingsPreferences shell.close(); prefRequestRoot.setChecked(true); - + prefCBTransProxy.setEnabled(true); + } catch (Exception e) { diff --git a/src/org/torproject/android/vpn/OrbotVpnService.java b/src/org/torproject/android/vpn/OrbotVpnService.java index e202078..2fe3daa 100644 --- a/src/org/torproject/android/vpn/OrbotVpnService.java +++ b/src/org/torproject/android/vpn/OrbotVpnService.java @@ -17,10 +17,13 @@ package org.torproject.android.vpn;
import java.net.InetAddress; +import java.util.ArrayList; import java.util.Locale;
import org.torproject.android.service.TorServiceConstants; import org.torproject.android.service.TorServiceUtils; +import org.torproject.android.settings.AppManager; +import org.torproject.android.settings.TorifiedApp;
import android.annotation.TargetApi; import android.app.PendingIntent; @@ -178,9 +181,6 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
private void stopVPN () { - - Tun2Socks.Stop(); - //stopSocksBypass ();
if (mInterface != null){ @@ -202,8 +202,14 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { } }
+ Tun2Socks.Stop(); + mThreadVPN = null;
+ + // Tun2Socks.Stop(); + + }
@Override @@ -293,7 +299,24 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void doLollipopAppRouting (Builder builder) throws NameNotFoundException { - builder.addDisallowedApplication("org.torproject.android"); + + ArrayList<TorifiedApp> apps = AppManager.getApps(this, TorServiceUtils.getSharedPrefs(getApplicationContext())); + + boolean appAllowed = false; + + for (TorifiedApp app : apps) + { + if (app.isTorified()) + { + builder.addAllowedApplication(app.getUsername()); + appAllowed = true; + } + + } + + if (!appAllowed) + builder.addDisallowedApplication(getPackageName()); + }
@Override
tor-commits@lists.torproject.org