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

Commit ddbd1b98 authored by Bryce Lee's avatar Bryce Lee Committed by android-build-merger
Browse files

Merge "Do not sleep activities in focused stack when keyguard is going away" into pi-dev

am: 3912a7f5

Change-Id: I7d547cf1ca947f83357ac0d8c7cc773d5a9b8662
parents 5dd917de 3912a7f5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -5287,6 +5287,14 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

    boolean shouldSleepActivities() {
        final ActivityDisplay display = getDisplay();

        // Do not sleep activities in this stack if we're marked as focused and the keyguard
        // is in the process of going away.
        if (mStackSupervisor.getFocusedStack() == this
                && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) {
            return false;
        }

        return display != null ? display.isSleeping() : mService.isSleepingLocked();
    }

+8 −0
Original line number Diff line number Diff line
@@ -97,6 +97,14 @@ class KeyguardController {
        return mKeyguardShowing && !mKeyguardGoingAway;
    }

    /**
     * @return {@code true} if the keyguard is going away, {@code false} otherwise.
     */
    boolean isKeyguardGoingAway() {
        // Also check keyguard showing in case value is stale.
        return mKeyguardGoingAway && mKeyguardShowing;
    }

    /**
     * Update the Keyguard showing state.
     */
+36 −0
Original line number Diff line number Diff line
@@ -37,12 +37,15 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.app.servertransaction.DestroyActivityItem;
import android.content.pm.ActivityInfo;
import android.os.Debug;
import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.SmallTest;
@@ -518,4 +521,37 @@ public class ActivityStackTests extends ActivityTestsBase {
        assertTrue(mTask.mActivities.isEmpty());
        assertTrue(mStack.getAllTasks().isEmpty());
    }

    @Test
    public void testShouldSleepActivities() throws Exception {
        // When focused activity and keyguard is going away, we should not sleep regardless
        // of the display state
        verifyShouldSleepActivities(true /* focusedStack */, true /*keyguardGoingAway*/,
                true /* displaySleeping */, false /* expected*/);

        // When not the focused stack, defer to display sleeping state.
        verifyShouldSleepActivities(false /* focusedStack */, true /*keyguardGoingAway*/,
                true /* displaySleeping */, true /* expected*/);

        // If keyguard is going away, defer to the display sleeping state.
        verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/,
                true /* displaySleeping */, true /* expected*/);
        verifyShouldSleepActivities(true /* focusedStack */, false /*keyguardGoingAway*/,
                false /* displaySleeping */, false /* expected*/);
    }

    private void verifyShouldSleepActivities(boolean focusedStack,
            boolean keyguardGoingAway, boolean displaySleeping, boolean expected) {
        mSupervisor.mFocusedStack = focusedStack ? mStack : null;

        final ActivityDisplay display = mock(ActivityDisplay.class);
        final KeyguardController keyguardController = mSupervisor.getKeyguardController();

        doReturn(display).when(mSupervisor).getActivityDisplay(anyInt());
        doReturn(keyguardGoingAway).when(keyguardController).isKeyguardGoingAway();
        doReturn(displaySleeping).when(display).isSleeping();

        assertEquals(expected, mStack.shouldSleepActivities());
    }

}
+2 −0
Original line number Diff line number Diff line
@@ -316,6 +316,7 @@ public class ActivityTestsBase {
        @Override
        final protected ActivityStackSupervisor createStackSupervisor() {
            final ActivityStackSupervisor supervisor = spy(createTestSupervisor());
            final KeyguardController keyguardController = mock(KeyguardController.class);

            // No home stack is set.
            doNothing().when(supervisor).moveHomeStackToFront(any());
@@ -330,6 +331,7 @@ public class ActivityTestsBase {
            doNothing().when(supervisor).scheduleIdleTimeoutLocked(any());
            // unit test version does not handle launch wake lock
            doNothing().when(supervisor).acquireLaunchWakelock();
            doReturn(keyguardController).when(supervisor).getKeyguardController();

            supervisor.initialize();