• 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 <sys/types.h>
19 #include <sys/socket.h>
20 #include <unistd.h>
21 
22 #include "ipc_skeleton.h"
23 #include "string_ex.h"
24 #include "tokenid_kit.h"
25 
26 
27 #include "bytrace_adapter.h"
28 #include "error_multimodal.h"
29 #include "multimodal_input_connect_def_parcel.h"
30 #include "multimodalinput_ipc_interface_code.h"
31 #include "nap_process.h"
32 #include "permission_helper.h"
33 #include "pixel_map.h"
34 #include "time_cost_chk.h"
35 #ifdef PLAYER_FRAMEWORK_EXISTS
36 #include "screen_capture_monitor.h"
37 #endif
38 
39 #undef MMI_LOG_DOMAIN
40 #define MMI_LOG_DOMAIN MMI_LOG_SERVER
41 #undef MMI_LOG_TAG
42 #define MMI_LOG_TAG "MultimodalInputConnectStub"
43 
44 namespace OHOS {
45 namespace MMI {
46 namespace {
47 constexpr int32_t MAX_AXIS_INFO { 64 };
48 constexpr int32_t UID_TRANSFORM_DIVISOR { 200000 };
49 const std::string SCENEBOARD_NAME { "com.ohos.sceneboard" };
50 constexpr int32_t KEY_MAX_LIST_SIZE { 5 };
51 
g_parseInputDevice(MessageParcel & data,std::shared_ptr<InputDevice> & inputDevice)52 int32_t g_parseInputDevice(MessageParcel &data, std::shared_ptr<InputDevice> &inputDevice)
53 {
54     CHKPR(inputDevice, RET_ERR);
55     int32_t value = 0;
56     READINT32(data, value, IPC_PROXY_DEAD_OBJECT_ERR);
57     inputDevice->SetId(value);
58     READINT32(data, value, IPC_PROXY_DEAD_OBJECT_ERR);
59     inputDevice->SetType(value);
60     std::string element;
61     READSTRING(data, element, IPC_PROXY_DEAD_OBJECT_ERR);
62     inputDevice->SetName(element);
63     READINT32(data, value, IPC_PROXY_DEAD_OBJECT_ERR);
64     inputDevice->SetBus(value);
65     READINT32(data, value, IPC_PROXY_DEAD_OBJECT_ERR);
66     inputDevice->SetVersion(value);
67     READINT32(data, value, IPC_PROXY_DEAD_OBJECT_ERR);
68     inputDevice->SetProduct(value);
69     READINT32(data, value, IPC_PROXY_DEAD_OBJECT_ERR);
70     inputDevice->SetVendor(value);
71     READSTRING(data, element, IPC_PROXY_DEAD_OBJECT_ERR);
72     inputDevice->SetPhys(element);
73     READSTRING(data, element, IPC_PROXY_DEAD_OBJECT_ERR);
74     inputDevice->SetUniq(element);
75     uint64_t caps;
76     READUINT64(data, caps, IPC_PROXY_DEAD_OBJECT_ERR);
77     inputDevice->SetCapabilities(static_cast<unsigned long>(caps));
78     uint32_t size = 0;
79     READUINT32(data, size, IPC_PROXY_DEAD_OBJECT_ERR);
80     if (size > MAX_AXIS_INFO) {
81         return RET_ERR;
82     }
83     InputDevice::AxisInfo axis;
84     for (uint32_t i = 0; i < size; ++i) {
85         int32_t val = 0;
86         READINT32(data, val, IPC_PROXY_DEAD_OBJECT_ERR);
87         axis.SetMinimum(val);
88         READINT32(data, val, IPC_PROXY_DEAD_OBJECT_ERR);
89         axis.SetMaximum(val);
90         READINT32(data, val, IPC_PROXY_DEAD_OBJECT_ERR);
91         axis.SetAxisType(val);
92         READINT32(data, val, IPC_PROXY_DEAD_OBJECT_ERR);
93         axis.SetFuzz(val);
94         READINT32(data, val, IPC_PROXY_DEAD_OBJECT_ERR);
95         axis.SetFlat(val);
96         READINT32(data, val, IPC_PROXY_DEAD_OBJECT_ERR);
97         axis.SetResolution(val);
98         inputDevice->AddAxisInfo(axis);
99     }
100     return RET_OK;
101 }
102 } // namespace
103 const int32_t TUPLE_PID { 0 };
104 const int32_t TUPLE_UID { 1 };
105 const int32_t TUPLE_NAME { 2 };
106 const int32_t DEFAULT_POINTER_COLOR { 0x000000 };
107 constexpr int32_t MAX_N_TRANSMIT_INFRARED_PATTERN { 1024 };
108 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)109 int32_t MultimodalInputConnectStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
110     MessageParcel& reply, MessageOption& option)
111 {
112     int32_t pid = GetCallingPid();
113     TimeCostChk chk("IPC-OnRemoteRequest", "overtime 300(us)", MAX_OVER_TIME, pid,
114         static_cast<int64_t>(code));
115     MMI_HILOGD("RemoteRequest code:%{public}d, tid:%{public}" PRIu64 ", pid:%{public}d", code, GetThisThreadId(), pid);
116 
117     std::u16string descriptor = data.ReadInterfaceToken();
118     if (descriptor != IMultimodalInputConnect::GetDescriptor()) {
119         MMI_HILOGE("Get unexpect descriptor:%{public}s", Str16ToStr8(descriptor).c_str());
120         return ERR_INVALID_STATE;
121     }
122     ResetLogTrace();
123     BytraceAdapter::StartIpcServer(code);
124     int32_t ret = RET_ERR;
125     switch (code) {
126         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ALLOC_SOCKET_FD):
127             ret =  StubHandleAllocSocketFd(data, reply);
128             break;
129         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ADD_INPUT_EVENT_FILTER):
130             ret = StubAddInputEventFilter(data, reply);
131             break;
132         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::RMV_INPUT_EVENT_FILTER):
133             ret = StubRemoveInputEventFilter(data, reply);
134             break;
135         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_MOUSE_SCROLL_ROWS):
136             ret = StubSetMouseScrollRows(data, reply);
137             break;
138         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_MOUSE_SCROLL_ROWS):
139             ret = StubGetMouseScrollRows(data, reply);
140             break;
141         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_POINTER_SIZE):
142             ret = StubSetPointerSize(data, reply);
143             break;
144         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_POINTER_SIZE):
145             ret = StubGetPointerSize(data, reply);
146             break;
147         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_CUSTOM_CURSOR):
148             ret = StubSetCustomCursor(data, reply);
149             break;
150         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_MOUSE_ICON):
151             ret = StubSetMouseIcon(data, reply);
152             break;
153         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_MOUSE_PRIMARY_BUTTON):
154             ret = StubSetMousePrimaryButton(data, reply);
155             break;
156         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_MOUSE_PRIMARY_BUTTON):
157             ret = StubGetMousePrimaryButton(data, reply);
158             break;
159         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_HOVER_SCROLL_STATE):
160             ret = StubSetHoverScrollState(data, reply);
161             break;
162         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_HOVER_SCROLL_STATE):
163             ret = StubGetHoverScrollState(data, reply);
164             break;
165         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_POINTER_VISIBLE):
166             ret = StubSetPointerVisible(data, reply);
167             break;
168         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_POINTER_STYLE):
169             ret = StubSetPointerStyle(data, reply);
170             break;
171         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::NOTIFY_NAP_ONLINE):
172             ret = StubNotifyNapOnline(data, reply);
173             break;
174         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::RMV_INPUT_EVENT_OBSERVER):
175             ret = StubRemoveInputEventObserver(data, reply);
176             break;
177         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_NAP_STATUS):
178             ret = StubSetNapStatus(data, reply);
179             break;
180         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::CLEAN_WIDNOW_STYLE):
181             ret = StubClearWindowPointerStyle(data, reply);
182             break;
183         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_POINTER_STYLE):
184             ret = StubGetPointerStyle(data, reply);
185             break;
186         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::IS_POINTER_VISIBLE):
187             ret = StubIsPointerVisible(data, reply);
188             break;
189         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::REGISTER_DEV_MONITOR):
190             ret = StubRegisterInputDeviceMonitor(data, reply);
191             break;
192         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::UNREGISTER_DEV_MONITOR):
193             ret = StubUnregisterInputDeviceMonitor(data, reply);
194             break;
195         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_DEVICE_IDS):
196             ret = StubGetDeviceIds(data, reply);
197             break;
198         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_DEVICE):
199             ret = StubGetDevice(data, reply);
200             break;
201         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SUPPORT_KEYS):
202             ret = StubSupportKeys(data, reply);
203             break;
204         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_KEYBOARD_TYPE):
205             ret = StubGetKeyboardType(data, reply);
206             break;
207         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_POINTER_COLOR):
208             ret = StubSetPointerColor(data, reply);
209             break;
210         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_POINTER_COLOR):
211             ret = StubGetPointerColor(data, reply);
212             break;
213         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_POINTER_SPEED):
214             ret = StubSetPointerSpeed(data, reply);
215             break;
216         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_POINTER_SPEED):
217             ret = StubGetPointerSpeed(data, reply);
218             break;
219         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SUBSCRIBE_KEY_EVENT):
220             ret = StubSubscribeKeyEvent(data, reply);
221             break;
222         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::UNSUBSCRIBE_KEY_EVENT):
223             ret = StubUnsubscribeKeyEvent(data, reply);
224             break;
225         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SUBSCRIBE_SWITCH_EVENT):
226             ret = StubSubscribeSwitchEvent(data, reply);
227             break;
228         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::UNSUBSCRIBE_SWITCH_EVENT):
229             ret = StubUnsubscribeSwitchEvent(data, reply);
230             break;
231         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::MARK_PROCESSED):
232             ret = StubMarkProcessed(data, reply);
233             break;
234         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ADD_INPUT_HANDLER):
235             ret = StubAddInputHandler(data, reply);
236             break;
237         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::REMOVE_INPUT_HANDLER):
238             ret = StubRemoveInputHandler(data, reply);
239             break;
240         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ADD_PRE_INPUT_HANDLER):
241             ret = StubAddPreInputHandler(data, reply);
242             break;
243         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::REMOVE_PRE_INPUT_HANDLER):
244             ret = StubRemovePreInputHandler(data, reply);
245             break;
246         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::MARK_EVENT_CONSUMED):
247             ret = StubMarkEventConsumed(data, reply);
248             break;
249         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::MOVE_MOUSE):
250             ret = StubMoveMouseEvent(data, reply);
251             break;
252         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SHIFT_APP_POINTER_EVENT):
253             ret = StubShiftAppPointerEvent(data, reply);
254             break;
255         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::INJECT_KEY_EVENT):
256             ret = StubInjectKeyEvent(data, reply);
257             break;
258         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::INJECT_POINTER_EVENT):
259             ret = StubInjectPointerEvent(data, reply);
260             break;
261         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_ANR_OBSERVER):
262             ret = StubSetAnrListener(data, reply);
263             break;
264         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_DISPLAY_BIND_INFO):
265             ret = StubGetDisplayBindInfo(data, reply);
266             break;
267         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_ALL_NAPSTATUS_DATA):
268             ret = StubGetAllMmiSubscribedEvents(data, reply);
269             break;
270         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_DISPLAY_BIND):
271             ret = StubSetDisplayBind(data, reply);
272             break;
273         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_FUNCTION_KEY_STATE):
274             ret = StubGetFunctionKeyState(data, reply);
275             break;
276         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_FUNCTION_KEY_STATE):
277             ret = StubSetFunctionKeyState(data, reply);
278             break;
279         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_POINTER_LOCATION):
280             ret = StubSetPointerLocation(data, reply);
281             break;
282         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_CAPTURE_MODE):
283             ret = StubSetMouseCaptureMode(data, reply);
284             break;
285         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_WINDOW_PID):
286             ret = StubGetWindowPid(data, reply);
287             break;
288         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::APPEND_EXTRA_DATA):
289             ret = StubAppendExtraData(data, reply);
290             break;
291         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ENABLE_INPUT_DEVICE):
292             ret = StubEnableInputDevice(data, reply);
293             break;
294         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ENABLE_COMBINE_KEY):
295             ret = StubEnableCombineKey(data, reply);
296             break;
297         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_KEY_DOWN_DURATION):
298             ret = StubSetKeyDownDuration(data, reply);
299             break;
300         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_SCROLL_SWITCH):
301             ret = StubSetTouchpadScrollSwitch(data, reply);
302             break;
303         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_SCROLL_SWITCH):
304             ret = StubGetTouchpadScrollSwitch(data, reply);
305             break;
306         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_SCROLL_DIRECT_SWITCH):
307             ret = StubSetTouchpadScrollDirection(data, reply);
308             break;
309         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_SCROLL_DIRECT_SWITCH):
310             ret = StubGetTouchpadScrollDirection(data, reply);
311             break;
312         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_TAP_SWITCH):
313             ret = StubSetTouchpadTapSwitch(data, reply);
314             break;
315         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_TAP_SWITCH):
316             ret = StubGetTouchpadTapSwitch(data, reply);
317             break;
318         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_POINTER_SPEED):
319             ret = StubSetTouchpadPointerSpeed(data, reply);
320             break;
321         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_POINTER_SPEED):
322             ret = StubGetTouchpadPointerSpeed(data, reply);
323             break;
324         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_KEYBOARD_REPEAT_DELAY):
325             ret = StubSetKeyboardRepeatDelay(data, reply);
326             break;
327         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_KEYBOARD_REPEAT_RATE):
328             ret = StubSetKeyboardRepeatRate(data, reply);
329             break;
330         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_PINCH_SWITCH):
331             ret = StubSetTouchpadPinchSwitch(data, reply);
332             break;
333         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_PINCH_SWITCH):
334             ret = StubGetTouchpadPinchSwitch(data, reply);
335             break;
336         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_SWIPE_SWITCH):
337             ret = StubSetTouchpadSwipeSwitch(data, reply);
338             break;
339         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_SWIPE_SWITCH):
340             ret = StubGetTouchpadSwipeSwitch(data, reply);
341             break;
342         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_RIGHT_CLICK_TYPE):
343             ret = StubSetTouchpadRightClickType(data, reply);
344             break;
345         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_RIGHT_CLICK_TYPE):
346             ret = StubGetTouchpadRightClickType(data, reply);
347             break;
348         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_TP_ROTATE_SWITCH):
349             return StubSetTouchpadRotateSwitch(data, reply);
350             break;
351         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_TP_ROTATE_SWITCH):
352             return StubGetTouchpadRotateSwitch(data, reply);
353             break;
354         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_DOUBLE_TAP_DRAG_STATE):
355             ret = StubSetTouchpadDoubleTapAndDragState(data, reply);
356             break;
357         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_DOUBLE_TAP_DRAG_STATE):
358             ret = StubGetTouchpadDoubleTapAndDragState(data, reply);
359             break;
360         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_KEYBOARD_REPEAT_DELAY):
361             ret = StubGetKeyboardRepeatDelay(data, reply);
362             break;
363         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_KEYBOARD_REPEAT_RATE):
364             ret = StubGetKeyboardRepeatRate(data, reply);
365             break;
366         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_MOUSE_HOT_SPOT):
367             ret = StubSetMouseHotSpot(data, reply);
368             break;
369         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_SHIELD_STATUS):
370             ret = StubSetShieldStatus(data, reply);
371             break;
372         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_SHIELD_STATUS):
373             ret = StubGetShieldStatus(data, reply);
374             break;
375         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_KEY_STATE):
376             ret = StubGetKeyState(data, reply);
377             break;
378         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::NATIVE_AUTHORIZE):
379             ret = StubAuthorize(data, reply);
380             break;
381         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::NATIVE_CANCEL_INJECTION):
382             ret = StubCancelInjection(data, reply);
383             break;
384         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_PIXEL_MAP_DATA):
385             ret = StubSetPixelMapData(data, reply);
386             break;
387         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::NATIVE_INFRARED_OWN):
388             ret = StubHasIrEmitter(data, reply);
389             break;
390         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::NATIVE_INFRARED_FREQUENCY):
391             ret = StubGetInfraredFrequencies(data, reply);
392             break;
393         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::NATIVE_CANCEL_TRANSMIT):
394             ret = StubTransmitInfrared(data, reply);
395             break;
396         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_CURRENT_USERID):
397             ret = StubSetCurrentUser(data, reply);
398             break;
399         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ADD_VIRTUAL_INPUT_DEVICE):
400             ret = StubAddVirtualInputDevice(data, reply);
401             break;
402         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::REMOVE_VIRTUAL_INPUT_DEVICE):
403             ret = StubRemoveVirtualInputDevice(data, reply);
404             break;
405         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ENABLE_HARDWARE_CURSOR_STATS):
406             return StubEnableHardwareCursorStats(data, reply);
407             break;
408         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_HARDWARE_CURSOR_STATS):
409             return StubGetHardwareCursorStats(data, reply);
410             break;
411 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
412         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_POINTER_SNAPSHOT):
413             ret = StubGetPointerSnapshot(data, reply);
414             break;
415 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
416 #ifdef OHOS_BUILD_ENABLE_ANCO
417         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::ADD_ANCO_CHANNEL):
418             ret = StubAncoAddChannel(data, reply);
419             break;
420         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::REMOVE_ANCO_CHANNEL):
421             ret = StubAncoRemoveChannel(data, reply);
422             break;
423 #endif // OHOS_BUILD_ENABLE_ANCO
424         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::TRANSFER_BINDER_CLIENT_SERVICE):
425             ret = StubTransferBinderClientService(data, reply);
426             break;
427         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_SYSTEM_EVENT_TIME_INTERVAL):
428             ret = StubGetIntervalSinceLastInput(data, reply);
429             break;
430         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::GET_CURSOR_SURFACE_ID):
431             ret = StubGetCursorSurfaceId(data, reply);
432             break;
433         case static_cast<uint32_t>(MultimodalinputConnectInterfaceCode::SET_CUSTOM_MOUSE_CURSOR):
434             ret = StubSetCustomMouseCursor(data, reply);
435             break;
436         default: {
437             MMI_HILOGE("Unknown code:%{public}u, go switch default", code);
438             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
439         }
440     }
441     BytraceAdapter::StopIpcServer();
442     return ret;
443 }
444 
StubHandleAllocSocketFd(MessageParcel & data,MessageParcel & reply)445 int32_t MultimodalInputConnectStub::StubHandleAllocSocketFd(MessageParcel& data, MessageParcel& reply)
446 {
447     int32_t pid = GetCallingPid();
448     if (!IsRunning()) {
449         MMI_HILOGE("Service is not running. pid:%{public}d, go switch default", pid);
450         return MMISERVICE_NOT_RUNNING;
451     }
452     sptr<ConnectReqParcel> req = data.ReadParcelable<ConnectReqParcel>();
453     CHKPR(req, ERROR_NULL_POINTER);
454     MMI_HILOGD("clientName:%{public}s, moduleId:%{public}d", req->data.clientName.c_str(), req->data.moduleId);
455 
456     int32_t clientFd = INVALID_SOCKET_FD;
457     int32_t tokenType = PER_HELPER->GetTokenType();
458     int32_t ret = AllocSocketFd(req->data.clientName, req->data.moduleId, clientFd, tokenType);
459     if (ret != RET_OK) {
460         MMI_HILOGE("AllocSocketFd failed pid:%{public}d, go switch default", pid);
461         if (clientFd >= 0) {
462             close(clientFd);
463         }
464         return ret;
465     }
466 
467     if (!reply.WriteFileDescriptor(clientFd)) {
468         MMI_HILOGE("Write file descriptor failed");
469         close(clientFd);
470         return IPC_STUB_WRITE_PARCEL_ERR;
471     }
472 
473     WRITEINT32(reply, tokenType, IPC_STUB_WRITE_PARCEL_ERR);
474     MMI_HILOGI("Send clientFd to client, clientFd:%{public}d, tokenType:%{public}d", clientFd, tokenType);
475     close(clientFd);
476     return RET_OK;
477 }
478 
StubAddInputEventFilter(MessageParcel & data,MessageParcel & reply)479 int32_t MultimodalInputConnectStub::StubAddInputEventFilter(MessageParcel& data, MessageParcel& reply)
480 {
481     CALL_DEBUG_ENTER;
482     if (!PER_HELPER->VerifySystemApp()) {
483         MMI_HILOGE("Verify system APP failed");
484         return ERROR_NOT_SYSAPI;
485     }
486     if (!PER_HELPER->CheckInputEventFilter()) {
487         MMI_HILOGE("Filter permission check failed");
488         return ERROR_NO_PERMISSION;
489     }
490     sptr<IRemoteObject> client = data.ReadRemoteObject();
491     CHKPR(client, ERR_INVALID_VALUE);
492     sptr<IEventFilter> filter = iface_cast<IEventFilter>(client);
493     CHKPR(filter, ERROR_NULL_POINTER);
494     int32_t filterId = -1;
495     READINT32(data, filterId, IPC_PROXY_DEAD_OBJECT_ERR);
496     int32_t priority = 0;
497     READINT32(data, priority, IPC_PROXY_DEAD_OBJECT_ERR);
498     uint32_t deviceTags = 0;
499     READUINT32(data, deviceTags, IPC_PROXY_DEAD_OBJECT_ERR);
500     int32_t ret = AddInputEventFilter(filter, filterId, priority, deviceTags);
501     if (ret != RET_OK) {
502         MMI_HILOGE("Call AddInputEventFilter failed:%{public}d", ret);
503         return ret;
504     }
505     MMI_HILOGD("Success pid:%{public}d", GetCallingPid());
506     return RET_OK;
507 }
508 
StubRemoveInputEventFilter(MessageParcel & data,MessageParcel & reply)509 int32_t MultimodalInputConnectStub::StubRemoveInputEventFilter(MessageParcel& data, MessageParcel& reply)
510 {
511     CALL_DEBUG_ENTER;
512     if (!PER_HELPER->VerifySystemApp()) {
513         MMI_HILOGE("Verify system APP failed");
514         return ERROR_NOT_SYSAPI;
515     }
516     if (!PER_HELPER->CheckInputEventFilter()) {
517         MMI_HILOGE("Filter permission check failed");
518         return ERROR_NO_PERMISSION;
519     }
520     int32_t filterId = -1;
521     READINT32(data, filterId, IPC_PROXY_DEAD_OBJECT_ERR);
522     int32_t ret = RemoveInputEventFilter(filterId);
523     if (ret != RET_OK) {
524         MMI_HILOGE("Call RemoveInputEventFilter failed:%{public}d", ret);
525         return ret;
526     }
527     MMI_HILOGD("Success pid:%{public}d", GetCallingPid());
528     return RET_OK;
529 }
530 
StubSetMouseScrollRows(MessageParcel & data,MessageParcel & reply)531 int32_t MultimodalInputConnectStub::StubSetMouseScrollRows(MessageParcel& data, MessageParcel& reply)
532 {
533     CALL_DEBUG_ENTER;
534     if (!IsRunning()) {
535         MMI_HILOGE("Service is not running");
536         return MMISERVICE_NOT_RUNNING;
537     }
538 
539     if (!PER_HELPER->VerifySystemApp()) {
540         MMI_HILOGE("Verify system APP failed");
541         return ERROR_NOT_SYSAPI;
542     }
543 
544     int32_t rows = 3; // the initial number of scrolling rows is 3.
545     READINT32(data, rows, IPC_PROXY_DEAD_OBJECT_ERR);
546     int32_t ret = SetMouseScrollRows(rows);
547     if (ret != RET_OK) {
548         MMI_HILOGE("Call SetMouseScrollRows failed:%{public}d", ret);
549         return ret;
550     }
551     MMI_HILOGD("Success rows:%{public}d, pid:%{public}d", rows, GetCallingPid());
552     return RET_OK;
553 }
554 
StubSetCustomCursor(MessageParcel & data,MessageParcel & reply)555 int32_t MultimodalInputConnectStub::StubSetCustomCursor(MessageParcel& data, MessageParcel& reply)
556 {
557     CALL_DEBUG_ENTER;
558     if (!IsRunning()) {
559         MMI_HILOGE("Service is not running");
560         return MMISERVICE_NOT_RUNNING;
561     }
562     int32_t windowId = 0;
563     int32_t windowPid = INVALID_PID;
564     int32_t focusX = 0;
565     int32_t focusY = 0;
566     READINT32(data, windowPid, IPC_PROXY_DEAD_OBJECT_ERR);
567     READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR);
568     READINT32(data, focusX, IPC_PROXY_DEAD_OBJECT_ERR);
569     READINT32(data, focusY, IPC_PROXY_DEAD_OBJECT_ERR);
570     if (windowId <= 0) {
571         MMI_HILOGE("Invalid windowId:%{public}d", windowId);
572         return RET_ERR;
573     }
574     OHOS::Media::PixelMap* pixelMap = Media::PixelMap::Unmarshalling(data);
575     CHKPR(pixelMap, RET_ERR);
576     int32_t ret = SetCustomCursor(windowPid, windowId, focusX, focusY, (void*)pixelMap);
577     if (ret != RET_OK) {
578         MMI_HILOGE("Call SetCustomCursor failed:%{public}d", ret);
579         return ret;
580     }
581     return RET_OK;
582 }
583 
StubSetMouseIcon(MessageParcel & data,MessageParcel & reply)584 int32_t MultimodalInputConnectStub::StubSetMouseIcon(MessageParcel& data, MessageParcel& reply)
585 {
586     CALL_DEBUG_ENTER;
587     if (!IsRunning()) {
588         MMI_HILOGE("Service is not running");
589         return MMISERVICE_NOT_RUNNING;
590     }
591     int32_t windowId = 0;
592     OHOS::Media::PixelMap *pixelMap = OHOS::Media::PixelMap::Unmarshalling(data);
593     CHKPR(pixelMap, RET_ERR);
594     READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR);
595     MMI_HILOGD("Reading windowid the tlv count:%{public}d", windowId);
596     if (windowId <= 0) {
597         MMI_HILOGE("Invalid windowId:%{public}d", windowId);
598         return RET_ERR;
599     }
600 
601     int32_t ret = SetMouseIcon(windowId, (void*)pixelMap);
602     if (ret != RET_OK) {
603         MMI_HILOGE("Call SetMouseIcon failed:%{public}d", ret);
604         return ret;
605     }
606     return RET_OK;
607 }
608 
StubSetMouseHotSpot(MessageParcel & data,MessageParcel & reply)609 int32_t MultimodalInputConnectStub::StubSetMouseHotSpot(MessageParcel& data, MessageParcel& reply)
610 {
611     CALL_DEBUG_ENTER;
612     if (!PER_HELPER->VerifySystemApp()) {
613         MMI_HILOGE("Verify system APP failed");
614         return ERROR_NOT_SYSAPI;
615     }
616     if (!IsRunning()) {
617         MMI_HILOGE("Service is not running");
618         return MMISERVICE_NOT_RUNNING;
619     }
620     int32_t windowId = 0;
621     int32_t winPid = -1;
622     READINT32(data, winPid, IPC_PROXY_DEAD_OBJECT_ERR);
623     READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR);
624     if (windowId <= 0) {
625         MMI_HILOGE("Invalid windowId:%{public}d", windowId);
626         return RET_ERR;
627     }
628     int32_t hotSpotX = 0;
629     READINT32(data, hotSpotX, IPC_PROXY_DEAD_OBJECT_ERR);
630     int32_t hotSpotY = 0;
631     READINT32(data, hotSpotY, IPC_PROXY_DEAD_OBJECT_ERR);
632     int32_t ret = SetMouseHotSpot(winPid, windowId, hotSpotX, hotSpotY);
633     if (ret != RET_OK) {
634         MMI_HILOGE("Call SetMouseHotSpot failed:%{public}d", ret);
635         return ret;
636     }
637     return RET_OK;
638 }
639 
StubGetMouseScrollRows(MessageParcel & data,MessageParcel & reply)640 int32_t MultimodalInputConnectStub::StubGetMouseScrollRows(MessageParcel& data, MessageParcel& reply)
641 {
642     CALL_DEBUG_ENTER;
643     if (!IsRunning()) {
644         MMI_HILOGE("Service is not running");
645         return MMISERVICE_NOT_RUNNING;
646     }
647 
648     if (!PER_HELPER->VerifySystemApp()) {
649         MMI_HILOGE("Verify system APP failed");
650         return ERROR_NOT_SYSAPI;
651     }
652 
653     int32_t rows = 3; // the initial number of scrolling rows is 3.
654     int32_t ret = GetMouseScrollRows(rows);
655     if (ret != RET_OK) {
656         MMI_HILOGE("Call GetMouseScrollRows failed ret:%{public}d", ret);
657         return ret;
658     }
659     WRITEINT32(reply, rows, IPC_STUB_WRITE_PARCEL_ERR);
660     MMI_HILOGD("Mouse scroll rows:%{public}d, ret:%{public}d", rows, ret);
661     return RET_OK;
662 }
663 
StubSetPointerSize(MessageParcel & data,MessageParcel & reply)664 int32_t MultimodalInputConnectStub::StubSetPointerSize(MessageParcel& data, MessageParcel& reply)
665 {
666     CALL_DEBUG_ENTER;
667     if (!IsRunning()) {
668         MMI_HILOGE("Service is not running");
669         return MMISERVICE_NOT_RUNNING;
670     }
671 
672     if (!PER_HELPER->VerifySystemApp()) {
673         MMI_HILOGE("Verify system APP failed");
674         return ERROR_NOT_SYSAPI;
675     }
676 
677     int32_t size = 1; // the initial pointer size is 1.
678     READINT32(data, size, IPC_PROXY_DEAD_OBJECT_ERR);
679     int32_t ret = SetPointerSize(size);
680     if (ret != RET_OK) {
681         MMI_HILOGE("Call SetPointerSize failed ret:%{public}d", ret);
682         return ret;
683     }
684     MMI_HILOGD("Success size:%{public}d, pid:%{public}d", size, GetCallingPid());
685     return RET_OK;
686 }
687 
StubSetNapStatus(MessageParcel & data,MessageParcel & reply)688 int32_t MultimodalInputConnectStub::StubSetNapStatus(MessageParcel& data, MessageParcel& reply)
689 {
690     CALL_DEBUG_ENTER;
691     if (!PER_HELPER->VerifySystemApp()) {
692         MMI_HILOGE("Verify system APP failed");
693         return ERROR_NOT_SYSAPI;
694     }
695     if (!IsRunning()) {
696         MMI_HILOGE("Service is not running");
697         return MMISERVICE_NOT_RUNNING;
698     }
699     int32_t napPid = -1;
700     int32_t napUid = -1;
701     std::string napBundleName;
702     int32_t napStatus = 0;
703     READINT32(data, napPid, IPC_PROXY_DEAD_OBJECT_ERR);
704     READINT32(data, napUid, IPC_PROXY_DEAD_OBJECT_ERR);
705     READSTRING(data, napBundleName, IPC_PROXY_DEAD_OBJECT_ERR);
706     READINT32(data, napStatus, IPC_PROXY_DEAD_OBJECT_ERR);
707 
708     int32_t ret = SetNapStatus(napPid, napUid, napBundleName, napStatus);
709     if (ret != RET_OK) {
710         MMI_HILOGE("Call StubSetNapStatus failed ret:%{public}d", ret);
711         return ret;
712     }
713     MMI_HILOGD("Success set napStatus:%{public}d, pid:%{public}d", napStatus, GetCallingPid());
714     return RET_OK;
715 }
716 
StubGetPointerSize(MessageParcel & data,MessageParcel & reply)717 int32_t MultimodalInputConnectStub::StubGetPointerSize(MessageParcel& data, MessageParcel& reply)
718 {
719     CALL_DEBUG_ENTER;
720     if (!IsRunning()) {
721         MMI_HILOGE("Service is not running");
722         return MMISERVICE_NOT_RUNNING;
723     }
724 
725     if (!PER_HELPER->VerifySystemApp()) {
726         MMI_HILOGE("Verify system APP failed");
727         return ERROR_NOT_SYSAPI;
728     }
729 
730     int32_t size = 1; // the initial pointer size is 1.
731     int32_t ret = GetPointerSize(size);
732     if (ret != RET_OK) {
733         MMI_HILOGE("Call GetPoinerSize failed ret:%{public}d", ret);
734         return ret;
735     }
736     WRITEINT32(reply, size, IPC_STUB_WRITE_PARCEL_ERR);
737     MMI_HILOGD("Pointer size:%{public}d, ret:%{public}d", size, ret);
738     return RET_OK;
739 }
740 
StubGetCursorSurfaceId(MessageParcel & data,MessageParcel & reply)741 int32_t MultimodalInputConnectStub::StubGetCursorSurfaceId(MessageParcel& data, MessageParcel& reply)
742 {
743     if (!IsRunning()) {
744         MMI_HILOGE("Service is not running");
745         return MMISERVICE_NOT_RUNNING;
746     }
747     if (!PER_HELPER->VerifySystemApp()) {
748         MMI_HILOGE("Verify system APP failed");
749         return ERROR_NOT_SYSAPI;
750     }
751     uint64_t surfaceId {};
752     auto ret = GetCursorSurfaceId(surfaceId);
753     if (ret != RET_OK) {
754         MMI_HILOGE("GetCursorSurfaceId fail, ret:%{public}d", ret);
755         return ret;
756     }
757     WRITEUINT64(reply, surfaceId, IPC_STUB_WRITE_PARCEL_ERR);
758     return RET_OK;
759 }
760 
StubSetMousePrimaryButton(MessageParcel & data,MessageParcel & reply)761 int32_t MultimodalInputConnectStub::StubSetMousePrimaryButton(MessageParcel& data, MessageParcel& reply)
762 {
763     CALL_DEBUG_ENTER;
764     if (!PER_HELPER->VerifySystemApp()) {
765         MMI_HILOGE("Verify system APP failed");
766         return ERROR_NOT_SYSAPI;
767     }
768 
769     int32_t primaryButton = -1;
770     READINT32(data, primaryButton, IPC_PROXY_DEAD_OBJECT_ERR);
771     int32_t ret = SetMousePrimaryButton(primaryButton);
772     if (ret != RET_OK) {
773         MMI_HILOGE("Call SetMousePrimaryButton failed ret:%{public}d", ret);
774         return ret;
775     }
776     MMI_HILOGD("Success primaryButton:%{public}d, pid:%{public}d", primaryButton, GetCallingPid());
777     return RET_OK;
778 }
779 
StubGetMousePrimaryButton(MessageParcel & data,MessageParcel & reply)780 int32_t MultimodalInputConnectStub::StubGetMousePrimaryButton(MessageParcel& data, MessageParcel& reply)
781 {
782     CALL_DEBUG_ENTER;
783     if (!PER_HELPER->VerifySystemApp()) {
784         MMI_HILOGE("Verify system APP failed");
785         return ERROR_NOT_SYSAPI;
786     }
787 
788     int32_t primaryButton = -1;
789     int32_t ret = GetMousePrimaryButton(primaryButton);
790     if (ret != RET_OK) {
791         MMI_HILOGE("Call GetMousePrimaryButton failed ret:%{public}d", ret);
792         return ret;
793     }
794     WRITEINT32(reply, primaryButton, IPC_STUB_WRITE_PARCEL_ERR);
795     MMI_HILOGD("Mouse primaryButton:%{public}d, ret:%{public}d", primaryButton, ret);
796     return RET_OK;
797 }
798 
StubSetHoverScrollState(MessageParcel & data,MessageParcel & reply)799 int32_t MultimodalInputConnectStub::StubSetHoverScrollState(MessageParcel& data, MessageParcel& reply)
800 {
801     CALL_DEBUG_ENTER;
802     if (!PER_HELPER->VerifySystemApp()) {
803         MMI_HILOGE("Verify system APP failed");
804         return ERROR_NOT_SYSAPI;
805     }
806 
807     bool state = true;
808     READBOOL(data, state, IPC_PROXY_DEAD_OBJECT_ERR);
809     int32_t ret = SetHoverScrollState(state);
810     if (ret != RET_OK) {
811         MMI_HILOGE("Call SetHoverScrollState failed, ret:%{public}d", ret);
812         return ret;
813     }
814     MMI_HILOGD("Success state:%{public}d, pid:%{public}d", state, GetCallingPid());
815     return RET_OK;
816 }
817 
StubGetHoverScrollState(MessageParcel & data,MessageParcel & reply)818 int32_t MultimodalInputConnectStub::StubGetHoverScrollState(MessageParcel& data, MessageParcel& reply)
819 {
820     CALL_DEBUG_ENTER;
821     if (!PER_HELPER->VerifySystemApp()) {
822         MMI_HILOGE("Verify system APP failed");
823         return ERROR_NOT_SYSAPI;
824     }
825 
826     bool state = true;
827     int32_t ret = GetHoverScrollState(state);
828     if (ret != RET_OK) {
829         MMI_HILOGE("Call GetHoverScrollState failed, ret:%{public}d", ret);
830         return ret;
831     }
832     WRITEBOOL(reply, state, IPC_STUB_WRITE_PARCEL_ERR);
833     MMI_HILOGD("Mouse hover scroll state:%{public}d, ret:%{public}d", state, ret);
834     return RET_OK;
835 }
836 
StubSetPointerVisible(MessageParcel & data,MessageParcel & reply)837 int32_t MultimodalInputConnectStub::StubSetPointerVisible(MessageParcel& data, MessageParcel& reply)
838 {
839     CALL_DEBUG_ENTER;
840     bool visible = false;
841     READBOOL(data, visible, IPC_PROXY_DEAD_OBJECT_ERR);
842     int32_t priority = 0;
843     READINT32(data, priority, IPC_PROXY_DEAD_OBJECT_ERR);
844     int32_t ret = SetPointerVisible(visible, priority);
845     if (ret != RET_OK) {
846         MMI_HILOGE("Call SetPointerVisible failed ret:%{public}d", ret);
847         return ret;
848     }
849     MMI_HILOGD("Success visible:%{public}d,pid:%{public}d", visible, GetCallingPid());
850     return RET_OK;
851 }
852 
StubIsPointerVisible(MessageParcel & data,MessageParcel & reply)853 int32_t MultimodalInputConnectStub::StubIsPointerVisible(MessageParcel& data, MessageParcel& reply)
854 {
855     CALL_DEBUG_ENTER;
856     bool visible = false;
857     int32_t ret = IsPointerVisible(visible);
858     if (ret != RET_OK) {
859         MMI_HILOGE("Call IsPointerVisible failed ret:%{public}d", ret);
860         return ret;
861     }
862     WRITEBOOL(reply, visible, IPC_STUB_WRITE_PARCEL_ERR);
863     MMI_HILOGD("visible:%{public}d, ret:%{public}d, pid:%{public}d", visible, ret, GetCallingPid());
864     return RET_OK;
865 }
866 
StubMarkProcessed(MessageParcel & data,MessageParcel & reply)867 int32_t MultimodalInputConnectStub::StubMarkProcessed(MessageParcel& data, MessageParcel& reply)
868 {
869     CALL_DEBUG_ENTER;
870     if (!IsRunning()) {
871         MMI_HILOGE("Service is not running");
872         return MMISERVICE_NOT_RUNNING;
873     }
874     int32_t eventType;
875     READINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR);
876     int32_t eventId;
877     READINT32(data, eventId, IPC_PROXY_DEAD_OBJECT_ERR);
878     int32_t ret = MarkProcessed(eventType, eventId);
879     if (ret != RET_OK) {
880         MMI_HILOGD("MarkProcessed failed, ret:%{public}d", ret);
881         return ret;
882     }
883     return RET_OK;
884 }
885 
StubSetPointerColor(MessageParcel & data,MessageParcel & reply)886 int32_t MultimodalInputConnectStub::StubSetPointerColor(MessageParcel& data, MessageParcel& reply)
887 {
888     CALL_DEBUG_ENTER;
889     if (!IsRunning()) {
890         MMI_HILOGE("Service is not running");
891         return MMISERVICE_NOT_RUNNING;
892     }
893 
894     if (!PER_HELPER->VerifySystemApp()) {
895         MMI_HILOGE("Verify system APP failed");
896         return ERROR_NOT_SYSAPI;
897     }
898 
899     int32_t color = DEFAULT_POINTER_COLOR;
900     READINT32(data, color, IPC_PROXY_DEAD_OBJECT_ERR);
901     int32_t ret = SetPointerColor(color);
902     if (ret != RET_OK) {
903         MMI_HILOGE("Call SetPointerColor failed ret:%{public}d", ret);
904         return ret;
905     }
906     MMI_HILOGD("Success color:%{public}d, pid:%{public}d", color, GetCallingPid());
907     return RET_OK;
908 }
909 
StubGetPointerColor(MessageParcel & data,MessageParcel & reply)910 int32_t MultimodalInputConnectStub::StubGetPointerColor(MessageParcel& data, MessageParcel& reply)
911 {
912     CALL_DEBUG_ENTER;
913     if (!IsRunning()) {
914         MMI_HILOGE("Service is not running");
915         return MMISERVICE_NOT_RUNNING;
916     }
917 
918     if (!PER_HELPER->VerifySystemApp()) {
919         MMI_HILOGE("Verify system APP failed");
920         return ERROR_NOT_SYSAPI;
921     }
922 
923     int32_t color = DEFAULT_POINTER_COLOR;
924     int32_t ret = GetPointerColor(color);
925     if (ret != RET_OK) {
926         MMI_HILOGE("Call GetPointerColor failed ret:%{public}d", ret);
927         return ret;
928     }
929     WRITEINT32(reply, color, IPC_STUB_WRITE_PARCEL_ERR);
930     MMI_HILOGD("Pointer color:%{public}d, ret:%{public}d", color, ret);
931     return RET_OK;
932 }
933 
StubSetPointerSpeed(MessageParcel & data,MessageParcel & reply)934 int32_t MultimodalInputConnectStub::StubSetPointerSpeed(MessageParcel& data, MessageParcel& reply)
935 {
936     CALL_DEBUG_ENTER;
937     if (!PER_HELPER->VerifySystemApp()) {
938         MMI_HILOGE("Verify system APP failed");
939         return ERROR_NOT_SYSAPI;
940     }
941 
942     int32_t speed = 0;
943     READINT32(data, speed, IPC_PROXY_DEAD_OBJECT_ERR);
944     int32_t ret = SetPointerSpeed(speed);
945     if (ret != RET_OK) {
946         MMI_HILOGE("Set pointer speed failed ret:%{public}d", ret);
947         return RET_ERR;
948     }
949     return RET_OK;
950 }
951 
StubGetPointerSpeed(MessageParcel & data,MessageParcel & reply)952 int32_t MultimodalInputConnectStub::StubGetPointerSpeed(MessageParcel& data, MessageParcel& reply)
953 {
954     CALL_DEBUG_ENTER;
955     if (!PER_HELPER->VerifySystemApp()) {
956         MMI_HILOGE("Verify system APP failed");
957         return ERROR_NOT_SYSAPI;
958     }
959 
960     int32_t speed = 0;
961     int32_t ret = GetPointerSpeed(speed);
962     if (ret != RET_OK) {
963         MMI_HILOGE("Call get pointer speed failed ret:%{public}d", ret);
964         return RET_ERR;
965     }
966     WRITEINT32(reply, speed, IPC_STUB_WRITE_PARCEL_ERR);
967     MMI_HILOGD("Pointer speed:%{public}d, ret:%{public}d", speed, ret);
968     return RET_OK;
969 }
970 
StubNotifyNapOnline(MessageParcel & data,MessageParcel & reply)971 int32_t MultimodalInputConnectStub::StubNotifyNapOnline(MessageParcel& data, MessageParcel& reply)
972 {
973     CALL_DEBUG_ENTER;
974     int32_t ret = NotifyNapOnline();
975     return ret;
976 }
977 
StubRemoveInputEventObserver(MessageParcel & data,MessageParcel & reply)978 int32_t MultimodalInputConnectStub::StubRemoveInputEventObserver(MessageParcel& data, MessageParcel& reply)
979 {
980     CALL_DEBUG_ENTER;
981     if (!PER_HELPER->VerifySystemApp()) {
982         MMI_HILOGE("Verify system APP failed");
983         return ERROR_NOT_SYSAPI;
984     }
985     int32_t ret = RemoveInputEventObserver();
986     return ret;
987 }
988 
StubSetPointerStyle(MessageParcel & data,MessageParcel & reply)989 int32_t MultimodalInputConnectStub::StubSetPointerStyle(MessageParcel& data, MessageParcel& reply)
990 {
991     CALL_DEBUG_ENTER;
992     int32_t windowId = 0;
993     READINT32(data, windowId, RET_ERR);
994     PointerStyle pointerStyle;
995     READINT32(data, pointerStyle.size, RET_ERR);
996     READINT32(data, pointerStyle.color, RET_ERR);
997     READINT32(data, pointerStyle.id, RET_ERR);
998     bool isUiExtension;
999     READBOOL(data, isUiExtension, RET_ERR);
1000     if (windowId == -1 && !PER_HELPER->VerifySystemApp()) {
1001         MMI_HILOGE("can not set global winid, because this is not sys app");
1002         return ERROR_NOT_SYSAPI;
1003     }
1004     int32_t ret = SetPointerStyle(windowId, pointerStyle, isUiExtension);
1005     if (ret != RET_OK) {
1006         MMI_HILOGE("Call SetPointerStyle failed ret:%{public}d", ret);
1007         return ret;
1008     }
1009     MMI_HILOGD("Successfully set windowId:%{public}d, icon:%{public}d", windowId, pointerStyle.id);
1010     return RET_OK;
1011 }
1012 
StubClearWindowPointerStyle(MessageParcel & data,MessageParcel & reply)1013 int32_t MultimodalInputConnectStub::StubClearWindowPointerStyle(MessageParcel& data, MessageParcel& reply)
1014 {
1015     CALL_DEBUG_ENTER;
1016     if (!PER_HELPER->VerifySystemApp()) {
1017         MMI_HILOGE("Verify system APP failed");
1018         return ERROR_NOT_SYSAPI;
1019     }
1020     int32_t pid = 0;
1021     int32_t windowId = 0;
1022     READINT32(data, pid, RET_ERR);
1023     READINT32(data, windowId, RET_ERR);
1024     int32_t ret = ClearWindowPointerStyle(pid, windowId);
1025     if (ret != RET_OK) {
1026         MMI_HILOGE("Call SetPointerStyle failed ret:%{public}d", ret);
1027         return ret;
1028     }
1029     MMI_HILOGD("Successfully clean pointerStyle for windowId:%{public}d, pid:%{public}d", windowId, pid);
1030     return RET_OK;
1031 }
1032 
StubGetPointerStyle(MessageParcel & data,MessageParcel & reply)1033 int32_t MultimodalInputConnectStub::StubGetPointerStyle(MessageParcel& data, MessageParcel& reply)
1034 {
1035     CALL_DEBUG_ENTER;
1036     int32_t windowId = 0;
1037     READINT32(data, windowId, RET_ERR);
1038     bool isUiExtension;
1039     READBOOL(data, isUiExtension, RET_ERR);
1040     PointerStyle pointerStyle;
1041     int32_t ret = GetPointerStyle(windowId, pointerStyle, isUiExtension);
1042     if (ret != RET_OK) {
1043         MMI_HILOGE("Call GetPointerStyle failed ret:%{public}d", ret);
1044         return ret;
1045     }
1046     WRITEINT32(reply, pointerStyle.size, RET_ERR);
1047     WRITEINT32(reply, pointerStyle.color, RET_ERR);
1048     WRITEINT32(reply, pointerStyle.id, RET_ERR);
1049     WRITEINT32(reply, pointerStyle.options, RET_ERR);
1050     MMI_HILOGD("Successfully get windowId:%{public}d, icon:%{public}d", windowId, pointerStyle.id);
1051     return RET_OK;
1052 }
1053 
StubSupportKeys(MessageParcel & data,MessageParcel & reply)1054 int32_t MultimodalInputConnectStub::StubSupportKeys(MessageParcel& data, MessageParcel& reply)
1055 {
1056     CALL_DEBUG_ENTER;
1057     int32_t deviceId = -1;
1058     READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
1059     int32_t size = 0;
1060     READINT32(data, size, IPC_PROXY_DEAD_OBJECT_ERR);
1061     if (size < 0 || size > ExtraData::MAX_BUFFER_SIZE) {
1062         MMI_HILOGE("Invalid size:%{public}d", size);
1063         return RET_ERR;
1064     }
1065     std::vector<int32_t> keys;
1066     int32_t key = 0;
1067     for (int32_t i = 0; i < size; ++i) {
1068         READINT32(data, key, IPC_PROXY_DEAD_OBJECT_ERR);
1069         keys.push_back(key);
1070     }
1071     std::vector<bool> keystroke;
1072     int32_t ret = SupportKeys(deviceId, keys, keystroke);
1073     if (ret != RET_OK) {
1074         MMI_HILOGE("Call SupportKeys failed ret:%{public}d", ret);
1075         return RET_ERR;
1076     }
1077     if (!reply.WriteBoolVector(keystroke)) {
1078         MMI_HILOGE("Write keyStroke failed");
1079         return RET_ERR;
1080     }
1081     return ret;
1082 }
1083 
StubGetDeviceIds(MessageParcel & data,MessageParcel & reply)1084 int32_t MultimodalInputConnectStub::StubGetDeviceIds(MessageParcel& data, MessageParcel& reply)
1085 {
1086     CALL_DEBUG_ENTER;
1087     std::vector<int32_t> ids;
1088     int32_t ret = GetDeviceIds(ids);
1089     if (ret != RET_OK) {
1090         MMI_HILOGE("Call GetDeviceIds failed ret:%{public}d", ret);
1091         return RET_ERR;
1092     }
1093     if (!reply.WriteInt32Vector(ids)) {
1094         MMI_HILOGE("Write ids failed");
1095         return RET_ERR;
1096     }
1097     return ret;
1098 }
1099 
StubGetDevice(MessageParcel & data,MessageParcel & reply)1100 int32_t MultimodalInputConnectStub::StubGetDevice(MessageParcel& data, MessageParcel& reply)
1101 {
1102     CALL_DEBUG_ENTER;
1103     int32_t deviceId = -1;
1104     READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
1105     std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
1106     int32_t ret = GetDevice(deviceId, inputDevice);
1107     if (ret != RET_OK) {
1108         MMI_HILOGE("Call GetDevice failed ret:%{public}d", ret);
1109         return RET_ERR;
1110     }
1111     WRITEINT32(reply, inputDevice->GetId(), IPC_STUB_WRITE_PARCEL_ERR);
1112     WRITEINT32(reply, inputDevice->GetType(), IPC_STUB_WRITE_PARCEL_ERR);
1113     WRITESTRING(reply, inputDevice->GetName(), IPC_STUB_WRITE_PARCEL_ERR);
1114     WRITEINT32(reply, inputDevice->GetBus(), IPC_STUB_WRITE_PARCEL_ERR);
1115     WRITEINT32(reply, inputDevice->GetVersion(), IPC_STUB_WRITE_PARCEL_ERR);
1116     WRITEINT32(reply, inputDevice->GetProduct(), IPC_STUB_WRITE_PARCEL_ERR);
1117     WRITEINT32(reply, inputDevice->GetVendor(), IPC_STUB_WRITE_PARCEL_ERR);
1118     WRITESTRING(reply, inputDevice->GetPhys(), IPC_STUB_WRITE_PARCEL_ERR);
1119     WRITESTRING(reply, inputDevice->GetUniq(), IPC_STUB_WRITE_PARCEL_ERR);
1120     WRITEUINT64(reply, static_cast<uint64_t>(inputDevice->GetCapabilities()), IPC_STUB_WRITE_PARCEL_ERR);
1121     WRITEUINT32(reply, static_cast<uint32_t>(inputDevice->GetAxisInfo().size()), IPC_STUB_WRITE_PARCEL_ERR);
1122     for (const auto &item : inputDevice->GetAxisInfo()) {
1123         WRITEINT32(reply, item.GetMinimum(), IPC_STUB_WRITE_PARCEL_ERR);
1124         WRITEINT32(reply, item.GetMaximum(), IPC_STUB_WRITE_PARCEL_ERR);
1125         WRITEINT32(reply, item.GetAxisType(), IPC_STUB_WRITE_PARCEL_ERR);
1126         WRITEINT32(reply, item.GetFuzz(), IPC_STUB_WRITE_PARCEL_ERR);
1127         WRITEINT32(reply, item.GetFlat(), IPC_STUB_WRITE_PARCEL_ERR);
1128         WRITEINT32(reply, item.GetResolution(), IPC_STUB_WRITE_PARCEL_ERR);
1129     }
1130     return RET_OK;
1131 }
1132 
StubRegisterInputDeviceMonitor(MessageParcel & data,MessageParcel & reply)1133 int32_t MultimodalInputConnectStub::StubRegisterInputDeviceMonitor(MessageParcel& data, MessageParcel& reply)
1134 {
1135     CALL_DEBUG_ENTER;
1136     int32_t ret = RegisterDevListener();
1137     if (ret != RET_OK) {
1138         MMI_HILOGE("Call RegisterInputDeviceMonitor failed ret:%{public}d", ret);
1139     }
1140     return ret;
1141 }
1142 
StubUnregisterInputDeviceMonitor(MessageParcel & data,MessageParcel & reply)1143 int32_t MultimodalInputConnectStub::StubUnregisterInputDeviceMonitor(MessageParcel& data, MessageParcel& reply)
1144 {
1145     CALL_DEBUG_ENTER;
1146     int32_t ret = UnregisterDevListener();
1147     if (ret != RET_OK) {
1148         MMI_HILOGE("Call UnregisterInputDeviceMonitor failed ret:%{public}d", ret);
1149     }
1150     return ret;
1151 }
1152 
StubGetKeyboardType(MessageParcel & data,MessageParcel & reply)1153 int32_t MultimodalInputConnectStub::StubGetKeyboardType(MessageParcel& data, MessageParcel& reply)
1154 {
1155     CALL_DEBUG_ENTER;
1156     int32_t deviceId = -1;
1157     READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
1158     int32_t keyboardType = 0;
1159     int32_t ret = GetKeyboardType(deviceId, keyboardType);
1160     if (ret != RET_OK) {
1161         MMI_HILOGE("Call GetKeyboardType failed ret:%{public}d", ret);
1162         return RET_ERR;
1163     }
1164     WRITEINT32(reply, keyboardType, IPC_STUB_WRITE_PARCEL_ERR);
1165     return ret;
1166 }
1167 
StubAddInputHandler(MessageParcel & data,MessageParcel & reply)1168 int32_t MultimodalInputConnectStub::StubAddInputHandler(MessageParcel& data, MessageParcel& reply)
1169 {
1170     CALL_DEBUG_ENTER;
1171     int32_t handlerType = 0;
1172     READINT32(data, handlerType, IPC_PROXY_DEAD_OBJECT_ERR);
1173     if (!PER_HELPER->VerifySystemApp()) {
1174         if (handlerType == InputHandlerType::MONITOR) {
1175 #ifdef PLAYER_FRAMEWORK_EXISTS
1176             int pid = GetCallingPid();
1177             int capturePid = OHOS::Media::ScreenCaptureMonitor::GetInstance()->IsScreenCaptureWorking();
1178             if (capturePid != pid) {
1179                 MMI_HILOGE("Calling pid is: %{public}d, but screen capture pid is: %{public}d", pid, capturePid);
1180                 return ERROR_NO_PERMISSION;
1181             }
1182 #else
1183             return ERROR_NOT_SYSAPI;
1184 #endif
1185         } else if (handlerType != InputHandlerType::INTERCEPTOR) {
1186             MMI_HILOGE("Verify system APP failed");
1187             return ERROR_NOT_SYSAPI;
1188         }
1189     }
1190 
1191     if (!IsRunning()) {
1192         MMI_HILOGE("Service is not running");
1193         return MMISERVICE_NOT_RUNNING;
1194     }
1195     if ((handlerType == InputHandlerType::INTERCEPTOR) && (!PER_HELPER->CheckInterceptor())) {
1196         MMI_HILOGE("Interceptor permission check failed");
1197         return ERROR_NO_PERMISSION;
1198     }
1199     if ((handlerType == InputHandlerType::MONITOR) && (!PER_HELPER->CheckMonitor())) {
1200         MMI_HILOGE("Monitor permission check failed");
1201         return ERROR_NO_PERMISSION;
1202     }
1203     uint32_t eventType = 0;
1204     READUINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR);
1205     int32_t priority = 0;
1206     READINT32(data, priority, IPC_PROXY_DEAD_OBJECT_ERR);
1207     int32_t deviceTags = 0;
1208     READINT32(data, deviceTags, IPC_PROXY_DEAD_OBJECT_ERR);
1209     int32_t ret = AddInputHandler(static_cast<InputHandlerType>(handlerType), eventType, priority,
1210         deviceTags);
1211     if (ret != RET_OK) {
1212         MMI_HILOGE("Call AddInputHandler failed ret:%{public}d", ret);
1213         return ret;
1214     }
1215     return RET_OK;
1216 }
1217 
StubAddPreInputHandler(MessageParcel & data,MessageParcel & reply)1218 int32_t MultimodalInputConnectStub::StubAddPreInputHandler(MessageParcel& data, MessageParcel& reply)
1219 {
1220     CALL_DEBUG_ENTER;
1221     if (!PER_HELPER->VerifySystemApp()) {
1222         return ERROR_NOT_SYSAPI;
1223     }
1224 
1225     if (!IsRunning()) {
1226         MMI_HILOGE("Service is not running");
1227         return MMISERVICE_NOT_RUNNING;
1228     }
1229 
1230     if (!PER_HELPER->CheckMonitor()) {
1231         MMI_HILOGE("Monitor permission check failed");
1232         return ERROR_NO_PERMISSION;
1233     }
1234     int32_t handlerId = -1;
1235     READINT32(data, handlerId, IPC_PROXY_DEAD_OBJECT_ERR);
1236     int32_t eventType = 0;
1237     READINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR);
1238     std::vector<int32_t> keys;
1239     int32_t keysLen = 0;
1240     int32_t key = 0;
1241     READINT32(data, keysLen, IPC_PROXY_DEAD_OBJECT_ERR);
1242     if (keysLen <= 0 || keysLen > KEY_MAX_LIST_SIZE) {
1243         MMI_HILOGE("Invalid keysLen:%{public}d", keysLen);
1244         return RET_ERR;
1245     }
1246     for (int32_t i = 0; i < keysLen; ++i) {
1247         READINT32(data, key, IPC_PROXY_DEAD_OBJECT_ERR);
1248         keys.push_back(key);
1249     }
1250 
1251     int32_t ret = AddPreInputHandler(handlerId, eventType, keys);
1252     if (ret != RET_OK) {
1253         MMI_HILOGE("Call AddPreInputHandler failed ret:%{public}d", ret);
1254         return ret;
1255     }
1256     return RET_OK;
1257 }
1258 
StubRemovePreInputHandler(MessageParcel & data,MessageParcel & reply)1259 int32_t MultimodalInputConnectStub::StubRemovePreInputHandler(MessageParcel& data, MessageParcel& reply)
1260 {
1261     CALL_DEBUG_ENTER;
1262     if (!PER_HELPER->VerifySystemApp()) {
1263         return ERROR_NOT_SYSAPI;
1264     }
1265 
1266     if (!IsRunning()) {
1267         MMI_HILOGE("Service is not running");
1268         return MMISERVICE_NOT_RUNNING;
1269     }
1270     if (!PER_HELPER->CheckMonitor()) {
1271         MMI_HILOGE("Monitor permission check failed");
1272         return ERROR_NO_PERMISSION;
1273     }
1274     int32_t handlerId = -1;
1275     READINT32(data, handlerId, IPC_PROXY_DEAD_OBJECT_ERR);
1276     int32_t ret = RemovePreInputHandler(handlerId);
1277     if (ret != RET_OK) {
1278         MMI_HILOGE("Call RemovePreInputHandler failed ret:%{public}d", ret);
1279         return ret;
1280     }
1281     return RET_OK;
1282 }
1283 
StubRemoveInputHandler(MessageParcel & data,MessageParcel & reply)1284 int32_t MultimodalInputConnectStub::StubRemoveInputHandler(MessageParcel& data, MessageParcel& reply)
1285 {
1286     CALL_DEBUG_ENTER;
1287     int32_t handlerType = 0;
1288     READINT32(data, handlerType, IPC_PROXY_DEAD_OBJECT_ERR);
1289     if (!PER_HELPER->VerifySystemApp()) {
1290         if (handlerType != InputHandlerType::MONITOR && handlerType != InputHandlerType::INTERCEPTOR) {
1291             MMI_HILOGE("Verify system APP failed");
1292             return ERROR_NOT_SYSAPI;
1293         }
1294     }
1295 
1296     if (!IsRunning()) {
1297         MMI_HILOGE("Service is not running");
1298         return MMISERVICE_NOT_RUNNING;
1299     }
1300     if ((handlerType == InputHandlerType::INTERCEPTOR) && (!PER_HELPER->CheckInterceptor())) {
1301         MMI_HILOGE("Interceptor permission check failed");
1302         return ERROR_NO_PERMISSION;
1303     }
1304     if ((handlerType == InputHandlerType::MONITOR) && (!PER_HELPER->CheckMonitor())) {
1305         MMI_HILOGE("Monitor permission check failed");
1306         return ERROR_NO_PERMISSION;
1307     }
1308     uint32_t eventType = 0;
1309     READUINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR);
1310     int32_t priority = 0;
1311     READINT32(data, priority, IPC_PROXY_DEAD_OBJECT_ERR);
1312     int32_t deviceTags = 0;
1313     READINT32(data, deviceTags, IPC_PROXY_DEAD_OBJECT_ERR);
1314     int32_t ret = RemoveInputHandler(static_cast<InputHandlerType>(handlerType), eventType, priority,
1315         deviceTags);
1316     if (ret != RET_OK) {
1317         MMI_HILOGE("Call RemoveInputHandler failed ret:%{public}d", ret);
1318         return ret;
1319     }
1320     return RET_OK;
1321 }
1322 
StubMarkEventConsumed(MessageParcel & data,MessageParcel & reply)1323 int32_t MultimodalInputConnectStub::StubMarkEventConsumed(MessageParcel& data, MessageParcel& reply)
1324 {
1325     CALL_DEBUG_ENTER;
1326     if (!PER_HELPER->CheckMonitor()) {
1327         MMI_HILOGE("Permission check failed");
1328         return ERROR_NO_PERMISSION;
1329     }
1330 
1331     if (!IsRunning()) {
1332         MMI_HILOGE("Service is not running");
1333         return MMISERVICE_NOT_RUNNING;
1334     }
1335     int32_t eventId = 0;
1336     READINT32(data, eventId, IPC_PROXY_DEAD_OBJECT_ERR);
1337     int32_t ret = MarkEventConsumed(eventId);
1338     if (ret != RET_OK) {
1339         MMI_HILOGE("Call MarkEventConsumed failed ret:%{public}d", ret);
1340         return ret;
1341     }
1342     return RET_OK;
1343 }
1344 
StubSubscribeKeyEvent(MessageParcel & data,MessageParcel & reply)1345 int32_t MultimodalInputConnectStub::StubSubscribeKeyEvent(MessageParcel& data, MessageParcel& reply)
1346 {
1347     CALL_DEBUG_ENTER;
1348     if (!PER_HELPER->VerifySystemApp()) {
1349         MMI_HILOGE("Verify system APP failed");
1350         return ERROR_NOT_SYSAPI;
1351     }
1352 
1353     if (!IsRunning()) {
1354         MMI_HILOGE("Service is not running");
1355         return MMISERVICE_NOT_RUNNING;
1356     }
1357 
1358     int32_t subscribeId = 0;
1359     READINT32(data, subscribeId, IPC_PROXY_DEAD_OBJECT_ERR);
1360 
1361     auto keyOption = std::make_shared<KeyOption>();
1362     if (!keyOption->ReadFromParcel(data)) {
1363         MMI_HILOGE("Read keyOption failed");
1364         return IPC_PROXY_DEAD_OBJECT_ERR;
1365     }
1366     int32_t ret = SubscribeKeyEvent(subscribeId, keyOption);
1367     if (ret != RET_OK) {
1368         MMI_HILOGE("SubscribeKeyEvent failed, ret:%{public}d", ret);
1369         return ret;
1370     }
1371     return RET_OK;
1372 }
1373 
StubUnsubscribeKeyEvent(MessageParcel & data,MessageParcel & reply)1374 int32_t MultimodalInputConnectStub::StubUnsubscribeKeyEvent(MessageParcel& data, MessageParcel& reply)
1375 {
1376     CALL_DEBUG_ENTER;
1377     if (!PER_HELPER->VerifySystemApp()) {
1378         MMI_HILOGE("Verify system APP failed");
1379         return ERROR_NOT_SYSAPI;
1380     }
1381 
1382     if (!IsRunning()) {
1383         MMI_HILOGE("Service is not running");
1384         return MMISERVICE_NOT_RUNNING;
1385     }
1386 
1387     int32_t subscribeId = 0;
1388     READINT32(data, subscribeId, IPC_PROXY_DEAD_OBJECT_ERR);
1389 
1390     int32_t ret = UnsubscribeKeyEvent(subscribeId);
1391     if (ret != RET_OK) {
1392         MMI_HILOGE("UnsubscribeKeyEvent failed, ret:%{public}d", ret);
1393         return ret;
1394     }
1395     return RET_OK;
1396 }
1397 
StubSubscribeSwitchEvent(MessageParcel & data,MessageParcel & reply)1398 int32_t MultimodalInputConnectStub::StubSubscribeSwitchEvent(MessageParcel& data, MessageParcel& reply)
1399 {
1400     CALL_DEBUG_ENTER;
1401     if (!PER_HELPER->VerifySystemApp()) {
1402         MMI_HILOGE("Verify system APP failed");
1403         return ERROR_NOT_SYSAPI;
1404     }
1405 
1406     if (!IsRunning()) {
1407         MMI_HILOGE("Service is not running");
1408         return MMISERVICE_NOT_RUNNING;
1409     }
1410 
1411     int32_t subscribeId = 0;
1412     int32_t switchType = 0;
1413     READINT32(data, subscribeId, IPC_PROXY_DEAD_OBJECT_ERR);
1414     READINT32(data, switchType, IPC_PROXY_DEAD_OBJECT_ERR);
1415 
1416     int32_t ret = SubscribeSwitchEvent(subscribeId, switchType);
1417     if (ret != RET_OK) {
1418         MMI_HILOGE("SubscribeSwitchEvent failed, ret:%{public}d", ret);
1419     }
1420     return ret;
1421 }
1422 
StubUnsubscribeSwitchEvent(MessageParcel & data,MessageParcel & reply)1423 int32_t MultimodalInputConnectStub::StubUnsubscribeSwitchEvent(MessageParcel& data, MessageParcel& reply)
1424 {
1425     CALL_DEBUG_ENTER;
1426     if (!PER_HELPER->VerifySystemApp()) {
1427         MMI_HILOGE("Verify system APP failed");
1428         return ERROR_NOT_SYSAPI;
1429     }
1430 
1431     if (!IsRunning()) {
1432         MMI_HILOGE("Service is not running");
1433         return MMISERVICE_NOT_RUNNING;
1434     }
1435 
1436     int32_t subscribeId = 0;
1437     READINT32(data, subscribeId, IPC_PROXY_DEAD_OBJECT_ERR);
1438 
1439     int32_t ret = UnsubscribeSwitchEvent(subscribeId);
1440     if (ret != RET_OK) {
1441         MMI_HILOGE("UnsubscribeSwitchEvent failed, ret:%{public}d", ret);
1442     }
1443     return ret;
1444 }
1445 
StubMoveMouseEvent(MessageParcel & data,MessageParcel & reply)1446 int32_t MultimodalInputConnectStub::StubMoveMouseEvent(MessageParcel& data, MessageParcel& reply)
1447 {
1448     CALL_DEBUG_ENTER;
1449     if (!PER_HELPER->VerifySystemApp()) {
1450         MMI_HILOGE("Verify system APP failed");
1451         return ERROR_NOT_SYSAPI;
1452     }
1453     if (!PER_HELPER->CheckMouseCursor()) {
1454         MMI_HILOGE("Mouse cursor permission check failed");
1455         return ERROR_NO_PERMISSION;
1456     }
1457     if (!IsRunning()) {
1458         MMI_HILOGE("Service is not running");
1459         return MMISERVICE_NOT_RUNNING;
1460     }
1461     int32_t offsetX = 0;
1462     READINT32(data, offsetX, IPC_PROXY_DEAD_OBJECT_ERR);
1463     int32_t offsetY = 0;
1464     READINT32(data, offsetY, IPC_PROXY_DEAD_OBJECT_ERR);
1465 
1466     int32_t ret = MoveMouseEvent(offsetX, offsetY);
1467     if (ret != RET_OK) {
1468         MMI_HILOGE("MoveMouseEvent failed, ret:%{public}d", ret);
1469         return ret;
1470     }
1471     return RET_OK;
1472 }
1473 
StubInjectKeyEvent(MessageParcel & data,MessageParcel & reply)1474 int32_t MultimodalInputConnectStub::StubInjectKeyEvent(MessageParcel& data, MessageParcel& reply)
1475 {
1476     CALL_DEBUG_ENTER;
1477     if (!IsRunning()) {
1478         MMI_HILOGE("Service is not running");
1479         return MMISERVICE_NOT_RUNNING;
1480     }
1481     auto event = KeyEvent::Create();
1482     CHKPR(event, ERROR_NULL_POINTER);
1483     if (!event->ReadFromParcel(data)) {
1484         MMI_HILOGE("Read Key Event failed");
1485         return IPC_PROXY_DEAD_OBJECT_ERR;
1486     }
1487     LogTracer lt(event->GetId(), event->GetEventType(), event->GetKeyAction());
1488     bool isNativeInject { false };
1489     READBOOL(data, isNativeInject, IPC_PROXY_DEAD_OBJECT_ERR);
1490     if (!isNativeInject && !PER_HELPER->VerifySystemApp()) {
1491         MMI_HILOGE("Verify system APP failed");
1492         return ERROR_NOT_SYSAPI;
1493     }
1494     EndLogTraceId(event->GetId());
1495     event->UpdateId();
1496     LogTracer lt1(event->GetId(), event->GetEventType(), event->GetKeyAction());
1497     int32_t ret = InjectKeyEvent(event, isNativeInject);
1498     if (ret != RET_OK) {
1499         MMI_HILOGE("InjectKeyEvent failed, ret:%{public}d", ret);
1500         return ret;
1501     }
1502     return RET_OK;
1503 }
1504 
StubInjectPointerEvent(MessageParcel & data,MessageParcel & reply)1505 int32_t MultimodalInputConnectStub::StubInjectPointerEvent(MessageParcel& data, MessageParcel& reply)
1506 {
1507     CALL_DEBUG_ENTER;
1508     if (!IsRunning()) {
1509         MMI_HILOGE("Service is not running");
1510         return MMISERVICE_NOT_RUNNING;
1511     }
1512     auto pointerEvent = PointerEvent::Create();
1513     CHKPR(pointerEvent, ERROR_NULL_POINTER);
1514     if (!pointerEvent->ReadFromParcel(data)) {
1515         MMI_HILOGE("Read Pointer Event failed");
1516         return IPC_PROXY_DEAD_OBJECT_ERR;
1517     }
1518     bool isNativeInject { false };
1519     READBOOL(data, isNativeInject, IPC_PROXY_DEAD_OBJECT_ERR);
1520     if (!isNativeInject && !PER_HELPER->VerifySystemApp()) {
1521         MMI_HILOGE("Verify system APP failed");
1522         return ERROR_NOT_SYSAPI;
1523     }
1524     int32_t ret = InjectPointerEvent(pointerEvent, isNativeInject);
1525     if (ret != RET_OK) {
1526         MMI_HILOGE("Call InjectPointerEvent failed ret:%{public}d", ret);
1527         return ret;
1528     }
1529     return RET_OK;
1530 }
1531 
StubSetAnrListener(MessageParcel & data,MessageParcel & reply)1532 int32_t MultimodalInputConnectStub::StubSetAnrListener(MessageParcel& data, MessageParcel& reply)
1533 {
1534     CALL_DEBUG_ENTER;
1535     if (!PER_HELPER->VerifySystemApp()) {
1536         MMI_HILOGE("Verify system APP failed");
1537         return ERROR_NOT_SYSAPI;
1538     }
1539     if (!IsRunning()) {
1540         MMI_HILOGE("Service is not running");
1541         return MMISERVICE_NOT_RUNNING;
1542     }
1543     int32_t ret = SetAnrObserver();
1544     if (ret != RET_OK) {
1545         MMI_HILOGE("Call SetAnrObserver failed, ret:%{public}d", ret);
1546     }
1547     return ret;
1548 }
1549 
1550 
StubGetDisplayBindInfo(MessageParcel & data,MessageParcel & reply)1551 int32_t MultimodalInputConnectStub::StubGetDisplayBindInfo(MessageParcel& data, MessageParcel& reply)
1552 {
1553     CALL_DEBUG_ENTER;
1554     if (!PER_HELPER->VerifySystemApp()) {
1555         MMI_HILOGE("Verify system APP failed");
1556         return ERROR_NOT_SYSAPI;
1557     }
1558     if (!IsRunning()) {
1559         MMI_HILOGE("Service is not running");
1560         return MMISERVICE_NOT_RUNNING;
1561     }
1562     DisplayBindInfos infos;
1563     int32_t ret = GetDisplayBindInfo(infos);
1564     if (ret != RET_OK) {
1565         MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
1566         return ret;
1567     }
1568     int32_t size = static_cast<int32_t>(infos.size());
1569     WRITEINT32(reply, size, ERR_INVALID_VALUE);
1570     infos.reserve(size);
1571     for (const auto &info : infos) {
1572         WRITEINT32(reply, info.inputDeviceId, ERR_INVALID_VALUE);
1573         WRITESTRING(reply, info.inputDeviceName, ERR_INVALID_VALUE);
1574         WRITEINT32(reply, info.displayId, ERR_INVALID_VALUE);
1575         WRITESTRING(reply, info.displayName, ERR_INVALID_VALUE);
1576     }
1577     return RET_OK;
1578 }
1579 
StubGetAllMmiSubscribedEvents(MessageParcel & data,MessageParcel & reply)1580 int32_t MultimodalInputConnectStub::StubGetAllMmiSubscribedEvents(MessageParcel& data, MessageParcel& reply)
1581 {
1582     CALL_DEBUG_ENTER;
1583     if (!PER_HELPER->VerifySystemApp()) {
1584         MMI_HILOGE("Verify system APP failed");
1585         return ERROR_NOT_SYSAPI;
1586     }
1587     if (!IsRunning()) {
1588         MMI_HILOGE("Service is not running");
1589         return MMISERVICE_NOT_RUNNING;
1590     }
1591     std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> datas;
1592     int32_t ret = GetAllMmiSubscribedEvents(datas);
1593     if (ret != RET_OK) {
1594         MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret);
1595         return ret;
1596     }
1597     int32_t size = static_cast<int32_t>(datas.size());
1598     WRITEINT32(reply, size, ERR_INVALID_VALUE);
1599     for (const auto &data : datas) {
1600         WRITEINT32(reply, std::get<TUPLE_PID>(data.first), ERR_INVALID_VALUE);
1601         WRITEINT32(reply, std::get<TUPLE_UID>(data.first), ERR_INVALID_VALUE);
1602         WRITESTRING(reply, std::get<TUPLE_NAME>(data.first), ERR_INVALID_VALUE);
1603         WRITEINT32(reply, data.second, ERR_INVALID_VALUE);
1604     }
1605     return RET_OK;
1606 }
1607 
StubSetDisplayBind(MessageParcel & data,MessageParcel & reply)1608 int32_t MultimodalInputConnectStub::StubSetDisplayBind(MessageParcel& data, MessageParcel& reply)
1609 {
1610     CALL_DEBUG_ENTER;
1611     if (!PER_HELPER->VerifySystemApp()) {
1612         MMI_HILOGE("Verify system APP failed");
1613         return ERROR_NOT_SYSAPI;
1614     }
1615     if (!IsRunning()) {
1616         MMI_HILOGE("Service is not running");
1617         return MMISERVICE_NOT_RUNNING;
1618     }
1619     int32_t inputDeviceId = -1;
1620     READINT32(data, inputDeviceId, ERR_INVALID_VALUE);
1621     int32_t displayId = -1;
1622     READINT32(data, displayId, ERR_INVALID_VALUE);
1623     std::string msg;
1624     int32_t ret = SetDisplayBind(inputDeviceId, displayId, msg);
1625     if (ret != RET_OK) {
1626         MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret);
1627     }
1628     WRITESTRING(reply, msg, ERR_INVALID_VALUE);
1629     return ret;
1630 }
1631 
StubGetFunctionKeyState(MessageParcel & data,MessageParcel & reply)1632 int32_t MultimodalInputConnectStub::StubGetFunctionKeyState(MessageParcel &data, MessageParcel &reply)
1633 {
1634     CALL_DEBUG_ENTER;
1635     if (!IsRunning()) {
1636         MMI_HILOGE("Service is not running");
1637         return MMISERVICE_NOT_RUNNING;
1638     }
1639 
1640     int32_t funcKey { 0 };
1641     bool state { false };
1642     READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR);
1643     int32_t ret = GetFunctionKeyState(funcKey, state);
1644     if (ret != RET_OK) {
1645         MMI_HILOGE("Call GetKeyboardEnableState failed ret:%{public}d", ret);
1646         return ret;
1647     }
1648 
1649     WRITEBOOL(reply, state, IPC_PROXY_DEAD_OBJECT_ERR);
1650     return RET_OK;
1651 }
1652 
StubSetFunctionKeyState(MessageParcel & data,MessageParcel & reply)1653 int32_t MultimodalInputConnectStub::StubSetFunctionKeyState(MessageParcel &data, MessageParcel &reply)
1654 {
1655     CALL_DEBUG_ENTER;
1656     if (!PER_HELPER->CheckFunctionKeyEnabled()) {
1657         MMI_HILOGE("Set function key state permission check failed");
1658         return ERROR_NO_PERMISSION;
1659     }
1660     if (!IsRunning()) {
1661         MMI_HILOGE("Service is not running");
1662         return MMISERVICE_NOT_RUNNING;
1663     }
1664 
1665     int32_t funcKey { 0 };
1666     bool enable { false };
1667     READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR);
1668     READBOOL(data, enable, IPC_PROXY_DEAD_OBJECT_ERR);
1669     int32_t ret = SetFunctionKeyState(funcKey, enable);
1670     if (ret != RET_OK) {
1671         MMI_HILOGE("Call SetFunctionKeyState failed ret:%{public}d", ret);
1672     }
1673     return ret;
1674 }
1675 
StubSetPointerLocation(MessageParcel & data,MessageParcel & reply)1676 int32_t MultimodalInputConnectStub::StubSetPointerLocation(MessageParcel &data, MessageParcel &reply)
1677 {
1678     CALL_DEBUG_ENTER;
1679     if (!PER_HELPER->VerifySystemApp()) {
1680         MMI_HILOGE("StubSetPointerLocation Verify system APP failed");
1681         return ERROR_NOT_SYSAPI;
1682     }
1683     if (!PER_HELPER->CheckMouseCursor()) {
1684         MMI_HILOGE("Mouse cursor permission check failed");
1685         return ERROR_NO_PERMISSION;
1686     }
1687     if (!IsRunning()) {
1688         MMI_HILOGE("Service is not running");
1689         return MMISERVICE_NOT_RUNNING;
1690     }
1691 
1692     int32_t x = 0;
1693     int32_t y = 0;
1694     READINT32(data, x, IPC_PROXY_DEAD_OBJECT_ERR);
1695     READINT32(data, y, IPC_PROXY_DEAD_OBJECT_ERR);
1696     int32_t ret = SetPointerLocation(x, y);
1697     if (ret != RET_OK) {
1698         MMI_HILOGE("Call SetFunctionKeyState failed ret:%{public}d", ret);
1699     }
1700     return ret;
1701 }
1702 
StubSetMouseCaptureMode(MessageParcel & data,MessageParcel & reply)1703 int32_t MultimodalInputConnectStub::StubSetMouseCaptureMode(MessageParcel& data, MessageParcel& reply)
1704 {
1705     CALL_DEBUG_ENTER;
1706     if (!PER_HELPER->VerifySystemApp()) {
1707         MMI_HILOGE("Verify system APP failed");
1708         return ERROR_NOT_SYSAPI;
1709     }
1710     int32_t windowId = -1;
1711     bool isCaptureMode = false;
1712     READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR);
1713     READBOOL(data, isCaptureMode, IPC_PROXY_DEAD_OBJECT_ERR);
1714     int32_t ret = SetMouseCaptureMode(windowId, isCaptureMode);
1715     if (ret != RET_OK) {
1716         MMI_HILOGE("Fail to call SetMouseCaptureMode, ret:%{public}d", ret);
1717     }
1718     return ret;
1719 }
1720 
StubGetWindowPid(MessageParcel & data,MessageParcel & reply)1721 int32_t MultimodalInputConnectStub::StubGetWindowPid(MessageParcel& data, MessageParcel& reply)
1722 {
1723     CALL_DEBUG_ENTER;
1724     if (!IsRunning()) {
1725         MMI_HILOGE("Service is not running");
1726         return MMISERVICE_NOT_RUNNING;
1727     }
1728 
1729     int32_t windowId = 0;
1730     READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR);
1731     int32_t ret = GetWindowPid(windowId);
1732     if (ret == RET_ERR) {
1733         MMI_HILOGE("Get window pid failed");
1734     }
1735     WRITEINT32(reply, ret, ERR_INVALID_VALUE);
1736     return RET_OK;
1737 }
1738 
StubAppendExtraData(MessageParcel & data,MessageParcel & reply)1739 int32_t MultimodalInputConnectStub::StubAppendExtraData(MessageParcel& data, MessageParcel& reply)
1740 {
1741     CALL_DEBUG_ENTER;
1742     if (!PER_HELPER->VerifySystemApp()) {
1743         MMI_HILOGE("Verify system APP failed");
1744         return ERROR_NOT_SYSAPI;
1745     }
1746     if (!IsRunning()) {
1747         MMI_HILOGE("Service is not running");
1748         return MMISERVICE_NOT_RUNNING;
1749     }
1750     ExtraData extraData;
1751     READBOOL(data, extraData.appended, IPC_PROXY_DEAD_OBJECT_ERR);
1752     int32_t size = 0;
1753     READINT32(data, size, IPC_PROXY_DEAD_OBJECT_ERR);
1754     if (size > ExtraData::MAX_BUFFER_SIZE) {
1755         MMI_HILOGE("Append extra data failed, buffer is oversize:%{public}d", size);
1756         return ERROR_OVER_SIZE_BUFFER;
1757     }
1758     uint8_t buffer = 0;
1759     for (int32_t i = 0; i < size; ++i) {
1760         READUINT8(data, buffer, IPC_PROXY_DEAD_OBJECT_ERR);
1761         extraData.buffer.push_back(buffer);
1762     }
1763     READINT32(data, extraData.sourceType, IPC_PROXY_DEAD_OBJECT_ERR);
1764     READINT32(data, extraData.pointerId, IPC_PROXY_DEAD_OBJECT_ERR);
1765     READINT32(data, extraData.pullId, IPC_PROXY_DEAD_OBJECT_ERR);
1766     int32_t ret = AppendExtraData(extraData);
1767     if (ret != RET_OK) {
1768         MMI_HILOGE("Fail to call AppendExtraData, ret:%{public}d", ret);
1769     }
1770     return ret;
1771 }
1772 
StubEnableCombineKey(MessageParcel & data,MessageParcel & reply)1773 int32_t MultimodalInputConnectStub::StubEnableCombineKey(MessageParcel& data, MessageParcel& reply)
1774 {
1775     CALL_DEBUG_ENTER;
1776     if (!PER_HELPER->VerifySystemApp()) {
1777         MMI_HILOGE("Verify system APP failed");
1778         return ERROR_NOT_SYSAPI;
1779     }
1780     if (!IsRunning()) {
1781         MMI_HILOGE("Service is not running");
1782         return MMISERVICE_NOT_RUNNING;
1783     }
1784     bool enable;
1785     READBOOL(data, enable, IPC_PROXY_DEAD_OBJECT_ERR);
1786     int32_t ret = EnableCombineKey(enable);
1787     if (ret != RET_OK) {
1788         MMI_HILOGE("Call EnableCombineKey failed, ret:%{public}d", ret);
1789     }
1790     return ret;
1791 }
1792 
StubEnableInputDevice(MessageParcel & data,MessageParcel & reply)1793 int32_t MultimodalInputConnectStub::StubEnableInputDevice(MessageParcel& data, MessageParcel& reply)
1794 {
1795     CALL_DEBUG_ENTER;
1796     MMI_HILOGW("EnableInputDevice is not supported yet");
1797     return RET_OK;
1798 }
1799 
StubSetKeyDownDuration(MessageParcel & data,MessageParcel & reply)1800 int32_t MultimodalInputConnectStub::StubSetKeyDownDuration(MessageParcel& data, MessageParcel& reply)
1801 {
1802     CALL_DEBUG_ENTER;
1803     if (!PER_HELPER->VerifySystemApp()) {
1804         MMI_HILOGE("Verify system APP failed");
1805         return ERROR_NOT_SYSAPI;
1806     }
1807     if (!IsRunning()) {
1808         MMI_HILOGE("Service is not running");
1809         return MMISERVICE_NOT_RUNNING;
1810     }
1811     std::string businessId;
1812     READSTRING(data, businessId, IPC_PROXY_DEAD_OBJECT_ERR);
1813     int32_t delay = 0;
1814     READINT32(data, delay, IPC_PROXY_DEAD_OBJECT_ERR);
1815     int32_t ret = SetKeyDownDuration(businessId, delay);
1816     if (ret != RET_OK) {
1817         MMI_HILOGE("Set key down duration failed ret:%{public}d", ret);
1818         return ret;
1819     }
1820     return RET_OK;
1821 }
1822 
VerifyTouchPadSetting(void)1823 int32_t MultimodalInputConnectStub::VerifyTouchPadSetting(void)
1824 {
1825     if (!IsRunning()) {
1826         MMI_HILOGE("Service is not running");
1827         return MMISERVICE_NOT_RUNNING;
1828     }
1829 
1830     if (!PER_HELPER->VerifySystemApp()) {
1831         MMI_HILOGE("Verify system APP failed");
1832         return ERROR_NOT_SYSAPI;
1833     }
1834 
1835     return RET_OK;
1836 }
1837 
StubSetTouchpadScrollSwitch(MessageParcel & data,MessageParcel & reply)1838 int32_t MultimodalInputConnectStub::StubSetTouchpadScrollSwitch(MessageParcel& data, MessageParcel& reply)
1839 {
1840     CALL_DEBUG_ENTER;
1841     int32_t ret = VerifyTouchPadSetting();
1842     if (ret != RET_OK) {
1843         MMI_HILOGE("Verify touchpad setting failed");
1844         return ret;
1845     }
1846 
1847     bool switchFlag = true;
1848     READBOOL(data, switchFlag, IPC_PROXY_DEAD_OBJECT_ERR);
1849     ret = SetTouchpadScrollSwitch(switchFlag);
1850     if (ret != RET_OK) {
1851         MMI_HILOGE("Set touchpad scroll switch failed ret:%{public}d", ret);
1852         return ret;
1853     }
1854     return RET_OK;
1855 }
1856 
StubGetTouchpadScrollSwitch(MessageParcel & data,MessageParcel & reply)1857 int32_t MultimodalInputConnectStub::StubGetTouchpadScrollSwitch(MessageParcel& data, MessageParcel& reply)
1858 {
1859     CALL_DEBUG_ENTER;
1860     int32_t ret = VerifyTouchPadSetting();
1861     if (ret != RET_OK) {
1862         MMI_HILOGE("Verify touchpad setting failed");
1863         return ret;
1864     }
1865 
1866     bool switchFlag = true;
1867     ret = GetTouchpadScrollSwitch(switchFlag);
1868     if (ret != RET_OK) {
1869         MMI_HILOGE("Call GetTouchpadScrollSwitch failed ret:%{public}d", ret);
1870         return ret;
1871     }
1872     WRITEBOOL(reply, switchFlag, IPC_STUB_WRITE_PARCEL_ERR);
1873     MMI_HILOGD("Touchpad scroll switch :%{public}d, ret:%{public}d", switchFlag, ret);
1874     return RET_OK;
1875 }
1876 
StubSetTouchpadScrollDirection(MessageParcel & data,MessageParcel & reply)1877 int32_t MultimodalInputConnectStub::StubSetTouchpadScrollDirection(MessageParcel& data, MessageParcel& reply)
1878 {
1879     CALL_DEBUG_ENTER;
1880     int32_t ret = VerifyTouchPadSetting();
1881     if (ret != RET_OK) {
1882         MMI_HILOGE("Verify touchpad setting failed");
1883         return ret;
1884     }
1885 
1886     bool state = true;
1887     READBOOL(data, state, IPC_PROXY_DEAD_OBJECT_ERR);
1888     ret = SetTouchpadScrollDirection(state);
1889     if (ret != RET_OK) {
1890         MMI_HILOGE("Set touchpad scroll direction switch failed ret:%{public}d", ret);
1891         return ret;
1892     }
1893     return RET_OK;
1894 }
1895 
StubGetTouchpadScrollDirection(MessageParcel & data,MessageParcel & reply)1896 int32_t MultimodalInputConnectStub::StubGetTouchpadScrollDirection(MessageParcel& data, MessageParcel& reply)
1897 {
1898     CALL_DEBUG_ENTER;
1899     int32_t ret = VerifyTouchPadSetting();
1900     if (ret != RET_OK) {
1901         MMI_HILOGE("Verify touchpad setting failed");
1902         return ret;
1903     }
1904 
1905     bool state = true;
1906     ret = GetTouchpadScrollDirection(state);
1907     if (ret != RET_OK) {
1908         MMI_HILOGE("Call GetTouchpadScrollDirection failed ret:%{public}d", ret);
1909         return ret;
1910     }
1911     WRITEBOOL(reply, state, IPC_STUB_WRITE_PARCEL_ERR);
1912     MMI_HILOGD("Touchpad scroll direction switch state:%{public}d, ret:%{public}d", state, ret);
1913     return RET_OK;
1914 }
1915 
StubSetTouchpadTapSwitch(MessageParcel & data,MessageParcel & reply)1916 int32_t MultimodalInputConnectStub::StubSetTouchpadTapSwitch(MessageParcel& data, MessageParcel& reply)
1917 {
1918     CALL_DEBUG_ENTER;
1919     int32_t ret = VerifyTouchPadSetting();
1920     if (ret != RET_OK) {
1921         MMI_HILOGE("Verify touchpad setting failed");
1922         return ret;
1923     }
1924 
1925     bool switchFlag = true;
1926     READBOOL(data, switchFlag, IPC_PROXY_DEAD_OBJECT_ERR);
1927     ret = SetTouchpadTapSwitch(switchFlag);
1928     if (ret != RET_OK) {
1929         MMI_HILOGE("Set touchpad tap switch failed ret:%{public}d", ret);
1930         return ret;
1931     }
1932     return RET_OK;
1933 }
1934 
StubGetTouchpadTapSwitch(MessageParcel & data,MessageParcel & reply)1935 int32_t MultimodalInputConnectStub::StubGetTouchpadTapSwitch(MessageParcel& data, MessageParcel& reply)
1936 {
1937     CALL_DEBUG_ENTER;
1938     int32_t ret = VerifyTouchPadSetting();
1939     if (ret != RET_OK) {
1940         MMI_HILOGE("Verify touchpad setting failed");
1941         return ret;
1942     }
1943 
1944     bool switchFlag = true;
1945     ret = GetTouchpadTapSwitch(switchFlag);
1946     if (ret != RET_OK) {
1947         MMI_HILOGE("Call GetTouchpadTapSwitch failed ret:%{public}d", ret);
1948         return ret;
1949     }
1950     WRITEBOOL(reply, switchFlag, IPC_STUB_WRITE_PARCEL_ERR);
1951     MMI_HILOGD("Touchpad tap switchFlag:%{public}d, ret:%{public}d", switchFlag, ret);
1952     return RET_OK;
1953 }
1954 
StubSetTouchpadPointerSpeed(MessageParcel & data,MessageParcel & reply)1955 int32_t MultimodalInputConnectStub::StubSetTouchpadPointerSpeed(MessageParcel& data, MessageParcel& reply)
1956 {
1957     CALL_DEBUG_ENTER;
1958     int32_t ret = VerifyTouchPadSetting();
1959     if (ret != RET_OK) {
1960         MMI_HILOGE("Verify touchpad setting failed");
1961         return ret;
1962     }
1963 
1964     int32_t speed = 1;
1965     READINT32(data, speed, IPC_PROXY_DEAD_OBJECT_ERR);
1966     ret = SetTouchpadPointerSpeed(speed);
1967     if (ret != RET_OK) {
1968         MMI_HILOGE("Set touchpad pointer speed failed ret:%{public}d", ret);
1969         return ret;
1970     }
1971     return RET_OK;
1972 }
1973 
StubGetTouchpadPointerSpeed(MessageParcel & data,MessageParcel & reply)1974 int32_t MultimodalInputConnectStub::StubGetTouchpadPointerSpeed(MessageParcel& data, MessageParcel& reply)
1975 {
1976     CALL_DEBUG_ENTER;
1977     int32_t ret = VerifyTouchPadSetting();
1978     if (ret != RET_OK) {
1979         MMI_HILOGE("Verify touchpad setting failed");
1980         return ret;
1981     }
1982 
1983     int32_t speed = 1;
1984     ret = GetTouchpadPointerSpeed(speed);
1985     if (ret != RET_OK) {
1986         MMI_HILOGE("Call GetTouchpadPointerSpeed failed ret:%{public}d", ret);
1987         return ret;
1988     }
1989     WRITEINT32(reply, speed, IPC_STUB_WRITE_PARCEL_ERR);
1990     MMI_HILOGD("Touchpad pointer speed:%{public}d, ret:%{public}d", speed, ret);
1991     return RET_OK;
1992 }
1993 
StubSetKeyboardRepeatDelay(MessageParcel & data,MessageParcel & reply)1994 int32_t MultimodalInputConnectStub::StubSetKeyboardRepeatDelay(MessageParcel& data, MessageParcel& reply)
1995 {
1996     CALL_DEBUG_ENTER;
1997     if (!IsRunning()) {
1998         MMI_HILOGE("Service is not running");
1999         return MMISERVICE_NOT_RUNNING;
2000     }
2001     if (!PER_HELPER->VerifySystemApp()) {
2002         MMI_HILOGE("Verify system APP failed");
2003         return ERROR_NOT_SYSAPI;
2004     }
2005     int32_t delay = 0;
2006     READINT32(data, delay, IPC_PROXY_DEAD_OBJECT_ERR);
2007     int32_t ret = SetKeyboardRepeatDelay(delay);
2008     if (ret != RET_OK) {
2009         MMI_HILOGE("Set keyboard repeat delay failed ret:%{public}d", ret);
2010         return RET_ERR;
2011     }
2012     return RET_OK;
2013 }
2014 
StubSetKeyboardRepeatRate(MessageParcel & data,MessageParcel & reply)2015 int32_t MultimodalInputConnectStub::StubSetKeyboardRepeatRate(MessageParcel& data, MessageParcel& reply)
2016 {
2017     CALL_DEBUG_ENTER;
2018     if (!IsRunning()) {
2019         MMI_HILOGE("Service is not running");
2020         return MMISERVICE_NOT_RUNNING;
2021     }
2022     if (!PER_HELPER->VerifySystemApp()) {
2023         MMI_HILOGE("Verify system APP failed");
2024         return ERROR_NOT_SYSAPI;
2025     }
2026     int32_t rate = 0;
2027     READINT32(data, rate, IPC_PROXY_DEAD_OBJECT_ERR);
2028     int32_t ret = SetKeyboardRepeatRate(rate);
2029     if (ret != RET_OK) {
2030         MMI_HILOGE("Set keyboard repeat rate failed ret:%{public}d", ret);
2031         return RET_ERR;
2032     }
2033     return RET_OK;
2034 }
2035 
StubGetKeyboardRepeatDelay(MessageParcel & data,MessageParcel & reply)2036 int32_t MultimodalInputConnectStub::StubGetKeyboardRepeatDelay(MessageParcel& data, MessageParcel& reply)
2037 {
2038     CALL_DEBUG_ENTER;
2039     if (!IsRunning()) {
2040         MMI_HILOGE("Service is not running");
2041         return MMISERVICE_NOT_RUNNING;
2042     }
2043     if (!PER_HELPER->VerifySystemApp()) {
2044         MMI_HILOGE("Verify system APP failed");
2045         return ERROR_NOT_SYSAPI;
2046     }
2047     int32_t delay = 0;
2048     int32_t ret = GetKeyboardRepeatDelay(delay);
2049     if (ret != RET_OK) {
2050         MMI_HILOGE("Get keyboard repeat delay failed ret:%{public}d", ret);
2051         return RET_ERR;
2052     }
2053     WRITEINT32(reply, delay, IPC_STUB_WRITE_PARCEL_ERR);
2054     return RET_OK;
2055 }
2056 
StubGetKeyboardRepeatRate(MessageParcel & data,MessageParcel & reply)2057 int32_t MultimodalInputConnectStub::StubGetKeyboardRepeatRate(MessageParcel& data, MessageParcel& reply)
2058 {
2059     CALL_DEBUG_ENTER;
2060     if (!IsRunning()) {
2061         MMI_HILOGE("Service is not running");
2062         return MMISERVICE_NOT_RUNNING;
2063     }
2064     if (!PER_HELPER->VerifySystemApp()) {
2065         MMI_HILOGE("Verify system APP failed");
2066         return ERROR_NOT_SYSAPI;
2067     }
2068     int32_t rate = 0;
2069     int32_t ret = GetKeyboardRepeatRate(rate);
2070     if (ret != RET_OK) {
2071         MMI_HILOGE("Get keyboard repeat rate failed ret:%{public}d", ret);
2072         return RET_ERR;
2073     }
2074     WRITEINT32(reply, rate, IPC_STUB_WRITE_PARCEL_ERR);
2075     return RET_OK;
2076 }
2077 
StubSetTouchpadPinchSwitch(MessageParcel & data,MessageParcel & reply)2078 int32_t MultimodalInputConnectStub::StubSetTouchpadPinchSwitch(MessageParcel& data, MessageParcel& reply)
2079 {
2080     CALL_DEBUG_ENTER;
2081     int32_t ret = VerifyTouchPadSetting();
2082     if (ret != RET_OK) {
2083         MMI_HILOGE("Verify touchpad setting failed");
2084         return ret;
2085     }
2086 
2087     bool switchFlag = true;
2088     READBOOL(data, switchFlag, IPC_PROXY_DEAD_OBJECT_ERR);
2089     ret = SetTouchpadPinchSwitch(switchFlag);
2090     if (ret != RET_OK) {
2091         MMI_HILOGE("Set touchpad pinch switch failed ret:%{public}d", ret);
2092         return ret;
2093     }
2094     return RET_OK;
2095 }
2096 
StubGetTouchpadPinchSwitch(MessageParcel & data,MessageParcel & reply)2097 int32_t MultimodalInputConnectStub::StubGetTouchpadPinchSwitch(MessageParcel& data, MessageParcel& reply)
2098 {
2099     CALL_DEBUG_ENTER;
2100     int32_t ret = VerifyTouchPadSetting();
2101     if (ret != RET_OK) {
2102         MMI_HILOGE("Verify touchpad setting failed");
2103         return ret;
2104     }
2105 
2106     bool switchFlag = true;
2107     ret = GetTouchpadPinchSwitch(switchFlag);
2108     if (ret != RET_OK) {
2109         MMI_HILOGE("Call GetTouchpadPinchSwitch failed ret:%{public}d", ret);
2110         return ret;
2111     }
2112     WRITEBOOL(reply, switchFlag, IPC_STUB_WRITE_PARCEL_ERR);
2113     MMI_HILOGD("Touchpad pinch switchFlag:%{public}d, ret:%{public}d", switchFlag, ret);
2114     return RET_OK;
2115 }
2116 
StubSetTouchpadSwipeSwitch(MessageParcel & data,MessageParcel & reply)2117 int32_t MultimodalInputConnectStub::StubSetTouchpadSwipeSwitch(MessageParcel& data, MessageParcel& reply)
2118 {
2119     CALL_DEBUG_ENTER;
2120     int32_t ret = VerifyTouchPadSetting();
2121     if (ret != RET_OK) {
2122         MMI_HILOGE("Verify touchpad setting failed");
2123         return ret;
2124     }
2125 
2126     bool switchFlag = true;
2127     READBOOL(data, switchFlag, IPC_PROXY_DEAD_OBJECT_ERR);
2128     ret = SetTouchpadSwipeSwitch(switchFlag);
2129     if (ret != RET_OK) {
2130         MMI_HILOGE("Set touchpad swipe switch failed ret:%{public}d", ret);
2131         return ret;
2132     }
2133     return RET_OK;
2134 }
2135 
StubGetTouchpadSwipeSwitch(MessageParcel & data,MessageParcel & reply)2136 int32_t MultimodalInputConnectStub::StubGetTouchpadSwipeSwitch(MessageParcel& data, MessageParcel& reply)
2137 {
2138     CALL_DEBUG_ENTER;
2139     int32_t ret = VerifyTouchPadSetting();
2140     if (ret != RET_OK) {
2141         MMI_HILOGE("Verify touchpad setting failed");
2142         return ret;
2143     }
2144 
2145     bool switchFlag = true;
2146     ret = GetTouchpadSwipeSwitch(switchFlag);
2147     if (ret != RET_OK) {
2148         MMI_HILOGE("Call GetTouchpadSwipeSwitch failed ret:%{public}d", ret);
2149         return ret;
2150     }
2151     WRITEBOOL(reply, switchFlag, IPC_STUB_WRITE_PARCEL_ERR);
2152     MMI_HILOGD("Touchpad swipe switchFlag:%{public}d, ret:%{public}d", switchFlag, ret);
2153     return RET_OK;
2154 }
2155 
StubSetTouchpadRightClickType(MessageParcel & data,MessageParcel & reply)2156 int32_t MultimodalInputConnectStub::StubSetTouchpadRightClickType(MessageParcel& data, MessageParcel& reply)
2157 {
2158     CALL_DEBUG_ENTER;
2159     int32_t ret = VerifyTouchPadSetting();
2160     if (ret != RET_OK) {
2161         MMI_HILOGE("Verify touchpad setting failed");
2162         return ret;
2163     }
2164 
2165     int32_t type = 1;
2166     READINT32(data, type, IPC_PROXY_DEAD_OBJECT_ERR);
2167     ret = SetTouchpadRightClickType(type);
2168     if (ret != RET_OK) {
2169         MMI_HILOGE("Set touchpad right button menu type failed ret:%{public}d", ret);
2170         return ret;
2171     }
2172     return RET_OK;
2173 }
2174 
StubGetTouchpadRightClickType(MessageParcel & data,MessageParcel & reply)2175 int32_t MultimodalInputConnectStub::StubGetTouchpadRightClickType(MessageParcel& data, MessageParcel& reply)
2176 {
2177     CALL_DEBUG_ENTER;
2178     int32_t ret = VerifyTouchPadSetting();
2179     if (ret != RET_OK) {
2180         MMI_HILOGE("Verify touchpad setting failed");
2181         return ret;
2182     }
2183 
2184     int32_t type = 1;
2185     ret = GetTouchpadRightClickType(type);
2186     if (ret != RET_OK) {
2187         MMI_HILOGE("Call GetTouchpadRightClickType failed ret:%{public}d", ret);
2188         return ret;
2189     }
2190     WRITEINT32(reply, type, IPC_STUB_WRITE_PARCEL_ERR);
2191     MMI_HILOGD("Touchpad right button menu type:%{public}d, ret:%{public}d", type, ret);
2192     return RET_OK;
2193 }
2194 
StubSetTouchpadRotateSwitch(MessageParcel & data,MessageParcel & reply)2195 int32_t MultimodalInputConnectStub::StubSetTouchpadRotateSwitch(MessageParcel& data, MessageParcel& reply)
2196 {
2197     CALL_DEBUG_ENTER;
2198     int32_t ret = VerifyTouchPadSetting();
2199     if (ret != RET_OK) {
2200         MMI_HILOGE("Verify touchpad setting failed");
2201         return ret;
2202     }
2203 
2204     bool rotateSwitch = true;
2205     READBOOL(data, rotateSwitch, IPC_PROXY_DEAD_OBJECT_ERR);
2206     ret = SetTouchpadRotateSwitch(rotateSwitch);
2207     if (ret != RET_OK) {
2208         MMI_HILOGE("Set touchpad rotate switch failed ret:%{public}d", ret);
2209         return ret;
2210     }
2211     return RET_OK;
2212 }
2213 
StubGetTouchpadRotateSwitch(MessageParcel & data,MessageParcel & reply)2214 int32_t MultimodalInputConnectStub::StubGetTouchpadRotateSwitch(MessageParcel& data, MessageParcel& reply)
2215 {
2216     CALL_DEBUG_ENTER;
2217     int32_t ret = VerifyTouchPadSetting();
2218     if (ret != RET_OK) {
2219         MMI_HILOGE("Verify touchpad setting failed");
2220         return ret;
2221     }
2222 
2223     bool rotateSwitch = true;
2224     ret = GetTouchpadRotateSwitch(rotateSwitch);
2225     if (ret != RET_OK) {
2226         MMI_HILOGE("GetTouchpadRotateSwitch failed ret:%{public}d", ret);
2227         return ret;
2228     }
2229     WRITEBOOL(reply, rotateSwitch, IPC_STUB_WRITE_PARCEL_ERR);
2230     MMI_HILOGD("Touchpad rotate switch:%{public}d, ret:%{public}d", rotateSwitch, ret);
2231     return RET_OK;
2232 }
2233 
StubSetTouchpadDoubleTapAndDragState(MessageParcel & data,MessageParcel & reply)2234 int32_t MultimodalInputConnectStub::StubSetTouchpadDoubleTapAndDragState(MessageParcel& data, MessageParcel& reply)
2235 {
2236     CALL_DEBUG_ENTER;
2237     int32_t ret = VerifyTouchPadSetting();
2238     if (ret != RET_OK) {
2239         MMI_HILOGE("Verify touchpad setting failed");
2240         return ret;
2241     }
2242 
2243     bool switchFlag = true;
2244     READBOOL(data, switchFlag, IPC_PROXY_DEAD_OBJECT_ERR);
2245     ret = SetTouchpadDoubleTapAndDragState(switchFlag);
2246     if (ret != RET_OK) {
2247         MMI_HILOGE("Set touchpad double tap and drag switch failed ret:%{public}d", ret);
2248         return ret;
2249     }
2250     return RET_OK;
2251 }
2252 
StubGetTouchpadDoubleTapAndDragState(MessageParcel & data,MessageParcel & reply)2253 int32_t MultimodalInputConnectStub::StubGetTouchpadDoubleTapAndDragState(MessageParcel& data, MessageParcel& reply)
2254 {
2255     CALL_DEBUG_ENTER;
2256     int32_t ret = VerifyTouchPadSetting();
2257     if (ret != RET_OK) {
2258         MMI_HILOGE("Verify touchpad setting failed");
2259         return ret;
2260     }
2261 
2262     bool switchFlag = true;
2263     ret = GetTouchpadDoubleTapAndDragState(switchFlag);
2264     if (ret != RET_OK) {
2265         MMI_HILOGE("GetTouchpadDoubleTapAndDragState failed ret:%{public}d", ret);
2266         return ret;
2267     }
2268     WRITEBOOL(reply, switchFlag, IPC_STUB_WRITE_PARCEL_ERR);
2269     return RET_OK;
2270 }
2271 
StubSetShieldStatus(MessageParcel & data,MessageParcel & reply)2272 int32_t MultimodalInputConnectStub::StubSetShieldStatus(MessageParcel& data, MessageParcel& reply)
2273 {
2274     CALL_DEBUG_ENTER;
2275     if (!PER_HELPER->VerifySystemApp()) {
2276         MMI_HILOGE("Verify system APP failed");
2277         return ERROR_NOT_SYSAPI;
2278     }
2279     if (!PER_HELPER->CheckDispatchControl()) {
2280         MMI_HILOGE("input dispatch control permission check failed");
2281         return ERROR_NO_PERMISSION;
2282     }
2283     if (!IsRunning()) {
2284         MMI_HILOGE("Service is not running");
2285         return MMISERVICE_NOT_RUNNING;
2286     }
2287 
2288     int32_t shieldMode { 0 };
2289     bool isShield { false };
2290     READINT32(data, shieldMode, IPC_PROXY_DEAD_OBJECT_ERR);
2291     READBOOL(data, isShield, IPC_PROXY_DEAD_OBJECT_ERR);
2292     int32_t ret = SetShieldStatus(shieldMode, isShield);
2293     if (ret != RET_OK) {
2294         MMI_HILOGE("Call SetShieldStatus failed, ret:%{public}d", ret);
2295         return ret;
2296     }
2297     MMI_HILOGD("Success shieldMode:%{public}d, isShield:%{public}d", shieldMode, isShield);
2298     return RET_OK;
2299 }
2300 
StubGetShieldStatus(MessageParcel & data,MessageParcel & reply)2301 int32_t MultimodalInputConnectStub::StubGetShieldStatus(MessageParcel& data, MessageParcel& reply)
2302 {
2303     CALL_DEBUG_ENTER;
2304     if (!PER_HELPER->VerifySystemApp()) {
2305         MMI_HILOGE("Verify system APP failed");
2306         return ERROR_NOT_SYSAPI;
2307     }
2308     if (!PER_HELPER->CheckDispatchControl()) {
2309         MMI_HILOGE("input dispatch control permission check failed");
2310         return ERROR_NO_PERMISSION;
2311     }
2312     if (!IsRunning()) {
2313         MMI_HILOGE("Service is not running");
2314         return MMISERVICE_NOT_RUNNING;
2315     }
2316 
2317     int32_t shieldMode { 0 };
2318     bool state { false };
2319     READINT32(data, shieldMode, IPC_PROXY_DEAD_OBJECT_ERR);
2320     int32_t ret = GetShieldStatus(shieldMode, state);
2321     if (ret != RET_OK) {
2322         MMI_HILOGE("Call GetShieldStatus failed ret:%{public}d", ret);
2323         return ret;
2324     }
2325     WRITEBOOL(reply, state, IPC_PROXY_DEAD_OBJECT_ERR);
2326     return RET_OK;
2327 }
2328 
StubGetKeyState(MessageParcel & data,MessageParcel & reply)2329 int32_t MultimodalInputConnectStub::StubGetKeyState(MessageParcel& data, MessageParcel& reply)
2330 {
2331     CALL_DEBUG_ENTER;
2332     std::vector<int32_t> pressedKeys;
2333     std::map<int32_t, int32_t> specialKeysState;
2334     int32_t ret = GetKeyState(pressedKeys, specialKeysState);
2335     if (ret != RET_OK) {
2336         MMI_HILOGE("Call GetKeyState failed ret:%{public}d", ret);
2337         return RET_ERR;
2338     }
2339     if (!reply.WriteInt32Vector(pressedKeys)) {
2340         MMI_HILOGE("Write pressedKeys failed");
2341         return RET_ERR;
2342     }
2343     std::vector<int32_t> specialKeysStateTmp;
2344     for (const auto &item : specialKeysState) {
2345         specialKeysStateTmp.push_back(item.second);
2346     }
2347     if (!reply.WriteInt32Vector(specialKeysStateTmp)) {
2348         MMI_HILOGE("Write specialKeysStateTmp failed");
2349         return RET_ERR;
2350     }
2351     return ret;
2352 }
2353 
StubAuthorize(MessageParcel & data,MessageParcel & reply)2354 int32_t MultimodalInputConnectStub::StubAuthorize(MessageParcel& data, MessageParcel& reply)
2355 {
2356     CALL_DEBUG_ENTER;
2357     if (!PER_HELPER->VerifySystemApp()) {
2358         MMI_HILOGE("Verify system APP failed");
2359         return ERROR_NOT_SYSAPI;
2360     }
2361     if (!PER_HELPER->CheckAuthorize()) {
2362         MMI_HILOGE("input authorize permission check failed");
2363         return ERROR_NO_PERMISSION;
2364     }
2365     bool isAuthorize { false };
2366     READBOOL(data, isAuthorize, IPC_PROXY_DEAD_OBJECT_ERR);
2367     int32_t ret = Authorize(isAuthorize);
2368     if (ret != RET_OK) {
2369         MMI_HILOGE("Call Authorize failed ret:%{public}d", ret);
2370         return ret;
2371     }
2372     return RET_OK;
2373 }
2374 
StubCancelInjection(MessageParcel & data,MessageParcel & reply)2375 int32_t MultimodalInputConnectStub::StubCancelInjection(MessageParcel& data, MessageParcel& reply)
2376 {
2377     CALL_DEBUG_ENTER;
2378     int32_t ret = CancelInjection();
2379     if (ret != RET_OK) {
2380         MMI_HILOGE("Call CancelInjection failed ret:%{public}d", ret);
2381         return ret;
2382     }
2383     return RET_OK;
2384 }
2385 
StubHasIrEmitter(MessageParcel & data,MessageParcel & reply)2386 int32_t MultimodalInputConnectStub::StubHasIrEmitter(MessageParcel& data, MessageParcel& reply)
2387 {
2388     CALL_DEBUG_ENTER;
2389     if (!PER_HELPER->VerifySystemApp()) {
2390         MMI_HILOGE("Verify system APP failed");
2391         return ERROR_NOT_SYSAPI;
2392     }
2393     bool hasIrEmitter = false;
2394     int32_t ret = HasIrEmitter(hasIrEmitter);
2395     if (ret != RET_OK) {
2396         MMI_HILOGE("Call StubHasIrEmitter failed ret:%{public}d", ret);
2397         return ret;
2398     }
2399     WRITEBOOL(reply, hasIrEmitter, IPC_STUB_WRITE_PARCEL_ERR);
2400     return RET_OK;
2401 }
2402 
StubGetInfraredFrequencies(MessageParcel & data,MessageParcel & reply)2403 int32_t MultimodalInputConnectStub::StubGetInfraredFrequencies(MessageParcel& data, MessageParcel& reply)
2404 {
2405     CALL_DEBUG_ENTER;
2406     if (!PER_HELPER->CheckInfraredEmmit()) {
2407         MMI_HILOGE("Infrared permission check failed");
2408         return ERROR_NO_PERMISSION;
2409     }
2410     std::vector<InfraredFrequency> requencys;
2411     int32_t ret = GetInfraredFrequencies(requencys);
2412     if (ret != RET_OK) {
2413         MMI_HILOGE("Call StubGetInfraredFrequencies failed returnCode:%{public}d", ret);
2414         return ret;
2415     }
2416     WRITEINT64(reply, requencys.size());
2417     for (const auto &item : requencys) {
2418         WRITEINT64(reply, item.max_);
2419         WRITEINT64(reply, item.min_);
2420     }
2421     return RET_OK;
2422 }
2423 
StubTransmitInfrared(MessageParcel & data,MessageParcel & reply)2424 int32_t MultimodalInputConnectStub::StubTransmitInfrared(MessageParcel& data, MessageParcel& reply)
2425 {
2426     CALL_DEBUG_ENTER;
2427     if (!PER_HELPER->CheckInfraredEmmit()) {
2428         MMI_HILOGE("StubTransmitInfrared permission check failed. returnCode:%{public}d", ERROR_NO_PERMISSION);
2429         return ERROR_NO_PERMISSION;
2430     }
2431     int64_t number = 0;
2432     READINT64(data, number, IPC_PROXY_DEAD_OBJECT_ERR);
2433     int32_t patternLen = 0;
2434     std::vector<int64_t> pattern;
2435     READINT32(data, patternLen, IPC_PROXY_DEAD_OBJECT_ERR);
2436     if (patternLen > MAX_N_TRANSMIT_INFRARED_PATTERN || patternLen <= 0) {
2437         MMI_HILOGE("Transmit infrared pattern len is invalid");
2438         return false;
2439     }
2440     for (int32_t i = 0; i < patternLen; i++) {
2441         int64_t value = 0;
2442         READINT64(data, value);
2443         pattern.push_back(value);
2444     }
2445     int32_t ret = TransmitInfrared(number, pattern);
2446     if (ret != RET_OK) {
2447         MMI_HILOGE("Call StubTransmitInfrared failed returnCode:%{public}d", ret);
2448         return ret;
2449     }
2450     WRITEINT32(reply, ret);
2451     return RET_OK;
2452 }
2453 
StubSetPixelMapData(MessageParcel & data,MessageParcel & reply)2454 int32_t MultimodalInputConnectStub::StubSetPixelMapData(MessageParcel& data, MessageParcel& reply)
2455 {
2456     CALL_DEBUG_ENTER;
2457     if (!PER_HELPER->VerifySystemApp()) {
2458         MMI_HILOGE("Verify system APP failed");
2459         return ERROR_NOT_SYSAPI;
2460     }
2461     if (!IsRunning()) {
2462         MMI_HILOGE("Service is not running");
2463         return MMISERVICE_NOT_RUNNING;
2464     }
2465     int32_t infoId = -1;
2466     READINT32(data, infoId, IPC_PROXY_DEAD_OBJECT_ERR);
2467     if (infoId <= 0) {
2468         MMI_HILOGE("Invalid infoId:%{public}d", infoId);
2469         return RET_ERR;
2470     }
2471     OHOS::Media::PixelMap* pixelMap = Media::PixelMap::Unmarshalling(data);
2472     CHKPR(pixelMap, RET_ERR);
2473     int32_t ret = SetPixelMapData(infoId, static_cast<void*>(pixelMap));
2474     if (ret != RET_OK) {
2475         MMI_HILOGE("Failed to call SetPixelMapData, ret:%{public}d", ret);
2476     }
2477     return ret;
2478 }
2479 
StubSetCurrentUser(MessageParcel & data,MessageParcel & reply)2480 int32_t MultimodalInputConnectStub::StubSetCurrentUser(MessageParcel& data, MessageParcel& reply)
2481 {
2482     CALL_DEBUG_ENTER;
2483     if (!PER_HELPER->VerifySystemApp()) {
2484         MMI_HILOGE("StubSetCurrentUser Verify system APP failed");
2485         return ERROR_NOT_SYSAPI;
2486     }
2487     int32_t userId = 0;
2488     READINT32(data, userId, IPC_PROXY_DEAD_OBJECT_ERR);
2489     std::string callingTokenName;
2490     Security::AccessToken::HapTokenInfo callingTokenInfo;
2491     auto tokenId = IPCSkeleton::GetCallingTokenID();
2492     if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, callingTokenInfo) != 0) {
2493         MMI_HILOGE("GetHapTokenInfo failed");
2494         return RET_ERR;
2495     }
2496     callingTokenName = callingTokenInfo.bundleName;
2497     int32_t callingUid = GetCallingUid();
2498     if (callingUid < UID_TRANSFORM_DIVISOR) {
2499         MMI_HILOGE("CallingUid is not within the range:%{public}d", callingUid);
2500         return RET_ERR;
2501     }
2502     if (callingUid / UID_TRANSFORM_DIVISOR != userId) {
2503         MMI_HILOGE("Invalid CallingUid:%{public}d", callingUid);
2504         return RET_ERR;
2505     }
2506     if (callingTokenName != SCENEBOARD_NAME) {
2507         MMI_HILOGE("Invalid Caller:%{public}s", callingTokenName.c_str());
2508         return RET_ERR;
2509     }
2510     int32_t ret = SetCurrentUser(userId);
2511     if (ret != RET_OK) {
2512         MMI_HILOGE("Failed to call SetCurrentUser ret:%{public}d", ret);
2513         return ret;
2514     }
2515     WRITEINT32(reply, ret);
2516     return RET_OK;
2517 }
2518 
StubAddVirtualInputDevice(MessageParcel & data,MessageParcel & reply)2519 int32_t MultimodalInputConnectStub::StubAddVirtualInputDevice(MessageParcel& data, MessageParcel& reply)
2520 {
2521     CALL_DEBUG_ENTER;
2522     if (!PER_HELPER->VerifySystemApp()) {
2523         MMI_HILOGE("Verify system APP failed");
2524         return ERROR_NOT_SYSAPI;
2525     }
2526     auto device = std::make_shared<InputDevice>();
2527     if (g_parseInputDevice(data, device) != RET_OK) {
2528         MMI_HILOGE("ParseInputDevice failed");
2529         return RET_ERR;
2530     }
2531     int32_t deviceId { -1 };
2532     int32_t ret = AddVirtualInputDevice(device, deviceId);
2533     if (ret != RET_OK) {
2534         MMI_HILOGE("AddVirtualInputDevice failed");
2535         return ret;
2536     }
2537     WRITEINT32(reply, deviceId);
2538     return RET_OK;
2539 }
2540 
StubRemoveVirtualInputDevice(MessageParcel & data,MessageParcel & reply)2541 int32_t MultimodalInputConnectStub::StubRemoveVirtualInputDevice(MessageParcel& data, MessageParcel& reply)
2542 {
2543     CALL_DEBUG_ENTER;
2544     if (!PER_HELPER->VerifySystemApp()) {
2545         MMI_HILOGE("Verify system APP failed");
2546         return ERROR_NOT_SYSAPI;
2547     }
2548     int32_t deviceId { -1 };
2549     READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR);
2550     int32_t ret = RemoveVirtualInputDevice(deviceId);
2551     if (ret != RET_OK) {
2552         MMI_HILOGE("RemoveVirtualInputDevice failed");
2553         return ret;
2554     }
2555     WRITEINT32(reply, ret);
2556     return RET_OK;
2557 }
2558 
StubEnableHardwareCursorStats(MessageParcel & data,MessageParcel & reply)2559 int32_t MultimodalInputConnectStub::StubEnableHardwareCursorStats(MessageParcel& data, MessageParcel& reply)
2560 {
2561     CALL_DEBUG_ENTER;
2562     bool enable = false;
2563     READBOOL(data, enable, IPC_PROXY_DEAD_OBJECT_ERR);
2564     int32_t ret = EnableHardwareCursorStats(enable);
2565     if (ret != RET_OK) {
2566         MMI_HILOGE("Call EnableHardwareCursorStats failed ret:%{public}d", ret);
2567         return ret;
2568     }
2569     return RET_OK;
2570 }
2571 
StubGetHardwareCursorStats(MessageParcel & data,MessageParcel & reply)2572 int32_t MultimodalInputConnectStub::StubGetHardwareCursorStats(MessageParcel& data, MessageParcel& reply)
2573 {
2574     CALL_DEBUG_ENTER;
2575     uint32_t frameCount = 0;
2576     uint32_t vsyncCount = 0;
2577     int32_t ret = GetHardwareCursorStats(frameCount, vsyncCount);
2578     if (ret != RET_OK) {
2579         MMI_HILOGE("Call GetHardwareCursorStats failed ret:%{public}d", ret);
2580         return ret;
2581     }
2582     WRITEUINT32(reply, frameCount, IPC_PROXY_DEAD_OBJECT_ERR);
2583     WRITEUINT32(reply, vsyncCount, IPC_PROXY_DEAD_OBJECT_ERR);
2584     return RET_OK;
2585 }
2586 
2587 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
StubGetPointerSnapshot(MessageParcel & data,MessageParcel & reply)2588 int32_t MultimodalInputConnectStub::StubGetPointerSnapshot(MessageParcel &data, MessageParcel &reply)
2589 {
2590     CALL_DEBUG_ENTER;
2591     if (!IsRunning()) {
2592         MMI_HILOGE("Service is not running");
2593         return MMISERVICE_NOT_RUNNING;
2594     }
2595     if (!PER_HELPER->VerifySystemApp()) {
2596         MMI_HILOGE("Verify system APP failed");
2597         return ERROR_NOT_SYSAPI;
2598     }
2599     std::shared_ptr<Media::PixelMap> pixelMap;
2600     int32_t ret = GetPointerSnapshot(&pixelMap);
2601     if (ret != RET_OK) {
2602         MMI_HILOGE("Call GetPointerSnapshot failed ret:%{public}d", ret);
2603         return ret;
2604     }
2605     CHKPR(pixelMap, ERR_INVALID_VALUE);
2606     if (pixelMap->GetCapacity() == 0) {
2607         MMI_HILOGE("pixelMap is empty, we dont have to pass it to the server");
2608         return ERR_INVALID_VALUE;
2609     }
2610     pixelMap->Marshalling(reply);
2611     return RET_OK;
2612 }
2613 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
2614 
2615 #ifdef OHOS_BUILD_ENABLE_ANCO
StubAncoAddChannel(MessageParcel & data,MessageParcel & reply)2616 int32_t MultimodalInputConnectStub::StubAncoAddChannel(MessageParcel& data, MessageParcel& reply)
2617 {
2618     CALL_DEBUG_ENTER;
2619     if (!PER_HELPER->VerifySystemApp()) {
2620         MMI_HILOGE("Verify system APP failed");
2621         return ERROR_NOT_SYSAPI;
2622     }
2623     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2624     CHKPR(remoteObj, ERR_INVALID_VALUE);
2625     sptr<IAncoChannel> channel = iface_cast<IAncoChannel>(remoteObj);
2626     CHKPR(channel, ERROR_NULL_POINTER);
2627     int32_t ret = AncoAddChannel(channel);
2628     if (ret != RET_OK) {
2629         MMI_HILOGE("AncoAddChannel fail, error:%{public}d", ret);
2630     }
2631     WRITEINT32(reply, ret);
2632     return ret;
2633 }
2634 
StubAncoRemoveChannel(MessageParcel & data,MessageParcel & reply)2635 int32_t MultimodalInputConnectStub::StubAncoRemoveChannel(MessageParcel& data, MessageParcel& reply)
2636 {
2637     CALL_DEBUG_ENTER;
2638     if (!PER_HELPER->VerifySystemApp()) {
2639         MMI_HILOGE("Verify system APP failed");
2640         return ERROR_NOT_SYSAPI;
2641     }
2642     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2643     CHKPR(remoteObj, ERR_INVALID_VALUE);
2644     sptr<IAncoChannel> channel = iface_cast<IAncoChannel>(remoteObj);
2645     CHKPR(channel, ERROR_NULL_POINTER);
2646     int32_t ret = AncoRemoveChannel(channel);
2647     if (ret != RET_OK) {
2648         MMI_HILOGE("AncoRemoveChannel fail, error:%{public}d", ret);
2649     }
2650     WRITEINT32(reply, ret);
2651     return ret;
2652 }
2653 #endif // OHOS_BUILD_ENABLE_ANCO
2654 
StubTransferBinderClientService(MessageParcel & data,MessageParcel & reply)2655 int32_t MultimodalInputConnectStub::StubTransferBinderClientService(MessageParcel& data, MessageParcel& reply)
2656 {
2657     CALL_DEBUG_ENTER;
2658     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
2659     CHKPR(remoteObj, ERROR_NULL_POINTER);
2660     int32_t ret = TransferBinderClientSrv(remoteObj);
2661     if (ret != RET_OK) {
2662         MMI_HILOGE("TransferBinderClientSrv failed");
2663         return ret;
2664     }
2665     WRITEINT32(reply, ret);
2666     return RET_OK;
2667 }
2668 
StubSkipPointerLayer(MessageParcel & data,MessageParcel & reply)2669 int32_t MultimodalInputConnectStub::StubSkipPointerLayer(MessageParcel& data, MessageParcel& reply)
2670 {
2671     CALL_DEBUG_ENTER;
2672     bool isSkip = true;
2673     READBOOL(data, isSkip, IPC_PROXY_DEAD_OBJECT_ERR);
2674     int32_t ret = SkipPointerLayer(isSkip);
2675     if (ret != RET_OK) {
2676         MMI_HILOGE("Call SkipPointerLayer failed, ret:%{public}d", ret);
2677         return ret;
2678     }
2679     MMI_HILOGD("Success isSkip:%{public}d, pid:%{public}d", isSkip, GetCallingPid());
2680     return RET_OK;
2681 }
2682 
StubGetIntervalSinceLastInput(MessageParcel & data,MessageParcel & reply)2683 int32_t MultimodalInputConnectStub::StubGetIntervalSinceLastInput(MessageParcel& data, MessageParcel& reply)
2684 {
2685     CALL_DEBUG_ENTER;
2686     int64_t timeInterval = 0;
2687     int32_t ret = GetIntervalSinceLastInput(timeInterval);
2688     if (ret != RET_OK) {
2689         MMI_HILOGE("Failed to call StubGetIntervalSinceLastInput ret:%{public}d", ret);
2690     } else {
2691         WRITEINT64(reply, timeInterval);
2692     }
2693     return ret;
2694 }
2695 
StubShiftAppPointerEvent(MessageParcel & data,MessageParcel & reply)2696 int32_t MultimodalInputConnectStub::StubShiftAppPointerEvent(MessageParcel& data, MessageParcel& reply)
2697 {
2698     CALL_DEBUG_ENTER;
2699     if (!PER_HELPER->VerifySystemApp()) {
2700         MMI_HILOGE("Verify system APP failed");
2701         return ERROR_NOT_SYSAPI;
2702     }
2703     if (!IsRunning()) {
2704         MMI_HILOGE("Service is not running");
2705         return MMISERVICE_NOT_RUNNING;
2706     }
2707     ShiftWindowParam param;
2708     READINT32(data, param.sourceWindowId, ERR_INVALID_VALUE);
2709     READINT32(data, param.targetWindowId, ERR_INVALID_VALUE);
2710     READINT32(data, param.x, ERR_INVALID_VALUE);
2711     READINT32(data, param.y, ERR_INVALID_VALUE);
2712     bool autoGenDown = true;
2713     READBOOL(data, autoGenDown, IPC_PROXY_DEAD_OBJECT_ERR);
2714     int32_t ret = ShiftAppPointerEvent(param, autoGenDown);
2715     if (ret != RET_OK) {
2716         MMI_HILOGE("shift AppPointerEvent failed, ret:%{public}d", ret);
2717     }
2718     return ret;
2719 }
2720 
StubSetCustomMouseCursor(MessageParcel & data,MessageParcel & reply)2721 int32_t MultimodalInputConnectStub::StubSetCustomMouseCursor(MessageParcel& data, MessageParcel& reply)
2722 {
2723     CALL_DEBUG_ENTER;
2724     if (!IsRunning()) {
2725         MMI_HILOGE("Service is not running");
2726         return MMISERVICE_NOT_RUNNING;
2727     }
2728     int32_t windowId = 0;
2729     CustomCursor cursor;
2730     CursorOptions options;
2731     READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR);
2732     OHOS::Media::PixelMap* pixelMapPtr = Media::PixelMap::Unmarshalling(data);
2733     CHKPR(pixelMapPtr, RET_ERR);
2734     cursor.pixelMap = (void*)pixelMapPtr;
2735     READINT32(data, cursor.focusX, IPC_PROXY_DEAD_OBJECT_ERR);
2736     READINT32(data, cursor.focusY, IPC_PROXY_DEAD_OBJECT_ERR);
2737     READBOOL(data, options.followSystem, IPC_PROXY_DEAD_OBJECT_ERR);
2738 
2739     int32_t ret = SetCustomCursor(windowId, cursor, options);
2740     if (ret != RET_OK) {
2741         MMI_HILOGE("Call SetCustomCursor failed:%{public}d", ret);
2742         return ret;
2743     }
2744     return RET_OK;
2745 }
2746 } // namespace MMI
2747 } // namespace OHOS
2748