• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_state_callback.h"
28 #include "power_errors.h"
29 #include "power_state_machine_info.h"
30 #include "running_lock_info.h"
31 #include "shutdown/ishutdown_client.h"
32 #include "suspend/isync_sleep_callback.h"
33 
34 namespace OHOS {
35 namespace PowerMgr {
36 class IPowerMgr : public IShutdownClient, public IRemoteBroker {
37 public:
38     virtual PowerErrors CreateRunningLock(const sptr<IRemoteObject>& remoteObj,
39         const RunningLockInfo& runningLockInfo) = 0;
40     virtual bool ReleaseRunningLock(const sptr<IRemoteObject>& remoteObj) = 0;
41     virtual bool IsRunningLockTypeSupported(RunningLockType type) = 0;
42     virtual bool Lock(const sptr<IRemoteObject>& remoteObj, int32_t timeOutMs) = 0;
43     virtual bool UnLock(const sptr<IRemoteObject>& remoteObj) = 0;
44     virtual bool QueryRunningLockLists(std::map<std::string, RunningLockInfo>& runningLockLists) = 0;
45     virtual bool IsUsed(const sptr<IRemoteObject>& remoteObj) = 0;
46     virtual bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) = 0;
47     virtual bool ProxyRunningLocks(bool isProxied, const std::vector<std::pair<pid_t, pid_t>>& processInfos) = 0;
48     virtual bool ResetRunningLocks() = 0;
49 
50     // Used for power state machine.
51     virtual PowerErrors RebootDevice(const std::string& reason) = 0;
52     virtual PowerErrors RebootDeviceForDeprecated(const std::string& reason) = 0;
53     virtual PowerErrors ShutDownDevice(const std::string& reason) = 0;
54     virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed) = 0;
55     virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) = 0;
56     virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) = 0;
57     virtual bool OverrideScreenOffTime(int64_t timeout) = 0;
58     virtual bool RestoreScreenOffTime() = 0;
59     virtual PowerState GetState() = 0;
60     virtual bool IsScreenOn() = 0;
61     virtual bool ForceSuspendDevice(int64_t callTimeMs) = 0;
62     virtual bool RegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback) = 0;
63     virtual bool UnRegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback) = 0;
64 
65     virtual bool RegisterSyncSleepCallback(const sptr<ISyncSleepCallback>& callback,
66         SleepPriority priority = SleepPriority::DEFAULT) = 0;
67     virtual bool UnRegisterSyncSleepCallback(const sptr<ISyncSleepCallback>& callback) = 0;
68 
69     // Used for callback registration upon power mode.
70     virtual bool RegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback) = 0;
71     virtual bool UnRegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback) = 0;
72 
73     virtual bool SetDisplaySuspend(bool enable) = 0;
74     virtual PowerErrors SetDeviceMode(const PowerMode& mode) = 0;
75     virtual PowerMode GetDeviceMode() = 0;
76     virtual std::string ShellDump(const std::vector<std::string>& args, uint32_t argc) = 0;
77     virtual PowerErrors IsStandby(bool& isStandby) = 0;
78 
79     virtual void RegisterShutdownCallback(
80         const sptr<ITakeOverShutdownCallback>& callback, ShutdownPriority priority) = 0;
81     virtual void UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback) = 0;
82 
83     virtual void RegisterShutdownCallback(
84         const sptr<IAsyncShutdownCallback>& callback, ShutdownPriority priority) = 0;
85     virtual void UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback) = 0;
86     virtual void RegisterShutdownCallback(
87         const sptr<ISyncShutdownCallback>& callback, ShutdownPriority priority) = 0;
88     virtual void UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback) = 0;
89 
90     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.IPowerMgr");
91 };
92 } // namespace PowerMgr
93 } // namespace OHOS
94 #endif // POWERMGR_IPOWER_MANAGER_H
95