From 0c9aed677530fbc54ffdd385a5f37ac186283daa Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Wed, 26 Jan 2022 16:39:34 -0800 Subject: [PATCH] Wait for attachment in Activity syncEngine There is a race between starting-window finishDraw and app attachment on cold-start. If the starting-window finishes first, the transition won't know if there is an associated display rotation. This results in the launch transition playing early but into the wrong rotation. Once the app does attach, a new transition will be created for the display rotation yielding an ugly animation. Solve this by just waiting for attachment before reporting syncFinished (after checking visibleRequested). Bug: 202201326 Test: cold-launch activity into a different rotation many times and observe 1 transition instead of 2. Change-Id: I744e8d35b4a11200be2374ca923ed9606e619977 --- services/core/java/com/android/server/wm/ActivityRecord.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 49d6a344419ff..18c1baba6b825 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -9350,6 +9350,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A boolean isSyncFinished() { if (!super.isSyncFinished()) return false; if (!isVisibleRequested()) return true; + // Wait for attach. That is the earliest time where we know if there will be an associated + // display rotation. If we don't wait, the starting-window can finishDrawing first and + // cause the display rotation to end-up in a following transition. + if (!isAttached()) return false; // If visibleRequested, wait for at-least one visible child. for (int i = mChildren.size() - 1; i >= 0; --i) { if (mChildren.get(i).isVisibleRequested()) {