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