From f90293af98b68bdfb2a05c78e9f5e5ad6c73b4bf Mon Sep 17 00:00:00 2001 From: althafvly Date: Mon, 12 Aug 2024 19:01:56 +0530 Subject: [PATCH] Updater: Delete updates on boot --- src/org/lineageos/updater/UpdaterReceiver.java | 12 ++++-------- src/org/lineageos/updater/misc/Utils.java | 11 +++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/org/lineageos/updater/UpdaterReceiver.java b/src/org/lineageos/updater/UpdaterReceiver.java index f412f4e3..c8857db0 100644 --- a/src/org/lineageos/updater/UpdaterReceiver.java +++ b/src/org/lineageos/updater/UpdaterReceiver.java @@ -28,10 +28,10 @@ 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; +import org.lineageos.updater.misc.Utils; import java.text.DateFormat; @@ -87,18 +87,14 @@ 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); - } + Utils.removeInstalledUpdate(context); 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(); + Utils.removeInstalledUpdate(context); if (shouldShowUpdateFailedNotification(context)) { pref.edit().putBoolean(Constants.PREF_INSTALL_NOTIFIED, true).apply(); diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 5dc759f9..88032781 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -54,6 +54,7 @@ import org.json.JSONException; import org.json.JSONObject; import org.lineageos.updater.R; import org.lineageos.updater.UpdatesDbHelper; +import org.lineageos.updater.controller.UpdaterController; import org.lineageos.updater.controller.UpdaterService; import org.lineageos.updater.model.Update; import org.lineageos.updater.model.UpdateBaseInfo; @@ -490,6 +491,16 @@ public class Utils { preferences.edit().putBoolean(DOWNLOADS_CLEANUP_DONE, true).apply(); } + 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); + pref.edit().remove(Constants.PREF_NEEDS_DELETE_ID).apply(); + } + } + public static File appendSequentialNumber(final File file) { String name; String extension; -- GitLab