From 57142133670c0d6fd92548ecb230bb0ad6547974 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Tue, 5 Apr 2022 12:53:36 -0700 Subject: [PATCH] Add displayId to transferTouch To account for the case where the displays are mirrored, add display id to transferTouch(..). When mirroring is on, windows with identical tokens would be positioned on different displays. This could break the transferTouch API, if the window of mirror happens to be found first. This could mean that screenrecording may have different behaviour from the regular usage. Bug: 220077253 Test: atest inputflinger_tests Test: manual testing - pull down notification shade from home screen Change-Id: Ia8965cad83e2c29062329958edbc9516ae67f1ed --- .../com/android/server/input/InputManagerService.java | 4 ++-- .../android/server/input/NativeInputManagerService.java | 8 ++++++-- .../core/java/com/android/server/wm/WindowState.java | 2 +- .../jni/com_android_server_input_InputManagerService.cpp | 9 +++++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 603d0128cc445..71afc40831c50 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -658,10 +658,10 @@ public class InputManagerService extends IInputManager.Stub * gesture * @return True if the transfer succeeded, false if there was no active touch gesture happening */ - public boolean transferTouch(IBinder destChannelToken) { + public boolean transferTouch(IBinder destChannelToken, int displayId) { // TODO(b/162194035): Replace this with a SPY window Objects.requireNonNull(destChannelToken, "destChannelToken must not be null"); - return mNative.transferTouch(destChannelToken); + return mNative.transferTouch(destChannelToken, displayId); } /** diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java index 7178d20786e3c..854170ef79bdf 100644 --- a/services/core/java/com/android/server/input/NativeInputManagerService.java +++ b/services/core/java/com/android/server/input/NativeInputManagerService.java @@ -90,7 +90,11 @@ public interface NativeInputManagerService { boolean transferTouchFocus(IBinder fromChannelToken, IBinder toChannelToken, boolean isDragDrop); - boolean transferTouch(IBinder destChannelToken); + /** + * Transfer the current touch gesture to the window identified by 'destChannelToken' positioned + * on display with id 'displayId'. + */ + boolean transferTouch(IBinder destChannelToken, int displayId); void setPointerSpeed(int speed); @@ -263,7 +267,7 @@ public interface NativeInputManagerService { boolean isDragDrop); @Override - public native boolean transferTouch(IBinder destChannelToken); + public native boolean transferTouch(IBinder destChannelToken, int displayId); @Override public native void setPointerSpeed(int speed); diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 8546e8002602b..e9b2d60f27b98 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -2798,7 +2798,7 @@ class WindowState extends WindowContainer implements WindowManagerP * Move the touch gesture from the currently touched window on this display to this window. */ public boolean transferTouch() { - return mWmService.mInputManager.transferTouch(mInputChannelToken); + return mWmService.mInputManager.transferTouch(mInputChannelToken, getDisplayId()); } void disposeInputChannel() { diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index fa5e450c687a7..479ddcea5956e 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -1846,12 +1846,13 @@ static jboolean nativeTransferTouchFocus(JNIEnv* env, jobject nativeImplObj, } } -static jboolean nativeTransferTouch(JNIEnv* env, jobject nativeImplObj, - jobject destChannelTokenObj) { +static jboolean nativeTransferTouch(JNIEnv* env, jobject nativeImplObj, jobject destChannelTokenObj, + jint displayId) { sp destChannelToken = ibinderForJavaObject(env, destChannelTokenObj); NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - if (im->getInputManager()->getDispatcher().transferTouch(destChannelToken)) { + if (im->getInputManager()->getDispatcher().transferTouch(destChannelToken, + static_cast(displayId))) { return JNI_TRUE; } else { return JNI_FALSE; @@ -2345,7 +2346,7 @@ static const JNINativeMethod gInputManagerMethods[] = { {"setSystemUiLightsOut", "(Z)V", (void*)nativeSetSystemUiLightsOut}, {"transferTouchFocus", "(Landroid/os/IBinder;Landroid/os/IBinder;Z)Z", (void*)nativeTransferTouchFocus}, - {"transferTouch", "(Landroid/os/IBinder;)Z", (void*)nativeTransferTouch}, + {"transferTouch", "(Landroid/os/IBinder;I)Z", (void*)nativeTransferTouch}, {"setPointerSpeed", "(I)V", (void*)nativeSetPointerSpeed}, {"setPointerAcceleration", "(F)V", (void*)nativeSetPointerAcceleration}, {"setShowTouches", "(Z)V", (void*)nativeSetShowTouches},