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 "hilog/log.h" 26 #include "iremote_object.h" 27 #include "ipower_mode_callback.h" 28 #include "ipower_state_callback.h" 29 #include "ipower_runninglock_callback.h" 30 #include "ipower_mgr.h" 31 #include "iscreen_off_pre_callback.h" 32 #include "running_lock_info.h" 33 #include "power_errors.h" 34 #include "power_mgr_service.h" 35 #include "power_state_machine_info.h" 36 37 namespace OHOS { 38 namespace PowerMgr { 39 class PowerMgrServiceTestProxy { 40 public: 41 PowerMgrServiceTestProxy(const sptr<PowerMgrService>& service); 42 ~PowerMgrServiceTestProxy() = default; 43 44 int32_t CreateRunningLockIpc( 45 const sptr<IRemoteObject>& remoteObj, const RunningLockInfo& runningLockInfo, int32_t& powerError); 46 int32_t ReleaseRunningLockIpc(const sptr<IRemoteObject>& remoteObj, const std::string& name = ""); 47 int32_t IsRunningLockTypeSupportedIpc(int32_t lockType, bool& lockSupported); 48 int32_t LockIpc(const sptr<IRemoteObject>& remoteObj, int32_t timeOutMs, int32_t& powerError); 49 int32_t UnLockIpc(const sptr<IRemoteObject>& remoteObj, const std::string& name, int32_t& powerError); 50 int32_t ProxyRunningLockIpc(bool isProxied, pid_t pid, pid_t uid); 51 int32_t ProxyRunningLocksIpc(bool isProxied, const VectorPair& vectorPairInfos); 52 int32_t ResetRunningLocksIpc(); 53 int32_t IsUsedIpc(const sptr<IRemoteObject>& remoteObj, bool& isUsed); 54 int32_t SuspendDeviceIpc(int64_t callTimeMs, int32_t reasonValue, bool suspendImmed, 55 const std::string& apiVersion, int32_t& powerError); 56 int32_t WakeupDeviceIpc(int64_t callTimeMs, int32_t reasonValue, const std::string& details, 57 const std::string& apiVersion, int32_t& powerError); 58 int32_t RefreshActivityIpc(int64_t callTimeMs, 59 int32_t activityType = static_cast<int32_t>(UserActivityType::USER_ACTIVITY_TYPE_OTHER), 60 bool needChangeBacklight = true); 61 int32_t OverrideScreenOffTimeIpc(int64_t timeout, int32_t& powerError); 62 int32_t RestoreScreenOffTimeIpc(const std::string& apiVersion, int32_t& powerError); 63 int32_t GetStateIpc(int32_t& powerState); 64 int32_t IsScreenOnIpc(bool needPrintLog, bool& isScreenOn); 65 int32_t ForceSuspendDeviceIpc(int64_t callTimeMs); 66 int32_t IsForceSleepingIpc(bool& isForceSleeping); 67 int32_t RebootDeviceIpc(const std::string& reason, int32_t& powerError); 68 int32_t RebootDeviceForDeprecatedIpc(const std::string& reason, int32_t& powerError); 69 int32_t ShutDownDeviceIpc(const std::string& reason, int32_t& powerError); 70 int32_t RegisterPowerStateCallbackIpc(const sptr<IPowerStateCallback>& callback, bool isSync = true); 71 int32_t UnRegisterPowerStateCallbackIpc(const sptr<IPowerStateCallback>& callback); 72 int32_t RegisterPowerModeCallbackIpc(const sptr<IPowerModeCallback>& callback); 73 int32_t UnRegisterPowerModeCallbackIpc(const sptr<IPowerModeCallback>& callback); 74 int32_t RegisterScreenStateCallbackIpc(int32_t remainTime, const sptr<IScreenOffPreCallback>& callback); 75 int32_t UnRegisterScreenStateCallbackIpc(const sptr<IScreenOffPreCallback>& callback); 76 int32_t RegisterRunningLockCallbackIpc(const sptr<IPowerRunninglockCallback>& callback); 77 int32_t UnRegisterRunningLockCallbackIpc(const sptr<IPowerRunninglockCallback>& callback); 78 bool RegisterSuspendTakeoverCallbackIpc(const sptr<ITakeOverSuspendCallback>& callback); 79 bool UnRegisterSuspendTakeoverCallbackIpc(const sptr<ITakeOverSuspendCallback>& callback); 80 int32_t SetDisplaySuspendIpc(bool enable); 81 int32_t SetDeviceModeIpc(int32_t modeValue, int32_t& powerError); 82 int32_t GetDeviceModeIpc(int32_t& powerMode); 83 int32_t ShellDumpIpc(const std::vector<std::string>& args, uint32_t argc, std::string& returnDump); 84 int32_t IsStandbyIpc(bool& isStandby, int32_t& powerError); 85 private: 86 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD000F00, "PowerTest"}; 87 sptr<PowerMgrStub> stub_ {nullptr}; 88 const int VECTOR_MAX_SIZE = 102400; 89 }; 90 } // namespace PowerMgr 91 } // namespace OHOS 92 #endif // POWERMGR_SERVICE_TEST_PROXY_H 93