1 /* 2 * Copyright (c) 2021-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 16 #ifndef POWER_MODE_POLICY_H 17 #define POWER_MODE_POLICY_H 18 19 #include <string> 20 #include <map> 21 #include <list> 22 #include "power_save_mode.h" 23 24 #define INIT_VALUE_FALSE (-1) 25 #define LAST_MODE_FLAG 0 26 27 namespace OHOS { 28 namespace PowerMgr { 29 class PowerModePolicy { 30 public: 31 class ServiceType { 32 public: 33 static constexpr uint32_t DISPLAY_OFFTIME = 101; 34 static constexpr uint32_t SLEEPTIME = 102; 35 static constexpr uint32_t AUTO_ADJUST_BRIGHTNESS = 103; 36 static constexpr uint32_t AUTO_WINDOWN_RORATION = 107; 37 static constexpr uint32_t SMART_BACKLIGHT = 115; 38 static constexpr uint32_t VIBRATORS_STATE = 120; 39 }; 40 41 ~PowerModePolicy() = default; 42 int32_t GetPowerModeValuePolicy(uint32_t type); 43 int32_t GetPowerModeRecoverPolicy(uint32_t type); 44 void SetPowerModePolicy(uint32_t mode, uint32_t lastMode); 45 typedef std::function<void(bool)> ModeAction; 46 void AddAction(uint32_t type, ModeAction& action); 47 void TriggerAllActions(bool isBoot); 48 bool IsValidType(uint32_t type); 49 50 private: 51 std::list<ModePolicy> openPolicy; 52 std::list<ModePolicy> closePolicy; 53 std::list<ModePolicy> recoverPolicy; 54 55 std::map<uint32_t, ModeAction> actionMap; 56 std::map<uint32_t, int32_t> valueModePolicy; 57 std::map<uint32_t, int32_t> recoverModePolicy; 58 std::map<uint32_t, int32_t>::iterator valueiter; 59 std::map<uint32_t, int32_t>::iterator recoveriter; 60 61 std::list<ModePolicy>::iterator openlit; 62 std::list<ModePolicy>::iterator closelit; 63 std::list<ModePolicy>::iterator recoverlit; 64 void ReadOpenPolicy(uint32_t mode); 65 void ReadRecoverPolicy(uint32_t lastMode); 66 void CompareModeItem(uint32_t mode, uint32_t lastMode); 67 int32_t GetPolicyFromMap(uint32_t type); 68 int32_t GetRecoverPolicyFromMap(uint32_t type); 69 }; 70 } // namespace PowerMgr 71 } // namespace OHOS 72 #endif // POWER_MODE_POLICY_H 73