From 35264cb754c32dfd3b24a5c1a1113b125f2b30e2 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 9 Apr 2021 13:42:09 -0700 Subject: [PATCH] Fix issue with callback not being made on the sysui main thread Bug: 182705044 Test: atest SystemUITests Change-Id: I83457f75a35e22f6e06c94e18b807ab88f59dd09 --- .../wm/shell/bubbles/BubbleController.java | 22 ++++++++++--------- .../com/android/wm/shell/bubbles/Bubbles.java | 2 +- .../systemui/wmshell/BubblesManager.java | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) 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 d31e637b778ee..44d31c5152cf9 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 @@ -701,14 +701,11 @@ public class BubbleController { return (isSummary && isSuppressedSummary) || isSuppressedBubble; } - private void removeSuppressedSummaryIfNecessary(String groupKey, Consumer callback, - Executor callbackExecutor) { + private void removeSuppressedSummaryIfNecessary(String groupKey, Consumer callback) { if (mBubbleData.isSummarySuppressed(groupKey)) { mBubbleData.removeSuppressedSummary(groupKey); if (callback != null) { - callbackExecutor.execute(() -> { - callback.accept(mBubbleData.getSummaryKey(groupKey)); - }); + callback.accept(mBubbleData.getSummaryKey(groupKey)); } } } @@ -1252,8 +1249,10 @@ public class BubbleController { public void removeSuppressedSummaryIfNecessary(String groupKey, Consumer callback, Executor callbackExecutor) { mMainExecutor.execute(() -> { - BubbleController.this.removeSuppressedSummaryIfNecessary(groupKey, callback, - callbackExecutor); + Consumer cb = callback != null + ? (key) -> callbackExecutor.execute(() -> callback.accept(key)) + : null; + BubbleController.this.removeSuppressedSummaryIfNecessary(groupKey, cb); }); } @@ -1294,10 +1293,13 @@ public class BubbleController { @Override public boolean handleDismissalInterception(BubbleEntry entry, - @Nullable List children, IntConsumer removeCallback) { + @Nullable List children, IntConsumer removeCallback, + Executor callbackExecutor) { + IntConsumer cb = removeCallback != null + ? (index) -> callbackExecutor.execute(() -> removeCallback.accept(index)) + : null; return mMainExecutor.executeBlockingForResult(() -> { - return BubbleController.this.handleDismissalInterception(entry, children, - removeCallback); + return BubbleController.this.handleDismissalInterception(entry, children, cb); }, Boolean.class); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubbles.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubbles.java index 8e061e9c98741..9a01f14ca0a3e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubbles.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubbles.java @@ -140,7 +140,7 @@ public interface Bubbles { * @return true if we want to intercept the dismissal of the entry, else false. */ boolean handleDismissalInterception(BubbleEntry entry, @Nullable List children, - IntConsumer removeCallback); + IntConsumer removeCallback, Executor callbackExecutor); /** Set the proxy to commnuicate with SysUi side components. */ void setSysuiProxy(SysuiProxy proxy); diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java b/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java index afeda967c8c15..84688a7221ae8 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/BubblesManager.java @@ -630,7 +630,7 @@ public class BubblesManager implements Dumpable { } else { mNotificationGroupManager.onEntryRemoved(entry); } - }); + }, mSysuiMainExecutor); } /**