From 622ea3beb3627206e4efcd318ee6d2e9ab3f98c3 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 26 May 2023 22:15:32 +0800 Subject: [PATCH] Reduce unnecessary redraw of wallpaper when switching orientation In legacy transition, the wallpaper can change to invisible from: ActivityRecord#onAnimationFinished -> onExitAnimationDone -> hideWallpapers Since shell transition no longer calls onAnimationFinished, it usually relies on the next prepareSurface after the wallpaper target finishes transition. But when launching activity with orientation change, the display transition will execute right after the open transition is done. Then all windows are in transition and wallpaper will keep visible. That causes wallpaper to receive a redraw request for new rotation. But actually the wallpaper target is already invisible. So 1. Check isVisible instead of inTransition because everything is in transition for a display transition. 2. As legacy transition, when committing invisible for the wallpaper target, request to hide wallpaper as well. Then with VisibleRequested=false, it won't be requested to redraw. This also reduces the chance to update wallpaper offset with inconsistent orientation because the wallpaper won't perform relayout to change requested size. Bug: 281973565 Bug: 283952978 Test: Launch landscape app from portrait home. There should not have "finishDrawing of orientation" for wallpaper. And the window frame of wallpaper in dumpsys should still be portrait. Change-Id: Ib84b86784477684bf4a2cebeee70a61f98ae57a0 --- .../core/java/com/android/server/wm/ActivityRecord.java | 9 ++++++++- .../java/com/android/server/wm/WallpaperController.java | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 3db031510317e..2b2100e56f443 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -5630,11 +5630,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A setClientVisible(visible); } + final DisplayContent displayContent = getDisplayContent(); if (!visible) { mImeInsetsFrozenUntilStartInput = true; + if (usingShellTransitions) { + final WindowState wallpaperTarget = + displayContent.mWallpaperController.getWallpaperTarget(); + if (wallpaperTarget != null && wallpaperTarget.mActivityRecord == this) { + displayContent.mWallpaperController.hideWallpapers(wallpaperTarget); + } + } } - final DisplayContent displayContent = getDisplayContent(); if (!displayContent.mClosingApps.contains(this) && !displayContent.mOpeningApps.contains(this) && !fromTransition) { diff --git a/services/core/java/com/android/server/wm/WallpaperController.java b/services/core/java/com/android/server/wm/WallpaperController.java index edafe0606b134..20ce98ca2faee 100644 --- a/services/core/java/com/android/server/wm/WallpaperController.java +++ b/services/core/java/com/android/server/wm/WallpaperController.java @@ -146,11 +146,10 @@ class WallpaperController { } } else { final ActivityRecord ar = w.mActivityRecord; - final TransitionController tc = w.mTransitionController; // The animating window can still be visible on screen if it is in transition, so we // should check whether this window can be wallpaper target even when visibleRequested // is false. - if (ar != null && !ar.isVisibleRequested() && !tc.inTransition(ar)) { + if (ar != null && !ar.isVisibleRequested() && !ar.isVisible()) { // An activity that is not going to remain visible shouldn't be the target. return false; }