summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/inputflinger/reader/InputDevice.cpp35
-rw-r--r--services/inputflinger/reader/InputReader.cpp6
-rw-r--r--services/inputflinger/reader/include/InputDevice.h6
-rw-r--r--services/inputflinger/reader/include/InputReader.h2
-rw-r--r--services/inputflinger/tests/InputReader_test.cpp3
-rw-r--r--services/inputflinger/tests/InstrumentedInputReader.cpp4
-rw-r--r--services/inputflinger/tests/InstrumentedInputReader.h2
7 files changed, 29 insertions, 29 deletions
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index f247159b57..8c872a799f 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -173,23 +173,18 @@ void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) {
mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});
}
-[[nodiscard]] std::list<NotifyArgs> InputDevice::addEventHubDevice(
- nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig) {
+void InputDevice::addEventHubDevice(int32_t eventHubId,
+ const InputReaderConfiguration& readerConfig) {
if (mDevices.find(eventHubId) != mDevices.end()) {
- return {};
+ return;
}
+ std::unique_ptr<InputDeviceContext> contextPtr(new InputDeviceContext(*this, eventHubId));
+ std::vector<std::unique_ptr<InputMapper>> mappers = createMappers(*contextPtr, readerConfig);
- // Add an empty device configure and keep it enabled to allow mapper population
- // with correct configuration/context
- addEmptyEventHubDevice(eventHubId);
- std::list<NotifyArgs> out = configure(when, readerConfig, {}, /*forceEnable=*/true);
-
- DevicePair& devicePair = mDevices[eventHubId];
- devicePair.second = createMappers(*devicePair.first, 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();
- return out;
}
void InputDevice::removeEventHubDevice(int32_t eventHubId) {
@@ -202,7 +197,7 @@ void InputDevice::removeEventHubDevice(int32_t eventHubId) {
std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
const InputReaderConfiguration& readerConfig,
- ConfigurationChanges changes, bool forceEnable) {
+ ConfigurationChanges changes) {
std::list<NotifyArgs> out;
mSources = 0;
mClasses = ftl::Flags<InputDeviceClass>(0);
@@ -316,17 +311,25 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
}
}
- if (!changes.any() || changes.test(Change::ENABLED_STATE) ||
- changes.test(Change::DISPLAY_INFO)) {
+ if (changes.test(Change::ENABLED_STATE) || changes.test(Change::DISPLAY_INFO)) {
// Whether a device is enabled can depend on the display association,
// so update the enabled state when there is a change in display info.
- out += updateEnableState(when, readerConfig, forceEnable);
+ // NOTE: The first configuration of a mapper must happen with the device enabled.
+ // Do not execute this code on the first configure to prevent mappers
+ // from being configured with the device disabled.
+ out += updateEnableState(when, readerConfig, false);
}
for_each_mapper([this, when, &readerConfig, changes, &out](InputMapper& mapper) {
out += mapper.reconfigure(when, readerConfig, changes);
mSources |= mapper.getSources();
});
+
+ // If a device is just plugged but it might be disabled, we need to update some info like
+ // axis range of touch from each InputMapper first, then disable it.
+ if (!changes.any()) {
+ out += updateEnableState(when, readerConfig);
+ }
}
return out;
}
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index 7d0f28b508..ea95f7857a 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -234,7 +234,7 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
}
InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
- std::shared_ptr<InputDevice> device = createDeviceLocked(when, eventHubId, identifier);
+ std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier);
notifyAll(device->configure(when, mConfig, /*changes=*/{}));
notifyAll(device->reset(when));
@@ -319,7 +319,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {
}
std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
- nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) {
+ int32_t eventHubId, const InputDeviceIdentifier& identifier) {
auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) {
const InputDeviceIdentifier identifier2 =
devicePair.second->getDeviceInfo().getIdentifier();
@@ -334,7 +334,7 @@ std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
identifier);
}
- notifyAll(device->addEventHubDevice(when, 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 d92f4a24eb..85393bf550 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -80,13 +80,11 @@ public:
void dump(std::string& dump, const std::string& eventHubDevStr);
void addEmptyEventHubDevice(int32_t eventHubId);
- [[nodiscard]] std::list<NotifyArgs> addEventHubDevice(
- nsecs_t when, 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,
- ConfigurationChanges changes,
- bool forceEnable = false);
+ ConfigurationChanges changes);
[[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
[[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
[[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h
index 391a8895dd..9112913565 100644
--- a/services/inputflinger/reader/include/InputReader.h
+++ b/services/inputflinger/reader/include/InputReader.h
@@ -121,7 +121,7 @@ public:
protected:
// These members are protected so they can be instrumented by test cases.
- virtual std::shared_ptr<InputDevice> createDeviceLocked(nsecs_t when, int32_t deviceId,
+ virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId,
const InputDeviceIdentifier& identifier)
REQUIRES(mLock);
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index f4e471dcbb..5a24723aee 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2660,8 +2660,7 @@ TEST_F(InputDeviceTest, DumpDoesNotCrash) {
mFakeEventHub->addDevice(TEST_EVENTHUB_ID, "Test EventHub device", InputDeviceClass::BATTERY);
InputDevice device(mReader->getContext(), /*id=*/1, /*generation=*/2, /*identifier=*/{});
- auto _ = device.addEventHubDevice(ARBITRARY_TIME, 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);
diff --git a/services/inputflinger/tests/InstrumentedInputReader.cpp b/services/inputflinger/tests/InstrumentedInputReader.cpp
index 110ca5fab0..1f8cd12b75 100644
--- a/services/inputflinger/tests/InstrumentedInputReader.cpp
+++ b/services/inputflinger/tests/InstrumentedInputReader.cpp
@@ -38,13 +38,13 @@ std::shared_ptr<InputDevice> InstrumentedInputReader::newDevice(int32_t deviceId
}
std::shared_ptr<InputDevice> InstrumentedInputReader::createDeviceLocked(
- nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) REQUIRES(mLock) {
+ int32_t eventHubId, const InputDeviceIdentifier& identifier) REQUIRES(mLock) {
if (!mNextDevices.empty()) {
std::shared_ptr<InputDevice> device(std::move(mNextDevices.front()));
mNextDevices.pop();
return device;
}
- return InputReader::createDeviceLocked(when, eventHubId, identifier);
+ return InputReader::createDeviceLocked(eventHubId, identifier);
}
} // namespace android
diff --git a/services/inputflinger/tests/InstrumentedInputReader.h b/services/inputflinger/tests/InstrumentedInputReader.h
index e6bf3f98b5..7f8d5562ef 100644
--- a/services/inputflinger/tests/InstrumentedInputReader.h
+++ b/services/inputflinger/tests/InstrumentedInputReader.h
@@ -44,7 +44,7 @@ public:
protected:
virtual std::shared_ptr<InputDevice> createDeviceLocked(
- nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier);
+ int32_t eventHubId, const InputDeviceIdentifier& identifier);
class FakeInputReaderContext : public ContextImpl {
public: