15ccb8f90Sopenharmony_ci/*
25ccb8f90Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
35ccb8f90Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45ccb8f90Sopenharmony_ci * you may not use this file except in compliance with the License.
55ccb8f90Sopenharmony_ci * You may obtain a copy of the License at
65ccb8f90Sopenharmony_ci *
75ccb8f90Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85ccb8f90Sopenharmony_ci *
95ccb8f90Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105ccb8f90Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115ccb8f90Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125ccb8f90Sopenharmony_ci * See the License for the specific language governing permissions and
135ccb8f90Sopenharmony_ci * limitations under the License.
145ccb8f90Sopenharmony_ci */
155ccb8f90Sopenharmony_ci
165ccb8f90Sopenharmony_ci#include "power_mgr_proxy.h"
175ccb8f90Sopenharmony_ci#include "power_mgr_async_reply.h"
185ccb8f90Sopenharmony_ci
195ccb8f90Sopenharmony_ci#include <message_parcel.h>
205ccb8f90Sopenharmony_ci#include <string_ex.h>
215ccb8f90Sopenharmony_ci#include "message_option.h"
225ccb8f90Sopenharmony_ci#include "shutdown_proxy_delegator.h"
235ccb8f90Sopenharmony_ci#include "power_log.h"
245ccb8f90Sopenharmony_ci#include "power_common.h"
255ccb8f90Sopenharmony_ci#include "power_mgr_ipc_interface_code.h"
265ccb8f90Sopenharmony_ci#include "running_lock_info.h"
275ccb8f90Sopenharmony_ci
285ccb8f90Sopenharmony_cinamespace OHOS {
295ccb8f90Sopenharmony_cinamespace PowerMgr {
305ccb8f90Sopenharmony_ciconstexpr uint32_t MAX_PROXY_RUNNINGLOCK_NUM = 2000;
315ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::CreateRunningLock(const sptr<IRemoteObject>& remoteObj,
325ccb8f90Sopenharmony_ci    const RunningLockInfo& runningLockInfo)
335ccb8f90Sopenharmony_ci{
345ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
355ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
365ccb8f90Sopenharmony_ci
375ccb8f90Sopenharmony_ci    MessageParcel data;
385ccb8f90Sopenharmony_ci    MessageParcel reply;
395ccb8f90Sopenharmony_ci    MessageOption option;
405ccb8f90Sopenharmony_ci
415ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
425ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
435ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
445ccb8f90Sopenharmony_ci    }
455ccb8f90Sopenharmony_ci
465ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL);
475ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Parcelable, &runningLockInfo, PowerErrors::ERR_CONNECTION_FAIL);
485ccb8f90Sopenharmony_ci
495ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
505ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::CREATE_RUNNINGLOCK),
515ccb8f90Sopenharmony_ci        data, reply, option);
525ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
535ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
545ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
555ccb8f90Sopenharmony_ci    }
565ccb8f90Sopenharmony_ci    int32_t error;
575ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
585ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
595ccb8f90Sopenharmony_ci}
605ccb8f90Sopenharmony_ci
615ccb8f90Sopenharmony_cibool PowerMgrProxy::ReleaseRunningLock(const sptr<IRemoteObject>& remoteObj, const std::string& name)
625ccb8f90Sopenharmony_ci{
635ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
645ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
655ccb8f90Sopenharmony_ci
665ccb8f90Sopenharmony_ci    MessageParcel data;
675ccb8f90Sopenharmony_ci    MessageParcel reply;
685ccb8f90Sopenharmony_ci    MessageOption option;
695ccb8f90Sopenharmony_ci
705ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
715ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
725ccb8f90Sopenharmony_ci        return false;
735ccb8f90Sopenharmony_ci    }
745ccb8f90Sopenharmony_ci
755ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), false);
765ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, name, false);
775ccb8f90Sopenharmony_ci
785ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
795ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RELEASE_RUNNINGLOCK),
805ccb8f90Sopenharmony_ci        data, reply, option);
815ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
825ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
835ccb8f90Sopenharmony_ci        return false;
845ccb8f90Sopenharmony_ci    }
855ccb8f90Sopenharmony_ci    return true;
865ccb8f90Sopenharmony_ci}
875ccb8f90Sopenharmony_ci
885ccb8f90Sopenharmony_cibool PowerMgrProxy::IsRunningLockTypeSupported(RunningLockType type)
895ccb8f90Sopenharmony_ci{
905ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
915ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
925ccb8f90Sopenharmony_ci
935ccb8f90Sopenharmony_ci    bool result = false;
945ccb8f90Sopenharmony_ci    MessageParcel data;
955ccb8f90Sopenharmony_ci    MessageParcel reply;
965ccb8f90Sopenharmony_ci    MessageOption option;
975ccb8f90Sopenharmony_ci
985ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
995ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
1005ccb8f90Sopenharmony_ci        return result;
1015ccb8f90Sopenharmony_ci    }
1025ccb8f90Sopenharmony_ci
1035ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast<uint32_t>(type), false);
1045ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
1055ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_RUNNINGLOCK_TYPE_SUPPORTED),
1065ccb8f90Sopenharmony_ci        data, reply, option);
1075ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
1085ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
1095ccb8f90Sopenharmony_ci        return result;
1105ccb8f90Sopenharmony_ci    }
1115ccb8f90Sopenharmony_ci
1125ccb8f90Sopenharmony_ci    if (!reply.ReadBool(result)) {
1135ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "ReadBool fail");
1145ccb8f90Sopenharmony_ci    }
1155ccb8f90Sopenharmony_ci
1165ccb8f90Sopenharmony_ci    return result;
1175ccb8f90Sopenharmony_ci}
1185ccb8f90Sopenharmony_ci
1195ccb8f90Sopenharmony_cibool PowerMgrProxy::UpdateWorkSource(const sptr<IRemoteObject>& remoteObj,
1205ccb8f90Sopenharmony_ci    const std::map<int32_t, std::string>& workSources)
1215ccb8f90Sopenharmony_ci{
1225ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
1235ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
1245ccb8f90Sopenharmony_ci
1255ccb8f90Sopenharmony_ci    MessageParcel data;
1265ccb8f90Sopenharmony_ci    MessageParcel reply;
1275ccb8f90Sopenharmony_ci    MessageOption option = { MessageOption::TF_ASYNC };
1285ccb8f90Sopenharmony_ci
1295ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1305ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
1315ccb8f90Sopenharmony_ci        return false;
1325ccb8f90Sopenharmony_ci    }
1335ccb8f90Sopenharmony_ci
1345ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), false);
1355ccb8f90Sopenharmony_ci    uint32_t size = workSources.size();
1365ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, size, false);
1375ccb8f90Sopenharmony_ci    for (const auto& wks : workSources) {
1385ccb8f90Sopenharmony_ci        RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, wks.first, false);
1395ccb8f90Sopenharmony_ci        RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, wks.second, false);
1405ccb8f90Sopenharmony_ci    }
1415ccb8f90Sopenharmony_ci
1425ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
1435ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UPDATE_WORK_SOURCE),
1445ccb8f90Sopenharmony_ci        data, reply, option);
1455ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
1465ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
1475ccb8f90Sopenharmony_ci        return false;
1485ccb8f90Sopenharmony_ci    }
1495ccb8f90Sopenharmony_ci    return true;
1505ccb8f90Sopenharmony_ci}
1515ccb8f90Sopenharmony_ci
1525ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::Lock(const sptr<IRemoteObject>& remoteObj, int32_t timeOutMs)
1535ccb8f90Sopenharmony_ci{
1545ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
1555ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
1565ccb8f90Sopenharmony_ci
1575ccb8f90Sopenharmony_ci    MessageParcel data;
1585ccb8f90Sopenharmony_ci    MessageParcel reply;
1595ccb8f90Sopenharmony_ci    MessageOption option;
1605ccb8f90Sopenharmony_ci
1615ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1625ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
1635ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
1645ccb8f90Sopenharmony_ci    }
1655ccb8f90Sopenharmony_ci
1665ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(
1675ccb8f90Sopenharmony_ci        data, RemoteObject, remoteObj.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL);
1685ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, timeOutMs, PowerErrors::ERR_CONNECTION_FAIL);
1695ccb8f90Sopenharmony_ci
1705ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
1715ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_LOCK),
1725ccb8f90Sopenharmony_ci        data, reply, option);
1735ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
1745ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
1755ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
1765ccb8f90Sopenharmony_ci    }
1775ccb8f90Sopenharmony_ci    int32_t error;
1785ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL);
1795ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
1805ccb8f90Sopenharmony_ci}
1815ccb8f90Sopenharmony_ci
1825ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::UnLock(const sptr<IRemoteObject>& remoteObj, const std::string& name)
1835ccb8f90Sopenharmony_ci{
1845ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
1855ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
1865ccb8f90Sopenharmony_ci
1875ccb8f90Sopenharmony_ci    MessageParcel data;
1885ccb8f90Sopenharmony_ci    MessageParcel reply;
1895ccb8f90Sopenharmony_ci    MessageOption option;
1905ccb8f90Sopenharmony_ci
1915ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
1925ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
1935ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
1945ccb8f90Sopenharmony_ci    }
1955ccb8f90Sopenharmony_ci
1965ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(
1975ccb8f90Sopenharmony_ci        data, RemoteObject, remoteObj.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL);
1985ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String, name, PowerErrors::ERR_CONNECTION_FAIL);
1995ccb8f90Sopenharmony_ci
2005ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
2015ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_UNLOCK),
2025ccb8f90Sopenharmony_ci        data, reply, option);
2035ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
2045ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
2055ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
2065ccb8f90Sopenharmony_ci    }
2075ccb8f90Sopenharmony_ci    int32_t error;
2085ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL);
2095ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
2105ccb8f90Sopenharmony_ci}
2115ccb8f90Sopenharmony_ci
2125ccb8f90Sopenharmony_cibool PowerMgrProxy::QueryRunningLockLists(std::map<std::string, RunningLockInfo>& runningLockLists)
2135ccb8f90Sopenharmony_ci{
2145ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
2155ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
2165ccb8f90Sopenharmony_ci
2175ccb8f90Sopenharmony_ci    MessageParcel data;
2185ccb8f90Sopenharmony_ci    MessageParcel reply;
2195ccb8f90Sopenharmony_ci    MessageOption option;
2205ccb8f90Sopenharmony_ci
2215ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
2225ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
2235ccb8f90Sopenharmony_ci        return false;
2245ccb8f90Sopenharmony_ci    }
2255ccb8f90Sopenharmony_ci
2265ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
2275ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_QUERY),
2285ccb8f90Sopenharmony_ci        data, reply, option);
2295ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
2305ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
2315ccb8f90Sopenharmony_ci        return false;
2325ccb8f90Sopenharmony_ci    }
2335ccb8f90Sopenharmony_ci    int32_t num = reply.ReadInt32();
2345ccb8f90Sopenharmony_ci    for (int i = 0; i < num; i++) {
2355ccb8f90Sopenharmony_ci        std::string key = reply.ReadString();
2365ccb8f90Sopenharmony_ci        RunningLockInfo* info = reply.ReadParcelable<RunningLockInfo>();
2375ccb8f90Sopenharmony_ci        if (info != nullptr) {
2385ccb8f90Sopenharmony_ci            runningLockLists.insert(std::pair<std::string, RunningLockInfo>(key, *info));
2395ccb8f90Sopenharmony_ci            delete info;
2405ccb8f90Sopenharmony_ci        }
2415ccb8f90Sopenharmony_ci    }
2425ccb8f90Sopenharmony_ci    return true;
2435ccb8f90Sopenharmony_ci}
2445ccb8f90Sopenharmony_ci
2455ccb8f90Sopenharmony_cibool PowerMgrProxy::IsUsed(const sptr<IRemoteObject>& remoteObj)
2465ccb8f90Sopenharmony_ci{
2475ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
2485ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
2495ccb8f90Sopenharmony_ci
2505ccb8f90Sopenharmony_ci    MessageParcel data;
2515ccb8f90Sopenharmony_ci    MessageParcel reply;
2525ccb8f90Sopenharmony_ci    MessageOption option;
2535ccb8f90Sopenharmony_ci
2545ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
2555ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
2565ccb8f90Sopenharmony_ci        return false;
2575ccb8f90Sopenharmony_ci    }
2585ccb8f90Sopenharmony_ci
2595ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, remoteObj.GetRefPtr(), false);
2605ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
2615ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_ISUSED),
2625ccb8f90Sopenharmony_ci        data, reply, option);
2635ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
2645ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
2655ccb8f90Sopenharmony_ci        return false;
2665ccb8f90Sopenharmony_ci    }
2675ccb8f90Sopenharmony_ci    bool used = false;
2685ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, used, false);
2695ccb8f90Sopenharmony_ci    return used;
2705ccb8f90Sopenharmony_ci}
2715ccb8f90Sopenharmony_ci
2725ccb8f90Sopenharmony_cibool PowerMgrProxy::ProxyRunningLock(bool isProxied, pid_t pid, pid_t uid)
2735ccb8f90Sopenharmony_ci{
2745ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
2755ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
2765ccb8f90Sopenharmony_ci
2775ccb8f90Sopenharmony_ci    MessageParcel data;
2785ccb8f90Sopenharmony_ci    MessageParcel reply;
2795ccb8f90Sopenharmony_ci    MessageOption option;
2805ccb8f90Sopenharmony_ci
2815ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
2825ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
2835ccb8f90Sopenharmony_ci        return false;
2845ccb8f90Sopenharmony_ci    }
2855ccb8f90Sopenharmony_ci
2865ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, false);
2875ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, pid, false);
2885ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, uid, false);
2895ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
2905ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCK),
2915ccb8f90Sopenharmony_ci        data, reply, option);
2925ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
2935ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
2945ccb8f90Sopenharmony_ci        return false;
2955ccb8f90Sopenharmony_ci    }
2965ccb8f90Sopenharmony_ci    bool succ = false;
2975ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false);
2985ccb8f90Sopenharmony_ci    return succ;
2995ccb8f90Sopenharmony_ci}
3005ccb8f90Sopenharmony_ci
3015ccb8f90Sopenharmony_cibool PowerMgrProxy::ProxyRunningLocks(bool isProxied, const std::vector<std::pair<pid_t, pid_t>>& processInfos)
3025ccb8f90Sopenharmony_ci{
3035ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
3045ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
3055ccb8f90Sopenharmony_ci
3065ccb8f90Sopenharmony_ci    MessageParcel data;
3075ccb8f90Sopenharmony_ci    MessageParcel reply;
3085ccb8f90Sopenharmony_ci    MessageOption option;
3095ccb8f90Sopenharmony_ci
3105ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
3115ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
3125ccb8f90Sopenharmony_ci        return false;
3135ccb8f90Sopenharmony_ci    }
3145ccb8f90Sopenharmony_ci
3155ccb8f90Sopenharmony_ci    size_t size = processInfos.size();
3165ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, false);
3175ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, size, false);
3185ccb8f90Sopenharmony_ci    if (size > MAX_PROXY_RUNNINGLOCK_NUM) {
3195ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "size exceed limit, size=%{public}zu", size);
3205ccb8f90Sopenharmony_ci        return false;
3215ccb8f90Sopenharmony_ci    }
3225ccb8f90Sopenharmony_ci    for (size_t i = 0; i < size; ++i) {
3235ccb8f90Sopenharmony_ci        RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].first, false);
3245ccb8f90Sopenharmony_ci        RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].second, false);
3255ccb8f90Sopenharmony_ci    }
3265ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(static_cast<int>(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCKS),
3275ccb8f90Sopenharmony_ci        data, reply, option);
3285ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
3295ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
3305ccb8f90Sopenharmony_ci        return false;
3315ccb8f90Sopenharmony_ci    }
3325ccb8f90Sopenharmony_ci    bool succ = false;
3335ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false);
3345ccb8f90Sopenharmony_ci    return succ;
3355ccb8f90Sopenharmony_ci}
3365ccb8f90Sopenharmony_ci
3375ccb8f90Sopenharmony_cibool PowerMgrProxy::ResetRunningLocks()
3385ccb8f90Sopenharmony_ci{
3395ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
3405ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
3415ccb8f90Sopenharmony_ci
3425ccb8f90Sopenharmony_ci    MessageParcel data;
3435ccb8f90Sopenharmony_ci    MessageParcel reply;
3445ccb8f90Sopenharmony_ci    MessageOption option;
3455ccb8f90Sopenharmony_ci
3465ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
3475ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
3485ccb8f90Sopenharmony_ci        return false;
3495ccb8f90Sopenharmony_ci    }
3505ccb8f90Sopenharmony_ci
3515ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RESET_RUNNINGLOCKS),
3525ccb8f90Sopenharmony_ci        data, reply, option);
3535ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
3545ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
3555ccb8f90Sopenharmony_ci        return false;
3565ccb8f90Sopenharmony_ci    }
3575ccb8f90Sopenharmony_ci    bool succ = false;
3585ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, succ, false);
3595ccb8f90Sopenharmony_ci    return succ;
3605ccb8f90Sopenharmony_ci}
3615ccb8f90Sopenharmony_ci
3625ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::RebootDevice(const std::string& reason)
3635ccb8f90Sopenharmony_ci{
3645ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
3655ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
3665ccb8f90Sopenharmony_ci
3675ccb8f90Sopenharmony_ci    MessageParcel data;
3685ccb8f90Sopenharmony_ci    MessageParcel reply;
3695ccb8f90Sopenharmony_ci    MessageOption option;
3705ccb8f90Sopenharmony_ci
3715ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
3725ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed");
3735ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
3745ccb8f90Sopenharmony_ci    }
3755ccb8f90Sopenharmony_ci
3765ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(reason), PowerErrors::ERR_CONNECTION_FAIL);
3775ccb8f90Sopenharmony_ci
3785ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
3795ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE), data, reply, option);
3805ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
3815ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
3825ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
3835ccb8f90Sopenharmony_ci    }
3845ccb8f90Sopenharmony_ci    int32_t error;
3855ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
3865ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
3875ccb8f90Sopenharmony_ci}
3885ccb8f90Sopenharmony_ci
3895ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::RebootDeviceForDeprecated(const std::string& reason)
3905ccb8f90Sopenharmony_ci{
3915ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
3925ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
3935ccb8f90Sopenharmony_ci
3945ccb8f90Sopenharmony_ci    MessageParcel data;
3955ccb8f90Sopenharmony_ci    MessageParcel reply;
3965ccb8f90Sopenharmony_ci    MessageOption option;
3975ccb8f90Sopenharmony_ci
3985ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
3995ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed");
4005ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4015ccb8f90Sopenharmony_ci    }
4025ccb8f90Sopenharmony_ci
4035ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(reason), PowerErrors::ERR_CONNECTION_FAIL);
4045ccb8f90Sopenharmony_ci
4055ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
4065ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE_FOR_DEPRECATED),
4075ccb8f90Sopenharmony_ci        data, reply, option);
4085ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
4095ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
4105ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4115ccb8f90Sopenharmony_ci    }
4125ccb8f90Sopenharmony_ci    int32_t error;
4135ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
4145ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
4155ccb8f90Sopenharmony_ci}
4165ccb8f90Sopenharmony_ci
4175ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::ShutDownDevice(const std::string& reason)
4185ccb8f90Sopenharmony_ci{
4195ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
4205ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
4215ccb8f90Sopenharmony_ci
4225ccb8f90Sopenharmony_ci    MessageParcel data;
4235ccb8f90Sopenharmony_ci    MessageParcel reply;
4245ccb8f90Sopenharmony_ci    MessageOption option;
4255ccb8f90Sopenharmony_ci
4265ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
4275ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed");
4285ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4295ccb8f90Sopenharmony_ci    }
4305ccb8f90Sopenharmony_ci
4315ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(reason), PowerErrors::ERR_CONNECTION_FAIL);
4325ccb8f90Sopenharmony_ci
4335ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
4345ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SHUTDOWN_DEVICE), data, reply, option);
4355ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
4365ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SHUTDOWN, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
4375ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4385ccb8f90Sopenharmony_ci    }
4395ccb8f90Sopenharmony_ci    int32_t error;
4405ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
4415ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
4425ccb8f90Sopenharmony_ci}
4435ccb8f90Sopenharmony_ci
4445ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::SetSuspendTag(const std::string& tag)
4455ccb8f90Sopenharmony_ci{
4465ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
4475ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
4485ccb8f90Sopenharmony_ci
4495ccb8f90Sopenharmony_ci    MessageParcel data;
4505ccb8f90Sopenharmony_ci    MessageParcel reply;
4515ccb8f90Sopenharmony_ci    MessageOption option;
4525ccb8f90Sopenharmony_ci
4535ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
4545ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
4555ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4565ccb8f90Sopenharmony_ci    }
4575ccb8f90Sopenharmony_ci
4585ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(tag), PowerErrors::ERR_CONNECTION_FAIL);
4595ccb8f90Sopenharmony_ci
4605ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
4615ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SET_SUSPEND_TAG), data, reply, option);
4625ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
4635ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
4645ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4655ccb8f90Sopenharmony_ci    }
4665ccb8f90Sopenharmony_ci    int32_t error;
4675ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
4685ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
4695ccb8f90Sopenharmony_ci}
4705ccb8f90Sopenharmony_ci
4715ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed)
4725ccb8f90Sopenharmony_ci{
4735ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
4745ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
4755ccb8f90Sopenharmony_ci
4765ccb8f90Sopenharmony_ci    MessageParcel data;
4775ccb8f90Sopenharmony_ci    MessageParcel reply;
4785ccb8f90Sopenharmony_ci    MessageOption option;
4795ccb8f90Sopenharmony_ci
4805ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
4815ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
4825ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4835ccb8f90Sopenharmony_ci    }
4845ccb8f90Sopenharmony_ci
4855ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, PowerErrors::ERR_CONNECTION_FAIL);
4865ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32,
4875ccb8f90Sopenharmony_ci        static_cast<uint32_t>(reason), PowerErrors::ERR_CONNECTION_FAIL);
4885ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, suspendImmed, PowerErrors::ERR_CONNECTION_FAIL);
4895ccb8f90Sopenharmony_ci
4905ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
4915ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SUSPEND_DEVICE), data, reply, option);
4925ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
4935ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
4945ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
4955ccb8f90Sopenharmony_ci    }
4965ccb8f90Sopenharmony_ci    int32_t error;
4975ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
4985ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
4995ccb8f90Sopenharmony_ci}
5005ccb8f90Sopenharmony_ci
5015ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details)
5025ccb8f90Sopenharmony_ci{
5035ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
5045ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
5055ccb8f90Sopenharmony_ci
5065ccb8f90Sopenharmony_ci    MessageParcel data;
5075ccb8f90Sopenharmony_ci    MessageParcel reply;
5085ccb8f90Sopenharmony_ci    MessageOption option;
5095ccb8f90Sopenharmony_ci
5105ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
5115ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_WAKEUP, "Write descriptor failed");
5125ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
5135ccb8f90Sopenharmony_ci    }
5145ccb8f90Sopenharmony_ci
5155ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, PowerErrors::ERR_CONNECTION_FAIL);
5165ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32,
5175ccb8f90Sopenharmony_ci        static_cast<uint32_t>(reason), PowerErrors::ERR_CONNECTION_FAIL);
5185ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, String16, Str8ToStr16(details), PowerErrors::ERR_CONNECTION_FAIL);
5195ccb8f90Sopenharmony_ci
5205ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
5215ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE), data, reply, option);
5225ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
5235ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_WAKEUP, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
5245ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
5255ccb8f90Sopenharmony_ci    }
5265ccb8f90Sopenharmony_ci    int32_t error;
5275ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
5285ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
5295ccb8f90Sopenharmony_ci}
5305ccb8f90Sopenharmony_ci
5315ccb8f90Sopenharmony_civoid PowerMgrProxy::WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details)
5325ccb8f90Sopenharmony_ci{
5335ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
5345ccb8f90Sopenharmony_ci    RETURN_IF(remote == nullptr);
5355ccb8f90Sopenharmony_ci
5365ccb8f90Sopenharmony_ci    MessageParcel data;
5375ccb8f90Sopenharmony_ci    MessageParcel reply;
5385ccb8f90Sopenharmony_ci    MessageOption option = { MessageOption::TF_ASYNC };
5395ccb8f90Sopenharmony_ci
5405ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
5415ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_WAKEUP, "Write descriptor failed");
5425ccb8f90Sopenharmony_ci        return;
5435ccb8f90Sopenharmony_ci    }
5445ccb8f90Sopenharmony_ci
5455ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Int64, callTimeMs);
5465ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Uint32, static_cast<uint32_t>(reason));
5475ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, String16, Str8ToStr16(details));
5485ccb8f90Sopenharmony_ci
5495ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
5505ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE), data, reply, option);
5515ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
5525ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_WAKEUP, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
5535ccb8f90Sopenharmony_ci        return;
5545ccb8f90Sopenharmony_ci    }
5555ccb8f90Sopenharmony_ci}
5565ccb8f90Sopenharmony_ci
5575ccb8f90Sopenharmony_cibool PowerMgrProxy::RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight)
5585ccb8f90Sopenharmony_ci{
5595ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
5605ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
5615ccb8f90Sopenharmony_ci
5625ccb8f90Sopenharmony_ci    MessageParcel data;
5635ccb8f90Sopenharmony_ci    MessageParcel reply;
5645ccb8f90Sopenharmony_ci    MessageOption option;
5655ccb8f90Sopenharmony_ci
5665ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
5675ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_ACTIVITY, "Write descriptor failed");
5685ccb8f90Sopenharmony_ci        return false;
5695ccb8f90Sopenharmony_ci    }
5705ccb8f90Sopenharmony_ci
5715ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, false);
5725ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast<uint32_t>(type), false);
5735ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, needChangeBacklight, false);
5745ccb8f90Sopenharmony_ci
5755ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
5765ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REFRESH_ACTIVITY), data, reply, option);
5775ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
5785ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_ACTIVITY, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
5795ccb8f90Sopenharmony_ci        return false;
5805ccb8f90Sopenharmony_ci    }
5815ccb8f90Sopenharmony_ci    return true;
5825ccb8f90Sopenharmony_ci}
5835ccb8f90Sopenharmony_ci
5845ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::OverrideScreenOffTime(int64_t timeout)
5855ccb8f90Sopenharmony_ci{
5865ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
5875ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
5885ccb8f90Sopenharmony_ci
5895ccb8f90Sopenharmony_ci    MessageParcel data;
5905ccb8f90Sopenharmony_ci    MessageParcel reply;
5915ccb8f90Sopenharmony_ci    MessageOption option;
5925ccb8f90Sopenharmony_ci
5935ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
5945ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_SVC, "Write descriptor failed");
5955ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
5965ccb8f90Sopenharmony_ci    }
5975ccb8f90Sopenharmony_ci
5985ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, timeout, PowerErrors::ERR_CONNECTION_FAIL);
5995ccb8f90Sopenharmony_ci
6005ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
6015ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_TIME),
6025ccb8f90Sopenharmony_ci        data, reply, option);
6035ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
6045ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_SVC, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
6055ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
6065ccb8f90Sopenharmony_ci    }
6075ccb8f90Sopenharmony_ci
6085ccb8f90Sopenharmony_ci    int32_t error;
6095ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
6105ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
6115ccb8f90Sopenharmony_ci}
6125ccb8f90Sopenharmony_ci
6135ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::RestoreScreenOffTime()
6145ccb8f90Sopenharmony_ci{
6155ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
6165ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
6175ccb8f90Sopenharmony_ci
6185ccb8f90Sopenharmony_ci    MessageParcel data;
6195ccb8f90Sopenharmony_ci    MessageParcel reply;
6205ccb8f90Sopenharmony_ci    MessageOption option;
6215ccb8f90Sopenharmony_ci
6225ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
6235ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
6245ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
6255ccb8f90Sopenharmony_ci    }
6265ccb8f90Sopenharmony_ci
6275ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
6285ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RESTORE_DISPLAY_OFF_TIME),
6295ccb8f90Sopenharmony_ci        data, reply, option);
6305ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
6315ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
6325ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
6335ccb8f90Sopenharmony_ci    }
6345ccb8f90Sopenharmony_ci
6355ccb8f90Sopenharmony_ci    int32_t error;
6365ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
6375ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
6385ccb8f90Sopenharmony_ci}
6395ccb8f90Sopenharmony_ci
6405ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::ForceSuspendDevice(int64_t callTimeMs)
6415ccb8f90Sopenharmony_ci{
6425ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
6435ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
6445ccb8f90Sopenharmony_ci
6455ccb8f90Sopenharmony_ci    MessageParcel data;
6465ccb8f90Sopenharmony_ci    MessageParcel reply;
6475ccb8f90Sopenharmony_ci    MessageOption option = { MessageOption::TF_ASYNC };
6485ccb8f90Sopenharmony_ci
6495ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
6505ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
6515ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
6525ccb8f90Sopenharmony_ci    }
6535ccb8f90Sopenharmony_ci
6545ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int64, callTimeMs, PowerErrors::ERR_CONNECTION_FAIL);
6555ccb8f90Sopenharmony_ci    sptr<PowerMgrStubAsync> asyncCallback = new PowerMgrStubAsync();
6565ccb8f90Sopenharmony_ci    data.WriteRemoteObject(asyncCallback->AsObject());
6575ccb8f90Sopenharmony_ci
6585ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
6595ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::FORCE_DEVICE_SUSPEND), data, reply, option);
6605ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
6615ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
6625ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
6635ccb8f90Sopenharmony_ci    }
6645ccb8f90Sopenharmony_ci
6655ccb8f90Sopenharmony_ci    int waitTime = 100;
6665ccb8f90Sopenharmony_ci    int error = asyncCallback->WaitForAsyncReply(waitTime);
6675ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
6685ccb8f90Sopenharmony_ci}
6695ccb8f90Sopenharmony_ci
6705ccb8f90Sopenharmony_ciPowerState PowerMgrProxy::GetState()
6715ccb8f90Sopenharmony_ci{
6725ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
6735ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerState::UNKNOWN);
6745ccb8f90Sopenharmony_ci
6755ccb8f90Sopenharmony_ci    uint32_t result = 0;
6765ccb8f90Sopenharmony_ci    MessageParcel data;
6775ccb8f90Sopenharmony_ci    MessageParcel reply;
6785ccb8f90Sopenharmony_ci    MessageOption option;
6795ccb8f90Sopenharmony_ci
6805ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
6815ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed");
6825ccb8f90Sopenharmony_ci        return PowerState::UNKNOWN;
6835ccb8f90Sopenharmony_ci    }
6845ccb8f90Sopenharmony_ci
6855ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
6865ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::GET_STATE), data, reply, option);
6875ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
6885ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
6895ccb8f90Sopenharmony_ci        return PowerState::UNKNOWN;
6905ccb8f90Sopenharmony_ci    }
6915ccb8f90Sopenharmony_ci    if (!reply.ReadUint32(result)) {
6925ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "ReadUint32 failed");
6935ccb8f90Sopenharmony_ci        return PowerState::UNKNOWN;
6945ccb8f90Sopenharmony_ci    }
6955ccb8f90Sopenharmony_ci
6965ccb8f90Sopenharmony_ci    return static_cast<PowerState>(result);
6975ccb8f90Sopenharmony_ci}
6985ccb8f90Sopenharmony_ci
6995ccb8f90Sopenharmony_cibool PowerMgrProxy::IsScreenOn(bool needPrintLog)
7005ccb8f90Sopenharmony_ci{
7015ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
7025ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
7035ccb8f90Sopenharmony_ci
7045ccb8f90Sopenharmony_ci    bool result = false;
7055ccb8f90Sopenharmony_ci    MessageParcel data;
7065ccb8f90Sopenharmony_ci    MessageParcel reply;
7075ccb8f90Sopenharmony_ci    MessageOption option;
7085ccb8f90Sopenharmony_ci
7095ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
7105ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
7115ccb8f90Sopenharmony_ci        return result;
7125ccb8f90Sopenharmony_ci    }
7135ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, needPrintLog, false);
7145ccb8f90Sopenharmony_ci
7155ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
7165ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_SCREEN_ON), data, reply, option);
7175ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
7185ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
7195ccb8f90Sopenharmony_ci        return result;
7205ccb8f90Sopenharmony_ci    }
7215ccb8f90Sopenharmony_ci
7225ccb8f90Sopenharmony_ci    if (!reply.ReadBool(result)) {
7235ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Read IsScreenOn failed");
7245ccb8f90Sopenharmony_ci    }
7255ccb8f90Sopenharmony_ci
7265ccb8f90Sopenharmony_ci    return result;
7275ccb8f90Sopenharmony_ci}
7285ccb8f90Sopenharmony_ci
7295ccb8f90Sopenharmony_cibool PowerMgrProxy::IsFoldScreenOn()
7305ccb8f90Sopenharmony_ci{
7315ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
7325ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
7335ccb8f90Sopenharmony_ci
7345ccb8f90Sopenharmony_ci    bool result = false;
7355ccb8f90Sopenharmony_ci    MessageParcel data;
7365ccb8f90Sopenharmony_ci    MessageParcel reply;
7375ccb8f90Sopenharmony_ci    MessageOption option;
7385ccb8f90Sopenharmony_ci
7395ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
7405ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
7415ccb8f90Sopenharmony_ci        return result;
7425ccb8f90Sopenharmony_ci    }
7435ccb8f90Sopenharmony_ci
7445ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
7455ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_FOLD_SCREEN_ON), data, reply, option);
7465ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
7475ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
7485ccb8f90Sopenharmony_ci        return result;
7495ccb8f90Sopenharmony_ci    }
7505ccb8f90Sopenharmony_ci
7515ccb8f90Sopenharmony_ci    if (!reply.ReadBool(result)) {
7525ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Read IsFoldScreenOn failed");
7535ccb8f90Sopenharmony_ci    }
7545ccb8f90Sopenharmony_ci
7555ccb8f90Sopenharmony_ci    return result;
7565ccb8f90Sopenharmony_ci}
7575ccb8f90Sopenharmony_ci
7585ccb8f90Sopenharmony_cibool PowerMgrProxy::IsCollaborationScreenOn()
7595ccb8f90Sopenharmony_ci{
7605ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
7615ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
7625ccb8f90Sopenharmony_ci
7635ccb8f90Sopenharmony_ci    bool result = false;
7645ccb8f90Sopenharmony_ci    MessageParcel data;
7655ccb8f90Sopenharmony_ci    MessageParcel reply;
7665ccb8f90Sopenharmony_ci    MessageOption option;
7675ccb8f90Sopenharmony_ci
7685ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
7695ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
7705ccb8f90Sopenharmony_ci        return result;
7715ccb8f90Sopenharmony_ci    }
7725ccb8f90Sopenharmony_ci
7735ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
7745ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_COLLABORATION_SCREEN_ON), data, reply, option);
7755ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
7765ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
7775ccb8f90Sopenharmony_ci        return result;
7785ccb8f90Sopenharmony_ci    }
7795ccb8f90Sopenharmony_ci
7805ccb8f90Sopenharmony_ci    if (!reply.ReadBool(result)) {
7815ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Read IsCollaborationScreenOn failed");
7825ccb8f90Sopenharmony_ci    }
7835ccb8f90Sopenharmony_ci
7845ccb8f90Sopenharmony_ci    return result;
7855ccb8f90Sopenharmony_ci}
7865ccb8f90Sopenharmony_ci
7875ccb8f90Sopenharmony_cibool PowerMgrProxy::RegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback, bool isSync)
7885ccb8f90Sopenharmony_ci{
7895ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
7905ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
7915ccb8f90Sopenharmony_ci
7925ccb8f90Sopenharmony_ci    MessageParcel data;
7935ccb8f90Sopenharmony_ci    MessageParcel reply;
7945ccb8f90Sopenharmony_ci    MessageOption option;
7955ccb8f90Sopenharmony_ci
7965ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
7975ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed");
7985ccb8f90Sopenharmony_ci        return false;
7995ccb8f90Sopenharmony_ci    }
8005ccb8f90Sopenharmony_ci
8015ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
8025ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, isSync, false);
8035ccb8f90Sopenharmony_ci
8045ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
8055ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_POWER_STATE_CALLBACK),
8065ccb8f90Sopenharmony_ci        data, reply, option);
8075ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
8085ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
8095ccb8f90Sopenharmony_ci        return false;
8105ccb8f90Sopenharmony_ci    }
8115ccb8f90Sopenharmony_ci    return true;
8125ccb8f90Sopenharmony_ci}
8135ccb8f90Sopenharmony_ci
8145ccb8f90Sopenharmony_cibool PowerMgrProxy::UnRegisterPowerStateCallback(const sptr<IPowerStateCallback>& callback)
8155ccb8f90Sopenharmony_ci{
8165ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
8175ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
8185ccb8f90Sopenharmony_ci
8195ccb8f90Sopenharmony_ci    MessageParcel data;
8205ccb8f90Sopenharmony_ci    MessageParcel reply;
8215ccb8f90Sopenharmony_ci    MessageOption option;
8225ccb8f90Sopenharmony_ci
8235ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
8245ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed");
8255ccb8f90Sopenharmony_ci        return false;
8265ccb8f90Sopenharmony_ci    }
8275ccb8f90Sopenharmony_ci
8285ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
8295ccb8f90Sopenharmony_ci
8305ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
8315ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_STATE_CALLBACK),
8325ccb8f90Sopenharmony_ci        data, reply, option);
8335ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
8345ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
8355ccb8f90Sopenharmony_ci        return false;
8365ccb8f90Sopenharmony_ci    }
8375ccb8f90Sopenharmony_ci    return true;
8385ccb8f90Sopenharmony_ci}
8395ccb8f90Sopenharmony_ci
8405ccb8f90Sopenharmony_cibool PowerMgrProxy::RegisterSyncSleepCallback(const sptr<ISyncSleepCallback>& callback, SleepPriority priority)
8415ccb8f90Sopenharmony_ci{
8425ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
8435ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
8445ccb8f90Sopenharmony_ci
8455ccb8f90Sopenharmony_ci    MessageParcel data;
8465ccb8f90Sopenharmony_ci    MessageParcel reply;
8475ccb8f90Sopenharmony_ci    MessageOption option;
8485ccb8f90Sopenharmony_ci
8495ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
8505ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed");
8515ccb8f90Sopenharmony_ci        return false;
8525ccb8f90Sopenharmony_ci    }
8535ccb8f90Sopenharmony_ci
8545ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
8555ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast<uint32_t>(priority), false);
8565ccb8f90Sopenharmony_ci
8575ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
8585ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_SLEEP_CALLBACK),
8595ccb8f90Sopenharmony_ci        data, reply, option);
8605ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
8615ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
8625ccb8f90Sopenharmony_ci        return false;
8635ccb8f90Sopenharmony_ci    }
8645ccb8f90Sopenharmony_ci    return true;
8655ccb8f90Sopenharmony_ci}
8665ccb8f90Sopenharmony_ci
8675ccb8f90Sopenharmony_ci
8685ccb8f90Sopenharmony_cibool PowerMgrProxy::UnRegisterSyncSleepCallback(const sptr<ISyncSleepCallback>& callback)
8695ccb8f90Sopenharmony_ci{
8705ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
8715ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
8725ccb8f90Sopenharmony_ci
8735ccb8f90Sopenharmony_ci    MessageParcel data;
8745ccb8f90Sopenharmony_ci    MessageParcel reply;
8755ccb8f90Sopenharmony_ci    MessageOption option;
8765ccb8f90Sopenharmony_ci
8775ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
8785ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed");
8795ccb8f90Sopenharmony_ci        return false;
8805ccb8f90Sopenharmony_ci    }
8815ccb8f90Sopenharmony_ci
8825ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
8835ccb8f90Sopenharmony_ci
8845ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
8855ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_SLEEP_CALLBACK),
8865ccb8f90Sopenharmony_ci        data, reply, option);
8875ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
8885ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
8895ccb8f90Sopenharmony_ci        return false;
8905ccb8f90Sopenharmony_ci    }
8915ccb8f90Sopenharmony_ci    return true;
8925ccb8f90Sopenharmony_ci}
8935ccb8f90Sopenharmony_ci
8945ccb8f90Sopenharmony_cibool PowerMgrProxy::RegisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& callback)
8955ccb8f90Sopenharmony_ci{
8965ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
8975ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
8985ccb8f90Sopenharmony_ci
8995ccb8f90Sopenharmony_ci    MessageParcel data;
9005ccb8f90Sopenharmony_ci    MessageParcel reply;
9015ccb8f90Sopenharmony_ci    MessageOption option;
9025ccb8f90Sopenharmony_ci
9035ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
9045ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed");
9055ccb8f90Sopenharmony_ci        return false;
9065ccb8f90Sopenharmony_ci    }
9075ccb8f90Sopenharmony_ci
9085ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
9095ccb8f90Sopenharmony_ci
9105ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
9115ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_HIBERNATE_CALLBACK),
9125ccb8f90Sopenharmony_ci        data, reply, option);
9135ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
9145ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
9155ccb8f90Sopenharmony_ci        return false;
9165ccb8f90Sopenharmony_ci    }
9175ccb8f90Sopenharmony_ci    return true;
9185ccb8f90Sopenharmony_ci}
9195ccb8f90Sopenharmony_ci
9205ccb8f90Sopenharmony_ci
9215ccb8f90Sopenharmony_cibool PowerMgrProxy::UnRegisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& callback)
9225ccb8f90Sopenharmony_ci{
9235ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
9245ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
9255ccb8f90Sopenharmony_ci
9265ccb8f90Sopenharmony_ci    MessageParcel data;
9275ccb8f90Sopenharmony_ci    MessageParcel reply;
9285ccb8f90Sopenharmony_ci    MessageOption option;
9295ccb8f90Sopenharmony_ci
9305ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
9315ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed");
9325ccb8f90Sopenharmony_ci        return false;
9335ccb8f90Sopenharmony_ci    }
9345ccb8f90Sopenharmony_ci
9355ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
9365ccb8f90Sopenharmony_ci
9375ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
9385ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_HIBERNATE_CALLBACK),
9395ccb8f90Sopenharmony_ci        data, reply, option);
9405ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
9415ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
9425ccb8f90Sopenharmony_ci        return false;
9435ccb8f90Sopenharmony_ci    }
9445ccb8f90Sopenharmony_ci    return true;
9455ccb8f90Sopenharmony_ci}
9465ccb8f90Sopenharmony_ci
9475ccb8f90Sopenharmony_cibool PowerMgrProxy::RegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback)
9485ccb8f90Sopenharmony_ci{
9495ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
9505ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
9515ccb8f90Sopenharmony_ci
9525ccb8f90Sopenharmony_ci    MessageParcel data;
9535ccb8f90Sopenharmony_ci    MessageParcel reply;
9545ccb8f90Sopenharmony_ci    MessageOption option;
9555ccb8f90Sopenharmony_ci
9565ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
9575ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed");
9585ccb8f90Sopenharmony_ci        return false;
9595ccb8f90Sopenharmony_ci    }
9605ccb8f90Sopenharmony_ci
9615ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
9625ccb8f90Sopenharmony_ci
9635ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
9645ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_POWER_MODE_CALLBACK),
9655ccb8f90Sopenharmony_ci        data, reply, option);
9665ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
9675ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
9685ccb8f90Sopenharmony_ci        return false;
9695ccb8f90Sopenharmony_ci    }
9705ccb8f90Sopenharmony_ci    return true;
9715ccb8f90Sopenharmony_ci}
9725ccb8f90Sopenharmony_ci
9735ccb8f90Sopenharmony_cibool PowerMgrProxy::UnRegisterPowerModeCallback(const sptr<IPowerModeCallback>& callback)
9745ccb8f90Sopenharmony_ci{
9755ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
9765ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
9775ccb8f90Sopenharmony_ci
9785ccb8f90Sopenharmony_ci    MessageParcel data;
9795ccb8f90Sopenharmony_ci    MessageParcel reply;
9805ccb8f90Sopenharmony_ci    MessageOption option;
9815ccb8f90Sopenharmony_ci
9825ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
9835ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed");
9845ccb8f90Sopenharmony_ci        return false;
9855ccb8f90Sopenharmony_ci    }
9865ccb8f90Sopenharmony_ci
9875ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
9885ccb8f90Sopenharmony_ci
9895ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
9905ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_MODE_CALLBACK),
9915ccb8f90Sopenharmony_ci        data, reply, option);
9925ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
9935ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
9945ccb8f90Sopenharmony_ci        return false;
9955ccb8f90Sopenharmony_ci    }
9965ccb8f90Sopenharmony_ci    return true;
9975ccb8f90Sopenharmony_ci}
9985ccb8f90Sopenharmony_ci
9995ccb8f90Sopenharmony_cibool PowerMgrProxy::RegisterScreenStateCallback(int32_t remainTime, const sptr<IScreenOffPreCallback>& callback)
10005ccb8f90Sopenharmony_ci{
10015ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
10025ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (remainTime <= 0) || (callback == nullptr), false);
10035ccb8f90Sopenharmony_ci    MessageParcel data;
10045ccb8f90Sopenharmony_ci    MessageParcel reply;
10055ccb8f90Sopenharmony_ci    MessageOption option;
10065ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
10075ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "Write descriptor failed");
10085ccb8f90Sopenharmony_ci        return false;
10095ccb8f90Sopenharmony_ci    }
10105ccb8f90Sopenharmony_ci
10115ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Int32, remainTime, false);
10125ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
10135ccb8f90Sopenharmony_ci
10145ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
10155ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_SCREEN_OFF_PRE_CALLBACK),
10165ccb8f90Sopenharmony_ci        data, reply, option);
10175ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
10185ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
10195ccb8f90Sopenharmony_ci        return false;
10205ccb8f90Sopenharmony_ci    }
10215ccb8f90Sopenharmony_ci    return true;
10225ccb8f90Sopenharmony_ci}
10235ccb8f90Sopenharmony_ci
10245ccb8f90Sopenharmony_cibool PowerMgrProxy::UnRegisterScreenStateCallback(const sptr<IScreenOffPreCallback>& callback)
10255ccb8f90Sopenharmony_ci{
10265ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
10275ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
10285ccb8f90Sopenharmony_ci
10295ccb8f90Sopenharmony_ci    MessageParcel data;
10305ccb8f90Sopenharmony_ci    MessageParcel reply;
10315ccb8f90Sopenharmony_ci    MessageOption option;
10325ccb8f90Sopenharmony_ci
10335ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
10345ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "Write descriptor failed");
10355ccb8f90Sopenharmony_ci        return false;
10365ccb8f90Sopenharmony_ci    }
10375ccb8f90Sopenharmony_ci
10385ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
10395ccb8f90Sopenharmony_ci
10405ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
10415ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_SCREEN_OFF_PRE_CALLBACK),
10425ccb8f90Sopenharmony_ci        data, reply, option);
10435ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
10445ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SCREEN_OFF_PRE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
10455ccb8f90Sopenharmony_ci        return false;
10465ccb8f90Sopenharmony_ci    }
10475ccb8f90Sopenharmony_ci    return true;
10485ccb8f90Sopenharmony_ci}
10495ccb8f90Sopenharmony_ci
10505ccb8f90Sopenharmony_cibool PowerMgrProxy::RegisterRunningLockCallback(const sptr<IPowerRunninglockCallback>& callback)
10515ccb8f90Sopenharmony_ci{
10525ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
10535ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
10545ccb8f90Sopenharmony_ci
10555ccb8f90Sopenharmony_ci    MessageParcel data;
10565ccb8f90Sopenharmony_ci    MessageParcel reply;
10575ccb8f90Sopenharmony_ci    MessageOption option;
10585ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
10595ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
10605ccb8f90Sopenharmony_ci        return false;
10615ccb8f90Sopenharmony_ci    }
10625ccb8f90Sopenharmony_ci
10635ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
10645ccb8f90Sopenharmony_ci
10655ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
10665ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_RUNNINGLOCK_CALLBACK),
10675ccb8f90Sopenharmony_ci        data, reply, option);
10685ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
10695ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
10705ccb8f90Sopenharmony_ci        return false;
10715ccb8f90Sopenharmony_ci    }
10725ccb8f90Sopenharmony_ci    return true;
10735ccb8f90Sopenharmony_ci}
10745ccb8f90Sopenharmony_ci
10755ccb8f90Sopenharmony_cibool PowerMgrProxy::UnRegisterRunningLockCallback(const sptr<IPowerRunninglockCallback>& callback)
10765ccb8f90Sopenharmony_ci{
10775ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
10785ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false);
10795ccb8f90Sopenharmony_ci
10805ccb8f90Sopenharmony_ci    MessageParcel data;
10815ccb8f90Sopenharmony_ci    MessageParcel reply;
10825ccb8f90Sopenharmony_ci    MessageOption option;
10835ccb8f90Sopenharmony_ci
10845ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
10855ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "Write descriptor failed");
10865ccb8f90Sopenharmony_ci        return false;
10875ccb8f90Sopenharmony_ci    }
10885ccb8f90Sopenharmony_ci
10895ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, callback->AsObject(), false);
10905ccb8f90Sopenharmony_ci
10915ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
10925ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_RUNNINGLOCK_CALLBACK),
10935ccb8f90Sopenharmony_ci        data, reply, option);
10945ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
10955ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_RUNNING_LOCK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
10965ccb8f90Sopenharmony_ci        return false;
10975ccb8f90Sopenharmony_ci    }
10985ccb8f90Sopenharmony_ci    return true;
10995ccb8f90Sopenharmony_ci}
11005ccb8f90Sopenharmony_ci
11015ccb8f90Sopenharmony_cibool PowerMgrProxy::SetDisplaySuspend(bool enable)
11025ccb8f90Sopenharmony_ci{
11035ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
11045ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
11055ccb8f90Sopenharmony_ci
11065ccb8f90Sopenharmony_ci    MessageParcel data;
11075ccb8f90Sopenharmony_ci    MessageParcel reply;
11085ccb8f90Sopenharmony_ci    MessageOption option;
11095ccb8f90Sopenharmony_ci
11105ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
11115ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
11125ccb8f90Sopenharmony_ci        return false;
11135ccb8f90Sopenharmony_ci    }
11145ccb8f90Sopenharmony_ci
11155ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, enable, false);
11165ccb8f90Sopenharmony_ci
11175ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
11185ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SET_DISPLAY_SUSPEND),
11195ccb8f90Sopenharmony_ci        data, reply, option);
11205ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
11215ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
11225ccb8f90Sopenharmony_ci        return false;
11235ccb8f90Sopenharmony_ci    }
11245ccb8f90Sopenharmony_ci    return true;
11255ccb8f90Sopenharmony_ci}
11265ccb8f90Sopenharmony_ci
11275ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::Hibernate(bool clearMemory)
11285ccb8f90Sopenharmony_ci{
11295ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
11305ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
11315ccb8f90Sopenharmony_ci
11325ccb8f90Sopenharmony_ci    MessageParcel data;
11335ccb8f90Sopenharmony_ci    MessageParcel reply;
11345ccb8f90Sopenharmony_ci    MessageOption option = { MessageOption::TF_ASYNC };
11355ccb8f90Sopenharmony_ci
11365ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
11375ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
11385ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
11395ccb8f90Sopenharmony_ci    }
11405ccb8f90Sopenharmony_ci
11415ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, clearMemory, PowerErrors::ERR_CONNECTION_FAIL);
11425ccb8f90Sopenharmony_ci    sptr<PowerMgrStubAsync> asyncCallback = new PowerMgrStubAsync();
11435ccb8f90Sopenharmony_ci    data.WriteRemoteObject(asyncCallback->AsObject());
11445ccb8f90Sopenharmony_ci
11455ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
11465ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::HIBERNATE),
11475ccb8f90Sopenharmony_ci        data, reply, option);
11485ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
11495ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
11505ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
11515ccb8f90Sopenharmony_ci    }
11525ccb8f90Sopenharmony_ci
11535ccb8f90Sopenharmony_ci    int waitTime = 100;
11545ccb8f90Sopenharmony_ci    int error = asyncCallback->WaitForAsyncReply(waitTime);
11555ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
11565ccb8f90Sopenharmony_ci}
11575ccb8f90Sopenharmony_ci
11585ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::SetDeviceMode(const PowerMode& mode)
11595ccb8f90Sopenharmony_ci{
11605ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
11615ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
11625ccb8f90Sopenharmony_ci
11635ccb8f90Sopenharmony_ci    MessageParcel data;
11645ccb8f90Sopenharmony_ci    MessageParcel reply;
11655ccb8f90Sopenharmony_ci    MessageOption option;
11665ccb8f90Sopenharmony_ci
11675ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
11685ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed");
11695ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
11705ccb8f90Sopenharmony_ci    }
11715ccb8f90Sopenharmony_ci
11725ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast<uint32_t>(mode), PowerErrors::ERR_CONNECTION_FAIL);
11735ccb8f90Sopenharmony_ci
11745ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
11755ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SETMODE_DEVICE), data, reply, option);
11765ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
11775ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
11785ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
11795ccb8f90Sopenharmony_ci    }
11805ccb8f90Sopenharmony_ci    int32_t error;
11815ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_OK);
11825ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
11835ccb8f90Sopenharmony_ci}
11845ccb8f90Sopenharmony_ci
11855ccb8f90Sopenharmony_ciPowerMode PowerMgrProxy::GetDeviceMode()
11865ccb8f90Sopenharmony_ci{
11875ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
11885ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, static_cast<PowerMode>(false));
11895ccb8f90Sopenharmony_ci
11905ccb8f90Sopenharmony_ci    MessageParcel data;
11915ccb8f90Sopenharmony_ci    MessageParcel reply;
11925ccb8f90Sopenharmony_ci    MessageOption option;
11935ccb8f90Sopenharmony_ci
11945ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
11955ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "Write descriptor failed");
11965ccb8f90Sopenharmony_ci        return PowerMode::NORMAL_MODE;
11975ccb8f90Sopenharmony_ci    }
11985ccb8f90Sopenharmony_ci
11995ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
12005ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::GETMODE_DEVICE),
12015ccb8f90Sopenharmony_ci        data, reply, option);
12025ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
12035ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
12045ccb8f90Sopenharmony_ci        return PowerMode::NORMAL_MODE;
12055ccb8f90Sopenharmony_ci    }
12065ccb8f90Sopenharmony_ci
12075ccb8f90Sopenharmony_ci    uint32_t used = static_cast<uint32_t>(PowerMode::NORMAL_MODE);
12085ccb8f90Sopenharmony_ci    if (!reply.ReadUint32(used)) {
12095ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "ReadUint32 fail");
12105ccb8f90Sopenharmony_ci    }
12115ccb8f90Sopenharmony_ci    return static_cast<PowerMode>(used);
12125ccb8f90Sopenharmony_ci}
12135ccb8f90Sopenharmony_ci
12145ccb8f90Sopenharmony_cistd::string PowerMgrProxy::ShellDump(const std::vector<std::string>& args, uint32_t argc)
12155ccb8f90Sopenharmony_ci{
12165ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
12175ccb8f90Sopenharmony_ci    std::string result = "remote error";
12185ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, result);
12195ccb8f90Sopenharmony_ci
12205ccb8f90Sopenharmony_ci    MessageParcel data;
12215ccb8f90Sopenharmony_ci    MessageParcel reply;
12225ccb8f90Sopenharmony_ci    MessageOption option;
12235ccb8f90Sopenharmony_ci
12245ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
12255ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
12265ccb8f90Sopenharmony_ci        return result;
12275ccb8f90Sopenharmony_ci    }
12285ccb8f90Sopenharmony_ci    if (argc > args.size()) {
12295ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "argc is greater than args size!");
12305ccb8f90Sopenharmony_ci        return result;
12315ccb8f90Sopenharmony_ci    }
12325ccb8f90Sopenharmony_ci
12335ccb8f90Sopenharmony_ci    data.WriteUint32(argc);
12345ccb8f90Sopenharmony_ci    for (uint32_t i = 0; i < argc; i++) {
12355ccb8f90Sopenharmony_ci        data.WriteString(args[i]);
12365ccb8f90Sopenharmony_ci    }
12375ccb8f90Sopenharmony_ci    int ret = remote->SendRequest(
12385ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SHELL_DUMP), data, reply, option);
12395ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
12405ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
12415ccb8f90Sopenharmony_ci        return result;
12425ccb8f90Sopenharmony_ci    }
12435ccb8f90Sopenharmony_ci    result = reply.ReadString();
12445ccb8f90Sopenharmony_ci
12455ccb8f90Sopenharmony_ci    return result;
12465ccb8f90Sopenharmony_ci}
12475ccb8f90Sopenharmony_ci
12485ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::IsStandby(bool& isStandby)
12495ccb8f90Sopenharmony_ci{
12505ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
12515ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
12525ccb8f90Sopenharmony_ci
12535ccb8f90Sopenharmony_ci    MessageParcel data;
12545ccb8f90Sopenharmony_ci    MessageParcel reply;
12555ccb8f90Sopenharmony_ci    MessageOption option;
12565ccb8f90Sopenharmony_ci
12575ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
12585ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
12595ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
12605ccb8f90Sopenharmony_ci    }
12615ccb8f90Sopenharmony_ci
12625ccb8f90Sopenharmony_ci    int32_t ret = remote->SendRequest(
12635ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_STANDBY), data, reply, option);
12645ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
12655ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
12665ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
12675ccb8f90Sopenharmony_ci    }
12685ccb8f90Sopenharmony_ci
12695ccb8f90Sopenharmony_ci    int32_t error;
12705ccb8f90Sopenharmony_ci
12715ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL);
12725ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, isStandby, PowerErrors::ERR_CONNECTION_FAIL);
12735ccb8f90Sopenharmony_ci
12745ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
12755ccb8f90Sopenharmony_ci}
12765ccb8f90Sopenharmony_ci
12775ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::SetForceTimingOut(bool enabled, const sptr<IRemoteObject>& token)
12785ccb8f90Sopenharmony_ci{
12795ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
12805ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
12815ccb8f90Sopenharmony_ci
12825ccb8f90Sopenharmony_ci    MessageParcel data;
12835ccb8f90Sopenharmony_ci    MessageParcel reply;
12845ccb8f90Sopenharmony_ci    MessageOption option;
12855ccb8f90Sopenharmony_ci
12865ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
12875ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
12885ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
12895ccb8f90Sopenharmony_ci    }
12905ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool,
12915ccb8f90Sopenharmony_ci        static_cast<uint32_t>(enabled), PowerErrors::ERR_CONNECTION_FAIL);
12925ccb8f90Sopenharmony_ci    if (token.GetRefPtr() == nullptr) {
12935ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "token nullptr");
12945ccb8f90Sopenharmony_ci    }
12955ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, token, PowerErrors::ERR_CONNECTION_FAIL);
12965ccb8f90Sopenharmony_ci    int32_t ret = remote->SendRequest(
12975ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SET_FORCE_TIMING_OUT), data, reply, option);
12985ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
12995ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
13005ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
13015ccb8f90Sopenharmony_ci    }
13025ccb8f90Sopenharmony_ci    int32_t error;
13035ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL);
13045ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
13055ccb8f90Sopenharmony_ci}
13065ccb8f90Sopenharmony_ci
13075ccb8f90Sopenharmony_ciPowerErrors PowerMgrProxy::LockScreenAfterTimingOut(
13085ccb8f90Sopenharmony_ci    bool enabledLockScreen, bool checkLock, bool sendScreenOffEvent, const sptr<IRemoteObject>& token)
13095ccb8f90Sopenharmony_ci{
13105ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
13115ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, PowerErrors::ERR_CONNECTION_FAIL);
13125ccb8f90Sopenharmony_ci
13135ccb8f90Sopenharmony_ci    MessageParcel data;
13145ccb8f90Sopenharmony_ci    MessageParcel reply;
13155ccb8f90Sopenharmony_ci    MessageOption option;
13165ccb8f90Sopenharmony_ci
13175ccb8f90Sopenharmony_ci    if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
13185ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Write descriptor failed");
13195ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
13205ccb8f90Sopenharmony_ci    }
13215ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, enabledLockScreen, PowerErrors::ERR_CONNECTION_FAIL);
13225ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, checkLock, PowerErrors::ERR_CONNECTION_FAIL);
13235ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, sendScreenOffEvent, PowerErrors::ERR_CONNECTION_FAIL);
13245ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, RemoteObject, token.GetRefPtr(), PowerErrors::ERR_CONNECTION_FAIL);
13255ccb8f90Sopenharmony_ci
13265ccb8f90Sopenharmony_ci    int32_t ret = remote->SendRequest(
13275ccb8f90Sopenharmony_ci        static_cast<int>(PowerMgr::PowerMgrInterfaceCode::LOCK_SCREEN_AFTER_TIMING_OUT), data, reply, option);
13285ccb8f90Sopenharmony_ci    if (ret != ERR_OK) {
13295ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
13305ccb8f90Sopenharmony_ci        return PowerErrors::ERR_CONNECTION_FAIL;
13315ccb8f90Sopenharmony_ci    }
13325ccb8f90Sopenharmony_ci    int32_t error;
13335ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Int32, error, PowerErrors::ERR_CONNECTION_FAIL);
13345ccb8f90Sopenharmony_ci    return static_cast<PowerErrors>(error);
13355ccb8f90Sopenharmony_ci}
13365ccb8f90Sopenharmony_ci
13375ccb8f90Sopenharmony_civoid PowerMgrProxy::RegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback, ShutdownPriority priority)
13385ccb8f90Sopenharmony_ci{
13395ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
13405ccb8f90Sopenharmony_ci    RETURN_IF(remote == nullptr);
13415ccb8f90Sopenharmony_ci    auto delegator = std::make_unique<ShutdownProxyDelegator>(remote, PowerMgrProxy::GetDescriptor());
13425ccb8f90Sopenharmony_ci    delegator->RegisterShutdownCallback(callback, priority);
13435ccb8f90Sopenharmony_ci}
13445ccb8f90Sopenharmony_ci
13455ccb8f90Sopenharmony_civoid PowerMgrProxy::UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback)
13465ccb8f90Sopenharmony_ci{
13475ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
13485ccb8f90Sopenharmony_ci    RETURN_IF(remote == nullptr);
13495ccb8f90Sopenharmony_ci    auto delegator = std::make_unique<ShutdownProxyDelegator>(remote, PowerMgrProxy::GetDescriptor());
13505ccb8f90Sopenharmony_ci    delegator->UnRegisterShutdownCallback(callback);
13515ccb8f90Sopenharmony_ci}
13525ccb8f90Sopenharmony_ci
13535ccb8f90Sopenharmony_civoid PowerMgrProxy::RegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback, ShutdownPriority priority)
13545ccb8f90Sopenharmony_ci{
13555ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
13565ccb8f90Sopenharmony_ci    RETURN_IF(remote == nullptr);
13575ccb8f90Sopenharmony_ci    auto delegator = std::make_unique<ShutdownProxyDelegator>(remote, PowerMgrProxy::GetDescriptor());
13585ccb8f90Sopenharmony_ci    delegator->RegisterShutdownCallback(callback, priority);
13595ccb8f90Sopenharmony_ci}
13605ccb8f90Sopenharmony_ci
13615ccb8f90Sopenharmony_civoid PowerMgrProxy::UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback)
13625ccb8f90Sopenharmony_ci{
13635ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
13645ccb8f90Sopenharmony_ci    RETURN_IF(remote == nullptr);
13655ccb8f90Sopenharmony_ci    auto delegator = std::make_unique<ShutdownProxyDelegator>(remote, PowerMgrProxy::GetDescriptor());
13665ccb8f90Sopenharmony_ci    delegator->UnRegisterShutdownCallback(callback);
13675ccb8f90Sopenharmony_ci}
13685ccb8f90Sopenharmony_ci
13695ccb8f90Sopenharmony_civoid PowerMgrProxy::RegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback, ShutdownPriority priority)
13705ccb8f90Sopenharmony_ci{
13715ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
13725ccb8f90Sopenharmony_ci    RETURN_IF(remote == nullptr);
13735ccb8f90Sopenharmony_ci    auto delegator = std::make_unique<ShutdownProxyDelegator>(remote, PowerMgrProxy::GetDescriptor());
13745ccb8f90Sopenharmony_ci    delegator->RegisterShutdownCallback(callback, priority);
13755ccb8f90Sopenharmony_ci}
13765ccb8f90Sopenharmony_ci
13775ccb8f90Sopenharmony_civoid PowerMgrProxy::UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback)
13785ccb8f90Sopenharmony_ci{
13795ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
13805ccb8f90Sopenharmony_ci    RETURN_IF(remote == nullptr);
13815ccb8f90Sopenharmony_ci    auto delegator = std::make_unique<ShutdownProxyDelegator>(remote, PowerMgrProxy::GetDescriptor());
13825ccb8f90Sopenharmony_ci    delegator->UnRegisterShutdownCallback(callback);
13835ccb8f90Sopenharmony_ci}
13845ccb8f90Sopenharmony_ci} // namespace PowerMgr
13855ccb8f90Sopenharmony_ci} // namespace OHOS
1386