Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecb3891d authored by Kean Mariotti's avatar Kean Mariotti
Browse files

viewcapture: fix NPE (WindowListener#mRoot)

WindowListener#onDraw() assumes that mRoot != null which may not be true
when the capture is being stopped, i.e. when a non-UI thread is setting
"mRoot = null" while the UI thread is executing WindowListener#onDraw().

Bug: 391977087
Flag: EXEMPT minor bugfix
Test: check the NPE doesn't happen again on the lab
Change-Id: I6a7c979e1862beb27e204baf30c1d33c93b0c2a5
parent 66f97f4a
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -328,7 +328,14 @@ public abstract class ViewCapture {
        @UiThread
        public void onDraw() {
            Trace.beginSection("vc#onDraw");
            captureViewTree(mRoot, mViewPropertyRef);
            try {
                View root = mRoot;
                if (root == null) {
                    // Handle the corner case where another (non-UI) thread
                    // concurrently stopped the capture and set mRoot = null
                    return;
                }
                captureViewTree(root, mViewPropertyRef);
                ViewPropertyRef captured = mViewPropertyRef.next;
                if (captured != null) {
                    captured.callback = mCaptureCallback;
@@ -336,8 +343,10 @@ public abstract class ViewCapture {
                    mBgExecutor.execute(captured);
                }
                mIsFirstFrame = false;
            } finally {
                Trace.endSection();
            }
        }

        /**
         * Copy clean views from the last frame on the background thread. Clean views are