Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea362ca3 authored by Sahil Sonar's avatar Sahil Sonar 💬
Browse files

Merge branch '2452-u-updater_delete' into 'v1-u'

Updater: Delete updates on boot

See merge request !194
parents 735082e8 55d5603b
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -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();
+11 −0
Original line number Diff line number Diff line
@@ -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;
@@ -484,6 +485,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;