From 86918964d693e3843858ebd2e3c08df5c1b2adc6 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Thu, 26 Apr 2018 15:28:12 -0700 Subject: [PATCH] Don't allow non-showOnLock activity to be next on finish. Previously, we required the next activity (determined by top running activity) to be showOnLock in the case the keyguard was locked and the current activity is finished. However, this was bypassed if the focused stack had a top running activity. This changelist applies the same restrictions to the aforementioned activity. Test: atest ActivityStackSupervisorTests#testTopRunningActivity Change-Id: I70ae64e0b0f4765b383bce91017bb675d0376d31 Fixes: 76424176 --- .../server/am/ActivityStackSupervisor.java | 24 ++++++++++++++++--- .../am/ActivityStackSupervisorTests.java | 22 +++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index e5565dccc70ea..425efe16c5aed 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -1224,7 +1224,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D ActivityRecord topRunningActivityLocked(boolean considerKeyguardState) { final ActivityStack focusedStack = mFocusedStack; ActivityRecord r = focusedStack.topRunningActivityLocked(); - if (r != null) { + if (r != null && isValidTopRunningActivity(r, considerKeyguardState)) { return r; } @@ -1257,12 +1257,11 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D continue; } - final boolean keyguardLocked = getKeyguardController().isKeyguardLocked(); // This activity can be considered the top running activity if we are not // considering the locked state, the keyguard isn't locked, or we can show when // locked. - if (!considerKeyguardState || !keyguardLocked || topActivity.canShowWhenLocked()) { + if (isValidTopRunningActivity(topActivity, considerKeyguardState)) { return topActivity; } } @@ -1270,6 +1269,25 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D return null; } + /** + * Verifies an {@link ActivityRecord} can be the top activity based on keyguard state and + * whether we are considering it. + */ + private boolean isValidTopRunningActivity(ActivityRecord record, + boolean considerKeyguardState) { + if (!considerKeyguardState) { + return true; + } + + final boolean keyguardLocked = getKeyguardController().isKeyguardLocked(); + + if (!keyguardLocked) { + return true; + } + + return record.canShowWhenLocked(); + } + @VisibleForTesting void getRunningTasks(int maxNum, List list, @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode, diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java index 9daea1afc505a..5ed39b4749c55 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityStackSupervisorTests.java @@ -332,13 +332,12 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { } /** - * Verifies the correct activity is returned when querying the top running activity with an - * empty focused stack. + * Verifies the correct activity is returned when querying the top running activity. */ @Test - public void testNonFocusedTopRunningActivity() throws Exception { + public void testTopRunningActivity() throws Exception { // Create stack to hold focus - final ActivityStack focusedStack = mService.mStackSupervisor.getDefaultDisplay() + final ActivityStack emptyStack = mService.mStackSupervisor.getDefaultDisplay() .createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); final KeyguardController keyguard = mSupervisor.getKeyguardController(); @@ -347,7 +346,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { final ActivityRecord activity = new ActivityBuilder(mService).setCreateTask(true) .setStack(stack).build(); - mSupervisor.mFocusedStack = focusedStack; + mSupervisor.mFocusedStack = emptyStack; doAnswer((InvocationOnMock invocationOnMock) -> { final SparseIntArray displayIds = invocationOnMock.getArgument(0); @@ -366,6 +365,12 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { assertEquals(null, mService.mStackSupervisor.topRunningActivityLocked( true /* considerKeyguardState */)); + // Change focus to stack with activity. + mSupervisor.mFocusedStack = stack; + assertEquals(activity, mService.mStackSupervisor.topRunningActivityLocked()); + assertEquals(null, mService.mStackSupervisor.topRunningActivityLocked( + true /* considerKeyguardState */)); + // Add activity that should be shown on the keyguard. final ActivityRecord showWhenLockedActivity = new ActivityBuilder(mService) .setCreateTask(true) @@ -377,5 +382,12 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked()); assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked( true /* considerKeyguardState */)); + + // Change focus back to empty stack + mSupervisor.mFocusedStack = emptyStack; + // Ensure the show when locked activity is returned when not the focused stack + assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked()); + assertEquals(showWhenLockedActivity, mService.mStackSupervisor.topRunningActivityLocked( + true /* considerKeyguardState */)); } }