From a07c2fc48e5dac0bd1e1e09ee84856941684269f Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 24 Dec 2024 11:05:42 +0100 Subject: [PATCH] Updater: Allow 22.X to 22.X+N OTAs Change-Id: Ic4f5d94d4040bd744a372d3bb5090aba70e0688f --- .../java/org/lineageos/updater/misc/Utils.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 b7ba720..cb9e407 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -112,11 +112,25 @@ public class Utils { return true; } + private static boolean compareVersions(String a, String b) { + 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 majorA == majorB && minorA >= minorB; + } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { + return false; + } + } + public static boolean canInstall(UpdateBaseInfo update) { return (SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) || update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) && - update.getVersion().equalsIgnoreCase( - SystemProperties.get(Constants.PROP_BUILD_VERSION)); + compareVersions( + update.getVersion(), SystemProperties.get(Constants.PROP_BUILD_VERSION)); } public static List parseJson(File file, boolean compatibleOnly)