/* * 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 { 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; 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::map& 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.first, false); RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, wks.second, 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; 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; 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(); 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); 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; 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; 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; 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; 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) { 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); 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; 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) { 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); 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; 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) { 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); 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; RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); return static_cast(error); } PowerErrors PowerMgrProxy::RestoreScreenOffTime() { 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; } 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; RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK); return static_cast(error); } PowerErrors PowerMgrProxy::ForceSuspendDevice(int64_t callTimeMs) { 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); 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) { 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); 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; 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; } 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; 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; 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; 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); } } // namespace PowerMgr } // namespace OHOS