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

Commit 51483569 authored by Arthur Hung's avatar Arthur Hung Committed by Android (Google) Code Review
Browse files

Merge "Expose input association to be testable"

parents 651aa5a1 72986928
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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()) {
@@ -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;
@@ -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());
}
@@ -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)},
+1 −0
Original line number Diff line number Diff line
@@ -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();
+8 −3
Original line number Diff line number Diff line
@@ -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);
@@ -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();
@@ -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();
@@ -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:
+13 −0
Original line number Diff line number Diff line
@@ -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() {
@@ -110,6 +111,10 @@ public class Event {
        return mAbsInfo;
    }

    public String getPort() {
        return mInputport;
    }

    /**
     * Convert an event to String.
     */
@@ -124,6 +129,7 @@ public class Event {
            + ", configuration=" + mConfiguration
            + ", duration=" + mDuration
            + ", ff_effects_max=" + mFfEffectsMax
            + ", port=" + mInputport
            + "}";
    }

@@ -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");
@@ -262,6 +272,9 @@ public class Event {
                            case "duration":
                                eb.setDuration(readInt());
                                break;
                            case "port":
                                eb.setInputport(mReader.nextString());
                                break;
                            default:
                                mReader.skipValue();
                        }
+1 −1
Original line number Diff line number Diff line
@@ -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