From f50fb5b1833dbfec6ff53f4a10e80fef61f6aa09 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Tue, 28 Jan 2020 17:12:28 -0500 Subject: [PATCH] Start saving screenshot in background earlier Currently, we only start saving the screenshot after the animation into the corner is complete. Since it takes non-negligible time to save (~.5 seconds, more if smart screenshots don't exit earlier), and we don't pop up the actions shade until we've finished saving, this difference is user-visible. Beginning the async saving task earlier mitigates the apparent delay. Bug: 148605860 Test: manual Change-Id: Icc98fc4f9920fb89cb08654c2ab8ee6f6d3321fa --- .../systemui/screenshot/GlobalScreenshot.java | 42 +++++++++++-------- .../screenshot/SaveImageInBackgroundTask.java | 5 --- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index 880b8f8776e8a..92105fb278a38 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -438,27 +438,35 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset ValueAnimator screenshotDropInAnim = screenRect != null ? createRectAnimation(screenRect) : createScreenshotDropInAnimation(); - ValueAnimator screenshotFadeOutAnim = createScreenshotToCornerAnimation(w, h); + ValueAnimator screenshotToCornerAnimation = createScreenshotToCornerAnimation(w, h); mScreenshotAnimation = new AnimatorSet(); - mScreenshotAnimation.playSequentially(screenshotDropInAnim, screenshotFadeOutAnim); - mScreenshotAnimation.addListener(new AnimatorListenerAdapter() { + mScreenshotAnimation.playSequentially(screenshotDropInAnim, screenshotToCornerAnimation); + + saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { @Override - public void onAnimationEnd(Animator animation) { - // Save the screenshot once we have a bit of time now - saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { - @Override - void onActionsReady(Uri uri, List smartActions, - List actions) { - if (uri == null) { - mNotificationsController.notifyScreenshotError( - R.string.screenshot_failed_to_capture_text); + void onActionsReady(Uri uri, List smartActions, + List actions) { + if (uri == null) { + mNotificationsController.notifyScreenshotError( + R.string.screenshot_failed_to_capture_text); + } else { + mScreenshotHandler.post(() -> { + if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) { + mScreenshotAnimation.addListener( + new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + createScreenshotActionsShadeAnimation( + smartActions, actions).start(); + } + }); } else { - mScreenshotHandler.post(() -> - createScreenshotActionsShadeAnimation(smartActions, - actions).start()); + createScreenshotActionsShadeAnimation(smartActions, + actions).start(); } - } - }); + }); + } mScreenshotHandler.removeMessages(MESSAGE_CORNER_TIMEOUT); mScreenshotHandler.sendMessageDelayed( mScreenshotHandler.obtainMessage(MESSAGE_CORNER_TIMEOUT), diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java b/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java index e6082dddd6c78..1219aadd76d3d 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java @@ -38,7 +38,6 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.ParcelFileDescriptor; -import android.os.Process; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; @@ -124,10 +123,6 @@ class SaveImageInBackgroundTask extends AsyncTask { return null; } - // By default, AsyncTask sets the worker thread to have background thread priority, - // so bump it back up so that we save a little quicker. - Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND); - ContentResolver resolver = mContext.getContentResolver(); Bitmap image = mParams.image; Resources r = mContext.getResources();