]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/platform-hardware-interfaces.git/blobdiff - health/2.0/default/Health.cpp
health: registerCallback() and getHealthInfo() does not notify all callbacks
[android/platform-hardware-interfaces.git] / health / 2.0 / default / Health.cpp
index 4a4bee06fb510cc849363e7b5d015ed2181e97a4..a2b81d1ba17320458e8f2bfeea575e703cd08f9a 100644 (file)
@@ -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;