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

Commit 1cd1c555 authored by Mark Renouf's avatar Mark Renouf
Browse files

ScrollCaptureConnection: fix npe on close() when active

A reference to the callback was being removed while still
needed. Instead use a local copy for posted callback.

Bug: 12345678
Test: atest ScrollCaptureConnectionTest#testCloseWhileActive
Change-Id: I3a11ac86a8c291972f442ebce962ba8a3a1ddee6
parent 41f4544e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -185,7 +185,8 @@ public class ScrollCaptureConnection extends IScrollCaptureConnection.Stub {
            }
            Log.w(TAG, "close(): capture session still active! Ending now.");
            // -> UiThread
            mUiThread.execute(() -> mLocal.onScrollCaptureEnd(() -> { /* ignore */ }));
            final ScrollCaptureCallback callback = mLocal;
            mUiThread.execute(() -> callback.onScrollCaptureEnd(() -> { /* ignore */ }));
            mActive = false;
        }
        mActive = false;
+12 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.os.Handler;
import android.os.ICancellationSignal;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;

import androidx.test.filters.SmallTest;
@@ -189,4 +190,15 @@ public class ScrollCaptureConnectionTest {
        verifyNoMoreInteractions(mRemote);
    }

    @Test
    public void testClose_whileActive() throws RemoteException {
        mConnection.startCapture(mSurface, mRemote);

        mCallback.completeStartRequest();
        assertTrue(mConnection.isActive());

        mConnection.close();
        mCallback.completeEndRequest();
        assertFalse(mConnection.isActive());
    }
}