[MediaProjection] Immediately clean up mirrored surface.

When MediaProjection is stopped, the VirtualDisplay used to capture
content is released. This triggers DisplayContent#remove, for the
DisplayContent associated with that VirtualDisplay.

Clean up the mirrored surface if the DisplayContent is used for
layer mirroring, to prevent an eventual out of memory error
when MediaProjection is started/stopped several times, and the
garbage collection has not yet cleared up unusued surfaces. Note
the surfaces would be removed eventually, since they no longer
have a reference.

Bug: 197576836
Test: manual
Change-Id: Ic28c0b3deeb1c332c36feaf661342c68c28db192
This commit is contained in:
Naomi Musgrave
2021-08-25 11:35:27 +01:00
parent 0e08f81393
commit 162f78c838

View File

@@ -5786,6 +5786,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
}
mRemoved = true;
if (mMirroredSurface != null) {
// Do not wait for the mirrored surface to be garbage collected, but clean up
// immediately.
mWmService.mTransactionFactory.get().remove(mMirroredSurface).apply();
mMirroredSurface = null;
}
// Only update focus/visibility for the last one because there may be many root tasks are
// reparented and the intermediate states are unnecessary.
if (lastReparentedRootTask != null) {