From 91ca98485733d8490fd62170d673a18ffb6e1b44 Mon Sep 17 00:00:00 2001 From: Caitlin Cassidy Date: Mon, 19 Jul 2021 17:34:16 +0000 Subject: [PATCH] [Dagger] Move StatusBarIconController and FeatureFlags from KeyguardStatusBarView to its controller. Test: atest and manual Bug: 138786270 Change-Id: I5fe29ab36650268fe627f5e0c64aebc261ce090a --- .../phone/KeyguardStatusBarView.java | 43 +++---------------- .../KeyguardStatusBarViewController.java | 38 +++++++++++++++- .../NotificationPanelViewController.java | 4 ++ .../phone/StatusBarIconController.java | 17 ++++++++ .../phone/StatusBarIconControllerImpl.java | 8 ++++ .../android/systemui/util/ViewController.java | 10 +++++ .../KeyguardStatusBarViewControllerTest.java | 24 ++++++++++- 7 files changed, 103 insertions(+), 41 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java index 72a3a124b4832..222ed631fd652 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java @@ -43,17 +43,12 @@ import android.widget.TextView; import com.android.settingslib.Utils; import com.android.systemui.BatteryMeterView; -import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.animation.Interpolators; import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; -import com.android.systemui.statusbar.FeatureFlags; -import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; import java.io.FileDescriptor; import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; /** * The header group on Keyguard. @@ -80,15 +75,11 @@ public class KeyguardStatusBarView extends RelativeLayout { private int mSystemIconsSwitcherHiddenExpandedMargin; private int mSystemIconsBaseMargin; private View mSystemIconsContainer; - private TintedIconManager mIconManager; - private List mBlockedIcons = new ArrayList<>(); private View mCutoutSpace; private ViewGroup mStatusIconArea; private int mLayoutState = LAYOUT_NONE; - private FeatureFlags mFeatureFlags; - /** * Draw this many pixels into the left/right side of the cutout to optimally use the space */ @@ -122,8 +113,6 @@ public class KeyguardStatusBarView extends RelativeLayout { mStatusIconContainer = findViewById(R.id.statusIcons); loadDimens(); - loadBlockList(); - mFeatureFlags = Dependency.get(FeatureFlags.class); } @Override @@ -183,14 +172,6 @@ public class KeyguardStatusBarView extends RelativeLayout { R.dimen.rounded_corner_content_padding); } - // Set hidden status bar items - private void loadBlockList() { - Resources r = getResources(); - mBlockedIcons.add(r.getString(com.android.internal.R.string.status_bar_volume)); - mBlockedIcons.add(r.getString(com.android.internal.R.string.status_bar_alarm_clock)); - mBlockedIcons.add(r.getString(com.android.internal.R.string.status_bar_call_strength)); - } - private void updateVisibilities() { if (mMultiUserAvatar.getParent() != mStatusIconArea && !mKeyguardUserSwitcherEnabled) { @@ -327,20 +308,6 @@ public class KeyguardStatusBarView extends RelativeLayout { return true; } - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - mIconManager = new TintedIconManager(findViewById(R.id.statusIcons), mFeatureFlags); - mIconManager.setBlockList(mBlockedIcons); - Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager); - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager); - } - /** Should only be called from {@link KeyguardStatusBarViewController}. */ void onUserInfoChanged(Drawable picture) { mMultiUserAvatar.setImageDrawable(picture); @@ -421,9 +388,9 @@ public class KeyguardStatusBarView extends RelativeLayout { } /** Should only be called from {@link KeyguardStatusBarViewController}. */ - void onThemeChanged() { + void onThemeChanged(StatusBarIconController.TintedIconManager iconManager) { mBatteryView.setColorsFromContext(mContext); - updateIconsAndTextColors(); + updateIconsAndTextColors(iconManager); } /** Should only be called from {@link KeyguardStatusBarViewController}. */ @@ -433,7 +400,7 @@ public class KeyguardStatusBarView extends RelativeLayout { mBatteryView.updatePercentView(); } - private void updateIconsAndTextColors() { + private void updateIconsAndTextColors(StatusBarIconController.TintedIconManager iconManager) { @ColorInt int textColor = Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColor); @ColorInt int iconColor = Utils.getColorStateListDefaultColor(mContext, @@ -441,8 +408,8 @@ public class KeyguardStatusBarView extends RelativeLayout { R.color.light_mode_icon_color_single_tone); float intensity = textColor == Color.WHITE ? 0 : 1; mCarrierLabel.setTextColor(iconColor); - if (mIconManager != null) { - mIconManager.setTint(iconColor); + if (iconManager != null) { + iconManager.setTint(iconColor); } applyDarkness(R.id.battery, mEmptyRect, intensity, iconColor); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java index 4d17cbce13a64..5d8d36e5caf6c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewController.java @@ -20,10 +20,12 @@ import static com.android.systemui.statusbar.events.SystemStatusAnimationSchedul import static com.android.systemui.statusbar.events.SystemStatusAnimationSchedulerKt.ANIMATING_OUT; import android.animation.ValueAnimator; +import android.content.res.Resources; import androidx.annotation.NonNull; import com.android.keyguard.CarrierTextController; +import com.android.systemui.R; import com.android.systemui.statusbar.events.SystemStatusAnimationCallback; import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler; import com.android.systemui.statusbar.policy.BatteryController; @@ -33,6 +35,9 @@ import com.android.systemui.util.ViewController; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import javax.inject.Inject; @@ -43,6 +48,8 @@ public class KeyguardStatusBarViewController extends ViewController mView.onUserInfoChanged(picture); + private final List mBlockedIcons; + private boolean mBatteryListening; + private StatusBarIconController.TintedIconManager mTintedIconManager; @Inject public KeyguardStatusBarViewController( @@ -103,13 +113,23 @@ public class KeyguardStatusBarViewController extends ViewController allSlots = getSlots(); for (int i = 0; i < allSlots.size(); i++) { diff --git a/packages/SystemUI/src/com/android/systemui/util/ViewController.java b/packages/SystemUI/src/com/android/systemui/util/ViewController.java index 0dd5788105b71..32bbe1c44c5c5 100644 --- a/packages/SystemUI/src/com/android/systemui/util/ViewController.java +++ b/packages/SystemUI/src/com/android/systemui/util/ViewController.java @@ -109,6 +109,16 @@ public abstract class ViewController { } } + /** + * Destroys this controller so that it never receives view attach and detach events again. + * Does nothing if the view is null. + */ + public void destroy() { + if (mView != null) { + mView.removeOnAttachStateChangeListener(mOnAttachStateListener); + } + } + /** * Called when the view is attached and a call to {@link #init()} has been made in either order. */ diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java index c792a4d800945..217a77d9ffdfe 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java @@ -19,11 +19,16 @@ package com.android.systemui.statusbar.phone; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.view.ViewGroup; import androidx.test.filters.SmallTest; import com.android.keyguard.CarrierTextController; +import com.android.systemui.R; import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.ConfigurationController; @@ -39,6 +44,8 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase { @Mock private KeyguardStatusBarView mKeyguardStatusBarView; @Mock + private ViewGroup mViewGroup; + @Mock private CarrierTextController mCarrierTextController; @Mock private ConfigurationController mConfigurationController; @@ -48,6 +55,10 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase { private BatteryController mBatteryController; @Mock private UserInfoController mUserInfoController; + @Mock + private StatusBarIconController mStatusBarIconController; + @Mock + private FeatureFlags mFeatureFlags; private KeyguardStatusBarViewController mController; @@ -55,13 +66,19 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase { public void setup() throws Exception { MockitoAnnotations.initMocks(this); + when(mKeyguardStatusBarView.getResources()).thenReturn(mContext.getResources()); + when(mKeyguardStatusBarView.findViewById(R.id.statusIcons)).thenReturn(mViewGroup); + when(mViewGroup.getContext()).thenReturn(mContext); + mController = new KeyguardStatusBarViewController( mKeyguardStatusBarView, mCarrierTextController, mConfigurationController, mAnimationScheduler, mBatteryController, - mUserInfoController + mUserInfoController, + mStatusBarIconController, + new StatusBarIconController.TintedIconManager.Factory(mFeatureFlags) ); } @@ -72,15 +89,20 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase { verify(mConfigurationController).addCallback(any()); verify(mAnimationScheduler).addCallback(any()); verify(mUserInfoController).addCallback(any()); + verify(mStatusBarIconController).addIconGroup(any()); } @Test public void onViewDetached_callbacksUnregistered() { + // Set everything up first. + mController.onViewAttached(); + mController.onViewDetached(); verify(mConfigurationController).removeCallback(any()); verify(mAnimationScheduler).removeCallback(any()); verify(mUserInfoController).removeCallback(any()); + verify(mStatusBarIconController).removeIconGroup(any()); } @Test