From f17e4acdeb55779e59fd19aa273e9920ff30c2f4 Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 5 Sep 2024 13:30:05 +0530 Subject: [PATCH 1/3] Updater: Hide update available when needed --- res/layout/activity_updates.xml | 1 + src/org/lineageos/updater/UpdatesActivity.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/res/layout/activity_updates.xml b/res/layout/activity_updates.xml index 52e6aa7f..1db6fcfb 100644 --- a/res/layout/activity_updates.xml +++ b/res/layout/activity_updates.xml @@ -132,6 +132,7 @@ android:paddingStart="16dp" android:textSize="16sp" android:background="@color/toolbar_collapsed" + android:visibility="gone" android:text="@string/e_available_updates" android:textColor="?android:textColorPrimary" /> diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 75074bda..68ca2b86 100644 --- a/src/org/lineageos/updater/UpdatesActivity.java +++ b/src/org/lineageos/updater/UpdatesActivity.java @@ -299,9 +299,11 @@ public class UpdatesActivity extends UpdatesListActivity { if (sortedUpdates.isEmpty()) { findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); findViewById(R.id.content).setVisibility(View.GONE); + findViewById(R.id.available_update_header).setVisibility(View.GONE); } else { findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.content).setVisibility(View.VISIBLE); + findViewById(R.id.available_update_header).setVisibility(View.VISIBLE); sortedUpdates.sort((u1, u2) -> Long.compare(u2.getTimestamp(), u1.getTimestamp())); for (UpdateInfo update : sortedUpdates) { updateIds.add(update.getDownloadId()); @@ -458,6 +460,7 @@ public class UpdatesActivity extends UpdatesListActivity { } } else { findViewById(R.id.content).setVisibility(View.GONE); + findViewById(R.id.available_update_header).setVisibility(View.GONE); findViewById(R.id.no_new_updates_view).setVisibility(View.GONE); findViewById(R.id.refresh_progress).setVisibility(View.VISIBLE); } @@ -473,6 +476,7 @@ public class UpdatesActivity extends UpdatesListActivity { findViewById(R.id.refresh_progress).setVisibility(View.GONE); if (mAdapter.getItemCount() > 0) { findViewById(R.id.content).setVisibility(View.VISIBLE); + findViewById(R.id.available_update_header).setVisibility(View.VISIBLE); } else { findViewById(R.id.no_new_updates_view).setVisibility(View.VISIBLE); } -- GitLab From b00da03e296535b27ada390e97cd90a8f1c2811f Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 5 Sep 2024 16:08:49 +0530 Subject: [PATCH 2/3] Updater: Change reboot notification priority --- src/org/lineageos/updater/controller/UpdaterService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index d713153c..d5077faf 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -282,6 +282,7 @@ public class UpdaterService extends Service { private void handleUpdateStatusChange(UpdateInfo update) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = pref.edit(); + mNotificationBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); switch (update.getStatus()) { case DELETED: { notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); @@ -489,6 +490,7 @@ public class UpdaterService extends Service { mNotificationBuilder.setTicker(text); mNotificationBuilder.setOngoing(true); mNotificationBuilder.setAutoCancel(false); + mNotificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX); mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); boolean deleteUpdate = pref.getBoolean(Constants.PREF_AUTO_DELETE_UPDATES, true); -- GitLab From c963e33aa4f6dce72f766c143eb228dbca19160a Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 5 Sep 2024 16:18:55 +0530 Subject: [PATCH 3/3] Updater: Remove update before loading list --- src/org/lineageos/updater/UpdatesActivity.java | 4 ++++ src/org/lineageos/updater/controller/UpdaterService.java | 7 +++++++ src/org/lineageos/updater/misc/Utils.java | 8 +++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 68ca2b86..835eba98 100644 --- a/src/org/lineageos/updater/UpdatesActivity.java +++ b/src/org/lineageos/updater/UpdatesActivity.java @@ -111,6 +111,10 @@ public class UpdatesActivity extends UpdatesListActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_updates); + if (UpdaterService.isDeviceRebooted()) { + Utils.removeInstalledUpdate(this); + } + UiModeManager uiModeManager = getSystemService(UiModeManager.class); mIsTV = uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION; diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index d5077faf..3deaecf7 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -97,6 +97,8 @@ public class UpdaterService extends Service { private static ConnectivityManager.NetworkCallback mConnectionStateMonitor; private static ConnectivityManager mConnectivityManager; + private static boolean mDeviceRebooted = true; + @Override public void onCreate() { super.onCreate(); @@ -263,6 +265,10 @@ public class UpdaterService extends Service { return mUpdaterController; } + public static boolean isDeviceRebooted() { + return mDeviceRebooted; + } + private void tryStopSelf() { if (isNetworkCallBackActive || areNotificationsActive()) return; if (!mHasClients && !mUpdaterController.hasActiveDownloads() && @@ -283,6 +289,7 @@ public class UpdaterService extends Service { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = pref.edit(); mNotificationBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); + mDeviceRebooted = false; switch (update.getStatus()) { case DELETED: { notifySystemUpdaterService(STATUS_WAITING_DOWNLOAD, update); diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 88032781..0ff5e42e 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -494,9 +494,11 @@ public class Utils { public static void removeInstalledUpdate(Context context) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); String downloadId = pref.getString(Constants.PREF_NEEDS_DELETE_ID, null); - UpdaterController controller = UpdaterController.getInstance(context); - if (controller != null && downloadId != null) { - controller.deleteUpdate(downloadId); + if (downloadId != null) { + UpdaterController controller = UpdaterController.getInstance(context); + if (controller != null) { + controller.deleteUpdate(downloadId); + } pref.edit().remove(Constants.PREF_NEEDS_DELETE_ID).apply(); } } -- GitLab