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

Commit 692c65bf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Pass BTN_GEAR_DOWN and BTN_GEAR_UP to apps" into rvc-dev

parents 12a5e88d a0d2b809
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1318,7 +1318,7 @@ status_t EventHub::openDeviceLocked(const char* devicePath) {
    // joystick and gamepad buttons which are handled like keyboards for the most part.
    // joystick and gamepad buttons which are handled like keyboards for the most part.
    bool haveKeyboardKeys =
    bool haveKeyboardKeys =
            containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC)) ||
            containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC)) ||
            containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK),
            containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_WHEEL),
                                sizeof_bit_array(KEY_MAX + 1));
                                sizeof_bit_array(KEY_MAX + 1));
    bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC),
    bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC),
                                                  sizeof_bit_array(BTN_MOUSE)) ||
                                                  sizeof_bit_array(BTN_MOUSE)) ||
+1 −1
Original line number Original line Diff line number Diff line
@@ -233,7 +233,7 @@ void KeyboardInputMapper::process(const RawEvent* rawEvent) {
}
}


bool KeyboardInputMapper::isKeyboardOrGamepadKey(int32_t scanCode) {
bool KeyboardInputMapper::isKeyboardOrGamepadKey(int32_t scanCode) {
    return scanCode < BTN_MOUSE || scanCode >= KEY_OK ||
    return scanCode < BTN_MOUSE || scanCode >= BTN_WHEEL ||
            (scanCode >= BTN_MISC && scanCode < BTN_MOUSE) ||
            (scanCode >= BTN_MISC && scanCode < BTN_MOUSE) ||
            (scanCode >= BTN_JOYSTICK && scanCode < BTN_DIGI);
            (scanCode >= BTN_JOYSTICK && scanCode < BTN_DIGI);
}
}
+22 −0
Original line number Original line Diff line number Diff line
@@ -1848,6 +1848,28 @@ TEST_F(InputReaderIntegrationTest, SendsEventsToInputListener) {
    ASSERT_LE(prevTimestamp, keyArgs.eventTime);
    ASSERT_LE(prevTimestamp, keyArgs.eventTime);
}
}


/**
 * The Steam controller sends BTN_GEAR_DOWN and BTN_GEAR_UP for the two "paddle" buttons
 * on the back. In this test, we make sure that BTN_GEAR_DOWN / BTN_WHEEL and BTN_GEAR_UP
 * are passed to the listener.
 */
static_assert(BTN_GEAR_DOWN == BTN_WHEEL);
TEST_F(InputReaderIntegrationTest, SendsGearDownAndUpToInputListener) {
    std::unique_ptr<UinputSteamController> controller = createUinputDevice<UinputSteamController>();
    ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
    NotifyKeyArgs keyArgs;

    controller->pressAndReleaseKey(BTN_GEAR_DOWN);
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyKeyWasCalled(&keyArgs)); // ACTION_DOWN
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyKeyWasCalled(&keyArgs)); // ACTION_UP
    ASSERT_EQ(BTN_GEAR_DOWN, keyArgs.scanCode);

    controller->pressAndReleaseKey(BTN_GEAR_UP);
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyKeyWasCalled(&keyArgs)); // ACTION_DOWN
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyKeyWasCalled(&keyArgs)); // ACTION_UP
    ASSERT_EQ(BTN_GEAR_UP, keyArgs.scanCode);
}

// --- TouchProcessTest ---
// --- TouchProcessTest ---
class TouchIntegrationTest : public InputReaderIntegrationTest {
class TouchIntegrationTest : public InputReaderIntegrationTest {
protected:
protected:
+3 −0
Original line number Original line Diff line number Diff line
@@ -125,6 +125,9 @@ void UinputHomeKey::pressAndReleaseHomeKey() {
    pressAndReleaseKey(KEY_HOME);
    pressAndReleaseKey(KEY_HOME);
}
}


// --- UinputSteamController
UinputSteamController::UinputSteamController() : UinputKeyboard({BTN_GEAR_DOWN, BTN_GEAR_UP}) {}

// --- UinputTouchScreen ---
// --- UinputTouchScreen ---
UinputTouchScreen::UinputTouchScreen(const Rect* size)
UinputTouchScreen::UinputTouchScreen(const Rect* size)
      : UinputDevice(UinputTouchScreen::DEVICE_NAME), mSize(*size) {}
      : UinputDevice(UinputTouchScreen::DEVICE_NAME), mSize(*size) {}
+10 −0
Original line number Original line Diff line number Diff line
@@ -108,6 +108,16 @@ private:
    UinputHomeKey();
    UinputHomeKey();
};
};


// A joystick device that sends a BTN_GEAR_DOWN / BTN_WHEEL key.
class UinputSteamController : public UinputKeyboard {
public:
    template <class D, class... Ts>
    friend std::unique_ptr<D> createUinputDevice(Ts... args);

private:
    UinputSteamController();
};

// --- UinputTouchScreen ---
// --- UinputTouchScreen ---
// A touch screen device with specific size.
// A touch screen device with specific size.
class UinputTouchScreen : public UinputDevice {
class UinputTouchScreen : public UinputDevice {