Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b1cf97a authored by Aayush Gupta's avatar Aayush Gupta Committed by Nishith Khanna
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>
Change-Id: I839033daa355f7faddb4ff641f1ffa59600b7472
parent 596c2099
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -436,7 +436,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport
            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
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
            @Override
            public void onSuccess() {
                try {
                    if (json.exists() && Utils.checkForNewUpdates(json, jsonNew)) {
                    if (json.exists() && Utils.checkForNewUpdates(jsonNew)) {
                        showNotification(context);
                        updateRepeatingUpdatesCheck(context);
                    }
+6 −13
Original line number Diff line number Diff line
@@ -48,10 +48,8 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.regex.Pattern;
@@ -223,22 +221,17 @@ 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
     */
    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;
            }
        }