android - How to convert InputQueue to AInputQueue for apilevel 28 to 32 - Stack Overflow

I have custom implementation of NativeActivity (called MyNativeActivity) for which I need to handle onI

I have custom implementation of NativeActivity (called MyNativeActivity) for which I need to handle onInputQueueCreated(). Vanilla NativeActivity does by calling getNativePtr() directly.

NativeActivity.java

    public void onInputQueueCreated(InputQueue queue) {
        if (!mDestroyed) {
            mCurInputQueue = queue;
            onInputQueueCreatedNative(mNativeHandle, queue.getNativePtr());
        }
    }

But getNativePtr() being hidden member, It can only be used via JNI which I do for apilevel below 28. And for 33 and above I use AInputQueue_fromJava() provided by android-ndk.

Now the issue is for apilevel 28-32, getNativePtr() does not work and always return null.

Accessing hidden method Landroid/view/InputQueue;->getNativePtr()J (dark greylist, JNI)

So can InputQueue be even converted to AInputQueue ?

Edit:

With suggestion from perplexity.ai, I also tried reflection. this too returns null.

import java.lang.reflect.Method;
import sun.misc.Unsafe;
...
    public static long getIQNativePtr(InputQueue queue) {
        try {
            // Access the hidden method
            Method method = InputQueue.class.getDeclaredMethod("getNativePtr");
            method.setAccessible(true); // Bypass access checks
            return (long) method.invoke(queue); // Invoke and return native pointer
        } catch (Exception e) {
            e.printStackTrace();
            return 0; // Handle error appropriately
        }
    }
...

I have custom implementation of NativeActivity (called MyNativeActivity) for which I need to handle onInputQueueCreated(). Vanilla NativeActivity does by calling getNativePtr() directly.

NativeActivity.java

    public void onInputQueueCreated(InputQueue queue) {
        if (!mDestroyed) {
            mCurInputQueue = queue;
            onInputQueueCreatedNative(mNativeHandle, queue.getNativePtr());
        }
    }

But getNativePtr() being hidden member, It can only be used via JNI which I do for apilevel below 28. And for 33 and above I use AInputQueue_fromJava() provided by android-ndk.

Now the issue is for apilevel 28-32, getNativePtr() does not work and always return null.

Accessing hidden method Landroid/view/InputQueue;->getNativePtr()J (dark greylist, JNI)

So can InputQueue be even converted to AInputQueue ?

Edit:

With suggestion from perplexity.ai, I also tried reflection. this too returns null.

import java.lang.reflect.Method;
import sun.misc.Unsafe;
...
    public static long getIQNativePtr(InputQueue queue) {
        try {
            // Access the hidden method
            Method method = InputQueue.class.getDeclaredMethod("getNativePtr");
            method.setAccessible(true); // Bypass access checks
            return (long) method.invoke(queue); // Invoke and return native pointer
        } catch (Exception e) {
            e.printStackTrace();
            return 0; // Handle error appropriately
        }
    }
...
Share Improve this question edited Mar 3 at 8:53 dawnmenu asked Mar 3 at 8:12 dawnmenudawnmenu 415 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There was no need to handle onInputQueueCreated() and onInputQueueDestroyed() like NativeActivity does. Using onTouchEvent() onKeyUp() and onKeyDown() solved the issue.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745104229a4611462.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信