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 491914c17c)
(cherry picked from commit c3eaf66225)
Merged-In: I44e2a794981fc114ada0ce98cd2471adf623d856
Change-Id: I44e2a794981fc114ada0ce98cd2471adf623d856
This commit is contained in:
Riddle Hsu
2022-01-18 15:40:25 +08:00
committed by Xin Li
parent 941c4a4af0
commit 6c04f9b6da
4 changed files with 6 additions and 2 deletions

View File

@@ -1067,8 +1067,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mAppTransition = new AppTransition(mWmService.mContext, mWmService, this); mAppTransition = new AppTransition(mWmService.mContext, mWmService, this);
mAppTransition.registerListenerLocked(mWmService.mActivityManagerAppTransitionNotifier); mAppTransition.registerListenerLocked(mWmService.mActivityManagerAppTransitionNotifier);
mTransitionController.registerLegacyListener(
mWmService.mActivityManagerAppTransitionNotifier);
mAppTransition.registerListenerLocked(mFixedRotationTransitionListener); mAppTransition.registerListenerLocked(mFixedRotationTransitionListener);
mAppTransitionController = new AppTransitionController(mWmService, this); mAppTransitionController = new AppTransitionController(mWmService, this);
mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this); mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this);

View File

@@ -3311,6 +3311,7 @@ public class DisplayPolicy {
} }
void release() { void release() {
mDisplayContent.mTransitionController.unregisterLegacyListener(mAppTransitionListener);
mHandler.post(mGestureNavigationSettingsObserver::unregister); mHandler.post(mGestureNavigationSettingsObserver::unregister);
} }

View File

@@ -430,6 +430,10 @@ class TransitionController {
mLegacyListeners.add(listener); mLegacyListeners.add(listener);
} }
void unregisterLegacyListener(WindowManagerInternal.AppTransitionListener listener) {
mLegacyListeners.remove(listener);
}
void dispatchLegacyAppTransitionPending() { void dispatchLegacyAppTransitionPending() {
for (int i = 0; i < mLegacyListeners.size(); ++i) { for (int i = 0; i < mLegacyListeners.size(); ++i) {
mLegacyListeners.get(i).onAppTransitionPendingLocked(); mLegacyListeners.get(i).onAppTransitionPendingLocked();

View File

@@ -137,6 +137,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
void setWindowManager(WindowManagerService wms) { void setWindowManager(WindowManagerService wms) {
mTransitionController = new TransitionController(mService, wms.mTaskSnapshotController); mTransitionController = new TransitionController(mService, wms.mTaskSnapshotController);
mTransitionController.registerLegacyListener(wms.mActivityManagerAppTransitionNotifier);
} }
TransitionController getTransitionController() { TransitionController getTransitionController() {