From 327e14505353a2e7a94a66f11838967516e75310 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 22 Mar 2021 17:04:27 +0800 Subject: [PATCH] Take snapshot when device becomes dozing and pulsing The device supports pulsing won't turn the screen off when sleeping (TaskSnapshotController#screenTurningOff is not called). So add another path to take a snapshot to avoid showing inconsistent animation when unlocking. Bug: 182571838 Test: 1. Enable "Always show time and info". 2. Open any app and go to home. 3. Launch the app again and make some changes to its content. 4. Press power key to enter dozing. 5. Unlock and check if the animation has the latest content. Change-Id: I97aaed519091fa6e9d8fd4862301fcb3186efe14 --- .../android/server/wm/KeyguardController.java | 5 +++ .../server/wm/TaskSnapshotController.java | 36 +++++++++++-------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/wm/KeyguardController.java b/services/core/java/com/android/server/wm/KeyguardController.java index b31c2e462766f..20216c3afcd49 100644 --- a/services/core/java/com/android/server/wm/KeyguardController.java +++ b/services/core/java/com/android/server/wm/KeyguardController.java @@ -167,6 +167,11 @@ class KeyguardController { if (aodChanged) { // Ensure the new state takes effect. mWindowManager.mWindowPlacerLocked.performSurfacePlacement(); + // If the device can enter AOD and keyguard at the same time, the screen will not be + // turned off, so the snapshot needs to be refreshed when these states are changed. + if (aodShowing && keyguardShowing && keyguardChanged) { + mWindowManager.mTaskSnapshotController.snapshotForSleeping(DEFAULT_DISPLAY); + } } if (keyguardChanged) { diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java index 8915eba3d509a..5af44317b8c1f 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotController.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java @@ -635,20 +635,7 @@ class TaskSnapshotController { mHandler.post(() -> { try { synchronized (mService.mGlobalLock) { - mTmpTasks.clear(); - mService.mRoot.getDisplayContent(displayId).forAllTasks(task -> { - // Since RecentsAnimation will handle task snapshot while switching apps - // with the best capture timing (e.g. IME window capture), No need - // additional task capture while task is controlled by RecentsAnimation. - if (task.isVisible() && !task.isAnimatingByRecents()) { - mTmpTasks.add(task); - } - }); - // Allow taking snapshot of home when turning screen off to reduce the delay of - // waking from secure lock to home. - final boolean allowSnapshotHome = displayId == Display.DEFAULT_DISPLAY && - mService.mPolicy.isKeyguardSecure(mService.mCurrentUserId); - snapshotTasks(mTmpTasks, allowSnapshotHome); + snapshotForSleeping(displayId); } } finally { listener.onScreenOff(); @@ -656,6 +643,27 @@ class TaskSnapshotController { }); } + /** Called when the device is going to sleep (e.g. screen off, AOD without screen off). */ + void snapshotForSleeping(int displayId) { + if (shouldDisableSnapshots()) { + return; + } + mTmpTasks.clear(); + mService.mRoot.getDisplayContent(displayId).forAllTasks(task -> { + // Since RecentsAnimation will handle task snapshot while switching apps with the best + // capture timing (e.g. IME window capture), No need additional task capture while task + // is controlled by RecentsAnimation. + if (task.isVisible() && !task.isAnimatingByRecents()) { + mTmpTasks.add(task); + } + }); + // Allow taking snapshot of home when turning screen off to reduce the delay of waking from + // secure lock to home. + final boolean allowSnapshotHome = displayId == Display.DEFAULT_DISPLAY + && mService.mPolicy.isKeyguardSecure(mService.mCurrentUserId); + snapshotTasks(mTmpTasks, allowSnapshotHome); + } + /** * @return The {@link Appearance} flags for the top fullscreen opaque window in the given * {@param task}.