diff options
author | lilinnan <lilinnan@xiaomi.corp-partner.google.com> | 2022-07-19 16:00:50 +0800 |
---|---|---|
committer | Prabir Pradhan <prabirmsp@google.com> | 2022-08-31 21:12:51 +0000 |
commit | e74b35ffd574e4ddccb2112efcb9e337653cd9a6 (patch) | |
tree | 11cd3505fdf42b592e5ffe056e08b9c38ae07946 | |
parent | 2c23a2ee8f19f3a73ddbaddfb91566488e55e73c (diff) | |
download | native-e74b35ffd574e4ddccb2112efcb9e337653cd9a6.tar.gz |
Fix spot not disappear when display id changed
Turn on show touches in settings, and finger press on screen, let the
spot show, at now, display id changed, the spot will stay on screen.
when display id changed, we should cancel touch event and update
spot state.
Bug: 239378650
Bug: 234662773
Test: atest inputflinger_tests
Signed-off-by: lilinnan <lilinnan@xiaomi.corp-partner.google.com>
Change-Id: Ic289d772087e53716b4d63c431d9f41af721150e
Merged-In: Ic289d772087e53716b4d63c431d9f41af721150e
(cherry picked from commit 687e58faa44d7f5b4a5f21ca59442252716839ea)
-rw-r--r-- | services/inputflinger/reader/mapper/TouchInputMapper.cpp | 14 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 32 |
2 files changed, 44 insertions, 2 deletions
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index 637b1cb263..b5b2b45763 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -390,6 +390,10 @@ void TouchInputMapper::configure(nsecs_t when, const InputReaderConfiguration* c } if (changes && resetNeeded) { + // If device was reset, cancel touch event and update touch spot state. + cancelTouch(mCurrentRawState.when, mCurrentRawState.readTime); + mCurrentCookedState.clear(); + updateTouchSpots(); // Send reset, unless this is the first time the device has been configured, // in which case the reader will call reset itself after all mappers are ready. NotifyDeviceResetArgs args(getContext()->getNextId(), when, getDeviceId()); @@ -941,6 +945,7 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) bool skipViewportUpdate = false; if (viewportChanged) { const bool viewportOrientationChanged = mViewport.orientation != newViewport->orientation; + const bool viewportDisplayIdChanged = mViewport.displayId != newViewport->displayId; mViewport = *newViewport; if (mDeviceMode == DeviceMode::DIRECT || mDeviceMode == DeviceMode::POINTER) { @@ -1016,8 +1021,9 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) : getInverseRotation(mViewport.orientation); // For orientation-aware devices that work in the un-rotated coordinate space, the // viewport update should be skipped if it is only a change in the orientation. - skipViewportUpdate = mParameters.orientationAware && mDisplayWidth == oldDisplayWidth && - mDisplayHeight == oldDisplayHeight && viewportOrientationChanged; + skipViewportUpdate = !viewportDisplayIdChanged && mParameters.orientationAware && + mDisplayWidth == oldDisplayWidth && mDisplayHeight == oldDisplayHeight && + viewportOrientationChanged; // Apply the input device orientation for the device. mInputDeviceOrientation = @@ -1926,6 +1932,10 @@ void TouchInputMapper::dispatchVirtualKey(nsecs_t when, nsecs_t readTime, uint32 } void TouchInputMapper::abortTouches(nsecs_t when, nsecs_t readTime, uint32_t policyFlags) { + if (mCurrentMotionAborted) { + // Current motion event was already aborted. + return; + } BitSet32 currentIdBits = mCurrentCookedState.cookedPointerData.touchingIdBits; if (!currentIdBits.isEmpty()) { int32_t metaState = getContext()->getGlobalMetaState(); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index c36704bf15..8065ad645c 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -6690,6 +6690,34 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsV toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0)); } +TEST_F(SingleTouchInputMapperTest, + Process_WhenViewportDisplayIdChanged_TouchIsCanceledAndDeviceIsReset) { + addConfigurationProperty("touch.deviceType", "touchScreen"); + prepareDisplay(DISPLAY_ORIENTATION_0); + prepareButtons(); + prepareAxes(POSITION); + SingleTouchInputMapper& mapper = addMapperAndConfigure<SingleTouchInputMapper>(); + NotifyMotionArgs motionArgs; + + // Down. + processDown(mapper, 100, 200); + processSync(mapper); + + // We should receive a down event + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); + + // Change display id + clearViewports(); + prepareSecondaryDisplay(ViewportType::INTERNAL); + + // We should receive a cancel event + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); + ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionArgs.action); + // Then receive reset called + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled()); +} + // --- TouchDisplayProjectionTest --- class TouchDisplayProjectionTest : public SingleTouchInputMapperTest { @@ -8725,6 +8753,10 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_WhenNotOrientationAware_AreRotated // window's coordinate space. frames[0].rotate(getInverseRotation(orientation)); ASSERT_EQ(frames, motionArgs.videoFrames); + + // Release finger. + processSync(mapper); + ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); } } |