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

Commit 3d1b4654 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert behavior of loading the AssociatedDevice"

parents e02d7119 edeec3ba
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -1418,17 +1418,28 @@ std::shared_ptr<const EventHub::AssociatedDevice> EventHub::obtainAssociatedDevi
    }

    const auto& path = *sysfsRootPathOpt;
    for (const auto& [id, dev] : mDevices) {
        if (dev->associatedDevice && dev->associatedDevice->sysfsRootPath == path) {
            return dev->associatedDevice;
        }
    }

    return std::make_shared<AssociatedDevice>(
    std::shared_ptr<const AssociatedDevice> associatedDevice = std::make_shared<AssociatedDevice>(
            AssociatedDevice{.sysfsRootPath = path,
                             .countryCode = readCountryCodeLocked(path),
                             .batteryInfos = readBatteryConfiguration(path),
                             .lightInfos = readLightsConfiguration(path)});

    bool associatedDeviceChanged = false;
    for (const auto& [id, dev] : mDevices) {
        if (dev->associatedDevice && dev->associatedDevice->sysfsRootPath == path) {
            if (*associatedDevice != *dev->associatedDevice) {
                associatedDeviceChanged = true;
                dev->associatedDevice = associatedDevice;
            }
            associatedDevice = dev->associatedDevice;
        }
    }
    ALOGI_IF(associatedDeviceChanged,
             "The AssociatedDevice changed for path '%s'. Using new AssociatedDevice: %s",
             path.c_str(), associatedDevice->dump().c_str());

    return associatedDevice;
}

void EventHub::vibrate(int32_t deviceId, const VibrationElement& element) {
@@ -2650,4 +2661,9 @@ void EventHub::monitor() const {
    std::unique_lock<std::mutex> lock(mLock);
}

std::string EventHub::AssociatedDevice::dump() const {
    return StringPrintf("path=%s, numBatteries=%zu, numLight=%zu", sysfsRootPath.c_str(),
                        batteryInfos.size(), lightInfos.size());
}

} // namespace android
+11 −1
Original line number Diff line number Diff line
@@ -195,6 +195,9 @@ struct RawLightInfo {
    ftl::Flags<InputLightClass> flags;
    std::array<int32_t, COLOR_NUM> rgbIndex;
    std::filesystem::path path;

    bool operator==(const RawLightInfo&) const = default;
    bool operator!=(const RawLightInfo&) const = default;
};

/* Describes a raw battery. */
@@ -203,6 +206,9 @@ struct RawBatteryInfo {
    std::string name;
    ftl::Flags<InputBatteryClass> flags;
    std::filesystem::path path;

    bool operator==(const RawBatteryInfo&) const = default;
    bool operator!=(const RawBatteryInfo&) const = default;
};

/*
@@ -551,6 +557,10 @@ private:
        hardware::input::InputDeviceCountryCode countryCode;
        std::unordered_map<int32_t /*batteryId*/, RawBatteryInfo> batteryInfos;
        std::unordered_map<int32_t /*lightId*/, RawLightInfo> lightInfos;

        bool operator==(const AssociatedDevice&) const = default;
        bool operator!=(const AssociatedDevice&) const = default;
        std::string dump() const;
    };

    struct Device {
@@ -584,7 +594,7 @@ private:

        // A shared_ptr of a device associated with the input device.
        // The input devices that have the same sysfs path have the same associated device.
        const std::shared_ptr<const AssociatedDevice> associatedDevice;
        std::shared_ptr<const AssociatedDevice> associatedDevice;

        int32_t controllerNumber;