diff options
Diffstat (limited to 'thermal')
-rw-r--r-- | thermal/Thermal.cpp | 23 | ||||
-rw-r--r-- | thermal/thermal-helper.cpp | 7 | ||||
-rw-r--r-- | thermal/thermal-helper.h | 2 |
3 files changed, 26 insertions, 6 deletions
diff --git a/thermal/Thermal.cpp b/thermal/Thermal.cpp index 80aa53c4..c448b709 100644 --- a/thermal/Thermal.cpp +++ b/thermal/Thermal.cpp @@ -121,7 +121,7 @@ Return<void> Thermal::getCurrentTemperatures(bool filterType, TemperatureType_2_ return setInitFailureAndCallback(_hidl_cb, temperatures); } - if (!thermal_helper_.fillCurrentTemperatures(filterType, type, &temperatures)) { + if (!thermal_helper_.fillCurrentTemperatures(filterType, false, type, &temperatures)) { return setFailureAndCallback(_hidl_cb, temperatures, "Failed to read thermal sensors."); } @@ -171,6 +171,8 @@ Return<void> Thermal::registerThermalChangedCallback(const sp<IThermalChangedCal bool filterType, TemperatureType_2_0 type, registerThermalChangedCallback_cb _hidl_cb) { ThermalStatus status; + hidl_vec<Temperature_2_0> temperatures; + if (callback == nullptr) { status.code = ThermalStatusCode::FAILURE; status.debugMessage = "Invalid nullptr callback"; @@ -193,6 +195,21 @@ Return<void> Thermal::registerThermalChangedCallback(const sp<IThermalChangedCal << " Type: " << android::hardware::thermal::V2_0::toString(type); } _hidl_cb(status); + + // Send notification right away after thermal callback registration + if (thermal_helper_.fillCurrentTemperatures(filterType, true, type, &temperatures)) { + for (const auto &t : temperatures) { + if (!filterType || t.type == type) { + LOG(INFO) << "Sending notification: " + << " Type: " << android::hardware::thermal::V2_0::toString(t.type) + << " Name: " << t.name << " CurrentValue: " << t.value + << " ThrottlingStatus: " + << android::hardware::thermal::V2_0::toString(t.throttlingStatus); + callback->notifyThrottling(t); + } + } + } + return Void(); } @@ -565,8 +582,8 @@ Return<void> Thermal::debug(const hidl_handle &handle, const hidl_vec<hidl_strin { dump_buf << "getCurrentTemperatures:" << std::endl; hidl_vec<Temperature_2_0> temperatures; - if (!thermal_helper_.fillCurrentTemperatures(false, TemperatureType_2_0::SKIN, - &temperatures)) { + if (!thermal_helper_.fillCurrentTemperatures( + false, false, TemperatureType_2_0::SKIN, &temperatures)) { dump_buf << "Failed to getCurrentTemperatures." << std::endl; } diff --git a/thermal/thermal-helper.cpp b/thermal/thermal-helper.cpp index cbd63939..6eb0d508 100644 --- a/thermal/thermal-helper.cpp +++ b/thermal/thermal-helper.cpp @@ -1016,7 +1016,8 @@ bool ThermalHelper::fillTemperatures(hidl_vec<Temperature_1_0> *temperatures) co return current_index > 0; } -bool ThermalHelper::fillCurrentTemperatures(bool filterType, TemperatureType_2_0 type, +bool ThermalHelper::fillCurrentTemperatures(bool filterType, bool filterCallback, + TemperatureType_2_0 type, hidl_vec<Temperature_2_0> *temperatures) const { std::vector<Temperature_2_0> ret; for (const auto &name_info_pair : sensor_info_map_) { @@ -1024,13 +1025,15 @@ bool ThermalHelper::fillCurrentTemperatures(bool filterType, TemperatureType_2_0 if (filterType && name_info_pair.second.type != type) { continue; } + if (filterCallback && !name_info_pair.second.send_cb) { + continue; + } if (readTemperature(name_info_pair.first, &temp, nullptr, name_info_pair.second.virtual_sensor_info != nullptr)) { ret.emplace_back(std::move(temp)); } else { LOG(ERROR) << __func__ << ": error reading temperature for sensor: " << name_info_pair.first; - return false; } } *temperatures = ret; diff --git a/thermal/thermal-helper.h b/thermal/thermal-helper.h index 672d3522..20205979 100644 --- a/thermal/thermal-helper.h +++ b/thermal/thermal-helper.h @@ -112,7 +112,7 @@ class ThermalHelper { ~ThermalHelper() = default; bool fillTemperatures(hidl_vec<Temperature_1_0> *temperatures) const; - bool fillCurrentTemperatures(bool filterType, TemperatureType_2_0 type, + bool fillCurrentTemperatures(bool filterType, bool filterCallback, TemperatureType_2_0 type, hidl_vec<Temperature_2_0> *temperatures) const; bool fillTemperatureThresholds(bool filterType, TemperatureType_2_0 type, hidl_vec<TemperatureThreshold> *thresholds) const; |