• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define LOG_TAG "android.hardware.thermal.thermalcallback@1.1-impl"
2 #include <log/log.h>
3 
4 #include "ThermalCallback.h"
5 #include "services/thermalservice/ThermalService.h"
6 #include <math.h>
7 #include <android/os/Temperature.h>
8 #include <hardware/thermal.h>
9 
10 namespace android {
11 namespace hardware {
12 namespace thermal {
13 namespace V1_1 {
14 namespace implementation {
15 
16 using ::android::os::ThermalService;
17 using ::android::hardware::thermal::V1_0::TemperatureType;
18 
19 // Register a binder ThermalService object for sending events
registerThermalService(sp<ThermalService> thermalService)20 void ThermalCallback::registerThermalService(sp<ThermalService> thermalService)
21 {
22     mThermalService = thermalService;
23 }
24 
25 // Methods from IThermalCallback::V1_1 follow.
notifyThrottling(bool isThrottling,const android::hardware::thermal::V1_0::Temperature & temperature)26 Return<void> ThermalCallback::notifyThrottling(
27       bool isThrottling,
28       const android::hardware::thermal::V1_0::Temperature& temperature) {
29 
30     // Convert HIDL IThermal Temperature to binder IThermalService Temperature.
31     if (mThermalService != nullptr) {
32         float value = NAN;
33         int type = DEVICE_TEMPERATURE_UNKNOWN;
34 
35         switch(temperature.type) {
36           case TemperatureType::CPU:
37             type = DEVICE_TEMPERATURE_CPU;
38             break;
39           case TemperatureType::GPU:
40             type = DEVICE_TEMPERATURE_GPU;
41             break;
42           case TemperatureType::BATTERY:
43             type = DEVICE_TEMPERATURE_BATTERY;
44             break;
45           case TemperatureType::SKIN:
46             type = DEVICE_TEMPERATURE_SKIN;
47             break;
48           case TemperatureType::UNKNOWN:
49           default:
50             type = DEVICE_TEMPERATURE_UNKNOWN;
51             break;
52         }
53 
54         value = temperature.currentValue == UNKNOWN_TEMPERATURE ? NAN :
55             temperature.currentValue;
56 
57         android::os::Temperature thermal_svc_temp(value, type);
58         mThermalService->notifyThrottling(isThrottling, thermal_svc_temp);
59     } else {
60         ALOGE("IThermalService binder service not created, drop throttling event");
61     }
62     return Void();
63 }
64 
65 }  // namespace implementation
66 }  // namespace V1_1
67 }  // namespace thermal
68 }  // namespace hardware
69 }  // namespace android
70