Fix lock contention while swiping up
- Don't lock when making WM calls (only lock when resetting), and use own executor since the background executor is fixed to only two threads and other things can be running on them already (like task loading). Bug: 78585335 Change-Id: I73dfc380dd99908cfc30ff7c164a9677a5a126e0
This commit is contained in:
@@ -15,27 +15,32 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.quickstep;
|
package com.android.quickstep;
|
||||||
|
|
||||||
|
import com.android.launcher3.util.LooperExecutor;
|
||||||
import com.android.launcher3.util.TraceHelper;
|
import com.android.launcher3.util.TraceHelper;
|
||||||
|
import com.android.launcher3.util.UiThreadHelper;
|
||||||
import com.android.quickstep.util.RemoteAnimationTargetSet;
|
import com.android.quickstep.util.RemoteAnimationTargetSet;
|
||||||
import com.android.systemui.shared.system.BackgroundExecutor;
|
|
||||||
import com.android.systemui.shared.system.RecentsAnimationControllerCompat;
|
import com.android.systemui.shared.system.RecentsAnimationControllerCompat;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around RecentsAnimationController to help with some synchronization
|
* Wrapper around RecentsAnimationController to help with some synchronization
|
||||||
*/
|
*/
|
||||||
public class RecentsAnimationWrapper {
|
public class RecentsAnimationWrapper {
|
||||||
|
|
||||||
public RecentsAnimationControllerCompat controller;
|
|
||||||
public RemoteAnimationTargetSet targetSet;
|
public RemoteAnimationTargetSet targetSet;
|
||||||
|
|
||||||
|
private RecentsAnimationControllerCompat mController;
|
||||||
private boolean mInputConsumerEnabled = false;
|
private boolean mInputConsumerEnabled = false;
|
||||||
private boolean mBehindSystemBars = true;
|
private boolean mBehindSystemBars = true;
|
||||||
private boolean mSplitScreenMinimized = false;
|
private boolean mSplitScreenMinimized = false;
|
||||||
|
|
||||||
|
private final ExecutorService mExecutorService =
|
||||||
|
new LooperExecutor(UiThreadHelper.getBackgroundLooper());
|
||||||
|
|
||||||
public synchronized void setController(
|
public synchronized void setController(
|
||||||
RecentsAnimationControllerCompat controller, RemoteAnimationTargetSet targetSet) {
|
RecentsAnimationControllerCompat controller, RemoteAnimationTargetSet targetSet) {
|
||||||
TraceHelper.partitionSection("RecentsController", "Set controller " + controller);
|
TraceHelper.partitionSection("RecentsController", "Set controller " + controller);
|
||||||
this.controller = controller;
|
this.mController = controller;
|
||||||
this.targetSet = targetSet;
|
this.targetSet = targetSet;
|
||||||
|
|
||||||
if (mInputConsumerEnabled) {
|
if (mInputConsumerEnabled) {
|
||||||
@@ -48,17 +53,16 @@ public class RecentsAnimationWrapper {
|
|||||||
* on the background thread.
|
* on the background thread.
|
||||||
*/
|
*/
|
||||||
public void finish(boolean toHome, Runnable onFinishComplete) {
|
public void finish(boolean toHome, Runnable onFinishComplete) {
|
||||||
BackgroundExecutor.get().submit(() -> {
|
mExecutorService.submit(() -> {
|
||||||
synchronized (this) {
|
RecentsAnimationControllerCompat controller = mController;
|
||||||
TraceHelper.endSection("RecentsController",
|
mController = null;
|
||||||
"Finish " + controller + ", toHome=" + toHome);
|
TraceHelper.endSection("RecentsController",
|
||||||
if (controller != null) {
|
"Finish " + controller + ", toHome=" + toHome);
|
||||||
controller.setInputConsumerEnabled(false);
|
if (controller != null) {
|
||||||
controller.finish(toHome);
|
controller.setInputConsumerEnabled(false);
|
||||||
if (onFinishComplete != null) {
|
controller.finish(toHome);
|
||||||
onFinishComplete.run();
|
if (onFinishComplete != null) {
|
||||||
}
|
onFinishComplete.run();
|
||||||
controller = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -67,13 +71,12 @@ public class RecentsAnimationWrapper {
|
|||||||
public void enableInputConsumer() {
|
public void enableInputConsumer() {
|
||||||
mInputConsumerEnabled = true;
|
mInputConsumerEnabled = true;
|
||||||
if (mInputConsumerEnabled) {
|
if (mInputConsumerEnabled) {
|
||||||
BackgroundExecutor.get().submit(() -> {
|
mExecutorService.submit(() -> {
|
||||||
synchronized (this) {
|
RecentsAnimationControllerCompat controller = mController;
|
||||||
TraceHelper.partitionSection("RecentsController",
|
TraceHelper.partitionSection("RecentsController",
|
||||||
"Enabling consumer on " + controller);
|
"Enabling consumer on " + controller);
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
controller.setInputConsumerEnabled(true);
|
controller.setInputConsumerEnabled(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -84,13 +87,12 @@ public class RecentsAnimationWrapper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mBehindSystemBars = behindSystemBars;
|
mBehindSystemBars = behindSystemBars;
|
||||||
BackgroundExecutor.get().submit(() -> {
|
mExecutorService.submit(() -> {
|
||||||
synchronized (this) {
|
RecentsAnimationControllerCompat controller = mController;
|
||||||
TraceHelper.partitionSection("RecentsController",
|
TraceHelper.partitionSection("RecentsController",
|
||||||
"Setting behind system bars on " + controller);
|
"Setting behind system bars on " + controller);
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
controller.setAnimationTargetsBehindSystemBars(behindSystemBars);
|
controller.setAnimationTargetsBehindSystemBars(behindSystemBars);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -106,25 +108,28 @@ public class RecentsAnimationWrapper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mSplitScreenMinimized = minimized;
|
mSplitScreenMinimized = minimized;
|
||||||
BackgroundExecutor.get().submit(() -> {
|
mExecutorService.submit(() -> {
|
||||||
synchronized (this) {
|
RecentsAnimationControllerCompat controller = mController;
|
||||||
TraceHelper.partitionSection("RecentsController",
|
TraceHelper.partitionSection("RecentsController",
|
||||||
"Setting minimize dock on " + controller);
|
"Setting minimize dock on " + controller);
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
controller.setSplitScreenMinimized(minimized);
|
controller.setSplitScreenMinimized(minimized);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideCurrentInputMethod() {
|
public void hideCurrentInputMethod() {
|
||||||
BackgroundExecutor.get().submit(() -> {
|
mExecutorService.submit(() -> {
|
||||||
synchronized (this) {
|
RecentsAnimationControllerCompat controller = mController;
|
||||||
TraceHelper.partitionSection("RecentsController", "Hiding currentinput method");
|
TraceHelper.partitionSection("RecentsController",
|
||||||
if (controller != null) {
|
"Hiding currentinput method on " + controller);
|
||||||
controller.hideCurrentInputMethod();
|
if (controller != null) {
|
||||||
}
|
controller.hideCurrentInputMethod();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RecentsAnimationControllerCompat getController() {
|
||||||
|
return mController;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -491,21 +491,18 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> {
|
|||||||
private void updateFinalShift() {
|
private void updateFinalShift() {
|
||||||
float shift = mCurrentShift.value;
|
float shift = mCurrentShift.value;
|
||||||
|
|
||||||
synchronized (mRecentsAnimationWrapper) {
|
RecentsAnimationControllerCompat controller = mRecentsAnimationWrapper.getController();
|
||||||
if (mRecentsAnimationWrapper.controller != null) {
|
if (controller != null) {
|
||||||
Interpolator interpolator = mInteractionType == INTERACTION_QUICK_SCRUB
|
Interpolator interpolator = mInteractionType == INTERACTION_QUICK_SCRUB
|
||||||
? ACCEL_2 : LINEAR;
|
? ACCEL_2 : LINEAR;
|
||||||
float interpolated = interpolator.getInterpolation(shift);
|
float interpolated = interpolator.getInterpolation(shift);
|
||||||
mClipAnimationHelper.applyTransform(
|
mClipAnimationHelper.applyTransform(mRecentsAnimationWrapper.targetSet, interpolated);
|
||||||
mRecentsAnimationWrapper.targetSet, interpolated);
|
|
||||||
|
|
||||||
// TODO: This logic is spartanic!
|
// TODO: This logic is spartanic!
|
||||||
boolean passedThreshold = shift > 0.12f;
|
boolean passedThreshold = shift > 0.12f;
|
||||||
mRecentsAnimationWrapper.setAnimationTargetsBehindSystemBars(!passedThreshold);
|
mRecentsAnimationWrapper.setAnimationTargetsBehindSystemBars(!passedThreshold);
|
||||||
if (mActivityControlHelper.shouldMinimizeSplitScreen()) {
|
if (mActivityControlHelper.shouldMinimizeSplitScreen()) {
|
||||||
mRecentsAnimationWrapper
|
mRecentsAnimationWrapper.setSplitScreenMinimizedForTransaction(passedThreshold);
|
||||||
.setSplitScreenMinimizedForTransaction(passedThreshold);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,27 +704,25 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity> {
|
|||||||
|
|
||||||
private void switchToScreenshot() {
|
private void switchToScreenshot() {
|
||||||
boolean finishTransitionPosted = false;
|
boolean finishTransitionPosted = false;
|
||||||
synchronized (mRecentsAnimationWrapper) {
|
RecentsAnimationControllerCompat controller = mRecentsAnimationWrapper.getController();
|
||||||
if (mRecentsAnimationWrapper.controller != null) {
|
if (controller != null) {
|
||||||
// Update the screenshot of the task
|
// Update the screenshot of the task
|
||||||
if (mTaskSnapshot == null) {
|
if (mTaskSnapshot == null) {
|
||||||
mTaskSnapshot = mRecentsAnimationWrapper.controller
|
mTaskSnapshot = controller.screenshotTask(mRunningTaskId);
|
||||||
.screenshotTask(mRunningTaskId);
|
}
|
||||||
}
|
TaskView taskView = mRecentsView.updateThumbnail(mRunningTaskId, mTaskSnapshot);
|
||||||
TaskView taskView = mRecentsView.updateThumbnail(mRunningTaskId, mTaskSnapshot);
|
mRecentsView.setRunningTaskHidden(false);
|
||||||
mRecentsView.setRunningTaskHidden(false);
|
if (taskView != null) {
|
||||||
if (taskView != null) {
|
// Defer finishing the animation until the next launcher frame with the
|
||||||
// Defer finishing the animation until the next launcher frame with the
|
// new thumbnail
|
||||||
// new thumbnail
|
finishTransitionPosted = new WindowCallbacksCompat(taskView) {
|
||||||
finishTransitionPosted = new WindowCallbacksCompat(taskView) {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPostDraw(Canvas canvas) {
|
public void onPostDraw(Canvas canvas) {
|
||||||
setStateOnUiThread(STATE_SCREENSHOT_CAPTURED);
|
setStateOnUiThread(STATE_SCREENSHOT_CAPTURED);
|
||||||
detach();
|
detach();
|
||||||
}
|
}
|
||||||
}.attach();
|
}.attach();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!finishTransitionPosted) {
|
if (!finishTransitionPosted) {
|
||||||
|
|||||||
Reference in New Issue
Block a user