From 46223db636b6d2d62347a0b75dc713f2b2757fb8 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Fri, 17 Jul 2020 12:07:30 +0530 Subject: [PATCH 1/5] 0.10 is special, treat it as special! --- src/org/lineageos/updater/misc/Utils.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 25b850ba..6678998a 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -96,6 +96,19 @@ public class Utils { } public static boolean isCompatible(UpdateBaseInfo update) { + if (update.getVersion().compareTo("0.10") == 0){ + Log.d(TAG, update.getName() + " version update is special"); + if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && + update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { + Log.d(TAG, update.getName() + " is older than/equal to the current build"); + return false; + } + if (!update.getType().equalsIgnoreCase(SystemProperties.get(Constants.PROP_RELEASE_TYPE))) { + Log.d(TAG, update.getName() + " has type " + update.getType()); + return false; + } + return true; + } if (update.getVersion().compareTo(SystemProperties.get(Constants.PROP_BUILD_VERSION)) < 0) { Log.d(TAG, update.getName() + " is older than current Android version"); return false; -- GitLab From 10943f76da4869a65a14a4dcc77445471b4bbcb0 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Sat, 18 Jul 2020 01:36:40 +0530 Subject: [PATCH 2/5] Split and parse build version --- src/org/lineageos/updater/misc/Utils.java | 53 +++++++++++++++-------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 6678998a..6af3806e 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -53,6 +53,7 @@ import java.util.Locale; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import java.util.regex.Pattern; public class Utils { @@ -96,10 +97,23 @@ public class Utils { } public static boolean isCompatible(UpdateBaseInfo update) { - if (update.getVersion().compareTo("0.10") == 0){ - Log.d(TAG, update.getName() + " version update is special"); + String updateVersion = update.getVersion(); + String[] updateVersionParts = updateVersion.split(Pattern.quote(".")); + String updateMajorVersion = updateVersionParts[0]; + String updateMinorVersion = updateVersionParts[1]; + Log.d(TAG, "Update : Major "+updateMajorVersion +" Minor "+ updateMinorVersion ); + + String deviceVersion = SystemProperties.get(Constants.PROP_BUILD_VERSION); + String[] deviceVersionParts = deviceVersion.split(Pattern.quote(".")); + String deviceMajorVersion = deviceVersionParts[0]; + String deviceMinorVersion = deviceVersionParts[1]; + Log.d(TAG, "Device : Major "+ deviceMajorVersion +" Minor "+ deviceMinorVersion ); + + if(updateMajorVersion.compareTo(deviceMajorVersion) < 0){ + Log.d(TAG, "" + " is older than current Android version"); + if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && - update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { + update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { Log.d(TAG, update.getName() + " is older than/equal to the current build"); return false; } @@ -107,21 +121,22 @@ public class Utils { Log.d(TAG, update.getName() + " has type " + update.getType()); return false; } - return true; - } - if (update.getVersion().compareTo(SystemProperties.get(Constants.PROP_BUILD_VERSION)) < 0) { - Log.d(TAG, update.getName() + " is older than current Android version"); - return false; + } - if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && + if(updateMinorVersion.compareTo(deviceMinorVersion) < 0){ + Log.d(TAG, "" + " is older than current Android version"); + + if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { - Log.d(TAG, update.getName() + " is older than/equal to the current build"); - return false; - } - if (!update.getType().equalsIgnoreCase(SystemProperties.get(Constants.PROP_RELEASE_TYPE))) { - Log.d(TAG, update.getName() + " has type " + update.getType()); - return false; + Log.d(TAG, update.getName() + " is older than/equal to the current build"); + return false; + } + if (!update.getType().equalsIgnoreCase(SystemProperties.get(Constants.PROP_RELEASE_TYPE))) { + Log.d(TAG, update.getName() + " has type " + update.getType()); + return false; + } } + return true; } @@ -185,10 +200,14 @@ public class Utils { } public static String getChangelogURL(Context context) { + String device = SystemProperties.get(Constants.PROP_NEXT_DEVICE, + SystemProperties.get(Constants.PROP_DEVICE)); + + String version = SystemProperties.get(Constants.PROP_VERSION); - String buildVersion = SystemProperties.get(Constants.PROP_BUILD_VERSION); + String releaseType = SystemProperties.get(Constants.PROP_RELEASE_TYPE); - return context.getString(R.string.menu_changelog_url, buildVersion); + return context.getString(R.string.menu_changelog_url, device, version, releaseType); } public static void triggerUpdate(Context context, String downloadId) { -- GitLab From 24463600628527c554b403feb01019b00c7f2eed Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Mon, 20 Jul 2020 14:22:31 +0530 Subject: [PATCH 3/5] New logic to compare Major and Minor version --- src/org/lineageos/updater/misc/Utils.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 6af3806e..6b44968a 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -55,6 +55,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.regex.Pattern; + public class Utils { private static final String TAG = "Utils"; @@ -97,20 +98,20 @@ public class Utils { } public static boolean isCompatible(UpdateBaseInfo update) { - String updateVersion = update.getVersion(); + String updateVersion = update.getVersion(); String[] updateVersionParts = updateVersion.split(Pattern.quote(".")); - String updateMajorVersion = updateVersionParts[0]; - String updateMinorVersion = updateVersionParts[1]; + int updateMajorVersion = Integer.parseInt(updateVersionParts[0]); + int updateMinorVersion = Integer.parseInt(updateVersionParts[1]); Log.d(TAG, "Update : Major "+updateMajorVersion +" Minor "+ updateMinorVersion ); String deviceVersion = SystemProperties.get(Constants.PROP_BUILD_VERSION); String[] deviceVersionParts = deviceVersion.split(Pattern.quote(".")); - String deviceMajorVersion = deviceVersionParts[0]; - String deviceMinorVersion = deviceVersionParts[1]; + int deviceMajorVersion = Integer.parseInt(deviceVersionParts[0]); + int deviceMinorVersion = Integer.parseInt(deviceVersionParts[1]); Log.d(TAG, "Device : Major "+ deviceMajorVersion +" Minor "+ deviceMinorVersion ); - if(updateMajorVersion.compareTo(deviceMajorVersion) < 0){ - Log.d(TAG, "" + " is older than current Android version"); + if(updateMajorVersion <= deviceMajorVersion){ + Log.d(TAG, "" + " is Newer/Equal to current Major version"); if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { @@ -123,8 +124,8 @@ public class Utils { } } - if(updateMinorVersion.compareTo(deviceMinorVersion) < 0){ - Log.d(TAG, "" + " is older than current Android version"); + if(updateMinorVersion <= deviceMinorVersion){ + Log.d(TAG, "" + " is Newer/Equal to current Minor version"); if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { -- GitLab From 0799c9f7923e65eabdf49071f275a6cb58200a30 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Thu, 23 Jul 2020 18:06:15 +0530 Subject: [PATCH 4/5] Improve update compatiblity check logic --- src/org/lineageos/updater/misc/Utils.java | 48 ++++++++--------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 6b44968a..9a3a2f92 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -110,32 +110,23 @@ public class Utils { int deviceMinorVersion = Integer.parseInt(deviceVersionParts[1]); Log.d(TAG, "Device : Major "+ deviceMajorVersion +" Minor "+ deviceMinorVersion ); - if(updateMajorVersion <= deviceMajorVersion){ - Log.d(TAG, "" + " is Newer/Equal to current Major version"); - - if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && - update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { - Log.d(TAG, update.getName() + " is older than/equal to the current build"); - return false; - } - if (!update.getType().equalsIgnoreCase(SystemProperties.get(Constants.PROP_RELEASE_TYPE))) { - Log.d(TAG, update.getName() + " has type " + update.getType()); - return false; - } + if(updateMajorVersion < deviceMajorVersion){ + Log.d(TAG, "" + " is Older to current Major version"); + return false; } - if(updateMinorVersion <= deviceMinorVersion){ - Log.d(TAG, "" + " is Newer/Equal to current Minor version"); - - if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && - update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { - Log.d(TAG, update.getName() + " is older than/equal to the current build"); - return false; - } - if (!update.getType().equalsIgnoreCase(SystemProperties.get(Constants.PROP_RELEASE_TYPE))) { - Log.d(TAG, update.getName() + " has type " + update.getType()); - return false; - } + if(updateMinorVersion < deviceMinorVersion){ + Log.d(TAG, "" + " is Older to current Minor version"); + return false; + } + if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && + update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { + Log.d(TAG, update.getName() + " is older than/equal to the current build"); + return false; + } + if (!update.getType().equalsIgnoreCase(SystemProperties.get(Constants.PROP_RELEASE_TYPE))) { + Log.d(TAG, update.getName() + " has type " + update.getType()); + return false; } return true; @@ -201,14 +192,9 @@ public class Utils { } public static String getChangelogURL(Context context) { - String device = SystemProperties.get(Constants.PROP_NEXT_DEVICE, - SystemProperties.get(Constants.PROP_DEVICE)); - - String version = SystemProperties.get(Constants.PROP_VERSION); - - String releaseType = SystemProperties.get(Constants.PROP_RELEASE_TYPE); + String buildVersion = SystemProperties.get(Constants.PROP_BUILD_VERSION); - return context.getString(R.string.menu_changelog_url, device, version, releaseType); + return context.getString(R.string.menu_changelog_url, buildVersion); } public static void triggerUpdate(Context context, String downloadId) { -- GitLab From 9093c5b4c80345c2cc007872578151f58c833da1 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Mon, 27 Jul 2020 14:08:17 +0530 Subject: [PATCH 5/5] Use helper function for parsing version code Fix: Handle use case 1.0 is bigger than 0.9 Semantic versioning --- src/org/lineageos/updater/misc/Utils.java | 41 ++++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 9a3a2f92..d8022ac8 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -98,27 +98,17 @@ public class Utils { } public static boolean isCompatible(UpdateBaseInfo update) { - String updateVersion = update.getVersion(); - String[] updateVersionParts = updateVersion.split(Pattern.quote(".")); - int updateMajorVersion = Integer.parseInt(updateVersionParts[0]); - int updateMinorVersion = Integer.parseInt(updateVersionParts[1]); + int[] updateVersionParts = parseSemVer(update.getVersion()); + int updateMajorVersion = updateVersionParts[0]; + int updateMinorVersion = updateVersionParts[1]; Log.d(TAG, "Update : Major "+updateMajorVersion +" Minor "+ updateMinorVersion ); - String deviceVersion = SystemProperties.get(Constants.PROP_BUILD_VERSION); - String[] deviceVersionParts = deviceVersion.split(Pattern.quote(".")); - int deviceMajorVersion = Integer.parseInt(deviceVersionParts[0]); - int deviceMinorVersion = Integer.parseInt(deviceVersionParts[1]); + int[] deviceVersionParts = parseSemVer(SystemProperties.get(Constants.PROP_BUILD_VERSION)); + int deviceMajorVersion = deviceVersionParts[0]; + int deviceMinorVersion = deviceVersionParts[1]; Log.d(TAG, "Device : Major "+ deviceMajorVersion +" Minor "+ deviceMinorVersion ); - if(updateMajorVersion < deviceMajorVersion){ - Log.d(TAG, "" + " is Older to current Major version"); - return false; - } - if(updateMinorVersion < deviceMinorVersion){ - Log.d(TAG, "" + " is Older to current Minor version"); - return false; - } if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { Log.d(TAG, update.getName() + " is older than/equal to the current build"); @@ -128,10 +118,29 @@ public class Utils { Log.d(TAG, update.getName() + " has type " + update.getType()); return false; } + if(updateMajorVersion > deviceMajorVersion){ + Log.d(TAG, update.getName() + " is Newer to current Major version"); + return true; + } + if(updateMajorVersion < deviceMajorVersion){ + Log.d(TAG, update.getName() + " is Older to current Major version"); + return false; + } + if(updateMinorVersion < deviceMinorVersion){ + Log.d(TAG, update.getName() + " is Older to current Minor version"); + return false; + } return true; } + public static int[] parseSemVer(String versionCode) { + String[] versionParts = versionCode.split(Pattern.quote(".")); + int major = Integer.parseInt(versionParts[0]); + int minor = Integer.parseInt(versionParts[1]); + return new int[]{ major, minor }; + } + public static boolean canInstall(UpdateBaseInfo update) { return (SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) || update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)); -- GitLab