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

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

Merge changes Ib49522e5,I3f5c4e5c,I645543e9,I73bf4c9c into main

* changes:
  Fix missing grouping after shade closes
  Log AvalancheController outcome after running runnable
  Only log auto remove request if passed into AvalancheController
  Log BaseHeadsUpManager entry map
parents b338b544 6a051804
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.systemui.util.kotlin.JavaAdapter
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.time.SystemClock
import com.google.common.truth.Truth.assertThat
import junit.framework.Assert
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
@@ -244,35 +245,37 @@ class HeadsUpManagerPhoneTest(flags: FlagsParameterization) : BaseHeadsUpManager
        mSystemClock.advanceTime((TEST_AUTO_DISMISS_TIME + hmp.mExtensionTime / 2).toLong())
        Assert.assertTrue(hmp.isHeadsUpEntry(entry.key))
    }
    @Test
    @EnableFlags(NotificationThrottleHun.FLAG_NAME)
    fun testShowNotification_removeWhenReorderingAllowedTrue() {
        whenever(mVSProvider.isReorderingAllowed).thenReturn(true)
        val hmp = createHeadsUpManagerPhone()

        val notifEntry = HeadsUpManagerTestUtil.createEntry(/* id= */ 0, mContext)
        hmp.showNotification(notifEntry)
        assertThat(hmp.mEntriesToRemoveWhenReorderingAllowed.contains(notifEntry)).isTrue();
    }

    @Test
    @EnableFlags(NotificationThrottleHun.FLAG_NAME)
    fun testShowNotification_reorderNotAllowed_notPulsing_seenInShadeTrue() {
    fun testShowNotification_reorderNotAllowed_seenInShadeTrue() {
        whenever(mVSProvider.isReorderingAllowed).thenReturn(false)
        val hmp = createHeadsUpManagerPhone()

        val notifEntry = HeadsUpManagerTestUtil.createEntry(/* id= */ 0, mContext)
        val row = mock<ExpandableNotificationRow>()
        whenever(row.showingPulsing()).thenReturn(false)
        notifEntry.row = row

        hmp.showNotification(notifEntry)
        Assert.assertTrue(notifEntry.isSeenInShade)
        assertThat(notifEntry.isSeenInShade).isTrue();
    }

    @Test
    @EnableFlags(NotificationThrottleHun.FLAG_NAME)
    fun testShowNotification_reorderAllowed_notPulsing_seenInShadeFalse() {
    fun testShowNotification_reorderAllowed_seenInShadeFalse() {
        whenever(mVSProvider.isReorderingAllowed).thenReturn(true)
        val hmp = createHeadsUpManagerPhone()

        val notifEntry = HeadsUpManagerTestUtil.createEntry(/* id= */ 0, mContext)
        val row = mock<ExpandableNotificationRow>()
        whenever(row.showingPulsing()).thenReturn(false)
        notifEntry.row = row

        hmp.showNotification(notifEntry)
        Assert.assertFalse(notifEntry.isSeenInShade)
        assertThat(notifEntry.isSeenInShade).isFalse();
    }

    @Test
+4 −6
Original line number Diff line number Diff line
@@ -103,7 +103,8 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
    private boolean mTrackingHeadsUp;
    private final HashSet<String> mSwipedOutKeys = new HashSet<>();
    private final HashSet<NotificationEntry> mEntriesToRemoveAfterExpand = new HashSet<>();
    private final ArraySet<NotificationEntry> mEntriesToRemoveWhenReorderingAllowed
    @VisibleForTesting
    public final ArraySet<NotificationEntry> mEntriesToRemoveWhenReorderingAllowed
            = new ArraySet<>();
    private boolean mIsShadeOrQsExpanded;
    private boolean mIsQsExpanded;
@@ -630,11 +631,8 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
            super.setEntry(entry, removeRunnable);

            if (NotificationThrottleHun.isEnabled()) {
                if (!mVisualStabilityProvider.isReorderingAllowed()
                        // We don't want to allow reordering while pulsing, but headsup need to
                        // time out anyway
                        && !entry.showingPulsing()) {
                mEntriesToRemoveWhenReorderingAllowed.add(entry);
                if (!mVisualStabilityProvider.isReorderingAllowed()) {
                    entry.setSeenInShade(true);
                }
            }
+36 −14
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ constructor(

    private val tag = "AvalancheController"
    private val debug = Compile.IS_DEBUG && Log.isLoggable(tag, Log.DEBUG)
    var baseEntryMapStr : () -> String = { "baseEntryMapStr not initialized" }

    var enableAtRuntime = true
        set(value) {
            if (!value) {
@@ -116,17 +118,25 @@ constructor(
        val key = getKey(entry)

        if (runnable == null) {
            headsUpManagerLogger.logAvalancheUpdate(caller, isEnabled, key, "Runnable NULL, stop")
            headsUpManagerLogger.logAvalancheUpdate(
                caller, isEnabled, key,
                "Runnable NULL, stop. ${getStateStr()}"
            )
            return
        }
        if (!isEnabled) {
            headsUpManagerLogger.logAvalancheUpdate(caller, isEnabled, key,
                    "NOT ENABLED, run runnable")
            headsUpManagerLogger.logAvalancheUpdate(
                caller, isEnabled, key,
                "NOT ENABLED, run runnable. ${getStateStr()}"
            )
            runnable.run()
            return
        }
        if (entry == null) {
            headsUpManagerLogger.logAvalancheUpdate(caller, isEnabled, key, "Entry NULL, stop")
            headsUpManagerLogger.logAvalancheUpdate(
                caller, isEnabled, key,
                "Entry NULL, stop. ${getStateStr()}"
            )
            return
        }
        if (debug) {
@@ -181,32 +191,40 @@ constructor(
        val key = getKey(entry)

        if (runnable == null) {
            headsUpManagerLogger.logAvalancheDelete(caller, isEnabled, key, "Runnable NULL, stop")
            headsUpManagerLogger.logAvalancheDelete(
                caller, isEnabled, key,
                "Runnable NULL, stop. ${getStateStr()}"
            )
            return
        }
        if (!isEnabled) {
            headsUpManagerLogger.logAvalancheDelete(caller, isEnabled, key,
                    "NOT ENABLED, run runnable")
            runnable.run()
            headsUpManagerLogger.logAvalancheDelete(
                caller, isEnabled = false, key,
                "NOT ENABLED, run runnable. ${getStateStr()}"
            )
            return
        }
        if (entry == null) {
            headsUpManagerLogger.logAvalancheDelete(caller, isEnabled, key,
                    "Entry NULL, run runnable")
            runnable.run()
            headsUpManagerLogger.logAvalancheDelete(
                caller, isEnabled = true, key,
                "Entry NULL, run runnable. ${getStateStr()}"
            )
            return
        }
        val outcome: String
        if (entry in nextMap) {
            outcome = "remove from next"
            if (entry in nextMap) nextMap.remove(entry)
            if (entry in nextList) nextList.remove(entry)
            uiEventLogger.log(ThrottleEvent.AVALANCHE_THROTTLING_HUN_REMOVED)
            outcome = "remove from next. ${getStateStr()}"

        } else if (entry in debugDropSet) {
            outcome = "remove from dropset"
            debugDropSet.remove(entry)
            outcome = "remove from dropset. ${getStateStr()}"

        } else if (isShowing(entry)) {
            outcome = "remove showing"
            previousHunKey = getKey(headsUpEntryShowing)
            // Show the next HUN before removing this one, so that we don't tell listeners
            // onHeadsUpPinnedModeChanged, which causes
@@ -214,9 +232,11 @@ constructor(
            // HUN is animating out, resulting in a flicker.
            showNext()
            runnable.run()
            outcome = "remove showing. ${getStateStr()}"

        } else {
            outcome = "run runnable for untracked shown"
            runnable.run()
            outcome = "run runnable for untracked shown HUN. ${getStateStr()}"
        }
        headsUpManagerLogger.logAvalancheDelete(caller, isEnabled(), getKey(entry), outcome)
    }
@@ -405,7 +425,9 @@ constructor(
                "\n\tprevious: [$previousHunKey]" +
                "\n\tnext list: $nextListStr" +
                "\n\tnext map: $nextMapStr" +
                "\n\tdropped: $dropSetStr"
                "\n\tdropped: $dropSetStr" +
                "\nBHUM.mHeadsUpEntryMap: " +
                baseEntryMapStr()
    }

    private val dropSetStr: String
+14 −1
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
        mAccessibilityMgr = accessibilityManagerWrapper;
        mUiEventLogger = uiEventLogger;
        mAvalancheController = avalancheController;
        mAvalancheController.setBaseEntryMapStr(this::getEntryMapStr);
        Resources resources = context.getResources();
        mMinimumDisplayTime = NotificationThrottleHun.isEnabled()
                ? 500 : resources.getInteger(R.integer.heads_up_notification_minimum_time);
@@ -583,6 +584,18 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
        return  mUser;
    }

    private String getEntryMapStr() {
        if (mHeadsUpEntryMap.isEmpty()) {
            return "EMPTY";
        }
        StringBuilder entryMapStr = new StringBuilder();
        for (HeadsUpEntry entry: mHeadsUpEntryMap.values()) {
            entryMapStr.append("\n\t").append(
                    entry.mEntry == null ? "null" : entry.mEntry.getKey());
        }
        return entryMapStr.toString();
    }

    @Override
    public void dump(@NonNull PrintWriter pw, @NonNull String[] args) {
        pw.println("HeadsUpManager state:");
@@ -992,7 +1005,6 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
         * Clear any pending removal runnables.
         */
        public void cancelAutoRemovalCallbacks(@Nullable String reason) {
            mLogger.logAutoRemoveCancelRequest(this.mEntry, reason);
            Runnable runnable = () -> {
                final boolean removed = cancelAutoRemovalCallbackInternal();

@@ -1001,6 +1013,7 @@ public abstract class BaseHeadsUpManager implements HeadsUpManager {
                }
            };
            if (mEntry != null && isHeadsUpEntry(mEntry.getKey())) {
                mLogger.logAutoRemoveCancelRequest(this.mEntry, reason);
                mAvalancheController.update(this, runnable, reason + " cancelAutoRemovalCallbacks");
            } else {
                // Just removed