From c4b1aa4733e949450df6d5d51f9c4b0c725e3dfb Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Tue, 15 Nov 2022 02:22:39 +0000 Subject: [PATCH] Clear the focused app after reset adjacent TaskFragments The TaskFragments were stacked when the device folded. So, the focused app was occluded and became invisible. In that case, there was no focused window and ANR happened. Clear the focused app if the focused app became invisible after resetting the adjacent TaskFragments. Bug: 255631222 Test: locally verified by changing display size Change-Id: I3048824d6df8b63ea9a0f46e9167d9e5fc0da580 --- .../com/android/server/wm/WindowOrganizerController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java index 32a110ea530e1..37d6fe822c6f5 100644 --- a/services/core/java/com/android/server/wm/WindowOrganizerController.java +++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java @@ -975,6 +975,14 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub tf1.setAdjacentTaskFragment(tf2); effects |= TRANSACT_EFFECTS_LIFECYCLE; + // Clear the focused app if the focused app is no longer visible after reset the + // adjacent TaskFragments. + if (tf2 == null && tf1.getDisplayContent().mFocusedApp != null + && tf1.hasChild(tf1.getDisplayContent().mFocusedApp) + && !tf1.shouldBeVisible(null /* starting */)) { + tf1.getDisplayContent().setFocusedApp(null); + } + final Bundle bundle = hop.getLaunchOptions(); final WindowContainerTransaction.TaskFragmentAdjacentParams adjacentParams = bundle != null ? new WindowContainerTransaction.TaskFragmentAdjacentParams(