1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifdef POWERMGR_THERMAL_MANAGER_ENABLE 16 #include "policy/thermal_policy.h" 17 18 #include "thermal_mgr_client.h" 19 #include "work_sched_hilog.h" 20 21 using namespace std; 22 using namespace OHOS::PowerMgr; 23 24 namespace OHOS { 25 namespace WorkScheduler { 26 const int32_t COUNT_THERMAL_CRUCIAL = 0; 27 const int32_t COUNT_THERMAL_LOW = 1; 28 const int32_t COUNT_THERMAL_NORMAL = 3; 29 ThermalPolicy(shared_ptr<WorkPolicyManager> workPolicyManager)30ThermalPolicy::ThermalPolicy(shared_ptr<WorkPolicyManager> workPolicyManager) 31 { 32 workPolicyManager_ = workPolicyManager; 33 } 34 ~ThermalPolicy()35ThermalPolicy::~ThermalPolicy() 36 { 37 } 38 GetPolicyMaxRunning()39int32_t ThermalPolicy::GetPolicyMaxRunning() 40 { 41 auto& thermalMgrClient = ThermalMgrClient::GetInstance(); 42 ThermalLevel thermalLevel = thermalMgrClient.GetThermalLevel(); 43 int32_t res; 44 if (thermalLevel >= ThermalLevel::WARM) { 45 res = COUNT_THERMAL_CRUCIAL; 46 } else if (thermalLevel < ThermalLevel::WARM && thermalLevel >= ThermalLevel::NORMAL) { 47 res = COUNT_THERMAL_LOW; 48 } else { 49 res = COUNT_THERMAL_NORMAL; 50 } 51 WS_HILOGD("ThermalLevel:%{public}d, PolicyRes:%{public}d", thermalLevel, res); 52 return res; 53 } 54 GetPolicyName()55std::string ThermalPolicy::GetPolicyName() 56 { 57 return "THERMAL_POLICY"; 58 } 59 } // namespace WorkScheduler 60 } // namespace OHOS 61 #endif // POWERMGR_THERMAL_MANAGER_ENABLE