• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 
16 #ifndef POWERMGR_POWER_MGR_PowerSaveMode_H
17 #define POWERMGR_POWER_MGR_PowerSaveMode_H
18 
19 #include <string>
20 #include <list>
21 #include <map>
22 
23 #include "ipc_object_stub.h"
24 #include "libxml/tree.h"
25 #include "sp_singleton.h"
26 #include "system_ability.h"
27 
28 #define RETURN_FLAG_FALSE (-1)
29 #define SLEEP_FILTER_VALUE 124
30 
31 namespace OHOS {
32 namespace PowerMgr {
33 struct ModePolicy {
34     int32_t id;
35     int32_t value;
36     int32_t recover_flag;
37 };
38 enum ValueProp {
39     value,
40     recover
41 };
42 
43 class PowerSaveMode : public RefBase {
44 public:
45     PowerSaveMode();
46     ~PowerSaveMode()=default;
47     bool GetValuePolicy(std::list<ModePolicy> &openPolicy, int32_t mode);
48     bool GetRecoverPolicy(std::list<ModePolicy> &recoverPolicy, int32_t mode);
49     bool GetFilterPolicy(std::list<ModePolicy> &policy, int32_t mode, int32_t value);
50     int32_t GetSleepTime(int32_t mode);
51     std::list<ModePolicy> GetLastMode();
52     std::list<ModePolicy> SetLastMode(std::list<ModePolicy>& policy);
GetPolicyCache()53     std::map<int32_t, std::list<ModePolicy>> GetPolicyCache()
54     {
55         return policyCache_;
56     }
57 
58 private:
59     std::map<int32_t, std::list<ModePolicy>> policyCache_;
60     bool StartXMlParse(std::string path);
61     std::string GetProp(const xmlNodePtr& nodePtr, const std::string& key);
62 };
63 } // namespace PowerMgr
64 } // namespace OHOS
65 #endif // POWERMGR_POWER_MGR_PowerSaveMode_H
66