From 07ce971bb3229b60851a36f3980b9273c14ebea0 Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Wed, 11 May 2022 16:02:11 +0800 Subject: [PATCH] Fix starting window isn't removed In multi-window scenario, there's a case that the Activity that can't be starting window target is the last Activity to draw the first window, which blocks starting window removal. Also, when the Activity finally draws its first window, it can't remove the starting window because it doesn't conatain starting window information. This CL changes to only verify activities which can be the starting window target. That said, activities that can't be the starting window won't block starting window removal. Test: atest ActivityRecordTests Test: manual - reproducible steps in bug Bug: 228194878 Change-Id: Ibc004ca079f0b04609183cd3b6630d70662fdef5 --- .../core/java/com/android/server/wm/ActivityRecord.java | 6 ++++-- .../src/com/android/server/wm/ActivityRecordTests.java | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 6bb7acd651434..7d4a996157d22 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -6340,8 +6340,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A mSharedStartingData != null ? mSharedStartingData.mAssociatedTask : null; if (associatedTask == null) { removeStartingWindow(); - } else if (associatedTask.getActivity( - r -> r.mVisibleRequested && !r.firstWindowDrawn) == null) { + } else if (associatedTask.getActivity(r -> r.mVisibleRequested && !r.firstWindowDrawn + // Don't block starting window removal if an Activity can't be a starting window + // target. + && r.mSharedStartingData != null) == null) { // The last drawn activity may not be the one that owns the starting window. final ActivityRecord r = associatedTask.topActivityContainsStartingWindow(); if (r != null) { diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 533540e2568d8..2b4e4c3c633ad 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -2854,6 +2854,11 @@ public class ActivityRecordTests extends WindowTestsBase { assertTrue(activity2.isResizeable()); activity1.reparent(taskFragment1, POSITION_TOP); + // Adds an Activity which doesn't have shared starting data, and verify if it blocks + // starting window removal. + final ActivityRecord activity3 = new ActivityBuilder(mAtm).build(); + taskFragment2.addChild(activity3, POSITION_TOP); + verify(activity1.getSyncTransaction()).reparent(eq(startingWindow.mSurfaceControl), eq(task.mSurfaceControl)); assertEquals(activity1.mStartingData, startingWindow.mStartingData);