From b08159b4fff065c4d9397fbeeff8de884a212758 Mon Sep 17 00:00:00 2001 From: Biswarup Pal Date: Thu, 22 Aug 2024 09:12:19 +0000 Subject: Update dependent properties when deviceType is updated During TouchInputMapper configuration change, some properties such as mDisplayBounds, mRawToDisplay transform, etc are calculated based on the the deviceType of the input device. For VirtualNavigationTouchpad, these properties are not updated when the deviceType changes to "touchNavigation", resulting in wrong calculation of transforms. Hence, update these properties whenever deviceType changes during a configuration change. Test: atest SingleTouchInputMapperTest Test: atest android.hardware.input.cts.tests.VirtualDeviceMirrorDisplayTest#virtualNavigationTouchpad_touchEvent --iterations 100 Flag: EXEMPT minor fix Fixes: 361324951 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:9ce4d9ff277bb196cb816214d726a0019383c91f) Merged-In: I5f67bd24730c63473260ff8a630bbdc90325d375 Change-Id: I5f67bd24730c63473260ff8a630bbdc90325d375 --- .../reader/mapper/TouchInputMapper.cpp | 4 +- services/inputflinger/tests/InputReader_test.cpp | 115 +++++++++++++++------ 2 files changed, 83 insertions(+), 36 deletions(-) diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index 3c26d1d73e..539731b060 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -984,8 +984,9 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) viewportChanged = mViewport != newViewport; } + const bool deviceModeChanged = mDeviceMode != oldDeviceMode; bool skipViewportUpdate = false; - if (viewportChanged) { + if (viewportChanged || deviceModeChanged) { const bool viewportOrientationChanged = mViewport.orientation != newViewport.orientation; const bool viewportDisplayIdChanged = mViewport.displayId != newViewport.displayId; mViewport = newViewport; @@ -1027,7 +1028,6 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) } // If moving between pointer modes, need to reset some state. - bool deviceModeChanged = mDeviceMode != oldDeviceMode; if (deviceModeChanged) { mOrientedRanges.clear(); } diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 835f8b89c3..33ba79e717 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -57,6 +57,7 @@ namespace android { using namespace ftl::flag_operators; using testing::AllOf; +using testing::VariantWith; using std::chrono_literals::operator""ms; using std::chrono_literals::operator""s; @@ -4430,15 +4431,15 @@ protected: void prepareButtons(); void prepareAxes(int axes); - void processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y); - void processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y); - void processUp(SingleTouchInputMapper& mappery); - void processPressure(SingleTouchInputMapper& mapper, int32_t pressure); - void processToolMajor(SingleTouchInputMapper& mapper, int32_t toolMajor); - void processDistance(SingleTouchInputMapper& mapper, int32_t distance); - void processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, int32_t tiltY); - void processKey(SingleTouchInputMapper& mapper, int32_t code, int32_t value); - void processSync(SingleTouchInputMapper& mapper); + std::list processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y); + std::list processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y); + std::list processUp(SingleTouchInputMapper& mappery); + std::list processPressure(SingleTouchInputMapper& mapper, int32_t pressure); + std::list processToolMajor(SingleTouchInputMapper& mapper, int32_t toolMajor); + std::list processDistance(SingleTouchInputMapper& mapper, int32_t distance); + std::list processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, int32_t tiltY); + std::list processKey(SingleTouchInputMapper& mapper, int32_t code, int32_t value); + std::list processSync(SingleTouchInputMapper& mapper); }; void SingleTouchInputMapperTest::prepareButtons() { @@ -4468,47 +4469,57 @@ void SingleTouchInputMapperTest::prepareAxes(int axes) { } } -void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 1); - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x); - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y); +std::list SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper, + int32_t x, int32_t y) { + std::list args; + args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 1); + args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x); + args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y); + return args; } -void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x); - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y); +std::list SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper, + int32_t x, int32_t y) { + std::list args; + args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x); + args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y); + return args; } -void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper& mapper) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 0); +std::list SingleTouchInputMapperTest::processUp(SingleTouchInputMapper& mapper) { + return process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 0); } -void SingleTouchInputMapperTest::processPressure(SingleTouchInputMapper& mapper, int32_t pressure) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_PRESSURE, pressure); +std::list SingleTouchInputMapperTest::processPressure(SingleTouchInputMapper& mapper, + int32_t pressure) { + return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_PRESSURE, pressure); } -void SingleTouchInputMapperTest::processToolMajor(SingleTouchInputMapper& mapper, - int32_t toolMajor) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor); +std::list SingleTouchInputMapperTest::processToolMajor(SingleTouchInputMapper& mapper, + int32_t toolMajor) { + return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor); } -void SingleTouchInputMapperTest::processDistance(SingleTouchInputMapper& mapper, int32_t distance) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_DISTANCE, distance); +std::list SingleTouchInputMapperTest::processDistance(SingleTouchInputMapper& mapper, + int32_t distance) { + return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_DISTANCE, distance); } -void SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, - int32_t tiltY) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_X, tiltX); - process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_Y, tiltY); +std::list SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper, + int32_t tiltX, int32_t tiltY) { + std::list args; + args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_X, tiltX); + args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_Y, tiltY); + return args; } -void SingleTouchInputMapperTest::processKey(SingleTouchInputMapper& mapper, int32_t code, - int32_t value) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value); +std::list SingleTouchInputMapperTest::processKey(SingleTouchInputMapper& mapper, + int32_t code, int32_t value) { + return process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value); } -void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) { - process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0); +std::list SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) { + return process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0); } TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) { @@ -4599,6 +4610,42 @@ TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) { ASSERT_FALSE(flags[1]); } +TEST_F(SingleTouchInputMapperTest, DeviceTypeChange_RecalculatesRawToDisplayTransform) { + prepareDisplay(ui::ROTATION_0); + prepareAxes(POSITION); + addConfigurationProperty("touch.deviceType", "touchScreen"); + SingleTouchInputMapper& mapper = constructAndAddMapper(); + + const int32_t x = 900; + const int32_t y = 75; + std::list args; + args += processDown(mapper, x, y); + args += processSync(mapper); + + // Assert that motion event is received in display coordinate space for deviceType touchScreen. + ASSERT_THAT(args, + ElementsAre(VariantWith( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), + WithCoords(toDisplayX(x), toDisplayY(y)))))); + + // Add device type association after the device was created. + mFakePolicy->addDeviceTypeAssociation(DEVICE_LOCATION, "touchNavigation"); + // Send update to the mapper. + std::list unused = + mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), + InputReaderConfiguration::Change::DEVICE_TYPE /*changes*/); + + args.clear(); + args += processDown(mapper, x, y); + args += processSync(mapper); + + // Assert that motion event is received in raw coordinate space for deviceType touchNavigation. + ASSERT_THAT(args, + ElementsAre(VariantWith( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), + WithCoords(x - RAW_X_MIN, y - RAW_Y_MIN))))); +} + TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) { addConfigurationProperty("touch.deviceType", "touchScreen"); prepareDisplay(ui::ROTATION_0); -- cgit v1.2.3-59-g8ed1b