From 352aa3d13c8566c114b3fdd4233927a27889c42f Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 18 Aug 2023 18:20:42 +0800 Subject: [PATCH] Remove host activity association when removing EmbeddedWindow The common steps to destroy an activity is first to remove its window and then the activity record. So if EmbeddedWindow is removed when removing the window, onActivityRemoved won't be able to match. If an ActivityRecord is removed, its window will also be removed. So it can simply clean the host records when removing EmbeddedWindow. Bug: 296535363 Test: Launch "Wallpaper & style" from home several times. > adb shell dumpsys activity p | grep -A2 "Remote Activities" The output should only show one record per owner process. And then remove the task from recents. > adb shell dumpsys activity p | grep "Remote Activities" The output should be empty. Change-Id: Iebe96417ed5be1832995ad7649408c28e6c0f58c --- .../com/android/server/wm/ActivityRecord.java | 1 - .../server/wm/EmbeddedWindowController.java | 20 +++++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 5a6851ea196c2..37e4902d9d8e3 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -4364,7 +4364,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // Reset the last saved PiP snap fraction on removal. mDisplayContent.mPinnedTaskController.onActivityHidden(mActivityComponent); mDisplayContent.onRunningActivityChanged(); - mWmService.mEmbeddedWindowController.onActivityRemoved(this); mRemovingFromDisplay = false; } diff --git a/services/core/java/com/android/server/wm/EmbeddedWindowController.java b/services/core/java/com/android/server/wm/EmbeddedWindowController.java index 98027bbed37f1..c9bae127b8008 100644 --- a/services/core/java/com/android/server/wm/EmbeddedWindowController.java +++ b/services/core/java/com/android/server/wm/EmbeddedWindowController.java @@ -135,19 +135,6 @@ class EmbeddedWindowController { return mWindowsByWindowToken.get(windowToken); } - void onActivityRemoved(ActivityRecord activityRecord) { - for (int i = mWindows.size() - 1; i >= 0; i--) { - final EmbeddedWindow window = mWindows.valueAt(i); - if (window.mHostActivityRecord == activityRecord) { - final WindowProcessController processController = - mAtmService.getProcessController(window.mOwnerPid, window.mOwnerUid); - if (processController != null) { - processController.removeHostActivity(activityRecord); - } - } - } - } - static class EmbeddedWindow implements InputTarget { final IWindow mClient; @Nullable final WindowState mHostWindowState; @@ -230,6 +217,13 @@ class EmbeddedWindowController { mInputChannel.dispose(); mInputChannel = null; } + if (mHostActivityRecord != null) { + final WindowProcessController wpc = + mWmService.mAtmService.getProcessController(mOwnerPid, mOwnerUid); + if (wpc != null) { + wpc.removeHostActivity(mHostActivityRecord); + } + } } @Override