Compute visibilities when finishing show-when-lock activity

The activity visibilities was not updated in KeyguardController
while a show-when-locked activity was finished. Therefore, the
general activity below was resumed for a short time and flickering
the screen with transition animation.

Bug: 149837574
Test: start emergency dialer and exit
Test: atest ActivityRecordTests
Change-Id: I7cea9d3e00a856c392728c7a8c825d4633b73f55
This commit is contained in:
Louis Chang
2020-04-09 16:51:02 +08:00
parent ec38d551e3
commit 3d718c30c6
2 changed files with 45 additions and 0 deletions

View File

@@ -2656,6 +2656,17 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
return this;
}
// Ensure activity visibilities and update lockscreen occluded/dismiss state when
// finishing the top activity that occluded keyguard. So that, the
// ActivityStack#mTopActivityOccludesKeyguard can be updated and the activity below won't
// be resumed.
if (isState(PAUSED)
&& mStackSupervisor.getKeyguardController().isKeyguardLocked()
&& getStack().topActivityOccludesKeyguard()) {
getStack().ensureActivitiesVisible(null /* starting */, 0 /* configChanges */,
false /* preserveWindows */, false /* notifyClients */);
}
boolean activityRemoved = false;
// If this activity is currently visible, and the resumed activity is not yet visible, then

View File

@@ -32,6 +32,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
@@ -63,6 +64,7 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
@@ -1023,6 +1025,38 @@ public class ActivityRecordTests extends ActivityTestsBase {
verify(topActivity).destroyIfPossible(anyString());
}
/**
* Verify that complete finish request for a show-when-locked activity must ensure the
* keyguard occluded state being updated.
*/
@Test
public void testCompleteFinishing_showWhenLocked() {
// Make keyguard locked and set the top activity show-when-locked.
KeyguardController keyguardController = mActivity.mStackSupervisor.getKeyguardController();
doReturn(true).when(keyguardController).isKeyguardLocked();
final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build();
topActivity.mVisibleRequested = true;
topActivity.nowVisible = true;
topActivity.setState(RESUMED, "true");
doCallRealMethod().when(mRootWindowContainer).ensureActivitiesVisible(
any() /* starting */, anyInt() /* configChanges */,
anyBoolean() /* preserveWindows */, anyBoolean() /* notifyClients */);
topActivity.setShowWhenLocked(true);
// Verify the stack-top activity is occluded keyguard.
assertEquals(topActivity, mStack.topRunningActivity());
assertTrue(mStack.topActivityOccludesKeyguard());
// Finish the top activity
topActivity.setState(PAUSED, "true");
topActivity.finishing = true;
topActivity.completeFinishing("test");
// Verify new top activity does not occlude keyguard.
assertEquals(mActivity, mStack.topRunningActivity());
assertFalse(mStack.topActivityOccludesKeyguard());
}
/**
* Verify destroy activity request completes successfully.
*/