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

Commit a931d521 authored by Ashok Bhat's avatar Ashok Bhat Committed by David Butcher
Browse files

AArch64: Use long for pointers in view/input classes



For storing pointers, long is used in view/input classes,
as native pointers can be 64-bit.

In addition, some minor changes have been done
to conform with standard JNI practice (e.g. use
of jint instead of int in JNI function prototypes)

Change-Id: Iafda9f4653c023bcba95b873637d935d0b569f5d
Signed-off-by: default avatarAshok Bhat <ashok.bhat@arm.com>
Signed-off-by: default avatarMarcus Oakland <marcus.oakland@arm.com>
Signed-off-by: default avatarKévin PETIT <kevin.petit@arm.com>
parent 76d5cdd8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public final class InputChannel implements Parcelable {
    };
    
    @SuppressWarnings("unused")
    private int mPtr; // used by native code
    private long mPtr; // used by native code
    
    private static native InputChannel[] nativeOpenInputChannelPair(String name);
    
+5 −5
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ public abstract class InputEventReceiver {

    private final CloseGuard mCloseGuard = CloseGuard.get();

    private int mReceiverPtr;
    private long mReceiverPtr;

    // We keep references to the input channel and message queue objects here so that
    // they are not GC'd while the native peer of the receiver is using them.
@@ -44,11 +44,11 @@ public abstract class InputEventReceiver {
    // Map from InputEvent sequence numbers to dispatcher sequence numbers.
    private final SparseIntArray mSeqMap = new SparseIntArray();

    private static native int nativeInit(WeakReference<InputEventReceiver> receiver,
    private static native long nativeInit(WeakReference<InputEventReceiver> receiver,
            InputChannel inputChannel, MessageQueue messageQueue);
    private static native void nativeDispose(int receiverPtr);
    private static native void nativeFinishInputEvent(int receiverPtr, int seq, boolean handled);
    private static native boolean nativeConsumeBatchedInputEvents(int receiverPtr,
    private static native void nativeDispose(long receiverPtr);
    private static native void nativeFinishInputEvent(long receiverPtr, int seq, boolean handled);
    private static native boolean nativeConsumeBatchedInputEvents(long receiverPtr,
            long frameTimeNanos);

    /**
+5 −5
Original line number Diff line number Diff line
@@ -33,18 +33,18 @@ public abstract class InputEventSender {

    private final CloseGuard mCloseGuard = CloseGuard.get();

    private int mSenderPtr;
    private long mSenderPtr;

    // We keep references to the input channel and message queue objects here so that
    // they are not GC'd while the native peer of the receiver is using them.
    private InputChannel mInputChannel;
    private MessageQueue mMessageQueue;

    private static native int nativeInit(WeakReference<InputEventSender> sender,
    private static native long nativeInit(WeakReference<InputEventSender> sender,
            InputChannel inputChannel, MessageQueue messageQueue);
    private static native void nativeDispose(int senderPtr);
    private static native boolean nativeSendKeyEvent(int senderPtr, int seq, KeyEvent event);
    private static native boolean nativeSendMotionEvent(int senderPtr, int seq, MotionEvent event);
    private static native void nativeDispose(long senderPtr);
    private static native boolean nativeSendKeyEvent(long senderPtr, int seq, KeyEvent event);
    private static native boolean nativeSendMotionEvent(long senderPtr, int seq, MotionEvent event);

    /**
     * Creates an input event sender bound to the specified input channel.
+11 −11
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.os.Looper;
import android.os.MessageQueue;
import android.util.Pools.Pool;
import android.util.Pools.SimplePool;
import android.util.SparseArray;
import android.util.LongSparseArray;

import java.lang.ref.WeakReference;

@@ -32,20 +32,20 @@ import java.lang.ref.WeakReference;
 * input events.  Currently only usable from native code.
 */
public final class InputQueue {
    private final SparseArray<ActiveInputEvent> mActiveEventArray =
            new SparseArray<ActiveInputEvent>(20);
    private final LongSparseArray<ActiveInputEvent> mActiveEventArray =
            new LongSparseArray<ActiveInputEvent>(20);
    private final Pool<ActiveInputEvent> mActiveInputEventPool =
            new SimplePool<ActiveInputEvent>(20);

    private final CloseGuard mCloseGuard = CloseGuard.get();

    private int mPtr;
    private long mPtr;

    private static native int nativeInit(WeakReference<InputQueue> weakQueue,
    private static native long nativeInit(WeakReference<InputQueue> weakQueue,
            MessageQueue messageQueue);
    private static native int nativeSendKeyEvent(int ptr, KeyEvent e, boolean preDispatch);
    private static native int nativeSendMotionEvent(int ptr, MotionEvent e);
    private static native void nativeDispose(int ptr);
    private static native long nativeSendKeyEvent(long ptr, KeyEvent e, boolean preDispatch);
    private static native long nativeSendMotionEvent(long ptr, MotionEvent e);
    private static native void nativeDispose(long ptr);

    /** @hide */
    public InputQueue() {
@@ -84,7 +84,7 @@ public final class InputQueue {
    }

    /** @hide */
    public int getNativePtr() {
    public long getNativePtr() {
        return mPtr;
    }

@@ -92,7 +92,7 @@ public final class InputQueue {
    public void sendInputEvent(InputEvent e, Object token, boolean predispatch,
            FinishedInputEventCallback callback) {
        ActiveInputEvent event = obtainActiveInputEvent(token, callback);
        int id;
        long id;
        if (e instanceof KeyEvent) {
            id = nativeSendKeyEvent(mPtr, (KeyEvent) e, predispatch);
        } else {
@@ -101,7 +101,7 @@ public final class InputQueue {
        mActiveEventArray.put(id, event);
    }

    private void finishInputEvent(int id, boolean handled) {
    private void finishInputEvent(long id, boolean handled) {
        int index = mActiveEventArray.indexOfKey(id);
        if (index >= 0) {
            ActiveInputEvent e = mActiveEventArray.valueAt(index);
+5 −5
Original line number Diff line number Diff line
@@ -81,14 +81,14 @@ void NativeInputChannel::invokeAndRemoveDisposeCallback(JNIEnv* env, jobject obj

static NativeInputChannel* android_view_InputChannel_getNativeInputChannel(JNIEnv* env,
        jobject inputChannelObj) {
    jint intPtr = env->GetIntField(inputChannelObj, gInputChannelClassInfo.mPtr);
    return reinterpret_cast<NativeInputChannel*>(intPtr);
    jlong longPtr = env->GetLongField(inputChannelObj, gInputChannelClassInfo.mPtr);
    return reinterpret_cast<NativeInputChannel*>(longPtr);
}

static void android_view_InputChannel_setNativeInputChannel(JNIEnv* env, jobject inputChannelObj,
        NativeInputChannel* nativeInputChannel) {
    env->SetIntField(inputChannelObj, gInputChannelClassInfo.mPtr,
             reinterpret_cast<jint>(nativeInputChannel));
    env->SetLongField(inputChannelObj, gInputChannelClassInfo.mPtr,
             reinterpret_cast<jlong>(nativeInputChannel));
}

sp<InputChannel> android_view_InputChannel_getInputChannel(JNIEnv* env, jobject inputChannelObj) {
@@ -296,7 +296,7 @@ int register_android_view_InputChannel(JNIEnv* env) {
    FIND_CLASS(gInputChannelClassInfo.clazz, "android/view/InputChannel");

    GET_FIELD_ID(gInputChannelClassInfo.mPtr, gInputChannelClassInfo.clazz,
            "mPtr", "I");
            "mPtr", "J");
    
    GET_METHOD_ID(gInputChannelClassInfo.ctor, gInputChannelClassInfo.clazz,
            "<init>", "()V");
Loading