diff options
author | 2025-01-24 15:18:23 -0800 | |
---|---|---|
committer | 2025-01-27 11:08:29 -0800 | |
commit | 2f8c71a52c1f6d8808ece44fbdce25e6176f4e44 (patch) | |
tree | 825f7e0afaf90a86a929fc4467c3dbb8220aec18 | |
parent | 5920fd28beebeb682d3918da105bfe8ad68bde73 (diff) |
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
7 files changed, 24 insertions, 21 deletions
diff --git a/services/inputflinger/tests/CursorInputMapper_test.cpp b/services/inputflinger/tests/CursorInputMapper_test.cpp index 18e0b309ba..594ee3b579 100644 --- a/services/inputflinger/tests/CursorInputMapper_test.cpp +++ b/services/inputflinger/tests/CursorInputMapper_test.cpp @@ -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) { diff --git a/services/inputflinger/tests/InputMapperTest.cpp b/services/inputflinger/tests/InputMapperTest.cpp index 8235c90da6..77f42f2e72 100644 --- a/services/inputflinger/tests/InputMapperTest.cpp +++ b/services/inputflinger/tests/InputMapperTest.cpp @@ -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); } diff --git a/services/inputflinger/tests/InputMapperTest.h b/services/inputflinger/tests/InputMapperTest.h index 10ef6f1660..edc87a32b0 100644 --- a/services/inputflinger/tests/InputMapperTest.h +++ b/services/inputflinger/tests/InputMapperTest.h @@ -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); diff --git a/services/inputflinger/tests/InterfaceMocks.h b/services/inputflinger/tests/InterfaceMocks.h index 5910238186..dce54728ed 100644 --- a/services/inputflinger/tests/InterfaceMocks.h +++ b/services/inputflinger/tests/InterfaceMocks.h @@ -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 diff --git a/services/inputflinger/tests/KeyboardInputMapper_test.cpp b/services/inputflinger/tests/KeyboardInputMapper_test.cpp index 1dd32c447b..17acdd49cf 100644 --- a/services/inputflinger/tests/KeyboardInputMapper_test.cpp +++ b/services/inputflinger/tests/KeyboardInputMapper_test.cpp @@ -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, diff --git a/services/inputflinger/tests/MultiTouchInputMapper_test.cpp b/services/inputflinger/tests/MultiTouchInputMapper_test.cpp index d15048dddf..0ea22d4175 100644 --- a/services/inputflinger/tests/MultiTouchInputMapper_test.cpp +++ b/services/inputflinger/tests/MultiTouchInputMapper_test.cpp @@ -53,8 +53,9 @@ static constexpr int32_t ACTION_POINTER_1_DOWN = */ class MultiTouchInputMapperUnitTest : public InputMapperUnitTest { protected: - void SetUp() override { - InputMapperUnitTest::SetUp(); + void SetUp() override { SetUp(/*bus=*/0, /*isExternal=*/false); } + void SetUp(int bus, bool isExternal) override { + InputMapperUnitTest::SetUp(bus, isExternal); // Present scan codes expectScanCodes(/*present=*/true, diff --git a/services/inputflinger/tests/RotaryEncoderInputMapper_test.cpp b/services/inputflinger/tests/RotaryEncoderInputMapper_test.cpp index 157bee33e1..548df2255b 100644 --- a/services/inputflinger/tests/RotaryEncoderInputMapper_test.cpp +++ b/services/inputflinger/tests/RotaryEncoderInputMapper_test.cpp @@ -89,9 +89,9 @@ namespace vd_flags = android::companion::virtualdevice::flags; */ class RotaryEncoderInputMapperTest : public InputMapperUnitTest { protected: - void SetUp() override { SetUpWithBus(BUS_USB); } - void SetUpWithBus(int bus) override { - InputMapperUnitTest::SetUpWithBus(bus); + void SetUp() override { SetUp(/*bus=*/0, /*isExternal=*/false); } + void SetUp(int bus, bool isExternal) override { + InputMapperUnitTest::SetUp(bus, isExternal); EXPECT_CALL(mMockEventHub, hasRelativeAxis(EVENTHUB_ID, REL_WHEEL)) .WillRepeatedly(Return(true)); |