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