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