• 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_method_system_ability_proxy.h"
17 
18 #include "global.h"
19 #include "inputmethod_service_ipc_interface_code.h"
20 #include "itypes_util.h"
21 #include "message_option.h"
22 
23 namespace OHOS {
24 namespace MiscServices {
25 using namespace ErrorCode;
26 
InputMethodSystemAbilityProxy(const sptr<IRemoteObject> & object)27 InputMethodSystemAbilityProxy::InputMethodSystemAbilityProxy(const sptr<IRemoteObject> &object)
28     : IRemoteProxy<IInputMethodSystemAbility>(object)
29 {
30 }
31 
PrepareInput(InputClientInfo & inputClientInfo)32 int32_t InputMethodSystemAbilityProxy::PrepareInput(InputClientInfo &inputClientInfo)
33 {
34     return SendRequest(
35         static_cast<uint32_t>(InputMethodInterfaceCode::PREPARE_INPUT), [&inputClientInfo](MessageParcel &data) {
36             return ITypesUtil::Marshal(data, inputClientInfo);
37         });
38 }
39 
StartInput(sptr<IInputClient> client,bool isShowKeyboard,bool attachFlag)40 int32_t InputMethodSystemAbilityProxy::StartInput(sptr<IInputClient> client, bool isShowKeyboard, bool attachFlag)
41 {
42     IMSA_HILOGD("%{public}s in", __func__);
43     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT),
44         [isShowKeyboard, client, attachFlag](MessageParcel &data) {
45             return data.WriteRemoteObject(client->AsObject()) && data.WriteBool(isShowKeyboard) &&
46                    data.WriteBool(attachFlag);
47         });
48 }
49 
ShowCurrentInput()50 int32_t InputMethodSystemAbilityProxy::ShowCurrentInput()
51 {
52     IMSA_HILOGD("%{public}s in", __func__);
53     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT));
54 }
55 
HideCurrentInput()56 int32_t InputMethodSystemAbilityProxy::HideCurrentInput()
57 {
58     IMSA_HILOGD("%{public}s in", __func__);
59     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT));
60 }
61 
StopInputSession()62 int32_t InputMethodSystemAbilityProxy::StopInputSession()
63 {
64     IMSA_HILOGD("%{public}s in", __func__);
65     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT_SESSION));
66 }
67 
StopInput(sptr<IInputClient> client)68 int32_t InputMethodSystemAbilityProxy::StopInput(sptr<IInputClient> client)
69 {
70     IMSA_HILOGD("%{public}s in", __func__);
71     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT), [client](MessageParcel &data) {
72         return data.WriteRemoteObject(client->AsObject());
73     });
74 }
75 
ReleaseInput(sptr<IInputClient> client)76 int32_t InputMethodSystemAbilityProxy::ReleaseInput(sptr<IInputClient> client)
77 {
78     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT), [client](MessageParcel &data) {
79         return data.WriteRemoteObject(client->AsObject());
80     });
81 }
82 
DisplayOptionalInputMethod()83 int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethod()
84 {
85     IMSA_HILOGI("%{public}s in", __func__);
86     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_METHOD));
87 }
88 
SetCoreAndAgent(sptr<IInputMethodCore> core,sptr<IInputMethodAgent> agent)89 int32_t InputMethodSystemAbilityProxy::SetCoreAndAgent(sptr<IInputMethodCore> core, sptr<IInputMethodAgent> agent)
90 {
91     IMSA_HILOGD("%{public}s in", __func__);
92     return SendRequest(
93         static_cast<uint32_t>(InputMethodInterfaceCode::SET_CORE_AND_AGENT), [core, agent](MessageParcel &data) {
94             return data.WriteRemoteObject(core->AsObject()) && data.WriteRemoteObject(agent->AsObject());
95         });
96 }
97 
GetCurrentInputMethod()98 std::shared_ptr<Property> InputMethodSystemAbilityProxy::GetCurrentInputMethod()
99 {
100     IMSA_HILOGD("%{public}s in", __func__);
101     std::shared_ptr<Property> property = nullptr;
102     int32_t ret = SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD), nullptr,
103         [&property](MessageParcel &reply) {
104             property = std::make_shared<Property>();
105             return ITypesUtil::Unmarshal(reply, *property);
106         });
107     return ret != ErrorCode::NO_ERROR ? nullptr : property;
108 }
109 
GetCurrentInputMethodSubtype()110 std::shared_ptr<SubProperty> InputMethodSystemAbilityProxy::GetCurrentInputMethodSubtype()
111 {
112     IMSA_HILOGD("%{public}s in", __func__);
113     std::shared_ptr<SubProperty> property = nullptr;
114     int32_t ret = SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD_SUBTYPE),
115         nullptr, [&property](MessageParcel &reply) {
116             property = std::make_shared<SubProperty>();
117             return ITypesUtil::Unmarshal(reply, *property);
118         });
119     return ret != ErrorCode::NO_ERROR ? nullptr : property;
120 }
121 
ListInputMethod(InputMethodStatus status,std::vector<Property> & props)122 int32_t InputMethodSystemAbilityProxy::ListInputMethod(InputMethodStatus status, std::vector<Property> &props)
123 {
124     IMSA_HILOGD("%{public}s in", __func__);
125     return SendRequest(
126         static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD),
127         [status](MessageParcel &data) {
128             return ITypesUtil::Marshal(data, uint32_t(status));
129         },
130         [&props](MessageParcel &reply) {
131             return ITypesUtil::Unmarshal(reply, props);
132         });
133 }
134 
ShowCurrentInputDeprecated()135 int32_t InputMethodSystemAbilityProxy::ShowCurrentInputDeprecated()
136 {
137     IMSA_HILOGD("%{public}s in", __func__);
138     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT_DEPRECATED));
139 }
140 
HideCurrentInputDeprecated()141 int32_t InputMethodSystemAbilityProxy::HideCurrentInputDeprecated()
142 {
143     IMSA_HILOGD("%{public}s in", __func__);
144     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT_DEPRECATED));
145 }
146 
DisplayOptionalInputMethodDeprecated()147 int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethodDeprecated()
148 {
149     IMSA_HILOGD("%{public}s in", __func__);
150     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_DEPRECATED));
151 }
152 
ListInputMethodSubtype(const std::string & name,std::vector<SubProperty> & subProps)153 int32_t InputMethodSystemAbilityProxy::ListInputMethodSubtype(
154     const std::string &name, std::vector<SubProperty> &subProps)
155 {
156     IMSA_HILOGD("InputMethodSystemAbilityProxy::ListInputMethodSubtype");
157     return SendRequest(
158         static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD_SUBTYPE),
159         [&name](MessageParcel &data) {
160             return ITypesUtil::Marshal(data, name);
161         },
162         [&subProps](MessageParcel &reply) {
163             return ITypesUtil::Unmarshal(reply, subProps);
164         });
165 }
166 
ListCurrentInputMethodSubtype(std::vector<SubProperty> & subProps)167 int32_t InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype(std::vector<SubProperty> &subProps)
168 {
169     IMSA_HILOGD("InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype");
170     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::LIST_CURRENT_INPUT_METHOD_SUBTYPE), nullptr,
171         [&subProps](MessageParcel &reply) {
172             return ITypesUtil::Unmarshal(reply, subProps);
173         });
174 }
175 
SwitchInputMethod(const std::string & name,const std::string & subName)176 int32_t InputMethodSystemAbilityProxy::SwitchInputMethod(const std::string &name, const std::string &subName)
177 {
178     IMSA_HILOGD("InputMethodSystemAbilityProxy::SwitchInputMethod");
179     return SendRequest(
180         static_cast<uint32_t>(InputMethodInterfaceCode::SWITCH_INPUT_METHOD), [&name, &subName](MessageParcel &data) {
181             return ITypesUtil::Marshal(data, name, subName);
182         });
183 }
184 
PanelStatusChange(const InputWindowStatus & status,const InputWindowInfo & windowInfo)185 int32_t InputMethodSystemAbilityProxy::PanelStatusChange(
186     const InputWindowStatus &status, const InputWindowInfo &windowInfo)
187 {
188     IMSA_HILOGD("InputMethodSystemAbilityProxy::PanelStatusChange");
189     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE),
190         [status, windowInfo](MessageParcel &data) {
191             return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), windowInfo);
192         });
193 }
194 
UpdateListenEventFlag(InputClientInfo & clientInfo,EventType eventType)195 int32_t InputMethodSystemAbilityProxy::UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType)
196 {
197     IMSA_HILOGD("InputMethodSystemAbilityProxy::UpdateListenEventFlag");
198     return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::UPDATE_LISTEN_EVENT_FLAG),
199         [&clientInfo, eventType](MessageParcel &data) {
200             return ITypesUtil::Marshal(data, clientInfo, eventType);
201         });
202 }
203 
SendRequest(int code,ParcelHandler input,ParcelHandler output)204 int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output)
205 {
206     IMSA_HILOGD("InputMethodSystemAbilityProxy run in, code = %{public}d", code);
207     MessageParcel data;
208     MessageParcel reply;
209     MessageOption option{ MessageOption::TF_SYNC };
210     if (!data.WriteInterfaceToken(GetDescriptor())) {
211         IMSA_HILOGE("write interface token failed");
212         return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
213     }
214     if (input != nullptr && (!input(data))) {
215         IMSA_HILOGE("write data failed");
216         return ErrorCode::ERROR_EX_PARCELABLE;
217     }
218     auto ret = Remote()->SendRequest(code, data, reply, option);
219     if (ret != NO_ERROR) {
220         IMSA_HILOGE("transport exceptions, code: %{public}d, ret %{public}d", code, ret);
221         return ret;
222     }
223     ret = reply.ReadInt32();
224     if (ret != NO_ERROR) {
225         IMSA_HILOGE("dispose failed in service, code: %{public}d, ret: %{public}d", code, ret);
226         return ret;
227     }
228     if (output != nullptr && (!output(reply))) {
229         IMSA_HILOGE("reply parcel error");
230         return ErrorCode::ERROR_EX_PARCELABLE;
231     }
232     return ErrorCode::NO_ERROR;
233 }
234 } // namespace MiscServices
235 } // namespace OHOS
236