From 076abc38ce9c91d9a93d937bebcceb4cfff2f354 Mon Sep 17 00:00:00 2001 From: Lyn Han Date: Wed, 7 Sep 2022 15:05:12 -0700 Subject: [PATCH] Fix missing notifs after swipe Sometimes, when you swipe away a notification in the shade and that notification has a bubble, the shade does not update to fill the blank space. How this happened: - ShadeListBuilder depends on BubbleCoordinator's NotifFilter to tell it which notifications to filter out - BubbleCoordinator checks BubbleController's CachedState to see which notifications to suppress - BubbleController's CachedState #updateBubbleSuppressedState (and #onBubbleMetadataFlagChanged upstream) did not run because - In Bubble #setSuppressNotification mBubbleMetadataFlagListener is null, since it was never set by the Bubble constructor when loading bubbles from disk (unlike the Bubble constructor used for new bubbles) This change - sets BubbleMetadataFlagListener on bubbles loaded from disk so that their CachedStates update after their notifications are swiped away from the shade. - removes @Nullable annotation from BubbleMetadataFlagListener param and var declarations - adds dumpsys log so we can check it doesn't happen again. Fixes: 237897866 Test: have some BubbleChat bubbles, reboot phone => send messages from same chats to bring back same bubbles => swipe away shade notifications for these chats => see that notifs below move up to fill blank space Change-Id: Id61814fdc5fee87197f5ca48ae0bc469b713fab5 --- .../src/com/android/wm/shell/bubbles/Bubble.java | 7 +++++-- .../android/wm/shell/bubbles/BubbleController.java | 1 + .../src/com/android/wm/shell/bubbles/BubbleData.java | 1 - .../android/wm/shell/bubbles/BubbleDataRepository.kt | 11 ++++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java index 99b8885acdef9..b5a575499a3a4 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java @@ -170,7 +170,8 @@ public class Bubble implements BubbleViewProvider { @VisibleForTesting(visibility = PRIVATE) public Bubble(@NonNull final String key, @NonNull final ShortcutInfo shortcutInfo, final int desiredHeight, final int desiredHeightResId, @Nullable final String title, - int taskId, @Nullable final String locus, Executor mainExecutor) { + int taskId, @Nullable final String locus, Executor mainExecutor, + final Bubbles.BubbleMetadataFlagListener listener) { Objects.requireNonNull(key); Objects.requireNonNull(shortcutInfo); mMetadataShortcutId = shortcutInfo.getId(); @@ -188,11 +189,12 @@ public class Bubble implements BubbleViewProvider { mShowBubbleUpdateDot = false; mMainExecutor = mainExecutor; mTaskId = taskId; + mBubbleMetadataFlagListener = listener; } @VisibleForTesting(visibility = PRIVATE) public Bubble(@NonNull final BubbleEntry entry, - @Nullable final Bubbles.BubbleMetadataFlagListener listener, + final Bubbles.BubbleMetadataFlagListener listener, final Bubbles.PendingIntentCanceledListener intentCancelListener, Executor mainExecutor) { mKey = entry.getKey(); @@ -830,6 +832,7 @@ public class Bubble implements BubbleViewProvider { pw.print(" desiredHeight: "); pw.println(getDesiredHeightString()); pw.print(" suppressNotif: "); pw.println(shouldSuppressNotification()); pw.print(" autoExpand: "); pw.println(shouldAutoExpand()); + pw.print(" bubbleMetadataFlagListener null: " + (mBubbleMetadataFlagListener == null)); if (mExpandedView != null) { mExpandedView.dump(pw); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java index d63c25d074855..0e8dd4dd4eac8 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java @@ -309,6 +309,7 @@ public class BubbleController implements ConfigurationChangeListener { protected void onInit() { mBubbleData.setListener(mBubbleDataListener); mBubbleData.setSuppressionChangedListener(this::onBubbleMetadataFlagChanged); + mDataRepository.setSuppressionChangedListener(this::onBubbleMetadataFlagChanged); mBubbleData.setPendingIntentCancelledListener(bubble -> { if (bubble.getBubbleIntent() == null) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java index c64133f0b6688..af31391fec965 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleData.java @@ -158,7 +158,6 @@ public class BubbleData { @Nullable private Listener mListener; - @Nullable private Bubbles.BubbleMetadataFlagListener mBubbleMetadataFlagListener; private Bubbles.PendingIntentCanceledListener mCancelledListener; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt index 97560f44fb06f..3a5961462c87c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt @@ -25,6 +25,7 @@ import android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LA import android.content.pm.UserInfo import android.os.UserHandle import android.util.Log +import com.android.wm.shell.bubbles.Bubbles.BubbleMetadataFlagListener import com.android.wm.shell.bubbles.storage.BubbleEntity import com.android.wm.shell.bubbles.storage.BubblePersistentRepository import com.android.wm.shell.bubbles.storage.BubbleVolatileRepository @@ -47,6 +48,13 @@ internal class BubbleDataRepository( private val ioScope = CoroutineScope(Dispatchers.IO) private var job: Job? = null + // For use in Bubble construction. + private lateinit var bubbleMetadataFlagListener: BubbleMetadataFlagListener + + fun setSuppressionChangedListener(listener: BubbleMetadataFlagListener) { + bubbleMetadataFlagListener = listener + } + /** * Adds the bubble in memory, then persists the snapshot after adding the bubble to disk * asynchronously. @@ -197,7 +205,8 @@ internal class BubbleDataRepository( entity.title, entity.taskId, entity.locus, - mainExecutor + mainExecutor, + bubbleMetadataFlagListener ) } }