1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "input_manager_impl.h"
17 
18 #include <cinttypes>
19 
20 #include <unistd.h>
21 
22 #ifdef OHOS_BUILD_ENABLE_ANCO
23 #include "anco_channel.h"
24 #endif // OHOS_BUILD_ENABLE_ANCO
25 #include "anr_handler.h"
26 #include "bytrace_adapter.h"
27 #include "define_multimodal.h"
28 #include "error_multimodal.h"
29 #include "event_filter_service.h"
30 #include "event_log_helper.h"
31 #include "input_scene_board_judgement.h"
32 #include "mmi_client.h"
33 #include "multimodal_event_handler.h"
34 #include "multimodal_input_connect_manager.h"
35 #include "oh_input_manager.h"
36 #include "pixel_map.h"
37 #include "switch_event_input_subscribe_manager.h"
38 
39 #undef MMI_LOG_TAG
40 #define MMI_LOG_TAG "InputManagerImpl"
41 
42 namespace OHOS {
43 namespace MMI {
44 namespace {
45 constexpr size_t MAX_FILTER_NUM { 4 };
46 constexpr int32_t MAX_DELAY { 4000 };
47 constexpr int32_t MIN_DELAY { 0 };
48 constexpr int32_t SIMULATE_EVENT_START_ID { 10000 };
49 constexpr int32_t EVENT_TYPE { 0 };
50 constexpr uint8_t LOOP_COND { 2 };
51 constexpr int32_t MAX_PKT_SIZE { 8 * 1024 };
52 constexpr int32_t WINDOWINFO_RECT_COUNT { 2 };
53 constexpr int32_t DISPLAY_STRINGS_MAX_SIZE { 27 * 2 };
54 constexpr int32_t INVALID_KEY_ACTION { -1 };
55 constexpr int32_t MAX_WINDOW_SIZE { 15 };
56 const std::map<int32_t, int32_t> g_keyActionMap = {
57     {KeyEvent::KEY_ACTION_DOWN, KEY_ACTION_DOWN},
58     {KeyEvent::KEY_ACTION_UP, KEY_ACTION_UP},
59     {KeyEvent::KEY_ACTION_CANCEL, KEY_ACTION_CANCEL}
60 };
61 } // namespace
62 
63 struct MonitorEventConsumer : public IInputEventConsumer {
MonitorEventConsumerOHOS::MMI::MonitorEventConsumer64     explicit MonitorEventConsumer(const std::function<void(std::shared_ptr<PointerEvent>)> &monitor)
65         : monitor_ (monitor) {}
66 
MonitorEventConsumerOHOS::MMI::MonitorEventConsumer67     explicit MonitorEventConsumer(const std::function<void(std::shared_ptr<KeyEvent>)> &monitor)
68         : keyMonitor_ (monitor) {}
69 
OnInputEventOHOS::MMI::MonitorEventConsumer70     void OnInputEvent(std::shared_ptr<KeyEvent> keyEvent) const
71     {
72         CHKPV(keyEvent);
73         CHKPV(keyMonitor_);
74         keyMonitor_(keyEvent);
75     }
76 
OnInputEventOHOS::MMI::MonitorEventConsumer77     void OnInputEvent(std::shared_ptr<PointerEvent> pointerEvent) const
78     {
79         CHKPV(pointerEvent);
80         CHKPV(monitor_);
81         monitor_(pointerEvent);
82     }
83 
OnInputEventOHOS::MMI::MonitorEventConsumer84     void OnInputEvent(std::shared_ptr<AxisEvent> axisEvent) const
85     {
86         CHKPV(axisEvent);
87         CHKPV(axisMonitor_);
88         axisMonitor_(axisEvent);
89     }
90 
91 private:
92     std::function<void(std::shared_ptr<PointerEvent>)> monitor_;
93     std::function<void(std::shared_ptr<KeyEvent>)> keyMonitor_;
94     std::function<void(std::shared_ptr<AxisEvent>)> axisMonitor_;
95 };
96 
InputManagerImpl()97 InputManagerImpl::InputManagerImpl() {}
~InputManagerImpl()98 InputManagerImpl::~InputManagerImpl() {}
99 
GetDisplayBindInfo(DisplayBindInfos &infos)100 int32_t InputManagerImpl::GetDisplayBindInfo(DisplayBindInfos &infos)
101 {
102     CALL_INFO_TRACE;
103     std::lock_guard<std::mutex> guard(mtx_);
104     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetDisplayBindInfo(infos);
105     if (ret != RET_OK) {
106         MMI_HILOGE("GetDisplayBindInfo failed, ret:%{public}d", ret);
107         return RET_ERR;
108     }
109     return RET_OK;
110 }
111 
GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas)112 int32_t InputManagerImpl::GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas)
113 {
114     CALL_INFO_TRACE;
115     std::lock_guard<std::mutex> guard(mtx_);
116     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetAllMmiSubscribedEvents(datas);
117     if (ret != RET_OK) {
118         MMI_HILOGE("GetDisplayBindInfo failed, ret:%{public}d", ret);
119     }
120     return ret;
121 }
122 
SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg)123 int32_t InputManagerImpl::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg)
124 {
125     CALL_INFO_TRACE;
126     std::lock_guard<std::mutex> guard(mtx_);
127     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetDisplayBind(deviceId, displayId, msg);
128     if (ret != RET_OK) {
129         MMI_HILOGE("SetDisplayBind failed, ret:%{public}d", ret);
130         return RET_ERR;
131     }
132     return RET_OK;
133 }
134 
GetWindowPid(int32_t windowId)135 int32_t InputManagerImpl::GetWindowPid(int32_t windowId)
136 {
137     CALL_INFO_TRACE;
138     std::lock_guard<std::mutex> guard(mtx_);
139     return MULTIMODAL_INPUT_CONNECT_MGR->GetWindowPid(windowId);
140 }
141 
UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo)142 int32_t InputManagerImpl::UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo)
143 {
144     CALL_DEBUG_ENTER;
145     std::lock_guard<std::mutex> guard(mtx_);
146     if (displayGroupInfo.windowsInfo.size() < MAX_WINDOW_SIZE) {
147         windowGroupInfo_.windowsInfo.clear();
148     }
149     if (!MMIEventHdl.InitClient()) {
150         MMI_HILOGE("Failed to initialize MMI client");
151         return RET_ERR;
152     }
153     displayGroupInfo_ = displayGroupInfo;
154     int32_t ret = SendDisplayInfo();
155     if (ret != RET_OK) {
156         MMI_HILOGE("Failed to send display information to service");
157         return ret;
158     }
159     PrintDisplayInfo();
160     return RET_OK;
161 }
162 
UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo)163 int32_t InputManagerImpl::UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo)
164 {
165     CALL_DEBUG_ENTER;
166     std::lock_guard<std::mutex> guard(mtx_);
167     if (!MMIEventHdl.InitClient()) {
168         MMI_HILOGE("Failed to initialize MMI client");
169         return RET_ERR;
170     }
171     if (!IsValiadWindowAreas(windowGroupInfo.windowsInfo)) {
172         MMI_HILOGE("Invalid window information");
173         return PARAM_INPUT_INVALID;
174     }
175     windowGroupInfo_ = windowGroupInfo;
176     int32_t ret = SendWindowInfo();
177     if (ret != RET_OK) {
178         MMI_HILOGE("Failed to send window information to service");
179         return ret;
180     }
181     PrintWindowGroupInfo();
182     return RET_OK;
183 }
184 
IsValiadWindowAreas(const std::vector<WindowInfo> &windows)185 bool InputManagerImpl::IsValiadWindowAreas(const std::vector<WindowInfo> &windows)
186 {
187     CALL_DEBUG_ENTER;
188 #ifdef OHOS_BUILD_ENABLE_ANCO
189     if (IsValidAncoWindow(windows)) {
190         return true;
191     }
192 #endif // OHOS_BUILD_ENABLE_ANCO
193     for (const auto &window : windows) {
194         if (window.action == WINDOW_UPDATE_ACTION::DEL) {
195             continue;
196         }
197         if (window.defaultHotAreas.empty() || window.pointerHotAreas.empty() ||
198             (!window.pointerChangeAreas.empty() &&
199             window.pointerChangeAreas.size() != WindowInfo::POINTER_CHANGEAREA_COUNT) ||
200             (!window.transform.empty() && window.transform.size() != WindowInfo::WINDOW_TRANSFORM_SIZE)) {
201             MMI_HILOGE("Hot areas check failed! defaultHotAreas:size:%{public}zu,"
202                 "pointerHotAreas:size:%{public}zu, pointerChangeAreas:size:%{public}zu,"
203                 "transform:size:%{public}zu", window.defaultHotAreas.size(),
204                 window.pointerHotAreas.size(), window.pointerChangeAreas.size(),
205                 window.transform.size());
206             return false;
207         }
208     }
209     return true;
210 }
211 
GetDisplayMaxSize()212 int32_t InputManagerImpl::GetDisplayMaxSize()
213 {
214     return sizeof(DisplayInfo) + DISPLAY_STRINGS_MAX_SIZE;
215 }
216 
GetWindowMaxSize(int32_t maxAreasCount)217 int32_t InputManagerImpl::GetWindowMaxSize(int32_t maxAreasCount)
218 {
219     return sizeof(WindowInfo) + sizeof(Rect) * maxAreasCount * WINDOWINFO_RECT_COUNT
220            + sizeof(int32_t) * WindowInfo::POINTER_CHANGEAREA_COUNT
221            + sizeof(float) * WindowInfo::WINDOW_TRANSFORM_SIZE;
222 }
223 
224 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
SetEnhanceConfig(uint8_t *cfg, uint32_t cfgLen)225 void InputManagerImpl::SetEnhanceConfig(uint8_t *cfg, uint32_t cfgLen)
226 {
227     CALL_INFO_TRACE;
228     if (cfg == nullptr || cfgLen == 0) {
229         MMI_HILOGE("SecCompEnhance cfg info is empty");
230         return;
231     }
232     enhanceCfg_ = new (std::nothrow) uint8_t[cfgLen];
233     CHKPV(enhanceCfg_);
234     errno_t ret = memcpy_s(enhanceCfg_, cfgLen, cfg, cfgLen);
235     if (ret != EOK) {
236         MMI_HILOGE("cfg memcpy failed");
237         return;
238     }
239     enhanceCfgLen_ = cfgLen;
240     std::lock_guard<std::mutex> guard(mtx_);
241     if (!MMIEventHdl.InitClient()) {
242         MMI_HILOGE("Get mmi client is nullptr");
243         return;
244     }
245     SendEnhanceConfig();
246     PrintEnhanceConfig();
247 }
248 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
249 
AddInputEventFilter(std::shared_ptr<IInputEventFilter> filter, int32_t priority, uint32_t deviceTags)250 int32_t InputManagerImpl::AddInputEventFilter(std::shared_ptr<IInputEventFilter> filter, int32_t priority,
251     uint32_t deviceTags)
252 {
253     CALL_INFO_TRACE;
254     std::lock_guard<std::mutex> guard(mtx_);
255     CHKPR(filter, RET_ERR);
256     if (eventFilterServices_.size() >= MAX_FILTER_NUM) {
257         MMI_HILOGE("Too many filters, size:%{public}zu", eventFilterServices_.size());
258         return RET_ERR;
259     }
260     sptr<IEventFilter> service = new (std::nothrow) EventFilterService(filter);
261     CHKPR(service, RET_ERR);
262     const int32_t filterId = EventFilterService::GetNextId();
263     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->AddInputEventFilter(service, filterId, priority, deviceTags);
264     if (ret != RET_OK) {
265         MMI_HILOGE("AddInputEventFilter has send to server failed, priority:%{public}d, ret:%{public}d", priority, ret);
266         service = nullptr;
267         return RET_ERR;
268     }
269     auto it = eventFilterServices_.emplace(filterId, std::make_tuple(service, priority, deviceTags));
270     if (!it.second) {
271         MMI_HILOGW("filterId duplicate");
272     }
273     return filterId;
274 }
275 
AddInputEventObserver(std::shared_ptr<MMIEventObserver> observer)276 int32_t InputManagerImpl::AddInputEventObserver(std::shared_ptr<MMIEventObserver> observer)
277 {
278     CALL_INFO_TRACE;
279     std::lock_guard<std::mutex> guard(mtx_);
280     CHKPR(observer, RET_ERR);
281     if (!MMIEventHdl.InitClient()) {
282         MMI_HILOGE("Get mmi client is nullptr");
283         return RET_ERR;
284     }
285     eventObserver_ = observer;
286     NotifyNapOnline();
287     return RET_OK;
288 }
289 
RemoveInputEventObserver(std::shared_ptr<MMIEventObserver> observer)290 int32_t InputManagerImpl::RemoveInputEventObserver(std::shared_ptr<MMIEventObserver> observer)
291 {
292     CALL_INFO_TRACE;
293     std::lock_guard<std::mutex> guard(mtx_);
294     eventObserver_ = nullptr;
295     return MULTIMODAL_INPUT_CONNECT_MGR->RemoveInputEventObserver();
296 }
297 
NotifyNapOnline()298 int32_t InputManagerImpl::NotifyNapOnline()
299 {
300     CALL_DEBUG_ENTER;
301     return MULTIMODAL_INPUT_CONNECT_MGR->NotifyNapOnline();
302 }
303 
RemoveInputEventFilter(int32_t filterId)304 int32_t InputManagerImpl::RemoveInputEventFilter(int32_t filterId)
305 {
306     CALL_DEBUG_ENTER;
307     std::lock_guard<std::mutex> guard(mtx_);
308     if (eventFilterServices_.empty()) {
309         MMI_HILOGE("Filters is empty, size:%{public}zu", eventFilterServices_.size());
310         return RET_OK;
311     }
312     std::map<int32_t, std::tuple<sptr<IEventFilter>, int32_t, uint32_t>>::iterator it;
313     if (filterId != -1) {
314         it = eventFilterServices_.find(filterId);
315         if (it == eventFilterServices_.end()) {
316             MMI_HILOGE("Filter not found");
317             return RET_OK;
318         }
319     }
320     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->RemoveInputEventFilter(filterId);
321     if (ret != RET_OK) {
322         MMI_HILOGE("Remove filter failed, filter id:%{public}d, ret:%{public}d", filterId, ret);
323         return RET_ERR;
324     }
325     if (filterId != -1) {
326         eventFilterServices_.erase(it);
327     } else {
328         eventFilterServices_.clear();
329     }
330     MMI_HILOGI("Filter remove success");
331     return RET_OK;
332 }
333 
SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer, std::shared_ptr<AppExecFwk::EventHandler> eventHandler)334 void InputManagerImpl::SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer,
335     std::shared_ptr<AppExecFwk::EventHandler> eventHandler)
336 {
337     CALL_INFO_TRACE;
338     CHK_PID_AND_TID();
339     CHKPV(inputEventConsumer);
340     CHKPV(eventHandler);
341     {
342         std::lock_guard<std::mutex> guard(mtx_);
343         if (!MMIEventHdl.InitClient(eventHandler)) {
344             MMI_HILOGE("Client init failed");
345             return;
346         }
347     }
348     std::lock_guard<std::mutex> guard(resourceMtx_);
349     consumer_ = inputEventConsumer;
350     eventHandler_ = eventHandler;
351 }
352 
SubscribeKeyEvent(std::shared_ptr<KeyOption> keyOption, std::function<void(std::shared_ptr<KeyEvent>)> callback)353 int32_t InputManagerImpl::SubscribeKeyEvent(std::shared_ptr<KeyOption> keyOption,
354     std::function<void(std::shared_ptr<KeyEvent>)> callback)
355 {
356     CALL_INFO_TRACE;
357     CHK_PID_AND_TID();
358     std::lock_guard<std::mutex> guard(mtx_);
359 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
360     CHKPR(keyOption, RET_ERR);
361     CHKPR(callback, RET_ERR);
362     return KeyEventInputSubscribeMgr.SubscribeKeyEvent(keyOption, callback);
363 #else
364     MMI_HILOGW("Keyboard device does not support");
365     return ERROR_UNSUPPORT;
366 #endif // OHOS_BUILD_ENABLE_KEYBOARD
367 }
368 
UnsubscribeKeyEvent(int32_t subscriberId)369 void InputManagerImpl::UnsubscribeKeyEvent(int32_t subscriberId)
370 {
371     CALL_INFO_TRACE;
372     CHK_PID_AND_TID();
373     std::lock_guard<std::mutex> guard(mtx_);
374 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
375     KeyEventInputSubscribeMgr.UnsubscribeKeyEvent(subscriberId);
376 #else
377     MMI_HILOGW("Keyboard device does not support");
378 #endif // OHOS_BUILD_ENABLE_KEYBOARD
379 }
380 
SubscribeHotkey(std::shared_ptr<KeyOption> keyOption, std::function<void(std::shared_ptr<KeyEvent>)> callback)381 int32_t InputManagerImpl::SubscribeHotkey(std::shared_ptr<KeyOption> keyOption,
382     std::function<void(std::shared_ptr<KeyEvent>)> callback)
383 {
384     CALL_INFO_TRACE;
385     CHK_PID_AND_TID();
386     std::lock_guard<std::mutex> guard(mtx_);
387 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
388     CHKPR(keyOption, RET_ERR);
389     CHKPR(callback, RET_ERR);
390     return KeyEventInputSubscribeMgr.SubscribeHotkey(keyOption, callback);
391 #else
392     MMI_HILOGW("Keyboard device does not support");
393     return ERROR_UNSUPPORT;
394 #endif // OHOS_BUILD_ENABLE_KEYBOARD
395 }
396 
UnsubscribeHotkey(int32_t subscriberId)397 void InputManagerImpl::UnsubscribeHotkey(int32_t subscriberId)
398 {
399     CALL_INFO_TRACE;
400     CHK_PID_AND_TID();
401     std::lock_guard<std::mutex> guard(mtx_);
402 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
403     KeyEventInputSubscribeMgr.UnsubscribeHotkey(subscriberId);
404 #else
405     MMI_HILOGW("Keyboard device does not support");
406 #endif // OHOS_BUILD_ENABLE_KEYBOARD
407 }
408 
SubscribeSwitchEvent(int32_t switchType, std::function<void(std::shared_ptr<SwitchEvent>)> callback)409 int32_t InputManagerImpl::SubscribeSwitchEvent(int32_t switchType,
410     std::function<void(std::shared_ptr<SwitchEvent>)> callback)
411 {
412     CALL_INFO_TRACE;
413     CHK_PID_AND_TID();
414     std::lock_guard<std::mutex> guard(mtx_);
415 #ifdef OHOS_BUILD_ENABLE_SWITCH
416     CHKPR(callback, RET_ERR);
417     if (switchType < SwitchEvent::SwitchType::SWITCH_DEFAULT) {
418         MMI_HILOGE("Switch type error, switchType:%{public}d", switchType);
419         return RET_ERR;
420     }
421     return SWITCH_EVENT_INPUT_SUBSCRIBE_MGR.SubscribeSwitchEvent(switchType, callback);
422 #else
423     MMI_HILOGW("Switch device does not support");
424     return ERROR_UNSUPPORT;
425 #endif // OHOS_BUILD_ENABLE_SWITCH
426 }
427 
UnsubscribeSwitchEvent(int32_t subscriberId)428 void InputManagerImpl::UnsubscribeSwitchEvent(int32_t subscriberId)
429 {
430     CALL_INFO_TRACE;
431     CHK_PID_AND_TID();
432 #ifdef OHOS_BUILD_ENABLE_SWITCH
433     SWITCH_EVENT_INPUT_SUBSCRIBE_MGR.UnsubscribeSwitchEvent(subscriberId);
434 #else
435     MMI_HILOGW("Switch device does not support");
436 #endif // OHOS_BUILD_ENABLE_SWITCH
437 }
438 
439 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
OnKeyEventTask(std::shared_ptr<IInputEventConsumer> consumer, std::shared_ptr<KeyEvent> keyEvent)440 void InputManagerImpl::OnKeyEventTask(std::shared_ptr<IInputEventConsumer> consumer,
441     std::shared_ptr<KeyEvent> keyEvent)
442 {
443     CALL_INFO_TRACE;
444     LogTracer lt(keyEvent->GetId(), keyEvent->GetEventType(), keyEvent->GetKeyAction());
445     CHK_PID_AND_TID();
446     CHKPV(consumer);
447     BytraceAdapter::StartConsumer(keyEvent);
448     consumer->OnInputEvent(keyEvent);
449     BytraceAdapter::StopConsumer();
450     MMI_HILOGD("Key event callback keyCode:%{private}d", keyEvent->GetKeyCode());
451 }
452 
OnKeyEvent(std::shared_ptr<KeyEvent> keyEvent)453 void InputManagerImpl::OnKeyEvent(std::shared_ptr<KeyEvent> keyEvent)
454 {
455     CALL_INFO_TRACE;
456     CHK_PID_AND_TID();
457     CHKPV(keyEvent);
458     std::shared_ptr<AppExecFwk::EventHandler> eventHandler = nullptr;
459     std::shared_ptr<IInputEventConsumer> inputConsumer = nullptr;
460     {
461         std::lock_guard<std::mutex> guard(resourceMtx_);
462         CHKPV(eventHandler_);
463         CHKPV(consumer_);
464         eventHandler = eventHandler_;
465         inputConsumer = consumer_;
466     }
467     MMI_HILOG_DISPATCHI("id:%{public}d recv", keyEvent->GetId());
468     BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::TRACE_STOP, BytraceAdapter::KEY_DISPATCH_EVENT);
469     MMIClientPtr client = MMIEventHdl.GetMMIClient();
470     CHKPV(client);
471     if (client->IsEventHandlerChanged()) {
472         BytraceAdapter::StartPostTaskEvent(keyEvent);
473         if (!eventHandler->PostTask([this, inputConsumer, keyEvent] {
474                 return this->OnKeyEventTask(inputConsumer, keyEvent);
475             },
476             std::string("MMI::OnKeyEvent"), 0, AppExecFwk::EventHandler::Priority::VIP)) {
477             MMI_HILOG_DISPATCHE("Post task failed");
478             BytraceAdapter::StopPostTaskEvent();
479             return;
480         }
481         BytraceAdapter::StopPostTaskEvent();
482     } else {
483         BytraceAdapter::StartConsumer(keyEvent);
484         inputConsumer->OnInputEvent(keyEvent);
485         BytraceAdapter::StopConsumer();
486         MMI_HILOG_DISPATCHD("Key event report keyCode:%{private}d", keyEvent->GetKeyCode());
487     }
488     MMI_HILOG_DISPATCHD("Key event keyCode:%{private}d", keyEvent->GetKeyCode());
489 }
490 #endif // OHOS_BUILD_ENABLE_KEYBOARD
491 
492 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
OnPointerEventTask(std::shared_ptr<IInputEventConsumer> consumer, std::shared_ptr<PointerEvent> pointerEvent)493 void InputManagerImpl::OnPointerEventTask(std::shared_ptr<IInputEventConsumer> consumer,
494     std::shared_ptr<PointerEvent> pointerEvent)
495 {
496     CALL_DEBUG_ENTER;
497     LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction());
498     CHK_PID_AND_TID();
499     CHKPV(consumer);
500     CHKPV(pointerEvent);
501     BytraceAdapter::StartConsumer(pointerEvent);
502     consumer->OnInputEvent(pointerEvent);
503     BytraceAdapter::StopConsumer();
504     MMI_HILOG_DISPATCHD("Pointer event callback pointerId:%{public}d",
505         pointerEvent->GetPointerId());
506 }
507 
OnPointerEvent(std::shared_ptr<PointerEvent> pointerEvent)508 void InputManagerImpl::OnPointerEvent(std::shared_ptr<PointerEvent> pointerEvent)
509 {
510     CALL_DEBUG_ENTER;
511     CHK_PID_AND_TID();
512     CHKPV(pointerEvent);
513     std::shared_ptr<AppExecFwk::EventHandler> eventHandler = nullptr;
514     std::shared_ptr<IInputEventConsumer> inputConsumer = nullptr;
515     {
516         std::lock_guard<std::mutex> guard(resourceMtx_);
517         CHKPV(eventHandler_);
518         CHKPV(consumer_);
519         eventHandler = eventHandler_;
520         inputConsumer = consumer_;
521         lastPointerEvent_ = std::make_shared<PointerEvent>(*pointerEvent);
522     }
523     BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_STOP, BytraceAdapter::POINT_DISPATCH_EVENT);
524     MMIClientPtr client = MMIEventHdl.GetMMIClient();
525     CHKPV(client);
526     if (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE &&
527         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_AXIS_UPDATE &&
528         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_ROTATE_UPDATE &&
529         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE) {
530         MMI_HILOG_FREEZEI("id:%{public}d recv", pointerEvent->GetId());
531     }
532     if (client->IsEventHandlerChanged()) {
533         BytraceAdapter::StartPostTaskEvent(pointerEvent);
534         if (!eventHandler->PostTask([this, inputConsumer, pointerEvent] {
535                 return this->OnPointerEventTask(inputConsumer, pointerEvent);
536             },
537             std::string("MMI::OnPointerEvent"), 0, AppExecFwk::EventHandler::Priority::VIP)) {
538             MMI_HILOG_DISPATCHE("Post task failed");
539             BytraceAdapter::StopPostTaskEvent();
540             return;
541         }
542         BytraceAdapter::StopPostTaskEvent();
543     } else {
544         BytraceAdapter::StartConsumer(pointerEvent);
545         inputConsumer->OnInputEvent(pointerEvent);
546         BytraceAdapter::StopConsumer();
547     }
548     MMI_HILOG_DISPATCHD("Pointer event pointerId:%{public}d",
549         pointerEvent->GetPointerId());
550 }
551 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
552 
PackDisplayData(NetPacket &pkt)553 int32_t InputManagerImpl::PackDisplayData(NetPacket &pkt)
554 {
555     CALL_DEBUG_ENTER;
556     pkt << displayGroupInfo_.width << displayGroupInfo_.height
557         << displayGroupInfo_.focusWindowId << displayGroupInfo_.currentUserId;
558     if (pkt.ChkRWError()) {
559         MMI_HILOGE("Packet write logical data failed");
560         return RET_ERR;
561     }
562     if (PackWindowInfo(pkt) != RET_OK) {
563         MMI_HILOGE("Packet write windows info failed");
564         return RET_ERR;
565     }
566     return PackDisplayInfo(pkt);
567 }
568 
PackWindowGroupInfo(NetPacket &pkt)569 int32_t InputManagerImpl::PackWindowGroupInfo(NetPacket &pkt)
570 {
571     CALL_DEBUG_ENTER;
572     pkt << windowGroupInfo_.focusWindowId << windowGroupInfo_.displayId;
573     if (pkt.ChkRWError()) {
574         MMI_HILOGE("Packet write windowGroupInfo data failed");
575         return RET_ERR;
576     }
577     uint32_t num = static_cast<uint32_t>(windowGroupInfo_.windowsInfo.size());
578     pkt << num;
579     for (const auto &item : windowGroupInfo_.windowsInfo) {
580         pkt << item.id << item.pid << item.uid << item.area
581             << item.defaultHotAreas << item.pointerHotAreas
582             << item.agentWindowId << item.flags << item.action
583             << item.displayId << item.zOrder << item.pointerChangeAreas
584             << item.transform << item.windowInputType << item.privacyMode << item.windowType;
585         uint32_t uiExtentionWindowInfoNum = static_cast<uint32_t>(item.uiExtentionWindowInfo.size());
586         pkt << uiExtentionWindowInfoNum;
587         MMI_HILOGD("uiExtentionWindowInfoNum:%{public}u", uiExtentionWindowInfoNum);
588         if (!item.uiExtentionWindowInfo.empty()) {
589             PackUiExtentionWindowInfo(item.uiExtentionWindowInfo, pkt);
590             PrintWindowInfo(item.uiExtentionWindowInfo);
591         }
592         pkt << item.rectChangeBySystem;
593     }
594     if (pkt.ChkRWError()) {
595         MMI_HILOGE("Packet write windows data failed");
596         return RET_ERR;
597     }
598     return RET_OK;
599 }
600 
601 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
PackEnhanceConfig(NetPacket &pkt)602 int32_t InputManagerImpl::PackEnhanceConfig(NetPacket &pkt)
603 {
604     CALL_INFO_TRACE;
605     CHKPR(enhanceCfg_, RET_ERR);
606     pkt << enhanceCfgLen_;
607     for (uint32_t i = 0; i < enhanceCfgLen_; i++) {
608         pkt << enhanceCfg_[i];
609     }
610     if (pkt.ChkRWError()) {
611         MMI_HILOGE("Packet write security info config failed");
612         return RET_ERR;
613     }
614     return RET_OK;
615 }
616 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
617 
PackUiExtentionWindowInfo(const std::vector<WindowInfo>& windowsInfo, NetPacket &pkt)618 int32_t InputManagerImpl::PackUiExtentionWindowInfo(const std::vector<WindowInfo>& windowsInfo, NetPacket &pkt)
619 {
620     CALL_DEBUG_ENTER;
621     for (const auto &item : windowsInfo) {
622         pkt << item.id << item.pid << item.uid << item.area
623             << item.defaultHotAreas << item.pointerHotAreas
624             << item.agentWindowId << item.flags << item.action
625             << item.displayId << item.zOrder << item.pointerChangeAreas
626             << item.transform << item.windowInputType << item.privacyMode
627             << item.windowType << item.privacyUIFlag << item.rectChangeBySystem;
628     }
629     if (pkt.ChkRWError()) {
630         MMI_HILOGE("Packet write windows data failed");
631         return RET_ERR;
632     }
633     return RET_OK;
634 }
635 
PackWindowInfo(NetPacket &pkt)636 int32_t InputManagerImpl::PackWindowInfo(NetPacket &pkt) __attribute__((no_sanitize("cfi")))
637 {
638     CALL_DEBUG_ENTER;
639     uint32_t num = static_cast<uint32_t>(displayGroupInfo_.windowsInfo.size());
640     pkt << num;
641     for (const auto &item : displayGroupInfo_.windowsInfo) {
642         int32_t byteCount = 0;
643         pkt << item.id << item.pid << item.uid << item.area << item.defaultHotAreas
644             << item.pointerHotAreas << item.agentWindowId << item.flags << item.action
645             << item.displayId << item.zOrder << item.pointerChangeAreas << item.transform
646             << item.windowInputType << item.privacyMode << item.windowType;
647 
648         if (item.pixelMap == nullptr) {
649             pkt << byteCount;
650             uint32_t uiExtentionWindowInfoNum = static_cast<uint32_t>(item.uiExtentionWindowInfo.size());
651             pkt << uiExtentionWindowInfoNum;
652             MMI_HILOGD("uiExtentionWindowInfoNum:%{public}u", uiExtentionWindowInfoNum);
653             if (!item.uiExtentionWindowInfo.empty()) {
654                 PackUiExtentionWindowInfo(item.uiExtentionWindowInfo, pkt);
655                 PrintWindowInfo(item.uiExtentionWindowInfo);
656             }
657             pkt << item.rectChangeBySystem;
658             continue;
659         }
660         OHOS::Media::PixelMap* pixelMapPtr = static_cast<OHOS::Media::PixelMap*>(item.pixelMap);
661         byteCount = pixelMapPtr->GetByteCount();
662         int32_t ret = SetPixelMapData(item.id, item.pixelMap);
663         if (ret != RET_OK) {
664             byteCount = 0;
665             MMI_HILOGE("Failed to set pixel map");
666         }
667         pkt << byteCount;
668         uint32_t uiExtentionWindowInfoNum = static_cast<uint32_t>(item.uiExtentionWindowInfo.size());
669         pkt << uiExtentionWindowInfoNum;
670         MMI_HILOGD("uiExtentionWindowInfoNum:%{public}u", uiExtentionWindowInfoNum);
671         if (!item.uiExtentionWindowInfo.empty()) {
672             PackUiExtentionWindowInfo(item.uiExtentionWindowInfo, pkt);
673             PrintWindowInfo(item.uiExtentionWindowInfo);
674         }
675         pkt << item.rectChangeBySystem;
676     }
677     if (pkt.ChkRWError()) {
678         MMI_HILOGE("Packet write windows data failed");
679         return RET_ERR;
680     }
681     return RET_OK;
682 }
683 
PackDisplayInfo(NetPacket &pkt)684 int32_t InputManagerImpl::PackDisplayInfo(NetPacket &pkt)
685 {
686     CALL_DEBUG_ENTER;
687     uint32_t num = static_cast<uint32_t>(displayGroupInfo_.displaysInfo.size());
688     pkt << num;
689     for (const auto &item : displayGroupInfo_.displaysInfo) {
690         pkt << item.id << item.x << item.y << item.width
691             << item.height << item.dpi << item.name << item.uniq << item.direction
692             << item.displayDirection << item.displayMode << item.transform;
693     }
694     if (pkt.ChkRWError()) {
695         MMI_HILOGE("Packet write display data failed");
696         return RET_ERR;
697     }
698     return RET_OK;
699 }
700 
PrintWindowInfo(const std::vector<WindowInfo> &windowsInfo)701 void InputManagerImpl::PrintWindowInfo(const std::vector<WindowInfo> &windowsInfo)
702 {
703     if (!HiLogIsLoggable(MMI_LOG_DOMAIN, MMI_LOG_TAG, LOG_DEBUG)) {
704         return;
705     }
706     for (const auto &item : windowsInfo) {
707         MMI_HILOGD("windowsInfos,id:%{public}d,pid:%{public}d,uid:%{public}d,"
708             "area.x:%{public}d,area.y:%{public}d,area.width:%{public}d,area.height:%{public}d,"
709             "defaultHotAreas.size:%{public}zu,pointerHotAreas.size:%{public}zu,"
710             "agentWindowId:%{public}d,flags:%{public}d,action:%{public}d,displayId:%{public}d,"
711             "zOrder:%{public}f,privacyMode:%{public}d",
712             item.id, item.pid, item.uid, item.area.x, item.area.y, item.area.width,
713             item.area.height, item.defaultHotAreas.size(), item.pointerHotAreas.size(),
714             item.agentWindowId, item.flags, item.action, item.displayId, item.zOrder, item.privacyMode);
715         for (const auto &win : item.defaultHotAreas) {
716             MMI_HILOGD("defaultHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d",
717                 win.x, win.y, win.width, win.height);
718         }
719         for (const auto &pointer : item.pointerHotAreas) {
720             MMI_HILOGD("pointerHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d",
721                 pointer.x, pointer.y, pointer.width, pointer.height);
722         }
723 
724         std::string dump;
725         dump += StringPrintf("pointChangeAreas:[");
726         for (auto it : item.pointerChangeAreas) {
727             dump += StringPrintf("%d,", it);
728         }
729         dump += StringPrintf("] transform:[");
730         for (auto it : item.transform) {
731             dump += StringPrintf("%f,", it);
732         }
733         dump += StringPrintf("]\n");
734         std::istringstream stream(dump);
735         std::string line;
736         while (std::getline(stream, line, '\n')) {
737             MMI_HILOGD("%{public}s", line.c_str());
738         }
739     }
740 }
741 
PrintForemostThreeWindowInfo(const std::vector<WindowInfo> &windowsInfo)742 void InputManagerImpl::PrintForemostThreeWindowInfo(const std::vector<WindowInfo> &windowsInfo)
743 {
744     uint8_t times = 0;
745     for (const auto &item : windowsInfo) {
746         if (times > LOOP_COND) {
747             return;
748         }
749         MMI_HILOGD("WindowInfo[%{public}d,%{public}d,%{public}d,%{public}d,%{public}d,%{public}d,%{public}f]",
750             item.id, item.pid, item.area.x, item.area.y, item.area.width, item.area.height, item.zOrder);
751         for (const auto &pointer : item.pointerHotAreas) {
752             MMI_HILOGD("pointerHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d",
753                 pointer.x, pointer.y, pointer.width, pointer.height);
754         }
755         times++;
756     }
757 }
758 
PrintDisplayInfo()759 void InputManagerImpl::PrintDisplayInfo()
760 {
761     MMI_HILOGD("windowsInfos,num:%{public}zu,focusWindowId:%{public}d", displayGroupInfo_.windowsInfo.size(),
762         displayGroupInfo_.focusWindowId);
763     PrintForemostThreeWindowInfo(displayGroupInfo_.windowsInfo);
764     if (!HiLogIsLoggable(MMI_LOG_DOMAIN, MMI_LOG_TAG, LOG_DEBUG)) {
765         return;
766     }
767     MMI_HILOGD("logicalInfo,width:%{public}d,height:%{public}d,focusWindowId:%{public}d",
768         displayGroupInfo_.width, displayGroupInfo_.height, displayGroupInfo_.focusWindowId);
769     PrintWindowInfo(displayGroupInfo_.windowsInfo);
770 
771     MMI_HILOGD("displayInfos,num:%{public}zu", displayGroupInfo_.displaysInfo.size());
772     for (const auto &item : displayGroupInfo_.displaysInfo) {
773         MMI_HILOGD("displayInfos,id:%{public}d,x:%{public}d,y:%{public}d,"
774             "width:%{public}d,height:%{public}d,dpi:%{public}d,name:%{public}s,"
775             "uniq:%{public}s,direction:%{public}d,displayDirection:%{public}d,displayMode:%{public}d",
776             item.id, item.x, item.y, item.width, item.height, item.dpi, item.name.c_str(),
777             item.uniq.c_str(), item.direction, item.displayDirection, item.displayMode);
778     }
779 }
780 
PrintWindowGroupInfo()781 void InputManagerImpl::PrintWindowGroupInfo()
782 {
783     if (!HiLogIsLoggable(MMI_LOG_DOMAIN, MMI_LOG_TAG, LOG_DEBUG)) {
784         return;
785     }
786     MMI_HILOGD("windowsGroupInfo,focusWindowId:%{public}d,displayId:%{public}d",
787         windowGroupInfo_.focusWindowId, windowGroupInfo_.displayId);
788     PrintWindowInfo(windowGroupInfo_.windowsInfo);
789 }
790 
791 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
PrintEnhanceConfig()792 void InputManagerImpl::PrintEnhanceConfig()
793 {
794     CHKPV(enhanceCfg_);
795     MMI_HILOGD("securityConfigInfo, cfg len:%{public}d", enhanceCfgLen_);
796 }
797 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
798 
AddMonitor(std::function<void(std::shared_ptr<KeyEvent>)> monitor)799 int32_t InputManagerImpl::AddMonitor(std::function<void(std::shared_ptr<KeyEvent>)> monitor)
800 {
801     CALL_DEBUG_ENTER;
802 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_MONITOR)
803     CHKPR(monitor, INVALID_HANDLER_ID);
804     auto consumer = std::make_shared<MonitorEventConsumer>(monitor);
805     return AddMonitor(consumer, HANDLE_EVENT_TYPE_KEY);
806 #else
807     MMI_HILOGW("Keyboard device or monitor function does not support");
808     return ERROR_UNSUPPORT;
809 #endif // OHOS_BUILD_ENABLE_KEYBOARD || OHOS_BUILD_ENABLE_MONITOR
810 }
811 
AddMonitor(std::function<void(std::shared_ptr<PointerEvent>)> monitor)812 int32_t InputManagerImpl::AddMonitor(std::function<void(std::shared_ptr<PointerEvent>)> monitor)
813 {
814     CALL_DEBUG_ENTER;
815 #if (defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)) && defined(OHOS_BUILD_ENABLE_MONITOR)
816     CHKPR(monitor, INVALID_HANDLER_ID);
817     auto consumer = std::make_shared<MonitorEventConsumer>(monitor);
818     return AddMonitor(consumer, HANDLE_EVENT_TYPE_POINTER);
819 #else
820     MMI_HILOGW("Pointer/touchscreen device or monitor function does not support");
821     return ERROR_UNSUPPORT;
822 #endif // OHOS_BUILD_ENABLE_MONITOR || OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR
823 }
824 
AddMonitor(std::shared_ptr<IInputEventConsumer> consumer, HandleEventType eventType)825 int32_t InputManagerImpl::AddMonitor(std::shared_ptr<IInputEventConsumer> consumer, HandleEventType eventType)
826 {
827     CALL_DEBUG_ENTER;
828 #ifdef OHOS_BUILD_ENABLE_MONITOR
829     CHKPR(consumer, INVALID_HANDLER_ID);
830     std::lock_guard<std::mutex> guard(mtx_);
831     if (!MMIEventHdl.InitClient()) {
832         MMI_HILOGE("Client init failed");
833         return RET_ERR;
834     }
835     return IMonitorMgr->AddMonitor(consumer, eventType);
836 #else
837     MMI_HILOGI("Monitor function does not support");
838     return ERROR_UNSUPPORT;
839 #endif // OHOS_BUILD_ENABLE_MONITOR
840 }
841 
AddMonitor(std::shared_ptr<IInputEventConsumer> consumer, std::vector<int32_t> actionsType)842 int32_t InputManagerImpl::AddMonitor(std::shared_ptr<IInputEventConsumer> consumer, std::vector<int32_t> actionsType)
843 {
844     CALL_DEBUG_ENTER;
845 #ifdef OHOS_BUILD_ENABLE_MONITOR
846     CHKPR(consumer, INVALID_HANDLER_ID);
847     std::lock_guard<std::mutex> guard(mtx_);
848     if (!MMIEventHdl.InitClient()) {
849         MMI_HILOGE("Client init failed");
850         return RET_ERR;
851     }
852     return IMonitorMgr->AddMonitor(consumer, actionsType);
853 #else
854     MMI_HILOGI("Monitor function does not support");
855     return ERROR_UNSUPPORT;
856 #endif // OHOS_BUILD_ENABLE_MONITOR
857 }
858 
RemoveMonitor(int32_t monitorId)859 int32_t InputManagerImpl::RemoveMonitor(int32_t monitorId)
860 {
861     CALL_DEBUG_ENTER;
862 #ifdef OHOS_BUILD_ENABLE_MONITOR
863     std::lock_guard<std::mutex> guard(mtx_);
864     if (!MMIEventHdl.InitClient()) {
865         MMI_HILOGE("Client init failed");
866         return RET_ERR;
867     }
868     return IMonitorMgr->RemoveMonitor(monitorId);
869 #else
870     MMI_HILOGI("Monitor function does not support");
871     return ERROR_UNSUPPORT;
872 #endif // OHOS_BUILD_ENABLE_MONITOR
873 }
874 
AddGestureMonitor( std::shared_ptr<IInputEventConsumer> consumer, TouchGestureType type, int32_t fingers)875 int32_t InputManagerImpl::AddGestureMonitor(
876     std::shared_ptr<IInputEventConsumer> consumer, TouchGestureType type, int32_t fingers)
877 {
878 #ifdef OHOS_BUILD_ENABLE_MONITOR
879     CHKPR(consumer, INVALID_HANDLER_ID);
880     std::lock_guard<std::mutex> guard(mtx_);
881     if (!MMIEventHdl.InitClient()) {
882         MMI_HILOGE("Client init failed");
883         return RET_ERR;
884     }
885     return IMonitorMgr->AddGestureMonitor(consumer, type, fingers);
886 #else
887     MMI_HILOGI("Monitor function does not support");
888     return ERROR_UNSUPPORT;
889 #endif // OHOS_BUILD_ENABLE_MONITOR
890 }
891 
RemoveGestureMonitor(int32_t monitorId)892 int32_t InputManagerImpl::RemoveGestureMonitor(int32_t monitorId)
893 {
894 #ifdef OHOS_BUILD_ENABLE_MONITOR
895     std::lock_guard<std::mutex> guard(mtx_);
896     if (!MMIEventHdl.InitClient()) {
897         MMI_HILOGE("Client init failed");
898         return RET_ERR;
899     }
900     return IMonitorMgr->RemoveGestureMonitor(monitorId);
901 #else
902     MMI_HILOGI("Monitor function does not support");
903     return ERROR_UNSUPPORT;
904 #endif // OHOS_BUILD_ENABLE_MONITOR
905 }
906 
MarkConsumed(int32_t monitorId, int32_t eventId)907 void InputManagerImpl::MarkConsumed(int32_t monitorId, int32_t eventId)
908 {
909     CALL_INFO_TRACE;
910 #ifdef OHOS_BUILD_ENABLE_MONITOR
911     std::lock_guard<std::mutex> guard(mtx_);
912     if (!MMIEventHdl.InitClient()) {
913         MMI_HILOGE("Client init failed");
914         return;
915     }
916     IMonitorMgr->MarkConsumed(monitorId, eventId);
917 #else
918     MMI_HILOGI("Monitor function does not support");
919 #endif // OHOS_BUILD_ENABLE_MONITOR
920 }
921 
MoveMouse(int32_t offsetX, int32_t offsetY)922 void InputManagerImpl::MoveMouse(int32_t offsetX, int32_t offsetY)
923 {
924     CALL_INFO_TRACE;
925 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
926     std::lock_guard<std::mutex> guard(mtx_);
927     if (MMIEventHdl.MoveMouseEvent(offsetX, offsetY) != RET_OK) {
928         MMI_HILOGE("Failed to inject move mouse offset event");
929     }
930 #else
931     MMI_HILOGW("Pointer device or pointer drawing module does not support");
932 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
933 }
934 
AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor, int32_t priority, uint32_t deviceTags)935 int32_t InputManagerImpl::AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor,
936     int32_t priority, uint32_t deviceTags)
937 {
938     CALL_DEBUG_ENTER;
939 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
940     CHKPR(interceptor, INVALID_HANDLER_ID);
941     std::lock_guard<std::mutex> guard(mtx_);
942     if (!MMIEventHdl.InitClient()) {
943         MMI_HILOGE("Client init failed");
944         return RET_ERR;
945     }
946     return InputInterMgr->AddInterceptor(interceptor, HANDLE_EVENT_TYPE_ALL, priority, deviceTags);
947 #else
948     MMI_HILOGW("Interceptor function does not support");
949     return ERROR_UNSUPPORT;
950 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
951 }
952 
AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor, int32_t priority, uint32_t deviceTags)953 int32_t InputManagerImpl::AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor,
954     int32_t priority, uint32_t deviceTags)
955 {
956     CALL_DEBUG_ENTER;
957 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR)
958     CHKPR(interceptor, INVALID_HANDLER_ID);
959     std::lock_guard<std::mutex> guard(mtx_);
960     auto consumer = std::make_shared<MonitorEventConsumer>(interceptor);
961     if (!MMIEventHdl.InitClient()) {
962         MMI_HILOGE("Client init failed");
963         return RET_ERR;
964     }
965     return InputInterMgr->AddInterceptor(consumer, HANDLE_EVENT_TYPE_KEY, priority, deviceTags);
966 #else
967     MMI_HILOGW("Keyboard device or interceptor function does not support");
968     return ERROR_UNSUPPORT;
969 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR
970 }
971 
RemoveInterceptor(int32_t interceptorId)972 int32_t InputManagerImpl::RemoveInterceptor(int32_t interceptorId)
973 {
974     CALL_DEBUG_ENTER;
975 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
976     std::lock_guard<std::mutex> guard(mtx_);
977     if (!MMIEventHdl.InitClient()) {
978         MMI_HILOGE("Client init failed");
979         return RET_ERR;
980     }
981     return InputInterMgr->RemoveInterceptor(interceptorId);
982 #else
983     MMI_HILOGW("Interceptor function does not support");
984     return ERROR_UNSUPPORT;
985 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR
986 }
987 
SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent, bool isNativeInject)988 void InputManagerImpl::SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent, bool isNativeInject)
989 {
990     CALL_DEBUG_ENTER;
991 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
992     CHKPV(keyEvent);
993     if (!EventLogHelper::IsBetaVersion()) {
994         MMI_HILOGI("action:%{public}d", keyEvent->GetKeyAction());
995     } else {
996         MMI_HILOGI("KeyCode:%{private}d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction());
997     }
998     if (MMIEventHdl.InjectEvent(keyEvent, isNativeInject) != RET_OK) {
999         MMI_HILOGE("Failed to inject keyEvent");
1000     }
1001 #else
1002     MMI_HILOGW("Keyboard device does not support");
1003 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1004 }
1005 
HandleSimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)1006 void InputManagerImpl::HandleSimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
1007 {
1008     CALL_DEBUG_ENTER;
1009     int maxPointerId = SIMULATE_EVENT_START_ID;
1010     std::list<PointerEvent::PointerItem> pointerItems = pointerEvent->GetAllPointerItems();
1011     for (auto &pointerItem : pointerItems) {
1012         int32_t pointerId = pointerItem.GetPointerId();
1013         if (pointerId != -1) {
1014             maxPointerId = (maxPointerId > pointerId) ? maxPointerId : pointerId;
1015             continue;
1016         }
1017         maxPointerId += 1;
1018         pointerItem.SetPointerId(maxPointerId);
1019     }
1020     for (auto &pointerItem : pointerItems) {
1021         int32_t pointerId = pointerItem.GetPointerId();
1022         if (pointerId < SIMULATE_EVENT_START_ID) {
1023             pointerItem.SetOriginPointerId(pointerId);
1024             pointerItem.SetPointerId(pointerId + SIMULATE_EVENT_START_ID);
1025         }
1026     }
1027     pointerEvent->RemoveAllPointerItems();
1028     for (auto &pointerItem : pointerItems) {
1029         pointerEvent->AddPointerItem(pointerItem);
1030     }
1031     if ((pointerEvent->GetPointerId() < 0) && !pointerItems.empty()) {
1032         pointerEvent->SetPointerId(pointerItems.front().GetPointerId());
1033         MMI_HILOGD("Simulate pointer event id:%{public}d", pointerEvent->GetPointerId());
1034     }
1035     if (pointerEvent->GetPointerId() < SIMULATE_EVENT_START_ID) {
1036         pointerEvent->SetPointerId(pointerEvent->GetPointerId() + SIMULATE_EVENT_START_ID);
1037     }
1038 }
1039 
SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent, bool isNativeInject)1040 void InputManagerImpl::SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent, bool isNativeInject)
1041 {
1042     CALL_DEBUG_ENTER;
1043 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
1044     CHKPV(pointerEvent);
1045     if (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE &&
1046         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE &&
1047         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_HOVER_MOVE &&
1048         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_AXIS_UPDATE &&
1049         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_SWIPE_UPDATE &&
1050         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_ROTATE_UPDATE &&
1051         pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_FINGERPRINT_SLIDE) {
1052         MMI_HILOGI("Pointer event action:%{public}d", pointerEvent->GetPointerAction());
1053     }
1054     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE ||
1055         pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) {
1056 #ifndef OHOS_BUILD_ENABLE_POINTER
1057         MMI_HILOGW("Pointer device does not support");
1058         return;
1059 #endif // OHOS_BUILD_ENABLE_POINTER
1060     }
1061     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
1062 #ifndef OHOS_BUILD_ENABLE_TOUCH
1063         MMI_HILOGW("Touchscreen device does not support");
1064         return;
1065 #endif // OHOS_BUILD_ENABLE_TOUCH
1066     }
1067 #ifndef OHOS_BUILD_ENABLE_JOYSTICK
1068     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_JOYSTICK) {
1069         MMI_HILOGW("Joystick device does not support");
1070         return;
1071     }
1072 #endif // OHOS_BUILD_ENABLE_JOYSTICK
1073     if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_TOUCHPAD) {
1074         HandleSimulateInputEvent(pointerEvent);
1075     } else {
1076         int32_t pointerAction = pointerEvent->GetPointerAction();
1077         if (pointerAction < PointerEvent::POINTER_ACTION_SWIPE_BEGIN ||
1078             pointerAction > PointerEvent::POINTER_ACTION_SWIPE_END) {
1079             pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1080         }
1081     }
1082     if (MMIEventHdl.InjectPointerEvent(pointerEvent, isNativeInject) != RET_OK) {
1083         MMI_HILOGE("Failed to inject pointer event");
1084     }
1085 #else
1086     MMI_HILOGW("Pointer and touchscreen device does not support");
1087 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
1088 }
1089 
SimulateTouchPadEvent(std::shared_ptr<PointerEvent> pointerEvent, bool isNativeInject)1090 void InputManagerImpl::SimulateTouchPadEvent(std::shared_ptr<PointerEvent> pointerEvent, bool isNativeInject)
1091 {
1092 #if defined(OHOS_BUILD_ENABLE_POINTER)
1093     CHKPV(pointerEvent);
1094     if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE ||
1095         pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHPAD) {
1096         if (MMIEventHdl.InjectPointerEvent(pointerEvent, false) != RET_OK) {
1097             MMI_HILOGE("Failed to inject pointer event to touchPad");
1098         }
1099     }
1100 #endif // OHOS_BUILD_ENABLE_POINTER
1101 }
1102 
SetMouseScrollRows(int32_t rows)1103 int32_t InputManagerImpl::SetMouseScrollRows(int32_t rows)
1104 {
1105     CALL_INFO_TRACE;
1106 #if defined OHOS_BUILD_ENABLE_POINTER
1107     std::lock_guard<std::mutex> guard(mtx_);
1108     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetMouseScrollRows(rows);
1109     if (ret != RET_OK) {
1110         MMI_HILOGE("Set the number of mouse scrolling rows failed, ret:%{public}d", ret);
1111     }
1112     return ret;
1113 #else
1114     MMI_HILOGW("Pointer device module does not support");
1115     return ERROR_UNSUPPORT;
1116 #endif // OHOS_BUILD_ENABLE_POINTER
1117 }
1118 
SetCustomCursor(int32_t windowId, int32_t focusX, int32_t focusY, void* pixelMap)1119 int32_t InputManagerImpl::SetCustomCursor(int32_t windowId, int32_t focusX, int32_t focusY, void* pixelMap)
1120 {
1121     CALL_INFO_TRACE;
1122 #if defined OHOS_BUILD_ENABLE_POINTER
1123     int32_t winPid = GetWindowPid(windowId);
1124     if (winPid == -1) {
1125         MMI_HILOGE("The winPid is invalid");
1126         return RET_ERR;
1127     }
1128     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetCustomCursor(winPid, windowId, focusX, focusY, pixelMap);
1129     if (ret != RET_OK) {
1130         MMI_HILOGE("Set custom cursor failed, ret:%{public}d", ret);
1131     }
1132     return ret;
1133 #else
1134     MMI_HILOGW("Pointer device module does not support");
1135     return ERROR_UNSUPPORT;
1136 #endif // OHOS_BUILD_ENABLE_POINTER
1137 }
1138 
SetMouseIcon(int32_t windowId, void* pixelMap)1139 int32_t InputManagerImpl::SetMouseIcon(int32_t windowId, void* pixelMap)
1140 {
1141     CALL_INFO_TRACE;
1142 #if defined OHOS_BUILD_ENABLE_POINTER
1143     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetMouseIcon(windowId, pixelMap);
1144     if (ret != RET_OK) {
1145         MMI_HILOGE("Set the number of mouse scrolling rows failed, ret:%{public}d", ret);
1146     }
1147     return ret;
1148 #else
1149     MMI_HILOGW("Pointer device module does not support");
1150     return ERROR_UNSUPPORT;
1151 #endif // OHOS_BUILD_ENABLE_POINTER
1152 }
1153 
SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY)1154 int32_t InputManagerImpl::SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY)
1155 {
1156     CALL_INFO_TRACE;
1157 #if defined OHOS_BUILD_ENABLE_POINTER
1158     int32_t winPid = GetWindowPid(windowId);
1159     if (winPid == -1) {
1160         MMI_HILOGE("The winPid is invalid return -1");
1161         return RET_ERR;
1162     }
1163     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetMouseHotSpot(winPid, windowId, hotSpotX, hotSpotY);
1164     if (ret != RET_OK) {
1165         MMI_HILOGE("Set mouse hot spot failed, ret:%{public}d", ret);
1166     }
1167     return ret;
1168 #else
1169     MMI_HILOGW("Pointer device module does not support");
1170     return ERROR_UNSUPPORT;
1171 #endif // OHOS_BUILD_ENABLE_POINTER
1172 }
1173 
GetMouseScrollRows(int32_t &rows)1174 int32_t InputManagerImpl::GetMouseScrollRows(int32_t &rows)
1175 {
1176     CALL_INFO_TRACE;
1177 #ifdef OHOS_BUILD_ENABLE_POINTER
1178     std::lock_guard<std::mutex> guard(mtx_);
1179     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetMouseScrollRows(rows);
1180     if (ret != RET_OK) {
1181         MMI_HILOGE("Get the number of mouse scrolling rows failed");
1182     }
1183     return ret;
1184 #else
1185     MMI_HILOGW("Pointer device does not support");
1186     return ERROR_UNSUPPORT;
1187 #endif // OHOS_BUILD_ENABLE_POINTER
1188 }
1189 
SetPointerSize(int32_t size)1190 int32_t InputManagerImpl::SetPointerSize(int32_t size)
1191 {
1192     CALL_INFO_TRACE;
1193 #if defined OHOS_BUILD_ENABLE_POINTER
1194     std::lock_guard<std::mutex> guard(mtx_);
1195     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetPointerSize(size);
1196     if (ret != RET_OK) {
1197         MMI_HILOGE("Set pointer size failed, ret:%{public}d", ret);
1198     }
1199     return ret;
1200 #else
1201     MMI_HILOGW("Pointer device module does not support");
1202     return ERROR_UNSUPPORT;
1203 #endif // OHOS_BUILD_ENABLE_POINTER
1204 }
1205 
GetPointerSize(int32_t &size)1206 int32_t InputManagerImpl::GetPointerSize(int32_t &size)
1207 {
1208     CALL_INFO_TRACE;
1209 #ifdef OHOS_BUILD_ENABLE_POINTER
1210     std::lock_guard<std::mutex> guard(mtx_);
1211     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetPointerSize(size);
1212     if (ret != RET_OK) {
1213         MMI_HILOGE("Get pointer size failed");
1214     }
1215     return ret;
1216 #else
1217     MMI_HILOGW("Pointer device does not support");
1218     return ERROR_UNSUPPORT;
1219 #endif // OHOS_BUILD_ENABLE_POINTER
1220 }
1221 
SetMousePrimaryButton(int32_t primaryButton)1222 int32_t InputManagerImpl::SetMousePrimaryButton(int32_t primaryButton)
1223 {
1224     CALL_INFO_TRACE;
1225 #if defined OHOS_BUILD_ENABLE_POINTER
1226     std::lock_guard<std::mutex> guard(mtx_);
1227     if (primaryButton != LEFT_BUTTON && primaryButton != RIGHT_BUTTON) {
1228         MMI_HILOGE("primaryButton is invalid");
1229         return RET_ERR;
1230     }
1231     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetMousePrimaryButton(primaryButton);
1232     if (ret != RET_OK) {
1233         MMI_HILOGE("Set mouse primary button failed, ret:%{public}d", ret);
1234     }
1235     return ret;
1236 #else
1237     MMI_HILOGW("Pointer device module does not support");
1238     return ERROR_UNSUPPORT;
1239 #endif // OHOS_BUILD_ENABLE_POINTER
1240 }
1241 
GetMousePrimaryButton(int32_t &primaryButton)1242 int32_t InputManagerImpl::GetMousePrimaryButton(int32_t &primaryButton)
1243 {
1244     CALL_INFO_TRACE;
1245 #ifdef OHOS_BUILD_ENABLE_POINTER
1246     std::lock_guard<std::mutex> guard(mtx_);
1247     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetMousePrimaryButton(primaryButton);
1248     if (ret != RET_OK) {
1249         MMI_HILOGE("Get mouse primary button failed");
1250     }
1251     return ret;
1252 #else
1253     MMI_HILOGW("Pointer device does not support");
1254     return ERROR_UNSUPPORT;
1255 #endif // OHOS_BUILD_ENABLE_POINTER
1256 }
1257 
SetHoverScrollState(bool state)1258 int32_t InputManagerImpl::SetHoverScrollState(bool state)
1259 {
1260     CALL_INFO_TRACE;
1261 #if defined OHOS_BUILD_ENABLE_POINTER
1262     std::lock_guard<std::mutex> guard(mtx_);
1263     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetHoverScrollState(state);
1264     if (ret != RET_OK) {
1265         MMI_HILOGE("Set mouse hover scroll state failed, ret:%{public}d", ret);
1266     }
1267     return ret;
1268 #else
1269     MMI_HILOGW("Pointer device module does not support");
1270     return ERROR_UNSUPPORT;
1271 #endif // OHOS_BUILD_ENABLE_POINTER
1272 }
1273 
GetHoverScrollState(bool &state)1274 int32_t InputManagerImpl::GetHoverScrollState(bool &state)
1275 {
1276     CALL_INFO_TRACE;
1277 #ifdef OHOS_BUILD_ENABLE_POINTER
1278     std::lock_guard<std::mutex> guard(mtx_);
1279     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetHoverScrollState(state);
1280     if (ret != RET_OK) {
1281         MMI_HILOGE("Get mouse hover scroll state failed, ret:%{public}d", ret);
1282     }
1283     return ret;
1284 #else
1285     MMI_HILOGW("Pointer device does not support");
1286     return ERROR_UNSUPPORT;
1287 #endif // OHOS_BUILD_ENABLE_POINTER
1288 }
1289 
SetPointerVisible(bool visible, int32_t priority)1290 int32_t InputManagerImpl::SetPointerVisible(bool visible, int32_t priority)
1291 {
1292     CALL_INFO_TRACE;
1293 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1294     std::lock_guard<std::mutex> guard(mtx_);
1295     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetPointerVisible(visible, priority);
1296     if (ret != RET_OK) {
1297         MMI_HILOGE("Set pointer visible failed, ret:%{public}d", ret);
1298     }
1299     return ret;
1300 #else
1301     MMI_HILOGW("Pointer device or pointer drawing module does not support");
1302     return ERROR_UNSUPPORT;
1303 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1304 }
1305 
IsPointerVisible()1306 bool InputManagerImpl::IsPointerVisible()
1307 {
1308     CALL_INFO_TRACE;
1309 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1310     std::lock_guard<std::mutex> guard(mtx_);
1311     bool visible;
1312     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->IsPointerVisible(visible);
1313     if (ret != 0) {
1314         MMI_HILOGE("Get pointer visible failed, ret:%{public}d", ret);
1315     }
1316     return visible;
1317 #else
1318     MMI_HILOGW("Pointer device or pointer drawing module does not support");
1319     return false;
1320 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
1321 }
1322 
SetPointerColor(int32_t color)1323 int32_t InputManagerImpl::SetPointerColor(int32_t color)
1324 {
1325     CALL_INFO_TRACE;
1326 #if defined OHOS_BUILD_ENABLE_POINTER
1327     std::lock_guard<std::mutex> guard(mtx_);
1328     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetPointerColor(color);
1329     if (ret != RET_OK) {
1330         MMI_HILOGE("Set pointer color failed, ret:%{public}d", ret);
1331     }
1332     return ret;
1333 #else
1334     MMI_HILOGW("Pointer device module does not support");
1335     return ERROR_UNSUPPORT;
1336 #endif // OHOS_BUILD_ENABLE_POINTER
1337 }
1338 
GetPointerColor(int32_t &color)1339 int32_t InputManagerImpl::GetPointerColor(int32_t &color)
1340 {
1341     CALL_INFO_TRACE;
1342 #ifdef OHOS_BUILD_ENABLE_POINTER
1343     std::lock_guard<std::mutex> guard(mtx_);
1344     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetPointerColor(color);
1345     if (ret != RET_OK) {
1346         MMI_HILOGE("Get pointer color failed");
1347     }
1348     return ret;
1349 #else
1350     MMI_HILOGW("Pointer device does not support");
1351     return ERROR_UNSUPPORT;
1352 #endif // OHOS_BUILD_ENABLE_POINTER
1353 }
1354 
EnableCombineKey(bool enable)1355 int32_t InputManagerImpl::EnableCombineKey(bool enable)
1356 {
1357     CALL_INFO_TRACE;
1358     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->EnableCombineKey(enable);
1359     if (ret != RET_OK) {
1360         MMI_HILOGE("Enable combine key failed, ret:%{public}d", ret);
1361     }
1362     return ret;
1363 }
1364 
SetPointerSpeed(int32_t speed)1365 int32_t InputManagerImpl::SetPointerSpeed(int32_t speed)
1366 {
1367     CALL_INFO_TRACE;
1368 #ifdef OHOS_BUILD_ENABLE_POINTER
1369     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetPointerSpeed(speed);
1370     if (ret != RET_OK) {
1371         MMI_HILOGE("Failed to set pointer speed");
1372         return RET_ERR;
1373     }
1374     return RET_OK;
1375 #else
1376     MMI_HILOGW("Pointer device does not support");
1377     return ERROR_UNSUPPORT;
1378 #endif // OHOS_BUILD_ENABLE_POINTER
1379 }
1380 
GetPointerSpeed(int32_t &speed)1381 int32_t InputManagerImpl::GetPointerSpeed(int32_t &speed)
1382 {
1383     CALL_INFO_TRACE;
1384 #ifdef OHOS_BUILD_ENABLE_POINTER
1385     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetPointerSpeed(speed);
1386     if (ret != RET_OK) {
1387         MMI_HILOGE("Get pointer speed failed");
1388         return RET_ERR;
1389     }
1390     return RET_OK;
1391 #else
1392     return ERROR_UNSUPPORT;
1393     MMI_HILOGW("Pointer device does not support");
1394 #endif // OHOS_BUILD_ENABLE_POINTER
1395 }
1396 
SetPointerStyle(int32_t windowId, const PointerStyle& pointerStyle, bool isUiExtension)1397 int32_t InputManagerImpl::SetPointerStyle(int32_t windowId, const PointerStyle& pointerStyle, bool isUiExtension)
1398 {
1399     CALL_INFO_TRACE;
1400     if (pointerStyle.id < 0) {
1401         MMI_HILOGE("The param is invalid");
1402         return RET_ERR;
1403     }
1404 
1405     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetPointerStyle(windowId, pointerStyle, isUiExtension);
1406     if (ret != RET_OK) {
1407         MMI_HILOGE("Set pointer style failed, ret:%{public}d", ret);
1408         return ret;
1409     }
1410     return RET_OK;
1411 }
1412 
GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension)1413 int32_t InputManagerImpl::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension)
1414 {
1415     CALL_DEBUG_ENTER;
1416     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetPointerStyle(windowId, pointerStyle, isUiExtension);
1417     if (ret != RET_OK) {
1418         MMI_HILOGE("Get pointer style failed, ret:%{public}d", ret);
1419         return ret;
1420     }
1421     return RET_OK;
1422 }
1423 
OnConnected()1424 void InputManagerImpl::OnConnected()
1425 {
1426     CALL_INFO_TRACE;
1427     ReAddInputEventFilter();
1428     if (!displayGroupInfo_.windowsInfo.empty() && !displayGroupInfo_.displaysInfo.empty()) {
1429         MMI_HILOGD("displayGroupInfo_: windowsInfo size: %{public}zu, displaysInfo size: %{public}zu",
1430             displayGroupInfo_.windowsInfo.size(), displayGroupInfo_.displaysInfo.size());
1431         SendDisplayInfo();
1432         PrintDisplayInfo();
1433     }
1434     if (!windowGroupInfo_.windowsInfo.empty()) {
1435         MMI_HILOGD("windowGroupInfo_: windowsInfo size: %{public}zu", windowGroupInfo_.windowsInfo.size());
1436         SendWindowInfo();
1437     }
1438 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1439     SendEnhanceConfig();
1440     PrintEnhanceConfig();
1441 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1442 
1443     if (windowStatecallback_ != nullptr) {
1444         MMIClientPtr client = MMIEventHdl.GetMMIClient();
1445         if (client != nullptr) {
1446             NetPacket pkt(MmiMessageId::WINDOW_STATE_ERROR_CALLBACK);
1447             if (!client->SendMessage(pkt)) {
1448                 MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL);
1449             }
1450         } else {
1451             MMI_HILOGE("Get client failed");
1452         }
1453     }
1454     if (anrObservers_.empty()) {
1455         return;
1456     }
1457     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetAnrObserver();
1458     if (ret != RET_OK) {
1459         MMI_HILOGE("Set anr observer failed, ret:%{public}d", ret);
1460     }
1461 }
1462 
1463 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
1464 template<typename T>
RecoverPointerEvent(std::initializer_list<T> pointerActionEvents, T pointerActionEvent)1465 bool InputManagerImpl::RecoverPointerEvent(std::initializer_list<T> pointerActionEvents, T pointerActionEvent)
1466 {
1467     CALL_INFO_TRACE;
1468     std::lock_guard<std::mutex> guard(resourceMtx_);
1469     CHKPF(lastPointerEvent_);
1470     int32_t pointerAction = lastPointerEvent_->GetPointerAction();
1471     for (const auto &it : pointerActionEvents) {
1472         if (pointerAction == it) {
1473             PointerEvent::PointerItem item;
1474             int32_t pointerId = lastPointerEvent_->GetPointerId();
1475             if (!lastPointerEvent_->GetPointerItem(pointerId, item)) {
1476                 MMI_HILOG_DISPATCHD("Get pointer item failed. pointer:%{public}d",
1477                     pointerId);
1478                 return false;
1479             }
1480             item.SetPressed(false);
1481             lastPointerEvent_->UpdatePointerItem(pointerId, item);
1482             lastPointerEvent_->SetPointerAction(pointerActionEvent);
1483             OnPointerEvent(lastPointerEvent_);
1484             return true;
1485         }
1486     }
1487     return false;
1488 }
1489 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
1490 
OnDisconnected()1491 void InputManagerImpl::OnDisconnected()
1492 {
1493     CALL_INFO_TRACE;
1494 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
1495     std::initializer_list<int32_t> pointerActionEvents { PointerEvent::POINTER_ACTION_MOVE,
1496         PointerEvent::POINTER_ACTION_DOWN };
1497     std::initializer_list<int32_t> pointerActionPullEvents { PointerEvent::POINTER_ACTION_PULL_MOVE,
1498         PointerEvent::POINTER_ACTION_PULL_DOWN };
1499     if (RecoverPointerEvent(pointerActionEvents, PointerEvent::POINTER_ACTION_UP)) {
1500         MMI_HILOGE("Up event for service exception re-sending");
1501         return;
1502     }
1503 
1504     if (RecoverPointerEvent(pointerActionPullEvents, PointerEvent::POINTER_ACTION_PULL_UP)) {
1505         MMI_HILOGE("Pull up event for service exception re-sending");
1506         return;
1507     }
1508 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
1509 }
1510 
SendDisplayInfo()1511 int32_t InputManagerImpl::SendDisplayInfo()
1512 {
1513     CALL_DEBUG_ENTER;
1514     MMIClientPtr client = MMIEventHdl.GetMMIClient();
1515     CHKPR(client, RET_ERR);
1516     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
1517     int32_t ret = PackDisplayData(pkt);
1518     if (ret != RET_OK) {
1519         MMI_HILOGE("Pack display info failed");
1520         return ret;
1521     }
1522     if (!client->SendMessage(pkt)) {
1523         MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL);
1524         return MSG_SEND_FAIL;
1525     }
1526     return RET_OK;
1527 }
1528 
SendWindowInfo()1529 int32_t InputManagerImpl::SendWindowInfo()
1530 {
1531     CALL_DEBUG_ENTER;
1532     MMIClientPtr client = MMIEventHdl.GetMMIClient();
1533     CHKPR(client, RET_ERR);
1534     NetPacket pkt(MmiMessageId::WINDOW_INFO);
1535     int32_t ret = PackWindowGroupInfo(pkt);
1536     if (ret != RET_OK) {
1537         MMI_HILOGE("Pack window group info failed");
1538         return ret;
1539     }
1540     if (!client->SendMessage(pkt)) {
1541         MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL);
1542         return MSG_SEND_FAIL;
1543     }
1544     return RET_OK;
1545 }
1546 
RegisterWindowStateErrorCallback(std::function<void(int32_t, int32_t)> callback)1547 int32_t InputManagerImpl::RegisterWindowStateErrorCallback(std::function<void(int32_t, int32_t)> callback)
1548 {
1549     CALL_DEBUG_ENTER;
1550     const std::string sceneboard = "com.ohos.sceneboard";
1551     const std::string programName(GetProgramName());
1552     if (programName != sceneboard) {
1553         MMI_HILOGE("Not sceneboard paogramName");
1554         return RET_ERR;
1555     }
1556     CHKPR(callback, RET_ERR);
1557     windowStatecallback_ = callback;
1558     std::lock_guard<std::mutex> guard(mtx_);
1559     if (!MMIEventHdl.InitClient()) {
1560         MMI_HILOGE("Client init failed");
1561         return RET_ERR;
1562     }
1563     MMIClientPtr client = MMIEventHdl.GetMMIClient();
1564     CHKPR(client, RET_ERR);
1565     NetPacket pkt(MmiMessageId::WINDOW_STATE_ERROR_CALLBACK);
1566     if (!client->SendMessage(pkt)) {
1567         MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL);
1568         return MSG_SEND_FAIL;
1569     }
1570     return RET_OK;
1571 }
1572 
1573 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
SendEnhanceConfig()1574 void InputManagerImpl::SendEnhanceConfig()
1575 {
1576     MMIClientPtr client = MMIEventHdl.GetMMIClient();
1577     CHKPV(client);
1578     NetPacket pkt(MmiMessageId::SCINFO_CONFIG);
1579     if (PackEnhanceConfig(pkt) == RET_ERR) {
1580         return;
1581     }
1582     if (!client->SendMessage(pkt)) {
1583         MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL);
1584     }
1585 }
1586 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
1587 
ReAddInputEventFilter()1588 void InputManagerImpl::ReAddInputEventFilter()
1589 {
1590     CALL_INFO_TRACE;
1591     if (eventFilterServices_.size() > MAX_FILTER_NUM) {
1592         MMI_HILOGE("Too many filters, size:%{public}zu", eventFilterServices_.size());
1593         return;
1594     }
1595     for (const auto &[filterId, t] : eventFilterServices_) {
1596         const auto &[service, priority, deviceTags] = t;
1597         int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->AddInputEventFilter(service, filterId, priority, deviceTags);
1598         if (ret != RET_OK) {
1599             MMI_HILOGE("AddInputEventFilter has send to server failed, filterId:%{public}d, priority:%{public}d,"
1600                 "deviceTags:%{public}u, ret:%{public}d", filterId, priority, deviceTags, ret);
1601         }
1602     }
1603 }
1604 
RegisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener)1605 int32_t InputManagerImpl::RegisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener)
1606 {
1607     CALL_INFO_TRACE;
1608     std::lock_guard<std::mutex> guard(mtx_);
1609     if (!MMIEventHdl.InitClient()) {
1610         MMI_HILOGE("Client init failed");
1611         return RET_ERR;
1612     }
1613     return INPUT_DEVICE_IMPL.RegisterDevListener(type, listener);
1614 }
1615 
UnregisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener)1616 int32_t InputManagerImpl::UnregisterDevListener(std::string type,
1617     std::shared_ptr<IInputDeviceListener> listener)
1618 {
1619     CALL_INFO_TRACE;
1620     std::lock_guard<std::mutex> guard(mtx_);
1621     if (!MMIEventHdl.InitClient()) {
1622         MMI_HILOGE("Client init failed");
1623         return RET_ERR;
1624     }
1625     return INPUT_DEVICE_IMPL.UnregisterDevListener(type, listener);
1626 }
1627 
GetDeviceIds(std::function<void(std::vector<int32_t>&)> callback)1628 int32_t InputManagerImpl::GetDeviceIds(std::function<void(std::vector<int32_t>&)> callback)
1629 {
1630     CALL_DEBUG_ENTER;
1631     std::lock_guard<std::mutex> guard(mtx_);
1632     if (!MMIEventHdl.InitClient()) {
1633         MMI_HILOGE("Client init failed");
1634         return RET_ERR;
1635     }
1636     return INPUT_DEVICE_IMPL.GetInputDeviceIds(callback);
1637 }
1638 
GetDevice(int32_t deviceId, std::function<void(std::shared_ptr<InputDevice>)> callback)1639 int32_t InputManagerImpl::GetDevice(int32_t deviceId,
1640     std::function<void(std::shared_ptr<InputDevice>)> callback)
1641 {
1642     CALL_DEBUG_ENTER;
1643     std::lock_guard<std::mutex> guard(mtx_);
1644     if (!MMIEventHdl.InitClient()) {
1645         MMI_HILOGE("Client init failed");
1646         return RET_ERR;
1647     }
1648     return INPUT_DEVICE_IMPL.GetInputDevice(deviceId, callback);
1649 }
1650 
SupportKeys(int32_t deviceId, std::vector<int32_t> &keyCodes, std::function<void(std::vector<bool>&)> callback)1651 int32_t InputManagerImpl::SupportKeys(int32_t deviceId, std::vector<int32_t> &keyCodes,
1652     std::function<void(std::vector<bool>&)> callback)
1653 {
1654     CALL_INFO_TRACE;
1655     std::lock_guard<std::mutex> guard(mtx_);
1656     if (!MMIEventHdl.InitClient()) {
1657         MMI_HILOGE("Client init failed");
1658         return RET_ERR;
1659     }
1660     return INPUT_DEVICE_IMPL.SupportKeys(deviceId, keyCodes, callback);
1661 }
1662 
GetKeyboardType(int32_t deviceId, std::function<void(int32_t)> callback)1663 int32_t InputManagerImpl::GetKeyboardType(int32_t deviceId, std::function<void(int32_t)> callback)
1664 {
1665     CALL_DEBUG_ENTER;
1666     std::lock_guard<std::mutex> guard(mtx_);
1667     if (!MMIEventHdl.InitClient()) {
1668         MMI_HILOGE("Client init failed");
1669         return RET_ERR;
1670     }
1671     return INPUT_DEVICE_IMPL.GetKeyboardType(deviceId, callback);
1672 }
1673 
SetKeyboardRepeatDelay(int32_t delay)1674 int32_t InputManagerImpl::SetKeyboardRepeatDelay(int32_t delay)
1675 {
1676     CALL_INFO_TRACE;
1677     std::lock_guard<std::mutex> guard(mtx_);
1678     if (!MMIEventHdl.InitClient()) {
1679         MMI_HILOGE("Client init failed");
1680         return RET_ERR;
1681     }
1682     return INPUT_DEVICE_IMPL.SetKeyboardRepeatDelay(delay);
1683 }
1684 
SetKeyboardRepeatRate(int32_t rate)1685 int32_t InputManagerImpl::SetKeyboardRepeatRate(int32_t rate)
1686 {
1687     CALL_INFO_TRACE;
1688     std::lock_guard<std::mutex> guard(mtx_);
1689     if (!MMIEventHdl.InitClient()) {
1690         MMI_HILOGE("Client init failed");
1691         return RET_ERR;
1692     }
1693     return INPUT_DEVICE_IMPL.SetKeyboardRepeatRate(rate);
1694 }
1695 
GetKeyboardRepeatDelay(std::function<void(int32_t)> callback)1696 int32_t InputManagerImpl::GetKeyboardRepeatDelay(std::function<void(int32_t)> callback)
1697 {
1698     CALL_INFO_TRACE;
1699     std::lock_guard<std::mutex> guard(mtx_);
1700     if (!MMIEventHdl.InitClient()) {
1701         MMI_HILOGE("Client init failed");
1702         return RET_ERR;
1703     }
1704     return INPUT_DEVICE_IMPL.GetKeyboardRepeatDelay(callback);
1705 }
1706 
GetKeyboardRepeatRate(std::function<void(int32_t)> callback)1707 int32_t InputManagerImpl::GetKeyboardRepeatRate(std::function<void(int32_t)> callback)
1708 {
1709     CALL_INFO_TRACE;
1710     std::lock_guard<std::mutex> guard(mtx_);
1711     if (!MMIEventHdl.InitClient()) {
1712         MMI_HILOGE("Client init failed");
1713         return RET_ERR;
1714     }
1715     return INPUT_DEVICE_IMPL.GetKeyboardRepeatRate(callback);
1716 }
1717 
SetAnrObserver(std::shared_ptr<IAnrObserver> observer)1718 void InputManagerImpl::SetAnrObserver(std::shared_ptr<IAnrObserver> observer)
1719 {
1720     CALL_INFO_TRACE;
1721     std::lock_guard<std::mutex> guard(mtx_);
1722     if (!MMIEventHdl.InitClient()) {
1723         MMI_HILOG_ANRDETECTE("Client init failed");
1724         return;
1725     }
1726     for (auto iter = anrObservers_.begin(); iter != anrObservers_.end(); ++iter) {
1727         if (*iter == observer) {
1728             MMI_HILOG_ANRDETECTE("Observer already exist");
1729             return;
1730         }
1731     }
1732     anrObservers_.push_back(observer);
1733     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetAnrObserver();
1734     if (ret != RET_OK) {
1735         MMI_HILOG_ANRDETECTE("Set anr observer failed, ret:%{public}d", ret);
1736     }
1737 }
1738 
OnAnr(int32_t pid, int32_t eventId)1739 void InputManagerImpl::OnAnr(int32_t pid, int32_t eventId)
1740 {
1741     CALL_DEBUG_ENTER;
1742     CHK_PID_AND_TID();
1743     {
1744         std::lock_guard<std::mutex> guard(mtx_);
1745         for (const auto &observer : anrObservers_) {
1746             CHKPC(observer);
1747             observer->OnAnr(pid, eventId);
1748         }
1749     }
1750     MMI_HILOG_ANRDETECTI("ANR noticed pid:%{public}d eventId:%{public}d", pid, eventId);
1751 }
1752 
GetFunctionKeyState(int32_t funcKey)1753 bool InputManagerImpl::GetFunctionKeyState(int32_t funcKey)
1754 {
1755     CALL_INFO_TRACE;
1756 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1757     bool state { false };
1758     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetFunctionKeyState(funcKey, state);
1759     if (ret != RET_OK) {
1760         MMI_HILOGE("Send to server failed, ret:%{public}d", ret);
1761     }
1762     return state;
1763 #else
1764     MMI_HILOGW("Keyboard device does not support");
1765     return false;
1766 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1767 }
1768 
SetFunctionKeyState(int32_t funcKey, bool enable)1769 int32_t InputManagerImpl::SetFunctionKeyState(int32_t funcKey, bool enable)
1770 {
1771     CALL_INFO_TRACE;
1772 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1773     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetFunctionKeyState(funcKey, enable);
1774     if (ret != RET_OK) {
1775         MMI_HILOGE("Send to server failed, ret:%{public}d", ret);
1776         return RET_ERR;
1777     }
1778     return RET_OK;
1779 #else
1780     MMI_HILOGW("Keyboard device does not support");
1781     return ERROR_UNSUPPORT;
1782 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1783 }
1784 
SetPointerLocation(int32_t x, int32_t y)1785 int32_t InputManagerImpl::SetPointerLocation(int32_t x, int32_t y)
1786 {
1787     CALL_INFO_TRACE;
1788 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1789     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetPointerLocation(x, y);
1790     if (ret != RET_OK) {
1791         MMI_HILOGE("Set Pointer Location failed, ret:%{public}d", ret);
1792     }
1793     return ret;
1794 #else
1795     MMI_HILOGW("Pointer device or pointer drawing module does not support");
1796     return ERROR_UNSUPPORT;
1797 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1798 }
1799 
EnterCaptureMode(int32_t windowId)1800 int32_t InputManagerImpl::EnterCaptureMode(int32_t windowId)
1801 {
1802     CALL_INFO_TRACE;
1803 #if defined(OHOS_BUILD_ENABLE_POINTER)
1804     std::lock_guard<std::mutex> guard(mtx_);
1805     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetMouseCaptureMode(windowId, true);
1806     if (ret != RET_OK) {
1807         MMI_HILOGE("Enter captrue mode failed");
1808     }
1809     return ret;
1810 #else
1811     MMI_HILOGW("Pointer device module does not support");
1812     return ERROR_UNSUPPORT;
1813 #endif // OHOS_BUILD_ENABLE_POINTER
1814 }
1815 
LeaveCaptureMode(int32_t windowId)1816 int32_t InputManagerImpl::LeaveCaptureMode(int32_t windowId)
1817 {
1818     CALL_INFO_TRACE;
1819 #if defined(OHOS_BUILD_ENABLE_POINTER)
1820     std::lock_guard<std::mutex> guard(mtx_);
1821     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetMouseCaptureMode(windowId, false);
1822     if (ret != RET_OK) {
1823         MMI_HILOGE("Leave captrue mode failed");
1824     }
1825     return ret;
1826 #else
1827     MMI_HILOGW("Pointer device module does not support");
1828     return ERROR_UNSUPPORT;
1829 #endif // OHOS_BUILD_ENABLE_POINTER
1830 }
1831 
AppendExtraData(const ExtraData& extraData)1832 void InputManagerImpl::AppendExtraData(const ExtraData& extraData)
1833 {
1834     CALL_INFO_TRACE;
1835     if (extraData.buffer.size() > ExtraData::MAX_BUFFER_SIZE) {
1836         MMI_HILOGE("Append extra data failed, buffer is oversize:%{public}zu", extraData.buffer.size());
1837         return;
1838     }
1839     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->AppendExtraData(extraData);
1840     if (ret != RET_OK) {
1841         MMI_HILOGE("Append extra data failed:%{public}d", ret);
1842     }
1843 }
1844 
EnableInputDevice(bool enable)1845 int32_t InputManagerImpl::EnableInputDevice(bool enable)
1846 {
1847     CALL_INFO_TRACE;
1848     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->EnableInputDevice(enable);
1849     if (ret != RET_OK) {
1850         MMI_HILOGE("Enable input device failed, ret:%{public}d", ret);
1851     }
1852     return ret;
1853 }
1854 
SetKeyDownDuration(const std::string &businessId, int32_t delay)1855 int32_t InputManagerImpl::SetKeyDownDuration(const std::string &businessId, int32_t delay)
1856 {
1857     CALL_INFO_TRACE;
1858     if (delay < MIN_DELAY || delay > MAX_DELAY) {
1859         MMI_HILOGE("The param is invalid");
1860         return RET_ERR;
1861     }
1862     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetKeyDownDuration(businessId, delay);
1863     if (ret != RET_OK) {
1864         MMI_HILOGE("Set Key down duration failed, ret:%{public}d", ret);
1865         return ret;
1866     }
1867     return RET_OK;
1868 }
1869 
SetTouchpadScrollSwitch(bool switchFlag)1870 int32_t InputManagerImpl::SetTouchpadScrollSwitch(bool switchFlag)
1871 {
1872     CALL_INFO_TRACE;
1873 #if defined OHOS_BUILD_ENABLE_POINTER
1874     std::lock_guard<std::mutex> guard(mtx_);
1875     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadScrollSwitch(switchFlag);
1876     if (ret != RET_OK) {
1877         MMI_HILOGE("Set the touchpad scroll switch failed, ret:%{public}d", ret);
1878     }
1879     return ret;
1880 #else
1881     MMI_HILOGW("Pointer device module does not support");
1882     return ERROR_UNSUPPORT;
1883 #endif // OHOS_BUILD_ENABLE_POINTER
1884 }
1885 
GetTouchpadScrollSwitch(bool &switchFlag)1886 int32_t InputManagerImpl::GetTouchpadScrollSwitch(bool &switchFlag)
1887 {
1888     CALL_INFO_TRACE;
1889 #ifdef OHOS_BUILD_ENABLE_POINTER
1890     std::lock_guard<std::mutex> guard(mtx_);
1891     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadScrollSwitch(switchFlag);
1892     if (ret != RET_OK) {
1893         MMI_HILOGE("Get the touchpad scroll switch failed, ret:%{public}d", ret);
1894     }
1895     return ret;
1896 #else
1897     MMI_HILOGW("Pointer device does not support");
1898     return ERROR_UNSUPPORT;
1899 #endif // OHOS_BUILD_ENABLE_POINTER
1900 }
1901 
SetTouchpadScrollDirection(bool state)1902 int32_t InputManagerImpl::SetTouchpadScrollDirection(bool state)
1903 {
1904     CALL_INFO_TRACE;
1905 #if defined OHOS_BUILD_ENABLE_POINTER
1906     std::lock_guard<std::mutex> guard(mtx_);
1907     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadScrollDirection(state);
1908     if (ret != RET_OK) {
1909         MMI_HILOGE("Set the touchpad scroll direction switch failed, ret:%{public}d", ret);
1910     }
1911     return ret;
1912 #else
1913     MMI_HILOGW("Pointer device module does not support");
1914     return ERROR_UNSUPPORT;
1915 #endif // OHOS_BUILD_ENABLE_POINTER
1916 }
1917 
GetTouchpadScrollDirection(bool &state)1918 int32_t InputManagerImpl::GetTouchpadScrollDirection(bool &state)
1919 {
1920     CALL_INFO_TRACE;
1921 #ifdef OHOS_BUILD_ENABLE_POINTER
1922     std::lock_guard<std::mutex> guard(mtx_);
1923     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadScrollDirection(state);
1924     if (ret != RET_OK) {
1925         MMI_HILOGE("Get the touchpad scroll direction switch failed, ret:%{public}d", ret);
1926     }
1927     return ret;
1928 #else
1929     MMI_HILOGW("Pointer device does not support");
1930     return ERROR_UNSUPPORT;
1931 #endif // OHOS_BUILD_ENABLE_POINTER
1932 }
1933 
SetTouchpadTapSwitch(bool switchFlag)1934 int32_t InputManagerImpl::SetTouchpadTapSwitch(bool switchFlag)
1935 {
1936     CALL_INFO_TRACE;
1937 #if defined OHOS_BUILD_ENABLE_POINTER
1938     std::lock_guard<std::mutex> guard(mtx_);
1939     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadTapSwitch(switchFlag);
1940     if (ret != RET_OK) {
1941         MMI_HILOGE("Set the touchpad tap switch failed, ret:%{public}d", ret);
1942     }
1943     return ret;
1944 #else
1945     MMI_HILOGW("Pointer device module does not support");
1946     return ERROR_UNSUPPORT;
1947 #endif // OHOS_BUILD_ENABLE_POINTER
1948 }
1949 
GetTouchpadTapSwitch(bool &switchFlag)1950 int32_t InputManagerImpl::GetTouchpadTapSwitch(bool &switchFlag)
1951 {
1952     CALL_INFO_TRACE;
1953 #ifdef OHOS_BUILD_ENABLE_POINTER
1954     std::lock_guard<std::mutex> guard(mtx_);
1955     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadTapSwitch(switchFlag);
1956     if (ret != RET_OK) {
1957         MMI_HILOGE("Get the touchpad tap switch failed");
1958     }
1959     return ret;
1960 #else
1961     MMI_HILOGW("Pointer device does not support");
1962     return ERROR_UNSUPPORT;
1963 #endif // OHOS_BUILD_ENABLE_POINTER
1964 }
1965 
SetTouchpadPointerSpeed(int32_t speed)1966 int32_t InputManagerImpl::SetTouchpadPointerSpeed(int32_t speed)
1967 {
1968     CALL_INFO_TRACE;
1969 #if defined OHOS_BUILD_ENABLE_POINTER
1970     std::lock_guard<std::mutex> guard(mtx_);
1971     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadPointerSpeed(speed);
1972     if (ret != RET_OK) {
1973         MMI_HILOGE("Set the touchpad pointer speed failed, ret:%{public}d", ret);
1974     }
1975     return ret;
1976 #else
1977     MMI_HILOGW("Pointer device module does not support");
1978     return ERROR_UNSUPPORT;
1979 #endif // OHOS_BUILD_ENABLE_POINTER
1980 }
1981 
GetTouchpadPointerSpeed(int32_t &speed)1982 int32_t InputManagerImpl::GetTouchpadPointerSpeed(int32_t &speed)
1983 {
1984     CALL_INFO_TRACE;
1985 #ifdef OHOS_BUILD_ENABLE_POINTER
1986     std::lock_guard<std::mutex> guard(mtx_);
1987     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadPointerSpeed(speed);
1988     if (ret != RET_OK) {
1989         MMI_HILOGE("Get the touchpad pointer speed failed");
1990     }
1991     return ret;
1992 #else
1993     MMI_HILOGW("Pointer device does not support");
1994     return ERROR_UNSUPPORT;
1995 #endif // OHOS_BUILD_ENABLE_POINTER
1996 }
1997 
SetTouchpadPinchSwitch(bool switchFlag)1998 int32_t InputManagerImpl::SetTouchpadPinchSwitch(bool switchFlag)
1999 {
2000     CALL_INFO_TRACE;
2001 #if defined OHOS_BUILD_ENABLE_POINTER
2002     std::lock_guard<std::mutex> guard(mtx_);
2003     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadPinchSwitch(switchFlag);
2004     if (ret != RET_OK) {
2005         MMI_HILOGE("Set the touchpad pinch switch failed, ret:%{public}d", ret);
2006     }
2007     return ret;
2008 #else
2009     MMI_HILOGW("Pointer device module does not support");
2010     return ERROR_UNSUPPORT;
2011 #endif // OHOS_BUILD_ENABLE_POINTER
2012 }
2013 
GetTouchpadPinchSwitch(bool &switchFlag)2014 int32_t InputManagerImpl::GetTouchpadPinchSwitch(bool &switchFlag)
2015 {
2016     CALL_INFO_TRACE;
2017 #ifdef OHOS_BUILD_ENABLE_POINTER
2018     std::lock_guard<std::mutex> guard(mtx_);
2019     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadPinchSwitch(switchFlag);
2020     if (ret != RET_OK) {
2021         MMI_HILOGE("Get the touchpad pinch switch failed");
2022     }
2023     return ret;
2024 #else
2025     MMI_HILOGW("Pointer device does not support");
2026     return ERROR_UNSUPPORT;
2027 #endif // OHOS_BUILD_ENABLE_POINTER
2028 }
2029 
SetTouchpadSwipeSwitch(bool switchFlag)2030 int32_t InputManagerImpl::SetTouchpadSwipeSwitch(bool switchFlag)
2031 {
2032     CALL_INFO_TRACE;
2033 #if defined OHOS_BUILD_ENABLE_POINTER
2034     std::lock_guard<std::mutex> guard(mtx_);
2035     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadSwipeSwitch(switchFlag);
2036     if (ret != RET_OK) {
2037         MMI_HILOGE("Set the touchpad swipe switch failed, ret:%{public}d", ret);
2038     }
2039     return ret;
2040 #else
2041     MMI_HILOGW("Pointer device module does not support");
2042     return ERROR_UNSUPPORT;
2043 #endif // OHOS_BUILD_ENABLE_POINTER
2044 }
2045 
GetTouchpadSwipeSwitch(bool &switchFlag)2046 int32_t InputManagerImpl::GetTouchpadSwipeSwitch(bool &switchFlag)
2047 {
2048     CALL_INFO_TRACE;
2049 #ifdef OHOS_BUILD_ENABLE_POINTER
2050     std::lock_guard<std::mutex> guard(mtx_);
2051     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadSwipeSwitch(switchFlag);
2052     if (ret != RET_OK) {
2053         MMI_HILOGE("Get the touchpad swipe switch failed");
2054     }
2055     return ret;
2056 #else
2057     MMI_HILOGW("Pointer device does not support");
2058     return ERROR_UNSUPPORT;
2059 #endif // OHOS_BUILD_ENABLE_POINTER
2060 }
2061 
SetTouchpadRightClickType(int32_t type)2062 int32_t InputManagerImpl::SetTouchpadRightClickType(int32_t type)
2063 {
2064     CALL_INFO_TRACE;
2065 #if defined OHOS_BUILD_ENABLE_POINTER
2066     std::lock_guard<std::mutex> guard(mtx_);
2067     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadRightClickType(type);
2068     if (ret != RET_OK) {
2069         MMI_HILOGE("Set the touchpad right click type failed, ret:%{public}d", ret);
2070     }
2071     return ret;
2072 #else
2073     MMI_HILOGW("Pointer device module does not support");
2074     return ERROR_UNSUPPORT;
2075 #endif // OHOS_BUILD_ENABLE_POINTER
2076 }
2077 
GetTouchpadRightClickType(int32_t &type)2078 int32_t InputManagerImpl::GetTouchpadRightClickType(int32_t &type)
2079 {
2080     CALL_INFO_TRACE;
2081 #ifdef OHOS_BUILD_ENABLE_POINTER
2082     std::lock_guard<std::mutex> guard(mtx_);
2083     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadRightClickType(type);
2084     if (ret != RET_OK) {
2085         MMI_HILOGE("Get the touchpad right click failed");
2086     }
2087     return ret;
2088 #else
2089     MMI_HILOGW("Pointer device does not support");
2090     return ERROR_UNSUPPORT;
2091 #endif // OHOS_BUILD_ENABLE_POINTER
2092 }
2093 
SetTouchpadRotateSwitch(bool rotateSwitch)2094 int32_t InputManagerImpl::SetTouchpadRotateSwitch(bool rotateSwitch)
2095 {
2096     CALL_INFO_TRACE;
2097 #if defined OHOS_BUILD_ENABLE_POINTER
2098     std::lock_guard<std::mutex> guard(mtx_);
2099     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadRotateSwitch(rotateSwitch);
2100     if (ret != RET_OK) {
2101         MMI_HILOGE("Set touchpad rotate switch failed, ret:%{public}d", ret);
2102     }
2103     return ret;
2104 #else
2105     MMI_HILOGW("Pointer device module does not support");
2106     return ERROR_UNSUPPORT;
2107 #endif // OHOS_BUILD_ENABLE_POINTER
2108 }
2109 
GetTouchpadRotateSwitch(bool &rotateSwitch)2110 int32_t InputManagerImpl::GetTouchpadRotateSwitch(bool &rotateSwitch)
2111 {
2112     CALL_INFO_TRACE;
2113 #ifdef OHOS_BUILD_ENABLE_POINTER
2114     std::lock_guard<std::mutex> guard(mtx_);
2115     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadRotateSwitch(rotateSwitch);
2116     if (ret != RET_OK) {
2117         MMI_HILOGE("Get touchpad rotate switch failed");
2118     }
2119     return ret;
2120 #else
2121     MMI_HILOGW("Pointer device does not support");
2122     return ERROR_UNSUPPORT;
2123 #endif // OHOS_BUILD_ENABLE_POINTER
2124 }
2125 
EnableHardwareCursorStats(bool enable)2126 int32_t InputManagerImpl::EnableHardwareCursorStats(bool enable)
2127 {
2128     CALL_INFO_TRACE;
2129 #ifdef OHOS_BUILD_ENABLE_POINTER
2130     std::lock_guard<std::mutex> guard(mtx_);
2131     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->EnableHardwareCursorStats(enable);
2132     if (ret != RET_OK) {
2133         MMI_HILOGE("Enable hardware cursor stats failed");
2134     }
2135     return ret;
2136 #else
2137     MMI_HILOGW("Pointer device does not support");
2138     return ERROR_UNSUPPORT;
2139 #endif // OHOS_BUILD_ENABLE_POINTER
2140 }
2141 
GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount)2142 int32_t InputManagerImpl::GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount)
2143 {
2144     CALL_INFO_TRACE;
2145 #ifdef OHOS_BUILD_ENABLE_POINTER
2146     std::lock_guard<std::mutex> guard(mtx_);
2147     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetHardwareCursorStats(frameCount, vsyncCount);
2148     if (ret != RET_OK) {
2149         MMI_HILOGE("Get hardware cursor stats failed");
2150     }
2151     MMI_HILOGD("GetHardwareCursorStats, frameCount:%{public}d, vsyncCount:%{public}d", frameCount, vsyncCount);
2152     return ret;
2153 #else
2154     MMI_HILOGW("Pointer device does not support");
2155     return ERROR_UNSUPPORT;
2156 #endif // OHOS_BUILD_ENABLE_POINTER
2157 }
2158 
GetPointerSnapshot(void *pixelMapPtr)2159 int32_t InputManagerImpl::GetPointerSnapshot(void *pixelMapPtr)
2160 {
2161     CALL_DEBUG_ENTER;
2162 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_MAGICCURSOR)
2163     std::lock_guard<std::mutex> guard(mtx_);
2164     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetPointerSnapshot(pixelMapPtr);
2165     if (ret != RET_OK) {
2166         MMI_HILOGE("Get the pointer snapshot failed, ret:%{public}d", ret);
2167     }
2168     return ret;
2169 #else
2170     MMI_HILOGW("Pointer device module does not support");
2171     return ERROR_UNSUPPORT;
2172 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_MAGICCURSOR
2173 }
2174 
SetTouchpadScrollRows(int32_t rows)2175 int32_t InputManagerImpl::SetTouchpadScrollRows(int32_t rows)
2176 {
2177     CALL_INFO_TRACE;
2178 #if defined OHOS_BUILD_ENABLE_POINTER
2179     std::lock_guard<std::mutex> guard(mtx_);
2180     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadScrollRows(rows);
2181     if (ret != RET_OK) {
2182         MMI_HILOGE("Set the number of touchpad scrolling rows failed, ret:%{public}d", ret);
2183     }
2184     return ret;
2185 #else
2186     MMI_HILOGW("Pointer device module does not support");
2187     return ERROR_UNSUPPORT;
2188 #endif // OHOS_BUILD_ENABLE_POINTER
2189 }
2190 
GetTouchpadScrollRows(int32_t &rows)2191 int32_t InputManagerImpl::GetTouchpadScrollRows(int32_t &rows)
2192 {
2193     CALL_INFO_TRACE;
2194 #ifdef OHOS_BUILD_ENABLE_POINTER
2195     std::lock_guard<std::mutex> guard(mtx_);
2196     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadScrollRows(rows);
2197     if (ret != RET_OK) {
2198         MMI_HILOGE("Get the number of touchpad scrolling rows failed");
2199     }
2200     return ret;
2201 #else
2202     MMI_HILOGW("Pointer device does not support");
2203     return ERROR_UNSUPPORT;
2204 #endif // OHOS_BUILD_ENABLE_POINTER
2205 }
2206 
SetNapStatus(int32_t pid, int32_t uid, const std::string &bundleName, int32_t napStatus)2207 int32_t InputManagerImpl::SetNapStatus(int32_t pid, int32_t uid, const std::string &bundleName, int32_t napStatus)
2208 {
2209     CALL_INFO_TRACE;
2210     std::lock_guard<std::mutex> guard(mtx_);
2211     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetNapStatus(pid, uid, bundleName, napStatus);
2212     if (ret != RET_OK) {
2213         MMI_HILOGE("Set napStatus failed, ret:%{public}d", ret);
2214     }
2215     return ret;
2216 }
2217 
NotifyBundleName(int32_t pid, int32_t uid, const std::string &bundleName, int32_t syncStatus)2218 void InputManagerImpl::NotifyBundleName(int32_t pid, int32_t uid, const std::string &bundleName, int32_t syncStatus)
2219 {
2220     CALL_INFO_TRACE;
2221     CHKPV(eventObserver_);
2222     eventObserver_->SyncBundleName(pid, uid, bundleName, syncStatus);
2223 }
2224 
SetWindowPointerStyle(WindowArea area, int32_t pid, int32_t windowId)2225 void InputManagerImpl::SetWindowPointerStyle(WindowArea area, int32_t pid, int32_t windowId)
2226 {
2227     CALL_INFO_TRACE;
2228 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
2229     std::lock_guard<std::mutex> guard(mtx_);
2230     if (!MMIEventHdl.InitClient()) {
2231         MMI_HILOGE("Get mmi client is nullptr");
2232         return;
2233     }
2234     SendWindowAreaInfo(area, pid, windowId);
2235 #else
2236     MMI_HILOGW("Pointer device or pointer drawing module does not support");
2237 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
2238 }
2239 
SendWindowAreaInfo(WindowArea area, int32_t pid, int32_t windowId)2240 void InputManagerImpl::SendWindowAreaInfo(WindowArea area, int32_t pid, int32_t windowId)
2241 {
2242     CALL_INFO_TRACE;
2243     MMIClientPtr client = MMIEventHdl.GetMMIClient();
2244     CHKPV(client);
2245     NetPacket pkt(MmiMessageId::WINDOW_AREA_INFO);
2246     pkt << area << pid << windowId;
2247     if (pkt.ChkRWError()) {
2248         MMI_HILOGE("Packet write logical data failed");
2249         return;
2250     }
2251     if (!client->SendMessage(pkt)) {
2252         MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL);
2253     }
2254 }
2255 
ClearWindowPointerStyle(int32_t pid, int32_t windowId)2256 void InputManagerImpl::ClearWindowPointerStyle(int32_t pid, int32_t windowId)
2257 {
2258     CALL_INFO_TRACE;
2259     std::lock_guard<std::mutex> guard(mtx_);
2260     if (!MMIEventHdl.InitClient()) {
2261         MMI_HILOGE("Get mmi client is nullptr");
2262         return;
2263     }
2264     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->ClearWindowPointerStyle(pid, windowId);
2265     if (ret != RET_OK) {
2266         MMI_HILOGE("ClearWindowPointerStyle failed, ret:%{public}d", ret);
2267         return;
2268     }
2269 }
2270 
SetShieldStatus(int32_t shieldMode, bool isShield)2271 int32_t InputManagerImpl::SetShieldStatus(int32_t shieldMode, bool isShield)
2272 {
2273     CALL_INFO_TRACE;
2274     std::lock_guard<std::mutex> guard(mtx_);
2275 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
2276     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetShieldStatus(shieldMode, isShield);
2277     if (ret != RET_OK) {
2278         MMI_HILOGE("Set shield event interception status failed, ret:%{public}d", ret);
2279     }
2280     return ret;
2281 #else
2282     MMI_HILOGW("Keyboard device does not support");
2283     return ERROR_UNSUPPORT;
2284 #endif // OHOS_BUILD_ENABLE_KEYBOARD
2285 }
2286 
GetShieldStatus(int32_t shieldMode, bool &isShield)2287 int32_t InputManagerImpl::GetShieldStatus(int32_t shieldMode, bool &isShield)
2288 {
2289     CALL_INFO_TRACE;
2290     std::lock_guard<std::mutex> guard(mtx_);
2291 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
2292     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetShieldStatus(shieldMode, isShield);
2293     if (ret != RET_OK) {
2294         MMI_HILOGE("Get shield event interception status failed, ret:%{public}d", ret);
2295     }
2296     return ret;
2297 #else
2298     MMI_HILOGW("Keyboard device does not support");
2299     return ERROR_UNSUPPORT;
2300 #endif // OHOS_BUILD_ENABLE_KEYBOARD
2301 }
2302 
AddServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher)2303 void InputManagerImpl::AddServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher)
2304 {
2305     CALL_INFO_TRACE;
2306     MULTIMODAL_INPUT_CONNECT_MGR->AddServiceWatcher(watcher);
2307 }
2308 
RemoveServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher)2309 void InputManagerImpl::RemoveServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher)
2310 {
2311     CALL_INFO_TRACE;
2312     MULTIMODAL_INPUT_CONNECT_MGR->RemoveServiceWatcher(watcher);
2313 }
2314 
MarkProcessed(int32_t eventId, int64_t actionTime)2315 int32_t InputManagerImpl::MarkProcessed(int32_t eventId, int64_t actionTime)
2316 {
2317     CALL_DEBUG_ENTER;
2318     ANRHDL->SetLastProcessedEventId(EVENT_TYPE, eventId, actionTime);
2319     return RET_OK;
2320 }
2321 
GetKeyState(std::vector<int32_t> &pressedKeys, std::map<int32_t, int32_t> &specialKeysState)2322 int32_t InputManagerImpl::GetKeyState(std::vector<int32_t> &pressedKeys, std::map<int32_t, int32_t> &specialKeysState)
2323 {
2324     CALL_INFO_TRACE;
2325     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetKeyState(pressedKeys, specialKeysState);
2326     if (ret != RET_OK) {
2327         MMI_HILOGE("Get key state failed, ret:%{public}d", ret);
2328         return ret;
2329     }
2330     return RET_OK;
2331 }
2332 
Authorize(bool isAuthorize)2333 void InputManagerImpl::Authorize(bool isAuthorize)
2334 {
2335     if (MMIEventHdl.Authorize(isAuthorize) != RET_OK) {
2336         MMI_HILOGE("Failed to authorize");
2337     }
2338 }
2339 
CancelInjection()2340 int32_t InputManagerImpl::CancelInjection()
2341 {
2342     if (MMIEventHdl.CancelInjection() != RET_OK) {
2343         MMI_HILOGE("CancelInjection failed");
2344         return RET_ERR;
2345     }
2346     return RET_OK;
2347 }
2348 
2349 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD
SetVKeyboardArea(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY)2350 int32_t InputManagerImpl::SetVKeyboardArea(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY)
2351 {
2352     CALL_INFO_TRACE;
2353     return MULTIMODAL_INPUT_CONNECT_MGR->SetVKeyboardArea(topLeftX, topLeftY, bottomRightX, bottomRightY);
2354 }
2355 
SetMotionSpace(std::string& keyName, bool useShift, std::vector<int32_t>& pattern)2356 int32_t InputManagerImpl::SetMotionSpace(std::string& keyName, bool useShift, std::vector<int32_t>& pattern)
2357 {
2358     CALL_INFO_TRACE;
2359     return MULTIMODAL_INPUT_CONNECT_MGR->SetMotionSpace(keyName, useShift, pattern);
2360 }
2361 #endif // OHOS_BUILD_ENABLE_VKEYBOARD
2362 
HasIrEmitter(bool &hasIrEmitter)2363 int32_t InputManagerImpl::HasIrEmitter(bool &hasIrEmitter)
2364 {
2365     CALL_INFO_TRACE;
2366     return MULTIMODAL_INPUT_CONNECT_MGR->HasIrEmitter(hasIrEmitter);
2367 }
2368 
GetInfraredFrequencies(std::vector<InfraredFrequency>& requencys)2369 int32_t InputManagerImpl::GetInfraredFrequencies(std::vector<InfraredFrequency>& requencys)
2370 {
2371     CALL_INFO_TRACE;
2372     return MULTIMODAL_INPUT_CONNECT_MGR->GetInfraredFrequencies(requencys);
2373 }
2374 
TransmitInfrared(int64_t number, std::vector<int64_t>& pattern)2375 int32_t InputManagerImpl::TransmitInfrared(int64_t number, std::vector<int64_t>& pattern)
2376 {
2377     CALL_INFO_TRACE;
2378     return MULTIMODAL_INPUT_CONNECT_MGR->TransmitInfrared(number, pattern);
2379 }
2380 
SetPixelMapData(int32_t infoId, void* pixelMap)2381 int32_t InputManagerImpl::SetPixelMapData(int32_t infoId, void* pixelMap)
2382 {
2383     CALL_DEBUG_ENTER;
2384     if (infoId < 0 || pixelMap == nullptr) {
2385         MMI_HILOGE("Invalid infoId or pixelMap");
2386         return RET_ERR;
2387     }
2388     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetPixelMapData(infoId, pixelMap);
2389     if (ret != RET_OK) {
2390         MMI_HILOGE("Failed to set pixel map, ret:%{public}d", ret);
2391     }
2392     return ret;
2393 }
2394 
SetCurrentUser(int32_t userId)2395 int32_t InputManagerImpl::SetCurrentUser(int32_t userId)
2396 {
2397     CALL_DEBUG_ENTER;
2398     if (userId < 0) {
2399         MMI_HILOGE("Invalid userId");
2400         return RET_ERR;
2401     }
2402     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetCurrentUser(userId);
2403     if (ret != RET_OK) {
2404         MMI_HILOGE("Failed to set userId, ret:%{public}d", ret);
2405     }
2406     return ret;
2407 }
2408 
SetMoveEventFilters(bool flag)2409 int32_t InputManagerImpl::SetMoveEventFilters(bool flag)
2410 {
2411     CALL_DEBUG_ENTER;
2412 #ifdef OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
2413     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetMoveEventFilters(flag);
2414     if (ret != RET_OK) {
2415         MMI_HILOGE("Set move event filters failed, ret:%{public}d", ret);
2416     }
2417     return ret;
2418 #else
2419     MMI_HILOGW("Set move event filters does not support");
2420     return ERROR_UNSUPPORT;
2421 #endif // OHOS_BUILD_ENABLE_MOVE_EVENT_FILTERS
2422 }
2423 
SetTouchpadThreeFingersTapSwitch(bool switchFlag)2424 int32_t InputManagerImpl::SetTouchpadThreeFingersTapSwitch(bool switchFlag)
2425 {
2426     CALL_DEBUG_ENTER;
2427     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->SetTouchpadThreeFingersTapSwitch(switchFlag);
2428     if (ret != RET_OK) {
2429         MMI_HILOGE("Failed to SetTouchpadThreeFingersTapSwitch, ret:%{public}d", ret);
2430     }
2431     return ret;
2432 }
2433 
GetTouchpadThreeFingersTapSwitch(bool &switchFlag)2434 int32_t InputManagerImpl::GetTouchpadThreeFingersTapSwitch(bool &switchFlag)
2435 {
2436     CALL_DEBUG_ENTER;
2437     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->GetTouchpadThreeFingersTapSwitch(switchFlag);
2438     if (ret != RET_OK) {
2439         MMI_HILOGE("Failed to GetTouchpadThreeFingersTapSwitch, ret:%{public}d", ret);
2440     }
2441     return ret;
2442 }
2443 
GetWinSyncBatchSize(int32_t maxAreasCount, int32_t displayCount)2444 int32_t InputManagerImpl::GetWinSyncBatchSize(int32_t maxAreasCount, int32_t displayCount)
2445 {
2446     return (MAX_PKT_SIZE - GetDisplayMaxSize() * displayCount) / GetWindowMaxSize(maxAreasCount);
2447 }
2448 
AddVirtualInputDevice(std::shared_ptr<InputDevice> device, int32_t &deviceId)2449 int32_t InputManagerImpl::AddVirtualInputDevice(std::shared_ptr<InputDevice> device, int32_t &deviceId)
2450 {
2451     return MULTIMODAL_INPUT_CONNECT_MGR->AddVirtualInputDevice(device, deviceId);
2452 }
2453 
RemoveVirtualInputDevice(int32_t deviceId)2454 int32_t InputManagerImpl::RemoveVirtualInputDevice(int32_t deviceId)
2455 {
2456     return MULTIMODAL_INPUT_CONNECT_MGR->RemoveVirtualInputDevice(deviceId);
2457 }
2458 
AncoAddChannel(std::shared_ptr<IAncoConsumer> consumer)2459 int32_t InputManagerImpl::AncoAddChannel(std::shared_ptr<IAncoConsumer> consumer)
2460 {
2461 #ifdef OHOS_BUILD_ENABLE_ANCO
2462     std::lock_guard<std::mutex> guard(mtx_);
2463     if (ancoChannels_.find(consumer) != ancoChannels_.end()) {
2464         return RET_OK;
2465     }
2466     sptr<IAncoChannel> tChannel = sptr<AncoChannel>::MakeSptr(consumer);
2467     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->AncoAddChannel(tChannel);
2468     if (ret != RET_OK) {
2469         MMI_HILOGE("AncoAddChannel fail, error:%{public}d", ret);
2470         return ret;
2471     }
2472     ancoChannels_.emplace(consumer, tChannel);
2473     return RET_OK;
2474 #endif // OHOS_BUILD_ENABLE_ANCO
2475     MMI_HILOGI("AncoAddChannel function does not support");
2476     return ERROR_UNSUPPORT;
2477 }
2478 
AncoRemoveChannel(std::shared_ptr<IAncoConsumer> consumer)2479 int32_t InputManagerImpl::AncoRemoveChannel(std::shared_ptr<IAncoConsumer> consumer)
2480 {
2481 #ifdef OHOS_BUILD_ENABLE_ANCO
2482     std::lock_guard<std::mutex> guard(mtx_);
2483     auto iter = ancoChannels_.find(consumer);
2484     if (iter == ancoChannels_.end()) {
2485         MMI_HILOGI("Not associated with any channel");
2486         return RET_OK;
2487     }
2488     int32_t ret = MULTIMODAL_INPUT_CONNECT_MGR->AncoRemoveChannel(iter->second);
2489     if (ret != RET_OK) {
2490         MMI_HILOGE("AncoRemoveChannel fail, error:%{public}d", ret);
2491         return ret;
2492     }
2493     ancoChannels_.erase(iter);
2494     return RET_OK;
2495 #endif // OHOS_BUILD_ENABLE_ANCO
2496     MMI_HILOGI("AncoRemoveChannel function does not support");
2497     return ERROR_UNSUPPORT;
2498 }
2499 
SkipPointerLayer(bool isSkip)2500 int32_t InputManagerImpl::SkipPointerLayer(bool isSkip)
2501 {
2502     return MULTIMODAL_INPUT_CONNECT_MGR->SkipPointerLayer(isSkip);
2503 }
2504 
OnWindowStateError(int32_t pid, int32_t windowId)2505 void InputManagerImpl::OnWindowStateError(int32_t pid, int32_t windowId)
2506 {
2507     if (windowStatecallback_ != nullptr) {
2508         windowStatecallback_(pid, windowId);
2509     } else {
2510         MMI_HILOGE("Window state callback is null");
2511     }
2512 }
2513 
GetIntervalSinceLastInput(int64_t &timeInterval)2514 int32_t InputManagerImpl::GetIntervalSinceLastInput(int64_t &timeInterval)
2515 {
2516     CALL_DEBUG_ENTER;
2517     std::lock_guard<std::mutex> guard(mtx_);
2518     if (!MMIEventHdl.InitClient()) {
2519         MMI_HILOGE("Client init failed");
2520         return RET_ERR;
2521     }
2522     if (MULTIMODAL_INPUT_CONNECT_MGR->GetIntervalSinceLastInput(timeInterval) != RET_OK) {
2523         MMI_HILOGE("GetIntervalSinceLastInput failed");
2524         return RET_ERR;
2525     }
2526     return RET_OK;
2527 }
2528 
GetAllSystemHotkeys(std::vector<std::unique_ptr<KeyOption>> &keyOptions, int32_t &count)2529 int32_t InputManagerImpl::GetAllSystemHotkeys(std::vector<std::unique_ptr<KeyOption>> &keyOptions, int32_t &count)
2530 {
2531     CALL_INFO_TRACE;
2532     if (MULTIMODAL_INPUT_CONNECT_MGR->GetAllSystemHotkeys(keyOptions) != RET_OK) {
2533         MMI_HILOGE("GetAllSystemHotkeys failed");
2534         return RET_ERR;
2535     }
2536     count = static_cast<int32_t>(keyOptions.size());
2537     return RET_OK;
2538 }
2539 
ConvertToCapiKeyAction(int32_t keyAction)2540 int32_t InputManagerImpl::ConvertToCapiKeyAction(int32_t keyAction)
2541 {
2542     auto iter = g_keyActionMap.find(keyAction);
2543     if (iter == g_keyActionMap.end()) {
2544         MMI_HILOGE("Convert keyAction:%{public}d to capi failed", keyAction);
2545         return INVALID_KEY_ACTION;
2546     }
2547     return iter->second;
2548 }
2549 } // namespace MMI
2550 } // namespace OHOS