summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadBroadcastReceiver.java6
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Constants.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java9
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java19
4 files changed, 30 insertions, 5 deletions
diff --git a/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadBroadcastReceiver.java b/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadBroadcastReceiver.java
index f410b9ff..4719737b 100644
--- a/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadBroadcastReceiver.java
+++ b/app/src/fatweb/java/se.leap.bitmaskclient/appUpdate/DownloadBroadcastReceiver.java
@@ -20,14 +20,13 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
-import android.util.Log;
import android.widget.Toast;
import java.io.File;
import se.leap.bitmaskclient.Constants;
import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.utils.ConfigHelper;
+import se.leap.bitmaskclient.utils.PreferenceHelper;
import static android.app.Activity.RESULT_CANCELED;
import static se.leap.bitmaskclient.Constants.BROADCAST_DOWNLOAD_SERVICE_EVENT;
@@ -53,7 +52,6 @@ public class DownloadBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- Log.d(TAG, "DOWNLOAD ON RECEIVE!");
String action = intent.getAction();
if (action == null) {
return;
@@ -74,7 +72,7 @@ public class DownloadBroadcastReceiver extends BroadcastReceiver {
break;
case UPDATE_NOT_FOUND:
if (resultData.getBoolean(NO_NEW_VERISON, false)) {
- //TODO: Save in preferences date, retry in a week
+ PreferenceHelper.setLastAppUpdateCheck(context.getApplicationContext());
}
break;
case UPDATE_DOWNLOADED:
diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java
index f62af638..5fcaba2f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Constants.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java
@@ -37,6 +37,7 @@ public interface Constants {
String SHOW_EXPERIMENTAL = "show_experimental";
String USE_IPv6_FIREWALL = "use_ipv6_firewall";
String RESTART_ON_UPDATE = "restart_on_update";
+ String LAST_UPDATE_CHECK = "last_update_check";
//////////////////////////////////////////////
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
index 174e6657..e365c857 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipSetupObserver.java
@@ -77,6 +77,7 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
//The real timout is 4*2s + 1*4s + 1*8s + 1*16s + 1*32s + 1*64s = 132 s;
private static final String TIMEOUT = "4";
+ private static final int UPDATE_CHECK_TIMEOUT = 1000*60*60*24*7;
private Context context;
private VpnProfile setupVpnProfile;
private String observedProfileFromVpnStatus;
@@ -312,13 +313,19 @@ class EipSetupObserver extends BroadcastReceiver implements VpnStatus.StateListe
ProviderAPICommand.execute(context, ProviderAPI.DOWNLOAD_SERVICE_JSON, provider);
}
- DownloadServiceCommand.execute(context, CHECK_VERSION_FILE);
+ if (shouldCheckAppUpdate()) {
+ DownloadServiceCommand.execute(context, CHECK_VERSION_FILE);
+ }
finishGatewaySetup(false);
} else if ("TCP_CONNECT".equals(state)) {
changingGateway.set(false);
}
}
+ private boolean shouldCheckAppUpdate() {
+ return System.currentTimeMillis() - PreferenceHelper.getLastAppUpdateCheck(context) >= UPDATE_CHECK_TIMEOUT;
+ }
+
private void selectNextGateway() {
changingGateway.set(true);
reconnectTry.set(0);
diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
index 5ca2ec75..5b62d0ff 100644
--- a/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/PreferenceHelper.java
@@ -22,6 +22,7 @@ import static se.leap.bitmaskclient.Constants.ALLOW_TETHERING_WIFI;
import static se.leap.bitmaskclient.Constants.ALWAYS_ON_SHOW_DIALOG;
import static se.leap.bitmaskclient.Constants.DEFAULT_SHARED_PREFS_BATTERY_SAVER;
import static se.leap.bitmaskclient.Constants.EXCLUDED_APPS;
+import static se.leap.bitmaskclient.Constants.LAST_UPDATE_CHECK;
import static se.leap.bitmaskclient.Constants.LAST_USED_PROFILE;
import static se.leap.bitmaskclient.Constants.PROVIDER_CONFIGURED;
import static se.leap.bitmaskclient.Constants.PROVIDER_EIP_DEFINITION;
@@ -122,6 +123,14 @@ public class PreferenceHelper {
apply();
}
+ public static void setLastAppUpdateCheck(Context context) {
+ putLong(context, LAST_UPDATE_CHECK, System.currentTimeMillis());
+ }
+
+ public static long getLastAppUpdateCheck(Context context) {
+ return getLong(context, LAST_UPDATE_CHECK, 0);
+ }
+
public static void restartOnUpdate(Context context, boolean isEnabled) {
putBoolean(context, RESTART_ON_UPDATE, isEnabled);
}
@@ -223,6 +232,16 @@ public class PreferenceHelper {
return preferences.getStringSet(EXCLUDED_APPS, new HashSet<>());
}
+ public static long getLong(Context context, String key, long defValue) {
+ SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
+ return preferences.getLong(key, defValue);
+ }
+
+ public static void putLong(Context context, String key, long value) {
+ SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
+ preferences.edit().putLong(key, value).apply();
+ }
+
public static String getString(Context context, String key, String defValue) {
SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
return preferences.getString(key, defValue);