From 2204746d08c855aa4b62488ad88e3acfbf9902f5 Mon Sep 17 00:00:00 2001 From: lijilou Date: Tue, 17 Dec 2024 15:25:51 +0800 Subject: ContentRecorder: fix NPE problem to avoid crash when start recording. The getSurfaceControl method of WindowContainer may be return null in some suition. Test: OEM monkey test Flag: EXEMPT bugfix Bug: 384619345 Change-Id: I7930adfb3424f4b477513d2d00b4d7058216546d --- .../core/java/com/android/server/wm/ContentRecorder.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/ContentRecorder.java b/services/core/java/com/android/server/wm/ContentRecorder.java index 0aca51184565..1b4898665ebf 100644 --- a/services/core/java/com/android/server/wm/ContentRecorder.java +++ b/services/core/java/com/android/server/wm/ContentRecorder.java @@ -350,6 +350,15 @@ final class ContentRecorder implements WindowContainerListener { return; } + final SurfaceControl sourceSurface = mRecordedWindowContainer.getSurfaceControl(); + if (sourceSurface == null || !sourceSurface.isValid()) { + ProtoLog.v(WM_DEBUG_CONTENT_RECORDING, + "Content Recording: Unable to start recording for display %d since the " + + "surface is null or have been released.", + mDisplayContent.getDisplayId()); + return; + } + final int contentToRecord = mContentRecordingSession.getContentToRecord(); // TODO(b/297514518) Do not start capture if the app is in PIP, the bounds are inaccurate. @@ -377,8 +386,7 @@ final class ContentRecorder implements WindowContainerListener { mDisplayContent.getDisplayId(), mDisplayContent.getDisplayInfo().state); // Create a mirrored hierarchy for the SurfaceControl of the DisplayArea to capture. - mRecordedSurface = SurfaceControl.mirrorSurface( - mRecordedWindowContainer.getSurfaceControl()); + mRecordedSurface = SurfaceControl.mirrorSurface(sourceSurface); SurfaceControl.Transaction transaction = mDisplayContent.mWmService.mTransactionFactory.get() // Set the mMirroredSurface's parent to the root SurfaceControl for this -- cgit v1.2.3-59-g8ed1b