1 /* 2 * Copyright (c) 2021 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 void ListenSetting(); 46 void AddAction(uint32_t type, std::function<void()> action); 47 void TriggerAction(uint32_t type); 48 void TriggerAllActions(); 49 bool IsValidType(uint32_t type); 50 51 private: 52 std::list<ModePolicy> openPolicy; 53 std::list<ModePolicy> closePolicy; 54 std::list<ModePolicy> recoverPolicy; 55 56 std::map<uint32_t, std::function<void()>> actionMap; 57 std::map<uint32_t, int32_t> valueModePolicy; 58 std::map<uint32_t, int32_t> recoverModePolicy; 59 std::map<uint32_t, int32_t>::iterator valueiter; 60 std::map<uint32_t, int32_t>::iterator recoveriter; 61 62 std::list<ModePolicy>::iterator openlit; 63 std::list<ModePolicy>::iterator closelit; 64 std::list<ModePolicy>::iterator recoverlit; 65 void ReadOpenPolicy(uint32_t mode); 66 void ReadRecoverPolicy(uint32_t lastMode); 67 void CompareModeItem(uint32_t mode, uint32_t lastMode); 68 int32_t GetPolicyFromMap(uint32_t type); 69 int32_t GetRecoverPolicyFromMap(uint32_t type); 70 }; 71 } // namespace PowerMgr 72 } // namespace OHOS 73 #endif // POWER_MODE_POLICY_H 74