Loading health/aidl/default/Health.cpp +10 −17 Original line number Original line Diff line number Diff line Loading @@ -253,15 +253,6 @@ std::optional<bool> Health::ShouldKeepScreenOn() { return healthd_config_->screen_on(&props); return healthd_config_->screen_on(&props); } } namespace { bool IsDeadObjectLogged(const ndk::ScopedAStatus& ret) { if (ret.isOk()) return false; if (ret.getStatus() == ::STATUS_DEAD_OBJECT) return true; LOG(ERROR) << "Cannot call healthInfoChanged on callback: " << ret.getDescription(); return false; } } // namespace // // // Subclass helpers / overrides // Subclass helpers / overrides // // Loading Loading @@ -305,8 +296,10 @@ ndk::ScopedAStatus Health::registerCallback(const std::shared_ptr<IHealthInfoCal return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok(); } } if (auto res = callback->healthInfoChanged(health_info); IsDeadObjectLogged(res)) { auto res = callback->healthInfoChanged(health_info); (void)unregisterCallback(callback); if (!res.isOk()) { LOG(DEBUG) << "Cannot call healthInfoChanged:" << res.getDescription() << ". Do nothing here if callback is dead as it will be cleaned up later."; } } return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok(); } } Loading Loading @@ -353,13 +346,13 @@ ndk::ScopedAStatus Health::update() { void Health::OnHealthInfoChanged(const HealthInfo& health_info) { void Health::OnHealthInfoChanged(const HealthInfo& health_info) { // Notify all callbacks // Notify all callbacks std::unique_lock<decltype(callbacks_lock_)> lock(callbacks_lock_); std::unique_lock<decltype(callbacks_lock_)> lock(callbacks_lock_); // is_dead notifies a callback and return true if it is dead. for (const auto& linked : callbacks_) { auto is_dead = [&](const auto& linked) { auto res = linked->callback()->healthInfoChanged(health_info); auto res = linked->callback()->healthInfoChanged(health_info); return IsDeadObjectLogged(res); if (!res.isOk()) { }; LOG(DEBUG) << "Cannot call healthInfoChanged:" << res.getDescription() auto it = std::remove_if(callbacks_.begin(), callbacks_.end(), is_dead); << ". Do nothing here if callback is dead as it will be cleaned up later."; callbacks_.erase(it, callbacks_.end()); // calls unlinkToDeath on deleted callbacks. } } lock.unlock(); lock.unlock(); // Let HalHealthLoop::OnHealthInfoChanged() adjusts uevent / wakealarm periods // Let HalHealthLoop::OnHealthInfoChanged() adjusts uevent / wakealarm periods Loading Loading
health/aidl/default/Health.cpp +10 −17 Original line number Original line Diff line number Diff line Loading @@ -253,15 +253,6 @@ std::optional<bool> Health::ShouldKeepScreenOn() { return healthd_config_->screen_on(&props); return healthd_config_->screen_on(&props); } } namespace { bool IsDeadObjectLogged(const ndk::ScopedAStatus& ret) { if (ret.isOk()) return false; if (ret.getStatus() == ::STATUS_DEAD_OBJECT) return true; LOG(ERROR) << "Cannot call healthInfoChanged on callback: " << ret.getDescription(); return false; } } // namespace // // // Subclass helpers / overrides // Subclass helpers / overrides // // Loading Loading @@ -305,8 +296,10 @@ ndk::ScopedAStatus Health::registerCallback(const std::shared_ptr<IHealthInfoCal return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok(); } } if (auto res = callback->healthInfoChanged(health_info); IsDeadObjectLogged(res)) { auto res = callback->healthInfoChanged(health_info); (void)unregisterCallback(callback); if (!res.isOk()) { LOG(DEBUG) << "Cannot call healthInfoChanged:" << res.getDescription() << ". Do nothing here if callback is dead as it will be cleaned up later."; } } return ndk::ScopedAStatus::ok(); return ndk::ScopedAStatus::ok(); } } Loading Loading @@ -353,13 +346,13 @@ ndk::ScopedAStatus Health::update() { void Health::OnHealthInfoChanged(const HealthInfo& health_info) { void Health::OnHealthInfoChanged(const HealthInfo& health_info) { // Notify all callbacks // Notify all callbacks std::unique_lock<decltype(callbacks_lock_)> lock(callbacks_lock_); std::unique_lock<decltype(callbacks_lock_)> lock(callbacks_lock_); // is_dead notifies a callback and return true if it is dead. for (const auto& linked : callbacks_) { auto is_dead = [&](const auto& linked) { auto res = linked->callback()->healthInfoChanged(health_info); auto res = linked->callback()->healthInfoChanged(health_info); return IsDeadObjectLogged(res); if (!res.isOk()) { }; LOG(DEBUG) << "Cannot call healthInfoChanged:" << res.getDescription() auto it = std::remove_if(callbacks_.begin(), callbacks_.end(), is_dead); << ". Do nothing here if callback is dead as it will be cleaned up later."; callbacks_.erase(it, callbacks_.end()); // calls unlinkToDeath on deleted callbacks. } } lock.unlock(); lock.unlock(); // Let HalHealthLoop::OnHealthInfoChanged() adjusts uevent / wakealarm periods // Let HalHealthLoop::OnHealthInfoChanged() adjusts uevent / wakealarm periods Loading