From 1e9202c3d929083220924f7c76ea01a2b6f6af9f Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 22 Jul 2021 15:31:08 +0200 Subject: first implementation of the gateway button, started to remove labels from EipFragment, implement method to get the avearage load of a location as an enum value --- app/src/androidTest/legacy/VpnTestController.java | 2 +- .../bitmaskclient/base/fragments/EipFragment.java | 66 +++++++++---------- .../bitmaskclient/base/views/LocationButton.java | 44 +++++++++++++ .../base/views/LocationIndicator.java | 76 ++++++++++++++++++++++ .../se/leap/bitmaskclient/eip/GatewaysManager.java | 50 ++++++++++++++ .../res/drawable/cust_button_primary_hard_rect.xml | 21 ++++++ .../main/res/drawable/cust_button_primary_rect.xml | 3 - app/src/main/res/layout-xlarge/f_eip.xml | 46 ++----------- app/src/main/res/layout/f_eip.xml | 46 ++----------- app/src/main/res/layout/v_location_button.xml | 38 +++++++++++ .../res/layout/v_location_status_indicator.xml | 49 ++++++++++++++ app/src/main/res/values/strings.xml | 4 +- 12 files changed, 327 insertions(+), 118 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java create mode 100644 app/src/main/res/drawable/cust_button_primary_hard_rect.xml create mode 100644 app/src/main/res/layout/v_location_button.xml create mode 100644 app/src/main/res/layout/v_location_status_indicator.xml (limited to 'app') diff --git a/app/src/androidTest/legacy/VpnTestController.java b/app/src/androidTest/legacy/VpnTestController.java index e39ebae3..035ca2b0 100644 --- a/app/src/androidTest/legacy/VpnTestController.java +++ b/app/src/androidTest/legacy/VpnTestController.java @@ -35,7 +35,7 @@ public class VpnTestController { } protected Button getVpnButton() { - View button_view = solo.getView(R.id.vpn_main_button); + View button_view = solo.getView(R.id.gateway_location_button); if (button_view != null) return (Button) button_view; else diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index 615221ae..cc822463 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -38,9 +38,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.AppCompatButton; import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.AppCompatTextView; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; @@ -60,9 +58,11 @@ import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.FragmentManagerEnhanced; import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.base.models.ProviderObservable; +import se.leap.bitmaskclient.base.views.LocationButton; import se.leap.bitmaskclient.base.views.VpnStateImage; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; +import se.leap.bitmaskclient.eip.GatewaysManager; import se.leap.bitmaskclient.providersetup.ProviderAPICommand; import se.leap.bitmaskclient.providersetup.ProviderListActivity; import se.leap.bitmaskclient.providersetup.activities.CustomProviderSetupActivity; @@ -86,6 +86,7 @@ import static se.leap.bitmaskclient.base.utils.ConfigHelper.isDefaultBitmask; import static se.leap.bitmaskclient.base.utils.ViewHelper.convertDimensionToPx; import static se.leap.bitmaskclient.eip.EipSetupObserver.gatewayOrder; import static se.leap.bitmaskclient.eip.EipSetupObserver.reconnectingWithDifferentGateway; +import static se.leap.bitmaskclient.eip.GatewaysManager.Load.UNKNOWN; import static se.leap.bitmaskclient.providersetup.ProviderAPI.DOWNLOAD_GEOIP_JSON; import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE; import static se.leap.bitmaskclient.providersetup.ProviderAPI.USER_MESSAGE; @@ -104,18 +105,14 @@ public class EipFragment extends Fragment implements Observer { @BindView(R.id.vpn_state_image) VpnStateImage vpnStateImage; - @BindView(R.id.vpn_main_button) - AppCompatButton mainButton; - - @BindView(R.id.routed_text) - AppCompatTextView routedText; - - @BindView(R.id.vpn_route) - AppCompatTextView vpnRoute; + @BindView(R.id.gateway_location_button) + LocationButton locationButton; private Unbinder unbinder; private EipStatus eipStatus; + private GatewaysManager gatewaysManager; + //---saved Instance ------- private final String KEY_SHOW_PENDING_START_CANCELLATION = "KEY_SHOW_PENDING_START_CANCELLATION"; private final String KEY_SHOW_ASK_TO_STOP_EIP = "KEY_SHOW_ASK_TO_STOP_EIP"; @@ -168,6 +165,9 @@ public class EipFragment extends Fragment implements Observer { } else { Log.e(TAG, "activity is null in onCreate - no preferences set!"); } + + gatewaysManager = new GatewaysManager(getContext()); + } @Override @@ -252,7 +252,7 @@ public class EipFragment extends Fragment implements Observer { preferences.edit().putBoolean(EIP_RESTART_ON_BOOT, restartOnBoot).apply(); } - @OnClick(R.id.vpn_main_button) + @OnClick(R.id.gateway_location_button) void onButtonClick() { handleIcon(); } @@ -307,7 +307,7 @@ public class EipFragment extends Fragment implements Observer { } private void setMainButtonEnabled(boolean enabled) { - mainButton.setEnabled(enabled); + locationButton.setEnabled(enabled); vpnStateImage.setEnabled(enabled); } @@ -408,32 +408,35 @@ public class EipFragment extends Fragment implements Observer { setMainButtonEnabled(true); showConnectingLayout(activity); if (eipStatus.isReconnecting()) { - //Log.d(TAG, "eip show reconnecting toast!"); - //showReconnectToast(activity); + locationButton.setText(getString(R.string.reconnecting)); + } else { + locationButton.setText(getString(R.string.finding_best_connection)); } + locationButton.setVisibility(VISIBLE); + locationButton.setLocationLoad(UNKNOWN); } else if (eipStatus.isConnected() ) { - mainButton.setText(activity.getString(R.string.vpn_button_turn_off)); + locationButton.setText(activity.getString(R.string.vpn_button_turn_off)); setMainButtonEnabled(true); vpnStateImage.setStateIcon(R.drawable.vpn_connected); vpnStateImage.stopProgress(false); - routedText.setText(R.string.vpn_securely_routed); - routedText.setVisibility(VISIBLE); - vpnRoute.setVisibility(VISIBLE); - setVpnRouteText(); + locationButton.setLocationLoad(gatewaysManager.getLoadForLocation(VpnStatus.getLastConnectedVpnName())); + locationButton.setText(VpnStatus.getLastConnectedVpnName()); + locationButton.setVisibility(VISIBLE); colorBackground(); } else if(isOpenVpnRunningWithoutNetwork()){ - mainButton.setText(activity.getString(R.string.vpn_button_turn_off)); + locationButton.setText(activity.getString(R.string.vpn_button_turn_off)); setMainButtonEnabled(true); vpnStateImage.setStateIcon(R.drawable.vpn_disconnected); vpnStateImage.stopProgress(false); - routedText.setText(R.string.vpn_securely_routed_no_internet); - routedText.setVisibility(VISIBLE); - vpnRoute.setVisibility(VISIBLE); + locationButton.setVisibility(VISIBLE); setVpnRouteText(); colorBackgroundALittle(); } else if (eipStatus.isDisconnected() && reconnectingWithDifferentGateway()) { showConnectingLayout(activity); // showRetryToast(activity); + locationButton.setText(getString(R.string.finding_best_connection)); + locationButton.setVisibility(VISIBLE); + locationButton.setLocationLoad(UNKNOWN); } else if (eipStatus.isDisconnecting()) { setMainButtonEnabled(false); showDisconnectingLayout(activity); @@ -441,18 +444,18 @@ public class EipFragment extends Fragment implements Observer { setMainButtonEnabled(true); vpnStateImage.setStateIcon(R.drawable.vpn_blocking); vpnStateImage.stopProgress(false); - routedText.setText(getString(R.string.void_vpn_establish, getString(R.string.app_name))); - routedText.setVisibility(VISIBLE); - vpnRoute.setVisibility(GONE); colorBackgroundALittle(); + locationButton.setText(getString(R.string.finding_best_connection)); + locationButton.setVisibility(VISIBLE); + locationButton.setLocationLoad(UNKNOWN); } else { - mainButton.setText(activity.getString(R.string.vpn_button_turn_on)); + locationButton.setText(activity.getString(R.string.vpn_button_turn_on)); setMainButtonEnabled(true); vpnStateImage.setStateIcon(R.drawable.vpn_disconnected); vpnStateImage.stopProgress(false); - routedText.setVisibility(GONE); - vpnRoute.setVisibility(GONE); greyscaleBackground(); + locationButton.setLocationLoad(UNKNOWN); + locationButton.setVisibility(GONE); } } @@ -494,11 +497,8 @@ public class EipFragment extends Fragment implements Observer { } private void showConnectionTransitionLayout(Context activity, boolean isConnecting) { - mainButton.setText(activity.getString(android.R.string.cancel)); vpnStateImage.setStateIcon(R.drawable.vpn_connecting); vpnStateImage.showProgress(); - routedText.setVisibility(GONE); - vpnRoute.setVisibility(GONE); if (isConnecting) { colorBackgroundALittle(); } else { @@ -574,7 +574,7 @@ public class EipFragment extends Fragment implements Observer { if (!TextUtils.isEmpty(profileName)) { vpnRouteString += " (" + profileName + ")"; } - vpnRoute.setText(vpnRouteString); + // vpnRoute.setText(vpnRouteString); } private class EipFragmentServiceConnection implements ServiceConnection { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java new file mode 100644 index 00000000..1d7f0d18 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationButton.java @@ -0,0 +1,44 @@ +package se.leap.bitmaskclient.base.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatTextView; +import androidx.appcompat.widget.LinearLayoutCompat; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.eip.GatewaysManager; + +public class LocationButton extends LinearLayoutCompat { + private LocationIndicator locationIndicator; + private AppCompatTextView textView; + public LocationButton(@NonNull Context context) { + super(context); + initLayout(context); + } + + public LocationButton(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initLayout(context); + } + + private void initLayout(Context context) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rootview = inflater.inflate(R.layout.v_location_button, this, true); + locationIndicator = rootview.findViewById(R.id.load_indicator); + textView = rootview.findViewById(R.id.text_location); + } + + public void setLocationLoad(GatewaysManager.Load load) { + locationIndicator.setLoad(load); + } + + public void setText(CharSequence text) { + textView.setText(text); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java new file mode 100644 index 00000000..f5e3dbe2 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java @@ -0,0 +1,76 @@ +package se.leap.bitmaskclient.base.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; + +import androidx.annotation.Nullable; + +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.eip.GatewaysManager; + +public class LocationIndicator extends LinearLayout { + + private View level1; + private View level2; + private View level3; + + public LocationIndicator(Context context) { + super(context); + initLayout(context); + } + + public LocationIndicator(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + initLayout(context); + + } + + public LocationIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initLayout(context); + } + + + void initLayout(Context context) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rootview = inflater.inflate(R.layout.v_location_status_indicator, this, true); + level1 = rootview.findViewById(R.id.level1); + level2 = rootview.findViewById(R.id.level2); + level3 = rootview.findViewById(R.id.level3); + } + + public void setLoad(GatewaysManager.Load load) { + switch (load) { + case GOOD: + level1.setBackgroundColor(getResources().getColor(R.color.green200)); + level2.setBackgroundColor(getResources().getColor(R.color.green200)); + level3.setBackgroundColor(getResources().getColor(R.color.green200)); + level1.setVisibility(VISIBLE); + level2.setVisibility(VISIBLE); + level3.setVisibility(VISIBLE); + break; + case AVERAGE: + level1.setBackgroundColor(getResources().getColor(R.color.yellow200)); + level2.setBackgroundColor(getResources().getColor(R.color.yellow200)); + level1.setVisibility(VISIBLE); + level2.setVisibility(VISIBLE); + level3.setVisibility(INVISIBLE); + break; + case CRITICAL: + level1.setBackgroundColor(getResources().getColor(R.color.red200)); + level1.setVisibility(VISIBLE); + level2.setVisibility(INVISIBLE); + level3.setVisibility(INVISIBLE); + break; + default: + level1.setVisibility(INVISIBLE); + level2.setVisibility(INVISIBLE); + level3.setVisibility(INVISIBLE); + break; + } + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 05775d13..b311315c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Random; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConfigParser; @@ -59,6 +60,37 @@ import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; */ public class GatewaysManager { + public enum Load { + UNKNOWN(0), + GOOD(0.25), + AVERAGE(0.75), + CRITICAL(1.0); + + private final double value; + + Load(double i) { + value = i; + } + + public static Load getLoadByValue(double value) { + if (value == UNKNOWN.value) { + return UNKNOWN; + } else if (value <= GOOD.value) { + return GOOD; + } else if (value <= AVERAGE.value) { + return AVERAGE; + } else if (value <= CRITICAL.value) { + return CRITICAL; + } else { + return UNKNOWN; + } + } + + public double getValue() { + return value; + } + } + private static final String TAG = GatewaysManager.class.getSimpleName(); private Context context; @@ -117,6 +149,22 @@ public class GatewaysManager { return locations; } + public Load getLoadForLocation(@Nullable String name) { + List locations = getGatewayLocations(); + for (Location location : locations) { + if (location.name.equals(name)) { + + // fake values for now + Random rand = new Random(); + double averageLoad = rand.nextDouble(); //location.averageLoad; + return Load.getLoadByValue(averageLoad); + } + } + + // location not found + return Load.UNKNOWN; + } + private Gateway getGatewayFromTimezoneCalculation(int nClosest, Connection.TransportType transportType, @Nullable String city) { List list = new ArrayList<>(gateways.values()); GatewaySelector gatewaySelector = new GatewaySelector(list); @@ -326,4 +374,6 @@ public class GatewaysManager { } } + + } diff --git a/app/src/main/res/drawable/cust_button_primary_hard_rect.xml b/app/src/main/res/drawable/cust_button_primary_hard_rect.xml new file mode 100644 index 00000000..93be5c18 --- /dev/null +++ b/app/src/main/res/drawable/cust_button_primary_hard_rect.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/cust_button_primary_rect.xml b/app/src/main/res/drawable/cust_button_primary_rect.xml index c83d4e62..93be5c18 100644 --- a/app/src/main/res/drawable/cust_button_primary_rect.xml +++ b/app/src/main/res/drawable/cust_button_primary_rect.xml @@ -2,21 +2,18 @@ - - - diff --git a/app/src/main/res/layout-xlarge/f_eip.xml b/app/src/main/res/layout-xlarge/f_eip.xml index d4a51b8d..bef2d635 100644 --- a/app/src/main/res/layout-xlarge/f_eip.xml +++ b/app/src/main/res/layout-xlarge/f_eip.xml @@ -80,53 +80,21 @@ app:layout_constraintTop_toTopOf="@+id/guideline_horizontal_top" app:layout_constraintDimensionRatio="1:1" /> - - - - - + tools:text="SEATTLE" + android:gravity="center_vertical" /> diff --git a/app/src/main/res/layout/f_eip.xml b/app/src/main/res/layout/f_eip.xml index 3309eb5d..8dc1e33b 100644 --- a/app/src/main/res/layout/f_eip.xml +++ b/app/src/main/res/layout/f_eip.xml @@ -82,54 +82,20 @@ app:layout_constraintDimensionRatio="1:1" /> - - - - - + tools:text="SEATTLE" + android:gravity="center_vertical" /> diff --git a/app/src/main/res/layout/v_location_button.xml b/app/src/main/res/layout/v_location_button.xml new file mode 100644 index 00000000..7425231e --- /dev/null +++ b/app/src/main/res/layout/v_location_button.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/v_location_status_indicator.xml b/app/src/main/res/layout/v_location_status_indicator.xml new file mode 100644 index 00000000..97b55917 --- /dev/null +++ b/app/src/main/res/layout/v_location_status_indicator.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 22696c12..b6bdafa8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -155,7 +155,8 @@ Location with best connection Automatic Your traffic is currently routed through: - + Finding best connection… + Reconnecting… Starting bridges for censorship circumvention… Stopping bridges. Using bridges for censorship circumvention. @@ -181,5 +182,4 @@ Hide connection details %s has no internet connection. Please check your WiFi and cellular data settings. - -- cgit v1.2.3 From ff427f2863dd2c3c46030968f4d034553f09d0bf Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 23 Jul 2021 23:50:02 +0200 Subject: add click listener to gateway selection button, open the gateway selection fragment --- .../java/se/leap/bitmaskclient/base/fragments/EipFragment.java | 7 +++++++ app/src/main/res/layout/v_location_button.xml | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index cc822463..af34b7a5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -56,6 +56,7 @@ import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.FragmentManagerEnhanced; +import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.base.models.ProviderObservable; import se.leap.bitmaskclient.base.views.LocationButton; @@ -168,6 +169,7 @@ public class EipFragment extends Fragment implements Observer { gatewaysManager = new GatewaysManager(getContext()); + } @Override @@ -189,6 +191,11 @@ public class EipFragment extends Fragment implements Observer { } restoreFromSavedInstance(savedInstanceState); + locationButton.setOnClickListener(v -> { + FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); + Fragment fragment = new GatewaySelectionFragment(); + fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG); + }); return view; } diff --git a/app/src/main/res/layout/v_location_button.xml b/app/src/main/res/layout/v_location_button.xml index 7425231e..9e5445a4 100644 --- a/app/src/main/res/layout/v_location_button.xml +++ b/app/src/main/res/layout/v_location_button.xml @@ -4,8 +4,6 @@ android:orientation="horizontal" android:layout_width="match_parent" android:layout_gravity="center_vertical" - android:clickable="true" - android:focusable="true" android:padding="@dimen/stdpadding" android:background="@drawable/cust_button_primary_rect" android:layout_height="wrap_content"> -- cgit v1.2.3 From 05934715fec39cb22937e82acecd4add4fccd724 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 29 Jul 2021 18:23:55 +0200 Subject: implement location load indicator in gateway selection cell --- .../base/fragments/GatewaySelectionFragment.java | 7 ++++--- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 14 ++++++++------ app/src/main/res/layout/v_select_text_list_item.xml | 19 ++++++------------- 3 files changed, 18 insertions(+), 22 deletions(-) (limited to 'app') 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 d1222cd7..e4d8ca8b 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 @@ -46,6 +46,7 @@ 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.IconSwitchEntry; +import se.leap.bitmaskclient.base.views.LocationIndicator; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; @@ -189,7 +190,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen static class ViewHolder extends RecyclerView.ViewHolder { public AppCompatTextView locationLabel; - public AppCompatTextView qualityLabel; + public LocationIndicator locationIndicator; public AppCompatImageView checkedIcon; public View layout; @@ -197,7 +198,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen super(v); layout = v; locationLabel = (AppCompatTextView) v.findViewById(R.id.location); - qualityLabel = (AppCompatTextView) v.findViewById(R.id.quality); + locationIndicator = (LocationIndicator) v.findViewById(R.id.quality); checkedIcon = (AppCompatImageView) v.findViewById(R.id.checked_icon); } } @@ -263,7 +264,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen DrawableCompat.setTint(checkIcon, ContextCompat.getColor(holder.layout.getContext(), R.color.colorSuccess)); holder.checkedIcon.setImageDrawable(checkIcon); holder.checkedIcon.setVisibility(location.selected ? VISIBLE : INVISIBLE); - holder.qualityLabel.setText(getQualityString(location.averageLoad)); + holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); if (location.selected) { selectedLocation = location; } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index b311315c..24e9c323 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -130,9 +130,15 @@ public class GatewaysManager { while ((gateway = select(n, null)) != null) { if (!locationNames.containsKey(gateway.getName())) { locationNames.put(gateway.getName(), locations.size()); + // fake values for now + Random rand = new Random(); + double averageLoad = rand.nextDouble(); //location.averageLoad; + + Location location = new Location( gateway.getName(), - gateway.getFullness(), + averageLoad + /*gateway.getFullness()*/, 1, gateway.getName().equals(selectedCity)); locations.add(location); @@ -153,11 +159,7 @@ public class GatewaysManager { List locations = getGatewayLocations(); for (Location location : locations) { if (location.name.equals(name)) { - - // fake values for now - Random rand = new Random(); - double averageLoad = rand.nextDouble(); //location.averageLoad; - return Load.getLoadByValue(averageLoad); + return Load.getLoadByValue(location.averageLoad); } } diff --git a/app/src/main/res/layout/v_select_text_list_item.xml b/app/src/main/res/layout/v_select_text_list_item.xml index 07187016..36075424 100644 --- a/app/src/main/res/layout/v_select_text_list_item.xml +++ b/app/src/main/res/layout/v_select_text_list_item.xml @@ -19,20 +19,13 @@ tools:visibility="visible" /> - Date: Fri, 30 Jul 2021 15:46:40 +0200 Subject: draft gateway selection UI according to simlpy secure's proposals --- .../base/fragments/GatewaySelectionFragment.java | 158 ++++++++------------- .../base/fragments/MainActivityErrorDialog.java | 6 +- .../base/fragments/NavigationDrawerFragment.java | 2 +- .../leap/bitmaskclient/base/models/Location.java | 6 +- .../bitmaskclient/base/utils/PreferenceHelper.java | 10 +- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 20 ++- app/src/main/res/layout/f_drawer_main.xml | 2 +- app/src/main/res/layout/f_gateway_selection.xml | 34 ++--- .../main/res/layout/v_select_text_list_item.xml | 16 +-- app/src/main/res/values/strings.xml | 7 +- 10 files changed, 107 insertions(+), 154 deletions(-) (limited to 'app') 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 e4d8ca8b..ee4aea74 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 @@ -19,7 +19,6 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -29,23 +28,21 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatButton; -import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; -import androidx.core.content.ContextCompat; -import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import java.lang.ref.WeakReference; import java.util.List; import java.util.Observable; import java.util.Observer; +import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.R; 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.IconSwitchEntry; import se.leap.bitmaskclient.base.views.LocationIndicator; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; @@ -55,21 +52,23 @@ import static android.content.Context.MODE_PRIVATE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.models.Constants.PREFERRED_CITY; 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.getPreferredCity; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setPreferredCity; -public class GatewaySelectionFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, Observer { +interface LocationListSelectionListener { + void onLocationSelected(String name); +} + +public class GatewaySelectionFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, Observer, LocationListSelectionListener { private static final String TAG = GatewaySelectionFragment.class.getSimpleName(); private RecyclerView recyclerView; private LocationListAdapter locationListAdapter; - private IconSwitchEntry autoSelectionSwitch; - private AppCompatButton vpnButton; + private AppCompatTextView currentLocationDescription; + private AppCompatTextView currentLocation; + private AppCompatButton autoSelectionButton; private GatewaysManager gatewaysManager; private SharedPreferences preferences; private EipStatus eipStatus; @@ -97,8 +96,8 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initRecyclerView(); - initAutoSelectionSwitch(); - initVpnButton(); + initAutoSelectionButton(); + initCurrentLocationInfoPanel(); eipStatus.addObserver(this); preferences.registerOnSharedPreferenceChangeListener(this); } @@ -113,93 +112,94 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen private void initRecyclerView() { - recyclerView = (RecyclerView) getActivity().findViewById(R.id.gatewaySelection_list); + recyclerView = getActivity().findViewById(R.id.gatewaySelection_list); recyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(this.getContext()); recyclerView.setLayoutManager(layoutManager); - locationListAdapter = new LocationListAdapter(gatewaysManager.getGatewayLocations()); + locationListAdapter = new LocationListAdapter(gatewaysManager.getGatewayLocations(), this); recyclerView.setAdapter(locationListAdapter); - recyclerView.setVisibility(getPreferredCity(getContext()) == null ? INVISIBLE : VISIBLE); + recyclerView.setVisibility(VISIBLE); } - private void initAutoSelectionSwitch() { - autoSelectionSwitch = getActivity().findViewById(R.id.automatic_gateway_switch); - autoSelectionSwitch.setSingleLine(false); - autoSelectionSwitch.setSubtitle(getString(R.string.gateway_selection_warning, getString(R.string.app_name))); - autoSelectionSwitch.setChecked(getPreferredCity(getContext()) == null); - autoSelectionSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> { - recyclerView.setVisibility(!isChecked ? VISIBLE : View.GONE); - Log.d(TAG, "autoselection enabled: " + isChecked); - if (isChecked) { - PreferenceHelper.setPreferredCity(getContext(), null); - locationListAdapter.resetSelection(); - } - setVpnButtonState(); + private void initAutoSelectionButton() { + autoSelectionButton = getActivity().findViewById(R.id.automatic_gateway_selection_btn); + autoSelectionButton.setOnClickListener(v -> { + startEipService(null); }); } - private void initVpnButton() { - vpnButton = getActivity().findViewById(R.id.vpn_button); - setVpnButtonState(); - vpnButton.setOnClickListener(v -> { + private void initCurrentLocationInfoPanel() { + currentLocationDescription = getActivity().findViewById(R.id.current_location_description); + currentLocation = getActivity().findViewById(R.id.current_location); + setLocationDescription(EipStatus.getInstance(), PreferenceHelper.getPreferredCity(getContext())); + } + + private void setLocationDescription(EipStatus eipStatus, String preferredCity) { + if (eipStatus.isConnected()) { + currentLocationDescription.setText(preferredCity == null ? + R.string.gateway_selection_automatic_location : + R.string.gateway_selection_manual_location); + currentLocation.setText(VpnStatus.getLastConnectedVpnName()); + currentLocation.setVisibility(VISIBLE); + } else if (preferredCity == null) { + currentLocationDescription.setText(R.string.gateway_selection_automatic_not_connected); + currentLocation.setVisibility(INVISIBLE); + } else { + currentLocationDescription.setText(R.string.gateway_selection_manual_not_connected); + currentLocation.setText(preferredCity); + currentLocation.setVisibility(VISIBLE); + } + } + + protected void startEipService(String preferredCity) { + new Thread(() -> { + PreferenceHelper.setPreferredCity(getContext(), preferredCity); EipCommand.startVPN(getContext(), false); 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); - }); - } - - private void setVpnButtonState() { - if (eipStatus.isDisconnected()) { - vpnButton.setText(R.string.vpn_button_turn_on); - } else { - vpnButton.setText(R.string.reconnect); - } - vpnButton.setEnabled( - (locationListAdapter.selectedLocation != null && locationListAdapter.selectedLocation.selected) || - autoSelectionSwitch.isChecked()); + }).start(); } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (USE_BRIDGES.equals(key)) { locationListAdapter.updateData(gatewaysManager.getGatewayLocations()); - setVpnButtonState(); - } else if (PREFERRED_CITY.equals(key)) { - setVpnButtonState(); } } + @Override + public void onLocationSelected(String name) { + startEipService(name); + } + @Override public void update(Observable o, Object arg) { if (o instanceof EipStatus) { - eipStatus = (EipStatus) o; Activity activity = getActivity(); if (activity != null) { - activity.runOnUiThread(this::setVpnButtonState); + activity.runOnUiThread(() -> setLocationDescription((EipStatus) o, PreferenceHelper.getPreferredCity(getContext()))); } } - } + static class LocationListAdapter extends RecyclerView.Adapter { private static final String TAG = LocationListAdapter.class.getSimpleName(); private List values; - private Location selectedLocation = null; + private final WeakReference callback; static class ViewHolder extends RecyclerView.ViewHolder { public AppCompatTextView locationLabel; public LocationIndicator locationIndicator; - public AppCompatImageView checkedIcon; public View layout; public ViewHolder(View v) { super(v); layout = v; - locationLabel = (AppCompatTextView) v.findViewById(R.id.location); - locationIndicator = (LocationIndicator) v.findViewById(R.id.quality); - checkedIcon = (AppCompatImageView) v.findViewById(R.id.checked_icon); + locationLabel = v.findViewById(R.id.location); + locationIndicator = v.findViewById(R.id.quality); } } @@ -213,20 +213,14 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen notifyItemRemoved(position); } - public void resetSelection() { - if (selectedLocation != null) { - selectedLocation.selected = false; - notifyDataSetChanged(); - } - } - public void updateData(List data) { values = data; notifyDataSetChanged(); } - public LocationListAdapter(List data) { + public LocationListAdapter(List data, LocationListSelectionListener selectionListener) { values = data; + callback = new WeakReference<>(selectionListener); } @NonNull @@ -246,42 +240,12 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen holder.locationLabel.setText(location.name); holder.layout.setOnClickListener(v -> { Log.d(TAG, "view at position clicked: " + position); - if (selectedLocation == null) { - selectedLocation = location; - selectedLocation.selected = true; - } else if (selectedLocation.name.equals(location.name)){ - selectedLocation.selected = !selectedLocation.selected; - } else { - selectedLocation.selected = false; - selectedLocation = location; - selectedLocation.selected = true; + LocationListSelectionListener listener = callback.get(); + if (listener != null) { + listener.onLocationSelected(location.name); } - setPreferredCity(holder.layout.getContext(), selectedLocation.selected ? selectedLocation.name : null); - holder.checkedIcon.setVisibility(selectedLocation.selected ? VISIBLE : INVISIBLE); - notifyDataSetChanged(); }); - Drawable checkIcon = DrawableCompat.wrap(holder.layout.getContext().getResources().getDrawable(R.drawable.ic_check_bold)).mutate(); - DrawableCompat.setTint(checkIcon, ContextCompat.getColor(holder.layout.getContext(), R.color.colorSuccess)); - holder.checkedIcon.setImageDrawable(checkIcon); - holder.checkedIcon.setVisibility(location.selected ? VISIBLE : INVISIBLE); holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); - if (location.selected) { - selectedLocation = location; - } - } - - public String getQualityString(double quality) { - if (quality == 0) { - return ""; - } else if (quality < 0.25) { - return "BAD"; - } else if (quality < 0.6) { - return "AVERAGE"; - } else if (quality < 0.8){ - return "GOOD"; - } else { - return "EXCELLENT"; - } } 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 86f8471c..da48effc 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 @@ -124,8 +124,10 @@ public class MainActivityErrorDialog extends DialogFragment { builder.setNegativeButton(R.string.cancel, (dialog, id) -> {}); if (getPreferredCity(applicationContext) != null) { builder.setPositiveButton(R.string.warning_option_try_best, (dialog, which) -> { - setPreferredCity(applicationContext, null); - EipCommand.startVPN(applicationContext, false); + new Thread(() -> { + setPreferredCity(applicationContext, null); + EipCommand.startVPN(applicationContext, false); + }).start(); }); } else if (provider.supportsPluggableTransports()) { if (getUseBridges(applicationContext)) { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java index a13692a5..1f4d0b17 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/NavigationDrawerFragment.java @@ -425,7 +425,7 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen } manualGatewaySelection = drawerView.findViewById(R.id.manualGatewaySelection); String preferredGateway = getPreferredCity(getContext()); - String subtitle = preferredGateway != null ? preferredGateway : getString(R.string.gateway_selection_best_location); + String subtitle = preferredGateway != null ? preferredGateway : getString(R.string.gateway_selection_recommended_location); manualGatewaySelection.setSubtitle(subtitle); boolean show = ProviderObservable.getInstance().getCurrentProvider().hasGatewaysInDifferentLocations(); manualGatewaySelection.setVisibility(show ? VISIBLE : GONE); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java index ae7818ba..8e032d18 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java @@ -6,13 +6,11 @@ public class Location { @NonNull public String name; public double averageLoad; public int numberOfGateways; - public boolean selected; - public Location(@NonNull String name, double averageLoad, int numberOfGateways, boolean selected) { + public Location(@NonNull String name, double averageLoad, int numberOfGateways) { this.name = name; this.averageLoad = averageLoad; this.numberOfGateways = numberOfGateways; - this.selected = selected; } @Override @@ -24,7 +22,6 @@ public class Location { if (Double.compare(location.averageLoad, averageLoad) != 0) return false; if (numberOfGateways != location.numberOfGateways) return false; - if (selected != location.selected) return false; return name.equals(location.name); } @@ -36,7 +33,6 @@ public class Location { temp = Double.doubleToLongBits(averageLoad); result = 31 * result + (int) (temp ^ (temp >>> 32)); result = 31 * result + numberOfGateways; - result = 31 * result + (selected ? 1 : 0); return result; } } 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 06fb25e9..93284968 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 @@ -3,6 +3,7 @@ package se.leap.bitmaskclient.base.utils; import android.content.Context; import android.content.SharedPreferences; import androidx.annotation.NonNull; +import androidx.annotation.WorkerThread; import org.json.JSONException; import org.json.JSONObject; @@ -229,8 +230,9 @@ public class PreferenceHelper { return getString(context, PREFERRED_CITY, null); } + @WorkerThread public static void setPreferredCity(Context context, String city) { - putString(context, PREFERRED_CITY, city); + putStringSync(context, PREFERRED_CITY, city); } public static JSONObject getEipDefinitionFromPreferences(SharedPreferences preferences) { @@ -277,6 +279,12 @@ public class PreferenceHelper { return preferences.getString(key, defValue); } + @WorkerThread + public static void putStringSync(Context context, String key, String value) { + SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + preferences.edit().putString(key, value).commit(); + } + public static void putString(Context context, String key, String value) { SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); preferences.edit().putString(key, value).apply(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 24e9c323..0819e9b6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -93,10 +93,10 @@ public class GatewaysManager { private static final String TAG = GatewaysManager.class.getSimpleName(); - private Context context; - private LinkedHashMap gateways = new LinkedHashMap<>(); - private Type listType = new TypeToken>() {}.getType(); - private ArrayList presortedList = new ArrayList<>(); + private final Context context; + private final LinkedHashMap gateways = new LinkedHashMap<>(); + private final Type listType = new TypeToken>() {}.getType(); + private final ArrayList presortedList = new ArrayList<>(); public GatewaysManager(Context context) { this.context = context; @@ -128,24 +128,30 @@ public class GatewaysManager { int n = 0; Gateway gateway; while ((gateway = select(n, null)) != null) { + String name = gateway.getName(); + if (name == null) { + Log.e(TAG, "Gateway without location name found. This should never happen. Provider misconfigured?"); + continue; + } + if (!locationNames.containsKey(gateway.getName())) { locationNames.put(gateway.getName(), locations.size()); // fake values for now Random rand = new Random(); double averageLoad = rand.nextDouble(); //location.averageLoad; - + Log.d(TAG, "getGatewayLocations - new averageLoad (" + gateway.getName() + "): " + averageLoad); Location location = new Location( gateway.getName(), averageLoad /*gateway.getFullness()*/, - 1, - gateway.getName().equals(selectedCity)); + 1); locations.add(location); } else { int index = locationNames.get(gateway.getName()); Location location = locations.get(index); location.averageLoad = (location.numberOfGateways * location.averageLoad + gateway.getFullness()) / (location.numberOfGateways + 1); + Log.d(TAG, "getGatewayLocations - updated averageLoad: (" + gateway.getName() + "): " + location.averageLoad); location.numberOfGateways += 1; locations.set(index, location); } diff --git a/app/src/main/res/layout/f_drawer_main.xml b/app/src/main/res/layout/f_drawer_main.xml index 1f1df7f2..95e6169b 100644 --- a/app/src/main/res/layout/f_drawer_main.xml +++ b/app/src/main/res/layout/f_drawer_main.xml @@ -101,7 +101,7 @@ + + android:text="@string/gateway_selection_automatic_location" /> - - - - + + android:text="@string/gateway_selection_recommended_location" + /> diff --git a/app/src/main/res/layout/v_select_text_list_item.xml b/app/src/main/res/layout/v_select_text_list_item.xml index 36075424..1d7054a4 100644 --- a/app/src/main/res/layout/v_select_text_list_item.xml +++ b/app/src/main/res/layout/v_select_text_list_item.xml @@ -6,25 +6,13 @@ xmlns:tools="http://schemas.android.com/tools"> - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b6bdafa8..7c0c46f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -152,9 +152,12 @@ No permissions to install app. Select location %s will find the best connection for you. - Location with best connection + Use recommended location Automatic - Your traffic is currently routed through: + Your traffic is currently routed through: + Your traffic will be routed through: + Your traffic is automatically routed through the best location: + Your traffic will be automatically routed through the best location. Finding best connection… Reconnecting… Starting bridges for censorship circumvention… -- cgit v1.2.3 From d366b98aafdb0b211ed7b3870354477ffc250462 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Fri, 30 Jul 2021 18:22:12 +0200 Subject: show bridges icon in gateway selector for locations supporting them --- .../base/fragments/GatewaySelectionFragment.java | 25 +++++--------------- .../leap/bitmaskclient/base/models/Location.java | 27 ++++++++++++++++++++-- .../java/se/leap/bitmaskclient/eip/Gateway.java | 4 ++++ .../se/leap/bitmaskclient/eip/GatewaySelector.java | 10 ++++++++ .../se/leap/bitmaskclient/eip/GatewaysManager.java | 26 +++++++++++++-------- .../main/res/layout/v_select_text_list_item.xml | 15 ++++++++++-- 6 files changed, 75 insertions(+), 32 deletions(-) (limited to 'app') 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 ee4aea74..450cba4d 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 @@ -18,7 +18,6 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Activity; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -28,6 +27,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatButton; +import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatTextView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; @@ -39,6 +39,7 @@ import java.util.Observable; import java.util.Observer; import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.connection.Connection; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; @@ -48,18 +49,15 @@ 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.INVISIBLE; import static android.view.View.VISIBLE; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; -import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; interface LocationListSelectionListener { void onLocationSelected(String name); } -public class GatewaySelectionFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, Observer, LocationListSelectionListener { +public class GatewaySelectionFragment extends Fragment implements Observer, LocationListSelectionListener { private static final String TAG = GatewaySelectionFragment.class.getSimpleName(); @@ -70,7 +68,6 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen private AppCompatTextView currentLocation; private AppCompatButton autoSelectionButton; private GatewaysManager gatewaysManager; - private SharedPreferences preferences; private EipStatus eipStatus; public GatewaySelectionFragment() { @@ -81,7 +78,6 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gatewaysManager = new GatewaysManager(getContext()); - preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); eipStatus = EipStatus.getInstance(); } @@ -98,19 +94,14 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen initRecyclerView(); initAutoSelectionButton(); initCurrentLocationInfoPanel(); - eipStatus.addObserver(this); - preferences.registerOnSharedPreferenceChangeListener(this); } @Override public void onDestroyView() { super.onDestroyView(); - preferences.unregisterOnSharedPreferenceChangeListener(this); eipStatus.deleteObserver(this); } - - private void initRecyclerView() { recyclerView = getActivity().findViewById(R.id.gatewaySelection_list); recyclerView.setHasFixedSize(true); @@ -162,13 +153,6 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen }).start(); } - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (USE_BRIDGES.equals(key)) { - locationListAdapter.updateData(gatewaysManager.getGatewayLocations()); - } - } - @Override public void onLocationSelected(String name) { startEipService(name); @@ -193,6 +177,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen static class ViewHolder extends RecyclerView.ViewHolder { public AppCompatTextView locationLabel; public LocationIndicator locationIndicator; + public AppCompatImageView bridgeView; public View layout; public ViewHolder(View v) { @@ -200,6 +185,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen layout = v; locationLabel = v.findViewById(R.id.location); locationIndicator = v.findViewById(R.id.quality); + bridgeView = v.findViewById(R.id.bridge_image); } } @@ -246,6 +232,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen } }); holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); + holder.bridgeView.setVisibility(location.supportedTransports.contains(Connection.TransportType.OBFS4) ? VISIBLE : View.GONE); } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java index 8e032d18..3ec7d38c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Location.java @@ -1,16 +1,37 @@ +/** + * Copyright (c) 2021 LEAP Encryption Access Project and contributers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package se.leap.bitmaskclient.base.models; import androidx.annotation.NonNull; +import java.util.HashSet; +import de.blinkt.openvpn.core.connection.Connection; public class Location { @NonNull public String name; + @NonNull public HashSet supportedTransports; public double averageLoad; public int numberOfGateways; - public Location(@NonNull String name, double averageLoad, int numberOfGateways) { + public Location(@NonNull String name, double averageLoad, int numberOfGateways, @NonNull HashSet supportedTransports) { this.name = name; this.averageLoad = averageLoad; this.numberOfGateways = numberOfGateways; + this.supportedTransports = supportedTransports; } @Override @@ -22,7 +43,8 @@ public class Location { if (Double.compare(location.averageLoad, averageLoad) != 0) return false; if (numberOfGateways != location.numberOfGateways) return false; - return name.equals(location.name); + if (!name.equals(location.name)) return false; + return supportedTransports.equals(location.supportedTransports); } @Override @@ -30,6 +52,7 @@ public class Location { int result; long temp; result = name.hashCode(); + result = 31 * result + supportedTransports.hashCode(); temp = Double.doubleToLongBits(averageLoad); result = 31 * result + (int) (temp ^ (temp >>> 32)); result = 31 * result + numberOfGateways; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java index 78b33355..8a48684f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java @@ -195,6 +195,10 @@ public class Gateway { return vpnProfiles.get(transportType) != null; } + public HashSet getSupportedTransports() { + return new HashSet<>(vpnProfiles.keySet()); + } + public int getTimezone() { return timezone; } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java index 33fd3c21..a48cc6d5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaySelector.java @@ -2,6 +2,8 @@ package se.leap.bitmaskclient.eip; import android.util.Log; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -18,7 +20,15 @@ public class GatewaySelector { public GatewaySelector(List gateways) { this.gateways = gateways; this.offsets = calculateOffsets(); + } + public ArrayList getGatewaysSortedByDistance() { + ArrayList list = new ArrayList<>(); + int i = 0; + for (Collection gatewayCollection : offsets.values()) { + list.addAll(gatewayCollection); + } + return list; } public Gateway select() { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 0819e9b6..0b2c2030 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -43,7 +43,6 @@ import de.blinkt.openvpn.core.connection.Connection; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.base.models.ProviderObservable; -import se.leap.bitmaskclient.base.utils.PreferenceHelper; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN; @@ -121,13 +120,20 @@ public class GatewaysManager { return getGatewayFromTimezoneCalculation(nClosest, transportType, city); } + public ArrayList getSortedGateways() { + if (presortedList.size() > 0) { + return presortedList; + } else { + GatewaySelector gatewaySelector = new GatewaySelector(new ArrayList<>(gateways.values())); + return gatewaySelector.getGatewaysSortedByDistance(); + } + } + public List getGatewayLocations() { - String selectedCity = PreferenceHelper.getPreferredCity(context); HashMap locationNames = new HashMap<>(); ArrayList locations = new ArrayList<>(); - int n = 0; - Gateway gateway; - while ((gateway = select(n, null)) != null) { + ArrayList gateways = getSortedGateways(); + for (Gateway gateway : gateways) { String name = gateway.getName(); if (name == null) { Log.e(TAG, "Gateway without location name found. This should never happen. Provider misconfigured?"); @@ -139,23 +145,25 @@ public class GatewaysManager { // fake values for now Random rand = new Random(); double averageLoad = rand.nextDouble(); //location.averageLoad; - Log.d(TAG, "getGatewayLocations - new averageLoad (" + gateway.getName() + "): " + averageLoad); + Log.d(TAG, "getGatewayLocations - new averageLoad (" + gateway.getName() + " - " + gateway.getHost()+ "): " + averageLoad); Location location = new Location( gateway.getName(), averageLoad /*gateway.getFullness()*/, - 1); + 1, + gateway.getSupportedTransports() + ); locations.add(location); } else { int index = locationNames.get(gateway.getName()); Location location = locations.get(index); location.averageLoad = (location.numberOfGateways * location.averageLoad + gateway.getFullness()) / (location.numberOfGateways + 1); - Log.d(TAG, "getGatewayLocations - updated averageLoad: (" + gateway.getName() + "): " + location.averageLoad); + Log.d(TAG, "getGatewayLocations - updated averageLoad: (" + gateway.getName() + " - " + gateway.getHost()+ "): " + location.averageLoad); location.numberOfGateways += 1; + location.supportedTransports.addAll(gateway.getSupportedTransports()); locations.set(index, location); } - n++; } return locations; diff --git a/app/src/main/res/layout/v_select_text_list_item.xml b/app/src/main/res/layout/v_select_text_list_item.xml index 1d7054a4..373de14f 100644 --- a/app/src/main/res/layout/v_select_text_list_item.xml +++ b/app/src/main/res/layout/v_select_text_list_item.xml @@ -16,14 +16,25 @@ tools:visibility="visible" /> + + Date: Fri, 30 Jul 2021 20:38:23 +0200 Subject: ask user to change location or disable bridges if manually selected location doesn't support bridges --- .../se/leap/bitmaskclient/base/MainActivity.java | 13 +++++++-- .../base/fragments/GatewaySelectionFragment.java | 32 ++++++++++++++++++---- .../base/fragments/MainActivityErrorDialog.java | 25 ++++++++++++++++- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 3 +- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 19 +++++++++++-- app/src/main/res/values/untranslatable.xml | 3 ++ 6 files changed, 83 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java index 18ac8b7c..54977f0a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java @@ -60,6 +60,7 @@ import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_LAUNCH_VPN; import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_PREPARE_VPN; import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_START; import static se.leap.bitmaskclient.base.models.Constants.EIP_REQUEST; +import static se.leap.bitmaskclient.base.models.Constants.LOCATION; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY; import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP; import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_LOG_IN; @@ -85,6 +86,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, public final static String ACTION_SHOW_VPN_FRAGMENT = "action_show_vpn_fragment"; public final static String ACTION_SHOW_LOG_FRAGMENT = "action_show_log_fragment"; + public final static String ACTION_SHOW_DIALOG_FRAGMENT = "action_show_dialog_fragment"; /** * Fragment managing the behaviors, interactions and presentation of the navigation drawer. @@ -152,6 +154,13 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, fragment = new LogFragment(); setActionBarTitle(R.string.log_fragment_title); break; + case ACTION_SHOW_DIALOG_FRAGMENT: + if (intent.hasExtra(EIP.ERRORID)) { + String errorId = intent.getStringExtra(EIP.ERRORID); + String error = intent.getStringExtra(EIP.ERRORS); + String args = intent.getStringExtra(LOCATION); + showMainActivityErrorDialog(error, EIP.EIPErrors.valueOf(errorId), args); + } default: break; } @@ -324,12 +333,12 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, /** * Shows an error dialog */ - public void showMainActivityErrorDialog(String reasonToFail, EIP.EIPErrors error) { + public void showMainActivityErrorDialog(String reasonToFail, EIP.EIPErrors error, String... args) { try { FragmentTransaction fragmentTransaction = new FragmentManagerEnhanced( this.getSupportFragmentManager()).removePreviousFragment( MainActivityErrorDialog.TAG); - DialogFragment newFragment = MainActivityErrorDialog.newInstance(provider, reasonToFail, error); + DialogFragment newFragment = MainActivityErrorDialog.newInstance(provider, reasonToFail, error, args); newFragment.show(fragmentTransaction, MainActivityErrorDialog.TAG); } catch (IllegalStateException | NullPointerException e) { e.printStackTrace(); 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 450cba4d..2dcb0ec9 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 @@ -45,16 +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.LocationIndicator; +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.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; interface LocationListSelectionListener { - void onLocationSelected(String name); + void onLocationSelected(Location location); } public class GatewaySelectionFragment extends Fragment implements Observer, LocationListSelectionListener { @@ -154,8 +159,24 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } @Override - public void onLocationSelected(String name) { - startEipService(name); + public void onLocationSelected(Location location) { + String name = location.name; + Connection.TransportType selectedTransport = PreferenceHelper.getUsePluggableTransports(getContext()) ? OBFS4 : OPENVPN; + if (location.supportedTransports.contains(selectedTransport)) { + startEipService(name); + } else { + 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 @@ -168,7 +189,6 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca } } - static class LocationListAdapter extends RecyclerView.Adapter { private static final String TAG = LocationListAdapter.class.getSimpleName(); private List values; @@ -228,11 +248,11 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca Log.d(TAG, "view at position clicked: " + position); LocationListSelectionListener listener = callback.get(); if (listener != null) { - listener.onLocationSelected(location.name); + listener.onLocationSelected(location); } }); holder.locationIndicator.setLoad(GatewaysManager.Load.getLoadByValue(location.averageLoad)); - holder.bridgeView.setVisibility(location.supportedTransports.contains(Connection.TransportType.OBFS4) ? VISIBLE : View.GONE); + holder.bridgeView.setVisibility(location.supportedTransports.contains(OBFS4) ? VISIBLE : View.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 da48effc..f7805002 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,6 +18,8 @@ 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; @@ -27,11 +29,15 @@ import androidx.appcompat.app.AlertDialog; 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.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; @@ -56,6 +62,7 @@ public class MainActivityErrorDialog extends DialogFragment { final private static String KEY_REASON_TO_FAIL = "key reason to fail"; final private static String KEY_PROVIDER = "key provider"; private String reasonToFail; + private String[] args; private EIP.EIPErrors downloadError = UNKNOWN; private Provider provider; @@ -70,11 +77,12 @@ public class MainActivityErrorDialog extends DialogFragment { /** * @return a new instance of this DialogFragment. */ - public static DialogFragment newInstance(Provider provider, String reasonToFail, EIP.EIPErrors error) { + public static DialogFragment newInstance(Provider provider, String reasonToFail, EIP.EIPErrors error, String... args) { MainActivityErrorDialog dialogFragment = new MainActivityErrorDialog(); dialogFragment.reasonToFail = reasonToFail; dialogFragment.provider = provider; dialogFragment.downloadError = error; + dialogFragment.args = args; return dialogFragment; } @@ -150,6 +158,21 @@ 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/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index dd9054f1..a7e08bd7 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -127,7 +127,8 @@ public final class EIP extends JobIntentService implements Observer { ERROR_INVALID_VPN_CERTIFICATE, NO_MORE_GATEWAYS, ERROR_VPN_PREPARE, - ERROR_INVALID_PROFILE + ERROR_INVALID_PROFILE, + TRANSPORT_NOT_SUPPORTED, } /** diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 0b2c2030..dbb2a914 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -96,6 +96,7 @@ public class GatewaysManager { private final LinkedHashMap gateways = new LinkedHashMap<>(); private final Type listType = new TypeToken>() {}.getType(); private final ArrayList presortedList = new ArrayList<>(); + private ArrayList locations = new ArrayList<>(); public GatewaysManager(Context context) { this.context = context; @@ -130,6 +131,10 @@ public class GatewaysManager { } public List getGatewayLocations() { + if (locations.size() > 0) { + return locations; + } + HashMap locationNames = new HashMap<>(); ArrayList locations = new ArrayList<>(); ArrayList gateways = getSortedGateways(); @@ -166,16 +171,26 @@ public class GatewaysManager { } } + this.locations = locations; return locations; } - public Load getLoadForLocation(@Nullable String name) { + @Nullable + public Location getLocation(String name) { List locations = getGatewayLocations(); for (Location location : locations) { if (location.name.equals(name)) { - return Load.getLoadByValue(location.averageLoad); + return location; } } + return null; + } + + public Load getLoadForLocation(@Nullable String name) { + Location location = getLocation(name); + if (location != null) { + return Load.getLoadByValue(location.averageLoad); + } // location not found return Load.UNKNOWN; diff --git a/app/src/main/res/values/untranslatable.xml b/app/src/main/res/values/untranslatable.xml index a08857c1..a288d9a5 100644 --- a/app/src/main/res/values/untranslatable.xml +++ b/app/src/main/res/values/untranslatable.xml @@ -47,6 +47,9 @@ %1$s could not connect to %2$s. Do you want to try to connect automatically with best location? Try best location + %1$s doesn\'t support bridges to circumvent VPN filtering. Do you want to choose a different location or disable bridges? + Disable bridges + Choose different location \ No newline at end of file -- cgit v1.2.3 From 6d3c122bebf0ad4f7dc22d4963dc73dea4248251 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 16:34:09 +0200 Subject: adapt EIP main screen and strings to simply secure proposals --- .../de/blinkt/openvpn/core/OpenVPNService.java | 1 + .../java/de/blinkt/openvpn/core/VpnStatus.java | 10 ++ .../bitmaskclient/base/fragments/EipFragment.java | 39 +++++-- app/src/main/res/layout-port/f_eip.xml | 108 +++++++++++++++++++ app/src/main/res/layout-xlarge-port/f_eip.xml | 119 +++++++++++++++++++++ app/src/main/res/layout-xlarge/f_eip.xml | 61 +++++++---- app/src/main/res/layout/f_eip.xml | 103 ++++++++++++------ app/src/main/res/layout/v_location_button.xml | 3 +- app/src/main/res/values/untranslatable.xml | 8 +- 9 files changed, 391 insertions(+), 61 deletions(-) create mode 100644 app/src/main/res/layout-port/f_eip.xml create mode 100644 app/src/main/res/layout-xlarge-port/f_eip.xml (limited to 'app') diff --git a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 9ed2054e..ae38a59b 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/app/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -377,6 +377,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // connections[n], n>0 gets choosen? Connection connection = mProfile.mConnections[0]; + VpnStatus.setCurrentlyConnectingProfile(mProfile); VpnStatus.logInfo(R.string.building_configration); VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START); diff --git a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java index 8007f7c5..a8fed675 100644 --- a/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/app/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -48,6 +48,7 @@ public class VpnStatus { final static java.lang.Object readFileLock = new Object(); private static VpnProfile lastConnectedProfile; + private static VpnProfile currentlyConnectingProfile; public static TrafficHistory trafficHistory; @@ -170,6 +171,15 @@ public class VpnStatus { } + public static void setCurrentlyConnectingProfile(VpnProfile connectingProfile) { + currentlyConnectingProfile = connectingProfile; + } + + public static String getCurrentlyConnectingVpnName() { + return currentlyConnectingProfile != null ? currentlyConnectingProfile.mName : null; + } + + public static String getLastConnectedVpnName() { return lastConnectedProfile != null ? lastConnectedProfile.mName : null; } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index af34b7a5..e9402468 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -39,6 +39,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.AppCompatImageView; +import androidx.appcompat.widget.AppCompatTextView; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; @@ -50,6 +51,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.Unbinder; +import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConnectionStatus; import de.blinkt.openvpn.core.IOpenVPNServiceInternal; import de.blinkt.openvpn.core.OpenVPNService; @@ -84,6 +86,7 @@ import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_LOG_IN; import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_SWITCH_PROVIDER; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.utils.ConfigHelper.isDefaultBitmask; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; import static se.leap.bitmaskclient.base.utils.ViewHelper.convertDimensionToPx; import static se.leap.bitmaskclient.eip.EipSetupObserver.gatewayOrder; import static se.leap.bitmaskclient.eip.EipSetupObserver.reconnectingWithDifferentGateway; @@ -109,6 +112,12 @@ public class EipFragment extends Fragment implements Observer { @BindView(R.id.gateway_location_button) LocationButton locationButton; + @BindView(R.id.main_description) + AppCompatTextView mainDescription; + + @BindView(R.id.sub_description) + AppCompatTextView subDescription; + private Unbinder unbinder; private EipStatus eipStatus; @@ -408,21 +417,20 @@ public class EipFragment extends Fragment implements Observer { return; } - //Log.d(TAG, "eip fragment eipStatus state: " + eipStatus.getState() + " - level: " + eipStatus.getLevel() + " - is reconnecting: " + eipStatus.isReconnecting()); - - + Log.d(TAG, "eip fragment eipStatus state: " + eipStatus.getState() + " - level: " + eipStatus.getLevel() + " - is reconnecting: " + eipStatus.isReconnecting()); if (eipStatus.isConnecting() ) { setMainButtonEnabled(true); showConnectingLayout(activity); if (eipStatus.isReconnecting()) { - locationButton.setText(getString(R.string.reconnecting)); + subDescription.setText(getString(R.string.reconnecting)); } else { - locationButton.setText(getString(R.string.finding_best_connection)); + subDescription.setText(R.string.connection_not_connected); } + locationButton.setText(getString(R.string.finding_best_connection)); + mainDescription.setText(R.string.eip_state_insecure); locationButton.setVisibility(VISIBLE); locationButton.setLocationLoad(UNKNOWN); - } else if (eipStatus.isConnected() ) { - locationButton.setText(activity.getString(R.string.vpn_button_turn_off)); + } else if (eipStatus.isConnected()) { setMainButtonEnabled(true); vpnStateImage.setStateIcon(R.drawable.vpn_connected); vpnStateImage.stopProgress(false); @@ -430,23 +438,34 @@ public class EipFragment extends Fragment implements Observer { locationButton.setText(VpnStatus.getLastConnectedVpnName()); locationButton.setVisibility(VISIBLE); colorBackground(); + mainDescription.setText(R.string.eip_state_connected); + subDescription.setText(getPreferredCity(getContext()) == null ? + R.string.eip_state_connected_recommended : + R.string.eip_state_connected_manual); } else if(isOpenVpnRunningWithoutNetwork()){ - locationButton.setText(activity.getString(R.string.vpn_button_turn_off)); + Log.d(TAG, "eip fragment eipStatus - isOpenVpnRunningWithoutNetwork"); setMainButtonEnabled(true); vpnStateImage.setStateIcon(R.drawable.vpn_disconnected); vpnStateImage.stopProgress(false); locationButton.setVisibility(VISIBLE); + locationButton.setText(VpnStatus.getCurrentlyConnectingVpnName()); setVpnRouteText(); colorBackgroundALittle(); + mainDescription.setText(R.string.eip_state_insecure); + subDescription.setText(R.string.eip_state_no_network); } else if (eipStatus.isDisconnected() && reconnectingWithDifferentGateway()) { showConnectingLayout(activity); // showRetryToast(activity); locationButton.setText(getString(R.string.finding_best_connection)); locationButton.setVisibility(VISIBLE); locationButton.setLocationLoad(UNKNOWN); + mainDescription.setText(R.string.eip_state_insecure); + subDescription.setText(R.string.reconnecting); } else if (eipStatus.isDisconnecting()) { setMainButtonEnabled(false); showDisconnectingLayout(activity); + mainDescription.setText(R.string.eip_state_insecure); + subDescription.setText(R.string.connection_not_connected); } else if (eipStatus.isBlocking()) { setMainButtonEnabled(true); vpnStateImage.setStateIcon(R.drawable.vpn_blocking); @@ -455,6 +474,8 @@ public class EipFragment extends Fragment implements Observer { locationButton.setText(getString(R.string.finding_best_connection)); locationButton.setVisibility(VISIBLE); locationButton.setLocationLoad(UNKNOWN); + mainDescription.setText(R.string.eip_state_connected); + subDescription.setText(R.string.eip_state_blocking); } else { locationButton.setText(activity.getString(R.string.vpn_button_turn_on)); setMainButtonEnabled(true); @@ -463,6 +484,8 @@ public class EipFragment extends Fragment implements Observer { greyscaleBackground(); locationButton.setLocationLoad(UNKNOWN); locationButton.setVisibility(GONE); + mainDescription.setText(R.string.eip_state_insecure); + subDescription.setText(R.string.connection_not_connected); } } diff --git a/app/src/main/res/layout-port/f_eip.xml b/app/src/main/res/layout-port/f_eip.xml new file mode 100644 index 00000000..4dae126c --- /dev/null +++ b/app/src/main/res/layout-port/f_eip.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-xlarge-port/f_eip.xml b/app/src/main/res/layout-xlarge-port/f_eip.xml new file mode 100644 index 00000000..5325d6a6 --- /dev/null +++ b/app/src/main/res/layout-xlarge-port/f_eip.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-xlarge/f_eip.xml b/app/src/main/res/layout-xlarge/f_eip.xml index bef2d635..8ed9a57c 100644 --- a/app/src/main/res/layout-xlarge/f_eip.xml +++ b/app/src/main/res/layout-xlarge/f_eip.xml @@ -1,4 +1,8 @@ + @@ -34,7 +38,7 @@ android:orientation="horizontal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintRight_toRightOf="parent" - app:layout_constraintGuide_percent="0.7" + app:layout_constraintGuide_percent="0.66" /> - - + + + + + app:layout_constraintGuide_percent="0.1" + app:layout_constraintRight_toRightOf="parent" /> + app:layout_constraintGuide_percent="0.3" /> + + + + + app:layout_constraintGuide_percent="0.7" /> - - - + + + + diff --git a/app/src/main/res/layout/v_location_button.xml b/app/src/main/res/layout/v_location_button.xml index 9e5445a4..d8eed9a3 100644 --- a/app/src/main/res/layout/v_location_button.xml +++ b/app/src/main/res/layout/v_location_button.xml @@ -6,11 +6,10 @@ android:layout_gravity="center_vertical" android:padding="@dimen/stdpadding" android:background="@drawable/cust_button_primary_rect" - android:layout_height="wrap_content"> + android:layout_height="match_parent"> %1$s doesn\'t support bridges to circumvent VPN filtering. Do you want to choose a different location or disable bridges? Disable bridges Choose different location - + Connection Insecure + You are connected to the recommended location + You are connected to + Connecting... + You may be leaking information to your internet provider or local network. + You have no working Internet connection. Once you get it back, you will be automatically connected to + %1$s is blocking all internet traffic. \ No newline at end of file -- cgit v1.2.3 From 033ac24155bf9b56fbf8a247ab582ecd2b934e9a Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:32:01 +0200 Subject: initial implementation of classic on-off push button --- .../bitmaskclient/base/fragments/EipFragment.java | 27 +++++++--------------- app/src/main/res/drawable/ic_btn_on_connecting.xml | 22 ++++++++++++++++++ app/src/main/res/drawable/ic_btn_on_disabled.xml | 20 ++++++++++++++++ .../main/res/drawable/ic_btn_on_primary_color.xml | 22 ++++++++++++++++++ app/src/main/res/layout/v_main_button.xml | 14 +++++++---- 5 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 app/src/main/res/drawable/ic_btn_on_connecting.xml create mode 100644 app/src/main/res/drawable/ic_btn_on_disabled.xml create mode 100644 app/src/main/res/drawable/ic_btn_on_primary_color.xml (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index e9402468..3650804f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -27,7 +27,6 @@ import android.graphics.ColorMatrixColorFilter; import android.os.Bundle; import android.os.IBinder; import android.os.Vibrator; -import android.text.TextUtils; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; @@ -51,7 +50,6 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.Unbinder; -import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ConnectionStatus; import de.blinkt.openvpn.core.IOpenVPNServiceInternal; import de.blinkt.openvpn.core.OpenVPNService; @@ -420,7 +418,7 @@ public class EipFragment extends Fragment implements Observer { Log.d(TAG, "eip fragment eipStatus state: " + eipStatus.getState() + " - level: " + eipStatus.getLevel() + " - is reconnecting: " + eipStatus.isReconnecting()); if (eipStatus.isConnecting() ) { setMainButtonEnabled(true); - showConnectingLayout(activity); + showConnectionTransitionLayout(true); if (eipStatus.isReconnecting()) { subDescription.setText(getString(R.string.reconnecting)); } else { @@ -432,7 +430,7 @@ public class EipFragment extends Fragment implements Observer { locationButton.setLocationLoad(UNKNOWN); } else if (eipStatus.isConnected()) { setMainButtonEnabled(true); - vpnStateImage.setStateIcon(R.drawable.vpn_connected); + vpnStateImage.setStateIcon(R.drawable.ic_btn_on_primary_color); vpnStateImage.stopProgress(false); locationButton.setLocationLoad(gatewaysManager.getLoadForLocation(VpnStatus.getLastConnectedVpnName())); locationButton.setText(VpnStatus.getLastConnectedVpnName()); @@ -445,16 +443,15 @@ public class EipFragment extends Fragment implements Observer { } else if(isOpenVpnRunningWithoutNetwork()){ Log.d(TAG, "eip fragment eipStatus - isOpenVpnRunningWithoutNetwork"); setMainButtonEnabled(true); - vpnStateImage.setStateIcon(R.drawable.vpn_disconnected); + vpnStateImage.setStateIcon(R.drawable.ic_btn_on_primary_color); vpnStateImage.stopProgress(false); locationButton.setVisibility(VISIBLE); locationButton.setText(VpnStatus.getCurrentlyConnectingVpnName()); - setVpnRouteText(); colorBackgroundALittle(); mainDescription.setText(R.string.eip_state_insecure); subDescription.setText(R.string.eip_state_no_network); } else if (eipStatus.isDisconnected() && reconnectingWithDifferentGateway()) { - showConnectingLayout(activity); + showConnectionTransitionLayout(true); // showRetryToast(activity); locationButton.setText(getString(R.string.finding_best_connection)); locationButton.setVisibility(VISIBLE); @@ -463,12 +460,12 @@ public class EipFragment extends Fragment implements Observer { subDescription.setText(R.string.reconnecting); } else if (eipStatus.isDisconnecting()) { setMainButtonEnabled(false); - showDisconnectingLayout(activity); + showConnectionTransitionLayout(false); mainDescription.setText(R.string.eip_state_insecure); subDescription.setText(R.string.connection_not_connected); } else if (eipStatus.isBlocking()) { setMainButtonEnabled(true); - vpnStateImage.setStateIcon(R.drawable.vpn_blocking); + vpnStateImage.setStateIcon(R.drawable.ic_btn_on_primary_color); vpnStateImage.stopProgress(false); colorBackgroundALittle(); locationButton.setText(getString(R.string.finding_best_connection)); @@ -518,16 +515,8 @@ public class EipFragment extends Fragment implements Observer { showToast(activity, message, true ); } - private void showConnectingLayout(Context activity) { - showConnectionTransitionLayout(activity, true); - } - - private void showDisconnectingLayout(Activity activity) { - showConnectionTransitionLayout(activity, false); - } - - private void showConnectionTransitionLayout(Context activity, boolean isConnecting) { - vpnStateImage.setStateIcon(R.drawable.vpn_connecting); + private void showConnectionTransitionLayout(boolean isConnecting) { + vpnStateImage.setStateIcon(R.drawable.ic_btn_on_connecting); vpnStateImage.showProgress(); if (isConnecting) { colorBackgroundALittle(); diff --git a/app/src/main/res/drawable/ic_btn_on_connecting.xml b/app/src/main/res/drawable/ic_btn_on_connecting.xml new file mode 100644 index 00000000..4b3d1384 --- /dev/null +++ b/app/src/main/res/drawable/ic_btn_on_connecting.xml @@ -0,0 +1,22 @@ + + + + diff --git a/app/src/main/res/drawable/ic_btn_on_disabled.xml b/app/src/main/res/drawable/ic_btn_on_disabled.xml new file mode 100644 index 00000000..9c83422d --- /dev/null +++ b/app/src/main/res/drawable/ic_btn_on_disabled.xml @@ -0,0 +1,20 @@ + + + + diff --git a/app/src/main/res/drawable/ic_btn_on_primary_color.xml b/app/src/main/res/drawable/ic_btn_on_primary_color.xml new file mode 100644 index 00000000..9f449299 --- /dev/null +++ b/app/src/main/res/drawable/ic_btn_on_primary_color.xml @@ -0,0 +1,22 @@ + + + + diff --git a/app/src/main/res/layout/v_main_button.xml b/app/src/main/res/layout/v_main_button.xml index d8ae211c..741fc88f 100644 --- a/app/src/main/res/layout/v_main_button.xml +++ b/app/src/main/res/layout/v_main_button.xml @@ -102,6 +102,7 @@ app:layout_constraintEnd_toEndOf="@id/border_guideline_right" app:layout_constraintStart_toStartOf="@id/border_guideline_left" app:layout_constraintTop_toTopOf="@id/border_guideline_top" + app:layout_constraintDimensionRatio="1:1" android:indeterminate="true" android:indeterminateDuration="800" android:indeterminateDrawable="@drawable/progressbar_circle" @@ -117,16 +118,19 @@ app:layout_constraintEnd_toStartOf="@+id/vpn_btn_guideline_right" app:layout_constraintStart_toStartOf="@+id/vpn_btn_guideline_left" app:layout_constraintTop_toTopOf="@+id/vpn_btn_guideline_top" + app:layout_constraintDimensionRatio="1:1" app:srcCompat="@drawable/black_circle" /> + app:layout_constraintBottom_toTopOf="@+id/icn_guideline_bottom" + app:layout_constraintEnd_toStartOf="@+id/icn_guideline_right" + app:layout_constraintStart_toStartOf="@+id/icn_guideline_left" + app:layout_constraintTop_toTopOf="@+id/icn_guideline_top" + app:layout_constraintDimensionRatio="1:1" + app:layout_constraintVertical_bias="0.35" + app:srcCompat="@drawable/ic_btn_on_disabled" /> \ No newline at end of file -- cgit v1.2.3 From 7d56739d95eb5e8552e13f102246af2f6c13101b Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:32:26 +0200 Subject: adapt bitmask background --- app/src/normal/res/drawable/background_eip.xml | 66 +++++++++++++------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'app') diff --git a/app/src/normal/res/drawable/background_eip.xml b/app/src/normal/res/drawable/background_eip.xml index 4b60e9dc..770a71d9 100644 --- a/app/src/normal/res/drawable/background_eip.xml +++ b/app/src/normal/res/drawable/background_eip.xml @@ -1,52 +1,52 @@ - - - - - - - - - + + + + + + + + + -- cgit v1.2.3 From a82d85c3f8ed72597c4a8da77c816501f5f6d47d Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:33:39 +0200 Subject: avoid layout jumping --- .../main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index 3650804f..7456fcc9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -70,7 +70,7 @@ import se.leap.bitmaskclient.providersetup.activities.CustomProviderSetupActivit import se.leap.bitmaskclient.providersetup.activities.LoginActivity; import se.leap.bitmaskclient.providersetup.models.LeapSRPSession; -import static android.view.View.GONE; +import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK; import static se.leap.bitmaskclient.R.string.vpn_certificate_user_message; @@ -480,7 +480,7 @@ public class EipFragment extends Fragment implements Observer { vpnStateImage.stopProgress(false); greyscaleBackground(); locationButton.setLocationLoad(UNKNOWN); - locationButton.setVisibility(GONE); + locationButton.setVisibility(INVISIBLE); mainDescription.setText(R.string.eip_state_insecure); subDescription.setText(R.string.connection_not_connected); } -- cgit v1.2.3 From 5eef2b3f995b48d0f993947dc28876c29f86421b Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:34:08 +0200 Subject: add missing vpn button state --- app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index 7456fcc9..2f50d258 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -476,7 +476,7 @@ public class EipFragment extends Fragment implements Observer { } else { locationButton.setText(activity.getString(R.string.vpn_button_turn_on)); setMainButtonEnabled(true); - vpnStateImage.setStateIcon(R.drawable.vpn_disconnected); + vpnStateImage.setStateIcon(R.drawable.ic_btn_on_disabled); vpnStateImage.stopProgress(false); greyscaleBackground(); locationButton.setLocationLoad(UNKNOWN); -- cgit v1.2.3 From a874ed7362f124900b9c8ea325f80393f0ba680e Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:34:26 +0200 Subject: cleanup --- .../java/se/leap/bitmaskclient/base/fragments/EipFragment.java | 9 --------- 1 file changed, 9 deletions(-) (limited to 'app') diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index 2f50d258..ef16d085 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -587,15 +587,6 @@ public class EipFragment extends Fragment implements Observer { } } - private void setVpnRouteText() { - String vpnRouteString = provider.getName(); - String profileName = VpnStatus.getLastConnectedVpnName(); - if (!TextUtils.isEmpty(profileName)) { - vpnRouteString += " (" + profileName + ")"; - } - // vpnRoute.setText(vpnRouteString); - } - private class EipFragmentServiceConnection implements ServiceConnection { @Override public void onServiceConnected(ComponentName className, -- cgit v1.2.3 From 41cb3b4adb137b9a1e0affea42e7f4e9cfa1d7dd Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:45:00 +0200 Subject: remove some padding in gateway selection fragment --- app/src/main/res/layout/f_gateway_selection.xml | 1 - 1 file changed, 1 deletion(-) (limited to 'app') diff --git a/app/src/main/res/layout/f_gateway_selection.xml b/app/src/main/res/layout/f_gateway_selection.xml index 5a384163..70a2bb1d 100644 --- a/app/src/main/res/layout/f_gateway_selection.xml +++ b/app/src/main/res/layout/f_gateway_selection.xml @@ -35,7 +35,6 @@ android:layout_height="wrap_content" android:gravity="center" android:textAppearance="?android:attr/textAppearanceLarge" - android:paddingTop="@dimen/activity_vertical_margin" android:paddingStart="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingEnd="@dimen/activity_horizontal_margin" -- cgit v1.2.3 From 1f8b9f9c65a60de9813c77344bdba0fa8153cb62 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 18:48:06 +0200 Subject: add missing eip status observer registration in GatewaySelectionFragment --- .../se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java | 1 + 1 file changed, 1 insertion(+) (limited to 'app') 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 2dcb0ec9..c0b9d2d4 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 @@ -84,6 +84,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca super.onCreate(savedInstanceState); gatewaysManager = new GatewaysManager(getContext()); eipStatus = EipStatus.getInstance(); + eipStatus.addObserver(this); } @Override -- cgit v1.2.3 From a2067cd5b56387405cb653de8940e7afc448449d Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 19:30:54 +0200 Subject: Add BuildConfig to disable color filtering of the main screen background, if VPN is turned off. Make EipFragment's text colors customizable --- app/build.gradle | 4 ++++ app/src/custom/res/values/custom-theme.xml | 7 ++++-- .../bitmaskclient/base/fragments/EipFragment.java | 25 ++++++++++++++-------- app/src/main/res/layout-port/f_eip.xml | 2 ++ app/src/main/res/layout-xlarge-port/f_eip.xml | 2 ++ app/src/main/res/layout-xlarge/f_eip.xml | 2 ++ app/src/main/res/layout/f_eip.xml | 3 ++- app/src/main/res/values/colors.xml | 1 + 8 files changed, 34 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/build.gradle b/app/build.gradle index 6db23476..8fcd9e90 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,6 +37,8 @@ android { buildConfigField 'boolean', 'priotize_anonymous_usage', 'false' //allow manual gateway selection buildConfigField 'boolean', 'allow_manual_gateway_selection', 'true' + // grey out background in EipFragment (main screen) if VPN is not running + buildConfigField 'boolean', 'use_color_filter', 'true' // static update url pointing to the latest stable release apk buildConfigField "String", "update_apk_url", '"https://dl.bitmask.net/client/android/Bitmask-Android-latest.apk"' @@ -118,6 +120,8 @@ android { buildConfigField 'boolean', 'priotize_anonymous_usage', 'true' //allow manual gateway selection buildConfigField 'boolean', 'allow_manual_gateway_selection', 'true' + // grey out background in EipFragment (main screen) if VPN is not running + buildConfigField 'boolean', 'use_color_filter', 'false' //Build Config Fields for automatic apk update checks diff --git a/app/src/custom/res/values/custom-theme.xml b/app/src/custom/res/values/custom-theme.xml index 1c8f1ab2..71d22ac6 100644 --- a/app/src/custom/res/values/custom-theme.xml +++ b/app/src/custom/res/values/custom-theme.xml @@ -2,11 +2,14 @@ - #5e9ee3 + #2E639C - #5c7ce1 + #021122 #ffffff #cccccc + + #ffffff + diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index ef16d085..d8be1cc5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -54,6 +54,7 @@ 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 se.leap.bitmaskclient.BuildConfig; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.FragmentManagerEnhanced; import se.leap.bitmaskclient.base.MainActivity; @@ -552,21 +553,27 @@ public class EipFragment extends Fragment implements Observer { } private void greyscaleBackground() { - ColorMatrix matrix = new ColorMatrix(); - matrix.setSaturation(0); - ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix); - background.setColorFilter(cf); - background.setImageAlpha(255); + if (BuildConfig.use_color_filter) { + ColorMatrix matrix = new ColorMatrix(); + matrix.setSaturation(0); + ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix); + background.setColorFilter(cf); + background.setImageAlpha(255); + } } private void colorBackgroundALittle() { - background.setColorFilter(null); - background.setImageAlpha(144); + if (BuildConfig.use_color_filter) { + background.setColorFilter(null); + background.setImageAlpha(144); + } } private void colorBackground() { - background.setColorFilter(null); - background.setImageAlpha(210); + if (BuildConfig.use_color_filter) { + background.setColorFilter(null); + background.setImageAlpha(210); + } } private void updateInvalidVpnCertificate() { diff --git a/app/src/main/res/layout-port/f_eip.xml b/app/src/main/res/layout-port/f_eip.xml index 4dae126c..03401d16 100644 --- a/app/src/main/res/layout-port/f_eip.xml +++ b/app/src/main/res/layout-port/f_eip.xml @@ -65,6 +65,7 @@ android:padding="@dimen/activity_margin" android:textAppearance="@android:style/TextAppearance.Large" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" app:layout_constraintDimensionRatio="1:1" tools:text="CONNETION" android:gravity="center" @@ -82,6 +83,7 @@ android:padding="@dimen/activity_margin" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" app:layout_constraintDimensionRatio="1:1" tools:text="A LONG TEXT WITH SEVERAL THINGS BLABLkk \n kdjfkj \n kjdfkjdf" android:gravity="center" diff --git a/app/src/main/res/layout-xlarge-port/f_eip.xml b/app/src/main/res/layout-xlarge-port/f_eip.xml index 5325d6a6..6a115a8b 100644 --- a/app/src/main/res/layout-xlarge-port/f_eip.xml +++ b/app/src/main/res/layout-xlarge-port/f_eip.xml @@ -76,6 +76,7 @@ android:padding="@dimen/activity_margin" android:textAppearance="@android:style/TextAppearance.Large" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" app:layout_constraintDimensionRatio="1:1" tools:text="CONNETION" android:gravity="center" @@ -93,6 +94,7 @@ android:padding="@dimen/activity_margin" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" app:layout_constraintDimensionRatio="1:1" tools:text="A LONG TEXT WITH SEVERAL THINGS BLABLkk" android:gravity="center" diff --git a/app/src/main/res/layout-xlarge/f_eip.xml b/app/src/main/res/layout-xlarge/f_eip.xml index 8ed9a57c..1ea7ba4b 100644 --- a/app/src/main/res/layout-xlarge/f_eip.xml +++ b/app/src/main/res/layout-xlarge/f_eip.xml @@ -80,6 +80,7 @@ android:padding="@dimen/stdpadding" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" app:layout_constraintDimensionRatio="1:1" tools:text="CONNETION SECURE" android:maxLines="1" @@ -96,6 +97,7 @@ android:padding="@dimen/stdpadding" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" app:layout_constraintDimensionRatio="1:1" android:maxLines="5" android:ellipsize="end" diff --git a/app/src/main/res/layout/f_eip.xml b/app/src/main/res/layout/f_eip.xml index 0cefcd6c..e3e8fe0a 100644 --- a/app/src/main/res/layout/f_eip.xml +++ b/app/src/main/res/layout/f_eip.xml @@ -97,6 +97,7 @@ android:paddingEnd="@dimen/stdpadding" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" app:layout_constraintDimensionRatio="1:1" tools:text="CONNETION SECURE" /> @@ -111,12 +112,12 @@ app:layout_constraintBottom_toTopOf="@+id/gateway_location_button" android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" android:textStyle="bold" + android:textColor="@color/colorEipFragmentFont" android:paddingLeft="@dimen/stdpadding" android:paddingStart="@dimen/stdpadding" android:paddingRight="@dimen/stdpadding" android:paddingEnd="@dimen/stdpadding" android:paddingBottom="@dimen/stdpadding" - app:layout_constraintDimensionRatio="1:1" tools:text="Your traffic is securly routed through \n another" android:maxLines="2" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index a8cdb28e..e911a6d1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -34,6 +34,7 @@ @color/white @color/black800 + @color/black800 #B33A3A -- cgit v1.2.3 From 41fbc2f409d5438fcc3ce51d5679888d0c8df7a3 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 31 Jul 2021 19:42:41 +0200 Subject: disable GatewaysManager tests checking average gateway load, because currently we fake the values --- .../java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java index 08591b6d..27bfdb34 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -345,7 +345,10 @@ public class GatewaysManagerTest { assertNull(gatewaysManager.select(0, "Stockholm")); } - @Test + /* + This test is disabled since we fake load values in gateway manager with randomized numbers. + */ + /* @Test public void testGetLocations_openvpn() { Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", "v4/riseup_geoip_v4.json"); @@ -364,9 +367,12 @@ public class GatewaysManagerTest { assertEquals(averageLoad, location.averageLoad); } } - } + } */ - @Test + /* + This test is disabled since we fake load values in gateway manager with randomized numbers. + */ + /*@Test public void testGetLocations_obfs4() { Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", "v4/riseup_geoip_v4.json"); @@ -390,6 +396,7 @@ public class GatewaysManagerTest { } } + */ private String getJsonStringFor(String filename) throws IOException { -- cgit v1.2.3 From 739e0f16c80da1bad574890d6d8c8f09fa7bbbc0 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 1 Aug 2021 00:50:06 +0200 Subject: make button text color customizable --- app/src/custom/res/values/custom-theme.xml | 2 ++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/styles.xml | 1 + 3 files changed, 4 insertions(+) (limited to 'app') diff --git a/app/src/custom/res/values/custom-theme.xml b/app/src/custom/res/values/custom-theme.xml index 71d22ac6..6d2bf0f8 100644 --- a/app/src/custom/res/values/custom-theme.xml +++ b/app/src/custom/res/values/custom-theme.xml @@ -11,5 +11,7 @@ #cccccc #ffffff + + #ffffff diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e911a6d1..86ac1128 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -35,6 +35,7 @@ @color/white @color/black800 @color/black800 + @color/black800 #B33A3A diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index b8c0bc59..9b05d3fe 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -65,6 +65,7 @@ @drawable/cust_button_primary 36dp 75dp + @color/colorFontBtn