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