From f557975d72b64d7ed13c53c153b40c0fb5522757 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 26 Nov 2021 10:58:56 +0100 Subject: disable location entries that are not supporting current transport, show hint in GatewaySelectionFragment and an option to disable bridges --- .../base/fragments/GatewaySelectionFragment.java | 41 ++++++++++++---------- .../base/fragments/MainActivityErrorDialog.java | 38 +++++--------------- 2 files changed, 32 insertions(+), 47 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/base/fragments') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 72cca644..4e7bb6ab 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -28,6 +28,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatTextView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -44,20 +45,21 @@ import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.views.SelectLocationEntry; -import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; import static android.content.Context.MODE_PRIVATE; +import static android.view.View.GONE; +import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; 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.base.MainActivity.ACTION_SHOW_DIALOG_FRAGMENT; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.models.Constants.LOCATION; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarTitle; interface LocationListSelectionListener { @@ -76,6 +78,8 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca private EipStatus eipStatus; private SharedPreferences preferences; private Connection.TransportType selectedTransport; + private AppCompatTextView bridgesHint; + private AppCompatTextView disableBridges; public GatewaySelectionFragment() { // Required empty public constructor @@ -88,7 +92,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca eipStatus = EipStatus.getInstance(); eipStatus.addObserver(this); preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - selectedTransport = PreferenceHelper.getUseBridges(preferences) ? OBFS4 : OPENVPN; + selectedTransport = getUseBridges(preferences) ? OBFS4 : OPENVPN; preferences.registerOnSharedPreferenceChangeListener(this); } @@ -104,6 +108,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca super.onViewCreated(view, savedInstanceState); initRecyclerView(); initRecommendedLocationEntry(); + initBridgesHint(view); setActionBarTitle(this, R.string.gateway_selection_title); } @@ -136,6 +141,16 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca updateRecommendedLocation(); } + private void initBridgesHint(@NonNull View view) { + bridgesHint = view.findViewById(R.id.manual_subtitle); + bridgesHint.setVisibility(getUseBridges(getContext()) ? VISIBLE : GONE); + disableBridges = view.findViewById(R.id.disable_bridges); + disableBridges.setVisibility(getUseBridges(getContext()) ? VISIBLE : GONE); + disableBridges.setOnClickListener(v -> { + useBridges(getContext(), false); + }); + } + private void updateRecommendedLocation() { Location location = new Location(); boolean isManualSelection = PreferenceHelper.getPreferredCity(getContext()) != null; @@ -174,22 +189,9 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca String name = location.getName(); if (location.supportsTransport(selectedTransport)) { startEipService(name); - } else { - locationListAdapter.unselectAll(); - askToChangeTransport(name); } } - private void askToChangeTransport(String name) { - Intent intent = new Intent(getContext(), MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.setAction(ACTION_SHOW_DIALOG_FRAGMENT); - intent.putExtra(EIP.ERRORID, EIP.EIPErrors.TRANSPORT_NOT_SUPPORTED.toString()); - intent.putExtra(EIP.ERRORS, getString(R.string.warning_bridges_not_supported, name)); - intent.putExtra(LOCATION, name); - startActivity(intent); - } - @Override public void update(Observable o, Object arg) { if (o instanceof EipStatus) { @@ -204,9 +206,12 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(USE_BRIDGES)) { - selectedTransport = PreferenceHelper.getUseBridges(sharedPreferences) ? OBFS4 : OPENVPN; + boolean showBridges = getUseBridges(sharedPreferences); + selectedTransport = showBridges ? OBFS4 : OPENVPN; gatewaysManager.updateTransport(selectedTransport); locationListAdapter.updateTransport(selectedTransport, gatewaysManager); + bridgesHint.setVisibility(showBridges ? VISIBLE : GONE); + disableBridges.setVisibility(showBridges ? VISIBLE : GONE); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java index f7805002..f1895307 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java @@ -18,37 +18,32 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; import org.json.JSONObject; import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.base.MainActivity; -import se.leap.bitmaskclient.base.utils.PreferenceHelper; +import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipCommand; -import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.providersetup.ProviderAPICommand; -import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_DIALOG_FRAGMENT; -import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setPreferredCity; -import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE; import static se.leap.bitmaskclient.R.string.warning_option_try_ovpn; import static se.leap.bitmaskclient.R.string.warning_option_try_pt; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setPreferredCity; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; import static se.leap.bitmaskclient.eip.EIP.EIPErrors.UNKNOWN; import static se.leap.bitmaskclient.eip.EIP.EIPErrors.valueOf; -import static se.leap.bitmaskclient.eip.EIP.ERRORS; import static se.leap.bitmaskclient.eip.EIP.ERRORID; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; +import static se.leap.bitmaskclient.eip.EIP.ERRORS; +import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE; /** * Implements an error dialog for the main activity. @@ -158,21 +153,6 @@ public class MainActivityErrorDialog extends DialogFragment { case ERROR_VPN_PREPARE: builder.setPositiveButton(android.R.string.ok, (dialog, which) -> { }); break; - case TRANSPORT_NOT_SUPPORTED: - - builder.setPositiveButton(R.string.option_different_location, (dialog, which) -> { }); - builder.setNegativeButton(R.string.option_disable_bridges, (dialog, which) -> { - PreferenceHelper.useBridges(applicationContext, false); - PreferenceHelper.setPreferredCity(applicationContext, args[0]); - - EipCommand.startVPN(applicationContext, false); - // at this point the gateway selection dialog is shown, let's switch to the main view - Intent intent = new Intent(getContext(), MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.setAction(ACTION_SHOW_VPN_FRAGMENT); - startActivity(intent); - }); - break; default: break; } -- cgit v1.2.3