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

Commit 6c8f2e45 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Delete alert window notification channel when no longer used

We no longer need the notification channel for alert window
use for a process e.g. the package is uninstalled, then go ahead
and delete the channel.

Change-Id: I2dea9af0e73810f91b248ad85cab73fa4f8271f4
Fixes: 67883657
Test: steps from bug
parent faf85253
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -72,20 +72,23 @@ class AlertWindowNotification {
    }

    /** Cancels the notification */
    void cancel() {
    void cancel(boolean deleteChannel) {
        // We can't call into NotificationManager with WM lock held since it might call into AM.
        // So, we post a message to do it later.
        mService.mH.post(this::onCancelNotification);
        mService.mH.post(() -> onCancelNotification(deleteChannel));
    }

    /** Don't call with the window manager lock held! */
    private void onCancelNotification() {
    private void onCancelNotification(boolean deleteChannel) {
        if (!mPosted) {
            // Notification isn't currently posted...
            return;
        }
        mPosted = false;
        mNotificationManager.cancel(mNotificationTag, NOTIFICATION_ID);
        if (deleteChannel) {
            mNotificationManager.deleteNotificationChannel(mNotificationTag);
        }
    }

    /** Don't call with the window manager lock held! */
@@ -146,8 +149,12 @@ class AlertWindowNotification {

        final String nameChannel =
                context.getString(R.string.alert_windows_notification_channel_name, appName);
        final NotificationChannel channel =
                new NotificationChannel(mNotificationTag, nameChannel, IMPORTANCE_MIN);

        NotificationChannel channel = mNotificationManager.getNotificationChannel(mNotificationTag);
        if (channel != null) {
            return;
        }
        channel = new NotificationChannel(mNotificationTag, nameChannel, IMPORTANCE_MIN);
        channel.enableLights(false);
        channel.enableVibration(false);
        channel.setBlockableSystem(true);
+2 −2
Original line number Diff line number Diff line
@@ -547,7 +547,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
            if (allowed) {
                mAlertWindowNotification.post();
            } else {
                mAlertWindowNotification.cancel();
                mAlertWindowNotification.cancel(false /* deleteChannel */);
            }
        }
    }
@@ -586,7 +586,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        if (mAlertWindowNotification == null) {
            return;
        }
        mAlertWindowNotification.cancel();
        mAlertWindowNotification.cancel(true /* deleteChannel */);
        mAlertWindowNotification = null;
    }