199552fe9Sopenharmony_ci/*
299552fe9Sopenharmony_ci * Copyright (c) 2023 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_proxy.h"
1799552fe9Sopenharmony_ci
1899552fe9Sopenharmony_ci#include <message_parcel.h>
1999552fe9Sopenharmony_ci
2099552fe9Sopenharmony_ci#include "standby_service_errors.h"
2199552fe9Sopenharmony_ci#include "standby_service_log.h"
2299552fe9Sopenharmony_ci#include "istandby_ipc_inteface_code.h"
2399552fe9Sopenharmony_ci
2499552fe9Sopenharmony_cinamespace OHOS {
2599552fe9Sopenharmony_cinamespace DevStandbyMgr {
2699552fe9Sopenharmony_ciStandbyServiceProxy::StandbyServiceProxy(const sptr<IRemoteObject>& impl)
2799552fe9Sopenharmony_ci    :IRemoteProxy<IStandbyService>(impl) {}
2899552fe9Sopenharmony_ciStandbyServiceProxy::~StandbyServiceProxy() {}
2999552fe9Sopenharmony_ci
3099552fe9Sopenharmony_ciErrCode StandbyServiceProxy::SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber)
3199552fe9Sopenharmony_ci{
3299552fe9Sopenharmony_ci    if (subscriber == nullptr) {
3399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent subscriber is null");
3499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
3599552fe9Sopenharmony_ci    }
3699552fe9Sopenharmony_ci
3799552fe9Sopenharmony_ci    MessageParcel data;
3899552fe9Sopenharmony_ci    MessageParcel reply;
3999552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
4099552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
4199552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent write descriptor failed");
4299552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
4399552fe9Sopenharmony_ci    }
4499552fe9Sopenharmony_ci    if (!data.WriteRemoteObject(subscriber->AsObject())) {
4599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent write subscriber failed");
4699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
4799552fe9Sopenharmony_ci    }
4899552fe9Sopenharmony_ci    if (!data.WriteString(subscriber->GetSubscriberName())) {
4999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent write SubscriberName failed");
5099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
5199552fe9Sopenharmony_ci    }
5299552fe9Sopenharmony_ci    if (!data.WriteString(subscriber->GetModuleName())) {
5399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent write ModuleName failed");
5499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
5599552fe9Sopenharmony_ci    }
5699552fe9Sopenharmony_ci
5799552fe9Sopenharmony_ci    ErrCode result = InnerTransact(
5899552fe9Sopenharmony_ci        static_cast<uint32_t>(IStandbyInterfaceCode::SUBSCRIBE_STANDBY_CALLBACK), option, data, reply);
5999552fe9Sopenharmony_ci    if (result != ERR_OK) {
6099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent fail: transact ErrCode=%{public}d", result);
6199552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
6299552fe9Sopenharmony_ci    }
6399552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
6499552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent fail: read result failed");
6599552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
6699552fe9Sopenharmony_ci    }
6799552fe9Sopenharmony_ci    if (result != ERR_OK) {
6899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SubscribeSleepStateEvent failed");
6999552fe9Sopenharmony_ci    }
7099552fe9Sopenharmony_ci    return result;
7199552fe9Sopenharmony_ci}
7299552fe9Sopenharmony_ci
7399552fe9Sopenharmony_ciErrCode StandbyServiceProxy::UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber)
7499552fe9Sopenharmony_ci{
7599552fe9Sopenharmony_ci    if (subscriber == nullptr) {
7699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("UnsubscribeSleepStateEvent subscriber is null");
7799552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
7899552fe9Sopenharmony_ci    }
7999552fe9Sopenharmony_ci
8099552fe9Sopenharmony_ci    MessageParcel data;
8199552fe9Sopenharmony_ci    MessageParcel reply;
8299552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
8399552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
8499552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("UnsubscribeSleepStateEvent write descriptor failed");
8599552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
8699552fe9Sopenharmony_ci    }
8799552fe9Sopenharmony_ci    if (!data.WriteRemoteObject(subscriber->AsObject())) {
8899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("UnsubscribeSleepStateEvent write subscriber failed");
8999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
9099552fe9Sopenharmony_ci    }
9199552fe9Sopenharmony_ci
9299552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::UNSUBSCRIBE_STANDBY_CALLBACK),
9399552fe9Sopenharmony_ci        option, data, reply);
9499552fe9Sopenharmony_ci    if (result != ERR_OK) {
9599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("UnsubscribeSleepStateEvent fail: transact ErrCode=%{public}d", result);
9699552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
9799552fe9Sopenharmony_ci    }
9899552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
9999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("UnsubscribeSleepStateEvent fail: read result failed");
10099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
10199552fe9Sopenharmony_ci    }
10299552fe9Sopenharmony_ci    if (result != ERR_OK) {
10399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("UnsubscribeSleepStateEvent failed");
10499552fe9Sopenharmony_ci        return result;
10599552fe9Sopenharmony_ci    }
10699552fe9Sopenharmony_ci    return result;
10799552fe9Sopenharmony_ci}
10899552fe9Sopenharmony_ci
10999552fe9Sopenharmony_ciErrCode StandbyServiceProxy::ApplyAllowResource(const sptr<ResourceRequest>& resourceRequest)
11099552fe9Sopenharmony_ci{
11199552fe9Sopenharmony_ci    MessageParcel data;
11299552fe9Sopenharmony_ci    MessageParcel reply;
11399552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
11499552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
11599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ApplyAllowResource write descriptor failed");
11699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
11799552fe9Sopenharmony_ci    }
11899552fe9Sopenharmony_ci    if (!resourceRequest->Marshalling(data)) {
11999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ApplyAllowResource write parameter failed");
12099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
12199552fe9Sopenharmony_ci    }
12299552fe9Sopenharmony_ci
12399552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::APPLY_ALLOW_RESOURCE),
12499552fe9Sopenharmony_ci        option, data, reply);
12599552fe9Sopenharmony_ci    if (result != ERR_OK) {
12699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ApplyAllowResource fail: transact ErrCode=%{public}d", result);
12799552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
12899552fe9Sopenharmony_ci    }
12999552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
13099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ApplyAllowResource fail: read result failed");
13199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
13299552fe9Sopenharmony_ci    }
13399552fe9Sopenharmony_ci    if (result != ERR_OK) {
13499552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ApplyAllowResource failed");
13599552fe9Sopenharmony_ci        return result;
13699552fe9Sopenharmony_ci    }
13799552fe9Sopenharmony_ci    return result;
13899552fe9Sopenharmony_ci}
13999552fe9Sopenharmony_ci
14099552fe9Sopenharmony_ciErrCode StandbyServiceProxy::UnapplyAllowResource(const sptr<ResourceRequest>& resourceRequest)
14199552fe9Sopenharmony_ci{
14299552fe9Sopenharmony_ci    MessageParcel data;
14399552fe9Sopenharmony_ci    MessageParcel reply;
14499552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
14599552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
14699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("RemoveAllowList write descriptor failed");
14799552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
14899552fe9Sopenharmony_ci    }
14999552fe9Sopenharmony_ci    if (!resourceRequest->Marshalling(data)) {
15099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("RemoveAllowList write parameter failed");
15199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
15299552fe9Sopenharmony_ci    }
15399552fe9Sopenharmony_ci
15499552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::UNAPPLY_ALLOW_RESOURCE),
15599552fe9Sopenharmony_ci        option, data, reply);
15699552fe9Sopenharmony_ci    if (result != ERR_OK) {
15799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("RemoveAllowList fail: transact ErrCode=%{public}d", result);
15899552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
15999552fe9Sopenharmony_ci    }
16099552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
16199552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("RemoveAllowList fail: read result failed");
16299552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
16399552fe9Sopenharmony_ci    }
16499552fe9Sopenharmony_ci    if (result != ERR_OK) {
16599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("RemoveAllowList failed");
16699552fe9Sopenharmony_ci        return result;
16799552fe9Sopenharmony_ci    }
16899552fe9Sopenharmony_ci    return result;
16999552fe9Sopenharmony_ci}
17099552fe9Sopenharmony_ci
17199552fe9Sopenharmony_ciErrCode StandbyServiceProxy::GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList,
17299552fe9Sopenharmony_ci    uint32_t reasonCode)
17399552fe9Sopenharmony_ci{
17499552fe9Sopenharmony_ci    MessageParcel data;
17599552fe9Sopenharmony_ci    MessageParcel reply;
17699552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
17799552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
17899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetAllowList write descriptor failed");
17999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
18099552fe9Sopenharmony_ci    }
18199552fe9Sopenharmony_ci    if (!data.WriteUint32(allowType) || !data.WriteUint32(reasonCode)) {
18299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetAllowList write parameter failed");
18399552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
18499552fe9Sopenharmony_ci    }
18599552fe9Sopenharmony_ci
18699552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::GET_ALLOW_LIST),
18799552fe9Sopenharmony_ci        option, data, reply);
18899552fe9Sopenharmony_ci    if (result != ERR_OK) {
18999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetAllowList fail: transact ErrCode=%{public}d", result);
19099552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
19199552fe9Sopenharmony_ci    }
19299552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
19399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetAllowList fail: read result failed.");
19499552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
19599552fe9Sopenharmony_ci    }
19699552fe9Sopenharmony_ci    if (result != ERR_OK) {
19799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetAllowList failed");
19899552fe9Sopenharmony_ci        return result;
19999552fe9Sopenharmony_ci    }
20099552fe9Sopenharmony_ci    uint32_t infoSize = reply.ReadUint32();
20199552fe9Sopenharmony_ci    for (uint32_t i = 0; i < infoSize; i++) {
20299552fe9Sopenharmony_ci        auto info = AllowInfo::Unmarshalling(reply);
20399552fe9Sopenharmony_ci        if (info == nullptr) {
20499552fe9Sopenharmony_ci            STANDBYSERVICE_LOGW("GetAllowList Read Parcelable infos failed.");
20599552fe9Sopenharmony_ci            return ERR_STANDBY_PARCELABLE_FAILED;
20699552fe9Sopenharmony_ci        }
20799552fe9Sopenharmony_ci        allowInfoList.emplace_back(*info);
20899552fe9Sopenharmony_ci    }
20999552fe9Sopenharmony_ci
21099552fe9Sopenharmony_ci    return result;
21199552fe9Sopenharmony_ci}
21299552fe9Sopenharmony_ci
21399552fe9Sopenharmony_ciErrCode StandbyServiceProxy::IsDeviceInStandby(bool& isStandby)
21499552fe9Sopenharmony_ci{
21599552fe9Sopenharmony_ci    MessageParcel data;
21699552fe9Sopenharmony_ci    MessageParcel reply;
21799552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
21899552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
21999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby write descriptor failed");
22099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
22199552fe9Sopenharmony_ci    }
22299552fe9Sopenharmony_ci
22399552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::IS_DEVICE_IN_STANDBY),
22499552fe9Sopenharmony_ci        option, data, reply);
22599552fe9Sopenharmony_ci    if (result != ERR_OK) {
22699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby fail: transact ErrCode=%{public}d", result);
22799552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
22899552fe9Sopenharmony_ci    }
22999552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
23099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby fail: read result failed.");
23199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
23299552fe9Sopenharmony_ci    }
23399552fe9Sopenharmony_ci    if (result != ERR_OK) {
23499552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby failed");
23599552fe9Sopenharmony_ci        return result;
23699552fe9Sopenharmony_ci    }
23799552fe9Sopenharmony_ci    if (!reply.ReadBool(isStandby)) {
23899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby fail: read result failed.");
23999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
24099552fe9Sopenharmony_ci    }
24199552fe9Sopenharmony_ci    return result;
24299552fe9Sopenharmony_ci}
24399552fe9Sopenharmony_ci
24499552fe9Sopenharmony_ciErrCode StandbyServiceProxy::SetNatInterval(uint32_t& type, bool& enable, uint32_t& interval)
24599552fe9Sopenharmony_ci{
24699552fe9Sopenharmony_ci    MessageParcel data;
24799552fe9Sopenharmony_ci    MessageParcel reply;
24899552fe9Sopenharmony_ci    MessageOption option;
24999552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
25099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SetNatInterval write descriptor failed");
25199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
25299552fe9Sopenharmony_ci    }
25399552fe9Sopenharmony_ci
25499552fe9Sopenharmony_ci    if (!data.WriteUint32(type) || !data.WriteBool(enable) || !data.WriteUint32(interval)) {
25599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SetNatInterval write parameter failed");
25699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
25799552fe9Sopenharmony_ci    }
25899552fe9Sopenharmony_ci
25999552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::SET_NAT_INTERVAL),
26099552fe9Sopenharmony_ci        option, data, reply);
26199552fe9Sopenharmony_ci    if (result != ERR_OK) {
26299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SetNatInterval fail: transact ErrCode=%{public}d", result);
26399552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
26499552fe9Sopenharmony_ci    }
26599552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
26699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SetNatInterval fail: read result failed.");
26799552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
26899552fe9Sopenharmony_ci    }
26999552fe9Sopenharmony_ci    if (result != ERR_OK) {
27099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("SetNatInterval failed");
27199552fe9Sopenharmony_ci        return result;
27299552fe9Sopenharmony_ci    }
27399552fe9Sopenharmony_ci    return result;
27499552fe9Sopenharmony_ci}
27599552fe9Sopenharmony_ci
27699552fe9Sopenharmony_ciErrCode StandbyServiceProxy::ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName)
27799552fe9Sopenharmony_ci{
27899552fe9Sopenharmony_ci    MessageParcel data;
27999552fe9Sopenharmony_ci    MessageParcel reply;
28099552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
28199552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
28299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby write descriptor failed");
28399552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
28499552fe9Sopenharmony_ci    }
28599552fe9Sopenharmony_ci
28699552fe9Sopenharmony_ci    if (!data.WriteBool(started) || !data.WriteInt32(uid) || !data.WriteString(bundleName)) {
28799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus write parameter failed");
28899552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
28999552fe9Sopenharmony_ci    }
29099552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::REPORT_WORK_SCHEDULER_STATUS),
29199552fe9Sopenharmony_ci        option, data, reply);
29299552fe9Sopenharmony_ci    if (result != ERR_OK) {
29399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus fail: transact ErrCode=%{public}d", result);
29499552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
29599552fe9Sopenharmony_ci    }
29699552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
29799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus fail: read result failed.");
29899552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
29999552fe9Sopenharmony_ci    }
30099552fe9Sopenharmony_ci    if (result != ERR_OK) {
30199552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportWorkSchedulerStatus failed");
30299552fe9Sopenharmony_ci        return result;
30399552fe9Sopenharmony_ci    }
30499552fe9Sopenharmony_ci    return result;
30599552fe9Sopenharmony_ci}
30699552fe9Sopenharmony_ci
30799552fe9Sopenharmony_ciErrCode StandbyServiceProxy::GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList,
30899552fe9Sopenharmony_ci    uint32_t reasonCode)
30999552fe9Sopenharmony_ci{
31099552fe9Sopenharmony_ci    MessageParcel data;
31199552fe9Sopenharmony_ci    MessageParcel reply;
31299552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
31399552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
31499552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetRestrictList write descriptor failed");
31599552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
31699552fe9Sopenharmony_ci    }
31799552fe9Sopenharmony_ci    if (!data.WriteUint32(restrictType) || !data.WriteUint32(reasonCode)) {
31899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetRestrictList write parameter failed");
31999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
32099552fe9Sopenharmony_ci    }
32199552fe9Sopenharmony_ci
32299552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::GET_RESTRICT_LIST),
32399552fe9Sopenharmony_ci        option, data, reply);
32499552fe9Sopenharmony_ci    if (result != ERR_OK) {
32599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetRestrictList fail: transact ErrCode=%{public}d", result);
32699552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
32799552fe9Sopenharmony_ci    }
32899552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
32999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetRestrictList fail: read result failed.");
33099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
33199552fe9Sopenharmony_ci    }
33299552fe9Sopenharmony_ci    if (result != ERR_OK) {
33399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("GetRestrictList failed");
33499552fe9Sopenharmony_ci        return result;
33599552fe9Sopenharmony_ci    }
33699552fe9Sopenharmony_ci    uint32_t infoSize = reply.ReadUint32();
33799552fe9Sopenharmony_ci    for (uint32_t i = 0; i < infoSize; i++) {
33899552fe9Sopenharmony_ci        auto info = AllowInfo::Unmarshalling(reply);
33999552fe9Sopenharmony_ci        if (info == nullptr) {
34099552fe9Sopenharmony_ci            STANDBYSERVICE_LOGW("GetRestrictList Read Parcelable infos failed.");
34199552fe9Sopenharmony_ci            return ERR_STANDBY_PARCELABLE_FAILED;
34299552fe9Sopenharmony_ci        }
34399552fe9Sopenharmony_ci        restrictInfoList.emplace_back(*info);
34499552fe9Sopenharmony_ci    }
34599552fe9Sopenharmony_ci
34699552fe9Sopenharmony_ci    return result;
34799552fe9Sopenharmony_ci}
34899552fe9Sopenharmony_ci
34999552fe9Sopenharmony_ciErrCode StandbyServiceProxy::IsStrategyEnabled(const std::string& strategyName, bool& enabled)
35099552fe9Sopenharmony_ci{
35199552fe9Sopenharmony_ci    MessageParcel data;
35299552fe9Sopenharmony_ci    MessageParcel reply;
35399552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
35499552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
35599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsStrategyEnabled write descriptor failed");
35699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
35799552fe9Sopenharmony_ci    }
35899552fe9Sopenharmony_ci    if (!data.WriteString(strategyName)) {
35999552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsStrategyEnabled write parameter failed");
36099552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
36199552fe9Sopenharmony_ci    }
36299552fe9Sopenharmony_ci
36399552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::IS_STRATEGY_ENABLED),
36499552fe9Sopenharmony_ci        option, data, reply);
36599552fe9Sopenharmony_ci    if (result != ERR_OK) {
36699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsStrategyEnabled fail: transact ErrCode=%{public}d", result);
36799552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
36899552fe9Sopenharmony_ci    }
36999552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
37099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsStrategyEnabled fail: read result failed.");
37199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
37299552fe9Sopenharmony_ci    }
37399552fe9Sopenharmony_ci    if (result != ERR_OK) {
37499552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsStrategyEnabled failed");
37599552fe9Sopenharmony_ci        return result;
37699552fe9Sopenharmony_ci    }
37799552fe9Sopenharmony_ci    if (!reply.ReadBool(enabled)) {
37899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsStrategyEnabled fail: read result failed.");
37999552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
38099552fe9Sopenharmony_ci    }
38199552fe9Sopenharmony_ci    return result;
38299552fe9Sopenharmony_ci}
38399552fe9Sopenharmony_ci
38499552fe9Sopenharmony_ciErrCode StandbyServiceProxy::ReportPowerOverused(const std::string &module, uint32_t level)
38599552fe9Sopenharmony_ci{
38699552fe9Sopenharmony_ci    MessageParcel data;
38799552fe9Sopenharmony_ci    MessageParcel reply;
38899552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
38999552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
39099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby write descriptor failed");
39199552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
39299552fe9Sopenharmony_ci    }
39399552fe9Sopenharmony_ci
39499552fe9Sopenharmony_ci    if (!data.WriteString(module) || !data.WriteUint32(level)) {
39599552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportPowerOverused write parameter failed");
39699552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
39799552fe9Sopenharmony_ci    }
39899552fe9Sopenharmony_ci
39999552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::POWER_OVERUSED),
40099552fe9Sopenharmony_ci        option, data, reply);
40199552fe9Sopenharmony_ci    if (result != ERR_OK) {
40299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportPowerOverused fail: transact ErrCode=%{public}d", result);
40399552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
40499552fe9Sopenharmony_ci    }
40599552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
40699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportPowerOverused fail: read result failed.");
40799552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
40899552fe9Sopenharmony_ci    }
40999552fe9Sopenharmony_ci    if (result != ERR_OK) {
41099552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportPowerOverused failed");
41199552fe9Sopenharmony_ci        return result;
41299552fe9Sopenharmony_ci    }
41399552fe9Sopenharmony_ci    return result;
41499552fe9Sopenharmony_ci}
41599552fe9Sopenharmony_ci
41699552fe9Sopenharmony_ciErrCode StandbyServiceProxy::ReportDeviceStateChanged(DeviceStateType type, bool enabled)
41799552fe9Sopenharmony_ci{
41899552fe9Sopenharmony_ci    MessageParcel data;
41999552fe9Sopenharmony_ci    MessageParcel reply;
42099552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
42199552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
42299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("IsDeviceInStandby write descriptor failed");
42399552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
42499552fe9Sopenharmony_ci    }
42599552fe9Sopenharmony_ci
42699552fe9Sopenharmony_ci    if (!data.WriteInt32(static_cast<int32_t>(type)) || !data.WriteBool(enabled)) {
42799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportDeviceStateChanged write parameter failed");
42899552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
42999552fe9Sopenharmony_ci    }
43099552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::REPORT_DEVICE_STATE_CHANGED),
43199552fe9Sopenharmony_ci        option, data, reply);
43299552fe9Sopenharmony_ci    if (result != ERR_OK) {
43399552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportDeviceStateChanged fail: transact ErrCode=%{public}d", result);
43499552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
43599552fe9Sopenharmony_ci    }
43699552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
43799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportDeviceStateChanged fail: read result failed.");
43899552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
43999552fe9Sopenharmony_ci    }
44099552fe9Sopenharmony_ci    if (result != ERR_OK) {
44199552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportDeviceStateChanged failed");
44299552fe9Sopenharmony_ci        return result;
44399552fe9Sopenharmony_ci    }
44499552fe9Sopenharmony_ci    return result;
44599552fe9Sopenharmony_ci}
44699552fe9Sopenharmony_ci
44799552fe9Sopenharmony_ciErrCode StandbyServiceProxy::InnerTransact(uint32_t code, MessageOption& flags,
44899552fe9Sopenharmony_ci    MessageParcel& data, MessageParcel& reply)
44999552fe9Sopenharmony_ci{
45099552fe9Sopenharmony_ci    auto remote = Remote();
45199552fe9Sopenharmony_ci    if (remote == nullptr) {
45299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGE("InnerTransact get Remote fail code %{public}d", code);
45399552fe9Sopenharmony_ci        return ERR_DEAD_OBJECT;
45499552fe9Sopenharmony_ci    }
45599552fe9Sopenharmony_ci    int32_t err = remote->SendRequest(code, data, reply, flags);
45699552fe9Sopenharmony_ci    switch (err) {
45799552fe9Sopenharmony_ci        case NO_ERROR: {
45899552fe9Sopenharmony_ci            return ERR_OK;
45999552fe9Sopenharmony_ci        }
46099552fe9Sopenharmony_ci        case DEAD_OBJECT: {
46199552fe9Sopenharmony_ci            STANDBYSERVICE_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}u", err, code);
46299552fe9Sopenharmony_ci            return ERR_DEAD_OBJECT;
46399552fe9Sopenharmony_ci        }
46499552fe9Sopenharmony_ci        default: {
46599552fe9Sopenharmony_ci            STANDBYSERVICE_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}u", err, code);
46699552fe9Sopenharmony_ci            return ERR_STANDBY_TRANSACT_FAILED;
46799552fe9Sopenharmony_ci        }
46899552fe9Sopenharmony_ci    }
46999552fe9Sopenharmony_ci}
47099552fe9Sopenharmony_ci
47199552fe9Sopenharmony_ciErrCode StandbyServiceProxy::HandleEvent(const uint32_t resType, const int64_t value, const std::string &sceneInfo)
47299552fe9Sopenharmony_ci{
47399552fe9Sopenharmony_ci    MessageParcel data;
47499552fe9Sopenharmony_ci    MessageParcel reply;
47599552fe9Sopenharmony_ci    MessageOption option = {MessageOption::TF_SYNC};
47699552fe9Sopenharmony_ci    if (!data.WriteInterfaceToken(StandbyServiceProxy::GetDescriptor())) {
47799552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleEvent write descriptor failed");
47899552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
47999552fe9Sopenharmony_ci    }
48099552fe9Sopenharmony_ci
48199552fe9Sopenharmony_ci    if (!data.WriteUint32(resType) || !data.WriteInt64(value) || !data.WriteString(sceneInfo)) {
48299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("ReportDeviceStateChanged wirte parameter failed");
48399552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
48499552fe9Sopenharmony_ci    }
48599552fe9Sopenharmony_ci    ErrCode result = InnerTransact(static_cast<uint32_t>(IStandbyInterfaceCode::HANDLE_EVENT),
48699552fe9Sopenharmony_ci                                   option, data, reply);
48799552fe9Sopenharmony_ci    if (result != ERR_OK) {
48899552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleEvent fail: transact ErrCode=%{public}d", result);
48999552fe9Sopenharmony_ci        return ERR_STANDBY_TRANSACT_FAILED;
49099552fe9Sopenharmony_ci    }
49199552fe9Sopenharmony_ci    if (!reply.ReadInt32(result)) {
49299552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleEvent fail: read result dailed.");
49399552fe9Sopenharmony_ci        return ERR_STANDBY_PARCELABLE_FAILED;
49499552fe9Sopenharmony_ci    }
49599552fe9Sopenharmony_ci    if (result != ERR_OK) {
49699552fe9Sopenharmony_ci        STANDBYSERVICE_LOGW("HandleEvent failed");
49799552fe9Sopenharmony_ci        return result;
49899552fe9Sopenharmony_ci    }
49999552fe9Sopenharmony_ci    return result;
50099552fe9Sopenharmony_ci}
50199552fe9Sopenharmony_ci}  // namespace DevStandbyMgr
50299552fe9Sopenharmony_ci}  // namespace OHOS