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

Commit edeec3ba authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Revert behavior of loading the AssociatedDevice

ag/19714571 changed the behavior of loading AssociatedDevices so that it
was only read once for each sysfsPath, even if multiple event hub
devices had the same sysfs path.

However, that caused CTS hardware tests that read battery info to be
flaky. To mitigate this, we revert to the previous behavior of
re-loading the AssociatedDevice for each event hub device for now, until
we can debug the source of this issue.

Bug: 243979881
Test: atest SonyDualshock4BluetoothTest#testBattery --iterations 100
Change-Id: If7ab1076f0528945cf75073986ad0397471533ca
parent 6f8b77e3
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -1416,17 +1416,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) {
@@ -2645,4 +2656,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;