summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-26 10:58:56 +0100
committercyBerta <cyberta@riseup.net>2021-11-26 10:58:56 +0100
commitf557975d72b64d7ed13c53c153b40c0fb5522757 (patch)
tree3dbe03aad0b01ffcc52bc20d309452166b070c3e /app/src/main/java/se
parentc8fba40687516c2e93b6ba691af96f6fb6838df2 (diff)
disable location entries that are not supporting current transport, show hint in GatewaySelectionFragment and an option to disable bridges
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java41
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java38
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java13
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java1
4 files changed, 41 insertions, 52 deletions
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;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java
index 2a082579..3d4f93ff 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java
@@ -65,14 +65,19 @@ public class SelectLocationEntry extends LinearLayout {
title.setText(text);
title.setVisibility(text != null ? VISIBLE : GONE);
}
+
public void setLocation(Location location, Connection.TransportType transportType) {
- boolean valid = location.hasLocationInfo();
- locationText.setVisibility(valid ? VISIBLE : GONE);
- locationIndicator.setVisibility(valid ? VISIBLE : GONE);
- bridgesView.setVisibility(transportType == OBFS4 && location.supportsTransport(OBFS4) ? VISIBLE : GONE);
+ boolean hasData = location.hasLocationInfo();
+ boolean supportsSelectedTransport = location.supportsTransport(transportType);
+ locationText.setVisibility(hasData ? VISIBLE : GONE);
+ locationIndicator.setVisibility(hasData ? VISIBLE : GONE);
+ bridgesView.setVisibility(transportType == OBFS4 && supportsSelectedTransport ? VISIBLE : GONE);
locationText.setText(location.getName());
locationIndicator.setLoad(Load.getLoadByValue(location.getAverageLoad(transportType)));
selectedView.setChecked(location.selected);
+ locationText.setEnabled(supportsSelectedTransport);
+ selectedView.setEnabled(supportsSelectedTransport);
+ setEnabled(!hasData || supportsSelectedTransport);
}
public void showDivider(boolean show) {
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 a7e08bd7..4db8f0c2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -128,7 +128,6 @@ public final class EIP extends JobIntentService implements Observer {
NO_MORE_GATEWAYS,
ERROR_VPN_PREPARE,
ERROR_INVALID_PROFILE,
- TRANSPORT_NOT_SUPPORTED,
}
/**