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

am: ddbd1b9826

Change-Id: Ia985ab2491077fc39031df2c66591a0cbe087e5b
This commit is contained in:
Bryce Lee
2018-03-16 20:16:38 +00:00
committed by android-build-merger
4 changed files with 54 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -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.
*/

View File

@@ -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());
}
}

View File

@@ -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();