blob: bb48387c00e7fa8778f8ae52c8b2b2328f87a022 [file] [log] [blame]
Wei Wang52150002018-10-24 19:33:10 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "android.hardware.thermal.thermalchangedcallback@2.0-impl"
18#include <log/log.h>
19
20#include <android/os/Temperature.h>
21#include <hardware/thermal.h>
22#include <cmath>
23#include "ThermalChangedCallback.h"
24#include "services/thermalservice/ThermalService.h"
25
26namespace android {
27namespace hardware {
28namespace thermal {
29namespace V2_0 {
30namespace implementation {
31
32using ::android::hardware::thermal::V2_0::TemperatureType;
33using ::android::hardware::thermal::V2_0::ThrottlingSeverity;
34using ::android::os::ThermalService;
35
36// Register a binder ThermalService object for sending events
37void ThermalChangedCallback::registerThermalService(sp<ThermalService> thermalService) {
38 mThermalService = thermalService;
39}
40
41// Methods from IThermalChangedCallback::V2_0 follow.
42Return<void> ThermalChangedCallback::notifyThrottling(
43 const android::hardware::thermal::V2_0::Temperature& temperature) {
44 // Convert HIDL IThermal Temperature to binder IThermalService Temperature.
45 if (mThermalService != nullptr) {
46 float value = NAN;
47 int type = DEVICE_TEMPERATURE_UNKNOWN;
48
49 switch (temperature.type) {
50 case TemperatureType::CPU:
51 type = DEVICE_TEMPERATURE_CPU;
52 break;
53 case TemperatureType::GPU:
54 type = DEVICE_TEMPERATURE_GPU;
55 break;
56 case TemperatureType::BATTERY:
57 type = DEVICE_TEMPERATURE_BATTERY;
58 break;
59 case TemperatureType::SKIN:
60 type = DEVICE_TEMPERATURE_SKIN;
61 break;
62 case TemperatureType::UNKNOWN:
63 default:
64 type = DEVICE_TEMPERATURE_UNKNOWN;
65 break;
66 }
67 bool isThrottling = (static_cast<size_t>(temperature.throttlingStatus) >=
68 static_cast<size_t>(ThrottlingSeverity::SEVERE))
69 ? true
70 : false;
Wei Wang3911b8d2018-10-30 15:56:20 -070071 value = temperature.value == UNKNOWN_TEMPERATURE ? NAN :
72 temperature.value;
Wei Wang52150002018-10-24 19:33:10 -070073 android::os::Temperature thermal_svc_temp(value, type);
74 mThermalService->notifyThrottling(isThrottling, thermal_svc_temp);
75 } else {
76 SLOGE("IThermalService binder service not created, drop throttling event");
77 }
78 return Void();
79}
80
81} // namespace implementation
82} // namespace V2_0
83} // namespace thermal
84} // namespace hardware
85} // namespace android