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

Commit e6e19a51 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Delete alert window notification channel when no longer used"

parents 35501be1 6c8f2e45
Loading
Loading
Loading
Loading
+12 −5
Original line number Original line Diff line number Diff line
@@ -72,20 +72,23 @@ class AlertWindowNotification {
    }
    }


    /** Cancels the notification */
    /** 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.
        // 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.
        // 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! */
    /** Don't call with the window manager lock held! */
    private void onCancelNotification() {
    private void onCancelNotification(boolean deleteChannel) {
        if (!mPosted) {
        if (!mPosted) {
            // Notification isn't currently posted...
            // Notification isn't currently posted...
            return;
            return;
        }
        }
        mPosted = false;
        mPosted = false;
        mNotificationManager.cancel(mNotificationTag, NOTIFICATION_ID);
        mNotificationManager.cancel(mNotificationTag, NOTIFICATION_ID);
        if (deleteChannel) {
            mNotificationManager.deleteNotificationChannel(mNotificationTag);
        }
    }
    }


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


        final String nameChannel =
        final String nameChannel =
                context.getString(R.string.alert_windows_notification_channel_name, appName);
                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.enableLights(false);
        channel.enableVibration(false);
        channel.enableVibration(false);
        channel.setBlockableSystem(true);
        channel.setBlockableSystem(true);
+2 −2
Original line number Original line Diff line number Diff line
@@ -547,7 +547,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
            if (allowed) {
            if (allowed) {
                mAlertWindowNotification.post();
                mAlertWindowNotification.post();
            } else {
            } else {
                mAlertWindowNotification.cancel();
                mAlertWindowNotification.cancel(false /* deleteChannel */);
            }
            }
        }
        }
    }
    }
@@ -586,7 +586,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        if (mAlertWindowNotification == null) {
        if (mAlertWindowNotification == null) {
            return;
            return;
        }
        }
        mAlertWindowNotification.cancel();
        mAlertWindowNotification.cancel(true /* deleteChannel */);
        mAlertWindowNotification = null;
        mAlertWindowNotification = null;
    }
    }