15ba71b47Sopenharmony_ci/*
25ba71b47Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
35ba71b47Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45ba71b47Sopenharmony_ci * you may not use this file except in compliance with the License.
55ba71b47Sopenharmony_ci * You may obtain a copy of the License at
65ba71b47Sopenharmony_ci *
75ba71b47Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85ba71b47Sopenharmony_ci *
95ba71b47Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105ba71b47Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115ba71b47Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125ba71b47Sopenharmony_ci * See the License for the specific language governing permissions and
135ba71b47Sopenharmony_ci * limitations under the License.
145ba71b47Sopenharmony_ci */
155ba71b47Sopenharmony_ci
165ba71b47Sopenharmony_ci#include "local_ability_manager_proxy.h"
175ba71b47Sopenharmony_ci
185ba71b47Sopenharmony_ci#include "ipc_types.h"
195ba71b47Sopenharmony_ci#include "iremote_object.h"
205ba71b47Sopenharmony_ci#include "message_option.h"
215ba71b47Sopenharmony_ci#include "message_parcel.h"
225ba71b47Sopenharmony_ci#include "nlohmann/json.hpp"
235ba71b47Sopenharmony_ci#include "refbase.h"
245ba71b47Sopenharmony_ci
255ba71b47Sopenharmony_ciusing namespace std;
265ba71b47Sopenharmony_ciusing namespace OHOS::HiviewDFX;
275ba71b47Sopenharmony_ci
285ba71b47Sopenharmony_cinamespace OHOS {
295ba71b47Sopenharmony_ci#undef LOG_DOMAIN
305ba71b47Sopenharmony_ci#define LOG_DOMAIN 0xD001800
315ba71b47Sopenharmony_ci#undef LOG_TAG
325ba71b47Sopenharmony_ci#define LOG_TAG "SA"
335ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::StartAbility(int32_t systemAbilityId, const std::string& eventStr)
345ba71b47Sopenharmony_ci{
355ba71b47Sopenharmony_ci    HILOG_INFO(LOG_CORE, "StartAbility proxy SA:%{public}d", systemAbilityId);
365ba71b47Sopenharmony_ci    if (systemAbilityId <= 0) {
375ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StartAbility systemAbilityId invalid.");
385ba71b47Sopenharmony_ci        return false;
395ba71b47Sopenharmony_ci    }
405ba71b47Sopenharmony_ci
415ba71b47Sopenharmony_ci    if (eventStr.empty()) {
425ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StartAbility eventStr invalid.");
435ba71b47Sopenharmony_ci        return false;
445ba71b47Sopenharmony_ci    }
455ba71b47Sopenharmony_ci
465ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
475ba71b47Sopenharmony_ci    if (iro == nullptr) {
485ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "StartAbility Remote return null");
495ba71b47Sopenharmony_ci        return false;
505ba71b47Sopenharmony_ci    }
515ba71b47Sopenharmony_ci
525ba71b47Sopenharmony_ci    MessageParcel data;
535ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
545ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StartAbility interface token check failed");
555ba71b47Sopenharmony_ci        return false;
565ba71b47Sopenharmony_ci    }
575ba71b47Sopenharmony_ci    bool ret = data.WriteInt32(systemAbilityId);
585ba71b47Sopenharmony_ci    if (!ret) {
595ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StartAbility write systemAbilityId failed!");
605ba71b47Sopenharmony_ci        return false;
615ba71b47Sopenharmony_ci    }
625ba71b47Sopenharmony_ci    ret = data.WriteString(eventStr);
635ba71b47Sopenharmony_ci    if (!ret) {
645ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StartAbility write eventStr failed!");
655ba71b47Sopenharmony_ci        return false;
665ba71b47Sopenharmony_ci    }
675ba71b47Sopenharmony_ci    MessageParcel reply;
685ba71b47Sopenharmony_ci    MessageOption option(MessageOption::TF_ASYNC);
695ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
705ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::START_ABILITY_TRANSACTION), data, reply, option);
715ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
725ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "StartAbility SendRequest failed, return value : %{public}d", status);
735ba71b47Sopenharmony_ci        return false;
745ba71b47Sopenharmony_ci    }
755ba71b47Sopenharmony_ci    HILOG_INFO(LOG_CORE, "StartAbility SendRequest suc, SA:%{public}d, pid:%{public}d", systemAbilityId, getpid());
765ba71b47Sopenharmony_ci    return true;
775ba71b47Sopenharmony_ci}
785ba71b47Sopenharmony_ci
795ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::StopAbility(int32_t systemAbilityId, const std::string& eventStr)
805ba71b47Sopenharmony_ci{
815ba71b47Sopenharmony_ci    if (systemAbilityId <= 0) {
825ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StopAbility systemAbilityId invalid.");
835ba71b47Sopenharmony_ci        return false;
845ba71b47Sopenharmony_ci    }
855ba71b47Sopenharmony_ci
865ba71b47Sopenharmony_ci    if (eventStr.empty()) {
875ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StartAbility eventStr invalid.");
885ba71b47Sopenharmony_ci        return false;
895ba71b47Sopenharmony_ci    }
905ba71b47Sopenharmony_ci
915ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
925ba71b47Sopenharmony_ci    if (iro == nullptr) {
935ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "StopAbility Remote return null");
945ba71b47Sopenharmony_ci        return false;
955ba71b47Sopenharmony_ci    }
965ba71b47Sopenharmony_ci
975ba71b47Sopenharmony_ci    MessageParcel data;
985ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
995ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StopAbility interface token check failed");
1005ba71b47Sopenharmony_ci        return false;
1015ba71b47Sopenharmony_ci    }
1025ba71b47Sopenharmony_ci    bool ret = data.WriteInt32(systemAbilityId);
1035ba71b47Sopenharmony_ci    if (!ret) {
1045ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StopAbility write systemAbilityId failed!");
1055ba71b47Sopenharmony_ci        return false;
1065ba71b47Sopenharmony_ci    }
1075ba71b47Sopenharmony_ci    ret = data.WriteString(eventStr);
1085ba71b47Sopenharmony_ci    if (!ret) {
1095ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "StopAbility write eventStr failed!");
1105ba71b47Sopenharmony_ci        return false;
1115ba71b47Sopenharmony_ci    }
1125ba71b47Sopenharmony_ci    MessageParcel reply;
1135ba71b47Sopenharmony_ci    MessageOption option(MessageOption::TF_ASYNC);
1145ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
1155ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::STOP_ABILITY_TRANSACTION), data, reply, option);
1165ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
1175ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "StopAbility SendRequest failed, return value : %{public}d", status);
1185ba71b47Sopenharmony_ci        return false;
1195ba71b47Sopenharmony_ci    }
1205ba71b47Sopenharmony_ci    return true;
1215ba71b47Sopenharmony_ci}
1225ba71b47Sopenharmony_ci
1235ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::ActiveAbility(int32_t systemAbilityId,
1245ba71b47Sopenharmony_ci    const nlohmann::json& activeReason)
1255ba71b47Sopenharmony_ci{
1265ba71b47Sopenharmony_ci    if (systemAbilityId <= 0) {
1275ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "ActiveAbility systemAbilityId invalid.");
1285ba71b47Sopenharmony_ci        return false;
1295ba71b47Sopenharmony_ci    }
1305ba71b47Sopenharmony_ci
1315ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
1325ba71b47Sopenharmony_ci    if (iro == nullptr) {
1335ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "ActiveAbility Remote return null");
1345ba71b47Sopenharmony_ci        return false;
1355ba71b47Sopenharmony_ci    }
1365ba71b47Sopenharmony_ci
1375ba71b47Sopenharmony_ci    MessageParcel data;
1385ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
1395ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "ActiveAbility interface token check failed");
1405ba71b47Sopenharmony_ci        return false;
1415ba71b47Sopenharmony_ci    }
1425ba71b47Sopenharmony_ci    if (!data.WriteInt32(systemAbilityId)) {
1435ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "ActiveAbility write systemAbilityId failed!");
1445ba71b47Sopenharmony_ci        return false;
1455ba71b47Sopenharmony_ci    }
1465ba71b47Sopenharmony_ci    if (!data.WriteString(activeReason.dump())) {
1475ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "ActiveAbility write activeReason failed!");
1485ba71b47Sopenharmony_ci        return false;
1495ba71b47Sopenharmony_ci    }
1505ba71b47Sopenharmony_ci
1515ba71b47Sopenharmony_ci    MessageParcel reply;
1525ba71b47Sopenharmony_ci    MessageOption option;
1535ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
1545ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::ACTIVE_ABILITY_TRANSACTION), data, reply, option);
1555ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
1565ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "ActiveAbility SendRequest failed, return value : %{public}d", status);
1575ba71b47Sopenharmony_ci        return false;
1585ba71b47Sopenharmony_ci    }
1595ba71b47Sopenharmony_ci    bool result = false;
1605ba71b47Sopenharmony_ci    if (!reply.ReadBool(result)) {
1615ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "ActiveAbility read result failed!");
1625ba71b47Sopenharmony_ci        return false;
1635ba71b47Sopenharmony_ci    }
1645ba71b47Sopenharmony_ci    return result;
1655ba71b47Sopenharmony_ci}
1665ba71b47Sopenharmony_ci
1675ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::IdleAbility(int32_t systemAbilityId,
1685ba71b47Sopenharmony_ci    const nlohmann::json& idleReason, int32_t& delayTime)
1695ba71b47Sopenharmony_ci{
1705ba71b47Sopenharmony_ci    if (systemAbilityId <= 0) {
1715ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IdleAbility systemAbilityId invalid.");
1725ba71b47Sopenharmony_ci        return false;
1735ba71b47Sopenharmony_ci    }
1745ba71b47Sopenharmony_ci
1755ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
1765ba71b47Sopenharmony_ci    if (iro == nullptr) {
1775ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "IdleAbility Remote return null");
1785ba71b47Sopenharmony_ci        return false;
1795ba71b47Sopenharmony_ci    }
1805ba71b47Sopenharmony_ci
1815ba71b47Sopenharmony_ci    MessageParcel data;
1825ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
1835ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IdleAbility interface token check failed");
1845ba71b47Sopenharmony_ci        return false;
1855ba71b47Sopenharmony_ci    }
1865ba71b47Sopenharmony_ci    if (!data.WriteInt32(systemAbilityId)) {
1875ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IdleAbility write systemAbilityId failed!");
1885ba71b47Sopenharmony_ci        return false;
1895ba71b47Sopenharmony_ci    }
1905ba71b47Sopenharmony_ci    if (!data.WriteString(idleReason.dump())) {
1915ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IdleAbility write ildeReason failed!");
1925ba71b47Sopenharmony_ci        return false;
1935ba71b47Sopenharmony_ci    }
1945ba71b47Sopenharmony_ci
1955ba71b47Sopenharmony_ci    MessageParcel reply;
1965ba71b47Sopenharmony_ci    MessageOption option;
1975ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
1985ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::IDLE_ABILITY_TRANSACTION), data, reply, option);
1995ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
2005ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "IdleAbility SendRequest failed, return value : %{public}d", status);
2015ba71b47Sopenharmony_ci        return false;
2025ba71b47Sopenharmony_ci    }
2035ba71b47Sopenharmony_ci    bool result = false;
2045ba71b47Sopenharmony_ci    if (!reply.ReadBool(result)) {
2055ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IdleAbility read result failed!");
2065ba71b47Sopenharmony_ci        return false;
2075ba71b47Sopenharmony_ci    }
2085ba71b47Sopenharmony_ci    if (!reply.ReadInt32(delayTime)) {
2095ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IdleAbility read delayTime failed!");
2105ba71b47Sopenharmony_ci        return false;
2115ba71b47Sopenharmony_ci    }
2125ba71b47Sopenharmony_ci    return result;
2135ba71b47Sopenharmony_ci}
2145ba71b47Sopenharmony_ci
2155ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::SendStrategyToSA(int32_t type, int32_t systemAbilityId,
2165ba71b47Sopenharmony_ci    int32_t level, std::string& action)
2175ba71b47Sopenharmony_ci{
2185ba71b47Sopenharmony_ci    if (systemAbilityId <= 0) {
2195ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SendStrategy systemAbilityId invalid.");
2205ba71b47Sopenharmony_ci        return false;
2215ba71b47Sopenharmony_ci    }
2225ba71b47Sopenharmony_ci
2235ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
2245ba71b47Sopenharmony_ci    if (iro == nullptr) {
2255ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "SendStrategy Remote return null");
2265ba71b47Sopenharmony_ci        return false;
2275ba71b47Sopenharmony_ci    }
2285ba71b47Sopenharmony_ci
2295ba71b47Sopenharmony_ci    MessageParcel data;
2305ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
2315ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SendStrategy interface token check failed");
2325ba71b47Sopenharmony_ci        return false;
2335ba71b47Sopenharmony_ci    }
2345ba71b47Sopenharmony_ci    bool ret = data.WriteInt32(type);
2355ba71b47Sopenharmony_ci    if (!ret) {
2365ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SendStrategy write type failed!");
2375ba71b47Sopenharmony_ci        return false;
2385ba71b47Sopenharmony_ci    }
2395ba71b47Sopenharmony_ci    ret = data.WriteInt32(systemAbilityId);
2405ba71b47Sopenharmony_ci    if (!ret) {
2415ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SendStrategy write systemAbilityId failed!");
2425ba71b47Sopenharmony_ci        return false;
2435ba71b47Sopenharmony_ci    }
2445ba71b47Sopenharmony_ci    ret = data.WriteInt32(level);
2455ba71b47Sopenharmony_ci    if (!ret) {
2465ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SendStrategy write level failed!");
2475ba71b47Sopenharmony_ci        return false;
2485ba71b47Sopenharmony_ci    }
2495ba71b47Sopenharmony_ci    ret = data.WriteString(action);
2505ba71b47Sopenharmony_ci    if (!ret) {
2515ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SendStrategy write action failed!");
2525ba71b47Sopenharmony_ci        return false;
2535ba71b47Sopenharmony_ci    }
2545ba71b47Sopenharmony_ci
2555ba71b47Sopenharmony_ci    MessageParcel reply;
2565ba71b47Sopenharmony_ci    MessageOption option(MessageOption::TF_ASYNC);
2575ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
2585ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::SEND_STRATEGY_TO_SA_TRANSACTION), data, reply, option);
2595ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
2605ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "SendStrategy SendRequest failed, return value : %{public}d", status);
2615ba71b47Sopenharmony_ci        return false;
2625ba71b47Sopenharmony_ci    }
2635ba71b47Sopenharmony_ci    return true;
2645ba71b47Sopenharmony_ci}
2655ba71b47Sopenharmony_ci
2665ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::IpcStatCmdProc(int32_t fd, int32_t cmd)
2675ba71b47Sopenharmony_ci{
2685ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
2695ba71b47Sopenharmony_ci    if (iro == nullptr) {
2705ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "IpcStatCmdProc Remote null");
2715ba71b47Sopenharmony_ci        return false;
2725ba71b47Sopenharmony_ci    }
2735ba71b47Sopenharmony_ci
2745ba71b47Sopenharmony_ci    MessageParcel data;
2755ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
2765ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IpcStatCmdProc interface token check failed");
2775ba71b47Sopenharmony_ci        return false;
2785ba71b47Sopenharmony_ci    }
2795ba71b47Sopenharmony_ci
2805ba71b47Sopenharmony_ci    if (!data.WriteFileDescriptor(fd)) {
2815ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IpcStatCmdProc write fd failed");
2825ba71b47Sopenharmony_ci        return false;
2835ba71b47Sopenharmony_ci    }
2845ba71b47Sopenharmony_ci
2855ba71b47Sopenharmony_ci    if (!data.WriteInt32(cmd)) {
2865ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IpcStatCmdProc write cmd faild");
2875ba71b47Sopenharmony_ci        return false;
2885ba71b47Sopenharmony_ci    }
2895ba71b47Sopenharmony_ci
2905ba71b47Sopenharmony_ci    MessageParcel reply;
2915ba71b47Sopenharmony_ci    MessageOption option;
2925ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
2935ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::IPC_STAT_CMD_TRANSACTION), data, reply, option);
2945ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
2955ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "IpcStatCmdProc SendRequest failed, return value : %{public}d", status);
2965ba71b47Sopenharmony_ci        return false;
2975ba71b47Sopenharmony_ci    }
2985ba71b47Sopenharmony_ci
2995ba71b47Sopenharmony_ci    bool result = false;
3005ba71b47Sopenharmony_ci    if (!reply.ReadBool(result)) {
3015ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "IpcStatCmdProc read bool faild");
3025ba71b47Sopenharmony_ci        return false;
3035ba71b47Sopenharmony_ci    }
3045ba71b47Sopenharmony_ci
3055ba71b47Sopenharmony_ci    return result;
3065ba71b47Sopenharmony_ci}
3075ba71b47Sopenharmony_ci
3085ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::FfrtDumperProc(std::string& ffrtDumperInfo)
3095ba71b47Sopenharmony_ci{
3105ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
3115ba71b47Sopenharmony_ci    if (iro == nullptr) {
3125ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "FfrtDumperProc Remote null");
3135ba71b47Sopenharmony_ci        return false;
3145ba71b47Sopenharmony_ci    }
3155ba71b47Sopenharmony_ci
3165ba71b47Sopenharmony_ci    MessageParcel data;
3175ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
3185ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "FfrtDumperProc write interface token failed");
3195ba71b47Sopenharmony_ci        return false;
3205ba71b47Sopenharmony_ci    }
3215ba71b47Sopenharmony_ci
3225ba71b47Sopenharmony_ci    MessageParcel reply;
3235ba71b47Sopenharmony_ci    MessageOption option;
3245ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
3255ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::FFRT_DUMPER_TRANSACTION), data, reply, option);
3265ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
3275ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "FfrtDumperProc SendRequest failed, return value : %{public}d", status);
3285ba71b47Sopenharmony_ci        return false;
3295ba71b47Sopenharmony_ci    }
3305ba71b47Sopenharmony_ci    if (!reply.ReadString(ffrtDumperInfo)) {
3315ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "FfrtDumperProc read ffrtDumperInfo failed!");
3325ba71b47Sopenharmony_ci        return false;
3335ba71b47Sopenharmony_ci    }
3345ba71b47Sopenharmony_ci    return true;
3355ba71b47Sopenharmony_ci}
3365ba71b47Sopenharmony_ci
3375ba71b47Sopenharmony_ciint32_t LocalAbilityManagerProxy::SystemAbilityExtProc(const std::string& extension, int32_t said,
3385ba71b47Sopenharmony_ci    SystemAbilityExtensionPara* callback, bool isAsync)
3395ba71b47Sopenharmony_ci{
3405ba71b47Sopenharmony_ci    if (said <= 0) {
3415ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SystemAbilityExtProc systemAbilityId invalid.");
3425ba71b47Sopenharmony_ci        return INVALID_DATA;
3435ba71b47Sopenharmony_ci    }
3445ba71b47Sopenharmony_ci
3455ba71b47Sopenharmony_ci    if (extension.empty()) {
3465ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SystemAbilityExtProc extension invalid.");
3475ba71b47Sopenharmony_ci        return INVALID_DATA;
3485ba71b47Sopenharmony_ci    }
3495ba71b47Sopenharmony_ci
3505ba71b47Sopenharmony_ci    sptr<IRemoteObject> iro = Remote();
3515ba71b47Sopenharmony_ci    if (iro == nullptr) {
3525ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "SystemAbilityExtProc Remote return null");
3535ba71b47Sopenharmony_ci        return OBJECT_NULL;
3545ba71b47Sopenharmony_ci    }
3555ba71b47Sopenharmony_ci
3565ba71b47Sopenharmony_ci    MessageParcel data;
3575ba71b47Sopenharmony_ci    if (!PrepareData(data, said, extension)) {
3585ba71b47Sopenharmony_ci        return INVALID_DATA;
3595ba71b47Sopenharmony_ci    }
3605ba71b47Sopenharmony_ci
3615ba71b47Sopenharmony_ci    if (callback != nullptr && !callback->InputParaSet(data)) {
3625ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SystemAbilityExtProc InputParaSet failed!");
3635ba71b47Sopenharmony_ci        return INVALID_DATA;
3645ba71b47Sopenharmony_ci    }
3655ba71b47Sopenharmony_ci
3665ba71b47Sopenharmony_ci    MessageParcel reply;
3675ba71b47Sopenharmony_ci    MessageOption option;
3685ba71b47Sopenharmony_ci    if (isAsync) {
3695ba71b47Sopenharmony_ci        option.SetFlags(MessageOption::TF_ASYNC);
3705ba71b47Sopenharmony_ci    }
3715ba71b47Sopenharmony_ci
3725ba71b47Sopenharmony_ci    int32_t status = iro->SendRequest(
3735ba71b47Sopenharmony_ci        static_cast<uint32_t>(SafwkInterfaceCode::SYSTEM_ABILITY_EXT_TRANSACTION), data, reply, option);
3745ba71b47Sopenharmony_ci    if (status != NO_ERROR) {
3755ba71b47Sopenharmony_ci        HILOG_ERROR(LOG_CORE, "SystemAbilityExtProc SendRequest failed, return value : %{public}d", status);
3765ba71b47Sopenharmony_ci        return status;
3775ba71b47Sopenharmony_ci    }
3785ba71b47Sopenharmony_ci
3795ba71b47Sopenharmony_ci    if ((!isAsync) && callback != nullptr && !callback->OutputParaGet(reply)) {
3805ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SystemAbilityExtProc OutputParaGet failed!");
3815ba71b47Sopenharmony_ci        return INVALID_DATA;
3825ba71b47Sopenharmony_ci    }
3835ba71b47Sopenharmony_ci    return NO_ERROR;
3845ba71b47Sopenharmony_ci}
3855ba71b47Sopenharmony_ci
3865ba71b47Sopenharmony_cibool LocalAbilityManagerProxy::PrepareData(MessageParcel& data, int32_t said, const std::string& extension)
3875ba71b47Sopenharmony_ci{
3885ba71b47Sopenharmony_ci    if (!data.WriteInterfaceToken(LOCAL_ABILITY_MANAGER_INTERFACE_TOKEN)) {
3895ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SystemAbilityExtProc interface token check failed");
3905ba71b47Sopenharmony_ci        return false;
3915ba71b47Sopenharmony_ci    }
3925ba71b47Sopenharmony_ci
3935ba71b47Sopenharmony_ci    if (!data.WriteInt32(said)) {
3945ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SystemAbilityExtProc write said failed!");
3955ba71b47Sopenharmony_ci        return false;
3965ba71b47Sopenharmony_ci    }
3975ba71b47Sopenharmony_ci
3985ba71b47Sopenharmony_ci    if (!data.WriteString(extension)) {
3995ba71b47Sopenharmony_ci        HILOG_WARN(LOG_CORE, "SystemAbilityExtProc write extension failed!");
4005ba71b47Sopenharmony_ci        return false;
4015ba71b47Sopenharmony_ci    }
4025ba71b47Sopenharmony_ci    return true;
4035ba71b47Sopenharmony_ci}
4045ba71b47Sopenharmony_ci}
405