From 32f43028731fb26eb6f72e6d99b654f0c8e61904 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 23 Jul 2024 15:50:31 +0530 Subject: [PATCH 1/5] Updater: Make reboot notification persist --- src/org/lineageos/updater/controller/UpdaterService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index d2ac3fdd..59f8c304 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -494,8 +494,8 @@ public class UpdaterService extends Service { getString(R.string.reboot), getRebootPendingIntent()); mNotificationBuilder.setTicker(text); - mNotificationBuilder.setOngoing(false); - mNotificationBuilder.setAutoCancel(true); + mNotificationBuilder.setOngoing(true); + mNotificationBuilder.setAutoCancel(false); mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); -- GitLab From 12082717b8593d14dd348e3b67abeb6beb92a8f4 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 23 Jul 2024 16:04:02 +0530 Subject: [PATCH 2/5] Updater: Use existing function instead of variable --- src/org/lineageos/updater/controller/UpdaterService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index 59f8c304..c4c51881 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -263,9 +263,9 @@ public class UpdaterService extends Service { } private void tryStopSelf() { + if (isNetworkCallBackActive()) return; if (!mHasClients && !mUpdaterController.hasActiveDownloads() && - !mUpdaterController.isInstallingUpdate() && !isNetworkCallBackActive() - && !areNotificationsActive()) { + !mUpdaterController.isInstallingUpdate() && !areNotificationsActive()) { Log.d(TAG, "Service no longer needed, stopping"); stopSelf(); } @@ -323,7 +323,7 @@ public class UpdaterService extends Service { mNotificationBuilder.addAction(android.R.drawable.ic_media_pause, getString(R.string.pause_button), getPausePendingIntent(update.getDownloadId())); - if (isNetworkCallBackActive) { + if (isNetworkCallBackActive()) { editor.putString(Constants.RESUME_DOWNLOAD_ID, "").apply(); setupNetworkCallback(false); } @@ -346,7 +346,7 @@ public class UpdaterService extends Service { mNotificationBuilder.addAction(android.R.drawable.ic_media_play, getString(R.string.resume_button), getResumePendingIntent(update.getDownloadId())); - if (isNetworkCallBackActive) { + if (isNetworkCallBackActive()) { editor.putString(Constants.RESUME_DOWNLOAD_ID, "").apply(); setupNetworkCallback(false); } -- GitLab From 5b788f920e1e1658be3ee27cbf95dd73ea138477 Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 23 Jul 2024 16:58:53 +0530 Subject: [PATCH 3/5] Updater: Keep updater alive for notifications --- .../updater/controller/UpdaterService.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index c4c51881..460519a1 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -55,6 +55,7 @@ import org.lineageos.updater.model.UpdateStatus; import java.io.IOException; import java.text.DateFormat; import java.text.NumberFormat; +import java.util.Arrays; public class UpdaterService extends Service { @@ -263,27 +264,19 @@ public class UpdaterService extends Service { } private void tryStopSelf() { - if (isNetworkCallBackActive()) return; + if (isNetworkCallBackActive() || areNotificationsActive()) return; if (!mHasClients && !mUpdaterController.hasActiveDownloads() && - !mUpdaterController.isInstallingUpdate() && !areNotificationsActive()) { + !mUpdaterController.isInstallingUpdate()) { 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; + StatusBarNotification[] notifications = mNotificationManager.getActiveNotifications(); + return notifications != null && Arrays.stream(notifications) + .anyMatch(notification -> notification.getId() == NOTIFICATION_ID || + notification.getPackageName().equals(getPackageName())); } private void handleUpdateStatusChange(UpdateInfo update) { @@ -503,7 +496,9 @@ public class UpdaterService extends Service { mUpdaterController.deleteUpdate(update.getDownloadId()); } - tryStopSelf(); + if (!mUpdaterController.isWaitingForReboot(update.getDownloadId())) { + tryStopSelf(); + } break; } case INSTALLATION_FAILED: { -- GitLab From 69278b80c8e0828e29e84eab78d49b04e493c566 Mon Sep 17 00:00:00 2001 From: althafvly Date: Wed, 24 Jul 2024 21:39:34 +0530 Subject: [PATCH 4/5] Updater: Delete update reboot action --- src/org/lineageos/updater/UpdaterReceiver.java | 9 ++++++++- src/org/lineageos/updater/controller/UpdaterService.java | 7 +++---- src/org/lineageos/updater/misc/Constants.java | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/org/lineageos/updater/UpdaterReceiver.java b/src/org/lineageos/updater/UpdaterReceiver.java index f295f05c..f412f4e3 100644 --- a/src/org/lineageos/updater/UpdaterReceiver.java +++ b/src/org/lineageos/updater/UpdaterReceiver.java @@ -28,6 +28,7 @@ import android.os.SystemProperties; import androidx.core.app.NotificationCompat; import androidx.preference.PreferenceManager; +import org.lineageos.updater.controller.UpdaterController; import org.lineageos.updater.misc.BuildInfoUtils; import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.StringGenerator; @@ -86,12 +87,18 @@ public class UpdaterReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); if (ACTION_INSTALL_REBOOT.equals(intent.getAction())) { + String downloadId = pref.getString(Constants.PREF_NEEDS_DELETE_ID, null); + UpdaterController controller = UpdaterController.getInstance(context); + if (controller != null && downloadId != null) { + controller.deleteUpdate(downloadId); + } PowerManager pm = context.getSystemService(PowerManager.class); pm.reboot(null); } else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { - SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); pref.edit().remove(Constants.PREF_NEEDS_REBOOT_ID).apply(); + pref.edit().remove(Constants.PREF_NEEDS_DELETE_ID).apply(); if (shouldShowUpdateFailedNotification(context)) { pref.edit().putBoolean(Constants.PREF_INSTALL_NOTIFIED, true).apply(); diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index 460519a1..993d3738 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -493,12 +493,11 @@ public class UpdaterService extends Service { boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); if (deleteUpdate) { - mUpdaterController.deleteUpdate(update.getDownloadId()); + pref.edit().putString(Constants.PREF_NEEDS_DELETE_ID, + update.getDownloadId()).apply(); } - if (!mUpdaterController.isWaitingForReboot(update.getDownloadId())) { - tryStopSelf(); - } + tryStopSelf(); break; } case INSTALLATION_FAILED: { diff --git a/src/org/lineageos/updater/misc/Constants.java b/src/org/lineageos/updater/misc/Constants.java index efe48c15..4cc912ba 100644 --- a/src/org/lineageos/updater/misc/Constants.java +++ b/src/org/lineageos/updater/misc/Constants.java @@ -38,6 +38,7 @@ public final class Constants { public static final String PREF_AB_PERF_MODE = "ab_perf_mode"; 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_NEEDS_DELETE_ID = "needs_delete_id"; public static final String UNCRYPT_FILE_EXT = ".uncrypt"; -- GitLab From 0564f894f66089d4f1d057a09dca12dfceb89b3f Mon Sep 17 00:00:00 2001 From: Mohammed Althaf Thayyil Date: Tue, 30 Jul 2024 09:24:19 +0000 Subject: [PATCH 5/5] Use isNetworkCallBackActive instead of fun --- src/org/lineageos/updater/controller/UpdaterService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index 993d3738..d713153c 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -264,7 +264,7 @@ public class UpdaterService extends Service { } private void tryStopSelf() { - if (isNetworkCallBackActive() || areNotificationsActive()) return; + if (isNetworkCallBackActive || areNotificationsActive()) return; if (!mHasClients && !mUpdaterController.hasActiveDownloads() && !mUpdaterController.isInstallingUpdate()) { Log.d(TAG, "Service no longer needed, stopping"); @@ -316,7 +316,7 @@ public class UpdaterService extends Service { mNotificationBuilder.addAction(android.R.drawable.ic_media_pause, getString(R.string.pause_button), getPausePendingIntent(update.getDownloadId())); - if (isNetworkCallBackActive()) { + if (isNetworkCallBackActive) { editor.putString(Constants.RESUME_DOWNLOAD_ID, "").apply(); setupNetworkCallback(false); } @@ -339,7 +339,7 @@ public class UpdaterService extends Service { mNotificationBuilder.addAction(android.R.drawable.ic_media_play, getString(R.string.resume_button), getResumePendingIntent(update.getDownloadId())); - if (isNetworkCallBackActive()) { + if (isNetworkCallBackActive) { editor.putString(Constants.RESUME_DOWNLOAD_ID, "").apply(); setupNetworkCallback(false); } -- GitLab