diff options
author | Norbel AMBANUMBEN <aanorbel@gmail.com> | 2024-10-21 19:26:39 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2024-11-28 22:53:30 +0100 |
commit | 7aeea7e4a157f6c54bf469fda3307f781bd6e188 (patch) | |
tree | 8f0ff17e425d25f05735f1a8443eab6aadec6d75 | |
parent | fe8fc4da464ab0daf2f36513222099075d3635f5 (diff) |
chore: update settings logic
4 files changed, 47 insertions, 57 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java index ed64ab00..9351756d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/CensorshipCircumventionFragment.java @@ -6,7 +6,6 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseObfs4Kcp; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUsePortHopping; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseSnowflake; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.hasSnowflakePrefs; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setObfuscationPinningKCP; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfs4; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfs4Kcp; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUsePortHopping; @@ -80,7 +79,7 @@ public class CensorshipCircumventionFragment extends Fragment { snowflakeRadioButton.setChecked(hasSnowflakePrefs() && getUseSnowflake()); binding.discoveryRadioGroup.addView(snowflakeRadioButton); - if (ProviderObservable.getInstance().getCurrentProvider().hasIntroducer()){ + if (ProviderObservable.getInstance().getCurrentProvider().hasIntroducer()) { RadioButton inviteProxyRadioButton = new RadioButton(binding.getRoot().getContext()); inviteProxyRadioButton.setText(getText(R.string.invite_proxy)); inviteProxyRadioButton.setId(DISCOVERY_INVITE_PROXY); @@ -106,13 +105,16 @@ public class CensorshipCircumventionFragment extends Fragment { noneRadioButton.setChecked(!getUseObfs4() && !getObfuscationPinningKCP()); noneRadioButton.setId(TUNNELING_NONE); binding.tunnelingRadioGroup.addView(noneRadioButton); - if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()){ + + if (ProviderObservable.getInstance().getCurrentProvider().supportsObfs4()) { RadioButton obfs4RadioButton = new RadioButton(binding.getRoot().getContext()); obfs4RadioButton.setText(getText(R.string.tunnelling_obfs4)); obfs4RadioButton.setId(TUNNELING_OBFS4); obfs4RadioButton.setChecked(getUseObfs4()); binding.tunnelingRadioGroup.addView(obfs4RadioButton); + } + if (ProviderObservable.getInstance().getCurrentProvider().supportsObfs4Kcp()) { RadioButton obfs4KcpRadioButton = new RadioButton(binding.getRoot().getContext()); obfs4KcpRadioButton.setText(getText(R.string.tunnelling_obfs4_kcp)); obfs4KcpRadioButton.setId(TUNNELING_OBFS4_KCP); @@ -136,6 +138,7 @@ public class CensorshipCircumventionFragment extends Fragment { } private void initPortHopping() { + binding.portHoppingSwitch.setVisibility(ProviderObservable.getInstance().getCurrentProvider().supportsObfs4Hop() ? View.VISIBLE : View.GONE); binding.portHoppingSwitch.findViewById(R.id.material_icon).setVisibility(View.GONE); binding.portHoppingSwitch.setChecked(getUsePortHopping()); binding.portHoppingSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java index 52b2cc5e..d0fa3aa4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java @@ -11,14 +11,10 @@ import static se.leap.bitmaskclient.base.models.Constants.USE_OBFUSCATION_PINNIN import static se.leap.bitmaskclient.base.utils.ConfigHelper.isCalyxOSWithTetheringSupport; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.allowExperimentalTransports; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getExcludedApps; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getObfuscationPinningKCP; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferUDP; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getShowAlwaysOnDialog; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseObfs4; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUsePortHopping; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseSnowflake; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.hasSnowflakePrefs; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.preferUDP; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setAllowExperimentalTransports; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfs4; @@ -27,6 +23,7 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfuscatio import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUsePortHopping; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useObfuscationPinning; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useSnowflake; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.usesManualBridges; import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle; @@ -84,7 +81,6 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh initAlwaysOnVpnEntry(view); initExcludeAppsEntry(view); initPreferUDPEntry(view); - initUseBridgesEntry(view); initAutomaticCircumventionEntry(view); initManualCircumventionEntry(view); initFirewallEntry(view); @@ -98,22 +94,35 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh private void initAutomaticCircumventionEntry(View rootView) { IconSwitchEntry automaticCircumvention = rootView.findViewById(R.id.bridge_automatic_switch); - automaticCircumvention.setChecked(!usesManualBridges()); - automaticCircumvention.setOnCheckedChangeListener((buttonView, isChecked) -> { - if (!buttonView.isPressed()) { - return; - } - if (isChecked){ - useBridges(false); - setUseObfs4Kcp(false); - setUseObfs4(false); - setUsePortHopping(false); - } - }); + if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()) { + automaticCircumvention.setVisibility(VISIBLE); + + automaticCircumvention.setChecked(getUseBridges() && !usesManualBridges()); + automaticCircumvention.setOnCheckedChangeListener((buttonView, isChecked) -> { + if (!buttonView.isPressed()) { + return; + } + + if (isChecked) { + useSnowflake(false); + setUseObfs4Kcp(false); + setUseObfs4(false); + setUsePortHopping(false); + } + useBridges(isChecked); + if (VpnStatus.isVPNActive()) { + EipCommand.startVPN(getContext(), false); + Toast.makeText(getContext(), R.string.reconnecting, Toast.LENGTH_LONG).show(); + } + }); + } else { + automaticCircumvention.setVisibility(GONE); + } } private void initManualCircumventionEntry(View rootView) { IconSwitchEntry manualConfiguration = rootView.findViewById(R.id.bridge_manual_switch); + manualConfiguration.setVisibility(ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports() ? VISIBLE : GONE); manualConfiguration.setChecked(usesManualBridges()); manualConfiguration.setOnCheckedChangeListener((buttonView, isChecked) -> { if (!buttonView.isPressed()) { @@ -136,32 +145,6 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh super.onDestroy(); } - private void initUseBridgesEntry(View rootView) { - IconSwitchEntry useBridges = rootView.findViewById(R.id.bridges_switch); - if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()) { - useBridges.setVisibility(VISIBLE); - useBridges.setChecked(getUseBridges()); - useBridges.setOnCheckedChangeListener((buttonView, isChecked) -> { - if (!buttonView.isPressed()) { - return; - } - useBridges(isChecked); - if (VpnStatus.isVPNActive()) { - EipCommand.startVPN(getContext(), false); - Toast.makeText(getContext(), R.string.reconnecting, Toast.LENGTH_LONG).show(); - } - }); - //We check the UI state of the useUdpEntry here as well, in order to avoid a situation - //where both entries are disabled, because both preferences are enabled. - //bridges can be enabled not only from here but also from error handling - boolean useUDP = getPreferUDP() && useUdpEntry.isEnabled(); - useBridges.setEnabled(!useUDP); - useBridges.setSubtitle(getString(useUDP ? R.string.disabled_while_udp_on : R.string.nav_drawer_subtitle_obfuscated_connection)); - } else { - useBridges.setVisibility(GONE); - } - } - private void initAlwaysOnVpnEntry(View rootView) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { IconTextEntry alwaysOnVpn = rootView.findViewById(R.id.always_on_vpn); @@ -381,6 +364,7 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh if (key.equals(USE_BRIDGES) || key.equals(PREFER_UDP)) { //initUseBridgesEntry(rootView); initPreferUDPEntry(rootView); + initManualCircumventionEntry(rootView); } else if (key.equals(USE_IPv6_FIREWALL)) { initFirewallEntry(getView()); } else if (key.equals(GATEWAY_PINNING)) { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java index 487134d4..ed0a9a15 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java @@ -201,6 +201,19 @@ public final class Provider implements Parcelable { return supportsTransports(new Pair[]{new Pair<>(OBFS4, KCP), new Pair<>(OBFS4_HOP, TCP), new Pair<>(OBFS4_HOP, KCP)}); } + + public boolean supportsObfs4() { + return supportsTransports(new Pair[]{new Pair<>(OBFS4, TCP)}); + } + + public boolean supportsObfs4Kcp() { + return supportsTransports(new Pair[]{new Pair<>(OBFS4, KCP)}); + } + + public boolean supportsObfs4Hop() { + return supportsTransports(new Pair[]{new Pair<>(OBFS4_HOP, KCP),new Pair<>(OBFS4_HOP, TCP)}); + } + private boolean supportsTransports(Pair<TransportType, TransportProtocol>[] transportTypes) { try { JSONArray gatewayJsons = eipServiceJson.getJSONArray(GATEWAYS); diff --git a/app/src/main/res/layout/f_settings.xml b/app/src/main/res/layout/f_settings.xml index 70b43dbb..e45f0bac 100644 --- a/app/src/main/res/layout/f_settings.xml +++ b/app/src/main/res/layout/f_settings.xml @@ -71,23 +71,13 @@ app:icon="@drawable/bridge_manual" app:singleLine="false" /> - <se.leap.bitmaskclient.base.views.IconSwitchEntry - android:id="@+id/bridges_switch" - android:layout_width="match_parent" - android:layout_height="wrap_content" - app:text="@string/nav_drawer_obfuscated_connection" - app:subtitle="@string/nav_drawer_subtitle_obfuscated_connection" - app:icon="@drawable/ic_bridge_36" - app:singleLine="false" /> - <androidx.appcompat.widget.AppCompatTextView android:id="@+id/experimental_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.AppCompat.Title" android:text="@string/experimental_features" - android:paddingTop="@dimen/activity_margin" - /> + android:paddingTop="@dimen/activity_margin" /> <se.leap.bitmaskclient.base.views.IconSwitchEntry |