Merge "[Dagger] Move BatteryStateChangeCallback out of KeyguardStatusBarView and into its controller." into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
07116477ab
@@ -49,8 +49,6 @@ 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 com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
|
||||
import com.android.systemui.statusbar.policy.UserInfoController;
|
||||
import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener;
|
||||
import com.android.systemui.statusbar.policy.UserInfoControllerImpl;
|
||||
@@ -64,7 +62,6 @@ import java.util.List;
|
||||
* The header group on Keyguard.
|
||||
*/
|
||||
public class KeyguardStatusBarView extends RelativeLayout implements
|
||||
BatteryStateChangeCallback,
|
||||
OnUserInfoChangedListener {
|
||||
|
||||
private static final int LAYOUT_NONE = 0;
|
||||
@@ -75,14 +72,12 @@ public class KeyguardStatusBarView extends RelativeLayout implements
|
||||
|
||||
private boolean mShowPercentAvailable;
|
||||
private boolean mBatteryCharging;
|
||||
private boolean mBatteryListening;
|
||||
|
||||
private TextView mCarrierLabel;
|
||||
private ImageView mMultiUserAvatar;
|
||||
private BatteryMeterView mBatteryView;
|
||||
private StatusIconContainer mStatusIconContainer;
|
||||
|
||||
private BatteryController mBatteryController;
|
||||
private boolean mKeyguardUserSwitcherEnabled;
|
||||
private final UserManager mUserManager;
|
||||
|
||||
@@ -132,7 +127,6 @@ public class KeyguardStatusBarView extends RelativeLayout implements
|
||||
|
||||
loadDimens();
|
||||
loadBlockList();
|
||||
mBatteryController = Dependency.get(BatteryController.class);
|
||||
mFeatureFlags = Dependency.get(FeatureFlags.class);
|
||||
}
|
||||
|
||||
@@ -337,18 +331,6 @@ public class KeyguardStatusBarView extends RelativeLayout implements
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setListening(boolean listening) {
|
||||
if (listening == mBatteryListening) {
|
||||
return;
|
||||
}
|
||||
mBatteryListening = listening;
|
||||
if (mBatteryListening) {
|
||||
mBatteryController.addCallback(this);
|
||||
} else {
|
||||
mBatteryController.removeCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
@@ -372,19 +354,14 @@ public class KeyguardStatusBarView extends RelativeLayout implements
|
||||
mMultiUserAvatar.setImageDrawable(picture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
|
||||
/** Should only be called from {@link KeyguardStatusBarViewController}. */
|
||||
void onBatteryLevelChanged(boolean charging) {
|
||||
if (mBatteryCharging != charging) {
|
||||
mBatteryCharging = charging;
|
||||
updateVisibilities();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPowerSaveChanged(boolean isPowerSave) {
|
||||
// could not care less
|
||||
}
|
||||
|
||||
public void setKeyguardUserSwitcherEnabled(boolean enabled) {
|
||||
mKeyguardUserSwitcherEnabled = enabled;
|
||||
}
|
||||
@@ -501,10 +478,10 @@ public class KeyguardStatusBarView extends RelativeLayout implements
|
||||
}
|
||||
}
|
||||
|
||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
/** Should only be called from {@link KeyguardStatusBarViewController}. */
|
||||
void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
pw.println("KeyguardStatusBarView:");
|
||||
pw.println(" mBatteryCharging: " + mBatteryCharging);
|
||||
pw.println(" mBatteryListening: " + mBatteryListening);
|
||||
pw.println(" mLayoutState: " + mLayoutState);
|
||||
pw.println(" mKeyguardUserSwitcherEnabled: " + mKeyguardUserSwitcherEnabled);
|
||||
if (mBatteryView != null) {
|
||||
|
||||
@@ -26,9 +26,13 @@ import androidx.annotation.NonNull;
|
||||
import com.android.keyguard.CarrierTextController;
|
||||
import com.android.systemui.statusbar.events.SystemStatusAnimationCallback;
|
||||
import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.util.ViewController;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** View Controller for {@link com.android.systemui.statusbar.phone.KeyguardStatusBarView}. */
|
||||
@@ -36,6 +40,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
private final CarrierTextController mCarrierTextController;
|
||||
private final ConfigurationController mConfigurationController;
|
||||
private final SystemStatusAnimationScheduler mAnimationScheduler;
|
||||
private final BatteryController mBatteryController;
|
||||
|
||||
private final ConfigurationController.ConfigurationListener mConfigurationListener =
|
||||
new ConfigurationController.ConfigurationListener() {
|
||||
@@ -76,16 +81,28 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
}
|
||||
};
|
||||
|
||||
private final BatteryController.BatteryStateChangeCallback mBatteryStateChangeCallback =
|
||||
new BatteryController.BatteryStateChangeCallback() {
|
||||
@Override
|
||||
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
|
||||
mView.onBatteryLevelChanged(charging);
|
||||
}
|
||||
};
|
||||
|
||||
private boolean mBatteryListening;
|
||||
|
||||
@Inject
|
||||
public KeyguardStatusBarViewController(
|
||||
KeyguardStatusBarView view,
|
||||
CarrierTextController carrierTextController,
|
||||
ConfigurationController configurationController,
|
||||
SystemStatusAnimationScheduler animationScheduler) {
|
||||
SystemStatusAnimationScheduler animationScheduler,
|
||||
BatteryController batteryController) {
|
||||
super(view);
|
||||
mCarrierTextController = carrierTextController;
|
||||
mConfigurationController = configurationController;
|
||||
mAnimationScheduler = animationScheduler;
|
||||
mBatteryController = batteryController;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,4 +128,24 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
public void onThemeChanged() {
|
||||
mView.onThemeChanged();
|
||||
}
|
||||
|
||||
/** Sets whether this controller should listen to battery updates. */
|
||||
public void setBatteryListening(boolean listening) {
|
||||
if (listening == mBatteryListening) {
|
||||
return;
|
||||
}
|
||||
mBatteryListening = listening;
|
||||
if (mBatteryListening) {
|
||||
mBatteryController.addCallback(mBatteryStateChangeCallback);
|
||||
} else {
|
||||
mBatteryController.removeCallback(mBatteryStateChangeCallback);
|
||||
}
|
||||
}
|
||||
|
||||
/** */
|
||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
pw.println("KeyguardStatusBarView:");
|
||||
pw.println(" mBatteryListening: " + mBatteryListening);
|
||||
mView.dump(fd, pw, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3128,7 +3128,7 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
}
|
||||
|
||||
private void setListening(boolean listening) {
|
||||
mKeyguardStatusBar.setListening(listening);
|
||||
mKeyguardStatusBarViewController.setBatteryListening(listening);
|
||||
if (mQs == null) return;
|
||||
mQs.setListening(listening);
|
||||
}
|
||||
@@ -3774,8 +3774,8 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
super.dump(fd, pw, args);
|
||||
pw.println(" gestureExclusionRect: " + calculateGestureExclusionRect());
|
||||
if (mKeyguardStatusBar != null) {
|
||||
mKeyguardStatusBar.dump(fd, pw, args);
|
||||
if (mKeyguardStatusBarViewController != null) {
|
||||
mKeyguardStatusBarViewController.dump(fd, pw, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.keyguard.CarrierTextController;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -42,6 +43,8 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
|
||||
private ConfigurationController mConfigurationController;
|
||||
@Mock
|
||||
private SystemStatusAnimationScheduler mAnimationScheduler;
|
||||
@Mock
|
||||
private BatteryController mBatteryController;
|
||||
|
||||
private KeyguardStatusBarViewController mController;
|
||||
|
||||
@@ -53,7 +56,8 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
|
||||
mKeyguardStatusBarView,
|
||||
mCarrierTextController,
|
||||
mConfigurationController,
|
||||
mAnimationScheduler
|
||||
mAnimationScheduler,
|
||||
mBatteryController
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,4 +76,29 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
|
||||
verify(mConfigurationController).removeCallback(any());
|
||||
verify(mAnimationScheduler).removeCallback(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBatteryListening_true_callbackAdded() {
|
||||
mController.setBatteryListening(true);
|
||||
|
||||
verify(mBatteryController).addCallback(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBatteryListening_false_callbackRemoved() {
|
||||
// First set to true so that we know setting to false is a change in state.
|
||||
mController.setBatteryListening(true);
|
||||
|
||||
mController.setBatteryListening(false);
|
||||
|
||||
verify(mBatteryController).removeCallback(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBatteryListening_trueThenTrue_callbackAddedOnce() {
|
||||
mController.setBatteryListening(true);
|
||||
mController.setBatteryListening(true);
|
||||
|
||||
verify(mBatteryController).addCallback(any());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user