Merge "Allow forcing status bar state changes and do so when the screen turns off." into rvc-dev am: 6e7841799c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16103659

Change-Id: Id68d18bf7766df42eeffc063dad251598000e1be
This commit is contained in:
TreeHugger Robot
2021-11-04 01:02:58 +00:00
committed by Automerger Merge Worker
4 changed files with 28 additions and 9 deletions

View File

@@ -134,11 +134,11 @@ public class StatusBarStateControllerImpl implements SysuiStatusBarStateControll
} }
@Override @Override
public boolean setState(int state) { public boolean setState(int state, boolean force) {
if (state > MAX_STATE || state < MIN_STATE) { if (state > MAX_STATE || state < MIN_STATE) {
throw new IllegalArgumentException("Invalid state " + state); throw new IllegalArgumentException("Invalid state " + state);
} }
if (state == mState) { if (!force && state == mState) {
return false; return false;
} }

View File

@@ -58,7 +58,19 @@ public interface SysuiStatusBarStateController extends StatusBarStateController
* @param state see {@link StatusBarState} for valid options * @param state see {@link StatusBarState} for valid options
* @return {@code true} if the state changed, else {@code false} * @return {@code true} if the state changed, else {@code false}
*/ */
boolean setState(int state); default boolean setState(int state) {
return setState(state, false /* force */);
}
/**
* Update the status bar state
* @param state see {@link StatusBarState} for valid options
* @param force whether to set the state even if it's the same as the current state. This will
* dispatch the state to all StatusBarStateListeners, ensuring that all listening
* components are reset to this state.
* @return {@code true} if the state was changed or set forcefully
*/
boolean setState(int state, boolean force);
/** /**
* Update the dozing state from {@link StatusBar}'s perspective * Update the dozing state from {@link StatusBar}'s perspective

View File

@@ -3152,6 +3152,10 @@ public class StatusBar extends SystemUI implements DemoMode,
} }
boolean updateIsKeyguard() { boolean updateIsKeyguard() {
return updateIsKeyguard(false /* force */);
}
boolean updateIsKeyguard(boolean force) {
boolean wakeAndUnlocking = mBiometricUnlockController.getMode() boolean wakeAndUnlocking = mBiometricUnlockController.getMode()
== BiometricUnlockController.MODE_WAKE_AND_UNLOCK; == BiometricUnlockController.MODE_WAKE_AND_UNLOCK;
@@ -3174,7 +3178,7 @@ public class StatusBar extends SystemUI implements DemoMode,
showKeyguardImpl(); showKeyguardImpl();
} }
} else { } else {
return hideKeyguardImpl(); return hideKeyguardImpl(force);
} }
return false; return false;
} }
@@ -3305,11 +3309,11 @@ public class StatusBar extends SystemUI implements DemoMode,
/** /**
* @return true if we would like to stay in the shade, false if it should go away entirely * @return true if we would like to stay in the shade, false if it should go away entirely
*/ */
public boolean hideKeyguardImpl() { public boolean hideKeyguardImpl(boolean force) {
mIsKeyguard = false; mIsKeyguard = false;
Trace.beginSection("StatusBar#hideKeyguard"); Trace.beginSection("StatusBar#hideKeyguard");
boolean staying = mStatusBarStateController.leaveOpenOnKeyguardHide(); boolean staying = mStatusBarStateController.leaveOpenOnKeyguardHide();
if (!(mStatusBarStateController.setState(StatusBarState.SHADE))) { if (!(mStatusBarStateController.setState(StatusBarState.SHADE, force))) {
//TODO: StatusBarStateController should probably know about hiding the keyguard and //TODO: StatusBarStateController should probably know about hiding the keyguard and
// notify listeners. // notify listeners.
@@ -3736,7 +3740,8 @@ public class StatusBar extends SystemUI implements DemoMode,
// is correct. // is correct.
mHandler.post(() -> onCameraLaunchGestureDetected(mLastCameraLaunchSource)); mHandler.post(() -> onCameraLaunchGestureDetected(mLastCameraLaunchSource));
} }
updateIsKeyguard(); // When finished going to sleep, force the status bar state to avoid stale state.
updateIsKeyguard(true /* force */);
} }
@Override @Override

View File

@@ -809,12 +809,14 @@ public class StatusBarTest extends SysuiTestCase {
// By default, showKeyguardImpl sets state to KEYGUARD. // By default, showKeyguardImpl sets state to KEYGUARD.
mStatusBar.showKeyguardImpl(); mStatusBar.showKeyguardImpl();
verify(mStatusBarStateController).setState(eq(StatusBarState.KEYGUARD)); verify(mStatusBarStateController).setState(
eq(StatusBarState.KEYGUARD), eq(false) /* force */);
// If useFullscreenUserSwitcher is true, state is set to FULLSCREEN_USER_SWITCHER. // If useFullscreenUserSwitcher is true, state is set to FULLSCREEN_USER_SWITCHER.
when(mUserSwitcherController.useFullscreenUserSwitcher()).thenReturn(true); when(mUserSwitcherController.useFullscreenUserSwitcher()).thenReturn(true);
mStatusBar.showKeyguardImpl(); mStatusBar.showKeyguardImpl();
verify(mStatusBarStateController).setState(eq(StatusBarState.FULLSCREEN_USER_SWITCHER)); verify(mStatusBarStateController).setState(
eq(StatusBarState.FULLSCREEN_USER_SWITCHER), eq(false) /* force */);
} }
@Test @Test