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/Android.bp b/services/thermalservice/libthermalcallback/Android.bp
index e98506e..312579c 100644
--- a/services/thermalservice/libthermalcallback/Android.bp
+++ b/services/thermalservice/libthermalcallback/Android.bp
@@ -2,6 +2,7 @@
name: "libthermalcallback",
srcs: [
"ThermalCallback.cpp",
+ "ThermalChangedCallback.cpp",
],
cflags: [
"-Wall",
@@ -10,6 +11,7 @@
include_dirs: ["frameworks/native"],
shared_libs: [
"android.hardware.thermal@1.1",
+ "android.hardware.thermal@2.0",
"libhidlbase",
"libhidltransport",
"liblog",
diff --git a/services/thermalservice/libthermalcallback/ThermalCallback.cpp b/services/thermalservice/libthermalcallback/ThermalCallback.cpp
index 5e094fa..0f3132c 100644
--- a/services/thermalservice/libthermalcallback/ThermalCallback.cpp
+++ b/services/thermalservice/libthermalcallback/ThermalCallback.cpp
@@ -1,11 +1,11 @@
#define LOG_TAG "android.hardware.thermal.thermalcallback@1.1-impl"
#include <log/log.h>
-#include "ThermalCallback.h"
-#include "services/thermalservice/ThermalService.h"
-#include <math.h>
#include <android/os/Temperature.h>
#include <hardware/thermal.h>
+#include <cmath>
+#include "ThermalCallback.h"
+#include "services/thermalservice/ThermalService.h"
namespace android {
namespace hardware {
@@ -57,7 +57,7 @@
android::os::Temperature thermal_svc_temp(value, type);
mThermalService->notifyThrottling(isThrottling, thermal_svc_temp);
} else {
- ALOGE("IThermalService binder service not created, drop throttling event");
+ SLOGE("IThermalService binder service not created, drop throttling event");
}
return Void();
}
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
diff --git a/services/thermalservice/libthermalcallback/ThermalChangedCallback.h b/services/thermalservice/libthermalcallback/ThermalChangedCallback.h
new file mode 100644
index 0000000..03de049
--- /dev/null
+++ b/services/thermalservice/libthermalcallback/ThermalChangedCallback.h
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#ifndef ANDROID_HARDWARE_THERMAL_V1_1_THERMALCHANGEDCALLBACK_H
+#define ANDROID_HARDWARE_THERMAL_V1_1_THERMALCHANGEDCALLBACK_H
+
+#include <android/hardware/thermal/2.0/IThermalChangedCallback.h>
+#include <android/hardware/thermal/2.0/types.h>
+#include <android/os/Temperature.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include "services/thermalservice/ThermalService.h"
+
+namespace android {
+namespace hardware {
+namespace thermal {
+namespace V2_0 {
+namespace implementation {
+
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::os::ThermalService;
+
+class ThermalChangedCallback : public IThermalChangedCallback {
+public:
+ // Register a binder ThermalService object for sending events
+ void registerThermalService(sp<ThermalService> thermalService);
+
+ // Methods from I ThermalChangedCallback::V2_0 follow.
+ Return<void> notifyThrottling(
+ const android::hardware::thermal::V2_0::Temperature& temperature) override;
+
+private:
+ // Our registered binder ThermalService object to use for sending events
+ sp<android::os::ThermalService> mThermalService;
+};
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace thermal
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_THERMAL_V1_1_THERMALCHANGEDCALLBACK_H