thermalservice: plumb up Thermal HAL 2.0 and add dump
Thermal HAL 2.0 provides multiple levels of thermal mitigation callback,
currently mapping ThrottlingSeverity::SEVERE and above to is_throttling
to keep same behavior.
In coming CL, the thermalservice API and hardware property manager
service will be updated.
(CL formatted with frameworks/native/.clang-format)
Bug: 111086696
Fixes: 118455688
Test: manually on a b1c1 with ThermalHAL 2.0
Tets: adb shell dumpsys thermalservice
Change-Id: I523edd1bfdf70ab6af07f0a5e996db38a9ae3864
diff --git a/services/thermalservice/libthermalcallback/ThermalChangedCallback.cpp b/services/thermalservice/libthermalcallback/ThermalChangedCallback.cpp
new file mode 100644
index 0000000..0efd732
--- /dev/null
+++ b/services/thermalservice/libthermalcallback/ThermalChangedCallback.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "android.hardware.thermal.thermalchangedcallback@2.0-impl"
+#include <log/log.h>
+
+#include <android/os/Temperature.h>
+#include <hardware/thermal.h>
+#include <cmath>
+#include "ThermalChangedCallback.h"
+#include "services/thermalservice/ThermalService.h"
+
+namespace android {
+namespace hardware {
+namespace thermal {
+namespace V2_0 {
+namespace implementation {
+
+using ::android::hardware::thermal::V2_0::TemperatureType;
+using ::android::hardware::thermal::V2_0::ThrottlingSeverity;
+using ::android::os::ThermalService;
+
+// Register a binder ThermalService object for sending events
+void ThermalChangedCallback::registerThermalService(sp<ThermalService> thermalService) {
+ mThermalService = thermalService;
+}
+
+// Methods from IThermalChangedCallback::V2_0 follow.
+Return<void> ThermalChangedCallback::notifyThrottling(
+ const android::hardware::thermal::V2_0::Temperature& temperature) {
+ // Convert HIDL IThermal Temperature to binder IThermalService Temperature.
+ if (mThermalService != nullptr) {
+ float value = NAN;
+ int type = DEVICE_TEMPERATURE_UNKNOWN;
+
+ switch (temperature.type) {
+ case TemperatureType::CPU:
+ type = DEVICE_TEMPERATURE_CPU;
+ break;
+ case TemperatureType::GPU:
+ type = DEVICE_TEMPERATURE_GPU;
+ break;
+ case TemperatureType::BATTERY:
+ type = DEVICE_TEMPERATURE_BATTERY;
+ break;
+ case TemperatureType::SKIN:
+ type = DEVICE_TEMPERATURE_SKIN;
+ break;
+ case TemperatureType::UNKNOWN:
+ default:
+ type = DEVICE_TEMPERATURE_UNKNOWN;
+ break;
+ }
+ bool isThrottling = (static_cast<size_t>(temperature.throttlingStatus) >=
+ static_cast<size_t>(ThrottlingSeverity::SEVERE))
+ ? true
+ : false;
+ android::os::Temperature thermal_svc_temp(value, type);
+ mThermalService->notifyThrottling(isThrottling, thermal_svc_temp);
+ } else {
+ SLOGE("IThermalService binder service not created, drop throttling event");
+ }
+ return Void();
+}
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace thermal
+} // namespace hardware
+} // namespace android