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

Commit 3dee2da9 authored by Beverly Tai's avatar Beverly Tai Committed by Automerger Merge Worker
Browse files

Merge "Start a new keyguard session on device sleep" into tm-qpr-dev am: 98ad6693

parents 4ddf22fc 98ad6693
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -234,7 +234,10 @@ public class StatusBarManager {

    /**
     * Session flag for {@link #registerSessionListener} indicating the listener
     * is interested in sessions on the keygaurd
     * is interested in sessions on the keygaurd.
     * Keyguard Session Boundaries:
     *     START_SESSION: device starts going to sleep OR the keyguard is newly shown
     *     END_SESSION: device starts going to sleep OR keyguard is no longer showing
     * @hide
     */
    public static final int SESSION_KEYGUARD = 1 << 0;
+10 −6
Original line number Diff line number Diff line
@@ -49,7 +49,9 @@ import javax.inject.Inject;
@SysUISingleton
public class SessionTracker implements CoreStartable {
    private static final String TAG = "SessionTracker";
    private static final boolean DEBUG = false;

    // To enable logs: `adb shell setprop log.tag.SessionTracker DEBUG` & restart sysui
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    // At most 20 bits: ~1m possibilities, ~0.5% probability of collision in 100 values
    private final InstanceIdSequence mInstanceIdGenerator = new InstanceIdSequence(1 << 20);
@@ -81,8 +83,8 @@ public class SessionTracker implements CoreStartable {
        mKeyguardUpdateMonitor.registerCallback(mKeyguardUpdateMonitorCallback);
        mKeyguardStateController.addCallback(mKeyguardStateCallback);

        mKeyguardSessionStarted = mKeyguardStateController.isShowing();
        if (mKeyguardSessionStarted) {
        if (mKeyguardStateController.isShowing()) {
            mKeyguardSessionStarted = true;
            startSession(SESSION_KEYGUARD);
        }
    }
@@ -136,12 +138,11 @@ public class SessionTracker implements CoreStartable {
            new KeyguardUpdateMonitorCallback() {
        @Override
        public void onStartedGoingToSleep(int why) {
            // we need to register to the KeyguardUpdateMonitor lifecycle b/c it gets called
            // before the WakefulnessLifecycle
            if (mKeyguardSessionStarted) {
                return;
                endSession(SESSION_KEYGUARD);
            }

            // Start a new session whenever the device goes to sleep
            mKeyguardSessionStarted = true;
            startSession(SESSION_KEYGUARD);
        }
@@ -154,6 +155,9 @@ public class SessionTracker implements CoreStartable {
            boolean wasSessionStarted = mKeyguardSessionStarted;
            boolean keyguardShowing = mKeyguardStateController.isShowing();
            if (keyguardShowing && !wasSessionStarted) {
                // the keyguard can start showing without the device going to sleep (ie: lockdown
                // from the power button), so we start a new keyguard session when the keyguard is
                // newly shown in addition to when the device starts going to sleep
                mKeyguardSessionStarted = true;
                startSession(SESSION_KEYGUARD);
            } else if (!keyguardShowing && wasSessionStarted) {
+30 −0
Original line number Diff line number Diff line
@@ -23,8 +23,10 @@ import static android.app.StatusBarManager.SESSION_KEYGUARD;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;

import static org.junit.Assert.assertNotEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -170,6 +172,34 @@ public class SessionTrackerTest extends SysuiTestCase {
                eq(SESSION_KEYGUARD), any(InstanceId.class));
    }

    @Test
    public void testKeyguardSessionOnDeviceStartsSleepingTwiceInARow_startsNewKeyguardSession()
            throws RemoteException {
        // GIVEN session tracker started w/o any sessions
        mSessionTracker.start();
        captureKeyguardUpdateMonitorCallback();

        // WHEN device starts going to sleep
        mKeyguardUpdateMonitorCallback.onStartedGoingToSleep(0);

        // THEN the keyguard session has a session id
        final InstanceId firstSessionId = mSessionTracker.getSessionId(SESSION_KEYGUARD);
        assertNotNull(firstSessionId);

        // WHEN device starts going to sleep a second time
        mKeyguardUpdateMonitorCallback.onStartedGoingToSleep(0);

        // THEN there's a new keyguard session with a unique session id
        final InstanceId secondSessionId = mSessionTracker.getSessionId(SESSION_KEYGUARD);
        assertNotNull(secondSessionId);
        assertNotEquals(firstSessionId, secondSessionId);

        // THEN session start event gets sent to status bar service twice (once per going to
        // sleep signal)
        verify(mStatusBarService, times(2)).onSessionStarted(
                eq(SESSION_KEYGUARD), any(InstanceId.class));
    }

    @Test
    public void testKeyguardSessionOnKeyguardShowingChange() throws RemoteException {
        // GIVEN session tracker started w/o any sessions