Skip to content

Commit b08159b

Browse files
author
Biswarup Pal
committed
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
1 parent a21dc6f commit b08159b

2 files changed

Lines changed: 83 additions & 36 deletions

File tree

services/inputflinger/reader/mapper/TouchInputMapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,9 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded)
984984
viewportChanged = mViewport != newViewport;
985985
}
986986

987+
const bool deviceModeChanged = mDeviceMode != oldDeviceMode;
987988
bool skipViewportUpdate = false;
988-
if (viewportChanged) {
989+
if (viewportChanged || deviceModeChanged) {
989990
const bool viewportOrientationChanged = mViewport.orientation != newViewport.orientation;
990991
const bool viewportDisplayIdChanged = mViewport.displayId != newViewport.displayId;
991992
mViewport = newViewport;
@@ -1027,7 +1028,6 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded)
10271028
}
10281029

10291030
// If moving between pointer modes, need to reset some state.
1030-
bool deviceModeChanged = mDeviceMode != oldDeviceMode;
10311031
if (deviceModeChanged) {
10321032
mOrientedRanges.clear();
10331033
}

services/inputflinger/tests/InputReader_test.cpp

Lines changed: 81 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace android {
5757

5858
using namespace ftl::flag_operators;
5959
using testing::AllOf;
60+
using testing::VariantWith;
6061
using std::chrono_literals::operator""ms;
6162
using std::chrono_literals::operator""s;
6263

@@ -4430,15 +4431,15 @@ class SingleTouchInputMapperTest : public TouchInputMapperTest {
44304431
void prepareButtons();
44314432
void prepareAxes(int axes);
44324433

4433-
void processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
4434-
void processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
4435-
void processUp(SingleTouchInputMapper& mappery);
4436-
void processPressure(SingleTouchInputMapper& mapper, int32_t pressure);
4437-
void processToolMajor(SingleTouchInputMapper& mapper, int32_t toolMajor);
4438-
void processDistance(SingleTouchInputMapper& mapper, int32_t distance);
4439-
void processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, int32_t tiltY);
4440-
void processKey(SingleTouchInputMapper& mapper, int32_t code, int32_t value);
4441-
void processSync(SingleTouchInputMapper& mapper);
4434+
std::list<NotifyArgs> processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
4435+
std::list<NotifyArgs> processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y);
4436+
std::list<NotifyArgs> processUp(SingleTouchInputMapper& mappery);
4437+
std::list<NotifyArgs> processPressure(SingleTouchInputMapper& mapper, int32_t pressure);
4438+
std::list<NotifyArgs> processToolMajor(SingleTouchInputMapper& mapper, int32_t toolMajor);
4439+
std::list<NotifyArgs> processDistance(SingleTouchInputMapper& mapper, int32_t distance);
4440+
std::list<NotifyArgs> processTilt(SingleTouchInputMapper& mapper, int32_t tiltX, int32_t tiltY);
4441+
std::list<NotifyArgs> processKey(SingleTouchInputMapper& mapper, int32_t code, int32_t value);
4442+
std::list<NotifyArgs> processSync(SingleTouchInputMapper& mapper);
44424443
};
44434444

44444445
void SingleTouchInputMapperTest::prepareButtons() {
@@ -4468,47 +4469,57 @@ void SingleTouchInputMapperTest::prepareAxes(int axes) {
44684469
}
44694470
}
44704471

4471-
void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper, int32_t x, int32_t y) {
4472-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 1);
4473-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
4474-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
4472+
std::list<NotifyArgs> SingleTouchInputMapperTest::processDown(SingleTouchInputMapper& mapper,
4473+
int32_t x, int32_t y) {
4474+
std::list<NotifyArgs> args;
4475+
args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 1);
4476+
args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
4477+
args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
4478+
return args;
44754479
}
44764480

4477-
void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper, int32_t x, int32_t y) {
4478-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
4479-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
4481+
std::list<NotifyArgs> SingleTouchInputMapperTest::processMove(SingleTouchInputMapper& mapper,
4482+
int32_t x, int32_t y) {
4483+
std::list<NotifyArgs> args;
4484+
args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_X, x);
4485+
args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_Y, y);
4486+
return args;
44804487
}
44814488

4482-
void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper& mapper) {
4483-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 0);
4489+
std::list<NotifyArgs> SingleTouchInputMapperTest::processUp(SingleTouchInputMapper& mapper) {
4490+
return process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_TOUCH, 0);
44844491
}
44854492

4486-
void SingleTouchInputMapperTest::processPressure(SingleTouchInputMapper& mapper, int32_t pressure) {
4487-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_PRESSURE, pressure);
4493+
std::list<NotifyArgs> SingleTouchInputMapperTest::processPressure(SingleTouchInputMapper& mapper,
4494+
int32_t pressure) {
4495+
return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_PRESSURE, pressure);
44884496
}
44894497

4490-
void SingleTouchInputMapperTest::processToolMajor(SingleTouchInputMapper& mapper,
4491-
int32_t toolMajor) {
4492-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
4498+
std::list<NotifyArgs> SingleTouchInputMapperTest::processToolMajor(SingleTouchInputMapper& mapper,
4499+
int32_t toolMajor) {
4500+
return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
44934501
}
44944502

4495-
void SingleTouchInputMapperTest::processDistance(SingleTouchInputMapper& mapper, int32_t distance) {
4496-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_DISTANCE, distance);
4503+
std::list<NotifyArgs> SingleTouchInputMapperTest::processDistance(SingleTouchInputMapper& mapper,
4504+
int32_t distance) {
4505+
return process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_DISTANCE, distance);
44974506
}
44984507

4499-
void SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper, int32_t tiltX,
4500-
int32_t tiltY) {
4501-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_X, tiltX);
4502-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_Y, tiltY);
4508+
std::list<NotifyArgs> SingleTouchInputMapperTest::processTilt(SingleTouchInputMapper& mapper,
4509+
int32_t tiltX, int32_t tiltY) {
4510+
std::list<NotifyArgs> args;
4511+
args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_X, tiltX);
4512+
args += process(mapper, ARBITRARY_TIME, READ_TIME, EV_ABS, ABS_TILT_Y, tiltY);
4513+
return args;
45034514
}
45044515

4505-
void SingleTouchInputMapperTest::processKey(SingleTouchInputMapper& mapper, int32_t code,
4506-
int32_t value) {
4507-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value);
4516+
std::list<NotifyArgs> SingleTouchInputMapperTest::processKey(SingleTouchInputMapper& mapper,
4517+
int32_t code, int32_t value) {
4518+
return process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, code, value);
45084519
}
45094520

4510-
void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) {
4511-
process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
4521+
std::list<NotifyArgs> SingleTouchInputMapperTest::processSync(SingleTouchInputMapper& mapper) {
4522+
return process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0);
45124523
}
45134524

45144525
TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) {
@@ -4599,6 +4610,42 @@ TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) {
45994610
ASSERT_FALSE(flags[1]);
46004611
}
46014612

4613+
TEST_F(SingleTouchInputMapperTest, DeviceTypeChange_RecalculatesRawToDisplayTransform) {
4614+
prepareDisplay(ui::ROTATION_0);
4615+
prepareAxes(POSITION);
4616+
addConfigurationProperty("touch.deviceType", "touchScreen");
4617+
SingleTouchInputMapper& mapper = constructAndAddMapper<SingleTouchInputMapper>();
4618+
4619+
const int32_t x = 900;
4620+
const int32_t y = 75;
4621+
std::list<NotifyArgs> args;
4622+
args += processDown(mapper, x, y);
4623+
args += processSync(mapper);
4624+
4625+
// Assert that motion event is received in display coordinate space for deviceType touchScreen.
4626+
ASSERT_THAT(args,
4627+
ElementsAre(VariantWith<NotifyMotionArgs>(
4628+
AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
4629+
WithCoords(toDisplayX(x), toDisplayY(y))))));
4630+
4631+
// Add device type association after the device was created.
4632+
mFakePolicy->addDeviceTypeAssociation(DEVICE_LOCATION, "touchNavigation");
4633+
// Send update to the mapper.
4634+
std::list<NotifyArgs> unused =
4635+
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
4636+
InputReaderConfiguration::Change::DEVICE_TYPE /*changes*/);
4637+
4638+
args.clear();
4639+
args += processDown(mapper, x, y);
4640+
args += processSync(mapper);
4641+
4642+
// Assert that motion event is received in raw coordinate space for deviceType touchNavigation.
4643+
ASSERT_THAT(args,
4644+
ElementsAre(VariantWith<NotifyMotionArgs>(
4645+
AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
4646+
WithCoords(x - RAW_X_MIN, y - RAW_Y_MIN)))));
4647+
}
4648+
46024649
TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) {
46034650
addConfigurationProperty("touch.deviceType", "touchScreen");
46044651
prepareDisplay(ui::ROTATION_0);

0 commit comments

Comments
 (0)