122736c2fSopenharmony_ci/*
222736c2fSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
422736c2fSopenharmony_ci * you may not use this file except in compliance with the License.
522736c2fSopenharmony_ci * You may obtain a copy of the License at
622736c2fSopenharmony_ci *
722736c2fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
822736c2fSopenharmony_ci *
922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and
1322736c2fSopenharmony_ci * limitations under the License.
1422736c2fSopenharmony_ci */
1522736c2fSopenharmony_ci
1622736c2fSopenharmony_ci#include "input_method_system_ability_stub.h"
1722736c2fSopenharmony_ci
1822736c2fSopenharmony_ci#include <chrono>
1922736c2fSopenharmony_ci#include <cinttypes>
2022736c2fSopenharmony_ci#include <memory>
2122736c2fSopenharmony_ci
2222736c2fSopenharmony_ci#include "element_name.h"
2322736c2fSopenharmony_ci#include "input_client_proxy.h"
2422736c2fSopenharmony_ci#include "input_method_core_proxy.h"
2522736c2fSopenharmony_ci#include "ipc_skeleton.h"
2622736c2fSopenharmony_ci#include "itypes_util.h"
2722736c2fSopenharmony_ci#include "xcollie/xcollie.h"
2822736c2fSopenharmony_ci#include "xcollie/xcollie_define.h"
2922736c2fSopenharmony_cinamespace OHOS {
3022736c2fSopenharmony_cinamespace MiscServices {
3122736c2fSopenharmony_ciusing namespace std::chrono;
3222736c2fSopenharmony_ciusing namespace HiviewDFX;
3322736c2fSopenharmony_ciconstexpr uint32_t FATAL_TIMEOUT = 30;    // 30s
3422736c2fSopenharmony_ciconstexpr int64_t WARNING_TIMEOUT = 5000; // 5s
3522736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
3622736c2fSopenharmony_ci    MessageOption &option)
3722736c2fSopenharmony_ci{
3822736c2fSopenharmony_ci    if (code != static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT)) {
3922736c2fSopenharmony_ci        IMSA_HILOGI("IMSA, code = %{public}u, callingPid/Uid/timestamp: %{public}d/%{public}d/%{public}lld", code,
4022736c2fSopenharmony_ci            IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid(),
4122736c2fSopenharmony_ci            std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
4222736c2fSopenharmony_ci                .count());
4322736c2fSopenharmony_ci    }
4422736c2fSopenharmony_ci    std::u16string remoteDescriptor = data.ReadInterfaceToken();
4522736c2fSopenharmony_ci    if (remoteDescriptor != IInputMethodSystemAbility::GetDescriptor()) {
4622736c2fSopenharmony_ci        IMSA_HILOGE("%{public}s descriptor failed!", __func__);
4722736c2fSopenharmony_ci        return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
4822736c2fSopenharmony_ci    }
4922736c2fSopenharmony_ci    if (code >= static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_BEGIN) &&
5022736c2fSopenharmony_ci        code < static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_END)) {
5122736c2fSopenharmony_ci        // service reboot when timeout 30s
5222736c2fSopenharmony_ci        auto id = XCollie::GetInstance().SetTimer("IMSA_API[" + std::to_string(code) + "]", FATAL_TIMEOUT, nullptr,
5322736c2fSopenharmony_ci            nullptr, XCOLLIE_FLAG_DEFAULT);
5422736c2fSopenharmony_ci        int64_t startPoint = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
5522736c2fSopenharmony_ci        auto ret = (this->*HANDLERS[code])(data, reply);
5622736c2fSopenharmony_ci        int64_t costTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() - startPoint;
5722736c2fSopenharmony_ci        // log warning when timeout 5s
5822736c2fSopenharmony_ci        if (costTime > WARNING_TIMEOUT) {
5922736c2fSopenharmony_ci            IMSA_HILOGW("code: %{public}d, pid: %{public}d, uid: %{public}d, cost: %{public}" PRId64 "", code,
6022736c2fSopenharmony_ci                IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid(), costTime);
6122736c2fSopenharmony_ci        }
6222736c2fSopenharmony_ci        XCollie::GetInstance().CancelTimer(id);
6322736c2fSopenharmony_ci        return ret;
6422736c2fSopenharmony_ci    } else {
6522736c2fSopenharmony_ci        IMSA_HILOGE("code error, code = %{public}u, callingPid: %{public}d, callingUid: %{public}d.", code,
6622736c2fSopenharmony_ci            IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
6722736c2fSopenharmony_ci        return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
6822736c2fSopenharmony_ci    }
6922736c2fSopenharmony_ci}
7022736c2fSopenharmony_ci
7122736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply)
7222736c2fSopenharmony_ci{
7322736c2fSopenharmony_ci    InputClientInfo clientInfo;
7422736c2fSopenharmony_ci    sptr<IRemoteObject> client = nullptr;
7522736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, clientInfo, client, clientInfo.channel)) {
7622736c2fSopenharmony_ci        IMSA_HILOGE("read clientInfo failed!");
7722736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
7822736c2fSopenharmony_ci    }
7922736c2fSopenharmony_ci    clientInfo.client = iface_cast<IInputClient>(client);
8022736c2fSopenharmony_ci    sptr<IRemoteObject> agent = nullptr;
8122736c2fSopenharmony_ci    int32_t ret = StartInput(clientInfo, agent);
8222736c2fSopenharmony_ci    return reply.WriteInt32(ret) && reply.WriteRemoteObject(agent) ? ErrorCode::NO_ERROR
8322736c2fSopenharmony_ci                                                                   : ErrorCode::ERROR_EX_PARCELABLE;
8422736c2fSopenharmony_ci}
8522736c2fSopenharmony_ci
8622736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
8722736c2fSopenharmony_ci{
8822736c2fSopenharmony_ci    int32_t ret = ShowCurrentInput();
8922736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
9022736c2fSopenharmony_ci}
9122736c2fSopenharmony_ci
9222736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
9322736c2fSopenharmony_ci{
9422736c2fSopenharmony_ci    int32_t ret = HideCurrentInput();
9522736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
9622736c2fSopenharmony_ci}
9722736c2fSopenharmony_ci
9822736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::StopInputSessionOnRemote(MessageParcel &data, MessageParcel &reply)
9922736c2fSopenharmony_ci{
10022736c2fSopenharmony_ci    int32_t ret = StopInputSession();
10122736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
10222736c2fSopenharmony_ci}
10322736c2fSopenharmony_ci
10422736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ShowInputOnRemote(MessageParcel &data, MessageParcel &reply)
10522736c2fSopenharmony_ci{
10622736c2fSopenharmony_ci    auto clientObject = data.ReadRemoteObject();
10722736c2fSopenharmony_ci    if (clientObject == nullptr) {
10822736c2fSopenharmony_ci        IMSA_HILOGE("clientObject is nullptr!");
10922736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
11022736c2fSopenharmony_ci    }
11122736c2fSopenharmony_ci    int32_t ret = ShowInput(iface_cast<IInputClient>(clientObject));
11222736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
11322736c2fSopenharmony_ci}
11422736c2fSopenharmony_ci
11522736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::HideInputOnRemote(MessageParcel &data, MessageParcel &reply)
11622736c2fSopenharmony_ci{
11722736c2fSopenharmony_ci    auto clientObject = data.ReadRemoteObject();
11822736c2fSopenharmony_ci    if (clientObject == nullptr) {
11922736c2fSopenharmony_ci        IMSA_HILOGE("clientObject is nullptr!");
12022736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
12122736c2fSopenharmony_ci    }
12222736c2fSopenharmony_ci    int32_t ret = HideInput(iface_cast<IInputClient>(clientObject));
12322736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
12422736c2fSopenharmony_ci}
12522736c2fSopenharmony_ci
12622736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ReleaseInputOnRemote(MessageParcel &data, MessageParcel &reply)
12722736c2fSopenharmony_ci{
12822736c2fSopenharmony_ci    auto clientObject = data.ReadRemoteObject();
12922736c2fSopenharmony_ci    if (clientObject == nullptr) {
13022736c2fSopenharmony_ci        IMSA_HILOGE("clientObject is nullptr!");
13122736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
13222736c2fSopenharmony_ci    }
13322736c2fSopenharmony_ci    int32_t ret = ReleaseInput(iface_cast<IInputClient>(clientObject));
13422736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
13522736c2fSopenharmony_ci}
13622736c2fSopenharmony_ci
13722736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::RequestShowInputOnRemote(MessageParcel &data, MessageParcel &reply)
13822736c2fSopenharmony_ci{
13922736c2fSopenharmony_ci    return reply.WriteInt32(RequestShowInput()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
14022736c2fSopenharmony_ci}
14122736c2fSopenharmony_ci
14222736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::RequestHideInputOnRemote(MessageParcel &data, MessageParcel &reply)
14322736c2fSopenharmony_ci{
14422736c2fSopenharmony_ci    return reply.WriteInt32(RequestHideInput()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
14522736c2fSopenharmony_ci}
14622736c2fSopenharmony_ci
14722736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::DisplayOptionalInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
14822736c2fSopenharmony_ci{
14922736c2fSopenharmony_ci    int32_t ret = DisplayOptionalInputMethod();
15022736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
15122736c2fSopenharmony_ci}
15222736c2fSopenharmony_ci
15322736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::SetCoreAndAgentOnRemote(MessageParcel &data, MessageParcel &reply)
15422736c2fSopenharmony_ci{
15522736c2fSopenharmony_ci    auto coreObject = data.ReadRemoteObject();
15622736c2fSopenharmony_ci    if (coreObject == nullptr) {
15722736c2fSopenharmony_ci        IMSA_HILOGE("coreObject is nullptr!");
15822736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
15922736c2fSopenharmony_ci    }
16022736c2fSopenharmony_ci    auto agentObject = data.ReadRemoteObject();
16122736c2fSopenharmony_ci    if (agentObject == nullptr) {
16222736c2fSopenharmony_ci        IMSA_HILOGE("agentObject is nullptr!");
16322736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
16422736c2fSopenharmony_ci    }
16522736c2fSopenharmony_ci    int32_t ret = SetCoreAndAgent(iface_cast<IInputMethodCore>(coreObject), agentObject);
16622736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
16722736c2fSopenharmony_ci}
16822736c2fSopenharmony_ci
16922736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::GetDefaultInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
17022736c2fSopenharmony_ci{
17122736c2fSopenharmony_ci    std::shared_ptr<Property> prop = std::make_shared<Property>();
17222736c2fSopenharmony_ci    bool isBrief = false;
17322736c2fSopenharmony_ci    auto ret = data.ReadBool(isBrief);
17422736c2fSopenharmony_ci    if (!ret) {
17522736c2fSopenharmony_ci        IMSA_HILOGE("read isBrief failed!");
17622736c2fSopenharmony_ci    }
17722736c2fSopenharmony_ci    ret = GetDefaultInputMethod(prop, isBrief);
17822736c2fSopenharmony_ci    if (prop == nullptr) {
17922736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
18022736c2fSopenharmony_ci    }
18122736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ret, *prop) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
18222736c2fSopenharmony_ci}
18322736c2fSopenharmony_ci
18422736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::IsDefaultImeSetOnRemote(MessageParcel &data, MessageParcel &reply)
18522736c2fSopenharmony_ci{
18622736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsDefaultImeSet()) ? ErrorCode::NO_ERROR
18722736c2fSopenharmony_ci                                                                           : ErrorCode::ERROR_EX_PARCELABLE;
18822736c2fSopenharmony_ci}
18922736c2fSopenharmony_ci
19022736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::EnableImeOnRemote(MessageParcel &data, MessageParcel &reply)
19122736c2fSopenharmony_ci{
19222736c2fSopenharmony_ci    std::string bundleName;
19322736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, bundleName)) {
19422736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
19522736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
19622736c2fSopenharmony_ci    }
19722736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, EnableIme(bundleName)) ? ErrorCode::NO_ERROR
19822736c2fSopenharmony_ci                                                                        : ErrorCode::ERROR_EX_PARCELABLE;
19922736c2fSopenharmony_ci}
20022736c2fSopenharmony_ci
20122736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::GetInputMethodConfigOnRemote(MessageParcel &data, MessageParcel &reply)
20222736c2fSopenharmony_ci{
20322736c2fSopenharmony_ci    OHOS::AppExecFwk::ElementName inputMethodConfig;
20422736c2fSopenharmony_ci    auto ret = GetInputMethodConfig(inputMethodConfig);
20522736c2fSopenharmony_ci    IMSA_HILOGD("GetInputMethodConfigOnRemote inputMethodConfig is %{public}s, %{public}s",
20622736c2fSopenharmony_ci        inputMethodConfig.GetBundleName().c_str(), inputMethodConfig.GetAbilityName().c_str());
20722736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ret, inputMethodConfig) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
20822736c2fSopenharmony_ci}
20922736c2fSopenharmony_ci
21022736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::GetSecurityModeOnRemote(MessageParcel &data, MessageParcel &reply)
21122736c2fSopenharmony_ci{
21222736c2fSopenharmony_ci    IMSA_HILOGD("GetSecurityModeOnRemote start.");
21322736c2fSopenharmony_ci    int32_t security;
21422736c2fSopenharmony_ci    auto ret = GetSecurityMode(security);
21522736c2fSopenharmony_ci    IMSA_HILOGD("GetSecurityModeOnRemote, security: %{public}d", security);
21622736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ret, security) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
21722736c2fSopenharmony_ci}
21822736c2fSopenharmony_ci
21922736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::GetCurrentInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
22022736c2fSopenharmony_ci{
22122736c2fSopenharmony_ci    auto property = GetCurrentInputMethod();
22222736c2fSopenharmony_ci    if (property == nullptr) {
22322736c2fSopenharmony_ci        IMSA_HILOGE("property is nullptr!");
22422736c2fSopenharmony_ci        return reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER) ? ErrorCode::NO_ERROR
22522736c2fSopenharmony_ci                                                                  : ErrorCode::ERROR_EX_PARCELABLE;
22622736c2fSopenharmony_ci    }
22722736c2fSopenharmony_ci    if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property)) {
22822736c2fSopenharmony_ci        IMSA_HILOGE("marshal failed!");
22922736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
23022736c2fSopenharmony_ci    }
23122736c2fSopenharmony_ci    return ErrorCode::NO_ERROR;
23222736c2fSopenharmony_ci}
23322736c2fSopenharmony_ci
23422736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::GetCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
23522736c2fSopenharmony_ci{
23622736c2fSopenharmony_ci    auto property = GetCurrentInputMethodSubtype();
23722736c2fSopenharmony_ci    if (property == nullptr) {
23822736c2fSopenharmony_ci        IMSA_HILOGE("property is nullptr!");
23922736c2fSopenharmony_ci        return reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER) ? ErrorCode::NO_ERROR
24022736c2fSopenharmony_ci                                                                  : ErrorCode::ERROR_EX_PARCELABLE;
24122736c2fSopenharmony_ci    }
24222736c2fSopenharmony_ci    if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property)) {
24322736c2fSopenharmony_ci        IMSA_HILOGE("marshal failed!");
24422736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
24522736c2fSopenharmony_ci    }
24622736c2fSopenharmony_ci    return ErrorCode::NO_ERROR;
24722736c2fSopenharmony_ci}
24822736c2fSopenharmony_ci
24922736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ListInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
25022736c2fSopenharmony_ci{
25122736c2fSopenharmony_ci    uint32_t status;
25222736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, status)) {
25322736c2fSopenharmony_ci        IMSA_HILOGE("read status failed!");
25422736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
25522736c2fSopenharmony_ci    }
25622736c2fSopenharmony_ci    std::vector<Property> properties = {};
25722736c2fSopenharmony_ci    auto ret = ListInputMethod(InputMethodStatus(status), properties);
25822736c2fSopenharmony_ci    if (!ITypesUtil::Marshal(reply, ret, properties)) {
25922736c2fSopenharmony_ci        IMSA_HILOGE("marshal failed!");
26022736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
26122736c2fSopenharmony_ci    }
26222736c2fSopenharmony_ci    return ErrorCode::NO_ERROR;
26322736c2fSopenharmony_ci}
26422736c2fSopenharmony_ci
26522736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ListInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
26622736c2fSopenharmony_ci{
26722736c2fSopenharmony_ci    std::string bundleName;
26822736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, bundleName)) {
26922736c2fSopenharmony_ci        IMSA_HILOGE("read bundleName failed!");
27022736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
27122736c2fSopenharmony_ci    }
27222736c2fSopenharmony_ci    std::vector<SubProperty> subProps = {};
27322736c2fSopenharmony_ci    auto ret = ListInputMethodSubtype(bundleName, subProps);
27422736c2fSopenharmony_ci    if (!ITypesUtil::Marshal(reply, ret, subProps)) {
27522736c2fSopenharmony_ci        IMSA_HILOGE("marshal failed!");
27622736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
27722736c2fSopenharmony_ci    }
27822736c2fSopenharmony_ci    return ErrorCode::NO_ERROR;
27922736c2fSopenharmony_ci}
28022736c2fSopenharmony_ci
28122736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ListCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
28222736c2fSopenharmony_ci{
28322736c2fSopenharmony_ci    std::vector<SubProperty> subProps = {};
28422736c2fSopenharmony_ci    auto ret = ListCurrentInputMethodSubtype(subProps);
28522736c2fSopenharmony_ci    if (!ITypesUtil::Marshal(reply, ret, subProps)) {
28622736c2fSopenharmony_ci        IMSA_HILOGE("marshal failed!");
28722736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
28822736c2fSopenharmony_ci    }
28922736c2fSopenharmony_ci    return ErrorCode::NO_ERROR;
29022736c2fSopenharmony_ci}
29122736c2fSopenharmony_ci
29222736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::SwitchInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
29322736c2fSopenharmony_ci{
29422736c2fSopenharmony_ci    std::string name;
29522736c2fSopenharmony_ci    std::string subName;
29622736c2fSopenharmony_ci    SwitchTrigger trigger;
29722736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, name, subName, trigger)) {
29822736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
29922736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
30022736c2fSopenharmony_ci    }
30122736c2fSopenharmony_ci    return reply.WriteInt32(SwitchInputMethod(name, subName, trigger)) ? ErrorCode::NO_ERROR
30222736c2fSopenharmony_ci                                                                       : ErrorCode::ERROR_EX_PARCELABLE;
30322736c2fSopenharmony_ci}
30422736c2fSopenharmony_ci
30522736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::PanelStatusChangeOnRemote(MessageParcel &data, MessageParcel &reply)
30622736c2fSopenharmony_ci{
30722736c2fSopenharmony_ci    uint32_t status = 0;
30822736c2fSopenharmony_ci    ImeWindowInfo info;
30922736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, status, info)) {
31022736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
31122736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
31222736c2fSopenharmony_ci    }
31322736c2fSopenharmony_ci    int32_t ret = PanelStatusChange(static_cast<InputWindowStatus>(status), info);
31422736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
31522736c2fSopenharmony_ci}
31622736c2fSopenharmony_ci
31722736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::UpdateListenEventFlagOnRemote(MessageParcel &data, MessageParcel &reply)
31822736c2fSopenharmony_ci{
31922736c2fSopenharmony_ci    InputClientInfo clientInfo;
32022736c2fSopenharmony_ci    sptr<IRemoteObject> client = nullptr;
32122736c2fSopenharmony_ci    uint32_t eventFlag = 0;
32222736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, clientInfo, client, clientInfo.channel, eventFlag)) {
32322736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
32422736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
32522736c2fSopenharmony_ci    }
32622736c2fSopenharmony_ci    clientInfo.client = iface_cast<IInputClient>(client);
32722736c2fSopenharmony_ci    int32_t ret = UpdateListenEventFlag(clientInfo, eventFlag);
32822736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
32922736c2fSopenharmony_ci}
33022736c2fSopenharmony_ci
33122736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
33222736c2fSopenharmony_ci{
33322736c2fSopenharmony_ci    int32_t ret = ShowCurrentInputDeprecated();
33422736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
33522736c2fSopenharmony_ci}
33622736c2fSopenharmony_ci
33722736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
33822736c2fSopenharmony_ci{
33922736c2fSopenharmony_ci    int32_t ret = HideCurrentInputDeprecated();
34022736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
34122736c2fSopenharmony_ci}
34222736c2fSopenharmony_ci
34322736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::IsCurrentImeOnRemote(MessageParcel &data, MessageParcel &reply)
34422736c2fSopenharmony_ci{
34522736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsCurrentIme()) ? ErrorCode::NO_ERROR
34622736c2fSopenharmony_ci                                                                           : ErrorCode::ERROR_EX_PARCELABLE;
34722736c2fSopenharmony_ci}
34822736c2fSopenharmony_ci
34922736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::UnRegisteredProxyImeOnRemote(MessageParcel &data, MessageParcel &reply)
35022736c2fSopenharmony_ci{
35122736c2fSopenharmony_ci    int32_t type = -1;
35222736c2fSopenharmony_ci    sptr<IRemoteObject> coreObject = nullptr;
35322736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, type, coreObject) || coreObject == nullptr) {
35422736c2fSopenharmony_ci        IMSA_HILOGE("coreObject is nullptr!");
35522736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
35622736c2fSopenharmony_ci    }
35722736c2fSopenharmony_ci    int32_t ret = UnRegisteredProxyIme(static_cast<UnRegisteredType>(type), iface_cast<IInputMethodCore>(coreObject));
35822736c2fSopenharmony_ci    return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
35922736c2fSopenharmony_ci}
36022736c2fSopenharmony_ci
36122736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::IsInputTypeSupportedOnRemote(MessageParcel &data, MessageParcel &reply)
36222736c2fSopenharmony_ci{
36322736c2fSopenharmony_ci    InputType type;
36422736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, type)) {
36522736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
36622736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
36722736c2fSopenharmony_ci    }
36822736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsInputTypeSupported(type)) ? ErrorCode::NO_ERROR
36922736c2fSopenharmony_ci                                                                                       : ErrorCode::ERROR_EX_PARCELABLE;
37022736c2fSopenharmony_ci}
37122736c2fSopenharmony_ci
37222736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::StartInputTypeOnRemote(MessageParcel &data, MessageParcel &reply)
37322736c2fSopenharmony_ci{
37422736c2fSopenharmony_ci    InputType type;
37522736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, type)) {
37622736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
37722736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
37822736c2fSopenharmony_ci    }
37922736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, StartInputType(type)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
38022736c2fSopenharmony_ci}
38122736c2fSopenharmony_ci
38222736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ExitCurrentInputTypeOnRemote(MessageParcel &data, MessageParcel &reply)
38322736c2fSopenharmony_ci{
38422736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ExitCurrentInputType()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
38522736c2fSopenharmony_ci}
38622736c2fSopenharmony_ci
38722736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply)
38822736c2fSopenharmony_ci{
38922736c2fSopenharmony_ci    PanelInfo info;
39022736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, info)) {
39122736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
39222736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
39322736c2fSopenharmony_ci    }
39422736c2fSopenharmony_ci    bool isShown = false;
39522736c2fSopenharmony_ci    int32_t ret = IsPanelShown(info, isShown);
39622736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ret, isShown) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
39722736c2fSopenharmony_ci}
39822736c2fSopenharmony_ci
39922736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::IsDefaultImeOnRemote(MessageParcel &data, MessageParcel &reply)
40022736c2fSopenharmony_ci{
40122736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, IsDefaultIme()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
40222736c2fSopenharmony_ci}
40322736c2fSopenharmony_ci
40422736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::ConnectSystemCmdOnRemote(MessageParcel &data, MessageParcel &reply)
40522736c2fSopenharmony_ci{
40622736c2fSopenharmony_ci    auto systemCmdStub = data.ReadRemoteObject();
40722736c2fSopenharmony_ci    if (systemCmdStub == nullptr) {
40822736c2fSopenharmony_ci        IMSA_HILOGE("systemCmdStub is nullptr!");
40922736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
41022736c2fSopenharmony_ci    }
41122736c2fSopenharmony_ci    sptr<IRemoteObject> agent = nullptr;
41222736c2fSopenharmony_ci    int32_t ret = ConnectSystemCmd(systemCmdStub, agent);
41322736c2fSopenharmony_ci    return reply.WriteInt32(ret) && reply.WriteRemoteObject(agent) ? ErrorCode::NO_ERROR
41422736c2fSopenharmony_ci                                                                   : ErrorCode::ERROR_EX_PARCELABLE;
41522736c2fSopenharmony_ci}
41622736c2fSopenharmony_ci
41722736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::IsCurrentImeByPidOnRemote(MessageParcel &data, MessageParcel &reply)
41822736c2fSopenharmony_ci{
41922736c2fSopenharmony_ci    int32_t pid = -1;
42022736c2fSopenharmony_ci    if (!ITypesUtil::Unmarshal(data, pid)) {
42122736c2fSopenharmony_ci        IMSA_HILOGE("unmarshal failed!");
42222736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_PARCELABLE;
42322736c2fSopenharmony_ci    }
42422736c2fSopenharmony_ci    return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsCurrentImeByPid(pid)) ? ErrorCode::NO_ERROR
42522736c2fSopenharmony_ci                                                                           : ErrorCode::ERROR_EX_PARCELABLE;
42622736c2fSopenharmony_ci}
42722736c2fSopenharmony_ci
42822736c2fSopenharmony_ciint32_t InputMethodSystemAbilityStub::InitConnectOnRemote(MessageParcel &data, MessageParcel &reply)
42922736c2fSopenharmony_ci{
43022736c2fSopenharmony_ci    return reply.WriteInt32(InitConnect()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
43122736c2fSopenharmony_ci}
43222736c2fSopenharmony_ci} // namespace MiscServices
43322736c2fSopenharmony_ci} // namespace OHOS