diff options
5 files changed, 25 insertions, 5 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java index e79946bf..fc91d7e4 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderApiManager.java @@ -187,6 +187,7 @@ public class ProviderApiManager extends ProviderApiManagerBase { setErrorResult(result, eipServiceJsonString); } else{ provider.setEipServiceJson(eipServiceJson); + provider.setLastEipServiceUpdate(System.currentTimeMillis()); result.putBoolean(BROADCAST_RESULT_KEY, true); } } catch (NullPointerException | JSONException e) { diff --git a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java index 1a0214dd..eceba0db 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java @@ -141,6 +141,7 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe Provider provider; switch (resultCode) { case CORRECTLY_DOWNLOADED_EIP_SERVICE: + Log.d(TAG, "correctly updated service json"); provider = resultData.getParcelable(PROVIDER_KEY); ProviderObservable.getInstance().updateProvider(provider); PreferenceHelper.storeProviderInPreferences(preferences, provider); @@ -269,10 +270,9 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe //?? } else if ("CONNECTED".equals(state)) { //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, MODE_PRIVATE); - Provider provider = getSavedProviderFromSharedPreferences(preferences); + Provider provider = ProviderObservable.getInstance().getCurrentProvider(); + if (setupNClosestGateway.get() > 0 || provider.shouldUpdateEipServiceJson()) { + //setupNClostestGateway > 0: at least one failed gateway -> did the provider change it's gateways? ProviderAPICommand.execute(context, ProviderAPI.DOWNLOAD_SERVICE_JSON, provider); } finishGatewaySetup(false); diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index 067f9b2e..507a11bf 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -44,6 +44,7 @@ import static se.leap.bitmaskclient.ProviderAPI.ERRORS; */ public final class Provider implements Parcelable { + private static long EIP_SERVICE_TIMEOUT = 1000 * 60 * 60 * 24 * 3; private JSONObject definition = new JSONObject(); // Represents our Provider's provider.json private JSONObject eipServiceJson = new JSONObject(); private DefaultedURL mainUrl = new DefaultedURL(); @@ -54,6 +55,7 @@ public final class Provider implements Parcelable { private String apiVersion = ""; private String privateKey = ""; private String vpnCertificate = ""; + private long lastEipServiceUpdate = 0L; private boolean allowAnonymous; private boolean allowRegistered; @@ -268,6 +270,7 @@ public final class Provider implements Parcelable { parcel.writeString(getEipServiceJsonString()); parcel.writeString(getPrivateKey()); parcel.writeString(getVpnCertificate()); + parcel.writeLong(lastEipServiceUpdate); } @Override @@ -286,7 +289,8 @@ public final class Provider implements Parcelable { privateKey.equals(p.getPrivateKey()) && vpnCertificate.equals(p.getVpnCertificate()) && allowAnonymous == p.allowsAnonymous() && - allowRegistered == p.allowsRegistered(); + allowRegistered == p.allowsRegistered() && + lastEipServiceUpdate == p.getLastEipServiceUpdate(); } else return false; } @@ -336,6 +340,7 @@ public final class Provider implements Parcelable { if (!tmpString.isEmpty()) { this.setVpnCertificate(tmpString); } + this.lastEipServiceUpdate = in.readLong(); } catch (MalformedURLException | JSONException e) { e.printStackTrace(); } @@ -368,6 +373,18 @@ public final class Provider implements Parcelable { return allowRegistered; } + public void setLastEipServiceUpdate(long timestamp) { + lastEipServiceUpdate = timestamp; + } + + public long getLastEipServiceUpdate() { + return lastEipServiceUpdate; + } + + public boolean shouldUpdateEipServiceJson() { + return System.currentTimeMillis() - lastEipServiceUpdate >= EIP_SERVICE_TIMEOUT; + } + public boolean setEipServiceJson(JSONObject eipServiceJson) { if (eipServiceJson.has(ERRORS)) { return false; diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java index 46782802..0baa4e0d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java @@ -216,6 +216,7 @@ public abstract class ProviderApiManagerBase { } break; case DOWNLOAD_SERVICE_JSON: + Log.d(TAG, "update eip service json"); result = getAndSetEipServiceJson(provider); if (result.getBoolean(BROADCAST_RESULT_KEY)) { sendToReceiverOrBroadcast(receiver, CORRECTLY_DOWNLOADED_EIP_SERVICE, result, provider); diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java index 10582cf3..41a63ad7 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderApiManager.java @@ -174,6 +174,7 @@ public class ProviderApiManager extends ProviderApiManagerBase { setErrorResult(result, eipServiceJsonString); } else { provider.setEipServiceJson(eipServiceJson); + provider.setLastEipServiceUpdate(System.currentTimeMillis()); result.putBoolean(BROADCAST_RESULT_KEY, true); } } catch (NullPointerException | JSONException e) { |