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

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

Mocked device should be consistently external or internal

Currently, we are allowing device's isExternal API to return different
values dynamically. In practice, this property should not change.

In this CL, make this property determined upon construction, and force
the current users to explicitly specify it.

This will allow us to more simply emulate external touchscreens in
subsequent CLs.

Bug: 378308551
Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Flag: TEST_ONLY
Change-Id: Iaf917c336fba8c66f3b7f7459bf7fe9aaae02d5e
parent 5920fd28
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -141,9 +141,9 @@ namespace vd_flags = android::companion::virtualdevice::flags;
 */
class CursorInputMapperUnitTestBase : public InputMapperUnitTest {
protected:
    void SetUp() override { SetUpWithBus(BUS_USB); }
    void SetUpWithBus(int bus) override {
        InputMapperUnitTest::SetUpWithBus(bus);
    void SetUp() override { SetUp(BUS_USB, /*isExternal=*/false); }
    void SetUp(int bus, bool isExternal) override {
        InputMapperUnitTest::SetUp(bus, isExternal);

        // Current scan code state - all keys are UP by default
        setScanCodeState(KeyState::UP,
@@ -1142,7 +1142,9 @@ constexpr nsecs_t MAX_BLUETOOTH_SMOOTHING_DELTA = ms2ns(32);

class BluetoothCursorInputMapperUnitTest : public CursorInputMapperUnitTestBase {
protected:
    void SetUp() override { SetUpWithBus(BUS_BLUETOOTH); }
    void SetUp() override {
        CursorInputMapperUnitTestBase::SetUp(BUS_BLUETOOTH, /*isExternal=*/true);
    }
};

TEST_F(BluetoothCursorInputMapperUnitTest, TimestampSmoothening) {
+4 −3
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ using testing::NiceMock;
using testing::Return;
using testing::ReturnRef;

void InputMapperUnitTest::SetUpWithBus(int bus) {
void InputMapperUnitTest::SetUp(int bus, bool isExternal) {
    mFakePolicy = sp<FakeInputReaderPolicy>::make();

    EXPECT_CALL(mMockInputReaderContext, getPolicy()).WillRepeatedly(Return(mFakePolicy.get()));
@@ -46,8 +46,9 @@ void InputMapperUnitTest::SetUpWithBus(int bus) {
        return mPropertyMap;
    });

    mDevice = std::make_unique<NiceMock<MockInputDevice>>(&mMockInputReaderContext, DEVICE_ID,
                                                          /*generation=*/2, mIdentifier);
    mDevice =
            std::make_unique<NiceMock<MockInputDevice>>(&mMockInputReaderContext, DEVICE_ID,
                                                        /*generation=*/2, mIdentifier, isExternal);
    ON_CALL((*mDevice), getConfiguration).WillByDefault(ReturnRef(mPropertyMap));
    mDeviceContext = std::make_unique<InputDeviceContext>(*mDevice, EVENTHUB_ID);
}
+2 −2
Original line number Diff line number Diff line
@@ -40,8 +40,8 @@ class InputMapperUnitTest : public testing::Test {
protected:
    static constexpr int32_t EVENTHUB_ID = 1;
    static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
    virtual void SetUp() override { SetUpWithBus(0); }
    virtual void SetUpWithBus(int bus);
    virtual void SetUp() override { SetUp(/*bus=*/0, /*isExternal=*/false); }
    virtual void SetUp(int bus, bool isExternal);

    void setupAxis(int axis, bool valid, int32_t min, int32_t max, int32_t resolution,
                   int32_t flat = 0, int32_t fuzz = 0);
+4 −3
Original line number Diff line number Diff line
@@ -196,14 +196,14 @@ public:
class MockInputDevice : public InputDevice {
public:
    MockInputDevice(InputReaderContext* context, int32_t id, int32_t generation,
                    const InputDeviceIdentifier& identifier)
          : InputDevice(context, id, generation, identifier) {}
                    const InputDeviceIdentifier& identifier, bool isExternal)
          : InputDevice(context, id, generation, identifier), mIsExternal(isExternal) {}

    MOCK_METHOD(uint32_t, getSources, (), (const, override));
    MOCK_METHOD(std::optional<DisplayViewport>, getAssociatedViewport, (), (const));
    MOCK_METHOD(KeyboardType, getKeyboardType, (), (const, override));
    MOCK_METHOD(bool, isEnabled, (), ());
    MOCK_METHOD(bool, isExternal, (), (override));
    bool isExternal() override { return mIsExternal; }

    MOCK_METHOD(void, dump, (std::string& dump, const std::string& eventHubDevStr), ());
    MOCK_METHOD(void, addEmptyEventHubDevice, (int32_t eventHubId), ());
@@ -266,5 +266,6 @@ public:

private:
    int32_t mGeneration = 0;
    const bool mIsExternal;
};
} // namespace android
+2 −4
Original line number Diff line number Diff line
@@ -1085,10 +1085,9 @@ TEST_F(KeyboardInputMapperTest, UsesSharedKeyboardSource) {
class KeyboardInputMapperTest_ExternalAlphabeticDevice : public KeyboardInputMapperUnitTest {
protected:
    void SetUp() override {
        InputMapperUnitTest::SetUp();
        InputMapperUnitTest::SetUp(/*bus=*/0, /*isExternal=*/true);
        ON_CALL((*mDevice), getSources).WillByDefault(Return(AINPUT_SOURCE_KEYBOARD));
        ON_CALL((*mDevice), getKeyboardType).WillByDefault(Return(KeyboardType::ALPHABETIC));
        ON_CALL((*mDevice), isExternal).WillByDefault(Return(true));
        EXPECT_CALL(mMockEventHub, getDeviceClasses(EVENTHUB_ID))
                .WillRepeatedly(Return(InputDeviceClass::KEYBOARD | InputDeviceClass::ALPHAKEY |
                                       InputDeviceClass::EXTERNAL));
@@ -1102,10 +1101,9 @@ protected:
class KeyboardInputMapperTest_ExternalNonAlphabeticDevice : public KeyboardInputMapperUnitTest {
protected:
    void SetUp() override {
        InputMapperUnitTest::SetUp();
        InputMapperUnitTest::SetUp(/*bus=*/0, /*isExternal=*/true);
        ON_CALL((*mDevice), getSources).WillByDefault(Return(AINPUT_SOURCE_KEYBOARD));
        ON_CALL((*mDevice), getKeyboardType).WillByDefault(Return(KeyboardType::NON_ALPHABETIC));
        ON_CALL((*mDevice), isExternal).WillByDefault(Return(true));
        EXPECT_CALL(mMockEventHub, getDeviceClasses(EVENTHUB_ID))
                .WillRepeatedly(Return(InputDeviceClass::KEYBOARD | InputDeviceClass::EXTERNAL));
        mMapper = createInputMapper<KeyboardInputMapper>(*mDeviceContext, mReaderConfiguration,
Loading