diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java index 009d4b9b48e60..4728c678f96c6 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotController.java @@ -674,15 +674,21 @@ public class ScreenshotController { if (mLastScrollCaptureRequest != null) { mLastScrollCaptureRequest.cancel(true); } - mLastScrollCaptureRequest = mScrollCaptureClient.request(DEFAULT_DISPLAY); + final ListenableFuture future = + mScrollCaptureClient.request(DEFAULT_DISPLAY); + mLastScrollCaptureRequest = future; mLastScrollCaptureRequest.addListener(() -> - onScrollCaptureResponseReady(mLastScrollCaptureRequest), mMainExecutor); + onScrollCaptureResponseReady(future), mMainExecutor); } private void onScrollCaptureResponseReady(Future 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); }