1 /*
2 * Copyright (c) 2021-2022 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 "mmi_service.h"
17
18 #include <cinttypes>
19 #include <csignal>
20 #include <parameters.h>
21 #include <sys/signalfd.h>
22 #ifdef OHOS_RSS_CLIENT
23 #include <unordered_map>
24 #endif
25
26 #include "anr_manager.h"
27 #include "dfx_hisysevent.h"
28 #include "event_dump.h"
29 #include "input_device_manager.h"
30 #include "input_windows_manager.h"
31 #include "i_pointer_drawing_manager.h"
32 #include "key_map_manager.h"
33 #include "multimodal_input_connect_def_parcel.h"
34 #include "permission_helper.h"
35 #include "string_ex.h"
36 #ifdef OHOS_RSS_CLIENT
37 #include "res_sched_client.h"
38 #include "res_type.h"
39 #include "system_ability_definition.h"
40 #endif
41
42 #include "mmi_log.h"
43 #include "timer_manager.h"
44 #include "util.h"
45 #include "util_ex.h"
46 #include "util_napi_error.h"
47 #include "xcollie/watchdog.h"
48 #include "key_auto_repeat.h"
49 #include "key_command_handler.h"
50 #include "touch_event_normalize.h"
51 #include "display_event_monitor.h"
52 #include "fingersense_wrapper.h"
53
54 namespace OHOS {
55 namespace MMI {
56 namespace {
57 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MMIService" };
58 const std::string DEF_INPUT_SEAT = "seat0";
59 constexpr int32_t WATCHDOG_INTERVAL_TIME = 10000;
60 constexpr int32_t WATCHDOG_DELAY_TIME = 15000;
61 } // namespace
62
63 const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton<MMIService>::GetInstance().get());
64
65 struct mmi_epoll_event {
66 int32_t fd{ 0 };
67 EpollEventType event_type{ EPOLL_EVENT_BEGIN };
68 };
69
CheckDefineOutput(const char * fmt,Ts...args)70 template <class... Ts> void CheckDefineOutput(const char *fmt, Ts... args)
71 {
72 CHKPV(fmt);
73 char buf[MAX_PACKET_BUF_SIZE] = {};
74 int32_t ret = snprintf_s(buf, MAX_PACKET_BUF_SIZE, MAX_PACKET_BUF_SIZE - 1, fmt, args...);
75 if (ret == -1) {
76 KMSG_LOGI("Call snprintf_s failed.ret = %d", ret);
77 return;
78 }
79 KMSG_LOGI("%s", buf);
80 MMI_HILOGI("%{public}s", buf);
81 }
82
CheckDefine()83 static void CheckDefine()
84 {
85 CheckDefineOutput("ChkDefs:");
86 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
87 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_POINTER_DRAWING");
88 #endif
89 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
90 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_INTERCEPTOR");
91 #endif
92 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
93 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_KEYBOARD");
94 #endif
95 #ifdef OHOS_BUILD_ENABLE_POINTER
96 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_POINTER");
97 #endif
98 #ifdef OHOS_BUILD_ENABLE_TOUCH
99 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_TOUCH");
100 #endif
101 #ifdef OHOS_BUILD_ENABLE_MONITOR
102 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_MONITOR");
103 #endif
104 }
105
MMIService()106 MMIService::MMIService() : SystemAbility(MULTIMODAL_INPUT_CONNECT_SERVICE_ID, true) {}
107
~MMIService()108 MMIService::~MMIService() {}
109
AddEpoll(EpollEventType type,int32_t fd)110 int32_t MMIService::AddEpoll(EpollEventType type, int32_t fd)
111 {
112 if (!(type >= EPOLL_EVENT_BEGIN && type < EPOLL_EVENT_END)) {
113 MMI_HILOGE("Invalid param type");
114 return RET_ERR;
115 }
116 if (fd < 0) {
117 MMI_HILOGE("Invalid param fd_");
118 return RET_ERR;
119 }
120 if (mmiFd_ < 0) {
121 MMI_HILOGE("Invalid param mmiFd_");
122 return RET_ERR;
123 }
124 auto eventData = static_cast<mmi_epoll_event *>(malloc(sizeof(mmi_epoll_event)));
125 if (!eventData) {
126 MMI_HILOGE("Malloc failed");
127 return RET_ERR;
128 }
129 eventData->fd = fd;
130 eventData->event_type = type;
131 MMI_HILOGI("userdata:[fd:%{public}d,type:%{public}d]", eventData->fd, eventData->event_type);
132
133 struct epoll_event ev = {};
134 ev.events = EPOLLIN;
135 ev.data.ptr = eventData;
136 auto ret = EpollCtl(fd, EPOLL_CTL_ADD, ev, mmiFd_);
137 if (ret < 0) {
138 free(eventData);
139 eventData = nullptr;
140 ev.data.ptr = nullptr;
141 return ret;
142 }
143 return RET_OK;
144 }
145
DelEpoll(EpollEventType type,int32_t fd)146 int32_t MMIService::DelEpoll(EpollEventType type, int32_t fd)
147 {
148 if (!(type >= EPOLL_EVENT_BEGIN && type < EPOLL_EVENT_END)) {
149 MMI_HILOGE("Invalid param type");
150 return RET_ERR;
151 }
152 if (fd < 0) {
153 MMI_HILOGE("Invalid param fd_");
154 return RET_ERR;
155 }
156 if (mmiFd_ < 0) {
157 MMI_HILOGE("Invalid param mmiFd_");
158 return RET_ERR;
159 }
160 struct epoll_event ev = {};
161 auto ret = EpollCtl(fd, EPOLL_CTL_DEL, ev, mmiFd_);
162 if (ret < 0) {
163 MMI_HILOGE("DelEpoll failed");
164 return ret;
165 }
166 return RET_OK;
167 }
168
IsRunning() const169 bool MMIService::IsRunning() const
170 {
171 return (state_ == ServiceRunningState::STATE_RUNNING);
172 }
173
InitLibinputService()174 bool MMIService::InitLibinputService()
175 {
176 if (!(libinputAdapter_.Init(std::bind(&InputEventHandler::OnEvent, InputHandler, std::placeholders::_1)))) {
177 MMI_HILOGE("Libinput init, bind failed");
178 return false;
179 }
180 auto inputFds = libinputAdapter_.GetInputFds();
181 for (auto fd : inputFds) {
182 auto ret = AddEpoll(EPOLL_EVENT_INPUT, fd);
183 if (ret < 0) {
184 MMI_HILOGE("AddEpoll error ret:%{public}d", ret);
185 EpollClose();
186 return false;
187 }
188 MMI_HILOGI("AddEpoll, epollfd:%{public}d, fd:%{public}d", mmiFd_, fd);
189 }
190 return true;
191 }
192
InitService()193 bool MMIService::InitService()
194 {
195 MMI_HILOGD("Server msg handler Init");
196 sMsgHandler_.Init(*this);
197 if (state_ != ServiceRunningState::STATE_NOT_START) {
198 MMI_HILOGE("Service running status is not enabled");
199 return false;
200 }
201 if (EpollCreate(MAX_EVENT_SIZE) < 0) {
202 MMI_HILOGE("Create epoll failed");
203 return false;
204 }
205 auto ret = AddEpoll(EPOLL_EVENT_SOCKET, epollFd_);
206 if (ret < 0) {
207 MMI_HILOGE("AddEpoll error ret:%{public}d", ret);
208 EpollClose();
209 return false;
210 }
211 state_ = ServiceRunningState::STATE_RUNNING;
212 if (!(Publish(this))) {
213 state_ = ServiceRunningState::STATE_NOT_START;
214 MMI_HILOGE("Service initialization failed");
215 return false;
216 }
217 MMI_HILOGI("AddEpoll, epollfd:%{public}d,fd:%{public}d", mmiFd_, epollFd_);
218 return true;
219 }
220
InitDelegateTasks()221 bool MMIService::InitDelegateTasks()
222 {
223 CALL_DEBUG_ENTER;
224 if (!delegateTasks_.Init()) {
225 MMI_HILOGE("The delegate task init failed");
226 return false;
227 }
228 auto ret = AddEpoll(EPOLL_EVENT_ETASK, delegateTasks_.GetReadFd());
229 if (ret < 0) {
230 MMI_HILOGE("AddEpoll error ret:%{public}d", ret);
231 EpollClose();
232 return false;
233 }
234 MMI_HILOGI("AddEpoll, epollfd:%{public}d,fd:%{public}d", mmiFd_, delegateTasks_.GetReadFd());
235 return true;
236 }
237
Init()238 int32_t MMIService::Init()
239 {
240 CheckDefine();
241 MMI_HILOGD("WindowsManager Init");
242 WinMgr->Init(*this);
243 MMI_HILOGD("ANRManager Init");
244 ANRMgr->Init(*this);
245 MMI_HILOGD("PointerDrawingManager Init");
246 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
247 FINGERSENSE_WRAPPER->InitFingerSenseWrapper();
248 DISPLAY_MONITOR->InitCommonEventSubscriber();
249 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
250 #ifdef OHOS_BUILD_ENABLE_POINTER
251 if (!IPointerDrawingManager::GetInstance()->Init()) {
252 MMI_HILOGE("Pointer draw init failed");
253 return POINTER_DRAW_INIT_FAIL;
254 }
255 #endif // OHOS_BUILD_ENABLE_POINTER
256 mmiFd_ = EpollCreate(MAX_EVENT_SIZE);
257 if (mmiFd_ < 0) {
258 MMI_HILOGE("Create epoll failed");
259 return EPOLL_CREATE_FAIL;
260 }
261 MMI_HILOGD("Input msg handler init");
262 InputHandler->Init(*this);
263 if (!InitLibinputService()) {
264 MMI_HILOGE("Libinput init failed");
265 return LIBINPUT_INIT_FAIL;
266 }
267 if (!InitDelegateTasks()) {
268 MMI_HILOGE("Delegate tasks init failed");
269 return ETASKS_INIT_FAIL;
270 }
271 SetRecvFun(std::bind(&ServerMsgHandler::OnMsgHandler, &sMsgHandler_, std::placeholders::_1, std::placeholders::_2));
272 KeyMapMgr->GetConfigKeyValue("default_keymap", KeyMapMgr->GetDefaultKeyId());
273 OHOS::system::SetParameter(INPUT_POINTER_DEVICE, "false");
274 if (!InitService()) {
275 MMI_HILOGE("Saservice init failed");
276 return SASERVICE_INIT_FAIL;
277 }
278 MMI_HILOGI("Set para input.pointer.device false");
279 return RET_OK;
280 }
281
OnStart()282 void MMIService::OnStart()
283 {
284 int sleepSeconds = 3;
285 std::string name = "mmi-service";
286 sleep(sleepSeconds);
287 CHK_PID_AND_TID();
288 int32_t ret = Init();
289 if (RET_OK != ret) {
290 MMI_HILOGE("Init mmi_service failed");
291 return;
292 }
293 MMI_HILOGD("Started successfully");
294 AddReloadDeviceTimer();
295 t_ = std::thread(std::bind(&MMIService::OnThread, this));
296 pthread_setname_np(t_.native_handle(), name.c_str());
297 #ifdef OHOS_RSS_CLIENT
298 MMI_HILOGI("Add system ability listener start");
299 AddSystemAbilityListener(RES_SCHED_SYS_ABILITY_ID);
300 MMI_HILOGI("Add system ability listener success");
301 #endif
302
303 TimerMgr->AddTimer(WATCHDOG_INTERVAL_TIME, -1, [this]() {
304 MMI_HILOGD("Set thread status flag to true");
305 threadStatusFlag_ = true;
306 });
307 auto taskFunc = [this]() {
308 if (threadStatusFlag_) {
309 MMI_HILOGD("Set thread status flag to false");
310 threadStatusFlag_ = false;
311 } else {
312 MMI_HILOGE("Watchdog happened");
313 }
314 };
315 MMI_HILOGI("Run periodical task start");
316 HiviewDFX::Watchdog::GetInstance().RunPeriodicalTask("MMIService", taskFunc, WATCHDOG_INTERVAL_TIME,
317 WATCHDOG_DELAY_TIME);
318 MMI_HILOGI("Run periodical task success");
319 }
320
OnStop()321 void MMIService::OnStop()
322 {
323 CHK_PID_AND_TID();
324 UdsStop();
325 libinputAdapter_.Stop();
326 state_ = ServiceRunningState::STATE_NOT_START;
327 #ifdef OHOS_RSS_CLIENT
328 MMI_HILOGI("Remove system ability listener start");
329 RemoveSystemAbilityListener(RES_SCHED_SYS_ABILITY_ID);
330 MMI_HILOGI("Remove system ability listener success");
331 #endif
332 }
333
AllocSocketFd(const std::string & programName,const int32_t moduleType,int32_t & toReturnClientFd,int32_t & tokenType)334 int32_t MMIService::AllocSocketFd(const std::string &programName, const int32_t moduleType, int32_t &toReturnClientFd,
335 int32_t &tokenType)
336 {
337 MMI_HILOGI("Enter, programName:%{public}s,moduleType:%{public}d", programName.c_str(), moduleType);
338
339 toReturnClientFd = IMultimodalInputConnect::INVALID_SOCKET_FD;
340 int32_t serverFd = IMultimodalInputConnect::INVALID_SOCKET_FD;
341 int32_t pid = GetCallingPid();
342 int32_t uid = GetCallingUid();
343 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&UDSServer::AddSocketPairInfo, this, programName, moduleType,
344 uid, pid, serverFd, std::ref(toReturnClientFd), tokenType));
345 DfxHisysevent::ClientConnectData data = {
346 .pid = pid,
347 .uid = uid,
348 .moduleType = moduleType,
349 .programName = programName,
350 .serverFd = serverFd
351 };
352 if (ret != RET_OK) {
353 MMI_HILOGE("Call AddSocketPairInfo failed,return %{public}d", ret);
354 DfxHisysevent::OnClientConnect(data, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
355 return RET_ERR;
356 }
357 MMI_HILOGIK("Leave, programName:%{public}s,moduleType:%{public}d,alloc success", programName.c_str(), moduleType);
358 DfxHisysevent::OnClientConnect(data, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
359 return RET_OK;
360 }
361
AddInputEventFilter(sptr<IEventFilter> filter,int32_t filterId,int32_t priority,uint32_t deviceTags)362 int32_t MMIService::AddInputEventFilter(sptr<IEventFilter> filter, int32_t filterId, int32_t priority,
363 uint32_t deviceTags)
364 {
365 CALL_INFO_TRACE;
366 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD)
367 CHKPR(filter, ERROR_NULL_POINTER);
368 int32_t clientPid = GetCallingPid();
369 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&ServerMsgHandler::AddInputEventFilter, &sMsgHandler_, filter,
370 filterId, priority, deviceTags, clientPid));
371 if (ret != RET_OK) {
372 MMI_HILOGE("Add event filter failed,return %{public}d", ret);
373 return ret;
374 }
375 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD
376 return RET_OK;
377 }
378
RemoveInputEventFilter(int32_t filterId)379 int32_t MMIService::RemoveInputEventFilter(int32_t filterId)
380 {
381 CALL_INFO_TRACE;
382 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD)
383 int32_t clientPid = GetCallingPid();
384 int32_t ret = delegateTasks_.PostSyncTask(
385 std::bind(&ServerMsgHandler::RemoveInputEventFilter, &sMsgHandler_, filterId, clientPid));
386 if (ret != RET_OK) {
387 MMI_HILOGE("Remove event filter failed,return %{public}d", ret);
388 return ret;
389 }
390 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD
391 return RET_OK;
392 }
393
OnConnected(SessionPtr s)394 void MMIService::OnConnected(SessionPtr s)
395 {
396 CHKPV(s);
397 MMI_HILOGI("fd:%{public}d", s->GetFd());
398 }
399
OnDisconnected(SessionPtr s)400 void MMIService::OnDisconnected(SessionPtr s)
401 {
402 CHKPV(s);
403 MMI_HILOGW("Enter, session desc:%{public}s, fd:%{public}d", s->GetDescript().c_str(), s->GetFd());
404 auto ret = RemoveInputEventFilter(-1);
405 if (ret != RET_OK) {
406 MMI_HILOGF("Remove all filter failed, ret:%{public}d", ret);
407 }
408 #ifdef OHOS_BUILD_ENABLE_POINTER
409 IPointerDrawingManager::GetInstance()->DeletePointerVisible(s->GetPid());
410 #endif // OHOS_BUILD_ENABLE_POINTER
411 }
412
SetMouseScrollRows(int32_t rows)413 int32_t MMIService::SetMouseScrollRows(int32_t rows)
414 {
415 CALL_DEBUG_ENTER;
416 #if defined OHOS_BUILD_ENABLE_POINTER
417 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetMouseScrollRows, MouseEventHdr, rows));
418 if (ret != RET_OK) {
419 MMI_HILOGE("Set the number of mouse scrolling rows failed, return %{public}d", ret);
420 return ret;
421 }
422 #endif // OHOS_BUILD_ENABLE_POINTER
423 return RET_OK;
424 }
425
SetMouseIcon(int32_t windowId,void * pixelMap)426 int32_t MMIService::SetMouseIcon(int32_t windowId, void* pixelMap)
427 {
428 CALL_DEBUG_ENTER;
429 #if defined OHOS_BUILD_ENABLE_POINTER
430 int32_t ret = delegateTasks_.PostSyncTask(std::bind(std::bind(&IPointerDrawingManager::SetMouseIcon,
431 IPointerDrawingManager::GetInstance(), windowId, pixelMap)));
432 if (ret != RET_OK) {
433 MMI_HILOGE("Set the mouse icon failed, return %{public}d", ret);
434 return ret;
435 }
436 #endif // OHOS_BUILD_ENABLE_POINTER
437 return RET_OK;
438 }
439
SetMouseHotSpot(int32_t windowId,int32_t hotSpotX,int32_t hotSpotY)440 int32_t MMIService::SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY)
441 {
442 CALL_DEBUG_ENTER;
443 #if defined OHOS_BUILD_ENABLE_POINTER
444 int32_t ret = delegateTasks_.PostSyncTask(std::bind(std::bind(&IPointerDrawingManager::SetMouseHotSpot,
445 IPointerDrawingManager::GetInstance(), windowId, hotSpotX, hotSpotY)));
446 if (ret != RET_OK) {
447 MMI_HILOGE("Set the mouse hot spot failed, return %{public}d", ret);
448 return ret;
449 }
450 #endif // OHOS_BUILD_ENABLE_POINTER
451 return RET_OK;
452 }
453
454 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadMouseScrollRows(int32_t & rows)455 int32_t MMIService::ReadMouseScrollRows(int32_t &rows)
456 {
457 rows = MouseEventHdr->GetMouseScrollRows();
458 return RET_OK;
459 }
460 #endif // OHOS_BUILD_ENABLE_POINTER
461
GetMouseScrollRows(int32_t & rows)462 int32_t MMIService::GetMouseScrollRows(int32_t &rows)
463 {
464 CALL_DEBUG_ENTER;
465 #ifdef OHOS_BUILD_ENABLE_POINTER
466 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadMouseScrollRows, this, std::ref(rows)));
467 if (ret != RET_OK) {
468 MMI_HILOGE("Get the number of mouse scrolling rows failed, return %{public}d", ret);
469 return RET_ERR;
470 }
471 #endif // OHOS_BUILD_ENABLE_POINTER
472 return RET_OK;
473 }
474
SetPointerSize(int32_t size)475 int32_t MMIService::SetPointerSize(int32_t size)
476 {
477 CALL_DEBUG_ENTER;
478 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
479 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&IPointerDrawingManager::SetPointerSize,
480 IPointerDrawingManager::GetInstance(), size));
481 if (ret != RET_OK) {
482 MMI_HILOGE("Set pointer size failed,return %{public}d", ret);
483 return ret;
484 }
485 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
486 return RET_OK;
487 }
488
489 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
ReadPointerSize(int32_t & size)490 int32_t MMIService::ReadPointerSize(int32_t &size)
491 {
492 size = IPointerDrawingManager::GetInstance()->GetPointerSize();
493 return RET_OK;
494 }
495 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
496
GetPointerSize(int32_t & size)497 int32_t MMIService::GetPointerSize(int32_t &size)
498 {
499 CALL_DEBUG_ENTER;
500 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
501 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadPointerSize, this, std::ref(size)));
502 if (ret != RET_OK) {
503 MMI_HILOGE("Get pointer size failed, return %{public}d", ret);
504 return ret;
505 }
506 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
507 return RET_OK;
508 }
509
SetMousePrimaryButton(int32_t primaryButton)510 int32_t MMIService::SetMousePrimaryButton(int32_t primaryButton)
511 {
512 CALL_DEBUG_ENTER;
513 #if defined OHOS_BUILD_ENABLE_POINTER
514 int32_t ret = delegateTasks_.PostSyncTask(
515 std::bind(&MouseEventNormalize::SetMousePrimaryButton, MouseEventHdr, primaryButton));
516 if (ret != RET_OK) {
517 MMI_HILOGE("Set mouse primary button failed,return %{public}d", ret);
518 return ret;
519 }
520 #endif // OHOS_BUILD_ENABLE_POINTER
521 return RET_OK;
522 }
523
524 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadMousePrimaryButton(int32_t & primaryButton)525 int32_t MMIService::ReadMousePrimaryButton(int32_t &primaryButton)
526 {
527 primaryButton = MouseEventHdr->GetMousePrimaryButton();
528 return RET_OK;
529 }
530 #endif // OHOS_BUILD_ENABLE_POINTER
531
GetMousePrimaryButton(int32_t & primaryButton)532 int32_t MMIService::GetMousePrimaryButton(int32_t &primaryButton)
533 {
534 CALL_DEBUG_ENTER;
535 #ifdef OHOS_BUILD_ENABLE_POINTER
536 int32_t ret =
537 delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadMousePrimaryButton, this, std::ref(primaryButton)));
538 if (ret != RET_OK) {
539 MMI_HILOGE("Get mouse primary button failed,return %{public}d", ret);
540 return RET_ERR;
541 }
542 #endif // OHOS_BUILD_ENABLE_POINTER
543 return RET_OK;
544 }
545
SetPointerVisible(bool visible)546 int32_t MMIService::SetPointerVisible(bool visible)
547 {
548 CALL_DEBUG_ENTER;
549 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
550 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&IPointerDrawingManager::SetPointerVisible,
551 IPointerDrawingManager::GetInstance(), GetCallingPid(), visible));
552 if (ret != RET_OK) {
553 MMI_HILOGE("Set pointer visible failed,return %{public}d", ret);
554 return ret;
555 }
556 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
557 return RET_OK;
558 }
559
560 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
CheckPointerVisible(bool & visible)561 int32_t MMIService::CheckPointerVisible(bool &visible)
562 {
563 visible = IPointerDrawingManager::GetInstance()->IsPointerVisible();
564 return RET_OK;
565 }
566 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
567
IsPointerVisible(bool & visible)568 int32_t MMIService::IsPointerVisible(bool &visible)
569 {
570 CALL_DEBUG_ENTER;
571 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
572 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::CheckPointerVisible, this, std::ref(visible)));
573 if (ret != RET_OK) {
574 MMI_HILOGE("Is pointer visible failed,return %{public}d", ret);
575 return RET_ERR;
576 }
577 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
578 return RET_OK;
579 }
580
MarkProcessed(int32_t eventType,int32_t eventId)581 int32_t MMIService::MarkProcessed(int32_t eventType, int32_t eventId)
582 {
583 CALL_DEBUG_ENTER;
584 int32_t ret =
585 delegateTasks_.PostSyncTask(std::bind(&ANRManager::MarkProcessed, ANRMgr, GetCallingPid(), eventType, eventId));
586 if (ret != RET_OK) {
587 MMI_HILOGE("Mark event processed failed, ret:%{public}d", ret);
588 return RET_ERR;
589 }
590 return RET_OK;
591 }
592
SetPointerColor(int32_t color)593 int32_t MMIService::SetPointerColor(int32_t color)
594 {
595 CALL_DEBUG_ENTER;
596 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
597 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&IPointerDrawingManager::SetPointerColor,
598 IPointerDrawingManager::GetInstance(), color));
599 if (ret != RET_OK) {
600 MMI_HILOGE("Set pointer color failed,return %{public}d", ret);
601 return ret;
602 }
603 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
604 return RET_OK;
605 }
606
607 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
ReadPointerColor(int32_t & color)608 int32_t MMIService::ReadPointerColor(int32_t &color)
609 {
610 color = IPointerDrawingManager::GetInstance()->GetPointerColor();
611 return RET_OK;
612 }
613 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
614
GetPointerColor(int32_t & color)615 int32_t MMIService::GetPointerColor(int32_t &color)
616 {
617 CALL_DEBUG_ENTER;
618 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
619 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadPointerColor, this, std::ref(color)));
620 if (ret != RET_OK) {
621 MMI_HILOGE("Get pointer color failed, return %{public}d", ret);
622 return ret;
623 }
624 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
625 return RET_OK;
626 }
627
SetPointerSpeed(int32_t speed)628 int32_t MMIService::SetPointerSpeed(int32_t speed)
629 {
630 CALL_DEBUG_ENTER;
631 #ifdef OHOS_BUILD_ENABLE_POINTER
632 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetPointerSpeed, MouseEventHdr, speed));
633 if (ret != RET_OK) {
634 MMI_HILOGE("Set pointer speed failed,return %{public}d", ret);
635 return RET_ERR;
636 }
637 #endif // OHOS_BUILD_ENABLE_POINTER
638 return RET_OK;
639 }
640
641 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadPointerSpeed(int32_t & speed)642 int32_t MMIService::ReadPointerSpeed(int32_t &speed)
643 {
644 speed = MouseEventHdr->GetPointerSpeed();
645 return RET_OK;
646 }
647 #endif // OHOS_BUILD_ENABLE_POINTER
648
GetPointerSpeed(int32_t & speed)649 int32_t MMIService::GetPointerSpeed(int32_t &speed)
650 {
651 CALL_DEBUG_ENTER;
652 #ifdef OHOS_BUILD_ENABLE_POINTER
653 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadPointerSpeed, this, std::ref(speed)));
654 if (ret != RET_OK) {
655 MMI_HILOGE("Get pointer speed failed,return %{public}d", ret);
656 return RET_ERR;
657 }
658 #endif // OHOS_BUILD_ENABLE_POINTER
659 return RET_OK;
660 }
661
SetPointerStyle(int32_t windowId,PointerStyle pointerStyle)662 int32_t MMIService::SetPointerStyle(int32_t windowId, PointerStyle pointerStyle)
663 {
664 CALL_DEBUG_ENTER;
665 #ifdef OHOS_BUILD_ENABLE_POINTER
666 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&IPointerDrawingManager::SetPointerStyle,
667 IPointerDrawingManager::GetInstance(), GetCallingPid(), windowId, pointerStyle));
668 if (ret != RET_OK) {
669 MMI_HILOGE("Set pointer style failed,return %{public}d", ret);
670 return ret;
671 }
672 #endif // OHOS_BUILD_ENABLE_POINTER
673 return RET_OK;
674 }
675
GetPointerStyle(int32_t windowId,PointerStyle & pointerStyle)676 int32_t MMIService::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle)
677 {
678 CALL_DEBUG_ENTER;
679 #ifdef OHOS_BUILD_ENABLE_POINTER
680 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&IPointerDrawingManager::GetPointerStyle,
681 IPointerDrawingManager::GetInstance(), GetCallingPid(), windowId, std::ref(pointerStyle)));
682 if (ret != RET_OK) {
683 MMI_HILOGE("Get pointer style failed,return %{public}d", ret);
684 return ret;
685 }
686 #endif // OHOS_BUILD_ENABLE_POINTER
687 return RET_OK;
688 }
689
SetHoverScrollState(bool state)690 int32_t MMIService::SetHoverScrollState(bool state)
691 {
692 CALL_DEBUG_ENTER;
693 #if defined OHOS_BUILD_ENABLE_POINTER
694 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&InputWindowsManager::SetHoverScrollState, WinMgr, state));
695 if (ret != RET_OK) {
696 MMI_HILOGE("Set mouse hover scroll state failed,return %{public}d", ret);
697 return ret;
698 }
699 #endif // OHOS_BUILD_ENABLE_POINTER
700 return RET_OK;
701 }
702
703 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadHoverScrollState(bool & state)704 int32_t MMIService::ReadHoverScrollState(bool &state)
705 {
706 state = WinMgr->GetHoverScrollState();
707 return RET_OK;
708 }
709 #endif // OHOS_BUILD_ENABLE_POINTER
710
GetHoverScrollState(bool & state)711 int32_t MMIService::GetHoverScrollState(bool &state)
712 {
713 CALL_DEBUG_ENTER;
714 #ifdef OHOS_BUILD_ENABLE_POINTER
715 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadHoverScrollState, this, std::ref(state)));
716 if (ret != RET_OK) {
717 MMI_HILOGE("Get mouse hover scroll state, return %{public}d", ret);
718 return ret;
719 }
720 #endif // OHOS_BUILD_ENABLE_POINTER
721 return RET_OK;
722 }
723
OnSupportKeys(int32_t deviceId,std::vector<int32_t> & keys,std::vector<bool> & keystroke)724 int32_t MMIService::OnSupportKeys(int32_t deviceId, std::vector<int32_t> &keys, std::vector<bool> &keystroke)
725 {
726 CALL_DEBUG_ENTER;
727 int32_t ret = InputDevMgr->SupportKeys(deviceId, keys, keystroke);
728 if (keystroke.size() > MAX_SUPPORT_KEY) {
729 MMI_HILOGE("Device exceeds the max range");
730 return RET_ERR;
731 }
732 if (ret != RET_OK) {
733 MMI_HILOGE("Device id not support");
734 return ret;
735 }
736 return RET_OK;
737 }
738
SupportKeys(int32_t deviceId,std::vector<int32_t> & keys,std::vector<bool> & keystroke)739 int32_t MMIService::SupportKeys(int32_t deviceId, std::vector<int32_t> &keys, std::vector<bool> &keystroke)
740 {
741 CALL_DEBUG_ENTER;
742 int32_t ret =
743 delegateTasks_.PostSyncTask(std::bind(&MMIService::OnSupportKeys, this, deviceId, keys, std::ref(keystroke)));
744 if (ret != RET_OK) {
745 MMI_HILOGE("Support keys info process failed, ret:%{public}d", ret);
746 return ret;
747 }
748 return RET_OK;
749 }
750
OnGetDeviceIds(std::vector<int32_t> & ids)751 int32_t MMIService::OnGetDeviceIds(std::vector<int32_t> &ids)
752 {
753 CALL_DEBUG_ENTER;
754 ids = InputDevMgr->GetInputDeviceIds();
755 return RET_OK;
756 }
757
GetDeviceIds(std::vector<int32_t> & ids)758 int32_t MMIService::GetDeviceIds(std::vector<int32_t> &ids)
759 {
760 CALL_DEBUG_ENTER;
761 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetDeviceIds, this, std::ref(ids)));
762 if (ret != RET_OK) {
763 MMI_HILOGE("Get deviceids failed, ret:%{public}d", ret);
764 return RET_ERR;
765 }
766 return RET_OK;
767 }
768
OnGetDevice(int32_t deviceId,std::shared_ptr<InputDevice> & inputDevice)769 int32_t MMIService::OnGetDevice(int32_t deviceId, std::shared_ptr<InputDevice> &inputDevice)
770 {
771 CALL_DEBUG_ENTER;
772 if (InputDevMgr->GetInputDevice(deviceId) == nullptr) {
773 MMI_HILOGE("Input device not found");
774 return COMMON_PARAMETER_ERROR;
775 }
776 inputDevice = InputDevMgr->GetInputDevice(deviceId);
777 return RET_OK;
778 }
779
GetDevice(int32_t deviceId,std::shared_ptr<InputDevice> & inputDevice)780 int32_t MMIService::GetDevice(int32_t deviceId, std::shared_ptr<InputDevice> &inputDevice)
781 {
782 CALL_DEBUG_ENTER;
783 int32_t ret =
784 delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetDevice, this, deviceId, std::ref(inputDevice)));
785 if (ret != RET_OK) {
786 MMI_HILOGE("Get input device info failed, ret:%{public}d", ret);
787 return ret;
788 }
789 return RET_OK;
790 }
791
OnRegisterDevListener(int32_t pid)792 int32_t MMIService::OnRegisterDevListener(int32_t pid)
793 {
794 auto sess = GetSession(GetClientFd(pid));
795 CHKPR(sess, RET_ERR);
796 InputDevMgr->AddDevListener(sess, [sess](int32_t id, const std::string &type) {
797 CALL_DEBUG_ENTER;
798 CHKPV(sess);
799 NetPacket pkt(MmiMessageId::ADD_INPUT_DEVICE_LISTENER);
800 pkt << type << id;
801 if (pkt.ChkRWError()) {
802 MMI_HILOGE("Packet write data failed");
803 return;
804 }
805 if (!sess->SendMsg(pkt)) {
806 MMI_HILOGE("Sending failed");
807 return;
808 }
809 });
810 return RET_OK;
811 }
812
RegisterDevListener()813 int32_t MMIService::RegisterDevListener()
814 {
815 CALL_DEBUG_ENTER;
816 int32_t pid = GetCallingPid();
817 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnRegisterDevListener, this, pid));
818 if (ret != RET_OK) {
819 MMI_HILOGE("Register device listener failed, ret:%{public}d", ret);
820 return RET_ERR;
821 }
822 return RET_OK;
823 }
824
OnUnregisterDevListener(int32_t pid)825 int32_t MMIService::OnUnregisterDevListener(int32_t pid)
826 {
827 auto sess = GetSession(GetClientFd(pid));
828 InputDevMgr->RemoveDevListener(sess);
829 return RET_OK;
830 }
831
UnregisterDevListener()832 int32_t MMIService::UnregisterDevListener()
833 {
834 CALL_DEBUG_ENTER;
835 int32_t pid = GetCallingPid();
836 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnUnregisterDevListener, this, pid));
837 if (ret != RET_OK) {
838 MMI_HILOGE("Unregister device listener failed failed, ret:%{public}d", ret);
839 return RET_ERR;
840 }
841 return RET_OK;
842 }
843
OnGetKeyboardType(int32_t deviceId,int32_t & keyboardType)844 int32_t MMIService::OnGetKeyboardType(int32_t deviceId, int32_t &keyboardType)
845 {
846 int32_t ret = InputDevMgr->GetKeyboardType(deviceId, keyboardType);
847 if (ret != RET_OK) {
848 MMI_HILOGE("GetKeyboardType call failed");
849 return ret;
850 }
851 return RET_OK;
852 }
853
GetKeyboardType(int32_t deviceId,int32_t & keyboardType)854 int32_t MMIService::GetKeyboardType(int32_t deviceId, int32_t &keyboardType)
855 {
856 CALL_DEBUG_ENTER;
857 int32_t ret =
858 delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetKeyboardType, this, deviceId, std::ref(keyboardType)));
859 if (ret != RET_OK) {
860 MMI_HILOGE("Get keyboard type failed, ret:%{public}d", ret);
861 return ret;
862 }
863 return ret;
864 }
865
SetKeyboardRepeatDelay(int32_t delay)866 int32_t MMIService::SetKeyboardRepeatDelay(int32_t delay)
867 {
868 CALL_DEBUG_ENTER;
869 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
870 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&KeyAutoRepeat::SetKeyboardRepeatDelay, KeyRepeat, delay));
871 if (ret != RET_OK) {
872 MMI_HILOGE("Set keyboard repeat delay failed, ret:%{public}d", ret);
873 return ret;
874 }
875 #endif // OHOS_BUILD_ENABLE_KEYBOARD
876 return RET_OK;
877 }
878
SetKeyboardRepeatRate(int32_t rate)879 int32_t MMIService::SetKeyboardRepeatRate(int32_t rate)
880 {
881 CALL_DEBUG_ENTER;
882 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
883 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&KeyAutoRepeat::SetKeyboardRepeatRate, KeyRepeat, rate));
884 if (ret != RET_OK) {
885 MMI_HILOGE("Set keyboard repeat rate failed, ret:%{public}d", ret);
886 return ret;
887 }
888 #endif // OHOS_BUILD_ENABLE_KEYBOARD
889 return RET_OK;
890 }
891
GetKeyboardRepeatDelay(int32_t & delay)892 int32_t MMIService::GetKeyboardRepeatDelay(int32_t &delay)
893 {
894 CALL_DEBUG_ENTER;
895 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
896 int32_t ret =
897 delegateTasks_.PostSyncTask(std::bind(&KeyAutoRepeat::GetKeyboardRepeatDelay, KeyRepeat, std::ref(delay)));
898 if (ret != RET_OK) {
899 MMI_HILOGE("Get keyboard repeat delay failed, ret:%{public}d", ret);
900 return ret;
901 }
902 #endif // OHOS_BUILD_ENABLE_KEYBOARD
903 return RET_OK;
904 }
905
GetKeyboardRepeatRate(int32_t & rate)906 int32_t MMIService::GetKeyboardRepeatRate(int32_t &rate)
907 {
908 CALL_DEBUG_ENTER;
909 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
910 int32_t ret =
911 delegateTasks_.PostSyncTask(std::bind(&KeyAutoRepeat::GetKeyboardRepeatRate, KeyRepeat, std::ref(rate)));
912 if (ret != RET_OK) {
913 MMI_HILOGE("Get keyboard repeat rate failed, ret:%{public}d", ret);
914 return ret;
915 }
916 #endif // OHOS_BUILD_ENABLE_KEYBOARD
917 return RET_OK;
918 }
919
920 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
CheckAddInput(int32_t pid,InputHandlerType handlerType,HandleEventType eventType,int32_t priority,uint32_t deviceTags)921 int32_t MMIService::CheckAddInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType,
922 int32_t priority, uint32_t deviceTags)
923 {
924 auto sess = GetSessionByPid(pid);
925 CHKPR(sess, ERROR_NULL_POINTER);
926 return sMsgHandler_.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
927 }
928 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
929
AddInputHandler(InputHandlerType handlerType,HandleEventType eventType,int32_t priority,uint32_t deviceTags)930 int32_t MMIService::AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority,
931 uint32_t deviceTags)
932 {
933 CALL_INFO_TRACE;
934 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
935 int32_t pid = GetCallingPid();
936 int32_t ret = delegateTasks_.PostSyncTask(
937 std::bind(&MMIService::CheckAddInput, this, pid, handlerType, eventType, priority, deviceTags));
938 if (ret != RET_OK) {
939 MMI_HILOGE("Add input handler failed, ret:%{public}d", ret);
940 return RET_ERR;
941 }
942 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
943 return RET_OK;
944 }
945
946 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
CheckRemoveInput(int32_t pid,InputHandlerType handlerType,HandleEventType eventType,int32_t priority,uint32_t deviceTags)947 int32_t MMIService::CheckRemoveInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType,
948 int32_t priority, uint32_t deviceTags)
949 {
950 auto sess = GetSessionByPid(pid);
951 CHKPR(sess, ERROR_NULL_POINTER);
952 return sMsgHandler_.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
953 }
954 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
955
RemoveInputHandler(InputHandlerType handlerType,HandleEventType eventType,int32_t priority,uint32_t deviceTags)956 int32_t MMIService::RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority,
957 uint32_t deviceTags)
958 {
959 CALL_INFO_TRACE;
960 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
961 int32_t pid = GetCallingPid();
962 int32_t ret = delegateTasks_.PostSyncTask(
963 std::bind(&MMIService::CheckRemoveInput, this, pid, handlerType, eventType, priority, deviceTags));
964 if (ret != RET_OK) {
965 MMI_HILOGE("Remove input handler failed, ret:%{public}d", ret);
966 return RET_ERR;
967 }
968 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
969 return RET_OK;
970 }
971
972 #ifdef OHOS_BUILD_ENABLE_MONITOR
CheckMarkConsumed(int32_t pid,int32_t eventId)973 int32_t MMIService::CheckMarkConsumed(int32_t pid, int32_t eventId)
974 {
975 auto sess = GetSessionByPid(pid);
976 CHKPR(sess, ERROR_NULL_POINTER);
977 return sMsgHandler_.OnMarkConsumed(sess, eventId);
978 }
979 #endif // OHOS_BUILD_ENABLE_MONITOR
980
MarkEventConsumed(int32_t eventId)981 int32_t MMIService::MarkEventConsumed(int32_t eventId)
982 {
983 CALL_DEBUG_ENTER;
984 #ifdef OHOS_BUILD_ENABLE_MONITOR
985 int32_t pid = GetCallingPid();
986 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::CheckMarkConsumed, this, pid, eventId));
987 if (ret != RET_OK) {
988 MMI_HILOGE("Mark event consumed failed, ret:%{public}d", ret);
989 return RET_ERR;
990 }
991 #endif // OHOS_BUILD_ENABLE_MONITOR
992 return RET_OK;
993 }
994
MoveMouseEvent(int32_t offsetX,int32_t offsetY)995 int32_t MMIService::MoveMouseEvent(int32_t offsetX, int32_t offsetY)
996 {
997 CALL_DEBUG_ENTER;
998 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
999 int32_t ret =
1000 delegateTasks_.PostSyncTask(std::bind(&ServerMsgHandler::OnMoveMouse, &sMsgHandler_, offsetX, offsetY));
1001 if (ret != RET_OK) {
1002 MMI_HILOGE("The movemouse event processed failed, ret:%{public}d", ret);
1003 return RET_ERR;
1004 }
1005 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1006 return RET_OK;
1007 }
1008
InjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)1009 int32_t MMIService::InjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)
1010 {
1011 CALL_DEBUG_ENTER;
1012 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1013 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::CheckInjectKeyEvent, this, keyEvent));
1014 if (ret != RET_OK) {
1015 MMI_HILOGE("Inject key event failed, ret:%{public}d", ret);
1016 return RET_ERR;
1017 }
1018 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1019 return RET_OK;
1020 }
1021
1022 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
CheckInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)1023 int32_t MMIService::CheckInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent)
1024 {
1025 CHKPR(keyEvent, ERROR_NULL_POINTER);
1026 return sMsgHandler_.OnInjectKeyEvent(keyEvent);
1027 }
1028 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1029
1030 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
CheckInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)1031 int32_t MMIService::CheckInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)
1032 {
1033 CHKPR(pointerEvent, ERROR_NULL_POINTER);
1034 return sMsgHandler_.OnInjectPointerEvent(pointerEvent);
1035 }
1036 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
1037
InjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)1038 int32_t MMIService::InjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent)
1039 {
1040 CALL_DEBUG_ENTER;
1041 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
1042 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::CheckInjectPointerEvent, this, pointerEvent));
1043 if (ret != RET_OK) {
1044 MMI_HILOGE("Inject pointer event failed, ret:%{public}d", ret);
1045 return RET_ERR;
1046 }
1047 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
1048 return RET_OK;
1049 }
1050
1051 #ifdef OHOS_RSS_CLIENT
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1052 void MMIService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
1053 {
1054 CALL_INFO_TRACE;
1055 if (systemAbilityId == RES_SCHED_SYS_ABILITY_ID) {
1056 int sleepSeconds = 1;
1057 sleep(sleepSeconds);
1058 uint64_t tid = tid_.load();
1059 std::unordered_map<std::string, std::string> payload;
1060 payload["uid"] = std::to_string(getuid());
1061 payload["pid"] = std::to_string(getpid());
1062 ResourceSchedule::ResSchedClient::GetInstance().ReportData(
1063 ResourceSchedule::ResType::RES_TYPE_REPORT_MMI_PROCESS, tid, payload);
1064 }
1065 }
1066 #endif
1067
SubscribeKeyEvent(int32_t subscribeId,const std::shared_ptr<KeyOption> option)1068 int32_t MMIService::SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr<KeyOption> option)
1069 {
1070 CALL_DEBUG_ENTER;
1071 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1072 int32_t pid = GetCallingPid();
1073 int32_t ret = delegateTasks_.PostSyncTask(
1074 std::bind(&ServerMsgHandler::OnSubscribeKeyEvent, &sMsgHandler_, this, pid, subscribeId, option));
1075 if (ret != RET_OK) {
1076 MMI_HILOGE("The subscribe key event processed failed, ret:%{public}d", ret);
1077 return RET_ERR;
1078 }
1079 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1080 return RET_OK;
1081 }
1082
UnsubscribeKeyEvent(int32_t subscribeId)1083 int32_t MMIService::UnsubscribeKeyEvent(int32_t subscribeId)
1084 {
1085 CALL_INFO_TRACE;
1086 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1087 int32_t pid = GetCallingPid();
1088 int32_t ret = delegateTasks_.PostSyncTask(
1089 std::bind(&ServerMsgHandler::OnUnsubscribeKeyEvent, &sMsgHandler_, this, pid, subscribeId));
1090 if (ret != RET_OK) {
1091 MMI_HILOGE("The unsubscribe key event processed failed, ret:%{public}d", ret);
1092 return RET_ERR;
1093 }
1094 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1095 return RET_OK;
1096 }
1097
SubscribeSwitchEvent(int32_t subscribeId)1098 int32_t MMIService::SubscribeSwitchEvent(int32_t subscribeId)
1099 {
1100 CALL_INFO_TRACE;
1101 #ifdef OHOS_BUILD_ENABLE_SWITCH
1102 int32_t pid = GetCallingPid();
1103 int32_t ret = delegateTasks_.PostSyncTask(
1104 std::bind(&ServerMsgHandler::OnSubscribeSwitchEvent, &sMsgHandler_, this, pid, subscribeId));
1105 if (ret != RET_OK) {
1106 MMI_HILOGE("The subscribe switch event processed failed, ret:%{public}d", ret);
1107 return RET_ERR;
1108 }
1109 #endif // OHOS_BUILD_ENABLE_SWITCH
1110 return RET_OK;
1111 }
1112
UnsubscribeSwitchEvent(int32_t subscribeId)1113 int32_t MMIService::UnsubscribeSwitchEvent(int32_t subscribeId)
1114 {
1115 CALL_INFO_TRACE;
1116 #ifdef OHOS_BUILD_ENABLE_SWITCH
1117 int32_t pid = GetCallingPid();
1118 int32_t ret = delegateTasks_.PostSyncTask(
1119 std::bind(&ServerMsgHandler::OnUnsubscribeSwitchEvent, &sMsgHandler_, this, pid, subscribeId));
1120 if (ret != RET_OK) {
1121 MMI_HILOGE("The unsubscribe switch event processed failed, ret:%{public}d", ret);
1122 return RET_ERR;
1123 }
1124 #endif // OHOS_BUILD_ENABLE_SWITCH
1125 return RET_OK;
1126 }
1127
SetAnrObserver()1128 int32_t MMIService::SetAnrObserver()
1129 {
1130 CALL_DEBUG_ENTER;
1131 int32_t pid = GetCallingPid();
1132 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&ANRManager::SetANRNoticedPid, ANRMgr, pid));
1133 if (ret != RET_OK) {
1134 MMI_HILOGE("Set ANRNoticed pid failed, ret:%{public}d", ret);
1135 return RET_ERR;
1136 }
1137 return RET_OK;
1138 }
1139
GetDisplayBindInfo(DisplayBindInfos & infos)1140 int32_t MMIService::GetDisplayBindInfo(DisplayBindInfos &infos)
1141 {
1142 CALL_DEBUG_ENTER;
1143 int32_t ret =
1144 delegateTasks_.PostSyncTask(std::bind(&InputWindowsManager::GetDisplayBindInfo, WinMgr, std::ref(infos)));
1145 if (ret != RET_OK) {
1146 MMI_HILOGE("GetDisplayBindInfo pid failed, ret:%{public}d", ret);
1147 return RET_ERR;
1148 }
1149 return RET_OK;
1150 }
1151
SetDisplayBind(int32_t deviceId,int32_t displayId,std::string & msg)1152 int32_t MMIService::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg)
1153 {
1154 CALL_DEBUG_ENTER;
1155 int32_t ret = delegateTasks_.PostSyncTask(
1156 std::bind(&InputWindowsManager::SetDisplayBind, WinMgr, deviceId, displayId, std::ref(msg)));
1157 if (ret != RET_OK) {
1158 MMI_HILOGE("SetDisplayBind pid failed, ret:%{public}d", ret);
1159 return RET_ERR;
1160 }
1161 return RET_OK;
1162 }
1163
GetFunctionKeyState(int32_t funcKey,bool & state)1164 int32_t MMIService::GetFunctionKeyState(int32_t funcKey, bool &state)
1165 {
1166 CALL_INFO_TRACE;
1167 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1168 int32_t ret = delegateTasks_.PostSyncTask(
1169 std::bind(&ServerMsgHandler::OnGetFunctionKeyState, &sMsgHandler_, funcKey, std::ref(state)));
1170 if (ret != RET_OK) {
1171 MMI_HILOGE("Failed to get the keyboard status, ret:%{public}d", ret);
1172 return RET_ERR;
1173 }
1174 #else
1175 MMI_HILOGD("Function not supported");
1176 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1177 return RET_OK;
1178 }
1179
SetFunctionKeyState(int32_t funcKey,bool enable)1180 int32_t MMIService::SetFunctionKeyState(int32_t funcKey, bool enable)
1181 {
1182 CALL_INFO_TRACE;
1183 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1184 int32_t ret = delegateTasks_.PostSyncTask(
1185 std::bind(&ServerMsgHandler::OnSetFunctionKeyState, &sMsgHandler_, funcKey, enable));
1186 if (ret != RET_OK) {
1187 MMI_HILOGE("Failed to update the keyboard status, ret:%{public}d", ret);
1188 return RET_ERR;
1189 }
1190 #else
1191 MMI_HILOGD("Function not supported");
1192 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1193 return RET_OK;
1194 }
1195
SetPointerLocation(int32_t x,int32_t y)1196 int32_t MMIService::SetPointerLocation(int32_t x, int32_t y)
1197 {
1198 CALL_DEBUG_ENTER;
1199 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1200 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetPointerLocation, MouseEventHdr, x, y));
1201 if (ret != RET_OK) {
1202 MMI_HILOGE("Set pointer location failed,ret %{public}d", ret);
1203 return RET_ERR;
1204 }
1205 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1206 return RET_OK;
1207 }
OnDelegateTask(epoll_event & ev)1208 void MMIService::OnDelegateTask(epoll_event &ev)
1209 {
1210 if ((ev.events & EPOLLIN) == 0) {
1211 MMI_HILOGW("Not epollin");
1212 return;
1213 }
1214 DelegateTasks::TaskData data = {};
1215 auto res = read(delegateTasks_.GetReadFd(), &data, sizeof(data));
1216 if (res == -1) {
1217 MMI_HILOGW("Read failed erron:%{public}d", errno);
1218 }
1219 MMI_HILOGD("RemoteRequest notify td:%{public}" PRId64 ",std:%{public}" PRId64 ""
1220 ",taskId:%{public}d",
1221 GetThisThreadId(), data.tid, data.taskId);
1222 delegateTasks_.ProcessTasks();
1223 }
1224
OnThread()1225 void MMIService::OnThread()
1226 {
1227 SetThreadName(std::string("mmi_service"));
1228 uint64_t tid = GetThisThreadId();
1229 delegateTasks_.SetWorkerThreadId(tid);
1230 MMI_HILOGI("Main worker thread start. tid:%{public}" PRId64 "", tid);
1231 #ifdef OHOS_RSS_CLIENT
1232 tid_.store(tid);
1233 #endif
1234 libinputAdapter_.ProcessPendingEvents();
1235 while (state_ == ServiceRunningState::STATE_RUNNING) {
1236 epoll_event ev[MAX_EVENT_SIZE] = {};
1237 int32_t timeout = TimerMgr->CalcNextDelay();
1238 MMI_HILOGD("timeout:%{public}d", timeout);
1239 int32_t count = EpollWait(ev[0], MAX_EVENT_SIZE, timeout, mmiFd_);
1240 for (int32_t i = 0; i < count && state_ == ServiceRunningState::STATE_RUNNING; i++) {
1241 auto mmiEd = reinterpret_cast<mmi_epoll_event *>(ev[i].data.ptr);
1242 CHKPC(mmiEd);
1243 if (mmiEd->event_type == EPOLL_EVENT_INPUT) {
1244 libinputAdapter_.EventDispatch(mmiEd->fd);
1245 } else if (mmiEd->event_type == EPOLL_EVENT_SOCKET) {
1246 OnEpollEvent(ev[i]);
1247 } else if (mmiEd->event_type == EPOLL_EVENT_SIGNAL) {
1248 OnSignalEvent(mmiEd->fd);
1249 } else if (mmiEd->event_type == EPOLL_EVENT_ETASK) {
1250 OnDelegateTask(ev[i]);
1251 } else {
1252 MMI_HILOGW("Unknown epoll event type:%{public}d", mmiEd->event_type);
1253 }
1254 }
1255 TimerMgr->ProcessTimers();
1256 if (state_ != ServiceRunningState::STATE_RUNNING) {
1257 break;
1258 }
1259 }
1260 MMI_HILOGI("Main worker thread stop. tid:%{public}" PRId64 "", tid);
1261 }
1262
InitSignalHandler()1263 bool MMIService::InitSignalHandler()
1264 {
1265 CALL_DEBUG_ENTER;
1266 sigset_t mask = { 0 };
1267 int32_t retCode = sigfillset(&mask);
1268 if (retCode < 0) {
1269 MMI_HILOGE("Fill signal set failed:%{public}d", errno);
1270 return false;
1271 }
1272
1273 retCode = sigprocmask(SIG_SETMASK, &mask, nullptr);
1274 if (retCode < 0) {
1275 MMI_HILOGE("Sigprocmask failed:%{public}d", errno);
1276 return false;
1277 }
1278
1279 int32_t fdSignal = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
1280 if (fdSignal < 0) {
1281 MMI_HILOGE("Signal fd failed:%{public}d", errno);
1282 return false;
1283 }
1284
1285 retCode = AddEpoll(EPOLL_EVENT_SIGNAL, fdSignal);
1286 if (retCode < 0) {
1287 MMI_HILOGE("AddEpoll signalFd failed:%{public}d", retCode);
1288 close(fdSignal);
1289 return false;
1290 }
1291 return true;
1292 }
1293
OnSignalEvent(int32_t signalFd)1294 void MMIService::OnSignalEvent(int32_t signalFd)
1295 {
1296 CALL_DEBUG_ENTER;
1297 signalfd_siginfo sigInfo;
1298 int32_t size = ::read(signalFd, &sigInfo, sizeof(signalfd_siginfo));
1299 if (size != static_cast<int32_t>(sizeof(signalfd_siginfo))) {
1300 MMI_HILOGE("Read signal info failed, invalid size:%{public}d,errno:%{public}d", size, errno);
1301 return;
1302 }
1303 int32_t signo = static_cast<int32_t>(sigInfo.ssi_signo);
1304 MMI_HILOGD("Receive signal:%{public}d", signo);
1305 switch (signo) {
1306 case SIGINT:
1307 case SIGQUIT:
1308 case SIGILL:
1309 case SIGABRT:
1310 case SIGBUS:
1311 case SIGFPE:
1312 case SIGKILL:
1313 case SIGSEGV:
1314 case SIGTERM: {
1315 state_ = ServiceRunningState::STATE_EXIT;
1316 break;
1317 }
1318 default: {
1319 break;
1320 }
1321 }
1322 }
1323
AddReloadDeviceTimer()1324 void MMIService::AddReloadDeviceTimer()
1325 {
1326 CALL_DEBUG_ENTER;
1327 TimerMgr->AddTimer(2000, 2, [this]() {
1328 auto deviceIds = InputDevMgr->GetInputDeviceIds();
1329 if (deviceIds.empty()) {
1330 libinputAdapter_.ReloadDevice();
1331 }
1332 });
1333 }
1334
Dump(int32_t fd,const std::vector<std::u16string> & args)1335 int32_t MMIService::Dump(int32_t fd, const std::vector<std::u16string> &args)
1336 {
1337 CALL_DEBUG_ENTER;
1338 if (fd < 0) {
1339 MMI_HILOGE("The fd is invalid");
1340 return DUMP_PARAM_ERR;
1341 }
1342 if (args.empty()) {
1343 MMI_HILOGE("The args cannot be empty");
1344 mprintf(fd, "args cannot be empty\n");
1345 MMIEventDump->DumpHelp(fd);
1346 return DUMP_PARAM_ERR;
1347 }
1348 std::vector<std::string> argList = { "" };
1349 std::transform(args.begin(), args.end(), std::back_inserter(argList),
1350 [](const std::u16string &arg) { return Str16ToStr8(arg); });
1351 MMIEventDump->ParseCommand(fd, argList);
1352 return RET_OK;
1353 }
1354
SetMouseCaptureMode(int32_t windowId,bool isCaptureMode)1355 int32_t MMIService::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode)
1356 {
1357 CALL_DEBUG_ENTER;
1358 int32_t ret = delegateTasks_.PostSyncTask(
1359 std::bind(&InputWindowsManager::SetMouseCaptureMode, WinMgr, windowId, isCaptureMode));
1360 if (ret != RET_OK) {
1361 MMI_HILOGE("Set capture failed,return %{public}d", ret);
1362 return RET_ERR;
1363 }
1364 return RET_OK;
1365 }
1366
OnGetWindowPid(int32_t windowId,int32_t & windowPid)1367 int32_t MMIService::OnGetWindowPid(int32_t windowId, int32_t &windowPid)
1368 {
1369 CALL_DEBUG_ENTER;
1370 windowPid = WinMgr->GetWindowPid(windowId);
1371 if (windowPid == RET_ERR) {
1372 MMI_HILOGE("Get window pid failed");
1373 }
1374 MMI_HILOGD("windowpid is %{public}d", windowPid);
1375 return RET_OK;
1376 }
1377
GetWindowPid(int32_t windowId)1378 int32_t MMIService::GetWindowPid(int32_t windowId)
1379 {
1380 CALL_DEBUG_ENTER;
1381 int32_t windowPid = -1;
1382 int32_t ret =
1383 delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetWindowPid, this, windowId, std::ref(windowPid)));
1384 if (ret != RET_OK) {
1385 MMI_HILOGE("OnGetWindowPid failed, ret:%{public}d", ret);
1386 return RET_ERR;
1387 }
1388 MMI_HILOGD("windowpid is %{public}d", windowPid);
1389 return windowPid;
1390 }
1391
AppendExtraData(const ExtraData & extraData)1392 int32_t MMIService::AppendExtraData(const ExtraData &extraData)
1393 {
1394 CALL_DEBUG_ENTER;
1395 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&InputWindowsManager::AppendExtraData, WinMgr, extraData));
1396 if (ret != RET_OK) {
1397 MMI_HILOGE("Append extra data failed:%{public}d", ret);
1398 }
1399 return ret;
1400 }
1401
EnableInputDevice(bool enable)1402 int32_t MMIService::EnableInputDevice(bool enable)
1403 {
1404 CALL_DEBUG_ENTER;
1405 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&InputDeviceManager::OnEnableInputDevice, InputDevMgr, enable));
1406 if (ret != RET_OK) {
1407 MMI_HILOGE("OnEnableInputDevice failed:%{public}d", ret);
1408 }
1409 return ret;
1410 }
1411
UpdateSettingsXml(const std::string & businessId,int32_t delay)1412 int32_t MMIService::UpdateSettingsXml(const std::string &businessId, int32_t delay)
1413 {
1414 std::shared_ptr<KeyCommandHandler> eventKeyCommandHandler = InputHandler->GetKeyCommandHandler();
1415 CHKPR(eventKeyCommandHandler, RET_ERR);
1416 return eventKeyCommandHandler->UpdateSettingsXml(businessId, delay);
1417 }
1418
SetKeyDownDuration(const std::string & businessId,int32_t delay)1419 int32_t MMIService::SetKeyDownDuration(const std::string &businessId, int32_t delay)
1420 {
1421 CALL_DEBUG_ENTER;
1422 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::UpdateSettingsXml, this, businessId, delay));
1423 if (ret != RET_OK) {
1424 MMI_HILOGE("Set key down duration failed: %{public}d", ret);
1425 return ret;
1426 }
1427 return RET_OK;
1428 }
1429
1430 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadTouchpadScrollSwich(bool & switchFlag)1431 int32_t MMIService::ReadTouchpadScrollSwich(bool &switchFlag)
1432 {
1433 MouseEventHdr->GetTouchpadScrollSwitch(switchFlag);
1434 return RET_OK;
1435 }
1436
ReadTouchpadScrollDirection(bool & switchFlag)1437 int32_t MMIService::ReadTouchpadScrollDirection(bool &switchFlag)
1438 {
1439 MouseEventHdr->GetTouchpadScrollDirection(switchFlag);
1440 return RET_OK;
1441 }
1442
ReadTouchpadTapSwitch(bool & switchFlag)1443 int32_t MMIService::ReadTouchpadTapSwitch(bool &switchFlag)
1444 {
1445 MouseEventHdr->GetTouchpadTapSwitch(switchFlag);
1446 return RET_OK;
1447 }
1448
ReadTouchpadPointerSpeed(int32_t & speed)1449 int32_t MMIService::ReadTouchpadPointerSpeed(int32_t &speed)
1450 {
1451 MouseEventHdr->GetTouchpadPointerSpeed(speed);
1452 return RET_OK;
1453 }
1454
ReadTouchpadPinchSwitch(bool & switchFlag)1455 int32_t MMIService::ReadTouchpadPinchSwitch(bool &switchFlag)
1456 {
1457 TouchEventHdr->GetTouchpadPinchSwitch(switchFlag);
1458 return RET_OK;
1459 }
1460
ReadTouchpadSwipeSwitch(bool & switchFlag)1461 int32_t MMIService::ReadTouchpadSwipeSwitch(bool &switchFlag)
1462 {
1463 TouchEventHdr->GetTouchpadSwipeSwitch(switchFlag);
1464 return RET_OK;
1465 }
1466
ReadTouchpadRightMenuType(int32_t & type)1467 int32_t MMIService::ReadTouchpadRightMenuType(int32_t &type)
1468 {
1469 MouseEventHdr->GetTouchpadRightClickType(type);
1470 return RET_OK;
1471 }
1472
1473 #endif // OHOS_BUILD_ENABLE_POINTER
1474
SetTouchpadScrollSwitch(bool switchFlag)1475 int32_t MMIService::SetTouchpadScrollSwitch(bool switchFlag)
1476 {
1477 CALL_DEBUG_ENTER;
1478 #if defined OHOS_BUILD_ENABLE_POINTER
1479 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetTouchpadScrollSwitch,
1480 MouseEventHdr, switchFlag));
1481 if (ret != RET_OK) {
1482 MMI_HILOGE("Set touchpad scroll switch failed, return %{public}d", ret);
1483 return ret;
1484 }
1485 #endif // OHOS_BUILD_ENABLE_POINTER
1486 return RET_OK;
1487 }
1488
GetTouchpadScrollSwitch(bool & switchFlag)1489 int32_t MMIService::GetTouchpadScrollSwitch(bool &switchFlag)
1490 {
1491 CALL_DEBUG_ENTER;
1492 #ifdef OHOS_BUILD_ENABLE_POINTER
1493 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadTouchpadScrollSwich, this,
1494 std::ref(switchFlag)));
1495 if (ret != RET_OK) {
1496 MMI_HILOGE("Get touchpad scroll switch failed, return %{public}d", ret);
1497 return RET_ERR;
1498 }
1499 #endif // OHOS_BUILD_ENABLE_POINTER
1500 return RET_OK;
1501 }
1502
SetTouchpadScrollDirection(bool state)1503 int32_t MMIService::SetTouchpadScrollDirection(bool state)
1504 {
1505 CALL_DEBUG_ENTER;
1506 #if defined OHOS_BUILD_ENABLE_POINTER
1507 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetTouchpadScrollDirection,
1508 MouseEventHdr, state));
1509 if (ret != RET_OK) {
1510 MMI_HILOGE("Set touchpad scroll direction switch failed, return %{public}d", ret);
1511 return ret;
1512 }
1513 #endif // OHOS_BUILD_ENABLE_POINTER
1514 return RET_OK;
1515 }
1516
GetTouchpadScrollDirection(bool & state)1517 int32_t MMIService::GetTouchpadScrollDirection(bool &state)
1518 {
1519 CALL_DEBUG_ENTER;
1520 #ifdef OHOS_BUILD_ENABLE_POINTER
1521 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadTouchpadScrollDirection, this,
1522 std::ref(state)));
1523 if (ret != RET_OK) {
1524 MMI_HILOGE("Get touchpad scroll direction switch failed, return %{public}d", ret);
1525 return RET_ERR;
1526 }
1527 #endif // OHOS_BUILD_ENABLE_POINTER
1528 return RET_OK;
1529 }
1530
SetTouchpadTapSwitch(bool switchFlag)1531 int32_t MMIService::SetTouchpadTapSwitch(bool switchFlag)
1532 {
1533 CALL_DEBUG_ENTER;
1534 #if defined OHOS_BUILD_ENABLE_POINTER
1535 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetTouchpadTapSwitch,
1536 MouseEventHdr, switchFlag));
1537 if (ret != RET_OK) {
1538 MMI_HILOGE("Set touchpad tap switch failed, return %{public}d", ret);
1539 return ret;
1540 }
1541 #endif // OHOS_BUILD_ENABLE_POINTER
1542 return RET_OK;
1543 }
1544
GetTouchpadTapSwitch(bool & switchFlag)1545 int32_t MMIService::GetTouchpadTapSwitch(bool &switchFlag)
1546 {
1547 CALL_DEBUG_ENTER;
1548 #ifdef OHOS_BUILD_ENABLE_POINTER
1549 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadTouchpadTapSwitch, this,
1550 std::ref(switchFlag)));
1551 if (ret != RET_OK) {
1552 MMI_HILOGE("Get touchpad tap switch failed, return %{public}d", ret);
1553 return RET_ERR;
1554 }
1555 #endif // OHOS_BUILD_ENABLE_POINTER
1556 return RET_OK;
1557 }
1558
SetTouchpadPointerSpeed(int32_t speed)1559 int32_t MMIService::SetTouchpadPointerSpeed(int32_t speed)
1560 {
1561 CALL_DEBUG_ENTER;
1562 #if defined OHOS_BUILD_ENABLE_POINTER
1563 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetTouchpadPointerSpeed,
1564 MouseEventHdr, speed));
1565 if (ret != RET_OK) {
1566 MMI_HILOGE("Set touchpad speed failed, return %{public}d", ret);
1567 return ret;
1568 }
1569 #endif // OHOS_BUILD_ENABLE_POINTER
1570 return RET_OK;
1571 }
1572
GetTouchpadPointerSpeed(int32_t & speed)1573 int32_t MMIService::GetTouchpadPointerSpeed(int32_t &speed)
1574 {
1575 CALL_DEBUG_ENTER;
1576 #ifdef OHOS_BUILD_ENABLE_POINTER
1577 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadTouchpadPointerSpeed, this,
1578 std::ref(speed)));
1579 if (ret != RET_OK) {
1580 MMI_HILOGE("Get touchpad speed failed, return %{public}d", ret);
1581 return RET_ERR;
1582 }
1583 #endif // OHOS_BUILD_ENABLE_POINTER
1584 return RET_OK;
1585 }
1586
SetTouchpadPinchSwitch(bool switchFlag)1587 int32_t MMIService::SetTouchpadPinchSwitch(bool switchFlag)
1588 {
1589 CALL_DEBUG_ENTER;
1590 #if defined OHOS_BUILD_ENABLE_POINTER
1591 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&TouchEventNormalize::SetTouchpadPinchSwitch,
1592 TouchEventHdr, switchFlag));
1593 if (ret != RET_OK) {
1594 MMI_HILOGE("Set touch pad pinch switch failed, return %{public}d", ret);
1595 return ret;
1596 }
1597 #endif // OHOS_BUILD_ENABLE_POINTER
1598 return RET_OK;
1599 }
1600
GetTouchpadPinchSwitch(bool & switchFlag)1601 int32_t MMIService::GetTouchpadPinchSwitch(bool &switchFlag)
1602 {
1603 CALL_DEBUG_ENTER;
1604 #ifdef OHOS_BUILD_ENABLE_POINTER
1605 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadTouchpadPinchSwitch, this,
1606 std::ref(switchFlag)));
1607 if (ret != RET_OK) {
1608 MMI_HILOGE("Get touch pad pinch switch failed, return %{public}d", ret);
1609 return RET_ERR;
1610 }
1611 #endif // OHOS_BUILD_ENABLE_POINTER
1612 return RET_OK;
1613 }
1614
SetTouchpadSwipeSwitch(bool switchFlag)1615 int32_t MMIService::SetTouchpadSwipeSwitch(bool switchFlag)
1616 {
1617 CALL_DEBUG_ENTER;
1618 #if defined OHOS_BUILD_ENABLE_POINTER
1619 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&TouchEventNormalize::SetTouchpadSwipeSwitch,
1620 TouchEventHdr, switchFlag));
1621 if (ret != RET_OK) {
1622 MMI_HILOGE("Set touchpad swipe switch failed, return %{public}d", ret);
1623 return ret;
1624 }
1625 #endif // OHOS_BUILD_ENABLE_POINTER
1626 return RET_OK;
1627 }
1628
GetTouchpadSwipeSwitch(bool & switchFlag)1629 int32_t MMIService::GetTouchpadSwipeSwitch(bool &switchFlag)
1630 {
1631 CALL_DEBUG_ENTER;
1632 #ifdef OHOS_BUILD_ENABLE_POINTER
1633 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadTouchpadSwipeSwitch, this,
1634 std::ref(switchFlag)));
1635 if (ret != RET_OK) {
1636 MMI_HILOGE("Get touchpad swipe switch failed, return %{public}d", ret);
1637 return RET_ERR;
1638 }
1639 #endif // OHOS_BUILD_ENABLE_POINTER
1640 return RET_OK;
1641 }
1642
SetTouchpadRightClickType(int32_t type)1643 int32_t MMIService::SetTouchpadRightClickType(int32_t type)
1644 {
1645 CALL_DEBUG_ENTER;
1646 #if defined OHOS_BUILD_ENABLE_POINTER
1647 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetTouchpadRightClickType,
1648 MouseEventHdr, type));
1649 if (ret != RET_OK) {
1650 MMI_HILOGE("Set touchpad right button menu type failed, return %{public}d", ret);
1651 return ret;
1652 }
1653 #endif // OHOS_BUILD_ENABLE_POINTER
1654 return RET_OK;
1655 }
1656
GetTouchpadRightClickType(int32_t & type)1657 int32_t MMIService::GetTouchpadRightClickType(int32_t &type)
1658 {
1659 CALL_DEBUG_ENTER;
1660 #ifdef OHOS_BUILD_ENABLE_POINTER
1661 int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::ReadTouchpadRightMenuType, this,
1662 std::ref(type)));
1663 if (ret != RET_OK) {
1664 MMI_HILOGE("Get touchpad right button menu type failed, return %{public}d", ret);
1665 return RET_ERR;
1666 }
1667 #endif // OHOS_BUILD_ENABLE_POINTER
1668 return RET_OK;
1669 }
1670 } // namespace MMI
1671 } // namespace OHOS
1672