From b1c3b17ea4bb8a351d7f04fb48f2b7be62191edf Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Fri, 19 Nov 2021 12:57:13 -0800 Subject: [PATCH] Address communal callbacks in NotificationPanelViewController. This change ensures communal callbacks in NotificationPanelViewController happen on the proper thread. Test: atest NotificationPanelViewControllerTest Bug: 206500528 Change-Id: I82bb443cdd1945d02c6fd0ecbbc7fc9f9857f783 --- .../NotificationPanelViewController.java | 25 ++++++++----------- .../NotificationPanelViewControllerTest.java | 4 ++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index a9753acc2de0e..16aac4d765a79 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -506,23 +506,11 @@ public class NotificationPanelViewController extends PanelViewController { mPanelAlphaAnimator.getProperty(), Interpolators.ALPHA_IN); private final NotificationEntryManager mEntryManager; - private final CommunalSourceMonitor.Callback mCommunalSourceMonitorCallback = - new CommunalSourceMonitor.Callback() { - @Override - public void onSourceAvailable(WeakReference source) { - setCommunalSource(source); - } - }; + private final CommunalSourceMonitor.Callback mCommunalSourceMonitorCallback; private WeakReference mCommunalSource; - private final CommunalSource.Callback mCommunalSourceCallback = - new CommunalSource.Callback() { - @Override - public void onDisconnected() { - setCommunalSource(null /*source*/); - } - }; + private final CommunalSource.Callback mCommunalSourceCallback; private final CommandQueue mCommandQueue; private final NotificationLockscreenUserManager mLockscreenUserManager; @@ -904,6 +892,15 @@ public class NotificationPanelViewController extends PanelViewController { mMaxKeyguardNotifications = resources.getInteger(R.integer.keyguard_max_notification_count); mKeyguardUnfoldTransition = unfoldComponent.map(c -> c.getKeyguardUnfoldTransition()); + + mCommunalSourceCallback = () -> { + mUiExecutor.execute(() -> setCommunalSource(null /*source*/)); + }; + + mCommunalSourceMonitorCallback = (source) -> { + mUiExecutor.execute(() -> setCommunalSource(source)); + }; + updateUserSwitcherFlags(); onFinishInflate(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java index 81ddc670745bd..270c64ddfa7a0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java @@ -358,6 +358,7 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { private NotificationsQuickSettingsContainer mNotificationContainerParent; private List mOnAttachStateChangeListeners; private FalsingManagerFake mFalsingManager = new FalsingManagerFake(); + private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock()); @Before public void setup() { @@ -511,7 +512,7 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { mQuickAccessWalletController, mQrCodeScannerController, mRecordingController, - new FakeExecutor(new FakeSystemClock()), + mExecutor, mSecureSettings, mSplitShadeHeaderController, mUnlockedScreenOffAnimationController, @@ -936,6 +937,7 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { ArgumentCaptor.forClass(WeakReference.class); monitorCallback.getValue().onSourceAvailable(new WeakReference<>(mCommunalSource)); + mExecutor.runAllReady(); verify(mCommunalHostViewController).show(sourceCapture.capture()); assertThat(sourceCapture.getValue().get()).isEqualTo(mCommunalSource);