Skip to content

Commit 3bc04bf

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Fix stylus hover spot not disappearing" into main
2 parents b36f043 + c17f042 commit 3bc04bf

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
@@ -367,7 +367,8 @@ void PointerChoreographer::processTouchscreenAndStylusEventLocked(const NotifyMo
367367
const uint8_t actionIndex = MotionEvent::getActionIndex(args.action);
368368
std::array<uint32_t, MAX_POINTER_ID + 1> idToIndex;
369369
BitSet32 idBits;
370-
if (maskedAction != AMOTION_EVENT_ACTION_UP && maskedAction != AMOTION_EVENT_ACTION_CANCEL) {
370+
if (maskedAction != AMOTION_EVENT_ACTION_UP && maskedAction != AMOTION_EVENT_ACTION_CANCEL &&
371+
maskedAction != AMOTION_EVENT_ACTION_HOVER_EXIT) {
371372
for (size_t i = 0; i < args.getPointerCount(); i++) {
372373
if (maskedAction == AMOTION_EVENT_ACTION_POINTER_UP && actionIndex == i) {
373374
continue;

services/inputflinger/tests/PointerChoreographer_test.cpp

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

833+
/**
834+
* In this test, we simulate the complete event of the stylus approaching and clicking on the
835+
* screen, and then leaving the screen. We should ensure that spots are displayed correctly.
836+
*/
833837
TEST_F(PointerChoreographerTest, TouchSetsSpotsForStylusEvent) {
834838
mChoreographer.setShowTouchesEnabled(true);
839+
mChoreographer.setStylusPointerIconEnabled(false);
835840
mChoreographer.notifyInputDevicesChanged(
836841
{/*id=*/0,
837842
{generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS,
838843
DISPLAY_ID)}});
839844

840-
// Emit down event with stylus properties.
841-
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN,
845+
// First, the stylus begin to approach the screen.
846+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER,
842847
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
843848
.pointer(STYLUS_POINTER)
844849
.deviceId(DEVICE_ID)
845850
.displayId(DISPLAY_ID)
846851
.build());
847852
auto pc = assertPointerControllerCreated(ControllerType::TOUCH);
848853
pc->assertSpotCount(DISPLAY_ID, 1);
854+
855+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE,
856+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
857+
.pointer(STYLUS_POINTER)
858+
.deviceId(DEVICE_ID)
859+
.displayId(DISPLAY_ID)
860+
.build());
861+
pc->assertSpotCount(DISPLAY_ID, 1);
862+
863+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT,
864+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
865+
.pointer(STYLUS_POINTER)
866+
.deviceId(DEVICE_ID)
867+
.displayId(DISPLAY_ID)
868+
.build());
869+
pc->assertSpotCount(DISPLAY_ID, 0);
870+
871+
// Now, use stylus touch the screen.
872+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN,
873+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
874+
.pointer(STYLUS_POINTER)
875+
.deviceId(DEVICE_ID)
876+
.displayId(DISPLAY_ID)
877+
.build());
878+
pc->assertSpotCount(DISPLAY_ID, 1);
879+
880+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_MOVE,
881+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
882+
.pointer(STYLUS_POINTER)
883+
.deviceId(DEVICE_ID)
884+
.displayId(DISPLAY_ID)
885+
.build());
886+
pc->assertSpotCount(DISPLAY_ID, 1);
887+
888+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_UP,
889+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
890+
.pointer(STYLUS_POINTER)
891+
.deviceId(DEVICE_ID)
892+
.displayId(DISPLAY_ID)
893+
.build());
894+
pc->assertSpotCount(DISPLAY_ID, 0);
895+
896+
// Then, the stylus start leave from the screen.
897+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER,
898+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
899+
.pointer(STYLUS_POINTER)
900+
.deviceId(DEVICE_ID)
901+
.displayId(DISPLAY_ID)
902+
.build());
903+
pc->assertSpotCount(DISPLAY_ID, 1);
904+
905+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE,
906+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
907+
.pointer(STYLUS_POINTER)
908+
.deviceId(DEVICE_ID)
909+
.displayId(DISPLAY_ID)
910+
.build());
911+
pc->assertSpotCount(DISPLAY_ID, 1);
912+
913+
mChoreographer.notifyMotion(MotionArgsBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT,
914+
AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS)
915+
.pointer(STYLUS_POINTER)
916+
.deviceId(DEVICE_ID)
917+
.displayId(DISPLAY_ID)
918+
.build());
919+
pc->assertSpotCount(DISPLAY_ID, 0);
849920
}
850921

851922
TEST_F(PointerChoreographerTest, TouchSetsSpotsForTwoDisplays) {

0 commit comments

Comments
 (0)