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 POWERMGR_POWER_MGR_CLIENT_H 17 #define POWERMGR_POWER_MGR_CLIENT_H 18 19 #include <string> 20 21 #include <singleton.h> 22 23 #include "power_state_machine_info.h" 24 #include "running_lock.h" 25 26 namespace OHOS { 27 namespace PowerMgr { 28 class PowerMgrClient final : public DelayedRefSingleton<PowerMgrClient> { 29 DECLARE_DELAYED_REF_SINGLETON(PowerMgrClient) 30 31 public: 32 DISALLOW_COPY_AND_MOVE(PowerMgrClient); 33 /** 34 * Reboot the device. 35 * 36 * @param reason The reason for rebooting the device. e.g.updater 37 */ 38 void RebootDevice(const std::string& reason); 39 40 /** 41 * Shut down the device. 42 * 43 * @param reason The reason for shutting down the device. 44 * 45 */ 46 void ShutDownDevice(const std::string& reason); 47 48 /** 49 * Suspend device and set screen off. 50 * 51 * @param reason The reason why will you suspend the device, such as timeout/powerkey/forcesuspend and so on. 52 */ 53 void SuspendDevice(SuspendDeviceType reason = SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, 54 bool suspendImmed = false); 55 56 /** 57 * Wake up the device and set the screen on. 58 * 59 * @param reason The reason for waking up the device, such as powerkey/plugin/application. 60 */ 61 void WakeupDevice(WakeupDeviceType reason = WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, 62 const std::string& detail = std::string("app call")); 63 64 /** 65 * Refresh the screentimeout time, and keep the screen on. RefreshActivity works only when the screen is on. 66 * 67 * @param type The RefreshActivity type, such as touch/button/accessibility and so on. 68 * @param needChangeBacklight Whether to change the backlight state, for example, from DIM to BRIGHT. 69 * Set it to false if you don't want to change the backlight state. 70 */ 71 void RefreshActivity(UserActivityType type = UserActivityType::USER_ACTIVITY_TYPE_OTHER); 72 73 /** 74 * Check whether the device screen is on. The result may be true or false, depending on the system state. 75 */ 76 bool IsScreenOn(); 77 78 /** 79 * Get Power state. The result is PowerState type. 80 */ 81 PowerState GetState(); 82 83 /** 84 * Forcibly suspend the device into deepsleep, and return the suspend result. 85 */ 86 bool ForceSuspendDevice(); 87 88 /** 89 * Check whether the type of running lock is supported 90 */ 91 bool IsRunningLockTypeSupported(uint32_t type); 92 93 /** 94 * Enable/disable display suspend state 95 */ 96 void SetDisplaySuspend(bool enable); 97 98 /** 99 * Enum for set/get device mode 100 */ 101 enum { 102 NORMAL_MODE = 600, 103 POWER_SAVE_MODE = 601, 104 EXTREME_MODE = 602 105 }; 106 /* Set the device mode. 107 * 108 * @param set The mode the device. 109 */ 110 void SetDeviceMode(const uint32_t mode); 111 112 /** 113 * Get the device mode. 114 * 115 * @param Get The mode the device. 116 */ 117 uint32_t GetDeviceMode(); 118 119 std::shared_ptr<RunningLock> CreateRunningLock(const std::string& name, RunningLockType type); 120 void RegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback); 121 void UnRegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback); 122 void RegisterShutdownCallback(const sptr<IShutdownCallback>& callback, 123 IShutdownCallback::ShutdownPriority priority 124 = IShutdownCallback::ShutdownPriority::POWER_SHUTDOWN_PRIORITY_DEFAULT); 125 void UnRegisterShutdownCallback(const sptr<IShutdownCallback>& callback); 126 void RegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback); 127 void UnRegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback); 128 std::string Dump(const std::vector<std::string>& args); 129 130 private: 131 class PowerMgrDeathRecipient : public IRemoteObject::DeathRecipient { 132 public: 133 PowerMgrDeathRecipient() = default; 134 ~PowerMgrDeathRecipient() = default; 135 void OnRemoteDied(const wptr<IRemoteObject>& remote); 136 private: 137 DISALLOW_COPY_AND_MOVE(PowerMgrDeathRecipient); 138 }; 139 140 ErrCode Connect(); 141 sptr<IPowerMgr> proxy_ {nullptr}; 142 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 143 void ResetProxy(const wptr<IRemoteObject>& remote); 144 std::mutex mutex_; 145 }; 146 } // namespace PowerMgr 147 } // namespace OHOS 148 #endif // POWERMGR_POWER_MGR_CLIENT_H 149