From c0fcd2f1928004377d049b392d18e3db63ab24ac 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 --- .../java/org/lineageos/updater/controller/UpdaterService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 bb15f23b..7eb3ab3e 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -486,8 +486,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 1e117a90606631087e7842468986ee58236aee1e 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 --- .../org/lineageos/updater/controller/UpdaterService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 7eb3ab3e..96931f3e 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -255,9 +255,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(); } @@ -315,7 +315,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); } @@ -338,7 +338,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 50e36c7624dd081067bd5558222ca86b3ca52450 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/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index 96931f3e..bbc6627e 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -45,6 +45,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 { @@ -255,27 +256,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) { @@ -496,7 +489,9 @@ public class UpdaterService extends Service { mUpdaterController.deleteUpdate(update.getDownloadId()); } - tryStopSelf(); + if (!mUpdaterController.isWaitingForReboot(update.getDownloadId())) { + tryStopSelf(); + } break; } case INSTALLATION_FAILED: { -- GitLab From 37d7a184869809fb8860c1c442d4cf1005939052 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 --- .../main/java/org/lineageos/updater/UpdaterReceiver.java | 9 ++++++++- .../org/lineageos/updater/controller/UpdaterService.java | 7 +++---- .../main/java/org/lineageos/updater/misc/Constants.java | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java index 1ba25219..ec9d039e 100644 --- a/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java +++ b/app/src/main/java/org/lineageos/updater/UpdaterReceiver.java @@ -17,6 +17,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; @@ -75,12 +76,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/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java index bbc6627e..0da32029 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -486,12 +486,11 @@ public class UpdaterService extends Service { boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); boolean isLocal = Update.LOCAL_ID.equals(update.getDownloadId()); if (deleteUpdate || isLocal) { - 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/app/src/main/java/org/lineageos/updater/misc/Constants.java b/app/src/main/java/org/lineageos/updater/misc/Constants.java index 7a484fc2..0dfd8ad5 100644 --- a/app/src/main/java/org/lineageos/updater/misc/Constants.java +++ b/app/src/main/java/org/lineageos/updater/misc/Constants.java @@ -28,6 +28,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_NEEDS_DELETE_ID = "needs_delete_id"; public static final String PREF_NETWORK_CALLBACK_ACTIVE = "pref_network_callback_active"; public static final String UNCRYPT_FILE_EXT = ".uncrypt"; -- GitLab From e5a3022edf6fb00fcc24c64364d31491b13197c4 Mon Sep 17 00:00:00 2001 From: Mohammed Althaf Thayyil Date: Tue, 30 Jul 2024 09:25:13 +0000 Subject: [PATCH 5/5] Use isNetworkCallBackActive instead of fun --- .../org/lineageos/updater/controller/UpdaterService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 0da32029..727bf747 100644 --- a/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java +++ b/app/src/main/java/org/lineageos/updater/controller/UpdaterService.java @@ -256,7 +256,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"); @@ -308,7 +308,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); } @@ -331,7 +331,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