From f29cb28924bd8c528d1523f9bde200577676e32f Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 17 Nov 2022 11:43:41 +0000 Subject: [PATCH 1/5] switch to string on updateSystemUpdaterService to avoid a crash --- .../updater/controller/UpdaterService.java | 2 +- src/org/lineageos/updater/misc/Utils.java | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index c0354f92..09f646e1 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -553,6 +553,6 @@ public class UpdaterService extends Service { } private void notifySystemUpdaterService(int status, UpdateInfo update) { - Utils.updateSystemUpdaterService(this, status, Float.parseFloat(update.getVersion())); + Utils.updateSystemUpdaterService(this, status, update.getVersion()); } } diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index c33bb081..37b08fd4 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -293,27 +293,31 @@ public class Utils { int[] deviceVersionParts = parseSemVer(SystemProperties.get(Constants.PROP_BUILD_VERSION)); int deviceMajorVersion = deviceVersionParts[0]; int deviceMinorVersion = deviceVersionParts[1]; - final float currentVersion = Float.parseFloat(deviceMajorVersion + "." + deviceMinorVersion); - float highestAvailableVersion = currentVersion; - boolean hasUpdate = false; + int deviceMaintenanceVersion = deviceVersionParts.length > 2 ? deviceVersionParts[2] : 0; + int highestMajorVersion = deviceMajorVersion; + int highestMinorVersion = deviceMinorVersion; + boolean hasUpdate = false; for (UpdateInfo update : newList) { if (isCompatible(update)) { Log.d(TAG, "New compatible update available"); int[] updateVersionParts = parseSemVer(update.getVersion()); int updateMajorVersion = updateVersionParts[0]; int updateMinorVersion = updateVersionParts[1]; + int updateMaintenanceVersion = updateVersionParts.length > 2 ? updateVersionParts[2] : 0; float thisUpdate = Float.parseFloat(updateMajorVersion + "." + updateMinorVersion); - if (thisUpdate > highestAvailableVersion) { - highestAvailableVersion = thisUpdate; + if (updateMajorVersion >= highestMajorVersion && updateMinorVersion >= highestMinorVersion && updateMaintenanceVersion >= highestMaintenanceVersion) { + highestMajorVersion = updateMajorVersion; + highestMinorVersion = updateMinorVersion; + highestMaintenanceVersion = updateMaintenanceVersion; } hasUpdate = true; } } if (hasUpdate) { - updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestAvailableVersion); + updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestMajorVersion+"."+highestMinorVersion+(highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); return true; } else { - updateSystemUpdaterService(context, STATUS_IDLE, highestAvailableVersion); + updateSystemUpdaterService(context, STATUS_IDLE, highestMajorVersion+"."+highestMinorVersion+(highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); return false; } } @@ -500,7 +504,7 @@ public class Utils { return new File(Constants.UPDATE_RECOVERY_EXEC).exists(); } - public static void updateSystemUpdaterService(Context context, int status, float version) { + public static void updateSystemUpdaterService(Context context, int status, String version) { final SystemUpdateManager updateManager = context.getSystemService(SystemUpdateManager.class); final Bundle oldInfo = updateManager.retrieveSystemUpdateInfo(); @@ -509,7 +513,7 @@ public class Utils { if (status != oldStatus) { PersistableBundle infoBundle = new PersistableBundle(); infoBundle.putInt(KEY_STATUS, status); - infoBundle.putString(KEY_TITLE, String.valueOf(version)); + infoBundle.putString(KEY_TITLE, version); updateManager.updateSystemUpdateInfo(infoBundle); } } -- GitLab From 8784fd92fe40f632c641179c0f6247a778b08b1b Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 17 Nov 2022 13:03:20 +0000 Subject: [PATCH 2/5] forgotten highestMaintenanceVersion --- src/org/lineageos/updater/misc/Utils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 37b08fd4..cbe05c9e 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -296,6 +296,7 @@ public class Utils { int deviceMaintenanceVersion = deviceVersionParts.length > 2 ? deviceVersionParts[2] : 0; int highestMajorVersion = deviceMajorVersion; int highestMinorVersion = deviceMinorVersion; + int highestMaintenanceVersion = deviceMaintenanceVersion; boolean hasUpdate = false; for (UpdateInfo update : newList) { if (isCompatible(update)) { -- GitLab From dbda3024ff4dc05e0a832b2676085ad420b61b7d Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 17 Nov 2022 16:11:13 +0000 Subject: [PATCH 3/5] Apply 1 suggestion(s) to 1 file(s) --- src/org/lineageos/updater/misc/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index cbe05c9e..42e7b386 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -315,7 +315,7 @@ public class Utils { } } if (hasUpdate) { - updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestMajorVersion+"."+highestMinorVersion+(highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); + updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestMajorVersion + "." + highestMinorVersion + (highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); return true; } else { updateSystemUpdaterService(context, STATUS_IDLE, highestMajorVersion+"."+highestMinorVersion+(highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); -- GitLab From 5749d3961647712802081ec481a97d440e68f863 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 17 Nov 2022 16:13:12 +0000 Subject: [PATCH 4/5] fix indentation --- src/org/lineageos/updater/misc/Utils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 42e7b386..6cff7eb5 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -301,9 +301,9 @@ public class Utils { for (UpdateInfo update : newList) { if (isCompatible(update)) { Log.d(TAG, "New compatible update available"); - int[] updateVersionParts = parseSemVer(update.getVersion()); - int updateMajorVersion = updateVersionParts[0]; - int updateMinorVersion = updateVersionParts[1]; + int[] updateVersionParts = parseSemVer(update.getVersion()); + int updateMajorVersion = updateVersionParts[0]; + int updateMinorVersion = updateVersionParts[1]; int updateMaintenanceVersion = updateVersionParts.length > 2 ? updateVersionParts[2] : 0; float thisUpdate = Float.parseFloat(updateMajorVersion + "." + updateMinorVersion); if (updateMajorVersion >= highestMajorVersion && updateMinorVersion >= highestMinorVersion && updateMaintenanceVersion >= highestMaintenanceVersion) { -- GitLab From ddc2c3de8fecc0fa9568dffa94dc2a71ae028110 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 17 Nov 2022 16:23:50 +0000 Subject: [PATCH 5/5] fix bad cases --- src/org/lineageos/updater/misc/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 6cff7eb5..9052e87a 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -306,7 +306,7 @@ public class Utils { int updateMinorVersion = updateVersionParts[1]; int updateMaintenanceVersion = updateVersionParts.length > 2 ? updateVersionParts[2] : 0; float thisUpdate = Float.parseFloat(updateMajorVersion + "." + updateMinorVersion); - if (updateMajorVersion >= highestMajorVersion && updateMinorVersion >= highestMinorVersion && updateMaintenanceVersion >= highestMaintenanceVersion) { + if (updateMajorVersion*10000+updateMinorVersion*100+updateMaintenanceVersion >= highestMajorVersion*10000+highestMinorVersion*100+highestMaintenanceVersion) { highestMajorVersion = updateMajorVersion; highestMinorVersion = updateMinorVersion; highestMaintenanceVersion = updateMaintenanceVersion; -- GitLab