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

Commit e5eeb04e authored by Yifan Hong's avatar Yifan Hong Committed by android-build-merger
Browse files

health: registerCallback() and getHealthInfo() does not notify all callbacks am: e9fc235e

am: 13acc0be

Change-Id: I321fc8bc280b3f0a324a0f239217147b7545f439
parents 1c0e4c6f 13acc0be
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ Return<Result> Health::registerCallback(const sp<IHealthInfoCallback>& callback)
        // ignore the error
    }

    return update();
    return updateAndNotify(callback);
}

bool Health::unregisterCallbackInternal(const sp<IBase>& callback) {
@@ -156,6 +156,18 @@ Return<Result> Health::update() {
    return Result::SUCCESS;
}

Return<Result> Health::updateAndNotify(const sp<IHealthInfoCallback>& callback) {
    std::lock_guard<decltype(callbacks_lock_)> lock(callbacks_lock_);
    std::vector<sp<IHealthInfoCallback>> storedCallbacks{std::move(callbacks_)};
    callbacks_.clear();
    if (callback != nullptr) {
        callbacks_.push_back(callback);
    }
    Return<Result> result = update();
    callbacks_ = std::move(storedCallbacks);
    return result;
}

void Health::notifyListeners(HealthInfo* healthInfo) {
    std::vector<StorageInfo> info;
    get_storage_info(info);
@@ -233,7 +245,7 @@ Return<void> Health::getDiskStats(getDiskStats_cb _hidl_cb) {
Return<void> Health::getHealthInfo(getHealthInfo_cb _hidl_cb) {
    using android::hardware::health::V1_0::hal_conversion::convertToHealthInfo;

    update();
    updateAndNotify(nullptr);
    struct android::BatteryProperties p = getBatteryProperties(battery_monitor_.get());

    V1_0::HealthInfo batteryInfo;
+4 −0
Original line number Diff line number Diff line
@@ -64,6 +64,10 @@ struct Health : public IHealth, hidl_death_recipient {
    std::unique_ptr<BatteryMonitor> battery_monitor_;

    bool unregisterCallbackInternal(const sp<IBase>& cb);

    // update() and only notify the given callback, but none of the other callbacks.
    // If cb is null, do not notify any callback at all.
    Return<Result> updateAndNotify(const sp<IHealthInfoCallback>& cb);
};

}  // namespace implementation