1 /* 2 * Copyright (C) 2022 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 #pragma once 18 19 #include <aidl/android/hardware/power/IPower.h> 20 #include <aidl/google/hardware/power/extension/pixel/IPowerExt.h> 21 #include <android/hardware/thermal/2.0/IThermal.h> 22 23 #include <queue> 24 #include <shared_mutex> 25 #include <string> 26 #include <unordered_map> 27 #include <unordered_set> 28 29 namespace android { 30 namespace hardware { 31 namespace thermal { 32 namespace V2_0 { 33 namespace implementation { 34 35 using ::aidl::android::hardware::power::IPower; 36 using ::aidl::google::hardware::power::extension::pixel::IPowerExt; 37 38 using ::android::hardware::hidl_vec; 39 using ::android::hardware::thermal::V2_0::IThermal; 40 using Temperature_2_0 = ::android::hardware::thermal::V2_0::Temperature; 41 using ::android::hardware::thermal::V2_0::TemperatureThreshold; 42 using ::android::hardware::thermal::V2_0::ThrottlingSeverity; 43 using CdevRequestStatus = std::unordered_map<std::string, int>; 44 45 class PowerHalService { 46 public: 47 PowerHalService(); 48 ~PowerHalService() = default; 49 bool connect(); isAidlPowerHalExist()50 bool isAidlPowerHalExist() { return power_hal_aidl_exist_; } 51 bool isModeSupported(const std::string &type, const ThrottlingSeverity &t); isPowerHalConnected()52 bool isPowerHalConnected() { return power_hal_aidl_ != nullptr; } isPowerHalExtConnected()53 bool isPowerHalExtConnected() { return power_hal_ext_aidl_ != nullptr; } 54 void setMode(const std::string &type, const ThrottlingSeverity &t, const bool &enable, 55 const bool error_on_exit = false); 56 57 private: 58 bool power_hal_aidl_exist_; 59 std::shared_ptr<IPower> power_hal_aidl_; 60 std::shared_ptr<IPowerExt> power_hal_ext_aidl_; 61 std::mutex lock_; 62 }; 63 64 } // namespace implementation 65 } // namespace V2_0 66 } // namespace thermal 67 } // namespace hardware 68 } // namespace android 69