Merge "[Dagger] Move StatusBarIconController and FeatureFlags from KeyguardStatusBarView to its controller." into sc-v2-dev

This commit is contained in:
Caitlin Cassidy
2021-07-26 14:49:26 +00:00
committed by Android (Google) Code Review
7 changed files with 103 additions and 41 deletions

View File

@@ -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<String> 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);

View File

@@ -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<KeyguardStat
private final SystemStatusAnimationScheduler mAnimationScheduler;
private final BatteryController mBatteryController;
private final UserInfoController mUserInfoController;
private final StatusBarIconController mStatusBarIconController;
private final StatusBarIconController.TintedIconManager.Factory mTintedIconManagerFactory;
private final ConfigurationController.ConfigurationListener mConfigurationListener =
new ConfigurationController.ConfigurationListener() {
@@ -94,7 +101,10 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
private final UserInfoController.OnUserInfoChangedListener mOnUserInfoChangedListener =
(name, picture, userAccount) -> mView.onUserInfoChanged(picture);
private final List<String> mBlockedIcons;
private boolean mBatteryListening;
private StatusBarIconController.TintedIconManager mTintedIconManager;
@Inject
public KeyguardStatusBarViewController(
@@ -103,13 +113,23 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
ConfigurationController configurationController,
SystemStatusAnimationScheduler animationScheduler,
BatteryController batteryController,
UserInfoController userInfoController) {
UserInfoController userInfoController,
StatusBarIconController statusBarIconController,
StatusBarIconController.TintedIconManager.Factory tintedIconManagerFactory) {
super(view);
mCarrierTextController = carrierTextController;
mConfigurationController = configurationController;
mAnimationScheduler = animationScheduler;
mBatteryController = batteryController;
mUserInfoController = userInfoController;
mStatusBarIconController = statusBarIconController;
mTintedIconManagerFactory = tintedIconManagerFactory;
Resources r = getResources();
mBlockedIcons = Collections.unmodifiableList(Arrays.asList(
r.getString(com.android.internal.R.string.status_bar_volume),
r.getString(com.android.internal.R.string.status_bar_alarm_clock),
r.getString(com.android.internal.R.string.status_bar_call_strength)));
}
@Override
@@ -123,19 +143,33 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
mConfigurationController.addCallback(mConfigurationListener);
mAnimationScheduler.addCallback(mAnimationCallback);
mUserInfoController.addCallback(mOnUserInfoChangedListener);
if (mTintedIconManager == null) {
mTintedIconManager =
mTintedIconManagerFactory.create(mView.findViewById(R.id.statusIcons));
mTintedIconManager.setBlockList(mBlockedIcons);
mStatusBarIconController.addIconGroup(mTintedIconManager);
}
onThemeChanged();
}
@Override
protected void onViewDetached() {
// Don't receive future #onViewAttached calls so that we don't accidentally have two
// controllers registered for the same view.
// TODO(b/194181195): This shouldn't be necessary.
destroy();
mConfigurationController.removeCallback(mConfigurationListener);
mAnimationScheduler.removeCallback(mAnimationCallback);
mUserInfoController.removeCallback(mOnUserInfoChangedListener);
if (mTintedIconManager != null) {
mStatusBarIconController.removeIconGroup(mTintedIconManager);
}
}
/** Should be called when the theme changes. */
public void onThemeChanged() {
mView.onThemeChanged();
mView.onThemeChanged(mTintedIconManager);
}
/** Sets whether this controller should listen to battery updates. */

View File

@@ -971,6 +971,10 @@ public class NotificationPanelViewController extends PanelViewController {
KeyguardStatusBarViewComponent statusBarViewComponent =
mKeyguardStatusBarViewComponentFactory.build(keyguardStatusBarView);
if (mKeyguardStatusBarViewController != null) {
// TODO(b/194181195): This shouldn't be necessary.
mKeyguardStatusBarViewController.onViewDetached();
}
mKeyguardStatusBarViewController =
statusBarViewComponent.getKeyguardStatusBarViewController();
mKeyguardStatusBarViewController.init();

View File

@@ -35,6 +35,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.demomode.DemoModeCommandReceiver;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
@@ -50,6 +51,8 @@ import com.android.systemui.statusbar.phone.StatusBarSignalPolicy.WifiIconState;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
public interface StatusBarIconController {
/**
@@ -213,6 +216,20 @@ public interface StatusBarIconController {
icons.setColor(mColor);
return icons;
}
@SysUISingleton
public static class Factory {
private final FeatureFlags mFeatureFlags;
@Inject
public Factory(FeatureFlags featureFlags) {
mFeatureFlags = featureFlags;
}
public TintedIconManager create(ViewGroup group) {
return new TintedIconManager(group, mFeatureFlags);
}
}
}
/**

View File

@@ -23,6 +23,7 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.view.ViewGroup;
import com.android.internal.statusbar.StatusBarIcon;
@@ -88,6 +89,13 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
/** */
@Override
public void addIconGroup(IconManager group) {
for (IconManager existingIconManager : mIconGroups) {
if (existingIconManager.mGroup == group.mGroup) {
Log.e(TAG, "Adding new IconManager for the same ViewGroup. This could cause "
+ "unexpected results.");
}
}
mIconGroups.add(group);
List<Slot> allSlots = getSlots();
for (int i = 0; i < allSlots.size(); i++) {

View File

@@ -109,6 +109,16 @@ public abstract class ViewController<T extends View> {
}
}
/**
* 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.
*/

View File

@@ -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