From 633bce87ac12451cfe31f97368f859142a34f152 Mon Sep 17 00:00:00 2001 From: wangjingchang Date: Wed, 21 May 2025 17:31:57 +0800 Subject: [PATCH] =?UTF-8?q?style:=20power=5Fmanager=E4=BB=93IDL=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangjingchang --- bundle.json | 1 - frameworks/native/power_mgr_client.cpp | 184 ++- frameworks/native/running_lock.cpp | 21 +- frameworks/native/running_lock_info.cpp | 34 + .../native/shutdown/shutdown_client.cpp | 15 +- interfaces/inner_api/BUILD.gn | 12 +- .../include/power_mgr_ipc_interface_code.h | 73 - .../native/include/running_lock_info.h | 10 + ..._code.h => itake_over_shutdown_callback.h} | 24 +- services/BUILD.gn | 119 +- services/IPowerMgr.idl | 99 ++ services/native/include/power_mgr_service.h | 3 +- .../include/power_mgr_service_ipc_adapter.h | 291 ++-- services/native/src/power_mgr_service.cpp | 14 +- .../src/power_mgr_service_ipc_adapter.cpp | 442 +++++ services/zidl/include/ipower_mgr_async.h | 21 + services/zidl/include/power_mgr_async_reply.h | 30 +- .../power_mgr_async_reply_proxy.h} | 81 +- .../power_mgr_async_reply_stub.h} | 90 +- services/zidl/include/power_mgr_proxy.h | 117 -- services/zidl/include/power_mgr_stub.h | 87 - services/zidl/src/power_mgr_async_reply.cpp | 2 + services/zidl/src/power_mgr_proxy.cpp | 1442 ----------------- services/zidl/src/power_mgr_stub.cpp | 774 --------- .../src/shutdown/shutdown_proxy_delegator.cpp | 161 -- .../src/shutdown/shutdown_stub_delegator.cpp | 127 -- .../asyncshutdowncallback_fuzzer_test.cpp | 10 +- .../createrunninglock_fuzzer_test.cpp | 5 +- .../forcesuspenddevice_fuzzer_test.cpp | 5 +- .../getsetdevicemode_fuzzer_test.cpp | 8 +- .../getstate_fuzzer/getstate_fuzzer_test.cpp | 4 +- .../hibernate_fuzzer_test.cpp | 4 +- .../iscollaborationscreenon_fuzzer_test.cpp | 4 +- .../isfoldscreenon_fuzzer_test.cpp | 5 +- ...isrunninglocktypesupported_fuzzer_test.cpp | 4 +- .../isscreenon_fuzzer_test.cpp | 4 +- .../isstandby_fuzzer_test.cpp | 4 +- .../lockscreenaftertimingout_fuzzer_test.cpp | 4 +- .../lockunlockisused_fuzzer_test.cpp | 8 +- .../overridescreenofftime_fuzzer_test.cpp | 6 +- .../powermodecallback_fuzzer_test.cpp | 6 +- .../powerstatecallback_fuzzer_test.cpp | 6 +- .../proxyrunninglock_fuzzer_test.cpp | 5 +- .../proxyrunninglocks_fuzzer_test.cpp | 5 +- .../queryrunninglocklists_fuzzer_test.cpp | 5 +- .../rebootdevice_fuzzer_test.cpp | 6 +- .../refreshactivity_fuzzer_test.cpp | 5 +- .../releaserunninglock_fuzzer_test.cpp | 5 +- .../resetrunninglocks_fuzzer_test.cpp | 5 +- .../runninglockcallback_fuzzer_test.cpp | 6 +- .../screenstatecallback_fuzzer_test.cpp | 6 +- .../setdisplaysuspend_fuzzer_test.cpp | 5 +- .../setforcetimingout_fuzzer_test.cpp | 5 +- .../setsuspendtag_fuzzer_test.cpp | 5 +- .../shelldump_fuzzer_test.cpp | 4 +- .../shutdowndevice_fuzzer_test.cpp | 5 +- .../suspenddevice_fuzzer_test.cpp | 4 +- .../synchibernatecallback_fuzzer_test.cpp | 6 +- .../syncshutdowncallback_fuzzer_test.cpp | 10 +- .../syncsleepcallback_fuzzer_test.cpp | 6 +- .../takeovershutdowncallback_fuzzer_test.cpp | 6 +- .../wakeupdevice_fuzzer_test.cpp | 4 +- test/systemtest/BUILD.gn | 14 + test/unittest/BUILD.gn | 212 ++- .../interface_test/running_lock_test.h | 12 +- .../include/power_client_callback_test.h | 64 + .../servicetest/powermgr_service_test_proxy.h | 77 +- .../interface_test/power_mgr_service_test.cpp | 31 +- .../src/interface_test/running_lock_test.cpp | 73 +- .../interface_test/shutdown_client_test.cpp | 5 + .../src/mock/power_mock_object_test.cpp | 119 +- .../src/mock/power_mock_parcel_test.cpp | 100 +- .../src/mock/power_mock_peer_test.cpp | 116 +- .../src/mock/power_mock_proxy_test.cpp | 115 +- .../src/power_client_callback_test.cpp | 142 ++ test/unittest/src/servicetest/BUILD.gn | 12 + .../powermgr_service_mock_parcel_test.cpp | 105 +- .../powermgr_service_native_test.cpp | 843 ++++++---- .../powermgr_service_test_proxy.cpp | 1311 +++++++++------ 79 files changed, 3551 insertions(+), 4269 deletions(-) delete mode 100644 interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h rename interfaces/inner_api/native/include/shutdown/{shutdown_client_ipc_interface_code.h => itake_over_shutdown_callback.h} (47%) create mode 100644 services/IPowerMgr.idl rename interfaces/inner_api/native/include/ipower_mgr.h => services/native/include/power_mgr_service_ipc_adapter.h (40%) create mode 100644 services/native/src/power_mgr_service_ipc_adapter.cpp create mode 100644 services/zidl/include/ipower_mgr_async.h rename services/zidl/{src/shutdown/shutdown_stub_delegator.h => include/power_mgr_async_reply_proxy.h} (41%) rename services/zidl/{src/shutdown/shutdown_proxy_delegator.h => include/power_mgr_async_reply_stub.h} (36%) delete mode 100644 services/zidl/include/power_mgr_proxy.h delete mode 100644 services/zidl/include/power_mgr_stub.h delete mode 100644 services/zidl/src/power_mgr_proxy.cpp delete mode 100644 services/zidl/src/power_mgr_stub.cpp delete mode 100644 services/zidl/src/shutdown/shutdown_proxy_delegator.cpp delete mode 100644 services/zidl/src/shutdown/shutdown_stub_delegator.cpp create mode 100644 test/unittest/include/power_client_callback_test.h create mode 100644 test/unittest/src/power_client_callback_test.cpp diff --git a/bundle.json b/bundle.json index e862c37e..0e407cd6 100644 --- a/bundle.json +++ b/bundle.json @@ -123,7 +123,6 @@ "name": "//base/powermgr/power_manager/interfaces/inner_api:powermgr_client", "header": { "header_files": [ - "ipower_mgr.h", "ipower_state_callback.h", "iscreen_off_pre_callback.h", "power_errors.h", diff --git a/frameworks/native/power_mgr_client.cpp b/frameworks/native/power_mgr_client.cpp index 80121394..78b943f7 100644 --- a/frameworks/native/power_mgr_client.cpp +++ b/frameworks/native/power_mgr_client.cpp @@ -38,12 +38,14 @@ #include "power_log.h" #include "power_common.h" #include "running_lock_info.h" +#include "power_mgr_async_reply_stub.h" namespace OHOS { namespace PowerMgr { std::vector> PowerMgrClient::runningLocks_; std::mutex PowerMgrClient::runningLocksMutex_; std::mutex g_instanceMutex; +constexpr int32_t MAX_VERSION_STRING_SIZE = 4; PowerMgrClient::PowerMgrClient() { @@ -175,21 +177,27 @@ PowerErrors PowerMgrClient::RebootDevice(const std::string& reason) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - return proxy->RebootDevice(reason); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + proxy->RebootDeviceIpc(reason, powerError); + return static_cast(powerError); } PowerErrors PowerMgrClient::RebootDeviceForDeprecated(const std::string& reason) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - return proxy->RebootDeviceForDeprecated(reason); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + proxy->RebootDeviceForDeprecatedIpc(reason, powerError); + return static_cast(powerError); } PowerErrors PowerMgrClient::ShutDownDevice(const std::string& reason) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - return proxy->ShutDownDevice(reason); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + proxy->ShutDownDeviceIpc(reason, powerError); + return static_cast(powerError); } PowerErrors PowerMgrClient::SetSuspendTag(const std::string &tag) @@ -197,7 +205,9 @@ PowerErrors PowerMgrClient::SetSuspendTag(const std::string &tag) sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); POWER_HILOGI(FEATURE_SUSPEND, "Set suspend tag: %{public}s", tag.c_str()); - return proxy->SetSuspendTag(tag); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + proxy->SetSuspendTagIpc(tag, powerError); + return static_cast(powerError); } PowerErrors PowerMgrClient::SuspendDevice( @@ -206,7 +216,11 @@ PowerErrors PowerMgrClient::SuspendDevice( sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); POWER_HILOGD(FEATURE_SUSPEND, " Calling SuspendDevice success"); - return proxy->SuspendDevice(GetTickCount(), reason, suspendImmed, apiVersion); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + int32_t reasonValue = static_cast(reason); + RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); + proxy->SuspendDeviceIpc(GetTickCount(), reasonValue, suspendImmed, apiVersion, powerError); + return static_cast(powerError); } PowerErrors PowerMgrClient::WakeupDevice( @@ -215,7 +229,11 @@ PowerErrors PowerMgrClient::WakeupDevice( sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); POWER_HILOGD(FEATURE_WAKEUP, " Calling WakeupDevice success"); - return proxy->WakeupDevice(GetTickCount(), reason, detail, apiVersion); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + int32_t reasonValue = static_cast(reason); + RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); + proxy->WakeupDeviceIpc(GetTickCount(), reasonValue, detail, apiVersion, powerError); + return static_cast(powerError); } void PowerMgrClient::WakeupDeviceAsync(WakeupDeviceType reason, const std::string& detail) @@ -223,14 +241,22 @@ void PowerMgrClient::WakeupDeviceAsync(WakeupDeviceType reason, const std::strin sptr proxy = GetPowerMgrProxy(); RETURN_IF(proxy == nullptr); POWER_HILOGD(FEATURE_WAKEUP, " Calling WakeupDeviceAsync success"); - return proxy->WakeupDeviceAsync(GetTickCount(), reason, detail); + int32_t reasonValue = static_cast(reason); + std::string apiVersion; + proxy->WakeupDeviceAsyncIpc(GetTickCount(), reasonValue, detail, apiVersion); + return; } bool PowerMgrClient::RefreshActivity(UserActivityType type) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); - bool ret = proxy->RefreshActivity(GetTickCount(), type, true); + bool ret = false; + int32_t activityType = static_cast(type); + int32_t result = proxy->RefreshActivityIpc(GetTickCount(), activityType, true); + if (result == ERR_OK) { + ret = true; + } POWER_HILOGD(FEATURE_ACTIVITY, "Calling RefreshActivity Success"); return ret; } @@ -243,7 +269,10 @@ PowerErrors PowerMgrClient::OverrideScreenOffTime(int64_t timeout, const std::st } sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - PowerErrors ret = proxy->OverrideScreenOffTime(timeout, apiVersion); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); + proxy->OverrideScreenOffTimeIpc(timeout, apiVersion, powerError); + PowerErrors ret = static_cast(powerError); POWER_HILOGD(COMP_FWK, "Calling OverrideScreenOffTime Success"); return ret; } @@ -252,7 +281,10 @@ PowerErrors PowerMgrClient::RestoreScreenOffTime(const std::string& apiVersion) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - PowerErrors ret = proxy->RestoreScreenOffTime(apiVersion); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); + proxy->RestoreScreenOffTimeIpc(apiVersion, powerError); + PowerErrors ret = static_cast(powerError); POWER_HILOGD(COMP_FWK, "Calling RestoreScreenOffTime Success"); return ret; } @@ -262,14 +294,22 @@ bool PowerMgrClient::IsRunningLockTypeSupported(RunningLockType type) POWER_HILOGD(FEATURE_RUNNING_LOCK, "RunningLockType=%{public}u", type); sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); - return proxy->IsRunningLockTypeSupported(type); + bool lockSupported = false; + int32_t lockType = static_cast(type); + proxy->IsRunningLockTypeSupportedIpc(lockType, lockSupported); + return lockSupported; } PowerErrors PowerMgrClient::ForceSuspendDevice(const std::string& apiVersion) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - PowerErrors ret = proxy->ForceSuspendDevice(GetTickCount(), apiVersion); + sptr asyncCallback = new PowerMgrStubAsync(); + sptr powerProxy = iface_cast(asyncCallback); + RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); + proxy->ForceSuspendDeviceIpc(GetTickCount(), apiVersion, powerProxy); + int waitTime = 100; + PowerErrors ret = static_cast(asyncCallback->WaitForAsyncReply(waitTime)); POWER_HILOGD(FEATURE_SUSPEND, "Calling ForceSuspendDevice Success"); return ret; } @@ -279,7 +319,7 @@ bool PowerMgrClient::IsScreenOn(bool needPrintLog) sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); bool ret = false; - ret = proxy->IsScreenOn(needPrintLog); + proxy->IsScreenOnIpc(needPrintLog, ret); if (needPrintLog) { POWER_HILOGI(COMP_FWK, "IsScreenOn=%{public}d, caller pid=%{public}d", ret, getpid()); } else { @@ -293,7 +333,7 @@ bool PowerMgrClient::IsFoldScreenOn() sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); bool ret = false; - ret = proxy->IsFoldScreenOn(); + proxy->IsFoldScreenOnIpc(ret); POWER_HILOGI(COMP_FWK, "IsFoldScreenOn=%{public}d, caller pid=%{public}d", ret, getpid()); return ret; } @@ -303,7 +343,7 @@ bool PowerMgrClient::IsCollaborationScreenOn() sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); bool ret = false; - ret = proxy->IsCollaborationScreenOn(); + proxy->IsCollaborationScreenOnIpc(ret); POWER_HILOGI(COMP_FWK, "IsCollaborationScreenOn=%{public}d, caller pid=%{public}d", ret, getpid()); return ret; } @@ -312,7 +352,9 @@ PowerState PowerMgrClient::GetState() { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerState::UNKNOWN); - return proxy->GetState(); + int32_t powerState = static_cast(PowerErrors::ERR_FAILURE); + proxy->GetStateIpc(powerState); + return static_cast(powerState); } std::shared_ptr PowerMgrClient::CreateRunningLock(const std::string& name, RunningLockType type) @@ -345,85 +387,95 @@ bool PowerMgrClient::ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); - return proxy->ProxyRunningLock(isProxied, pid, uid); + bool result = false; + int32_t ret = proxy->ProxyRunningLockIpc(isProxied, pid, uid); + if (ret == ERR_OK) { + result = true; + } + return result; } bool PowerMgrClient::ProxyRunningLocks(bool isProxied, const std::vector>& processInfos) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); - return proxy->ProxyRunningLocks(isProxied, processInfos); + VectorPair vectorPairInfos; + vectorPairInfos.processInfos = processInfos; + int32_t ret = proxy->ProxyRunningLocksIpc(isProxied, vectorPairInfos); + return ret == ERR_OK; } bool PowerMgrClient::ResetRunningLocks() { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); - return proxy->ResetRunningLocks(); + int32_t ret = proxy->ResetRunningLocksIpc(); + return ret == ERR_OK; } bool PowerMgrClient::RegisterPowerStateCallback(const sptr& callback, bool isSync) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->RegisterPowerStateCallback(callback, isSync); - return ret; + int32_t ret = proxy->RegisterPowerStateCallbackIpc(callback, isSync); + return ret == ERR_OK; } bool PowerMgrClient::UnRegisterPowerStateCallback(const sptr& callback) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->UnRegisterPowerStateCallback(callback); - return ret; + int32_t ret = proxy->UnRegisterPowerStateCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->RegisterSyncSleepCallback(callback, priority); - return ret; + int32_t priorityValue = static_cast(priority); + int32_t ret = proxy->RegisterSyncSleepCallbackIpc(callback, priorityValue); + return ret == ERR_OK; } bool PowerMgrClient::UnRegisterSyncSleepCallback(const sptr& callback) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->UnRegisterSyncSleepCallback(callback); - return ret; + int32_t ret = proxy->UnRegisterSyncSleepCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::RegisterSyncHibernateCallback(const sptr& callback) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->RegisterSyncHibernateCallback(callback); - return ret; + int32_t ret = proxy->RegisterSyncHibernateCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::UnRegisterSyncHibernateCallback(const sptr& callback) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->UnRegisterSyncHibernateCallback(callback); - return ret; + int32_t ret = proxy->UnRegisterSyncHibernateCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::RegisterPowerModeCallback(const sptr& callback) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->RegisterPowerModeCallback(callback); - return ret; + int32_t ret = proxy->RegisterPowerModeCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::UnRegisterPowerModeCallback(const sptr& callback) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); - bool ret = proxy->UnRegisterPowerModeCallback(callback); - return ret; + int32_t ret = proxy->UnRegisterPowerModeCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::RegisterScreenStateCallback(int32_t remainTime, const sptr& callback) @@ -431,8 +483,8 @@ bool PowerMgrClient::RegisterScreenStateCallback(int32_t remainTime, const sptr< sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((remainTime <= 0) || (callback == nullptr) || (proxy == nullptr), false); POWER_HILOGI(FEATURE_SCREEN_OFF_PRE, "Register screen off pre Callback by client"); - bool ret = proxy->RegisterScreenStateCallback(remainTime, callback); - return ret; + int32_t ret = proxy->RegisterScreenStateCallbackIpc(remainTime, callback); + return ret == ERR_OK; } bool PowerMgrClient::UnRegisterScreenStateCallback(const sptr& callback) @@ -440,8 +492,8 @@ bool PowerMgrClient::UnRegisterScreenStateCallback(const sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); POWER_HILOGI(FEATURE_SCREEN_OFF_PRE, "Unregister screen off pre Callback by client"); - bool ret = proxy->UnRegisterScreenStateCallback(callback); - return ret; + int32_t ret = proxy->UnRegisterScreenStateCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::RegisterRunningLockCallback(const sptr& callback) @@ -449,8 +501,8 @@ bool PowerMgrClient::RegisterRunningLockCallback(const sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); POWER_HILOGI(FEATURE_RUNNING_LOCK, "Register running lock Callback by client"); - bool ret = proxy->RegisterRunningLockCallback(callback); - return ret; + int32_t ret = proxy->RegisterRunningLockCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::UnRegisterRunningLockCallback(const sptr& callback) @@ -458,37 +510,48 @@ bool PowerMgrClient::UnRegisterRunningLockCallback(const sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET((callback == nullptr) || (proxy == nullptr), false); POWER_HILOGI(FEATURE_RUNNING_LOCK, "Unregister running lock Callback by client"); - bool ret = proxy->UnRegisterRunningLockCallback(callback); - return ret; + int32_t ret = proxy->UnRegisterRunningLockCallbackIpc(callback); + return ret == ERR_OK; } bool PowerMgrClient::SetDisplaySuspend(bool enable) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); - bool ret = proxy->SetDisplaySuspend(enable); - return ret; + int32_t ret = proxy->SetDisplaySuspendIpc(enable); + return ret == ERR_OK; } PowerErrors PowerMgrClient::Hibernate(bool clearMemory, const std::string& reason, const std::string& apiVersion) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - return proxy->Hibernate(clearMemory, reason, apiVersion); + sptr asyncCallback = new PowerMgrStubAsync(); + sptr powerProxy = iface_cast(asyncCallback); + RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); + proxy->HibernateIpc(clearMemory, reason, apiVersion, powerProxy); + int waitTime = 100; + PowerErrors ret = static_cast(asyncCallback->WaitForAsyncReply(waitTime)); + return ret; } PowerErrors PowerMgrClient::SetDeviceMode(const PowerMode mode) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - return proxy->SetDeviceMode(mode); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + int32_t modeValue = static_cast(mode); + proxy->SetDeviceModeIpc(modeValue, powerError); + return static_cast(powerError); } PowerMode PowerMgrClient::GetDeviceMode() { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, static_cast(0)); - return static_cast(proxy->GetDeviceMode()); + int32_t powerMode = 0; + proxy->GetDeviceModeIpc(powerMode); + return static_cast(powerMode); } std::string PowerMgrClient::Dump(const std::vector& args) @@ -496,7 +559,9 @@ std::string PowerMgrClient::Dump(const std::vector& args) std::string error = "can't connect service"; sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, error); - return proxy->ShellDump(args, args.size()); + std::string returnDump; + proxy->ShellDumpIpc(args, args.size(), returnDump); + return returnDump; } PowerErrors PowerMgrClient::GetError() @@ -510,8 +575,9 @@ PowerErrors PowerMgrClient::IsStandby(bool& isStandby) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - PowerErrors ret = proxy->IsStandby(isStandby); - return ret; + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + proxy->IsStandbyIpc(isStandby, powerError); + return static_cast(powerError); } bool PowerMgrClient::QueryRunningLockLists(std::map& runningLockLists) @@ -519,14 +585,17 @@ bool PowerMgrClient::QueryRunningLockLists(std::map proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, false); POWER_HILOGD(FEATURE_RUNNING_LOCK, "Query running lock lists by client"); - return proxy->QueryRunningLockLists(runningLockLists); + int32_t ret = proxy->QueryRunningLockListsIpc(runningLockLists); + return ret == ERR_OK; } PowerErrors PowerMgrClient::SetForceTimingOut(bool enabled) { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - PowerErrors ret = proxy->SetForceTimingOut(enabled, token_); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + proxy->SetForceTimingOutIpc(enabled, token_, powerError); + PowerErrors ret = static_cast(powerError); return ret; } @@ -534,7 +603,9 @@ PowerErrors PowerMgrClient::LockScreenAfterTimingOut(bool enabledLockScreen, boo { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - PowerErrors ret = proxy->LockScreenAfterTimingOut(enabledLockScreen, checkLock, sendScreenOffEvent, token_); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + proxy->LockScreenAfterTimingOutIpc(enabledLockScreen, checkLock, sendScreenOffEvent, token_, powerError); + PowerErrors ret = static_cast(powerError); return ret; } @@ -542,7 +613,10 @@ PowerErrors PowerMgrClient::IsRunningLockEnabled(const RunningLockType type, boo { sptr proxy = GetPowerMgrProxy(); RETURN_IF_WITH_RET(proxy == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - return proxy->IsRunningLockEnabled(type, result); + int32_t powerError = static_cast(PowerErrors::ERR_CONNECTION_FAIL); + int32_t lockType = static_cast(type); + proxy->IsRunningLockEnabledIpc(lockType, result, powerError); + return static_cast(powerError); } } // namespace PowerMgr diff --git a/frameworks/native/running_lock.cpp b/frameworks/native/running_lock.cpp index 56ea986f..c379ada7 100644 --- a/frameworks/native/running_lock.cpp +++ b/frameworks/native/running_lock.cpp @@ -62,7 +62,9 @@ PowerErrors RunningLock::Create() POWER_HILOGE(FEATURE_RUNNING_LOCK, "CProxy=null"); return PowerErrors::ERR_CONNECTION_FAIL; } - return proxy->CreateRunningLock(token_, runningLockInfo_); + int32_t powerError = static_cast(PowerErrors::ERR_FAILURE); + proxy->CreateRunningLockIpc(token_, runningLockInfo_, powerError); + return static_cast(powerError); } PowerErrors RunningLock::Recover(const wptr& proxy) @@ -80,7 +82,9 @@ ErrCode RunningLock::UpdateWorkSource(const std::vector& workSources) POWER_HILOGE(FEATURE_RUNNING_LOCK, "UpProxy=null"); return E_GET_POWER_SERVICE_FAILED; } - if (!proxy->UpdateWorkSource(token_, workSources)) { + int32_t ret = proxy->UpdateWorkSourceIpc(token_, workSources); + if (ret != ERR_OK) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "Failed to UpdateWorkSource"); return E_INNER_ERR; } return ERR_OK; @@ -102,7 +106,9 @@ ErrCode RunningLock::Lock(int32_t timeOutMs) timeOutMs = DEFAULT_TIMEOUT; POWER_HILOGW(FEATURE_RUNNING_LOCK, "use default timeout"); } - PowerErrors error = proxy->Lock(token_, timeOutMs); + int32_t powerError = static_cast(PowerErrors::ERR_FAILURE); + proxy->LockIpc(token_, timeOutMs, powerError); + PowerErrors error = static_cast(powerError); if (error != PowerErrors::ERR_OK) { return error == PowerErrors::ERR_PERMISSION_DENIED ? E_PERMISSION_DENIED : E_INNER_ERR; } @@ -117,7 +123,9 @@ ErrCode RunningLock::UnLock() return E_GET_POWER_SERVICE_FAILED; } POWER_HILOGD(FEATURE_RUNNING_LOCK, "Service side UnLock call"); - PowerErrors error = proxy->UnLock(token_, runningLockInfo_.name); + int32_t powerError = static_cast(PowerErrors::ERR_FAILURE); + proxy->UnLockIpc(token_, runningLockInfo_.name, powerError); + PowerErrors error = static_cast(powerError); if (error != PowerErrors::ERR_OK) { return error == PowerErrors::ERR_PERMISSION_DENIED ? E_PERMISSION_DENIED : E_INNER_ERR; } @@ -131,7 +139,8 @@ bool RunningLock::IsUsed() POWER_HILOGE(FEATURE_RUNNING_LOCK, "IProxy=null"); return false; } - bool ret = proxy->IsUsed(token_); + bool ret = false; + proxy->IsUsedIpc(token_, ret); POWER_HILOGD(FEATURE_RUNNING_LOCK, "Is Used: %{public}d", ret); return ret; } @@ -145,7 +154,7 @@ void RunningLock::Release() } // ReleaseRunningLock POWER_HILOGI(FEATURE_RUNNING_LOCK, "RlsN=%{public}s", runningLockInfo_.name.c_str()); - proxy->ReleaseRunningLock(token_, runningLockInfo_.name); + proxy->ReleaseRunningLockIpc(token_, runningLockInfo_.name); } } // namespace PowerMgr } // namespace OHOS diff --git a/frameworks/native/running_lock_info.cpp b/frameworks/native/running_lock_info.cpp index deaee889..1a84fe1f 100644 --- a/frameworks/native/running_lock_info.cpp +++ b/frameworks/native/running_lock_info.cpp @@ -22,6 +22,7 @@ namespace OHOS { namespace PowerMgr { +constexpr uint32_t MAX_PROXY_RUNNINGLOCK_NUM = 2000; bool RunningLockInfo::ReadFromParcel(Parcel& parcel) { uint32_t readType; @@ -64,5 +65,38 @@ bool RunningLockInfo::Marshalling(Parcel& parcel) const RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(parcel, Int32, static_cast(uid), false); return true; } + +bool VectorPair::Marshalling(Parcel& parcel) const +{ + size_t size = processInfos.size(); + RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(parcel, Int32, size, false); + if (size > MAX_PROXY_RUNNINGLOCK_NUM) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "size exceed limit, size=%{public}zu", size); + return false; + } + for (size_t i = 0; i < size; ++i) { + RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(parcel, Int32, processInfos[i].first, false); + RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(parcel, Int32, processInfos[i].second, false); + } + return true; +} + +VectorPair* VectorPair::Unmarshalling(Parcel& parcel) +{ + auto vectorPairPtr = std::make_unique(); + + int32_t size {0}; + RETURN_IF_READ_PARCEL_FAILED_WITH_RET(parcel, Int32, size, nullptr); + if (size <= 0 || size > MAX_PROXY_RUNNINGLOCK_NUM) { + POWER_HILOGW(COMP_FWK, "size exceed limit, size=%{public}d", size); + return nullptr; + } + vectorPairPtr->processInfos.resize(size); + for (int i = 0; i < size; ++i) { + RETURN_IF_READ_PARCEL_FAILED_WITH_RET(parcel, Int32, vectorPairPtr->processInfos[i].first, nullptr); + RETURN_IF_READ_PARCEL_FAILED_WITH_RET(parcel, Int32, vectorPairPtr->processInfos[i].second, nullptr); + } + return vectorPairPtr.release(); +} } // namespace PowerMgr } // namespace OHOS diff --git a/frameworks/native/shutdown/shutdown_client.cpp b/frameworks/native/shutdown/shutdown_client.cpp index a4572994..2c40f301 100644 --- a/frameworks/native/shutdown/shutdown_client.cpp +++ b/frameworks/native/shutdown/shutdown_client.cpp @@ -33,39 +33,42 @@ void ShutdownClient::RegisterShutdownCallback( const sptr& callback, ShutdownPriority priority) { RETURN_IF(Connect() != ERR_OK); - proxy_->RegisterShutdownCallback(callback, priority); + int32_t priorityValue = static_cast(priority); + proxy_->RegisterShutdownCallbackIpc(callback, priorityValue); } void ShutdownClient::UnRegisterShutdownCallback(const sptr& callback) { RETURN_IF(Connect() != ERR_OK); - proxy_->UnRegisterShutdownCallback(callback); + proxy_->UnRegisterShutdownCallbackIpc(callback); } void ShutdownClient::RegisterShutdownCallback( const sptr& callback, ShutdownPriority priority) { RETURN_IF(Connect() != ERR_OK); - proxy_->RegisterShutdownCallback(callback, priority); + int32_t priorityValue = static_cast(priority); + proxy_->RegisterShutdownCallbackIpc(callback, priorityValue); } void ShutdownClient::UnRegisterShutdownCallback(const sptr& callback) { RETURN_IF(Connect() != ERR_OK); - proxy_->UnRegisterShutdownCallback(callback); + proxy_->UnRegisterShutdownCallbackIpc(callback); } void ShutdownClient::RegisterShutdownCallback( const sptr& callback, ShutdownPriority priority) { RETURN_IF(Connect() != ERR_OK); - proxy_->RegisterShutdownCallback(callback, priority); + int32_t priorityValue = static_cast(priority); + proxy_->RegisterShutdownCallbackIpc(callback, priorityValue); } void ShutdownClient::UnRegisterShutdownCallback(const sptr& callback) { RETURN_IF(Connect() != ERR_OK); - proxy_->UnRegisterShutdownCallback(callback); + proxy_->UnRegisterShutdownCallbackIpc(callback); } } // namespace PowerMgr } // namespace OHOS diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index e2e2211c..12942e84 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -28,6 +28,12 @@ config("powermgr_private_config") { } ohos_shared_library("powermgr_client") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" sources = [ @@ -38,7 +44,6 @@ ohos_shared_library("powermgr_client") { "${powermgr_framework_native}/shutdown/shutdown_client.cpp", "${powermgr_framework_native}/shutdown/takeover_info.cpp", "${powermgr_service_zidl}/src/power_mgr_async_reply.cpp", - "${powermgr_service_zidl}/src/power_mgr_proxy.cpp", "${powermgr_service_zidl}/src/power_mode_callback_proxy.cpp", "${powermgr_service_zidl}/src/power_mode_callback_stub.cpp", "${powermgr_service_zidl}/src/power_runninglock_callback_proxy.cpp", @@ -49,7 +54,6 @@ ohos_shared_library("powermgr_client") { "${powermgr_service_zidl}/src/screen_off_pre_callback_stub.cpp", "${powermgr_service_zidl}/src/shutdown/async_shutdown_callback_proxy.cpp", "${powermgr_service_zidl}/src/shutdown/async_shutdown_callback_stub.cpp", - "${powermgr_service_zidl}/src/shutdown/shutdown_proxy_delegator.cpp", "${powermgr_service_zidl}/src/shutdown/sync_shutdown_callback_proxy.cpp", "${powermgr_service_zidl}/src/shutdown/sync_shutdown_callback_stub.cpp", "${powermgr_service_zidl}/src/shutdown/takeover_shutdown_callback_proxy.cpp", @@ -61,15 +65,19 @@ ohos_shared_library("powermgr_client") { ] configs = [ + "${powermgr_service_path}:powermgr_public_config", "${powermgr_utils_path}:coverage_flags", ":powermgr_private_config", ] public_configs = [ ":powermgr_public_config", + "${powermgr_service_path}:powermgr_public_config", "${powermgr_utils_path}:utils_config", ] + deps = [ "${powermgr_service_path}:powermgr_proxy" ] + external_deps = [ "ability_base:want", "c_utils:utils", diff --git a/interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h b/interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h deleted file mode 100644 index 8c508d84..00000000 --- a/interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POWER_MGR_IPC_INTERFACE_DODE_H -#define POWER_MGR_IPC_INTERFACE_DODE_H - -/* SAID: 3301 */ -namespace OHOS { -namespace PowerMgr { -enum class PowerMgrInterfaceCode { - CREATE_RUNNINGLOCK = 0, - RELEASE_RUNNINGLOCK, - IS_RUNNINGLOCK_TYPE_SUPPORTED, - RUNNINGLOCK_LOCK, - RUNNINGLOCK_UNLOCK, - RUNNINGLOCK_QUERY, - RUNNINGLOCK_ISUSED, - PROXY_RUNNINGLOCK, - PROXY_RUNNINGLOCKS, - RESET_RUNNINGLOCKS, - WAKEUP_DEVICE, - SUSPEND_DEVICE, - REFRESH_ACTIVITY, - OVERRIDE_DISPLAY_OFF_TIME, - RESTORE_DISPLAY_OFF_TIME, - GET_STATE, - IS_SCREEN_ON, - IS_FOLD_SCREEN_ON, - IS_COLLABORATION_SCREEN_ON, - FORCE_DEVICE_SUSPEND, - REBOOT_DEVICE, - REBOOT_DEVICE_FOR_DEPRECATED, - SHUTDOWN_DEVICE, - REG_POWER_STATE_CALLBACK, - UNREG_POWER_STATE_CALLBACK, - REG_POWER_MODE_CALLBACK, - UNREG_POWER_MODE_CALLBACK, - SET_DISPLAY_SUSPEND, - SETMODE_DEVICE, - GETMODE_DEVICE, - SHELL_DUMP, - IS_STANDBY, - REG_SYNC_SLEEP_CALLBACK, - UNREG_SYNC_SLEEP_CALLBACK, - SET_FORCE_TIMING_OUT, - LOCK_SCREEN_AFTER_TIMING_OUT, - HIBERNATE, - REG_SCREEN_OFF_PRE_CALLBACK, - UNREG_SCREEN_OFF_PRE_CALLBACK, - REG_RUNNINGLOCK_CALLBACK, - UNREG_RUNNINGLOCK_CALLBACK, - SET_SUSPEND_TAG, - REG_SYNC_HIBERNATE_CALLBACK, - UNREG_SYNC_HIBERNATE_CALLBACK, - UPDATE_WORK_SOURCE, - IS_RUNNINGLOCK_ENABLED -}; -} // space PowerMgr -} // namespace OHOS - -#endif // POWER_MGR_IPC_INTERFACE_DODE_H diff --git a/interfaces/inner_api/native/include/running_lock_info.h b/interfaces/inner_api/native/include/running_lock_info.h index 6e2faec1..29751d9e 100644 --- a/interfaces/inner_api/native/include/running_lock_info.h +++ b/interfaces/inner_api/native/include/running_lock_info.h @@ -21,6 +21,8 @@ #include +#include "power_errors.h" + namespace OHOS { namespace PowerMgr { /** @@ -98,6 +100,14 @@ struct RunningLockInfo : public Parcelable { bool Marshalling(Parcel& parcel) const override; static RunningLockInfo* Unmarshalling(Parcel& parcel); }; + +struct VectorPair : public Parcelable { +public: + std::vector> processInfos; + + virtual bool Marshalling(Parcel &parcel) const override; + static VectorPair* Unmarshalling(Parcel &parcel); +}; } // namespace PowerMgr } // namespace OHOS #endif // POWERMGR_RUNNING_LOCK_INFO_H diff --git a/interfaces/inner_api/native/include/shutdown/shutdown_client_ipc_interface_code.h b/interfaces/inner_api/native/include/shutdown/itake_over_shutdown_callback.h similarity index 47% rename from interfaces/inner_api/native/include/shutdown/shutdown_client_ipc_interface_code.h rename to interfaces/inner_api/native/include/shutdown/itake_over_shutdown_callback.h index 2092020a..1012f7bf 100644 --- a/interfaces/inner_api/native/include/shutdown/shutdown_client_ipc_interface_code.h +++ b/interfaces/inner_api/native/include/shutdown/itake_over_shutdown_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,23 +13,9 @@ * limitations under the License. */ -#ifndef SHUTDOWN_CLIENT_IPC_INTERFACE_DODE_H -#define SHUTDOWN_CLIENT_IPC_INTERFACE_DODE_H +#ifndef POWERMGR_POWER_MANAGER_ITAKE_OVER_SHUTDOWN_CALLBACK_H +#define POWERMGR_POWER_MANAGER_ITAKE_OVER_SHUTDOWN_CALLBACK_H -/* SAID: 3301 */ -namespace OHOS { -namespace PowerMgr { -enum class ShutdownClientInterfaceCode { - CMD_START = 200, - CMD_REG_TAKEOVER_SHUTDOWN_CALLBACK, - CMD_UNREG_TAKEOVER_SHUTDOWN_CALLBACK, - CMD_REG_ASYNC_SHUTDOWN_CALLBACK, - CMD_UNREG_ASYNC_SHUTDOWN_CALLBACK, - CMD_REG_SYNC_SHUTDOWN_CALLBACK, - CMD_UNREG_SYNC_SHUTDOWN_CALLBACK, - CMD_END = 299, -}; -} // space PowerMgr -} // namespace OHOS +#include "itakeover_shutdown_callback.h" -#endif // SHUTDOWN_CLIENT_IPC_INTERFACE_DODE_H \ No newline at end of file +#endif // POWERMGR_POWER_MANAGER_ITAKE_OVER_SHUTDOWN_CALLBACK_H diff --git a/services/BUILD.gn b/services/BUILD.gn index c1495f03..d203e3ec 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("../powermgr.gni") config("powermgr_public_config") { @@ -18,6 +19,10 @@ config("powermgr_public_config") { "native/include", "zidl/include", "${powermgr_inner_api}/native/include", + "${powermgr_inner_api}/native/include/hibernate", + "${powermgr_inner_api}/native/include/shutdown", + "${powermgr_inner_api}/native/include/suspend", + "${target_gen_dir}", ] } @@ -40,6 +45,86 @@ config("powermgr_private_config") { } } +idl_gen_interface("powermgr_interface") { + sources = [ "IPowerMgr.idl" ] + + log_domainid = "0xD002902" + log_tag = "PowerSvc" + subsystem_name = "powermgr" + part_name = "${powermgr_part_name}" +} + +ohos_source_set("powermgr_proxy") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":powermgr_interface") + sources = filter_include(output_values, [ "*_proxy.cpp" ]) + configs = [ + "${powermgr_utils_path}:utils_config", + "${powermgr_utils_path}:coverage_flags", + ":zidl_private_config", + ] + + public_configs = [ ":powermgr_public_config" ] + + deps = [ ":powermgr_interface" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "ipc:ipc_single", + ] + + subsystem_name = "powermgr" + part_name = "${powermgr_part_name}" +} + +ohos_source_set("powermgr_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":powermgr_interface") + sources = filter_include(output_values, [ "*_stub.cpp" ]) + sources += [ + "zidl/src/power_mgr_async_reply.cpp", + "zidl/src/power_mode_callback_stub.cpp", + "zidl/src/power_runninglock_callback_stub.cpp", + "zidl/src/power_state_callback_stub.cpp", + "zidl/src/screen_off_pre_callback_stub.cpp", + "zidl/src/sync_sleep_callback_stub.cpp", + ] + + configs = [ + "${powermgr_utils_path}:utils_config", + "${powermgr_utils_path}:coverage_flags", + ":zidl_private_config", + ] + + public_configs = [ ":powermgr_public_config" ] + + deps = [ + ":powermgr_interface", + "${powermgr_inner_api}:powermgr_client", + ] + + external_deps = [ + "c_utils:utils", + "hicollie:libhicollie", + "hilog:libhilog", + "ipc:ipc_core", + "ipc:ipc_single", + ] + + subsystem_name = "powermgr" + part_name = "${powermgr_part_name}" +} + ohos_shared_library("powermgrservice") { sanitize = { cfi = true @@ -54,6 +139,7 @@ ohos_shared_library("powermgrservice") { "native/src/power_mgr_factory.cpp", "native/src/power_mgr_notify.cpp", "native/src/power_mgr_service.cpp", + "native/src/power_mgr_service_ipc_adapter.cpp", "native/src/power_mode_module.cpp", "native/src/power_mode_policy.cpp", "native/src/power_save_mode.cpp", @@ -273,39 +359,6 @@ config("zidl_private_config") { include_dirs = [ "zidl/src/shutdown" ] } -ohos_shared_library("powermgr_stub") { - sources = [ - "zidl/src/power_mgr_async_reply.cpp", - "zidl/src/power_mgr_stub.cpp", - "zidl/src/power_mode_callback_stub.cpp", - "zidl/src/power_runninglock_callback_stub.cpp", - "zidl/src/power_state_callback_stub.cpp", - "zidl/src/screen_off_pre_callback_stub.cpp", - "zidl/src/shutdown/shutdown_stub_delegator.cpp", - "zidl/src/sync_sleep_callback_stub.cpp", - ] - - configs = [ - "${powermgr_utils_path}:utils_config", - "${powermgr_utils_path}:coverage_flags", - ":zidl_private_config", - ] - - public_configs = [ ":powermgr_public_config" ] - - deps = [ "${powermgr_inner_api}:powermgr_client" ] - - external_deps = [ - "c_utils:utils", - "hicollie:libhicollie", - "hilog:libhilog", - "ipc:ipc_core", - ] - - subsystem_name = "powermgr" - part_name = "${powermgr_part_name}" -} - group("service") { deps = [ ":powermgr_stub", diff --git a/services/IPowerMgr.idl b/services/IPowerMgr.idl new file mode 100644 index 00000000..d4e267b1 --- /dev/null +++ b/services/IPowerMgr.idl @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +sequenceable OHOS.IRemoteObject; +sequenceable RunningLockInfo..OHOS.PowerMgr.RunningLockInfo; +sequenceable RunningLockInfo..OHOS.PowerMgr.VectorPair; +interface OHOS.PowerMgr.IPowerStateCallback; +interface OHOS.PowerMgr.ISyncSleepCallback; +interface OHOS.PowerMgr.ISyncHibernateCallback; +interface OHOS.PowerMgr.IPowerModeCallback; +interface OHOS.PowerMgr.IScreenOffPreCallback; +interface OHOS.PowerMgr.ITakeOverShutdownCallback; +interface OHOS.PowerMgr.IAsyncShutdownCallback; +interface OHOS.PowerMgr.ISyncShutdownCallback; +interface OHOS.PowerMgr.IPowerRunninglockCallback; +interface OHOS.PowerMgr.IPowerMgrAsync; + +interface OHOS.PowerMgr.IPowerMgr { + void CreateRunningLockIpc([in] IRemoteObject remoteObj, [in] RunningLockInfo runningLockInfo, [out] int powerError); + void ReleaseRunningLockIpc([in] IRemoteObject remoteObj, [in] String name); + void IsRunningLockTypeSupportedIpc([in] int lockType, [out] boolean lockTypesSupported); + [oneway] void UpdateWorkSourceIpc([in] IRemoteObject remoteObj, [in] int[] workSources); + void LockIpc([in] IRemoteObject remoteObj, [in] int timeOutMs, [out] int powerError); + void UnLockIpc([in] IRemoteObject remoteObj, [in] String name, [out] int powerError); + void QueryRunningLockListsIpc([out] OrderedMap runningLockLists); + void IsUsedIpc([in] IRemoteObject remoteObj, [out] boolean isUsed); + void ProxyRunningLockIpc([in] boolean isProxied, [in] int pid, [in] int uid); + + void ProxyRunningLocksIpc([in] boolean isProxied, [in] VectorPair vectorPairInfos); + + void ResetRunningLocksIpc(); + + // Used for power state machine. + void RebootDeviceIpc([in] String reason, [out] int powerError); + void RebootDeviceForDeprecatedIpc([in] String reason, [out] int powerError); + void ShutDownDeviceIpc([in] String reason, [out] int powerError); + void SetSuspendTagIpc([in] String tag, [out] int powerError); + void SuspendDeviceIpc([in] long callTimeMs, [in] int reasonValue, [in] boolean suspendImmed, [in] String apiVersion, [out] int powerError); + void WakeupDeviceIpc([in] long callTimeMs, [in] int reasonValue, [in] String details, [in] String apiVersion, [out] int powerError); + [oneway] void WakeupDeviceAsyncIpc([in] long callTimeMs, [in] int reasonValue, [in] String details, [in] String apiVersion); + void RefreshActivityIpc([in] long callTimeMs, [in] int activityType, [in] boolean needChangeBacklight); + void OverrideScreenOffTimeIpc([in] long timeout, [in] String apiVersion, [out] int powerError); + void RestoreScreenOffTimeIpc([in] String apiVersion, [out] int powerError); + void GetStateIpc([out] int powerState); + void IsScreenOnIpc([in] boolean needPrintLog, [out] boolean isScreenOn); + void IsFoldScreenOnIpc([out] boolean screenOn); + void IsCollaborationScreenOnIpc([out] boolean collaborationScreenOn); + [oneway] void ForceSuspendDeviceIpc([in] long callTimeMs, [in] String apiVersion, [in] IPowerMgrAsync powerProxy); + void RegisterPowerStateCallbackIpc([in] IPowerStateCallback powerCallback, [in] boolean isSync); + void UnRegisterPowerStateCallbackIpc([in] IPowerStateCallback powerCallback); + + void RegisterSyncSleepCallbackIpc([in] ISyncSleepCallback powerCallback, [in] int priorityValue); + void UnRegisterSyncSleepCallbackIpc([in] ISyncSleepCallback powerCallback); + + void RegisterSyncHibernateCallbackIpc([in] ISyncHibernateCallback powerCallback); + void UnRegisterSyncHibernateCallbackIpc([in] ISyncHibernateCallback powerCallback); + + // Used for Callback registration upon power mode. + void RegisterPowerModeCallbackIpc([in] IPowerModeCallback powerCallback); + void UnRegisterPowerModeCallbackIpc([in] IPowerModeCallback powerCallback); + + void RegisterScreenStateCallbackIpc([in] int remainTime, [in] IScreenOffPreCallback powerCallback); + void UnRegisterScreenStateCallbackIpc([in] IScreenOffPreCallback powerCallback); + + void SetDisplaySuspendIpc([in] boolean enable); + [oneway] void HibernateIpc([in] boolean clearMemory, [in] String reason, [in] String apiVersion, [in] IPowerMgrAsync powerProxy); + void SetDeviceModeIpc([in] int modeValue, [out] int powerError); + void GetDeviceModeIpc([out] int powerMode); + void ShellDumpIpc([in] String[] args, [in] unsigned int argc, [out] String returnDump); + void IsStandbyIpc([out] boolean isStandby, [out] int powerError); + + void SetForceTimingOutIpc([in] boolean enabled, [in] IRemoteObject token, [out] int powerError); + void LockScreenAfterTimingOutIpc([in] boolean enabledLockScreen, [in] boolean checkLock, [in] boolean sendScreenOffEvent, + [in] IRemoteObject token, [out] int powerError); + + void RegisterShutdownCallbackIpc([in] ITakeOverShutdownCallback powerCallback, [in] int priorityValue); + void UnRegisterShutdownCallbackIpc([in] ITakeOverShutdownCallback powerCallback); + + void RegisterShutdownCallbackIpc([in] IAsyncShutdownCallback powerCallback, [in] int priorityValue); + void UnRegisterShutdownCallbackIpc([in] IAsyncShutdownCallback powerCallback); + void RegisterShutdownCallbackIpc([in] ISyncShutdownCallback powerCallback, [in] int priorityValue); + void UnRegisterShutdownCallbackIpc([in] ISyncShutdownCallback powerCallback); + + void RegisterRunningLockCallbackIpc([in] IPowerRunninglockCallback powerCallback); + void UnRegisterRunningLockCallbackIpc([in] IPowerRunninglockCallback powerCallback); + void IsRunningLockEnabledIpc([in] int lockType, [out] boolean lockEnabledResult, [out] int powerError); +} \ No newline at end of file diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index 0741f57d..65652cac 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -27,6 +27,7 @@ #include "ffrt_utils.h" #include "ipower_mgr.h" #include "power_mgr_notify.h" +#include "power_mgr_service_ipc_adapter.h" #include "power_mgr_stub.h" #include "power_mode_module.h" #include "power_save_mode.h" @@ -53,7 +54,7 @@ enum class PowerConnectStatus : int32_t { #endif class RunningLockMgr; -class PowerMgrService final : public SystemAbility, public PowerMgrStub { +class PowerMgrService final : public SystemAbility, public PowerMgrServiceAdapter { DECLARE_SYSTEM_ABILITY(PowerMgrService) DECLARE_DELAYED_SP_SINGLETON(PowerMgrService); diff --git a/interfaces/inner_api/native/include/ipower_mgr.h b/services/native/include/power_mgr_service_ipc_adapter.h similarity index 40% rename from interfaces/inner_api/native/include/ipower_mgr.h rename to services/native/include/power_mgr_service_ipc_adapter.h index 15618948..9e5ee8bb 100644 --- a/interfaces/inner_api/native/include/ipower_mgr.h +++ b/services/native/include/power_mgr_service_ipc_adapter.h @@ -1,120 +1,171 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POWERMGR_IPOWER_MANAGER_H -#define POWERMGR_IPOWER_MANAGER_H - -#include -#include -#include - -#include -#include - -#include "ipower_mode_callback.h" -#include "ipower_runninglock_callback.h" -#include "ipower_state_callback.h" -#include "iscreen_off_pre_callback.h" -#include "power_errors.h" -#include "power_state_machine_info.h" -#include "running_lock_info.h" -#include "shutdown/ishutdown_client.h" -#include "suspend/isync_sleep_callback.h" -#include "hibernate/isync_hibernate_callback.h" - -namespace OHOS { -namespace PowerMgr { -class IPowerMgr : public IShutdownClient, public IRemoteBroker { -public: - virtual PowerErrors CreateRunningLock(const sptr& remoteObj, - const RunningLockInfo& runningLockInfo) = 0; - virtual bool ReleaseRunningLock(const sptr& remoteObj, const std::string& name = "") = 0; - virtual bool IsRunningLockTypeSupported(RunningLockType type) = 0; - virtual bool UpdateWorkSource(const sptr& remoteObj, - const std::vector& workSources) = 0; - virtual PowerErrors Lock(const sptr& remoteObj, int32_t timeOutMs = -1) = 0; - virtual PowerErrors UnLock(const sptr& remoteObj, const std::string& name = "") = 0; - virtual bool QueryRunningLockLists(std::map& runningLockLists) = 0; - virtual bool IsUsed(const sptr& remoteObj) = 0; - virtual bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) = 0; - virtual bool ProxyRunningLocks(bool isProxied, const std::vector>& processInfos) = 0; - virtual bool ResetRunningLocks() = 0; - - // Used for power state machine. - virtual PowerErrors RebootDevice(const std::string& reason) = 0; - virtual PowerErrors RebootDeviceForDeprecated(const std::string& reason) = 0; - virtual PowerErrors ShutDownDevice(const std::string& reason) = 0; - virtual PowerErrors SetSuspendTag(const std::string& tag) = 0; - virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, - bool suspendImmed, const std::string& apiVersion) = 0; - virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, - const std::string& details, const std::string& apiVersion) = 0; - virtual void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) = 0; - virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) = 0; - virtual PowerErrors OverrideScreenOffTime(int64_t timeout, const std::string& apiVersion) = 0; - virtual PowerErrors RestoreScreenOffTime(const std::string& apiVersion) = 0; - virtual PowerState GetState() = 0; - virtual bool IsScreenOn(bool needPrintLog = true) = 0; - virtual bool IsFoldScreenOn() = 0; - virtual bool IsCollaborationScreenOn() = 0; - virtual PowerErrors ForceSuspendDevice(int64_t callTimeMs, const std::string& apiVersion) = 0; - virtual bool RegisterPowerStateCallback(const sptr& callback, bool isSync = true) = 0; - virtual bool UnRegisterPowerStateCallback(const sptr& callback) = 0; - - virtual bool RegisterSyncSleepCallback(const sptr& callback, - SleepPriority priority = SleepPriority::DEFAULT) = 0; - virtual bool UnRegisterSyncSleepCallback(const sptr& callback) = 0; - - virtual bool RegisterSyncHibernateCallback(const sptr& callback) = 0; - virtual bool UnRegisterSyncHibernateCallback(const sptr& callback) = 0; - - // Used for callback registration upon power mode. - virtual bool RegisterPowerModeCallback(const sptr& callback) = 0; - virtual bool UnRegisterPowerModeCallback(const sptr& callback) = 0; - - virtual bool RegisterScreenStateCallback(int32_t remainTime, const sptr& callback) = 0; - virtual bool UnRegisterScreenStateCallback(const sptr& callback) = 0; - - virtual bool SetDisplaySuspend(bool enable) = 0; - virtual PowerErrors Hibernate(bool clearMemory, const std::string& reason, const std::string& apiVersion) = 0; - virtual PowerErrors SetDeviceMode(const PowerMode& mode) = 0; - virtual PowerMode GetDeviceMode() = 0; - virtual std::string ShellDump(const std::vector& args, uint32_t argc) = 0; - virtual PowerErrors IsStandby(bool& isStandby) = 0; - - virtual PowerErrors SetForceTimingOut(bool enabled, const sptr& token) = 0; - virtual PowerErrors LockScreenAfterTimingOut( - bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, const sptr& token) = 0; - - virtual void RegisterShutdownCallback( - const sptr& callback, ShutdownPriority priority) = 0; - virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; - - virtual void RegisterShutdownCallback( - const sptr& callback, ShutdownPriority priority) = 0; - virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; - virtual void RegisterShutdownCallback( - const sptr& callback, ShutdownPriority priority) = 0; - virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; - - virtual bool RegisterRunningLockCallback(const sptr& callback) = 0; - virtual bool UnRegisterRunningLockCallback(const sptr& callback) = 0; - virtual PowerErrors IsRunningLockEnabled(const RunningLockType type, bool& result) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.IPowerMgr"); -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_IPOWER_MANAGER_H +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef POWERMGR_POWER_MGR_SERVICE_ADAPTER_H +#define POWERMGR_POWER_MGR_SERVICE_ADAPTER_H + +#include +#include "ipower_mgr.h" +#include "power_mgr_stub.h" + +namespace OHOS { +namespace PowerMgr { + +class PowerMgrServiceAdapter : public PowerMgrStub { +public: + virtual int32_t RebootDeviceIpc(const std::string& reason, int32_t& powerError) override; + virtual int32_t RebootDeviceForDeprecatedIpc(const std::string& reason, int32_t& powerError) override; + virtual int32_t ShutDownDeviceIpc(const std::string& reason, int32_t& powerError) override; + virtual int32_t SetSuspendTagIpc(const std::string& tag, int32_t& powerError) override; + virtual int32_t SuspendDeviceIpc(int64_t callTimeMs, int32_t reasonValue, bool suspendImmed, + const std::string& apiVersion, int32_t& powerError) override; + virtual int32_t WakeupDeviceIpc(int64_t callTimeMs, int32_t reasonValue, const std::string& details, + const std::string& apiVersion, int32_t& powerError) override; + virtual int32_t WakeupDeviceAsyncIpc(int64_t callTimeMs, int32_t reasonValue, const std::string& details, + const std::string& apiVersion) override; + virtual int32_t RefreshActivityIpc(int64_t callTimeMs, int32_t activityType, bool needChangeBacklight) override; + virtual int32_t OverrideScreenOffTimeIpc( + int64_t timeout, const std::string& apiVersion, int32_t& powerError) override; + virtual int32_t RestoreScreenOffTimeIpc(const std::string& apiVersion, int32_t& powerError) override; + virtual int32_t GetStateIpc(int32_t& powerState) override; + virtual int32_t IsScreenOnIpc(bool needPrintLog, bool& isScreenOn) override; + virtual int32_t IsFoldScreenOnIpc(bool& isFoldScreenOn) override; + virtual int32_t IsCollaborationScreenOnIpc(bool& isCollaborationScreenOn) override; + virtual int32_t ForceSuspendDeviceIpc( + int64_t callTimeMs, const std::string& apiVersion, const sptr& powerProxy) override; + virtual int32_t HibernateIpc(bool clearMemory, const std::string& reason, + const std::string& apiVersion, const sptr& powerProxy) override; + virtual int32_t CreateRunningLockIpc( + const sptr& remoteObj, const RunningLockInfo& runningLockInfo, int32_t& powerError) override; + virtual int32_t ReleaseRunningLockIpc(const sptr& remoteObj, const std::string& name = "") override; + virtual int32_t IsRunningLockTypeSupportedIpc(int32_t lockType, bool& lockSupported) override; + virtual int32_t UpdateWorkSourceIpc(const sptr& remoteObj, + const std::vector& workSources) override; + virtual int32_t LockIpc(const sptr& remoteObj, int32_t timeOutMs, int32_t& powerError) override; + virtual int32_t UnLockIpc( + const sptr& remoteObj, const std::string& name, int32_t& powerError) override; + virtual int32_t QueryRunningLockListsIpc(std::map& runningLockLists) override; + virtual int32_t IsUsedIpc(const sptr& remoteObj, bool& isUsed) override; + virtual int32_t ProxyRunningLockIpc(bool isProxied, pid_t pid, pid_t uid) override; + virtual int32_t ProxyRunningLocksIpc(bool isProxied, const VectorPair& vectorPairInfos) override; + virtual int32_t ResetRunningLocksIpc() override; + virtual int32_t RegisterPowerStateCallbackIpc(const sptr& callback, bool isSync) override; + virtual int32_t UnRegisterPowerStateCallbackIpc(const sptr& callback) override; + + virtual int32_t RegisterSyncSleepCallbackIpc( + const sptr& callback, int32_t priorityValue) override; + virtual int32_t UnRegisterSyncSleepCallbackIpc(const sptr& callback) override; + virtual int32_t RegisterSyncHibernateCallbackIpc(const sptr& callback) override; + virtual int32_t UnRegisterSyncHibernateCallbackIpc(const sptr& callback) override; + + virtual int32_t RegisterPowerModeCallbackIpc(const sptr& callback) override; + virtual int32_t UnRegisterPowerModeCallbackIpc(const sptr& callback) override; + + virtual int32_t RegisterScreenStateCallbackIpc( + int32_t remainTime, const sptr& callback) override; + virtual int32_t UnRegisterScreenStateCallbackIpc(const sptr& callback) override; + + virtual int32_t RegisterRunningLockCallbackIpc(const sptr& callback) override; + virtual int32_t UnRegisterRunningLockCallbackIpc(const sptr& callback) override; + virtual int32_t SetDisplaySuspendIpc(bool enable) override; + virtual int32_t SetDeviceModeIpc(int32_t modeValue, int32_t& powerError) override; + virtual int32_t GetDeviceModeIpc(int32_t& powerMode) override; + virtual int32_t ShellDumpIpc(const std::vector& args, uint32_t argc, std::string& returnDump) override; + virtual int32_t IsStandbyIpc(bool& isStandby, int32_t& powerError) override; + virtual int32_t SetForceTimingOutIpc(bool enabled, const sptr& token, int32_t& powerError) override; + virtual int32_t LockScreenAfterTimingOutIpc(bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, + const sptr& token, int32_t& powerError) override; + virtual int32_t IsRunningLockEnabledIpc(int32_t lockType, bool& result, int32_t& powerError) override; + + int32_t RegisterShutdownCallbackIpc( + const sptr& callback, int32_t priorityValue) override; + int32_t UnRegisterShutdownCallbackIpc(const sptr& callback) override; + + int32_t RegisterShutdownCallbackIpc(const sptr& callback, int32_t priorityValue) override; + int32_t UnRegisterShutdownCallbackIpc(const sptr& callback) override; + int32_t RegisterShutdownCallbackIpc(const sptr& callback, int32_t priorityValue) override; + int32_t UnRegisterShutdownCallbackIpc(const sptr& callback) override; + + virtual PowerErrors RebootDevice(const std::string& reason) = 0; + virtual PowerErrors RebootDeviceForDeprecated(const std::string& reason) = 0; + virtual PowerErrors ShutDownDevice(const std::string& reason) = 0; + virtual PowerErrors SetSuspendTag(const std::string& tag) = 0; + virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, + bool suspendImmed, const std::string& apiVersion = "-1") = 0; + virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, + const std::string& details, const std::string& apiVersion = "-1") = 0; + virtual void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) = 0; + virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) = 0; + virtual PowerErrors OverrideScreenOffTime(int64_t timeout, const std::string& apiVersion = "-1") = 0; + virtual PowerErrors RestoreScreenOffTime(const std::string& apiVersion = "-1") = 0; + virtual PowerState GetState() = 0; + virtual bool IsScreenOn(bool needPrintLog = true) = 0; + virtual bool IsFoldScreenOn() = 0; + virtual bool IsCollaborationScreenOn() = 0; + virtual PowerErrors ForceSuspendDevice(int64_t callTimeMs, const std::string& apiVersion = "-1") = 0; + virtual PowerErrors Hibernate( + bool clearMemory, const std::string& reason = "", const std::string& apiVersion = "-1") = 0; + virtual PowerErrors CreateRunningLock( + const sptr& remoteObj, const RunningLockInfo& runningLockInfo) = 0; + virtual bool ReleaseRunningLock(const sptr& remoteObj, const std::string& name = "") = 0; + virtual bool IsRunningLockTypeSupported(RunningLockType type) = 0; + virtual bool UpdateWorkSource(const sptr& remoteObj, + const std::vector& workSources) = 0; + virtual PowerErrors Lock(const sptr& remoteObj, int32_t timeOutMs = -1) = 0; + virtual PowerErrors UnLock(const sptr& remoteObj, const std::string& name = "") = 0; + virtual bool QueryRunningLockLists(std::map& runningLockLists) = 0; + virtual bool IsUsed(const sptr& remoteObj) = 0; + virtual bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) = 0; + virtual bool ProxyRunningLocks(bool isProxied, + const std::vector>& processInfos) = 0; + virtual bool ResetRunningLocks() = 0; + virtual bool RegisterPowerStateCallback(const sptr& callback, bool isSync = true) = 0; + virtual bool UnRegisterPowerStateCallback(const sptr& callback) = 0; + + virtual bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) = 0; + virtual bool UnRegisterSyncSleepCallback(const sptr& callback) = 0; + virtual bool RegisterSyncHibernateCallback(const sptr& callback) = 0; + virtual bool UnRegisterSyncHibernateCallback(const sptr& callback) = 0; + + virtual bool RegisterPowerModeCallback(const sptr& callback) = 0; + virtual bool UnRegisterPowerModeCallback(const sptr& callback) = 0; + + virtual bool RegisterScreenStateCallback(int32_t remainTime, const sptr& callback) = 0; + virtual bool UnRegisterScreenStateCallback(const sptr& callback) = 0; + + virtual bool RegisterRunningLockCallback(const sptr& callback) = 0; + virtual bool UnRegisterRunningLockCallback(const sptr& callback) = 0; + virtual bool SetDisplaySuspend(bool enable) = 0; + virtual PowerErrors SetDeviceMode(const PowerMode& mode) = 0; + virtual PowerMode GetDeviceMode() = 0; + virtual std::string ShellDump(const std::vector& args, uint32_t argc) = 0; + virtual PowerErrors IsStandby(bool& isStandby) = 0; + virtual PowerErrors SetForceTimingOut(bool enabled, const sptr& token) = 0; + virtual PowerErrors LockScreenAfterTimingOut( + bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, const sptr& token) = 0; + virtual PowerErrors IsRunningLockEnabled(const RunningLockType type, bool& result) = 0; + + virtual void RegisterShutdownCallback( + const sptr& callback, ShutdownPriority priority) = 0; + virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; + + virtual void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) = 0; + virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; + virtual void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) = 0; + virtual void UnRegisterShutdownCallback(const sptr& callback) = 0; +}; +} // namespace PowerMgr +} // namespace OHOS +#endif // POWERMGR_POWER_MGR_SERVICE_ADAPTER_H \ No newline at end of file diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index f5b3c563..02f9229d 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -131,7 +131,7 @@ void PowerMgrService::OnStart() PowerExtIntfWrapper::Instance().Init(); g_moduleMgr = ModuleMgrScan(POWER_PLUGIN_AUTORUN_PATH); #endif - + if (!Publish(DelayedSpSingleton::GetInstance())) { POWER_HILOGE(COMP_SVC, "Register to system ability manager failed"); return; @@ -1066,7 +1066,7 @@ PowerErrors PowerMgrService::SuspendDevice( return PowerErrors::ERR_FAILURE; } #endif - + if (shutdownController_->IsShuttingDown()) { POWER_HILOGW(FEATURE_SUSPEND, "System is shutting down, can't suspend"); return PowerErrors::ERR_OK; @@ -1314,7 +1314,6 @@ RunningLockParam PowerMgrService::FillRunningLockParam(const RunningLockInfo& in PowerErrors PowerMgrService::CreateRunningLock( const sptr& remoteObj, const RunningLockInfo& runningLockInfo) { - PowerXCollie powerXCollie("PowerMgrService::CreateRunningLock", true); std::lock_guard lock(lockMutex_); if (!Permission::IsPermissionGranted("ohos.permission.RUNNING_LOCK")) { return PowerErrors::ERR_PERMISSION_DENIED; @@ -1335,7 +1334,6 @@ PowerErrors PowerMgrService::CreateRunningLock( bool PowerMgrService::ReleaseRunningLock(const sptr& remoteObj, const std::string& name) { - PowerXCollie powerXCollie("PowerMgrService::ReleaseRunningLock", true); std::lock_guard lock(lockMutex_); bool result = false; if (!Permission::IsPermissionGranted("ohos.permission.RUNNING_LOCK")) { @@ -1370,7 +1368,6 @@ bool PowerMgrService::IsRunningLockTypeSupported(RunningLockType type) bool PowerMgrService::UpdateWorkSource(const sptr& remoteObj, const std::vector& workSources) { - PowerXCollie powerXCollie("PowerMgrService::UpdateWorkSource", true); if (!Permission::IsPermissionGranted("ohos.permission.RUNNING_LOCK")) { return false; } @@ -1392,7 +1389,6 @@ PowerErrors PowerMgrService::Lock(const sptr& remoteObj, int32_t pid_t pid = IPCSkeleton::GetCallingPid(); auto uid = IPCSkeleton::GetCallingUid(); #endif - PowerXCollie powerXCollie("PowerMgrService::Lock", true); if (!Permission::IsPermissionGranted("ohos.permission.RUNNING_LOCK")) { return PowerErrors::ERR_PERMISSION_DENIED; } @@ -1428,7 +1424,6 @@ PowerErrors PowerMgrService::UnLock(const sptr& remoteObj, const pid_t pid = IPCSkeleton::GetCallingPid(); auto uid = IPCSkeleton::GetCallingUid(); #endif - PowerXCollie powerXCollie("PowerMgrService::UnLock", true); if (!Permission::IsPermissionGranted("ohos.permission.RUNNING_LOCK")) { return PowerErrors::ERR_PERMISSION_DENIED; } @@ -1450,7 +1445,6 @@ PowerErrors PowerMgrService::UnLock(const sptr& remoteObj, const bool PowerMgrService::QueryRunningLockLists(std::map& runningLockLists) { - PowerXCollie powerXCollie("PowerMgrService::QueryRunningLockLists", true); std::lock_guard lock(lockMutex_); if (!Permission::IsPermissionGranted("ohos.permission.RUNNING_LOCK")) { return false; @@ -1500,7 +1494,6 @@ void PowerMgrService::ForceUnLock(const sptr& remoteObj) bool PowerMgrService::IsUsed(const sptr& remoteObj) { - PowerXCollie powerXCollie("PowerMgrService::IsUsed", true); std::lock_guard lock(lockMutex_); auto isUsed = runningLockMgr_->IsUsed(remoteObj); POWER_HILOGD(FEATURE_RUNNING_LOCK, "RunningLock is Used: %{public}d", isUsed); @@ -1509,7 +1502,6 @@ bool PowerMgrService::IsUsed(const sptr& remoteObj) bool PowerMgrService::ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) { - PowerXCollie powerXCollie("PowerMgrService::ProxyRunningLock", true); std::lock_guard lock(lockMutex_); if (!Permission::IsSystem()) { return false; @@ -1519,7 +1511,6 @@ bool PowerMgrService::ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) bool PowerMgrService::ProxyRunningLocks(bool isProxied, const std::vector>& processInfos) { - PowerXCollie powerXCollie("PowerMgrService::ProxyRunningLocks", true); if (!Permission::IsSystem()) { return false; } @@ -1530,7 +1521,6 @@ bool PowerMgrService::ProxyRunningLocks(bool isProxied, const std::vector(RebootDevice(reason)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RebootDeviceForDeprecatedIpc(const std::string& reason, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RebootDeviceForDeprecated", false); + powerError = static_cast(RebootDeviceForDeprecated(reason)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::ShutDownDeviceIpc(const std::string& reason, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::ShutDownDevice", false); + powerError = static_cast(ShutDownDevice(reason)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::SetSuspendTagIpc(const std::string& tag, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::SetSuspendTag", false); + powerError = static_cast(SetSuspendTag(tag)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::SuspendDeviceIpc(int64_t callTimeMs, int32_t reasonValue, bool suspendImmed, + const std::string& apiVersion, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::SuspendDevice", false); + SuspendDeviceType reason = static_cast(reasonValue); + powerError = static_cast(SuspendDevice(callTimeMs, reason, suspendImmed, apiVersion)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::WakeupDeviceIpc(int64_t callTimeMs, int32_t reasonValue, + const std::string& details, const std::string& apiVersion, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::WakeupDevice", false); + WakeupDeviceType reason = static_cast(reasonValue); + powerError = static_cast(WakeupDevice(callTimeMs, reason, details, apiVersion)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::WakeupDeviceAsyncIpc( + int64_t callTimeMs, int32_t reasonValue, const std::string& details, const std::string& apiVersion) +{ + WakeupDeviceType reason = static_cast(reasonValue); + return static_cast(WakeupDevice(callTimeMs, reason, details, apiVersion)); +} + +int32_t PowerMgrServiceAdapter::RefreshActivityIpc(int64_t callTimeMs, int32_t activityType, bool needChangeBacklight) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RefreshActivity", false); + UserActivityType type = static_cast(activityType); + RefreshActivity(callTimeMs, type, needChangeBacklight); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::OverrideScreenOffTimeIpc( + int64_t timeout, const std::string& apiVersion, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::OverrideScreenOffTime", false); + powerError = static_cast(OverrideScreenOffTime(timeout, apiVersion)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RestoreScreenOffTimeIpc(const std::string& apiVersion, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RestoreScreenOffTime", false); + powerError = static_cast(RestoreScreenOffTime(apiVersion)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::GetStateIpc(int32_t& powerState) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::GetState", false); + powerState = static_cast(GetState()); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::IsScreenOnIpc(bool needPrintLog, bool& isScreenOn) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::IsScreenOn", false); + isScreenOn = IsScreenOn(needPrintLog); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::IsFoldScreenOnIpc(bool& isFoldScreenOn) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::IsFoldScreenOn", false); + isFoldScreenOn = IsFoldScreenOn(); + return ERR_OK; +} + + +int32_t PowerMgrServiceAdapter::IsCollaborationScreenOnIpc(bool& isCollaborationScreenOn) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::IsCollaborationScreenOn", false); + isCollaborationScreenOn = IsCollaborationScreenOn(); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::ForceSuspendDeviceIpc( + int64_t callTimeMs, const std::string& apiVersion, const sptr& powerProxy) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::ForceSuspendDevice", false); + int32_t result = static_cast(ForceSuspendDevice(callTimeMs, apiVersion)); + if (powerProxy != nullptr) { + powerProxy->SendAsyncReply(result); + } + return result; +} + +int32_t PowerMgrServiceAdapter::HibernateIpc(bool clearMemory, const std::string& reason, + const std::string& apiVersion, const sptr& powerProxy) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::Hibernate", false); + int32_t result = static_cast(Hibernate(clearMemory, reason, apiVersion)); + if (powerProxy != nullptr) { + powerProxy->SendAsyncReply(result); + } + return result; +} + +int32_t PowerMgrServiceAdapter::CreateRunningLockIpc( + const sptr& remoteObj, const RunningLockInfo& runningLockInfo, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::CreateRunningLock", true); + powerError = static_cast(CreateRunningLock(remoteObj, runningLockInfo)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::ReleaseRunningLockIpc(const sptr& remoteObj, const std::string& name) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::ReleaseRunningLock", true); + ReleaseRunningLock(remoteObj, name); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::IsRunningLockTypeSupportedIpc(int32_t lockType, bool& lockSupported) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::IsRunningLockTypeSupported", false); + RunningLockType type = static_cast(lockType); + lockSupported = IsRunningLockTypeSupported(type); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UpdateWorkSourceIpc( + const sptr& remoteObj, const std::vector& workSources) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UpdateWorkSource", true); + UpdateWorkSource(remoteObj, workSources); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::LockIpc(const sptr& remoteObj, int32_t timeOutMs, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::Lock", true); + powerError = static_cast(Lock(remoteObj, timeOutMs)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnLockIpc( + const sptr& remoteObj, const std::string& name, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnLock", true); + powerError = static_cast(UnLock(remoteObj, name)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::QueryRunningLockListsIpc(std::map& runningLockLists) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::QueryRunningLockLists", true); + QueryRunningLockLists(runningLockLists); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterRunningLockCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterRunningLockCallback", false); + RegisterRunningLockCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterRunningLockCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterRunningLockCallback", false); + UnRegisterRunningLockCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::IsUsedIpc(const sptr& remoteObj, bool& isUsed) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::IsUsed", true); + isUsed = IsUsed(remoteObj); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::ProxyRunningLockIpc(bool isProxied, pid_t pid, pid_t uid) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::ProxyRunningLock", true); + if (!ProxyRunningLock(isProxied, pid, uid)) { + POWER_HILOGI(FEATURE_SUSPEND, "ProxyRunningLock failed"); + return INIT_VALUE; + } + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::ProxyRunningLocksIpc(bool isProxied, const VectorPair& vectorPairInfos) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::ProxyRunningLocks", true); + const std::vector>& processInfos = vectorPairInfos.processInfos; + if (!ProxyRunningLocks(isProxied, processInfos)) { + POWER_HILOGI(FEATURE_SUSPEND, "ProxyRunningLocks failed"); + return INIT_VALUE; + } + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::ResetRunningLocksIpc() +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::ResetRunningLocks", true); + if (!ResetRunningLocks()) { + POWER_HILOGI(FEATURE_SUSPEND, "ResetRunningLocks failed"); + return INIT_VALUE; + } + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterPowerStateCallbackIpc(const sptr& callback, bool isSync) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterPowerStateCallback", false); + RegisterPowerStateCallback(callback, isSync); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterPowerStateCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterPowerStateCallback", false); + UnRegisterPowerStateCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterSyncSleepCallbackIpc( + const sptr& callback, int32_t priorityValue) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterSyncSleepCallback", false); + SleepPriority priority = static_cast(priorityValue); + RegisterSyncSleepCallback(callback, priority); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterSyncSleepCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterSyncSleepCallback", false); + UnRegisterSyncSleepCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterSyncHibernateCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterSyncHibernateCallback", false); + RegisterSyncHibernateCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterSyncHibernateCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterSyncHibernateCallback", false); + UnRegisterSyncHibernateCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterPowerModeCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterPowerModeCallback", false); + RegisterPowerModeCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterPowerModeCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterPowerModeCallback", false); + UnRegisterPowerModeCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterScreenStateCallbackIpc( + int32_t remainTime, const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterScreenStateCallback", false); + RegisterScreenStateCallback(remainTime, callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterScreenStateCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterScreenStateCallback", false); + UnRegisterScreenStateCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::SetDisplaySuspendIpc(bool enable) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::SetDisplaySuspend", false); + SetDisplaySuspend(enable); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::SetDeviceModeIpc(int32_t modeValue, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::SetDeviceMode", false); + PowerMode mode = static_cast(modeValue); + powerError = static_cast(SetDeviceMode(mode)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::GetDeviceModeIpc(int32_t& powerMode) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::GetDeviceMode", false); + powerMode = static_cast(GetDeviceMode()); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::ShellDumpIpc( + const std::vector& args, uint32_t argc, std::string& returnDump) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::ShellDump", false); + returnDump = ShellDump(args, argc); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterShutdownCallbackIpc( + const sptr& callback, int32_t priorityValue) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterShutdownCallback TakeOver", false); + ShutdownPriority priority = static_cast(priorityValue); + RegisterShutdownCallback(callback, priority); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterShutdownCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterShutdownCallback TakeOver", false); + UnRegisterShutdownCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterShutdownCallbackIpc( + const sptr& callback, int32_t priorityValue) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterShutdownCallback Async", false); + ShutdownPriority priority = static_cast(priorityValue); + RegisterShutdownCallback(callback, priority); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterShutdownCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterShutdownCallback Async", false); + UnRegisterShutdownCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::RegisterShutdownCallbackIpc( + const sptr& callback, int32_t priorityValue) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::RegisterShutdownCallback Sync", false); + ShutdownPriority priority = static_cast(priorityValue); + RegisterShutdownCallback(callback, priority); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::UnRegisterShutdownCallbackIpc(const sptr& callback) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::UnRegisterShutdownCallback Sync", false); + UnRegisterShutdownCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::IsStandbyIpc(bool& isStandby, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::IsStandby", false); + powerError = static_cast(IsStandby(isStandby)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::SetForceTimingOutIpc( + bool enabled, const sptr& token, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::SetForceTimingOut", false); + powerError = static_cast(SetForceTimingOut(enabled, token)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::LockScreenAfterTimingOutIpc(bool enabledLockScreen, bool checkLock, + bool sendScreenOffEvent, const sptr& token, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::LockScreenAfterTimingOut", false); + powerError = static_cast( + LockScreenAfterTimingOut(enabledLockScreen, checkLock, sendScreenOffEvent, token)); + return ERR_OK; +} + +int32_t PowerMgrServiceAdapter::IsRunningLockEnabledIpc(int32_t lockType, bool& result, int32_t& powerError) +{ + PowerXCollie powerXCollie("PowerMgrServiceAdapter::IsRunningLockEnabled", false); + RunningLockType type = static_cast(lockType); + powerError = static_cast(IsRunningLockEnabled(type, result)); + return ERR_OK; +} +} // namespace PowerMgr +} // namespace OHOS diff --git a/services/zidl/include/ipower_mgr_async.h b/services/zidl/include/ipower_mgr_async.h new file mode 100644 index 00000000..521ed889 --- /dev/null +++ b/services/zidl/include/ipower_mgr_async.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef POWERMGR_SERVICES_ASYNC_H +#define POWERMGR_SERVICES_ASYNC_H + +#include "power_mgr_async_reply.h" + +#endif // POWERMGR_SERVICES_ASYNC_H diff --git a/services/zidl/include/power_mgr_async_reply.h b/services/zidl/include/power_mgr_async_reply.h index 7ab22027..5221fb29 100644 --- a/services/zidl/include/power_mgr_async_reply.h +++ b/services/zidl/include/power_mgr_async_reply.h @@ -20,8 +20,6 @@ #include #include #include "iremote_broker.h" -#include "iremote_stub.h" -#include "iremote_proxy.h" namespace OHOS { namespace PowerMgr { @@ -35,32 +33,6 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.IPowerMgrAsync"); }; -class PowerMgrStubAsync : public IRemoteStub { -public: - DISALLOW_COPY_AND_MOVE(PowerMgrStubAsync); - PowerMgrStubAsync() = default; - ~PowerMgrStubAsync() override = default; - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - void SendAsyncReply(int reply) override; - int WaitForAsyncReply(int timeout); -private: - std::mutex mutex_; - std::condition_variable cv_; - int asyncReply_ = { 0 }; - bool notified {false}; -}; - -class PowerMgrProxyAsync : public IRemoteProxy { -public: - explicit PowerMgrProxyAsync(const sptr& impl) - : IRemoteProxy(impl) {} - ~PowerMgrProxyAsync() = default; - DISALLOW_COPY_AND_MOVE(PowerMgrProxyAsync); - - void SendAsyncReply(int reply) override; -private: - static inline BrokerDelegator delegator_; -}; } // namespace PowerMgr } // namespace OHOS -#endif // POWERMGR_SERVICES_ASYNC_REPLY_H \ No newline at end of file +#endif // POWERMGR_SERVICES_ASYNC_REPLY_H diff --git a/services/zidl/src/shutdown/shutdown_stub_delegator.h b/services/zidl/include/power_mgr_async_reply_proxy.h similarity index 41% rename from services/zidl/src/shutdown/shutdown_stub_delegator.h rename to services/zidl/include/power_mgr_async_reply_proxy.h index 493695e1..25d4fa27 100644 --- a/services/zidl/src/shutdown/shutdown_stub_delegator.h +++ b/services/zidl/include/power_mgr_async_reply_proxy.h @@ -1,43 +1,38 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POWERMGR_POWER_MANAGER_SHUTDOWN_STUB_DELEGATOR_H -#define POWERMGR_POWER_MANAGER_SHUTDOWN_STUB_DELEGATOR_H - -#include "power_mgr_stub.h" - -namespace OHOS { -namespace PowerMgr { -class ShutdownStubDelegator { -public: - explicit ShutdownStubDelegator(IRemoteStub& stub) : stub_(stub) {} - int32_t HandleRemoteRequest(uint32_t code, MessageParcel& data, [[maybe_unused]] MessageParcel& reply, - [[maybe_unused]] MessageOption& option); - -private: - int32_t RegisterTakeOverShutdownCallback(MessageParcel& data); - int32_t UnRegisterTakeOverShutdownCallback(MessageParcel& data); - - int32_t RegisterAsyncShutdownCallback(MessageParcel& data); - int32_t UnRegisterAsyncShutdownCallback(MessageParcel& data); - int32_t RegisterSyncShutdownCallback(MessageParcel& data); - int32_t UnRegisterSyncShutdownCallback(MessageParcel& data); - - IRemoteStub& stub_; -}; -} // namespace PowerMgr -} // namespace OHOS - -#endif // POWERMGR_POWER_MANAGER_SHUTDOWN_STUB_DELEGATOR_H +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef POWERMGR_SERVICES_ASYNC_REPLY_PROXY_H +#define POWERMGR_SERVICES_ASYNC_REPLY_PROXY_H + +#include +#include "power_mgr_async_reply.h" + +namespace OHOS { +namespace PowerMgr { + +class PowerMgrProxyAsync : public IRemoteProxy { +public: + explicit PowerMgrProxyAsync(const sptr& impl) + : IRemoteProxy(impl) {} + ~PowerMgrProxyAsync() = default; + DISALLOW_COPY_AND_MOVE(PowerMgrProxyAsync); + + void SendAsyncReply(int reply) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace PowerMgr +} // namespace OHOS +#endif // POWERMGR_SERVICES_ASYNC_REPLY_PROXY_H diff --git a/services/zidl/src/shutdown/shutdown_proxy_delegator.h b/services/zidl/include/power_mgr_async_reply_stub.h similarity index 36% rename from services/zidl/src/shutdown/shutdown_proxy_delegator.h rename to services/zidl/include/power_mgr_async_reply_stub.h index 7d125d43..2684d2ec 100644 --- a/services/zidl/src/shutdown/shutdown_proxy_delegator.h +++ b/services/zidl/include/power_mgr_async_reply_stub.h @@ -1,49 +1,41 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POWERMGR_POWER_MANAGER_SHUTDOWN_PROXY_H -#define POWERMGR_POWER_MANAGER_SHUTDOWN_PROXY_H - -#include - -#include "ipower_mgr.h" -#include "iremote_object.h" - -namespace OHOS { -namespace PowerMgr { -class ShutdownProxyDelegator { -public: - ShutdownProxyDelegator(const sptr& remote, std::u16string descriptor) - : remote_(remote), descriptor_(std::move(descriptor)) - { - } - virtual ~ShutdownProxyDelegator() = default; - - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority); - void UnRegisterShutdownCallback(const sptr& callback); - - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority); - void UnRegisterShutdownCallback(const sptr& callback); - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority); - void UnRegisterShutdownCallback(const sptr& callback); - -private: - sptr remote_; - std::u16string descriptor_; -}; -} // namespace PowerMgr -} // namespace OHOS - -#endif // POWERMGR_POWER_MANAGER_SHUTDOWN_PROXY_H +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef POWERMGR_SERVICES_ASYNC_REPLY_STUB_H +#define POWERMGR_SERVICES_ASYNC_REPLY_STUB_H + +#include +#include "power_mgr_async_reply.h" + +namespace OHOS { +namespace PowerMgr { + +class PowerMgrStubAsync : public IRemoteStub { +public: + DISALLOW_COPY_AND_MOVE(PowerMgrStubAsync); + PowerMgrStubAsync() = default; + ~PowerMgrStubAsync() override = default; + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + void SendAsyncReply(int reply) override; + int WaitForAsyncReply(int timeout); +private: + std::mutex mutex_; + std::condition_variable cv_; + int asyncReply_ = { 0 }; + bool notified {false}; +}; +} // namespace PowerMgr +} // namespace OHOS +#endif // POWERMGR_SERVICES_ASYNC_REPLY_STUB_H diff --git a/services/zidl/include/power_mgr_proxy.h b/services/zidl/include/power_mgr_proxy.h deleted file mode 100644 index eef8d4e5..00000000 --- a/services/zidl/include/power_mgr_proxy.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POWERMGR_SERVICES_IPOWER_MANAGER_PROXY_H -#define POWERMGR_SERVICES_IPOWER_MANAGER_PROXY_H - -#include -#include -#include -#include -#include -#include -#include -#include "refbase.h" -#include "iremote_broker.h" -#include "iremote_object.h" -#include "ipower_mode_callback.h" -#include "ipower_state_callback.h" -#include "ipower_runninglock_callback.h" -#include "ipower_mgr.h" -#include "iscreen_off_pre_callback.h" -#include "running_lock_info.h" -#include "power_state_machine_info.h" -#include "power_errors.h" - -namespace OHOS { -namespace PowerMgr { -class PowerMgrProxy : public IRemoteProxy { -public: - explicit PowerMgrProxy(const sptr& impl) - : IRemoteProxy(impl) {} - ~PowerMgrProxy() = default; - DISALLOW_COPY_AND_MOVE(PowerMgrProxy); - - virtual PowerErrors CreateRunningLock(const sptr& remoteObj, - const RunningLockInfo& runningLockInfo) override; - virtual bool ReleaseRunningLock(const sptr& remoteObj, const std::string& name = "") override; - virtual bool IsRunningLockTypeSupported(RunningLockType type) override; - virtual bool UpdateWorkSource(const sptr& remoteObj, - const std::vector& workSources) override; - virtual PowerErrors Lock(const sptr& remoteObj, int32_t timeOutMs = -1) override; - virtual PowerErrors UnLock(const sptr& remoteObj, const std::string& name = "") override; - virtual bool QueryRunningLockLists(std::map& runningLockLists) override; - virtual bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) override; - virtual bool ProxyRunningLocks(bool isProxied, - const std::vector>& processInfos) override; - virtual bool ResetRunningLocks() override; - virtual bool IsUsed(const sptr& remoteObj) override; - // Use for PowerStateMachine - virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, - bool suspendImmed, const std::string& apiVersion = "-1") override; - virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, - const std::string& details, const std::string& apiVersion = "-1") override; - virtual void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) override; - virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) override; - virtual PowerErrors OverrideScreenOffTime(int64_t timeout, const std::string& apiVersion = "-1") override; - virtual PowerErrors RestoreScreenOffTime(const std::string& apiVersion = "-1") override; - virtual PowerState GetState() override; - virtual bool IsScreenOn(bool needPrintLog = true) override; - virtual bool IsFoldScreenOn() override; - virtual bool IsCollaborationScreenOn() override; - virtual PowerErrors ForceSuspendDevice(int64_t callTimeMs, const std::string& apiVersion = "-1") override; - virtual PowerErrors RebootDevice(const std::string& reason) override; - virtual PowerErrors RebootDeviceForDeprecated(const std::string& reason) override; - virtual PowerErrors ShutDownDevice(const std::string& reason) override; - virtual PowerErrors SetSuspendTag(const std::string& tag) override; - virtual bool RegisterPowerStateCallback(const sptr& callback, bool isSync = true) override; - virtual bool UnRegisterPowerStateCallback(const sptr& callback) override; - virtual bool RegisterPowerModeCallback(const sptr& callback) override; - virtual bool UnRegisterPowerModeCallback(const sptr& callback) override; - virtual bool RegisterScreenStateCallback(int32_t remainTime, const sptr& callback) override; - virtual bool UnRegisterScreenStateCallback(const sptr& callback) override; - virtual bool RegisterRunningLockCallback(const sptr& callback) override; - virtual bool UnRegisterRunningLockCallback(const sptr& callback) override; - virtual bool SetDisplaySuspend(bool enable) override; - virtual PowerErrors Hibernate( - bool clearMemory, const std::string& reason = "", const std::string& apiVersion = "-1") override; - virtual PowerErrors SetDeviceMode(const PowerMode& mode) override; - virtual PowerMode GetDeviceMode() override; - virtual std::string ShellDump(const std::vector& args, uint32_t argc) override; - virtual PowerErrors IsStandby(bool& isStandby) override; - - virtual PowerErrors SetForceTimingOut(bool enabled, const sptr& token) override; - virtual PowerErrors LockScreenAfterTimingOut( - bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, const sptr& token) override; - - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) override; - void UnRegisterShutdownCallback(const sptr& callback) override; - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) override; - void UnRegisterShutdownCallback(const sptr& callback) override; - void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) override; - void UnRegisterShutdownCallback(const sptr& callback) override; - - virtual bool RegisterSyncHibernateCallback(const sptr& callback) override; - virtual bool UnRegisterSyncHibernateCallback(const sptr& callback) override; - virtual bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) override; - virtual bool UnRegisterSyncSleepCallback(const sptr& callback) override; - virtual PowerErrors IsRunningLockEnabled(const RunningLockType type, bool& result) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_SERVICES_IPOWER_MANAGER_PROXY_H diff --git a/services/zidl/include/power_mgr_stub.h b/services/zidl/include/power_mgr_stub.h deleted file mode 100644 index ffdf6551..00000000 --- a/services/zidl/include/power_mgr_stub.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POWERMGR_SERVICES_IPOWER_MANAGER_STUB_H -#define POWERMGR_SERVICES_IPOWER_MANAGER_STUB_H - -#include -#include - -#include "ipower_mgr.h" - -namespace OHOS { -namespace PowerMgr { -class PowerMgrStub : public IRemoteStub { -public: - DISALLOW_COPY_AND_MOVE(PowerMgrStub); - PowerMgrStub() = default; - ~PowerMgrStub() override = default; - int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - static bool IsShutdownCommand(uint32_t code); - - int32_t WakeupDeviceStub(MessageParcel& data, MessageParcel& reply); - int32_t SuspendDeviceStub(MessageParcel& data, MessageParcel& reply); - int32_t RefreshActivityStub(MessageParcel& data); - int32_t OverrideScreenOffTimeStub(MessageParcel& data, MessageParcel& reply); - int32_t RestoreScreenOffTimeStub(MessageParcel& data, MessageParcel& reply); - int32_t GetStateStub(MessageParcel& reply); - int32_t IsScreenOnStub(MessageParcel& data, MessageParcel& reply); - int32_t IsFoldScreenOnStub(MessageParcel& reply); - int32_t IsCollaborationScreenOnStub(MessageParcel& reply); - int32_t ForceSuspendDeviceStub(MessageParcel& data, MessageParcel& reply); - int32_t ProxyRunningLockStub(MessageParcel& data, MessageParcel& reply); - int32_t ProxyRunningLocksStub(MessageParcel& data, MessageParcel& reply); - int32_t ResetAllPorxyStub(MessageParcel& data, MessageParcel& reply); - int32_t CreateRunningLockStub(MessageParcel& data, MessageParcel& reply); - int32_t ReleaseRunningLockStub(MessageParcel& data); - int32_t IsRunningLockTypeSupportedStub(MessageParcel& data, MessageParcel& reply); - int32_t UpdateWorkSourceStub(MessageParcel& data); - int32_t LockStub(MessageParcel& data, MessageParcel& reply); - int32_t UnLockStub(MessageParcel& data, MessageParcel& reply); - int32_t QueryRunningLockListsStub(MessageParcel& data, MessageParcel& reply); - int32_t IsUsedStub(MessageParcel& data, MessageParcel& reply); - int32_t RebootDeviceStub(MessageParcel& data, MessageParcel& reply); - int32_t RebootDeviceForDeprecatedStub(MessageParcel& data, MessageParcel& reply); - int32_t ShutDownDeviceStub(MessageParcel& data, MessageParcel& reply); - int32_t SetSuspendTagStub(MessageParcel& data, MessageParcel& reply); - int32_t RegisterPowerStateCallbackStub(MessageParcel& data); - - int32_t RegisterSyncHibernateCallbackStub(MessageParcel& data); - int32_t UnRegisterSyncHibernateCallbackStub(MessageParcel& data); - int32_t RegisterSyncSleepCallbackStub(MessageParcel& data); - int32_t UnRegisterSyncSleepCallbackStub(MessageParcel& data); - - int32_t UnRegisterPowerStateCallbackStub(MessageParcel& data); - int32_t RegisterPowerModeCallbackStub(MessageParcel& data); - int32_t UnRegisterPowerModeCallbackStub(MessageParcel& data); - int32_t RegisterScreenStateCallbackStub(MessageParcel& data); - int32_t UnRegisterScreenStateCallbackStub(MessageParcel& data); - int32_t RegisterRunningLockCallbackStub(MessageParcel& data); - int32_t UnRegisterRunningLockCallbackStub(MessageParcel& data); - int32_t SetDisplaySuspendStub(MessageParcel& data); - int32_t HibernateStub(MessageParcel& data, MessageParcel& reply); - int32_t SetDeviceModeStub(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceModeStub(MessageParcel& reply); - int32_t ShellDumpStub(MessageParcel& data, MessageParcel& reply); - int32_t IsStandbyStub(MessageParcel& data, MessageParcel& reply); - int32_t SetForceTimingOutStub(MessageParcel& data, MessageParcel& reply); - int32_t LockScreenAfterTimingOutStub(MessageParcel& data, MessageParcel& reply); - int32_t IsRunningLockEnabledStub(MessageParcel& data, MessageParcel& reply); -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_SERVICES_IPOWER_MANAGER_STUB_H diff --git a/services/zidl/src/power_mgr_async_reply.cpp b/services/zidl/src/power_mgr_async_reply.cpp index e4c56df1..adbc5aad 100644 --- a/services/zidl/src/power_mgr_async_reply.cpp +++ b/services/zidl/src/power_mgr_async_reply.cpp @@ -14,6 +14,8 @@ */ #include "power_mgr_async_reply.h" +#include "power_mgr_async_reply_proxy.h" +#include "power_mgr_async_reply_stub.h" #include "power_common.h" namespace OHOS { diff --git a/services/zidl/src/power_mgr_proxy.cpp b/services/zidl/src/power_mgr_proxy.cpp deleted file mode 100644 index 745ce4e4..00000000 --- a/services/zidl/src/power_mgr_proxy.cpp +++ /dev/null @@ -1,1442 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "power_mgr_proxy.h" -#include "power_mgr_async_reply.h" - -#include -#include -#include "message_option.h" -#include "shutdown_proxy_delegator.h" -#include "power_log.h" -#include "power_common.h" -#include "power_mgr_ipc_interface_code.h" -#include "running_lock_info.h" - -namespace OHOS { -namespace PowerMgr { -namespace { -constexpr int32_t MAX_PARAM_NUM = 2000; -constexpr uint32_t MAX_PROXY_RUNNINGLOCK_NUM = 2000; -constexpr int32_t MAX_VERSION_STRING_SIZE = 4; -} -PowerErrors PowerMgrProxy::CreateRunningLock(const sptr& remoteObj, - const RunningLockInfo& runningLockInfo) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Parcelable, &runningLockInfo, PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::CREATE_RUNNINGLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -bool PowerMgrProxy::ReleaseRunningLock(const sptr& remoteObj, const std::string& name) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, name, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RELEASE_RUNNINGLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::IsRunningLockTypeSupported(RunningLockType type) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - bool result = false; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return result; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast(type), false); - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_RUNNINGLOCK_TYPE_SUPPORTED), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return result; - } - - if (!reply.ReadBool(result)) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "ReadBool fail"); - } - - return result; -} - -bool PowerMgrProxy::UpdateWorkSource(const sptr& remoteObj, - const std::vector& workSources) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), false); - uint32_t size = workSources.size(); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, size, false); - for (const auto& wks : workSources) { - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, wks, false); - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UPDATE_WORK_SOURCE), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -PowerErrors PowerMgrProxy::Lock(const sptr& remoteObj, int32_t timeOutMs) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET( - data, RemoteObject, remoteObj.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, timeOutMs, PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_LOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::UnLock(const sptr& remoteObj, const std::string& name) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET( - data, RemoteObject, remoteObj.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, name, PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_UNLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); - return static_cast(error); -} - -bool PowerMgrProxy::QueryRunningLockLists(std::map& runningLockLists) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_QUERY), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - int32_t num = reply.ReadInt32(); - if (num < 0 || num > MAX_PARAM_NUM) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "num exceed limit, num=%{public}d", num); - return false; - } - for (int i = 0; i < num; i++) { - std::string key = reply.ReadString(); - RunningLockInfo* info = reply.ReadParcelable(); - if (info != nullptr) { - runningLockLists.insert(std::pair(key, *info)); - delete info; - } - } - return true; -} - -bool PowerMgrProxy::IsUsed(const sptr& remoteObj) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), false); - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_ISUSED), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - bool used = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, used, false); - return used; -} - -bool PowerMgrProxy::ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, pid, false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, uid, false); - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - bool succ = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false); - return succ; -} - -bool PowerMgrProxy::ProxyRunningLocks(bool isProxied, const std::vector>& processInfos) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - size_t size = processInfos.size(); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, size, false); - if (size > MAX_PROXY_RUNNINGLOCK_NUM) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "size exceed limit, size=%{public}zu", size); - return false; - } - for (size_t i = 0; i < size; ++i) { - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].first, false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].second, false); - } - int ret = remote->SendRequest(static_cast(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCKS), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - bool succ = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false); - return succ; -} - -bool PowerMgrProxy::ResetRunningLocks() -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - int ret = remote->SendRequest(static_cast(PowerMgr::PowerMgrInterfaceCode::RESET_RUNNINGLOCKS), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - bool succ = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false); - return succ; -} - -PowerErrors PowerMgrProxy::RebootDevice(const std::string& reason) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(reason), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::RebootDeviceForDeprecated(const std::string& reason) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(reason), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE_FOR_DEPRECATED), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::ShutDownDevice(const std::string& reason) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(reason), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SHUTDOWN_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::SetSuspendTag(const std::string& tag) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(tag), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SET_SUSPEND_TAG), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::SuspendDevice( - int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed, const std::string& apiVersion) -{ - RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, - static_cast(reason), PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, suspendImmed, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET( - data, String16, Str8ToStr16(apiVersion), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SUSPEND_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::WakeupDevice( - int64_t callTimeMs, WakeupDeviceType reason, const std::string& details, const std::string& apiVersion) -{ - RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_WAKEUP, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, - static_cast(reason), PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(details), PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET( - data, String16, Str8ToStr16(apiVersion), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_WAKEUP, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -void PowerMgrProxy::WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) -{ - sptr remote = Remote(); - RETURN_IF(remote == nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_WAKEUP, "Write descriptor failed"); - return; - } - - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Int64, callTimeMs); - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Uint32, static_cast(reason)); - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, String16, Str8ToStr16(details)); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_WAKEUP, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return; - } -} - -bool PowerMgrProxy::RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_ACTIVITY, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast(type), false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, needChangeBacklight, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REFRESH_ACTIVITY), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_ACTIVITY, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -PowerErrors PowerMgrProxy::OverrideScreenOffTime(int64_t timeout, const std::string& apiVersion) -{ - RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_SVC, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, timeout, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET( - data, String16, Str8ToStr16(apiVersion), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_TIME), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_SVC, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::RestoreScreenOffTime(const std::string& apiVersion) -{ - RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET( - data, String16, Str8ToStr16(apiVersion), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RESTORE_DISPLAY_OFF_TIME), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::ForceSuspendDevice(int64_t callTimeMs, const std::string& apiVersion) -{ - RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET( - data, String16, Str8ToStr16(apiVersion), PowerErrors::ERR_CONNECTION_FAIL); - sptr asyncCallback = new PowerMgrStubAsync(); - data.WriteRemoteObject(asyncCallback->AsObject()); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::FORCE_DEVICE_SUSPEND), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - int waitTime = 100; - int error = asyncCallback->WaitForAsyncReply(waitTime); - return static_cast(error); -} - -PowerState PowerMgrProxy::GetState() -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerState::UNKNOWN); - - uint32_t result = 0; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return PowerState::UNKNOWN; - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::GET_STATE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerState::UNKNOWN; - } - if (!reply.ReadUint32(result)) { - POWER_HILOGE(FEATURE_POWER_STATE, "ReadUint32 failed"); - return PowerState::UNKNOWN; - } - - return static_cast(result); -} - -bool PowerMgrProxy::IsScreenOn(bool needPrintLog) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - bool result = false; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return result; - } - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, needPrintLog, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_SCREEN_ON), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return result; - } - - if (!reply.ReadBool(result)) { - POWER_HILOGE(COMP_FWK, "Read IsScreenOn failed"); - } - - return result; -} - -bool PowerMgrProxy::IsFoldScreenOn() -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - bool result = false; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return result; - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_FOLD_SCREEN_ON), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return result; - } - - if (!reply.ReadBool(result)) { - POWER_HILOGE(COMP_FWK, "Read IsFoldScreenOn failed"); - } - - return result; -} - -bool PowerMgrProxy::IsCollaborationScreenOn() -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - bool result = false; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return result; - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_COLLABORATION_SCREEN_ON), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return result; - } - - if (!reply.ReadBool(result)) { - POWER_HILOGE(COMP_FWK, "Read IsCollaborationScreenOn failed"); - } - - return result; -} - -bool PowerMgrProxy::RegisterPowerStateCallback(const sptr& callback, bool isSync) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, isSync, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_POWER_STATE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::UnRegisterPowerStateCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_STATE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast(priority), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_SLEEP_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - - -bool PowerMgrProxy::UnRegisterSyncSleepCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_SLEEP_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::RegisterSyncHibernateCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_HIBERNATE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - - -bool PowerMgrProxy::UnRegisterSyncHibernateCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_HIBERNATE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::RegisterPowerModeCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_POWER_MODE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::UnRegisterPowerModeCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_MODE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::RegisterScreenStateCallback(int32_t remainTime, const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (remainTime <= 0) || (callback == nullptr), false); - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, remainTime, false); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SCREEN_OFF_PRE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::UnRegisterScreenStateCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SCREEN_OFF_PRE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::RegisterRunningLockCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_RUNNINGLOCK_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::UnRegisterRunningLockCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_RUNNINGLOCK_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -bool PowerMgrProxy::SetDisplaySuspend(bool enable) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return false; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, enable, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SET_DISPLAY_SUSPEND), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; - } - return true; -} - -PowerErrors PowerMgrProxy::Hibernate(bool clearMemory, const std::string& reason, const std::string& apiVersion) -{ - RETURN_IF_WITH_RET(apiVersion.size() >= MAX_VERSION_STRING_SIZE, PowerErrors::ERR_PARAM_INVALID); - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, clearMemory, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(reason), PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(apiVersion), PowerErrors::ERR_CONNECTION_FAIL); - sptr asyncCallback = new PowerMgrStubAsync(); - data.WriteRemoteObject(asyncCallback->AsObject()); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::HIBERNATE), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - int waitTime = 100; - int error = asyncCallback->WaitForAsyncReply(waitTime); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::SetDeviceMode(const PowerMode& mode) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast(mode), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SETMODE_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); -} - -PowerMode PowerMgrProxy::GetDeviceMode() -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, static_cast(false)); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return PowerMode::NORMAL_MODE; - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::GETMODE_DEVICE), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerMode::NORMAL_MODE; - } - - uint32_t used = static_cast(PowerMode::NORMAL_MODE); - if (!reply.ReadUint32(used)) { - POWER_HILOGE(FEATURE_POWER_MODE, "ReadUint32 fail"); - } - return static_cast(used); -} - -std::string PowerMgrProxy::ShellDump(const std::vector& args, uint32_t argc) -{ - sptr remote = Remote(); - std::string result = "remote error"; - RETURN_IF_WITH_RET(remote == nullptr, result); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return result; - } - if (argc > args.size()) { - POWER_HILOGE(COMP_FWK, "argc is greater than args size!"); - return result; - } - - data.WriteUint32(argc); - for (uint32_t i = 0; i < argc; i++) { - data.WriteString(args[i]); - } - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SHELL_DUMP), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return result; - } - result = reply.ReadString(); - - return result; -} - -PowerErrors PowerMgrProxy::IsStandby(bool& isStandby) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - int32_t ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_STANDBY), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - int32_t error = ERR_OK; - - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, isStandby, PowerErrors::ERR_CONNECTION_FAIL); - - return static_cast(error); -} - -PowerErrors PowerMgrProxy::SetForceTimingOut(bool enabled, const sptr& token) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, - static_cast(enabled), PowerErrors::ERR_CONNECTION_FAIL); - if (token.GetRefPtr() == nullptr) { - POWER_HILOGE(COMP_FWK, "token nullptr"); - } - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, token, PowerErrors::ERR_CONNECTION_FAIL); - int32_t ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SET_FORCE_TIMING_OUT), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); - return static_cast(error); -} - -PowerErrors PowerMgrProxy::LockScreenAfterTimingOut( - bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, const sptr& token) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, enabledLockScreen, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, checkLock, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, sendScreenOffEvent, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, token.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL); - - int32_t ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::LOCK_SCREEN_AFTER_TIMING_OUT), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); - return static_cast(error); -} - -void PowerMgrProxy::RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) -{ - sptr remote = Remote(); - RETURN_IF(remote == nullptr); - auto delegator = std::make_unique(remote, PowerMgrProxy::GetDescriptor()); - delegator->RegisterShutdownCallback(callback, priority); -} - -void PowerMgrProxy::UnRegisterShutdownCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF(remote == nullptr); - auto delegator = std::make_unique(remote, PowerMgrProxy::GetDescriptor()); - delegator->UnRegisterShutdownCallback(callback); -} - -void PowerMgrProxy::RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) -{ - sptr remote = Remote(); - RETURN_IF(remote == nullptr); - auto delegator = std::make_unique(remote, PowerMgrProxy::GetDescriptor()); - delegator->RegisterShutdownCallback(callback, priority); -} - -void PowerMgrProxy::UnRegisterShutdownCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF(remote == nullptr); - auto delegator = std::make_unique(remote, PowerMgrProxy::GetDescriptor()); - delegator->UnRegisterShutdownCallback(callback); -} - -void PowerMgrProxy::RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) -{ - sptr remote = Remote(); - RETURN_IF(remote == nullptr); - auto delegator = std::make_unique(remote, PowerMgrProxy::GetDescriptor()); - delegator->RegisterShutdownCallback(callback, priority); -} - -void PowerMgrProxy::UnRegisterShutdownCallback(const sptr& callback) -{ - sptr remote = Remote(); - RETURN_IF(remote == nullptr); - auto delegator = std::make_unique(remote, PowerMgrProxy::GetDescriptor()); - delegator->UnRegisterShutdownCallback(callback); -} - -PowerErrors PowerMgrProxy::IsRunningLockEnabled(const RunningLockType type, bool& result) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast(type), PowerErrors::ERR_CONNECTION_FAIL); - - int ret = remote->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_RUNNINGLOCK_ENABLED), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; - } - - int32_t error = ERR_OK; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, result, PowerErrors::ERR_CONNECTION_FAIL); - return static_cast(error); -} -} // namespace PowerMgr -} // namespace OHOS diff --git a/services/zidl/src/power_mgr_stub.cpp b/services/zidl/src/power_mgr_stub.cpp deleted file mode 100644 index 22eb11c8..00000000 --- a/services/zidl/src/power_mgr_stub.cpp +++ /dev/null @@ -1,774 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "power_mgr_stub.h" -#include "power_mgr_async_reply.h" - -#include -#include - -#include "running_lock_info.h" -#include "power_common.h" -#include "power_errors.h" -#include "power_mgr_ipc_interface_code.h" -#include "shutdown_stub_delegator.h" -#include "shutdown/shutdown_client_ipc_interface_code.h" -#include "xcollie/xcollie.h" - -using namespace OHOS::HiviewDFX; - -namespace OHOS { -namespace PowerMgr { -namespace { -constexpr uint32_t PARAM_MAX_NUM = 10; -constexpr uint32_t PARAM_MAX_SIZE = 2000; -constexpr int32_t MAX_PROXY_RUNNINGLOCK_NUM = 2000; -std::unique_ptr g_shutdownDelegator; -std::mutex g_shutdownMutex; -} -int PowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) -{ - POWER_HILOGD(COMP_FWK, "code=%{public}u, flags=%{public}d", code, option.GetFlags()); - std::u16string descriptor = PowerMgrStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - POWER_HILOGE(COMP_FWK, "Descriptor is not matched"); - return E_GET_POWER_SERVICE_FAILED; - } - if (IsShutdownCommand(code)) { - { - std::lock_guard lock(g_shutdownMutex); - if (g_shutdownDelegator == nullptr) { - g_shutdownDelegator = std::make_unique(*this); - RETURN_IF_WITH_RET(g_shutdownDelegator == nullptr, ERR_NO_INIT) - } - } - int ret = g_shutdownDelegator->HandleRemoteRequest(code, data, reply, option); - if (ret == ERR_INVALID_OPERATION) { - ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return ret; - } - - const int DFX_DELAY_S = 60; - int id = HiviewDFX::XCollie::GetInstance().SetTimer("PowerMgrStub", DFX_DELAY_S, nullptr, nullptr, - HiviewDFX::XCOLLIE_FLAG_LOG); - - int ret = ERR_OK; - switch (code) { - case static_cast(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE): - ret = WakeupDeviceStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::SUSPEND_DEVICE): - ret = SuspendDeviceStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REFRESH_ACTIVITY): - ret = RefreshActivityStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE): - ret = RebootDeviceStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE_FOR_DEPRECATED): - ret = RebootDeviceForDeprecatedStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::SHUTDOWN_DEVICE): - ret = ShutDownDeviceStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::SET_SUSPEND_TAG): - ret = SetSuspendTagStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_TIME): - ret = OverrideScreenOffTimeStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::RESTORE_DISPLAY_OFF_TIME): - ret = RestoreScreenOffTimeStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::GET_STATE): - ret = GetStateStub(reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::IS_SCREEN_ON): - ret = IsScreenOnStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::IS_FOLD_SCREEN_ON): - ret = IsFoldScreenOnStub(reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::IS_COLLABORATION_SCREEN_ON): - ret = IsCollaborationScreenOnStub(reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::FORCE_DEVICE_SUSPEND): - ret = ForceSuspendDeviceStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::CREATE_RUNNINGLOCK): - ret = CreateRunningLockStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::RELEASE_RUNNINGLOCK): - ret = ReleaseRunningLockStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::IS_RUNNINGLOCK_TYPE_SUPPORTED): - ret = IsRunningLockTypeSupportedStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_LOCK): - ret = LockStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_UNLOCK): - ret = UnLockStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_QUERY): - ret = QueryRunningLockListsStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCK): - ret = ProxyRunningLockStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_ISUSED): - ret = IsUsedStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCKS): - ret = ProxyRunningLocksStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::RESET_RUNNINGLOCKS): - ret = ResetAllPorxyStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_POWER_STATE_CALLBACK): - ret = RegisterPowerStateCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_STATE_CALLBACK): - ret = UnRegisterPowerStateCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_POWER_MODE_CALLBACK): - ret = RegisterPowerModeCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_MODE_CALLBACK): - ret = UnRegisterPowerModeCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::SET_DISPLAY_SUSPEND): - ret = SetDisplaySuspendStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::HIBERNATE): - ret = HibernateStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::SETMODE_DEVICE): - ret = SetDeviceModeStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::GETMODE_DEVICE): - ret = GetDeviceModeStub(reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::SHELL_DUMP): - ret = ShellDumpStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::IS_STANDBY): - ret = IsStandbyStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_HIBERNATE_CALLBACK): - ret = RegisterSyncHibernateCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_HIBERNATE_CALLBACK): - ret = UnRegisterSyncHibernateCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_SLEEP_CALLBACK): - ret = RegisterSyncSleepCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_SLEEP_CALLBACK): - ret = UnRegisterSyncSleepCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::SET_FORCE_TIMING_OUT): - ret = SetForceTimingOutStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::LOCK_SCREEN_AFTER_TIMING_OUT): - ret = LockScreenAfterTimingOutStub(data, reply); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_RUNNINGLOCK_CALLBACK): - ret = RegisterRunningLockCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_RUNNINGLOCK_CALLBACK): - ret = UnRegisterRunningLockCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SCREEN_OFF_PRE_CALLBACK): - ret = RegisterScreenStateCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SCREEN_OFF_PRE_CALLBACK): - ret = UnRegisterScreenStateCallbackStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::UPDATE_WORK_SOURCE): - ret = UpdateWorkSourceStub(data); - break; - case static_cast(PowerMgr::PowerMgrInterfaceCode::IS_RUNNINGLOCK_ENABLED): - ret = IsRunningLockEnabledStub(data, reply); - break; - default: - ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - HiviewDFX::XCollie::GetInstance().CancelTimer(id); - return ret; -} - -int32_t PowerMgrStub::CreateRunningLockStub(MessageParcel& data, MessageParcel& reply) -{ - sptr remoteObj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR); - std::unique_ptr runningLockInfo(data.ReadParcelable()); - RETURN_IF_WITH_RET((runningLockInfo == nullptr), E_READ_PARCEL_ERROR); - PowerErrors error = CreateRunningLock(remoteObj, *runningLockInfo); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::ReleaseRunningLockStub(MessageParcel& data) -{ - sptr remoteObj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR); - std::string name; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, String, name, E_READ_PARCEL_ERROR); - ReleaseRunningLock(remoteObj, name); - return ERR_OK; -} - -int32_t PowerMgrStub::IsRunningLockTypeSupportedStub(MessageParcel& data, MessageParcel& reply) -{ - auto type = static_cast(RunningLockType::RUNNINGLOCK_BUTT); - bool ret = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR); - ret = IsRunningLockTypeSupported(static_cast(type)); - if (!reply.WriteBool(ret)) { - POWER_HILOGE(FEATURE_SUSPEND, "WriteBool fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::UpdateWorkSourceStub(MessageParcel& data) -{ - sptr remoteObj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR); - uint32_t size = 0; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, size, E_READ_PARCEL_ERROR); - if (size > PARAM_MAX_SIZE) { - return E_EXCEED_PARAM_LIMIT; - } - std::vector workSources(size); - for (uint32_t i = 0; i < size; ++i) { - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, workSources[i], E_READ_PARCEL_ERROR); - } - UpdateWorkSource(remoteObj, workSources); - return ERR_OK; -} - -int32_t PowerMgrStub::LockStub(MessageParcel& data, MessageParcel& reply) -{ - sptr remoteObj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR); - int32_t timeOutMs = 0; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, timeOutMs, E_READ_PARCEL_ERROR); - PowerErrors error = Lock(remoteObj, timeOutMs); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::UnLockStub(MessageParcel& data, MessageParcel& reply) -{ - sptr remoteObj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR); - std::string name; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, String, name, E_READ_PARCEL_ERROR); - PowerErrors error = UnLock(remoteObj, name); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::QueryRunningLockListsStub(MessageParcel& data, MessageParcel& reply) -{ - std::map runningLockLists; - QueryRunningLockLists(runningLockLists); - reply.WriteInt32(runningLockLists.size()); - for (auto it : runningLockLists) { - reply.WriteString(it.first); - reply.WriteParcelable(&it.second); - } - return ERR_OK; -} -int32_t PowerMgrStub::IsUsedStub(MessageParcel& data, MessageParcel& reply) -{ - sptr remoteObj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR); - bool ret = IsUsed(remoteObj); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::ProxyRunningLockStub(MessageParcel& data, MessageParcel& reply) -{ - bool isProxied = false; - pid_t uid; - pid_t pid; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, pid, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, uid, E_READ_PARCEL_ERROR); - bool ret = ProxyRunningLock(isProxied, pid, uid); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::ProxyRunningLocksStub(MessageParcel& data, MessageParcel& reply) -{ - bool isProxied = false; - std::vector> processInfos {}; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, E_READ_PARCEL_ERROR); - int32_t size {0}; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, size, E_READ_PARCEL_ERROR); - if (size <= 0 || size > MAX_PROXY_RUNNINGLOCK_NUM) { - POWER_HILOGW(COMP_FWK, "size exceed limit, size=%{public}d", size); - return E_EXCEED_PARAM_LIMIT; - } - processInfos.resize(size); - for (int i = 0; i < size; ++i) { - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].first, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].second, E_READ_PARCEL_ERROR); - } - bool ret = ProxyRunningLocks(isProxied, processInfos); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::ResetAllPorxyStub(MessageParcel& data, MessageParcel& reply) -{ - bool ret = ResetRunningLocks(); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::RebootDeviceStub(MessageParcel& data, MessageParcel& reply) -{ - std::string reason = Str16ToStr8(data.ReadString16()); - PowerErrors error = RebootDevice(reason); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::RebootDeviceForDeprecatedStub(MessageParcel& data, MessageParcel& reply) -{ - std::string reason = Str16ToStr8(data.ReadString16()); - PowerErrors error = RebootDeviceForDeprecated(reason); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::ShutDownDeviceStub(MessageParcel& data, MessageParcel& reply) -{ - std::string reason = Str16ToStr8(data.ReadString16()); - PowerErrors error = ShutDownDevice(reason); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::SetSuspendTagStub(MessageParcel& data, MessageParcel& reply) -{ - std::string tag = Str16ToStr8(data.ReadString16()); - PowerErrors error = SetSuspendTag(tag); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::WakeupDeviceStub(MessageParcel& data, MessageParcel& reply) -{ - int64_t time = 0; - uint32_t reason = 0; - - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, reason, E_READ_PARCEL_ERROR); - std::string details = Str16ToStr8(data.ReadString16()); - std::string apiVersion = Str16ToStr8(data.ReadString16()); - - PowerErrors error = WakeupDevice(time, static_cast(reason), details, apiVersion); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::SuspendDeviceStub(MessageParcel& data, MessageParcel& reply) -{ - int64_t time = 0; - uint32_t reason = 0; - bool suspendImmed = true; - - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, reason, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, suspendImmed, E_READ_PARCEL_ERROR); - std::string apiVersion = Str16ToStr8(data.ReadString16()); - - PowerErrors error = SuspendDevice(time, static_cast(reason), suspendImmed, apiVersion); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::RefreshActivityStub(MessageParcel& data) -{ - int64_t time = 0; - uint32_t type = 0; - bool needChangeBacklight = true; - - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, needChangeBacklight, E_READ_PARCEL_ERROR); - - RefreshActivity(time, static_cast(type), needChangeBacklight); - return ERR_OK; -} - -int32_t PowerMgrStub::OverrideScreenOffTimeStub(MessageParcel& data, MessageParcel& reply) -{ - int64_t timeout = 0; - - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, timeout, E_READ_PARCEL_ERROR); - std::string apiVersion = Str16ToStr8(data.ReadString16()); - - PowerErrors error = OverrideScreenOffTime(timeout, apiVersion); - if (!reply.WriteInt32(static_cast(error))) { - POWER_HILOGE(COMP_FWK, "WriteInt32 fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::RestoreScreenOffTimeStub(MessageParcel& data, MessageParcel& reply) -{ - std::string apiVersion = Str16ToStr8(data.ReadString16()); - PowerErrors error = RestoreScreenOffTime(apiVersion); - if (!reply.WriteInt32(static_cast(error))) { - POWER_HILOGE(COMP_FWK, "WriteInt32 fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::ForceSuspendDeviceStub(MessageParcel& data, MessageParcel& reply) -{ - int64_t time = 0; - - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR); - std::string apiVersion = Str16ToStr8(data.ReadString16()); - sptr powerProxy = iface_cast(data.ReadRemoteObject()); - - PowerErrors error = ForceSuspendDevice(time, apiVersion); - int result = static_cast(error); - if (powerProxy != nullptr) { - powerProxy->SendAsyncReply(result); - } - return ERR_OK; -} - -int32_t PowerMgrStub::GetStateStub(MessageParcel& reply) -{ - PowerState ret = GetState(); - if (!reply.WriteUint32(static_cast(ret))) { - POWER_HILOGE(FEATURE_POWER_STATE, "WriteUint32 fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::IsCollaborationScreenOnStub(MessageParcel& reply) -{ - bool ret = false; - ret = IsCollaborationScreenOn(); - if (!reply.WriteBool(ret)) { - POWER_HILOGE(COMP_FWK, "WriteBool fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::IsFoldScreenOnStub(MessageParcel& reply) -{ - bool ret = false; - ret = IsFoldScreenOn(); - if (!reply.WriteBool(ret)) { - POWER_HILOGE(COMP_FWK, "WriteBool fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::IsScreenOnStub(MessageParcel& data, MessageParcel& reply) -{ - bool ret = false; - bool needPrintLog = true; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, needPrintLog, E_READ_PARCEL_ERROR); - ret = IsScreenOn(needPrintLog); - if (!reply.WriteBool(ret)) { - POWER_HILOGE(COMP_FWK, "WriteBool fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::RegisterPowerStateCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - bool isSync = true; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, isSync, E_READ_PARCEL_ERROR); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - RegisterPowerStateCallback(callback, isSync); - return ERR_OK; -} - -int32_t PowerMgrStub::UnRegisterPowerStateCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - UnRegisterPowerStateCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::RegisterSyncHibernateCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - RegisterSyncHibernateCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::UnRegisterSyncHibernateCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - UnRegisterSyncHibernateCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::RegisterSyncSleepCallbackStub(MessageParcel& data) -{ - uint32_t priority; - sptr obj = data.ReadRemoteObject(); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, priority, E_READ_PARCEL_ERROR); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - RegisterSyncSleepCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::UnRegisterSyncSleepCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - UnRegisterSyncSleepCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::RegisterPowerModeCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - RegisterPowerModeCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::UnRegisterPowerModeCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - UnRegisterPowerModeCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::RegisterScreenStateCallbackStub(MessageParcel& data) -{ - int32_t remainTime = 0; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, remainTime, E_READ_PARCEL_ERROR); - - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - RegisterScreenStateCallback(remainTime, callback); - return ERR_OK; -} - -int32_t PowerMgrStub::UnRegisterScreenStateCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - UnRegisterScreenStateCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::RegisterRunningLockCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - RegisterRunningLockCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::UnRegisterRunningLockCallbackStub(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - sptr callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - UnRegisterRunningLockCallback(callback); - return ERR_OK; -} - -int32_t PowerMgrStub::SetDisplaySuspendStub(MessageParcel& data) -{ - bool enable = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enable, E_READ_PARCEL_ERROR); - SetDisplaySuspend(enable); - return ERR_OK; -} - -int32_t PowerMgrStub::HibernateStub(MessageParcel& data, MessageParcel& reply) -{ - bool clearMemory = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, clearMemory, E_READ_PARCEL_ERROR); - std::string reason = Str16ToStr8(data.ReadString16()); - std::string apiVersion = Str16ToStr8(data.ReadString16()); - sptr powerProxy = iface_cast(data.ReadRemoteObject()); - - PowerErrors error = Hibernate(clearMemory, reason, apiVersion); - int result = static_cast(error); - if (powerProxy != nullptr) { - powerProxy->SendAsyncReply(result); - } - return ERR_OK; -} - -int32_t PowerMgrStub::SetDeviceModeStub(MessageParcel& data, MessageParcel& reply) -{ - uint32_t mode = 0; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, mode, E_READ_PARCEL_ERROR); - PowerErrors error = SetDeviceMode(static_cast(mode)); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::GetDeviceModeStub(MessageParcel& reply) -{ - uint32_t ret = 0; - ret = static_cast(GetDeviceMode()); - if (!reply.WriteUint32(static_cast(ret))) { - POWER_HILOGE(FEATURE_POWER_MODE, "WriteUint32 fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -int32_t PowerMgrStub::ShellDumpStub(MessageParcel& data, MessageParcel& reply) -{ - uint32_t argc; - std::vector args; - - if (!data.ReadUint32(argc)) { - POWER_HILOGE(COMP_FWK, "ReadUint32 fail"); - return E_READ_PARCEL_ERROR; - } - - if (argc >= PARAM_MAX_NUM) { - POWER_HILOGW(COMP_FWK, "params exceed limit, argc=%{public}d", argc); - return E_EXCEED_PARAM_LIMIT; - } - - for (uint32_t i = 0; i < argc; i++) { - std::string arg = data.ReadString(); - if (arg.empty()) { - POWER_HILOGW(COMP_FWK, "read args fail, arg index=%{public}d", i); - return E_READ_PARCEL_ERROR; - } - args.push_back(arg); - } - - std::string ret = ShellDump(args, argc); - if (!reply.WriteString(ret)) { - POWER_HILOGE(COMP_FWK, "WriteString fail"); - return E_WRITE_PARCEL_ERROR; - } - return ERR_OK; -} - -bool PowerMgrStub::IsShutdownCommand(uint32_t code) -{ - return (code >= static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_START)) && - (code <= static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_END)); -} - -int32_t PowerMgrStub::IsStandbyStub(MessageParcel& data, MessageParcel& reply) -{ - bool isStandby = false; - PowerErrors ret = IsStandby(isStandby); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(ret), E_WRITE_PARCEL_ERROR); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isStandby, E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::SetForceTimingOutStub(MessageParcel& data, MessageParcel& reply) -{ - POWER_HILOGI(COMP_FWK, "SetForceTimingOutStub msg received"); - bool enabled = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enabled, E_READ_PARCEL_ERROR); - sptr token = data.ReadRemoteObject(); - if (!token) { - POWER_HILOGE(COMP_FWK, "ReadRemoteObject failed, possibly blocked by SeLinux"); - } - PowerErrors ret = SetForceTimingOut(enabled, token); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(ret), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::LockScreenAfterTimingOutStub(MessageParcel& data, MessageParcel& reply) -{ - bool enabledLockScreen = true; - bool checkLock = false; - bool sendScreenOffEvent = true; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enabledLockScreen, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, checkLock, E_READ_PARCEL_ERROR); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, sendScreenOffEvent, E_READ_PARCEL_ERROR); - sptr token = data.ReadRemoteObject(); - if (!token) { - POWER_HILOGI(COMP_FWK, "ReadRemoteObject failed, possibly blocked by SeLinux"); - } - PowerErrors ret = LockScreenAfterTimingOut(enabledLockScreen, checkLock, sendScreenOffEvent, token); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(ret), E_WRITE_PARCEL_ERROR); - return ERR_OK; -} - -int32_t PowerMgrStub::IsRunningLockEnabledStub(MessageParcel& data, MessageParcel& reply) -{ - auto type = static_cast(RunningLockType::RUNNINGLOCK_BUTT); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR); - bool result = false; - PowerErrors error = IsRunningLockEnabled(static_cast(type), result); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast(error), E_WRITE_PARCEL_ERROR); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, result, E_WRITE_PARCEL_ERROR); - return ERR_OK; -} -} // namespace PowerMgr -} // namespace OHOS diff --git a/services/zidl/src/shutdown/shutdown_proxy_delegator.cpp b/services/zidl/src/shutdown/shutdown_proxy_delegator.cpp deleted file mode 100644 index fdb600ff..00000000 --- a/services/zidl/src/shutdown/shutdown_proxy_delegator.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "shutdown_proxy_delegator.h" - -#include "power_common.h" -#include "shutdown/shutdown_client_ipc_interface_code.h" - -namespace OHOS { -namespace PowerMgr { -void ShutdownProxyDelegator::RegisterShutdownCallback( - const sptr& callback, ShutdownPriority priority) -{ - RETURN_IF((remote_ == nullptr) || (callback == nullptr)) - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(descriptor_)) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return; - } - - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, RemoteObject, callback->AsObject()); - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Uint32, static_cast(priority)); - - int ret = remote_->SendRequest( - static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_REG_TAKEOVER_SHUTDOWN_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret); - } -} - -void ShutdownProxyDelegator::UnRegisterShutdownCallback(const sptr& callback) -{ - RETURN_IF((remote_ == nullptr) || (callback == nullptr)) - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(descriptor_)) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return; - } - - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, RemoteObject, callback->AsObject()); - - int ret = remote_->SendRequest( - static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_UNREG_TAKEOVER_SHUTDOWN_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret); - } -} - -void ShutdownProxyDelegator::RegisterShutdownCallback( - const sptr& callback, ShutdownPriority priority) -{ - RETURN_IF((remote_ == nullptr) || (callback == nullptr)) - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(descriptor_)) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return; - } - - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, RemoteObject, callback->AsObject()); - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Uint32, static_cast(priority)); - - int ret = remote_->SendRequest( - static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_REG_ASYNC_SHUTDOWN_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret); - } -} - -void ShutdownProxyDelegator::UnRegisterShutdownCallback(const sptr& callback) -{ - RETURN_IF((remote_ == nullptr) || (callback == nullptr)) - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(descriptor_)) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return; - } - - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, RemoteObject, callback->AsObject()); - - int ret = remote_->SendRequest( - static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_UNREG_ASYNC_SHUTDOWN_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret); - } -} - -void ShutdownProxyDelegator::RegisterShutdownCallback( - const sptr& callback, ShutdownPriority priority) -{ - RETURN_IF((remote_ == nullptr) || (callback == nullptr)) - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(descriptor_)) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return; - } - - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, RemoteObject, callback->AsObject()); - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Uint32, static_cast(priority)); - - int ret = remote_->SendRequest( - static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_REG_SYNC_SHUTDOWN_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret); - } -} - -void ShutdownProxyDelegator::UnRegisterShutdownCallback(const sptr& callback) -{ - RETURN_IF((remote_ == nullptr) || (callback == nullptr)) - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(descriptor_)) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return; - } - - RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, RemoteObject, callback->AsObject()); - - int ret = remote_->SendRequest( - static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_UNREG_SYNC_SHUTDOWN_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret); - } -} -} // namespace PowerMgr -} // namespace OHOS diff --git a/services/zidl/src/shutdown/shutdown_stub_delegator.cpp b/services/zidl/src/shutdown/shutdown_stub_delegator.cpp deleted file mode 100644 index 77171875..00000000 --- a/services/zidl/src/shutdown/shutdown_stub_delegator.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "shutdown_stub_delegator.h" - -#include "power_common.h" -#include "shutdown/shutdown_client_ipc_interface_code.h" -#include "xcollie/xcollie.h" - -namespace OHOS { -namespace PowerMgr { -namespace { -constexpr int32_t DFX_DELAY_S = 60; - -} -int32_t ShutdownStubDelegator::HandleRemoteRequest( - uint32_t code, MessageParcel& data, [[maybe_unused]] MessageParcel& reply, [[maybe_unused]] MessageOption& option) -{ - int32_t id = HiviewDFX::XCollie::GetInstance().SetTimer("ShutdownStub", DFX_DELAY_S, nullptr, nullptr, - HiviewDFX::XCOLLIE_FLAG_LOG); - int32_t ret = ERR_OK; - switch (code) { - case static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_REG_TAKEOVER_SHUTDOWN_CALLBACK): - ret = RegisterTakeOverShutdownCallback(data); - break; - case static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_UNREG_TAKEOVER_SHUTDOWN_CALLBACK): - ret = UnRegisterTakeOverShutdownCallback(data); - break; - case static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_REG_ASYNC_SHUTDOWN_CALLBACK): - ret = RegisterAsyncShutdownCallback(data); - break; - case static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_UNREG_ASYNC_SHUTDOWN_CALLBACK): - ret = UnRegisterAsyncShutdownCallback(data); - break; - case static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_REG_SYNC_SHUTDOWN_CALLBACK): - ret = RegisterSyncShutdownCallback(data); - break; - case static_cast(PowerMgr::ShutdownClientInterfaceCode::CMD_UNREG_SYNC_SHUTDOWN_CALLBACK): - ret = UnRegisterSyncShutdownCallback(data); - break; - default: - ret = ERR_INVALID_OPERATION; - break; - } - HiviewDFX::XCollie::GetInstance().CancelTimer(id); - return ret; -} - -int32_t ShutdownStubDelegator::RegisterTakeOverShutdownCallback(MessageParcel& data) -{ - uint32_t priority; - sptr obj = data.ReadRemoteObject(); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, priority, E_READ_PARCEL_ERROR); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - auto callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - stub_.RegisterShutdownCallback(callback, static_cast(priority)); - return ERR_OK; -} - -int32_t ShutdownStubDelegator::UnRegisterTakeOverShutdownCallback(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - auto callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - stub_.UnRegisterShutdownCallback(callback); - return ERR_OK; -} - -int32_t ShutdownStubDelegator::RegisterAsyncShutdownCallback(MessageParcel& data) -{ - uint32_t priority; - sptr obj = data.ReadRemoteObject(); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, priority, E_READ_PARCEL_ERROR); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - auto callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - stub_.RegisterShutdownCallback(callback, static_cast(priority)); - return ERR_OK; -} - -int32_t ShutdownStubDelegator::UnRegisterAsyncShutdownCallback(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - auto callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - stub_.UnRegisterShutdownCallback(callback); - return ERR_OK; -} - -int32_t ShutdownStubDelegator::RegisterSyncShutdownCallback(MessageParcel& data) -{ - uint32_t priority; - sptr obj = data.ReadRemoteObject(); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, priority, E_READ_PARCEL_ERROR); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - auto callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - stub_.RegisterShutdownCallback(callback, static_cast(priority)); - return ERR_OK; -} - -int32_t ShutdownStubDelegator::UnRegisterSyncShutdownCallback(MessageParcel& data) -{ - sptr obj = data.ReadRemoteObject(); - RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); - auto callback = iface_cast(obj); - RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); - stub_.UnRegisterShutdownCallback(callback); - return ERR_OK; -} -} // namespace PowerMgr -} // namespace OHOS diff --git a/test/fuzztest/asyncshutdowncallback_fuzzer/asyncshutdowncallback_fuzzer_test.cpp b/test/fuzztest/asyncshutdowncallback_fuzzer/asyncshutdowncallback_fuzzer_test.cpp index 85bec233..fde96c35 100644 --- a/test/fuzztest/asyncshutdowncallback_fuzzer/asyncshutdowncallback_fuzzer_test.cpp +++ b/test/fuzztest/asyncshutdowncallback_fuzzer/asyncshutdowncallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "asyncshutdowncallback_fuzzer" #include "power_fuzzer.h" -#include "shutdown/shutdown_client_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,9 +30,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub( - static_cast(ShutdownClientInterfaceCode::CMD_REG_ASYNC_SHUTDOWN_CALLBACK), data, size); - g_serviceTest.TestPowerServiceStub( - static_cast(ShutdownClientInterfaceCode::CMD_UNREG_ASYNC_SHUTDOWN_CALLBACK), data, size); + g_serviceTest.TestPowerServiceStub(static_cast( + IPowerMgrIpcCode::COMMAND_REGISTER_SHUTDOWN_CALLBACK_IPC_IN_IASYNCSHUTDOWNCALLBACK_IN_INT), data, size); + g_serviceTest.TestPowerServiceStub(static_cast( + IPowerMgrIpcCode::COMMAND_UN_REGISTER_SHUTDOWN_CALLBACK_IPC_IN_IASYNCSHUTDOWNCALLBACK), data, size); return 0; } diff --git a/test/fuzztest/createrunninglock_fuzzer/createrunninglock_fuzzer_test.cpp b/test/fuzztest/createrunninglock_fuzzer/createrunninglock_fuzzer_test.cpp index 1a7f11c4..12f77c71 100644 --- a/test/fuzztest/createrunninglock_fuzzer/createrunninglock_fuzzer_test.cpp +++ b/test/fuzztest/createrunninglock_fuzzer/createrunninglock_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "createrunninglock_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::CREATE_RUNNINGLOCK), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_CREATE_RUNNING_LOCK_IPC), data, size); return 0; } diff --git a/test/fuzztest/forcesuspenddevice_fuzzer/forcesuspenddevice_fuzzer_test.cpp b/test/fuzztest/forcesuspenddevice_fuzzer/forcesuspenddevice_fuzzer_test.cpp index 12d7f33a..d1c114d9 100644 --- a/test/fuzztest/forcesuspenddevice_fuzzer/forcesuspenddevice_fuzzer_test.cpp +++ b/test/fuzztest/forcesuspenddevice_fuzzer/forcesuspenddevice_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "forcesuspenddevice_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::FORCE_DEVICE_SUSPEND), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_FORCE_SUSPEND_DEVICE_IPC), data, size); return 0; } diff --git a/test/fuzztest/getsetdevicemode_fuzzer/getsetdevicemode_fuzzer_test.cpp b/test/fuzztest/getsetdevicemode_fuzzer/getsetdevicemode_fuzzer_test.cpp index 9659ba93..3e08134d 100644 --- a/test/fuzztest/getsetdevicemode_fuzzer/getsetdevicemode_fuzzer_test.cpp +++ b/test/fuzztest/getsetdevicemode_fuzzer/getsetdevicemode_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "getsetdevicemode_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,7 +30,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::SETMODE_DEVICE), data, size); - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::GETMODE_DEVICE), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_SET_DEVICE_MODE_IPC), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_GET_DEVICE_MODE_IPC), data, size); return 0; } diff --git a/test/fuzztest/getstate_fuzzer/getstate_fuzzer_test.cpp b/test/fuzztest/getstate_fuzzer/getstate_fuzzer_test.cpp index 60c17b3b..6d9b17cb 100644 --- a/test/fuzztest/getstate_fuzzer/getstate_fuzzer_test.cpp +++ b/test/fuzztest/getstate_fuzzer/getstate_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "getstate_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::GET_STATE), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_GET_STATE_IPC), data, size); return 0; } diff --git a/test/fuzztest/hibernate_fuzzer/hibernate_fuzzer_test.cpp b/test/fuzztest/hibernate_fuzzer/hibernate_fuzzer_test.cpp index e8fd5b46..87a41594 100644 --- a/test/fuzztest/hibernate_fuzzer/hibernate_fuzzer_test.cpp +++ b/test/fuzztest/hibernate_fuzzer/hibernate_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "hibernate_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::HIBERNATE), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_HIBERNATE_IPC), data, size); return 0; } diff --git a/test/fuzztest/iscollaborationscreenon_fuzzer/iscollaborationscreenon_fuzzer_test.cpp b/test/fuzztest/iscollaborationscreenon_fuzzer/iscollaborationscreenon_fuzzer_test.cpp index 797e8a43..27a258ed 100644 --- a/test/fuzztest/iscollaborationscreenon_fuzzer/iscollaborationscreenon_fuzzer_test.cpp +++ b/test/fuzztest/iscollaborationscreenon_fuzzer/iscollaborationscreenon_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "iscollaborationscreenon_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,6 +31,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::IS_COLLABORATION_SCREEN_ON), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_IS_COLLABORATION_SCREEN_ON_IPC), data, size); return 0; } diff --git a/test/fuzztest/isfoldscreenon_fuzzer/isfoldscreenon_fuzzer_test.cpp b/test/fuzztest/isfoldscreenon_fuzzer/isfoldscreenon_fuzzer_test.cpp index 4e4f1ead..e34c9a27 100644 --- a/test/fuzztest/isfoldscreenon_fuzzer/isfoldscreenon_fuzzer_test.cpp +++ b/test/fuzztest/isfoldscreenon_fuzzer/isfoldscreenon_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "isfoldscreenon_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::IS_FOLD_SCREEN_ON), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_IS_FOLD_SCREEN_ON_IPC), data, size); return 0; } diff --git a/test/fuzztest/isrunninglocktypesupported_fuzzer/isrunninglocktypesupported_fuzzer_test.cpp b/test/fuzztest/isrunninglocktypesupported_fuzzer/isrunninglocktypesupported_fuzzer_test.cpp index f706dffe..8d5568ca 100644 --- a/test/fuzztest/isrunninglocktypesupported_fuzzer/isrunninglocktypesupported_fuzzer_test.cpp +++ b/test/fuzztest/isrunninglocktypesupported_fuzzer/isrunninglocktypesupported_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "isrunninglocktypesupported_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,6 +31,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::IS_RUNNINGLOCK_TYPE_SUPPORTED), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_IS_RUNNING_LOCK_TYPE_SUPPORTED_IPC), data, size); return 0; } diff --git a/test/fuzztest/isscreenon_fuzzer/isscreenon_fuzzer_test.cpp b/test/fuzztest/isscreenon_fuzzer/isscreenon_fuzzer_test.cpp index 030549f9..764f89ad 100644 --- a/test/fuzztest/isscreenon_fuzzer/isscreenon_fuzzer_test.cpp +++ b/test/fuzztest/isscreenon_fuzzer/isscreenon_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "isscreenon_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::IS_SCREEN_ON), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_IS_SCREEN_ON_IPC), data, size); return 0; } diff --git a/test/fuzztest/isstandby_fuzzer/isstandby_fuzzer_test.cpp b/test/fuzztest/isstandby_fuzzer/isstandby_fuzzer_test.cpp index 9f1b7d10..a9e7946d 100644 --- a/test/fuzztest/isstandby_fuzzer/isstandby_fuzzer_test.cpp +++ b/test/fuzztest/isstandby_fuzzer/isstandby_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "isstandby_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::IS_STANDBY), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_IS_STANDBY_IPC), data, size); return 0; } diff --git a/test/fuzztest/lockscreenaftertimingout_fuzzer/lockscreenaftertimingout_fuzzer_test.cpp b/test/fuzztest/lockscreenaftertimingout_fuzzer/lockscreenaftertimingout_fuzzer_test.cpp index a8d0c525..f94ca560 100644 --- a/test/fuzztest/lockscreenaftertimingout_fuzzer/lockscreenaftertimingout_fuzzer_test.cpp +++ b/test/fuzztest/lockscreenaftertimingout_fuzzer/lockscreenaftertimingout_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "lockscreenaftertimingout_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,6 +31,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::LOCK_SCREEN_AFTER_TIMING_OUT), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_LOCK_SCREEN_AFTER_TIMING_OUT_IPC), data, size); return 0; } diff --git a/test/fuzztest/lockunlockisused_fuzzer/lockunlockisused_fuzzer_test.cpp b/test/fuzztest/lockunlockisused_fuzzer/lockunlockisused_fuzzer_test.cpp index 37b2a2cb..aafa1d84 100644 --- a/test/fuzztest/lockunlockisused_fuzzer/lockunlockisused_fuzzer_test.cpp +++ b/test/fuzztest/lockunlockisused_fuzzer/lockunlockisused_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "lockunlockisused_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,8 +30,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::RUNNINGLOCK_LOCK), data, size); - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::RUNNINGLOCK_UNLOCK), data, size); - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::RUNNINGLOCK_ISUSED), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_LOCK_IPC), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_UN_LOCK_IPC), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_IS_USED_IPC), data, size); return 0; } diff --git a/test/fuzztest/overridescreenofftime_fuzzer/overridescreenofftime_fuzzer_test.cpp b/test/fuzztest/overridescreenofftime_fuzzer/overridescreenofftime_fuzzer_test.cpp index 5cabe57b..fd7e435d 100644 --- a/test/fuzztest/overridescreenofftime_fuzzer/overridescreenofftime_fuzzer_test.cpp +++ b/test/fuzztest/overridescreenofftime_fuzzer/overridescreenofftime_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "overridescreenofftime_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_TIME), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_OVERRIDE_SCREEN_OFF_TIME_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::RESTORE_DISPLAY_OFF_TIME), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_RESTORE_SCREEN_OFF_TIME_IPC), data, size); return 0; } diff --git a/test/fuzztest/powermodecallback_fuzzer/powermodecallback_fuzzer_test.cpp b/test/fuzztest/powermodecallback_fuzzer/powermodecallback_fuzzer_test.cpp index 22d6711c..74f3d415 100644 --- a/test/fuzztest/powermodecallback_fuzzer/powermodecallback_fuzzer_test.cpp +++ b/test/fuzztest/powermodecallback_fuzzer/powermodecallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "powermodecallback_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::REG_POWER_MODE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_MODE_CALLBACK_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::UNREG_POWER_MODE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_MODE_CALLBACK_IPC), data, size); return 0; } diff --git a/test/fuzztest/powerstatecallback_fuzzer/powerstatecallback_fuzzer_test.cpp b/test/fuzztest/powerstatecallback_fuzzer/powerstatecallback_fuzzer_test.cpp index 197a2a05..91976d48 100644 --- a/test/fuzztest/powerstatecallback_fuzzer/powerstatecallback_fuzzer_test.cpp +++ b/test/fuzztest/powerstatecallback_fuzzer/powerstatecallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "powerstatecallback_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::REG_POWER_STATE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_STATE_CALLBACK_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::UNREG_POWER_STATE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_STATE_CALLBACK_IPC), data, size); return 0; } diff --git a/test/fuzztest/proxyrunninglock_fuzzer/proxyrunninglock_fuzzer_test.cpp b/test/fuzztest/proxyrunninglock_fuzzer/proxyrunninglock_fuzzer_test.cpp index 363f239c..e4e0406e 100644 --- a/test/fuzztest/proxyrunninglock_fuzzer/proxyrunninglock_fuzzer_test.cpp +++ b/test/fuzztest/proxyrunninglock_fuzzer/proxyrunninglock_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "proxyrunninglock_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::PROXY_RUNNINGLOCK), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCK_IPC), data, size); return 0; } diff --git a/test/fuzztest/proxyrunninglocks_fuzzer/proxyrunninglocks_fuzzer_test.cpp b/test/fuzztest/proxyrunninglocks_fuzzer/proxyrunninglocks_fuzzer_test.cpp index e269381d..34c7b0a7 100644 --- a/test/fuzztest/proxyrunninglocks_fuzzer/proxyrunninglocks_fuzzer_test.cpp +++ b/test/fuzztest/proxyrunninglocks_fuzzer/proxyrunninglocks_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "proxyrunninglocks_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::PROXY_RUNNINGLOCKS), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCKS_IPC), data, size); return 0; } diff --git a/test/fuzztest/queryrunninglocklists_fuzzer/queryrunninglocklists_fuzzer_test.cpp b/test/fuzztest/queryrunninglocklists_fuzzer/queryrunninglocklists_fuzzer_test.cpp index 39630b38..b57cdb00 100644 --- a/test/fuzztest/queryrunninglocklists_fuzzer/queryrunninglocklists_fuzzer_test.cpp +++ b/test/fuzztest/queryrunninglocklists_fuzzer/queryrunninglocklists_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "queryrunninglocklists_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::RUNNINGLOCK_QUERY), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_QUERY_RUNNING_LOCK_LISTS_IPC), data, size); return 0; } diff --git a/test/fuzztest/rebootdevice_fuzzer/rebootdevice_fuzzer_test.cpp b/test/fuzztest/rebootdevice_fuzzer/rebootdevice_fuzzer_test.cpp index c009546c..084ffe35 100644 --- a/test/fuzztest/rebootdevice_fuzzer/rebootdevice_fuzzer_test.cpp +++ b/test/fuzztest/rebootdevice_fuzzer/rebootdevice_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "rebootdevice_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,8 +30,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::REBOOT_DEVICE), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_REBOOT_DEVICE_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::REBOOT_DEVICE_FOR_DEPRECATED), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REBOOT_DEVICE_FOR_DEPRECATED_IPC), data, size); return 0; } diff --git a/test/fuzztest/refreshactivity_fuzzer/refreshactivity_fuzzer_test.cpp b/test/fuzztest/refreshactivity_fuzzer/refreshactivity_fuzzer_test.cpp index 0146507c..2ebe2e37 100644 --- a/test/fuzztest/refreshactivity_fuzzer/refreshactivity_fuzzer_test.cpp +++ b/test/fuzztest/refreshactivity_fuzzer/refreshactivity_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "refreshactivity_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::REFRESH_ACTIVITY), data, size); + uint32_t code = static_cast(IPowerMgrIpcCode::COMMAND_REFRESH_ACTIVITY_IPC); + g_serviceTest.TestPowerServiceStub(code, data, size); return 0; } diff --git a/test/fuzztest/releaserunninglock_fuzzer/releaserunninglock_fuzzer_test.cpp b/test/fuzztest/releaserunninglock_fuzzer/releaserunninglock_fuzzer_test.cpp index 04ac03c5..b69048f6 100644 --- a/test/fuzztest/releaserunninglock_fuzzer/releaserunninglock_fuzzer_test.cpp +++ b/test/fuzztest/releaserunninglock_fuzzer/releaserunninglock_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "releaserunninglock_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::RELEASE_RUNNINGLOCK), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_RELEASE_RUNNING_LOCK_IPC), data, size); return 0; } diff --git a/test/fuzztest/resetrunninglocks_fuzzer/resetrunninglocks_fuzzer_test.cpp b/test/fuzztest/resetrunninglocks_fuzzer/resetrunninglocks_fuzzer_test.cpp index f7687e22..22964dea 100644 --- a/test/fuzztest/resetrunninglocks_fuzzer/resetrunninglocks_fuzzer_test.cpp +++ b/test/fuzztest/resetrunninglocks_fuzzer/resetrunninglocks_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "resetrunninglocks_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::RESET_RUNNINGLOCKS), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_RESET_RUNNING_LOCKS_IPC), data, size); return 0; } diff --git a/test/fuzztest/runninglockcallback_fuzzer/runninglockcallback_fuzzer_test.cpp b/test/fuzztest/runninglockcallback_fuzzer/runninglockcallback_fuzzer_test.cpp index 3f19c0bd..62a83650 100644 --- a/test/fuzztest/runninglockcallback_fuzzer/runninglockcallback_fuzzer_test.cpp +++ b/test/fuzztest/runninglockcallback_fuzzer/runninglockcallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "runninglockcallback_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::REG_RUNNINGLOCK_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_RUNNING_LOCK_CALLBACK_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::UNREG_RUNNINGLOCK_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_RUNNING_LOCK_CALLBACK_IPC), data, size); return 0; } diff --git a/test/fuzztest/screenstatecallback_fuzzer/screenstatecallback_fuzzer_test.cpp b/test/fuzztest/screenstatecallback_fuzzer/screenstatecallback_fuzzer_test.cpp index 79dc7aac..42efad7d 100644 --- a/test/fuzztest/screenstatecallback_fuzzer/screenstatecallback_fuzzer_test.cpp +++ b/test/fuzztest/screenstatecallback_fuzzer/screenstatecallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "screenstatecallback_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::REG_SCREEN_OFF_PRE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_SCREEN_STATE_CALLBACK_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::UNREG_SCREEN_OFF_PRE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SCREEN_STATE_CALLBACK_IPC), data, size); return 0; } diff --git a/test/fuzztest/setdisplaysuspend_fuzzer/setdisplaysuspend_fuzzer_test.cpp b/test/fuzztest/setdisplaysuspend_fuzzer/setdisplaysuspend_fuzzer_test.cpp index b1e589b7..49517a3c 100644 --- a/test/fuzztest/setdisplaysuspend_fuzzer/setdisplaysuspend_fuzzer_test.cpp +++ b/test/fuzztest/setdisplaysuspend_fuzzer/setdisplaysuspend_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "setdisplaysuspend_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::SET_DISPLAY_SUSPEND), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_SET_DISPLAY_SUSPEND_IPC), data, size); return 0; } diff --git a/test/fuzztest/setforcetimingout_fuzzer/setforcetimingout_fuzzer_test.cpp b/test/fuzztest/setforcetimingout_fuzzer/setforcetimingout_fuzzer_test.cpp index 2f65194a..b7094477 100644 --- a/test/fuzztest/setforcetimingout_fuzzer/setforcetimingout_fuzzer_test.cpp +++ b/test/fuzztest/setforcetimingout_fuzzer/setforcetimingout_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "setforcetimingout_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ PowerFuzzerTest g_serviceTest; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::SET_FORCE_TIMING_OUT), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_SET_FORCE_TIMING_OUT_IPC), data, size); return 0; } diff --git a/test/fuzztest/setsuspendtag_fuzzer/setsuspendtag_fuzzer_test.cpp b/test/fuzztest/setsuspendtag_fuzzer/setsuspendtag_fuzzer_test.cpp index f1b0cc56..462fea58 100644 --- a/test/fuzztest/setsuspendtag_fuzzer/setsuspendtag_fuzzer_test.cpp +++ b/test/fuzztest/setsuspendtag_fuzzer/setsuspendtag_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "setsuspendtag_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::SET_SUSPEND_TAG), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_SET_SUSPEND_TAG_IPC), data, size); return 0; } diff --git a/test/fuzztest/shelldump_fuzzer/shelldump_fuzzer_test.cpp b/test/fuzztest/shelldump_fuzzer/shelldump_fuzzer_test.cpp index 4414dd9e..25128b3a 100644 --- a/test/fuzztest/shelldump_fuzzer/shelldump_fuzzer_test.cpp +++ b/test/fuzztest/shelldump_fuzzer/shelldump_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "shelldump_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::SHELL_DUMP), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_SHELL_DUMP_IPC), data, size); return 0; } diff --git a/test/fuzztest/shutdowndevice_fuzzer/shutdowndevice_fuzzer_test.cpp b/test/fuzztest/shutdowndevice_fuzzer/shutdowndevice_fuzzer_test.cpp index 02055423..846eb12e 100644 --- a/test/fuzztest/shutdowndevice_fuzzer/shutdowndevice_fuzzer_test.cpp +++ b/test/fuzztest/shutdowndevice_fuzzer/shutdowndevice_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "shutdowndevice_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::SHUTDOWN_DEVICE), data, size); + g_serviceTest.TestPowerServiceStub( + static_cast(IPowerMgrIpcCode::COMMAND_SHUT_DOWN_DEVICE_IPC), data, size); return 0; } diff --git a/test/fuzztest/suspenddevice_fuzzer/suspenddevice_fuzzer_test.cpp b/test/fuzztest/suspenddevice_fuzzer/suspenddevice_fuzzer_test.cpp index 5d45640b..f16a0c79 100644 --- a/test/fuzztest/suspenddevice_fuzzer/suspenddevice_fuzzer_test.cpp +++ b/test/fuzztest/suspenddevice_fuzzer/suspenddevice_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "suspenddevice_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::SUSPEND_DEVICE), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_SUSPEND_DEVICE_IPC), data, size); return 0; } diff --git a/test/fuzztest/synchibernatecallback_fuzzer/synchibernatecallback_fuzzer_test.cpp b/test/fuzztest/synchibernatecallback_fuzzer/synchibernatecallback_fuzzer_test.cpp index 225ee9e4..05c1917d 100644 --- a/test/fuzztest/synchibernatecallback_fuzzer/synchibernatecallback_fuzzer_test.cpp +++ b/test/fuzztest/synchibernatecallback_fuzzer/synchibernatecallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "synchibernatecallback_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::REG_SYNC_HIBERNATE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_SYNC_HIBERNATE_CALLBACK_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::UNREG_SYNC_HIBERNATE_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SYNC_HIBERNATE_CALLBACK_IPC), data, size); return 0; } diff --git a/test/fuzztest/syncshutdowncallback_fuzzer/syncshutdowncallback_fuzzer_test.cpp b/test/fuzztest/syncshutdowncallback_fuzzer/syncshutdowncallback_fuzzer_test.cpp index 5fc93eb1..4e778589 100644 --- a/test/fuzztest/syncshutdowncallback_fuzzer/syncshutdowncallback_fuzzer_test.cpp +++ b/test/fuzztest/syncshutdowncallback_fuzzer/syncshutdowncallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "syncshutdowncallback_fuzzer" #include "power_fuzzer.h" -#include "shutdown/shutdown_client_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,9 +30,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub( - static_cast(ShutdownClientInterfaceCode::CMD_REG_SYNC_SHUTDOWN_CALLBACK), data, size); - g_serviceTest.TestPowerServiceStub( - static_cast(ShutdownClientInterfaceCode::CMD_UNREG_SYNC_SHUTDOWN_CALLBACK), data, size); + g_serviceTest.TestPowerServiceStub(static_cast( + IPowerMgrIpcCode::COMMAND_REGISTER_SHUTDOWN_CALLBACK_IPC_IN_ISYNCSHUTDOWNCALLBACK_IN_INT), data, size); + g_serviceTest.TestPowerServiceStub(static_cast( + IPowerMgrIpcCode::COMMAND_UN_REGISTER_SHUTDOWN_CALLBACK_IPC_IN_ISYNCSHUTDOWNCALLBACK), data, size); return 0; } diff --git a/test/fuzztest/syncsleepcallback_fuzzer/syncsleepcallback_fuzzer_test.cpp b/test/fuzztest/syncsleepcallback_fuzzer/syncsleepcallback_fuzzer_test.cpp index b12daac9..b63048b7 100644 --- a/test/fuzztest/syncsleepcallback_fuzzer/syncsleepcallback_fuzzer_test.cpp +++ b/test/fuzztest/syncsleepcallback_fuzzer/syncsleepcallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "syncsleepcallback_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::REG_SYNC_SLEEP_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_SYNC_SLEEP_CALLBACK_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(PowerMgrInterfaceCode::UNREG_SYNC_SLEEP_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SYNC_SLEEP_CALLBACK_IPC), data, size); return 0; } diff --git a/test/fuzztest/takeovershutdowncallback_fuzzer/takeovershutdowncallback_fuzzer_test.cpp b/test/fuzztest/takeovershutdowncallback_fuzzer/takeovershutdowncallback_fuzzer_test.cpp index bfb315b9..288f9241 100644 --- a/test/fuzztest/takeovershutdowncallback_fuzzer/takeovershutdowncallback_fuzzer_test.cpp +++ b/test/fuzztest/takeovershutdowncallback_fuzzer/takeovershutdowncallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "takeovershutdowncallback_fuzzer" #include "power_fuzzer.h" -#include "shutdown/shutdown_client_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ PowerFuzzerTest g_serviceTest; g_serviceTest.TestPowerServiceStub( - static_cast(ShutdownClientInterfaceCode::CMD_REG_TAKEOVER_SHUTDOWN_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_SHUTDOWN_CALLBACK_IPC), data, size); g_serviceTest.TestPowerServiceStub( - static_cast(ShutdownClientInterfaceCode::CMD_UNREG_TAKEOVER_SHUTDOWN_CALLBACK), data, size); + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SHUTDOWN_CALLBACK_IPC), data, size); return 0; } diff --git a/test/fuzztest/wakeupdevice_fuzzer/wakeupdevice_fuzzer_test.cpp b/test/fuzztest/wakeupdevice_fuzzer/wakeupdevice_fuzzer_test.cpp index cfeaa5e7..981519e6 100644 --- a/test/fuzztest/wakeupdevice_fuzzer/wakeupdevice_fuzzer_test.cpp +++ b/test/fuzztest/wakeupdevice_fuzzer/wakeupdevice_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "wakeupdevice_fuzzer" #include "power_fuzzer.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ PowerFuzzerTest g_serviceTest; - g_serviceTest.TestPowerServiceStub(static_cast(PowerMgrInterfaceCode::WAKEUP_DEVICE), data, size); + g_serviceTest.TestPowerServiceStub(static_cast(IPowerMgrIpcCode::COMMAND_WAKEUP_DEVICE_IPC), data, size); return 0; } diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index 963d52bb..6c765b68 100644 --- a/test/systemtest/BUILD.gn +++ b/test/systemtest/BUILD.gn @@ -68,6 +68,13 @@ if (has_hiviewdfx_hisysevent_part) { ohos_systemtest("ces_system") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/ces_system_test.cpp" ] configs = [ @@ -191,6 +198,13 @@ ohos_systemtest("test_power_mgr_system") { sources = [ "src/power_mgr_system_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 15b113f4..80170c73 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -92,6 +92,13 @@ ohos_unittest("test_power_mgr_client") { sources = [ "src/interface_test/power_mgr_client_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -119,6 +126,13 @@ ohos_unittest("test_register_callback_mode") { sources = [ "src/power_register_callback_mode_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -141,6 +155,13 @@ ohos_unittest("test_power_get_mode") { sources = [ "src/power_get_mode_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -163,6 +184,13 @@ ohos_unittest("test_power_set_mode") { sources = [ "src/power_set_mode_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -200,9 +228,35 @@ ohos_unittest("test_power_device_mode") { external_deps = deps_ex } +ohos_unittest("power_client_callback_test") { + module_out_path = module_output_path + + sources = [ "src/power_client_callback_test.cpp" ] + + configs = [ + "${powermgr_utils_path}:utils_config", + ":module_private_config", + "${powermgr_utils_path}:coverage_flags", + ] + + deps = [ + "${powermgr_inner_api}:powermgr_client", + "${powermgr_service_path}:powermgrservice", + ] + + external_deps = deps_ex +} + ohos_unittest("test_running_lock") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/interface_test/running_lock_test.cpp" ] configs = [ @@ -213,6 +267,7 @@ ohos_unittest("test_running_lock") { deps = [ "${powermgr_inner_api}:powermgr_client", + "${powermgr_service_path}:powermgr_proxy", "${powermgr_service_path}:powermgrservice", "//third_party/googletest:gtest_main", ] @@ -331,6 +386,13 @@ ohos_unittest("test_power_state_machine") { sources = [ "src/interface_test/power_state_machine_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -381,6 +443,13 @@ ohos_unittest("test_power_mgr_mock") { ohos_unittest("test_power_mgr_fail_check") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/power_mgr_fail_check_test.cpp" ] configs = [ @@ -543,11 +612,17 @@ ohos_unittest("test_power_mock_object") { module_out_path = module_output_path sources = [ - "${powermgr_service_zidl}/src/power_mgr_proxy.cpp", "mock/mock_power_remote_object.cpp", "src/mock/power_mock_object_test.cpp", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -557,6 +632,7 @@ ohos_unittest("test_power_mock_object") { deps = [ "${powermgr_inner_api}:powermgr_client", + "${powermgr_service_path}:powermgr_proxy", "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "//third_party/googletest:gtest_main", @@ -569,12 +645,18 @@ ohos_unittest("test_mock_parcel") { module_out_path = module_output_path sources = [ - "${powermgr_service_zidl}/src/power_mgr_proxy.cpp", "mock/mock_message_parcel.cpp", "mock/mock_parcel.cpp", "src/mock/power_mock_parcel_test.cpp", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -584,6 +666,7 @@ ohos_unittest("test_mock_parcel") { deps = [ "${powermgr_inner_api}:powermgr_client", + "${powermgr_service_path}:powermgr_proxy", "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "${powermgr_utils_path}/permission:power_permission", @@ -597,11 +680,17 @@ ohos_unittest("test_mock_peer") { module_out_path = module_output_path sources = [ - "${powermgr_service_zidl}/src/power_mgr_proxy.cpp", "mock/mock_peer_holder.cpp", "src/mock/power_mock_peer_test.cpp", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -611,6 +700,7 @@ ohos_unittest("test_mock_peer") { deps = [ "${powermgr_inner_api}:powermgr_client", + "${powermgr_service_path}:powermgr_proxy", "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "//third_party/googletest:gtest_main", @@ -623,12 +713,18 @@ ohos_unittest("test_mock_proxy") { module_out_path = module_output_path sources = [ - "${powermgr_service_zidl}/src/power_mgr_proxy.cpp", "mock/mock_message_parcel.cpp", "mock/mock_parcel.cpp", "src/mock/power_mock_proxy_test.cpp", ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -643,6 +739,7 @@ ohos_unittest("test_mock_proxy") { deps = [ "${powermgr_inner_api}:powermgr_client", + "${powermgr_service_path}:powermgr_proxy", "${powermgr_service_path}:powermgr_stub", "${powermgr_service_path}:powermgrservice", "//third_party/googletest:gtest_main", @@ -657,6 +754,13 @@ ohos_unittest("power_state_machine_native_test") { sources = [ "src/native_power_state_machine_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -679,6 +783,13 @@ ohos_unittest("test_running_lock_native") { sources = [ "src/running_lock_native_test.cpp" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + configs = [ "${powermgr_utils_path}:utils_config", ":module_private_config", @@ -736,6 +847,13 @@ ohos_unittest("test_device_state_action_native") { module_out_path = module_output_path defines += defs + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/device_state_action_native_test.cpp" ] configs = [ @@ -781,6 +899,13 @@ ohos_unittest("test_power_mgr_client_native") { module_out_path = module_output_path defines += defs + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/power_mgr_client_native_test.cpp" ] configs = [ @@ -803,6 +928,14 @@ ohos_unittest("test_power_mgr_client_native") { ohos_unittest("power_mode_module_native_test") { module_out_path = module_output_path defines += defs + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/power_mode_module_native_test.cpp" ] configs = [ "${powermgr_utils_path}:utils_config", @@ -822,6 +955,13 @@ ohos_unittest("test_running_lock_hub_native") { module_out_path = module_output_path defines += defs + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + include_dirs = [ "${powermgr_service_path}/native/src/actions/default/suspend" ] @@ -878,6 +1018,13 @@ ohos_unittest("test_running_lock_mock") { ohos_unittest("test_power_suspend_parse") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/interface_test/power_suspend_parse_test.cpp" ] configs = [ @@ -915,6 +1062,13 @@ ohos_unittest("test_power_suspend_parse") { ohos_unittest("test_power_wakeup_parse") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/interface_test/power_wakeup_parse_test.cpp" ] configs = [ @@ -952,6 +1106,13 @@ ohos_unittest("test_power_wakeup_parse") { ohos_unittest("test_power_suspend_controller") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/interface_test/power_suspend_controller_test.cpp" ] configs = [ @@ -991,6 +1152,13 @@ ohos_unittest("test_power_suspend_controller") { ohos_unittest("test_power_suspend") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/scenario_test/wakeup_suspend/power_suspend_test.cpp" ] configs = [ @@ -1030,6 +1198,13 @@ ohos_unittest("test_power_suspend") { ohos_unittest("test_power_wakeup_controller") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/interface_test/power_wakeup_controller_test.cpp" ] configs = [ @@ -1069,6 +1244,13 @@ ohos_unittest("test_power_wakeup_controller") { ohos_unittest("test_power_wakeup") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/scenario_test/wakeup_suspend/power_wakeup_test.cpp" ] configs = [ @@ -1127,6 +1309,13 @@ ohos_unittest("test_power_shutdown_clinet") { ohos_unittest("test_power_getcontroller_mock") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/power_getcontroller_mock_test.cpp" ] configs = [ @@ -1166,6 +1355,13 @@ ohos_unittest("test_power_getcontroller_mock") { ohos_unittest("test_power_screenon_mock") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/power_screenon_mock_test.cpp" ] configs = [ @@ -1205,6 +1401,13 @@ ohos_unittest("test_power_screenon_mock") { ohos_unittest("test_power_parsesources_mock") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../cfi_blocklist.txt" + } + sources = [ "src/power_parsesources_mock_test.cpp" ] configs = [ @@ -1337,6 +1540,7 @@ ohos_unittest("test_running_lock_timer_handler") { group("unittest") { testonly = true deps = [ + ":power_client_callback_test", ":power_mode_module_native_test", ":power_state_machine_native_test", ":test_device_state_action_native", diff --git a/test/unittest/include/interface_test/running_lock_test.h b/test/unittest/include/interface_test/running_lock_test.h index c7bf741c..3ec61e26 100644 --- a/test/unittest/include/interface_test/running_lock_test.h +++ b/test/unittest/include/interface_test/running_lock_test.h @@ -31,6 +31,15 @@ namespace OHOS { namespace PowerMgr { class RunningLockTest : public testing::Test { public: + RunningLockTest() + { + sptr service = DelayedSpSingleton::GetInstance(); + service->OnStart(); + stub_ = static_cast(service); + } + + ~RunningLockTest() = default; + void TestRunningLockInnerExisit(sptr& token, RunningLockInfo& runningLockInfo) { auto lockMap = runningLockMgr_->GetRunningLockMap(); @@ -55,7 +64,8 @@ public: } static std::shared_ptr runningLockMgr_; - static sptr pmsTest_; +protected: + sptr stub_ {nullptr}; }; } // namespace PowerMgr } // namespace OHOS diff --git a/test/unittest/include/power_client_callback_test.h b/test/unittest/include/power_client_callback_test.h new file mode 100644 index 00000000..f6a467c9 --- /dev/null +++ b/test/unittest/include/power_client_callback_test.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef POWERMGR_CLIENT_CALLBACK_TEST_H +#define POWERMGR_CLIENT_CALLBACK_TEST_H + +#include + +#include "power_mgr_service.h" +#include "power_runninglock_callback_stub.h" +#include "screen_off_pre_callback_stub.h" +#include "sync_hibernate_callback_stub.h" +#include "sync_sleep_callback_stub.h" + +namespace OHOS { +namespace PowerMgr { +class PowerMgrClientCallbackTest : public testing::Test { +public: + + class PowerRunningLockTest1Callback : public IRemoteStub { + public: + PowerRunningLockTest1Callback() {}; + virtual ~PowerRunningLockTest1Callback() {}; + virtual void HandleRunningLockMessage(std::string message) override; + }; + + class ScreenOffPreTest1Callback : public IRemoteStub { + public: + ScreenOffPreTest1Callback() {}; + virtual ~ScreenOffPreTest1Callback() {}; + virtual void OnScreenStateChanged(uint32_t state) override; + }; + + class PowerSyncHibernateTest1Callback : public IRemoteStub { + public: + PowerSyncHibernateTest1Callback() {}; + virtual ~PowerSyncHibernateTest1Callback() {}; + virtual void OnSyncHibernate() override; + virtual void OnSyncWakeup(bool hibernateResult = false) override; + }; + + class PowerSyncSleepTest1Callback : public IRemoteStub { + public: + PowerSyncSleepTest1Callback() {}; + virtual ~PowerSyncSleepTest1Callback() {}; + virtual void OnSyncSleep(bool onForceSleep) override; + virtual void OnSyncWakeup(bool onForceSleep) override; + }; +}; +} // namespace PowerMgr +} // namespace OHOS +#endif // POWERMGR_CLIENT_CALLBACK_TEST_H \ No newline at end of file diff --git a/test/unittest/include/servicetest/powermgr_service_test_proxy.h b/test/unittest/include/servicetest/powermgr_service_test_proxy.h index 17641b3b..be1805b2 100644 --- a/test/unittest/include/servicetest/powermgr_service_test_proxy.h +++ b/test/unittest/include/servicetest/powermgr_service_test_proxy.h @@ -22,6 +22,7 @@ #include #include +#include "hilog/log.h" #include "iremote_object.h" #include "ipower_mode_callback.h" #include "ipower_state_callback.h" @@ -40,46 +41,46 @@ public: PowerMgrServiceTestProxy(const sptr& service); ~PowerMgrServiceTestProxy() = default; - PowerErrors CreateRunningLock(const sptr& remoteObj, const RunningLockInfo& runningLockInfo); - bool ReleaseRunningLock(const sptr& remoteObj, const std::string& name = ""); - bool IsRunningLockTypeSupported(RunningLockType type); - bool Lock(const sptr& remoteObj, int32_t timeOutMs = -1); - bool UnLock(const sptr& remoteObj, const std::string& name = ""); - bool ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid); - bool ProxyRunningLocks(bool isProxied, - const std::vector>& processInfos); - bool ResetRunningLocks(); - bool IsUsed(const sptr& remoteObj); - PowerErrors SuspendDevice(int64_t callTimeMs, - SuspendDeviceType reason = SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, - bool suspendImmed = false); - PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason = WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, - const std::string& detail = std::string("app call")); - bool RefreshActivity(int64_t callTimeMs, UserActivityType type = UserActivityType::USER_ACTIVITY_TYPE_OTHER, - bool needChangeBacklight = true); - PowerErrors OverrideScreenOffTime(int64_t timeout); - PowerErrors RestoreScreenOffTime(); - PowerState GetState(); - bool IsScreenOn(bool needPrintLog = true); - PowerErrors ForceSuspendDevice(int64_t callTimeMs); - PowerErrors RebootDevice(const std::string& reason); - PowerErrors RebootDeviceForDeprecated(const std::string& reason); - PowerErrors ShutDownDevice(const std::string& reason); - bool RegisterPowerStateCallback(const sptr& callback, bool isSync = true); - bool UnRegisterPowerStateCallback(const sptr& callback); - bool RegisterPowerModeCallback(const sptr& callback); - bool UnRegisterPowerModeCallback(const sptr& callback); - bool RegisterScreenStateCallback(int32_t remainTime, const sptr& callback); - bool UnRegisterScreenStateCallback(const sptr& callback); - bool RegisterRunningLockCallback(const sptr& callback); - bool UnRegisterRunningLockCallback(const sptr& callback); - bool SetDisplaySuspend(bool enable); - PowerErrors SetDeviceMode(const PowerMode& mode); - PowerMode GetDeviceMode(); - std::string ShellDump(const std::vector& args, uint32_t argc); - PowerErrors IsStandby(bool& isStandby); + int32_t CreateRunningLockIpc( + const sptr& remoteObj, const RunningLockInfo& runningLockInfo, int32_t& powerError); + int32_t ReleaseRunningLockIpc(const sptr& remoteObj, const std::string& name = ""); + int32_t IsRunningLockTypeSupportedIpc(int32_t lockType, bool& lockSupported); + int32_t LockIpc(const sptr& remoteObj, int32_t timeOutMs, int32_t& powerError); + int32_t UnLockIpc(const sptr& remoteObj, const std::string& name, int32_t& powerError); + int32_t ProxyRunningLockIpc(bool isProxied, pid_t pid, pid_t uid); + int32_t ProxyRunningLocksIpc(bool isProxied, const VectorPair& vectorPairInfos); + int32_t ResetRunningLocksIpc(); + int32_t IsUsedIpc(const sptr& remoteObj, bool& isUsed); + int32_t SuspendDeviceIpc(int64_t callTimeMs, int32_t reasonValue, bool suspendImmed, + const std::string& apiVersion, int32_t& powerError); + int32_t WakeupDeviceIpc(int64_t callTimeMs, int32_t reasonValue, const std::string& details, + const std::string& apiVersion, int32_t& powerError); + int32_t RefreshActivityIpc(int64_t callTimeMs, int32_t activityType, bool needChangeBacklight = true); + int32_t OverrideScreenOffTimeIpc(int64_t timeout, int32_t& powerError); + int32_t RestoreScreenOffTimeIpc(const std::string& apiVersion, int32_t& powerError); + int32_t GetStateIpc(int32_t& powerState); + int32_t IsScreenOnIpc(bool needPrintLog, bool& isScreenOn); + int32_t ForceSuspendDeviceIpc(int64_t callTimeMs); + int32_t RebootDeviceIpc(const std::string& reason, int32_t& powerError); + int32_t RebootDeviceForDeprecatedIpc(const std::string& reason, int32_t& powerError); + int32_t ShutDownDeviceIpc(const std::string& reason, int32_t& powerError); + int32_t RegisterPowerStateCallbackIpc(const sptr& callback, bool isSync = true); + int32_t UnRegisterPowerStateCallbackIpc(const sptr& callback); + int32_t RegisterPowerModeCallbackIpc(const sptr& callback); + int32_t UnRegisterPowerModeCallbackIpc(const sptr& callback); + int32_t RegisterScreenStateCallbackIpc(int32_t remainTime, const sptr& callback); + int32_t UnRegisterScreenStateCallbackIpc(const sptr& callback); + int32_t RegisterRunningLockCallbackIpc(const sptr& callback); + int32_t UnRegisterRunningLockCallbackIpc(const sptr& callback); + int32_t SetDisplaySuspendIpc(bool enable); + int32_t SetDeviceModeIpc(int32_t modeValue, int32_t& powerError); + int32_t GetDeviceModeIpc(int32_t& powerMode); + int32_t ShellDumpIpc(const std::vector& args, uint32_t argc, std::string& returnDump); + int32_t IsStandbyIpc(bool& isStandby, int32_t& powerError); private: + static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD000F00, "PowerTest"}; sptr stub_ {nullptr}; + const int VECTOR_MAX_SIZE = 102400; }; } // namespace PowerMgr } // namespace OHOS diff --git a/test/unittest/src/interface_test/power_mgr_service_test.cpp b/test/unittest/src/interface_test/power_mgr_service_test.cpp index d7f38306..9d89ff5b 100644 --- a/test/unittest/src/interface_test/power_mgr_service_test.cpp +++ b/test/unittest/src/interface_test/power_mgr_service_test.cpp @@ -176,7 +176,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService005, TestSize.Level0) powerMgrClient.WakeupDevice(); EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(-1) == PowerErrors::ERR_OK); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService005: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService005 function end!"); } @@ -228,7 +228,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService008, TestSize.Level0) EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(-1) == PowerErrors::ERR_OK); powerMgrClient.WakeupDevice(); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService008: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService008 function end!"); } @@ -247,7 +247,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService009, TestSize.Level0) EXPECT_TRUE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); sleep(PARM_TWO); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService009: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService009 function end!"); } @@ -264,7 +264,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService010, TestSize.Level0) EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(0) == PowerErrors::ERR_OK); EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService010: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService010 function end!"); } @@ -281,7 +281,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService011, TestSize.Level0) EXPECT_FALSE(powerMgrClient.OverrideScreenOffTime(-1) == PowerErrors::ERR_OK);; EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService011: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService011 function end!"); } @@ -301,7 +301,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService012, TestSize.Level0) powerMgrClient.WakeupDevice(); sleep(PARM_TWO); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService012: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService012 function end!"); } @@ -319,7 +319,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService013, TestSize.Level0) EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); powerMgrClient.WakeupDevice(); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService013: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService013 function end!"); } @@ -337,7 +337,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService014, TestSize.Level0) EXPECT_FALSE(powerMgrClient.RestoreScreenOffTime() == PowerErrors::ERR_OK); powerMgrClient.WakeupDevice(); EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrService014: Prepare Fail, Screen is OFF."; - + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService014 function end!"); } @@ -405,6 +405,7 @@ HWTEST_F (PowerMgrServiceTest, PowerMgrService018, TestSize.Level0) runningLock->Lock(); ASSERT_TRUE(runningLock->IsUsed()) << "runningLock->IsUsed() != true"; runningLock->UnLock(); + EXPECT_EQ(powerMgrClient.ResetRunningLocks(), true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService018 function end!"); } @@ -820,4 +821,18 @@ HWTEST_F(PowerMgrServiceTest, PowerMgrServiceTest030, TestSize.Level2) POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService030 function end!"); } #endif + +/** + * @tc.name: PowerMgrService031 + * @tc.desc: Test ForceSuspendDevice. + * @tc.type: FUNC + */ +HWTEST_F(PowerMgrServiceTest, PowerMgrService031, TestSize.Level0) +{ + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService031 function start!"); + auto& powerMgrClient = PowerMgrClient::GetInstance(); + EXPECT_EQ(powerMgrClient.ForceSuspendDevice(""), PowerErrors::ERR_OK); + powerMgrClient.WakeupDevice(); + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceTest::PowerMgrService031 function end!"); +} } diff --git a/test/unittest/src/interface_test/running_lock_test.cpp b/test/unittest/src/interface_test/running_lock_test.cpp index 3e0d0edd..b9366bb9 100644 --- a/test/unittest/src/interface_test/running_lock_test.cpp +++ b/test/unittest/src/interface_test/running_lock_test.cpp @@ -18,6 +18,7 @@ #include #include "actions/irunning_lock_action.h" +#include "power_mgr_proxy.h" #include "power_mgr_service.h" #include "running_lock_mgr.h" #include "power_log.h" @@ -28,6 +29,8 @@ using namespace OHOS; using namespace std; namespace { +constexpr int32_t VECTOR_MAX_SIZE = 102400; +constexpr int32_t TEST_PROCESS_COUNT = 2000; constexpr int32_t US_PER_MS = 1000; constexpr int32_t app0Uid = 8; constexpr int32_t app1Uid = 9; @@ -39,7 +42,7 @@ namespace { * @tc.desc: Test RunningLockInnerKit function, connect PowerMgrService and call member function. * @tc.type: FUNC */ -HWTEST_F (RunningLockTest, RunningLockTest001, TestSize.Level0) +HWTEST_F(RunningLockTest, RunningLockTest001, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "RunningLockTest001 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -60,7 +63,7 @@ HWTEST_F (RunningLockTest, RunningLockTest001, TestSize.Level0) * @tc.desc: Test RunningLockInnerKit function, timeout lock. * @tc.type: FUNC */ -HWTEST_F (RunningLockTest, RunningLockTest002, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest002, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest002 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -90,7 +93,7 @@ HWTEST_F (RunningLockTest, RunningLockTest002, TestSize.Level1) * @tc.desc: Test RunningLockInnerKit function, timeout lock. * @tc.type: FUNC */ -HWTEST_F (RunningLockTest, RunningLockTest003, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest003, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest003 function start!"); if (false) { @@ -134,7 +137,7 @@ HWTEST_F (RunningLockTest, RunningLockTest003, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI6NWQD */ -HWTEST_F (RunningLockTest, RunningLockTest004, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest004, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest004 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -173,7 +176,7 @@ HWTEST_F (RunningLockTest, RunningLockTest004, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI6S0YY */ -HWTEST_F (RunningLockTest, RunningLockTest005, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest005, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest005 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -197,7 +200,7 @@ HWTEST_F (RunningLockTest, RunningLockTest005, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI6S0YY */ -HWTEST_F (RunningLockTest, RunningLockTest006, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest006, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest006 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -226,7 +229,7 @@ HWTEST_F (RunningLockTest, RunningLockTest006, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI6S0YY */ -HWTEST_F (RunningLockTest, RunningLockTest007, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest007, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest007 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -256,7 +259,7 @@ HWTEST_F (RunningLockTest, RunningLockTest007, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI6S0YY */ -HWTEST_F (RunningLockTest, RunningLockTest008, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest008, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest008 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -280,7 +283,7 @@ HWTEST_F (RunningLockTest, RunningLockTest008, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI6S0YY */ -HWTEST_F (RunningLockTest, RunningLockTest009, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest009, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest009 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -317,7 +320,7 @@ HWTEST_F (RunningLockTest, RunningLockTest009, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI6S0YY */ -HWTEST_F (RunningLockTest, RunningLockTest010, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest010, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest010 function start!"); pid_t curUid = 1; @@ -334,7 +337,7 @@ HWTEST_F (RunningLockTest, RunningLockTest010, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI7405P */ -HWTEST_F (RunningLockTest, RunningLockTest011, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest011, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest011 function start!"); auto runninglockProxy = std::make_shared(); @@ -353,7 +356,7 @@ HWTEST_F (RunningLockTest, RunningLockTest011, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI7405P */ -HWTEST_F (RunningLockTest, RunningLockTest012, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest012, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest012 function start!"); auto runninglockProxy = std::make_shared(); @@ -374,7 +377,7 @@ HWTEST_F (RunningLockTest, RunningLockTest012, TestSize.Level1) * @tc.type: FUNC * @tc.require: issueI7405P */ -HWTEST_F (RunningLockTest, RunningLockTest013, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest013, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest013 function start!"); auto runninglockProxy = std::make_shared(); @@ -398,9 +401,15 @@ HWTEST_F(RunningLockTest, RunningLockTest014, TestSize.Level1) pid_t curUid = getuid(); pid_t curPid = getpid(); std::vector> processInfos; - processInfos.push_back(std::pair(curPid, curUid)); auto& powerMgrClient = PowerMgrClient::GetInstance(); + EXPECT_FALSE(powerMgrClient.ProxyRunningLocks(true, processInfos)); + processInfos.emplace_back(curPid, curUid); EXPECT_TRUE(powerMgrClient.ProxyRunningLocks(true, processInfos)); + + for (int i = 0; i < TEST_PROCESS_COUNT; ++i) { + processInfos.emplace_back(static_cast(US_PER_MS + i), static_cast(TEST_PROCESS_COUNT + i)); + } + EXPECT_FALSE(powerMgrClient.ProxyRunningLocks(true, processInfos)); POWER_HILOGI(LABEL_TEST, "RunningLockTest014 function end!"); } @@ -441,7 +450,7 @@ HWTEST_F(RunningLockTest, RunningLockTest015, TestSize.Level1) * @tc.type: FUNC * @tc.require */ -HWTEST_F (RunningLockTest, RunningLockTest016, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest016, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest016 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -467,7 +476,7 @@ HWTEST_F (RunningLockTest, RunningLockTest016, TestSize.Level1) * @tc.type: FUNC * @tc.require */ -HWTEST_F (RunningLockTest, RunningLockTest017, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest017, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest017 function start!"); auto& powerMgrClient = PowerMgrClient::GetInstance(); @@ -485,6 +494,8 @@ HWTEST_F (RunningLockTest, RunningLockTest017, TestSize.Level1) EXPECT_FALSE(runningLock->IsUsed()); EXPECT_TRUE(powerMgrClient.ProxyRunningLock(false, curPid, 0)); EXPECT_TRUE(runningLock->IsUsed()); + std::vector hugeWorkSource(VECTOR_MAX_SIZE + 1, 1); + EXPECT_EQ(runningLock->UpdateWorkSource(hugeWorkSource), E_INNER_ERR); runningLock->UnLock(); POWER_HILOGI(LABEL_TEST, "RunningLockTest017 function end!"); } @@ -495,7 +506,7 @@ HWTEST_F (RunningLockTest, RunningLockTest017, TestSize.Level1) * @tc.type: FUNC * @tc.require */ -HWTEST_F (RunningLockTest, RunningLockTest018, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest018, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest018 function start!"); auto runninglockProxy = std::make_shared(); @@ -505,7 +516,7 @@ HWTEST_F (RunningLockTest, RunningLockTest018, TestSize.Level1) sptr remoteObj2 = nullptr; runninglockProxy->AddRunningLock(pid, uid, remoteObj); runninglockProxy->RemoveRunningLock(pid, uid, remoteObj2); - + EXPECT_TRUE(runninglockProxy->UpdateWorkSource(pid, uid, remoteObj, {{0, {"test", false}}})); runninglockProxy->RemoveRunningLock(pid, uid, remoteObj); EXPECT_TRUE(runninglockProxy->IncreaseProxyCnt(pid, uid)); @@ -519,7 +530,7 @@ HWTEST_F (RunningLockTest, RunningLockTest018, TestSize.Level1) * @tc.type: FUNC * @tc.require */ -HWTEST_F (RunningLockTest, RunningLockTest019, TestSize.Level1) +HWTEST_F(RunningLockTest, RunningLockTest019, TestSize.Level1) { POWER_HILOGI(LABEL_TEST, "RunningLockTest019 function start!"); auto runninglockProxy = std::make_shared(); @@ -529,7 +540,7 @@ HWTEST_F (RunningLockTest, RunningLockTest019, TestSize.Level1) sptr remoteObj2 = nullptr; runninglockProxy->AddRunningLock(pid, uid, remoteObj); runninglockProxy->RemoveRunningLock(pid, uid, remoteObj2); - + EXPECT_TRUE(runninglockProxy->UpdateWorkSource(pid, uid, remoteObj, {{0, {"test019", false}}})); EXPECT_TRUE(runninglockProxy->UpdateProxyState(pid, uid, remoteObj, true)); EXPECT_TRUE(runninglockProxy->UpdateProxyState(pid, uid, remoteObj, false)); @@ -538,4 +549,26 @@ HWTEST_F (RunningLockTest, RunningLockTest019, TestSize.Level1) EXPECT_TRUE(runninglockProxy->DecreaseProxyCnt(pid, uid)); POWER_HILOGI(LABEL_TEST, "RunningLockTest019 function end!"); } + +HWTEST_F(RunningLockTest, RunningLockTest020, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "RunningLockTest020 function start!"); + EXPECT_NE(stub_, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor()); + data.WriteInt32(1); + VectorPair vectorPairInfos; + vectorPairInfos.processInfos.resize(VECTOR_MAX_SIZE + 1); + for (size_t i = 0; i < vectorPairInfos.processInfos.size(); ++i) { + vectorPairInfos.processInfos[i] = {static_cast(i), static_cast(i + 100)}; + } + EXPECT_FALSE(data.WriteParcelable(&vectorPairInfos)); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCKS_IPC), data, reply, option); + EXPECT_EQ(result, ERR_INVALID_DATA); + POWER_HILOGI(LABEL_TEST, "RunningLockTest020 function end!"); +} } // namespace \ No newline at end of file diff --git a/test/unittest/src/interface_test/shutdown_client_test.cpp b/test/unittest/src/interface_test/shutdown_client_test.cpp index 88d8f9cd..4c45d063 100644 --- a/test/unittest/src/interface_test/shutdown_client_test.cpp +++ b/test/unittest/src/interface_test/shutdown_client_test.cpp @@ -110,6 +110,11 @@ HWTEST_F(ShutdownClientTest, RegisterShutdownCallback001, TestSize.Level0) EXPECT_FALSE(g_isOnSyncShutdown); EXPECT_TRUE(g_isOnTakeOverShutdown); + powerMgrClient.RebootDeviceForDeprecated("RegisterShutdownCallback001"); + EXPECT_FALSE(g_isOnAsyncShutdown); + EXPECT_FALSE(g_isOnSyncShutdown); + EXPECT_TRUE(g_isOnTakeOverShutdown); + powerMgrClient.ShutDownDevice("RegisterShutdownCallback001"); EXPECT_FALSE(g_isOnAsyncShutdown); EXPECT_FALSE(g_isOnSyncShutdown); diff --git a/test/unittest/src/mock/power_mock_object_test.cpp b/test/unittest/src/mock/power_mock_object_test.cpp index 197572e0..9cc1985a 100644 --- a/test/unittest/src/mock/power_mock_object_test.cpp +++ b/test/unittest/src/mock/power_mock_object_test.cpp @@ -28,6 +28,7 @@ #include "running_lock.h" #include "running_lock_info.h" #include "running_lock_token_stub.h" +#include "power_mgr_async_reply_stub.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -58,6 +59,12 @@ namespace { */ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest001, TestSize.Level2) { + int32_t powerError = 1; + int32_t timeOutMs = -1; + int32_t powerState = -1; + int32_t ret = 0; + std::string name; + bool isUsed = false; POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest001 function start!"); PowerMode mode = PowerMode::NORMAL_MODE; sptr remote = new MockPowerRemoteObject(); @@ -69,13 +76,17 @@ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest001, TestSize.Level2) stateCallbackProxy->OnPowerStateChanged(state); sptr token = new RunningLockTokenStub(); RunningLockInfo info("test1", RunningLockType::RUNNINGLOCK_SCREEN); - EXPECT_FALSE(sptrProxy->CreateRunningLock(token, info) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->ReleaseRunningLock(token)); - state = sptrProxy->GetState(); - EXPECT_EQ(state, PowerState::UNKNOWN); - EXPECT_FALSE(sptrProxy->Lock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->UnLock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->IsUsed(token)); + sptrProxy->CreateRunningLockIpc(token, info, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + EXPECT_NE(sptrProxy->ReleaseRunningLockIpc(token, name), ERR_OK); + ret = sptrProxy->GetStateIpc(powerState); + EXPECT_EQ(ret, ERR_TRANSACTION_FAILED); + sptrProxy->LockIpc(token, timeOutMs, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->UnLockIpc(token, name, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->IsUsedIpc(token, isUsed); + EXPECT_FALSE(isUsed); POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest001 function end!"); } @@ -90,25 +101,36 @@ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest002, TestSize.Level2) POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest002 function start!"); pid_t uid = 0; pid_t pid = 0; + int32_t powerError = 1; + int32_t powerMode = 0; + int32_t ret = 0; + std::string apiVersion = "-1"; + bool lockTypeSupported = false; sptr remote = new MockPowerRemoteObject(); std::shared_ptr sptrProxy = std::make_shared(remote); PowerMode mode = PowerMode::NORMAL_MODE; int32_t suspendReason = (static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX)) + 1; SuspendDeviceType abnormaltype = SuspendDeviceType(suspendReason); - auto error1 = sptrProxy->SuspendDevice(0, abnormaltype, false); - EXPECT_EQ(error1, PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_FALSE(sptrProxy->SetDisplaySuspend(true)); - auto error2 = - sptrProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, std::string("app call")); - EXPECT_EQ(error2, PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_FALSE(sptrProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_ATTENTION, true)); - EXPECT_EQ(sptrProxy->SetDeviceMode(mode), PowerErrors::ERR_CONNECTION_FAIL); - auto ret = sptrProxy->GetDeviceMode(); - EXPECT_TRUE(ret == mode); - EXPECT_FALSE(sptrProxy->ProxyRunningLock(true, pid, uid)); - EXPECT_FALSE(sptrProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND)); - EXPECT_FALSE(sptrProxy->OverrideScreenOffTime(200) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->RestoreScreenOffTime() == PowerErrors::ERR_OK); + ret = sptrProxy->SuspendDeviceIpc(0, static_cast(abnormaltype), false, apiVersion, powerError); + EXPECT_EQ(ret, ERR_TRANSACTION_FAILED); + EXPECT_NE(sptrProxy->SetDisplaySuspendIpc(true), ERR_OK); + ret = sptrProxy->WakeupDeviceIpc(GetTickCount(), static_cast(WakeupDeviceType::WAKEUP_DEVICE_APPLICATION), + std::string("app call"), apiVersion, powerError); + EXPECT_EQ(ret, ERR_TRANSACTION_FAILED); + int32_t attention = static_cast(UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); + EXPECT_NE(sptrProxy->RefreshActivityIpc(GetTickCount(), attention, true), ERR_OK); + ret = sptrProxy->SetDeviceModeIpc(static_cast(mode), powerError); + EXPECT_EQ(ret, ERR_TRANSACTION_FAILED); + sptrProxy->GetDeviceModeIpc(powerMode); + EXPECT_FALSE(powerMode == static_cast(mode)); + EXPECT_NE(sptrProxy->ProxyRunningLockIpc(true, pid, uid), ERR_OK); + sptrProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_BACKGROUND), lockTypeSupported); + EXPECT_FALSE(lockTypeSupported); + sptrProxy->OverrideScreenOffTimeIpc(200, apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->RestoreScreenOffTimeIpc(apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest002 function end!"); } @@ -120,6 +142,10 @@ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest002, TestSize.Level2) */ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest003, TestSize.Level2) { + int32_t powerError = 1; + int32_t timeOutMs = -1; + std::string name; + bool isUsed = false; POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest003 function start!"); sptr remote = new MockPowerRemoteObject(); std::shared_ptr sptrProxy = std::make_shared(remote); @@ -130,11 +156,15 @@ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest003, TestSize.Level2) sptr token = new RunningLockTokenStub(); #ifdef HAS_SENSORS_SENSOR_PART RunningLockInfo info("test2", RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL); - EXPECT_FALSE(sptrProxy->CreateRunningLock(token, info) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->ReleaseRunningLock(token)); - EXPECT_FALSE(sptrProxy->Lock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->UnLock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->IsUsed(token)); + sptrProxy->CreateRunningLockIpc(token, info, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + EXPECT_NE(sptrProxy->ReleaseRunningLockIpc(token, name), ERR_OK); + sptrProxy->LockIpc(token, timeOutMs, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->UnLockIpc(token, name, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->IsUsedIpc(token, isUsed); + EXPECT_FALSE(isUsed); #endif POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest003 function end!"); } @@ -147,28 +177,33 @@ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest003, TestSize.Level2) */ HWTEST_F(PowerMockObjectTest, PowerMockObjectTest004, TestSize.Level2) { + int32_t powerError = 1; + std::string apiVersion = "-1"; POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest004 function start!"); sptr remote = new MockPowerRemoteObject(); std::shared_ptr sptrProxy = std::make_shared(remote); sptr cb1 = new PowerStateTestCallback(); sptr cb3 = new PowerModeTestCallback(); sptr cb5 =new PowerRunningLockTestCallback(); - EXPECT_FALSE(sptrProxy->RegisterPowerStateCallback(cb1)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerStateCallback(cb1)); - EXPECT_FALSE(sptrProxy->RegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(nullptr)); - sptrProxy->RebootDevice(" "); - sptrProxy->RebootDeviceForDeprecated(" "); - sptrProxy->ShutDownDevice(" "); - EXPECT_FALSE(sptrProxy->ForceSuspendDevice(0) == PowerErrors::ERR_OK); + sptr asyncCallback = new PowerMgrStubAsync(); + sptr powerProxy = iface_cast(asyncCallback); + EXPECT_NE(sptrProxy->RegisterPowerStateCallbackIpc(cb1, true), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerStateCallbackIpc(cb1), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerStateCallbackIpc(nullptr, true), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerStateCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(nullptr), ERR_OK); + sptrProxy->RebootDeviceIpc(" ", powerError); + sptrProxy->RebootDeviceForDeprecatedIpc(" ", powerError); + sptrProxy->ShutDownDeviceIpc(" ", powerError); + int32_t ret = sptrProxy->ForceSuspendDeviceIpc(0, apiVersion, powerProxy); + EXPECT_EQ(ret, ERR_TRANSACTION_FAILED); POWER_HILOGI(LABEL_TEST, "PowerMockObjectTest004 function end!"); } } // namespace \ No newline at end of file diff --git a/test/unittest/src/mock/power_mock_parcel_test.cpp b/test/unittest/src/mock/power_mock_parcel_test.cpp index 6d04c3df..1acb001f 100644 --- a/test/unittest/src/mock/power_mock_parcel_test.cpp +++ b/test/unittest/src/mock/power_mock_parcel_test.cpp @@ -30,6 +30,7 @@ #include "running_lock.h" #include "running_lock_info.h" #include "running_lock_token_stub.h" +#include "power_mgr_async_reply_stub.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -141,17 +142,25 @@ HWTEST_F(MockParcelTest, PowerMockParcelTest004, TestSize.Level2) POWER_HILOGI(LABEL_TEST, "PowerMockParcelTest004 function start!"); pid_t uid = 0; pid_t pid = 0; + int32_t powerError = 1; + int32_t timeOutMs = -1; + std::string name; + bool lockTypeSupported = false; + bool isUsed = false; sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); sptr token = new RunningLockTokenStub(); RunningLockInfo info("test1", RunningLockType::RUNNINGLOCK_SCREEN); - sptrProxy->CreateRunningLock(token, info); - sptrProxy->ReleaseRunningLock(token); - sptrProxy->ProxyRunningLock(true, pid, uid); - EXPECT_FALSE(sptrProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BUTT)); - sptrProxy->Lock(token); - sptrProxy->UnLock(token); - EXPECT_FALSE(sptrProxy->IsUsed(token)); + sptrProxy->CreateRunningLockIpc(token, info, powerError); + sptrProxy->ReleaseRunningLockIpc(token, name); + sptrProxy->ProxyRunningLockIpc(true, pid, uid); + sptrProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_BUTT), lockTypeSupported); + EXPECT_FALSE(lockTypeSupported); + sptrProxy->LockIpc(token, timeOutMs, powerError); + sptrProxy->UnLockIpc(token, name, powerError); + sptrProxy->IsUsedIpc(token, isUsed); + EXPECT_FALSE(isUsed); POWER_HILOGI(LABEL_TEST, "PowerMockParcelTest004 function end!"); } @@ -164,25 +173,25 @@ HWTEST_F(MockParcelTest, PowerMockParcelTest004, TestSize.Level2) HWTEST_F(MockParcelTest, PowerMockParcelTest005, TestSize.Level2) { POWER_HILOGI(LABEL_TEST, "PowerMockParcelTest005 function start!"); - bool ret = 0; + int32_t ret = 0; sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); sptr cb1 = new PowerStateTestCallback(); sptr cb3 = new PowerModeTestCallback(); sptr cb5 =new PowerRunningLockTestCallback(); - ret = sptrProxy->RegisterPowerStateCallback(cb1); - EXPECT_EQ(ret, false); - sptrProxy->UnRegisterPowerStateCallback(cb1); - sptrProxy->RegisterPowerStateCallback(nullptr); - sptrProxy->UnRegisterPowerStateCallback(nullptr); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(nullptr)); + ret = sptrProxy->RegisterPowerStateCallbackIpc(cb1, true); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + sptrProxy->UnRegisterPowerStateCallbackIpc(cb1); + sptrProxy->RegisterPowerStateCallbackIpc(nullptr, true); + sptrProxy->UnRegisterPowerStateCallbackIpc(nullptr); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(nullptr), ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMockParcelTest005 function end!"); } @@ -194,30 +203,45 @@ HWTEST_F(MockParcelTest, PowerMockParcelTest005, TestSize.Level2) */ HWTEST_F(MockParcelTest, PowerMockParcelTest006, TestSize.Level2) { + int32_t powerError = 1; + int32_t powerMode = 0; + int32_t powerState = -1; + std::string apiVersion = "-1"; + bool isScreenOn = false; POWER_HILOGI(LABEL_TEST, "PowerMockParcelTest006 function start!"); sptr remote = new IPCObjectStub(); + sptr asyncCallback = new PowerMgrStubAsync(); + sptr powerProxy = iface_cast(asyncCallback); std::shared_ptr sptrProxy = std::make_shared(remote); int32_t suspendReason = (static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX)) + 1; SuspendDeviceType abnormaltype = SuspendDeviceType(suspendReason); - sptrProxy->SuspendDevice(0, abnormaltype, false); - sptrProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, std::string("app call")); - sptrProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_ATTENTION, true); - EXPECT_FALSE(sptrProxy->OverrideScreenOffTime(200) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->RestoreScreenOffTime() == PowerErrors::ERR_OK); - auto state = sptrProxy->GetState(); - EXPECT_EQ(state, PowerState::UNKNOWN); - EXPECT_FALSE(sptrProxy->IsScreenOn()); - sptrProxy->SetDisplaySuspend(true); + sptrProxy->SuspendDeviceIpc(0, static_cast(abnormaltype), false, apiVersion, powerError); + sptrProxy->WakeupDeviceIpc(GetTickCount(), static_cast(WakeupDeviceType::WAKEUP_DEVICE_APPLICATION), + std::string("app call"), apiVersion, powerError); + int32_t userAttention = static_cast(UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); + sptrProxy->RefreshActivityIpc(GetTickCount(), userAttention, true); + sptrProxy->OverrideScreenOffTimeIpc(200, apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->RestoreScreenOffTimeIpc(apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + int32_t result = sptrProxy->GetStateIpc(powerState); + EXPECT_EQ(result, ERR_INVALID_VALUE); + sptrProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_FALSE(isScreenOn); + sptrProxy->SetDisplaySuspendIpc(true); PowerMode mode1 = PowerMode::NORMAL_MODE; - sptrProxy->SetDeviceMode(mode1); - sptrProxy->GetDeviceMode(); - sptrProxy->RebootDevice(" "); - sptrProxy->ShutDownDevice(" "); - sptrProxy->ForceSuspendDevice(0); + sptrProxy->SetDeviceModeIpc(static_cast(mode1), powerError); + sptrProxy->GetDeviceModeIpc(powerMode); + sptrProxy->RebootDeviceIpc(" ", powerError); + sptrProxy->ShutDownDeviceIpc(" ", powerError); + sptrProxy->ForceSuspendDeviceIpc(0, apiVersion, powerProxy); + int waitTime = 100; + PowerErrors ret = static_cast(asyncCallback->WaitForAsyncReply(waitTime)); static std::vector dumpArgs; dumpArgs.push_back("-a"); - std::string errCode = "remote error"; - std::string actualDebugInfo = sptrProxy->ShellDump(dumpArgs, dumpArgs.size()); + std::string errCode; + std::string actualDebugInfo; + sptrProxy->ShellDumpIpc(dumpArgs, dumpArgs.size(), actualDebugInfo); EXPECT_EQ(actualDebugInfo, errCode); POWER_HILOGI(LABEL_TEST, "PowerMockParcelTest006 function end!"); } @@ -235,4 +259,4 @@ HWTEST_F (MockParcelTest, PowerUtilMockParcelTest001, TestSize.Level2) EXPECT_TRUE(Permission::IsPermissionGranted("")); POWER_HILOGI(LABEL_TEST, "PowerUtilMockParcelTest001 function end!"); } -} // namespace +} // namespace \ No newline at end of file diff --git a/test/unittest/src/mock/power_mock_peer_test.cpp b/test/unittest/src/mock/power_mock_peer_test.cpp index 7c21e82b..2b34f3f8 100644 --- a/test/unittest/src/mock/power_mock_peer_test.cpp +++ b/test/unittest/src/mock/power_mock_peer_test.cpp @@ -29,6 +29,8 @@ #include "running_lock.h" #include "running_lock_info.h" #include "running_lock_token_stub.h" +#include "power_mgr_async_reply_stub.h" + using namespace testing::ext; using namespace OHOS::PowerMgr; using namespace OHOS; @@ -106,19 +108,32 @@ HWTEST_F(MockPeerTest, MockPeerTest001, TestSize.Level2) POWER_HILOGI(LABEL_TEST, "MockPeerTest001 function start!"); pid_t uid = 0; pid_t pid = 0; + int32_t powerError = 1; + int32_t timeOutMs = -1; + std::string name; + bool lockTypeSupported = false; + bool isUsed = false; sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); sptr token = new RunningLockTokenStub(); RunningLockInfo info("test1", RunningLockType::RUNNINGLOCK_SCREEN); - EXPECT_FALSE(sptrProxy->CreateRunningLock(token, info) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->ReleaseRunningLock(token)); - EXPECT_FALSE(sptrProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BUTT)); - EXPECT_FALSE(sptrProxy->Lock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->UnLock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->IsUsed(token)); - EXPECT_FALSE(sptrProxy->ProxyRunningLock(true, pid, uid)); - EXPECT_FALSE(sptrProxy->ProxyRunningLocks(true, {std::make_pair(pid, uid)})); - EXPECT_FALSE(sptrProxy->ResetRunningLocks()); + sptrProxy->CreateRunningLockIpc(token, info, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + EXPECT_NE(sptrProxy->ReleaseRunningLockIpc(token, name), ERR_OK); + sptrProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_BUTT), lockTypeSupported); + EXPECT_FALSE(lockTypeSupported); + sptrProxy->LockIpc(token, timeOutMs, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->UnLockIpc(token, name, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->IsUsedIpc(token, isUsed); + EXPECT_FALSE(isUsed); + EXPECT_NE(sptrProxy->ProxyRunningLockIpc(true, pid, uid), ERR_OK); + std::unique_ptr vectorPairInfos = std::make_unique(); + vectorPairInfos->processInfos.push_back(std::make_pair(pid, uid)); + EXPECT_NE(sptrProxy->ProxyRunningLocksIpc(true, *vectorPairInfos), ERR_OK); + EXPECT_NE(sptrProxy->ResetRunningLocksIpc(), ERR_OK); POWER_HILOGI(LABEL_TEST, "MockPeerTest001 function end!"); } @@ -130,26 +145,38 @@ HWTEST_F(MockPeerTest, MockPeerTest001, TestSize.Level2) */ HWTEST_F(MockPeerTest, MockPeerTest002, TestSize.Level2) { + int32_t powerError = 1; + int32_t powerMode = 0; + int32_t powerState = -1; + std::string apiVersion = "-1"; + int32_t ret = 0; + bool isScreenOn = false; POWER_HILOGI(LABEL_TEST, "MockPeerTest002 function start!"); sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); int32_t suspendReason = (static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX)) + 1; SuspendDeviceType abnormaltype = SuspendDeviceType(suspendReason); - EXPECT_EQ(sptrProxy->SuspendDevice(0, abnormaltype, false), PowerErrors::ERR_CONNECTION_FAIL); - auto error = - sptrProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, std::string("app call")); - EXPECT_EQ(error, PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_FALSE(sptrProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_ATTENTION, true)); - EXPECT_FALSE(sptrProxy->OverrideScreenOffTime(200) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->RestoreScreenOffTime() == PowerErrors::ERR_OK); - auto state = sptrProxy->GetState(); - EXPECT_EQ(state, PowerState::UNKNOWN); - EXPECT_FALSE(sptrProxy->IsScreenOn()); - sptrProxy->SetDisplaySuspend(true); + ret = sptrProxy->SuspendDeviceIpc(0, static_cast(abnormaltype), false, apiVersion, powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = sptrProxy->WakeupDeviceIpc(GetTickCount(), static_cast(WakeupDeviceType::WAKEUP_DEVICE_APPLICATION), + std::string("app call"), apiVersion, powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + int32_t userAttention = static_cast(UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); + EXPECT_NE(sptrProxy->RefreshActivityIpc(GetTickCount(), userAttention, true), ERR_OK); + sptrProxy->OverrideScreenOffTimeIpc(200, apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->RestoreScreenOffTimeIpc(apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + ret = sptrProxy->GetStateIpc(powerState); + EXPECT_EQ(ret, ERR_INVALID_DATA); + sptrProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_FALSE(isScreenOn); + sptrProxy->SetDisplaySuspendIpc(true); PowerMode mode1 = PowerMode::NORMAL_MODE; - EXPECT_EQ(sptrProxy->SetDeviceMode(mode1), PowerErrors::ERR_CONNECTION_FAIL); - auto mode2 = sptrProxy->GetDeviceMode(); - EXPECT_FALSE(mode2 == mode1); + ret = sptrProxy->SetDeviceModeIpc(static_cast(mode1), powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + sptrProxy->GetDeviceModeIpc(powerMode); + EXPECT_FALSE(powerMode == static_cast(mode1)); POWER_HILOGI(LABEL_TEST, "MockPeerTest002 function end!"); } @@ -161,31 +188,40 @@ HWTEST_F(MockPeerTest, MockPeerTest002, TestSize.Level2) */ HWTEST_F(MockPeerTest, MockPeerTest003, TestSize.Level2) { + int32_t powerError = 1; + std::string apiVersion = "-1"; + int32_t ret = 0; POWER_HILOGI(LABEL_TEST, "MockPeerTest003 function start!"); sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); sptr cb1 = new PowerStateTestCallback(); sptr cb3 = new PowerModeTestCallback(); sptr cb5 =new PowerRunningLockTestCallback(); - EXPECT_FALSE(sptrProxy->RegisterPowerStateCallback(cb1)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerStateCallback(cb1)); - EXPECT_FALSE(sptrProxy->RegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(nullptr)); - EXPECT_EQ(sptrProxy->RebootDevice(" "), PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_EQ(sptrProxy->ShutDownDevice(" "), PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_FALSE(sptrProxy->ForceSuspendDevice(0) == PowerErrors::ERR_OK); + sptr asyncCallback = new PowerMgrStubAsync(); + sptr powerProxy = iface_cast(asyncCallback); + EXPECT_NE(sptrProxy->RegisterPowerStateCallbackIpc(cb1, true), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerStateCallbackIpc(cb1), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerStateCallbackIpc(nullptr, true), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerStateCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(nullptr), ERR_OK); + ret = sptrProxy->RebootDeviceIpc(" ", powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = sptrProxy->ShutDownDeviceIpc(" ", powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = sptrProxy->ForceSuspendDeviceIpc(0, apiVersion, powerProxy); + EXPECT_EQ(ret, ERR_INVALID_DATA); static std::vector dumpArgs; dumpArgs.push_back("-a"); - std::string errorCode = "remote error"; - std::string actualDebugInfo = sptrProxy->ShellDump(dumpArgs, dumpArgs.size()); + std::string errorCode; + std::string actualDebugInfo; + sptrProxy->ShellDumpIpc(dumpArgs, dumpArgs.size(), actualDebugInfo); EXPECT_EQ(errorCode, actualDebugInfo); POWER_HILOGI(LABEL_TEST, "MockPeerTest003 function end!"); } diff --git a/test/unittest/src/mock/power_mock_proxy_test.cpp b/test/unittest/src/mock/power_mock_proxy_test.cpp index 104c464f..87315ae5 100644 --- a/test/unittest/src/mock/power_mock_proxy_test.cpp +++ b/test/unittest/src/mock/power_mock_proxy_test.cpp @@ -29,6 +29,7 @@ #include "running_lock.h" #include "running_lock_info.h" #include "running_lock_token_stub.h" +#include "power_mgr_async_reply_stub.h" using namespace testing::ext; using namespace OHOS::PowerMgr; @@ -60,19 +61,32 @@ HWTEST_F(PowerMockProxyTest, PowerMockProxyTest001, TestSize.Level2) POWER_HILOGI(LABEL_TEST, "PowerMockProxyTest001 function start!"); pid_t uid = 0; pid_t pid = 0; + int32_t powerError = 1; + int32_t timeOutMs = -1; + std::string name; + bool lockTypeSupported = false; + bool isUsed = false; sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); sptr token = new RunningLockTokenStub(); RunningLockInfo info("test1", RunningLockType::RUNNINGLOCK_SCREEN); - EXPECT_FALSE(sptrProxy->CreateRunningLock(token, info) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->ReleaseRunningLock(token)); - EXPECT_FALSE(sptrProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BUTT)); - EXPECT_FALSE(sptrProxy->Lock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->UnLock(token) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->IsUsed(token)); - EXPECT_FALSE(sptrProxy->ProxyRunningLock(true, pid, uid)); - EXPECT_FALSE(sptrProxy->ProxyRunningLocks(true, {std::make_pair(pid, uid)})); - EXPECT_FALSE(sptrProxy->ResetRunningLocks()); + sptrProxy->CreateRunningLockIpc(token, info, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + EXPECT_NE(sptrProxy->ReleaseRunningLockIpc(token, name), ERR_OK); + sptrProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_BUTT), lockTypeSupported); + EXPECT_FALSE(lockTypeSupported); + sptrProxy->LockIpc(token, timeOutMs, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->UnLockIpc(token, name, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->IsUsedIpc(token, isUsed); + EXPECT_FALSE(isUsed); + EXPECT_NE(sptrProxy->ProxyRunningLockIpc(true, pid, uid), ERR_OK); + std::unique_ptr vectorPairInfos = std::make_unique(); + vectorPairInfos->processInfos.push_back(std::make_pair(pid, uid)); + EXPECT_NE(sptrProxy->ProxyRunningLocksIpc(true, *vectorPairInfos), ERR_OK); + EXPECT_NE(sptrProxy->ResetRunningLocksIpc(), ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMockProxyTest001 function end!"); } @@ -83,26 +97,38 @@ HWTEST_F(PowerMockProxyTest, PowerMockProxyTest001, TestSize.Level2) */ HWTEST_F(PowerMockProxyTest, PowerMockProxyTest002, TestSize.Level2) { + int32_t powerError = 1; + int32_t powerMode = 0; + int32_t powerState = -1; + std::string apiVersion = "-1"; + bool isScreenOn = false; + int32_t ret = 0; POWER_HILOGI(LABEL_TEST, "PowerMockProxyTest002 function start!"); sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); int32_t suspendReason = (static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX)) + 1; SuspendDeviceType abnormaltype = SuspendDeviceType(suspendReason); - EXPECT_EQ(sptrProxy->SuspendDevice(0, abnormaltype, false), PowerErrors::ERR_CONNECTION_FAIL); - auto error = - sptrProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, std::string("app call")); - EXPECT_EQ(error, PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_FALSE(sptrProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_ATTENTION, true)); - EXPECT_FALSE(sptrProxy->OverrideScreenOffTime(200) == PowerErrors::ERR_OK); - EXPECT_FALSE(sptrProxy->RestoreScreenOffTime() == PowerErrors::ERR_OK); - auto state = sptrProxy->GetState(); - EXPECT_EQ(state, PowerState::UNKNOWN); - EXPECT_FALSE(sptrProxy->IsScreenOn()); - sptrProxy->SetDisplaySuspend(true); + ret = sptrProxy->SuspendDeviceIpc(0, static_cast(abnormaltype), false, apiVersion, powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = sptrProxy->WakeupDeviceIpc(GetTickCount(), static_cast(WakeupDeviceType::WAKEUP_DEVICE_APPLICATION), + std::string("app call"), apiVersion, powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + int32_t userAttention = static_cast(UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); + EXPECT_NE(sptrProxy->RefreshActivityIpc(GetTickCount(), userAttention, true), ERR_OK); + sptrProxy->OverrideScreenOffTimeIpc(200, apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + sptrProxy->RestoreScreenOffTimeIpc(apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + ret = sptrProxy->GetStateIpc(powerState); + EXPECT_NE(ret, ERR_OK); + sptrProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_FALSE(isScreenOn); + sptrProxy->SetDisplaySuspendIpc(true); PowerMode mode1 = PowerMode::NORMAL_MODE; - EXPECT_EQ(sptrProxy->SetDeviceMode(mode1), PowerErrors::ERR_CONNECTION_FAIL); - auto mode2 = sptrProxy->GetDeviceMode(); - EXPECT_TRUE(mode2 == mode1); + ret = sptrProxy->SetDeviceModeIpc(static_cast(mode1), powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = sptrProxy->GetDeviceModeIpc(powerMode); + EXPECT_NE(ret, ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMockProxyTest002 function end!"); } @@ -113,31 +139,40 @@ HWTEST_F(PowerMockProxyTest, PowerMockProxyTest002, TestSize.Level2) */ HWTEST_F(PowerMockProxyTest, PowerMockProxyTest003, TestSize.Level2) { + int32_t powerError = 1; + std::string apiVersion = "-1"; + int32_t ret = 0; POWER_HILOGI(LABEL_TEST, "PowerMockProxyTest003 function start!"); sptr remote = new IPCObjectStub(); std::shared_ptr sptrProxy = std::make_shared(remote); sptr cb1 = new PowerStateTestCallback(); sptr cb3 = new PowerModeTestCallback(); sptr cb5 =new PowerRunningLockTestCallback(); - EXPECT_FALSE(sptrProxy->RegisterPowerStateCallback(cb1)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerStateCallback(cb1)); - EXPECT_FALSE(sptrProxy->RegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(cb3)); - EXPECT_FALSE(sptrProxy->RegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(cb5)); - EXPECT_FALSE(sptrProxy->RegisterRunningLockCallback(nullptr)); - EXPECT_FALSE(sptrProxy->UnRegisterRunningLockCallback(nullptr)); - EXPECT_EQ(sptrProxy->RebootDevice(" "), PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_EQ(sptrProxy->ShutDownDevice(" "), PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_FALSE(sptrProxy->ForceSuspendDevice(0) == PowerErrors::ERR_OK); + sptr asyncCallback = new PowerMgrStubAsync(); + sptr powerProxy = iface_cast(asyncCallback); + EXPECT_NE(sptrProxy->RegisterPowerStateCallbackIpc(cb1, true), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerStateCallbackIpc(cb1), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerStateCallbackIpc(nullptr, true), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerStateCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(cb3), ERR_OK); + EXPECT_NE(sptrProxy->RegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(cb5), ERR_OK); + EXPECT_NE(sptrProxy->RegisterRunningLockCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(sptrProxy->UnRegisterRunningLockCallbackIpc(nullptr), ERR_OK); + ret = sptrProxy->RebootDeviceIpc(" ", powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = sptrProxy->ShutDownDeviceIpc(" ", powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = sptrProxy->ForceSuspendDeviceIpc(0, apiVersion, powerProxy); + EXPECT_EQ(ret, ERR_INVALID_DATA); static std::vector dumpArgs; dumpArgs.push_back("-a"); - std::string errorCode = "remote error"; - std::string actualDebugInfo = sptrProxy->ShellDump(dumpArgs, dumpArgs.size()); + std::string errorCode; + std::string actualDebugInfo; + sptrProxy->ShellDumpIpc(dumpArgs, dumpArgs.size(), actualDebugInfo); EXPECT_EQ(errorCode, actualDebugInfo); POWER_HILOGI(LABEL_TEST, "PowerMockProxyTest003 function end!"); } diff --git a/test/unittest/src/power_client_callback_test.cpp b/test/unittest/src/power_client_callback_test.cpp new file mode 100644 index 00000000..8e7943d4 --- /dev/null +++ b/test/unittest/src/power_client_callback_test.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "power_client_callback_test.h" + +#include + +#include +#include +#include +#include +#include + +#include "power_common.h" +#include "power_mgr_client.h" +#include "power_mgr_service.h" +#include "power_state_machine.h" + +using namespace testing::ext; +using namespace OHOS::PowerMgr; +using namespace OHOS; +using namespace std; + +void PowerMgrClientCallbackTest::PowerRunningLockTest1Callback::HandleRunningLockMessage(std::string message) +{ + POWER_HILOGI(LABEL_TEST, "PowerRunningLockTest1Callback::HandleRunningLockMessage."); +} + +void PowerMgrClientCallbackTest::ScreenOffPreTest1Callback::OnScreenStateChanged(uint32_t state) +{ + POWER_HILOGI(LABEL_TEST, "ScreenOffPreTest1Callback::OnScreenStateChanged."); +} + +void PowerMgrClientCallbackTest::PowerSyncHibernateTest1Callback::OnSyncHibernate() +{ + POWER_HILOGI(LABEL_TEST, "PowerSyncHibernateTest1Callback::OnSyncHibernate."); +} + +void PowerMgrClientCallbackTest::PowerSyncHibernateTest1Callback::OnSyncWakeup(bool hibernateResult) +{ + POWER_HILOGI(LABEL_TEST, "PowerSyncHibernateTest1Callback::OnSyncWakeup."); +} + +void PowerMgrClientCallbackTest::PowerSyncSleepTest1Callback::OnSyncSleep(bool onForceSleep) +{ + POWER_HILOGI(LABEL_TEST, "PowerSyncSleepTest1Callback::OnSyncSleep."); +} + +void PowerMgrClientCallbackTest::PowerSyncSleepTest1Callback::OnSyncWakeup(bool onForceSleep) +{ + POWER_HILOGI(LABEL_TEST, "PowerSyncSleepTest1Callback::OnSyncWakeup."); +} + +namespace { +/** + * @tc.name: PowerMgrRunningLockCallback001 + * @tc.desc: test PowerRunninglockCallback + * @tc.type: FUNC + */ +HWTEST_F(PowerMgrClientCallbackTest, PowerMgrRunningLockCallback001, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "PowerMgrRunningLockCallback001 function start!"); + bool ret = 0; + auto& powerMgrClient = PowerMgrClient::GetInstance(); + sptr cb = new PowerRunningLockTest1Callback(); + ret = powerMgrClient.RegisterRunningLockCallback(cb); + EXPECT_TRUE(ret); + ret = 0; + ret = powerMgrClient.UnRegisterRunningLockCallback(cb); + EXPECT_TRUE(ret); + POWER_HILOGI(LABEL_TEST, "PowerMgrRunningLockCallback001 function end!"); +} + +/** + * @tc.name: PowerMgrScreenOffCallback001 + * @tc.desc: test ScreenOffPreCallback + * @tc.type: FUNC + */ +HWTEST_F(PowerMgrClientCallbackTest, PowerMgrScreenOffCallback001, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "PowerMgrScreenOffCallback001 function start!"); + bool ret = 0; + auto& powerMgrClient = PowerMgrClient::GetInstance(); + sptr cb = new ScreenOffPreTest1Callback(); + ret = powerMgrClient.RegisterScreenStateCallback(4000, cb); + EXPECT_TRUE(ret); + ret = 0; + ret = powerMgrClient.UnRegisterScreenStateCallback(cb); + EXPECT_TRUE(ret); + POWER_HILOGI(LABEL_TEST, "PowerMgrScreenOffCallback001 function end!"); +} + +/** + * @tc.name: PowerMgrSyncHibernateCallback001 + * @tc.desc: test SyncHibernateCallback + * @tc.type: FUNC + */ +HWTEST_F(PowerMgrClientCallbackTest, PowerMgrSyncHibernateCallback001, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "PowerMgrSyncHibernateCallback001 function start!"); + bool ret = 0; + auto& powerMgrClient = PowerMgrClient::GetInstance(); + sptr cb = new PowerSyncHibernateTest1Callback(); + ret = powerMgrClient.RegisterSyncHibernateCallback(cb); + EXPECT_TRUE(ret); + ret = 0; + ret = powerMgrClient.UnRegisterSyncHibernateCallback(cb); + EXPECT_TRUE(ret); + POWER_HILOGI(LABEL_TEST, "PowerMgrSyncHibernateCallback001 function end!"); +} + +/** + * @tc.name: PowerMgrSyncSleepCallback001 + * @tc.desc: test SyncSleepCallback + * @tc.type: FUNC + */ +HWTEST_F(PowerMgrClientCallbackTest, PowerMgrSyncSleepCallback001, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "PowerMgrSyncSleepCallback001 function start!"); + bool ret = 0; + auto& powerMgrClient = PowerMgrClient::GetInstance(); + sptr cb = new PowerSyncSleepTest1Callback(); + ret = powerMgrClient.RegisterSyncSleepCallback(cb, SleepPriority::HIGH); + EXPECT_TRUE(ret); + ret = 0; + ret = powerMgrClient.UnRegisterSyncSleepCallback(cb); + EXPECT_TRUE(ret); + POWER_HILOGI(LABEL_TEST, "PowerMgrSyncSleepCallback001 function end!"); +} +} \ No newline at end of file diff --git a/test/unittest/src/servicetest/BUILD.gn b/test/unittest/src/servicetest/BUILD.gn index 40c80aa6..d8bce15a 100644 --- a/test/unittest/src/servicetest/BUILD.gn +++ b/test/unittest/src/servicetest/BUILD.gn @@ -73,6 +73,12 @@ if (has_sensors_sensor_part) { ohos_unittest("powermgr_native_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ "powermgr_service_native_test.cpp", "powermgr_service_test_proxy.cpp", @@ -99,6 +105,12 @@ ohos_unittest("powermgr_native_test") { ohos_unittest("powermgr_native_mock_parcel_test") { module_out_path = module_output_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ "${powermgr_root_path}/test/unittest/mock/mock_message_parcel.cpp", "${powermgr_root_path}/test/unittest/mock/mock_parcel.cpp", diff --git a/test/unittest/src/servicetest/mock/powermgr_service_mock_parcel_test.cpp b/test/unittest/src/servicetest/mock/powermgr_service_mock_parcel_test.cpp index 09417542..f7230abf 100644 --- a/test/unittest/src/servicetest/mock/powermgr_service_mock_parcel_test.cpp +++ b/test/unittest/src/servicetest/mock/powermgr_service_mock_parcel_test.cpp @@ -84,15 +84,27 @@ HWTEST_F(PowerMgrServiceMockParcelTest, PowerMgrServiceMockParcelTest001, TestSi pid_t uid = 0; pid_t pid = 0; int32_t timeOutMs = 0; - EXPECT_FALSE(g_powerMgrServiceProxy->CreateRunningLock(token, runningLockInfo) == PowerErrors::ERR_OK); - EXPECT_FALSE(g_powerMgrServiceProxy->ReleaseRunningLock(token)); - EXPECT_FALSE(g_powerMgrServiceProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BUTT)); - EXPECT_FALSE(g_powerMgrServiceProxy->Lock(token)); - EXPECT_FALSE(g_powerMgrServiceProxy->UnLock(token)); - EXPECT_FALSE(g_powerMgrServiceProxy->IsUsed(token)); - EXPECT_FALSE(g_powerMgrServiceProxy->ProxyRunningLock(true, pid, uid)); - EXPECT_FALSE(g_powerMgrServiceProxy->ProxyRunningLocks(true, {std::make_pair(pid, uid)})); - EXPECT_FALSE(g_powerMgrServiceProxy->ResetRunningLocks()); + int32_t powerError = 1; + std::string name; + bool lockTypeSupported = false; + bool isUsed = false; + g_powerMgrServiceProxy->CreateRunningLockIpc(token, runningLockInfo, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + EXPECT_NE(g_powerMgrServiceProxy->ReleaseRunningLockIpc(token), ERR_OK); + g_powerMgrServiceProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_BUTT), lockTypeSupported); + EXPECT_FALSE(lockTypeSupported); + g_powerMgrServiceProxy->LockIpc(token, timeOutMs, powerError); + EXPECT_NE(powerError, ERR_OK); + g_powerMgrServiceProxy->UnLockIpc(token, name, powerError); + EXPECT_NE(powerError, ERR_OK); + g_powerMgrServiceProxy->IsUsedIpc(token, isUsed); + EXPECT_FALSE(isUsed); + EXPECT_NE(g_powerMgrServiceProxy->ProxyRunningLockIpc(true, pid, uid), ERR_OK); + std::unique_ptr vectorPairInfos = std::make_unique(); + vectorPairInfos->processInfos.push_back(std::make_pair(pid, uid)); + EXPECT_NE(g_powerMgrServiceProxy->ProxyRunningLocksIpc(true, *vectorPairInfos), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->ResetRunningLocksIpc(), ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceMockParcelTest001 end."); } @@ -106,24 +118,36 @@ HWTEST_F(PowerMgrServiceMockParcelTest, PowerMgrServiceMockParcelTest002, TestSi { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceMockParcelTest002 start."); int32_t PARM_ONE = 1; + int32_t powerError = 1; + int32_t powerState = -1; + std::string apiVersion = "-1"; + int32_t ret = 0; + bool isScreenOn = false; ASSERT_NE(g_powerMgrServiceProxy, nullptr); int32_t suspendReason = (static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX)) + PARM_ONE; - SuspendDeviceType abnormaltype = SuspendDeviceType(suspendReason); - EXPECT_EQ(g_powerMgrServiceProxy->SuspendDevice(0, abnormaltype, false), PowerErrors::ERR_CONNECTION_FAIL); - auto error = g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), - WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, std::string("app call")); - EXPECT_EQ(error, PowerErrors::ERR_CONNECTION_FAIL); - EXPECT_FALSE(g_powerMgrServiceProxy->RefreshActivity(GetTickCount(), - UserActivityType::USER_ACTIVITY_TYPE_ATTENTION, true)); - EXPECT_FALSE(g_powerMgrServiceProxy->OverrideScreenOffTime(200) == PowerErrors::ERR_OK); - EXPECT_FALSE(g_powerMgrServiceProxy->RestoreScreenOffTime() == PowerErrors::ERR_OK); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::UNKNOWN); - EXPECT_FALSE(g_powerMgrServiceProxy->IsScreenOn()); - g_powerMgrServiceProxy->SetDisplaySuspend(true); + ret = g_powerMgrServiceProxy->SuspendDeviceIpc(0, suspendReason, false, apiVersion, powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + ret = g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_APPLICATION), + std::string("app call"), apiVersion, powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + int32_t attention = static_cast(UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); + EXPECT_NE(g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), attention, true), ERR_OK); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(200, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + g_powerMgrServiceProxy->RestoreScreenOffTimeIpc(apiVersion, powerError); + EXPECT_FALSE(powerError == static_cast(PowerErrors::ERR_OK)); + ret = g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_FALSE(isScreenOn); + g_powerMgrServiceProxy->SetDisplaySuspendIpc(true); PowerMode setMode = PowerMode::NORMAL_MODE; - EXPECT_EQ(g_powerMgrServiceProxy->SetDeviceMode(setMode), PowerErrors::ERR_CONNECTION_FAIL); - PowerMode getMode = g_powerMgrServiceProxy->GetDeviceMode(); - EXPECT_TRUE(getMode == setMode); + ret = g_powerMgrServiceProxy->SetDeviceModeIpc(static_cast(setMode), powerError); + EXPECT_EQ(ret, ERR_INVALID_DATA); + int32_t getMode = 0; + ret = g_powerMgrServiceProxy->GetDeviceModeIpc(getMode); + EXPECT_EQ(ret, ERR_INVALID_VALUE); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceMockParcelTest002 end."); } @@ -136,27 +160,30 @@ HWTEST_F(PowerMgrServiceMockParcelTest, PowerMgrServiceMockParcelTest002, TestSi HWTEST_F(PowerMgrServiceMockParcelTest, PowerMgrServiceMockParcelTest003, TestSize.Level2) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceMockParcelTest003 start."); + int32_t powerError = 1; + std::string apiVersion = "-1"; ASSERT_NE(g_powerMgrServiceProxy, nullptr); sptr stateCb = new PowerStateTestCallback(); sptr modeCb = new PowerModeTestCallback(); sptr RunninglockCb =new PowerRunningLockTestCallback(); - EXPECT_FALSE(g_powerMgrServiceProxy->RegisterPowerStateCallback(stateCb)); - EXPECT_FALSE(g_powerMgrServiceProxy->UnRegisterPowerStateCallback(stateCb)); - EXPECT_FALSE(g_powerMgrServiceProxy->RegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(g_powerMgrServiceProxy->UnRegisterPowerStateCallback(nullptr)); - EXPECT_FALSE(g_powerMgrServiceProxy->RegisterPowerModeCallback(modeCb)); - EXPECT_FALSE(g_powerMgrServiceProxy->UnRegisterPowerModeCallback(modeCb)); - EXPECT_FALSE(g_powerMgrServiceProxy->RegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(g_powerMgrServiceProxy->UnRegisterPowerModeCallback(nullptr)); - EXPECT_FALSE(g_powerMgrServiceProxy->RegisterRunningLockCallback(RunninglockCb)); - EXPECT_FALSE(g_powerMgrServiceProxy->UnRegisterRunningLockCallback(RunninglockCb)); - EXPECT_FALSE(g_powerMgrServiceProxy->RegisterRunningLockCallback(nullptr)); - EXPECT_FALSE(g_powerMgrServiceProxy->UnRegisterRunningLockCallback(nullptr)); - EXPECT_FALSE(g_powerMgrServiceProxy->ForceSuspendDevice(0) == PowerErrors::ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->RegisterPowerStateCallbackIpc(stateCb), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->UnRegisterPowerStateCallbackIpc(stateCb), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->RegisterPowerStateCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->UnRegisterPowerStateCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->RegisterPowerModeCallbackIpc(modeCb), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->UnRegisterPowerModeCallbackIpc(modeCb), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->RegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->UnRegisterPowerModeCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->RegisterRunningLockCallbackIpc(RunninglockCb), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->UnRegisterRunningLockCallbackIpc(RunninglockCb), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->RegisterRunningLockCallbackIpc(nullptr), ERR_OK); + EXPECT_NE(g_powerMgrServiceProxy->UnRegisterRunningLockCallbackIpc(nullptr), ERR_OK); + EXPECT_FALSE(g_powerMgrServiceProxy->ForceSuspendDeviceIpc(0) == ERR_OK); static std::vector dumpArgs; dumpArgs.push_back("-a"); - std::string errorCode = "remote error"; - std::string actualDebugInfo = g_powerMgrServiceProxy->ShellDump(dumpArgs, dumpArgs.size()); + std::string errorCode; + std::string actualDebugInfo; + g_powerMgrServiceProxy->ShellDumpIpc(dumpArgs, dumpArgs.size(), actualDebugInfo); EXPECT_EQ(errorCode, actualDebugInfo); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceMockParcelTest003 end."); } diff --git a/test/unittest/src/servicetest/powermgr_service_native_test.cpp b/test/unittest/src/servicetest/powermgr_service_native_test.cpp index f7b2954b..e3df5e92 100644 --- a/test/unittest/src/servicetest/powermgr_service_native_test.cpp +++ b/test/unittest/src/servicetest/powermgr_service_native_test.cpp @@ -35,6 +35,9 @@ namespace { static sptr g_powerMgrService = nullptr; static std::shared_ptr g_powerMgrServiceProxy = nullptr; constexpr int32_t DISPLAY_POWER_MANAGER_ID = 3308; +constexpr int32_t FAIL_VALUE = -1; +constexpr int32_t REASON_VALUE = static_cast(WakeupDeviceType::WAKEUP_DEVICE_APPLICATION); +const std::string API_VERSION = "-1"; const std::string TEST_DEVICE_ID = "test_device_id"; } // namespace @@ -44,11 +47,13 @@ void PowerMgrServiceNativeTest::SetUpTestCase() g_powerMgrService = DelayedSpSingleton::GetInstance(); g_powerMgrService->OnStart(); g_powerMgrService->OnAddSystemAbility(DISPLAY_POWER_MANAGER_ID, TEST_DEVICE_ID); + int32_t powerError = 1; + bool isScreenOn = false; if (g_powerMgrServiceProxy == nullptr) { g_powerMgrServiceProxy = std::make_shared(g_powerMgrService); } - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); // wait for "SetState for INIT" to be done sleep(WAIT_INIT_TIME_S); } @@ -89,15 +94,22 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest001, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest001 function start!"); int32_t PARM_TWO = 2; - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(SCREEN_OFF_WAIT_TIME_MS, powerError); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->RefreshActivity(GetTickCount()); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + int32_t userOther = static_cast(UserActivityType::USER_ACTIVITY_TYPE_OTHER) + g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), userOther); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest001 function end!"); } @@ -111,15 +123,22 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest002, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest002 function start!"); int32_t PARM_TWO = 2; - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(SCREEN_OFF_WAIT_TIME_MS, powerError); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_BUTTON); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + int32_t userButton = static_cast(UserActivityType::USER_ACTIVITY_TYPE_BUTTON); + g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), userButton); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest002 function end!"); } @@ -133,15 +152,22 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest003, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest003 function start!"); int32_t PARM_TWO = 2; - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(SCREEN_OFF_WAIT_TIME_MS, powerError); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_TOUCH); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + int32_t userTouch = static_cast(UserActivityType::USER_ACTIVITY_TYPE_TOUCH); + g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), userTouch); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest003 function end!"); } @@ -155,15 +181,22 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest004, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest004 function start!"); int32_t PARM_TWO = 2; - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(SCREEN_OFF_WAIT_TIME_MS, powerError); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + int32_t userAcc = static_cast(UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY); + g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), userAcc); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest004 function end!"); } @@ -177,17 +210,26 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest005, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest005 function start!"); int32_t PARM_TWO = 2; - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(SCREEN_OFF_WAIT_TIME_MS, powerError); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + int32_t userAttention = static_cast(UserActivityType::USER_ACTIVITY_TYPE_ATTENTION); + g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), userAttention); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest005 function end!"); } @@ -201,17 +243,26 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest006, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest006 function start!"); int32_t PARM_TWO = 2; - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(SCREEN_OFF_WAIT_TIME_MS, powerError); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->RefreshActivity(GetTickCount(), UserActivityType::USER_ACTIVITY_TYPE_SOFTWARE); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + int32_t software = static_cast(UserActivityType::USER_ACTIVITY_TYPE_SOFTWARE); + g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), software); sleep(SCREEN_OFF_WAIT_TIME_S / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest006 function end!"); } @@ -226,15 +277,21 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest007, TestSize.Level POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest007 function start!"); int32_t PARM_TWO = 2; UserActivityType abnormaltype = UserActivityType(9); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(SCREEN_OFF_WAIT_TIME_MS); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(SCREEN_OFF_WAIT_TIME_MS, powerError); usleep(SCREEN_OFF_WAIT_TIME_S * TRANSFER_NS_TO_MS / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->RefreshActivity(GetTickCount(), abnormaltype); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->RefreshActivityIpc(GetTickCount(), static_cast(abnormaltype)); usleep(SCREEN_OFF_WAIT_TIME_S * TRANSFER_NS_TO_MS / PARM_TWO); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest007 function end!"); } @@ -249,12 +306,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest008, TestSize.Level POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest008 function start!"); int32_t wakeupReason = (static_cast(WakeupDeviceType::WAKEUP_DEVICE_MAX)) + 1; WakeupDeviceType abnormaltype = WakeupDeviceType(wakeupReason); + int32_t powerError = 1; + bool isScreenOn = false; - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); sleep(SLEEP_WAIT_TIME_S); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), abnormaltype); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), static_cast(abnormaltype), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest008 function end!"); } @@ -268,14 +330,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest009, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest009 function start!"); int32_t suspendReason = (static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX)) + 1; - SuspendDeviceType abnormaltype = SuspendDeviceType(suspendReason); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount(), abnormaltype, false); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), suspendReason, false, API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest009 function end!"); } @@ -288,8 +356,15 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest009, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest010, TestSize.Level2) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest010 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + std::string name; + bool isScreenOn = false; + bool isUsed = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); int32_t time = SLEEP_WAIT_TIME_MS; sptr token = new RunningLockTokenStub(); RunningLockInfo runningLockInfo; @@ -298,21 +373,27 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest010, TestSize.Level int32_t timeOutMs = 0; pid_t uid = 0; pid_t pid = 0; - auto error = g_powerMgrServiceProxy->CreateRunningLock(token, runningLockInfo); - EXPECT_TRUE(error == PowerErrors::ERR_OK); - EXPECT_FALSE(g_powerMgrServiceProxy->ProxyRunningLock(true, pid, uid)); - EXPECT_TRUE(g_powerMgrServiceProxy->ProxyRunningLocks(true, {std::make_pair(pid, uid)})); - EXPECT_TRUE(g_powerMgrServiceProxy->ResetRunningLocks()); - g_powerMgrServiceProxy->OverrideScreenOffTime(time); - g_powerMgrServiceProxy->Lock(token); - EXPECT_EQ(g_powerMgrServiceProxy->IsUsed(token), true); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + g_powerMgrServiceProxy->CreateRunningLockIpc(token, runningLockInfo, powerError); + EXPECT_TRUE(powerError == static_cast(PowerErrors::ERR_OK)); + EXPECT_EQ(g_powerMgrServiceProxy->ProxyRunningLockIpc(true, pid, uid), FAIL_VALUE); + std::unique_ptr vectorPairInfos = std::make_unique(); + vectorPairInfos->processInfos.push_back(std::make_pair(pid, uid)); + EXPECT_EQ(g_powerMgrServiceProxy->ProxyRunningLocksIpc(true, *vectorPairInfos), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->ResetRunningLocksIpc(), ERR_OK); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(time, powerError); + g_powerMgrServiceProxy->LockIpc(token, timeOutMs, powerError); + g_powerMgrServiceProxy->IsUsedIpc(token, isUsed); + EXPECT_EQ(isUsed, true); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); usleep(time * TRANSFER_MS_TO_S); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - g_powerMgrServiceProxy->UnLock(token); - EXPECT_EQ(g_powerMgrServiceProxy->IsUsed(token), false); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); - EXPECT_TRUE(g_powerMgrServiceProxy->ReleaseRunningLock(token)); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->UnLockIpc(token, name, powerError); + g_powerMgrServiceProxy->IsUsedIpc(token, isUsed); + EXPECT_EQ(isUsed, false); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); + EXPECT_EQ(g_powerMgrServiceProxy->ReleaseRunningLockIpc(token), ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest010 function end!"); } @@ -325,28 +406,39 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest010, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest011, TestSize.Level2) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest011 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + std::string name; + bool isScreenOn = false; + bool isUsed = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); int32_t time = SLEEP_WAIT_TIME_MS; sptr token = new RunningLockTokenStub(); RunningLockInfo runningLockInfo; runningLockInfo.name = "runninglock"; runningLockInfo.type = RunningLockType::RUNNINGLOCK_SCREEN; int32_t timeOutMs = 0; - auto error = g_powerMgrServiceProxy->CreateRunningLock(token, runningLockInfo); - EXPECT_TRUE(error == PowerErrors::ERR_OK); - g_powerMgrServiceProxy->OverrideScreenOffTime(time); - - g_powerMgrServiceProxy->Lock(token); - EXPECT_EQ(g_powerMgrServiceProxy->IsUsed(token), true); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + g_powerMgrServiceProxy->CreateRunningLockIpc(token, runningLockInfo, powerError); + EXPECT_TRUE(powerError == static_cast(PowerErrors::ERR_OK)); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(time, powerError); + + g_powerMgrServiceProxy->LockIpc(token, timeOutMs, powerError); + g_powerMgrServiceProxy->IsUsedIpc(token, isUsed); + EXPECT_EQ(isUsed, true); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); usleep(time * TRANSFER_MS_TO_S * DOUBLE_TIMES); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - - g_powerMgrServiceProxy->UnLock(token); - EXPECT_EQ(g_powerMgrServiceProxy->IsUsed(token), false); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); - EXPECT_TRUE(g_powerMgrServiceProxy->ReleaseRunningLock(token)); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + + g_powerMgrServiceProxy->UnLockIpc(token, name, powerError); + g_powerMgrServiceProxy->IsUsedIpc(token, isUsed); + EXPECT_EQ(isUsed, false); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); + EXPECT_EQ(g_powerMgrServiceProxy->ReleaseRunningLockIpc(token), ERR_OK); sleep(2); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest011 function end!"); } @@ -360,28 +452,38 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest011, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest012, TestSize.Level2) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest012 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + std::string name; + bool isScreenOn = false; + bool isUsed = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); int32_t time = SLEEP_WAIT_TIME_MS; sptr token = new RunningLockTokenStub(); RunningLockInfo runningLockInfo; runningLockInfo.name = "runninglock"; runningLockInfo.type = RunningLockType::RUNNINGLOCK_SCREEN; int32_t timeOutMs = 0; - auto error = g_powerMgrServiceProxy->CreateRunningLock(token, runningLockInfo); - EXPECT_TRUE(error == PowerErrors::ERR_OK); - g_powerMgrServiceProxy->OverrideScreenOffTime(time); - - g_powerMgrServiceProxy->Lock(token); - EXPECT_EQ(g_powerMgrServiceProxy->IsUsed(token), true); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->UnLock(token); - EXPECT_EQ(g_powerMgrServiceProxy->IsUsed(token), false); - g_powerMgrServiceProxy->OverrideScreenOffTime(PowerStateMachine::DEFAULT_SLEEP_TIME_MS); - EXPECT_TRUE(g_powerMgrServiceProxy->ReleaseRunningLock(token)); + g_powerMgrServiceProxy->CreateRunningLockIpc(token, runningLockInfo, powerError); + EXPECT_TRUE(powerError == static_cast(PowerErrors::ERR_OK)); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(time, powerError); + + g_powerMgrServiceProxy->LockIpc(token, timeOutMs, powerError); + g_powerMgrServiceProxy->IsUsedIpc(token, isUsed); + EXPECT_EQ(isUsed, true); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->UnLockIpc(token, name, powerError); + g_powerMgrServiceProxy->IsUsedIpc(token, isUsed); + EXPECT_EQ(isUsed, false); + g_powerMgrServiceProxy->OverrideScreenOffTimeIpc(PowerStateMachine::DEFAULT_SLEEP_TIME_MS, powerError); + EXPECT_EQ(g_powerMgrServiceProxy->ReleaseRunningLockIpc(token), ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest012 function end!"); } @@ -394,12 +496,16 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest012, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest013, TestSize.Level2) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest013 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - g_powerMgrServiceProxy->SetDisplaySuspend(true); - - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - g_powerMgrServiceProxy->SetDisplaySuspend(false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + g_powerMgrServiceProxy->SetDisplaySuspendIpc(true); + + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + g_powerMgrServiceProxy->SetDisplaySuspendIpc(false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest013 function end!"); } @@ -412,11 +518,16 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest013, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest014, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest014 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest014 function end!"); } @@ -429,11 +540,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest014, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest015, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest015 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice(GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_DEVICE_ADMIN, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), + static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_DEVICE_ADMIN), false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest015 function end!"); } @@ -446,11 +563,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest015, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest016, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest016 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice(GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), + static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT), false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest016 function end!"); } @@ -463,11 +586,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest016, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest017, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest017 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice(GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_LID, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), + static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_LID), false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest017 function end!"); } @@ -480,11 +609,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest017, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest018, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest018 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice(GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), + static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY), false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest018 function end!"); } @@ -497,11 +632,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest018, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest019, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest019 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice(GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_HDMI, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), + static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_HDMI), false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest019 function end!"); } @@ -514,11 +655,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest019, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest020, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest020 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice(GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_SLEEP_KEY, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), + static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_SLEEP_KEY), false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest020 function end!"); } @@ -531,12 +678,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest020, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest021, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest021 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice( - GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_ACCESSIBILITY, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + int32_t suspendAcc = static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_ACCESSIBILITY); + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), suspendAcc, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest021 function end!"); } @@ -549,12 +701,17 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest021, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest022, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest022 function start!"); - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - - g_powerMgrServiceProxy->SuspendDevice( - GetTickCount(), SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND, false); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + int32_t powerError = 1; + bool isScreenOn = false; + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), + static_cast(SuspendDeviceType::SUSPEND_DEVICE_REASON_FORCE_SUSPEND), false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest022 function end!"); } @@ -567,12 +724,19 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest022, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest023, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest023 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest023 function end!"); } @@ -585,12 +749,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest023, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest024, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest024 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest024 function end!"); } @@ -603,12 +775,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest024, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest025, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest025 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest025 function end!"); } @@ -621,12 +801,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest025, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest026, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest026 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_PLUGGED_IN); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_PLUGGED_IN), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest026 function end!"); } @@ -639,12 +827,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest026, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest027, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest027 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_GESTURE); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_GESTURE), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest027 function end!"); } @@ -657,12 +853,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest027, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest028, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest028 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_CAMERA_LAUNCH); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_CAMERA_LAUNCH), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest028 function end!"); } @@ -675,12 +879,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest028, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest029, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest029 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_WAKE_KEY); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_WAKE_KEY), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest029 function end!"); } @@ -693,12 +905,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest029, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest030, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest030 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_WAKE_MOTION); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_WAKE_MOTION), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest030 function end!"); } @@ -711,12 +931,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest030, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest031, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest031 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_HDMI); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_HDMI), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest031 function end!"); } @@ -729,12 +957,19 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest031, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest032, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest032 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_LID); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), static_cast(WakeupDeviceType::WAKEUP_DEVICE_LID), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest032 function end!"); } @@ -747,12 +982,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest032, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest033, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest033 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_DOUBLE_CLICK); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_DOUBLE_CLICK), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest033 function end!"); } @@ -765,12 +1008,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest033, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest034, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest034 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_KEYBOARD); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_KEYBOARD), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest034 function end!"); } @@ -783,12 +1034,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest034, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest035, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest035 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_MOUSE); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_MOUSE), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest035 function end!"); } @@ -801,20 +1060,30 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest035, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest036, TestSize.Level2) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest036 function start!"); - auto ret = g_powerMgrServiceProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BUTT); - EXPECT_EQ(ret, false); - ret = g_powerMgrServiceProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_SCREEN); - EXPECT_EQ(ret, true); - ret = g_powerMgrServiceProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_BACKGROUND); - EXPECT_EQ(ret, true); + int32_t powerError = 1; + bool lockTypeSupported = false; + bool isScreenOn = false; + g_powerMgrServiceProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_BUTT), lockTypeSupported); + EXPECT_EQ(lockTypeSupported, false); + g_powerMgrServiceProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_SCREEN), lockTypeSupported); + EXPECT_EQ(lockTypeSupported, true); + g_powerMgrServiceProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_BACKGROUND), lockTypeSupported); + EXPECT_EQ(lockTypeSupported, true); #ifdef HAS_SENSORS_SENSOR_PART - ret = g_powerMgrServiceProxy->IsRunningLockTypeSupported(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL); - EXPECT_EQ(ret, true); + g_powerMgrServiceProxy->IsRunningLockTypeSupportedIpc( + static_cast(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL), lockTypeSupported); + EXPECT_EQ(lockTypeSupported, true); #endif - g_powerMgrServiceProxy->WakeupDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); + g_powerMgrServiceProxy->WakeupDeviceIpc( + GetTickCount(), REASON_VALUE, std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest036 function end!"); } @@ -832,14 +1101,14 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest037, TestSize.Level sptr screenOffPreCallback = new ScreenOffPreTestCallback(); sptr RunninglockCallback =new PowerRunningLockTestCallback(); - EXPECT_TRUE(g_powerMgrServiceProxy->RegisterPowerStateCallback(stateCallback)); - EXPECT_TRUE(g_powerMgrServiceProxy->UnRegisterPowerStateCallback(stateCallback)); - EXPECT_TRUE(g_powerMgrServiceProxy->RegisterPowerModeCallback(modeCallback)); - EXPECT_TRUE(g_powerMgrServiceProxy->UnRegisterPowerModeCallback(modeCallback)); - EXPECT_TRUE(g_powerMgrServiceProxy->RegisterScreenStateCallback(4000, screenOffPreCallback)); - EXPECT_TRUE(g_powerMgrServiceProxy->UnRegisterScreenStateCallback(screenOffPreCallback)); - EXPECT_TRUE(g_powerMgrServiceProxy->RegisterRunningLockCallback(RunninglockCallback)); - EXPECT_TRUE(g_powerMgrServiceProxy->UnRegisterRunningLockCallback(RunninglockCallback)); + EXPECT_EQ(g_powerMgrServiceProxy->RegisterPowerStateCallbackIpc(stateCallback), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->UnRegisterPowerStateCallbackIpc(stateCallback), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->RegisterPowerModeCallbackIpc(modeCallback), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->UnRegisterPowerModeCallbackIpc(modeCallback), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->RegisterScreenStateCallbackIpc(4000, screenOffPreCallback), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->UnRegisterScreenStateCallbackIpc(screenOffPreCallback), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->RegisterRunningLockCallbackIpc(RunninglockCallback), ERR_OK); + EXPECT_EQ(g_powerMgrServiceProxy->UnRegisterRunningLockCallbackIpc(RunninglockCallback), ERR_OK); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest037 function end!"); } @@ -860,11 +1129,13 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest038, TestSize.Level std::string expectedDebugInfo; expectedDebugInfo.append("Power manager dump options:\n"); - std::string noneDebugInfo = g_powerMgrServiceProxy->ShellDump(dumpArgsNone, dumpArgsNone.size()); + std::string noneDebugInfo; + g_powerMgrServiceProxy->ShellDumpIpc(dumpArgsNone, dumpArgsNone.size(), noneDebugInfo); auto noneIndex = noneDebugInfo.find(expectedDebugInfo); EXPECT_TRUE(noneIndex != string::npos); - std::string helpDebugInfo = g_powerMgrServiceProxy->ShellDump(dumpArgsHelp, dumpArgsHelp.size()); + std::string helpDebugInfo; + g_powerMgrServiceProxy->ShellDumpIpc(dumpArgsHelp, dumpArgsHelp.size(), helpDebugInfo); auto helpIndex = helpDebugInfo.find(expectedDebugInfo); EXPECT_TRUE(helpIndex != string::npos); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest038 function end!"); @@ -880,8 +1151,9 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest039, TestSize.Level { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest039 function start!"); bool standby = false; - auto error = g_powerMgrServiceProxy->IsStandby(standby); - EXPECT_NE(error, PowerErrors::ERR_CONNECTION_FAIL); + int32_t powerError = 1; + g_powerMgrServiceProxy->IsStandbyIpc(standby, powerError); + EXPECT_NE(powerError, static_cast(PowerErrors::ERR_CONNECTION_FAIL)); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest039 function end!"); } @@ -894,12 +1166,20 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest039, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest040, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest040 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_AOD_SLIDING); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), + static_cast(WakeupDeviceType::WAKEUP_DEVICE_AOD_SLIDING), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest040 function end!"); } @@ -912,12 +1192,19 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest040, TestSize.Level HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNativeTest041, TestSize.Level0) { POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest041 function start!"); - g_powerMgrServiceProxy->SuspendDevice(GetTickCount()); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), false); - - g_powerMgrServiceProxy->WakeupDevice(GetTickCount(), WakeupDeviceType::WAKEUP_DEVICE_PEN); - EXPECT_EQ(g_powerMgrServiceProxy->GetState(), PowerState::AWAKE); - EXPECT_EQ(g_powerMgrServiceProxy->IsScreenOn(), true); + int32_t powerError = 1; + int32_t powerState = -1; + bool isScreenOn = false; + g_powerMgrServiceProxy->SuspendDeviceIpc(GetTickCount(), REASON_VALUE, false, API_VERSION, powerError); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, false); + + g_powerMgrServiceProxy->WakeupDeviceIpc(GetTickCount(), static_cast(WakeupDeviceType::WAKEUP_DEVICE_PEN), + std::string("app call"), API_VERSION, powerError); + g_powerMgrServiceProxy->GetStateIpc(powerState); + EXPECT_EQ(powerState, static_cast(PowerState::AWAKE)); + g_powerMgrServiceProxy->IsScreenOnIpc(true, isScreenOn); + EXPECT_EQ(isScreenOn, true); POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNativeTest041 function end!"); } } // namespace diff --git a/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp b/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp index abf158b4..991cb4d6 100644 --- a/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp +++ b/test/unittest/src/servicetest/powermgr_service_test_proxy.cpp @@ -20,11 +20,13 @@ #include "errors.h" #include "message_option.h" +#include "hilog/log.h" #include "power_common.h" #include "power_log.h" -#include "power_mgr_ipc_interface_code.h" +#include "ipower_mgr.h" #include "power_mgr_proxy.h" +using OHOS::HiviewDFX::HiLog; namespace OHOS { namespace PowerMgr { constexpr int32_t MAX_PROXY_RUNNINGLOCK_NUM = 2000; @@ -35,871 +37,1232 @@ PowerMgrServiceTestProxy::PowerMgrServiceTestProxy(const sptr& } } -PowerErrors PowerMgrServiceTestProxy::CreateRunningLock(const sptr& remoteObj, - const RunningLockInfo& runningLockInfo) +int32_t PowerMgrServiceTestProxy::CreateRunningLockIpc(const sptr& remoteObj, + const RunningLockInfo& runningLockInfo, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(remoteObj.GetRefPtr()); - data.WriteParcelable(&runningLockInfo); + if (!data.WriteRemoteObject(remoteObj)) { + HiLog::Error(LABEL, "Write [remoteObj] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&runningLockInfo)) { + HiLog::Error(LABEL, "Write [runningLockInfo] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::CREATE_RUNNINGLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_CREATE_RUNNING_LOCK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_CREATE_RUNNING_LOCK_IPC)); + return errCode; + } + + powerError = reply.ReadInt32(); + return ERR_OK; } -bool PowerMgrServiceTestProxy::ReleaseRunningLock(const sptr& remoteObj, const std::string& name) +int32_t PowerMgrServiceTestProxy::ReleaseRunningLockIpc(const sptr& remoteObj, const std::string& name) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteRemoteObject(remoteObj)) { + HiLog::Error(LABEL, "Write [remoteObj] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(name))) { + HiLog::Error(LABEL, "Write [name] failed!"); + return ERR_INVALID_DATA; } - data.WriteRemoteObject(remoteObj.GetRefPtr()); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, name, false); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_RELEASE_RUNNING_LOCK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RELEASE_RUNNINGLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_RELEASE_RUNNING_LOCK_IPC)); + return errCode; } - return true; + + return ERR_OK; } -bool PowerMgrServiceTestProxy::IsRunningLockTypeSupported(RunningLockType type) +int32_t PowerMgrServiceTestProxy::IsRunningLockTypeSupportedIpc(int32_t lockType, bool& lockTypesSupported) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); - bool result = false; MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return result; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteUint32(static_cast(type)); + if (!data.WriteInt32(lockType)) { + HiLog::Error(LABEL, "Write [lockType] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_RUNNINGLOCK_TYPE_SUPPORTED), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_IS_RUNNING_LOCK_TYPE_SUPPORTED_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); return result; } - if (!reply.ReadBool(result)) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "ReadBool fail"); + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_IS_RUNNING_LOCK_TYPE_SUPPORTED_IPC)); + return errCode; } - return result; + lockTypesSupported = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; } -bool PowerMgrServiceTestProxy::Lock(const sptr& remoteObj, int32_t timeOutMs) +int32_t PowerMgrServiceTestProxy::LockIpc(const sptr& remoteObj, int32_t timeOutMs, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(remoteObj.GetRefPtr()); - data.WriteInt32(timeOutMs); + if (!data.WriteRemoteObject(remoteObj)) { + HiLog::Error(LABEL, "Write [remoteObj] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(timeOutMs)) { + HiLog::Error(LABEL, "Write [timeOutMs] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_LOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_LOCK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_LOCK_IPC)); + return errCode; } - return true; + + powerError = reply.ReadInt32(); + return ERR_OK; } -bool PowerMgrServiceTestProxy::UnLock(const sptr& remoteObj, const std::string& name) +int32_t PowerMgrServiceTestProxy::UnLockIpc(const sptr& remoteObj, + const std::string& name, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(remoteObj.GetRefPtr()); - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, name, false); + if (!data.WriteRemoteObject(remoteObj)) { + HiLog::Error(LABEL, "Write [remoteObj] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(name))) { + HiLog::Error(LABEL, "Write [name] failed!"); + return ERR_INVALID_DATA; + } + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_UN_LOCK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_UNLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_UN_LOCK_IPC)); + return errCode; } - return true; + + powerError = reply.ReadInt32(); + return ERR_OK; } -bool PowerMgrServiceTestProxy::IsUsed(const sptr& remoteObj) +int32_t PowerMgrServiceTestProxy::IsUsedIpc(const sptr& remoteObj, bool& isUsed) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(remoteObj.GetRefPtr()); - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_ISUSED), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + if (!data.WriteRemoteObject(remoteObj)) { + HiLog::Error(LABEL, "Write [remoteObj] failed!"); + return ERR_INVALID_DATA; } - bool used = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, used, false); - return used; + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_IS_USED_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_IS_USED_IPC)); + return errCode; + } + + isUsed = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; } -bool PowerMgrServiceTestProxy::ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid) +int32_t PowerMgrServiceTestProxy::ProxyRunningLockIpc(bool isProxied, int32_t pid, int32_t uid) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteBool(isProxied); - data.WriteInt32(pid); - data.WriteInt32(uid); + if (!data.WriteInt32(isProxied ? 1 : 0)) { + HiLog::Error(LABEL, "Write [isProxied] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(pid)) { + HiLog::Error(LABEL, "Write [pid] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(uid)) { + HiLog::Error(LABEL, "Write [uid] failed!"); + return ERR_INVALID_DATA; + } + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCK_IPC)); + return errCode; } - bool succ = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false); - return succ; + + return ERR_OK; } -bool PowerMgrServiceTestProxy::ProxyRunningLocks(bool isProxied, - const std::vector>& processInfos) +int32_t PowerMgrServiceTestProxy::ProxyRunningLocksIpc(bool isProxied, const VectorPair& vectorPairInfos) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - int32_t size = processInfos.size(); - data.WriteBool(isProxied); - data.WriteUint32(size); - if (size > MAX_PROXY_RUNNINGLOCK_NUM) { - POWER_HILOGE(COMP_FWK, "size exceed limit, size=%{public}d", size); - return false; + if (!data.WriteInt32(isProxied ? 1 : 0)) { + HiLog::Error(LABEL, "Write [isProxied] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&vectorPairInfos)) { + HiLog::Error(LABEL, "Write [vectorPairInfos] failed!"); + return ERR_INVALID_DATA; } - for (int i = 0; i < size; ++i) { - data.WriteInt32(processInfos[i].first); - data.WriteInt32(processInfos[i].second); + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCKS_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCKS), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_PROXY_RUNNING_LOCKS_IPC)); + return errCode; } - bool succ = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false); - return succ; + + return ERR_OK; } -bool PowerMgrServiceTestProxy::ResetRunningLocks() +int32_t PowerMgrServiceTestProxy::ResetRunningLocksIpc() { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_RESET_RUNNING_LOCKS_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - int ret = stub_->SendRequest(static_cast(PowerMgr::PowerMgrInterfaceCode::RESET_RUNNINGLOCKS), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_RESET_RUNNING_LOCKS_IPC)); + return errCode; } - bool succ = false; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false); - return succ; + + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::RebootDevice(const std::string& reason) +int32_t PowerMgrServiceTestProxy::RebootDeviceIpc(const std::string& reason, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteString16(Str8ToStr16(reason)); + if (!data.WriteString16(Str8ToStr16(reason))) { + HiLog::Error(LABEL, "Write [reason] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_REBOOT_DEVICE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_REBOOT_DEVICE_IPC)); + return errCode; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + powerError = reply.ReadInt32(); + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::ShutDownDevice(const std::string& reason) +int32_t PowerMgrServiceTestProxy::ShutDownDeviceIpc(const std::string& reason, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(reason))) { + HiLog::Error(LABEL, "Write [reason] failed!"); + return ERR_INVALID_DATA; } - data.WriteString16(Str8ToStr16(reason)); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_SHUT_DOWN_DEVICE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SHUTDOWN_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_SHUT_DOWN_DEVICE_IPC)); + return errCode; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + powerError = reply.ReadInt32(); + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed) +int32_t PowerMgrServiceTestProxy::SuspendDeviceIpc(int64_t callTimeMs, int32_t reasonValue, + bool suspendImmed, const std::string& apiVersion, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteInt64(callTimeMs); - data.WriteUint32(static_cast(reason)); - data.WriteBool(suspendImmed); + if (!data.WriteInt64(callTimeMs)) { + HiLog::Error(LABEL, "Write [callTimeMs] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(reasonValue)) { + HiLog::Error(LABEL, "Write [reasonValue] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(suspendImmed ? 1 : 0)) { + HiLog::Error(LABEL, "Write [suspendImmed] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(apiVersion))) { + HiLog::Error(LABEL, "Write [apiVersion] failed!"); + return ERR_INVALID_DATA; + } + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_SUSPEND_DEVICE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SUSPEND_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_SUSPEND_DEVICE_IPC)); + return errCode; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + powerError = reply.ReadInt32(); + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, - const std::string& details) +int32_t PowerMgrServiceTestProxy::WakeupDeviceIpc(int64_t callTimeMs, int32_t reasonValue, + const std::string& details, const std::string& apiVersion, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_WAKEUP, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteInt64(callTimeMs); - data.WriteUint32(static_cast(reason)); - data.WriteString16(Str8ToStr16(details)); + if (!data.WriteInt64(callTimeMs)) { + HiLog::Error(LABEL, "Write [callTimeMs] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(reasonValue)) { + HiLog::Error(LABEL, "Write [reasonValue] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(details))) { + HiLog::Error(LABEL, "Write [details] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(apiVersion))) { + HiLog::Error(LABEL, "Write [apiVersion] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_WAKEUP, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_WAKEUP_DEVICE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_WAKEUP_DEVICE_IPC)); + return errCode; + } + + powerError = reply.ReadInt32(); + return ERR_OK; } -bool PowerMgrServiceTestProxy::RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) +int32_t PowerMgrServiceTestProxy::RefreshActivityIpc(int64_t callTimeMs, int32_t activityType, bool needChangeBacklight) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_ACTIVITY, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteInt64(callTimeMs); - data.WriteUint32(static_cast(type)); - data.WriteBool(needChangeBacklight); + if (!data.WriteInt64(callTimeMs)) { + HiLog::Error(LABEL, "Write [callTimeMs] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(activityType)) { + HiLog::Error(LABEL, "Write [activityType] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(needChangeBacklight ? 1 : 0)) { + HiLog::Error(LABEL, "Write [needChangeBacklight] failed!"); + return ERR_INVALID_DATA; + } + uint32_t code = static_cast(IPowerMgrIpcCode::COMMAND_REFRESH_ACTIVITY_IPC) + int32_t result = stub_->OnRemoteRequest(code, data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REFRESH_ACTIVITY), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_ACTIVITY, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", code); + return errCode; } - return true; + + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::OverrideScreenOffTime(int64_t timeout) +int32_t PowerMgrServiceTestProxy::OverrideScreenOffTimeIpc(int64_t timeout, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_SVC, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt64(timeout)) { + HiLog::Error(LABEL, "Write [timeout] failed!"); + return ERR_INVALID_DATA; } - data.WriteInt64(timeout); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_OVERRIDE_SCREEN_OFF_TIME_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_TIME), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_SVC, "SendRequest is failed, ret: %{public}d", ret); - return PowerErrors::ERR_CONNECTION_FAIL; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_OVERRIDE_SCREEN_OFF_TIME_IPC)); + return errCode; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + powerError = reply.ReadInt32(); + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::RestoreScreenOffTime() +int32_t PowerMgrServiceTestProxy::RestoreScreenOffTimeIpc(const std::string& apiVersion, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::RESTORE_DISPLAY_OFF_TIME), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "SendRequest is failed, ret: %{public}d", ret); - return PowerErrors::ERR_CONNECTION_FAIL; + if (!data.WriteString16(Str8ToStr16(apiVersion))) { + HiLog::Error(LABEL, "Write [apiVersion] failed!"); + return ERR_INVALID_DATA; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_RESTORE_SCREEN_OFF_TIME_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_RESTORE_SCREEN_OFF_TIME_IPC)); + return errCode; + } + + powerError = reply.ReadInt32(); + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::ForceSuspendDevice(int64_t callTimeMs) +int32_t PowerMgrServiceTestProxy::ForceSuspendDeviceIpc(int64_t callTimeMs) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteInt64(callTimeMs); + if (!data.WriteInt64(callTimeMs)) { + HiLog::Error(LABEL, "Write [callTimeMs] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::FORCE_DEVICE_SUSPEND), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "SendRequest is failed, ret: %{public}d", ret); - return PowerErrors::ERR_CONNECTION_FAIL; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_FORCE_SUSPEND_DEVICE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + int32_t error = ERR_OK; + RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, ERR_OK); + return error; } -PowerState PowerMgrServiceTestProxy::GetState() +int32_t PowerMgrServiceTestProxy::GetStateIpc(int32_t& powerState) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerState::UNKNOWN); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); - uint32_t result = 0; MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return PowerState::UNKNOWN; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::GET_STATE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerState::UNKNOWN; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_GET_STATE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - if (!reply.ReadUint32(result)) { - POWER_HILOGE(FEATURE_POWER_STATE, "ReadUint32 failed"); - return PowerState::UNKNOWN; + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_GET_STATE_IPC)); + return errCode; } - return static_cast(result); + powerState = reply.ReadInt32(); + return ERR_OK; } -bool PowerMgrServiceTestProxy::IsScreenOn(bool needPrintLog) +int32_t PowerMgrServiceTestProxy::IsScreenOnIpc(bool needPrintLog, bool& isScreenOn) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); - bool result = false; MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return result; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(needPrintLog ? 1 : 0)) { + HiLog::Error(LABEL, "Write [needPrintLog] failed!"); + return ERR_INVALID_DATA; } - RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, needPrintLog, false); - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_SCREEN_ON), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_IS_SCREEN_ON_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); return result; } - if (!reply.ReadBool(result)) { - POWER_HILOGE(COMP_FWK, "ReadBool fail"); + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_IS_SCREEN_ON_IPC)); + return errCode; } - return result; + isScreenOn = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; } -bool PowerMgrServiceTestProxy::RegisterPowerStateCallback(const sptr& callback, bool isSync) +int32_t PowerMgrServiceTestProxy::RegisterPowerStateCallbackIpc( + const sptr& powerCallback, bool isSync) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(callback->AsObject()); - data.WriteBool(isSync); + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(isSync ? 1 : 0)) { + HiLog::Error(LABEL, "Write [isSync] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_POWER_STATE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_STATE_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - return true; + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_STATE_CALLBACK_IPC)); + return errCode; + } + + return ERR_OK; } -bool PowerMgrServiceTestProxy::UnRegisterPowerStateCallback(const sptr& callback) +int32_t PowerMgrServiceTestProxy::UnRegisterPowerStateCallbackIpc(const sptr& powerCallback) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(callback->AsObject()); + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_STATE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_STATE_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - return true; + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_STATE_CALLBACK_IPC)); + return errCode; + } + + return ERR_OK; } -bool PowerMgrServiceTestProxy::RegisterPowerModeCallback(const sptr& callback) +int32_t PowerMgrServiceTestProxy::RegisterPowerModeCallbackIpc(const sptr& powerCallback) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(callback->AsObject()); + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_POWER_MODE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_MODE_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - return true; + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_POWER_MODE_CALLBACK_IPC)); + return errCode; + } + + return ERR_OK; } -bool PowerMgrServiceTestProxy::UnRegisterPowerModeCallback(const sptr& callback) +int32_t PowerMgrServiceTestProxy::UnRegisterPowerModeCallbackIpc(const sptr& powerCallback) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(callback->AsObject()); + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_MODE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_MODE_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_POWER_MODE_CALLBACK_IPC)); + return errCode; } - return true; + + return ERR_OK; } -bool PowerMgrServiceTestProxy::RegisterScreenStateCallback(int32_t remainTime, - const sptr& callback) +int32_t PowerMgrServiceTestProxy::RegisterScreenStateCallbackIpc( + int32_t remainTime, const sptr& powerCallback) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (remainTime <= 0) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(remainTime)) { + HiLog::Error(LABEL, "Write [remainTime] failed!"); + return ERR_INVALID_DATA; + } + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; + } + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_SCREEN_STATE_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - data.WriteInt32(remainTime); - data.WriteRemoteObject(callback->AsObject()); - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SCREEN_OFF_PRE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_SCREEN_STATE_CALLBACK_IPC)); + return errCode; } - return true; + + return ERR_OK; } -bool PowerMgrServiceTestProxy::UnRegisterScreenStateCallback(const sptr& callback) +int32_t PowerMgrServiceTestProxy::UnRegisterScreenStateCallbackIpc(const sptr& powerCallback) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(callback->AsObject()); + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; + } + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SCREEN_STATE_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SCREEN_OFF_PRE_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_SCREEN_STATE_CALLBACK_IPC)); + return errCode; } - return true; + + return ERR_OK; } -bool PowerMgrServiceTestProxy::RegisterRunningLockCallback(const sptr& callback) +int32_t PowerMgrServiceTestProxy::RegisterRunningLockCallbackIpc(const sptr& powerCallback) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteRemoteObject(callback->AsObject()); + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::REG_RUNNINGLOCK_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_RUNNING_LOCK_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - return true; + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_REGISTER_RUNNING_LOCK_CALLBACK_IPC)); + return errCode; + } + + return ERR_OK; } -bool PowerMgrServiceTestProxy::UnRegisterRunningLockCallback(const sptr& callback) +int32_t PowerMgrServiceTestProxy::UnRegisterRunningLockCallbackIpc(const sptr& powerCallback) { - RETURN_IF_WITH_RET((stub_ == nullptr) || (callback == nullptr), false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (powerCallback == nullptr) { + HiLog::Error(LABEL, "powerCallback is nullptr!"); + return ERR_INVALID_DATA; + } + if (!data.WriteRemoteObject(powerCallback->AsObject())) { + HiLog::Error(LABEL, "Write [powerCallback] failed!"); + return ERR_INVALID_DATA; } - data.WriteRemoteObject(callback->AsObject()); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_RUNNING_LOCK_CALLBACK_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_RUNNINGLOCK_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_UN_REGISTER_RUNNING_LOCK_CALLBACK_IPC)); + return errCode; } - return true; + + return ERR_OK; } -bool PowerMgrServiceTestProxy::SetDisplaySuspend(bool enable) +int32_t PowerMgrServiceTestProxy::SetDisplaySuspendIpc(bool enable) { - RETURN_IF_WITH_RET(stub_ == nullptr, false); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); - return false; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(enable ? 1 : 0)) { + HiLog::Error(LABEL, "Write [enable] failed!"); + return ERR_INVALID_DATA; } - data.WriteBool(enable); + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_SET_DISPLAY_SUSPEND_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SET_DISPLAY_SUSPEND), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return false; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_SET_DISPLAY_SUSPEND_IPC)); + return errCode; } - return true; + + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::SetDeviceMode(const PowerMode& mode) +int32_t PowerMgrServiceTestProxy::SetDeviceModeIpc(int32_t modeValue, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteUint32(static_cast(mode)); + if (!data.WriteInt32(modeValue)) { + HiLog::Error(LABEL, "Write [modeValue] failed!"); + return ERR_INVALID_DATA; + } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SETMODE_DEVICE), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_SET_DEVICE_MODE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - int32_t error; - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); - return static_cast(error); + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_SET_DEVICE_MODE_IPC)); + return errCode; + } + + powerError = reply.ReadInt32(); + return ERR_OK; } -PowerMode PowerMgrServiceTestProxy::GetDeviceMode() +int32_t PowerMgrServiceTestProxy::GetDeviceModeIpc(int32_t& powerMode) { - RETURN_IF_WITH_RET(stub_ == nullptr, static_cast(false)); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed"); - return PowerMode::NORMAL_MODE; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::GETMODE_DEVICE), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerMode::NORMAL_MODE; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_GET_DEVICE_MODE_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - uint32_t used = static_cast(PowerMode::NORMAL_MODE); - if (!reply.ReadUint32(used)) { - POWER_HILOGE(FEATURE_POWER_MODE, "ReadUint32 fail"); + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_GET_DEVICE_MODE_IPC)); + return errCode; } - return static_cast(used); + + powerMode = reply.ReadInt32(); + return ERR_OK; } -std::string PowerMgrServiceTestProxy::ShellDump(const std::vector& args, uint32_t argc) +int32_t PowerMgrServiceTestProxy::ShellDumpIpc(const std::vector& args, + uint32_t argc, std::string& returnDump) { - std::string result = "remote error"; - RETURN_IF_WITH_RET(stub_ == nullptr, result); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return result; - } - if (argc > args.size()) { - POWER_HILOGE(COMP_FWK, "argc is greater than args size!"); - return result; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - data.WriteUint32(argc); - for (uint32_t i = 0; i < argc; i++) { - data.WriteString(args[i]); + if (args.size() > static_cast(VECTOR_MAX_SIZE)) { + HiLog::Error(LABEL, "The vector/array size exceeds the security limit!"); + return ERR_INVALID_DATA; } - int ret = stub_->OnRemoteRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::SHELL_DUMP), - data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); + data.WriteInt32(args.size()); + for (auto it3 = args.begin(); it3 != args.end(); ++it3) { + if (!data.WriteString16(Str8ToStr16((*it3)))) { + HiLog::Error(LABEL, "Write [(*it3)] failed!"); + return ERR_INVALID_DATA; + } + } + if (!data.WriteUint32(argc)) { + HiLog::Error(LABEL, "Write [argc] failed!"); + return ERR_INVALID_DATA; + } + + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_SHELL_DUMP_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); return result; } - result = reply.ReadString(); - return result; + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_SHELL_DUMP_IPC)); + return errCode; + } + + returnDump = Str16ToStr8(reply.ReadString16()); + return ERR_OK; } -PowerErrors PowerMgrServiceTestProxy::IsStandby(bool& isStandby) +int32_t PowerMgrServiceTestProxy::IsStandbyIpc(bool& isStandby, int32_t& powerError) { - RETURN_IF_WITH_RET(stub_ == nullptr, PowerErrors::ERR_CONNECTION_FAIL); + RETURN_IF_WITH_RET(stub_ == nullptr, ERR_INVALID_DATA); MessageParcel data; MessageParcel reply; - MessageOption option; + MessageOption option(MessageOption::TF_SYNC); if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { - POWER_HILOGE(COMP_FWK, "Write descriptor failed"); - return PowerErrors::ERR_CONNECTION_FAIL; + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; } - int32_t ret = stub_->SendRequest( - static_cast(PowerMgr::PowerMgrInterfaceCode::IS_STANDBY), data, reply, option); - if (ret != ERR_OK) { - POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret); - return PowerErrors::ERR_CONNECTION_FAIL; + int32_t result = stub_->OnRemoteRequest( + static_cast(IPowerMgrIpcCode::COMMAND_IS_STANDBY_IPC), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; } - int32_t error; - - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL); - RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, isStandby, PowerErrors::ERR_CONNECTION_FAIL); + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IPowerMgrIpcCode::COMMAND_IS_STANDBY_IPC)); + return errCode; + } - return static_cast(error); + isStandby = reply.ReadInt32() == 1 ? true : false; + powerError = reply.ReadInt32(); + return ERR_OK; } } // namespace PowerMgr } // namespace OHOS -- Gitee