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

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

Updater: check for active notifications before self stop

Change-Id: I869ab48a0d518bac3522aab2b8778321612855d1
parent 5ac9a9dd
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.SharedPreferences;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.service.notification.StatusBarNotification;
import android.text.format.Formatter;
import android.util.Log;

@@ -249,12 +250,28 @@ public class UpdaterService extends Service {

    private void tryStopSelf() {
        if (!mHasClients && !mUpdaterController.hasActiveDownloads() &&
                !mUpdaterController.isInstallingUpdate() && !isNetworkCallBackActive()) {
                !mUpdaterController.isInstallingUpdate() && !isNetworkCallBackActive()
                && !areNotificationsActive()) {
            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;
    }

    private void handleUpdateStatusChange(UpdateInfo update) {
        switch (update.getStatus()) {
            case DELETED: {