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

Commit 23c3ba3b authored by Romain Hunault's avatar Romain Hunault 🚴🏻 Committed by Nishith Khanna
Browse files

Updater: Allow OTA updates with different version number



Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
Change-Id: I24ee83c5a94f47742f6c9cad23630bc6833cfe81
Signed-off-by: default avataralthafvly <althafvly@gmail.com>
parent 94f5325a
Loading
Loading
Loading
Loading
+1 −24
Original line number Diff line number Diff line
@@ -101,32 +101,9 @@ public class Utils {
        return true;
    }

    private static boolean compareVersions(String a, String b, boolean allowMajorUpgrades) {
        try {
            int majorA = Integer.parseInt(a.split("\\.")[0]);
            int minorA = Integer.parseInt(a.split("\\.")[1]);

            int majorB = Integer.parseInt(b.split("\\.")[0]);
            int minorB = Integer.parseInt(b.split("\\.")[1]);

            // Return early and allow if we allow major version upgrades
            return (allowMajorUpgrades && majorA > majorB)
                    || (majorA == majorB && minorA >= minorB);
        } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
            return false;
        }
    }

    public static boolean canInstall(UpdateBaseInfo update) {
        boolean allowMajorUpgrades = SystemProperties.getBoolean(
                Constants.PROP_ALLOW_MAJOR_UPGRADES, false);

        return (SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) ||
                update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) &&
                compareVersions(
                        update.getVersion(),
                        SystemProperties.get(Constants.PROP_BUILD_VERSION),
                        allowMajorUpgrades);
                update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0));
    }

    public static List<UpdateInfo> parseJson(File file, boolean compatibleOnly)