• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "input_client_proxy.h"
17 
18 #include "global.h"
19 #include "itypes_util.h"
20 #include "message_option.h"
21 #include "message_parcel.h"
22 
23 namespace OHOS {
24 namespace MiscServices {
25 using namespace ErrorCode;
InputClientProxy(const sptr<IRemoteObject> & object)26 InputClientProxy::InputClientProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IInputClient>(object) { }
27 
OnInputReady(const sptr<IRemoteObject> & agent,const std::pair<int64_t,std::string> & imeInfo)28 int32_t InputClientProxy::OnInputReady(const sptr<IRemoteObject> &agent, const std::pair<int64_t, std::string> &imeInfo)
29 {
30     return SendRequest(ON_INPUT_READY, [agent, imeInfo](MessageParcel &data) {
31         auto ret = ITypesUtil::Marshal(data, agent);
32         ITypesUtil::Marshal(data, imeInfo.first, imeInfo.second);
33         return ret;
34     });
35 }
36 
OnInputStop(bool isStopInactiveClient,bool isAsync)37 int32_t InputClientProxy::OnInputStop(bool isStopInactiveClient, bool isAsync)
38 {
39     MessageOption option = isAsync ? MessageOption::TF_ASYNC : MessageOption::TF_SYNC;
40     return SendRequest(
41         ON_INPUT_STOP,
42         [isStopInactiveClient](MessageParcel &data) {
43             return ITypesUtil::Marshal(data, isStopInactiveClient);
44         },
45         nullptr, option);
46 }
47 
OnSwitchInput(const Property & property,const SubProperty & subProperty)48 int32_t InputClientProxy::OnSwitchInput(const Property &property, const SubProperty &subProperty)
49 {
50     return SendRequest(ON_SWITCH_INPUT, [&property, &subProperty](MessageParcel &data) {
51         return ITypesUtil::Marshal(data, property, subProperty);
52     });
53 }
54 
OnPanelStatusChange(const InputWindowStatus & status,const ImeWindowInfo & info)55 int32_t InputClientProxy::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
56 {
57     return SendRequest(ON_PANEL_STATUS_CHANGE, [&status, &info](MessageParcel &data) {
58         return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), info);
59     });
60 }
61 
NotifyInputStart(uint32_t callingWndId,int32_t requestKeyboardReason)62 int32_t InputClientProxy::NotifyInputStart(uint32_t callingWndId, int32_t requestKeyboardReason)
63 {
64     IMSA_HILOGD("InputClientProxy::NotifyInputStart");
65     return SendRequest(ON_NOTIFY_INPUT_START, [callingWndId, requestKeyboardReason](MessageParcel &data) {
66         return ITypesUtil::Marshal(data, callingWndId, requestKeyboardReason);
67     });
68 }
69 
NotifyInputStop()70 int32_t InputClientProxy::NotifyInputStop()
71 {
72     IMSA_HILOGD("InputClientProxy::NotifyInputStop");
73     return SendRequest(ON_NOTIFY_INPUT_STOP, nullptr);
74 }
DeactivateClient()75 void InputClientProxy::DeactivateClient()
76 {
77     SendRequest(DEACTIVATE_CLIENT, nullptr, nullptr, MessageOption::TF_ASYNC);
78 }
79 
SendRequest(int code,ParcelHandler input,ParcelHandler output,MessageOption option)80 int32_t InputClientProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output, MessageOption option)
81 {
82     IMSA_HILOGD("InputClientProxy run in, code = %{public}d", code);
83     MessageParcel data;
84     MessageParcel reply;
85     if (!data.WriteInterfaceToken(GetDescriptor())) {
86         IMSA_HILOGE("write interface token failed!");
87         return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
88     }
89     if (input != nullptr && (!input(data))) {
90         IMSA_HILOGE("write data failed!");
91         return ErrorCode::ERROR_EX_PARCELABLE;
92     }
93     auto remote = Remote();
94     if (remote == nullptr) {
95         IMSA_HILOGE("remote is nullptr!");
96         return ErrorCode::ERROR_IPC_REMOTE_NULLPTR;
97     }
98     auto ret = remote->SendRequest(code, data, reply, option);
99     if (ret != NO_ERROR) {
100         IMSA_HILOGE("send request failed, code: %{public}d, ret: %{public}d!", code, ret);
101         return ret;
102     }
103     ret = reply.ReadInt32();
104     if (ret != NO_ERROR) {
105         IMSA_HILOGE("reply error, ret: %{public}d!", ret);
106         return ret;
107     }
108     if (output != nullptr && (!output(reply))) {
109         IMSA_HILOGE("reply parcel error!");
110         return ErrorCode::ERROR_EX_PARCELABLE;
111     }
112     return ret;
113 }
114 } // namespace MiscServices
115 } // namespace OHOS