From 98897a585683485eed82527e20d979c6da34222b Mon Sep 17 00:00:00 2001 From: Caitlin Cassidy Date: Fri, 13 Aug 2021 15:37:53 +0000 Subject: [PATCH] [Dagger] Remove the simple Dependency.get calls from StatusBarNotificationPresenter. Test: atest and manual Bug: 138786270 Change-Id: I2230a314802a52489491eacb94908310de517aaa --- .../systemui/statusbar/phone/StatusBar.java | 32 +++++++++++--- .../phone/StatusBarNotificationPresenter.java | 44 ++++++++++--------- .../StatusBarNotificationPresenterTest.java | 25 ++++++----- 3 files changed, 62 insertions(+), 39 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index cbc852b47076b..9c2b2793c4673 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -1511,14 +1511,32 @@ public class StatusBar extends SystemUI implements ); // TODO: inject this. - mPresenter = new StatusBarNotificationPresenter(mContext, mNotificationPanelViewController, - mHeadsUpManager, mNotificationShadeWindowView, mStackScrollerController, - mDozeScrimController, mScrimController, mNotificationShadeWindowController, - mDynamicPrivacyController, mKeyguardStateController, + mPresenter = new StatusBarNotificationPresenter( + mContext, + mNotificationPanelViewController, + mHeadsUpManager, + mNotificationShadeWindowView, + mStackScrollerController, + mDozeScrimController, + mScrimController, + mNotificationShadeWindowController, + mDynamicPrivacyController, + mKeyguardStateController, mKeyguardIndicationController, - this /* statusBar */, mShadeController, - mLockscreenShadeTransitionController, mCommandQueue, mInitController, - mNotificationInterruptStateProvider); + this /* statusBar */, + mShadeController, + mLockscreenShadeTransitionController, + mCommandQueue, + mViewHierarchyManager, + mLockscreenUserManager, + mStatusBarStateController, + mMediaManager, + mGutsManager, + mKeyguardUpdateMonitor, + mInitController, + mNotificationInterruptStateProvider, + mRemoteInputManager, + mConfigurationController); mNotificationShelfController.setOnActivatedListener(mPresenter); mRemoteInputManager.addControllerCallback(mNotificationShadeWindowController); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java index cb844d8c5ac93..608697df79058 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java @@ -47,7 +47,6 @@ import com.android.systemui.InitController; import com.android.systemui.R; import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.ActivityStarter.OnDismissAction; -import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.KeyguardIndicationController; import com.android.systemui.statusbar.LockscreenShadeTransitionController; @@ -65,7 +64,6 @@ import com.android.systemui.statusbar.notification.NotificationEntryListener; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl; -import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager; import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider; import com.android.systemui.statusbar.notification.interruption.NotificationInterruptSuppressor; import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; @@ -92,20 +90,14 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, private final ActivityStarter mActivityStarter = Dependency.get(ActivityStarter.class); private final KeyguardStateController mKeyguardStateController; - private final NotificationViewHierarchyManager mViewHierarchyManager = - Dependency.get(NotificationViewHierarchyManager.class); - private final NotificationLockscreenUserManager mLockscreenUserManager = - Dependency.get(NotificationLockscreenUserManager.class); - private final SysuiStatusBarStateController mStatusBarStateController = - (SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class); + private final NotificationViewHierarchyManager mViewHierarchyManager; + private final NotificationLockscreenUserManager mLockscreenUserManager; + private final SysuiStatusBarStateController mStatusBarStateController; private final NotificationEntryManager mEntryManager = Dependency.get(NotificationEntryManager.class); - private final NotificationMediaManager mMediaManager = - Dependency.get(NotificationMediaManager.class); - private final VisualStabilityManager mVisualStabilityManager = - Dependency.get(VisualStabilityManager.class); - private final NotificationGutsManager mGutsManager = - Dependency.get(NotificationGutsManager.class); + private final NotificationMediaManager mMediaManager; + private final NotificationGutsManager mGutsManager; + private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; private final NotificationPanelViewController mNotificationPanel; private final HeadsUpManagerPhone mHeadsUpManager; @@ -144,8 +136,16 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, ShadeController shadeController, LockscreenShadeTransitionController shadeTransitionController, CommandQueue commandQueue, + NotificationViewHierarchyManager notificationViewHierarchyManager, + NotificationLockscreenUserManager lockscreenUserManager, + SysuiStatusBarStateController sysuiStatusBarStateController, + NotificationMediaManager notificationMediaManager, + NotificationGutsManager notificationGutsManager, + KeyguardUpdateMonitor keyguardUpdateMonitor, InitController initController, - NotificationInterruptStateProvider notificationInterruptStateProvider) { + NotificationInterruptStateProvider notificationInterruptStateProvider, + NotificationRemoteInputManager remoteInputManager, + ConfigurationController configurationController) { mKeyguardStateController = keyguardStateController; mNotificationPanel = panel; mHeadsUpManager = headsUp; @@ -156,6 +156,12 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, mShadeController = shadeController; mShadeTransitionController = shadeTransitionController; mCommandQueue = commandQueue; + mViewHierarchyManager = notificationViewHierarchyManager; + mLockscreenUserManager = lockscreenUserManager; + mStatusBarStateController = sysuiStatusBarStateController; + mMediaManager = notificationMediaManager; + mGutsManager = notificationGutsManager; + mKeyguardUpdateMonitor = keyguardUpdateMonitor; mAboveShelfObserver = new AboveShelfObserver(stackScrollerController.getView()); mNotificationShadeWindowController = notificationShadeWindowController; mAboveShelfObserver.setListener(statusBarWindow.findViewById( @@ -176,8 +182,6 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, Slog.e(TAG, "Failed to register VR mode state listener: " + e); } } - NotificationRemoteInputManager remoteInputManager = - Dependency.get(NotificationRemoteInputManager.class); remoteInputManager.setUpWithCallback( Dependency.get(NotificationRemoteInputManager.Callback.class), mNotificationPanel.createRemoteInputDelegate()); @@ -220,14 +224,14 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, onUserSwitched(mLockscreenUserManager.getCurrentUserId()); }); - Dependency.get(ConfigurationController.class).addCallback(this); + configurationController.addCallback(this); } @Override public void onDensityOrFontScaleChanged() { MessagingMessage.dropCache(); MessagingGroup.dropCache(); - if (!Dependency.get(KeyguardUpdateMonitor.class).isSwitchingUser()) { + if (!mKeyguardUpdateMonitor.isSwitchingUser()) { updateNotificationsOnDensityOrFontScaleChanged(); } else { mReinflateNotificationsOnUserSwitched = true; @@ -236,7 +240,7 @@ public class StatusBarNotificationPresenter implements NotificationPresenter, @Override public void onUiModeChanged() { - if (!Dependency.get(KeyguardUpdateMonitor.class).isSwitchingUser()) { + if (!mKeyguardUpdateMonitor.isSwitchingUser()) { updateNotificationOnUiModeChanged(); } else { mDispatchUiModeChangeOnUserSwitched = true; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java index fd85c4485404c..03a353b6c2b47 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java @@ -34,6 +34,7 @@ import androidx.test.filters.SmallTest; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.testing.FakeMetricsLogger; +import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.ForegroundServiceNotificationListener; import com.android.systemui.InitController; import com.android.systemui.SysuiTestCase; @@ -51,7 +52,6 @@ import com.android.systemui.statusbar.notification.DynamicPrivacyController; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; -import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager; import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider; import com.android.systemui.statusbar.notification.interruption.NotificationInterruptSuppressor; import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; @@ -59,6 +59,7 @@ import com.android.systemui.statusbar.notification.row.NotificationGutsManager; import com.android.systemui.statusbar.notification.stack.NotificationListContainer; import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController; +import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardStateController; import org.junit.Before; @@ -86,22 +87,13 @@ public class StatusBarNotificationPresenterTest extends SysuiTestCase { @Before public void setup() { - NotificationRemoteInputManager notificationRemoteInputManager = - mock(NotificationRemoteInputManager.class); mMetricsLogger = new FakeMetricsLogger(); mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); mCommandQueue = new CommandQueue(mContext); mDependency.injectTestDependency(StatusBarStateController.class, mock(SysuiStatusBarStateController.class)); mDependency.injectTestDependency(ShadeController.class, mShadeController); - mDependency.injectTestDependency(NotificationRemoteInputManager.class, - notificationRemoteInputManager); - mDependency.injectMockDependency(NotificationViewHierarchyManager.class); mDependency.injectMockDependency(NotificationRemoteInputManager.Callback.class); - mDependency.injectMockDependency(NotificationLockscreenUserManager.class); - mDependency.injectMockDependency(NotificationMediaManager.class); - mDependency.injectMockDependency(VisualStabilityManager.class); - mDependency.injectMockDependency(NotificationGutsManager.class); mDependency.injectMockDependency(NotificationShadeWindowController.class); mDependency.injectMockDependency(ForegroundServiceNotificationListener.class); NotificationEntryManager entryManager = @@ -126,8 +118,17 @@ public class StatusBarNotificationPresenterTest extends SysuiTestCase { mock(KeyguardStateController.class), mock(KeyguardIndicationController.class), mStatusBar, mock(ShadeControllerImpl.class), mock(LockscreenShadeTransitionController.class), - mCommandQueue, mInitController, - mNotificationInterruptStateProvider); + mCommandQueue, + mock(NotificationViewHierarchyManager.class), + mock(NotificationLockscreenUserManager.class), + mock(SysuiStatusBarStateController.class), + mock(NotificationMediaManager.class), + mock(NotificationGutsManager.class), + mock(KeyguardUpdateMonitor.class), + mInitController, + mNotificationInterruptStateProvider, + mock(NotificationRemoteInputManager.class), + mock(ConfigurationController.class)); mInitController.executePostInitTasks(); ArgumentCaptor suppressorCaptor = ArgumentCaptor.forClass(NotificationInterruptSuppressor.class);