From c9159bf47b57c990b883f7565684aa8022ba76be Mon Sep 17 00:00:00 2001 From: Nolen Johnson Date: Wed, 25 Dec 2024 00:28:01 -0500 Subject: [PATCH] Updater: Allow Updater to handle major upgrades via property * If the user has GMS installed, they'll need to install an updated copy, as addon.d won't restore it, and if it did it likely wouldn't work. So we can't support this unconditionally. * If the user has no-GMS, this should be totally fine to do, so the user could set the property, upgrade, and go on their merry way. This use-case is why I didn't make this an `ro.` property. * If someone building LineageOS builds GMS into the images, upgrade via this method would also be feasible. Change-Id: If2a6e6767dcb182d3dbd2a95c81a940fdb53547e --- .../java/org/lineageos/updater/misc/Constants.java | 1 + .../main/java/org/lineageos/updater/misc/Utils.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/misc/Constants.java b/app/src/main/java/org/lineageos/updater/misc/Constants.java index beb9423..46ec5e6 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Constants.java +++ b/app/src/main/java/org/lineageos/updater/misc/Constants.java @@ -39,6 +39,7 @@ public final class Constants { public static final String UNCRYPT_FILE_EXT = ".uncrypt"; public static final String PROP_AB_DEVICE = "ro.build.ab_update"; + public static final String PROP_ALLOW_MAJOR_UPGRADES = "lineage.updater.allow_major_upgrades"; public static final String PROP_BUILD_DATE = "ro.build.date.utc"; public static final String PROP_BUILD_VERSION = "ro.lineage.build.version"; public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental"; diff --git a/app/src/main/java/org/lineageos/updater/misc/Utils.java b/app/src/main/java/org/lineageos/updater/misc/Utils.java index bc6ba6f..1b11d41 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -112,7 +112,7 @@ public class Utils { return true; } - private static boolean compareVersions(String a, String b) { + 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]); @@ -120,6 +120,9 @@ public class Utils { 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) + return majorA == majorB && minorA >= minorB; } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { return false; @@ -127,10 +130,15 @@ public class Utils { } 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)); + update.getVersion(), + SystemProperties.get(Constants.PROP_BUILD_VERSION), + allowMajorUpgrades); } public static List parseJson(File file, boolean compatibleOnly)