diff options
Diffstat (limited to 'app/src')
4 files changed, 94 insertions, 25 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 cecf98da..269286cd 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 @@ -1,7 +1,13 @@ package se.leap.bitmaskclient.base.fragments; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getObfuscationPinningKCP; +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.setObfuscationPinningKCP; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfs4; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUsePortHopping; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useSnowflake; import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle; @@ -16,6 +22,7 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.base.models.ProviderObservable; import se.leap.bitmaskclient.databinding.FCensorshipCircumventionBinding; public class CensorshipCircumventionFragment extends Fragment { @@ -62,22 +69,24 @@ public class CensorshipCircumventionFragment extends Fragment { RadioButton noneRadioButton = new RadioButton(binding.getRoot().getContext()); noneRadioButton.setText(getText(R.string.none)); noneRadioButton.setId(DISCOVERY_NONE); + noneRadioButton.setChecked(!(hasSnowflakePrefs() && getUseSnowflake()) && !ProviderObservable.getInstance().getCurrentProvider().hasIntroducer()); binding.discoveryRadioGroup.addView(noneRadioButton); if (hasSnowflakePrefs()) { - RadioButton snowflakeRadioButton = new RadioButton(binding.getRoot().getContext()); snowflakeRadioButton.setText(getText(R.string.snowflake)); snowflakeRadioButton.setId(DISCOVERY_SNOWFLAKE); snowflakeRadioButton.setChecked(hasSnowflakePrefs() && getUseSnowflake()); binding.discoveryRadioGroup.addView(snowflakeRadioButton); - } - RadioButton inviteProxyRadioButton = new RadioButton(binding.getRoot().getContext()); - inviteProxyRadioButton.setText(getText(R.string.invite_proxy)); - inviteProxyRadioButton.setId(DISCOVERY_INVITE_PROXY); - binding.discoveryRadioGroup.addView(inviteProxyRadioButton); + if (ProviderObservable.getInstance().getCurrentProvider().hasIntroducer()){ + RadioButton inviteProxyRadioButton = new RadioButton(binding.getRoot().getContext()); + inviteProxyRadioButton.setText(getText(R.string.invite_proxy)); + inviteProxyRadioButton.setId(DISCOVERY_INVITE_PROXY); + inviteProxyRadioButton.setChecked(true); + binding.discoveryRadioGroup.addView(inviteProxyRadioButton); + } binding.discoveryRadioGroup.setOnCheckedChangeListener((group, checkedId) -> { if (checkedId == DISCOVERY_NONE) { @@ -94,26 +103,33 @@ public class CensorshipCircumventionFragment extends Fragment { private void initTunneling() { RadioButton noneRadioButton = new RadioButton(binding.getRoot().getContext()); noneRadioButton.setText(getText(R.string.none)); + noneRadioButton.setChecked(!getUseObfs4() && !getObfuscationPinningKCP()); noneRadioButton.setId(TUNNELING_NONE); binding.tunnelingRadioGroup.addView(noneRadioButton); - - RadioButton obfs4RadioButton = new RadioButton(binding.getRoot().getContext()); - obfs4RadioButton.setText(getText(R.string.tunnelling_obfs4)); - obfs4RadioButton.setId(TUNNELING_OBFS4); - binding.tunnelingRadioGroup.addView(obfs4RadioButton); - - RadioButton obfs4KcpRadioButton = new RadioButton(binding.getRoot().getContext()); - obfs4KcpRadioButton.setText(getText(R.string.tunnelling_obfs4_kcp)); - obfs4KcpRadioButton.setId(TUNNELING_OBFS4_KCP); - binding.tunnelingRadioGroup.addView(obfs4KcpRadioButton); + if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()){ + 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); + + RadioButton obfs4KcpRadioButton = new RadioButton(binding.getRoot().getContext()); + obfs4KcpRadioButton.setText(getText(R.string.tunnelling_obfs4_kcp)); + obfs4KcpRadioButton.setId(TUNNELING_OBFS4_KCP); + obfs4KcpRadioButton.setChecked(getObfuscationPinningKCP()); + binding.tunnelingRadioGroup.addView(obfs4KcpRadioButton); + } binding.tunnelingRadioGroup.setOnCheckedChangeListener((group, checkedId) -> { if (checkedId == TUNNELING_NONE) { - // TODO set up none + setObfuscationPinningKCP(false); + setUseObfs4(false); } else if (checkedId == TUNNELING_OBFS4) { - // TODO set up obfs4 + setObfuscationPinningKCP(false); + setUseObfs4(true); } else if (checkedId == TUNNELING_OBFS4_KCP) { - // TODO set up obfs4 + kcp + setObfuscationPinningKCP(true); + setUseObfs4(false); } }); @@ -121,8 +137,12 @@ public class CensorshipCircumventionFragment extends Fragment { private void initPortHopping() { binding.portHoppingSwitch.findViewById(R.id.material_icon).setVisibility(View.GONE); + binding.portHoppingSwitch.setChecked(getUsePortHopping()); binding.portHoppingSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - // TODO set up port hopping + if (!buttonView.isPressed()) { + return; + } + setUsePortHopping(isChecked); }); } }
\ No newline at end of file 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 4aed0643..1a63e145 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,12 +11,19 @@ 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; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setUseObfuscationPinning; +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.ViewHelper.setActionBarSubtitle; @@ -89,18 +96,40 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh private void initAutomaticCircumventionEntry(View rootView) { IconSwitchEntry automaticCircumvention = rootView.findViewById(R.id.bridge_automatic_switch); + automaticCircumvention.setChecked(!hasManualCircumventionConfig()); automaticCircumvention.setOnCheckedChangeListener((buttonView, isChecked) -> { - + if (!buttonView.isPressed()) { + return; + } + if (isChecked){ + useBridges(false); + setUseObfuscationPinning(false); + setUseObfs4(false); + setUsePortHopping(false); + } }); } private void initManualCircumventionEntry(View rootView) { - FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); IconSwitchEntry manualConfiguration = rootView.findViewById(R.id.bridge_manual_switch); - manualConfiguration.setOnClickListener((buttonView) -> { - Fragment fragment = CensorshipCircumventionFragment.newInstance(); - fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); + manualConfiguration.setChecked(hasManualCircumventionConfig()); + manualConfiguration.setOnCheckedChangeListener((buttonView, isChecked) -> { + if (!buttonView.isPressed()) { + return; + } + openManualConfigurationFragment(); }); + manualConfiguration.setOnClickListener((buttonView) -> openManualConfigurationFragment()); + } + + private void openManualConfigurationFragment() { + FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); + Fragment fragment = CensorshipCircumventionFragment.newInstance(); + fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); + } + + private boolean hasManualCircumventionConfig() { + return getUseSnowflake() || getUseObfs4() || getObfuscationPinningKCP() || getUsePortHopping(); } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java index 754491f8..535cd474 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java @@ -54,6 +54,8 @@ public interface Constants { String OBFUSCATION_PINNING_LOCATION = "obfuscation_pinning_location"; String USE_SYSTEM_PROXY = "usesystemproxy"; String CUSTOM_PROVIDER_DOMAINS = "custom_provider_domains"; + String USE_PORT_HOPPING = "use_port_hopping"; + String USE_OBSF4 = "use_obsf4"; ////////////////////////////////////////////// diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java index c2c0d85e..1f7b2597 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java @@ -40,6 +40,8 @@ import static se.leap.bitmaskclient.base.models.Constants.SHOW_EXPERIMENTAL; import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; import static se.leap.bitmaskclient.base.models.Constants.USE_IPv6_FIREWALL; import static se.leap.bitmaskclient.base.models.Constants.USE_OBFUSCATION_PINNING; +import static se.leap.bitmaskclient.base.models.Constants.USE_OBSF4; +import static se.leap.bitmaskclient.base.models.Constants.USE_PORT_HOPPING; import static se.leap.bitmaskclient.base.models.Constants.USE_SNOWFLAKE; import static se.leap.bitmaskclient.base.models.Constants.USE_SYSTEM_PROXY; @@ -564,6 +566,22 @@ public class PreferenceHelper { putBoolean(USE_IPv6_FIREWALL, useFirewall); } + public static boolean getUsePortHopping() { + return getBoolean(USE_PORT_HOPPING, false); + } + + public static void setUsePortHopping(boolean usePortHopping) { + putBoolean(USE_PORT_HOPPING, usePortHopping); + } + + public static boolean getUseObfs4() { + return getBoolean(USE_OBSF4, false); + } + + public static void setUseObfs4(boolean useObsf4) { + putBoolean(USE_OBSF4, useObsf4); + } + public static boolean useIpv6Firewall() { return getBoolean(USE_IPv6_FIREWALL, false); } |