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
This commit is contained in:
Nathan Freitas 2015-06-25 10:48:50 -04:00
parent bf8113cd19
commit 1b6126e3d0
4 changed files with 51 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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,6 +148,7 @@ public class SettingsPreferences
shell.close();
prefRequestRoot.setChecked(true);
prefCBTransProxy.setEnabled(true);
}
catch (Exception e)

View File

@ -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