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: I56e24fbbdeb3b673837982df3fa67e485d03b3b2
This commit is contained in:
Winson Chung 2018-05-09 10:47:35 -07:00
parent 639b07178f
commit 12c4ecb015
1 changed files with 36 additions and 38 deletions

View File

@ -15,10 +15,14 @@
*/
package com.android.quickstep;
import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.TraceHelper;
import com.android.launcher3.util.UiThreadHelper;
import com.android.quickstep.util.RemoteAnimationTargetSet;
import com.android.systemui.shared.system.BackgroundExecutor;
import com.android.systemui.shared.system.RecentsAnimationControllerCompat;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Wrapper around RecentsAnimationController to help with some synchronization
@ -28,6 +32,9 @@ public class RecentsAnimationWrapper {
public RecentsAnimationControllerCompat controller;
public RemoteAnimationTargetSet targetSet;
private final ExecutorService mExecutorService =
new LooperExecutor(UiThreadHelper.getBackgroundLooper());
private boolean mInputConsumerEnabled = false;
private boolean mBehindSystemBars = true;
private boolean mSplitScreenMinimized = false;
@ -48,17 +55,16 @@ public class RecentsAnimationWrapper {
* on the background thread.
*/
public void finish(boolean toHome, Runnable onFinishComplete) {
BackgroundExecutor.get().submit(() -> {
synchronized (this) {
TraceHelper.endSection("RecentsController",
"Finish " + controller + ", toHome=" + toHome);
if (controller != null) {
controller.setInputConsumerEnabled(false);
controller.finish(toHome);
if (onFinishComplete != null) {
onFinishComplete.run();
}
controller = null;
mExecutorService.submit(() -> {
TraceHelper.endSection("RecentsController",
"Finish " + controller + ", toHome=" + toHome);
RecentsAnimationControllerCompat thisController = controller;
controller = null;
if (thisController != null) {
thisController.setInputConsumerEnabled(false);
thisController.finish(toHome);
if (onFinishComplete != null) {
onFinishComplete.run();
}
}
});
@ -67,13 +73,11 @@ public class RecentsAnimationWrapper {
public void enableInputConsumer() {
mInputConsumerEnabled = true;
if (mInputConsumerEnabled) {
BackgroundExecutor.get().submit(() -> {
synchronized (this) {
TraceHelper.partitionSection("RecentsController",
"Enabling consumer on " + controller);
if (controller != null) {
controller.setInputConsumerEnabled(true);
}
mExecutorService.submit(() -> {
TraceHelper.partitionSection("RecentsController",
"Enabling consumer on " + controller);
if (controller != null) {
controller.setInputConsumerEnabled(true);
}
});
}
@ -84,13 +88,11 @@ public class RecentsAnimationWrapper {
return;
}
mBehindSystemBars = behindSystemBars;
BackgroundExecutor.get().submit(() -> {
synchronized (this) {
TraceHelper.partitionSection("RecentsController",
"Setting behind system bars on " + controller);
if (controller != null) {
controller.setAnimationTargetsBehindSystemBars(behindSystemBars);
}
mExecutorService.submit(() -> {
TraceHelper.partitionSection("RecentsController",
"Setting behind system bars on " + controller);
if (controller != null) {
controller.setAnimationTargetsBehindSystemBars(behindSystemBars);
}
});
}
@ -106,24 +108,20 @@ public class RecentsAnimationWrapper {
return;
}
mSplitScreenMinimized = minimized;
BackgroundExecutor.get().submit(() -> {
synchronized (this) {
TraceHelper.partitionSection("RecentsController",
"Setting minimize dock on " + controller);
if (controller != null) {
controller.setSplitScreenMinimized(minimized);
}
mExecutorService.submit(() -> {
TraceHelper.partitionSection("RecentsController",
"Setting minimize dock on " + controller);
if (controller != null) {
controller.setSplitScreenMinimized(minimized);
}
});
}
public void hideCurrentInputMethod() {
BackgroundExecutor.get().submit(() -> {
synchronized (this) {
TraceHelper.partitionSection("RecentsController", "Hiding currentinput method");
if (controller != null) {
controller.hideCurrentInputMethod();
}
mExecutorService.submit(() -> {
TraceHelper.partitionSection("RecentsController", "Hiding currentinput method");
if (controller != null) {
controller.hideCurrentInputMethod();
}
});
}