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

Commit 2d31d666 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Use a separate ScreenSize class in VirtualInputDeviceController

Before this CL, width and height of the screen were being passed
directly to the low-level function.

For some input device types, it is required to provide valid values for
these, while for others (like upcoming gamepad), it's not needed.

These values are now being put into a separate struct, so that the
calling code can be more explicit that it's providing it (or not).

Bug: 439992405
Test: atest InputTests
Flag: EXEMPT PURE_REFACTOR
Change-Id: Ided8b0789e9a400beb5362443618e727e7329bdc
parent ccee9a90
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -33,53 +33,53 @@ namespace android {
static constexpr jlong INVALID_PTR = 0;

static unique_fd openUinputJni(JNIEnv* env, jstring name, jint vendorId, jint productId,
                               jstring phys, DeviceType deviceType, jint screenHeight,
                               jint screenWidth) {
                               jstring phys, DeviceType deviceType,
                               std::optional<ui::Size> screenSize) {
    ScopedUtfChars readableName(env, name);
    ScopedUtfChars readablePhys(env, phys);
    return openUinput(readableName.c_str(), vendorId, productId, readablePhys.c_str(), deviceType,
                      screenHeight, screenWidth);
                      screenSize);
}

static jlong nativeOpenUinputDpad(JNIEnv* env, jobject thiz, jstring name, jint vendorId,
                                  jint productId, jstring phys) {
    auto fd = openUinputJni(env, name, vendorId, productId, phys, DeviceType::DPAD,
                            /* screenHeight= */ 0, /* screenWidth= */ 0);
                            /* screenSize= */ std::nullopt);
    return fd.ok() ? reinterpret_cast<jlong>(new VirtualDpad(std::move(fd))) : INVALID_PTR;
}

static jlong nativeOpenUinputKeyboard(JNIEnv* env, jobject thiz, jstring name, jint vendorId,
                                      jint productId, jstring phys) {
    auto fd = openUinputJni(env, name, vendorId, productId, phys, DeviceType::KEYBOARD,
                            /* screenHeight= */ 0, /* screenWidth= */ 0);
                            /* screenSize= */ std::nullopt);
    return fd.ok() ? reinterpret_cast<jlong>(new VirtualKeyboard(std::move(fd))) : INVALID_PTR;
}

static jlong nativeOpenUinputMouse(JNIEnv* env, jobject thiz, jstring name, jint vendorId,
                                   jint productId, jstring phys) {
    auto fd = openUinputJni(env, name, vendorId, productId, phys, DeviceType::MOUSE,
                            /* screenHeight= */ 0, /* screenWidth= */ 0);
                            /* screenSize= */ std::nullopt);
    return fd.ok() ? reinterpret_cast<jlong>(new VirtualMouse(std::move(fd))) : INVALID_PTR;
}

static jlong nativeOpenUinputTouchscreen(JNIEnv* env, jobject thiz, jstring name, jint vendorId,
                                         jint productId, jstring phys, jint height, jint width) {
    auto fd = openUinputJni(env, name, vendorId, productId, phys, DeviceType::TOUCHSCREEN, height,
                            width);
    auto fd = openUinputJni(env, name, vendorId, productId, phys, DeviceType::TOUCHSCREEN,
                            ui::Size{static_cast<int>(width), static_cast<int>(height)});
    return fd.ok() ? reinterpret_cast<jlong>(new VirtualTouchscreen(std::move(fd))) : INVALID_PTR;
}

static jlong nativeOpenUinputStylus(JNIEnv* env, jobject thiz, jstring name, jint vendorId,
                                    jint productId, jstring phys, jint height, jint width) {
    auto fd =
            openUinputJni(env, name, vendorId, productId, phys, DeviceType::STYLUS, height, width);
    auto fd = openUinputJni(env, name, vendorId, productId, phys, DeviceType::STYLUS,
                            ui::Size{static_cast<int>(width), static_cast<int>(height)});
    return fd.ok() ? reinterpret_cast<jlong>(new VirtualStylus(std::move(fd))) : INVALID_PTR;
}

static jlong nativeOpenUinputRotaryEncoder(JNIEnv* env, jobject thiz, jstring name, jint vendorId,
                                           jint productId, jstring phys, jint height, jint width) {
                                           jint productId, jstring phys) {
    auto fd = openUinputJni(env, name, vendorId, productId, phys, DeviceType::ROTARY_ENCODER,
                            /* screenHeight= */ 0, /* screenWidth= */ 0);
                            /* screenSize= */ std::nullopt);
    return fd.ok() ? reinterpret_cast<jlong>(new VirtualRotaryEncoder(std::move(fd))) : INVALID_PTR;
}