From 162f78c838c484af0cd10e4755a724882dcc027d Mon Sep 17 00:00:00 2001 From: Naomi Musgrave Date: Wed, 25 Aug 2021 11:35:27 +0100 Subject: [PATCH] [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 --- .../core/java/com/android/server/wm/DisplayContent.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 74287c415f302..62a6f39a45025 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -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) {