From 449e7a2c785771a0056c35159453734f52d1fd12 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Mon, 10 May 2021 12:39:14 +0530 Subject: [PATCH 1/3] updater: add support for android version upgrades --- push-update.sh | 8 ++- .../updater/misc/BuildInfoUtils.java | 4 ++ src/org/lineageos/updater/misc/Constants.java | 1 + src/org/lineageos/updater/misc/Utils.java | 18 +++++++ src/org/lineageos/updater/misc/Version.java | 49 +++++++++++++++++++ .../lineageos/updater/model/UpdateBase.java | 23 +++++++++ .../updater/model/UpdateBaseInfo.java | 4 ++ 7 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/org/lineageos/updater/misc/Version.java diff --git a/push-update.sh b/push-update.sh index ee6e8333..05d5db06 100755 --- a/push-update.sh +++ b/push-update.sh @@ -38,9 +38,11 @@ zip_name=`basename "$zip_path"` id=`echo "$zip_name" | sha1sum | cut -d' ' -f1` version=`echo "$zip_name" | cut -d'-' -f2` type=`echo "$zip_name" | cut -d'-' -f4` -build_date=`echo "$zip_name" | cut -d'-' -f3 | cut -d'_' -f1` +build_date=`echo "$zip_name" | cut -d'-' -f4 | cut -d'_' -f1` timestamp=`date --date="$build_date 23:59:59" +%s` size=`stat -c "%s" "$zip_path"` +display_version= +android_version='10' adb push "$zip_path" "$zip_path_device" adb shell chgrp cache "$zip_path_device" @@ -52,5 +54,9 @@ adb shell "sqlite3 /data/data/org.lineageos.updater/databases/updates.db" \ "\"INSERT INTO updates (status, path, download_id, timestamp, type, version, size)" \ " VALUES ($status, '$zip_path_device', '$id', $timestamp, '$type', '$version', $size)\"" +# adb shell "sqlite3 /data/data/org.lineageos.updater/databases/updates.db" \ +# "\"INSERT INTO updates (status, path, download_id, timestamp, type, version, display_version, android_version, size)" \ +# " VALUES ($status, '$zip_path_device', '$id', $timestamp, '$type', '$version', '$display_version', '$android_version', $size)\"" + # Exit root mode adb unroot diff --git a/src/org/lineageos/updater/misc/BuildInfoUtils.java b/src/org/lineageos/updater/misc/BuildInfoUtils.java index 6a647faf..c01e26ca 100644 --- a/src/org/lineageos/updater/misc/BuildInfoUtils.java +++ b/src/org/lineageos/updater/misc/BuildInfoUtils.java @@ -33,4 +33,8 @@ public final class BuildInfoUtils { public static String getDisplayVersion() { return SystemProperties.get(Constants.PROP_BUILD_DISPLAY_VERSION); } + + public static String getReleaseVersion() { + return SystemProperties.get(Constants.PROP_BUILD_RELEASE_VERSION); + } } diff --git a/src/org/lineageos/updater/misc/Constants.java b/src/org/lineageos/updater/misc/Constants.java index 6ba705c7..69e759c4 100644 --- a/src/org/lineageos/updater/misc/Constants.java +++ b/src/org/lineageos/updater/misc/Constants.java @@ -42,6 +42,7 @@ public final class Constants { 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_DISPLAY_VERSION = "ro.lineage.display.version"; + public static final String PROP_BUILD_RELEASE_VERSION = "ro.build.version.release"; public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental"; public static final String PROP_DEVICE = "ro.lineage.device"; public static final String PROP_NEXT_DEVICE = "ro.updater.next_device"; diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 4d7d4ec5..d449fae6 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -92,6 +92,8 @@ public class Utils { update.setDownloadUrl(object.getString("url")); update.setVersion(object.getString("version")); update.setDisplayVersion(object.getString("display_version")); + update.setReleaseVersion(object.getString("android_version")); + update.setUpgradeSupported(object.getBoolean("is_upgrade_supported")); return update; } @@ -105,6 +107,22 @@ public class Utils { Log.d(TAG, update.getName() + " has type " + update.getType()); return false; } + if (update.getUpgradeSupported()) { + Log.d(TAG, " is_upgrade_supported :" + update.getUpgradeSupported()); + Log.d(TAG, " Check for newer Android version "); + + if (!update.getReleaseVersion().equals(SystemProperties.get(Constants.PROP_BUILD_RELEASE_VERSION))) { + Log.d(TAG, update.getName() + " android_version :" + update.getReleaseVersion()); + Version deviceAndroidVersion = new Version(SystemProperties.get(Constants.PROP_BUILD_RELEASE_VERSION)); + Version updateAndroidVersion = new Version(update.getReleaseVersion()); + if (updateAndroidVersion.compareTo(deviceAndroidVersion)==1){ + Log.d(TAG, " newer Android version is available"); + return true; + } + Log.d(TAG, " Same or old Android version "); + } + } + return true; } diff --git a/src/org/lineageos/updater/misc/Version.java b/src/org/lineageos/updater/misc/Version.java new file mode 100644 index 00000000..6b26290a --- /dev/null +++ b/src/org/lineageos/updater/misc/Version.java @@ -0,0 +1,49 @@ +package org.lineageos.updater.misc; + + +public class Version implements Comparable { + + private String version; + + public final String get() { + return this.version; + } + + public Version(String version) { + if(version == null) + throw new IllegalArgumentException("Version can not be null"); + if(!version.matches("[0-9]+(\\.[0-9]+)*")) + throw new IllegalArgumentException("Invalid version format"); + this.version = version; + } + + @Override public int compareTo(Version that) { + if(that == null) + return 1; + String[] thisParts = this.get().split("\\."); + String[] thatParts = that.get().split("\\."); + int length = Math.max(thisParts.length, thatParts.length); + for(int i = 0; i < length; i++) { + int thisPart = i < thisParts.length ? + Integer.parseInt(thisParts[i]) : 0; + int thatPart = i < thatParts.length ? + Integer.parseInt(thatParts[i]) : 0; + if(thisPart < thatPart) + return -1; + if(thisPart > thatPart) + return 1; + } + return 0; + } + + @Override public boolean equals(Object that) { + if(this == that) + return true; + if(that == null) + return false; + if(this.getClass() != that.getClass()) + return false; + return this.compareTo((Version) that) == 0; + } + +} \ No newline at end of file diff --git a/src/org/lineageos/updater/model/UpdateBase.java b/src/org/lineageos/updater/model/UpdateBase.java index cfa2027e..3161d79a 100644 --- a/src/org/lineageos/updater/model/UpdateBase.java +++ b/src/org/lineageos/updater/model/UpdateBase.java @@ -24,7 +24,9 @@ public class UpdateBase implements UpdateBaseInfo { private String mType; private String mVersion; private String mDisplayVersion; + private String mReleaseVersion; private long mFileSize; + private boolean mUpgradeSupported; public UpdateBase() { } @@ -37,7 +39,9 @@ public class UpdateBase implements UpdateBaseInfo { mType = update.getType(); mVersion = update.getVersion(); mDisplayVersion = update.getDisplayVersion(); + mReleaseVersion = update.getReleaseVersion(); mFileSize = update.getFileSize(); + mUpgradeSupported = update.getUpgradeSupported(); } @Override @@ -94,6 +98,15 @@ public class UpdateBase implements UpdateBaseInfo { mDisplayVersion = displayVersion; } + @Override + public String getReleaseVersion() { + return mReleaseVersion; + } + + public void setReleaseVersion(String releaseVersion) { + mReleaseVersion = releaseVersion; + } + @Override public String getDownloadUrl() { return mDownloadUrl; @@ -111,4 +124,14 @@ public class UpdateBase implements UpdateBaseInfo { public void setFileSize(long fileSize) { mFileSize = fileSize; } + + @Override + public boolean getUpgradeSupported() { + return mUpgradeSupported; + } + + public void setUpgradeSupported(boolean upgradeSupported) { + mUpgradeSupported = upgradeSupported; + } + } diff --git a/src/org/lineageos/updater/model/UpdateBaseInfo.java b/src/org/lineageos/updater/model/UpdateBaseInfo.java index 2921e96f..ffdb6bd3 100644 --- a/src/org/lineageos/updater/model/UpdateBaseInfo.java +++ b/src/org/lineageos/updater/model/UpdateBaseInfo.java @@ -28,7 +28,11 @@ public interface UpdateBaseInfo { String getDisplayVersion(); + String getReleaseVersion(); + String getDownloadUrl(); long getFileSize(); + + boolean getUpgradeSupported(); } -- GitLab From e4b54df69ee8b9aaf3c1bfdad1310253d8003391 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Mon, 10 May 2021 12:45:58 +0530 Subject: [PATCH 2/3] Switch to test OTA server --- res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 31f1bf59..88b7f0a6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -32,7 +32,7 @@ {type} - Build type {incr} - Incremental version --> - https://ota.ecloud.global/api/v1/{device}/{type}/{incr} + https://test.ota.ecloud.global/api/v1/{device}/{type}/{incr} Verification failed Verifying update -- GitLab From 26f6f8619e9d4106c0d529f335862de314d4d0c5 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Fri, 14 May 2021 18:45:05 +0530 Subject: [PATCH 3/3] New AlertDialog text for version Upgrade --- res/values/strings.xml | 3 ++ .../lineageos/updater/UpdatesListAdapter.java | 10 ++++- src/org/lineageos/updater/misc/Utils.java | 37 +++++++++++-------- .../lineageos/updater/model/UpdateBase.java | 12 ++++++ .../updater/model/UpdateBaseInfo.java | 3 ++ 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 88b7f0a6..db3acfaa 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -112,6 +112,9 @@ You are about to upgrade to %1$s.\n\nIf you press %2$s, the device will restart itself in recovery mode to install the update.\n\nNote: This feature requires a compatible Recovery or updates will need to be installed manually. You are about to upgrade to %1$s.\n\nIf you press %2$s, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot. + Upgrade to /e/OS based on Android 10 + You are about to upgrade your phone to a more recent version of /e/OS that is derived from Android 10. It will update your device\'s firmware to a more recent version. This upgrade will give you access to system updates and security patches for at least 3 more years.\n\nConsequently, this update will be longer than usual as it updates more components. Your device may reboot multiple times, and will encrypt your data if they are not already. + Cancel the installation? Download URL diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java index 0df51d98..ca88f50e 100644 --- a/src/org/lineageos/updater/UpdatesListAdapter.java +++ b/src/org/lineageos/updater/UpdatesListAdapter.java @@ -447,11 +447,17 @@ public class UpdatesListAdapter extends RecyclerView.Adapter