From 6c04f9b6da88021675611ce4f504a8337749d8c3 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 18 Jan 2022 15:40:25 +0800 Subject: [PATCH] Fix leakage of DisplayContent referenced from TransitionController Unlike AppTransition which is associated DisplayContent, the TransitionController is a global instance. So it needs to unregister the listener when the display is removed. Bug: 214991741 Test: Start/stop screen recording multiple times (create virtual display). The heap dump of system server should not contain many DisplayContent instances. (cherry picked from commit 491914c17c869a174f91d0414181d1be11e040a3) (cherry picked from commit c3eaf662257919343210b96f5d5aef161df0723e) Merged-In: I44e2a794981fc114ada0ce98cd2471adf623d856 Change-Id: I44e2a794981fc114ada0ce98cd2471adf623d856 --- services/core/java/com/android/server/wm/DisplayContent.java | 2 -- services/core/java/com/android/server/wm/DisplayPolicy.java | 1 + .../core/java/com/android/server/wm/TransitionController.java | 4 ++++ .../java/com/android/server/wm/WindowOrganizerController.java | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 40549548da62..1e31fdab30d0 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -1067,8 +1067,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mAppTransition = new AppTransition(mWmService.mContext, mWmService, this); mAppTransition.registerListenerLocked(mWmService.mActivityManagerAppTransitionNotifier); - mTransitionController.registerLegacyListener( - mWmService.mActivityManagerAppTransitionNotifier); mAppTransition.registerListenerLocked(mFixedRotationTransitionListener); mAppTransitionController = new AppTransitionController(mWmService, this); mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this); diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java index ef3c5a3df84e..1ff2ebeb8c14 100644 --- a/services/core/java/com/android/server/wm/DisplayPolicy.java +++ b/services/core/java/com/android/server/wm/DisplayPolicy.java @@ -3311,6 +3311,7 @@ public class DisplayPolicy { } void release() { + mDisplayContent.mTransitionController.unregisterLegacyListener(mAppTransitionListener); mHandler.post(mGestureNavigationSettingsObserver::unregister); } diff --git a/services/core/java/com/android/server/wm/TransitionController.java b/services/core/java/com/android/server/wm/TransitionController.java index e05457010df8..929ec3b929b2 100644 --- a/services/core/java/com/android/server/wm/TransitionController.java +++ b/services/core/java/com/android/server/wm/TransitionController.java @@ -430,6 +430,10 @@ class TransitionController { mLegacyListeners.add(listener); } + void unregisterLegacyListener(WindowManagerInternal.AppTransitionListener listener) { + mLegacyListeners.remove(listener); + } + void dispatchLegacyAppTransitionPending() { for (int i = 0; i < mLegacyListeners.size(); ++i) { mLegacyListeners.get(i).onAppTransitionPendingLocked(); diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java index 42766bdb0732..6970c7942a50 100644 --- a/services/core/java/com/android/server/wm/WindowOrganizerController.java +++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java @@ -137,6 +137,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub void setWindowManager(WindowManagerService wms) { mTransitionController = new TransitionController(mService, wms.mTaskSnapshotController); + mTransitionController.registerLegacyListener(wms.mActivityManagerAppTransitionNotifier); } TransitionController getTransitionController() {