Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc2e363d authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Use IBinder pointer when hashing in InputTransferToken.

Hashing the IBinder java object from JNI doesn't always yield the
same value so instead hash the native IBinder pointer

Test: SurfaceControlViewHostTests#requestFocusWithMultipleWindows
Test:
AccessibilityEmbeddedHierarchyTest#testEmbeddedView_PerformActionTransfersWindowInputFocus
Test: SurfaceControlInputReceiverTests#testTransferGestureFromHostToEmbedded

Fixes: 329491286
Fixes: 329909546
Fixes: 329950249
Change-Id: Ie613de91a0223dbbfa6f677339fd97f18213098f
parent ace5c353
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public final class InputTransferToken implements Parcelable {
    private static native void nativeWriteToParcel(long nativeObject, Parcel out);
    private static native long nativeReadFromParcel(Parcel in);
    private static native IBinder nativeGetBinderToken(long nativeObject);
    private static native long nativeGetBinderTokenRef(long nativeObject);
    private static native long nativeGetNativeInputTransferTokenFinalizer();
    private static native boolean nativeEquals(long nativeObject1, long nativeObject2);

@@ -130,7 +131,7 @@ public final class InputTransferToken implements Parcelable {
     */
    @Override
    public int hashCode() {
        return Objects.hash(getToken());
        return Objects.hash(nativeGetBinderTokenRef(mNativeObject));
    }

    /**
+6 −0
Original line number Diff line number Diff line
@@ -70,6 +70,11 @@ static jobject nativeGetBinderToken(JNIEnv* env, jclass clazz, jlong nativeObj)
    return javaObjectForIBinder(env, inputTransferToken->mToken);
}

static jlong nativeGetBinderTokenRef(JNIEnv*, jclass, jlong nativeObj) {
    sp<InputTransferToken> inputTransferToken = reinterpret_cast<InputTransferToken*>(nativeObj);
    return reinterpret_cast<jlong>(inputTransferToken->mToken.get());
}

InputTransferToken* android_window_InputTransferToken_getNativeInputTransferToken(
        JNIEnv* env, jobject inputTransferTokenObj) {
    if (inputTransferTokenObj != nullptr &&
@@ -114,6 +119,7 @@ static const JNINativeMethod sInputTransferTokenMethods[] = {
    {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V", (void*)nativeWriteToParcel},
    {"nativeReadFromParcel", "(Landroid/os/Parcel;)J", (void*)nativeReadFromParcel},
    {"nativeGetBinderToken", "(J)Landroid/os/IBinder;", (void*)nativeGetBinderToken},
    {"nativeGetBinderTokenRef", "(J)J", (void*)nativeGetBinderTokenRef},
    {"nativeGetNativeInputTransferTokenFinalizer", "()J", (void*)nativeGetNativeInputTransferTokenFinalizer},
        {"nativeEquals", "(JJ)Z", (void*) nativeEquals},
        // clang-format on