Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e2733e2 authored by Michal Brzezinski's avatar Michal Brzezinski
Browse files

Making sure shade doesn't open after unfolding when no security is set

Shade was opening because `mKeyguardStateController.isShowing()` is false when screen is off but no security set. I changed the logic of isShadeOpen to actually say if shade is open instead of being always true on keyguard and made small fixes to the logic in CentralSurfaces. We want to keep shade open only when we're in unlocked (SHADE) state.

Added isShadeOpen method to NPVC - it should be helpful for other use cases and might be less confusing to use than isFullyExpanded.

Fixes: 259012717
Test: manual -> set security to none -> turn screen off in folded mode -> unfold -> see launcher instead of shade
Test: NotificationPanelViewControllerTest
Change-Id: I5c1ce04fac5e549a49a53bd409c6e198483b4647
parent 0513b9e1
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_N
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
import static com.android.systemui.statusbar.StatusBarState.SHADE;
import static com.android.systemui.statusbar.StatusBarState.SHADE_LOCKED;
import static com.android.systemui.statusbar.VibratorHelper.TOUCH_VIBRATION_ATTRIBUTES;
import static com.android.systemui.statusbar.notification.stack.StackStateAnimator.ANIMATION_DURATION_FOLD_TO_AOD;
import static com.android.systemui.util.DumpUtilsKt.asIndenting;
@@ -5031,10 +5032,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;
    }
+8 −2
Original line number Diff line number Diff line
@@ -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.
+2 −3
Original line number Diff line number Diff line
@@ -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
+15 −16
Original line number Diff line number Diff line
@@ -34,6 +34,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;
@@ -1121,10 +1122,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(): "
@@ -1135,18 +1135,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
            // 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;
            } else {
                // below makes shade stay open when going from folded to unfolded
                mStatusBarStateController.setLeaveOpenOnKeyguardHide(true);
            }
        }
    }

+36 −0
Original line number Diff line number Diff line
@@ -1709,6 +1709,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);
Loading