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