From 9e5c45cb478ba9b71b2a6f111ea7bd47eecfc6ef Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Mon, 14 Jun 2021 14:48:35 -0400 Subject: [PATCH] Move BatteryStateChangeCallback internal to StatusBar. Removes one of the "does not crash" tests. This test should be more specific. Bug: 190746471 Test: atest SystemUITests Change-Id: I4ed380308f5231949034e927cf015bc3cdb671d0 --- .../systemui/statusbar/phone/StatusBar.java | 160 +++++++++--------- .../statusbar/phone/StatusBarTest.java | 9 - 2 files changed, 81 insertions(+), 88 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 3b5bce02f0266..28510abb51b45 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -252,8 +252,7 @@ import dagger.Lazy; /** */ public class StatusBar extends SystemUI implements ActivityStarter, - StatusBarStateController.StateListener, - LifecycleOwner, BatteryController.BatteryStateChangeCallback, + LifecycleOwner, ActivityLaunchAnimator.Callback { public static final boolean MULTIUSER_DEBUG = false; @@ -842,6 +841,84 @@ public class StatusBar extends SystemUI implements } } }; + + private StatusBarStateController.StateListener mStateListener = + new StatusBarStateController.StateListener() { + @Override + public void onStatePreChange(int oldState, int newState) { + // If we're visible and switched to SHADE_LOCKED (the user dragged + // down on the lockscreen), clear notification LED, vibration, + // ringing. + // Other transitions are covered in handleVisibleToUserChanged(). + if (mVisible && (newState == StatusBarState.SHADE_LOCKED + || mStatusBarStateController.goingToFullShade())) { + clearNotificationEffects(); + } + if (newState == StatusBarState.KEYGUARD) { + mRemoteInputManager.onPanelCollapsed(); + maybeEscalateHeadsUp(); + } + } + + @Override + public void onStateChanged(int newState) { + mState = newState; + updateReportRejectedTouchVisibility(); + mDozeServiceHost.updateDozing(); + updateTheme(); + mNavigationBarController.touchAutoDim(mDisplayId); + Trace.beginSection("StatusBar#updateKeyguardState"); + if (mState == StatusBarState.KEYGUARD && mStatusBarView != null) { + mStatusBarView.removePendingHideExpandedRunnables(); + } + updateDozingState(); + checkBarModes(); + updateScrimController(); + mPresenter.updateMediaMetaData(false, mState != StatusBarState.KEYGUARD); + updateKeyguardState(); + Trace.endSection(); + } + + @Override + public void onDozeAmountChanged(float linear, float eased) { + if (mFeatureFlags.useNewLockscreenAnimations() + && !(mLightRevealScrim.getRevealEffect() instanceof CircleReveal)) { + mLightRevealScrim.setRevealAmount(1f - linear); + } + } + + @Override + public void onDozingChanged(boolean isDozing) { + Trace.beginSection("StatusBar#updateDozing"); + mDozing = isDozing; + + // Collapse the notification panel if open + boolean dozingAnimated = mDozeServiceHost.getDozingRequested() + && mDozeParameters.shouldControlScreenOff(); + mNotificationPanelViewController.resetViews(dozingAnimated); + + updateQsExpansionEnabled(); + mKeyguardViewMediator.setDozing(mDozing); + + mNotificationsController.requestNotificationUpdate("onDozingChanged"); + updateDozingState(); + mDozeServiceHost.updateDozing(); + updateScrimController(); + updateReportRejectedTouchVisibility(); + Trace.endSection(); + } + }; + + private final BatteryController.BatteryStateChangeCallback mBatteryStateChangeCallback = + new BatteryController.BatteryStateChangeCallback() { + @Override + public void onPowerSaveChanged(boolean isPowerSave) { + mHandler.post(mCheckBarModes); + if (mDozeServiceHost != null) { + mDozeServiceHost.firePowerSaveChanged(isPowerSave); + } + } + }; /** * Public constructor for StatusBar. * @@ -1058,7 +1135,7 @@ public class StatusBar extends SystemUI implements mKeyguardIndicationController.init(); mColorExtractor.addOnColorsChangedListener(mOnColorsChangedListener); - mStatusBarStateController.addCallback(this, + mStatusBarStateController.addCallback(mStateListener, SysuiStatusBarStateController.RANK_STATUS_BAR); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); @@ -1174,7 +1251,7 @@ public class StatusBar extends SystemUI implements mConfigurationController.addCallback(mConfigurationListener); - mBatteryController.observe(mLifecycle, this); + mBatteryController.observe(mLifecycle, mBatteryStateChangeCallback); mLifecycle.setCurrentState(RESUMED); // set the initial view visibility @@ -1542,19 +1619,6 @@ public class StatusBar extends SystemUI implements return mLifecycle; } - @Override - public void onPowerSaveChanged(boolean isPowerSave) { - mHandler.post(mCheckBarModes); - if (mDozeServiceHost != null) { - mDozeServiceHost.firePowerSaveChanged(isPowerSave); - } - } - - @Override - public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { - // noop - } - @VisibleForTesting protected void registerBroadcastReceiver() { IntentFilter filter = new IntentFilter(); @@ -3515,69 +3579,7 @@ public class StatusBar extends SystemUI implements mNotificationPanelViewController.collapseWithDuration(duration); } - @Override - public void onStatePreChange(int oldState, int newState) { - // If we're visible and switched to SHADE_LOCKED (the user dragged - // down on the lockscreen), clear notification LED, vibration, - // ringing. - // Other transitions are covered in handleVisibleToUserChanged(). - if (mVisible && (newState == StatusBarState.SHADE_LOCKED - || mStatusBarStateController.goingToFullShade())) { - clearNotificationEffects(); - } - if (newState == StatusBarState.KEYGUARD) { - mRemoteInputManager.onPanelCollapsed(); - maybeEscalateHeadsUp(); - } - } - @Override - public void onStateChanged(int newState) { - mState = newState; - updateReportRejectedTouchVisibility(); - mDozeServiceHost.updateDozing(); - updateTheme(); - mNavigationBarController.touchAutoDim(mDisplayId); - Trace.beginSection("StatusBar#updateKeyguardState"); - if (mState == StatusBarState.KEYGUARD && mStatusBarView != null) { - mStatusBarView.removePendingHideExpandedRunnables(); - } - updateDozingState(); - checkBarModes(); - updateScrimController(); - mPresenter.updateMediaMetaData(false, mState != StatusBarState.KEYGUARD); - updateKeyguardState(); - Trace.endSection(); - } - - @Override - public void onDozeAmountChanged(float linear, float eased) { - if (mFeatureFlags.useNewLockscreenAnimations() - && !(mLightRevealScrim.getRevealEffect() instanceof CircleReveal)) { - mLightRevealScrim.setRevealAmount(1f - linear); - } - } - - @Override - public void onDozingChanged(boolean isDozing) { - Trace.beginSection("StatusBar#updateDozing"); - mDozing = isDozing; - - // Collapse the notification panel if open - boolean dozingAnimated = mDozeServiceHost.getDozingRequested() - && mDozeParameters.shouldControlScreenOff(); - mNotificationPanelViewController.resetViews(dozingAnimated); - - updateQsExpansionEnabled(); - mKeyguardViewMediator.setDozing(mDozing); - - mNotificationsController.requestNotificationUpdate("onDozingChanged"); - updateDozingState(); - mDozeServiceHost.updateDozing(); - updateScrimController(); - updateReportRejectedTouchVisibility(); - Trace.endSection(); - } /** * Updates the light reveal effect to reflect the reason we're waking or sleeping (for example, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java index 079a621546dd7..d3c67074dcab4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java @@ -753,15 +753,6 @@ public class StatusBarTest extends SysuiTestCase { new PrintWriter(new ByteArrayOutputStream()), "var", /* transitions= */ null); } - @Test - @RunWithLooper(setAsMainLooper = true) - public void testUpdateKeyguardState_DoesNotCrash() { - mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD); - when(mLockscreenUserManager.getCurrentProfiles()).thenReturn( - new SparseArray<>()); - mStatusBar.onStateChanged(StatusBarState.SHADE); - } - @Test public void testFingerprintNotification_UpdatesScrims() { mStatusBar.notifyBiometricAuthModeChanged();