Merge "Making sure shade doesn't open after unfolding when no security is set" into tm-qpr-dev

This commit is contained in:
Michał Brzeziński
2022-12-16 21:58:14 +00:00
committed by Android (Google) Code Review
6 changed files with 107 additions and 36 deletions

View File

@@ -4994,10 +4994,37 @@ public final class NotificationPanelViewController implements Dumpable {
return mExpandedFraction; return mExpandedFraction;
} }
/**
* This method should not be used anymore, you should probably use {@link #isShadeFullyOpen()}
* instead. It was overused as indicating if shade is open or we're on keyguard/AOD.
* Moving forward we should be explicit about the what state we're checking.
* @return if panel is covering the screen, which means we're in expanded shade or keyguard/AOD
*
* @deprecated depends on the state you check, use {@link #isShadeFullyOpen()},
* {@link #isOnAod()}, {@link #isOnKeyguard()} instead.
*/
@Deprecated
public boolean isFullyExpanded() { public boolean isFullyExpanded() {
return mExpandedHeight >= getMaxPanelTransitionDistance(); return mExpandedHeight >= getMaxPanelTransitionDistance();
} }
/**
* Returns true if shade is fully opened, that is we're actually in the notification shade
* with QQS or QS. It's different from {@link #isFullyExpanded()} that it will not report
* shade as always expanded if we're on keyguard/AOD. It will return true only when user goes
* from keyguard to shade.
*/
public boolean isShadeFullyOpen() {
if (mBarState == SHADE) {
return isFullyExpanded();
} else if (mBarState == SHADE_LOCKED) {
return true;
} else {
// case of two finger swipe from the top of keyguard
return computeQsExpansionFraction() == 1;
}
}
public boolean isFullyCollapsed() { public boolean isFullyCollapsed() {
return mExpandedFraction <= 0.0f; return mExpandedFraction <= 0.0f;
} }

View File

@@ -63,8 +63,14 @@ public interface ShadeController {
*/ */
boolean closeShadeIfOpen(); boolean closeShadeIfOpen();
/** Returns whether the shade is currently open or opening. */ /**
boolean isShadeOpen(); * Returns whether the shade is currently open.
* Even though in the current implementation shade is in expanded state on keyguard, this
* method makes distinction between shade being truly open and plain keyguard state:
* - if QS and notifications are visible on the screen, return true
* - for any other state, including keyguard, return false
*/
boolean isShadeFullyOpen();
/** /**
* Add a runnable for NotificationPanelView to post when the panel is expanded. * Add a runnable for NotificationPanelView to post when the panel is expanded.

View File

@@ -154,9 +154,8 @@ public final class ShadeControllerImpl implements ShadeController {
} }
@Override @Override
public boolean isShadeOpen() { public boolean isShadeFullyOpen() {
return mNotificationPanelViewController.isExpanding() return mNotificationPanelViewController.isShadeFullyOpen();
|| mNotificationPanelViewController.isFullyExpanded();
} }
@Override @Override

View File

@@ -35,6 +35,7 @@ import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME;
import static com.android.systemui.charging.WirelessChargingAnimation.UNKNOWN_BATTERY_LEVEL; import static com.android.systemui.charging.WirelessChargingAnimation.UNKNOWN_BATTERY_LEVEL;
import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP; import static com.android.systemui.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
import static com.android.systemui.statusbar.NotificationLockscreenUserManager.PERMISSION_SELF; import static com.android.systemui.statusbar.NotificationLockscreenUserManager.PERMISSION_SELF;
import static com.android.systemui.statusbar.StatusBarState.SHADE;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT; import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT; import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT_TRANSPARENT;
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE; import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE;
@@ -1147,10 +1148,9 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
private void onFoldedStateChangedInternal(boolean isFolded, boolean willGoToSleep) { private void onFoldedStateChangedInternal(boolean isFolded, boolean willGoToSleep) {
// Folded state changes are followed by a screen off event. // Folded state changes are followed by a screen off event.
// By default turning off the screen also closes the shade. // By default turning off the screen also closes the shade.
// We want to make sure that the shade status is kept after // We want to make sure that the shade status is kept after folding/unfolding.
// folding/unfolding. boolean isShadeOpen = mShadeController.isShadeFullyOpen();
boolean isShadeOpen = mShadeController.isShadeOpen(); boolean leaveOpen = isShadeOpen && !willGoToSleep && mState == SHADE;
boolean leaveOpen = isShadeOpen && !willGoToSleep;
if (DEBUG) { if (DEBUG) {
Log.d(TAG, String.format( Log.d(TAG, String.format(
"#onFoldedStateChanged(): " "#onFoldedStateChanged(): "
@@ -1161,18 +1161,17 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
isFolded, willGoToSleep, isShadeOpen, leaveOpen)); isFolded, willGoToSleep, isShadeOpen, leaveOpen));
} }
if (leaveOpen) { if (leaveOpen) {
if (mKeyguardStateController.isShowing()) { // below makes shade stay open when going from folded to unfolded
// When device state changes on keyguard we don't want to keep the state of mStatusBarStateController.setLeaveOpenOnKeyguardHide(true);
// the shade and instead we open clean state of keyguard with shade closed. }
// Normally some parts of QS state (like expanded/collapsed) are persisted and if (mState != SHADE && isShadeOpen) {
// that causes incorrect UI rendering, especially when changing state with QS // When device state changes on KEYGUARD/SHADE_LOCKED we don't want to keep the state of
// expanded. To prevent that we can close QS which resets QS and some parts of // the shade and instead we open clean state of keyguard with shade closed.
// the shade to its default state. Read more in b/201537421 // Normally some parts of QS state (like expanded/collapsed) are persisted and
mCloseQsBeforeScreenOff = true; // that causes incorrect UI rendering, especially when changing state with QS
} else { // expanded. To prevent that we can close QS which resets QS and some parts of
// below makes shade stay open when going from folded to unfolded // the shade to its default state. Read more in b/201537421
mStatusBarStateController.setLeaveOpenOnKeyguardHide(true); mCloseQsBeforeScreenOff = true;
}
} }
} }

View File

@@ -1681,6 +1681,42 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
assertThat(mNotificationPanelViewController.isFullyExpanded()).isTrue(); assertThat(mNotificationPanelViewController.isFullyExpanded()).isTrue();
} }
@Test
public void shadeExpanded_inShadeState() {
mStatusBarStateController.setState(SHADE);
mNotificationPanelViewController.setExpandedHeight(0);
assertThat(mNotificationPanelViewController.isShadeFullyOpen()).isFalse();
int transitionDistance = mNotificationPanelViewController.getMaxPanelTransitionDistance();
mNotificationPanelViewController.setExpandedHeight(transitionDistance);
assertThat(mNotificationPanelViewController.isShadeFullyOpen()).isTrue();
}
@Test
public void shadeExpanded_onKeyguard() {
mStatusBarStateController.setState(KEYGUARD);
int transitionDistance = mNotificationPanelViewController.getMaxPanelTransitionDistance();
mNotificationPanelViewController.setExpandedHeight(transitionDistance);
assertThat(mNotificationPanelViewController.isShadeFullyOpen()).isFalse();
// set maxQsExpansion in NPVC
int maxQsExpansion = 123;
mNotificationPanelViewController.setQs(mQs);
when(mQs.getDesiredHeight()).thenReturn(maxQsExpansion);
triggerLayoutChange();
mNotificationPanelViewController.setQsExpansionHeight(maxQsExpansion);
assertThat(mNotificationPanelViewController.isShadeFullyOpen()).isTrue();
}
@Test
public void shadeExpanded_onShadeLocked() {
mStatusBarStateController.setState(SHADE_LOCKED);
assertThat(mNotificationPanelViewController.isShadeFullyOpen()).isTrue();
}
private static MotionEvent createMotionEvent(int x, int y, int action) { private static MotionEvent createMotionEvent(int x, int y, int action) {
return MotionEvent.obtain( return MotionEvent.obtain(
/* downTime= */ 0, /* eventTime= */ 0, action, x, y, /* metaState= */ 0); /* downTime= */ 0, /* eventTime= */ 0, action, x, y, /* metaState= */ 0);

View File

@@ -19,6 +19,9 @@ package com.android.systemui.statusbar.phone;
import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
import static com.android.systemui.statusbar.StatusBarState.SHADE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse;
@@ -831,7 +834,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
when(mNotificationsController.getActiveNotificationsCount()).thenReturn(5); when(mNotificationsController.getActiveNotificationsCount()).thenReturn(5);
when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(true); when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE); mCentralSurfaces.setBarStateForTest(SHADE);
try { try {
mCentralSurfaces.handleVisibleToUserChanged(true); mCentralSurfaces.handleVisibleToUserChanged(true);
@@ -850,7 +853,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
when(mNotificationsController.getActiveNotificationsCount()).thenReturn(5); when(mNotificationsController.getActiveNotificationsCount()).thenReturn(5);
when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(false); when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(false);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE); mCentralSurfaces.setBarStateForTest(SHADE);
try { try {
mCentralSurfaces.handleVisibleToUserChanged(true); mCentralSurfaces.handleVisibleToUserChanged(true);
@@ -991,7 +994,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void testShowKeyguardImplementation_setsState() { public void testShowKeyguardImplementation_setsState() {
when(mLockscreenUserManager.getCurrentProfiles()).thenReturn(new SparseArray<>()); when(mLockscreenUserManager.getCurrentProfiles()).thenReturn(new SparseArray<>());
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE); mCentralSurfaces.setBarStateForTest(SHADE);
// By default, showKeyguardImpl sets state to KEYGUARD. // By default, showKeyguardImpl sets state to KEYGUARD.
mCentralSurfaces.showKeyguardImpl(); mCentralSurfaces.showKeyguardImpl();
@@ -1048,7 +1051,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShade_callsanimateCollapseShade_whenExpanded() { public void collapseShade_callsanimateCollapseShade_whenExpanded() {
// GIVEN the shade is expanded // GIVEN the shade is expanded
mCentralSurfaces.onShadeExpansionFullyChanged(true); mCentralSurfaces.onShadeExpansionFullyChanged(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE); mCentralSurfaces.setBarStateForTest(SHADE);
// WHEN collapseShade is called // WHEN collapseShade is called
mCentralSurfaces.collapseShade(); mCentralSurfaces.collapseShade();
@@ -1061,7 +1064,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShade_doesNotCallanimateCollapseShade_whenCollapsed() { public void collapseShade_doesNotCallanimateCollapseShade_whenCollapsed() {
// GIVEN the shade is collapsed // GIVEN the shade is collapsed
mCentralSurfaces.onShadeExpansionFullyChanged(false); mCentralSurfaces.onShadeExpansionFullyChanged(false);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE); mCentralSurfaces.setBarStateForTest(SHADE);
// WHEN collapseShade is called // WHEN collapseShade is called
mCentralSurfaces.collapseShade(); mCentralSurfaces.collapseShade();
@@ -1074,7 +1077,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShadeForBugReport_callsanimateCollapseShade_whenFlagDisabled() { public void collapseShadeForBugReport_callsanimateCollapseShade_whenFlagDisabled() {
// GIVEN the shade is expanded & flag enabled // GIVEN the shade is expanded & flag enabled
mCentralSurfaces.onShadeExpansionFullyChanged(true); mCentralSurfaces.onShadeExpansionFullyChanged(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE); mCentralSurfaces.setBarStateForTest(SHADE);
mFeatureFlags.set(Flags.LEAVE_SHADE_OPEN_FOR_BUGREPORT, false); mFeatureFlags.set(Flags.LEAVE_SHADE_OPEN_FOR_BUGREPORT, false);
// WHEN collapseShadeForBugreport is called // WHEN collapseShadeForBugreport is called
@@ -1088,7 +1091,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShadeForBugReport_doesNotCallanimateCollapseShade_whenFlagEnabled() { public void collapseShadeForBugReport_doesNotCallanimateCollapseShade_whenFlagEnabled() {
// GIVEN the shade is expanded & flag enabled // GIVEN the shade is expanded & flag enabled
mCentralSurfaces.onShadeExpansionFullyChanged(true); mCentralSurfaces.onShadeExpansionFullyChanged(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE); mCentralSurfaces.setBarStateForTest(SHADE);
mFeatureFlags.set(Flags.LEAVE_SHADE_OPEN_FOR_BUGREPORT, true); mFeatureFlags.set(Flags.LEAVE_SHADE_OPEN_FOR_BUGREPORT, true);
// WHEN collapseShadeForBugreport is called // WHEN collapseShadeForBugreport is called
@@ -1100,10 +1103,10 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
@Test @Test
public void deviceStateChange_unfolded_shadeOpen_setsLeaveOpenOnKeyguardHide() { public void deviceStateChange_unfolded_shadeOpen_setsLeaveOpenOnKeyguardHide() {
when(mKeyguardStateController.isShowing()).thenReturn(false);
setFoldedStates(FOLD_STATE_FOLDED); setFoldedStates(FOLD_STATE_FOLDED);
setGoToSleepStates(FOLD_STATE_FOLDED); setGoToSleepStates(FOLD_STATE_FOLDED);
when(mNotificationPanelViewController.isFullyExpanded()).thenReturn(true); mCentralSurfaces.setBarStateForTest(SHADE);
when(mNotificationPanelViewController.isShadeFullyOpen()).thenReturn(true);
setDeviceState(FOLD_STATE_UNFOLDED); setDeviceState(FOLD_STATE_UNFOLDED);
@@ -1112,10 +1115,10 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
@Test @Test
public void deviceStateChange_unfolded_shadeOpen_onKeyguard_doesNotSetLeaveOpenOnKeyguardHide() { public void deviceStateChange_unfolded_shadeOpen_onKeyguard_doesNotSetLeaveOpenOnKeyguardHide() {
when(mKeyguardStateController.isShowing()).thenReturn(true);
setFoldedStates(FOLD_STATE_FOLDED); setFoldedStates(FOLD_STATE_FOLDED);
setGoToSleepStates(FOLD_STATE_FOLDED); setGoToSleepStates(FOLD_STATE_FOLDED);
when(mNotificationPanelViewController.isFullyExpanded()).thenReturn(true); mCentralSurfaces.setBarStateForTest(KEYGUARD);
when(mNotificationPanelViewController.isShadeFullyOpen()).thenReturn(true);
setDeviceState(FOLD_STATE_UNFOLDED); setDeviceState(FOLD_STATE_UNFOLDED);
@@ -1127,7 +1130,8 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void deviceStateChange_unfolded_shadeClose_doesNotSetLeaveOpenOnKeyguardHide() { public void deviceStateChange_unfolded_shadeClose_doesNotSetLeaveOpenOnKeyguardHide() {
setFoldedStates(FOLD_STATE_FOLDED); setFoldedStates(FOLD_STATE_FOLDED);
setGoToSleepStates(FOLD_STATE_FOLDED); setGoToSleepStates(FOLD_STATE_FOLDED);
when(mNotificationPanelViewController.isFullyExpanded()).thenReturn(false); mCentralSurfaces.setBarStateForTest(SHADE);
when(mNotificationPanelViewController.isShadeFullyOpen()).thenReturn(false);
setDeviceState(FOLD_STATE_UNFOLDED); setDeviceState(FOLD_STATE_UNFOLDED);
@@ -1161,12 +1165,12 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
// it to remain visible. // it to remain visible.
when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(true); when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(true);
setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */); setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */);
verify(mStatusBarStateController, never()).setState(StatusBarState.SHADE); verify(mStatusBarStateController, never()).setState(SHADE);
// Once the animation ends, verify that the keyguard is actually hidden. // Once the animation ends, verify that the keyguard is actually hidden.
when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(false); when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(false);
setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */); setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */);
verify(mStatusBarStateController).setState(StatusBarState.SHADE); verify(mStatusBarStateController).setState(SHADE);
} }
@Test @Test
@@ -1179,7 +1183,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
// immediately hide the keyguard. // immediately hide the keyguard.
when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(false); when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(false);
setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */); setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */);
verify(mStatusBarStateController).setState(StatusBarState.SHADE); verify(mStatusBarStateController).setState(SHADE);
} }
/** /**