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 (-2) 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 INTELL_VOICE = 105; 38 static constexpr uint32_t AUTO_WINDOWN_RORATION = 107; 39 static constexpr uint32_t LCD_BRIGHTNESS = 115; 40 static constexpr uint32_t VIBRATORS_STATE = 120; 41 }; 42 43 ~PowerModePolicy() = default; 44 int32_t GetPowerModeValuePolicy(uint32_t type); // from switchMap_ 45 void UpdatePowerModePolicy(uint32_t mode); 46 void RemoveBackupMapSettingSwitch(uint32_t switchId); 47 typedef std::function<void(bool)> ModeAction; 48 void AddAction(uint32_t type, ModeAction& action); 49 void TriggerAllActions(bool isBoot); 50 bool IsValidType(uint32_t type); 51 bool InitRecoverMap(); 52 53 private: 54 std::map<uint32_t, ModeAction> actionMap_; 55 std::map<uint32_t, int32_t> switchMap_; 56 std::map<uint32_t, int32_t> recoverMap_; 57 std::map<uint32_t, int32_t> backupMap_; 58 59 void ReadPowerModePolicy(uint32_t mode); 60 void ComparePowerModePolicy(); 61 void GetSettingSwitchState(uint32_t& switchId, int32_t& value); // from setting 62 int32_t GetPolicyFromMap(uint32_t type); 63 void SavePowerModeRecoverMap(); 64 int64_t GetSettingDisplayOffTime(int64_t defaultVal); 65 66 std::mutex policyMutex_; 67 std::mutex actionMapMutex_; 68 }; 69 } // namespace PowerMgr 70 } // namespace OHOS 71 #endif // POWER_MODE_POLICY_H 72