From 6c9269e559cb73744e11d3ca97cc8f6e08daf3df Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Wed, 24 Aug 2022 13:05:29 +0000 Subject: [PATCH 01/42] Updater: Rebrand to /e/ OS Change-Id: Idcf080541eb910c99f9057859d3d777768c7bde2 --- .../main/java/org/lineageos/updater/UpdaterReceiver.java | 2 +- .../main/java/org/lineageos/updater/UpdatesListAdapter.java | 4 ++-- .../org/lineageos/updater/controller/UpdaterService.java | 2 +- app/src/main/res/values/strings.xml | 6 ++++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java index 4b7cb7e4..6584c04d 100644 --- a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java @@ -61,7 +61,7 @@ public class UpdaterReceiver extends BroadcastReceiver { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String buildDate = StringGenerator.getDateLocalizedUTC(context, DateFormat.MEDIUM, preferences.getLong(Constants.PREF_INSTALL_NEW_TIMESTAMP, 0)); - String buildInfo = context.getString(R.string.list_build_version_date, + String buildInfo = context.getString(R.string.list_build_version_date_e, Utils.getDisplayVersion(BuildInfoUtils.getBuildVersion()), buildDate); Intent notificationIntent = new Intent(context, UpdatesActivity.class); diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index 30144701..e9b76d90 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -279,7 +279,7 @@ public class UpdatesListAdapter extends RecyclerView.AdapterFailed to import local update Install Local update + + + + + /e/OS %1$s + /e/OS %1$s - %2$s -- GitLab From 912b9781426e45749af1b76dba820834cb7348f2 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Wed, 24 Aug 2022 13:14:20 +0000 Subject: [PATCH 02/42] Updater: Get /e/ release notes Change-Id: I8345c9f2fc03df2339e157791aea5b8ed787b81f Updater: res: Redirect to proper changelog URL Change-Id: Ia16ba958968d84bb0b0e10e97e4085507d886905 --- app/src/main/java/org/lineageos/updater/misc/Constants.java | 1 + app/src/main/java/org/lineageos/updater/misc/Utils.java | 5 ++--- app/src/main/res/menu/menu_toolbar.xml | 2 +- app/src/main/res/values/strings.xml | 5 ++++- 4 files changed, 8 insertions(+), 5 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 beb9423f..bf8fd398 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Constants.java +++ b/app/src/main/java/org/lineageos/updater/misc/Constants.java @@ -47,6 +47,7 @@ public final class Constants { public static final String PROP_RELEASE_TYPE = "ro.lineage.releasetype"; public static final String PROP_UPDATER_ALLOW_DOWNGRADING = "lineage.updater.allow_downgrading"; public static final String PROP_UPDATER_URI = "lineage.updater.uri"; + public static final String PROP_VERSION = "ro.lineage.version"; public static final String PREF_INSTALL_OLD_TIMESTAMP = "install_old_timestamp"; public static final String PREF_INSTALL_NEW_TIMESTAMP = "install_new_timestamp"; 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 b7ba720f..8db5cdbf 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -174,9 +174,8 @@ public class Utils { } public static String getChangelogURL(Context context) { - String device = SystemProperties.get(Constants.PROP_NEXT_DEVICE, - SystemProperties.get(Constants.PROP_DEVICE)); - return context.getString(R.string.menu_changelog_url, device); + String buildVersion = SystemProperties.get(Constants.PROP_BUILD_VERSION); + return context.getString(R.string.menu_changelog_url, buildVersion); } public static void triggerUpdate(Context context, String downloadId) { diff --git a/app/src/main/res/menu/menu_toolbar.xml b/app/src/main/res/menu/menu_toolbar.xml index dbca3d03..58dd6b04 100644 --- a/app/src/main/res/menu/menu_toolbar.xml +++ b/app/src/main/res/menu/menu_toolbar.xml @@ -16,6 +16,6 @@ app:showAsAction="never" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f33182b..e1f073f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -84,7 +84,7 @@ Copy URL Export update Show changelog - https://download.lineageos.org/%1$s/changes + https://gitlab.e.foundation/e/os/releases/-/releases/v%1$s-s Prioritize update process Update recovery It is impossible to disable Lineage Recovery updates on this device. @@ -179,4 +179,7 @@ /e/OS %1$s /e/OS %1$s - %2$s + + + Show release notes -- GitLab From f96ea8a80462ec39721b7c6582771e2475d4a592 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Wed, 11 Jul 2018 10:16:02 +0200 Subject: [PATCH 03/42] Updater: Change default user-agent Change-Id: Ie5d8624b4fa92012459a7c4e05494a926024bba0 --- .../lineageos/updater/download/HttpURLConnectionClient.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java b/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java index b9c4b5dc..a3d54c22 100644 --- a/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java +++ b/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java @@ -58,6 +58,11 @@ public class HttpURLConnectionClient implements DownloadClient { DownloadClient.DownloadCallback callback, boolean useDuplicateLinks) throws IOException { mClient = (HttpURLConnection) new URL(url).openConnection(); + + String defaultUserAgent = mClient.getRequestProperty("User-Agent"); + String newUserAgent = defaultUserAgent+" ota_007_eels"; + mClient.setRequestProperty("User-Agent", newUserAgent); + mDestination = destination; mProgressListener = progressListener; mCallback = callback; -- GitLab From ef3dfbb740afadd937147c5c9d3ef8a2d2b0ef01 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Mon, 28 Sep 2020 15:46:49 +0000 Subject: [PATCH 04/42] Updater: Update the OTA url Signed-off-by: Aayush Gupta Change-Id: I1d53b83298ff322ce43d6730debf2b93bffd6458 --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e1f073f0..03010d16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,7 +32,7 @@ {type} - Build type {incr} - Incremental version --> - https://download.lineageos.org/api/v1/{device}/{type}/{incr} + https://ota.ecloud.global/api/v1/{device}/{type}/{incr} Verification failed Verifying update -- GitLab From 7485e66890f32c01b3aa6a71db8a29408b202ff8 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Thu, 24 Jan 2019 16:29:59 +0000 Subject: [PATCH 05/42] Updater: Allow OTA updates with different version number Signed-off-by: Aayush Gupta Change-Id: I24ee83c5a94f47742f6c9cad23630bc6833cfe81 --- app/src/main/java/org/lineageos/updater/misc/Utils.java | 4 +--- 1 file changed, 1 insertion(+), 3 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 8db5cdbf..ae645856 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -114,9 +114,7 @@ public class Utils { 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)); + update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)); } public static List parseJson(File file, boolean compatibleOnly) -- GitLab From e3ca05bc787dc6d50d00da51466a0a8d63297de9 Mon Sep 17 00:00:00 2001 From: Sooraj S Date: Tue, 28 Jul 2020 14:23:25 +0000 Subject: [PATCH 06/42] Updater: Use helper function for parsing version code Fix: Handle use case 1.0 is bigger than 0.9 Semantic versioning Signed-off-by: Alexandre Roux D'Anzi Signed-off-by: Aayush Gupta Change-Id: Id107366ebf38f1e269101b4baeac10f3991fe1bb --- .../org/lineageos/updater/misc/Utils.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 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 ae645856..bca99360 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -54,6 +54,8 @@ 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,12 +98,19 @@ public class Utils { } public static boolean isCompatible(UpdateBaseInfo update) { - if (update.getVersion().compareTo(SystemProperties.get(Constants.PROP_BUILD_VERSION)) < 0) { - Log.d(TAG, update.getName() + " is older than current Android version"); - return false; - } + int[] updateVersionParts = parseSemVer(update.getVersion()); + int updateMajorVersion = updateVersionParts[0]; + int updateMinorVersion = updateVersionParts[1]; + Log.d(TAG, "Update : Major "+updateMajorVersion +" Minor "+ updateMinorVersion ); + + 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 (!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; } @@ -109,9 +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 From 5a50277c5fd8f588811196a6e77d4b3b87848d5d Mon Sep 17 00:00:00 2001 From: Mohit Mali Date: Mon, 15 Feb 2021 15:13:40 +0530 Subject: [PATCH 07/42] Updater: Check updates daily Signed-off-by: Aayush Gupta Change-Id: Iad764a791645bdcaa28ebb01b9426afe4aa68393 --- app/src/main/java/org/lineageos/updater/misc/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bca99360..502f897e 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -417,7 +417,7 @@ public class Utils { public static int getUpdateCheckSetting(Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); return preferences.getInt(Constants.PREF_AUTO_UPDATES_CHECK_INTERVAL, - Constants.AUTO_UPDATES_CHECK_INTERVAL_WEEKLY); + Constants.AUTO_UPDATES_CHECK_INTERVAL_DAILY); } public static boolean isUpdateCheckEnabled(Context context) { -- GitLab From 9c001d68bef6d2527e90a4ddefc5628be17286b0 Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Tue, 23 Mar 2021 10:59:02 +0530 Subject: [PATCH 08/42] Updater: Enable auto deletion of updates by default Signed-off-by: Aayush Gupta Change-Id: Iea43138b6538233b8966db3274ea22c8875a82f8 --- app/src/main/java/org/lineageos/updater/UpdatesActivity.java | 2 +- .../java/org/lineageos/updater/controller/UpdaterService.java | 2 +- app/src/main/java/org/lineageos/updater/misc/Utils.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index 25ca0b8b..ba1b857d 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -592,7 +592,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); autoCheckInterval.setSelection(Utils.getUpdateCheckSetting(this)); - autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false)); + autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true)); meteredNetworkWarning.setChecked(prefs.getBoolean(Constants.PREF_METERED_NETWORK_WARNING, prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true))); abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, false)); diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index c6a5ac6a..903d1205 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -414,7 +414,7 @@ public class UpdaterService extends Service { mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); - boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false); + boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); boolean isLocal = Update.LOCAL_ID.equals(update.getDownloadId()); // Always delete local updates if (deleteUpdate || isLocal) { 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 502f897e..2ee635ce 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -316,7 +316,7 @@ public class Utils { long prevTimestamp = preferences.getLong(Constants.PREF_INSTALL_OLD_TIMESTAMP, 0); String lastUpdatePath = preferences.getString(Constants.PREF_INSTALL_PACKAGE_PATH, null); boolean reinstalling = preferences.getBoolean(Constants.PREF_INSTALL_AGAIN, false); - boolean deleteUpdates = preferences.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, false); + boolean deleteUpdates = preferences.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); if ((buildTimestamp != prevTimestamp || reinstalling) && deleteUpdates && lastUpdatePath != null) { File lastUpdate = new File(lastUpdatePath); -- GitLab From dcef6dcadb13e81a52664cd1161316bb1dcbcf9d Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Thu, 25 Mar 2021 12:32:31 +0530 Subject: [PATCH 09/42] Updater: Rework logic to check for new updates - Use the current system's version against update's version to check for new updates Signed-off-by: Aayush Gupta Change-Id: I839033daa355f7faddb4ff641f1ffa59600b7472 --- .../org/lineageos/updater/UpdatesActivity.java | 2 +- .../lineageos/updater/UpdatesCheckReceiver.java | 2 +- .../java/org/lineageos/updater/misc/Utils.java | 17 ++++++----------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index ba1b857d..dc83ee3a 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -426,7 +426,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport preferences.edit().putLong(Constants.PREF_LAST_UPDATE_CHECK, millis).apply(); updateLastCheckedString(); if (json.exists() && Utils.isUpdateCheckEnabled(this) && - Utils.checkForNewUpdates(json, jsonNew)) { + Utils.checkForNewUpdates(jsonNew)) { UpdatesCheckReceiver.updateRepeatingUpdatesCheck(this); } // In case we set a one-shot check because of a previous failure diff --git a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java index 9f454239..275b3519 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java @@ -90,7 +90,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { @Override public void onSuccess() { try { - if (json.exists() && Utils.checkForNewUpdates(json, jsonNew)) { + if (json.exists() && Utils.checkForNewUpdates(jsonNew)) { showNotification(context); updateRepeatingUpdatesCheck(context); } 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 2ee635ce..8a226f3e 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -236,22 +236,17 @@ public class Utils { /** * Compares two json formatted updates list files * - * @param oldJson old update list * @param newJson new update list - * @return true if newJson has at least a compatible update not available in oldJson + * @return true if newJson has an update with higher version than the installed system */ - public static boolean checkForNewUpdates(File oldJson, File newJson) + public static boolean checkForNewUpdates(File newJson) throws IOException, JSONException { - List oldList = parseJson(oldJson, true); List newList = parseJson(newJson, true); - Set oldIds = new HashSet<>(); - for (UpdateInfo update : oldList) { - oldIds.add(update.getDownloadId()); - } - // In case of no new updates, the old list should - // have all (if not more) the updates + float currentVersion = Float.parseFloat(BuildInfoUtils.getBuildVersion()); + for (UpdateInfo update : newList) { - if (!oldIds.contains(update.getDownloadId())) { + if (Float.parseFloat(update.getVersion()) > currentVersion) { + Log.d(TAG, "New compatiable update available"); return true; } } -- GitLab From 13c178a8549bcf944813179d9a5d6d441c90c261 Mon Sep 17 00:00:00 2001 From: Mohit Mali Date: Fri, 2 Apr 2021 18:48:31 +0000 Subject: [PATCH 10/42] Updater: Check in Settings if the device has to fetch updates from the staging OTA server Change-Id: Ice445b0ae4086dfbea91b3a34b7f13c3553282d0 --- .../org/lineageos/updater/misc/Utils.java | 31 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) 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 8a226f3e..ca0957d3 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2017-2023 The LineageOS Project + * Copyright (C) 2022 ECORP SAS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +23,11 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.database.Cursor; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; +import android.net.Uri; import android.os.SystemProperties; import android.os.storage.StorageManager; import android.util.Log; @@ -60,6 +63,7 @@ import java.util.regex.Pattern; public class Utils { private static final String TAG = "Utils"; + private static final String CONTENT_URI_PATH = "content://custom.setting.Provider.OTA_SERVER/cte"; private Utils() { } @@ -184,7 +188,20 @@ public class Utils { SystemProperties.get(Constants.PROP_DEVICE)); String type = SystemProperties.get(Constants.PROP_RELEASE_TYPE).toLowerCase(Locale.ROOT); - String serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI); + String serverUrl = ""; + if (retrieveStatus(context) != null) { + if (retrieveStatus(context).equals("true")) { + serverUrl = context.getString(R.string.ota_staging_server_url); + return serverUrl.replace("{device}", device) + .replace("{type}", type) + .replace("{incr}", incrementalVersion); + } else { + serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI); + } + } else { + serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI); + } + if (serverUrl.trim().isEmpty()) { serverUrl = context.getString(R.string.updater_server_url); } @@ -194,6 +211,18 @@ public class Utils { .replace("{incr}", incrementalVersion); } + /*get the status from database that ota option is on or off*/ + public static String retrieveStatus(Context context) { + String status = null; + Cursor cursor = context.getContentResolver().query(Uri.parse(CONTENT_URI_PATH), null, "id=?", new String[]{"1"}, "Status"); + if (cursor.moveToFirst()) { + do { + status = cursor.getString(cursor.getColumnIndex("Status")); + } while (cursor.moveToNext()); + } + return status; + } + public static String getUpgradeBlockedURL(Context context) { String device = SystemProperties.get(Constants.PROP_NEXT_DEVICE, SystemProperties.get(Constants.PROP_DEVICE)); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 03010d16..85206b09 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,6 +33,7 @@ {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 58e327e0975ecbbc99d00e63a4619f61890243bc Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Thu, 16 Aug 2018 11:29:48 +0200 Subject: [PATCH 11/42] Change displayed version value Change-Id: I28123e3108e795150f1c038de62e379ee2ae0e69 Update database schema Updater: Adapt displayVersion to show proper versioning Change-Id: I9f936bde0a380f0b80fe4382776641082a2b2a12 --- .../java/org/lineageos/updater/UpdatesActivity.java | 2 +- .../java/org/lineageos/updater/UpdatesDbHelper.java | 8 +++++++- .../org/lineageos/updater/UpdatesListAdapter.java | 4 ++-- .../org/lineageos/updater/misc/BuildInfoUtils.java | 4 ++++ .../java/org/lineageos/updater/misc/Constants.java | 1 + .../main/java/org/lineageos/updater/misc/Utils.java | 5 +++++ .../java/org/lineageos/updater/model/UpdateBase.java | 11 +++++++++++ .../org/lineageos/updater/model/UpdateBaseInfo.java | 2 ++ 8 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index dc83ee3a..23e2e239 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -181,7 +181,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport TextView headerTitle = findViewById(R.id.header_title); headerTitle.setText(getString(R.string.header_title_text, - Utils.getDisplayVersion(BuildInfoUtils.getBuildVersion()))); + Utils.getDisplayVersion(BuildInfoUtils.getDisplayVersion()))); updateLastCheckedString(); diff --git a/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java b/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java index 6c11a60c..9dadd4b6 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java @@ -30,7 +30,7 @@ import java.util.List; public class UpdatesDbHelper extends SQLiteOpenHelper { - public static final int DATABASE_VERSION = 1; + public static final int DATABASE_VERSION = 2; public static final String DATABASE_NAME = "updates.db"; public static class UpdateEntry implements BaseColumns { @@ -41,6 +41,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { public static final String COLUMN_NAME_TIMESTAMP = "timestamp"; public static final String COLUMN_NAME_TYPE = "type"; public static final String COLUMN_NAME_VERSION = "version"; + public static final String COLUMN_NAME_DISPLAY_VERSION = "display_version"; public static final String COLUMN_NAME_SIZE = "size"; } @@ -53,6 +54,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { UpdateEntry.COLUMN_NAME_TIMESTAMP + " INTEGER," + UpdateEntry.COLUMN_NAME_TYPE + " TEXT," + UpdateEntry.COLUMN_NAME_VERSION + " TEXT," + + UpdateEntry.COLUMN_NAME_DISPLAY_VERSION + " TEXT," + UpdateEntry.COLUMN_NAME_SIZE + " INTEGER)"; private static final String SQL_DELETE_ENTRIES = @@ -89,6 +91,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { values.put(UpdateEntry.COLUMN_NAME_TIMESTAMP, update.getTimestamp()); values.put(UpdateEntry.COLUMN_NAME_TYPE, update.getType()); values.put(UpdateEntry.COLUMN_NAME_VERSION, update.getVersion()); + values.put(UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, update.getDisplayVersion()); values.put(UpdateEntry.COLUMN_NAME_SIZE, update.getFileSize()); } @@ -125,6 +128,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { UpdateEntry.COLUMN_NAME_TIMESTAMP, UpdateEntry.COLUMN_NAME_TYPE, UpdateEntry.COLUMN_NAME_VERSION, + UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, UpdateEntry.COLUMN_NAME_STATUS, UpdateEntry.COLUMN_NAME_SIZE, }; @@ -146,6 +150,8 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { update.setType(cursor.getString(index)); index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_VERSION); update.setVersion(cursor.getString(index)); + index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_DISPLAY_VERSION); + update.setDisplayVersion(cursor.getString(index)); index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_STATUS); update.setPersistentStatus(cursor.getInt(index)); index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_SIZE); diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index e9b76d90..693463ca 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -280,7 +280,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter Date: Wed, 24 Aug 2022 13:25:31 +0000 Subject: [PATCH 12/42] Updater: Change dialog text Change-Id: Ic9f5d78d9983e6e3c3f743547ea4077c6c520a1f --- .../main/java/org/lineageos/updater/UpdatesListAdapter.java | 2 +- app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index 693463ca..9192178b 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -533,7 +533,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter preferences.edit() .putBoolean(Constants.HAS_SEEN_INFO_DIALOG, true) .apply()) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 85206b09..4a98c376 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -183,4 +183,7 @@ Show release notes + + + /e/OS updates are full installation packages. That means you can always install only the latest update, even if you skipped some in between! -- GitLab From bca32a5240e67e82bd3140993783fc08759f9a87 Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Mon, 23 May 2022 10:26:53 +0530 Subject: [PATCH 13/42] Updater: UpdatesCheckReceiver: Migrate to setExactAndAllowWhileIdle Signed-off-by: Aayush Gupta fixup! Updater: UpdatesCheckReceiver: Migrate to setExactAndAllowWhileIdle This commit partially reverts 99cd083ee69a97042ab8a0e790ee08e6e3aa3a15 (cherry picked from commit 90642329db2c9959d59eee61d8f6ee0e9f011233) --- .../java/org/lineageos/updater/UpdatesCheckReceiver.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java index 275b3519..1bc3bf3e 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java @@ -160,8 +160,8 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { PendingIntent updateCheckIntent = getRepeatingUpdatesCheckIntent(context); AlarmManager alarmMgr = context.getSystemService(AlarmManager.class); - alarmMgr.setRepeating(AlarmManager.RTC, System.currentTimeMillis() + - Utils.getUpdateCheckInterval(context), Utils.getUpdateCheckInterval(context), + alarmMgr.setExactAndAllowWhileIdle(AlarmManager.RTC, + System.currentTimeMillis() + Utils.getUpdateCheckInterval(context), updateCheckIntent); Date nextCheckDate = new Date(System.currentTimeMillis() + @@ -184,7 +184,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { long millisToNextCheck = AlarmManager.INTERVAL_HOUR * 2; PendingIntent updateCheckIntent = getUpdatesCheckIntent(context); AlarmManager alarmMgr = context.getSystemService(AlarmManager.class); - alarmMgr.set(AlarmManager.ELAPSED_REALTIME, + alarmMgr.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + millisToNextCheck, updateCheckIntent); -- GitLab From 47e554bf1c224c3ab54fcaa732a722ff89e93201 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Tue, 20 Sep 2022 12:59:40 +0000 Subject: [PATCH 14/42] Updater: Add support for SystemUpdateManager status --- .../lineageos/updater/UpdatesActivity.java | 2 +- .../updater/UpdatesCheckReceiver.java | 2 +- .../updater/controller/UpdaterService.java | 21 +++++++++ .../org/lineageos/updater/misc/Utils.java | 45 +++++++++++++++---- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index 23e2e239..086a21eb 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -426,7 +426,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport preferences.edit().putLong(Constants.PREF_LAST_UPDATE_CHECK, millis).apply(); updateLastCheckedString(); if (json.exists() && Utils.isUpdateCheckEnabled(this) && - Utils.checkForNewUpdates(jsonNew)) { + Utils.checkForNewUpdates(jsonNew, this)) { UpdatesCheckReceiver.updateRepeatingUpdatesCheck(this); } // In case we set a one-shot check because of a previous failure diff --git a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java index 1bc3bf3e..07beb1a7 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java @@ -90,7 +90,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { @Override public void onSuccess() { try { - if (json.exists() && Utils.checkForNewUpdates(jsonNew)) { + if (json.exists() && Utils.checkForNewUpdates(jsonNew, context)) { showNotification(context); updateRepeatingUpdatesCheck(context); } diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index 903d1205..5d019195 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -15,6 +15,10 @@ */ package org.lineageos.updater.controller; +import static android.os.SystemUpdateManager.STATUS_IN_PROGRESS; +import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD; +import static android.os.SystemUpdateManager.STATUS_WAITING_REBOOT; + import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; @@ -259,6 +263,7 @@ public class UpdaterService extends Service { private void handleUpdateStatusChange(UpdateInfo update) { switch (update.getStatus()) { case DELETED: { + notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); stopForeground(STOP_FOREGROUND_DETACH); mNotificationBuilder.setOngoing(false); mNotificationManager.cancel(NOTIFICATION_ID); @@ -266,6 +271,7 @@ public class UpdaterService extends Service { break; } case STARTING: { + notifySystemUpdaterService(STATUS_IN_PROGRESS, update); mNotificationBuilder.mActions.clear(); mNotificationBuilder.setProgress(0, 0, true); mNotificationStyle.setSummaryText(null); @@ -282,6 +288,7 @@ public class UpdaterService extends Service { break; } case DOWNLOADING: { + notifySystemUpdaterService(STATUS_IN_PROGRESS, update); String text = getString(R.string.downloading_notification); mNotificationStyle.bigText(text); mNotificationBuilder.setStyle(mNotificationStyle); @@ -296,6 +303,7 @@ public class UpdaterService extends Service { break; } case PAUSED: { + notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); stopForeground(STOP_FOREGROUND_DETACH); // In case we pause before the first progress update mNotificationBuilder.setProgress(100, update.getProgress(), false); @@ -315,6 +323,7 @@ public class UpdaterService extends Service { break; } case PAUSED_ERROR: { + notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); stopForeground(STOP_FOREGROUND_DETACH); int progress = update.getProgress(); // In case we pause before the first progress update @@ -335,6 +344,7 @@ public class UpdaterService extends Service { break; } case VERIFYING: { + notifySystemUpdaterService(STATUS_IN_PROGRESS, update); mNotificationBuilder.setProgress(0, 0, true); mNotificationStyle.setSummaryText(null); mNotificationBuilder.setStyle(mNotificationStyle); @@ -347,6 +357,7 @@ public class UpdaterService extends Service { break; } case VERIFIED: { + notifySystemUpdaterService(STATUS_IN_PROGRESS, update); stopForeground(STOP_FOREGROUND_DETACH); mNotificationBuilder.setStyle(null); mNotificationBuilder.setSmallIcon(R.drawable.ic_system_update); @@ -361,6 +372,7 @@ public class UpdaterService extends Service { break; } case VERIFICATION_FAILED: { + notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); stopForeground(STOP_FOREGROUND_DETACH); mNotificationBuilder.setStyle(null); mNotificationBuilder.setSmallIcon(android.R.drawable.stat_sys_warning); @@ -375,6 +387,7 @@ public class UpdaterService extends Service { break; } case INSTALLING: { + notifySystemUpdaterService(STATUS_IN_PROGRESS, update); mNotificationBuilder.mActions.clear(); mNotificationBuilder.setStyle(mNotificationStyle); mNotificationBuilder.setSmallIcon(R.drawable.ic_system_update); @@ -398,6 +411,7 @@ public class UpdaterService extends Service { break; } case INSTALLED: { + notifySystemUpdaterService(STATUS_WAITING_REBOOT, update); stopForeground(STOP_FOREGROUND_DETACH); mNotificationBuilder.mActions.clear(); mNotificationBuilder.setStyle(null); @@ -425,6 +439,7 @@ public class UpdaterService extends Service { break; } case INSTALLATION_FAILED: { + notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); stopForeground(STOP_FOREGROUND_DETACH); mNotificationBuilder.setStyle(null); mNotificationBuilder.setSmallIcon(android.R.drawable.stat_sys_warning); @@ -439,11 +454,13 @@ public class UpdaterService extends Service { break; } case INSTALLATION_CANCELLED: { + notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); stopForeground(true); tryStopSelf(); break; } case INSTALLATION_SUSPENDED: { + notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); stopForeground(STOP_FOREGROUND_DETACH); // In case we pause before the first progress update mNotificationBuilder.setProgress(100, update.getProgress(), false); @@ -543,4 +560,8 @@ public class UpdaterService extends Service { return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } + + private void notifySystemUpdaterService(int status, UpdateInfo update) { + Utils.updateSystemUpdaterService(this, status, Float.parseFloat(update.getVersion())); + } } 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 92dae28f..a232bbd1 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -16,6 +16,12 @@ */ package org.lineageos.updater.misc; +import static android.os.SystemUpdateManager.KEY_STATUS; +import static android.os.SystemUpdateManager.KEY_TITLE; +import static android.os.SystemUpdateManager.STATUS_IDLE; +import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD; +import static android.os.SystemUpdateManager.STATUS_UNKNOWN; + import android.app.AlarmManager; import android.content.ClipData; import android.content.ClipboardManager; @@ -28,7 +34,10 @@ import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.net.Uri; +import android.os.Bundle; +import android.os.PersistableBundle; import android.os.SystemProperties; +import android.os.SystemUpdateManager; import android.os.storage.StorageManager; import android.util.Log; import android.widget.Toast; @@ -59,7 +68,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.regex.Pattern; - public class Utils { private static final String TAG = "Utils"; @@ -273,18 +281,25 @@ public class Utils { * @param newJson new update list * @return true if newJson has an update with higher version than the installed system */ - public static boolean checkForNewUpdates(File newJson) + public static boolean checkForNewUpdates(File newJson, Context context) throws IOException, JSONException { List newList = parseJson(newJson, true); - float currentVersion = Float.parseFloat(BuildInfoUtils.getBuildVersion()); - + final float currentVersion = Float.parseFloat(BuildInfoUtils.getBuildVersion()); + float highestAvailableVersion = currentVersion; for (UpdateInfo update : newList) { - if (Float.parseFloat(update.getVersion()) > currentVersion) { - Log.d(TAG, "New compatiable update available"); - return true; + float availableversion = Float.parseFloat(update.getVersion()); + if (availableversion > highestAvailableVersion) { + highestAvailableVersion = availableversion; } } - return false; + + if (highestAvailableVersion > currentVersion) { + updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestAvailableVersion); + return true; + } else { + updateSystemUpdaterService(context, STATUS_IDLE, highestAvailableVersion); + return false; + } } /** @@ -479,4 +494,18 @@ public class Utils { // Lineage 20 and up should only be integer values (we don't have minor versions anymore) return (floatVersion >= 20) ? String.valueOf((int)floatVersion) : version; } + + public static void updateSystemUpdaterService(Context context, int status, float version) { + final SystemUpdateManager updateManager = context.getSystemService(SystemUpdateManager.class); + + final Bundle oldInfo = updateManager.retrieveSystemUpdateInfo(); + final int oldStatus = oldInfo.getInt(SystemUpdateManager.KEY_STATUS); + + if (status != oldStatus) { + PersistableBundle infoBundle = new PersistableBundle(); + infoBundle.putInt(KEY_STATUS, status); + infoBundle.putString(KEY_TITLE, String.valueOf(version)); + updateManager.updateSystemUpdateInfo(infoBundle); + } + } } -- GitLab From e384ee4ffff4c09b98005717c356887fded73e07 Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Wed, 7 Sep 2022 15:05:21 +0530 Subject: [PATCH 15/42] Change current version title to our brand name --- app/src/main/java/org/lineageos/updater/UpdatesActivity.java | 2 +- app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index 086a21eb..2f5504d3 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -180,7 +180,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport } TextView headerTitle = findViewById(R.id.header_title); - headerTitle.setText(getString(R.string.header_title_text, + headerTitle.setText(getString(R.string.header_title_text_e, Utils.getDisplayVersion(BuildInfoUtils.getDisplayVersion()))); updateLastCheckedString(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4a98c376..98e168fc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -186,4 +186,7 @@ /e/OS updates are full installation packages. That means you can always install only the latest update, even if you skipped some in between! + + + /e/OS\n%1$s -- GitLab From e64354f8e1bd0880f09463eb83361bcae82e8627 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 13 Oct 2022 14:35:53 +0000 Subject: [PATCH 16/42] S dont crash when receiving maintenance number --- .../updater/controller/UpdaterService.java | 2 +- .../download/HttpURLConnectionClient.java | 6 ++- .../org/lineageos/updater/misc/Utils.java | 41 +++++++++++++------ 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index 5d019195..3703bda9 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -562,6 +562,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/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java b/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java index a3d54c22..df6283b5 100644 --- a/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java +++ b/app/src/main/java/org/lineageos/updater/download/HttpURLConnectionClient.java @@ -16,6 +16,8 @@ package org.lineageos.updater.download; import android.os.SystemClock; +import android.os.SystemProperties; + import android.util.Log; import java.io.File; @@ -32,6 +34,8 @@ import java.util.PriorityQueue; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.lineageos.updater.misc.Constants; + public class HttpURLConnectionClient implements DownloadClient { private final static String TAG = "HttpURLConnectionClient"; @@ -60,7 +64,7 @@ public class HttpURLConnectionClient implements DownloadClient { mClient = (HttpURLConnection) new URL(url).openConnection(); String defaultUserAgent = mClient.getRequestProperty("User-Agent"); - String newUserAgent = defaultUserAgent+" ota_007_eels"; + String newUserAgent = defaultUserAgent + " eOS v" + SystemProperties.get(Constants.PROP_BUILD_VERSION); mClient.setRequestProperty("User-Agent", newUserAgent); mDestination = destination; 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 a232bbd1..4ef53819 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -284,21 +284,36 @@ public class Utils { public static boolean checkForNewUpdates(File newJson, Context context) throws IOException, JSONException { List newList = parseJson(newJson, true); - final float currentVersion = Float.parseFloat(BuildInfoUtils.getBuildVersion()); - float highestAvailableVersion = currentVersion; + int[] deviceVersionParts = parseSemVer(SystemProperties.get(Constants.PROP_BUILD_VERSION)); + int deviceMajorVersion = deviceVersionParts[0]; + int deviceMinorVersion = deviceVersionParts[1]; + int deviceMaintenanceVersion = deviceVersionParts.length > 2 ? deviceVersionParts[2] : 0; + int highestMajorVersion = deviceMajorVersion; + int highestMinorVersion = deviceMinorVersion; + int highestMaintenanceVersion = deviceMaintenanceVersion; + boolean hasUpdate = false; for (UpdateInfo update : newList) { - float availableversion = Float.parseFloat(update.getVersion()); - if (availableversion > highestAvailableVersion) { - highestAvailableVersion = availableversion; + 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 (updateMajorVersion*10000+updateMinorVersion*100+updateMaintenanceVersion >= highestMajorVersion*10000+highestMinorVersion*100+highestMaintenanceVersion) { + highestMajorVersion = updateMajorVersion; + highestMinorVersion = updateMinorVersion; + highestMaintenanceVersion = updateMaintenanceVersion; + } + hasUpdate = true; } } - - if (highestAvailableVersion > currentVersion) { - updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestAvailableVersion); - return true; + if (hasUpdate) { + updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestMajorVersion + "." + highestMinorVersion + (highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); + return true; } else { - updateSystemUpdaterService(context, STATUS_IDLE, highestAvailableVersion); - return false; + updateSystemUpdaterService(context, STATUS_IDLE, highestMajorVersion+"."+highestMinorVersion+(highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); + return false; } } @@ -495,7 +510,7 @@ public class Utils { return (floatVersion >= 20) ? String.valueOf((int)floatVersion) : version; } - 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(); @@ -504,7 +519,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 d0fbfe9f51e91e03da8926cbe183a1eaa03a5231 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 25 Oct 2022 10:47:07 +0530 Subject: [PATCH 17/42] Updater: add missing SCHEDULE_EXACT_ALARM permission --- app/privapp_whitelist_org.lineageos.updater.xml | 1 + app/src/main/AndroidManifest.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/privapp_whitelist_org.lineageos.updater.xml b/app/privapp_whitelist_org.lineageos.updater.xml index d88ad9cb..a6fcac7b 100644 --- a/app/privapp_whitelist_org.lineageos.updater.xml +++ b/app/privapp_whitelist_org.lineageos.updater.xml @@ -16,6 +16,7 @@ --> + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 80fd2bcb..378381d9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ + -- GitLab From 2e606bfcfa20ad0a3a5c9777ca5113c89462baba Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Wed, 24 Jul 2024 20:56:58 +0530 Subject: [PATCH 18/42] Improvements in system page --- .../lineageos/updater/UpdatesActivity.java | 17 +++---- app/src/main/res/layout/activity_updates.xml | 48 +++++++++++++++---- app/src/main/res/values/strings.xml | 3 ++ 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index 2f5504d3..e72ac655 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -391,10 +391,10 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport List sortedUpdates = controller.getUpdates(); if (sortedUpdates.isEmpty()) { findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); - findViewById(R.id.recycler_view).setVisibility(View.GONE); + findViewById(R.id.content).setVisibility(View.GONE); } else { findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); - findViewById(R.id.recycler_view).setVisibility(View.VISIBLE); + findViewById(R.id.content).setVisibility(View.VISIBLE); sortedUpdates.sort((u1, u2) -> Long.compare(u2.getTimestamp(), u1.getTimestamp())); for (UpdateInfo update : sortedUpdates) { updateIds.add(update.getDownloadId()); @@ -554,7 +554,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport mRefreshIconView.setEnabled(false); } } else { - findViewById(R.id.recycler_view).setVisibility(View.GONE); + findViewById(R.id.content).setVisibility(View.GONE); findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.refresh_progress).setVisibility(View.VISIBLE); } @@ -568,11 +568,12 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport } } else { findViewById(R.id.refresh_progress).setVisibility(View.GONE); - if (mAdapter.getItemCount() > 0) { - findViewById(R.id.recycler_view).setVisibility(View.VISIBLE); - } else { - findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); - } + } + + if (mAdapter.getItemCount() > 0) { + findViewById(R.id.content).setVisibility(View.VISIBLE); + } else { + findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); } } diff --git a/app/src/main/res/layout/activity_updates.xml b/app/src/main/res/layout/activity_updates.xml index adfe1a27..864ab818 100644 --- a/app/src/main/res/layout/activity_updates.xml +++ b/app/src/main/res/layout/activity_updates.xml @@ -48,14 +48,24 @@ android:paddingStart="16dp" app:layout_collapseMode="parallax"> + + @@ -112,13 +121,32 @@ android:textColor="?android:textColorSecondary" /> - + android:orientation="vertical" + android:visibility="gone" + app:layout_behavior="@string/appbar_scrolling_view_behavior"> + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 98e168fc..94c9d75f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -189,4 +189,7 @@ /e/OS\n%1$s + + Available updates: + Current version: -- GitLab From ccc2939385ab17a8925c7eef6b166fcef0e13891 Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 7 Nov 2022 14:45:44 +0530 Subject: [PATCH 19/42] Updater: add additional intervals for debug Change-Id: Iddbb5da58cc5a8d7caca627a6747ccd8fe791c3c --- .../lineageos/updater/UpdatesActivity.java | 20 +++++++++++++++++++ .../org/lineageos/updater/misc/Constants.java | 3 +++ .../org/lineageos/updater/misc/Utils.java | 13 ++++++++++++ .../main/res/layout/preferences_dialog.xml | 3 +-- app/src/main/res/values/arrays.xml | 6 ++++++ app/src/main/res/values/strings.xml | 3 +++ 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index e72ac655..f30c7bf1 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -43,6 +43,7 @@ import android.view.View; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; +import android.widget.ArrayAdapter; import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; @@ -80,6 +81,7 @@ import org.lineageos.updater.model.UpdateInfo; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -592,7 +594,25 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + + List intervalList = new ArrayList<>(Arrays.asList(getResources().getStringArray( + R.array.menu_auto_updates_check_interval_entries))); + + if (Utils.isDevModeOn(this)) { + // Add additional intervals while enabling developer options is on + intervalList.addAll(Arrays.asList(getResources().getStringArray( + R.array.menu_auto_updates_check_interval_entries_dev))); + } else if (Utils.getUpdateCheckSetting(this) > 3) { + prefs.edit().putInt(Constants.PREF_AUTO_UPDATES_CHECK_INTERVAL, + Constants.AUTO_UPDATES_CHECK_INTERVAL_DAILY).apply(); + } + + ArrayAdapter adapter = new ArrayAdapter<>(this, + android.R.layout.simple_list_item_1, intervalList); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + autoCheckInterval.setAdapter(adapter); autoCheckInterval.setSelection(Utils.getUpdateCheckSetting(this)); + autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true)); meteredNetworkWarning.setChecked(prefs.getBoolean(Constants.PREF_METERED_NETWORK_WARNING, prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true))); 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 c6b96aed..28f8a147 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Constants.java +++ b/app/src/main/java/org/lineageos/updater/misc/Constants.java @@ -27,6 +27,9 @@ public final class Constants { public static final int AUTO_UPDATES_CHECK_INTERVAL_DAILY = 1; public static final int AUTO_UPDATES_CHECK_INTERVAL_WEEKLY = 2; public static final int AUTO_UPDATES_CHECK_INTERVAL_MONTHLY = 3; + public static final int AUTO_UPDATES_CHECK_INTERVAL_5_MINUTES = 4; + public static final int AUTO_UPDATES_CHECK_INTERVAL_10_MINUTES = 5; + public static final int AUTO_UPDATES_CHECK_INTERVAL_30_MINUTES = 6; public static final String PREF_LAST_UPDATE_CHECK = "last_update_check"; public static final String PREF_AUTO_UPDATES_CHECK_INTERVAL = "auto_updates_check_interval"; 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 4ef53819..b3cc98ce 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -39,6 +39,7 @@ import android.os.PersistableBundle; import android.os.SystemProperties; import android.os.SystemUpdateManager; import android.os.storage.StorageManager; +import android.provider.Settings; import android.util.Log; import android.widget.Toast; @@ -455,6 +456,12 @@ public class Utils { return isAB; } + public static boolean isDevModeOn(Context context) { + int devOptions = Settings.Secure.getInt(context.getContentResolver(), + Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0); + return devOptions == 1; + } + public static boolean hasTouchscreen(Context context) { return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN); } @@ -485,6 +492,12 @@ public class Utils { public static long getUpdateCheckInterval(Context context) { switch (Utils.getUpdateCheckSetting(context)) { + case Constants.AUTO_UPDATES_CHECK_INTERVAL_5_MINUTES: + return AlarmManager.INTERVAL_FIFTEEN_MINUTES / 3; + case Constants.AUTO_UPDATES_CHECK_INTERVAL_10_MINUTES: + return AlarmManager.INTERVAL_HALF_HOUR / 3; + case Constants.AUTO_UPDATES_CHECK_INTERVAL_30_MINUTES: + return AlarmManager.INTERVAL_HALF_HOUR; case Constants.AUTO_UPDATES_CHECK_INTERVAL_DAILY: return AlarmManager.INTERVAL_DAY; case Constants.AUTO_UPDATES_CHECK_INTERVAL_WEEKLY: diff --git a/app/src/main/res/layout/preferences_dialog.xml b/app/src/main/res/layout/preferences_dialog.xml index c1b43560..013cf07d 100644 --- a/app/src/main/res/layout/preferences_dialog.xml +++ b/app/src/main/res/layout/preferences_dialog.xml @@ -25,8 +25,7 @@ android:id="@+id/preferences_auto_updates_check_interval" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_weight="1" - android:entries="@array/menu_auto_updates_check_interval_entries" /> + android:layout_weight="1" /> @string/menu_auto_updates_check_interval_weekly @string/menu_auto_updates_check_interval_monthly + + + @string/menu_auto_updates_check_interval_5_minutes + @string/menu_auto_updates_check_interval_10_minutes + @string/menu_auto_updates_check_interval_30_minutes + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 94c9d75f..25e4d5dd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,6 +76,9 @@ Refresh Preferences Auto updates check + Every 5 minutes + Every 10 minutes + Every 30 minutes Once a day Once a week Once a month -- GitLab From 0f042f1b2b4d85b5c108ad9c61406e249304a8c0 Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 7 Nov 2022 23:36:49 +0530 Subject: [PATCH 20/42] Updater: Add network ConnectionStateMonitor Change-Id: I54847a54e1cb0bff262deb3e57cae30fcd85b26f Updater: Move ConnectionStateMonitor to kotlin Change-Id: I7e0a1f68b71afe620706813daf76258b0c1682ae Updater: Improve ConnectionStateMonitor behaviour - Keep updater app alive till device back online for network callback. - Remove network callback once the internet is back. - Wait 10 seconds before doing anything when the device is online. Change-Id: I55e631cbf6cec9c19ec13e513a54ceaf10f8b2b9 Updater: Change one-shot check to 15 minutes - It was two hours previously Change-Id: I4fb4ae38805cedecbbd3bc86c930dfb4c3c11cc6 Updater: UpdatesCheckReceiver: Make exact alarm work every time Change-Id: Id950e6c4f44a445f78be60416e159045d120152e Updater: Simplify activity status for cnstate monitor Change-Id: I1a46444c35ce40c967a16cc8a5ae2d099e14d62e --- app/Android.bp | 5 +- .../updater/UpdatesCheckReceiver.java | 63 ++++++++++++---- .../updater/controller/UpdaterService.java | 9 ++- .../updater/misc/ConnectionStateMonitor.kt | 73 +++++++++++++++++++ .../org/lineageos/updater/misc/Constants.java | 1 + 5 files changed, 134 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/org/lineageos/updater/misc/ConnectionStateMonitor.kt diff --git a/app/Android.bp b/app/Android.bp index 4f79f132..a370fb09 100644 --- a/app/Android.bp +++ b/app/Android.bp @@ -10,7 +10,10 @@ android_app { // Include SettingsLib and its dependencies defaults: ["SettingsLibDefaults"], - srcs: ["src/main/java/**/*.java"], + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], resource_dirs: ["src/main/res"], manifest: "src/main/AndroidManifest.xml", diff --git a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java index 07beb1a7..d16e9c5b 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java @@ -23,6 +23,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.net.ConnectivityManager; +import android.net.NetworkCapabilities; +import android.net.NetworkRequest; import android.os.SystemClock; import android.util.Log; @@ -30,7 +33,9 @@ import androidx.core.app.NotificationCompat; import androidx.preference.PreferenceManager; import org.json.JSONException; +import org.lineageos.updater.controller.UpdaterService; import org.lineageos.updater.download.DownloadClient; +import org.lineageos.updater.misc.ConnectionStateMonitor; import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.Utils; @@ -49,6 +54,15 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { private static final String NEW_UPDATES_NOTIFICATION_CHANNEL = "new_updates_notification_channel"; + private final NetworkRequest networkRequest = new NetworkRequest.Builder() + .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) + .addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET) + .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) + .build(); + + private ConnectivityManager.NetworkCallback cnState; + private ConnectivityManager connectivityManager; + @Override public void onReceive(final Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { @@ -62,15 +76,21 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { return; } - if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { - // Set a repeating alarm on boot to check for new updates once per day - scheduleRepeatingUpdatesCheck(context); - } + // Exact alarms does not support repeating, so update to make it + // work like repeating alarms. To check for update at the exact time. + updateRepeatingUpdatesCheck(context); + + cnState = new ConnectionStateMonitor().getInstance(context); + connectivityManager = (ConnectivityManager) + context.getSystemService(Context.CONNECTIVITY_SERVICE); if (!Utils.isNetworkAvailable(context)) { - Log.d(TAG, "Network not available, scheduling new check"); - scheduleUpdatesCheck(context); + if (!UpdaterService.isNetworkCallBackActive()) { + setupNetworkCallback(true); + } return; + } else if (UpdaterService.isNetworkCallBackActive()) { + setupNetworkCallback(false); } final File json = Utils.getCachedUpdateList(context); @@ -122,6 +142,21 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { } } + public void setupNetworkCallback(boolean shouldEnable) { + if (shouldEnable) { + connectivityManager.registerNetworkCallback(networkRequest, cnState); + } else { + try { + connectivityManager.unregisterNetworkCallback(cnState); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Network callback was not registered"); + } + } + + UpdaterService.setNetworkCallBackActive(shouldEnable); + Log.d(TAG, "Network callback enabled: " + shouldEnable); + } + private static void showNotification(Context context) { NotificationManager notificationManager = context.getSystemService( NotificationManager.class); @@ -160,12 +195,10 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { PendingIntent updateCheckIntent = getRepeatingUpdatesCheckIntent(context); AlarmManager alarmMgr = context.getSystemService(AlarmManager.class); - alarmMgr.setExactAndAllowWhileIdle(AlarmManager.RTC, - System.currentTimeMillis() + Utils.getUpdateCheckInterval(context), - updateCheckIntent); + long nextCheck = System.currentTimeMillis() + Utils.getUpdateCheckInterval(context); + alarmMgr.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextCheck, updateCheckIntent); - Date nextCheckDate = new Date(System.currentTimeMillis() + - Utils.getUpdateCheckInterval(context)); + Date nextCheckDate = new Date(nextCheck); Log.d(TAG, "Setting automatic updates check: " + nextCheckDate); } @@ -181,14 +214,14 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { } public static void scheduleUpdatesCheck(Context context) { - long millisToNextCheck = AlarmManager.INTERVAL_HOUR * 2; + long millisToNextCheck = AlarmManager.INTERVAL_FIFTEEN_MINUTES; PendingIntent updateCheckIntent = getUpdatesCheckIntent(context); AlarmManager alarmMgr = context.getSystemService(AlarmManager.class); + long nextCheck = SystemClock.elapsedRealtime() + millisToNextCheck; alarmMgr.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, - SystemClock.elapsedRealtime() + millisToNextCheck, - updateCheckIntent); + nextCheck, updateCheckIntent); - Date nextCheckDate = new Date(System.currentTimeMillis() + millisToNextCheck); + Date nextCheckDate = new Date(nextCheck); Log.d(TAG, "Setting one-shot updates check: " + nextCheckDate); } diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index 3703bda9..fc589357 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -77,6 +77,7 @@ public class UpdaterService extends Service { private static final int NOTIFICATION_ID = 10; private final IBinder mBinder = new LocalBinder(); + private static boolean isNetworkCallBackActive = false; private boolean mHasClients; private BroadcastReceiver mBroadcastReceiver; @@ -254,7 +255,7 @@ public class UpdaterService extends Service { private void tryStopSelf() { if (!mHasClients && !mUpdaterController.hasActiveDownloads() && - !mUpdaterController.isInstallingUpdate()) { + !mUpdaterController.isInstallingUpdate() && !isNetworkCallBackActive()) { Log.d(TAG, "Service no longer needed, stopping"); stopSelf(); } @@ -482,6 +483,12 @@ public class UpdaterService extends Service { } } + public static void setNetworkCallBackActive(boolean isActive) { + isNetworkCallBackActive = isActive; + } + + public static boolean isNetworkCallBackActive() { return isNetworkCallBackActive; } + private void handleDownloadProgressChange(UpdateInfo update) { int progress = update.getProgress(); mNotificationBuilder.setProgress(100, progress, false); diff --git a/app/src/main/java/org/lineageos/updater/misc/ConnectionStateMonitor.kt b/app/src/main/java/org/lineageos/updater/misc/ConnectionStateMonitor.kt new file mode 100644 index 00000000..583d770c --- /dev/null +++ b/app/src/main/java/org/lineageos/updater/misc/ConnectionStateMonitor.kt @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 MURENA SAS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.lineageos.updater.misc + +import android.content.Context +import android.content.Intent +import android.net.ConnectivityManager +import android.net.Network +import android.os.Handler +import android.os.Looper +import android.util.Log +import org.lineageos.updater.UpdatesCheckReceiver + +class ConnectionStateMonitor { + companion object { + private var instance: ConnectivityManager.NetworkCallback? = null + } + + fun getInstance(context: Context): ConnectivityManager.NetworkCallback { + if (instance == null) { + instance = networkCallback(context) + } + + return instance!! + } + + /** + * API callbacks to determine which status we currently in + * we need the below callbacks: + * - onAvailable: device connected to a network of course + * - onLost: when the connection completely lost + */ + fun networkCallback(context: Context) = object: ConnectivityManager.NetworkCallback() { + private val tag = "ConnectionStateMonitor" + private val delayExecute = 10000L // 10 seconds + + private fun startUpdatesCheckReceiver(): Runnable = Runnable { + val broadcastIntent = Intent() + broadcastIntent.setClassName(context, UpdatesCheckReceiver::class.java.name) + context.sendBroadcast(broadcastIntent) + } + + private fun checkForUpdates() { + // Delay because some phones takes time go online + Handler(Looper.getMainLooper()).postDelayed( + startUpdatesCheckReceiver(), delayExecute + ) + } + + override fun onAvailable(network: Network) { + Log.d(tag, "Network available") + checkForUpdates() + } + + override fun onLost(network: Network) { + Log.d(tag, "Network not available") + checkForUpdates() + } + } +} 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 28f8a147..e3772582 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Constants.java +++ b/app/src/main/java/org/lineageos/updater/misc/Constants.java @@ -38,6 +38,7 @@ public final class Constants { public static final String PREF_METERED_NETWORK_WARNING = "pref_metered_network_warning"; public static final String PREF_MOBILE_DATA_WARNING = "pref_mobile_data_warning"; public static final String PREF_NEEDS_REBOOT_ID = "needs_reboot_id"; + public static final String PREF_NETWORK_CALLBACK_ACTIVE = "pref_network_callback_active"; public static final String UNCRYPT_FILE_EXT = ".uncrypt"; -- GitLab From 2b23cdf60864af245906a7ed5ab4cb24e5fa3f16 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 11 Oct 2022 12:33:10 +0530 Subject: [PATCH 21/42] Updater: Allow A/B devices to override update priority - Changing in mid-shipping will/should not change current value. --- app/src/main/java/org/lineageos/updater/UpdatesActivity.java | 3 ++- app/src/main/res/values/config.xml | 1 + app/src/main/res/values/symbols.xml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index f30c7bf1..eee8d2f4 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -616,7 +616,8 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport autoDelete.setChecked(prefs.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true)); meteredNetworkWarning.setChecked(prefs.getBoolean(Constants.PREF_METERED_NETWORK_WARNING, prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true))); - abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, false)); + abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, + getResources().getBoolean(R.bool.config_prioritizeUpdateProcess))); if (getResources().getBoolean(R.bool.config_hideRecoveryUpdate)) { // Hide the update feature if explicitly requested. diff --git a/app/src/main/res/values/config.xml b/app/src/main/res/values/config.xml index 76ab6862..16ab670f 100644 --- a/app/src/main/res/values/config.xml +++ b/app/src/main/res/values/config.xml @@ -16,4 +16,5 @@ --> false + false diff --git a/app/src/main/res/values/symbols.xml b/app/src/main/res/values/symbols.xml index f3dc0ba3..992614c0 100644 --- a/app/src/main/res/values/symbols.xml +++ b/app/src/main/res/values/symbols.xml @@ -16,4 +16,5 @@ --> + -- GitLab From 9c1478509b60b63f0a19dc166f84b09743931d13 Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 22 Dec 2022 13:35:02 +0530 Subject: [PATCH 22/42] Updater: Check for free space on install Change-Id: Ifb3385c879755dff6686f3f422fa95f80cfc1e99 Updater: Cleanup imports Change-Id: If4949ccf2efb19922c160d82f17a5a63a3b5ed75 --- .../lineageos/updater/UpdatesActivity.java | 2 +- .../lineageos/updater/UpdatesListAdapter.java | 62 ++++++++++++++++--- .../updater/controller/UpdateInstaller.java | 2 +- .../updater/controller/UpdaterService.java | 1 - .../download/HttpURLConnectionClient.java | 5 +- .../org/lineageos/updater/misc/Utils.java | 22 +++++-- app/src/main/res/values/strings.xml | 6 +- 7 files changed, 79 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index eee8d2f4..52acda4f 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -24,9 +24,9 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.res.Configuration; import android.content.ServiceConnection; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.icu.text.DateFormat; import android.net.Uri; import android.os.Build; diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index 9192178b..77373474 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -15,12 +15,10 @@ */ package org.lineageos.updater; -import android.app.Activity; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Resources; -import android.net.Uri; import android.os.BatteryManager; import android.os.PowerManager; import android.text.SpannableString; @@ -40,8 +38,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ContextThemeWrapper; @@ -55,17 +51,18 @@ import com.google.android.material.snackbar.Snackbar; import org.lineageos.updater.controller.UpdaterController; import org.lineageos.updater.controller.UpdaterService; -import org.lineageos.updater.misc.BuildInfoUtils; import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.Utils; import org.lineageos.updater.model.UpdateInfo; import org.lineageos.updater.model.UpdateStatus; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.text.DateFormat; +import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; @@ -326,6 +323,37 @@ public class UpdatesListAdapter extends RecyclerView.Adapter 0) { + requiredSpace -= updateFile.length(); + } + + if (availableFreeSpace < requiredSpace) { + // Not enough space to download file + double spaceNeeded = (requiredSpace - availableFreeSpace) / (1024.0 * 1024.0); + // Ignore if needed space is below 1 MB, like 0.25 + // We only show integer part to the user + if (spaceNeeded >= 1) { + String message = resources.getString(R.string.dialog_free_space_low_message_pct, + new DecimalFormat("# MB").format(spaceNeeded)); + return new AlertDialog.Builder(mActivity) + .setTitle(R.string.dialog_free_space_low_title) + .setMessage(message) + .setPositiveButton(android.R.string.ok, null); + } + } + + return null; + } + private void startDownloadWithWarning(final String downloadId) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mActivity); boolean warn = preferences.getBoolean(Constants.PREF_METERED_NETWORK_WARNING, true); @@ -363,7 +391,15 @@ public class UpdatesListAdapter extends RecyclerView.Adapter startDownloadWithWarning(downloadId) : null; + clickListener = enabled ? view -> { + AlertDialog.Builder freeSpaceDialog = getSpaceDialog( + mUpdaterController.getUpdate(downloadId)); + if (freeSpaceDialog != null) { + freeSpaceDialog.show(); + } else { + startDownloadWithWarning(downloadId); + } + } : null; break; case PAUSE: button.setText(R.string.action_pause); @@ -379,7 +415,12 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { if (canInstall) { - mUpdaterController.resumeDownload(downloadId); + AlertDialog.Builder freeSpaceDialog = getSpaceDialog(update); + if (freeSpaceDialog != null) { + freeSpaceDialog.show(); + } else { + mUpdaterController.resumeDownload(downloadId); + } } else { mActivity.showSnackbar(R.string.snack_update_not_installable, Snackbar.LENGTH_LONG); @@ -395,7 +436,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { if (canInstall) { AlertDialog.Builder installDialog = getInstallDialog(downloadId); - if (installDialog != null) { + AlertDialog.Builder freeSpaceDialog = getSpaceDialog(update); + if (freeSpaceDialog != null) { + freeSpaceDialog.show(); + } else if (installDialog != null) { installDialog.show(); } } else { @@ -468,8 +512,8 @@ public class UpdatesListAdapter extends RecyclerView.Adapter SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 25e4d5dd..e5f13809 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,7 +40,7 @@ Downloading Download paused Download error - Download completed + Update is ready to be installed Starting download Update failed Installation suspended @@ -70,7 +70,6 @@ ]]> Cannot install update with OverlayFS mounted - Reboot Refresh @@ -195,4 +194,7 @@ Available updates: Current version: + + Free up space + There is not enough space left to proceed with the update: you must free up another %1$s in the internal storage first. -- GitLab From 759b2181ed6a42cc5ca5ca7207d071d7a9f4c22b Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 10 Jan 2023 12:53:07 +0530 Subject: [PATCH 23/42] Updater: Check dev options toggle for test channel Change-Id: Ifecac146e3f637fa589241e513a269f3306764ed --- app/src/main/java/org/lineageos/updater/misc/Utils.java | 7 +++---- 1 file changed, 3 insertions(+), 4 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 2ac29aa3..2afa2219 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -218,7 +218,7 @@ public class Utils { String serverUrl = ""; if (retrieveStatus(context) != null) { - if (retrieveStatus(context).equals("true")) { + if (retrieveStatus(context).equals("true") && isDevModeOn(context)) { serverUrl = context.getString(R.string.ota_staging_server_url); return serverUrl.replace("{device}", device) .replace("{type}", type) @@ -471,9 +471,8 @@ public class Utils { } public static boolean isDevModeOn(Context context) { - int devOptions = Settings.Secure.getInt(context.getContentResolver(), - Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0); - return devOptions == 1; + return Settings.Secure.getInt(context.getContentResolver(), + Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) == 1; } public static boolean hasTouchscreen(Context context) { -- GitLab From 66c665cf99b2e8edb7395f731ff94cbc487b9ca9 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 6 Oct 2022 14:26:28 +0000 Subject: [PATCH 24/42] Updater: hide lower android versions Change-Id: Ic2746aa8507ba770c52c3cdc666b0f03ad533842 Signed-off-by: althafvly --- .../org/lineageos/updater/UpdatesDbHelper.java | 10 ++++++++-- .../java/org/lineageos/updater/misc/Utils.java | 14 +++++++++++++- .../org/lineageos/updater/model/UpdateBase.java | 10 ++++++++++ .../lineageos/updater/model/UpdateBaseInfo.java | 2 ++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java b/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java index 9dadd4b6..bf78b829 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesDbHelper.java @@ -30,7 +30,7 @@ import java.util.List; public class UpdatesDbHelper extends SQLiteOpenHelper { - public static final int DATABASE_VERSION = 2; + public static final int DATABASE_VERSION = 3; public static final String DATABASE_NAME = "updates.db"; public static class UpdateEntry implements BaseColumns { @@ -43,6 +43,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { public static final String COLUMN_NAME_VERSION = "version"; public static final String COLUMN_NAME_DISPLAY_VERSION = "display_version"; public static final String COLUMN_NAME_SIZE = "size"; + public static final String COLUMN_NAME_ANDROID_VERSION = "android_version"; } private static final String SQL_CREATE_ENTRIES = @@ -55,7 +56,8 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { UpdateEntry.COLUMN_NAME_TYPE + " TEXT," + UpdateEntry.COLUMN_NAME_VERSION + " TEXT," + UpdateEntry.COLUMN_NAME_DISPLAY_VERSION + " TEXT," + - UpdateEntry.COLUMN_NAME_SIZE + " INTEGER)"; + UpdateEntry.COLUMN_NAME_SIZE + " INTEGER," + + UpdateEntry.COLUMN_NAME_ANDROID_VERSION + " TEXT)"; private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + UpdateEntry.TABLE_NAME; @@ -93,6 +95,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { values.put(UpdateEntry.COLUMN_NAME_VERSION, update.getVersion()); values.put(UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, update.getDisplayVersion()); values.put(UpdateEntry.COLUMN_NAME_SIZE, update.getFileSize()); + values.put(UpdateEntry.COLUMN_NAME_ANDROID_VERSION, update.getAndroidVersion()); } public void removeUpdate(String downloadId) { @@ -131,6 +134,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, UpdateEntry.COLUMN_NAME_STATUS, UpdateEntry.COLUMN_NAME_SIZE, + UpdateEntry.COLUMN_NAME_ANDROID_VERSION, }; String sort = UpdateEntry.COLUMN_NAME_TIMESTAMP + " DESC"; Cursor cursor = db.query(UpdateEntry.TABLE_NAME, projection, selection, selectionArgs, @@ -156,6 +160,8 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { update.setPersistentStatus(cursor.getInt(index)); index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_SIZE); update.setFileSize(cursor.getLong(index)); + index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_ANDROID_VERSION); + update.setAndroidVersion(cursor.getString(index)); updates.add(update); } cursor.close(); 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 2afa2219..e91fd6fb 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -22,6 +22,7 @@ import static android.os.SystemUpdateManager.STATUS_IDLE; import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD; import android.app.AlarmManager; +import android.os.Build; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -107,6 +108,7 @@ public class Utils { update.setFileSize(object.getLong("size")); update.setDownloadUrl(object.getString("url")); update.setVersion(object.getString("version")); + update.setAndroidVersion(object.getString("android_version")); if (object.has("pre_version") && !object.getString("pre_version").isEmpty()) { update.setDisplayVersion(object.getString("version") + "-" + object.getString("pre_version")); } else { @@ -116,6 +118,17 @@ public class Utils { } public static boolean isCompatible(UpdateBaseInfo update) { + String updateAndroidVersion = update.getAndroidVersion(); + if (!updateAndroidVersion.isEmpty()) { + final int updateOSVersion = Float.valueOf(updateAndroidVersion).intValue(); + final int deviceOSVersion = Float.valueOf(Build.VERSION.RELEASE).intValue(); + if (deviceOSVersion > updateOSVersion) { + Log.d(TAG, "Update : Skipping " + update.getName() + " since the installed version " + + deviceOSVersion + " is newer than update " + updateOSVersion); + return false; + } + } + int[] updateVersionParts = parseSemVer(update.getVersion()); int updateMajorVersion = updateVersionParts[0]; int updateMinorVersion = updateVersionParts[1]; @@ -126,7 +139,6 @@ public class Utils { int deviceMinorVersion = deviceVersionParts[1]; Log.d(TAG, "Device : Major "+ deviceMajorVersion +" Minor "+ deviceMinorVersion ); - 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"); diff --git a/app/src/main/java/org/lineageos/updater/model/UpdateBase.java b/app/src/main/java/org/lineageos/updater/model/UpdateBase.java index cfa2027e..f1689bce 100644 --- a/app/src/main/java/org/lineageos/updater/model/UpdateBase.java +++ b/app/src/main/java/org/lineageos/updater/model/UpdateBase.java @@ -24,6 +24,7 @@ public class UpdateBase implements UpdateBaseInfo { private String mType; private String mVersion; private String mDisplayVersion; + private String mAndroidVersion; private long mFileSize; public UpdateBase() { @@ -111,4 +112,13 @@ public class UpdateBase implements UpdateBaseInfo { public void setFileSize(long fileSize) { mFileSize = fileSize; } + + @Override + public String getAndroidVersion() { + return mAndroidVersion; + } + + public void setAndroidVersion(String androidVersion) { + mAndroidVersion = androidVersion; + } } diff --git a/app/src/main/java/org/lineageos/updater/model/UpdateBaseInfo.java b/app/src/main/java/org/lineageos/updater/model/UpdateBaseInfo.java index 2921e96f..aea17bd8 100644 --- a/app/src/main/java/org/lineageos/updater/model/UpdateBaseInfo.java +++ b/app/src/main/java/org/lineageos/updater/model/UpdateBaseInfo.java @@ -31,4 +31,6 @@ public interface UpdateBaseInfo { String getDownloadUrl(); long getFileSize(); + + String getAndroidVersion(); } -- GitLab From 1d139ff4f5917ec7c2c5c0cc7975172485854980 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 7 Feb 2023 17:12:23 +0530 Subject: [PATCH 25/42] Updater: Utils: Move battery level check Change-Id: I94447b33e717bd05f8a93d8a7784c862a07f8c3a --- .../lineageos/updater/UpdatesListAdapter.java | 23 +------------------ .../org/lineageos/updater/misc/Utils.java | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index 77373474..89fb9efc 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -16,10 +16,8 @@ package org.lineageos.updater; import android.content.Intent; -import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Resources; -import android.os.BatteryManager; import android.os.PowerManager; import android.text.SpannableString; import android.text.format.Formatter; @@ -72,10 +70,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter mDownloadIds; @@ -513,7 +507,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter= required; - } - private static boolean isScratchMounted() { try (Stream lines = Files.lines(Path.of("/proc/mounts"))) { return lines.anyMatch(x -> x.split(" ")[1].equals("/mnt/scratch")); 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 e91fd6fb..864922e2 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -22,11 +22,11 @@ import static android.os.SystemUpdateManager.STATUS_IDLE; import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD; import android.app.AlarmManager; -import android.os.Build; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.database.Cursor; @@ -34,6 +34,8 @@ import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.net.Uri; +import android.os.BatteryManager; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.PersistableBundle; @@ -72,6 +74,10 @@ import java.util.zip.ZipFile; public class Utils { + private static final int BATTERY_PLUGGED_ANY = BatteryManager.BATTERY_PLUGGED_AC + | BatteryManager.BATTERY_PLUGGED_USB + | BatteryManager.BATTERY_PLUGGED_WIRELESS; + private static final String TAG = "Utils"; private static final String CONTENT_URI_PATH = "content://custom.setting.Provider.OTA_SERVER/cte"; @@ -548,6 +554,21 @@ public class Utils { return (floatVersion >= 20) ? String.valueOf((int)floatVersion) : version; } + public static boolean isBatteryLevelOk(Context context) { + Intent intent = context.registerReceiver(null, + new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); + if (!intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) { + return true; + } + int percent = Math.round(100.f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100) / + intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100)); + int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); + int required = (plugged & BATTERY_PLUGGED_ANY) != 0 ? + context.getResources().getInteger(R.integer.battery_ok_percentage_charging) : + context.getResources().getInteger(R.integer.battery_ok_percentage_discharging); + return percent >= required; + } + public static void updateSystemUpdaterService(Context context, int status, String version) { final SystemUpdateManager updateManager = context.getSystemService(SystemUpdateManager.class); -- GitLab From ba8d2342c0f07eb32775c21e814262368acf4b34 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 7 Feb 2023 17:13:17 +0530 Subject: [PATCH 26/42] Updater: Update A/B devices on one go Change-Id: Iac2a6888b8da6b27c0c9887f32266e8e5b73d9af --- .../lineageos/updater/UpdatesListAdapter.java | 9 ++-- .../updater/controller/UpdaterService.java | 43 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 + 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index 89fb9efc..8dfbe4d7 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -247,7 +247,8 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { if (checkbox.isChecked()) { preferences.edit() @@ -383,7 +385,8 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { AlertDialog.Builder freeSpaceDialog = getSpaceDialog( diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index d102c21b..646d03fc 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -363,12 +363,45 @@ public class UpdaterService extends Service { mNotificationBuilder.setSmallIcon(R.drawable.ic_system_update); mNotificationBuilder.setProgress(0, 0, false); String text = getString(R.string.download_completed_notification); + boolean hasRequiredSpace = Utils.availableFreeSpace() > (update.getFileSize() * 2); + + if (!Utils.canInstall(update) || !Utils.isBatteryLevelOk(this) + || !hasRequiredSpace) { + /* Show notification if any of the below condition didn't met. */ + text = getString(R.string.blocked_update_dialog_title) + ". "; + if (!Utils.isBatteryLevelOk(this)) { + text = text + getString(R.string.dialog_battery_low_title); + } else if (!hasRequiredSpace) { + text = text + getString(R.string.dialog_free_space_low_title); + } else if (!Utils.canInstall(update)) { + text = text + getString(R.string.verification_failed_notification); + } + } else if (!Utils.isABDevice()) { + /* Add action to reboot and install for Non-A/B devices. */ + mNotificationBuilder.mActions.clear(); + mNotificationBuilder.addAction(R.drawable.ic_system_update, + getString(R.string.reboot_install), + getInstallationPendingIntent(update.getDownloadId())); + } + mNotificationBuilder.setContentText(text); mNotificationBuilder.setTicker(text); mNotificationBuilder.setOngoing(false); mNotificationBuilder.setAutoCancel(true); mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); - tryStopSelf(); + + /* Make sure these conditions are met before auto install + - Can install package (Is a newer build or downgrade allowed) + - Battery level (Above 30% if discharging or 20% if charging) + - Free space to install (Double the size of the ota zip) + */ + if (Utils.isABDevice() && Utils.canInstall(update) + && Utils.isBatteryLevelOk(this) && hasRequiredSpace) { + Utils.triggerUpdate(this, update.getDownloadId()); + } else { + tryStopSelf(); + } + break; } case VERIFICATION_FAILED: { @@ -560,6 +593,14 @@ public class UpdaterService extends Service { PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); } + private PendingIntent getInstallationPendingIntent(String downloadId) { + final Intent intent = new Intent(this, UpdaterService.class); + intent.setAction(ACTION_INSTALL_UPDATE); + intent.putExtra(UpdaterService.EXTRA_DOWNLOAD_ID, downloadId); + return PendingIntent.getService(this, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); + } + private PendingIntent getResumeInstallationPendingIntent() { final Intent intent = new Intent(this, UpdaterService.class); intent.setAction(ACTION_INSTALL_RESUME); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5f13809..fbb3d5de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -52,6 +52,7 @@ Pause Resume Suspend + Reboot and install Installing update package Install error @@ -114,6 +115,7 @@ No new updates found. To manually check for new updates, use the Refresh button. Download + Apply update Pause Resume Install -- GitLab From 7db7d11596c7b6cc9e441cdd057d5f1c019586d7 Mon Sep 17 00:00:00 2001 From: althafvly Date: Wed, 8 Feb 2023 11:57:45 +0530 Subject: [PATCH 27/42] Updater: check for active notifications before self stop Change-Id: I869ab48a0d518bac3522aab2b8778321612855d1 --- .../updater/controller/UpdaterService.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index 646d03fc..3b417391 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -32,6 +32,7 @@ import android.content.pm.ServiceInfo; import android.os.Binder; import android.os.Bundle; import android.os.IBinder; +import android.service.notification.StatusBarNotification; import android.text.format.Formatter; import android.util.Log; @@ -254,12 +255,28 @@ public class UpdaterService extends Service { private void tryStopSelf() { if (!mHasClients && !mUpdaterController.hasActiveDownloads() && - !mUpdaterController.isInstallingUpdate() && !isNetworkCallBackActive()) { + !mUpdaterController.isInstallingUpdate() && !isNetworkCallBackActive() + && !areNotificationsActive()) { Log.d(TAG, "Service no longer needed, stopping"); stopSelf(); } } + private boolean areNotificationsActive() { + NotificationManager notificationManager = + (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + StatusBarNotification[] notifications = notificationManager.getActiveNotifications(); + if (notifications != null && notifications.length > 0) { + for (StatusBarNotification notification : notifications) { + if (notification.getId() == NOTIFICATION_ID && + notification.getPackageName().equals(getPackageName())) { + return true; + } + } + } + return false; + } + private void handleUpdateStatusChange(UpdateInfo update) { switch (update.getStatus()) { case DELETED: { -- GitLab From 31acc34b4198506f3a33d745fdbb02500edfaced Mon Sep 17 00:00:00 2001 From: Mohammed Althaf Thayyil Date: Mon, 17 Jul 2023 06:20:09 +0000 Subject: [PATCH 28/42] Updater: Generate license ID for ota requests --- app/privapp_whitelist_org.lineageos.updater.xml | 1 + app/src/main/AndroidManifest.xml | 2 ++ .../org/lineageos/updater/UpdatesCheckReceiver.java | 12 ++++++++++++ .../main/java/org/lineageos/updater/misc/Utils.java | 12 ++++++++++++ 4 files changed, 27 insertions(+) diff --git a/app/privapp_whitelist_org.lineageos.updater.xml b/app/privapp_whitelist_org.lineageos.updater.xml index a6fcac7b..6361985b 100644 --- a/app/privapp_whitelist_org.lineageos.updater.xml +++ b/app/privapp_whitelist_org.lineageos.updater.xml @@ -21,5 +21,6 @@ + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 378381d9..6f60113d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,6 +14,8 @@ + + Date: Thu, 27 Jul 2023 18:14:57 +0530 Subject: [PATCH 29/42] Updater: Simplify the update url checks --- .../java/org/lineageos/updater/misc/Utils.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 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 f892564e..76c6e4a3 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -242,18 +242,10 @@ public class Utils { String anonHash = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.OTA_ANON_HASH); - String serverUrl = ""; - if (retrieveStatus(context) != null) { - if (retrieveStatus(context).equals("true") && isDevModeOn(context)) { - serverUrl = context.getString(R.string.ota_staging_server_url); - return serverUrl.replace("{device}", device) - .replace("{type}", type) - .replace("{incr}", incrementalVersion); - } else { - serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI); - } - } else { - serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI); + String serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI); + if (retrieveStatus(context) != null && retrieveStatus(context).equals("true") + && isDevModeOn(context)) { + serverUrl = context.getString(R.string.ota_staging_server_url); } if (serverUrl.trim().isEmpty()) { -- GitLab From e4e3577a0e441a31cfb42a283b5044cce46749a5 Mon Sep 17 00:00:00 2001 From: Rohit Date: Thu, 4 Nov 2021 18:37:28 +0000 Subject: [PATCH 30/42] [t] Updater: Improve UX for users taking version upgrades Conflicts: res/values/strings.xml src/org/lineageos/updater/UpdatesDbHelper.java src/org/lineageos/updater/UpdatesListAdapter.java src/org/lineageos/updater/misc/Utils.java --- .../lineageos/updater/UpdatesListAdapter.java | 62 +++++++++++++++---- .../lineageos/updater/model/UpdateBase.java | 1 + app/src/main/res/layout/update_item_view.xml | 12 ++++ app/src/main/res/values/strings.xml | 8 ++- 4 files changed, 70 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index 8dfbe4d7..d4efcadf 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -18,6 +18,7 @@ package org.lineageos.updater; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; +import android.os.Build; import android.os.PowerManager; import android.text.SpannableString; import android.text.format.Formatter; @@ -94,6 +95,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { Utils.triggerUpdate(mActivity, downloadId); diff --git a/app/src/main/java/org/lineageos/updater/model/UpdateBase.java b/app/src/main/java/org/lineageos/updater/model/UpdateBase.java index f1689bce..167e3629 100644 --- a/app/src/main/java/org/lineageos/updater/model/UpdateBase.java +++ b/app/src/main/java/org/lineageos/updater/model/UpdateBase.java @@ -38,6 +38,7 @@ public class UpdateBase implements UpdateBaseInfo { mType = update.getType(); mVersion = update.getVersion(); mDisplayVersion = update.getDisplayVersion(); + mAndroidVersion = update.getAndroidVersion(); mFileSize = update.getFileSize(); } diff --git a/app/src/main/res/layout/update_item_view.xml b/app/src/main/res/layout/update_item_view.xml index 7198c37d..e15864e8 100644 --- a/app/src/main/res/layout/update_item_view.xml +++ b/app/src/main/res/layout/update_item_view.xml @@ -39,6 +39,18 @@ android:textSize="16sp" tools:text="LineageOS 20" /> + + Delete the selected update file? Apply update - You are about to install %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 install %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. + You are about to update to %1$s.\n\nIf you press %2$s, the device will restart itself in recovery mode to install the update. + You are about to update 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. + + Version Upgrade! + You are about to upgrade to %1$s, based on Android %2$s\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press %3$s, the device will restart itself into recovery mode to install the update. + You are about to upgrade to %1$s, based on Android %2$s.\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press %3$s, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot. Cancel the installation? -- GitLab From 2a1bf9d7b5c5e1ea59020025a9baa6aeaec0fdd6 Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 28 Aug 2023 15:05:38 +0530 Subject: [PATCH 31/42] Updater: Fix version not displaying build name - Our version is not full integers Change-Id: I22f028bbd4033049bfd022604cda06fb315644f2 --- .../java/org/lineageos/updater/UpdaterReceiver.java | 3 +-- .../java/org/lineageos/updater/UpdatesActivity.java | 2 +- .../org/lineageos/updater/UpdatesListAdapter.java | 2 +- .../main/java/org/lineageos/updater/misc/Utils.java | 11 ----------- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java index 6584c04d..081b8d97 100644 --- a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java @@ -31,7 +31,6 @@ import androidx.preference.PreferenceManager; import org.lineageos.updater.misc.BuildInfoUtils; import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.StringGenerator; -import org.lineageos.updater.misc.Utils; import java.text.DateFormat; @@ -62,7 +61,7 @@ public class UpdaterReceiver extends BroadcastReceiver { String buildDate = StringGenerator.getDateLocalizedUTC(context, DateFormat.MEDIUM, preferences.getLong(Constants.PREF_INSTALL_NEW_TIMESTAMP, 0)); String buildInfo = context.getString(R.string.list_build_version_date_e, - Utils.getDisplayVersion(BuildInfoUtils.getBuildVersion()), buildDate); + BuildInfoUtils.getBuildVersion(), buildDate); Intent notificationIntent = new Intent(context, UpdatesActivity.class); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index 52acda4f..cbf71f3a 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -183,7 +183,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport TextView headerTitle = findViewById(R.id.header_title); headerTitle.setText(getString(R.string.header_title_text_e, - Utils.getDisplayVersion(BuildInfoUtils.getDisplayVersion()))); + BuildInfoUtils.getDisplayVersion())); updateLastCheckedString(); diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index d4efcadf..b205f62c 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -275,7 +275,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter= 20) ? String.valueOf((int)floatVersion) : version; - } - public static boolean isBatteryLevelOk(Context context) { Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); -- GitLab From e176777d0f4d959f4ea8e4473d0dfeee646a9745 Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 28 Aug 2023 15:48:34 +0530 Subject: [PATCH 32/42] Updater: Cleanup check for update code - Remove unused code. - Use variable for duplicated code of lines. Change-Id: Iad699dcd958f0f99e9aec72b02f3c7d778e15d5f --- .../java/org/lineageos/updater/misc/Utils.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 b968c059..77487965 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -335,9 +335,11 @@ public class Utils { 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*10000+updateMinorVersion*100+updateMaintenanceVersion >= highestMajorVersion*10000+highestMinorVersion*100+highestMaintenanceVersion) { + int updateMaintenanceVersion = updateVersionParts.length > 2 + ? updateVersionParts[2] : 0; + if (updateMajorVersion * 10000 + updateMinorVersion * 100 + updateMaintenanceVersion + >= highestMajorVersion * 10000 + highestMinorVersion * 100 + + highestMaintenanceVersion) { highestMajorVersion = updateMajorVersion; highestMinorVersion = updateMinorVersion; highestMaintenanceVersion = updateMaintenanceVersion; @@ -345,11 +347,13 @@ public class Utils { hasUpdate = true; } } + String updateVersion = highestMajorVersion + "." + highestMinorVersion + + (highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : ""); if (hasUpdate) { - updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, highestMajorVersion + "." + highestMinorVersion + (highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); + updateSystemUpdaterService(context, STATUS_WAITING_DOWNLOAD, updateVersion); return true; } else { - updateSystemUpdaterService(context, STATUS_IDLE, highestMajorVersion+"."+highestMinorVersion+(highestMaintenanceVersion > 0 ? "." + highestMaintenanceVersion : "")); + updateSystemUpdaterService(context, STATUS_IDLE, updateVersion); return false; } } -- GitLab From 52d91be93b97e728c3aa2eee5f332ad1ff6154ab Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 28 Aug 2023 17:37:31 +0530 Subject: [PATCH 33/42] Updater: Fix checking android version Change-Id: Idadeb0f087b4c13e9eaaa8e3cd8194a72e7c82d7 --- .../java/org/lineageos/updater/misc/Utils.java | 15 +++++++++++++-- 1 file changed, 13 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 77487965..eec811b6 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -68,7 +68,9 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.UUID; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -129,11 +131,20 @@ public class Utils { return update; } + public static int parseAndroidVersion(String versionString) { + // Parse android versions such as 8.1.0. + // Older updates still shows in ota requests. + Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)"); + Matcher matcher = pattern.matcher(versionString); + return matcher.matches() ? Integer.parseInt(Objects.requireNonNull(matcher.group(1))) + : Float.valueOf(versionString).intValue(); + } + public static boolean isCompatible(UpdateBaseInfo update) { String updateAndroidVersion = update.getAndroidVersion(); if (!updateAndroidVersion.isEmpty()) { - final int updateOSVersion = Float.valueOf(updateAndroidVersion).intValue(); - final int deviceOSVersion = Float.valueOf(Build.VERSION.RELEASE).intValue(); + final int updateOSVersion = parseAndroidVersion(updateAndroidVersion); + final int deviceOSVersion = parseAndroidVersion(Build.VERSION.RELEASE); if (deviceOSVersion > updateOSVersion) { Log.d(TAG, "Update : Skipping " + update.getName() + " since the installed version " + deviceOSVersion + " is newer than update " + updateOSVersion); -- GitLab From cedaa1faabc66a832535a77eb51f228b8715da2f Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 29 Aug 2023 20:01:35 +0530 Subject: [PATCH 34/42] Updater: Avoid nullexception for android version check - mAndroidVersion wasn't before update so getAndroidVersion() was null. Change-Id: Ic195cc09dbbc4e7a082a6004316bc190ffe89dac --- .../main/java/org/lineageos/updater/UpdatesListAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index b205f62c..e979d2cb 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -277,7 +277,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter Date: Thu, 28 Sep 2023 17:56:33 +0530 Subject: [PATCH 35/42] Move our string modifications to e_strings.xml --- .../lineageos/updater/UpdaterReceiver.java | 2 +- .../lineageos/updater/UpdatesActivity.java | 2 +- .../lineageos/updater/UpdatesListAdapter.java | 26 +++++------ .../updater/controller/UpdaterService.java | 8 ++-- .../layout-television/activity_updates.xml | 2 +- app/src/main/res/layout/activity_updates.xml | 6 +-- app/src/main/res/layout/update_item_view.xml | 4 +- app/src/main/res/menu/menu_toolbar.xml | 2 +- app/src/main/res/values-de/e_strings.xml | 34 ++++++++++++++ app/src/main/res/values-es/e_strings.xml | 22 +++++++++ app/src/main/res/values-fr/e_strings.xml | 44 ++++++++++++++++++ app/src/main/res/values-is/e_strings.xml | 45 +++++++++++++++++++ app/src/main/res/values-it/e_strings.xml | 34 ++++++++++++++ app/src/main/res/values-nl/e_strings.xml | 34 ++++++++++++++ app/src/main/res/values-ru/e_strings.xml | 34 ++++++++++++++ app/src/main/res/values/arrays.xml | 6 +-- app/src/main/res/values/e_strings.xml | 39 ++++++++++++++++ app/src/main/res/values/strings.xml | 36 ++------------- 18 files changed, 318 insertions(+), 62 deletions(-) create mode 100644 app/src/main/res/values-de/e_strings.xml create mode 100644 app/src/main/res/values-es/e_strings.xml create mode 100644 app/src/main/res/values-fr/e_strings.xml create mode 100644 app/src/main/res/values-is/e_strings.xml create mode 100644 app/src/main/res/values-it/e_strings.xml create mode 100644 app/src/main/res/values-nl/e_strings.xml create mode 100644 app/src/main/res/values-ru/e_strings.xml create mode 100644 app/src/main/res/values/e_strings.xml diff --git a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java index 081b8d97..f295f05c 100644 --- a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java @@ -60,7 +60,7 @@ public class UpdaterReceiver extends BroadcastReceiver { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String buildDate = StringGenerator.getDateLocalizedUTC(context, DateFormat.MEDIUM, preferences.getLong(Constants.PREF_INSTALL_NEW_TIMESTAMP, 0)); - String buildInfo = context.getString(R.string.list_build_version_date_e, + String buildInfo = context.getString(R.string.e_list_build_version_date, BuildInfoUtils.getBuildVersion(), buildDate); Intent notificationIntent = new Intent(context, UpdatesActivity.class); diff --git a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java index cbf71f3a..9ac2f206 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesActivity.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesActivity.java @@ -182,7 +182,7 @@ public class UpdatesActivity extends UpdatesListActivity implements UpdateImport } TextView headerTitle = findViewById(R.id.header_title); - headerTitle.setText(getString(R.string.header_title_text_e, + headerTitle.setText(getString(R.string.e_header_title_text, BuildInfoUtils.getDisplayVersion())); updateLastCheckedString(); diff --git a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java index e979d2cb..1e2114db 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesListAdapter.java @@ -250,7 +250,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter= 1) { - String message = resources.getString(R.string.dialog_free_space_low_message_pct, + String message = resources.getString(R.string.e_dialog_free_space_low_message_pct, new DecimalFormat("# MB").format(spaceNeeded)); return new AlertDialog.Builder(mActivity) - .setTitle(R.string.dialog_free_space_low_title) + .setTitle(R.string.e_dialog_free_space_low_title) .setMessage(message) .setPositiveButton(android.R.string.ok, null); } @@ -373,7 +373,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { if (checkbox.isChecked()) { @@ -393,7 +393,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter { @@ -543,36 +543,36 @@ public class UpdatesListAdapter extends RecyclerView.Adapter preferences.edit() .putBoolean(Constants.HAS_SEEN_INFO_DIALOG, true) .apply()) diff --git a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index 3b417391..cb35783d 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -379,7 +379,7 @@ public class UpdaterService extends Service { mNotificationBuilder.setStyle(null); mNotificationBuilder.setSmallIcon(R.drawable.ic_system_update); mNotificationBuilder.setProgress(0, 0, false); - String text = getString(R.string.download_completed_notification); + String text = getString(R.string.e_download_completed_notification); boolean hasRequiredSpace = Utils.availableFreeSpace() > (update.getFileSize() * 2); if (!Utils.canInstall(update) || !Utils.isBatteryLevelOk(this) @@ -389,7 +389,7 @@ public class UpdaterService extends Service { if (!Utils.isBatteryLevelOk(this)) { text = text + getString(R.string.dialog_battery_low_title); } else if (!hasRequiredSpace) { - text = text + getString(R.string.dialog_free_space_low_title); + text = text + getString(R.string.e_dialog_free_space_low_title); } else if (!Utils.canInstall(update)) { text = text + getString(R.string.verification_failed_notification); } @@ -397,7 +397,7 @@ public class UpdaterService extends Service { /* Add action to reboot and install for Non-A/B devices. */ mNotificationBuilder.mActions.clear(); mNotificationBuilder.addAction(R.drawable.ic_system_update, - getString(R.string.reboot_install), + getString(R.string.e_reboot_install), getInstallationPendingIntent(update.getDownloadId())); } @@ -572,7 +572,7 @@ public class UpdaterService extends Service { private void setNotificationTitle(UpdateInfo update) { String buildDate = StringGenerator.getDateLocalizedUTC(this, DateFormat.MEDIUM, update.getTimestamp()); - String buildInfo = getString(R.string.list_build_version_date_e, + String buildInfo = getString(R.string.e_list_build_version_date, update.getVersion(), buildDate); mNotificationStyle.setBigContentTitle(buildInfo); mNotificationBuilder.setContentTitle(buildInfo); diff --git a/app/src/main/res/layout-television/activity_updates.xml b/app/src/main/res/layout-television/activity_updates.xml index efabfea4..df63d6c8 100644 --- a/app/src/main/res/layout-television/activity_updates.xml +++ b/app/src/main/res/layout-television/activity_updates.xml @@ -105,7 +105,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" - android:text="@string/list_no_updates" + android:text="@string/e_list_no_updates" android:textColor="?android:textColorSecondary" /> diff --git a/app/src/main/res/layout/activity_updates.xml b/app/src/main/res/layout/activity_updates.xml index 864ab818..ce0ac3fc 100644 --- a/app/src/main/res/layout/activity_updates.xml +++ b/app/src/main/res/layout/activity_updates.xml @@ -53,7 +53,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="24dp" - android:text="@string/current_version" + android:text="@string/e_current_version" android:textColor="?android:attr/textColorPrimary" android:textSize="16sp" /> @@ -117,7 +117,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" - android:text="@string/list_no_updates" + android:text="@string/e_list_no_updates" android:textColor="?android:textColorSecondary" /> @@ -138,7 +138,7 @@ android:paddingStart="16dp" android:textSize="16sp" android:background="?attr/colorPrimary" - android:text="@string/available_updates" + android:text="@string/e_available_updates" android:textColor="?android:textColorPrimary" /> diff --git a/app/src/main/res/values-de/e_strings.xml b/app/src/main/res/values-de/e_strings.xml new file mode 100644 index 00000000..159d08cc --- /dev/null +++ b/app/src/main/res/values-de/e_strings.xml @@ -0,0 +1,34 @@ + + + + Auf deinem Telefon läuft die neueste /e/OS-Version. Um manuell nach neuen Aktualisierungen zu suchen, verwende die Schaltfläche „Aktualisieren“. + /e/OS +\n%1$s + /e/OS-Aktualisierungen sind immer vollständige Installationspakete. Das bedeutet, dass du nur die neueste Aktualisierung aufspielen musst, selbst wenn du eine vorherige Aktualisierung vergessen hast. + Versionshinweise anzeigen + /e/OS %1$s - %2$s + /e/OS %1$s + Verfügbare Aktualisierungen: + Aktuelle Version: + Alle 30 Minuten + Alle 10 Minuten + Alle 5 Minuten + Die Aktualisierung kann nicht abgeschlossen werden, weil nicht genug Speicher frei ist. Mindestens %1$s freier interner Speicher ist nötig, bevor du weitermachst. + Platz schaffen + Aktualisierung installieren + Neustarten und Installieren + \ No newline at end of file diff --git a/app/src/main/res/values-es/e_strings.xml b/app/src/main/res/values-es/e_strings.xml new file mode 100644 index 00000000..9adf7197 --- /dev/null +++ b/app/src/main/res/values-es/e_strings.xml @@ -0,0 +1,22 @@ + + + + Versión actual: + Actualizaciones disponibles: + La actualización no puede completarse porque no hay suficiente espacio libre; al menos %1$s de espacio libre. Por favor, borra tu almacenamiento interno antes de proceder. + Liberar espacio + \ No newline at end of file diff --git a/app/src/main/res/values-fr/e_strings.xml b/app/src/main/res/values-fr/e_strings.xml new file mode 100644 index 00000000..9d53699f --- /dev/null +++ b/app/src/main/res/values-fr/e_strings.xml @@ -0,0 +1,44 @@ + + + + Vous utilisez actuellement la dernière version de /e/OS. Pour vérifier manuellement la présence de mises à jour, utilisez le bouton Actualiser. + Vous êtes sur le point de passer à la version %1$s. +\n +\nLorsque vous appuierez sur %2$s, votre appareil redémarrera automatiquement en mode récupération pour installer la mise à jour. +\n +\nRemarque : Cette opération nécessite une partition de récupération compatible, sans quoi les mises à jour devront être installées manuellement. + Vous êtes sur le point de passer à la version %1$s. +\n +\nLorsque vous appuierez sur %2$s, l’appareil commencera l\'installation en arrière plan. +\n +\nUne fois celle-ci terminée, il vous sera demandé de redémarrer. + + + Version actuelle : + /e/OS +\n%1$s + /e/OS %1$s - %2$s + /e/OS %1$s + Toutes les 30 minutes + Toutes les 10 minutes + Toutes les 5 minutes + L\'espace disponible n\'est pas suffisant pour installer la mise à jour : merci de libérer au moins %1$s de mémoire interne pour pouvoir continuer. + Libérez de l\'espace + Les mises à jour de /e/OS sont des paquets d\'installation complets. Cela signifie que vous pouvez vous contenter d\'installer la dernière mise à jour proposée, même si vous en avez raté quelques unes entre temps ! + Afficher les notes de version + Mises à jour disponibles : + \ No newline at end of file diff --git a/app/src/main/res/values-is/e_strings.xml b/app/src/main/res/values-is/e_strings.xml new file mode 100644 index 00000000..2d62dc0a --- /dev/null +++ b/app/src/main/res/values-is/e_strings.xml @@ -0,0 +1,45 @@ + + + + Uppfærsla er tilbúin til uppsetningar + Endurræsa og setja upp + Losa geymslupláss + Það er ekki nægilegt pláss eftir til að halda áfram með uppfærsluna: þú þarft fyrst að losa um %1$s í innri gagnageymslunni. + Á 5 mínútna fresti + Á 10 mínútna fresti + Á 30 mínútna fresti + Þú ert þegar að keyra nýjustu útgáfu /e/OS stýrikerfisins. Til að athuga handvirkt með nýjar uppfærslur, notaðu Endurlesa-hnappinn. + Setja inn uppfærslu + Þú ert í þann mund að setja upp %1$s. +\n +\nEf þú ýtir á %2$s, mun tækið endurræsa sig í endurheimtuham til að setja inn uppfærsluna. +\n +\nAthugaðu: Þessi eiginleiki krefst þess að til staðar séu samhæfð endurheimtugögn því annars þarf að setja uppfærslurnar inn handvirkt. + Þú ert í þann mund að setja upp %1$s. +\n +\nEf þú ýtir á %2$s, mun tækið hefja uppsetninguna í bakgrunnsferli. +\n +\nÞegar henni er lokið færðu beiðni um að endurræsa. + /e/OS %1$s + /e/OS %1$s - %2$s + Birta útgáfuupplýsingar + /e/OS +\n%1$s + Tiltækar uppfærslur: + Núverandi útgáfa: + Uppfærslur á /e/OS eru alltaf heilir uppsetningapakkar. Það þýðir að þú getur alltaf sett einungis upp nýjustu uppfærsluna, jafnvel þótt þú hafir sleppt einhverjum uppfærslum í millitíðinni! + \ No newline at end of file diff --git a/app/src/main/res/values-it/e_strings.xml b/app/src/main/res/values-it/e_strings.xml new file mode 100644 index 00000000..76327009 --- /dev/null +++ b/app/src/main/res/values-it/e_strings.xml @@ -0,0 +1,34 @@ + + + + Stai usando l\'ultima versione di /e/OS. Per verificare manualmente la presenza di aggiornamenti, utilizza il pulsante Aggiorna. + /e/OS +\n%1$s + Gli aggiornamenti di /e/OS sono pacchetti completi. Ciò significa che puoi sempre installare solo l\'ultimo aggiornamento, anche se ne hai saltati alcuni in mezzo! + Mostra note di rilascio + /e/OS %1$s - %2$s + /e/OS %1$s + Ogni 30 minuti + Ogni 10 minuti + Ogni 5 minuti + Versione attuale: + Agiornamenti disponibili: + Non c\'è spazio sufficiente per procedere con l\'aggiornamento; devi liberare almeno altri %1$s dalla memoria interna. + Libera spazio + Riavvia e installa + Applica aggiornamento + \ No newline at end of file diff --git a/app/src/main/res/values-nl/e_strings.xml b/app/src/main/res/values-nl/e_strings.xml new file mode 100644 index 00000000..908d7ff6 --- /dev/null +++ b/app/src/main/res/values-nl/e_strings.xml @@ -0,0 +1,34 @@ + + + + Je gebruikt de laatste versie van /e/OS. Gebruik de knop Vernieuwen om handmatig te controleren op nieuwe updates. + Beschikbare updates: + /e/OS +\n%1$s + /e/OS updates zijn volledige installatie pakketten.Dat betekend dat je altijd de laatste update kan installeren, zelfs als je hiermee sommige updates overslaat! + Toon release notes + /e/OS %1$s - %2$s + /e/OS %1$s + Huidige versie: + Elke 30 minuten + Elke 10 minuten + Elke 5 minuten + Er is niet genoeg geheugen vrij om deze update uit te voeren: je moet eerst nog %1$s intern geheugen vrijmaken. + Geheugen vrij maken + Update uitvoeren + Herstarten en installeren + \ No newline at end of file diff --git a/app/src/main/res/values-ru/e_strings.xml b/app/src/main/res/values-ru/e_strings.xml new file mode 100644 index 00000000..4471baeb --- /dev/null +++ b/app/src/main/res/values-ru/e_strings.xml @@ -0,0 +1,34 @@ + + + + Вы используете последнюю версию /e/OS. Чтобы проверить наличие обновлений вручную, используйте кнопку Обновить. + /e/OS +\n%1$s + Обновления /e/OS представляют собой полные установочные пакеты. Это означает, что вы всегда можете установить только последнее обновление, даже если вы пропустили несколько обновлений между ними! + Показать примечания к выпуску + /e/OS %1$s - %2$s + /e/OS %1$s + Каждые 30 минут + Каждые 10 минут + Каждые 5 минут + Текущая версия: + Доступные обновления: + Для продолжения обновления недостаточно места: сначала необходимо освободить еще %1$s во внутреннем хранилище. + Освободить место + Применить обновление + Перезагрузиться и установить + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 0448bf25..3374dccf 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -23,8 +23,8 @@ - @string/menu_auto_updates_check_interval_5_minutes - @string/menu_auto_updates_check_interval_10_minutes - @string/menu_auto_updates_check_interval_30_minutes + @string/e_menu_auto_updates_check_interval_5_minutes + @string/e_menu_auto_updates_check_interval_10_minutes + @string/e_menu_auto_updates_check_interval_30_minutes diff --git a/app/src/main/res/values/e_strings.xml b/app/src/main/res/values/e_strings.xml new file mode 100644 index 00000000..8082859c --- /dev/null +++ b/app/src/main/res/values/e_strings.xml @@ -0,0 +1,39 @@ + + + + Update is ready to be installed + Reboot and install + Free up space + There is not enough space left to proceed with the update: you must free up another %1$s in the internal storage first. + Every 5 minutes + Every 10 minutes + Every 30 minutes + You are running the latest /e/OS version. To manually check for updates, use the Refresh button. + Apply update + You are about to update to %1$s.\n\nIf you press %2$s, the device will restart itself in recovery mode to install the update. + You are about to update 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. + Version Upgrade! + You are about to upgrade to %1$s, based on Android %2$s\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press %3$s, the device will restart itself into recovery mode to install the update. + You are about to upgrade to %1$s, based on Android %2$s.\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press %3$s, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot. + /e/OS %1$s + /e/OS %1$s - %2$s + Show release notes + /e/OS updates are full installation packages. That means you can always install only the latest update, even if you skipped some in between! + /e/OS\n%1$s + Available updates: + Current version: + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5a5ba14e..85695efe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,7 +40,7 @@ Downloading Download paused Download error - Update is ready to be installed + Download completed Starting download Update failed Installation suspended @@ -52,7 +52,6 @@ Pause Resume Suspend - Reboot and install Installing update package Install error @@ -76,9 +75,6 @@ Refresh Preferences Auto updates check - Every 5 minutes - Every 10 minutes - Every 30 minutes Once a day Once a week Once a month @@ -115,7 +111,6 @@ No new updates found. To manually check for new updates, use the Refresh button. Download - Apply update Pause Resume Install @@ -127,12 +122,8 @@ Delete the selected update file? Apply update - You are about to update to %1$s.\n\nIf you press %2$s, the device will restart itself in recovery mode to install the update. - You are about to update 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. - - Version Upgrade! - You are about to upgrade to %1$s, based on Android %2$s\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press %3$s, the device will restart itself into recovery mode to install the update. - You are about to upgrade to %1$s, based on Android %2$s.\n\nRemember: it is always recommended to backup your data before upgrades.\n\nIf you press %3$s, the device will begin installing in the background.\n\nOnce completed, you will be prompted to reboot. + You are about to install %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 install %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. Cancel the installation? @@ -182,25 +173,4 @@ Failed to import local update Install Local update - - - - - /e/OS %1$s - /e/OS %1$s - %2$s - - - Show release notes - - - /e/OS updates are full installation packages. That means you can always install only the latest update, even if you skipped some in between! - - - /e/OS\n%1$s - - Available updates: - Current version: - - Free up space - There is not enough space left to proceed with the update: you must free up another %1$s in the internal storage first. -- GitLab From 4c8ec9dfda8596cf697992f4f13fb00b9283b06a Mon Sep 17 00:00:00 2001 From: althafvly Date: Wed, 4 Oct 2023 13:00:06 +0530 Subject: [PATCH 36/42] Update: add json validator Updater: validate update object early Updater: Check if value is empty first --- .../updater/UpdatesCheckReceiver.java | 12 +- .../lineageos/updater/misc/JsonValidator.java | 166 ++++++++++++++++++ .../org/lineageos/updater/misc/Utils.java | 15 ++ 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/org/lineageos/updater/misc/JsonValidator.java diff --git a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java index a6860e29..8db14e51 100644 --- a/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdatesCheckReceiver.java @@ -38,6 +38,7 @@ import org.lineageos.updater.controller.UpdaterService; import org.lineageos.updater.download.DownloadClient; import org.lineageos.updater.misc.ConnectionStateMonitor; import org.lineageos.updater.misc.Constants; +import org.lineageos.updater.misc.JsonValidator; import org.lineageos.updater.misc.Utils; import java.io.File; @@ -81,6 +82,11 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { Utils.cleanupDownloadsDir(context); } + final File json = Utils.getCachedUpdateList(context); + if (json.exists() && !JsonValidator.validateJsonFile(json) && json.delete()) { + Log.i(TAG, "Removing cached json file due validation failure"); + } + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -105,7 +111,6 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { setupNetworkCallback(false); } - final File json = Utils.getCachedUpdateList(context); final File jsonNew = new File(json.getAbsolutePath() + UUID.randomUUID()); String url = Utils.getServerURL(context); DownloadClient.DownloadCallback callback = new DownloadClient.DownloadCallback() { @@ -122,6 +127,11 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { @Override public void onSuccess() { try { + if (!JsonValidator.validateJsonFile(jsonNew)) { + Log.i(TAG, "Could not parse list, scheduling new check"); + scheduleUpdatesCheck(context); + return; + } if (json.exists() && Utils.checkForNewUpdates(jsonNew, context)) { showNotification(context); updateRepeatingUpdatesCheck(context); diff --git a/app/src/main/java/org/lineageos/updater/misc/JsonValidator.java b/app/src/main/java/org/lineageos/updater/misc/JsonValidator.java new file mode 100644 index 00000000..a1401c8e --- /dev/null +++ b/app/src/main/java/org/lineageos/updater/misc/JsonValidator.java @@ -0,0 +1,166 @@ +package org.lineageos.updater.misc; + +import android.util.Log; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class JsonValidator { + + private static final String TAG = "JsonValidator" ; + private static final String[] jsonMainFields = { + "error", + "id", + "response" + }; + private static final String[] requiredFields = { + "api_level", + "url", + "timestamp", + "md5sum", + "channel", + "filename", + "romtype", + "version", + "display_version", + "android_version", + "id" + }; + private static final String[] optionalFields = { + "changes", + "pre_version" + }; + + public static boolean validateJsonFile(File jsonFile) { + try { + if (!jsonFile.exists()) { + Log.i(TAG, "Unable to locate json file"); + return false; + } + + // Read the JSON data from the file + BufferedReader reader = new BufferedReader(new FileReader(jsonFile)); + StringBuilder jsonString = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + jsonString.append(line); + } + reader.close(); + + List missingRequiredFields = new ArrayList<>(); + JSONObject jsonObject = new JSONObject(jsonString.toString()); + for (String field : jsonMainFields) { + if (!isMainFieldValid(jsonObject, field)) { + missingRequiredFields.add(field); + } + } + + if (!missingRequiredFields.isEmpty()) { + Log.i(TAG, "Missing or invalid required field in response object: " + + missingRequiredFields); + return false; + } + } catch (IOException | JSONException e) { + Log.i(TAG, "Unable to parse the json file:" + e); + return false; + } + + return true; + } + + public static boolean validateResponseObject(JSONObject responseObject) { + List missingRequiredFields = new ArrayList<>(); + List missingOptionalFields = new ArrayList<>(); + + for (String field : requiredFields) { + if (!isObjectFieldValid(responseObject, field)) { + missingRequiredFields.add(field); + } + } + + for (String field : optionalFields) { + if (!isObjectFieldValid(responseObject, field)) { + missingOptionalFields.add(field); + } + } + + String filename = responseObject.optString("filename", ""); + if (!missingRequiredFields.isEmpty()) { + if (!filename.isEmpty()) { + Log.i(TAG, "Missing or invalid required field in response object for " + + filename + ": " + missingRequiredFields); + } + return false; + } else if (!missingOptionalFields.isEmpty() && !filename.isEmpty()) { + Log.i(TAG, "Missing or invalid optional field in response object for " + + filename + ": " + missingOptionalFields); + } + + return true; // All required fields are present and valid + } + + private static boolean isMainFieldValid(JSONObject jsonObject, String field) { + if (!jsonObject.has(field)) { + return false; + } + + String value = jsonObject.optString(field, ""); // Return empty string if field doesn't exist + + switch (field) { + case "id": + case "error": + // Allow null, as it's a valid value + return true; + case "response": + // Check if it's an array with a length >= 0 + return jsonObject.optJSONArray(field) != null + && jsonObject.optJSONArray(field).length() >= 0; + default: + return !value.isEmpty(); + } + } + + private static boolean isObjectFieldValid(JSONObject jsonObject, String field) { + if (!jsonObject.has(field) || jsonObject.isNull(field)) { + return false; + } + + String value = jsonObject.optString(field, ""); // Return empty string if field doesn't exist + if (value.isEmpty()) { + return false; + } + + switch (field) { + case "datetime": + case "timestamp": + case "size": + case "api_level": + return Utils.isInteger(value); + case "is_upgrade_supported": + return "true".equals(value) || "false".equals(value); + case "android_version": + // Check if it's a valid Android version number + return value.matches("^(\\d+)$|^(\\d+\\.\\d+)$|^(\\d+\\.\\d+\\.\\d+)$"); + case "md5sum": + // Check if it's a valid MD5 checksum + return value.matches("^[a-fA-F0-9]{32}$"); + case "filename": + return value.endsWith(".zip"); + case "id": + // Check if it's a valid SHA-256 checksum + return value.matches("^[a-fA-F0-9]{64}$"); + case "url": + // Check if it's a valid URL format + return value.startsWith("http://") || value.startsWith("https://"); + default: + return true; + } + } +} 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 eec811b6..a7491b32 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Utils.java +++ b/app/src/main/java/org/lineageos/updater/misc/Utils.java @@ -231,6 +231,12 @@ public class Utils { continue; } try { + boolean isValidated = JsonValidator.validateResponseObject( + updatesList.getJSONObject(i)); + if (!isValidated) { + Log.d(TAG, "Ignoring incompatible update"); + continue; + } UpdateInfo update = parseJsonUpdate(updatesList.getJSONObject(i)); if (!compatibleOnly || isCompatible(update)) { updates.add(update); @@ -590,4 +596,13 @@ public class Utils { updateManager.updateSystemUpdateInfo(infoBundle); } } + + public static boolean isInteger(String value) { + try { + Integer.parseInt(value); + return true; + } catch (NumberFormatException e) { + return false; + } + } } -- GitLab From 9b2da1cb8417834b0843b39467e0ed4ff1bd6696 Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Thu, 19 Oct 2023 12:51:36 +0530 Subject: [PATCH 37/42] Make ui improvements in update list - Available updates background is same as toolbar - Card corner radius has been made zero - Update action button position has been changed which fixes the issue of text getting hidden when button text is too long in some translations - Other elements in update card have been adjusted too to make it look better with new position of button --- app/src/main/res/layout/activity_updates.xml | 2 +- app/src/main/res/layout/update_item_view.xml | 189 +++++++++---------- 2 files changed, 95 insertions(+), 96 deletions(-) diff --git a/app/src/main/res/layout/activity_updates.xml b/app/src/main/res/layout/activity_updates.xml index ce0ac3fc..677282f4 100644 --- a/app/src/main/res/layout/activity_updates.xml +++ b/app/src/main/res/layout/activity_updates.xml @@ -137,7 +137,7 @@ android:paddingBottom="24dp" android:paddingStart="16dp" android:textSize="16sp" - android:background="?attr/colorPrimary" + android:background="@color/toolbar_collapsed" android:text="@string/e_available_updates" android:textColor="?android:textColorPrimary" /> diff --git a/app/src/main/res/layout/update_item_view.xml b/app/src/main/res/layout/update_item_view.xml index 8c29dc79..fdecfead 100644 --- a/app/src/main/res/layout/update_item_view.xml +++ b/app/src/main/res/layout/update_item_view.xml @@ -8,112 +8,60 @@ android:focusable="true" android:foreground="?attr/selectableItemBackground" android:nextFocusRight="@+id/update_action" - android:layout_marginTop="8dp" - android:layout_marginStart="8dp" - android:layout_marginEnd="8dp" - app:cardCornerRadius="16dp" + app:cardCornerRadius="0dp" app:contentPadding="16dp"> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="vertical"> - - - - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="horizontal" + android:weightSum="1" + android:baselineAligned="false"> - + android:layout_weight="1" + android:orientation="vertical"> - - - - - - - - + android:alpha="0.87" + android:drawablePadding="8dp" + android:maxLines="1" + android:paddingBottom="8sp" + android:textColor="?android:attr/textColorPrimary" + android:textSize="16sp" + tools:text="LineageOS 20" /> - - - - + android:maxLines="1" + android:textSize="14sp" + tools:text="18 June 2023" /> + -