1 /*
2 * Copyright (c) 2024 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/power_mode_policy.h"
16
17 #include "battery_srv_client.h"
18 #include "power_mgr_client.h"
19 #include "power_mode_info.h"
20 #include "work_sched_hilog.h"
21
22 using namespace std;
23 using namespace OHOS::PowerMgr;
24
25 namespace OHOS {
26 namespace WorkScheduler {
27 const int32_t COUNT_POWER_MODE_CRUCIAL = 1;
28 const int32_t COUNT_POWER_MODE_NORMAL = 3;
29
PowerModePolicy(shared_ptr<WorkPolicyManager> workPolicyManager)30 PowerModePolicy::PowerModePolicy(shared_ptr<WorkPolicyManager> workPolicyManager)
31 {
32 workPolicyManager_ = workPolicyManager;
33 }
34
~PowerModePolicy()35 PowerModePolicy::~PowerModePolicy()
36 {
37 }
38
GetPolicyMaxRunning()39 int32_t PowerModePolicy::GetPolicyMaxRunning()
40 {
41 int32_t res = COUNT_POWER_MODE_NORMAL;
42 auto mode = PowerMgrClient::GetInstance().GetDeviceMode();
43 if (mode == PowerMode::NORMAL_MODE || mode == PowerMode::PERFORMANCE_MODE) {
44 WS_HILOGD("power mode: %{public}d, PolicyRes: %{public}d", mode, res);
45 return res;
46 }
47 #ifdef POWERMGR_BATTERY_MANAGER_ENABLE
48 auto charge = BatterySrvClient::GetInstance().GetChargingStatus();
49 if (charge == BatteryChargeState::CHARGE_STATE_NONE || charge == BatteryChargeState::CHARGE_STATE_DISABLE) {
50 WS_HILOGI("charge: %{public}d, power mode: %{public}d, PolicyRes: %{public}d", charge, mode, res);
51 res = COUNT_POWER_MODE_CRUCIAL;
52 }
53 #endif
54 WS_HILOGI("power mode: %{public}d, PolicyRes: %{public}d", mode, res);
55 return res;
56 }
57
GetPolicyName()58 std::string PowerModePolicy::GetPolicyName()
59 {
60 return "POWER_MODE_POLICY";
61 }
62 } // namespace WorkScheduler
63 } // namespace OHOS