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_stub.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
225ccb8f90Sopenharmony_ci#include "running_lock_info.h"
235ccb8f90Sopenharmony_ci#include "power_common.h"
245ccb8f90Sopenharmony_ci#include "power_errors.h"
255ccb8f90Sopenharmony_ci#include "power_mgr_ipc_interface_code.h"
265ccb8f90Sopenharmony_ci#include "shutdown_stub_delegator.h"
275ccb8f90Sopenharmony_ci#include "shutdown/shutdown_client_ipc_interface_code.h"
285ccb8f90Sopenharmony_ci#include "xcollie/xcollie.h"
295ccb8f90Sopenharmony_ci
305ccb8f90Sopenharmony_ciusing namespace OHOS::HiviewDFX;
315ccb8f90Sopenharmony_ci
325ccb8f90Sopenharmony_cinamespace OHOS {
335ccb8f90Sopenharmony_cinamespace PowerMgr {
345ccb8f90Sopenharmony_cinamespace {
355ccb8f90Sopenharmony_ciconstexpr uint32_t PARAM_MAX_NUM = 10;
365ccb8f90Sopenharmony_ciconstexpr uint32_t PARAM_MAX_SIZE = 2000;
375ccb8f90Sopenharmony_ciconstexpr int32_t MAX_PROXY_RUNNINGLOCK_NUM = 2000;
385ccb8f90Sopenharmony_cistd::unique_ptr<ShutdownStubDelegator> g_shutdownDelegator;
395ccb8f90Sopenharmony_cistd::mutex g_shutdownMutex;
405ccb8f90Sopenharmony_ci}
415ccb8f90Sopenharmony_ciint PowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
425ccb8f90Sopenharmony_ci{
435ccb8f90Sopenharmony_ci    POWER_HILOGD(COMP_FWK, "code=%{public}u, flags=%{public}d", code, option.GetFlags());
445ccb8f90Sopenharmony_ci    std::u16string descriptor = PowerMgrStub::GetDescriptor();
455ccb8f90Sopenharmony_ci    std::u16string remoteDescriptor = data.ReadInterfaceToken();
465ccb8f90Sopenharmony_ci    if (descriptor != remoteDescriptor) {
475ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "Descriptor is not matched");
485ccb8f90Sopenharmony_ci        return E_GET_POWER_SERVICE_FAILED;
495ccb8f90Sopenharmony_ci    }
505ccb8f90Sopenharmony_ci    if (IsShutdownCommand(code)) {
515ccb8f90Sopenharmony_ci        {
525ccb8f90Sopenharmony_ci            std::lock_guard<std::mutex> lock(g_shutdownMutex);
535ccb8f90Sopenharmony_ci            if (g_shutdownDelegator == nullptr) {
545ccb8f90Sopenharmony_ci                g_shutdownDelegator = std::make_unique<ShutdownStubDelegator>(*this);
555ccb8f90Sopenharmony_ci                RETURN_IF_WITH_RET(g_shutdownDelegator == nullptr, ERR_NO_INIT)
565ccb8f90Sopenharmony_ci            }
575ccb8f90Sopenharmony_ci        }
585ccb8f90Sopenharmony_ci        int ret = g_shutdownDelegator->HandleRemoteRequest(code, data, reply, option);
595ccb8f90Sopenharmony_ci        if (ret == ERR_INVALID_OPERATION) {
605ccb8f90Sopenharmony_ci            ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
615ccb8f90Sopenharmony_ci        }
625ccb8f90Sopenharmony_ci        return ret;
635ccb8f90Sopenharmony_ci    }
645ccb8f90Sopenharmony_ci
655ccb8f90Sopenharmony_ci    const int DFX_DELAY_S = 60;
665ccb8f90Sopenharmony_ci    int id = HiviewDFX::XCollie::GetInstance().SetTimer("PowerMgrStub", DFX_DELAY_S, nullptr, nullptr,
675ccb8f90Sopenharmony_ci        HiviewDFX::XCOLLIE_FLAG_LOG);
685ccb8f90Sopenharmony_ci
695ccb8f90Sopenharmony_ci    int ret = ERR_OK;
705ccb8f90Sopenharmony_ci    switch (code) {
715ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE):
725ccb8f90Sopenharmony_ci            ret = WakeupDeviceStub(data, reply);
735ccb8f90Sopenharmony_ci            break;
745ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SUSPEND_DEVICE):
755ccb8f90Sopenharmony_ci            ret = SuspendDeviceStub(data, reply);
765ccb8f90Sopenharmony_ci            break;
775ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REFRESH_ACTIVITY):
785ccb8f90Sopenharmony_ci            ret = RefreshActivityStub(data);
795ccb8f90Sopenharmony_ci            break;
805ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE):
815ccb8f90Sopenharmony_ci            ret = RebootDeviceStub(data, reply);
825ccb8f90Sopenharmony_ci            break;
835ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REBOOT_DEVICE_FOR_DEPRECATED):
845ccb8f90Sopenharmony_ci            ret = RebootDeviceForDeprecatedStub(data, reply);
855ccb8f90Sopenharmony_ci            break;
865ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SHUTDOWN_DEVICE):
875ccb8f90Sopenharmony_ci            ret = ShutDownDeviceStub(data, reply);
885ccb8f90Sopenharmony_ci            break;
895ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SET_SUSPEND_TAG):
905ccb8f90Sopenharmony_ci            ret = SetSuspendTagStub(data, reply);
915ccb8f90Sopenharmony_ci            break;
925ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_TIME):
935ccb8f90Sopenharmony_ci            ret = OverrideScreenOffTimeStub(data, reply);
945ccb8f90Sopenharmony_ci            break;
955ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RESTORE_DISPLAY_OFF_TIME):
965ccb8f90Sopenharmony_ci            ret = RestoreScreenOffTimeStub(reply);
975ccb8f90Sopenharmony_ci            break;
985ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::GET_STATE):
995ccb8f90Sopenharmony_ci            ret = GetStateStub(reply);
1005ccb8f90Sopenharmony_ci            break;
1015ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_SCREEN_ON):
1025ccb8f90Sopenharmony_ci            ret = IsScreenOnStub(data, reply);
1035ccb8f90Sopenharmony_ci            break;
1045ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_FOLD_SCREEN_ON):
1055ccb8f90Sopenharmony_ci            ret = IsFoldScreenOnStub(reply);
1065ccb8f90Sopenharmony_ci            break;
1075ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_COLLABORATION_SCREEN_ON):
1085ccb8f90Sopenharmony_ci            ret = IsCollaborationScreenOnStub(reply);
1095ccb8f90Sopenharmony_ci            break;
1105ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::FORCE_DEVICE_SUSPEND):
1115ccb8f90Sopenharmony_ci            ret = ForceSuspendDeviceStub(data, reply);
1125ccb8f90Sopenharmony_ci            break;
1135ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::CREATE_RUNNINGLOCK):
1145ccb8f90Sopenharmony_ci            ret = CreateRunningLockStub(data, reply);
1155ccb8f90Sopenharmony_ci            break;
1165ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RELEASE_RUNNINGLOCK):
1175ccb8f90Sopenharmony_ci            ret = ReleaseRunningLockStub(data);
1185ccb8f90Sopenharmony_ci            break;
1195ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_RUNNINGLOCK_TYPE_SUPPORTED):
1205ccb8f90Sopenharmony_ci            ret = IsRunningLockTypeSupportedStub(data, reply);
1215ccb8f90Sopenharmony_ci            break;
1225ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_LOCK):
1235ccb8f90Sopenharmony_ci            ret = LockStub(data, reply);
1245ccb8f90Sopenharmony_ci            break;
1255ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_UNLOCK):
1265ccb8f90Sopenharmony_ci            ret = UnLockStub(data, reply);
1275ccb8f90Sopenharmony_ci            break;
1285ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_QUERY):
1295ccb8f90Sopenharmony_ci            ret = QueryRunningLockListsStub(data, reply);
1305ccb8f90Sopenharmony_ci            break;
1315ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCK):
1325ccb8f90Sopenharmony_ci            ret = ProxyRunningLockStub(data, reply);
1335ccb8f90Sopenharmony_ci            break;
1345ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RUNNINGLOCK_ISUSED):
1355ccb8f90Sopenharmony_ci            ret = IsUsedStub(data, reply);
1365ccb8f90Sopenharmony_ci            break;
1375ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::PROXY_RUNNINGLOCKS):
1385ccb8f90Sopenharmony_ci            ret = ProxyRunningLocksStub(data, reply);
1395ccb8f90Sopenharmony_ci            break;
1405ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::RESET_RUNNINGLOCKS):
1415ccb8f90Sopenharmony_ci            ret = ResetAllPorxyStub(data, reply);
1425ccb8f90Sopenharmony_ci            break;
1435ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_POWER_STATE_CALLBACK):
1445ccb8f90Sopenharmony_ci            ret = RegisterPowerStateCallbackStub(data);
1455ccb8f90Sopenharmony_ci            break;
1465ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_STATE_CALLBACK):
1475ccb8f90Sopenharmony_ci            ret = UnRegisterPowerStateCallbackStub(data);
1485ccb8f90Sopenharmony_ci            break;
1495ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_POWER_MODE_CALLBACK):
1505ccb8f90Sopenharmony_ci            ret = RegisterPowerModeCallbackStub(data);
1515ccb8f90Sopenharmony_ci            break;
1525ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_POWER_MODE_CALLBACK):
1535ccb8f90Sopenharmony_ci            ret = UnRegisterPowerModeCallbackStub(data);
1545ccb8f90Sopenharmony_ci            break;
1555ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SET_DISPLAY_SUSPEND):
1565ccb8f90Sopenharmony_ci            ret = SetDisplaySuspendStub(data);
1575ccb8f90Sopenharmony_ci            break;
1585ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::HIBERNATE):
1595ccb8f90Sopenharmony_ci            ret = HibernateStub(data, reply);
1605ccb8f90Sopenharmony_ci            break;
1615ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SETMODE_DEVICE):
1625ccb8f90Sopenharmony_ci            ret = SetDeviceModeStub(data, reply);
1635ccb8f90Sopenharmony_ci            break;
1645ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::GETMODE_DEVICE):
1655ccb8f90Sopenharmony_ci            ret = GetDeviceModeStub(reply);
1665ccb8f90Sopenharmony_ci            break;
1675ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SHELL_DUMP):
1685ccb8f90Sopenharmony_ci            ret = ShellDumpStub(data, reply);
1695ccb8f90Sopenharmony_ci            break;
1705ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::IS_STANDBY):
1715ccb8f90Sopenharmony_ci            ret = IsStandbyStub(data, reply);
1725ccb8f90Sopenharmony_ci            break;
1735ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_HIBERNATE_CALLBACK):
1745ccb8f90Sopenharmony_ci            ret = RegisterSyncHibernateCallbackStub(data);
1755ccb8f90Sopenharmony_ci            break;
1765ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_HIBERNATE_CALLBACK):
1775ccb8f90Sopenharmony_ci            ret = UnRegisterSyncHibernateCallbackStub(data);
1785ccb8f90Sopenharmony_ci            break;
1795ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_SLEEP_CALLBACK):
1805ccb8f90Sopenharmony_ci            ret = RegisterSyncSleepCallbackStub(data);
1815ccb8f90Sopenharmony_ci            break;
1825ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_SLEEP_CALLBACK):
1835ccb8f90Sopenharmony_ci            ret = UnRegisterSyncSleepCallbackStub(data);
1845ccb8f90Sopenharmony_ci            break;
1855ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::SET_FORCE_TIMING_OUT):
1865ccb8f90Sopenharmony_ci            ret = SetForceTimingOutStub(data, reply);
1875ccb8f90Sopenharmony_ci            break;
1885ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::LOCK_SCREEN_AFTER_TIMING_OUT):
1895ccb8f90Sopenharmony_ci            ret = LockScreenAfterTimingOutStub(data, reply);
1905ccb8f90Sopenharmony_ci            break;
1915ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_RUNNINGLOCK_CALLBACK):
1925ccb8f90Sopenharmony_ci            ret = RegisterRunningLockCallbackStub(data);
1935ccb8f90Sopenharmony_ci            break;
1945ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_RUNNINGLOCK_CALLBACK):
1955ccb8f90Sopenharmony_ci            ret = UnRegisterRunningLockCallbackStub(data);
1965ccb8f90Sopenharmony_ci            break;
1975ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::REG_SCREEN_OFF_PRE_CALLBACK):
1985ccb8f90Sopenharmony_ci            ret = RegisterScreenStateCallbackStub(data);
1995ccb8f90Sopenharmony_ci            break;
2005ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UNREG_SCREEN_OFF_PRE_CALLBACK):
2015ccb8f90Sopenharmony_ci            ret = UnRegisterScreenStateCallbackStub(data);
2025ccb8f90Sopenharmony_ci            break;
2035ccb8f90Sopenharmony_ci        case static_cast<int>(PowerMgr::PowerMgrInterfaceCode::UPDATE_WORK_SOURCE):
2045ccb8f90Sopenharmony_ci            ret = UpdateWorkSourceStub(data);
2055ccb8f90Sopenharmony_ci            break;
2065ccb8f90Sopenharmony_ci        default:
2075ccb8f90Sopenharmony_ci            ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
2085ccb8f90Sopenharmony_ci    }
2095ccb8f90Sopenharmony_ci    HiviewDFX::XCollie::GetInstance().CancelTimer(id);
2105ccb8f90Sopenharmony_ci    return ret;
2115ccb8f90Sopenharmony_ci}
2125ccb8f90Sopenharmony_ci
2135ccb8f90Sopenharmony_ciint32_t PowerMgrStub::CreateRunningLockStub(MessageParcel& data, MessageParcel& reply)
2145ccb8f90Sopenharmony_ci{
2155ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2165ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR);
2175ccb8f90Sopenharmony_ci    std::unique_ptr<RunningLockInfo> runningLockInfo(data.ReadParcelable<RunningLockInfo>());
2185ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((runningLockInfo == nullptr), E_READ_PARCEL_ERROR);
2195ccb8f90Sopenharmony_ci    PowerErrors error = CreateRunningLock(remoteObj, *runningLockInfo);
2205ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
2215ccb8f90Sopenharmony_ci    return ERR_OK;
2225ccb8f90Sopenharmony_ci}
2235ccb8f90Sopenharmony_ci
2245ccb8f90Sopenharmony_ciint32_t PowerMgrStub::ReleaseRunningLockStub(MessageParcel& data)
2255ccb8f90Sopenharmony_ci{
2265ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2275ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR);
2285ccb8f90Sopenharmony_ci    std::string name;
2295ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, String, name, E_READ_PARCEL_ERROR);
2305ccb8f90Sopenharmony_ci    ReleaseRunningLock(remoteObj, name);
2315ccb8f90Sopenharmony_ci    return ERR_OK;
2325ccb8f90Sopenharmony_ci}
2335ccb8f90Sopenharmony_ci
2345ccb8f90Sopenharmony_ciint32_t PowerMgrStub::IsRunningLockTypeSupportedStub(MessageParcel& data, MessageParcel& reply)
2355ccb8f90Sopenharmony_ci{
2365ccb8f90Sopenharmony_ci    auto type = static_cast<uint32_t >(RunningLockType::RUNNINGLOCK_BUTT);
2375ccb8f90Sopenharmony_ci    bool ret = false;
2385ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR);
2395ccb8f90Sopenharmony_ci    ret = IsRunningLockTypeSupported(static_cast<RunningLockType>(type));
2405ccb8f90Sopenharmony_ci    if (!reply.WriteBool(ret)) {
2415ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_SUSPEND, "WriteBool fail");
2425ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
2435ccb8f90Sopenharmony_ci    }
2445ccb8f90Sopenharmony_ci    return ERR_OK;
2455ccb8f90Sopenharmony_ci}
2465ccb8f90Sopenharmony_ci
2475ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UpdateWorkSourceStub(MessageParcel& data)
2485ccb8f90Sopenharmony_ci{
2495ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2505ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR);
2515ccb8f90Sopenharmony_ci    uint32_t size = 0;
2525ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, size, E_READ_PARCEL_ERROR);
2535ccb8f90Sopenharmony_ci    if (size > PARAM_MAX_SIZE) {
2545ccb8f90Sopenharmony_ci        return E_EXCEED_PARAM_LIMIT;
2555ccb8f90Sopenharmony_ci    }
2565ccb8f90Sopenharmony_ci    std::map<int32_t, std::string> workSources;
2575ccb8f90Sopenharmony_ci    for (uint32_t i = 0; i < size; ++i) {
2585ccb8f90Sopenharmony_ci        int32_t uid = 0;
2595ccb8f90Sopenharmony_ci        std::string bundleName;
2605ccb8f90Sopenharmony_ci        RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, uid, E_READ_PARCEL_ERROR);
2615ccb8f90Sopenharmony_ci        RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, String, bundleName, E_READ_PARCEL_ERROR);
2625ccb8f90Sopenharmony_ci        workSources[uid] = bundleName;
2635ccb8f90Sopenharmony_ci    }
2645ccb8f90Sopenharmony_ci    UpdateWorkSource(remoteObj, workSources);
2655ccb8f90Sopenharmony_ci    return ERR_OK;
2665ccb8f90Sopenharmony_ci}
2675ccb8f90Sopenharmony_ci
2685ccb8f90Sopenharmony_ciint32_t PowerMgrStub::LockStub(MessageParcel& data, MessageParcel& reply)
2695ccb8f90Sopenharmony_ci{
2705ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2715ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR);
2725ccb8f90Sopenharmony_ci    int32_t timeOutMs = 0;
2735ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, timeOutMs, E_READ_PARCEL_ERROR);
2745ccb8f90Sopenharmony_ci    PowerErrors error = Lock(remoteObj, timeOutMs);
2755ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
2765ccb8f90Sopenharmony_ci    return ERR_OK;
2775ccb8f90Sopenharmony_ci}
2785ccb8f90Sopenharmony_ci
2795ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UnLockStub(MessageParcel& data, MessageParcel& reply)
2805ccb8f90Sopenharmony_ci{
2815ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2825ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR);
2835ccb8f90Sopenharmony_ci    std::string name;
2845ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, String, name, E_READ_PARCEL_ERROR);
2855ccb8f90Sopenharmony_ci    PowerErrors error = UnLock(remoteObj, name);
2865ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
2875ccb8f90Sopenharmony_ci    return ERR_OK;
2885ccb8f90Sopenharmony_ci}
2895ccb8f90Sopenharmony_ci
2905ccb8f90Sopenharmony_ciint32_t PowerMgrStub::QueryRunningLockListsStub(MessageParcel& data, MessageParcel& reply)
2915ccb8f90Sopenharmony_ci{
2925ccb8f90Sopenharmony_ci    std::map<std::string, RunningLockInfo> runningLockLists;
2935ccb8f90Sopenharmony_ci    QueryRunningLockLists(runningLockLists);
2945ccb8f90Sopenharmony_ci    reply.WriteInt32(runningLockLists.size());
2955ccb8f90Sopenharmony_ci    for (auto it : runningLockLists) {
2965ccb8f90Sopenharmony_ci        reply.WriteString(it.first);
2975ccb8f90Sopenharmony_ci        reply.WriteParcelable(&it.second);
2985ccb8f90Sopenharmony_ci    }
2995ccb8f90Sopenharmony_ci    return ERR_OK;
3005ccb8f90Sopenharmony_ci}
3015ccb8f90Sopenharmony_ciint32_t PowerMgrStub::IsUsedStub(MessageParcel& data, MessageParcel& reply)
3025ccb8f90Sopenharmony_ci{
3035ccb8f90Sopenharmony_ci    sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
3045ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((remoteObj == nullptr), E_READ_PARCEL_ERROR);
3055ccb8f90Sopenharmony_ci    bool ret = IsUsed(remoteObj);
3065ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR);
3075ccb8f90Sopenharmony_ci    return ERR_OK;
3085ccb8f90Sopenharmony_ci}
3095ccb8f90Sopenharmony_ci
3105ccb8f90Sopenharmony_ciint32_t PowerMgrStub::ProxyRunningLockStub(MessageParcel& data, MessageParcel& reply)
3115ccb8f90Sopenharmony_ci{
3125ccb8f90Sopenharmony_ci    bool isProxied = false;
3135ccb8f90Sopenharmony_ci    pid_t uid;
3145ccb8f90Sopenharmony_ci    pid_t pid;
3155ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, E_READ_PARCEL_ERROR);
3165ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, pid, E_READ_PARCEL_ERROR);
3175ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, uid, E_READ_PARCEL_ERROR);
3185ccb8f90Sopenharmony_ci    bool ret = ProxyRunningLock(isProxied, pid, uid);
3195ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR);
3205ccb8f90Sopenharmony_ci    return ERR_OK;
3215ccb8f90Sopenharmony_ci}
3225ccb8f90Sopenharmony_ci
3235ccb8f90Sopenharmony_ciint32_t PowerMgrStub::ProxyRunningLocksStub(MessageParcel& data, MessageParcel& reply)
3245ccb8f90Sopenharmony_ci{
3255ccb8f90Sopenharmony_ci    bool isProxied = false;
3265ccb8f90Sopenharmony_ci    std::vector<std::pair<pid_t, pid_t>> processInfos {};
3275ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, isProxied, E_READ_PARCEL_ERROR);
3285ccb8f90Sopenharmony_ci    int32_t size {0};
3295ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, size, E_READ_PARCEL_ERROR);
3305ccb8f90Sopenharmony_ci    if (size <= 0 || size > MAX_PROXY_RUNNINGLOCK_NUM) {
3315ccb8f90Sopenharmony_ci        POWER_HILOGW(COMP_FWK, "size exceed limit, size=%{public}d", size);
3325ccb8f90Sopenharmony_ci        return E_EXCEED_PARAM_LIMIT;
3335ccb8f90Sopenharmony_ci    }
3345ccb8f90Sopenharmony_ci    processInfos.resize(size);
3355ccb8f90Sopenharmony_ci    for (int i = 0; i < size; ++i) {
3365ccb8f90Sopenharmony_ci        RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].first, E_READ_PARCEL_ERROR);
3375ccb8f90Sopenharmony_ci        RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, processInfos[i].second, E_READ_PARCEL_ERROR);
3385ccb8f90Sopenharmony_ci    }
3395ccb8f90Sopenharmony_ci    bool ret = ProxyRunningLocks(isProxied, processInfos);
3405ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR);
3415ccb8f90Sopenharmony_ci    return ERR_OK;
3425ccb8f90Sopenharmony_ci}
3435ccb8f90Sopenharmony_ci
3445ccb8f90Sopenharmony_ciint32_t PowerMgrStub::ResetAllPorxyStub(MessageParcel& data, MessageParcel& reply)
3455ccb8f90Sopenharmony_ci{
3465ccb8f90Sopenharmony_ci    bool ret = ResetRunningLocks();
3475ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, ret, E_WRITE_PARCEL_ERROR);
3485ccb8f90Sopenharmony_ci    return ERR_OK;
3495ccb8f90Sopenharmony_ci}
3505ccb8f90Sopenharmony_ci
3515ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RebootDeviceStub(MessageParcel& data, MessageParcel& reply)
3525ccb8f90Sopenharmony_ci{
3535ccb8f90Sopenharmony_ci    std::string reason = Str16ToStr8(data.ReadString16());
3545ccb8f90Sopenharmony_ci    PowerErrors error = RebootDevice(reason);
3555ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
3565ccb8f90Sopenharmony_ci    return ERR_OK;
3575ccb8f90Sopenharmony_ci}
3585ccb8f90Sopenharmony_ci
3595ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RebootDeviceForDeprecatedStub(MessageParcel& data, MessageParcel& reply)
3605ccb8f90Sopenharmony_ci{
3615ccb8f90Sopenharmony_ci    std::string reason = Str16ToStr8(data.ReadString16());
3625ccb8f90Sopenharmony_ci    PowerErrors error = RebootDeviceForDeprecated(reason);
3635ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
3645ccb8f90Sopenharmony_ci    return ERR_OK;
3655ccb8f90Sopenharmony_ci}
3665ccb8f90Sopenharmony_ci
3675ccb8f90Sopenharmony_ciint32_t PowerMgrStub::ShutDownDeviceStub(MessageParcel& data, MessageParcel& reply)
3685ccb8f90Sopenharmony_ci{
3695ccb8f90Sopenharmony_ci    std::string reason = Str16ToStr8(data.ReadString16());
3705ccb8f90Sopenharmony_ci    PowerErrors error = ShutDownDevice(reason);
3715ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
3725ccb8f90Sopenharmony_ci    return ERR_OK;
3735ccb8f90Sopenharmony_ci}
3745ccb8f90Sopenharmony_ci
3755ccb8f90Sopenharmony_ciint32_t PowerMgrStub::SetSuspendTagStub(MessageParcel& data, MessageParcel& reply)
3765ccb8f90Sopenharmony_ci{
3775ccb8f90Sopenharmony_ci    std::string tag = Str16ToStr8(data.ReadString16());
3785ccb8f90Sopenharmony_ci    PowerErrors error = SetSuspendTag(tag);
3795ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
3805ccb8f90Sopenharmony_ci    return ERR_OK;
3815ccb8f90Sopenharmony_ci}
3825ccb8f90Sopenharmony_ci
3835ccb8f90Sopenharmony_ciint32_t PowerMgrStub::WakeupDeviceStub(MessageParcel& data, MessageParcel& reply)
3845ccb8f90Sopenharmony_ci{
3855ccb8f90Sopenharmony_ci    int64_t time = 0;
3865ccb8f90Sopenharmony_ci    uint32_t reason = 0;
3875ccb8f90Sopenharmony_ci
3885ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR);
3895ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, reason, E_READ_PARCEL_ERROR);
3905ccb8f90Sopenharmony_ci    std::string details = Str16ToStr8(data.ReadString16());
3915ccb8f90Sopenharmony_ci
3925ccb8f90Sopenharmony_ci    PowerErrors error = WakeupDevice(time, static_cast<WakeupDeviceType>(reason), details);
3935ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
3945ccb8f90Sopenharmony_ci    return ERR_OK;
3955ccb8f90Sopenharmony_ci}
3965ccb8f90Sopenharmony_ci
3975ccb8f90Sopenharmony_ciint32_t PowerMgrStub::SuspendDeviceStub(MessageParcel& data, MessageParcel& reply)
3985ccb8f90Sopenharmony_ci{
3995ccb8f90Sopenharmony_ci    int64_t time = 0;
4005ccb8f90Sopenharmony_ci    uint32_t reason = 0;
4015ccb8f90Sopenharmony_ci    bool suspendImmed = true;
4025ccb8f90Sopenharmony_ci
4035ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR);
4045ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, reason, E_READ_PARCEL_ERROR);
4055ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, suspendImmed, E_READ_PARCEL_ERROR);
4065ccb8f90Sopenharmony_ci
4075ccb8f90Sopenharmony_ci    PowerErrors error = SuspendDevice(time, static_cast<SuspendDeviceType>(reason), suspendImmed);
4085ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
4095ccb8f90Sopenharmony_ci    return ERR_OK;
4105ccb8f90Sopenharmony_ci}
4115ccb8f90Sopenharmony_ci
4125ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RefreshActivityStub(MessageParcel& data)
4135ccb8f90Sopenharmony_ci{
4145ccb8f90Sopenharmony_ci    int64_t time = 0;
4155ccb8f90Sopenharmony_ci    uint32_t type = 0;
4165ccb8f90Sopenharmony_ci    bool needChangeBacklight = true;
4175ccb8f90Sopenharmony_ci
4185ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR);
4195ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR);
4205ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, needChangeBacklight, E_READ_PARCEL_ERROR);
4215ccb8f90Sopenharmony_ci
4225ccb8f90Sopenharmony_ci    RefreshActivity(time, static_cast<UserActivityType>(type), needChangeBacklight);
4235ccb8f90Sopenharmony_ci    return ERR_OK;
4245ccb8f90Sopenharmony_ci}
4255ccb8f90Sopenharmony_ci
4265ccb8f90Sopenharmony_ciint32_t PowerMgrStub::OverrideScreenOffTimeStub(MessageParcel& data, MessageParcel& reply)
4275ccb8f90Sopenharmony_ci{
4285ccb8f90Sopenharmony_ci    int64_t timeout = 0;
4295ccb8f90Sopenharmony_ci
4305ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, timeout, E_READ_PARCEL_ERROR);
4315ccb8f90Sopenharmony_ci
4325ccb8f90Sopenharmony_ci    PowerErrors error = OverrideScreenOffTime(timeout);
4335ccb8f90Sopenharmony_ci    if (!reply.WriteInt32(static_cast<int32_t>(error))) {
4345ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "WriteInt32 fail");
4355ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
4365ccb8f90Sopenharmony_ci    }
4375ccb8f90Sopenharmony_ci    return ERR_OK;
4385ccb8f90Sopenharmony_ci}
4395ccb8f90Sopenharmony_ci
4405ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RestoreScreenOffTimeStub(MessageParcel& reply)
4415ccb8f90Sopenharmony_ci{
4425ccb8f90Sopenharmony_ci    PowerErrors error = RestoreScreenOffTime();
4435ccb8f90Sopenharmony_ci    if (!reply.WriteInt32(static_cast<int32_t>(error))) {
4445ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "WriteInt32 fail");
4455ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
4465ccb8f90Sopenharmony_ci    }
4475ccb8f90Sopenharmony_ci    return ERR_OK;
4485ccb8f90Sopenharmony_ci}
4495ccb8f90Sopenharmony_ci
4505ccb8f90Sopenharmony_ciint32_t PowerMgrStub::ForceSuspendDeviceStub(MessageParcel& data, MessageParcel& reply)
4515ccb8f90Sopenharmony_ci{
4525ccb8f90Sopenharmony_ci    int64_t time = 0;
4535ccb8f90Sopenharmony_ci
4545ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int64, time, E_READ_PARCEL_ERROR);
4555ccb8f90Sopenharmony_ci    sptr<IPowerMgrAsync> powerProxy = iface_cast<IPowerMgrAsync>(data.ReadRemoteObject());
4565ccb8f90Sopenharmony_ci
4575ccb8f90Sopenharmony_ci    PowerErrors error = ForceSuspendDevice(time);
4585ccb8f90Sopenharmony_ci    int result = static_cast<int>(error);
4595ccb8f90Sopenharmony_ci    if (powerProxy != nullptr) {
4605ccb8f90Sopenharmony_ci        powerProxy->SendAsyncReply(result);
4615ccb8f90Sopenharmony_ci    }
4625ccb8f90Sopenharmony_ci    return ERR_OK;
4635ccb8f90Sopenharmony_ci}
4645ccb8f90Sopenharmony_ci
4655ccb8f90Sopenharmony_ciint32_t PowerMgrStub::GetStateStub(MessageParcel& reply)
4665ccb8f90Sopenharmony_ci{
4675ccb8f90Sopenharmony_ci    PowerState ret = GetState();
4685ccb8f90Sopenharmony_ci    if (!reply.WriteUint32(static_cast<uint32_t>(ret))) {
4695ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_STATE, "WriteUint32 fail");
4705ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
4715ccb8f90Sopenharmony_ci    }
4725ccb8f90Sopenharmony_ci    return ERR_OK;
4735ccb8f90Sopenharmony_ci}
4745ccb8f90Sopenharmony_ci
4755ccb8f90Sopenharmony_ciint32_t PowerMgrStub::IsCollaborationScreenOnStub(MessageParcel& reply)
4765ccb8f90Sopenharmony_ci{
4775ccb8f90Sopenharmony_ci    bool ret = false;
4785ccb8f90Sopenharmony_ci    ret = IsCollaborationScreenOn();
4795ccb8f90Sopenharmony_ci    if (!reply.WriteBool(ret)) {
4805ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "WriteBool fail");
4815ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
4825ccb8f90Sopenharmony_ci    }
4835ccb8f90Sopenharmony_ci    return ERR_OK;
4845ccb8f90Sopenharmony_ci}
4855ccb8f90Sopenharmony_ci
4865ccb8f90Sopenharmony_ciint32_t PowerMgrStub::IsFoldScreenOnStub(MessageParcel& reply)
4875ccb8f90Sopenharmony_ci{
4885ccb8f90Sopenharmony_ci    bool ret = false;
4895ccb8f90Sopenharmony_ci    ret = IsFoldScreenOn();
4905ccb8f90Sopenharmony_ci    if (!reply.WriteBool(ret)) {
4915ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "WriteBool fail");
4925ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
4935ccb8f90Sopenharmony_ci    }
4945ccb8f90Sopenharmony_ci    return ERR_OK;
4955ccb8f90Sopenharmony_ci}
4965ccb8f90Sopenharmony_ci
4975ccb8f90Sopenharmony_ciint32_t PowerMgrStub::IsScreenOnStub(MessageParcel& data, MessageParcel& reply)
4985ccb8f90Sopenharmony_ci{
4995ccb8f90Sopenharmony_ci    bool ret = false;
5005ccb8f90Sopenharmony_ci    bool needPrintLog = true;
5015ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, needPrintLog, E_READ_PARCEL_ERROR);
5025ccb8f90Sopenharmony_ci    ret = IsScreenOn(needPrintLog);
5035ccb8f90Sopenharmony_ci    if (!reply.WriteBool(ret)) {
5045ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "WriteBool fail");
5055ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
5065ccb8f90Sopenharmony_ci    }
5075ccb8f90Sopenharmony_ci    return ERR_OK;
5085ccb8f90Sopenharmony_ci}
5095ccb8f90Sopenharmony_ci
5105ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RegisterPowerStateCallbackStub(MessageParcel& data)
5115ccb8f90Sopenharmony_ci{
5125ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5135ccb8f90Sopenharmony_ci    bool isSync = true;
5145ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, isSync, E_READ_PARCEL_ERROR);
5155ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5165ccb8f90Sopenharmony_ci    sptr<IPowerStateCallback> callback = iface_cast<IPowerStateCallback>(obj);
5175ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5185ccb8f90Sopenharmony_ci    RegisterPowerStateCallback(callback, isSync);
5195ccb8f90Sopenharmony_ci    return ERR_OK;
5205ccb8f90Sopenharmony_ci}
5215ccb8f90Sopenharmony_ci
5225ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UnRegisterPowerStateCallbackStub(MessageParcel& data)
5235ccb8f90Sopenharmony_ci{
5245ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5255ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5265ccb8f90Sopenharmony_ci    sptr<IPowerStateCallback> callback = iface_cast<IPowerStateCallback>(obj);
5275ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5285ccb8f90Sopenharmony_ci    UnRegisterPowerStateCallback(callback);
5295ccb8f90Sopenharmony_ci    return ERR_OK;
5305ccb8f90Sopenharmony_ci}
5315ccb8f90Sopenharmony_ci
5325ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RegisterSyncHibernateCallbackStub(MessageParcel& data)
5335ccb8f90Sopenharmony_ci{
5345ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5355ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5365ccb8f90Sopenharmony_ci    sptr<ISyncHibernateCallback> callback = iface_cast<ISyncHibernateCallback>(obj);
5375ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5385ccb8f90Sopenharmony_ci    RegisterSyncHibernateCallback(callback);
5395ccb8f90Sopenharmony_ci    return ERR_OK;
5405ccb8f90Sopenharmony_ci}
5415ccb8f90Sopenharmony_ci
5425ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UnRegisterSyncHibernateCallbackStub(MessageParcel& data)
5435ccb8f90Sopenharmony_ci{
5445ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5455ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5465ccb8f90Sopenharmony_ci    sptr<ISyncHibernateCallback> callback = iface_cast<ISyncHibernateCallback>(obj);
5475ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5485ccb8f90Sopenharmony_ci    UnRegisterSyncHibernateCallback(callback);
5495ccb8f90Sopenharmony_ci    return ERR_OK;
5505ccb8f90Sopenharmony_ci}
5515ccb8f90Sopenharmony_ci
5525ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RegisterSyncSleepCallbackStub(MessageParcel& data)
5535ccb8f90Sopenharmony_ci{
5545ccb8f90Sopenharmony_ci    uint32_t priority;
5555ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5565ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, priority, E_READ_PARCEL_ERROR);
5575ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5585ccb8f90Sopenharmony_ci    sptr<ISyncSleepCallback> callback = iface_cast<ISyncSleepCallback>(obj);
5595ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5605ccb8f90Sopenharmony_ci    RegisterSyncSleepCallback(callback);
5615ccb8f90Sopenharmony_ci    return ERR_OK;
5625ccb8f90Sopenharmony_ci}
5635ccb8f90Sopenharmony_ci
5645ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UnRegisterSyncSleepCallbackStub(MessageParcel& data)
5655ccb8f90Sopenharmony_ci{
5665ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5675ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5685ccb8f90Sopenharmony_ci    sptr<ISyncSleepCallback> callback = iface_cast<ISyncSleepCallback>(obj);
5695ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5705ccb8f90Sopenharmony_ci    UnRegisterSyncSleepCallback(callback);
5715ccb8f90Sopenharmony_ci    return ERR_OK;
5725ccb8f90Sopenharmony_ci}
5735ccb8f90Sopenharmony_ci
5745ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RegisterPowerModeCallbackStub(MessageParcel& data)
5755ccb8f90Sopenharmony_ci{
5765ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5775ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5785ccb8f90Sopenharmony_ci    sptr<IPowerModeCallback> callback = iface_cast<IPowerModeCallback>(obj);
5795ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5805ccb8f90Sopenharmony_ci    RegisterPowerModeCallback(callback);
5815ccb8f90Sopenharmony_ci    return ERR_OK;
5825ccb8f90Sopenharmony_ci}
5835ccb8f90Sopenharmony_ci
5845ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UnRegisterPowerModeCallbackStub(MessageParcel& data)
5855ccb8f90Sopenharmony_ci{
5865ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
5875ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
5885ccb8f90Sopenharmony_ci    sptr<IPowerModeCallback> callback = iface_cast<IPowerModeCallback>(obj);
5895ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
5905ccb8f90Sopenharmony_ci    UnRegisterPowerModeCallback(callback);
5915ccb8f90Sopenharmony_ci    return ERR_OK;
5925ccb8f90Sopenharmony_ci}
5935ccb8f90Sopenharmony_ci
5945ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RegisterScreenStateCallbackStub(MessageParcel& data)
5955ccb8f90Sopenharmony_ci{
5965ccb8f90Sopenharmony_ci    int32_t remainTime = 0;
5975ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, remainTime, E_READ_PARCEL_ERROR);
5985ccb8f90Sopenharmony_ci
5995ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
6005ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
6015ccb8f90Sopenharmony_ci    sptr<IScreenOffPreCallback> callback = iface_cast<IScreenOffPreCallback>(obj);
6025ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
6035ccb8f90Sopenharmony_ci    RegisterScreenStateCallback(remainTime, callback);
6045ccb8f90Sopenharmony_ci    return ERR_OK;
6055ccb8f90Sopenharmony_ci}
6065ccb8f90Sopenharmony_ci
6075ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UnRegisterScreenStateCallbackStub(MessageParcel& data)
6085ccb8f90Sopenharmony_ci{
6095ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
6105ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
6115ccb8f90Sopenharmony_ci    sptr<IScreenOffPreCallback> callback = iface_cast<IScreenOffPreCallback>(obj);
6125ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
6135ccb8f90Sopenharmony_ci    UnRegisterScreenStateCallback(callback);
6145ccb8f90Sopenharmony_ci    return ERR_OK;
6155ccb8f90Sopenharmony_ci}
6165ccb8f90Sopenharmony_ci
6175ccb8f90Sopenharmony_ciint32_t PowerMgrStub::RegisterRunningLockCallbackStub(MessageParcel& data)
6185ccb8f90Sopenharmony_ci{
6195ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
6205ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
6215ccb8f90Sopenharmony_ci    sptr<IPowerRunninglockCallback> callback = iface_cast<IPowerRunninglockCallback>(obj);
6225ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
6235ccb8f90Sopenharmony_ci    RegisterRunningLockCallback(callback);
6245ccb8f90Sopenharmony_ci    return ERR_OK;
6255ccb8f90Sopenharmony_ci}
6265ccb8f90Sopenharmony_ci
6275ccb8f90Sopenharmony_ciint32_t PowerMgrStub::UnRegisterRunningLockCallbackStub(MessageParcel& data)
6285ccb8f90Sopenharmony_ci{
6295ccb8f90Sopenharmony_ci    sptr<IRemoteObject> obj = data.ReadRemoteObject();
6305ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
6315ccb8f90Sopenharmony_ci    sptr<IPowerRunninglockCallback> callback = iface_cast<IPowerRunninglockCallback>(obj);
6325ccb8f90Sopenharmony_ci    RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
6335ccb8f90Sopenharmony_ci    UnRegisterRunningLockCallback(callback);
6345ccb8f90Sopenharmony_ci    return ERR_OK;
6355ccb8f90Sopenharmony_ci}
6365ccb8f90Sopenharmony_ci
6375ccb8f90Sopenharmony_ciint32_t PowerMgrStub::SetDisplaySuspendStub(MessageParcel& data)
6385ccb8f90Sopenharmony_ci{
6395ccb8f90Sopenharmony_ci    bool enable = false;
6405ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enable, E_READ_PARCEL_ERROR);
6415ccb8f90Sopenharmony_ci    SetDisplaySuspend(enable);
6425ccb8f90Sopenharmony_ci    return ERR_OK;
6435ccb8f90Sopenharmony_ci}
6445ccb8f90Sopenharmony_ci
6455ccb8f90Sopenharmony_ciint32_t PowerMgrStub::HibernateStub(MessageParcel& data, MessageParcel& reply)
6465ccb8f90Sopenharmony_ci{
6475ccb8f90Sopenharmony_ci    bool clearMemory = false;
6485ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, clearMemory, E_READ_PARCEL_ERROR);
6495ccb8f90Sopenharmony_ci    sptr<IPowerMgrAsync> powerProxy = iface_cast<IPowerMgrAsync>(data.ReadRemoteObject());
6505ccb8f90Sopenharmony_ci
6515ccb8f90Sopenharmony_ci    PowerErrors error = Hibernate(clearMemory);
6525ccb8f90Sopenharmony_ci    int result = static_cast<int>(error);
6535ccb8f90Sopenharmony_ci    if (powerProxy != nullptr) {
6545ccb8f90Sopenharmony_ci        powerProxy->SendAsyncReply(result);
6555ccb8f90Sopenharmony_ci    }
6565ccb8f90Sopenharmony_ci    return ERR_OK;
6575ccb8f90Sopenharmony_ci}
6585ccb8f90Sopenharmony_ci
6595ccb8f90Sopenharmony_ciint32_t PowerMgrStub::SetDeviceModeStub(MessageParcel& data, MessageParcel& reply)
6605ccb8f90Sopenharmony_ci{
6615ccb8f90Sopenharmony_ci    uint32_t mode = 0;
6625ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, mode, E_READ_PARCEL_ERROR);
6635ccb8f90Sopenharmony_ci    PowerErrors error = SetDeviceMode(static_cast<PowerMode>(mode));
6645ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(error), E_WRITE_PARCEL_ERROR);
6655ccb8f90Sopenharmony_ci    return ERR_OK;
6665ccb8f90Sopenharmony_ci}
6675ccb8f90Sopenharmony_ci
6685ccb8f90Sopenharmony_ciint32_t PowerMgrStub::GetDeviceModeStub(MessageParcel& reply)
6695ccb8f90Sopenharmony_ci{
6705ccb8f90Sopenharmony_ci    uint32_t ret = 0;
6715ccb8f90Sopenharmony_ci    ret = static_cast<uint32_t>(GetDeviceMode());
6725ccb8f90Sopenharmony_ci    if (!reply.WriteUint32(static_cast<uint32_t>(ret))) {
6735ccb8f90Sopenharmony_ci        POWER_HILOGE(FEATURE_POWER_MODE, "WriteUint32 fail");
6745ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
6755ccb8f90Sopenharmony_ci    }
6765ccb8f90Sopenharmony_ci    return ERR_OK;
6775ccb8f90Sopenharmony_ci}
6785ccb8f90Sopenharmony_ci
6795ccb8f90Sopenharmony_ciint32_t PowerMgrStub::ShellDumpStub(MessageParcel& data, MessageParcel& reply)
6805ccb8f90Sopenharmony_ci{
6815ccb8f90Sopenharmony_ci    uint32_t argc;
6825ccb8f90Sopenharmony_ci    std::vector<std::string> args;
6835ccb8f90Sopenharmony_ci
6845ccb8f90Sopenharmony_ci    if (!data.ReadUint32(argc)) {
6855ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "ReadUint32 fail");
6865ccb8f90Sopenharmony_ci        return E_READ_PARCEL_ERROR;
6875ccb8f90Sopenharmony_ci    }
6885ccb8f90Sopenharmony_ci
6895ccb8f90Sopenharmony_ci    if (argc >= PARAM_MAX_NUM) {
6905ccb8f90Sopenharmony_ci        POWER_HILOGW(COMP_FWK, "params exceed limit, argc=%{public}d", argc);
6915ccb8f90Sopenharmony_ci        return E_EXCEED_PARAM_LIMIT;
6925ccb8f90Sopenharmony_ci    }
6935ccb8f90Sopenharmony_ci
6945ccb8f90Sopenharmony_ci    for (uint32_t i = 0; i < argc; i++) {
6955ccb8f90Sopenharmony_ci        std::string arg = data.ReadString();
6965ccb8f90Sopenharmony_ci        if (arg.empty()) {
6975ccb8f90Sopenharmony_ci            POWER_HILOGW(COMP_FWK, "read args fail, arg index=%{public}d", i);
6985ccb8f90Sopenharmony_ci            return E_READ_PARCEL_ERROR;
6995ccb8f90Sopenharmony_ci        }
7005ccb8f90Sopenharmony_ci        args.push_back(arg);
7015ccb8f90Sopenharmony_ci    }
7025ccb8f90Sopenharmony_ci
7035ccb8f90Sopenharmony_ci    std::string ret = ShellDump(args, argc);
7045ccb8f90Sopenharmony_ci    if (!reply.WriteString(ret)) {
7055ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "WriteString fail");
7065ccb8f90Sopenharmony_ci        return E_WRITE_PARCEL_ERROR;
7075ccb8f90Sopenharmony_ci    }
7085ccb8f90Sopenharmony_ci    return ERR_OK;
7095ccb8f90Sopenharmony_ci}
7105ccb8f90Sopenharmony_ci
7115ccb8f90Sopenharmony_cibool PowerMgrStub::IsShutdownCommand(uint32_t code)
7125ccb8f90Sopenharmony_ci{
7135ccb8f90Sopenharmony_ci    return (code >= static_cast<uint32_t>(PowerMgr::ShutdownClientInterfaceCode::CMD_START)) &&
7145ccb8f90Sopenharmony_ci        (code <= static_cast<uint32_t>(PowerMgr::ShutdownClientInterfaceCode::CMD_END));
7155ccb8f90Sopenharmony_ci}
7165ccb8f90Sopenharmony_ci
7175ccb8f90Sopenharmony_ciint32_t PowerMgrStub::IsStandbyStub(MessageParcel& data, MessageParcel& reply)
7185ccb8f90Sopenharmony_ci{
7195ccb8f90Sopenharmony_ci    bool isStandby = false;
7205ccb8f90Sopenharmony_ci    PowerErrors ret = IsStandby(isStandby);
7215ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(ret), E_WRITE_PARCEL_ERROR);
7225ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isStandby, E_WRITE_PARCEL_ERROR);
7235ccb8f90Sopenharmony_ci    return ERR_OK;
7245ccb8f90Sopenharmony_ci}
7255ccb8f90Sopenharmony_ci
7265ccb8f90Sopenharmony_ciint32_t PowerMgrStub::SetForceTimingOutStub(MessageParcel& data, MessageParcel& reply)
7275ccb8f90Sopenharmony_ci{
7285ccb8f90Sopenharmony_ci    POWER_HILOGI(COMP_FWK, "SetForceTimingOutStub msg received");
7295ccb8f90Sopenharmony_ci    bool enabled = false;
7305ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enabled, E_READ_PARCEL_ERROR);
7315ccb8f90Sopenharmony_ci    sptr<IRemoteObject> token = data.ReadRemoteObject();
7325ccb8f90Sopenharmony_ci    if (!token) {
7335ccb8f90Sopenharmony_ci        POWER_HILOGE(COMP_FWK, "ReadRemoteObject failed, possibly blocked by SeLinux");
7345ccb8f90Sopenharmony_ci    }
7355ccb8f90Sopenharmony_ci    PowerErrors ret = SetForceTimingOut(enabled, token);
7365ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(ret), E_WRITE_PARCEL_ERROR);
7375ccb8f90Sopenharmony_ci    return ERR_OK;
7385ccb8f90Sopenharmony_ci}
7395ccb8f90Sopenharmony_ci
7405ccb8f90Sopenharmony_ciint32_t PowerMgrStub::LockScreenAfterTimingOutStub(MessageParcel& data, MessageParcel& reply)
7415ccb8f90Sopenharmony_ci{
7425ccb8f90Sopenharmony_ci    bool enabledLockScreen = true;
7435ccb8f90Sopenharmony_ci    bool checkLock = false;
7445ccb8f90Sopenharmony_ci    bool sendScreenOffEvent = true;
7455ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enabledLockScreen, E_READ_PARCEL_ERROR);
7465ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, checkLock, E_READ_PARCEL_ERROR);
7475ccb8f90Sopenharmony_ci    RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, sendScreenOffEvent, E_READ_PARCEL_ERROR);
7485ccb8f90Sopenharmony_ci    sptr<IRemoteObject> token = data.ReadRemoteObject();
7495ccb8f90Sopenharmony_ci    if (!token) {
7505ccb8f90Sopenharmony_ci        POWER_HILOGI(COMP_FWK, "ReadRemoteObject failed, possibly blocked by SeLinux");
7515ccb8f90Sopenharmony_ci    }
7525ccb8f90Sopenharmony_ci    PowerErrors ret = LockScreenAfterTimingOut(enabledLockScreen, checkLock, sendScreenOffEvent, token);
7535ccb8f90Sopenharmony_ci    RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, static_cast<int32_t>(ret), E_WRITE_PARCEL_ERROR);
7545ccb8f90Sopenharmony_ci    return ERR_OK;
7555ccb8f90Sopenharmony_ci}
7565ccb8f90Sopenharmony_ci} // namespace PowerMgr
7575ccb8f90Sopenharmony_ci} // namespace OHOS
758