Commit 5a5b407b authored by Aayush Gupta's avatar Aayush Gupta
Browse files

updater: Rework logic to check for new updates



- Use the current system's version against update's version to check for new
  updates
Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
parent ee2c39b2
......@@ -296,7 +296,7 @@ public class UpdatesActivity extends UpdatesListActivity {
preferences.edit().putLong(Constants.PREF_LAST_UPDATE_CHECK, millis).apply();
updateLastCheckedString();
if (json.exists() && Utils.isUpdateCheckEnabled(this) &&
Utils.checkForNewUpdates(json, jsonNew)) {
Utils.checkForNewUpdates(jsonNew)) {
UpdatesCheckReceiver.updateRepeatingUpdatesCheck(this);
}
// In case we set a one-shot check because of a previous failure
......
......@@ -91,7 +91,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
@Override
public void onSuccess(File destination) {
try {
if (json.exists() && Utils.checkForNewUpdates(json, jsonNew)) {
if (json.exists() && Utils.checkForNewUpdates(jsonNew)) {
showNotification(context);
updateRepeatingUpdatesCheck(context);
}
......
......@@ -232,24 +232,19 @@ public class Utils {
/**
* Compares two json formatted updates list files
*
* @param oldJson old update list
* @param newJson new update list
* @return true if newJson has at least a compatible update not available in oldJson
* @return true if newJson has an update with higher version than the installed system
* @throws IOException
* @throws JSONException
*/
public static boolean checkForNewUpdates(File oldJson, File newJson)
public static boolean checkForNewUpdates(File newJson)
throws IOException, JSONException {
List<UpdateInfo> oldList = parseJson(oldJson, true);
List<UpdateInfo> newList = parseJson(newJson, true);
Set<String> oldIds = new HashSet<>();
for (UpdateInfo update : oldList) {
oldIds.add(update.getDownloadId());
}
// In case of no new updates, the old list should
// have all (if not more) the updates
float currentVersion = Float.parseFloat(BuildInfoUtils.getBuildVersion());
for (UpdateInfo update : newList) {
if (!oldIds.contains(update.getDownloadId())) {
if (Float.parseFloat(update.getVersion()) > currentVersion) {
Log.d(TAG, "New compatiable update available");
return true;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment