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