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

Commit e7963e03 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

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



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


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