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