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

Commit 85b8a7c6 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

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



Change-Id: I1f00b0f21a043480db16d99cfabb3872df01f529
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7af59a96 e7963e03
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);
        }