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

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

Merge "Revert "Fix HUNs re-showing after shade closes"" into main

parents 2d6f7667 a7d2f86a
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -13,18 +13,12 @@ class VisualStabilityProvider @Inject constructor() {
    /** The subset of active listeners which are temporary (will be removed after called) */
    private val temporaryListeners = ArraySet<OnReorderingAllowedListener>()

    private val banListeners = ListenerSet<OnReorderingBannedListener>()

    var isReorderingAllowed = true
        set(value) {
            if (field != value) {
                field = value
                if (value) {
                    notifyReorderingAllowed()
                } else {
                    banListeners.forEach { listener ->
                        listener.onReorderingBanned()
                    }
                }
            }
        }
@@ -44,10 +38,6 @@ class VisualStabilityProvider @Inject constructor() {
        allListeners.addIfAbsent(listener)
    }

    fun addPersistentReorderingBannedListener(listener: OnReorderingBannedListener) {
        banListeners.addIfAbsent(listener)
    }

    /** Add a listener which will be removed when it is called. */
    fun addTemporaryReorderingAllowedListener(listener: OnReorderingAllowedListener) {
        // Only add to the temporary set if it was added to the global set
@@ -67,8 +57,3 @@ class VisualStabilityProvider @Inject constructor() {
fun interface OnReorderingAllowedListener {
    fun onReorderingAllowed()
}

fun interface OnReorderingBannedListener {
    fun onReorderingBanned()
}
+1 −28
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.systemui.shade.domain.interactor.ShadeInteractor;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.provider.OnReorderingAllowedListener;
import com.android.systemui.statusbar.notification.collection.provider.OnReorderingBannedListener;
import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider;
import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
import com.android.systemui.statusbar.notification.data.repository.HeadsUpRepository;
@@ -88,7 +87,7 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
    private final List<OnHeadsUpPhoneListenerChange> mHeadsUpPhoneListeners = new ArrayList<>();
    private final VisualStabilityProvider mVisualStabilityProvider;

    private AvalancheController mAvalancheController;
    private final AvalancheController mAvalancheController;

    // TODO(b/328393698) move the topHeadsUpRow logic to an interactor
    private final MutableStateFlow<HeadsUpRowRepository> mTopHeadsUpRow =
@@ -177,7 +176,6 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
            javaAdapter.alwaysCollectFlow(shadeInteractor.isAnyExpanded(),
                    this::onShadeOrQsExpanded);
        }
        mVisualStabilityProvider.addPersistentReorderingBannedListener(mOnReorderingBannedListener);
    }

    public void setAnimationStateHandler(AnimationStateHandler handler) {
@@ -385,8 +383,6 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements

    private final OnReorderingAllowedListener mOnReorderingAllowedListener = () -> {
        mAnimationStateHandler.setHeadsUpGoingAwayAnimationsAllowed(false);
        mAvalancheController.setEnableAtRuntime(true);

        for (NotificationEntry entry : mEntriesToRemoveWhenReorderingAllowed) {
            if (isHeadsUpEntry(entry.getKey())) {
                // Maybe the heads-up was removed already
@@ -397,29 +393,6 @@ public class HeadsUpManagerPhone extends BaseHeadsUpManager implements
        mAnimationStateHandler.setHeadsUpGoingAwayAnimationsAllowed(true);
    };

    private final OnReorderingBannedListener mOnReorderingBannedListener = () -> {
        if (mAvalancheController != null) {
            // Waiting HUNs in AvalancheController are still promoted to the HUN section and thus
            // seen in open shade; clear them so we don't show them again when the shade closes and
            // reordering is allowed again.
            final int numDropped = mAvalancheController.getWaitingKeys().size();
            mAvalancheController.logDroppedHunsInBackground(numDropped);
            mAvalancheController.clearNext();

            // In open shade the first HUN is pinned, and visual stability logic prevents us from
            // unpinning this first HUN as long as the shade remains open. AvalancheController only
            // shows the next HUN when the currently showing HUN is unpinned, so we must disable
            // throttling here so that the incoming HUN stream is not forever paused. This is reset
            // when reorder becomes allowed.
            mAvalancheController.setEnableAtRuntime(false);

            // Note that we cannot do the above when
            // 1) the remove runnable runs because its delay means it may not run before shade close
            // 2) reordering is allowed again (when shade closes) because the HUN appear animation
            // will have started by then
        }
    };

    ///////////////////////////////////////////////////////////////////////////////////////////////
    //  HeadsUpManager utility (protected) methods overrides:

+7 −12
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ constructor(dumpManager: DumpManager,

    private val tag = "AvalancheController"
    private val debug = Compile.IS_DEBUG && Log.isLoggable(tag, Log.DEBUG)
    var enableAtRuntime = true

    // HUN showing right now, in the floating state where full shade is hidden, on launcher or AOD
    @VisibleForTesting var headsUpEntryShowing: HeadsUpEntry? = null
@@ -87,17 +86,13 @@ constructor(dumpManager: DumpManager,
        dumpManager.registerNormalDumpable(tag, /* module */ this)
    }

    fun isEnabled() : Boolean {
        return NotificationThrottleHun.isEnabled && enableAtRuntime
    }

    fun getShowingHunKey(): String {
        return getKey(headsUpEntryShowing)
    }

    /** Run or delay Runnable for given HeadsUpEntry */
    fun update(entry: HeadsUpEntry?, runnable: Runnable, label: String) {
        if (!isEnabled()) {
        if (!NotificationThrottleHun.isEnabled) {
            runnable.run()
            return
        }
@@ -153,7 +148,7 @@ constructor(dumpManager: DumpManager,
     * all Runnables associated with that entry.
     */
    fun delete(entry: HeadsUpEntry?, runnable: Runnable, label: String) {
        if (!isEnabled()) {
        if (!NotificationThrottleHun.isEnabled) {
            runnable.run()
            return
        }
@@ -194,7 +189,7 @@ constructor(dumpManager: DumpManager,
     *    BaseHeadsUpManager.HeadsUpEntry.calculateFinishTime to shorten display duration.
     */
    fun getDurationMs(entry: HeadsUpEntry, autoDismissMs: Int): Int {
        if (!isEnabled()) {
        if (!NotificationThrottleHun.isEnabled) {
            // Use default duration, like we did before AvalancheController existed
            return autoDismissMs
        }
@@ -243,7 +238,7 @@ constructor(dumpManager: DumpManager,

    /** Return true if entry is waiting to show. */
    fun isWaiting(key: String): Boolean {
        if (!isEnabled()) {
        if (!NotificationThrottleHun.isEnabled) {
            return false
        }
        for (entry in nextMap.keys) {
@@ -256,7 +251,7 @@ constructor(dumpManager: DumpManager,

    /** Return list of keys for huns waiting */
    fun getWaitingKeys(): MutableList<String> {
        if (!isEnabled()) {
        if (!NotificationThrottleHun.isEnabled) {
            return mutableListOf()
        }
        val keyList = mutableListOf<String>()
@@ -267,7 +262,7 @@ constructor(dumpManager: DumpManager,
    }

    fun getWaitingEntry(key: String): HeadsUpEntry? {
        if (!isEnabled()) {
        if (!NotificationThrottleHun.isEnabled) {
            return null
        }
        for (headsUpEntry in nextMap.keys) {
@@ -279,7 +274,7 @@ constructor(dumpManager: DumpManager,
    }

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