thermal: support cooling device status change notification
1. support the powercap in CoolingDevice
2. support the notification when CoolingDevice status changed
Bug: 312540064
Test: atest VtsHalThermalTargetTest
Change-Id: I58e39c0a2c070317b574f1a5d4abfa582cc56f34
diff --git a/thermal/aidl/default/Thermal.cpp b/thermal/aidl/default/Thermal.cpp
index f643d22..41d0be8 100644
--- a/thermal/aidl/default/Thermal.cpp
+++ b/thermal/aidl/default/Thermal.cpp
@@ -142,4 +142,53 @@
return ScopedAStatus::ok();
}
+ScopedAStatus Thermal::registerCoolingDeviceChangedCallbackWithType(
+ const std::shared_ptr<ICoolingDeviceChangedCallback>& in_callback, CoolingType in_type) {
+ LOG(VERBOSE) << __func__ << " ICoolingDeviceChangedCallback: " << in_callback
+ << ", CoolingType: " << static_cast<int32_t>(in_type);
+ if (in_callback == nullptr) {
+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+ "Invalid nullptr callback");
+ }
+ {
+ std::lock_guard<std::mutex> _lock(cdev_callback_mutex_);
+ if (std::any_of(cdev_callbacks_.begin(), cdev_callbacks_.end(),
+ [&](const std::shared_ptr<ICoolingDeviceChangedCallback>& c) {
+ return interfacesEqual(c, in_callback);
+ })) {
+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+ "Callback already registered");
+ }
+ cdev_callbacks_.push_back(in_callback);
+ }
+ return ScopedAStatus::ok();
+}
+
+ScopedAStatus Thermal::unregisterCoolingDeviceChangedCallback(
+ const std::shared_ptr<ICoolingDeviceChangedCallback>& in_callback) {
+ LOG(VERBOSE) << __func__ << " ICoolingDeviceChangedCallback: " << in_callback;
+ if (in_callback == nullptr) {
+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+ "Invalid nullptr callback");
+ }
+ {
+ std::lock_guard<std::mutex> _lock(cdev_callback_mutex_);
+ bool removed = false;
+ cdev_callbacks_.erase(
+ std::remove_if(cdev_callbacks_.begin(), cdev_callbacks_.end(),
+ [&](const std::shared_ptr<ICoolingDeviceChangedCallback>& c) {
+ if (interfacesEqual(c, in_callback)) {
+ removed = true;
+ return true;
+ }
+ return false;
+ }),
+ cdev_callbacks_.end());
+ if (!removed) {
+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+ "Callback wasn't registered");
+ }
+ }
+ return ScopedAStatus::ok();
+}
} // namespace aidl::android::hardware::thermal::impl::example