Improve the automatic updates checks

The builds for each device are released more or less at the same
time of the day, so check when the last build was released and
schedule the next check accordingly. Also, allow multiple automatic
updates check in the same day. There's no need to limit the number
of checks since they are not frequent and this can affect negatively
the effectiveness of the new algorithm. In addition to that, remove
any pending oneshot alarm in case a subsequent check succeeds and
log every new alarm.

Change-Id: I4668f2e342e51d3578992eec6d8c270065d9aa21
This commit is contained in:
Gabriele M
2017-08-31 17:29:50 +02:00
parent 5c09d5c5f1
commit 6f3dfda1b0
2 changed files with 115 additions and 44 deletions

View File

@@ -327,6 +327,12 @@ public class UpdatesActivity extends UpdatesListActivity {
long millis = System.currentTimeMillis();
preferences.edit().putLong(Constants.PREF_LAST_UPDATE_CHECK, millis).apply();
updateLastCheckedString();
if (json.exists() && preferences.getBoolean(Constants.PREF_AUTO_UPDATES_CHECK, true) &&
Utils.checkForNewUpdates(json, jsonNew)) {
UpdatesCheckReceiver.updateRepeatingUpdatesCheck(this);
}
// In case we set a one-shot check because of a previous failure
UpdatesCheckReceiver.cancelUpdatesCheck(this);
jsonNew.renameTo(json);
} catch (IOException | JSONException e) {
Log.e(TAG, "Could not read json", e);