diff options
| -rw-r--r-- | services/inputflinger/reader/mapper/TouchInputMapper.cpp | 4 | ||||
| -rw-r--r-- | 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 a3834908a7..64df226715 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -981,8 +981,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; @@ -1024,7 +1025,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 e6367b7303..93fae9b4ac 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -56,6 +56,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; @@ -4532,15 +4533,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<NotifyArgs> processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y); + std::list<NotifyArgs> processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y); + std::list<NotifyArgs> processUp(SingleTouchInputMapper& mappery); + std::list<NotifyArgs> processPressure(SingleTouchInputMapper& mapper, int32_t pressure); + std::list<NotifyArgs> processToolMajor(SingleTouchInputMapper& mapper, int32_t toolMajor); + std::list<NotifyArgs> processDistance(SingleTouchInputMapper& mapper, int32_t distance); + std::list<NotifyArgs> processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, int32_t tiltY); + std::list<NotifyArgs> processKey(SingleTouchInputMapper& mapper, int32_t code, int32_t value); + std::list<NotifyArgs> processSync(SingleTouchInputMapper& mapper); }; void SingleTouchInputMapperTest::prepareButtons() { @@ -4570,47 +4571,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<NotifyArgs> SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper, + int32_t x, int32_t y) { + std::list<NotifyArgs> 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<NotifyArgs> SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper, + int32_t x, int32_t y) { + std::list<NotifyArgs> 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<NotifyArgs> 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<NotifyArgs> 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<NotifyArgs> 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<NotifyArgs> 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<NotifyArgs> SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper, + int32_t tiltX, int32_t tiltY) { + std::list<NotifyArgs> 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<NotifyArgs> 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<NotifyArgs> SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) { + return process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0); } TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) { @@ -4701,6 +4712,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<SingleTouchInputMapper>(); + + const int32_t x = 900; + const int32_t y = 75; + std::list<NotifyArgs> 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<NotifyMotionArgs>( + 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<NotifyArgs> 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<NotifyMotionArgs>( + 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); |