From 59f532efad5562822fc36b44f37046abe1cb9e14 Mon Sep 17 00:00:00 2001 From: chaviw Date: Wed, 26 Dec 2018 15:34:59 -0800 Subject: [PATCH] Fix drag and drop (1/3) Add transferTouchFoucus API in SurfaceControl to pass info to native. Test: Builds Bug: 120463595 Change-Id: Ifb20a135c13de7380176e285dac273eef776ee19 --- core/java/android/view/SurfaceControl.java | 18 +++++++++++++++++- core/jni/android_view_SurfaceControl.cpp | 13 ++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index a006e5de283eb..1a708e8e30ec1 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -165,7 +165,8 @@ public class SurfaceControl implements Parcelable { private static native void nativeSetInputWindowInfo(long transactionObj, long nativeObject, InputWindowHandle handle); - + private static native void nativeTransferTouchFocus(long transactionObj, IBinder fromToken, + IBinder toToken); private final CloseGuard mCloseGuard = CloseGuard.get(); private final String mName; @@ -1541,6 +1542,21 @@ public class SurfaceControl implements Parcelable { return this; } + /** + * Transfers touch focus from one window to another. It is possible for multiple windows to + * have touch focus if they support split touch dispatch + * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this + * method only transfers touch focus of the specified window without affecting + * other windows that may also have touch focus at the same time. + * @param fromToken The token of a window that currently has touch focus. + * @param toToken The token of the window that should receive touch focus in + * place of the first. + */ + public Transaction transferTouchFocus(IBinder fromToken, IBinder toToken) { + nativeTransferTouchFocus(mNativeObject, fromToken, toToken); + return this; + } + @UnsupportedAppUsage public Transaction setMatrix(SurfaceControl sc, float dsdx, float dtdx, float dtdy, float dsdy) { diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index c745c160e1437..6576587899be1 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -348,6 +348,15 @@ static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactio transaction->setInputWindowInfo(ctrl, *handle->getInfo()); } +static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj, + jobject fromTokenObj, jobject toTokenObj) { + auto transaction = reinterpret_cast(transactionObj); + + sp fromToken(ibinderForJavaObject(env, fromTokenObj)); + sp toToken(ibinderForJavaObject(env, toTokenObj)); + transaction->transferTouchFocus(fromToken, toToken); +} + static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject, jfloatArray fColor) { auto transaction = reinterpret_cast(transactionObj); @@ -1032,7 +1041,9 @@ static const JNINativeMethod sSurfaceControlMethods[] = { {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;", (void*)nativeCaptureLayers }, {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V", - (void*)nativeSetInputWindowInfo }, + (void*)nativeSetInputWindowInfo }, + {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V", + (void*)nativeTransferTouchFocus }, {"nativeGetDisplayedContentSamplingAttributes", "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;", (void*)nativeGetDisplayedContentSamplingAttributes },