Move task positioning tasks from WindowManagerService.mH
The CL moves task positioning tasks from WindowManagerService.mH to
TaskPositioningController.mHandler.
Bug: 64149458
Test: atest com.android.server.wm.TaskPositioningControllerTests
Change-Id: I2a8ce22a1698e008b2abd2e8f1b06886cec697b4
diff --git a/services/core/java/com/android/server/wm/TaskPositioner.java b/services/core/java/com/android/server/wm/TaskPositioner.java
index ca9f3a9..fa7ea2f 100644
--- a/services/core/java/com/android/server/wm/TaskPositioner.java
+++ b/services/core/java/com/android/server/wm/TaskPositioner.java
@@ -203,7 +203,7 @@
// Post back to WM to handle clean-ups. We still need the input
// event handler for the last finishInputEvent()!
- mService.mH.sendEmptyMessage(H.FINISH_TASK_POSITIONING);
+ mService.mTaskPositioningController.finishTaskPositioning();
}
handled = true;
} catch (Exception e) {
diff --git a/services/core/java/com/android/server/wm/TaskPositioningController.java b/services/core/java/com/android/server/wm/TaskPositioningController.java
index bb5706c..4dfe290 100644
--- a/services/core/java/com/android/server/wm/TaskPositioningController.java
+++ b/services/core/java/com/android/server/wm/TaskPositioningController.java
@@ -22,6 +22,8 @@
import android.annotation.Nullable;
import android.app.IActivityManager;
import android.os.RemoteException;
+import android.os.Handler;
+import android.os.Looper;
import android.util.Slog;
import android.view.Display;
import android.view.IWindow;
@@ -37,6 +39,7 @@
private final InputManagerService mInputManager;
private final InputMonitor mInputMonitor;
private final IActivityManager mActivityManager;
+ private final Handler mHandler;
@GuardedBy("WindowManagerSerivce.mWindowMap")
private @Nullable TaskPositioner mTaskPositioner;
@@ -50,11 +53,12 @@
}
TaskPositioningController(WindowManagerService service, InputManagerService inputManager,
- InputMonitor inputMonitor, IActivityManager activityManager) {
+ InputMonitor inputMonitor, IActivityManager activityManager, Looper looper) {
mService = service;
mInputMonitor = inputMonitor;
mInputManager = inputManager;
mActivityManager = activityManager;
+ mHandler = new Handler(looper);
}
boolean startMovingTask(IWindow window, float startX, float startY) {
@@ -75,24 +79,27 @@
}
void handleTapOutsideTask(DisplayContent displayContent, int x, int y) {
- int taskId = -1;
- synchronized (mService.mWindowMap) {
- final Task task = displayContent.findTaskForResizePoint(x, y);
- if (task != null) {
- if (!startPositioningLocked(task.getTopVisibleAppMainWindow(), true /*resize*/,
- task.preserveOrientationOnResize(), x, y)) {
- return;
+ mHandler.post(() -> {
+ int taskId = -1;
+ synchronized (mService.mWindowMap) {
+ final Task task = displayContent.findTaskForResizePoint(x, y);
+ if (task != null) {
+ if (!startPositioningLocked(task.getTopVisibleAppMainWindow(), true /*resize*/,
+ task.preserveOrientationOnResize(), x, y)) {
+ return;
+ }
+ taskId = task.mTaskId;
+ } else {
+ taskId = displayContent.taskIdFromPoint(x, y);
}
- taskId = task.mTaskId;
- } else {
- taskId = displayContent.taskIdFromPoint(x, y);
}
- }
- if (taskId >= 0) {
- try {
- mActivityManager.setFocusedTask(taskId);
- } catch(RemoteException e) {}
- }
+ if (taskId >= 0) {
+ try {
+ mActivityManager.setFocusedTask(taskId);
+ } catch (RemoteException e) {
+ }
+ }
+ });
}
private boolean startPositioningLocked(WindowState win, boolean resize,
@@ -145,15 +152,17 @@
return true;
}
- void finishPositioning() {
- if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishPositioning");
+ void finishTaskPositioning() {
+ mHandler.post(() -> {
+ if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishPositioning");
- synchronized (mService.mWindowMap) {
- if (mTaskPositioner != null) {
- mTaskPositioner.unregister();
- mTaskPositioner = null;
- mInputMonitor.updateInputWindowsLw(true /*force*/);
+ synchronized (mService.mWindowMap) {
+ if (mTaskPositioner != null) {
+ mTaskPositioner.unregister();
+ mTaskPositioner = null;
+ mInputMonitor.updateInputWindowsLw(true /*force*/);
+ }
}
- }
+ });
}
}
diff --git a/services/core/java/com/android/server/wm/TaskTapPointerEventListener.java b/services/core/java/com/android/server/wm/TaskTapPointerEventListener.java
index 84ad576..5abda27 100644
--- a/services/core/java/com/android/server/wm/TaskTapPointerEventListener.java
+++ b/services/core/java/com/android/server/wm/TaskTapPointerEventListener.java
@@ -62,8 +62,8 @@
synchronized (this) {
if (!mTouchExcludeRegion.contains(x, y)) {
- mService.mH.obtainMessage(H.TAP_OUTSIDE_TASK,
- x, y, mDisplayContent).sendToTarget();
+ mService.mTaskPositioningController.handleTapOutsideTask(
+ mDisplayContent, x, y);
}
}
}
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 8c9948e..6ee02ea 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -1088,8 +1088,8 @@
mAllowTheaterModeWakeFromLayout = context.getResources().getBoolean(
com.android.internal.R.bool.config_allowTheaterModeWakeFromWindowLayout);
- mTaskPositioningController =
- new TaskPositioningController(this, mInputManager, mInputMonitor, mActivityManager);
+ mTaskPositioningController = new TaskPositioningController(
+ this, mInputManager, mInputMonitor, mActivityManager, mH.getLooper());
mDragDropController = new DragDropController(this, mH.getLooper());
LocalServices.addService(WindowManagerInternal.class, new LocalService());
@@ -4613,7 +4613,6 @@
public static final int DO_ANIMATION_CALLBACK = 26;
public static final int CLIENT_FREEZE_TIMEOUT = 30;
- public static final int TAP_OUTSIDE_TASK = 31;
public static final int NOTIFY_ACTIVITY_DRAWN = 32;
public static final int ALL_WINDOWS_DRAWN = 33;
@@ -4627,8 +4626,6 @@
public static final int RESET_ANR_MESSAGE = 38;
public static final int WALLPAPER_DRAW_PENDING_TIMEOUT = 39;
- public static final int FINISH_TASK_POSITIONING = 40;
-
public static final int UPDATE_DOCKED_STACK_DIVIDER = 41;
public static final int WINDOW_REPLACEMENT_TIMEOUT = 46;
@@ -4905,17 +4902,6 @@
break;
}
- case TAP_OUTSIDE_TASK: {
- mTaskPositioningController.handleTapOutsideTask(
- (DisplayContent)msg.obj, msg.arg1, msg.arg2);
- }
- break;
-
- case FINISH_TASK_POSITIONING: {
- mTaskPositioningController.finishPositioning();
- }
- break;
-
case NOTIFY_ACTIVITY_DRAWN:
try {
mActivityManager.notifyActivityDrawn((IBinder) msg.obj);
diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java
index 89447a9..6070516 100644
--- a/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/TaskPositioningControllerTests.java
@@ -33,6 +33,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
/**
* Tests for the {@link TaskPositioningController} class.
*
@@ -78,9 +79,9 @@
assertNotNull(mTarget.getDragWindowHandleLocked());
}
- assertTrue(sWm.mH.runWithScissors(() -> {
- mTarget.finishPositioning();
- }, TIMEOUT_MS));
+ mTarget.finishTaskPositioning();
+ // Wait until the looper processes finishTaskPositioning.
+ assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS));
assertFalse(mTarget.isPositioningLocked());
assertNull(mTarget.getDragWindowHandleLocked());
@@ -99,15 +100,17 @@
assertNotNull(mWindow.getTask().getTopVisibleAppMainWindow());
mTarget.handleTapOutsideTask(content, 0, 0);
+ // Wait until the looper processes finishTaskPositioning.
+ assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS));
synchronized (sWm.mWindowMap) {
assertTrue(mTarget.isPositioningLocked());
assertNotNull(mTarget.getDragWindowHandleLocked());
}
- assertTrue(sWm.mH.runWithScissors(() -> {
- mTarget.finishPositioning();
- }, TIMEOUT_MS));
+ mTarget.finishTaskPositioning();
+ // Wait until the looper processes finishTaskPositioning.
+ assertTrue(sWm.mH.runWithScissors(() -> {}, TIMEOUT_MS));
assertFalse(mTarget.isPositioningLocked());
assertNull(mTarget.getDragWindowHandleLocked());