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.
Change-Id: I44e2a794981fc114ada0ce98cd2471adf623d856
(cherry picked from commit 491914c17c)
Merged-In:I44e2a794981fc114ada0ce98cd2471adf623d856
This commit is contained in:
Riddle Hsu
2022-01-18 15:40:25 +08:00
committed by Android Build Coastguard Worker
parent 10925e6bf5
commit c3eaf66225
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.registerListenerLocked(mWmService.mActivityManagerAppTransitionNotifier);
mTransitionController.registerLegacyListener(
mWmService.mActivityManagerAppTransitionNotifier);
mAppTransition.registerListenerLocked(mFixedRotationTransitionListener);
mAppTransitionController = new AppTransitionController(mWmService, this);
mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this);

View File

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

View File

@@ -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();

View File

@@ -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() {