Loading services/inputflinger/reader/InputDevice.cpp +45 −35 Original line number Diff line number Diff line Loading @@ -67,14 +67,18 @@ bool InputDevice::isEnabled() { } std::list<NotifyArgs> InputDevice::updateEnableState(nsecs_t when, const InputReaderConfiguration& readerConfig) { const InputReaderConfiguration& readerConfig, bool forceEnable) { bool enable = forceEnable; if (!forceEnable) { // If the device was explicitly disabled by the user, it would be present in the // "disabledDevices" list. This device should be disabled. bool enable = readerConfig.disabledDevices.find(mId) == readerConfig.disabledDevices.end(); enable = readerConfig.disabledDevices.find(mId) == readerConfig.disabledDevices.end(); // If a device is associated with a specific display but there is no // associated DisplayViewport, don't enable the device. if (enable && (mAssociatedDisplayPort || mAssociatedDisplayUniqueId) && !mAssociatedViewport) { if (enable && (mAssociatedDisplayPort || mAssociatedDisplayUniqueId) && !mAssociatedViewport) { const std::string desc = mAssociatedDisplayPort ? "port " + std::to_string(*mAssociatedDisplayPort) : "uniqueId " + *mAssociatedDisplayUniqueId; Loading @@ -83,6 +87,7 @@ std::list<NotifyArgs> InputDevice::updateEnableState(nsecs_t when, getName().c_str(), desc.c_str()); enable = false; } } std::list<NotifyArgs> out; if (isEnabled() == enable) { Loading Loading @@ -168,18 +173,25 @@ void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) { mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))}); } void InputDevice::addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig) { [[nodiscard]] std::list<NotifyArgs> InputDevice::addEventHubDevice( nsecs_t when, 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); // insert the context into the devices set mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))}); // Add an empty device configure and keep it enabled to allow mapper population with correct // configuration/context, // Note: we need to ensure device is kept enabled till mappers are configured // TODO: b/281852638 refactor tests to remove this flag and reliance on the empty device addEmptyEventHubDevice(eventHubId); std::list<NotifyArgs> out = configureInternal(when, readerConfig, {}, /*forceEnable=*/true); DevicePair& devicePair = mDevices[eventHubId]; devicePair.second = createMappers(*devicePair.first, readerConfig); // Must change generation to flag this device as changed bumpGeneration(); return out; } void InputDevice::removeEventHubDevice(int32_t eventHubId) { Loading @@ -193,6 +205,12 @@ void InputDevice::removeEventHubDevice(int32_t eventHubId) { std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConfiguration& readerConfig, ConfigurationChanges changes) { return configureInternal(when, readerConfig, changes); } std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when, const InputReaderConfiguration& readerConfig, ConfigurationChanges changes, bool forceEnable) { std::list<NotifyArgs> out; mSources = 0; mClasses = ftl::Flags<InputDeviceClass>(0); Loading Loading @@ -289,24 +307,16 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, } } 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. // 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); } 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); if (!changes.any() || 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); } } return out; Loading services/inputflinger/reader/InputReader.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -236,7 +236,7 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) { } InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId); std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier); std::shared_ptr<InputDevice> device = createDeviceLocked(when, eventHubId, identifier); mPendingArgs += device->configure(when, mConfig, /*changes=*/{}); mPendingArgs += device->reset(when); Loading Loading @@ -319,7 +319,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) { } std::shared_ptr<InputDevice> InputReader::createDeviceLocked( int32_t eventHubId, const InputDeviceIdentifier& identifier) { nsecs_t when, 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(); Loading @@ -334,7 +334,7 @@ std::shared_ptr<InputDevice> InputReader::createDeviceLocked( device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(), identifier); } device->addEventHubDevice(eventHubId, mConfig); mPendingArgs += device->addEventHubDevice(when, eventHubId, mConfig); return device; } Loading services/inputflinger/reader/include/InputDevice.h +7 −2 Original line number Diff line number Diff line Loading @@ -80,7 +80,8 @@ public: void dump(std::string& dump, const std::string& eventHubDevStr); void addEmptyEventHubDevice(int32_t eventHubId); void addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig); [[nodiscard]] std::list<NotifyArgs> addEventHubDevice( nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig); void removeEventHubDevice(int32_t eventHubId); [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, const InputReaderConfiguration& readerConfig, Loading Loading @@ -205,8 +206,12 @@ private: std::vector<std::unique_ptr<InputMapper>> createMappers( InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig); [[nodiscard]] std::list<NotifyArgs> configureInternal( nsecs_t when, const InputReaderConfiguration& readerConfig, ConfigurationChanges changes, bool forceEnable = false); [[nodiscard]] std::list<NotifyArgs> updateEnableState( nsecs_t when, const InputReaderConfiguration& readerConfig); nsecs_t when, const InputReaderConfiguration& readerConfig, bool forceEnable = false); PropertyMap mConfiguration; Loading services/inputflinger/reader/include/InputReader.h +1 −1 Original line number Diff line number Diff line Loading @@ -121,7 +121,7 @@ public: protected: // These members are protected so they can be instrumented by test cases. virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId, virtual std::shared_ptr<InputDevice> createDeviceLocked(nsecs_t when, int32_t deviceId, const InputDeviceIdentifier& identifier) REQUIRES(mLock); Loading services/inputflinger/tests/InputReader_test.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -2835,7 +2835,8 @@ TEST_F(InputDeviceTest, DumpDoesNotCrash) { mFakeEventHub->addDevice(TEST_EVENTHUB_ID, "Test EventHub device", InputDeviceClass::BATTERY); InputDevice device(mReader->getContext(), /*id=*/1, /*generation=*/2, /*identifier=*/{}); device.addEventHubDevice(TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration()); auto _ = device.addEventHubDevice(ARBITRARY_TIME, TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration()); device.removeEventHubDevice(TEST_EVENTHUB_ID); std::string dumpStr, eventHubDevStr; device.dump(dumpStr, eventHubDevStr); Loading Loading
services/inputflinger/reader/InputDevice.cpp +45 −35 Original line number Diff line number Diff line Loading @@ -67,14 +67,18 @@ bool InputDevice::isEnabled() { } std::list<NotifyArgs> InputDevice::updateEnableState(nsecs_t when, const InputReaderConfiguration& readerConfig) { const InputReaderConfiguration& readerConfig, bool forceEnable) { bool enable = forceEnable; if (!forceEnable) { // If the device was explicitly disabled by the user, it would be present in the // "disabledDevices" list. This device should be disabled. bool enable = readerConfig.disabledDevices.find(mId) == readerConfig.disabledDevices.end(); enable = readerConfig.disabledDevices.find(mId) == readerConfig.disabledDevices.end(); // If a device is associated with a specific display but there is no // associated DisplayViewport, don't enable the device. if (enable && (mAssociatedDisplayPort || mAssociatedDisplayUniqueId) && !mAssociatedViewport) { if (enable && (mAssociatedDisplayPort || mAssociatedDisplayUniqueId) && !mAssociatedViewport) { const std::string desc = mAssociatedDisplayPort ? "port " + std::to_string(*mAssociatedDisplayPort) : "uniqueId " + *mAssociatedDisplayUniqueId; Loading @@ -83,6 +87,7 @@ std::list<NotifyArgs> InputDevice::updateEnableState(nsecs_t when, getName().c_str(), desc.c_str()); enable = false; } } std::list<NotifyArgs> out; if (isEnabled() == enable) { Loading Loading @@ -168,18 +173,25 @@ void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) { mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))}); } void InputDevice::addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig) { [[nodiscard]] std::list<NotifyArgs> InputDevice::addEventHubDevice( nsecs_t when, 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); // insert the context into the devices set mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))}); // Add an empty device configure and keep it enabled to allow mapper population with correct // configuration/context, // Note: we need to ensure device is kept enabled till mappers are configured // TODO: b/281852638 refactor tests to remove this flag and reliance on the empty device addEmptyEventHubDevice(eventHubId); std::list<NotifyArgs> out = configureInternal(when, readerConfig, {}, /*forceEnable=*/true); DevicePair& devicePair = mDevices[eventHubId]; devicePair.second = createMappers(*devicePair.first, readerConfig); // Must change generation to flag this device as changed bumpGeneration(); return out; } void InputDevice::removeEventHubDevice(int32_t eventHubId) { Loading @@ -193,6 +205,12 @@ void InputDevice::removeEventHubDevice(int32_t eventHubId) { std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConfiguration& readerConfig, ConfigurationChanges changes) { return configureInternal(when, readerConfig, changes); } std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when, const InputReaderConfiguration& readerConfig, ConfigurationChanges changes, bool forceEnable) { std::list<NotifyArgs> out; mSources = 0; mClasses = ftl::Flags<InputDeviceClass>(0); Loading Loading @@ -289,24 +307,16 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, } } 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. // 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); } 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); if (!changes.any() || 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); } } return out; Loading
services/inputflinger/reader/InputReader.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -236,7 +236,7 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) { } InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId); std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier); std::shared_ptr<InputDevice> device = createDeviceLocked(when, eventHubId, identifier); mPendingArgs += device->configure(when, mConfig, /*changes=*/{}); mPendingArgs += device->reset(when); Loading Loading @@ -319,7 +319,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) { } std::shared_ptr<InputDevice> InputReader::createDeviceLocked( int32_t eventHubId, const InputDeviceIdentifier& identifier) { nsecs_t when, 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(); Loading @@ -334,7 +334,7 @@ std::shared_ptr<InputDevice> InputReader::createDeviceLocked( device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(), identifier); } device->addEventHubDevice(eventHubId, mConfig); mPendingArgs += device->addEventHubDevice(when, eventHubId, mConfig); return device; } Loading
services/inputflinger/reader/include/InputDevice.h +7 −2 Original line number Diff line number Diff line Loading @@ -80,7 +80,8 @@ public: void dump(std::string& dump, const std::string& eventHubDevStr); void addEmptyEventHubDevice(int32_t eventHubId); void addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig); [[nodiscard]] std::list<NotifyArgs> addEventHubDevice( nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig); void removeEventHubDevice(int32_t eventHubId); [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, const InputReaderConfiguration& readerConfig, Loading Loading @@ -205,8 +206,12 @@ private: std::vector<std::unique_ptr<InputMapper>> createMappers( InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig); [[nodiscard]] std::list<NotifyArgs> configureInternal( nsecs_t when, const InputReaderConfiguration& readerConfig, ConfigurationChanges changes, bool forceEnable = false); [[nodiscard]] std::list<NotifyArgs> updateEnableState( nsecs_t when, const InputReaderConfiguration& readerConfig); nsecs_t when, const InputReaderConfiguration& readerConfig, bool forceEnable = false); PropertyMap mConfiguration; Loading
services/inputflinger/reader/include/InputReader.h +1 −1 Original line number Diff line number Diff line Loading @@ -121,7 +121,7 @@ public: protected: // These members are protected so they can be instrumented by test cases. virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId, virtual std::shared_ptr<InputDevice> createDeviceLocked(nsecs_t when, int32_t deviceId, const InputDeviceIdentifier& identifier) REQUIRES(mLock); Loading
services/inputflinger/tests/InputReader_test.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -2835,7 +2835,8 @@ TEST_F(InputDeviceTest, DumpDoesNotCrash) { mFakeEventHub->addDevice(TEST_EVENTHUB_ID, "Test EventHub device", InputDeviceClass::BATTERY); InputDevice device(mReader->getContext(), /*id=*/1, /*generation=*/2, /*identifier=*/{}); device.addEventHubDevice(TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration()); auto _ = device.addEventHubDevice(ARBITRARY_TIME, TEST_EVENTHUB_ID, mFakePolicy->getReaderConfiguration()); device.removeEventHubDevice(TEST_EVENTHUB_ID); std::string dumpStr, eventHubDevStr; device.dump(dumpStr, eventHubDevStr); Loading