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

Commit bd559096 authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixes an issue where users could be stuck with heads up notifications

In a previous refactor, the notification would not be removed as soon
as possible anymore when its lifetime was extended, leading to issues
where a notification would never time out and therefore never be removed.
Additionally would we also extend the lifetime while the panel is
expanded, which is wrong.

Change-Id: If51ae9ab77ad4eb10166c71db3b902c6ac32fd06
Fixes: 122885133
Test: atest packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java
parent 2bfd202e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -257,6 +257,10 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
    public void setShouldManageLifetime(NotificationEntry entry, boolean shouldExtend) {
        if (shouldExtend) {
            mExtendedLifetimeAlertEntries.add(entry);
            // We need to make sure that entries are stopping to alert eventually, let's remove
            // this as soon as possible.
            AlertEntry alertEntry = mAlertEntries.get(entry.key);
            alertEntry.removeAsSoonAsPossible();
        } else {
            mExtendedLifetimeAlertEntries.remove(entry);
        }
+8 −0
Original line number Diff line number Diff line
@@ -358,6 +358,14 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
        region.op(bounds, Op.UNION);
    }

    @Override
    public boolean shouldExtendLifetime(NotificationEntry entry) {
        // We should not defer the removal if reordering isn't allowed since otherwise
        // these won't disappear until reordering is allowed again, which happens only once
        // the notification panel is collapsed again.
        return mVisualStabilityManager.isReorderingAllowed() && super.shouldExtendLifetime(entry);
    }

    @Override
    public void onConfigChanged(Configuration newConfig) {
        Resources resources = mContext.getResources();
+21 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.app.ActivityManager;
import android.app.Notification;
@@ -75,6 +77,8 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {
    @Mock protected ExpandableNotificationRow mRow;

    private final class TestableAlertingNotificationManager extends AlertingNotificationManager {
        private AlertEntry mLastCreatedEntry;

        private TestableAlertingNotificationManager() {
            mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
            mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME;
@@ -87,6 +91,12 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {
        @Override
        protected void onAlertEntryRemoved(AlertEntry alertEntry) {}

        @Override
        protected AlertEntry createAlertEntry() {
            mLastCreatedEntry = spy(super.createAlertEntry());
            return mLastCreatedEntry;
        }

        @Override
        public int getContentFlag() {
            return FLAG_CONTENT_VIEW_CONTRACTED;
@@ -205,6 +215,17 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {
        assertTrue(mAlertingNotificationManager.mExtendedLifetimeAlertEntries.contains(mEntry));
    }

    @Test
    public void testSetShouldManageLifetime_setShouldManageCallsRemoval() {
        mAlertingNotificationManager.showNotification(mEntry);
        mAlertingNotificationManager.setShouldManageLifetime(mEntry, true /* shouldManage */);
        if (mAlertingNotificationManager instanceof TestableAlertingNotificationManager) {
            TestableAlertingNotificationManager testableManager =
                    (TestableAlertingNotificationManager) mAlertingNotificationManager;
            verify(testableManager.mLastCreatedEntry).removeAsSoonAsPossible();
        }
    }

    @Test
    public void testSetShouldManageLifetime_setShouldNotManage() {
        mAlertingNotificationManager.mExtendedLifetimeAlertEntries.add(mEntry);