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

Commit ea585c0a authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '7620-t-reboot_fix' into 'v1-t'

Add permanent reboot notification

See merge request !189
parents 789fa8b8 39628252
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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();
+11 −17
Original line number Diff line number Diff line
@@ -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 || areNotificationsActive()) return;
        if (!mHasClients && !mUpdaterController.hasActiveDownloads() &&
                !mUpdaterController.isInstallingUpdate() && !isNetworkCallBackActive()
                && !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) {
@@ -486,14 +479,15 @@ 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);
                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();
                }

                tryStopSelf();
+1 −0
Original line number Diff line number Diff line
@@ -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";