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