From 3f15a82e5b7a25b0e9c11bba74effbff89dc8602 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 9 Mar 2021 12:13:31 +0800 Subject: [PATCH] Do not consider finishing dream activity as occluded Otherwise it causes the next activity to be visible with redundant lifecycles. And if screen orientation is changed, the next activity may get wrong configuration by performing relayout with intermediate visibility. Test: 1. Enable dream, off/on screen and wait screen timeout. 2. Rotate device, touch dream activity and unlock keyguard. Check that home activity shows with correct layout. Bug: 181837363 Change-Id: I46aac2f2ca4208de39ace98fc8bc3917d13880ac --- .../android/server/wm/KeyguardController.java | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/services/core/java/com/android/server/wm/KeyguardController.java b/services/core/java/com/android/server/wm/KeyguardController.java index 57f263885ef2f..b31c2e462766f 100644 --- a/services/core/java/com/android/server/wm/KeyguardController.java +++ b/services/core/java/com/android/server/wm/KeyguardController.java @@ -16,6 +16,7 @@ package com.android.server.wm; +import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; import static android.view.Display.DEFAULT_DISPLAY; @@ -524,40 +525,36 @@ class KeyguardController { boolean occludedByActivity = false; final Task task = getRootTaskForControllingOccluding(display); - if (task != null) { - final ActivityRecord r = task.getTopNonFinishingActivity(); - if (r != null) { - final boolean showWhenLocked = r.canShowWhenLocked(); - if (r.containsDismissKeyguardWindow()) { - mDismissingKeyguardActivity = r; - } - if (r.getTurnScreenOnFlag() - && r.currentLaunchCanTurnScreenOn()) { - mTopTurnScreenOnActivity = r; - } + final ActivityRecord top = task != null ? task.getTopNonFinishingActivity() : null; + if (top != null) { + if (top.containsDismissKeyguardWindow()) { + mDismissingKeyguardActivity = top; + } + if (top.getTurnScreenOnFlag() && top.currentLaunchCanTurnScreenOn()) { + mTopTurnScreenOnActivity = top; + } - if (showWhenLocked) { - mTopOccludesActivity = r; - } + final boolean showWhenLocked = top.canShowWhenLocked(); + if (showWhenLocked) { + mTopOccludesActivity = top; + } - // Only the top activity may control occluded, as we can't occlude the Keyguard - // if the top app doesn't want to occlude it. - occludedByActivity = showWhenLocked || (mDismissingKeyguardActivity != null - && task.topRunningActivity() == mDismissingKeyguardActivity - && controller.canShowWhileOccluded( - true /* dismissKeyguard */, false /* showWhenLocked */)); - // FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD only apply for secondary display. - if (mDisplayId != DEFAULT_DISPLAY && task.mDisplayContent != null) { - occludedByActivity |= - task.mDisplayContent.canShowWithInsecureKeyguard() - && controller.canDismissKeyguard(); - } + // Only the top activity may control occluded, as we can't occlude the Keyguard + // if the top app doesn't want to occlude it. + occludedByActivity = showWhenLocked || (mDismissingKeyguardActivity != null + && task.topRunningActivity() == mDismissingKeyguardActivity + && controller.canShowWhileOccluded( + true /* dismissKeyguard */, false /* showWhenLocked */)); + // FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD only apply for secondary display. + if (mDisplayId != DEFAULT_DISPLAY) { + occludedByActivity |= display.canShowWithInsecureKeyguard() + && controller.canDismissKeyguard(); } } - // TODO(b/123372519): isShowingDream can only works on default display. - mOccluded = occludedByActivity || (mDisplayId == DEFAULT_DISPLAY - && mService.mRootWindowContainer.getDefaultDisplay() - .getDisplayPolicy().isShowingDreamLw()); + + final boolean dreaming = display.getDisplayPolicy().isShowingDreamLw() && (top != null + && top.getActivityType() == ACTIVITY_TYPE_DREAM); + mOccluded = dreaming || occludedByActivity; mRequestDismissKeyguard = lastDismissKeyguardActivity != mDismissingKeyguardActivity && !mOccluded && mDismissingKeyguardActivity != null