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

Commit ff5ab550 authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Check avalanche entry list when needed in BaseHeadsUpManager" into main

parents 29acc19f 8db41dee
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.when;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Person;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.FlagsParameterization;
import android.testing.TestableLooper;

@@ -149,6 +150,62 @@ public class BaseHeadsUpManagerTest extends SysuiTestCase {
        mAvalancheController = new AvalancheController(dumpManager);
    }

    @Test
    public void testHasNotifications_headsUpManagerMapNotEmpty_true() {
        final BaseHeadsUpManager bhum = createHeadsUpManager();
        final NotificationEntry entry = HeadsUpManagerTestUtil.createEntry(/* id = */ 0, mContext);
        bhum.showNotification(entry);

        assertThat(bhum.mHeadsUpEntryMap).isNotEmpty();
        assertThat(bhum.hasNotifications()).isTrue();
    }

    @Test
    @EnableFlags(NotificationThrottleHun.FLAG_NAME)
    public void testHasNotifications_avalancheMapNotEmpty_true() {
        final BaseHeadsUpManager bhum = createHeadsUpManager();
        final NotificationEntry notifEntry = HeadsUpManagerTestUtil.createEntry(/* id = */ 0,
                mContext);
        final BaseHeadsUpManager.HeadsUpEntry headsUpEntry = bhum.createHeadsUpEntry(notifEntry);
        mAvalancheController.addToNext(headsUpEntry, () -> {});

        assertThat(mAvalancheController.getWaitingEntryList()).isNotEmpty();
        assertThat(bhum.hasNotifications()).isTrue();
    }

    @Test
    @EnableFlags(NotificationThrottleHun.FLAG_NAME)
    public void testHasNotifications_false() {
        final BaseHeadsUpManager bhum = createHeadsUpManager();
        assertThat(bhum.mHeadsUpEntryMap).isEmpty();
        assertThat(mAvalancheController.getWaitingEntryList()).isEmpty();
        assertThat(bhum.hasNotifications()).isFalse();
    }

    @Test
    @EnableFlags(NotificationThrottleHun.FLAG_NAME)
    public void testGetHeadsUpEntryList_includesAvalancheEntryList() {
        final BaseHeadsUpManager bhum = createHeadsUpManager();
        final NotificationEntry notifEntry = HeadsUpManagerTestUtil.createEntry(/* id = */ 0,
                mContext);
        final BaseHeadsUpManager.HeadsUpEntry headsUpEntry = bhum.createHeadsUpEntry(notifEntry);
        mAvalancheController.addToNext(headsUpEntry, () -> {});

        assertThat(bhum.getHeadsUpEntryList()).contains(headsUpEntry);
    }

    @Test
    @EnableFlags(NotificationThrottleHun.FLAG_NAME)
    public void testGetHeadsUpEntry_returnsAvalancheEntry() {
        final BaseHeadsUpManager bhum = createHeadsUpManager();
        final NotificationEntry notifEntry = HeadsUpManagerTestUtil.createEntry(/* id = */ 0,
                mContext);
        final BaseHeadsUpManager.HeadsUpEntry headsUpEntry = bhum.createHeadsUpEntry(notifEntry);
        mAvalancheController.addToNext(headsUpEntry, () -> {});

        assertThat(bhum.getHeadsUpEntry(notifEntry.getKey())).isEqualTo(headsUpEntry);
    }

    @Test
    public void testShowNotification_addsEntry() {
        final BaseHeadsUpManager alm = createHeadsUpManager();
+6 −2
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
    private final List<OnHeadsUpPhoneListenerChange> mHeadsUpPhoneListeners = new ArrayList<>();
    private final VisualStabilityProvider mVisualStabilityProvider;

    private final AvalancheController mAvalancheController;

    // TODO(b/328393698) move the topHeadsUpRow logic to an interactor
    private final MutableStateFlow<HeadsUpRowRepository> mTopHeadsUpRow =
            StateFlowKt.MutableStateFlow(null);
@@ -155,6 +157,7 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
        mBypassController = bypassController;
        mGroupMembershipManager = groupMembershipManager;
        mVisualStabilityProvider = visualStabilityProvider;
        mAvalancheController = avalancheController;

        updateResources();
        configurationController.addCallback(new ConfigurationController.ConfigurationListener() {
@@ -653,9 +656,10 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
            boolean wasKeyguard = mStatusBarState == StatusBarState.KEYGUARD;
            boolean isKeyguard = newState == StatusBarState.KEYGUARD;
            mStatusBarState = newState;

            if (wasKeyguard && !isKeyguard && mBypassController.getBypassEnabled()) {
                ArrayList<String> keysToRemove = new ArrayList<>();
                for (HeadsUpEntry entry : mHeadsUpEntryMap.values()) {
                for (HeadsUpEntry entry : getHeadsUpEntryList()) {
                    if (entry.mEntry != null && entry.mEntry.isBubble() && !entry.isSticky()) {
                        keysToRemove.add(entry.mEntry.getKey());
                    }
@@ -671,7 +675,7 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
            if (!isDozing) {
                // Let's make sure all huns we got while dozing time out within the normal timeout
                // duration. Otherwise they could get stuck for a very long time
                for (HeadsUpEntry entry : mHeadsUpEntryMap.values()) {
                for (HeadsUpEntry entry : getHeadsUpEntryList()) {
                    entry.updateEntry(true /* updatePostTime */, "onDozingChanged(false)");
                }
            }
+7 −0
Original line number Diff line number Diff line
@@ -254,6 +254,13 @@ constructor(
        return null
    }

    fun getWaitingEntryList(): List<HeadsUpEntry> {
        if (!NotificationThrottleHun.isEnabled) {
            return mutableListOf()
        }
        return nextMap.keys.toList()
    }

    private fun isShowing(entry: HeadsUpEntry): Boolean {
        return headsUpEntryShowing != null && entry.mEntry?.key == headsUpEntryShowing?.mEntry?.key
    }
+14 −8
Original line number Diff line number Diff line
@@ -279,7 +279,6 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
     * Returns the entry if it is managed by this manager.
     * @param key key of notification
     * @return the entry
     * TODO(b/315362456) See if caller needs to check AvalancheController waiting entries
     */
    @Nullable
    public NotificationEntry getEntry(@NonNull String key) {
@@ -294,8 +293,13 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
    @NonNull
    @Override
    public Stream<NotificationEntry> getAllEntries() {
        // TODO(b/315362456) See if callers need to check AvalancheController
        return mHeadsUpEntryMap.values().stream().map(headsUpEntry -> headsUpEntry.mEntry);
        return getHeadsUpEntryList().stream().map(headsUpEntry -> headsUpEntry.mEntry);
    }

    public List<HeadsUpEntry> getHeadsUpEntryList() {
        List<HeadsUpEntry> entryList = new ArrayList<>(mHeadsUpEntryMap.values());
        entryList.addAll(mAvalancheController.getWaitingEntryList());
        return entryList;
    }

    /**
@@ -304,7 +308,8 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
     */
    @Override
    public boolean hasNotifications() {
        return !mHeadsUpEntryMap.isEmpty();
        return !mHeadsUpEntryMap.isEmpty()
                || !mAvalancheController.getWaitingEntryList().isEmpty();
    }

    /**
@@ -507,9 +512,11 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {

    @Nullable
    protected HeadsUpEntry getHeadsUpEntry(@NonNull String key) {
        // TODO(b/315362456) See if callers need to check AvalancheController
        if (mHeadsUpEntryMap.containsKey(key)) {
            return mHeadsUpEntryMap.get(key);
        }
        return mAvalancheController.getWaitingEntry(key);
    }

    /**
     * Returns the top Heads Up Notification, which appears to show at first.
@@ -688,8 +695,7 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
     */
    @Override
    public boolean isSticky(String key) {
        // TODO(b/315362456) See if callers need to check AvalancheController
        HeadsUpEntry headsUpEntry = mHeadsUpEntryMap.get(key);
        HeadsUpEntry headsUpEntry = getHeadsUpEntry(key);
        if (headsUpEntry != null) {
            return headsUpEntry.isSticky();
        }