1 /* 2 * Copyright (c) 2021-2024 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_THREAD_H 17 #define POWER_MODE_THREAD_H 18 19 #include <common_event_data.h> 20 #include <common_event_manager.h> 21 #include <common_event_publish_info.h> 22 #include <common_event_support.h> 23 24 #include "ipower_mode_callback.h" 25 26 #define FLAG_FALSE (-1) 27 #define LAST_MODE_FLAG 0 28 #define SETTINGS_PRIVIDER_VALUE_LCD_BRIGHTNESS 99 29 #define SETTINGS_PRIVIDER_VALUE_VIBRATION 1 30 #define SETTINGS_PRIVIDER_VALUE_ROTATION 1 31 32 namespace OHOS { 33 namespace PowerMgr { 34 class PowerModeModule { 35 public: 36 PowerModeModule(); 37 ~PowerModeModule() = default; 38 void InitPowerMode(); 39 void SetModeItem(PowerMode mode); 40 PowerMode GetModeItem(); 41 void EnableMode(PowerMode mode, bool isBoot = false); 42 void AddPowerModeCallback(const sptr<IPowerModeCallback>& callback); 43 void DelPowerModeCallback(const sptr<IPowerModeCallback>& callback); 44 45 private: 46 using IntentWant = OHOS::AAFwk::Want; 47 48 class CallbackManager : public IRemoteObject::DeathRecipient { 49 public: 50 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 51 void AddCallback(const sptr<IPowerModeCallback>& callback); 52 void RemoveCallback(const sptr<IPowerModeCallback>& callback); 53 void WaitingCallback(); 54 55 private: 56 std::mutex mutex_; 57 std::set<sptr<IRemoteObject>> callbacks_; 58 }; 59 60 PowerMode mode_; 61 uint32_t lastMode_; 62 bool observerRegisted_ = false; 63 64 void Prepare(); 65 void PublishPowerModeEvent(); 66 void UnregisterSaveModeObserver(); 67 void RegisterSaveModeObserver(); 68 void RegisterAutoAdjustBrightnessObserver(); 69 void RegisterAutoWindowRotationObserver(); 70 void RegisterVibrateStateObserver(); 71 void RegisterIntellVoiceObserver(); 72 73 sptr<CallbackManager> callbackMgr_; 74 void UpdateModepolicy(); 75 void RunAction(bool isBoot); 76 static void SetDisplayOffTime(bool isBoot); 77 static void SetSleepTime([[maybe_unused]] bool isBoot); 78 static void SetAutoAdjustBrightness(bool isBoot); 79 static void SetLcdBrightness(bool isBoot); 80 static void SetVibration(bool isBoot); 81 static void SetWindowRotation(bool isBoot); 82 static void SetIntellVoiceState(bool isBoot); 83 84 std::atomic<bool> started_; 85 std::mutex mutex_; 86 }; 87 } // namespace PowerMgr 88 } // namespace OHOS 89 #endif // POWER_MODE_THREAD_H 90