Skip to content

Commit c17f042

Browse files
Linnan LiAndroid Build Cherrypicker Worker
authored andcommitted
Fix stylus hover spot not disappearing
When we turn off the stylus hover icon feature and turn on “show touches”, we will use the touch spot display to show the stylus hover icon. But currently, we don't remove the hover spot after HOVER_EXIT, so the stylus hover spot will never disappear. We should add corresponding logic to handle it. This patch also refines a previous test to ensure that stylus events can be handled correctly by PointerChoreographer. Test: atest inputflinger_tests Flag: EXEMPT bugfix Bug: 353451540 Signed-off-by: Linnan Li <lilinnan@xiaomi.corp-partner.google.com> Merged-In: I4b04992605ba19bdf3fc5db74580b919ef8356c0 Change-Id: I4b04992605ba19bdf3fc5db74580b919ef8356c0
1 parent 454e2fe commit c17f042

2 files changed

Lines changed: 75 additions & 3 deletions

File tree

services/inputflinger/PointerChoreographer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ void PointerChoreographer::processTouchscreenAndStylusEventLocked(const NotifyMo
264264
const uint8_t actionIndex = MotionEvent::getActionIndex(args.action);
265265
std::array<uint32_t, MAX_POINTER_ID + 1> idToIndex;
266266
BitSet32 idBits;
267-
if (maskedAction != AMOTION_EVENT_ACTION_UP && maskedAction != AMOTION_EVENT_ACTION_CANCEL) {
267+
if (maskedAction != AMOTION_EVENT_ACTION_UP && maskedAction != AMOTION_EVENT_ACTION_CANCEL &&
268+
maskedAction != AMOTION_EVENT_ACTION_HOVER_EXIT) {
268269
for (size_t i = 0; i < args.getPointerCount(); i++) {
269270
if (maskedAction == AMOTION_EVENT_ACTION_POINTER_UP && actionIndex == i) {
270271
continue;

services/inputflinger/tests/PointerChoreographer_test.cpp

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,22 +645,93 @@ TEST_F(PointerChoreographerTest, TouchSetsSpots) {
645645
pc->assertSpotCount(DISPLAY_ID, 0);
646646
}
647647

648+
/**
649+
* In this test, we simulate the complete event of the stylus approaching and clicking on the
650+
* screen, and then leaving the screen. We should ensure that spots are displayed correctly.
651+
*/
648652
TEST_F(PointerChoreographerTest, TouchSetsSpotsForStylusEvent) {
649653
mChoreographer.setShowTouchesEnabled(true);
654+
mChoreographer.setStylusPointerIconEnabled(false);
650655
mChoreographer.notifyInputDevicesChanged(
651656
{/*id=*/0,
652657
{generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS,
653658
DISPLAY_ID)}});
654659

655-
// Emit down event with stylus properties.
656-
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN,
660+
// First, the stylus begin to approach the screen.
661+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER,
657662
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
658663
.pointer(STYLUS_POINTER)
659664
.deviceId(DEVICE_ID)
660665
.displayId(DISPLAY_ID)
661666
.build());
662667
auto pc = assertPointerControllerCreated(ControllerType::TOUCH);
663668
pc->assertSpotCount(DISPLAY_ID, 1);
669+
670+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE,
671+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
672+
.pointer(STYLUS_POINTER)
673+
.deviceId(DEVICE_ID)
674+
.displayId(DISPLAY_ID)
675+
.build());
676+
pc->assertSpotCount(DISPLAY_ID, 1);
677+
678+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT,
679+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
680+
.pointer(STYLUS_POINTER)
681+
.deviceId(DEVICE_ID)
682+
.displayId(DISPLAY_ID)
683+
.build());
684+
pc->assertSpotCount(DISPLAY_ID, 0);
685+
686+
// Now, use stylus touch the screen.
687+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN,
688+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
689+
.pointer(STYLUS_POINTER)
690+
.deviceId(DEVICE_ID)
691+
.displayId(DISPLAY_ID)
692+
.build());
693+
pc->assertSpotCount(DISPLAY_ID, 1);
694+
695+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE,
696+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
697+
.pointer(STYLUS_POINTER)
698+
.deviceId(DEVICE_ID)
699+
.displayId(DISPLAY_ID)
700+
.build());
701+
pc->assertSpotCount(DISPLAY_ID, 1);
702+
703+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_UP,
704+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
705+
.pointer(STYLUS_POINTER)
706+
.deviceId(DEVICE_ID)
707+
.displayId(DISPLAY_ID)
708+
.build());
709+
pc->assertSpotCount(DISPLAY_ID, 0);
710+
711+
// Then, the stylus start leave from the screen.
712+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER,
713+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
714+
.pointer(STYLUS_POINTER)
715+
.deviceId(DEVICE_ID)
716+
.displayId(DISPLAY_ID)
717+
.build());
718+
pc->assertSpotCount(DISPLAY_ID, 1);
719+
720+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE,
721+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
722+
.pointer(STYLUS_POINTER)
723+
.deviceId(DEVICE_ID)
724+
.displayId(DISPLAY_ID)
725+
.build());
726+
pc->assertSpotCount(DISPLAY_ID, 1);
727+
728+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT,
729+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
730+
.pointer(STYLUS_POINTER)
731+
.deviceId(DEVICE_ID)
732+
.displayId(DISPLAY_ID)
733+
.build());
734+
pc->assertSpotCount(DISPLAY_ID, 0);
664735
}
665736

666737
TEST_F(PointerChoreographerTest, TouchSetsSpotsForTwoDisplays) {

0 commit comments

Comments
 (0)