• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_stub.h"
17 
18 #include <cinttypes>
19 
20 #include "ipc_skeleton.h"
21 #include "itypes_util.h"
22 #include "xcollie/xcollie.h"
23 namespace OHOS {
24 namespace MiscServices {
25 using namespace std::chrono;
26 using namespace HiviewDFX;
27 constexpr uint32_t FATAL_TIMEOUT = 30;    // 30s
28 constexpr int64_t WARNING_TIMEOUT = 5000; // 5s
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t InputMethodSystemAbilityStub::OnRemoteRequest(
30     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
31 {
32     if (code != static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT)) {
33         IMSA_HILOGI("IMSA, code = %{public}u, callingPid/Uid/timestamp: %{public}d/%{public}d/%{public}lld", code,
34             IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid(),
35             std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
36                 .count());
37     }
38     std::u16string remoteDescriptor = data.ReadInterfaceToken();
39     if (remoteDescriptor != IInputMethodSystemAbility::GetDescriptor()) {
40         IMSA_HILOGE("%{public}s descriptor failed!", __func__);
41         return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
42     }
43     if (code >= static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_BEGIN) &&
44         code < static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_END)) {
45         // service reboot when timeout 30s
46         auto id = XCollie::GetInstance().SetTimer("IMSA_API[" + std::to_string(code) + "]", FATAL_TIMEOUT, nullptr,
47             nullptr, XCOLLIE_FLAG_DEFAULT);
48         int64_t startPoint = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
49         auto ret = (this->*HANDLERS[code])(data, reply);
50         int64_t costTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() - startPoint;
51         // log warning when timeout 5s
52         if (costTime > WARNING_TIMEOUT) {
53             IMSA_HILOGW("code: %{public}d, pid: %{public}d, uid: %{public}d, cost: %{public}" PRId64 "", code,
54                 IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid(), costTime);
55         }
56         XCollie::GetInstance().CancelTimer(id);
57         return ret;
58     } else {
59         IMSA_HILOGE("code error, code = %{public}u, callingPid: %{public}d, callingUid: %{public}d.", code,
60             IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
61         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
62     }
63 }
64 
StartInputOnRemote(MessageParcel & data,MessageParcel & reply)65 int32_t InputMethodSystemAbilityStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply)
66 {
67     InputClientInfo clientInfo;
68     sptr<IRemoteObject> client = nullptr;
69     if (!ITypesUtil::Unmarshal(data, clientInfo, client, clientInfo.channel)) {
70         IMSA_HILOGE("read clientInfo failed!");
71         return ErrorCode::ERROR_EX_PARCELABLE;
72     }
73     clientInfo.client = iface_cast<IInputClient>(client);
74     sptr<IRemoteObject> agent = nullptr;
75     std::pair<int64_t, std::string> imeInfo{ 0, "" };
76     int32_t ret = StartInput(clientInfo, agent, imeInfo);
77     auto marshalRet = reply.WriteInt32(ret) && reply.WriteRemoteObject(agent);
78     ITypesUtil::Marshal(reply, imeInfo.first, imeInfo.second);
79     return marshalRet ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
80 }
81 
ShowCurrentInputOnRemote(MessageParcel & data,MessageParcel & reply)82 int32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
83 {
84     ClientType type = ClientType::INNER_KIT;
85     ITypesUtil::Unmarshal(data, type);
86     int32_t ret = ShowCurrentInput(type);
87     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
88 }
89 
HideCurrentInputOnRemote(MessageParcel & data,MessageParcel & reply)90 int32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
91 {
92     int32_t ret = HideCurrentInput();
93     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
94 }
95 
StopInputSessionOnRemote(MessageParcel & data,MessageParcel & reply)96 int32_t InputMethodSystemAbilityStub::StopInputSessionOnRemote(MessageParcel &data, MessageParcel &reply)
97 {
98     int32_t ret = StopInputSession();
99     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
100 }
101 
ShowInputOnRemote(MessageParcel & data,MessageParcel & reply)102 int32_t InputMethodSystemAbilityStub::ShowInputOnRemote(MessageParcel &data, MessageParcel &reply)
103 {
104     auto clientObject = data.ReadRemoteObject();
105     if (clientObject == nullptr) {
106         IMSA_HILOGE("clientObject is nullptr!");
107         return ErrorCode::ERROR_EX_PARCELABLE;
108     }
109     ClientType type = ClientType::INNER_KIT;
110     ITypesUtil::Unmarshal(data, type);
111     int32_t requestKeyboardReason = data.ReadInt32();
112     int32_t ret = ShowInput(iface_cast<IInputClient>(clientObject), type, requestKeyboardReason);
113     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
114 }
115 
HideInputOnRemote(MessageParcel & data,MessageParcel & reply)116 int32_t InputMethodSystemAbilityStub::HideInputOnRemote(MessageParcel &data, MessageParcel &reply)
117 {
118     auto clientObject = data.ReadRemoteObject();
119     if (clientObject == nullptr) {
120         IMSA_HILOGE("clientObject is nullptr!");
121         return ErrorCode::ERROR_EX_PARCELABLE;
122     }
123     int32_t ret = HideInput(iface_cast<IInputClient>(clientObject));
124     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
125 }
126 
ReleaseInputOnRemote(MessageParcel & data,MessageParcel & reply)127 int32_t InputMethodSystemAbilityStub::ReleaseInputOnRemote(MessageParcel &data, MessageParcel &reply)
128 {
129     auto clientObject = data.ReadRemoteObject();
130     if (clientObject == nullptr) {
131         IMSA_HILOGE("clientObject is nullptr!");
132         return ErrorCode::ERROR_EX_PARCELABLE;
133     }
134     int32_t ret = ReleaseInput(iface_cast<IInputClient>(clientObject));
135     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
136 }
137 
RequestShowInputOnRemote(MessageParcel & data,MessageParcel & reply)138 int32_t InputMethodSystemAbilityStub::RequestShowInputOnRemote(MessageParcel &data, MessageParcel &reply)
139 {
140     return reply.WriteInt32(RequestShowInput()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
141 }
142 
RequestHideInputOnRemote(MessageParcel & data,MessageParcel & reply)143 int32_t InputMethodSystemAbilityStub::RequestHideInputOnRemote(MessageParcel &data, MessageParcel &reply)
144 {
145     bool isFocusTriggered = false;
146     auto ret = data.ReadBool(isFocusTriggered);
147     if (!ret) {
148         IMSA_HILOGE("read isFocusTriggered failed!");
149         return ErrorCode::ERROR_EX_PARCELABLE;
150     }
151     return reply.WriteInt32(RequestHideInput(isFocusTriggered)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
152 }
153 
DisplayOptionalInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)154 int32_t InputMethodSystemAbilityStub::DisplayOptionalInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
155 {
156     int32_t ret = DisplayOptionalInputMethod();
157     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
158 }
159 
SetCoreAndAgentOnRemote(MessageParcel & data,MessageParcel & reply)160 int32_t InputMethodSystemAbilityStub::SetCoreAndAgentOnRemote(MessageParcel &data, MessageParcel &reply)
161 {
162     auto coreObject = data.ReadRemoteObject();
163     if (coreObject == nullptr) {
164         IMSA_HILOGE("coreObject is nullptr!");
165         return ErrorCode::ERROR_EX_PARCELABLE;
166     }
167     auto agentObject = data.ReadRemoteObject();
168     if (agentObject == nullptr) {
169         IMSA_HILOGE("agentObject is nullptr!");
170         return ErrorCode::ERROR_EX_PARCELABLE;
171     }
172     int32_t ret = SetCoreAndAgent(iface_cast<IInputMethodCore>(coreObject), agentObject);
173     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
174 }
175 
GetDefaultInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)176 int32_t InputMethodSystemAbilityStub::GetDefaultInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
177 {
178     std::shared_ptr<Property> prop = std::make_shared<Property>();
179     bool isBrief = false;
180     auto ret = data.ReadBool(isBrief);
181     if (!ret) {
182         IMSA_HILOGE("read isBrief failed!");
183     }
184     ret = GetDefaultInputMethod(prop, isBrief);
185     if (prop == nullptr) {
186         return ErrorCode::ERROR_EX_PARCELABLE;
187     }
188     return ITypesUtil::Marshal(reply, ret, *prop) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
189 }
190 
IsDefaultImeSetOnRemote(MessageParcel & data,MessageParcel & reply)191 int32_t InputMethodSystemAbilityStub::IsDefaultImeSetOnRemote(MessageParcel &data, MessageParcel &reply)
192 {
193     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsDefaultImeSet()) ? ErrorCode::NO_ERROR
194                                                                            : ErrorCode::ERROR_EX_PARCELABLE;
195 }
196 
EnableImeOnRemote(MessageParcel & data,MessageParcel & reply)197 int32_t InputMethodSystemAbilityStub::EnableImeOnRemote(MessageParcel &data, MessageParcel &reply)
198 {
199     std::string bundleName;
200     if (!ITypesUtil::Unmarshal(data, bundleName)) {
201         IMSA_HILOGE("unmarshal failed!");
202         return ErrorCode::ERROR_EX_PARCELABLE;
203     }
204     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, EnableIme(bundleName)) ? ErrorCode::NO_ERROR
205                                                                         : ErrorCode::ERROR_EX_PARCELABLE;
206 }
207 
GetInputMethodConfigOnRemote(MessageParcel & data,MessageParcel & reply)208 int32_t InputMethodSystemAbilityStub::GetInputMethodConfigOnRemote(MessageParcel &data, MessageParcel &reply)
209 {
210     OHOS::AppExecFwk::ElementName inputMethodConfig;
211     auto ret = GetInputMethodConfig(inputMethodConfig);
212     IMSA_HILOGD("GetInputMethodConfigOnRemote inputMethodConfig is %{public}s, %{public}s",
213         inputMethodConfig.GetBundleName().c_str(), inputMethodConfig.GetAbilityName().c_str());
214     return ITypesUtil::Marshal(reply, ret, inputMethodConfig) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
215 }
216 
GetSecurityModeOnRemote(MessageParcel & data,MessageParcel & reply)217 int32_t InputMethodSystemAbilityStub::GetSecurityModeOnRemote(MessageParcel &data, MessageParcel &reply)
218 {
219     IMSA_HILOGD("GetSecurityModeOnRemote start.");
220     int32_t security;
221     auto ret = GetSecurityMode(security);
222     IMSA_HILOGD("GetSecurityModeOnRemote, security: %{public}d", security);
223     return ITypesUtil::Marshal(reply, ret, security) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
224 }
225 
GetCurrentInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)226 int32_t InputMethodSystemAbilityStub::GetCurrentInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
227 {
228     auto property = GetCurrentInputMethod();
229     if (property == nullptr) {
230         IMSA_HILOGE("property is nullptr!");
231         return reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER) ? ErrorCode::NO_ERROR
232                                                                   : ErrorCode::ERROR_EX_PARCELABLE;
233     }
234     if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property)) {
235         IMSA_HILOGE("marshal failed!");
236         return ErrorCode::ERROR_EX_PARCELABLE;
237     }
238     return ErrorCode::NO_ERROR;
239 }
240 
GetCurrentInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)241 int32_t InputMethodSystemAbilityStub::GetCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
242 {
243     auto property = GetCurrentInputMethodSubtype();
244     if (property == nullptr) {
245         IMSA_HILOGE("property is nullptr!");
246         return reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER) ? ErrorCode::NO_ERROR
247                                                                   : ErrorCode::ERROR_EX_PARCELABLE;
248     }
249     if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property)) {
250         IMSA_HILOGE("marshal failed!");
251         return ErrorCode::ERROR_EX_PARCELABLE;
252     }
253     return ErrorCode::NO_ERROR;
254 }
255 
ListInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)256 int32_t InputMethodSystemAbilityStub::ListInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
257 {
258     uint32_t status;
259     if (!ITypesUtil::Unmarshal(data, status)) {
260         IMSA_HILOGE("read status failed!");
261         return ErrorCode::ERROR_EX_PARCELABLE;
262     }
263     std::vector<Property> properties = {};
264     auto ret = ListInputMethod(InputMethodStatus(status), properties);
265     if (!ITypesUtil::Marshal(reply, ret, properties)) {
266         IMSA_HILOGE("marshal failed!");
267         return ErrorCode::ERROR_EX_PARCELABLE;
268     }
269     return ErrorCode::NO_ERROR;
270 }
271 
ListInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)272 int32_t InputMethodSystemAbilityStub::ListInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
273 {
274     std::string bundleName;
275     if (!ITypesUtil::Unmarshal(data, bundleName)) {
276         IMSA_HILOGE("read bundleName failed!");
277         return ErrorCode::ERROR_EX_PARCELABLE;
278     }
279     std::vector<SubProperty> subProps = {};
280     auto ret = ListInputMethodSubtype(bundleName, subProps);
281     if (!ITypesUtil::Marshal(reply, ret, subProps)) {
282         IMSA_HILOGE("marshal failed!");
283         return ErrorCode::ERROR_EX_PARCELABLE;
284     }
285     return ErrorCode::NO_ERROR;
286 }
287 
ListCurrentInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)288 int32_t InputMethodSystemAbilityStub::ListCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
289 {
290     std::vector<SubProperty> subProps = {};
291     auto ret = ListCurrentInputMethodSubtype(subProps);
292     if (!ITypesUtil::Marshal(reply, ret, subProps)) {
293         IMSA_HILOGE("marshal failed!");
294         return ErrorCode::ERROR_EX_PARCELABLE;
295     }
296     return ErrorCode::NO_ERROR;
297 }
298 
SwitchInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)299 int32_t InputMethodSystemAbilityStub::SwitchInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
300 {
301     std::string name;
302     std::string subName;
303     SwitchTrigger trigger;
304     if (!ITypesUtil::Unmarshal(data, name, subName, trigger)) {
305         IMSA_HILOGE("unmarshal failed!");
306         return ErrorCode::ERROR_EX_PARCELABLE;
307     }
308     return reply.WriteInt32(SwitchInputMethod(name, subName, trigger)) ? ErrorCode::NO_ERROR
309                                                                        : ErrorCode::ERROR_EX_PARCELABLE;
310 }
311 
PanelStatusChangeOnRemote(MessageParcel & data,MessageParcel & reply)312 int32_t InputMethodSystemAbilityStub::PanelStatusChangeOnRemote(MessageParcel &data, MessageParcel &reply)
313 {
314     uint32_t status = 0;
315     ImeWindowInfo info;
316     if (!ITypesUtil::Unmarshal(data, status, info)) {
317         IMSA_HILOGE("unmarshal failed!");
318         return ErrorCode::ERROR_EX_PARCELABLE;
319     }
320     int32_t ret = PanelStatusChange(static_cast<InputWindowStatus>(status), info);
321     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
322 }
323 
UpdateListenEventFlagOnRemote(MessageParcel & data,MessageParcel & reply)324 int32_t InputMethodSystemAbilityStub::UpdateListenEventFlagOnRemote(MessageParcel &data, MessageParcel &reply)
325 {
326     InputClientInfo clientInfo;
327     sptr<IRemoteObject> client = nullptr;
328     uint32_t eventFlag = 0;
329     if (!ITypesUtil::Unmarshal(data, clientInfo, client, clientInfo.channel, eventFlag)) {
330         IMSA_HILOGE("unmarshal failed!");
331         return ErrorCode::ERROR_EX_PARCELABLE;
332     }
333     clientInfo.client = iface_cast<IInputClient>(client);
334     int32_t ret = UpdateListenEventFlag(clientInfo, eventFlag);
335     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
336 }
337 
SetCallingWindowOnRemote(MessageParcel & data,MessageParcel & reply)338 int32_t InputMethodSystemAbilityStub::SetCallingWindowOnRemote(MessageParcel &data, MessageParcel &reply)
339 {
340     auto clientObject = data.ReadRemoteObject();
341     if (clientObject == nullptr) {
342         IMSA_HILOGE("clientObject is nullptr!");
343         return ErrorCode::ERROR_EX_PARCELABLE;
344     }
345     uint32_t windowId = 0;
346     if (!ITypesUtil::Unmarshal(data, windowId)) {
347         IMSA_HILOGE("unmarshal failed!");
348         return ErrorCode::ERROR_EX_PARCELABLE;
349     }
350     return ITypesUtil::Marshal(reply, SetCallingWindow(windowId, iface_cast<IInputClient>(clientObject))) ?
351         ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
352 }
353 
GetInputStartInfoOnRemote(MessageParcel & data,MessageParcel & reply)354 int32_t InputMethodSystemAbilityStub::GetInputStartInfoOnRemote(MessageParcel &data, MessageParcel &reply)
355 {
356     bool isInputStart = false;
357     uint32_t callingWndId = 0;
358     int32_t requestKeyboardReason = 0;
359     auto ret = GetInputStartInfo(isInputStart, callingWndId, requestKeyboardReason);
360     return ITypesUtil::Marshal(reply, ret, isInputStart, callingWndId, requestKeyboardReason) ?
361         ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
362 }
363 
ShowCurrentInputOnRemoteDeprecated(MessageParcel & data,MessageParcel & reply)364 int32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
365 {
366     int32_t ret = ShowCurrentInputDeprecated();
367     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
368 }
369 
HideCurrentInputOnRemoteDeprecated(MessageParcel & data,MessageParcel & reply)370 int32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
371 {
372     int32_t ret = HideCurrentInputDeprecated();
373     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
374 }
375 
IsCurrentImeOnRemote(MessageParcel & data,MessageParcel & reply)376 int32_t InputMethodSystemAbilityStub::IsCurrentImeOnRemote(MessageParcel &data, MessageParcel &reply)
377 {
378     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsCurrentIme()) ? ErrorCode::NO_ERROR
379                                                                            : ErrorCode::ERROR_EX_PARCELABLE;
380 }
381 
UnRegisteredProxyImeOnRemote(MessageParcel & data,MessageParcel & reply)382 int32_t InputMethodSystemAbilityStub::UnRegisteredProxyImeOnRemote(MessageParcel &data, MessageParcel &reply)
383 {
384     int32_t type = -1;
385     sptr<IRemoteObject> coreObject = nullptr;
386     if (!ITypesUtil::Unmarshal(data, type, coreObject) || coreObject == nullptr) {
387         IMSA_HILOGE("coreObject is nullptr!");
388         return ErrorCode::ERROR_EX_PARCELABLE;
389     }
390     int32_t ret = UnRegisteredProxyIme(static_cast<UnRegisteredType>(type), iface_cast<IInputMethodCore>(coreObject));
391     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
392 }
393 
IsInputTypeSupportedOnRemote(MessageParcel & data,MessageParcel & reply)394 int32_t InputMethodSystemAbilityStub::IsInputTypeSupportedOnRemote(MessageParcel &data, MessageParcel &reply)
395 {
396     InputType type;
397     if (!ITypesUtil::Unmarshal(data, type)) {
398         IMSA_HILOGE("unmarshal failed!");
399         return ErrorCode::ERROR_EX_PARCELABLE;
400     }
401     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsInputTypeSupported(type)) ? ErrorCode::NO_ERROR
402                                                                                        : ErrorCode::ERROR_EX_PARCELABLE;
403 }
404 
StartInputTypeOnRemote(MessageParcel & data,MessageParcel & reply)405 int32_t InputMethodSystemAbilityStub::StartInputTypeOnRemote(MessageParcel &data, MessageParcel &reply)
406 {
407     InputType type;
408     if (!ITypesUtil::Unmarshal(data, type)) {
409         IMSA_HILOGE("unmarshal failed!");
410         return ErrorCode::ERROR_EX_PARCELABLE;
411     }
412     return ITypesUtil::Marshal(reply, StartInputType(type)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
413 }
414 
ExitCurrentInputTypeOnRemote(MessageParcel & data,MessageParcel & reply)415 int32_t InputMethodSystemAbilityStub::ExitCurrentInputTypeOnRemote(MessageParcel &data, MessageParcel &reply)
416 {
417     return ITypesUtil::Marshal(reply, ExitCurrentInputType()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
418 }
419 
IsPanelShownOnRemote(MessageParcel & data,MessageParcel & reply)420 int32_t InputMethodSystemAbilityStub::IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply)
421 {
422     PanelInfo info;
423     if (!ITypesUtil::Unmarshal(data, info)) {
424         IMSA_HILOGE("unmarshal failed!");
425         return ErrorCode::ERROR_EX_PARCELABLE;
426     }
427     bool isShown = false;
428     int32_t ret = IsPanelShown(info, isShown);
429     return ITypesUtil::Marshal(reply, ret, isShown) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
430 }
431 
IsDefaultImeOnRemote(MessageParcel & data,MessageParcel & reply)432 int32_t InputMethodSystemAbilityStub::IsDefaultImeOnRemote(MessageParcel &data, MessageParcel &reply)
433 {
434     return ITypesUtil::Marshal(reply, IsDefaultIme()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
435 }
436 
ConnectSystemCmdOnRemote(MessageParcel & data,MessageParcel & reply)437 int32_t InputMethodSystemAbilityStub::ConnectSystemCmdOnRemote(MessageParcel &data, MessageParcel &reply)
438 {
439     auto systemCmdStub = data.ReadRemoteObject();
440     if (systemCmdStub == nullptr) {
441         IMSA_HILOGE("systemCmdStub is nullptr!");
442         return ErrorCode::ERROR_EX_PARCELABLE;
443     }
444     sptr<IRemoteObject> agent = nullptr;
445     int32_t ret = ConnectSystemCmd(systemCmdStub, agent);
446     return reply.WriteInt32(ret) && reply.WriteRemoteObject(agent) ? ErrorCode::NO_ERROR
447                                                                    : ErrorCode::ERROR_EX_PARCELABLE;
448 }
449 
IsCurrentImeByPidOnRemote(MessageParcel & data,MessageParcel & reply)450 int32_t InputMethodSystemAbilityStub::IsCurrentImeByPidOnRemote(MessageParcel &data, MessageParcel &reply)
451 {
452     int32_t pid = -1;
453     if (!ITypesUtil::Unmarshal(data, pid)) {
454         IMSA_HILOGE("unmarshal failed!");
455         return ErrorCode::ERROR_EX_PARCELABLE;
456     }
457     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsCurrentImeByPid(pid)) ? ErrorCode::NO_ERROR
458                                                                            : ErrorCode::ERROR_EX_PARCELABLE;
459 }
460 
InitConnectOnRemote(MessageParcel & data,MessageParcel & reply)461 int32_t InputMethodSystemAbilityStub::InitConnectOnRemote(MessageParcel &data, MessageParcel &reply)
462 {
463     return reply.WriteInt32(InitConnect()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
464 }
465 
GetInputMethodStateOnRemote(MessageParcel & data,MessageParcel & reply)466 int32_t InputMethodSystemAbilityStub::GetInputMethodStateOnRemote(MessageParcel &data, MessageParcel &reply)
467 {
468     EnabledStatus status = EnabledStatus::DISABLED;
469     int32_t ret = GetInputMethodState(status);
470     return ITypesUtil::Marshal(reply, ret, static_cast<int32_t>(status)) ? ErrorCode::NO_ERROR
471                                                                          : ErrorCode::ERROR_EX_PARCELABLE;
472 }
473 
IsSystemAppOnRemote(MessageParcel & data,MessageParcel & reply)474 int32_t InputMethodSystemAbilityStub::IsSystemAppOnRemote(MessageParcel &data, MessageParcel &reply)
475 {
476     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsSystemApp()) ? ErrorCode::NO_ERROR
477                                                                           : ErrorCode::ERROR_EX_PARCELABLE;
478 }
479 } // namespace MiscServices
480 } // namespace OHOS