From d2e91bace47b65cb2869795ed43329296713c985 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 29 Apr 2021 16:23:58 -0700 Subject: [PATCH] Take screenshot on ui helper thread in live tile - Unify the live tile/non-live tile flow for taking a screenshot and post it to the ui helper thread Bug: 186455799 Test: Test to verify that snapshots are still updated correctly Change-Id: I26759419adf89c73602589da531bbc494b5c29e3 --- .../android/quickstep/AbsSwipeUpHandler.java | 34 ++++++++----------- .../android/quickstep/views/RecentsView.java | 5 --- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 53f1fd0809..a20de10279 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -1408,23 +1408,17 @@ public abstract class AbsSwipeUpHandler, } protected void switchToScreenshot() { - final int runningTaskId = mGestureState.getRunningTaskId(); - if (LIVE_TILE.get()) { - if (mRecentsAnimationController != null) { - mRecentsAnimationController.getController().setWillFinishToHome(true); - // Update the screenshot of the task - if (mTaskSnapshot == null) { - mTaskSnapshot = mRecentsAnimationController.screenshotTask(runningTaskId); - } - mRecentsView.updateThumbnail(runningTaskId, mTaskSnapshot, false /* refreshNow */); - } - mStateCallback.setStateOnUiThread(STATE_SCREENSHOT_CAPTURED); - } else if (!hasTargets()) { + if (!hasTargets()) { // If there are no targets, then we don't need to capture anything mStateCallback.setStateOnUiThread(STATE_SCREENSHOT_CAPTURED); } else { + final int runningTaskId = mGestureState.getRunningTaskId(); + final boolean refreshView = !LIVE_TILE.get() /* refreshView */; boolean finishTransitionPosted = false; if (mRecentsAnimationController != null) { + if (LIVE_TILE.get()) { + mRecentsAnimationController.getController().setWillFinishToHome(true); + } // Update the screenshot of the task if (mTaskSnapshot == null) { UI_HELPER_EXECUTOR.execute(() -> { @@ -1433,14 +1427,14 @@ public abstract class AbsSwipeUpHandler, mRecentsAnimationController.screenshotTask(runningTaskId); MAIN_EXECUTOR.execute(() -> { mTaskSnapshot = taskSnapshot; - if (!updateThumbnail(runningTaskId)) { + if (!updateThumbnail(runningTaskId, refreshView)) { setScreenshotCapturedState(); } }); }); return; } - finishTransitionPosted = updateThumbnail(runningTaskId); + finishTransitionPosted = updateThumbnail(runningTaskId, refreshView); } if (!finishTransitionPosted) { setScreenshotCapturedState(); @@ -1449,17 +1443,17 @@ public abstract class AbsSwipeUpHandler, } // Returns whether finish transition was posted. - private boolean updateThumbnail(int runningTaskId) { + private boolean updateThumbnail(int runningTaskId, boolean refreshView) { boolean finishTransitionPosted = false; final TaskView taskView; - if (mGestureState.getEndTarget() == HOME) { - // Capture the screenshot before finishing the transition to home to ensure it's - // taken in the correct orientation, but no need to update the thumbnail. + if (mGestureState.getEndTarget() == HOME || mGestureState.getEndTarget() == NEW_TASK) { + // Capture the screenshot before finishing the transition to home or quickswitching to + // ensure it's taken in the correct orientation, but no need to update the thumbnail. taskView = null; } else { - taskView = mRecentsView.updateThumbnail(runningTaskId, mTaskSnapshot); + taskView = mRecentsView.updateThumbnail(runningTaskId, mTaskSnapshot, refreshView); } - if (taskView != null && !mCanceled) { + if (taskView != null && refreshView && !mCanceled) { // Defer finishing the animation until the next launcher frame with the // new thumbnail finishTransitionPosted = ViewUtils.postFrameDrawn(taskView, diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 596f74688d..f6749d5b19 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -702,11 +702,6 @@ public abstract class RecentsView