diff --git a/app/src/main/java/com/voipgrid/vialer/util/UpdateHelper.java b/app/src/main/java/com/voipgrid/vialer/util/UpdateHelper.java index 5cda4e0b..f078010e 100644 --- a/app/src/main/java/com/voipgrid/vialer/util/UpdateHelper.java +++ b/app/src/main/java/com/voipgrid/vialer/util/UpdateHelper.java @@ -6,8 +6,6 @@ import android.content.Context; import android.content.SharedPreferences; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; import android.os.AsyncTask; import android.preference.PreferenceManager; @@ -41,6 +39,16 @@ public class UpdateHelper extends AsyncTask { private final static String VERSION_CODE = "version_code"; private Boolean succesfulMigrate = true; + /** + * The milliseconds since a migration was last attempted. + */ + private static long lastMigrationAttempt = 0; + + /** + * The time between migration attempts. + */ + private static final long MIGRATION_ATTEMPT_TIMEOUT_MS = (60 * 60 * 24) * 1000; + public UpdateHelper(Context context, OnUpdateCompleted listener) { mContext = context; mJsonStorage = new JsonStorage(mContext); @@ -52,6 +60,7 @@ public UpdateHelper(Context context, OnUpdateCompleted listener) { @Override protected Void doInBackground(Void... params) { + lastMigrationAttempt = System.currentTimeMillis(); int currentVersion = BuildConfig.VERSION_CODE; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); int lastVersion = prefs.getInt(VERSION_CODE, 0); @@ -73,6 +82,8 @@ protected Void doInBackground(Void... params) { } public static boolean requiresUpdate(Context context) { + if(lastMigrationAttempt > (System.currentTimeMillis() - MIGRATION_ATTEMPT_TIMEOUT_MS) ) return false; + int lastVersion = PreferenceManager.getDefaultSharedPreferences(context).getInt(VERSION_CODE, 0); return BuildConfig.VERSION_CODE != lastVersion; @@ -145,9 +156,16 @@ private void enableSecureCalling() { try { Response response = call.execute(); - if(!response.isSuccessful()) succesfulMigrate = false; + if(!response.isSuccessful()) { + handleApiFailure(response.code()); + } } catch (IOException e) { - succesfulMigrate = false; + handleApiFailure(0); } } + + private void handleApiFailure(int code) { + mRemoteLogger.e("Enabling secure calling failed with code " + code); + succesfulMigrate = false; + } }