1 /* 2 * Copyright (c) 2021-2023 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_IPOWER_MANAGER_H 17 #define POWERMGR_IPOWER_MANAGER_H 18 19 #include <string> 20 #include <vector> 21 #include <map> 22 23 #include <iremote_broker.h> 24 #include <iremote_object.h> 25 26 #include "ipower_mode_callback.h" 27 #include "ipower_runninglock_callback.h" 28 #include "ipower_state_callback.h" 29 #include "iscreen_off_pre_callback.h" 30 #include "power_errors.h" 31 #include "power_state_machine_info.h" 32 #include "running_lock_info.h" 33 #include "shutdown/ishutdown_client.h" 34 #include "suspend/isync_sleep_callback.h" 35 #include "hibernate/isync_hibernate_callback.h" 36 37 namespace OHOS { 38 namespace PowerMgr { 39 class IPowerMgr : public IShutdownClient, public IRemoteBroker { 40 public: 41 virtual PowerErrors CreateRunningLock(const sptr<IRemoteObject>& remoteObj, 42 const RunningLockInfo& runningLockInfo) = 0; 43 virtual bool ReleaseRunningLock(const sptr<IRemoteObject>& remoteObj, const std::string& name = "") = 0; 44 virtual bool IsRunningLockTypeSupported(RunningLockType type) = 0; 45 virtual bool UpdateWorkSource(const sptr<IRemoteObject>& remoteObj, 46 const std::map<int32_t, std::string>& workSources) = 0; 47 virtual PowerErrors Lock(const sptr<IRemoteObject>& remoteObj, int32_t timeOutMs = -1) = 0; 48 virtual PowerErrors UnLock(const sptr<IRemoteObject>& remoteObj, const std::string& name = "") = 0; 49 virtual bool QueryRunningLockLists(std::map<std::string, RunningLockInfo>& runningLockLists) = 0; 50 virtual bool IsUsed(const sptr<IRemoteObject>& remoteObj) = 0; 51 virtual bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) = 0; 52 virtual bool ProxyRunningLocks(bool isProxied, const std::vector<std::pair<pid_t, pid_t>>& processInfos) = 0; 53 virtual bool ResetRunningLocks() = 0; 54 55 // Used for power state machine. 56 virtual PowerErrors RebootDevice(const std::string& reason) = 0; 57 virtual PowerErrors RebootDeviceForDeprecated(const std::string& reason) = 0; 58 virtual PowerErrors ShutDownDevice(const std::string& reason) = 0; 59 virtual PowerErrors SetSuspendTag(const std::string& tag) = 0; 60 virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed) = 0; 61 virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) = 0; 62 virtual void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) = 0; 63 virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) = 0; 64 virtual PowerErrors OverrideScreenOffTime(int64_t timeout) = 0; 65 virtual PowerErrors RestoreScreenOffTime() = 0; 66 virtual PowerState GetState() = 0; 67 virtual bool IsScreenOn(bool needPrintLog = true) = 0; 68 virtual bool IsFoldScreenOn() = 0; 69 virtual bool IsCollaborationScreenOn() = 0; 70 virtual PowerErrors ForceSuspendDevice(int64_t callTimeMs) = 0; 71 virtual bool RegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback, bool isSync = true) = 0; 72 virtual bool UnRegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback) = 0; 73 74 virtual bool RegisterSyncSleepCallback(const sptr<ISyncSleepCallback>& callback, 75 SleepPriority priority = SleepPriority::DEFAULT) = 0; 76 virtual bool UnRegisterSyncSleepCallback(const sptr<ISyncSleepCallback>& callback) = 0; 77 78 virtual bool RegisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& callback) = 0; 79 virtual bool UnRegisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& callback) = 0; 80 81 // Used for callback registration upon power mode. 82 virtual bool RegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback) = 0; 83 virtual bool UnRegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback) = 0; 84 85 virtual bool RegisterScreenStateCallback(int32_t remainTime, const sptr<IScreenOffPreCallback>& callback) = 0; 86 virtual bool UnRegisterScreenStateCallback(const sptr<IScreenOffPreCallback>& callback) = 0; 87 88 virtual bool SetDisplaySuspend(bool enable) = 0; 89 virtual PowerErrors Hibernate(bool clearMemory) = 0; 90 virtual PowerErrors SetDeviceMode(const PowerMode& mode) = 0; 91 virtual PowerMode GetDeviceMode() = 0; 92 virtual std::string ShellDump(const std::vector<std::string>& args, uint32_t argc) = 0; 93 virtual PowerErrors IsStandby(bool& isStandby) = 0; 94 95 virtual PowerErrors SetForceTimingOut(bool enabled, const sptr<IRemoteObject>& token) = 0; 96 virtual PowerErrors LockScreenAfterTimingOut( 97 bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, const sptr<IRemoteObject>& token) = 0; 98 99 virtual void RegisterShutdownCallback( 100 const sptr<ITakeOverShutdownCallback>& callback, ShutdownPriority priority) = 0; 101 virtual void UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback) = 0; 102 103 virtual void RegisterShutdownCallback( 104 const sptr<IAsyncShutdownCallback>& callback, ShutdownPriority priority) = 0; 105 virtual void UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback) = 0; 106 virtual void RegisterShutdownCallback( 107 const sptr<ISyncShutdownCallback>& callback, ShutdownPriority priority) = 0; 108 virtual void UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback) = 0; 109 110 virtual bool RegisterRunningLockCallback(const sptr<IPowerRunninglockCallback>& callback) = 0; 111 virtual bool UnRegisterRunningLockCallback(const sptr<IPowerRunninglockCallback>& callback) = 0; 112 113 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.IPowerMgr"); 114 }; 115 } // namespace PowerMgr 116 } // namespace OHOS 117 #endif // POWERMGR_IPOWER_MANAGER_H 118