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

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

Change-Id: Ibba97b19b47d825b5ff2ee785b54ba4b28b70e53
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Michał Brzeziński
2022-12-16 22:43:36 +00:00
committed by Automerger Merge Worker
6 changed files with 107 additions and 36 deletions

View File

@@ -4994,10 +4994,37 @@ public final class NotificationPanelViewController implements Dumpable {
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() {
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() {
return mExpandedFraction <= 0.0f;
}

View File

@@ -63,8 +63,14 @@ public interface ShadeController {
*/
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.

View File

@@ -154,9 +154,8 @@ public final class ShadeControllerImpl implements ShadeController {
}
@Override
public boolean isShadeOpen() {
return mNotificationPanelViewController.isExpanding()
|| mNotificationPanelViewController.isFullyExpanded();
public boolean isShadeFullyOpen() {
return mNotificationPanelViewController.isShadeFullyOpen();
}
@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.keyguard.WakefulnessLifecycle.WAKEFULNESS_ASLEEP;
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_TRANSPARENT;
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) {
// Folded state changes are followed by a screen off event.
// By default turning off the screen also closes the shade.
// We want to make sure that the shade status is kept after
// folding/unfolding.
boolean isShadeOpen = mShadeController.isShadeOpen();
boolean leaveOpen = isShadeOpen && !willGoToSleep;
// We want to make sure that the shade status is kept after folding/unfolding.
boolean isShadeOpen = mShadeController.isShadeFullyOpen();
boolean leaveOpen = isShadeOpen && !willGoToSleep && mState == SHADE;
if (DEBUG) {
Log.d(TAG, String.format(
"#onFoldedStateChanged(): "
@@ -1161,18 +1161,17 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
isFolded, willGoToSleep, isShadeOpen, leaveOpen));
}
if (leaveOpen) {
if (mKeyguardStateController.isShowing()) {
// When device state changes on keyguard we don't want to keep the state of
// 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
// that causes incorrect UI rendering, especially when changing state with QS
// expanded. To prevent that we can close QS which resets QS and some parts of
// the shade to its default state. Read more in b/201537421
mCloseQsBeforeScreenOff = true;
} else {
// below makes shade stay open when going from folded to unfolded
mStatusBarStateController.setLeaveOpenOnKeyguardHide(true);
}
// below makes shade stay open when going from folded to unfolded
mStatusBarStateController.setLeaveOpenOnKeyguardHide(true);
}
if (mState != SHADE && isShadeOpen) {
// When device state changes on KEYGUARD/SHADE_LOCKED we don't want to keep the state of
// 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
// that causes incorrect UI rendering, especially when changing state with QS
// expanded. To prevent that we can close QS which resets QS and some parts of
// the shade to its default state. Read more in b/201537421
mCloseQsBeforeScreenOff = true;
}
}

View File

@@ -1681,6 +1681,42 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase {
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) {
return MotionEvent.obtain(
/* 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.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 junit.framework.Assert.assertFalse;
@@ -831,7 +834,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
when(mNotificationsController.getActiveNotificationsCount()).thenReturn(5);
when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE);
mCentralSurfaces.setBarStateForTest(SHADE);
try {
mCentralSurfaces.handleVisibleToUserChanged(true);
@@ -850,7 +853,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
when(mNotificationsController.getActiveNotificationsCount()).thenReturn(5);
when(mNotificationPresenter.isPresenterFullyCollapsed()).thenReturn(false);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE);
mCentralSurfaces.setBarStateForTest(SHADE);
try {
mCentralSurfaces.handleVisibleToUserChanged(true);
@@ -991,7 +994,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void testShowKeyguardImplementation_setsState() {
when(mLockscreenUserManager.getCurrentProfiles()).thenReturn(new SparseArray<>());
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE);
mCentralSurfaces.setBarStateForTest(SHADE);
// By default, showKeyguardImpl sets state to KEYGUARD.
mCentralSurfaces.showKeyguardImpl();
@@ -1048,7 +1051,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShade_callsanimateCollapseShade_whenExpanded() {
// GIVEN the shade is expanded
mCentralSurfaces.onShadeExpansionFullyChanged(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE);
mCentralSurfaces.setBarStateForTest(SHADE);
// WHEN collapseShade is called
mCentralSurfaces.collapseShade();
@@ -1061,7 +1064,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShade_doesNotCallanimateCollapseShade_whenCollapsed() {
// GIVEN the shade is collapsed
mCentralSurfaces.onShadeExpansionFullyChanged(false);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE);
mCentralSurfaces.setBarStateForTest(SHADE);
// WHEN collapseShade is called
mCentralSurfaces.collapseShade();
@@ -1074,7 +1077,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShadeForBugReport_callsanimateCollapseShade_whenFlagDisabled() {
// GIVEN the shade is expanded & flag enabled
mCentralSurfaces.onShadeExpansionFullyChanged(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE);
mCentralSurfaces.setBarStateForTest(SHADE);
mFeatureFlags.set(Flags.LEAVE_SHADE_OPEN_FOR_BUGREPORT, false);
// WHEN collapseShadeForBugreport is called
@@ -1088,7 +1091,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void collapseShadeForBugReport_doesNotCallanimateCollapseShade_whenFlagEnabled() {
// GIVEN the shade is expanded & flag enabled
mCentralSurfaces.onShadeExpansionFullyChanged(true);
mCentralSurfaces.setBarStateForTest(StatusBarState.SHADE);
mCentralSurfaces.setBarStateForTest(SHADE);
mFeatureFlags.set(Flags.LEAVE_SHADE_OPEN_FOR_BUGREPORT, true);
// WHEN collapseShadeForBugreport is called
@@ -1100,10 +1103,10 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
@Test
public void deviceStateChange_unfolded_shadeOpen_setsLeaveOpenOnKeyguardHide() {
when(mKeyguardStateController.isShowing()).thenReturn(false);
setFoldedStates(FOLD_STATE_FOLDED);
setGoToSleepStates(FOLD_STATE_FOLDED);
when(mNotificationPanelViewController.isFullyExpanded()).thenReturn(true);
mCentralSurfaces.setBarStateForTest(SHADE);
when(mNotificationPanelViewController.isShadeFullyOpen()).thenReturn(true);
setDeviceState(FOLD_STATE_UNFOLDED);
@@ -1112,10 +1115,10 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
@Test
public void deviceStateChange_unfolded_shadeOpen_onKeyguard_doesNotSetLeaveOpenOnKeyguardHide() {
when(mKeyguardStateController.isShowing()).thenReturn(true);
setFoldedStates(FOLD_STATE_FOLDED);
setGoToSleepStates(FOLD_STATE_FOLDED);
when(mNotificationPanelViewController.isFullyExpanded()).thenReturn(true);
mCentralSurfaces.setBarStateForTest(KEYGUARD);
when(mNotificationPanelViewController.isShadeFullyOpen()).thenReturn(true);
setDeviceState(FOLD_STATE_UNFOLDED);
@@ -1127,7 +1130,8 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void deviceStateChange_unfolded_shadeClose_doesNotSetLeaveOpenOnKeyguardHide() {
setFoldedStates(FOLD_STATE_FOLDED);
setGoToSleepStates(FOLD_STATE_FOLDED);
when(mNotificationPanelViewController.isFullyExpanded()).thenReturn(false);
mCentralSurfaces.setBarStateForTest(SHADE);
when(mNotificationPanelViewController.isShadeFullyOpen()).thenReturn(false);
setDeviceState(FOLD_STATE_UNFOLDED);
@@ -1161,12 +1165,12 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
// it to remain visible.
when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(true);
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.
when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(false);
setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */);
verify(mStatusBarStateController).setState(StatusBarState.SHADE);
verify(mStatusBarStateController).setState(SHADE);
}
@Test
@@ -1179,7 +1183,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
// immediately hide the keyguard.
when(mKeyguardViewMediator.isOccludeAnimationPlaying()).thenReturn(false);
setKeyguardShowingAndOccluded(false /* showing */, true /* occluded */);
verify(mStatusBarStateController).setState(StatusBarState.SHADE);
verify(mStatusBarStateController).setState(SHADE);
}
/**