From 5012c172154d501126ada4b20edec266fd13bb40 Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Wed, 20 Oct 2021 11:12:14 -0400 Subject: [PATCH] Remove injected parametser from NSSL This substitutes in calls to Dependency#get. While this feels like a step backwards, it is the last step necessary before removing acual view injection. Removal of Dependency#get is ongoing and will include cleanup of this class. Bug: 149942757 Test: manual Change-Id: I129f0751f101cdce7ae92554b2a09d2091b7c13b Merged-In: I129f0751f101cdce7ae92554b2a09d2091b7c13b --- .../src/com/android/systemui/Dependency.java | 16 ++++++++++++ .../stack/NotificationStackScrollLayout.java | 22 +++++++--------- .../NotificationStackScrollLayoutTest.java | 25 +++++++++++-------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/Dependency.java b/packages/SystemUI/src/com/android/systemui/Dependency.java index c73d19b5a20d7..4e4034a28cb04 100644 --- a/packages/SystemUI/src/com/android/systemui/Dependency.java +++ b/packages/SystemUI/src/com/android/systemui/Dependency.java @@ -89,8 +89,12 @@ import com.android.systemui.statusbar.notification.NotificationEntryManager.Keyg import com.android.systemui.statusbar.notification.NotificationFilter; import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy; import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager; +import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager; +import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager; import com.android.systemui.statusbar.notification.logging.NotificationLogger; import com.android.systemui.statusbar.notification.row.NotificationGutsManager; +import com.android.systemui.statusbar.notification.stack.AmbientState; +import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager; import com.android.systemui.statusbar.phone.AutoHideController; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.KeyguardDismissUtil; @@ -102,6 +106,7 @@ import com.android.systemui.statusbar.phone.ShadeController; import com.android.systemui.statusbar.phone.StatusBarContentInsetsProvider; import com.android.systemui.statusbar.phone.StatusBarIconController; import com.android.systemui.statusbar.phone.StatusBarWindowController; +import com.android.systemui.statusbar.phone.UnlockedScreenOffAnimationController; import com.android.systemui.statusbar.policy.AccessibilityController; import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; import com.android.systemui.statusbar.policy.BatteryController; @@ -360,6 +365,11 @@ public class Dependency { @Inject Lazy mFeatureFlagsLazy; @Inject Lazy mContentInsetsProviderLazy; @Inject Lazy mInternetDialogFactory; + @Inject Lazy mNotificationSectionsManagerLazy; + @Inject Lazy mUnlockedScreenOffAnimationControllerLazy; + @Inject Lazy mAmbientStateLazy; + @Inject Lazy mGroupMembershipManagerLazy; + @Inject Lazy mGroupExpansionManagerLazy; @Inject public Dependency() { @@ -574,6 +584,12 @@ public class Dependency { mProviders.put(UiEventLogger.class, mUiEventLogger::get); mProviders.put(FeatureFlags.class, mFeatureFlagsLazy::get); mProviders.put(StatusBarContentInsetsProvider.class, mContentInsetsProviderLazy::get); + mProviders.put(NotificationSectionsManager.class, mNotificationSectionsManagerLazy::get); + mProviders.put(UnlockedScreenOffAnimationController.class, + mUnlockedScreenOffAnimationControllerLazy::get); + mProviders.put(AmbientState.class, mAmbientStateLazy::get); + mProviders.put(GroupMembershipManager.class, mGroupMembershipManagerLazy::get); + mProviders.put(GroupExpansionManager.class, mGroupExpansionManagerLazy::get); Dependency.setInstance(this); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java index 3e67f7e09615d..a3d87fbfa7726 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java @@ -74,6 +74,7 @@ import com.android.internal.graphics.ColorUtils; import com.android.internal.jank.InteractionJankMonitor; import com.android.keyguard.KeyguardSliceView; import com.android.settingslib.Utils; +import com.android.systemui.Dependency; import com.android.systemui.Dumpable; import com.android.systemui.ExpandHelper; import com.android.systemui.R; @@ -566,24 +567,19 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable @Nullable private OnClickListener mManageButtonClickListener; + // TODO(b/149942757): Remove the @Inject @Inject - public NotificationStackScrollLayout( - @Named(VIEW_CONTEXT) Context context, - AttributeSet attrs, - NotificationSectionsManager notificationSectionsManager, - GroupMembershipManager groupMembershipManager, - GroupExpansionManager groupExpansionManager, - AmbientState ambientState, - UnlockedScreenOffAnimationController unlockedScreenOffAnimationController) { + public NotificationStackScrollLayout(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs) { super(context, attrs, 0, 0); Resources res = getResources(); - mSectionsManager = notificationSectionsManager; - mUnlockedScreenOffAnimationController = unlockedScreenOffAnimationController; + mSectionsManager = Dependency.get(NotificationSectionsManager.class); + mUnlockedScreenOffAnimationController = + Dependency.get(UnlockedScreenOffAnimationController.class); updateSplitNotificationShade(); mSectionsManager.initialize(this, LayoutInflater.from(context)); mSections = mSectionsManager.createSectionsForBuckets(); - mAmbientState = ambientState; + mAmbientState = Dependency.get(AmbientState.class); mBgColor = Utils.getColorAttr(mContext, android.R.attr.colorBackgroundFloating) .getDefaultColor(); int minHeight = res.getDimensionPixelSize(R.dimen.notification_min_height); @@ -609,8 +605,8 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable mDebugPaint.setTextSize(25f); } mClearAllEnabled = res.getBoolean(R.bool.config_enableNotificationsClearAll); - mGroupMembershipManager = groupMembershipManager; - mGroupExpansionManager = groupExpansionManager; + mGroupMembershipManager = Dependency.get(GroupMembershipManager.class); + mGroupExpansionManager = Dependency.get(GroupExpansionManager.class); setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java index 9f42fa4d2ae7a..185d9cd8733eb 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutTest.java @@ -58,6 +58,8 @@ import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.SysuiStatusBarStateController; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.legacy.NotificationGroupManagerLegacy; +import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager; +import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.notification.row.FooterView; import com.android.systemui.statusbar.phone.KeyguardBypassController; @@ -110,9 +112,20 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { Settings.Secure.putIntForUser(mContext.getContentResolver(), NOTIFICATION_HISTORY_ENABLED, 1, UserHandle.USER_CURRENT); + + // Interact with real instance of AmbientState. + mAmbientState = new AmbientState(mContext, mNotificationSectionsManager, mBypassController); + // Inject dependencies before initializing the layout mDependency.injectTestDependency(SysuiStatusBarStateController.class, mBarState); mDependency.injectMockDependency(ShadeController.class); + mDependency.injectTestDependency( + NotificationSectionsManager.class, mNotificationSectionsManager); + mDependency.injectTestDependency(GroupMembershipManager.class, mGroupMembershipManger); + mDependency.injectTestDependency(GroupExpansionManager.class, mGroupExpansionManager); + mDependency.injectTestDependency(AmbientState.class, mAmbientState); + mDependency.injectTestDependency( + UnlockedScreenOffAnimationController.class, mUnlockedScreenOffAnimationController); NotificationShelfController notificationShelfController = mock(NotificationShelfController.class); @@ -123,22 +136,12 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase { mNotificationSection }); - // Interact with real instance of AmbientState. - mAmbientState = new AmbientState(mContext, mNotificationSectionsManager, mBypassController); - // The actual class under test. You may need to work with this class directly when // testing anonymous class members of mStackScroller, like mMenuEventListener, // which refer to members of NotificationStackScrollLayout. The spy // holds a copy of the CUT's instances of these KeyguardBypassController, so they still // refer to the CUT's member variables, not the spy's member variables. - mStackScrollerInternal = new NotificationStackScrollLayout( - getContext(), - null, - mNotificationSectionsManager, - mGroupMembershipManger, - mGroupExpansionManager, - mAmbientState, - mUnlockedScreenOffAnimationController); + mStackScrollerInternal = new NotificationStackScrollLayout(getContext(), null); mStackScrollerInternal.initView(getContext(), mNotificationSwipeHelper); mStackScroller = spy(mStackScrollerInternal); mStackScroller.setShelfController(notificationShelfController);