summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArpit Singh <arpitks@google.com>2023-05-25 12:34:04 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-05-25 12:34:04 +0000
commit01b8e815f1a73b376022cf72607ea235d52bd6ef (patch)
tree7bf27b798421f61d41e431b55aa0f05a7f813a29
parent1889c6a81ef5be2b252798b2f19f8680ea0e2a02 (diff)
parentc96ed759fb428c7b982c921611e5da05040e3cea (diff)
downloadnative-01b8e815f1a73b376022cf72607ea235d52bd6ef.tar.gz
Merge changes from topic "revert-23316821-WWTNIVUOBO" into udc-dev
* changes: Revert "InputMapper refactor: Configure empty InputDevice" Revert "InputMapper refactor: Revert "fix touch issue on portrai..."
-rw-r--r--services/inputflinger/reader/InputDevice.cpp61
-rw-r--r--services/inputflinger/reader/InputReader.cpp4
-rw-r--r--services/inputflinger/reader/include/InputDevice.h4
-rw-r--r--services/inputflinger/reader/mapper/MultiTouchInputMapper.h4
-rw-r--r--services/inputflinger/reader/mapper/SingleTouchInputMapper.h4
-rw-r--r--services/inputflinger/tests/InputReader_test.cpp5
6 files changed, 38 insertions, 44 deletions
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index c6b93a51c3..0a64a1c4a8 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -151,22 +151,21 @@ void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) {
return;
}
std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
- mDevices.insert(
- {eventHubId,
- std::make_pair<std::unique_ptr<InputDeviceContext>,
- std::vector<std::unique_ptr<InputMapper>>>(std::move(contextPtr), {})});
-}
-
-void InputDevice::populateMappers(int32_t eventHubId,
- const InputReaderConfiguration& readerConfig) {
- auto targetDevice = mDevices.find(eventHubId);
- LOG_ALWAYS_FATAL_IF(targetDevice == mDevices.end(),
- "InputDevice::populateMappers(): missing device with eventHubId %d ",
- eventHubId);
- // create and add mappers to device
- InputDeviceContext& context = *targetDevice->second.first;
- std::vector<std::unique_ptr<InputMapper>> mappers = createMappers(context, readerConfig);
- targetDevice->second.second = std::move(mappers);
+ std::vector<std::unique_ptr<InputMapper>> mappers;
+
+ mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
+}
+
+void InputDevice::addEventHubDevice(int32_t eventHubId,
+ const InputReaderConfiguration& readerConfig) {
+ if (mDevices.find(eventHubId) != mDevices.end()) {
+ return;
+ }
+ std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
+ std::vector<std::unique_ptr<InputMapper>> mappers = createMappers(*contextPtr, readerConfig);
+
+ // insert the context into the devices set
+ mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
// Must change generation to flag this device as changed
bumpGeneration();
}
@@ -441,29 +440,29 @@ int32_t InputDevice::getState(uint32_t sourceMask, int32_t code, GetStateFunc ge
}
std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
- InputDeviceContext& context, const InputReaderConfiguration& readerConfig) {
- ftl::Flags<InputDeviceClass> classes = context.getDeviceClasses();
+ InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig) {
+ ftl::Flags<InputDeviceClass> classes = contextPtr.getDeviceClasses();
std::vector<std::unique_ptr<InputMapper>> mappers;
// Switch-like devices.
if (classes.test(InputDeviceClass::SWITCH)) {
- mappers.push_back(createInputMapper<SwitchInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<SwitchInputMapper>(contextPtr, readerConfig));
}
// Scroll wheel-like devices.
if (classes.test(InputDeviceClass::ROTARY_ENCODER)) {
- mappers.push_back(createInputMapper<RotaryEncoderInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<RotaryEncoderInputMapper>(contextPtr, readerConfig));
}
// Vibrator-like devices.
if (classes.test(InputDeviceClass::VIBRATOR)) {
- mappers.push_back(createInputMapper<VibratorInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<VibratorInputMapper>(contextPtr, readerConfig));
}
// Battery-like devices or light-containing devices.
// PeripheralController will be created with associated EventHub device.
if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {
- mController = std::make_unique<PeripheralController>(context);
+ mController = std::make_unique<PeripheralController>(contextPtr);
}
// Keyboard-like devices.
@@ -483,13 +482,13 @@ std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
}
if (keyboardSource != 0) {
- mappers.push_back(createInputMapper<KeyboardInputMapper>(context, readerConfig,
+ mappers.push_back(createInputMapper<KeyboardInputMapper>(contextPtr, readerConfig,
keyboardSource, keyboardType));
}
// Cursor-like devices.
if (classes.test(InputDeviceClass::CURSOR)) {
- mappers.push_back(createInputMapper<CursorInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<CursorInputMapper>(contextPtr, readerConfig));
}
// Touchscreens and touchpad devices.
@@ -497,31 +496,31 @@ std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
sysprop::InputProperties::enable_touchpad_gestures_library().value_or(true);
// TODO(b/272518665): Fix the new touchpad stack for Sony DualShock 4 (5c4, 9cc) touchpads, or
// at least load this setting from the IDC file.
- const InputDeviceIdentifier identifier = context.getDeviceIdentifier();
+ const InputDeviceIdentifier identifier = contextPtr.getDeviceIdentifier();
const bool isSonyDualShock4Touchpad = identifier.vendor == 0x054c &&
(identifier.product == 0x05c4 || identifier.product == 0x09cc);
if (ENABLE_TOUCHPAD_GESTURES_LIBRARY && classes.test(InputDeviceClass::TOUCHPAD) &&
classes.test(InputDeviceClass::TOUCH_MT) && !isSonyDualShock4Touchpad) {
- mappers.push_back(createInputMapper<TouchpadInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<TouchpadInputMapper>(contextPtr, readerConfig));
} else if (classes.test(InputDeviceClass::TOUCH_MT)) {
- mappers.push_back(createInputMapper<MultiTouchInputMapper>(context, readerConfig));
+ mappers.push_back(std::make_unique<MultiTouchInputMapper>(contextPtr, readerConfig));
} else if (classes.test(InputDeviceClass::TOUCH)) {
- mappers.push_back(createInputMapper<SingleTouchInputMapper>(context, readerConfig));
+ mappers.push_back(std::make_unique<SingleTouchInputMapper>(contextPtr, readerConfig));
}
// Joystick-like devices.
if (classes.test(InputDeviceClass::JOYSTICK)) {
- mappers.push_back(createInputMapper<JoystickInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<JoystickInputMapper>(contextPtr, readerConfig));
}
// Motion sensor enabled devices.
if (classes.test(InputDeviceClass::SENSOR)) {
- mappers.push_back(createInputMapper<SensorInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<SensorInputMapper>(contextPtr, readerConfig));
}
// External stylus-like devices.
if (classes.test(InputDeviceClass::EXTERNAL_STYLUS)) {
- mappers.push_back(createInputMapper<ExternalStylusInputMapper>(context, readerConfig));
+ mappers.push_back(createInputMapper<ExternalStylusInputMapper>(contextPtr, readerConfig));
}
return mappers;
}
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index 8a33dff868..ea95f7857a 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -334,9 +334,7 @@ std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
identifier);
}
- device->addEmptyEventHubDevice(eventHubId);
- auto unused = device->configure(systemTime(SYSTEM_TIME_MONOTONIC), mConfig, /*changes=*/{});
- device->populateMappers(eventHubId, mConfig);
+ device->addEventHubDevice(eventHubId, mConfig);
return device;
}
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index 1729d4620d..0b8a608891 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -81,7 +81,7 @@ public:
void dump(std::string& dump, const std::string& eventHubDevStr);
void addEmptyEventHubDevice(int32_t eventHubId);
- void populateMappers(int32_t eventHubId, const InputReaderConfiguration& readerConfig);
+ void addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig);
void removeEventHubDevice(int32_t eventHubId);
[[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
const InputReaderConfiguration& readerConfig,
@@ -203,7 +203,7 @@ private:
int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
std::vector<std::unique_ptr<InputMapper>> createMappers(
- InputDeviceContext& context, const InputReaderConfiguration& readerConfig);
+ InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig);
PropertyMap mConfiguration;
diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.h b/services/inputflinger/reader/mapper/MultiTouchInputMapper.h
index 1d788dffd4..f300ee15bd 100644
--- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.h
@@ -27,6 +27,8 @@ public:
friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
const InputReaderConfiguration& readerConfig,
Args... args);
+ explicit MultiTouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
~MultiTouchInputMapper() override;
@@ -39,8 +41,6 @@ protected:
bool hasStylus() const override;
private:
- explicit MultiTouchInputMapper(InputDeviceContext& deviceContext,
- const InputReaderConfiguration& readerConfig);
// simulate_stylus_with_touch is a debug mode that converts all finger pointers reported by this
// mapper's touchscreen into stylus pointers, and adds SOURCE_STYLUS to the input device.
// It is used to simulate stylus events for debugging and testing on a device that does not
diff --git a/services/inputflinger/reader/mapper/SingleTouchInputMapper.h b/services/inputflinger/reader/mapper/SingleTouchInputMapper.h
index 7726bfb159..dac53cf700 100644
--- a/services/inputflinger/reader/mapper/SingleTouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/SingleTouchInputMapper.h
@@ -27,6 +27,8 @@ public:
friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
const InputReaderConfiguration& readerConfig,
Args... args);
+ explicit SingleTouchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
~SingleTouchInputMapper() override;
@@ -40,8 +42,6 @@ protected:
private:
SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
- explicit SingleTouchInputMapper(InputDeviceContext& deviceContext,
- const InputReaderConfiguration& readerConfig);
};
} // namespace android
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index c045e15f19..bfb371f02a 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2584,10 +2584,7 @@ TEST_F(InputDeviceTest, DumpDoesNotCrash) {
mFakeEventHub->addDevice(TEST_EVENTHUB_ID, "Test EventHub device", InputDeviceClass::BATTERY);
InputDevice device(mReader->getContext(), /*id=*/1, /*generation=*/2, /*identifier=*/{});
- device.addEmptyEventHubDevice(TEST_EVENTHUB_ID);
- auto unused = device.configure(systemTime(SYSTEM_TIME_MONOTONIC),
- mFakePolicy->getReaderConfiguration(), /*changes=*/{});
- device.populateMappers(TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration());
+ device.addEventHubDevice(TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration());
device.removeEventHubDevice(TEST_EVENTHUB_ID);
std::string dumpStr, eventHubDevStr;
device.dump(dumpStr, eventHubDevStr);