summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-10-19 02:19:44 +0200
committercyBerta <cyberta@riseup.net>2019-10-19 02:19:44 +0200
commit313627f7e8e174fab3df063905445af370deb26e (patch)
treeb3627a507fb1216178103de70e9cf506c61a0bc7 /app
parent76fb364ec44496f9aca3e58b01fdb6a0957b0940 (diff)
select next PT supporting Gateway if shapeshifter reports errors for the current one
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java30
1 files changed, 28 insertions, 2 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
index 92e3e1a4..7ded9069 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
@@ -16,13 +16,16 @@ import java.util.concurrent.atomic.AtomicInteger;
import de.blinkt.openvpn.LaunchVPN;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConnectionStatus;
+import de.blinkt.openvpn.core.LogItem;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.Gateway;
+import se.leap.bitmaskclient.eip.GatewaysManager;
import se.leap.bitmaskclient.utils.PreferenceHelper;
import static android.app.Activity.RESULT_CANCELED;
+import static android.content.Context.MODE_PRIVATE;
import static android.content.Intent.CATEGORY_DEFAULT;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NOTCONNECTED;
@@ -44,7 +47,7 @@ import static se.leap.bitmaskclient.utils.PreferenceHelper.getSavedProviderFromS
/**
* Created by cyberta on 05.12.18.
*/
-class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListener {
+class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListener, VpnStatus.LogListener {
private static final String TAG = EipSetupObserver.class.getName();
@@ -69,6 +72,7 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
updateIntentFilter.addCategory(CATEGORY_DEFAULT);
LocalBroadcastManager.getInstance(context.getApplicationContext()).registerReceiver(this, updateIntentFilter);
instance = this;
+ VpnStatus.addLogListener(this);
}
public static void init(Context context, SharedPreferences preferences) {
@@ -243,7 +247,7 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
//saveLastProfile(context.getApplicationContext(), setupVpnProfile.getUUIDString());
if (setupNClosestGateway.get() > 0) {
//at least one failed gateway -> did the provider change it's gateways?
- SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
+ SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
Provider provider = getSavedProviderFromSharedPreferences(preferences);
ProviderAPICommand.execute(context, ProviderAPI.DOWNLOAD_SERVICE_JSON, provider);
}
@@ -277,4 +281,26 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
public void setConnectedVPN(String uuid) {
observedProfileFromVpnStatus = uuid;
}
+
+ @Override
+ public void newLog(LogItem logItem) {
+ if (logItem.getLogLevel() == VpnStatus.LogLevel.ERROR) {
+ switch (logItem.getErrorType()) {
+ case SHAPESHIFTER:
+ VpnProfile profile = VpnStatus.getLastConnectedVpnProfile();
+ if (profile == null) {
+ EipCommand.startVPN(context.getApplicationContext(), false, 0);
+ } else {
+ GatewaysManager gatewaysManager = new GatewaysManager(context.getApplicationContext());
+ int position = gatewaysManager.getPosition(profile);
+ setupNClosestGateway.set(position >= 0 ? position : 0);
+ selectNextGateway();
+ }
+ break;
+ default:
+ break;
+
+ }
+ }
+ }
}