Loading services/inputflinger/include/InputReaderBase.h +3 −0 Original line number Diff line number Diff line Loading @@ -149,6 +149,9 @@ public: /* Get the Bluetooth address of an input device, if known. */ virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0; /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */ virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; }; // --- InputReaderConfiguration --- Loading services/inputflinger/reader/EventHub.cpp +50 −0 Original line number Diff line number Diff line Loading @@ -1531,6 +1531,20 @@ std::shared_ptr<const EventHub::AssociatedDevice> EventHub::obtainAssociatedDevi return associatedDevice; } bool EventHub::AssociatedDevice::isChanged() const { std::unordered_map<int32_t, RawBatteryInfo> newBatteryInfos = readBatteryConfiguration(sysfsRootPath); std::unordered_map<int32_t, RawLightInfo> newLightInfos = readLightsConfiguration(sysfsRootPath); std::optional<RawLayoutInfo> newLayoutInfo = readLayoutConfiguration(sysfsRootPath); if (newBatteryInfos == batteryInfos && newLightInfos == lightInfos && newLayoutInfo == layoutInfo) { return false; } return true; } void EventHub::vibrate(int32_t deviceId, const VibrationElement& element) { std::scoped_lock _l(mLock); Device* device = getDeviceLocked(deviceId); Loading Loading @@ -2536,6 +2550,42 @@ status_t EventHub::disableDevice(int32_t deviceId) { return device->disable(); } // TODO(b/274755573): Shift to uevent handling on native side and remove this method // Currently using Java UEventObserver to trigger this which uses UEvent infrastructure that uses a // NETLINK socket to observe UEvents. We can create similar infrastructure on Eventhub side to // directly observe UEvents instead of triggering from Java side. void EventHub::sysfsNodeChanged(const std::string& sysfsNodePath) { std::scoped_lock _l(mLock); // Check in opening devices for (auto it = mOpeningDevices.begin(); it != mOpeningDevices.end(); it++) { std::unique_ptr<Device>& device = *it; if (device->associatedDevice && sysfsNodePath.find(device->associatedDevice->sysfsRootPath.string()) != std::string::npos && device->associatedDevice->isChanged()) { it = mOpeningDevices.erase(it); openDeviceLocked(device->path); } } // Check in already added device std::vector<Device*> devicesToReopen; for (const auto& [id, device] : mDevices) { if (device->associatedDevice && sysfsNodePath.find(device->associatedDevice->sysfsRootPath.string()) != std::string::npos && device->associatedDevice->isChanged()) { devicesToReopen.push_back(device.get()); } } for (const auto& device : devicesToReopen) { closeDeviceLocked(*device); openDeviceLocked(device->path); } devicesToReopen.clear(); } void EventHub::createVirtualKeyboardLocked() { InputDeviceIdentifier identifier; identifier.name = "Virtual"; Loading services/inputflinger/reader/InputReader.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -928,6 +928,10 @@ bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { return *associatedDisplayId == displayId; } void InputReader::sysfsNodeChanged(const std::string& sysfsNodePath) { mEventHub->sysfsNodeChanged(sysfsNodePath); } void InputReader::dump(std::string& dump) { std::scoped_lock _l(mLock); Loading services/inputflinger/reader/include/EventHub.h +7 −0 Original line number Diff line number Diff line Loading @@ -388,6 +388,10 @@ public: /* Disable an input device. Closes file descriptor to that device. */ virtual status_t disableDevice(int32_t deviceId) = 0; /* Sysfs node changed. Reopen the Eventhub device if any new Peripheral like Light, Battery, * etc. is detected. */ virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; }; template <std::size_t BITS> Loading Loading @@ -567,6 +571,8 @@ public: status_t disableDevice(int32_t deviceId) override final; void sysfsNodeChanged(const std::string& sysfsNodePath) override final; ~EventHub() override; private: Loading @@ -578,6 +584,7 @@ private: std::unordered_map<int32_t /*lightId*/, RawLightInfo> lightInfos; std::optional<RawLayoutInfo> layoutInfo; bool isChanged() const; bool operator==(const AssociatedDevice&) const = default; bool operator!=(const AssociatedDevice&) const = default; std::string dump() const; Loading services/inputflinger/reader/include/InputReader.h +2 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,8 @@ public: std::optional<std::string> getBluetoothAddress(int32_t deviceId) const override; void sysfsNodeChanged(const std::string& sysfsNodePath) override; protected: // These members are protected so they can be instrumented by test cases. virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId, Loading Loading
services/inputflinger/include/InputReaderBase.h +3 −0 Original line number Diff line number Diff line Loading @@ -149,6 +149,9 @@ public: /* Get the Bluetooth address of an input device, if known. */ virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0; /* Sysfs node change reported. Recreate device if required to incorporate the new sysfs nodes */ virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; }; // --- InputReaderConfiguration --- Loading
services/inputflinger/reader/EventHub.cpp +50 −0 Original line number Diff line number Diff line Loading @@ -1531,6 +1531,20 @@ std::shared_ptr<const EventHub::AssociatedDevice> EventHub::obtainAssociatedDevi return associatedDevice; } bool EventHub::AssociatedDevice::isChanged() const { std::unordered_map<int32_t, RawBatteryInfo> newBatteryInfos = readBatteryConfiguration(sysfsRootPath); std::unordered_map<int32_t, RawLightInfo> newLightInfos = readLightsConfiguration(sysfsRootPath); std::optional<RawLayoutInfo> newLayoutInfo = readLayoutConfiguration(sysfsRootPath); if (newBatteryInfos == batteryInfos && newLightInfos == lightInfos && newLayoutInfo == layoutInfo) { return false; } return true; } void EventHub::vibrate(int32_t deviceId, const VibrationElement& element) { std::scoped_lock _l(mLock); Device* device = getDeviceLocked(deviceId); Loading Loading @@ -2536,6 +2550,42 @@ status_t EventHub::disableDevice(int32_t deviceId) { return device->disable(); } // TODO(b/274755573): Shift to uevent handling on native side and remove this method // Currently using Java UEventObserver to trigger this which uses UEvent infrastructure that uses a // NETLINK socket to observe UEvents. We can create similar infrastructure on Eventhub side to // directly observe UEvents instead of triggering from Java side. void EventHub::sysfsNodeChanged(const std::string& sysfsNodePath) { std::scoped_lock _l(mLock); // Check in opening devices for (auto it = mOpeningDevices.begin(); it != mOpeningDevices.end(); it++) { std::unique_ptr<Device>& device = *it; if (device->associatedDevice && sysfsNodePath.find(device->associatedDevice->sysfsRootPath.string()) != std::string::npos && device->associatedDevice->isChanged()) { it = mOpeningDevices.erase(it); openDeviceLocked(device->path); } } // Check in already added device std::vector<Device*> devicesToReopen; for (const auto& [id, device] : mDevices) { if (device->associatedDevice && sysfsNodePath.find(device->associatedDevice->sysfsRootPath.string()) != std::string::npos && device->associatedDevice->isChanged()) { devicesToReopen.push_back(device.get()); } } for (const auto& device : devicesToReopen) { closeDeviceLocked(*device); openDeviceLocked(device->path); } devicesToReopen.clear(); } void EventHub::createVirtualKeyboardLocked() { InputDeviceIdentifier identifier; identifier.name = "Virtual"; Loading
services/inputflinger/reader/InputReader.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -928,6 +928,10 @@ bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { return *associatedDisplayId == displayId; } void InputReader::sysfsNodeChanged(const std::string& sysfsNodePath) { mEventHub->sysfsNodeChanged(sysfsNodePath); } void InputReader::dump(std::string& dump) { std::scoped_lock _l(mLock); Loading
services/inputflinger/reader/include/EventHub.h +7 −0 Original line number Diff line number Diff line Loading @@ -388,6 +388,10 @@ public: /* Disable an input device. Closes file descriptor to that device. */ virtual status_t disableDevice(int32_t deviceId) = 0; /* Sysfs node changed. Reopen the Eventhub device if any new Peripheral like Light, Battery, * etc. is detected. */ virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; }; template <std::size_t BITS> Loading Loading @@ -567,6 +571,8 @@ public: status_t disableDevice(int32_t deviceId) override final; void sysfsNodeChanged(const std::string& sysfsNodePath) override final; ~EventHub() override; private: Loading @@ -578,6 +584,7 @@ private: std::unordered_map<int32_t /*lightId*/, RawLightInfo> lightInfos; std::optional<RawLayoutInfo> layoutInfo; bool isChanged() const; bool operator==(const AssociatedDevice&) const = default; bool operator!=(const AssociatedDevice&) const = default; std::string dump() const; Loading
services/inputflinger/reader/include/InputReader.h +2 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,8 @@ public: std::optional<std::string> getBluetoothAddress(int32_t deviceId) const override; void sysfsNodeChanged(const std::string& sysfsNodePath) override; protected: // These members are protected so they can be instrumented by test cases. virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId, Loading