199552fe9Sopenharmony_ci/*
299552fe9Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
399552fe9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
499552fe9Sopenharmony_ci * you may not use this file except in compliance with the License.
599552fe9Sopenharmony_ci * You may obtain a copy of the License at
699552fe9Sopenharmony_ci *
799552fe9Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
899552fe9Sopenharmony_ci *
999552fe9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1099552fe9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1199552fe9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1299552fe9Sopenharmony_ci * See the License for the specific language governing permissions and
1399552fe9Sopenharmony_ci * limitations under the License.
1499552fe9Sopenharmony_ci */
1599552fe9Sopenharmony_ci
1699552fe9Sopenharmony_ci#include "standby_service_stub.h"
1799552fe9Sopenharmony_ci
1899552fe9Sopenharmony_ci#include <ipc_skeleton.h>
1999552fe9Sopenharmony_ci#include <string_ex.h>
2099552fe9Sopenharmony_ci
2199552fe9Sopenharmony_ci#include "istandby_ipc_inteface_code.h"
2299552fe9Sopenharmony_ci#include "standby_service_subscriber_proxy.h"
2399552fe9Sopenharmony_ci#include "standby_service_errors.h"
2499552fe9Sopenharmony_ci#include "standby_service_log.h"
2599552fe9Sopenharmony_ci
2699552fe9Sopenharmony_cinamespace OHOS {
2799552fe9Sopenharmony_cinamespace DevStandbyMgr {
2899552fe9Sopenharmony_ciErrCode StandbyServiceStub::OnRemoteRequest(uint32_t code,
2999552fe9Sopenharmony_ci    MessageParcel& data, MessageParcel& reply, MessageOption& option)
3099552fe9Sopenharmony_ci{
3199552fe9Sopenharmony_ci    if (StandbyServiceStub::GetDescriptor() != data.ReadInterfaceToken()) {
3299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGE("StandbyServiceStub: Local descriptor not match remote.");
3399552fe9Sopenharmony_ci        return ERR_TRANSACTION_FAILED;
3499552fe9Sopenharmony_ci    }
3599552fe9Sopenharmony_ci
3699552fe9Sopenharmony_ci    switch (code) {
3799552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::SUBSCRIBE_STANDBY_CALLBACK):
3899552fe9Sopenharmony_ci            HandleSubscribeStandbyCallback(data, reply);
3999552fe9Sopenharmony_ci            break;
4099552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::UNSUBSCRIBE_STANDBY_CALLBACK):
4199552fe9Sopenharmony_ci            HandleUnsubscribeStandbyCallback(data, reply);
4299552fe9Sopenharmony_ci            break;
4399552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::APPLY_ALLOW_RESOURCE):
4499552fe9Sopenharmony_ci            HandleApplyAllowResource(data, reply);
4599552fe9Sopenharmony_ci            break;
4699552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::UNAPPLY_ALLOW_RESOURCE):
4799552fe9Sopenharmony_ci            HandleUnapplyAllowResource(data, reply);
4899552fe9Sopenharmony_ci            break;
4999552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::GET_ALLOW_LIST):
5099552fe9Sopenharmony_ci            HandleGetAllowList(data, reply);
5199552fe9Sopenharmony_ci            break;
5299552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::IS_DEVICE_IN_STANDBY):
5399552fe9Sopenharmony_ci            HandleIsDeviceInStandby(data, reply);
5499552fe9Sopenharmony_ci            break;
5599552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::REPORT_WORK_SCHEDULER_STATUS):
5699552fe9Sopenharmony_ci            HandleReportWorkSchedulerStatus(data, reply);
5799552fe9Sopenharmony_ci            break;
5899552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::GET_RESTRICT_LIST):
5999552fe9Sopenharmony_ci            HandleGetRestrictList(data, reply);
6099552fe9Sopenharmony_ci            break;
6199552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::IS_STRATEGY_ENABLED):
6299552fe9Sopenharmony_ci            HandleIsStrategyEnabled(data, reply);
6399552fe9Sopenharmony_ci            break;
6499552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::REPORT_DEVICE_STATE_CHANGED):
6599552fe9Sopenharmony_ci            HandleReportDeviceStateChanged(data, reply);
6699552fe9Sopenharmony_ci            break;
6799552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::HANDLE_EVENT):
6899552fe9Sopenharmony_ci            HandleCommonEvent(data, reply);
6999552fe9Sopenharmony_ci            break;
7099552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::SET_NAT_INTERVAL):
7199552fe9Sopenharmony_ci            HandleSetNatInterval(data, reply);
7299552fe9Sopenharmony_ci            break;
7399552fe9Sopenharmony_ci        case static_cast<uint32_t>(IStandbyInterfaceCode::POWER_OVERUSED):
7499552fe9Sopenharmony_ci            HandleReportPowerOverused(data, reply);
7599552fe9Sopenharmony_ci            break;
7699552fe9Sopenharmony_ci        default:
7799552fe9Sopenharmony_ci            return IRemoteStub<IStandbyService>::OnRemoteRequest(code, data, reply, option);
7899552fe9Sopenharmony_ci    }
7999552fe9Sopenharmony_ci    return ERR_OK;
8099552fe9Sopenharmony_ci}
8199552fe9Sopenharmony_ci
8299552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleSubscribeStandbyCallback(MessageParcel& data, MessageParcel& reply)
8399552fe9Sopenharmony_ci{
8499552fe9Sopenharmony_ci    auto subscriber = iface_cast<IStandbyServiceSubscriber>(data.ReadRemoteObject());
8599552fe9Sopenharmony_ci    if (!subscriber) {
8699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleSubscribeStandbyCallback Read callback fail.");
8799552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
8899552fe9Sopenharmony_ci    }
8999552fe9Sopenharmony_ci    std::string strategyName = data.ReadString();
9099552fe9Sopenharmony_ci    std::string moduleName = data.ReadString();
9199552fe9Sopenharmony_ci
9299552fe9Sopenharmony_ci    STANDBYSERVICE_LOGD("HandleSubscribeStandbyCallback strategyName is %{public}s, moduleName is %{public}s.",
9399552fe9Sopenharmony_ci        strategyName.c_str(), moduleName.c_str());
9499552fe9Sopenharmony_ci    subscriber->SetSubscriberName(strategyName);
9599552fe9Sopenharmony_ci    subscriber->SetModuleName(moduleName);
9699552fe9Sopenharmony_ci
9799552fe9Sopenharmony_ci    ErrCode result = SubscribeStandbyCallback(subscriber);
9899552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
9999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleSubscribeStandbyCallback Write result failed, ErrCode=%{public}d", result);
10099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
10199552fe9Sopenharmony_ci    }
10299552fe9Sopenharmony_ci    return ERR_OK;
10399552fe9Sopenharmony_ci}
10499552fe9Sopenharmony_ci
10599552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleReportWorkSchedulerStatus(MessageParcel& data, MessageParcel& reply)
10699552fe9Sopenharmony_ci{
10799552fe9Sopenharmony_ci    bool started {false};
10899552fe9Sopenharmony_ci    int32_t uid {0};
10999552fe9Sopenharmony_ci    std::string bundleName {""};
11099552fe9Sopenharmony_ci    if (!data.ReadBool(started) || !data.ReadInt32(uid) || !data.ReadString(bundleName)) {
11199552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleReportWorkSchedulerStatus ReadParcelable failed");
11299552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
11399552fe9Sopenharmony_ci    }
11499552fe9Sopenharmony_ci    ErrCode result = ReportWorkSchedulerStatus(started, uid, bundleName);
11599552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
11699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleReportWorkSchedulerStatus Write result failed, ErrCode=%{public}d", result);
11799552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
11899552fe9Sopenharmony_ci    }
11999552fe9Sopenharmony_ci    return ERR_OK;
12099552fe9Sopenharmony_ci}
12199552fe9Sopenharmony_ci
12299552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleGetRestrictList(MessageParcel& data, MessageParcel& reply)
12399552fe9Sopenharmony_ci{
12499552fe9Sopenharmony_ci    uint32_t restrictType {0};
12599552fe9Sopenharmony_ci    uint32_t reasonCode {0};
12699552fe9Sopenharmony_ci    if (!data.ReadUint32(restrictType) || !data.ReadUint32(reasonCode)) {
12799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleGetRestrictList ReadParcelable failed");
12899552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
12999552fe9Sopenharmony_ci    }
13099552fe9Sopenharmony_ci    std::vector<AllowInfo> restrictInfoList {};
13199552fe9Sopenharmony_ci    ErrCode result = GetRestrictList(restrictType, restrictInfoList, reasonCode);
13299552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
13399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleGetRestrictList Write result failed, ErrCode=%{public}d", result);
13499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
13599552fe9Sopenharmony_ci    }
13699552fe9Sopenharmony_ci    if (!reply.WriteUint32(restrictInfoList.size())) {
13799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleGetRestrictList Write result size failed");
13899552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
13999552fe9Sopenharmony_ci    }
14099552fe9Sopenharmony_ci    for (auto& info : restrictInfoList) {
14199552fe9Sopenharmony_ci        if (!info.Marshalling(reply)) {
14299552fe9Sopenharmony_ci            return ERR_STANDBY_PARCELABLE_FAILED;
14399552fe9Sopenharmony_ci        }
14499552fe9Sopenharmony_ci    }
14599552fe9Sopenharmony_ci    return ERR_OK;
14699552fe9Sopenharmony_ci}
14799552fe9Sopenharmony_ci
14899552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleIsStrategyEnabled(MessageParcel& data, MessageParcel& reply)
14999552fe9Sopenharmony_ci{
15099552fe9Sopenharmony_ci    bool enabled {false};
15199552fe9Sopenharmony_ci    std::string strategyName {""};
15299552fe9Sopenharmony_ci    if (!data.ReadString(strategyName)) {
15399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleIsStrategyEnabled ReadParcelable failed");
15499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
15599552fe9Sopenharmony_ci    }
15699552fe9Sopenharmony_ci    ErrCode result = IsDeviceInStandby(enabled);
15799552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
15899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleIsStrategyEnabled Write result failed, ErrCode=%{public}d", result);
15999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
16099552fe9Sopenharmony_ci    }
16199552fe9Sopenharmony_ci    if (!reply.WriteBool(enabled)) {
16299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleIsStrategyEnabled Write enabled failed");
16399552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
16499552fe9Sopenharmony_ci    }
16599552fe9Sopenharmony_ci    return ERR_OK;
16699552fe9Sopenharmony_ci}
16799552fe9Sopenharmony_ci
16899552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleUnsubscribeStandbyCallback(MessageParcel& data, MessageParcel& reply)
16999552fe9Sopenharmony_ci{
17099552fe9Sopenharmony_ci    sptr<IRemoteObject> subscriber = data.ReadRemoteObject();
17199552fe9Sopenharmony_ci    if (subscriber == nullptr) {
17299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleUnsubscribeStandbyCallback Read callback fail.");
17399552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
17499552fe9Sopenharmony_ci    }
17599552fe9Sopenharmony_ci
17699552fe9Sopenharmony_ci    ErrCode result = UnsubscribeStandbyCallback(iface_cast<IStandbyServiceSubscriber>(subscriber));
17799552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
17899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleUnsubscribeStandbyCallback Write result failed, ErrCode=%{public}d", result);
17999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
18099552fe9Sopenharmony_ci    }
18199552fe9Sopenharmony_ci    return ERR_OK;
18299552fe9Sopenharmony_ci}
18399552fe9Sopenharmony_ci
18499552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleApplyAllowResource(MessageParcel& data, MessageParcel& reply)
18599552fe9Sopenharmony_ci{
18699552fe9Sopenharmony_ci    auto resourceRequest = ResourceRequest::Unmarshalling(data);
18799552fe9Sopenharmony_ci    if (resourceRequest == nullptr) {
18899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleApplyAllowResource ReadParcelable failed");
18999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
19099552fe9Sopenharmony_ci    }
19199552fe9Sopenharmony_ci    ErrCode result = ApplyAllowResource(resourceRequest);
19299552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
19399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleApplyAllowResource Write result failed, ErrCode=%{public}d", result);
19499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
19599552fe9Sopenharmony_ci    }
19699552fe9Sopenharmony_ci    return ERR_OK;
19799552fe9Sopenharmony_ci}
19899552fe9Sopenharmony_ci
19999552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleUnapplyAllowResource(MessageParcel& data, MessageParcel& reply)
20099552fe9Sopenharmony_ci{
20199552fe9Sopenharmony_ci    auto resourceRequest = ResourceRequest::Unmarshalling(data);
20299552fe9Sopenharmony_ci    if (resourceRequest == nullptr) {
20399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleUnapplyAllowResource ReadParcelable failed");
20499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
20599552fe9Sopenharmony_ci    }
20699552fe9Sopenharmony_ci    ErrCode result = UnapplyAllowResource(resourceRequest);
20799552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
20899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleUnapplyAllowResource Write result failed, ErrCode=%{public}d", result);
20999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
21099552fe9Sopenharmony_ci    }
21199552fe9Sopenharmony_ci    return ERR_OK;
21299552fe9Sopenharmony_ci}
21399552fe9Sopenharmony_ci
21499552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleGetAllowList(MessageParcel& data, MessageParcel& reply)
21599552fe9Sopenharmony_ci{
21699552fe9Sopenharmony_ci    uint32_t allowType {0};
21799552fe9Sopenharmony_ci    uint32_t reasonCode {0};
21899552fe9Sopenharmony_ci    if (!data.ReadUint32(allowType) || !data.ReadUint32(reasonCode)) {
21999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleGetAllowList ReadParcelable failed");
22099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
22199552fe9Sopenharmony_ci    }
22299552fe9Sopenharmony_ci    std::vector<AllowInfo> allowInfoList {};
22399552fe9Sopenharmony_ci    ErrCode result = GetAllowList(allowType, allowInfoList, reasonCode);
22499552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
22599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleGetAllowList Write result failed, ErrCode=%{public}d", result);
22699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
22799552fe9Sopenharmony_ci    }
22899552fe9Sopenharmony_ci    if (!reply.WriteUint32(allowInfoList.size())) {
22999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleGetAllowList Write result size failed");
23099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
23199552fe9Sopenharmony_ci    }
23299552fe9Sopenharmony_ci    for (auto& info : allowInfoList) {
23399552fe9Sopenharmony_ci        if (!info.Marshalling(reply)) {
23499552fe9Sopenharmony_ci            return ERR_STANDBY_PARCELABLE_FAILED;
23599552fe9Sopenharmony_ci        }
23699552fe9Sopenharmony_ci    }
23799552fe9Sopenharmony_ci    return ERR_OK;
23899552fe9Sopenharmony_ci}
23999552fe9Sopenharmony_ci
24099552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleIsDeviceInStandby(MessageParcel& data, MessageParcel& reply)
24199552fe9Sopenharmony_ci{
24299552fe9Sopenharmony_ci    bool isStandby {false};
24399552fe9Sopenharmony_ci    ErrCode result = IsDeviceInStandby(isStandby);
24499552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
24599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleIsDeviceInStandby Write result failed, ErrCode=%{public}d", result);
24699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
24799552fe9Sopenharmony_ci    }
24899552fe9Sopenharmony_ci    if (!reply.WriteBool(isStandby)) {
24999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleIsDeviceInStandby Write isStandby failed");
25099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
25199552fe9Sopenharmony_ci    }
25299552fe9Sopenharmony_ci    return ERR_OK;
25399552fe9Sopenharmony_ci}
25499552fe9Sopenharmony_ci
25599552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleSetNatInterval(MessageParcel& data, MessageParcel& reply)
25699552fe9Sopenharmony_ci{
25799552fe9Sopenharmony_ci    uint32_t type {0};
25899552fe9Sopenharmony_ci    bool enable {false};
25999552fe9Sopenharmony_ci    uint32_t interval {0};
26099552fe9Sopenharmony_ci    if (!data.ReadUint32(type) || !data.ReadBool(enable) || !data.ReadUint32(interval)) {
26199552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleSetNatInterval ReadParcelable failed");
26299552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
26399552fe9Sopenharmony_ci    }
26499552fe9Sopenharmony_ci    ErrCode result = SetNatInterval(type, enable, interval);
26599552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
26699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleSetNatInterval Write result failed, ErrCode=%{public}d", result);
26799552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
26899552fe9Sopenharmony_ci    }
26999552fe9Sopenharmony_ci    return ERR_OK;
27099552fe9Sopenharmony_ci}
27199552fe9Sopenharmony_ci
27299552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleReportPowerOverused(MessageParcel& data, MessageParcel& reply)
27399552fe9Sopenharmony_ci{
27499552fe9Sopenharmony_ci    std::string module{""};
27599552fe9Sopenharmony_ci    uint32_t level{0};
27699552fe9Sopenharmony_ci
27799552fe9Sopenharmony_ci    if (!data.ReadString(module) || !data.ReadUint32(level)) {
27899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleReportPowerOverused ReadParcelable failed");
27999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
28099552fe9Sopenharmony_ci    }
28199552fe9Sopenharmony_ci    ErrCode result = ReportPowerOverused(module, level);
28299552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
28399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleReportPowerOverused Write result failed, ErrCode=%{public}d", result);
28499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
28599552fe9Sopenharmony_ci    }
28699552fe9Sopenharmony_ci
28799552fe9Sopenharmony_ci    return ERR_OK;
28899552fe9Sopenharmony_ci}
28999552fe9Sopenharmony_ci
29099552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleReportDeviceStateChanged(MessageParcel& data, MessageParcel& reply)
29199552fe9Sopenharmony_ci{
29299552fe9Sopenharmony_ci    int32_t type {0};
29399552fe9Sopenharmony_ci    bool enable {false};
29499552fe9Sopenharmony_ci    if (!data.ReadInt32(type) || !data.ReadBool(enable)) {
29599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleReportDeviceStateChanged ReadParcelable failed");
29699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
29799552fe9Sopenharmony_ci    }
29899552fe9Sopenharmony_ci    ErrCode result = ReportDeviceStateChanged(static_cast<DeviceStateType>(type), enable);
29999552fe9Sopenharmony_ci    if (!reply.WriteInt32(result)) {
30099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleReportDeviceStateChanged Write result failed, ErrCode=%{public}d", result);
30199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
30299552fe9Sopenharmony_ci    }
30399552fe9Sopenharmony_ci    return ERR_OK;
30499552fe9Sopenharmony_ci}
30599552fe9Sopenharmony_ci
30699552fe9Sopenharmony_ciErrCode StandbyServiceStub::HandleCommonEvent(MessageParcel& data, MessageParcel& reply)
30799552fe9Sopenharmony_ci{
30899552fe9Sopenharmony_ci    uint32_t resType = 0;
30999552fe9Sopenharmony_ci    if (!data.ReadUint32(resType)) {
31099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("Failed to read resType");
31199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
31299552fe9Sopenharmony_ci    }
31399552fe9Sopenharmony_ci    int64_t value = 0;
31499552fe9Sopenharmony_ci    if (!data.ReadInt64(value)) {
31599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("Failed to read value");
31699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
31799552fe9Sopenharmony_ci    }
31899552fe9Sopenharmony_ci    std::string sceneInfo = "";
31999552fe9Sopenharmony_ci    if (!data.ReadString(sceneInfo)) {
32099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("Failed to read sceneInfo");
32199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
32299552fe9Sopenharmony_ci    }
32399552fe9Sopenharmony_ci    return HandleEvent(resType, value, sceneInfo);
32499552fe9Sopenharmony_ci}
32599552fe9Sopenharmony_ci}  // namespace DevStandbyMgr
32699552fe9Sopenharmony_ci}  // namespace OHOS