• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "multimodal_input_connect_stub.h"
17 
18 #include <unistd.h>
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 
22 #include "string_ex.h"
23 
24 #include "error_multimodal.h"
25 #include "multimodal_input_connect_def_parcel.h"
26 #include "time_cost_chk.h"
27 #include "permission_helper.h"
28 
29 namespace OHOS {
30 namespace MMI {
31 namespace {
32 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MultimodalInputConnectStub" };
33 using ConnFunc = int32_t (MultimodalInputConnectStub::*)(MessageParcel& data, MessageParcel& reply);
34 } // namespace
35 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int32_t MultimodalInputConnectStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
37     MessageParcel& reply, MessageOption& option)
38 {
39     int32_t pid = GetCallingPid();
40     TimeCostChk chk("IPC-OnRemoteRequest", "overtime 300(us)", MAX_OVER_TIME, pid,
41         static_cast<int64_t>(code));
42     MMI_HILOGD("RemoteRequest code:%{public}d tid:%{public}" PRIu64 " pid:%{public}d", code, GetThisThreadId(), pid);
43 
44     std::u16string descriptor = data.ReadInterfaceToken();
45     if (descriptor != IMultimodalInputConnect::GetDescriptor()) {
46         MMI_HILOGE("Get unexpect descriptor:%{public}s", Str16ToStr8(descriptor).c_str());
47         return ERR_INVALID_STATE;
48     }
49     const static std::map<int32_t, ConnFunc> mapConnFunc = {
50         {IMultimodalInputConnect::ALLOC_SOCKET_FD, &MultimodalInputConnectStub::StubHandleAllocSocketFd},
51         {IMultimodalInputConnect::ADD_INPUT_EVENT_FILTER, &MultimodalInputConnectStub::StubAddInputEventFilter},
52         {IMultimodalInputConnect::SET_POINTER_VISIBLE, &MultimodalInputConnectStub::StubSetPointerVisible},
53         {IMultimodalInputConnect::SET_POINTER_STYLE, &MultimodalInputConnectStub::StubSetPointerStyle},
54         {IMultimodalInputConnect::GET_POINTER_STYLE, &MultimodalInputConnectStub::StubGetPointerStyle},
55         {IMultimodalInputConnect::IS_POINTER_VISIBLE, &MultimodalInputConnectStub::StubIsPointerVisible},
56         {IMultimodalInputConnect::REGISTER_DEV_MONITOR, &MultimodalInputConnectStub::StubRegisterInputDeviceMonitor},
57         {IMultimodalInputConnect::UNREGISTER_DEV_MONITOR,
58             &MultimodalInputConnectStub::StubUnregisterInputDeviceMonitor},
59         {IMultimodalInputConnect::GET_DEVICE_IDS, &MultimodalInputConnectStub::StubGetDeviceIds},
60         {IMultimodalInputConnect::GET_DEVICE, &MultimodalInputConnectStub::StubGetDevice},
61         {IMultimodalInputConnect::SUPPORT_KEYS, &MultimodalInputConnectStub::StubSupportKeys},
62         {IMultimodalInputConnect::GET_KEYBOARD_TYPE, &MultimodalInputConnectStub::StubGetKeyboardType},
63         {IMultimodalInputConnect::SET_POINTER_SPEED, &MultimodalInputConnectStub::StubSetPointerSpeed},
64         {IMultimodalInputConnect::GET_POINTER_SPEED, &MultimodalInputConnectStub::StubGetPointerSpeed},
65         {IMultimodalInputConnect::SUBSCRIBE_KEY_EVENT, &MultimodalInputConnectStub::StubSubscribeKeyEvent},
66         {IMultimodalInputConnect::UNSUBSCRIBE_KEY_EVENT, &MultimodalInputConnectStub::StubUnsubscribeKeyEvent},
67         {IMultimodalInputConnect::ADD_INPUT_HANDLER, &MultimodalInputConnectStub::StubAddInputHandler},
68         {IMultimodalInputConnect::REMOVE_INPUT_HANDLER, &MultimodalInputConnectStub::StubRemoveInputHandler},
69         {IMultimodalInputConnect::MARK_EVENT_CONSUMED, &MultimodalInputConnectStub::StubMarkEventConsumed},
70         {IMultimodalInputConnect::MOVE_MOUSE, &MultimodalInputConnectStub::StubMoveMouseEvent},
71         {IMultimodalInputConnect::INJECT_KEY_EVENT, &MultimodalInputConnectStub::StubInjectKeyEvent},
72         {IMultimodalInputConnect::INJECT_POINTER_EVENT, &MultimodalInputConnectStub::StubInjectPointerEvent},
73         {IMultimodalInputConnect::SET_ANR_OBSERVER, &MultimodalInputConnectStub::StubSetAnrListener},
74         {IMultimodalInputConnect::REGISTER_COOPERATE_MONITOR,
75             &MultimodalInputConnectStub::StubRegisterCooperateMonitor},
76         {IMultimodalInputConnect::UNREGISTER_COOPERATE_MONITOR,
77             &MultimodalInputConnectStub::StubUnregisterCooperateMonitor},
78         {IMultimodalInputConnect::ENABLE_INPUT_DEVICE_COOPERATE,
79             &MultimodalInputConnectStub::StubEnableInputDeviceCooperate},
80         {IMultimodalInputConnect::START_INPUT_DEVICE_COOPERATE,
81             &MultimodalInputConnectStub::StubStartInputDeviceCooperate},
82         {IMultimodalInputConnect::STOP_DEVICE_COOPERATE, &MultimodalInputConnectStub::StubStopDeviceCooperate},
83         {IMultimodalInputConnect::GET_INPUT_DEVICE_COOPERATE_STATE,
84             &MultimodalInputConnectStub::StubGetInputDeviceCooperateState},
85         {IMultimodalInputConnect::SET_INPUT_DEVICE_TO_SCREEN, &MultimodalInputConnectStub::StubSetInputDevice},
86         {IMultimodalInputConnect::GET_FUNCTION_KEY_STATE, &MultimodalInputConnectStub::StubGetFunctionKeyState},
87         {IMultimodalInputConnect::SET_FUNCTION_KEY_STATE, &MultimodalInputConnectStub::StubSetFunctionKeyState}
88     };
89     auto it = mapConnFunc.find(code);
90     if (it != mapConnFunc.end()) {
91         return (this->*it->second)(data, reply);
92     }
93     MMI_HILOGE("Unknown code:%{public}u, go switch default", code);
94     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
95 }
96 
StubHandleAllocSocketFd(MessageParcel & data,MessageParcel & reply)97 int32_t MultimodalInputConnectStub::StubHandleAllocSocketFd(MessageParcel& data, MessageParcel& reply)
98 {
99     int32_t pid = GetCallingPid();
100     if (!IsRunning()) {
101         MMI_HILOGE("Service is not running. pid:%{public}d, go switch default", pid);
102         return MMISERVICE_NOT_RUNNING;
103     }
104     sptr<ConnectReqParcel> req = data.ReadParcelable<ConnectReqParcel>();
105     CHKPR(req, ERROR_NULL_POINTER);
106     MMI_HILOGD("clientName:%{public}s,moduleId:%{public}d", req->data.clientName.c_str(), req->data.moduleId);
107 
108     int32_t clientFd = INVALID_SOCKET_FD;
109     int32_t tokenType = PerHelper->GetTokenType();
110     int32_t ret = AllocSocketFd(req->data.clientName, req->data.moduleId, clientFd, tokenType);
111     if (ret != RET_OK) {
112         MMI_HILOGE("AllocSocketFd failed pid:%{public}d, go switch default", pid);
113         if (clientFd >= 0) {
114             close(clientFd);
115         }
116         return ret;
117     }
118     reply.WriteFileDescriptor(clientFd);
119     WRITEINT32(reply, tokenType, IPC_STUB_WRITE_PARCEL_ERR);
120     MMI_HILOGI("Send clientFd to client, clientFd:%{public}d, tokenType:%{public}d", clientFd, tokenType);
121     close(clientFd);
122     return RET_OK;
123 }
124 
StubAddInputEventFilter(MessageParcel & data,MessageParcel & reply)125 int32_t MultimodalInputConnectStub::StubAddInputEventFilter(MessageParcel& data, MessageParcel& reply)
126 {
127     CALL_DEBUG_ENTER;
128     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_CORE)) {
129         MMI_HILOGE("Permission check failed");
130         return CHECK_PERMISSION_FAIL;
131     }
132 
133     sptr<IRemoteObject> client = data.ReadRemoteObject();
134     CHKPR(client, ERR_INVALID_VALUE);
135     sptr<IEventFilter> filter = iface_cast<IEventFilter>(client);
136     CHKPR(filter, ERROR_NULL_POINTER);
137 
138     int32_t ret = AddInputEventFilter(filter);
139     if (ret != RET_OK) {
140         MMI_HILOGE("Call AddInputEventFilter failed ret:%{public}d", ret);
141         return ret;
142     }
143     MMI_HILOGD("Success pid:%{public}d", GetCallingPid());
144     return RET_OK;
145 }
146 
StubSetPointerVisible(MessageParcel & data,MessageParcel & reply)147 int32_t MultimodalInputConnectStub::StubSetPointerVisible(MessageParcel& data, MessageParcel& reply)
148 {
149     CALL_DEBUG_ENTER;
150     bool visible = false;
151     READBOOL(data, visible, IPC_PROXY_DEAD_OBJECT_ERR);
152     int32_t ret = SetPointerVisible(visible);
153     if (ret != RET_OK) {
154         MMI_HILOGE("Call SetPointerVisible failed ret:%{public}d", ret);
155         return ret;
156     }
157     MMI_HILOGD("Success visible:%{public}d,pid:%{public}d", visible, GetCallingPid());
158     return RET_OK;
159 }
160 
StubIsPointerVisible(MessageParcel & data,MessageParcel & reply)161 int32_t MultimodalInputConnectStub::StubIsPointerVisible(MessageParcel& data, MessageParcel& reply)
162 {
163     CALL_DEBUG_ENTER;
164     bool visible = false;
165     int32_t ret = IsPointerVisible(visible);
166     if (ret != RET_OK) {
167         MMI_HILOGE("Call IsPointerVisible failed ret:%{public}d", ret);
168         return ret;
169     }
170     WRITEBOOL(reply, visible, IPC_STUB_WRITE_PARCEL_ERR);
171     MMI_HILOGD("visible:%{public}d,ret:%{public}d,pid:%{public}d", visible, ret, GetCallingPid());
172     return RET_OK;
173 }
174 
StubSetPointerSpeed(MessageParcel & data,MessageParcel & reply)175 int32_t MultimodalInputConnectStub::StubSetPointerSpeed(MessageParcel& data, MessageParcel& reply)
176 {
177     CALL_DEBUG_ENTER;
178     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
179         MMI_HILOGE("Permission check failed");
180         return CHECK_PERMISSION_FAIL;
181     }
182     int32_t speed;
183     READINT32(data, speed, IPC_PROXY_DEAD_OBJECT_ERR);
184     int32_t ret = SetPointerSpeed(speed);
185     if (ret != RET_OK) {
186         MMI_HILOGE("Set pointer speed failed ret:%{public}d", ret);
187         return RET_ERR;
188     }
189     return RET_OK;
190 }
191 
StubGetPointerSpeed(MessageParcel & data,MessageParcel & reply)192 int32_t MultimodalInputConnectStub::StubGetPointerSpeed(MessageParcel& data, MessageParcel& reply)
193 {
194     CALL_DEBUG_ENTER;
195     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
196         MMI_HILOGE("Permission check failed");
197         return CHECK_PERMISSION_FAIL;
198     }
199     int32_t speed;
200     int32_t ret = GetPointerSpeed(speed);
201     if (ret != RET_OK) {
202         MMI_HILOGE("Call get pointer speed failed ret:%{public}d", ret);
203         return RET_ERR;
204     }
205     WRITEINT32(reply, speed, IPC_STUB_WRITE_PARCEL_ERR);
206     MMI_HILOGD("Pointer speed:%{public}d,ret:%{public}d", speed, ret);
207     return RET_OK;
208 }
209 
StubSetPointerStyle(MessageParcel & data,MessageParcel & reply)210 int32_t MultimodalInputConnectStub::StubSetPointerStyle(MessageParcel& data, MessageParcel& reply)
211 {
212     CALL_DEBUG_ENTER;
213     int32_t windowId;
214     READINT32(data, windowId, RET_ERR);
215     int32_t pointerStyle;
216     READINT32(data, pointerStyle, RET_ERR);
217     int32_t ret = SetPointerStyle(windowId, pointerStyle);
218     if (ret != RET_OK) {
219         MMI_HILOGE("Call SetPointerStyle failed ret:%{public}d", ret);
220         return ret;
221     }
222     MMI_HILOGD("Successfully set window:%{public}d, icon:%{public}d", windowId, pointerStyle);
223     return RET_OK;
224 }
225 
StubGetPointerStyle(MessageParcel & data,MessageParcel & reply)226 int32_t MultimodalInputConnectStub::StubGetPointerStyle(MessageParcel& data, MessageParcel& reply)
227 {
228     CALL_DEBUG_ENTER;
229     int32_t windowId;
230     READINT32(data, windowId, RET_ERR);
231     int32_t pointerStyle;
232     int32_t ret = GetPointerStyle(windowId, pointerStyle);
233     if (ret != RET_OK) {
234         MMI_HILOGE("Call GetPointerStyle failed ret:%{public}d", ret);
235         return ret;
236     }
237     WRITEINT32(reply, pointerStyle, RET_ERR);
238     MMI_HILOGD("Successfully get window:%{public}d, icon:%{public}d", windowId, pointerStyle);
239     return RET_OK;
240 }
241 
StubSupportKeys(MessageParcel & data,MessageParcel & reply)242 int32_t MultimodalInputConnectStub::StubSupportKeys(MessageParcel& data, MessageParcel& reply)
243 {
244     CALL_DEBUG_ENTER;
245     int32_t userData = 0;
246     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
247     int32_t deviceId = -1;
248     READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
249     int32_t size = 0;
250     READINT32(data, size, IPC_PROXY_DEAD_OBJECT_ERR);
251     std::vector<int32_t> keys;
252     int32_t key = 0;
253     for (int32_t i = 0; i < size; ++i) {
254         READINT32(data, key, IPC_PROXY_DEAD_OBJECT_ERR);
255         keys.push_back(key);
256     }
257     int32_t ret = SupportKeys(userData, deviceId, keys);
258     if (ret != RET_OK) {
259         MMI_HILOGE("Call SupportKeys failed ret:%{public}d", ret);
260     }
261     return ret;
262 }
263 
StubGetDeviceIds(MessageParcel & data,MessageParcel & reply)264 int32_t MultimodalInputConnectStub::StubGetDeviceIds(MessageParcel& data, MessageParcel& reply)
265 {
266     CALL_DEBUG_ENTER;
267     int32_t userData = 0;
268     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
269     int32_t ret = GetDeviceIds(userData);
270     if (ret != RET_OK) {
271         MMI_HILOGE("Call GetDeviceIds failed ret:%{public}d", ret);
272     }
273     return ret;
274 }
275 
StubGetDevice(MessageParcel & data,MessageParcel & reply)276 int32_t MultimodalInputConnectStub::StubGetDevice(MessageParcel& data, MessageParcel& reply)
277 {
278     CALL_DEBUG_ENTER;
279     int32_t userData = 0;
280     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
281     int32_t deviceId = -1;
282     READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
283     int32_t ret = GetDevice(userData, deviceId);
284     if (ret != RET_OK) {
285         MMI_HILOGE("Call GetDevice failed ret:%{public}d", ret);
286     }
287     return ret;
288 }
289 
StubRegisterInputDeviceMonitor(MessageParcel & data,MessageParcel & reply)290 int32_t MultimodalInputConnectStub::StubRegisterInputDeviceMonitor(MessageParcel& data, MessageParcel& reply)
291 {
292     CALL_DEBUG_ENTER;
293     int32_t ret = RegisterDevListener();
294     if (ret != RET_OK) {
295         MMI_HILOGE("Call RegisterInputDeviceMonitor failed ret:%{public}d", ret);
296     }
297     return ret;
298 }
299 
StubUnregisterInputDeviceMonitor(MessageParcel & data,MessageParcel & reply)300 int32_t MultimodalInputConnectStub::StubUnregisterInputDeviceMonitor(MessageParcel& data, MessageParcel& reply)
301 {
302     CALL_DEBUG_ENTER;
303     int32_t ret = UnregisterDevListener();
304     if (ret != RET_OK) {
305         MMI_HILOGE("Call UnregisterInputDeviceMonitor failed ret:%{public}d", ret);
306     }
307     return ret;
308 }
309 
StubGetKeyboardType(MessageParcel & data,MessageParcel & reply)310 int32_t MultimodalInputConnectStub::StubGetKeyboardType(MessageParcel& data, MessageParcel& reply)
311 {
312     CALL_DEBUG_ENTER;
313     int32_t userData = 0;
314     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
315     int32_t deviceId = -1;
316     READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
317     int32_t ret = GetKeyboardType(userData, deviceId);
318     if (ret != RET_OK) {
319         MMI_HILOGE("Call GetKeyboardType failed ret:%{public}d", ret);
320     }
321     return ret;
322 }
323 
StubAddInputHandler(MessageParcel & data,MessageParcel & reply)324 int32_t MultimodalInputConnectStub::StubAddInputHandler(MessageParcel& data, MessageParcel& reply)
325 {
326     CALL_DEBUG_ENTER;
327     if (!IsRunning()) {
328         MMI_HILOGE("Service is not running");
329         return MMISERVICE_NOT_RUNNING;
330     }
331     int32_t handlerType;
332     READINT32(data, handlerType, IPC_PROXY_DEAD_OBJECT_ERR);
333     if ((handlerType == InputHandlerType::INTERCEPTOR) &&
334         (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE))) {
335         MMI_HILOGE("Interceptor permission check failed");
336         return CHECK_PERMISSION_FAIL;
337     }
338     if ((handlerType == InputHandlerType::MONITOR) && (!PerHelper->CheckMonitor())) {
339         MMI_HILOGE("Monitor permission check failed");
340         return ERROR_NO_PERMISSION;
341     }
342     uint32_t eventType;
343     READUINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR);
344     int32_t ret = AddInputHandler(static_cast<InputHandlerType>(handlerType), eventType);
345     if (ret != RET_OK) {
346         MMI_HILOGE("Call AddInputHandler failed ret:%{public}d", ret);
347         return ret;
348     }
349     return RET_OK;
350 }
351 
StubRemoveInputHandler(MessageParcel & data,MessageParcel & reply)352 int32_t MultimodalInputConnectStub::StubRemoveInputHandler(MessageParcel& data, MessageParcel& reply)
353 {
354     CALL_DEBUG_ENTER;
355     if (!IsRunning()) {
356         MMI_HILOGE("Service is not running");
357         return MMISERVICE_NOT_RUNNING;
358     }
359     int32_t handlerType;
360     READINT32(data, handlerType, IPC_PROXY_DEAD_OBJECT_ERR);
361     if ((handlerType == InputHandlerType::INTERCEPTOR) &&
362         (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE))) {
363         MMI_HILOGE("Interceptor permission check failed");
364         return CHECK_PERMISSION_FAIL;
365     }
366     if ((handlerType == InputHandlerType::MONITOR) && (!PerHelper->CheckMonitor())) {
367         MMI_HILOGE("Monitor permission check failed");
368         return CHECK_PERMISSION_FAIL;
369     }
370     uint32_t eventType;
371     READUINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR);
372     int32_t ret = RemoveInputHandler(static_cast<InputHandlerType>(handlerType), eventType);
373     if (ret != RET_OK) {
374         MMI_HILOGE("Call RemoveInputHandler failed ret:%{public}d", ret);
375         return ret;
376     }
377     return RET_OK;
378 }
379 
StubMarkEventConsumed(MessageParcel & data,MessageParcel & reply)380 int32_t MultimodalInputConnectStub::StubMarkEventConsumed(MessageParcel& data, MessageParcel& reply)
381 {
382     CALL_DEBUG_ENTER;
383     if (!PerHelper->CheckMonitor()) {
384         MMI_HILOGE("Permission check failed");
385         return CHECK_PERMISSION_FAIL;
386     }
387 
388     if (!IsRunning()) {
389         MMI_HILOGE("Service is not running");
390         return MMISERVICE_NOT_RUNNING;
391     }
392     int32_t eventId;
393     READINT32(data, eventId, IPC_PROXY_DEAD_OBJECT_ERR);
394     int32_t ret = MarkEventConsumed(eventId);
395     if (ret != RET_OK) {
396         MMI_HILOGE("Call MarkEventConsumed failed ret:%{public}d", ret);
397         return ret;
398     }
399     return RET_OK;
400 }
401 
StubSubscribeKeyEvent(MessageParcel & data,MessageParcel & reply)402 int32_t MultimodalInputConnectStub::StubSubscribeKeyEvent(MessageParcel& data, MessageParcel& reply)
403 {
404     CALL_DEBUG_ENTER;
405     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
406         MMI_HILOGE("Permission check failed");
407         return CHECK_PERMISSION_FAIL;
408     }
409 
410     if (!IsRunning()) {
411         MMI_HILOGE("Service is not running");
412         return MMISERVICE_NOT_RUNNING;
413     }
414 
415     int32_t subscribeId;
416     READINT32(data, subscribeId, IPC_PROXY_DEAD_OBJECT_ERR);
417 
418     auto keyOption = std::make_shared<KeyOption>();
419     if (!keyOption->ReadFromParcel(data)) {
420         MMI_HILOGE("Read keyOption failed");
421         return IPC_PROXY_DEAD_OBJECT_ERR;
422     }
423     int32_t ret = SubscribeKeyEvent(subscribeId, keyOption);
424     if (ret != RET_OK) {
425         MMI_HILOGE("SubscribeKeyEvent failed, ret:%{public}d", ret);
426         return ret;
427     }
428     return RET_OK;
429 }
430 
StubUnsubscribeKeyEvent(MessageParcel & data,MessageParcel & reply)431 int32_t MultimodalInputConnectStub::StubUnsubscribeKeyEvent(MessageParcel& data, MessageParcel& reply)
432 {
433     CALL_DEBUG_ENTER;
434     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
435         MMI_HILOGE("Permission check failed");
436         return CHECK_PERMISSION_FAIL;
437     }
438 
439     if (!IsRunning()) {
440         MMI_HILOGE("Service is not running");
441         return MMISERVICE_NOT_RUNNING;
442     }
443 
444     int32_t subscribeId;
445     READINT32(data, subscribeId, IPC_PROXY_DEAD_OBJECT_ERR);
446 
447     int32_t ret = UnsubscribeKeyEvent(subscribeId);
448     if (ret != RET_OK) {
449         MMI_HILOGE("UnsubscribeKeyEvent failed, ret:%{public}d", ret);
450         return ret;
451     }
452     return RET_OK;
453 }
454 
StubMoveMouseEvent(MessageParcel & data,MessageParcel & reply)455 int32_t MultimodalInputConnectStub::StubMoveMouseEvent(MessageParcel& data, MessageParcel& reply)
456 {
457     CALL_DEBUG_ENTER;
458     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
459         MMI_HILOGE("Permission check failed");
460         return CHECK_PERMISSION_FAIL;
461     }
462 
463     if (!IsRunning()) {
464         MMI_HILOGE("Service is not running");
465         return MMISERVICE_NOT_RUNNING;
466     }
467     int32_t offsetX;
468     READINT32(data, offsetX, IPC_PROXY_DEAD_OBJECT_ERR);
469     int32_t offsetY;
470     READINT32(data, offsetY, IPC_PROXY_DEAD_OBJECT_ERR);
471 
472     int32_t ret = MoveMouseEvent(offsetX, offsetY);
473     if (ret != RET_OK) {
474         MMI_HILOGE("MoveMouseEvent failed, ret:%{public}d", ret);
475         return ret;
476     }
477     return RET_OK;
478 }
479 
StubInjectKeyEvent(MessageParcel & data,MessageParcel & reply)480 int32_t MultimodalInputConnectStub::StubInjectKeyEvent(MessageParcel& data, MessageParcel& reply)
481 {
482     CALL_DEBUG_ENTER;
483     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
484         MMI_HILOGE("Permission check failed");
485         return CHECK_PERMISSION_FAIL;
486     }
487     if (!IsRunning()) {
488         MMI_HILOGE("Service is not running");
489         return MMISERVICE_NOT_RUNNING;
490     }
491     auto event = KeyEvent::Create();
492     CHKPR(event, ERROR_NULL_POINTER);
493     if (!event->ReadFromParcel(data)) {
494         MMI_HILOGE("Read Key Event failed");
495         return IPC_PROXY_DEAD_OBJECT_ERR;
496     }
497     int32_t ret = InjectKeyEvent(event);
498     if (ret != RET_OK) {
499         MMI_HILOGE("InjectKeyEvent failed, ret:%{public}d", ret);
500         return ret;
501     }
502     return RET_OK;
503 }
504 
StubInjectPointerEvent(MessageParcel & data,MessageParcel & reply)505 int32_t MultimodalInputConnectStub::StubInjectPointerEvent(MessageParcel& data, MessageParcel& reply)
506 {
507     CALL_DEBUG_ENTER;
508     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
509         MMI_HILOGE("Permission check failed");
510         return CHECK_PERMISSION_FAIL;
511     }
512     if (!IsRunning()) {
513         MMI_HILOGE("Service is not running");
514         return MMISERVICE_NOT_RUNNING;
515     }
516     auto pointerEvent = PointerEvent::Create();
517     CHKPR(pointerEvent, ERROR_NULL_POINTER);
518     if (!pointerEvent->ReadFromParcel(data)) {
519         MMI_HILOGE("Read Pointer Event failed");
520         return IPC_PROXY_DEAD_OBJECT_ERR;
521     }
522     int32_t ret = InjectPointerEvent(pointerEvent);
523     if (ret != RET_OK) {
524         MMI_HILOGE("Call InjectPointerEvent failed ret:%{public}d", ret);
525         return ret;
526     }
527     return RET_OK;
528 }
529 
StubSetAnrListener(MessageParcel & data,MessageParcel & reply)530 int32_t MultimodalInputConnectStub::StubSetAnrListener(MessageParcel& data, MessageParcel& reply)
531 {
532     CALL_DEBUG_ENTER;
533     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
534         MMI_HILOGE("Permission check failed");
535         return CHECK_PERMISSION_FAIL;
536     }
537     if (!IsRunning()) {
538         MMI_HILOGE("Service is not running");
539         return MMISERVICE_NOT_RUNNING;
540     }
541     int32_t ret = SetAnrObserver();
542     if (ret != RET_OK) {
543         MMI_HILOGE("Call SetAnrObserver failed, ret:%{public}d", ret);
544     }
545     return ret;
546 }
547 
StubRegisterCooperateMonitor(MessageParcel & data,MessageParcel & reply)548 int32_t MultimodalInputConnectStub::StubRegisterCooperateMonitor(MessageParcel& data, MessageParcel& reply)
549 {
550     CALL_DEBUG_ENTER;
551     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
552         MMI_HILOGE("Permission check failed");
553         return CHECK_PERMISSION_FAIL;
554     }
555     if (!IsRunning()) {
556         MMI_HILOGE("Service is not running");
557         return MMISERVICE_NOT_RUNNING;
558     }
559     int32_t ret = RegisterCooperateListener();
560     if (ret != RET_OK) {
561         MMI_HILOGE("Call RegisterCooperateEvent failed ret:%{public}d", ret);
562     }
563     return ret;
564 }
565 
StubUnregisterCooperateMonitor(MessageParcel & data,MessageParcel & reply)566 int32_t MultimodalInputConnectStub::StubUnregisterCooperateMonitor(MessageParcel& data, MessageParcel& reply)
567 {
568     CALL_DEBUG_ENTER;
569     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
570         MMI_HILOGE("Permission check failed");
571         return CHECK_PERMISSION_FAIL;
572     }
573     if (!IsRunning()) {
574         MMI_HILOGE("Service is not running");
575         return MMISERVICE_NOT_RUNNING;
576     }
577     int32_t ret = UnregisterCooperateListener();
578     if (ret != RET_OK) {
579         MMI_HILOGE("Call RegisterCooperateEvent failed ret:%{public}d", ret);
580     }
581     return ret;
582 }
583 
StubEnableInputDeviceCooperate(MessageParcel & data,MessageParcel & reply)584 int32_t MultimodalInputConnectStub::StubEnableInputDeviceCooperate(MessageParcel& data, MessageParcel& reply)
585 {
586     CALL_DEBUG_ENTER;
587     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
588         MMI_HILOGE("Permission check failed");
589         return CHECK_PERMISSION_FAIL;
590     }
591     if (!IsRunning()) {
592         MMI_HILOGE("Service is not running");
593         return MMISERVICE_NOT_RUNNING;
594     }
595     int32_t userData;
596     bool enabled;
597     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
598     READBOOL(data, enabled, IPC_PROXY_DEAD_OBJECT_ERR);
599     int32_t ret = EnableInputDeviceCooperate(userData, enabled);
600     if (ret != RET_OK) {
601         MMI_HILOGE("Call RegisterCooperateEvent failed ret:%{public}d", ret);
602     }
603     return ret;
604 }
605 
StubStartInputDeviceCooperate(MessageParcel & data,MessageParcel & reply)606 int32_t MultimodalInputConnectStub::StubStartInputDeviceCooperate(MessageParcel& data, MessageParcel& reply)
607 {
608     CALL_DEBUG_ENTER;
609     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
610         MMI_HILOGE("Permission check failed");
611         return CHECK_PERMISSION_FAIL;
612     }
613     if (!IsRunning()) {
614         MMI_HILOGE("Service is not running");
615         return MMISERVICE_NOT_RUNNING;
616     }
617     int32_t userData;
618     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
619     std::string sinkDeviceId;
620     READSTRING(data, sinkDeviceId, IPC_PROXY_DEAD_OBJECT_ERR);
621     int32_t srcInputDeviceId;
622     READINT32(data, srcInputDeviceId, IPC_PROXY_DEAD_OBJECT_ERR);
623     int32_t ret = StartInputDeviceCooperate(userData, sinkDeviceId, srcInputDeviceId);
624     if (ret != RET_OK) {
625         MMI_HILOGE("Call StartInputDeviceCooperate failed ret:%{public}d", ret);
626     }
627     return ret;
628 }
629 
StubStopDeviceCooperate(MessageParcel & data,MessageParcel & reply)630 int32_t MultimodalInputConnectStub::StubStopDeviceCooperate(MessageParcel& data, MessageParcel& reply)
631 {
632     CALL_DEBUG_ENTER;
633     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
634         MMI_HILOGE("Permission check failed");
635         return CHECK_PERMISSION_FAIL;
636     }
637     if (!IsRunning()) {
638         MMI_HILOGE("Service is not running");
639         return MMISERVICE_NOT_RUNNING;
640     }
641     int32_t userData;
642     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
643     int32_t ret = StopDeviceCooperate(userData);
644     if (ret != RET_OK) {
645         MMI_HILOGE("Call RegisterCooperateEvent failed ret:%{public}d", ret);
646     }
647     return ret;
648 }
649 
StubGetInputDeviceCooperateState(MessageParcel & data,MessageParcel & reply)650 int32_t MultimodalInputConnectStub::StubGetInputDeviceCooperateState(MessageParcel& data, MessageParcel& reply)
651 {
652     CALL_DEBUG_ENTER;
653     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
654         MMI_HILOGE("Permission check failed");
655         return CHECK_PERMISSION_FAIL;
656     }
657     if (!IsRunning()) {
658         MMI_HILOGE("Service is not running");
659         return MMISERVICE_NOT_RUNNING;
660     }
661     int32_t userData;
662     READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR);
663     std::string deviceId;
664     READSTRING(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
665     int32_t ret = GetInputDeviceCooperateState(userData, deviceId);
666     if (ret != RET_OK) {
667         MMI_HILOGE("Call RegisterCooperateEvent failed ret:%{public}d", ret);
668     }
669     return ret;
670 }
671 
StubSetInputDevice(MessageParcel & data,MessageParcel & reply)672 int32_t MultimodalInputConnectStub::StubSetInputDevice(MessageParcel& data, MessageParcel& reply)
673 {
674     CALL_DEBUG_ENTER;
675     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
676         MMI_HILOGE("Permission check failed");
677         return CHECK_PERMISSION_FAIL;
678     }
679     if (!IsRunning()) {
680         MMI_HILOGE("Service is not running");
681         return MMISERVICE_NOT_RUNNING;
682     }
683     std::string dhid;
684     READSTRING(data, dhid, IPC_PROXY_DEAD_OBJECT_ERR);
685     std::string screenId;
686     READSTRING(data, screenId, IPC_PROXY_DEAD_OBJECT_ERR);
687     int32_t ret = SetInputDevice(dhid, screenId);
688     if (ret != RET_OK) {
689         MMI_HILOGE("Call SetInputDevice failed ret:%{public}d", ret);
690         return ret;
691     }
692     return RET_OK;
693 }
694 
StubGetFunctionKeyState(MessageParcel & data,MessageParcel & reply)695 int32_t MultimodalInputConnectStub::StubGetFunctionKeyState(MessageParcel &data, MessageParcel &reply)
696 {
697     CALL_DEBUG_ENTER;
698     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
699         MMI_HILOGE("Permission check failed");
700         return CHECK_PERMISSION_FAIL;
701     }
702     if (!IsRunning()) {
703         MMI_HILOGE("Service is not running");
704         return MMISERVICE_NOT_RUNNING;
705     }
706 
707     int32_t funcKey { 0 };
708     bool state  { false };
709     READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR);
710     int32_t ret = GetFunctionKeyState(funcKey, state);
711     if (ret != RET_OK) {
712         MMI_HILOGE("Call GetKeyboardEnableState failed ret:%{public}d", ret);
713         return ret;
714     }
715 
716     WRITEBOOL(reply, state, IPC_PROXY_DEAD_OBJECT_ERR);
717     return RET_OK;
718 }
719 
StubSetFunctionKeyState(MessageParcel & data,MessageParcel & reply)720 int32_t MultimodalInputConnectStub::StubSetFunctionKeyState(MessageParcel &data, MessageParcel &reply)
721 {
722     CALL_DEBUG_ENTER;
723     if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) {
724         MMI_HILOGE("Permission check failed");
725         return CHECK_PERMISSION_FAIL;
726     }
727     if (!IsRunning()) {
728         MMI_HILOGE("Service is not running");
729         return MMISERVICE_NOT_RUNNING;
730     }
731 
732     int32_t funcKey { 0 };
733     bool enable  { false };
734     READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR);
735     READBOOL(data, enable, IPC_PROXY_DEAD_OBJECT_ERR);
736     int32_t ret = SetFunctionKeyState(funcKey, enable);
737     if (ret != RET_OK) {
738         MMI_HILOGE("Call SetFunctionKeyState failed ret:%{public}d", ret);
739     }
740     return ret;
741 }
742 } // namespace MMI
743 } // namespace OHOS
744