summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-03-12 03:52:36 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-03-12 03:52:36 +0000
commitc04814ff765105c09d666e2fc5122fd20ae25b83 (patch)
tree1d154739e3eeb177a468e145d04243684865dc76
parente1ca2891e53fc772680679a14c5315959a47222e (diff)
parent98fc6a134b24551da9f2fea99942d32adfce4c44 (diff)
Merge "Move drag event to InputDispatcher (4/n)" into sc-dev
-rw-r--r--core/java/android/view/ViewRootImpl.java11
-rw-r--r--services/core/java/com/android/server/input/InputManagerService.java11
-rw-r--r--services/core/java/com/android/server/wm/DragDropController.java2
-rw-r--r--services/core/java/com/android/server/wm/DragState.java44
-rw-r--r--services/core/java/com/android/server/wm/TaskPositioningController.java3
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerInternal.java3
-rw-r--r--services/core/jni/com_android_server_input_InputManagerService.cpp11
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java4
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java4
9 files changed, 32 insertions, 61 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 9fc415d6401f..35726c0c1f04 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -8572,6 +8572,17 @@ public final class ViewRootImpl implements ViewParent,
}
@Override
+ public void onDragEvent(boolean isExiting, float x, float y) {
+ // force DRAG_EXITED_EVENT if appropriate
+ DragEvent event = DragEvent.obtain(
+ isExiting ? DragEvent.ACTION_DRAG_EXITED : DragEvent.ACTION_DRAG_LOCATION,
+ x, y, 0 /* offsetX */, 0 /* offsetY */, null/* localState */,
+ null/* description */, null /* data */, null /* dragSurface */,
+ null /* dragAndDropPermissions */, false /* result */);
+ dispatchDragEvent(event);
+ }
+
+ @Override
public void dispose() {
unscheduleConsumeBatchedInput();
super.dispose();
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
index 7dc9a0b2a364..cbe6e69cbef3 100644
--- a/services/core/java/com/android/server/input/InputManagerService.java
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -304,7 +304,7 @@ public class InputManagerService extends IInputManager.Stub
int displayId, InputApplicationHandle application);
private static native void nativeSetFocusedDisplay(long ptr, int displayId);
private static native boolean nativeTransferTouchFocus(long ptr,
- IBinder fromChannelToken, IBinder toChannelToken);
+ IBinder fromChannelToken, IBinder toChannelToken, boolean isDragDrop);
private static native void nativeSetPointerSpeed(long ptr, int speed);
private static native void nativeSetShowTouches(long ptr, boolean enabled);
private static native void nativeSetInteractive(long ptr, boolean interactive);
@@ -1727,12 +1727,14 @@ public class InputManagerService extends IInputManager.Stub
* @param fromChannel The channel of a window that currently has touch focus.
* @param toChannel The channel of the window that should receive touch focus in
* place of the first.
+ * @param isDragDrop True if transfer touch focus for drag and drop.
* @return True if the transfer was successful. False if the window with the
* specified channel did not actually have touch focus at the time of the request.
*/
public boolean transferTouchFocus(@NonNull InputChannel fromChannel,
- @NonNull InputChannel toChannel) {
- return nativeTransferTouchFocus(mPtr, fromChannel.getToken(), toChannel.getToken());
+ @NonNull InputChannel toChannel, boolean isDragDrop) {
+ return nativeTransferTouchFocus(mPtr, fromChannel.getToken(), toChannel.getToken(),
+ isDragDrop);
}
/**
@@ -1752,7 +1754,8 @@ public class InputManagerService extends IInputManager.Stub
@NonNull IBinder toChannelToken) {
Objects.nonNull(fromChannelToken);
Objects.nonNull(toChannelToken);
- return nativeTransferTouchFocus(mPtr, fromChannelToken, toChannelToken);
+ return nativeTransferTouchFocus(mPtr, fromChannelToken, toChannelToken,
+ false /* isDragDrop */);
}
@Override // Binder call
diff --git a/services/core/java/com/android/server/wm/DragDropController.java b/services/core/java/com/android/server/wm/DragDropController.java
index 627af9149fe5..1120a074aa8c 100644
--- a/services/core/java/com/android/server/wm/DragDropController.java
+++ b/services/core/java/com/android/server/wm/DragDropController.java
@@ -182,8 +182,6 @@ class DragDropController {
if (SHOW_LIGHT_TRANSACTIONS) {
Slog.i(TAG_WM, "<<< CLOSE TRANSACTION performDrag");
}
-
- mDragState.notifyLocationLocked(touchX, touchY);
} finally {
if (surface != null) {
surface.release();
diff --git a/services/core/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java
index 0b3c065e0e73..08d5e800a808 100644
--- a/services/core/java/com/android/server/wm/DragState.java
+++ b/services/core/java/com/android/server/wm/DragState.java
@@ -515,50 +515,6 @@ class DragState {
mTransaction.setPosition(mSurfaceControl, x - mThumbOffsetX, y - mThumbOffsetY).apply();
ProtoLog.i(WM_SHOW_TRANSACTIONS, "DRAG %s: pos=(%d,%d)", mSurfaceControl,
(int) (x - mThumbOffsetX), (int) (y - mThumbOffsetY));
-
- notifyLocationLocked(x, y);
- }
-
- void notifyLocationLocked(float x, float y) {
- // Tell the affected window
- WindowState touchedWin = mDisplayContent.getTouchableWinAtPointLocked(x, y);
- if (touchedWin != null && !isWindowNotified(touchedWin)) {
- // The drag point is over a window which was not notified about a drag start.
- // Pretend it's over empty space.
- touchedWin = null;
- }
-
- try {
- final int myPid = Process.myPid();
-
- // have we dragged over a new window?
- if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
- if (DEBUG_DRAG) {
- Slog.d(TAG_WM, "sending DRAG_EXITED to " + mTargetWindow);
- }
- // force DRAG_EXITED_EVENT if appropriate
- DragEvent evt = obtainDragEvent(mTargetWindow, DragEvent.ACTION_DRAG_EXITED,
- 0, 0, 0, 0, null, null, null, null, null, false);
- mTargetWindow.mClient.dispatchDragEvent(evt);
- if (myPid != mTargetWindow.mSession.mPid) {
- evt.recycle();
- }
- }
- if (touchedWin != null) {
- if (false && DEBUG_DRAG) {
- Slog.d(TAG_WM, "sending DRAG_LOCATION to " + touchedWin);
- }
- DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DRAG_LOCATION,
- x, y, mThumbOffsetX, mThumbOffsetY, null, null, null, null, null, false);
- touchedWin.mClient.dispatchDragEvent(evt);
- if (myPid != touchedWin.mSession.mPid) {
- evt.recycle();
- }
- }
- } catch (RemoteException e) {
- Slog.w(TAG_WM, "can't send drag notification to windows");
- }
- mTargetWindow = touchedWin;
}
/**
diff --git a/services/core/java/com/android/server/wm/TaskPositioningController.java b/services/core/java/com/android/server/wm/TaskPositioningController.java
index 9d35c25fc546..525420e045b5 100644
--- a/services/core/java/com/android/server/wm/TaskPositioningController.java
+++ b/services/core/java/com/android/server/wm/TaskPositioningController.java
@@ -188,7 +188,8 @@ class TaskPositioningController {
transferFocusFromWin = displayContent.mCurrentFocus;
}
if (!mInputManager.transferTouchFocus(
- transferFocusFromWin.mInputChannel, mTaskPositioner.mClientChannel)) {
+ transferFocusFromWin.mInputChannel, mTaskPositioner.mClientChannel,
+ false /* isDragDrop */)) {
Slog.e(TAG_WM, "startPositioningLocked: Unable to transfer touch focus");
cleanUpTaskPositioner();
return false;
diff --git a/services/core/java/com/android/server/wm/WindowManagerInternal.java b/services/core/java/com/android/server/wm/WindowManagerInternal.java
index 7450782364f4..53ebfb2c6e0e 100644
--- a/services/core/java/com/android/server/wm/WindowManagerInternal.java
+++ b/services/core/java/com/android/server/wm/WindowManagerInternal.java
@@ -221,7 +221,8 @@ public abstract class WindowManagerInternal {
DragState state, Display display, InputManagerService service,
InputChannel source) {
state.register(display);
- return service.transferTouchFocus(source, state.getInputChannel());
+ return service.transferTouchFocus(source, state.getInputChannel(),
+ true /* isDragDrop */);
}
/**
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 10705af9ac38..be06d0395499 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -1783,8 +1783,9 @@ static void nativeSetSystemUiLightsOut(JNIEnv* /* env */, jclass /* clazz */, jl
im->setSystemUiLightsOut(lightsOut);
}
-static jboolean nativeTransferTouchFocus(JNIEnv* env,
- jclass /* clazz */, jlong ptr, jobject fromChannelTokenObj, jobject toChannelTokenObj) {
+static jboolean nativeTransferTouchFocus(JNIEnv* env, jclass /* clazz */, jlong ptr,
+ jobject fromChannelTokenObj, jobject toChannelTokenObj,
+ jboolean isDragDrop) {
if (fromChannelTokenObj == nullptr || toChannelTokenObj == nullptr) {
return JNI_FALSE;
}
@@ -1793,8 +1794,8 @@ static jboolean nativeTransferTouchFocus(JNIEnv* env,
sp<IBinder> toChannelToken = ibinderForJavaObject(env, toChannelTokenObj);
NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
- if (im->getInputManager()->getDispatcher()->transferTouchFocus(
- fromChannelToken, toChannelToken)) {
+ if (im->getInputManager()->getDispatcher()->transferTouchFocus(fromChannelToken, toChannelToken,
+ isDragDrop)) {
return JNI_TRUE;
} else {
return JNI_FALSE;
@@ -2267,7 +2268,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
(void*)nativeRequestPointerCapture},
{"nativeSetInputDispatchMode", "(JZZ)V", (void*)nativeSetInputDispatchMode},
{"nativeSetSystemUiLightsOut", "(JZ)V", (void*)nativeSetSystemUiLightsOut},
- {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)Z",
+ {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;Z)Z",
(void*)nativeTransferTouchFocus},
{"nativeSetPointerSpeed", "(JI)V", (void*)nativeSetPointerSpeed},
{"nativeSetShowTouches", "(JZ)V", (void*)nativeSetShowTouches},
diff --git a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
index 8703c3103607..7f9e7da99579 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DragDropControllerTests.java
@@ -154,7 +154,7 @@ public class DragDropControllerTests extends WindowTestsBase {
mWindow = createDropTargetWindow("Drag test window", 0);
doReturn(mWindow).when(mDisplayContent).getTouchableWinAtPointLocked(0, 0);
when(mWm.mInputManager.transferTouchFocus(any(InputChannel.class),
- any(InputChannel.class))).thenReturn(true);
+ any(InputChannel.class), any(boolean.class))).thenReturn(true);
mWm.mWindowMap.put(mWindow.mClient.asBinder(), mWindow);
}
@@ -370,7 +370,7 @@ public class DragDropControllerTests extends WindowTestsBase {
.build();
assertTrue(mWm.mInputManager.transferTouchFocus(new InputChannel(),
- new InputChannel()));
+ new InputChannel(), true /* isDragDrop */));
mToken = mTarget.performDrag(0, 0, mWindow.mClient, flag, surface, 0, 0, 0, 0, 0, data);
assertNotNull(mToken);
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
index 75226b7e66f7..8bc4cedf6fce 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
@@ -34,7 +34,6 @@ import static org.junit.Assert.assertTrue;
import android.platform.test.annotations.Presubmit;
import android.view.InputChannel;
-import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import org.junit.Before;
@@ -63,7 +62,8 @@ public class TaskPositioningControllerTests extends WindowTestsBase {
when(mWm.mInputManager.transferTouchFocus(
any(InputChannel.class),
- any(InputChannel.class))).thenReturn(true);
+ any(InputChannel.class),
+ any(boolean.class))).thenReturn(true);
mWindow = createWindow(null, TYPE_BASE_APPLICATION, "window");
mWindow.getTask().setResizeMode(RESIZE_MODE_RESIZEABLE);