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 #include "policy/thermal_policy.h" 16 17 #include "thermal_mgr_client.h" 18 #include "work_sched_hilog.h" 19 20 using namespace std; 21 using namespace OHOS::PowerMgr; 22 23 namespace OHOS { 24 namespace WorkScheduler { 25 const int32_t COUNT_THERMAL_CRUCIAL = 0; 26 const int32_t COUNT_THERMAL_LOW = 1; 27 const int32_t COUNT_THERMAL_NORMAL = 3; 28 ThermalPolicy(shared_ptr<WorkPolicyManager> workPolicyManager)29ThermalPolicy::ThermalPolicy(shared_ptr<WorkPolicyManager> workPolicyManager) 30 { 31 workPolicyManager_ = workPolicyManager; 32 } 33 ~ThermalPolicy()34ThermalPolicy::~ThermalPolicy() 35 { 36 } 37 GetPolicyMaxRunning()38int32_t ThermalPolicy::GetPolicyMaxRunning() 39 { 40 auto& thermalMgrClient = ThermalMgrClient::GetInstance(); 41 ThermalLevel thermalLevel = thermalMgrClient.GetThermalLevel(); 42 int32_t res; 43 if (thermalLevel >= ThermalLevel::WARM) { 44 res = COUNT_THERMAL_CRUCIAL; 45 } else if (thermalLevel < ThermalLevel::WARM && thermalLevel >= ThermalLevel::NORMAL) { 46 res = COUNT_THERMAL_LOW; 47 } else { 48 res = COUNT_THERMAL_NORMAL; 49 } 50 WS_HILOGI("ThermalLevel:%{public}d, PolicyRes:%{public}d", thermalLevel, res); 51 return res; 52 } 53 } // namespace WorkScheduler 54 } // namespace OHOS