1 /* 2 * Copyright (c) 2022-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_SERVICE_TEST_PROXY_H 17 #define POWERMGR_SERVICE_TEST_PROXY_H 18 19 #include <cstdint> 20 #include <sys/types.h> 21 #include <functional> 22 #include <iosfwd> 23 #include <vector> 24 25 #include "iremote_object.h" 26 #include "ipower_mode_callback.h" 27 #include "ipower_state_callback.h" 28 #include "ipower_runninglock_callback.h" 29 #include "ipower_mgr.h" 30 #include "iscreen_off_pre_callback.h" 31 #include "running_lock_info.h" 32 #include "power_errors.h" 33 #include "power_mgr_service.h" 34 #include "power_state_machine_info.h" 35 36 namespace OHOS { 37 namespace PowerMgr { 38 class PowerMgrServiceTestProxy { 39 public: 40 PowerMgrServiceTestProxy(const sptr<PowerMgrService>& service); 41 ~PowerMgrServiceTestProxy() = default; 42 43 PowerErrors CreateRunningLock(const sptr<IRemoteObject>& remoteObj, const RunningLockInfo& runningLockInfo); 44 bool ReleaseRunningLock(const sptr<IRemoteObject>& remoteObj, const std::string& name = ""); 45 bool IsRunningLockTypeSupported(RunningLockType type); 46 bool Lock(const sptr<IRemoteObject>& remoteObj, int32_t timeOutMs = -1); 47 bool UnLock(const sptr<IRemoteObject>& remoteObj, const std::string& name = ""); 48 bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid); 49 bool ProxyRunningLocks(bool isProxied, 50 const std::vector<std::pair<pid_t, pid_t>>& processInfos); 51 bool ResetRunningLocks(); 52 bool IsUsed(const sptr<IRemoteObject>& remoteObj); 53 PowerErrors SuspendDevice(int64_t callTimeMs, 54 SuspendDeviceType reason = SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, 55 bool suspendImmed = false); 56 PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason = WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, 57 const std::string& detail = std::string("app call")); 58 bool RefreshActivity(int64_t callTimeMs, UserActivityType type = UserActivityType::USER_ACTIVITY_TYPE_OTHER, 59 bool needChangeBacklight = true); 60 PowerErrors OverrideScreenOffTime(int64_t timeout); 61 PowerErrors RestoreScreenOffTime(); 62 PowerState GetState(); 63 bool IsScreenOn(bool needPrintLog = true); 64 PowerErrors ForceSuspendDevice(int64_t callTimeMs); 65 PowerErrors RebootDevice(const std::string& reason); 66 PowerErrors RebootDeviceForDeprecated(const std::string& reason); 67 PowerErrors ShutDownDevice(const std::string& reason); 68 bool RegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback, bool isSync = true); 69 bool UnRegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback); 70 bool RegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback); 71 bool UnRegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback); 72 bool RegisterScreenStateCallback(int32_t remainTime, const sptr<IScreenOffPreCallback>& callback); 73 bool UnRegisterScreenStateCallback(const sptr<IScreenOffPreCallback>& callback); 74 bool RegisterRunningLockCallback(const sptr<IPowerRunninglockCallback>& callback); 75 bool UnRegisterRunningLockCallback(const sptr<IPowerRunninglockCallback>& callback); 76 bool SetDisplaySuspend(bool enable); 77 PowerErrors SetDeviceMode(const PowerMode& mode); 78 PowerMode GetDeviceMode(); 79 std::string ShellDump(const std::vector<std::string>& args, uint32_t argc); 80 PowerErrors IsStandby(bool& isStandby); 81 private: 82 sptr<PowerMgrStub> stub_ {nullptr}; 83 }; 84 } // namespace PowerMgr 85 } // namespace OHOS 86 #endif // POWERMGR_SERVICE_TEST_PROXY_H 87