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

Commit 3ca7900f authored by Mark Renouf's avatar Mark Renouf Committed by Automerger Merge Worker
Browse files

Merge "Fix an NPE on cancellation when connection is closed" into tm-dev am:...

Merge "Fix an NPE on cancellation when connection is closed" into tm-dev am: 21469e70 am: d2b7db49 am: e7963e03 am: 85b8a7c6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17989525



Change-Id: I90254d97b05d91b4febfed6163eba87106401173
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6913701b 85b8a7c6
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -674,15 +674,21 @@ public class ScreenshotController {
        if (mLastScrollCaptureRequest != null) {
            mLastScrollCaptureRequest.cancel(true);
        }
        mLastScrollCaptureRequest = mScrollCaptureClient.request(DEFAULT_DISPLAY);
        final ListenableFuture<ScrollCaptureResponse> future =
                mScrollCaptureClient.request(DEFAULT_DISPLAY);
        mLastScrollCaptureRequest = future;
        mLastScrollCaptureRequest.addListener(() ->
                onScrollCaptureResponseReady(mLastScrollCaptureRequest), mMainExecutor);
                onScrollCaptureResponseReady(future), mMainExecutor);
    }

    private void onScrollCaptureResponseReady(Future<ScrollCaptureResponse> responseFuture) {
        try {
            if (mLastScrollCaptureResponse != null) {
                mLastScrollCaptureResponse.close();
                mLastScrollCaptureResponse = null;
            }
            if (responseFuture.isCancelled()) {
                return;
            }
            mLastScrollCaptureResponse = responseFuture.get();
            if (!mLastScrollCaptureResponse.isConnected()) {
@@ -707,8 +713,6 @@ public class ScreenshotController {
                // delay starting scroll capture to make sure the scrim is up before the app moves
                mScreenshotView.post(() -> runBatchScrollCapture(response));
            });
        } catch (CancellationException e) {
            // Ignore
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "requestScrollCapture failed", e);
        }