Loading cmds/uinput/jni/com_android_commands_uinput_Device.cpp +9 −3 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ JNIEnv* DeviceCallback::getJNIEnv() { std::unique_ptr<UinputDevice> UinputDevice::open(int32_t id, const char* name, int32_t vid, int32_t pid, uint16_t bus, uint32_t ffEffectsMax, const char* port, std::unique_ptr<DeviceCallback> callback) { android::base::unique_fd fd(::open(UINPUT_PATH, O_RDWR | O_NONBLOCK | O_CLOEXEC)); if (!fd.ok()) { Loading Loading @@ -131,6 +132,9 @@ std::unique_ptr<UinputDevice> UinputDevice::open(int32_t id, const char* name, i return nullptr; } // set the physical port. ::ioctl(fd, UI_SET_PHYS, port); if (::ioctl(fd, UI_DEV_CREATE) != 0) { ALOGE("Unable to create uinput device: %s.", strerror(errno)); return nullptr; Loading Loading @@ -240,17 +244,19 @@ std::vector<int32_t> toVector(JNIEnv* env, jintArray javaArray) { } static jlong openUinputDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid, jint pid, jint bus, jint ffEffectsMax, jobject callback) { jint pid, jint bus, jint ffEffectsMax, jstring rawPort, jobject callback) { ScopedUtfChars name(env, rawName); if (name.c_str() == nullptr) { return 0; } ScopedUtfChars port(env, rawPort); std::unique_ptr<uinput::DeviceCallback> cb = std::make_unique<uinput::DeviceCallback>(env, callback); std::unique_ptr<uinput::UinputDevice> d = uinput::UinputDevice::open(id, name.c_str(), vid, pid, bus, ffEffectsMax, uinput::UinputDevice::open(id, name.c_str(), vid, pid, bus, ffEffectsMax, port.c_str(), std::move(cb)); return reinterpret_cast<jlong>(d.release()); } Loading Loading @@ -303,7 +309,7 @@ static void setAbsInfo(JNIEnv* env, jclass /* clazz */, jint handle, jint axisCo static JNINativeMethod sMethods[] = { {"nativeOpenUinputDevice", "(Ljava/lang/String;IIIII" "(Ljava/lang/String;IIIIILjava/lang/String;" "Lcom/android/commands/uinput/Device$DeviceCallback;)J", reinterpret_cast<void*>(openUinputDevice)}, {"nativeInjectEvent", "(JIII)V", reinterpret_cast<void*>(injectEvent)}, Loading cmds/uinput/jni/com_android_commands_uinput_Device.h +1 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ class UinputDevice { public: static std::unique_ptr<UinputDevice> open(int32_t id, const char* name, int32_t vid, int32_t pid, uint16_t bus, uint32_t ff_effects_max, const char* port, std::unique_ptr<DeviceCallback> callback); virtual ~UinputDevice(); Loading cmds/uinput/src/com/android/commands/uinput/Device.java +8 −3 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public class Device { } private static native long nativeOpenUinputDevice(String name, int id, int vid, int pid, int bus, int ffEffectsMax, DeviceCallback callback); int bus, int ffEffectsMax, String port, DeviceCallback callback); private static native void nativeCloseUinputDevice(long ptr); private static native void nativeInjectEvent(long ptr, int type, int code, int value); private static native void nativeConfigure(int handle, int code, int[] configs); Loading @@ -69,7 +69,7 @@ public class Device { public Device(int id, String name, int vid, int pid, int bus, SparseArray<int[]> configuration, int ffEffectsMax, SparseArray<InputAbsInfo> absInfo) { SparseArray<InputAbsInfo> absInfo, String port) { mId = id; mThread = new HandlerThread("UinputDeviceHandler"); mThread.start(); Loading @@ -88,6 +88,11 @@ public class Device { } else { args.arg1 = id + ":" + vid + ":" + pid; } if (port != null) { args.arg2 = port; } else { args.arg2 = "uinput:" + id + ":" + vid + ":" + pid; } mHandler.obtainMessage(MSG_OPEN_UINPUT_DEVICE, args).sendToTarget(); mTimeToSend = SystemClock.uptimeMillis(); Loading Loading @@ -142,7 +147,7 @@ public class Device { case MSG_OPEN_UINPUT_DEVICE: SomeArgs args = (SomeArgs) msg.obj; mPtr = nativeOpenUinputDevice((String) args.arg1, args.argi1, args.argi2, args.argi3, args.argi4, args.argi5, args.argi3, args.argi4, args.argi5, (String) args.arg2, new DeviceCallback()); break; case MSG_INJECT_EVENT: Loading cmds/uinput/src/com/android/commands/uinput/Event.java +13 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ public class Event { private SparseArray<int[]> mConfiguration; private int mDuration; private int mFfEffectsMax = 0; private String mInputport; private SparseArray<InputAbsInfo> mAbsInfo; public int getId() { Loading Loading @@ -110,6 +111,10 @@ public class Event { return mAbsInfo; } public String getPort() { return mInputport; } /** * Convert an event to String. */ Loading @@ -124,6 +129,7 @@ public class Event { + ", configuration=" + mConfiguration + ", duration=" + mDuration + ", ff_effects_max=" + mFfEffectsMax + ", port=" + mInputport + "}"; } Loading Loading @@ -178,6 +184,10 @@ public class Event { mEvent.mAbsInfo = absInfo; } public void setInputport(String port) { mEvent.mInputport = port; } public Event build() { if (mEvent.mId == -1) { throw new IllegalStateException("No event id"); Loading Loading @@ -262,6 +272,9 @@ public class Event { case "duration": eb.setDuration(readInt()); break; case "port": eb.setInputport(mReader.nextString()); break; default: mReader.skipValue(); } Loading cmds/uinput/src/com/android/commands/uinput/Uinput.java +1 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public class Uinput { } int id = e.getId(); Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), e.getBus(), e.getConfiguration(), e.getFfEffectsMax(), e.getAbsInfo()); e.getConfiguration(), e.getFfEffectsMax(), e.getAbsInfo(), e.getPort()); mDevices.append(id, d); } Loading Loading
cmds/uinput/jni/com_android_commands_uinput_Device.cpp +9 −3 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ JNIEnv* DeviceCallback::getJNIEnv() { std::unique_ptr<UinputDevice> UinputDevice::open(int32_t id, const char* name, int32_t vid, int32_t pid, uint16_t bus, uint32_t ffEffectsMax, const char* port, std::unique_ptr<DeviceCallback> callback) { android::base::unique_fd fd(::open(UINPUT_PATH, O_RDWR | O_NONBLOCK | O_CLOEXEC)); if (!fd.ok()) { Loading Loading @@ -131,6 +132,9 @@ std::unique_ptr<UinputDevice> UinputDevice::open(int32_t id, const char* name, i return nullptr; } // set the physical port. ::ioctl(fd, UI_SET_PHYS, port); if (::ioctl(fd, UI_DEV_CREATE) != 0) { ALOGE("Unable to create uinput device: %s.", strerror(errno)); return nullptr; Loading Loading @@ -240,17 +244,19 @@ std::vector<int32_t> toVector(JNIEnv* env, jintArray javaArray) { } static jlong openUinputDevice(JNIEnv* env, jclass /* clazz */, jstring rawName, jint id, jint vid, jint pid, jint bus, jint ffEffectsMax, jobject callback) { jint pid, jint bus, jint ffEffectsMax, jstring rawPort, jobject callback) { ScopedUtfChars name(env, rawName); if (name.c_str() == nullptr) { return 0; } ScopedUtfChars port(env, rawPort); std::unique_ptr<uinput::DeviceCallback> cb = std::make_unique<uinput::DeviceCallback>(env, callback); std::unique_ptr<uinput::UinputDevice> d = uinput::UinputDevice::open(id, name.c_str(), vid, pid, bus, ffEffectsMax, uinput::UinputDevice::open(id, name.c_str(), vid, pid, bus, ffEffectsMax, port.c_str(), std::move(cb)); return reinterpret_cast<jlong>(d.release()); } Loading Loading @@ -303,7 +309,7 @@ static void setAbsInfo(JNIEnv* env, jclass /* clazz */, jint handle, jint axisCo static JNINativeMethod sMethods[] = { {"nativeOpenUinputDevice", "(Ljava/lang/String;IIIII" "(Ljava/lang/String;IIIIILjava/lang/String;" "Lcom/android/commands/uinput/Device$DeviceCallback;)J", reinterpret_cast<void*>(openUinputDevice)}, {"nativeInjectEvent", "(JIII)V", reinterpret_cast<void*>(injectEvent)}, Loading
cmds/uinput/jni/com_android_commands_uinput_Device.h +1 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ class UinputDevice { public: static std::unique_ptr<UinputDevice> open(int32_t id, const char* name, int32_t vid, int32_t pid, uint16_t bus, uint32_t ff_effects_max, const char* port, std::unique_ptr<DeviceCallback> callback); virtual ~UinputDevice(); Loading
cmds/uinput/src/com/android/commands/uinput/Device.java +8 −3 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public class Device { } private static native long nativeOpenUinputDevice(String name, int id, int vid, int pid, int bus, int ffEffectsMax, DeviceCallback callback); int bus, int ffEffectsMax, String port, DeviceCallback callback); private static native void nativeCloseUinputDevice(long ptr); private static native void nativeInjectEvent(long ptr, int type, int code, int value); private static native void nativeConfigure(int handle, int code, int[] configs); Loading @@ -69,7 +69,7 @@ public class Device { public Device(int id, String name, int vid, int pid, int bus, SparseArray<int[]> configuration, int ffEffectsMax, SparseArray<InputAbsInfo> absInfo) { SparseArray<InputAbsInfo> absInfo, String port) { mId = id; mThread = new HandlerThread("UinputDeviceHandler"); mThread.start(); Loading @@ -88,6 +88,11 @@ public class Device { } else { args.arg1 = id + ":" + vid + ":" + pid; } if (port != null) { args.arg2 = port; } else { args.arg2 = "uinput:" + id + ":" + vid + ":" + pid; } mHandler.obtainMessage(MSG_OPEN_UINPUT_DEVICE, args).sendToTarget(); mTimeToSend = SystemClock.uptimeMillis(); Loading Loading @@ -142,7 +147,7 @@ public class Device { case MSG_OPEN_UINPUT_DEVICE: SomeArgs args = (SomeArgs) msg.obj; mPtr = nativeOpenUinputDevice((String) args.arg1, args.argi1, args.argi2, args.argi3, args.argi4, args.argi5, args.argi3, args.argi4, args.argi5, (String) args.arg2, new DeviceCallback()); break; case MSG_INJECT_EVENT: Loading
cmds/uinput/src/com/android/commands/uinput/Event.java +13 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ public class Event { private SparseArray<int[]> mConfiguration; private int mDuration; private int mFfEffectsMax = 0; private String mInputport; private SparseArray<InputAbsInfo> mAbsInfo; public int getId() { Loading Loading @@ -110,6 +111,10 @@ public class Event { return mAbsInfo; } public String getPort() { return mInputport; } /** * Convert an event to String. */ Loading @@ -124,6 +129,7 @@ public class Event { + ", configuration=" + mConfiguration + ", duration=" + mDuration + ", ff_effects_max=" + mFfEffectsMax + ", port=" + mInputport + "}"; } Loading Loading @@ -178,6 +184,10 @@ public class Event { mEvent.mAbsInfo = absInfo; } public void setInputport(String port) { mEvent.mInputport = port; } public Event build() { if (mEvent.mId == -1) { throw new IllegalStateException("No event id"); Loading Loading @@ -262,6 +272,9 @@ public class Event { case "duration": eb.setDuration(readInt()); break; case "port": eb.setInputport(mReader.nextString()); break; default: mReader.skipValue(); } Loading
cmds/uinput/src/com/android/commands/uinput/Uinput.java +1 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public class Uinput { } int id = e.getId(); Device d = new Device(id, e.getName(), e.getVendorId(), e.getProductId(), e.getBus(), e.getConfiguration(), e.getFfEffectsMax(), e.getAbsInfo()); e.getConfiguration(), e.getFfEffectsMax(), e.getAbsInfo(), e.getPort()); mDevices.append(id, d); } Loading