[Dagger] Move ConfigurationController out of KeyguardStatusBarView and

into its controller.

Bug: 138786270
Test: atest (+ new unit tests) and manual
Change-Id: Ic2ab911d372e5d2ade25ec4432d363241fa3cdcd
This commit is contained in:
Caitlin Cassidy
2021-07-16 18:15:01 +00:00
parent cc8ebcaf9d
commit 740c6f5bde
4 changed files with 110 additions and 24 deletions

View File

@@ -56,8 +56,6 @@ import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener;
import com.android.systemui.statusbar.policy.UserInfoControllerImpl;
@@ -73,7 +71,6 @@ import java.util.List;
public class KeyguardStatusBarView extends RelativeLayout implements
BatteryStateChangeCallback,
OnUserInfoChangedListener,
ConfigurationListener,
SystemStatusAnimationCallback {
private static final int LAYOUT_NONE = 0;
@@ -190,7 +187,7 @@ public class KeyguardStatusBarView extends RelativeLayout implements
setLayoutParams(lp);
}
private void loadDimens() {
void loadDimens() {
Resources res = getResources();
mSystemIconsSwitcherHiddenExpandedMargin = res.getDimensionPixelSize(
R.dimen.system_icons_switcher_hidden_expanded_margin);
@@ -366,12 +363,10 @@ public class KeyguardStatusBarView extends RelativeLayout implements
UserInfoController userInfoController = Dependency.get(UserInfoController.class);
userInfoController.addCallback(this);
userInfoController.reloadUserInfo();
Dependency.get(ConfigurationController.class).addCallback(this);
mIconManager = new TintedIconManager(findViewById(R.id.statusIcons), mFeatureFlags);
mIconManager.setBlockList(mBlockedIcons);
Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
mAnimationScheduler.addCallback(this);
onThemeChanged();
}
@Override
@@ -379,7 +374,6 @@ public class KeyguardStatusBarView extends RelativeLayout implements
super.onDetachedFromWindow();
Dependency.get(UserInfoController.class).removeCallback(this);
Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
Dependency.get(ConfigurationController.class).removeCallback(this);
mAnimationScheduler.removeCallback(this);
}
@@ -467,7 +461,8 @@ public class KeyguardStatusBarView extends RelativeLayout implements
return false;
}
public void onThemeChanged() {
/** Should only be called from {@link KeyguardStatusBarViewController}. */
void onThemeChanged() {
mBatteryView.setColorsFromContext(mContext);
updateIconsAndTextColors();
// Reload user avatar
@@ -475,16 +470,10 @@ public class KeyguardStatusBarView extends RelativeLayout implements
.onDensityOrFontScaleChanged();
}
@Override
public void onDensityOrFontScaleChanged() {
loadDimens();
}
@Override
public void onOverlayChanged() {
/** Should only be called from {@link KeyguardStatusBarViewController}. */
void onOverlayChanged() {
mCarrierLabel.setTextAppearance(
Utils.getThemeAttr(mContext, com.android.internal.R.attr.textAppearanceSmall));
onThemeChanged();
mBatteryView.updatePercentView();
}

View File

@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.phone;
import com.android.keyguard.CarrierTextController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.util.ViewController;
import javax.inject.Inject;
@@ -24,12 +25,35 @@ import javax.inject.Inject;
/** View Controller for {@link com.android.systemui.statusbar.phone.KeyguardStatusBarView}. */
public class KeyguardStatusBarViewController extends ViewController<KeyguardStatusBarView> {
private final CarrierTextController mCarrierTextController;
private final ConfigurationController mConfigurationController;
private final ConfigurationController.ConfigurationListener mConfigurationListener =
new ConfigurationController.ConfigurationListener() {
@Override
public void onDensityOrFontScaleChanged() {
mView.loadDimens();
}
@Override
public void onOverlayChanged() {
KeyguardStatusBarViewController.this.onThemeChanged();
mView.onOverlayChanged();
}
@Override
public void onThemeChanged() {
KeyguardStatusBarViewController.this.onThemeChanged();
}
};
@Inject
public KeyguardStatusBarViewController(
KeyguardStatusBarView view, CarrierTextController carrierTextController) {
KeyguardStatusBarView view,
CarrierTextController carrierTextController,
ConfigurationController configurationController) {
super(view);
mCarrierTextController = carrierTextController;
mConfigurationController = configurationController;
}
@Override
@@ -40,9 +64,17 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
@Override
protected void onViewAttached() {
mConfigurationController.addCallback(mConfigurationListener);
onThemeChanged();
}
@Override
protected void onViewDetached() {
mConfigurationController.removeCallback(mConfigurationListener);
}
/** Should be called when the theme changes. */
public void onThemeChanged() {
mView.onThemeChanged();
}
}

View File

@@ -344,7 +344,7 @@ public class NotificationPanelViewController extends PanelViewController {
private KeyguardQsUserSwitchController mKeyguardQsUserSwitchController;
private KeyguardUserSwitcherController mKeyguardUserSwitcherController;
private KeyguardStatusBarView mKeyguardStatusBar;
private KeyguardStatusBarViewController mKeyguarStatusBarViewController;
private KeyguardStatusBarViewController mKeyguardStatusBarViewController;
private ViewGroup mBigClockContainer;
@VisibleForTesting QS mQs;
private FrameLayout mQsFrame;
@@ -976,9 +976,9 @@ public class NotificationPanelViewController extends PanelViewController {
KeyguardStatusBarViewComponent statusBarViewComponent =
mKeyguardStatusBarViewComponentFactory.build(keyguardStatusBarView);
mKeyguarStatusBarViewController =
mKeyguardStatusBarViewController =
statusBarViewComponent.getKeyguardStatusBarViewController();
mKeyguarStatusBarViewController.init();
mKeyguardStatusBarViewController.init();
if (mKeyguardUserSwitcherController != null) {
// Try to close the switcher so that callbacks are triggered if necessary.
@@ -1155,10 +1155,6 @@ public class NotificationPanelViewController extends PanelViewController {
mStatusBarStateListener.onDozeAmountChanged(mStatusBarStateController.getDozeAmount(),
mStatusBarStateController.getInterpolatedDozeAmount());
if (mKeyguardStatusBar != null) {
mKeyguardStatusBar.onThemeChanged();
}
mKeyguardStatusViewController.setKeyguardStatusViewVisibility(
mBarState,
false,

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.statusbar.phone;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import androidx.test.filters.SmallTest;
import com.android.keyguard.CarrierTextController;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.policy.ConfigurationController;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@SmallTest
public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
@Mock
private KeyguardStatusBarView mKeyguardStatusBarView;
@Mock
private CarrierTextController mCarrierTextController;
@Mock
private ConfigurationController mConfigurationController;
private KeyguardStatusBarViewController mController;
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
mController = new KeyguardStatusBarViewController(
mKeyguardStatusBarView,
mCarrierTextController,
mConfigurationController
);
}
@Test
public void onViewAttached_callbacksRegistered() {
mController.onViewAttached();
verify(mConfigurationController).addCallback(any());
}
@Test
public void onViewDetached_callbacksUnregistered() {
mController.onViewDetached();
verify(mConfigurationController).removeCallback(any());
}
}