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 <mutex> 22 #include <list> 23 #include "power_save_mode.h" 24 25 #define INIT_VALUE_FALSE (-1) 26 #define LAST_MODE_FLAG 0 27 28 namespace OHOS { 29 namespace PowerMgr { 30 class PowerModePolicy { 31 public: 32 class ServiceType { 33 public: 34 static constexpr uint32_t DISPLAY_OFFTIME = 101; 35 static constexpr uint32_t SLEEPTIME = 102; 36 static constexpr uint32_t AUTO_ADJUST_BRIGHTNESS = 103; 37 static constexpr uint32_t AUTO_WINDOWN_RORATION = 107; 38 static constexpr uint32_t SMART_BACKLIGHT = 115; 39 static constexpr uint32_t VIBRATORS_STATE = 120; 40 }; 41 42 ~PowerModePolicy() = default; 43 int32_t GetPowerModeValuePolicy(uint32_t type); 44 int32_t GetPowerModeRecoverPolicy(uint32_t type); 45 void SetPowerModePolicy(uint32_t mode, uint32_t lastMode); 46 typedef std::function<void(bool)> ModeAction; 47 void AddAction(uint32_t type, ModeAction& action); 48 void TriggerAllActions(bool isBoot); 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, ModeAction> 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 std::mutex policyMutex_; 71 std::mutex actionMapMutex_; 72 }; 73 } // namespace PowerMgr 74 } // namespace OHOS 75 #endif // POWER_MODE_POLICY_H 76