From 990c4fa151adf9f91dc729c21b44edb0f0b55ccf Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 19 Jul 2019 18:46:12 +0200 Subject: add simple UI to enable/disable PT usage --- .../leap/bitmaskclient/DrawerSettingsAdapter.java | 1 + .../main/java/se/leap/bitmaskclient/Provider.java | 5 +++ .../drawer/NavigationDrawerFragment.java | 37 ++++++++++++++++++---- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 6 +++- 4 files changed, 41 insertions(+), 8 deletions(-) (limited to 'app/src/main/java/se/leap') diff --git a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java b/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java index 89aeb4be..e2b21db9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java +++ b/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java @@ -45,6 +45,7 @@ public class DrawerSettingsAdapter extends BaseAdapter { public static final int BATTERY_SAVER = 3; public static final int ALWAYS_ON = 4; public static final int DONATE = 5; + public static final int PLUGGABLE_TRANSPORTS = 6; //view types public final static int VIEW_SIMPLE_TEXT = 0; diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index c81f5739..561453af 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -119,6 +119,11 @@ public final class Provider implements Parcelable { hasPrivateKey(); } + //TODO: implement me! + public boolean supportsPluggableTransports() { + return true; + } + public void setMainUrl(URL url) { mainUrl.setUrl(url); } diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index 640c143a..8c022b98 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -55,10 +55,12 @@ import se.leap.bitmaskclient.FragmentManagerEnhanced; import se.leap.bitmaskclient.MainActivity; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.ProviderListActivity; +import se.leap.bitmaskclient.ProviderObservable; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.fragments.AboutFragment; import se.leap.bitmaskclient.fragments.AlwaysOnDialog; import se.leap.bitmaskclient.fragments.LogFragment; +import se.leap.bitmaskclient.utils.PreferenceHelper; import static android.content.Context.MODE_PRIVATE; import static se.leap.bitmaskclient.BitmaskApp.getRefWatcher; @@ -74,6 +76,7 @@ import static se.leap.bitmaskclient.DrawerSettingsAdapter.DONATE; import static se.leap.bitmaskclient.DrawerSettingsAdapter.DrawerSettingsItem.getSimpleTextInstance; import static se.leap.bitmaskclient.DrawerSettingsAdapter.DrawerSettingsItem.getSwitchInstance; import static se.leap.bitmaskclient.DrawerSettingsAdapter.LOG; +import static se.leap.bitmaskclient.DrawerSettingsAdapter.PLUGGABLE_TRANSPORTS; import static se.leap.bitmaskclient.DrawerSettingsAdapter.SWITCH_PROVIDER; import static se.leap.bitmaskclient.R.string.about_fragment_title; import static se.leap.bitmaskclient.R.string.donate_title; @@ -84,7 +87,9 @@ import static se.leap.bitmaskclient.utils.PreferenceHelper.getProviderName; import static se.leap.bitmaskclient.utils.PreferenceHelper.getSaveBattery; import static se.leap.bitmaskclient.utils.PreferenceHelper.getSavedProviderFromSharedPreferences; import static se.leap.bitmaskclient.utils.PreferenceHelper.getShowAlwaysOnDialog; +import static se.leap.bitmaskclient.utils.PreferenceHelper.getUsePluggableTransports; import static se.leap.bitmaskclient.utils.PreferenceHelper.saveBattery; +import static se.leap.bitmaskclient.utils.PreferenceHelper.usePluggableTransports; /** * Fragment used for managing interactions for and presentation of a navigation drawer. @@ -254,14 +259,26 @@ public class NavigationDrawerFragment extends Fragment { private void setupSettingsListAdapter() { settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater()); - if (getContext() != null) { + if (getContext() == null) { + return; + } + + Provider currentProvider = ProviderObservable.getInstance().getCurrentProvider(); + if (currentProvider.supportsPluggableTransports()) { settingsListAdapter.addItem(getSwitchInstance(getContext(), - getString(R.string.save_battery), - R.drawable.ic_battery_36, - getSaveBattery(getContext()), - BATTERY_SAVER, - (buttonView, newStateIsChecked) -> onSwitchItemSelected(BATTERY_SAVER, newStateIsChecked))); + getString(R.string.nav_drawer_obfuscated_connection), + R.drawable.ic_bridge_36, + getUsePluggableTransports(getContext()), + PLUGGABLE_TRANSPORTS, + (buttonView, newStateIsChecked) -> onSwitchItemSelected(PLUGGABLE_TRANSPORTS, newStateIsChecked))); } + + settingsListAdapter.addItem(getSwitchInstance(getContext(), + getString(R.string.save_battery), + R.drawable.ic_battery_36, + getSaveBattery(getContext()), + BATTERY_SAVER, + (buttonView, newStateIsChecked) -> onSwitchItemSelected(BATTERY_SAVER, newStateIsChecked))); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(R.string.always_on_vpn), R.drawable.ic_always_on_36, ALWAYS_ON)); } @@ -440,10 +457,16 @@ public class NavigationDrawerFragment extends Fragment { if (newStateIsChecked) { showExperimentalFeatureAlert(); } else { - saveBattery(this.getContext(), false); + saveBattery(getContext(), false); disableSwitch(BATTERY_SAVER); } break; + case PLUGGABLE_TRANSPORTS: + if (getUsePluggableTransports(getContext()) == newStateIsChecked) { + //initial ui setup, ignore + return; + } + usePluggableTransports(getContext(), newStateIsChecked); default: break; } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 3855fa12..9431ef61 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -48,12 +48,14 @@ import de.blinkt.openvpn.core.ConnectionStatus; import de.blinkt.openvpn.core.IOpenVPNServiceInternal; import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.connection.Connection; import se.leap.bitmaskclient.OnBootReceiver; import se.leap.bitmaskclient.R; import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_OK; import static android.content.Intent.CATEGORY_DEFAULT; +import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN; import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT; import static se.leap.bitmaskclient.Constants.BROADCAST_GATEWAY_SETUP_OBSERVER_EVENT; @@ -76,6 +78,7 @@ import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.MainActivityErrorDialog.DOWNLOAD_ERRORS.ERROR_INVALID_VPN_CERTIFICATE; import static se.leap.bitmaskclient.R.string.vpn_certificate_is_invalid; import static se.leap.bitmaskclient.utils.ConfigHelper.ensureNotOnMainThread; +import static se.leap.bitmaskclient.utils.PreferenceHelper.getUsePluggableTransports; /** * EIP is the abstract base class for interacting with and managing the Encrypted @@ -244,8 +247,9 @@ public final class EIP extends JobIntentService implements Observer { */ private boolean launchActiveGateway(Gateway gateway, int nClosestGateway) { VpnProfile profile; + Connection.TransportType transportType = getUsePluggableTransports(this) ? OBFS4 : OPENVPN; if (gateway == null || - (profile = gateway.getProfile(OPENVPN)) == null) { + (profile = gateway.getProfile(transportType)) == null) { return false; } -- cgit v1.2.3