Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d63f1cc authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputReader: Add getter API for the sysfs node path of an InputDevice

Bug: 397208968
Test: Presubmit
Flag: EXEMPT bug fix
Change-Id: I25f41f41ec1f1e47590eef21b982287caea193a6
parent 6f9ad773
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -443,6 +443,9 @@ public:
    /* Get the Bluetooth address of an input device, if known. */
    virtual std::optional<std::string> getBluetoothAddress(int32_t deviceId) const = 0;

    /* Gets the sysfs root path for this device. Returns an empty path if there is none. */
    virtual std::filesystem::path getSysfsRootPath(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;

+18 −2
Original line number Diff line number Diff line
@@ -246,7 +246,7 @@ static nsecs_t processEventTimestamp(const struct input_event& event) {
/**
 * Returns the sysfs root path of the input device.
 */
static std::optional<std::filesystem::path> getSysfsRootPath(const char* devicePath) {
static std::optional<std::filesystem::path> getSysfsRootForEvdevDevicePath(const char* devicePath) {
    std::error_code errorCode;

    // Stat the device path to get the major and minor number of the character file
@@ -1619,7 +1619,7 @@ void EventHub::assignDescriptorLocked(InputDeviceIdentifier& identifier) {
std::shared_ptr<const EventHub::AssociatedDevice> EventHub::obtainAssociatedDeviceLocked(
        const std::filesystem::path& devicePath, const std::shared_ptr<PropertyMap>& config) const {
    const std::optional<std::filesystem::path> sysfsRootPathOpt =
            getSysfsRootPath(devicePath.c_str());
            getSysfsRootForEvdevDevicePath(devicePath.c_str());
    if (!sysfsRootPathOpt) {
        return nullptr;
    }
@@ -2666,6 +2666,18 @@ status_t EventHub::disableDevice(int32_t deviceId) {
    return device->disable();
}

std::filesystem::path EventHub::getSysfsRootPath(int32_t deviceId) const {
    std::scoped_lock _l(mLock);
    Device* device = getDeviceLocked(deviceId);
    if (device == nullptr) {
        ALOGE("Invalid device id=%" PRId32 " provided to %s", deviceId, __func__);
        return {};
    }

    return device->associatedDevice ? device->associatedDevice->sysfsRootPath
                                    : std::filesystem::path{};
}

// 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
@@ -2710,6 +2722,10 @@ void EventHub::handleSysfsNodeChangeNotificationsLocked() {
        auto reloadedDevice = AssociatedDevice(dev.associatedDevice->sysfsRootPath,
                                               dev.associatedDevice->baseDevConfig);
        const bool changed = *dev.associatedDevice != reloadedDevice;
        if (changed) {
            ALOGI("sysfsNodeChanged: Identified change in sysfs nodes for device: %s",
                  dev.identifier.name.c_str());
        }
        testedDevices.emplace(dev.associatedDevice, changed);
        return changed;
    };
+6 −0
Original line number Diff line number Diff line
@@ -136,6 +136,8 @@ void InputDevice::dump(std::string& dump, const std::string& eventHubDevStr) {
    } else {
        dump += "<none>\n";
    }
    dump += StringPrintf(INDENT2 "SysfsRootPath:     %s\n",
                         mSysfsRootPath.empty() ? "<none>" : mSysfsRootPath.c_str());
    dump += StringPrintf(INDENT2 "HasMic:     %s\n", toString(mHasMic));
    dump += StringPrintf(INDENT2 "Sources: %s\n",
                         inputEventSourceToString(deviceInfo.getSources()).c_str());
@@ -195,6 +197,10 @@ void InputDevice::addEmptyEventHubDevice(int32_t eventHubId) {
    DevicePair& devicePair = mDevices[eventHubId];
    devicePair.second = createMappers(*devicePair.first, readerConfig);

    if (mSysfsRootPath.empty()) {
        mSysfsRootPath = devicePair.first->getSysfsRootPath();
    }

    // Must change generation to flag this device as changed
    bumpGeneration();
    return out;
+10 −0
Original line number Diff line number Diff line
@@ -917,6 +917,16 @@ bool InputReader::canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId di
    return *associatedDisplayId == displayId;
}

std::filesystem::path InputReader::getSysfsRootPath(int32_t deviceId) const {
    std::scoped_lock _l(mLock);

    const InputDevice* device = findInputDeviceLocked(deviceId);
    if (!device) {
        return {};
    }
    return device->getSysfsRootPath();
}

void InputReader::sysfsNodeChanged(const std::string& sysfsNodePath) {
    mEventHub->sysfsNodeChanged(sysfsNodePath);
    mEventHub->wake();
+5 −0
Original line number Diff line number Diff line
@@ -399,6 +399,9 @@ public:
    /* Disable an input device. Closes file descriptor to that device. */
    virtual status_t disableDevice(int32_t deviceId) = 0;

    /* Gets the sysfs root path for this device. Returns an empty path if there is none. */
    virtual std::filesystem::path getSysfsRootPath(int32_t deviceId) const = 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;
@@ -614,6 +617,8 @@ public:

    status_t disableDevice(int32_t deviceId) override final;

    std::filesystem::path getSysfsRootPath(int32_t deviceId) const override final;

    void sysfsNodeChanged(const std::string& sysfsNodePath) override final;

    bool setKernelWakeEnabled(int32_t deviceId, bool enabled) override final;
Loading