1 /*
2 * Copyright (c) 2021-2023 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 <parameters.h>
19 #include <sys/signalfd.h>
20
21 #include <cinttypes>
22 #include <csignal>
23 #include "string_ex.h"
24 #ifdef OHOS_RSS_CLIENT
25 #include <unordered_map>
26 #endif
27
28 #include "ability_manager_client.h"
29 #include "anr_manager.h"
30 #include "app_debug_listener.h"
31 #include "app_state_observer.h"
32 #include "device_event_monitor.h"
33 #include "dfx_define.h"
34 #include "dfx_dump_catcher.h"
35 #include "dfx_hisysevent.h"
36 #include "dfx_json_formatter.h"
37
38 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
39 #include "display_event_monitor.h"
40 #endif // OHOS_BUILD_ENABLE_KEYBOARD
41 #include "event_dump.h"
42 #include "event_log_helper.h"
43 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
44 #include "fingersense_wrapper.h"
45 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
46 #ifdef OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
47 #include "gesturesense_wrapper.h"
48 #endif // OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
49 #include "infrared_emitter_controller.h"
50 #include "input_device_manager.h"
51 #include "ipc_skeleton.h"
52 #include "i_input_windows_manager.h"
53 #include "i_pointer_drawing_manager.h"
54 #include "i_preference_manager.h"
55 #include "key_auto_repeat.h"
56 #include "key_command_handler.h"
57 #include "key_map_manager.h"
58 #include "mmi_log.h"
59 #include "multimodal_input_connect_def_parcel.h"
60 #include "permission_helper.h"
61 #include "timer_manager.h"
62 #include "tokenid_kit.h"
63 #include "touch_event_normalize.h"
64 #include "util.h"
65 #include "util_ex.h"
66 #include "watchdog_task.h"
67 #include "xcollie/watchdog.h"
68 #include "xcollie/xcollie.h"
69 #include "xcollie/xcollie_define.h"
70
71 #ifdef OHOS_RSS_CLIENT
72 #include "res_sched_client.h"
73 #include "res_type.h"
74 #include "system_ability_definition.h"
75 #endif // OHOS_RSS_CLIENT
76 #include "setting_datashare.h"
77 #ifdef OHOS_BUILD_ENABLE_ANCO
78 #include "app_mgr_client.h"
79 #include "running_process_info.h"
80 #endif // OHOS_BUILD_ENABLE_ANCO
81
82 #undef MMI_LOG_TAG
83 #define MMI_LOG_TAG "MMIService"
84 #undef MMI_LOG_DOMAIN
85 #define MMI_LOG_DOMAIN MMI_LOG_SERVER
86
87 namespace OHOS {
88 namespace MMI {
89 namespace {
90 std::mutex g_instanceMutex;
91 MMIService* g_MMIService;
92 const std::string DEF_INPUT_SEAT { "seat0" };
93 const std::string THREAD_NAME { "mmi-service" };
94 const std::string SHELL_ASSISTANT { "com.shell_assistant" };
95 constexpr int32_t WATCHDOG_INTERVAL_TIME { 30000 };
96 constexpr int32_t WATCHDOG_DELAY_TIME { 40000 };
97 constexpr int32_t RELOAD_DEVICE_TIME { 2000 };
98 constexpr int32_t REMOVE_OBSERVER { -2 };
99 constexpr int32_t REPEAT_COUNT { 2 };
100 constexpr int32_t UNSUBSCRIBED { -1 };
101 constexpr int32_t UNOBSERVED { -1 };
102 constexpr int32_t SUBSCRIBED { 1 };
103 constexpr int32_t DISTRIBUTE_TIME { 1000 }; // 1000ms
104 constexpr int32_t COMMON_PARAMETER_ERROR { 401 };
105 constexpr size_t MAX_FRAME_NUMS { 100 };
106 constexpr int32_t THREAD_BLOCK_TIMER_SPAN_S { 3 };
107 const std::set<int32_t> g_keyCodeValueSet = {
108 KeyEvent::KEYCODE_FN, KeyEvent::KEYCODE_DPAD_UP, KeyEvent::KEYCODE_DPAD_DOWN, KeyEvent::KEYCODE_DPAD_LEFT,
109 KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::KEYCODE_ALT_LEFT, KeyEvent::KEYCODE_ALT_RIGHT,
110 KeyEvent::KEYCODE_SHIFT_LEFT, KeyEvent::KEYCODE_SHIFT_RIGHT, KeyEvent::KEYCODE_TAB, KeyEvent::KEYCODE_ENTER,
111 KeyEvent::KEYCODE_DEL, KeyEvent::KEYCODE_MENU, KeyEvent::KEYCODE_PAGE_UP, KeyEvent::KEYCODE_PAGE_DOWN,
112 KeyEvent::KEYCODE_ESCAPE, KeyEvent::KEYCODE_FORWARD_DEL, KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_CTRL_RIGHT,
113 KeyEvent::KEYCODE_CAPS_LOCK, KeyEvent::KEYCODE_SCROLL_LOCK, KeyEvent::KEYCODE_META_LEFT,
114 KeyEvent::KEYCODE_META_RIGHT, KeyEvent::KEYCODE_SYSRQ, KeyEvent::KEYCODE_BREAK, KeyEvent::KEYCODE_MOVE_HOME,
115 KeyEvent::KEYCODE_MOVE_END, KeyEvent::KEYCODE_INSERT, KeyEvent::KEYCODE_F1, KeyEvent::KEYCODE_F2,
116 KeyEvent::KEYCODE_F3, KeyEvent::KEYCODE_F4, KeyEvent::KEYCODE_F5, KeyEvent::KEYCODE_F6, KeyEvent::KEYCODE_F7,
117 KeyEvent::KEYCODE_F8, KeyEvent::KEYCODE_F9, KeyEvent::KEYCODE_F10, KeyEvent::KEYCODE_F11, KeyEvent::KEYCODE_F12,
118 KeyEvent::KEYCODE_NUM_LOCK
119 };
120 #ifdef OHOS_BUILD_ENABLE_ANCO
121 constexpr int32_t DEFAULT_USER_ID { 100 };
122 #endif // OHOS_BUILD_ENABLE_ANCO
123 } // namespace
124
125 const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(MMIService::GetInstance());
126
CheckDefineOutput(const char * fmt,Ts...args)127 template <class... Ts> void CheckDefineOutput(const char *fmt, Ts... args)
128 {
129 CHKPV(fmt);
130 char buf[MAX_PACKET_BUF_SIZE] = {};
131 int32_t ret = snprintf_s(buf, MAX_PACKET_BUF_SIZE, MAX_PACKET_BUF_SIZE - 1, fmt, args...);
132 if (ret == -1) {
133 KMSG_LOGE("Call snprintf_s failed.ret = %d", ret);
134 return;
135 }
136 KMSG_LOGI("%s", buf);
137 MMI_HILOGI("%{public}s", buf);
138 }
139
CheckDefine()140 static void CheckDefine()
141 {
142 CheckDefineOutput("ChkDefs:");
143 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
144 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_POINTER_DRAWING");
145 #endif
146 #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR
147 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_INTERCEPTOR");
148 #endif
149 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
150 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_KEYBOARD");
151 #endif
152 #ifdef OHOS_BUILD_ENABLE_POINTER
153 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_POINTER");
154 #endif
155 #ifdef OHOS_BUILD_ENABLE_TOUCH
156 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_TOUCH");
157 #endif
158 #ifdef OHOS_BUILD_ENABLE_MONITOR
159 CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_MONITOR");
160 #endif
161 }
162
MMIService()163 MMIService::MMIService() : SystemAbility(MULTIMODAL_INPUT_CONNECT_SERVICE_ID, true) {}
164
~MMIService()165 MMIService::~MMIService()
166 {
167 if (g_MMIService != nullptr) {
168 g_MMIService = nullptr;
169 }
170 MMI_HILOGI("~MMIService");
171 }
172
GetInstance()173 MMIService* MMIService::GetInstance()
174 {
175 if (g_MMIService == nullptr) {
176 std::lock_guard<std::mutex> lock(g_instanceMutex);
177 if (g_MMIService == nullptr) {
178 MMI_HILOGI("new MMIService");
179 g_MMIService = new MMIService();
180 }
181 }
182 return g_MMIService;
183 }
184
AddEpoll(EpollEventType type,int32_t fd)185 int32_t MMIService::AddEpoll(EpollEventType type, int32_t fd)
186 {
187 if (type < EPOLL_EVENT_BEGIN || type >= EPOLL_EVENT_END) {
188 MMI_HILOGE("Invalid param type");
189 return RET_ERR;
190 }
191 if (fd < 0) {
192 MMI_HILOGE("Invalid param fd_");
193 return RET_ERR;
194 }
195 if (mmiFd_ < 0) {
196 MMI_HILOGE("Invalid param mmiFd_");
197 return RET_ERR;
198 }
199 auto eventData = std::make_shared<mmi_epoll_event>();
200 eventData->fd = fd;
201 eventData->event_type = type;
202 MMI_HILOGI("userdata:[fd:%{public}d, type:%{public}d]", eventData->fd, eventData->event_type);
203
204 struct epoll_event ev = {};
205 ev.events = EPOLLIN;
206 ev.data.fd = fd;
207 auto ret = EpollCtl(fd, EPOLL_CTL_ADD, ev, mmiFd_);
208 if (ret < 0) {
209 eventData = nullptr;
210 ev.data.ptr = nullptr;
211 return ret;
212 }
213 AddEpollEvent(fd, eventData);
214 return RET_OK;
215 }
216
DelEpoll(EpollEventType type,int32_t fd)217 int32_t MMIService::DelEpoll(EpollEventType type, int32_t fd)
218 {
219 if (type < EPOLL_EVENT_BEGIN || type >= EPOLL_EVENT_END) {
220 MMI_HILOGE("Invalid param type");
221 return RET_ERR;
222 }
223 if (fd < 0) {
224 MMI_HILOGE("Invalid param fd_");
225 return RET_ERR;
226 }
227 if (mmiFd_ < 0) {
228 MMI_HILOGE("Invalid param mmiFd_");
229 return RET_ERR;
230 }
231 struct epoll_event ev = {};
232 auto ret = EpollCtl(fd, EPOLL_CTL_DEL, ev, mmiFd_);
233 if (ret < 0) {
234 MMI_HILOGE("DelEpoll failed");
235 return ret;
236 }
237 return RET_OK;
238 }
239
IsRunning() const240 bool MMIService::IsRunning() const
241 {
242 return (state_ == ServiceRunningState::STATE_RUNNING);
243 }
244
InitLibinputService()245 bool MMIService::InitLibinputService()
246 {
247 if (!(libinputAdapter_.Init([] (void *event, int64_t frameTime) {
248 ::OHOS::DelayedSingleton<InputEventHandler>::GetInstance()->OnEvent(event, frameTime);
249 }
250 ))) {
251 MMI_HILOGE("Libinput init, bind failed");
252 return false;
253 }
254 auto inputFds = libinputAdapter_.GetInputFds();
255 for (auto fd : inputFds) {
256 auto ret = AddEpoll(EPOLL_EVENT_INPUT, fd);
257 if (ret < 0) {
258 MMI_HILOGE("AddEpoll error ret:%{public}d", ret);
259 EpollClose();
260 return false;
261 }
262 MMI_HILOGD("AddEpoll, epollfd:%{public}d, fd:%{public}d", mmiFd_, fd);
263 }
264 return true;
265 }
266
InitService()267 bool MMIService::InitService()
268 {
269 MMI_HILOGD("Server msg handler Init");
270 sMsgHandler_.Init(*this);
271 if (state_ != ServiceRunningState::STATE_NOT_START) {
272 MMI_HILOGE("Service running status is not enabled");
273 return false;
274 }
275 if (EpollCreate(MAX_EVENT_SIZE) < 0) {
276 MMI_HILOGE("Create epoll failed");
277 return false;
278 }
279 auto ret = AddEpoll(EPOLL_EVENT_SOCKET, epollFd_);
280 if (ret < 0) {
281 MMI_HILOGE("AddEpoll error ret:%{public}d", ret);
282 EpollClose();
283 return false;
284 }
285 state_ = ServiceRunningState::STATE_RUNNING;
286 if (!(Publish(this))) {
287 state_ = ServiceRunningState::STATE_NOT_START;
288 MMI_HILOGE("Service initialization failed");
289 EpollClose();
290 return false;
291 }
292 MMI_HILOGI("AddEpoll, epollfd:%{public}d, fd:%{public}d", mmiFd_, epollFd_);
293 return true;
294 }
295
InitDelegateTasks()296 bool MMIService::InitDelegateTasks()
297 {
298 CALL_DEBUG_ENTER;
299 if (!delegateTasks_.Init()) {
300 MMI_HILOGE("The delegate task init failed");
301 return false;
302 }
303 auto ret = AddEpoll(EPOLL_EVENT_ETASK, delegateTasks_.GetReadFd());
304 if (ret < 0) {
305 MMI_HILOGE("AddEpoll error ret:%{public}d", ret);
306 EpollClose();
307 return false;
308 }
309 std::function<int32_t(DTaskCallback)> fun = [this](DTaskCallback cb) -> int32_t {
310 return delegateTasks_.PostSyncTask(cb);
311 };
312 delegateInterface_ = std::make_shared<DelegateInterface>(fun);
313 delegateInterface_->Init();
314 MMI_HILOGI("AddEpoll, epollfd:%{public}d, fd:%{public}d", mmiFd_, delegateTasks_.GetReadFd());
315 return true;
316 }
317
Init()318 int32_t MMIService::Init()
319 {
320 CheckDefine();
321 MMI_HILOGD("WindowsManager Init");
322 WIN_MGR->Init(*this);
323 MMI_HILOGD("NapProcess Init");
324 NapProcess::GetInstance()->Init(*this);
325 MMI_HILOGD("ANRManager Init");
326 ANRMgr->Init(*this);
327 MMI_HILOGI("PointerDrawingManager Init");
328 #ifdef OHOS_BUILD_ENABLE_POINTER
329 if (!IPointerDrawingManager::GetInstance()->Init()) {
330 MMI_HILOGE("Pointer draw init failed");
331 return POINTER_DRAW_INIT_FAIL;
332 }
333 #endif // OHOS_BUILD_ENABLE_POINTER
334 mmiFd_ = EpollCreate(MAX_EVENT_SIZE);
335 if (mmiFd_ < 0) {
336 MMI_HILOGE("Create epoll failed");
337 return EPOLL_CREATE_FAIL;
338 }
339 MMI_HILOGD("Input msg handler init");
340 InputHandler->Init(*this);
341 MMI_HILOGD("Libinput service init");
342 if (!InitLibinputService()) {
343 MMI_HILOGE("Libinput init failed");
344 return LIBINPUT_INIT_FAIL;
345 }
346 MMI_HILOGD("Init DelegateTasks init");
347 if (!InitDelegateTasks()) {
348 MMI_HILOGE("Delegate tasks init failed");
349 return ETASKS_INIT_FAIL;
350 }
351 SetRecvFun([this] (SessionPtr sess, NetPacket& pkt) {sMsgHandler_.OnMsgHandler(sess, pkt);});
352 KeyMapMgr->GetConfigKeyValue("default_keymap", KeyMapMgr->GetDefaultKeyId());
353 OHOS::system::SetParameter(INPUT_POINTER_DEVICES, "false");
354 if (!InitService()) {
355 MMI_HILOGE("Saservice init failed");
356 return SASERVICE_INIT_FAIL;
357 }
358 MMI_HILOGI("Set para input.pointer.device false");
359 return RET_OK;
360 }
361
OnStart()362 void MMIService::OnStart()
363 {
364 CHK_PID_AND_TID();
365 int32_t ret = Init();
366 CHKNOKRV(ret, "Init mmi_service failed");
367 MMI_HILOGD("Started successfully");
368 AddReloadDeviceTimer();
369 t_ = std::thread([this] {this->OnThread();});
370 pthread_setname_np(t_.native_handle(), THREAD_NAME.c_str());
371 #ifdef OHOS_RSS_CLIENT
372 MMI_HILOGI("Add system ability listener start");
373 AddSystemAbilityListener(RES_SCHED_SYS_ABILITY_ID);
374 MMI_HILOGI("Add system ability listener success");
375 #endif // OHOS_RSS_CLIENT
376 #if defined(OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER) && defined(OHOS_BUILD_ENABLE_KEYBOARD)
377 FINGERSENSE_WRAPPER->InitFingerSenseWrapper();
378 MMI_HILOGI("Add system ability listener start");
379 AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID);
380 MMI_HILOGI("Add system ability listener success");
381 DISPLAY_MONITOR->InitCommonEventSubscriber();
382 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER && OHOS_BUILD_ENABLE_KEYBOARD
383 #ifdef OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
384 GESTURESENSE_WRAPPER->InitGestureSenseWrapper();
385 #endif // OHOS_BUILD_ENABLE_GESTURESENSE_WRAPPER
386 MMI_HILOGI("Add app manager service listener start");
387 AddSystemAbilityListener(APP_MGR_SERVICE_ID);
388 APP_OBSERVER_MGR->InitAppStateObserver();
389 MMI_HILOGI("Add app manager service listener end");
390 AddSystemAbilityListener(RENDER_SERVICE);
391 AddAppDebugListener();
392 AddSystemAbilityListener(DISPLAY_MANAGER_SERVICE_SA_ID);
393 #if defined(OHOS_BUILD_ENABLE_MONITOR) && defined(PLAYER_FRAMEWORK_EXISTS)
394 MMI_HILOGI("Add system ability listener start");
395 AddSystemAbilityListener(PLAYER_DISTRIBUTED_SERVICE_ID);
396 MMI_HILOGI("Add system ability listener end");
397 #endif
398 #ifdef OHOS_BUILD_ENABLE_ANCO
399 InitAncoUds();
400 #endif // OHOS_BUILD_ENABLE_ANCO
401 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
402 IPointerDrawingManager::GetInstance()->InitPointerObserver();
403 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
404 PREFERENCES_MGR->InitPreferences();
405 TimerMgr->AddTimer(WATCHDOG_INTERVAL_TIME, -1, [this]() {
406 MMI_HILOGD("Set thread status flag to true");
407 threadStatusFlag_ = true;
408 });
409 auto taskFunc = [this]() {
410 if (threadStatusFlag_) {
411 MMI_HILOGD("Set thread status flag to false");
412 threadStatusFlag_ = false;
413 } else {
414 MMI_HILOGE("Timeout happened");
415 }
416 };
417 HiviewDFX::Watchdog::GetInstance().RunPeriodicalTask("MMIService", taskFunc, WATCHDOG_INTERVAL_TIME,
418 WATCHDOG_DELAY_TIME);
419 MMI_HILOGI("Run periodical task success");
420 }
421
OnStop()422 void MMIService::OnStop()
423 {
424 CHK_PID_AND_TID();
425 UdsStop();
426 libinputAdapter_.Stop();
427 state_ = ServiceRunningState::STATE_NOT_START;
428 #ifdef OHOS_RSS_CLIENT
429 MMI_HILOGI("Remove system ability listener start");
430 RemoveSystemAbilityListener(RES_SCHED_SYS_ABILITY_ID);
431 MMI_HILOGI("Remove system ability listener success");
432 #endif
433 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
434 RemoveSystemAbilityListener(COMMON_EVENT_SERVICE_ID);
435 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
436 RemoveSystemAbilityListener(APP_MGR_SERVICE_ID);
437 RemoveSystemAbilityListener(RENDER_SERVICE);
438 RemoveAppDebugListener();
439 RemoveSystemAbilityListener(DISPLAY_MANAGER_SERVICE_SA_ID);
440 #if defined(OHOS_BUILD_ENABLE_MONITOR) && defined(PLAYER_FRAMEWORK_EXISTS)
441 RemoveSystemAbilityListener(PLAYER_DISTRIBUTED_SERVICE_ID);
442 #endif
443 #ifdef OHOS_BUILD_ENABLE_ANCO
444 StopAncoUds();
445 #endif // OHOS_BUILD_ENABLE_ANCO
446 }
447
AddAppDebugListener()448 void MMIService::AddAppDebugListener()
449 {
450 CALL_DEBUG_ENTER;
451 appDebugListener_ = AppDebugListener::GetInstance();
452 auto errCode =
453 AAFwk::AbilityManagerClient::GetInstance()->RegisterAppDebugListener(appDebugListener_);
454 if (errCode != RET_OK) {
455 MMI_HILOGE("Call RegisterAppDebugListener failed, errCode:%{public}d", errCode);
456 }
457 }
458
RemoveAppDebugListener()459 void MMIService::RemoveAppDebugListener()
460 {
461 CALL_DEBUG_ENTER;
462 CHKPV(appDebugListener_);
463 auto errCode =
464 AAFwk::AbilityManagerClient::GetInstance()->UnregisterAppDebugListener(appDebugListener_);
465 if (errCode != RET_OK) {
466 MMI_HILOGE("Call UnregisterAppDebugListener failed, errCode:%{public}d", errCode);
467 }
468 }
469
AllocSocketFd(const std::string & programName,const int32_t moduleType,int32_t & toReturnClientFd,int32_t & tokenType)470 int32_t MMIService::AllocSocketFd(const std::string &programName, const int32_t moduleType, int32_t &toReturnClientFd,
471 int32_t &tokenType)
472 {
473 toReturnClientFd = IMultimodalInputConnect::INVALID_SOCKET_FD;
474 int32_t serverFd = IMultimodalInputConnect::INVALID_SOCKET_FD;
475 int32_t pid = GetCallingPid();
476 int32_t uid = GetCallingUid();
477 MMI_HILOGI("Enter, programName:%{public}s, moduleType:%{public}d, pid:%{public}d",
478 programName.c_str(), moduleType, pid);
479 int32_t ret = delegateTasks_.PostSyncTask(
480 [this, &programName, moduleType, uid, pid, &serverFd, &toReturnClientFd, &tokenType] {
481 return this->AddSocketPairInfo(programName, moduleType, uid, pid, serverFd, toReturnClientFd, tokenType);
482 }
483 );
484 DfxHisysevent::ClientConnectData data = {
485 .pid = pid,
486 .uid = uid,
487 .moduleType = moduleType,
488 .programName = programName,
489 .serverFd = serverFd
490 };
491 if (ret != RET_OK) {
492 MMI_HILOGE("Call AddSocketPairInfo failed, return:%{public}d", ret);
493 DfxHisysevent::OnClientConnect(data, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
494 return ret;
495 }
496 MMI_HILOGIK("Leave, programName:%{public}s, moduleType:%{public}d, alloc success", programName.c_str(),
497 moduleType);
498 DfxHisysevent::OnClientConnect(data, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
499 return RET_OK;
500 }
501
AddInputEventFilter(sptr<IEventFilter> filter,int32_t filterId,int32_t priority,uint32_t deviceTags)502 int32_t MMIService::AddInputEventFilter(sptr<IEventFilter> filter, int32_t filterId, int32_t priority,
503 uint32_t deviceTags)
504 {
505 CALL_INFO_TRACE;
506 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD)
507 CHKPR(filter, ERROR_NULL_POINTER);
508 int32_t clientPid = GetCallingPid();
509 int32_t ret = delegateTasks_.PostSyncTask(
510 [this, filter, filterId, priority, deviceTags, clientPid] {
511 return sMsgHandler_.AddInputEventFilter(filter, filterId, priority, deviceTags, clientPid);
512 }
513 );
514 if (ret != RET_OK) {
515 MMI_HILOGE("Add event filter failed, return:%{public}d", ret);
516 return ret;
517 }
518 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD
519 return RET_OK;
520 }
521
RemoveInputEventFilter(int32_t filterId)522 int32_t MMIService::RemoveInputEventFilter(int32_t filterId)
523 {
524 CALL_INFO_TRACE;
525 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD)
526 int32_t clientPid = GetCallingPid();
527 int32_t ret = delegateTasks_.PostSyncTask(
528 [this, filterId, clientPid] {
529 return sMsgHandler_.RemoveInputEventFilter(filterId, clientPid);
530 }
531 );
532 if (ret != RET_OK) {
533 MMI_HILOGE("Remove event filter failed, return:%{public}d", ret);
534 return ret;
535 }
536 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD
537 return RET_OK;
538 }
539
OnConnected(SessionPtr s)540 void MMIService::OnConnected(SessionPtr s)
541 {
542 CHKPV(s);
543 MMI_HILOGI("fd:%{public}d", s->GetFd());
544 #ifdef OHOS_BUILD_ENABLE_ANCO
545 if (s->GetProgramName() != SHELL_ASSISTANT) {
546 return;
547 }
548 auto appMgrClient = DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance();
549 if (appMgrClient == nullptr) {
550 return;
551 }
552 int32_t userid = WIN_MGR->GetCurrentUserId();
553 if (userid < 0) {
554 userid = DEFAULT_USER_ID;
555 }
556 std::vector<AppExecFwk::RunningProcessInfo> info;
557 appMgrClient->GetProcessRunningInfosByUserId(info, userid);
558 for (auto &item : info) {
559 if (item.bundleNames.empty()) {
560 continue;
561 }
562 if (SHELL_ASSISTANT == item.bundleNames[0].c_str()) {
563 MMI_HILOGW("record client processes pid %{public}d", item.pid_);
564 shellAssitentPid_ = item.pid_;
565 }
566 }
567 #endif // OHOS_BUILD_ENABLE_ANCO
568 }
569
OnDisconnected(SessionPtr s)570 void MMIService::OnDisconnected(SessionPtr s)
571 {
572 CHKPV(s);
573 MMI_HILOGW("Enter, session desc:%{public}s, fd:%{public}d", s->GetDescript().c_str(), s->GetFd());
574 auto ret = RemoveInputEventFilter(-1);
575 if (ret != RET_OK) {
576 MMI_HILOGF("Remove all filter failed, ret:%{public}d", ret);
577 }
578 #ifdef OHOS_BUILD_ENABLE_ANCO
579 if (s->GetProgramName() == SHELL_ASSISTANT && shellAssitentPid_ == s->GetPid()) {
580 MMI_HILOGW("clean all shell windows pid: %{public}d", s->GetPid());
581 shellAssitentPid_ = -1;
582 IInputWindowsManager::GetInstance()->CleanShellWindowIds();
583 }
584 #endif // OHOS_BUILD_ENABLE_ANCO
585 #ifdef OHOS_BUILD_ENABLE_POINTER
586 IPointerDrawingManager::GetInstance()->DeletePointerVisible(s->GetPid());
587 #endif // OHOS_BUILD_ENABLE_POINTER
588 }
589
SetMouseScrollRows(int32_t rows)590 int32_t MMIService::SetMouseScrollRows(int32_t rows)
591 {
592 CALL_INFO_TRACE;
593 #if defined OHOS_BUILD_ENABLE_POINTER
594 int32_t ret = delegateTasks_.PostSyncTask(
595 [rows] {
596 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetMouseScrollRows(rows);
597 }
598 );
599 if (ret != RET_OK) {
600 MMI_HILOGE("Set the number of mouse scrolling rows failed, return:%{public}d", ret);
601 return ret;
602 }
603 #endif // OHOS_BUILD_ENABLE_POINTER
604 return RET_OK;
605 }
606
SetCustomCursor(int32_t pid,int32_t windowId,int32_t focusX,int32_t focusY,void * pixelMap)607 int32_t MMIService::SetCustomCursor(int32_t pid, int32_t windowId, int32_t focusX, int32_t focusY, void* pixelMap)
608 {
609 CALL_INFO_TRACE;
610 #if defined OHOS_BUILD_ENABLE_POINTER
611 int32_t ret = CheckPidPermission(pid);
612 if (ret != RET_OK) {
613 MMI_HILOGE("Check pid permission failed");
614 return ret;
615 }
616 ret = delegateTasks_.PostSyncTask(std::bind(
617 [pixelMap, pid, windowId, focusX, focusY] {
618 return IPointerDrawingManager::GetInstance()->SetCustomCursor(pixelMap, pid, windowId, focusX, focusY);
619 }
620 ));
621 if (ret != RET_OK) {
622 MMI_HILOGE("Set the custom cursor failed, ret:%{public}d", ret);
623 return ret;
624 }
625 #endif // OHOS_BUILD_ENABLE_POINTER
626 return RET_OK;
627 }
628
SetMouseIcon(int32_t windowId,void * pixelMap)629 int32_t MMIService::SetMouseIcon(int32_t windowId, void* pixelMap)
630 {
631 CALL_INFO_TRACE;
632 #if defined OHOS_BUILD_ENABLE_POINTER
633 int32_t pid = GetCallingPid();
634 int32_t ret = CheckPidPermission(pid);
635 if (ret != RET_OK) {
636 MMI_HILOGE("Check pid permission failed");
637 return ret;
638 }
639 ret = delegateTasks_.PostSyncTask(std::bind(
640 [pid, windowId, pixelMap] {
641 return IPointerDrawingManager::GetInstance()->SetMouseIcon(pid, windowId, pixelMap);
642 }
643 ));
644 if (ret != RET_OK) {
645 MMI_HILOGE("Set the mouse icon failed, return:%{public}d", ret);
646 return ret;
647 }
648 #endif // OHOS_BUILD_ENABLE_POINTER
649 return RET_OK;
650 }
651
SetMouseHotSpot(int32_t pid,int32_t windowId,int32_t hotSpotX,int32_t hotSpotY)652 int32_t MMIService::SetMouseHotSpot(int32_t pid, int32_t windowId, int32_t hotSpotX, int32_t hotSpotY)
653 {
654 CALL_INFO_TRACE;
655 #if defined OHOS_BUILD_ENABLE_POINTER
656 int32_t ret = CheckPidPermission(pid);
657 if (ret != RET_OK) {
658 MMI_HILOGE("Check pid permission failed");
659 return ret;
660 }
661 ret = delegateTasks_.PostSyncTask(
662 [pid, windowId, hotSpotX, hotSpotY] {
663 return IPointerDrawingManager::GetInstance()->SetMouseHotSpot(pid, windowId, hotSpotX, hotSpotY);
664 }
665 );
666 if (ret != RET_OK) {
667 MMI_HILOGE("Set the mouse hot spot failed, return:%{public}d", ret);
668 return ret;
669 }
670 #endif // OHOS_BUILD_ENABLE_POINTER
671 return RET_OK;
672 }
673
SetNapStatus(int32_t pid,int32_t uid,std::string bundleName,int32_t napStatus)674 int32_t MMIService::SetNapStatus(int32_t pid, int32_t uid, std::string bundleName, int32_t napStatus)
675 {
676 CALL_INFO_TRACE;
677 int32_t ret = CheckPidPermission(pid);
678 if (ret != RET_OK) {
679 MMI_HILOGE("Check pid permission failed");
680 return ret;
681 }
682 NapProcess::GetInstance()->SetNapStatus(pid, uid, bundleName, napStatus);
683 return RET_OK;
684 }
685
686 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadMouseScrollRows(int32_t & rows)687 int32_t MMIService::ReadMouseScrollRows(int32_t &rows)
688 {
689 rows = MouseEventHdr->GetMouseScrollRows();
690 return RET_OK;
691 }
692 #endif // OHOS_BUILD_ENABLE_POINTER
693
GetMouseScrollRows(int32_t & rows)694 int32_t MMIService::GetMouseScrollRows(int32_t &rows)
695 {
696 CALL_INFO_TRACE;
697 #ifdef OHOS_BUILD_ENABLE_POINTER
698 int32_t ret = delegateTasks_.PostSyncTask(
699 [this, &rows] {
700 return this->ReadMouseScrollRows(rows);
701 }
702 );
703 if (ret != RET_OK) {
704 MMI_HILOGE("Get the number of mouse scrolling rows failed, ret:%{public}d", ret);
705 return ret;
706 }
707 #endif // OHOS_BUILD_ENABLE_POINTER
708 return RET_OK;
709 }
710
SetPointerSize(int32_t size)711 int32_t MMIService::SetPointerSize(int32_t size)
712 {
713 CALL_INFO_TRACE;
714 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
715 int32_t ret = delegateTasks_.PostSyncTask(
716 [size] {
717 return IPointerDrawingManager::GetInstance()->SetPointerSize(size);
718 }
719 );
720 if (ret != RET_OK) {
721 MMI_HILOGE("Set pointer size failed, return:%{public}d", ret);
722 return ret;
723 }
724 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
725 return RET_OK;
726 }
727
728 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
ReadPointerSize(int32_t & size)729 int32_t MMIService::ReadPointerSize(int32_t &size)
730 {
731 size = IPointerDrawingManager::GetInstance()->GetPointerSize();
732 return RET_OK;
733 }
734 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
735
GetPointerSize(int32_t & size)736 int32_t MMIService::GetPointerSize(int32_t &size)
737 {
738 CALL_INFO_TRACE;
739 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
740 int32_t ret = delegateTasks_.PostSyncTask(
741 [this, &size] {
742 return this->ReadPointerSize(size);
743 }
744 );
745 if (ret != RET_OK) {
746 MMI_HILOGE("Get pointer size failed, return:%{public}d", ret);
747 return ret;
748 }
749 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
750 return RET_OK;
751 }
752
SetMousePrimaryButton(int32_t primaryButton)753 int32_t MMIService::SetMousePrimaryButton(int32_t primaryButton)
754 {
755 CALL_INFO_TRACE;
756 #if defined OHOS_BUILD_ENABLE_POINTER
757 int32_t ret = delegateTasks_.PostSyncTask(
758 [primaryButton] {
759 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetMousePrimaryButton(primaryButton);
760 }
761 );
762 if (ret != RET_OK) {
763 MMI_HILOGE("Set mouse primary button failed, return:%{public}d", ret);
764 return ret;
765 }
766 #endif // OHOS_BUILD_ENABLE_POINTER
767 return RET_OK;
768 }
769
770 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadMousePrimaryButton(int32_t & primaryButton)771 int32_t MMIService::ReadMousePrimaryButton(int32_t &primaryButton)
772 {
773 primaryButton = MouseEventHdr->GetMousePrimaryButton();
774 return RET_OK;
775 }
776 #endif // OHOS_BUILD_ENABLE_POINTER
777
GetMousePrimaryButton(int32_t & primaryButton)778 int32_t MMIService::GetMousePrimaryButton(int32_t &primaryButton)
779 {
780 CALL_INFO_TRACE;
781 #ifdef OHOS_BUILD_ENABLE_POINTER
782 int32_t ret = delegateTasks_.PostSyncTask(
783 [this, &primaryButton] {
784 return this->ReadMousePrimaryButton(primaryButton);
785 }
786 );
787 if (ret != RET_OK) {
788 MMI_HILOGE("Get mouse primary button failed, return:%{public}d", ret);
789 return ret;
790 }
791 #endif // OHOS_BUILD_ENABLE_POINTER
792 return RET_OK;
793 }
794
SetPointerVisible(bool visible,int32_t priority)795 int32_t MMIService::SetPointerVisible(bool visible, int32_t priority)
796 {
797 CALL_INFO_TRACE;
798 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
799 auto tokenId = IPCSkeleton::GetCallingTokenID();
800 auto tokenType = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId);
801 bool isHap = false;
802 if (tokenType == OHOS::Security::AccessToken::TOKEN_HAP) {
803 isHap = true;
804 }
805 int32_t clientPid = GetCallingPid();
806 int32_t ret = delegateTasks_.PostSyncTask(
807 [clientPid, visible, priority, isHap] {
808 return IPointerDrawingManager::GetInstance()->SetPointerVisible(clientPid, visible, priority, isHap);
809 }
810 );
811 if (ret != RET_OK) {
812 MMI_HILOGE("Set pointer visible failed, return:%{public}d", ret);
813 return ret;
814 }
815 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
816 return RET_OK;
817 }
818
819 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
CheckPointerVisible(bool & visible)820 int32_t MMIService::CheckPointerVisible(bool &visible)
821 {
822 visible = IPointerDrawingManager::GetInstance()->IsPointerVisible();
823 return RET_OK;
824 }
825 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
826
IsPointerVisible(bool & visible)827 int32_t MMIService::IsPointerVisible(bool &visible)
828 {
829 CALL_DEBUG_ENTER;
830 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
831 int32_t ret = delegateTasks_.PostSyncTask(
832 [this, &visible] {
833 return this->CheckPointerVisible(visible);
834 }
835 );
836 if (ret != RET_OK) {
837 MMI_HILOGE("Is pointer visible failed, return:%{public}d", ret);
838 return ret;
839 }
840 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
841 return RET_OK;
842 }
843
MarkProcessed(int32_t eventType,int32_t eventId)844 int32_t MMIService::MarkProcessed(int32_t eventType, int32_t eventId)
845 {
846 CALL_DEBUG_ENTER;
847 CHKPR(ANRMgr, RET_ERR);
848 int32_t clientPid = GetCallingPid();
849 int32_t ret = delegateTasks_.PostSyncTask(
850 [clientPid, eventType, eventId] {
851 return ::OHOS::DelayedSingleton<ANRManager>::GetInstance()->MarkProcessed(clientPid, eventType, eventId);
852 }
853 );
854 if (ret != RET_OK) {
855 MMI_HILOGD("Mark event processed failed, ret:%{public}d", ret);
856 return ret;
857 }
858 return RET_OK;
859 }
860
SetPointerColor(int32_t color)861 int32_t MMIService::SetPointerColor(int32_t color)
862 {
863 CALL_INFO_TRACE;
864 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
865 int32_t ret = delegateTasks_.PostSyncTask(
866 [color] {
867 return IPointerDrawingManager::GetInstance()->SetPointerColor(color);
868 }
869 );
870 if (ret != RET_OK) {
871 MMI_HILOGE("Set pointer color failed, return:%{public}d", ret);
872 return ret;
873 }
874 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
875 return RET_OK;
876 }
877
878 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
ReadPointerColor(int32_t & color)879 int32_t MMIService::ReadPointerColor(int32_t &color)
880 {
881 color = IPointerDrawingManager::GetInstance()->GetPointerColor();
882 return RET_OK;
883 }
884 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
885
GetPointerColor(int32_t & color)886 int32_t MMIService::GetPointerColor(int32_t &color)
887 {
888 CALL_INFO_TRACE;
889 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
890 int32_t ret = delegateTasks_.PostSyncTask(
891 [this, &color] {
892 return this->ReadPointerColor(color);
893 }
894 );
895 if (ret != RET_OK) {
896 MMI_HILOGE("Get pointer color failed, return:%{public}d", ret);
897 return ret;
898 }
899 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
900 return RET_OK;
901 }
902
SetPointerSpeed(int32_t speed)903 int32_t MMIService::SetPointerSpeed(int32_t speed)
904 {
905 CALL_INFO_TRACE;
906 #ifdef OHOS_BUILD_ENABLE_POINTER
907 int32_t ret = delegateTasks_.PostSyncTask(
908 [speed] {
909 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetPointerSpeed(speed);
910 }
911 );
912 if (ret != RET_OK) {
913 MMI_HILOGE("Set pointer speed failed, return:%{public}d", ret);
914 return ret;
915 }
916 #endif // OHOS_BUILD_ENABLE_POINTER
917 return RET_OK;
918 }
919
920 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadPointerSpeed(int32_t & speed)921 int32_t MMIService::ReadPointerSpeed(int32_t &speed)
922 {
923 speed = MouseEventHdr->GetPointerSpeed();
924 return RET_OK;
925 }
926 #endif // OHOS_BUILD_ENABLE_POINTER
927
GetPointerSpeed(int32_t & speed)928 int32_t MMIService::GetPointerSpeed(int32_t &speed)
929 {
930 CALL_INFO_TRACE;
931 #ifdef OHOS_BUILD_ENABLE_POINTER
932 int32_t ret = delegateTasks_.PostSyncTask(
933 [this, &speed] {
934 return this->ReadPointerSpeed(speed);
935 }
936 );
937 if (ret != RET_OK) {
938 MMI_HILOGE("Get pointer speed failed, return:%{public}d", ret);
939 return ret;
940 }
941 #endif // OHOS_BUILD_ENABLE_POINTER
942 return RET_OK;
943 }
944
NotifyNapOnline()945 int32_t MMIService::NotifyNapOnline()
946 {
947 CALL_DEBUG_ENTER;
948 NapProcess::GetInstance()->NotifyNapOnline();
949 return RET_OK;
950 }
951
RemoveInputEventObserver()952 int32_t MMIService::RemoveInputEventObserver()
953 {
954 CALL_DEBUG_ENTER;
955 NapProcess::GetInstance()->RemoveInputEventObserver();
956 return RET_OK;
957 }
958
SetPointerStyle(int32_t windowId,PointerStyle pointerStyle,bool isUiExtension)959 int32_t MMIService::SetPointerStyle(int32_t windowId, PointerStyle pointerStyle, bool isUiExtension)
960 {
961 CALL_INFO_TRACE;
962 #ifdef OHOS_BUILD_ENABLE_POINTER
963 int32_t clientPid = GetCallingPid();
964 int32_t ret = delegateTasks_.PostSyncTask(
965 [clientPid, windowId, pointerStyle, isUiExtension] {
966 return IPointerDrawingManager::GetInstance()->SetPointerStyle(
967 clientPid, windowId, pointerStyle, isUiExtension);
968 }
969 );
970 if (ret != RET_OK) {
971 MMI_HILOGE("Set pointer style failed, return:%{public}d", ret);
972 return ret;
973 }
974 #endif // OHOS_BUILD_ENABLE_POINTER
975 return RET_OK;
976 }
977
ClearWindowPointerStyle(int32_t pid,int32_t windowId)978 int32_t MMIService::ClearWindowPointerStyle(int32_t pid, int32_t windowId)
979 {
980 CALL_DEBUG_ENTER;
981 #ifdef OHOS_BUILD_ENABLE_POINTER
982 int32_t ret = CheckPidPermission(pid);
983 if (ret != RET_OK) {
984 MMI_HILOGE("Check pid permission failed");
985 return ret;
986 }
987 ret = delegateTasks_.PostSyncTask(
988 [pid, windowId] {
989 return IPointerDrawingManager::GetInstance()->ClearWindowPointerStyle(pid, windowId);
990 }
991 );
992 if (ret != RET_OK) {
993 MMI_HILOGE("Set pointer style failed, return:%{public}d", ret);
994 return ret;
995 }
996 #endif // OHOS_BUILD_ENABLE_POINTER
997 return RET_OK;
998 }
999
GetPointerStyle(int32_t windowId,PointerStyle & pointerStyle,bool isUiExtension)1000 int32_t MMIService::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension)
1001 {
1002 CALL_DEBUG_ENTER;
1003 #ifdef OHOS_BUILD_ENABLE_POINTER
1004 int32_t clientPid = GetCallingPid();
1005 int32_t ret = delegateTasks_.PostSyncTask(
1006 [clientPid, windowId, &pointerStyle, isUiExtension] {
1007 return IPointerDrawingManager::GetInstance()->GetPointerStyle(
1008 clientPid, windowId, pointerStyle, isUiExtension);
1009 }
1010 );
1011 if (ret != RET_OK) {
1012 MMI_HILOGE("Get pointer style failed, return:%{public}d", ret);
1013 return ret;
1014 }
1015 #endif // OHOS_BUILD_ENABLE_POINTER
1016 return RET_OK;
1017 }
1018
SetHoverScrollState(bool state)1019 int32_t MMIService::SetHoverScrollState(bool state)
1020 {
1021 CALL_INFO_TRACE;
1022 #if defined OHOS_BUILD_ENABLE_POINTER
1023 int32_t ret = delegateTasks_.PostSyncTask(
1024 [state] {
1025 return ::OHOS::MMI::IInputWindowsManager::GetInstance()->SetHoverScrollState(state);
1026 }
1027 );
1028 if (ret != RET_OK) {
1029 MMI_HILOGE("Set mouse hover scroll state failed, return:%{public}d", ret);
1030 return ret;
1031 }
1032 #endif // OHOS_BUILD_ENABLE_POINTER
1033 return RET_OK;
1034 }
1035
1036 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadHoverScrollState(bool & state)1037 int32_t MMIService::ReadHoverScrollState(bool &state)
1038 {
1039 state = WIN_MGR->GetHoverScrollState();
1040 return RET_OK;
1041 }
1042 #endif // OHOS_BUILD_ENABLE_POINTER
1043
GetHoverScrollState(bool & state)1044 int32_t MMIService::GetHoverScrollState(bool &state)
1045 {
1046 CALL_INFO_TRACE;
1047 #ifdef OHOS_BUILD_ENABLE_POINTER
1048 int32_t ret = delegateTasks_.PostSyncTask(
1049 [this, &state] {
1050 return this->ReadHoverScrollState(state);
1051 }
1052 );
1053 if (ret != RET_OK) {
1054 MMI_HILOGE("Get mouse hover scroll state, return:%{public}d", ret);
1055 return ret;
1056 }
1057 #endif // OHOS_BUILD_ENABLE_POINTER
1058 return RET_OK;
1059 }
1060
OnSupportKeys(int32_t deviceId,std::vector<int32_t> & keys,std::vector<bool> & keystroke)1061 int32_t MMIService::OnSupportKeys(int32_t deviceId, std::vector<int32_t> &keys, std::vector<bool> &keystroke)
1062 {
1063 CALL_DEBUG_ENTER;
1064 int32_t ret = INPUT_DEV_MGR->SupportKeys(deviceId, keys, keystroke);
1065 if (ret != RET_OK) {
1066 MMI_HILOGE("Device id not support");
1067 return ret;
1068 }
1069 if (keystroke.size() > MAX_SUPPORT_KEY) {
1070 MMI_HILOGE("Device exceeds the max range");
1071 return RET_ERR;
1072 }
1073 return RET_OK;
1074 }
1075
SupportKeys(int32_t deviceId,std::vector<int32_t> & keys,std::vector<bool> & keystroke)1076 int32_t MMIService::SupportKeys(int32_t deviceId, std::vector<int32_t> &keys, std::vector<bool> &keystroke)
1077 {
1078 CALL_DEBUG_ENTER;
1079 int32_t ret = delegateTasks_.PostSyncTask(
1080 [this, deviceId, &keys, &keystroke] {
1081 return this->OnSupportKeys(deviceId, keys, keystroke);
1082 }
1083 );
1084 if (ret != RET_OK) {
1085 MMI_HILOGE("Support keys info process failed, ret:%{public}d", ret);
1086 return ret;
1087 }
1088 return RET_OK;
1089 }
1090
OnGetDeviceIds(std::vector<int32_t> & ids)1091 int32_t MMIService::OnGetDeviceIds(std::vector<int32_t> &ids)
1092 {
1093 CALL_DEBUG_ENTER;
1094 ids = INPUT_DEV_MGR->GetInputDeviceIds();
1095 return RET_OK;
1096 }
1097
GetDeviceIds(std::vector<int32_t> & ids)1098 int32_t MMIService::GetDeviceIds(std::vector<int32_t> &ids)
1099 {
1100 CALL_DEBUG_ENTER;
1101 int32_t ret = delegateTasks_.PostSyncTask(
1102 [this, &ids] {
1103 return this->OnGetDeviceIds(ids);
1104 }
1105 );
1106 if (ret != RET_OK) {
1107 MMI_HILOGE("Get deviceids failed, ret:%{public}d", ret);
1108 return ret;
1109 }
1110 return RET_OK;
1111 }
1112
OnGetDevice(int32_t deviceId,std::shared_ptr<InputDevice> & inputDevice)1113 int32_t MMIService::OnGetDevice(int32_t deviceId, std::shared_ptr<InputDevice> &inputDevice)
1114 {
1115 CALL_DEBUG_ENTER;
1116 if (INPUT_DEV_MGR->GetInputDevice(deviceId) == nullptr) {
1117 MMI_HILOGE("Input device not found");
1118 return COMMON_PARAMETER_ERROR;
1119 }
1120 inputDevice = INPUT_DEV_MGR->GetInputDevice(deviceId);
1121 return RET_OK;
1122 }
1123
GetDevice(int32_t deviceId,std::shared_ptr<InputDevice> & inputDevice)1124 int32_t MMIService::GetDevice(int32_t deviceId, std::shared_ptr<InputDevice> &inputDevice)
1125 {
1126 CALL_DEBUG_ENTER;
1127 int32_t ret = delegateTasks_.PostSyncTask(
1128 [this, deviceId, &inputDevice] {
1129 return this->OnGetDevice(deviceId, inputDevice);
1130 }
1131 );
1132 if (ret != RET_OK) {
1133 MMI_HILOGE("Get input device info failed, ret:%{public}d", ret);
1134 return ret;
1135 }
1136 return RET_OK;
1137 }
1138
OnRegisterDevListener(int32_t pid)1139 int32_t MMIService::OnRegisterDevListener(int32_t pid)
1140 {
1141 auto sess = GetSession(GetClientFd(pid));
1142 CHKPR(sess, RET_ERR);
1143 INPUT_DEV_MGR->AddDevListener(sess);
1144 return RET_OK;
1145 }
1146
RegisterDevListener()1147 int32_t MMIService::RegisterDevListener()
1148 {
1149 CALL_DEBUG_ENTER;
1150 int32_t pid = GetCallingPid();
1151 int32_t ret = delegateTasks_.PostSyncTask(
1152 [this, pid] {
1153 return this->OnRegisterDevListener(pid);
1154 }
1155 );
1156 if (ret != RET_OK) {
1157 MMI_HILOGE("Register device listener failed, ret:%{public}d", ret);
1158 return ret;
1159 }
1160 return RET_OK;
1161 }
1162
OnUnregisterDevListener(int32_t pid)1163 int32_t MMIService::OnUnregisterDevListener(int32_t pid)
1164 {
1165 auto sess = GetSession(GetClientFd(pid));
1166 INPUT_DEV_MGR->RemoveDevListener(sess);
1167 return RET_OK;
1168 }
1169
UnregisterDevListener()1170 int32_t MMIService::UnregisterDevListener()
1171 {
1172 CALL_DEBUG_ENTER;
1173 int32_t pid = GetCallingPid();
1174 int32_t ret = delegateTasks_.PostSyncTask(
1175 [this, pid] {
1176 return this->OnUnregisterDevListener(pid);
1177 }
1178 );
1179 if (ret != RET_OK) {
1180 MMI_HILOGE("Unregister device listener failed failed, ret:%{public}d", ret);
1181 return ret;
1182 }
1183 return RET_OK;
1184 }
1185
OnGetKeyboardType(int32_t deviceId,int32_t & keyboardType)1186 int32_t MMIService::OnGetKeyboardType(int32_t deviceId, int32_t &keyboardType)
1187 {
1188 CALL_DEBUG_ENTER;
1189 int32_t ret = INPUT_DEV_MGR->GetKeyboardType(deviceId, keyboardType);
1190 if (ret != RET_OK) {
1191 MMI_HILOGD("GetKeyboardType call failed");
1192 return ret;
1193 }
1194 return RET_OK;
1195 }
1196
GetKeyboardType(int32_t deviceId,int32_t & keyboardType)1197 int32_t MMIService::GetKeyboardType(int32_t deviceId, int32_t &keyboardType)
1198 {
1199 CALL_DEBUG_ENTER;
1200 int32_t ret = delegateTasks_.PostSyncTask(
1201 [this, deviceId, &keyboardType] {
1202 return this->OnGetKeyboardType(deviceId, keyboardType);
1203 }
1204 );
1205 if (ret != RET_OK) {
1206 MMI_HILOGD("Get keyboard type failed, ret:%{public}d", ret);
1207 return ret;
1208 }
1209 return ret;
1210 }
1211
SetKeyboardRepeatDelay(int32_t delay)1212 int32_t MMIService::SetKeyboardRepeatDelay(int32_t delay)
1213 {
1214 CALL_INFO_TRACE;
1215 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1216 int32_t ret = delegateTasks_.PostSyncTask(
1217 [delay] {
1218 return ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance()->SetKeyboardRepeatDelay(delay);
1219 }
1220 );
1221 if (ret != RET_OK) {
1222 MMI_HILOGE("Set keyboard repeat delay failed, ret:%{public}d", ret);
1223 return ret;
1224 }
1225 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1226 return RET_OK;
1227 }
1228
SetKeyboardRepeatRate(int32_t rate)1229 int32_t MMIService::SetKeyboardRepeatRate(int32_t rate)
1230 {
1231 CALL_INFO_TRACE;
1232 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1233 int32_t ret = delegateTasks_.PostSyncTask(
1234 [rate] {
1235 return ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance()->SetKeyboardRepeatRate(rate);
1236 }
1237 );
1238 if (ret != RET_OK) {
1239 MMI_HILOGE("Set keyboard repeat rate failed, ret:%{public}d", ret);
1240 return ret;
1241 }
1242 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1243 return RET_OK;
1244 }
1245
GetKeyboardRepeatDelay(int32_t & delay)1246 int32_t MMIService::GetKeyboardRepeatDelay(int32_t &delay)
1247 {
1248 CALL_INFO_TRACE;
1249 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1250 int32_t ret = delegateTasks_.PostSyncTask(
1251 [&delay] {
1252 return ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance()->GetKeyboardRepeatDelay(delay);
1253 }
1254 );
1255 if (ret != RET_OK) {
1256 MMI_HILOGE("Get keyboard repeat delay failed, ret:%{public}d", ret);
1257 return ret;
1258 }
1259 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1260 return RET_OK;
1261 }
1262
GetKeyboardRepeatRate(int32_t & rate)1263 int32_t MMIService::GetKeyboardRepeatRate(int32_t &rate)
1264 {
1265 CALL_INFO_TRACE;
1266 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1267 int32_t ret = delegateTasks_.PostSyncTask(
1268 [&rate] {
1269 return ::OHOS::DelayedSingleton<KeyAutoRepeat>::GetInstance()->GetKeyboardRepeatRate(rate);
1270 }
1271 );
1272 if (ret != RET_OK) {
1273 MMI_HILOGE("Get keyboard repeat rate failed, ret:%{public}d", ret);
1274 return ret;
1275 }
1276 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1277 return RET_OK;
1278 }
1279
1280 #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)1281 int32_t MMIService::CheckAddInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType,
1282 int32_t priority, uint32_t deviceTags)
1283 {
1284 auto sess = GetSessionByPid(pid);
1285 CHKPR(sess, ERROR_NULL_POINTER);
1286 return sMsgHandler_.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1287 }
1288 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
1289
AddInputHandler(InputHandlerType handlerType,HandleEventType eventType,int32_t priority,uint32_t deviceTags)1290 int32_t MMIService::AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority,
1291 uint32_t deviceTags)
1292 {
1293 CALL_INFO_TRACE;
1294 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
1295 int32_t pid = GetCallingPid();
1296 int32_t ret = delegateTasks_.PostSyncTask(
1297 [this, pid, handlerType, eventType, priority, deviceTags] {
1298 return this->CheckAddInput(pid, handlerType, eventType, priority, deviceTags);
1299 }
1300 );
1301 if (ret != RET_OK) {
1302 MMI_HILOGE("Add input handler failed, ret:%{public}d", ret);
1303 return ret;
1304 }
1305 if (NapProcess::GetInstance()->GetNapClientPid() != REMOVE_OBSERVER) {
1306 OHOS::MMI::NapProcess::NapStatusData napData;
1307 napData.pid = GetCallingPid();
1308 napData.uid = GetCallingUid();
1309 auto sess = GetSessionByPid(pid);
1310 CHKPR(sess, ERROR_NULL_POINTER);
1311 napData.bundleName = sess->GetProgramName();
1312 int32_t syncState = SUBSCRIBED;
1313 MMI_HILOGD("AddInputHandler info to observer : pid:%{public}d, uid:%d, bundleName:%{public}s",
1314 napData.pid, napData.uid, napData.bundleName.c_str());
1315 NapProcess::GetInstance()->AddMmiSubscribedEventData(napData, syncState);
1316 if (NapProcess::GetInstance()->GetNapClientPid() != UNOBSERVED) {
1317 NapProcess::GetInstance()->NotifyBundleName(napData, syncState);
1318 }
1319 }
1320 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
1321 return RET_OK;
1322 }
1323
1324 #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)1325 int32_t MMIService::CheckRemoveInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType,
1326 int32_t priority, uint32_t deviceTags)
1327 {
1328 auto sess = GetSessionByPid(pid);
1329 CHKPR(sess, ERROR_NULL_POINTER);
1330 return sMsgHandler_.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
1331 }
1332 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
1333
RemoveInputHandler(InputHandlerType handlerType,HandleEventType eventType,int32_t priority,uint32_t deviceTags)1334 int32_t MMIService::RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority,
1335 uint32_t deviceTags)
1336 {
1337 CALL_INFO_TRACE;
1338 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
1339 int32_t pid = GetCallingPid();
1340 int32_t ret = delegateTasks_.PostSyncTask(
1341 [this, pid, handlerType, eventType, priority, deviceTags] {
1342 return this->CheckRemoveInput(pid, handlerType, eventType, priority, deviceTags);
1343 }
1344 );
1345 if (ret != RET_OK) {
1346 MMI_HILOGE("Remove input handler failed, ret:%{public}d", ret);
1347 return ret;
1348 }
1349 if (NapProcess::GetInstance()->GetNapClientPid() != REMOVE_OBSERVER) {
1350 OHOS::MMI::NapProcess::NapStatusData napData;
1351 napData.pid = GetCallingPid();
1352 napData.uid = GetCallingUid();
1353 auto sess = GetSessionByPid(pid);
1354 CHKPR(sess, ERROR_NULL_POINTER);
1355 napData.bundleName = sess->GetProgramName();
1356 int32_t syncState = UNSUBSCRIBED;
1357 MMI_HILOGD("RemoveInputHandler info to observer : pid:%{public}d, uid:%{public}d, bundleName:%{public}s",
1358 napData.pid, napData.uid, napData.bundleName.c_str());
1359 NapProcess::GetInstance()->AddMmiSubscribedEventData(napData, syncState);
1360 if (NapProcess::GetInstance()->GetNapClientPid() != UNOBSERVED) {
1361 NapProcess::GetInstance()->NotifyBundleName(napData, syncState);
1362 }
1363 }
1364 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
1365 return RET_OK;
1366 }
1367
1368 #ifdef OHOS_BUILD_ENABLE_MONITOR
CheckMarkConsumed(int32_t pid,int32_t eventId)1369 int32_t MMIService::CheckMarkConsumed(int32_t pid, int32_t eventId)
1370 {
1371 auto sess = GetSessionByPid(pid);
1372 CHKPR(sess, ERROR_NULL_POINTER);
1373 return sMsgHandler_.OnMarkConsumed(sess, eventId);
1374 }
1375 #endif // OHOS_BUILD_ENABLE_MONITOR
1376
MarkEventConsumed(int32_t eventId)1377 int32_t MMIService::MarkEventConsumed(int32_t eventId)
1378 {
1379 CALL_DEBUG_ENTER;
1380 #ifdef OHOS_BUILD_ENABLE_MONITOR
1381 int32_t pid = GetCallingPid();
1382 int32_t ret = delegateTasks_.PostSyncTask(
1383 [this, pid, eventId] {
1384 return this->CheckMarkConsumed(pid, eventId);
1385 }
1386 );
1387 if (ret != RET_OK) {
1388 MMI_HILOGE("Mark event consumed failed, ret:%{public}d", ret);
1389 return ret;
1390 }
1391 #endif // OHOS_BUILD_ENABLE_MONITOR
1392 return RET_OK;
1393 }
1394
MoveMouseEvent(int32_t offsetX,int32_t offsetY)1395 int32_t MMIService::MoveMouseEvent(int32_t offsetX, int32_t offsetY)
1396 {
1397 CALL_DEBUG_ENTER;
1398 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1399 int32_t ret =
1400 delegateTasks_.PostSyncTask(
1401 [this, offsetX, offsetY] {
1402 return sMsgHandler_.OnMoveMouse(offsetX, offsetY);
1403 }
1404 );
1405 if (ret != RET_OK) {
1406 MMI_HILOGE("The movemouse event processed failed, ret:%{public}d", ret);
1407 return ret;
1408 }
1409 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1410 return RET_OK;
1411 }
1412
InjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent,bool isNativeInject)1413 int32_t MMIService::InjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent, bool isNativeInject)
1414 {
1415 CALL_DEBUG_ENTER;
1416 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1417 int32_t ret;
1418 int32_t pid = GetCallingPid();
1419 #ifdef OHOS_BUILD_ENABLE_ANCO
1420 ret = InjectKeyEventExt(keyEvent, pid, isNativeInject);
1421 #else
1422 ret = delegateTasks_.PostSyncTask(
1423 [this, keyEvent, pid, isNativeInject] {
1424 return this->CheckInjectKeyEvent(keyEvent, pid, isNativeInject);
1425 }
1426 );
1427 #endif // OHOS_BUILD_ENABLE_ANCO
1428 if (ret != RET_OK) {
1429 MMI_HILOGE("Inject key event failed, ret:%{public}d", ret);
1430 return ret;
1431 }
1432 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1433 return RET_OK;
1434 }
1435
CheckInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent,int32_t pid,bool isNativeInject)1436 int32_t MMIService::CheckInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent, int32_t pid, bool isNativeInject)
1437 {
1438 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1439 CHKPR(keyEvent, ERROR_NULL_POINTER);
1440 LogTracer lt(keyEvent->GetId(), keyEvent->GetEventType(), keyEvent->GetKeyAction());
1441 return sMsgHandler_.OnInjectKeyEvent(keyEvent, pid, isNativeInject);
1442 #else
1443 return RET_OK;
1444 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1445 }
1446
1447 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
OnGetKeyState(std::vector<int32_t> & pressedKeys,std::map<int32_t,int32_t> & specialKeysState)1448 int32_t MMIService::OnGetKeyState(std::vector<int32_t> &pressedKeys, std::map<int32_t, int32_t> &specialKeysState)
1449 {
1450 auto keyEvent = KeyEventHdr->GetKeyEvent();
1451 CHKPR(keyEvent, ERROR_NULL_POINTER);
1452 pressedKeys = keyEvent->GetPressedKeys();
1453 for (auto iter = pressedKeys.begin(); iter != pressedKeys.end();) {
1454 if (g_keyCodeValueSet.find(*iter) == g_keyCodeValueSet.end()) {
1455 iter = pressedKeys.erase(iter);
1456 continue;
1457 }
1458 ++iter;
1459 }
1460 specialKeysState[KeyEvent::KEYCODE_CAPS_LOCK] =
1461 static_cast<int32_t>(keyEvent->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY));
1462 specialKeysState[KeyEvent::KEYCODE_SCROLL_LOCK] =
1463 static_cast<int32_t>(keyEvent->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY));
1464 specialKeysState[KeyEvent::KEYCODE_NUM_LOCK] =
1465 static_cast<int32_t>(keyEvent->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY));
1466 return RET_OK;
1467 }
1468 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1469
CheckInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent,int32_t pid,bool isNativeInject,bool isShell)1470 int32_t MMIService::CheckInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent,
1471 int32_t pid, bool isNativeInject, bool isShell)
1472 {
1473 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
1474 CHKPR(pointerEvent, ERROR_NULL_POINTER);
1475 LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction());
1476 return sMsgHandler_.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, isShell);
1477 #else
1478 return RET_OK;
1479 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
1480 }
1481
InjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent,bool isNativeInject)1482 int32_t MMIService::InjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent, bool isNativeInject)
1483 {
1484 CALL_DEBUG_ENTER;
1485 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
1486 int32_t ret;
1487 int32_t pid = GetCallingPid();
1488 bool isShell = PER_HELPER->RequestFromShell();
1489 #ifdef OHOS_BUILD_ENABLE_ANCO
1490 ret = InjectPointerEventExt(pointerEvent, pid, isNativeInject, isShell);
1491 #else
1492 ret = delegateTasks_.PostSyncTask(
1493 [this, pointerEvent, pid, isNativeInject, isShell] {
1494 return this->CheckInjectPointerEvent(pointerEvent, pid, isNativeInject, isShell);
1495 }
1496 );
1497 #endif // OHOS_BUILD_ENABLE_ANCO
1498 if (ret != RET_OK) {
1499 MMI_HILOGE("Inject pointer event failed, ret:%{public}d", ret);
1500 return ret;
1501 }
1502 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
1503 return RET_OK;
1504 }
1505
1506 #ifdef OHOS_RSS_CLIENT
OnAddResSchedSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1507 void MMIService::OnAddResSchedSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
1508 {
1509 int sleepSeconds = 1;
1510 sleep(sleepSeconds);
1511 uint64_t tid = tid_.load();
1512 int32_t userInteraction = 2;
1513 std::unordered_map<std::string, std::string> payload;
1514 payload["uid"] = std::to_string(getuid());
1515 payload["pid"] = std::to_string(getpid());
1516 payload["extType"] = "10002";
1517 payload["tid"] = std::to_string(tid);
1518 payload["isSa"] = "1";
1519 payload["cgroupPrio"] = "1";
1520 payload["threadName"] = "mmi_service";
1521 ResourceSchedule::ResSchedClient::GetInstance().ReportData(
1522 ResourceSchedule::ResType::RES_TYPE_KEY_PERF_SCENE, userInteraction, payload);
1523 }
1524 #endif // OHOS_RSS_CLIENT
1525
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1526 void MMIService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
1527 {
1528 CALL_INFO_TRACE;
1529 MMI_HILOGI("systemAbilityId is %{public}d", systemAbilityId);
1530 #ifdef OHOS_RSS_CLIENT
1531 if (systemAbilityId == RES_SCHED_SYS_ABILITY_ID) {
1532 OnAddResSchedSystemAbility(systemAbilityId, deviceId);
1533 }
1534 #endif // OHOS_RSS_CLIENT
1535 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
1536 if (systemAbilityId == COMMON_EVENT_SERVICE_ID) {
1537 isCesStart_ = true;
1538 }
1539 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
1540 if (systemAbilityId == APP_MGR_SERVICE_ID) {
1541 APP_OBSERVER_MGR->InitAppStateObserver();
1542 }
1543 if (systemAbilityId == COMMON_EVENT_SERVICE_ID) {
1544 DEVICE_MONITOR->InitCommonEventSubscriber();
1545 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER)
1546 DISPLAY_MONITOR->InitCommonEventSubscriber();
1547 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
1548 }
1549 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1550 if (systemAbilityId == RENDER_SERVICE) {
1551 IPointerDrawingManager::GetInstance()->InitPointerCallback();
1552 }
1553 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1554 if (systemAbilityId == DISPLAY_MANAGER_SERVICE_SA_ID) {
1555 WIN_MGR->SetFoldState();
1556 }
1557 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1558 if (systemAbilityId == DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID) {
1559 if (SettingDataShare::GetInstance(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID).CheckIfSettingsDataReady()) {
1560 IPointerDrawingManager::GetInstance()->InitPointerObserver();
1561 auto keyHandler = InputHandler->GetKeyCommandHandler();
1562 if (keyHandler != nullptr) {
1563 keyHandler->InitKeyObserver();
1564 }
1565 }
1566 }
1567 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1568 #if defined(OHOS_BUILD_ENABLE_MONITOR) && defined(PLAYER_FRAMEWORK_EXISTS)
1569 if (systemAbilityId == PLAYER_DISTRIBUTED_SERVICE_ID) {
1570 auto monitorHandler = InputHandler->GetMonitorHandler();
1571 CHKPV(monitorHandler);
1572 monitorHandler->RegisterScreenCaptureListener();
1573 }
1574 #endif
1575 }
1576
SubscribeKeyEvent(int32_t subscribeId,const std::shared_ptr<KeyOption> option)1577 int32_t MMIService::SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr<KeyOption> option)
1578 {
1579 CALL_DEBUG_ENTER;
1580 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1581 int32_t pid = GetCallingPid();
1582 int32_t ret = delegateTasks_.PostSyncTask(
1583 [this, pid, subscribeId, option] {
1584 return sMsgHandler_.OnSubscribeKeyEvent(this, pid, subscribeId, option);
1585 }
1586 );
1587 if (ret != RET_OK) {
1588 MMI_HILOGE("The subscribe key event processed failed, ret:%{public}d", ret);
1589 return ret;
1590 }
1591 if (NapProcess::GetInstance()->GetNapClientPid() != REMOVE_OBSERVER) {
1592 OHOS::MMI::NapProcess::NapStatusData napData;
1593 napData.pid = GetCallingPid();
1594 napData.uid = GetCallingUid();
1595 auto sess = GetSessionByPid(pid);
1596 CHKPR(sess, ERROR_NULL_POINTER);
1597 napData.bundleName = sess->GetProgramName();
1598 int32_t syncState = SUBSCRIBED;
1599 MMI_HILOGD("SubscribeKeyEvent info to observer : pid:%{public}d, uid:%{public}d, bundleName:%{public}s",
1600 napData.pid, napData.uid, napData.bundleName.c_str());
1601 NapProcess::GetInstance()->AddMmiSubscribedEventData(napData, syncState);
1602 if (NapProcess::GetInstance()->GetNapClientPid() != UNOBSERVED) {
1603 NapProcess::GetInstance()->NotifyBundleName(napData, syncState);
1604 }
1605 }
1606 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1607 return RET_OK;
1608 }
1609
UnsubscribeKeyEvent(int32_t subscribeId)1610 int32_t MMIService::UnsubscribeKeyEvent(int32_t subscribeId)
1611 {
1612 CALL_INFO_TRACE;
1613 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1614 int32_t pid = GetCallingPid();
1615 int32_t ret = delegateTasks_.PostSyncTask(
1616 [this, pid, subscribeId] {
1617 return sMsgHandler_.OnUnsubscribeKeyEvent(this, pid, subscribeId);
1618 }
1619 );
1620 if (ret != RET_OK) {
1621 MMI_HILOGE("The unsubscribe key event processed failed, ret:%{public}d", ret);
1622 return ret;
1623 }
1624 if (NapProcess::GetInstance()->GetNapClientPid() != REMOVE_OBSERVER) {
1625 OHOS::MMI::NapProcess::NapStatusData napData;
1626 napData.pid = GetCallingPid();
1627 napData.uid = GetCallingUid();
1628 auto sess = GetSessionByPid(pid);
1629 CHKPR(sess, ERROR_NULL_POINTER);
1630 napData.bundleName = sess->GetProgramName();
1631 int32_t syncState = UNSUBSCRIBED;
1632 MMI_HILOGD("UnsubscribeKeyEvent info to observer : pid:%{public}d, uid:%{public}d, bundleName:%{public}s",
1633 napData.pid, napData.uid, napData.bundleName.c_str());
1634 NapProcess::GetInstance()->AddMmiSubscribedEventData(napData, syncState);
1635 if (NapProcess::GetInstance()->GetNapClientPid() != UNOBSERVED) {
1636 NapProcess::GetInstance()->NotifyBundleName(napData, syncState);
1637 }
1638 }
1639 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1640 return RET_OK;
1641 }
1642
SubscribeSwitchEvent(int32_t subscribeId,int32_t switchType)1643 int32_t MMIService::SubscribeSwitchEvent(int32_t subscribeId, int32_t switchType)
1644 {
1645 CALL_INFO_TRACE;
1646 #ifdef OHOS_BUILD_ENABLE_SWITCH
1647 int32_t pid = GetCallingPid();
1648 int32_t ret = delegateTasks_.PostSyncTask(
1649 [this, pid, subscribeId, switchType] {
1650 return sMsgHandler_.OnSubscribeSwitchEvent(this, pid, subscribeId, switchType);
1651 }
1652 );
1653 if (ret != RET_OK) {
1654 MMI_HILOGE("The subscribe switch event processed failed, ret:%{public}d", ret);
1655 return ret;
1656 }
1657 #endif // OHOS_BUILD_ENABLE_SWITCH
1658 return RET_OK;
1659 }
1660
UnsubscribeSwitchEvent(int32_t subscribeId)1661 int32_t MMIService::UnsubscribeSwitchEvent(int32_t subscribeId)
1662 {
1663 CALL_INFO_TRACE;
1664 #ifdef OHOS_BUILD_ENABLE_SWITCH
1665 int32_t pid = GetCallingPid();
1666 int32_t ret = delegateTasks_.PostSyncTask(
1667 [this, pid, subscribeId] {
1668 return sMsgHandler_.OnUnsubscribeSwitchEvent(this, pid, subscribeId);
1669 }
1670 );
1671 if (ret != RET_OK) {
1672 MMI_HILOGE("The unsubscribe switch event processed failed, ret:%{public}d", ret);
1673 return ret;
1674 }
1675 #endif // OHOS_BUILD_ENABLE_SWITCH
1676 return RET_OK;
1677 }
1678
SetAnrObserver()1679 int32_t MMIService::SetAnrObserver()
1680 {
1681 CALL_INFO_TRACE;
1682 int32_t pid = GetCallingPid();
1683 int32_t ret = delegateTasks_.PostSyncTask(
1684 [pid] {
1685 return ::OHOS::DelayedSingleton<ANRManager>::GetInstance()->SetANRNoticedPid(pid);
1686 }
1687 );
1688 if (ret != RET_OK) {
1689 MMI_HILOGE("Set ANRNoticed pid failed, ret:%{public}d", ret);
1690 return ret;
1691 }
1692 return RET_OK;
1693 }
1694
GetDisplayBindInfo(DisplayBindInfos & infos)1695 int32_t MMIService::GetDisplayBindInfo(DisplayBindInfos &infos)
1696 {
1697 CALL_INFO_TRACE;
1698 int32_t ret = delegateTasks_.PostSyncTask(
1699 [&infos] {
1700 return ::OHOS::MMI::IInputWindowsManager::GetInstance()->GetDisplayBindInfo(infos);
1701 }
1702 );
1703 if (ret != RET_OK) {
1704 MMI_HILOGE("GetDisplayBindInfo pid failed, ret:%{public}d", ret);
1705 return ret;
1706 }
1707 return RET_OK;
1708 }
1709
GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t,int32_t,std::string>,int32_t> & datas)1710 int32_t MMIService::GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas)
1711 {
1712 CALL_INFO_TRACE;
1713 NapProcess::GetInstance()->GetAllMmiSubscribedEvents(datas);
1714 return RET_OK;
1715 }
1716
SetDisplayBind(int32_t deviceId,int32_t displayId,std::string & msg)1717 int32_t MMIService::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg)
1718 {
1719 CALL_INFO_TRACE;
1720 int32_t ret = delegateTasks_.PostSyncTask(
1721 [deviceId, displayId, &msg] {
1722 return ::OHOS::MMI::IInputWindowsManager::GetInstance()->SetDisplayBind(deviceId, displayId, msg);
1723 }
1724 );
1725 if (ret != RET_OK) {
1726 MMI_HILOGE("SetDisplayBind pid failed, ret:%{public}d", ret);
1727 return ret;
1728 }
1729 return RET_OK;
1730 }
1731
GetFunctionKeyState(int32_t funcKey,bool & state)1732 int32_t MMIService::GetFunctionKeyState(int32_t funcKey, bool &state)
1733 {
1734 CALL_INFO_TRACE;
1735 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1736 int32_t ret = delegateTasks_.PostSyncTask(
1737 [this, funcKey, &state] {
1738 return sMsgHandler_.OnGetFunctionKeyState(funcKey, state);
1739 }
1740 );
1741 if (ret != RET_OK) {
1742 MMI_HILOGE("Failed to get the keyboard status, ret:%{public}d", ret);
1743 return ret;
1744 }
1745 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1746 return RET_OK;
1747 }
1748
SetFunctionKeyState(int32_t funcKey,bool enable)1749 int32_t MMIService::SetFunctionKeyState(int32_t funcKey, bool enable)
1750 {
1751 CALL_INFO_TRACE;
1752 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
1753 int32_t ret = delegateTasks_.PostSyncTask(
1754 [this, funcKey, enable] {
1755 return sMsgHandler_.OnSetFunctionKeyState(funcKey, enable);
1756 }
1757 );
1758 if (ret != RET_OK) {
1759 MMI_HILOGE("Failed to update the keyboard status, ret:%{public}d", ret);
1760 return ret;
1761 }
1762 #endif // OHOS_BUILD_ENABLE_KEYBOARD
1763 return RET_OK;
1764 }
1765
SetPointerLocation(int32_t x,int32_t y)1766 int32_t MMIService::SetPointerLocation(int32_t x, int32_t y)
1767 {
1768 CALL_INFO_TRACE;
1769 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
1770 int32_t ret = delegateTasks_.PostSyncTask(
1771 [x, y] {
1772 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetPointerLocation(x, y);
1773 }
1774 );
1775 if (ret != RET_OK) {
1776 MMI_HILOGE("Set pointer location failed, ret:%{public}d", ret);
1777 return ret;
1778 }
1779 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
1780 return RET_OK;
1781 }
1782
OnDelegateTask(epoll_event & ev)1783 void MMIService::OnDelegateTask(epoll_event &ev)
1784 {
1785 if ((ev.events & EPOLLIN) == 0) {
1786 MMI_HILOGW("Not epollin");
1787 return;
1788 }
1789 DelegateTasks::TaskData data = {};
1790 auto res = read(delegateTasks_.GetReadFd(), &data, sizeof(data));
1791 if (res == -1) {
1792 MMI_HILOGW("Read failed erron:%{public}d", errno);
1793 }
1794 MMI_HILOGD("RemoteRequest notify td:%{public}" PRId64 ",std:%{public}" PRId64 ""
1795 ",taskId:%{public}d",
1796 GetThisThreadId(), data.tid, data.taskId);
1797 delegateTasks_.ProcessTasks();
1798 }
1799
OnThread()1800 void MMIService::OnThread()
1801 {
1802 SetThreadName(std::string("mmi_service"));
1803 uint64_t tid = GetThisThreadId();
1804 delegateTasks_.SetWorkerThreadId(tid);
1805 MMI_HILOGI("Main worker thread start. tid:%{public}" PRId64 "", tid);
1806 #ifdef OHOS_RSS_CLIENT
1807 tid_.store(tid);
1808 #endif
1809 libinputAdapter_.ProcessPendingEvents();
1810 while (state_ == ServiceRunningState::STATE_RUNNING) {
1811 #if defined(OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER) && defined(OHOS_BUILD_ENABLE_KEYBOARD)
1812 if (isCesStart_ && !DISPLAY_MONITOR->IsCommonEventSubscriberInit()) {
1813 DISPLAY_MONITOR->InitCommonEventSubscriber();
1814 }
1815 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER && OHOS_BUILD_ENABLE_KEYBOARD
1816 epoll_event ev[MAX_EVENT_SIZE] = {};
1817 int32_t timeout = TimerMgr->CalcNextDelay();
1818 MMI_HILOGD("timeout:%{public}d", timeout);
1819 int32_t count = EpollWait(ev[0], MAX_EVENT_SIZE, timeout, mmiFd_);
1820 for (int32_t i = 0; i < count && state_ == ServiceRunningState::STATE_RUNNING; i++) {
1821 auto mmiEdIter = epollEventMap_.find(ev[i].data.fd);
1822 if (mmiEdIter == epollEventMap_.end()) {
1823 MMI_HILOGW("Invalid event %{public}d %{public}d", ev[i].data.fd, count);
1824 continue;
1825 }
1826 std::shared_ptr<mmi_epoll_event> mmiEd = mmiEdIter->second;
1827 CHKPC(mmiEd);
1828 epoll_event event = ev[i];
1829 if (mmiEd->event_type == EPOLL_EVENT_INPUT) {
1830 CalculateFuntionRunningTime([this, &mmiEd] () { libinputAdapter_.EventDispatch(mmiEd->fd); },
1831 "EPOLL_EVENT_INPUT");
1832 } else if (mmiEd->event_type == EPOLL_EVENT_SOCKET) {
1833 CalculateFuntionRunningTime([this, &event]() { this->OnEpollEvent(event); }, "EPOLL_EVENT_SOCKET");
1834 } else if (mmiEd->event_type == EPOLL_EVENT_SIGNAL) {
1835 OnSignalEvent(mmiEd->fd);
1836 } else if (mmiEd->event_type == EPOLL_EVENT_ETASK) {
1837 CalculateFuntionRunningTime([this, &event]() { this->OnDelegateTask(event); }, "EPOLL_EVENT_ETASK");
1838 } else {
1839 MMI_HILOGW("Unknown epoll event type:%{public}d", mmiEd->event_type);
1840 }
1841 }
1842 TimerMgr->ProcessTimers();
1843 if (state_ != ServiceRunningState::STATE_RUNNING) {
1844 break;
1845 }
1846 }
1847 MMI_HILOGI("Main worker thread stop. tid:%{public}" PRId64 "", tid);
1848 }
1849
InitSignalHandler()1850 bool MMIService::InitSignalHandler()
1851 {
1852 CALL_DEBUG_ENTER;
1853 sigset_t mask = { 0 };
1854 int32_t retCode = sigfillset(&mask);
1855 if (retCode < 0) {
1856 MMI_HILOGE("Fill signal set failed:%{public}d", errno);
1857 return false;
1858 }
1859
1860 retCode = sigprocmask(SIG_SETMASK, &mask, nullptr);
1861 if (retCode < 0) {
1862 MMI_HILOGE("Sigprocmask failed:%{public}d", errno);
1863 return false;
1864 }
1865
1866 int32_t fdSignal = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
1867 if (fdSignal < 0) {
1868 MMI_HILOGE("Signal fd failed:%{public}d", errno);
1869 return false;
1870 }
1871
1872 retCode = AddEpoll(EPOLL_EVENT_SIGNAL, fdSignal);
1873 if (retCode < 0) {
1874 MMI_HILOGE("AddEpoll signalFd failed:%{public}d", retCode);
1875 close(fdSignal);
1876 return false;
1877 }
1878 return true;
1879 }
1880
OnSignalEvent(int32_t signalFd)1881 void MMIService::OnSignalEvent(int32_t signalFd)
1882 {
1883 CALL_DEBUG_ENTER;
1884 signalfd_siginfo sigInfo;
1885 int32_t size = ::read(signalFd, &sigInfo, sizeof(signalfd_siginfo));
1886 if (size != static_cast<int32_t>(sizeof(signalfd_siginfo))) {
1887 MMI_HILOGE("Read signal info failed, invalid size:%{public}d, errno:%{public}d", size, errno);
1888 return;
1889 }
1890 int32_t signo = static_cast<int32_t>(sigInfo.ssi_signo);
1891 MMI_HILOGD("Receive signal:%{public}d", signo);
1892 switch (signo) {
1893 case SIGINT:
1894 case SIGQUIT:
1895 case SIGILL:
1896 case SIGABRT:
1897 case SIGBUS:
1898 case SIGFPE:
1899 case SIGKILL:
1900 case SIGSEGV:
1901 case SIGTERM: {
1902 state_ = ServiceRunningState::STATE_EXIT;
1903 break;
1904 }
1905 default: {
1906 break;
1907 }
1908 }
1909 }
1910
AddReloadDeviceTimer()1911 void MMIService::AddReloadDeviceTimer()
1912 {
1913 CALL_DEBUG_ENTER;
1914 TimerMgr->AddTimer(RELOAD_DEVICE_TIME, REPEAT_COUNT, [this]() {
1915 auto deviceIds = INPUT_DEV_MGR->GetInputDeviceIds();
1916 if (deviceIds.empty()) {
1917 libinputAdapter_.ReloadDevice();
1918 }
1919 });
1920 }
1921
Dump(int32_t fd,const std::vector<std::u16string> & args)1922 int32_t MMIService::Dump(int32_t fd, const std::vector<std::u16string> &args)
1923 {
1924 CALL_DEBUG_ENTER;
1925 if (fd < 0) {
1926 MMI_HILOGE("The fd is invalid");
1927 return DUMP_PARAM_ERR;
1928 }
1929 if (args.empty()) {
1930 MMI_HILOGE("The args cannot be empty");
1931 mprintf(fd, "args cannot be empty\n");
1932 MMIEventDump->DumpHelp(fd);
1933 return DUMP_PARAM_ERR;
1934 }
1935 std::vector<std::string> argList = { "" };
1936 std::transform(args.begin(), args.end(), std::back_inserter(argList),
1937 [](const std::u16string &arg) { return Str16ToStr8(arg); });
1938 MMIEventDump->ParseCommand(fd, argList);
1939 return RET_OK;
1940 }
1941
SetMouseCaptureMode(int32_t windowId,bool isCaptureMode)1942 int32_t MMIService::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode)
1943 {
1944 CALL_INFO_TRACE;
1945 int32_t ret = delegateTasks_.PostSyncTask(
1946 [windowId, isCaptureMode] {
1947 return ::OHOS::MMI::IInputWindowsManager::GetInstance()->SetMouseCaptureMode(windowId, isCaptureMode);
1948 }
1949 );
1950 if (ret != RET_OK) {
1951 MMI_HILOGE("Set capture failed, return:%{public}d", ret);
1952 return ret;
1953 }
1954 return RET_OK;
1955 }
1956
OnGetWindowPid(int32_t windowId,int32_t & windowPid)1957 int32_t MMIService::OnGetWindowPid(int32_t windowId, int32_t &windowPid)
1958 {
1959 CALL_DEBUG_ENTER;
1960 windowPid = WIN_MGR->GetWindowPid(windowId);
1961 if (windowPid == RET_ERR) {
1962 MMI_HILOGE("Get window pid failed");
1963 return RET_ERR;
1964 }
1965 MMI_HILOGD("windowpid is %{public}d", windowPid);
1966 return RET_OK;
1967 }
1968
GetWindowPid(int32_t windowId)1969 int32_t MMIService::GetWindowPid(int32_t windowId)
1970 {
1971 CALL_INFO_TRACE;
1972 int32_t windowPid = INVALID_PID;
1973 int32_t ret = delegateTasks_.PostSyncTask(
1974 [this, windowId, &windowPid] {
1975 return this->OnGetWindowPid(windowId, windowPid);
1976 }
1977 );
1978 if (ret != RET_OK) {
1979 MMI_HILOGE("OnGetWindowPid failed, ret:%{public}d", ret);
1980 return ret;
1981 }
1982 MMI_HILOGD("windowpid is %{public}d", windowPid);
1983 return windowPid;
1984 }
1985
AppendExtraData(const ExtraData & extraData)1986 int32_t MMIService::AppendExtraData(const ExtraData &extraData)
1987 {
1988 CALL_DEBUG_ENTER;
1989 int32_t ret = delegateTasks_.PostSyncTask(
1990 [extraData] {
1991 return ::OHOS::MMI::IInputWindowsManager::GetInstance()->AppendExtraData(extraData);
1992 }
1993 );
1994 if (ret != RET_OK) {
1995 MMI_HILOGE("Append extra data failed:%{public}d", ret);
1996 }
1997 return ret;
1998 }
1999
EnableInputDevice(bool enable)2000 int32_t MMIService::EnableInputDevice(bool enable)
2001 {
2002 CALL_DEBUG_ENTER;
2003 int32_t ret = delegateTasks_.PostSyncTask(
2004 [enable] {
2005 return ::OHOS::MMI::InputDeviceManager::GetInstance()->OnEnableInputDevice(enable);
2006 }
2007 );
2008 if (ret != RET_OK) {
2009 MMI_HILOGE("OnEnableInputDevice failed:%{public}d", ret);
2010 }
2011 return ret;
2012 }
2013
2014 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_COMBINATION_KEY)
UpdateCombineKeyState(bool enable)2015 int32_t MMIService::UpdateCombineKeyState(bool enable)
2016 {
2017 auto eventSubscriberHandler = InputHandler->GetSubscriberHandler();
2018 CHKPR(eventSubscriberHandler, RET_ERR);
2019 int32_t ret = eventSubscriberHandler->EnableCombineKey(enable);
2020 if (ret != RET_OK) {
2021 MMI_HILOGE("EnableCombineKey is failed in key command:%{public}d", ret);
2022 }
2023
2024 auto eventKeyCommandHandler = InputHandler->GetKeyCommandHandler();
2025 CHKPR(eventKeyCommandHandler, RET_ERR);
2026 ret = eventKeyCommandHandler->EnableCombineKey(enable);
2027 if (ret != RET_OK) {
2028 MMI_HILOGE("EnableCombineKey is failed in key command:%{public}d", ret);
2029 }
2030 return ret;
2031 }
2032 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_COMBINATION_KEY
2033
CheckPidPermission(int32_t pid)2034 int32_t MMIService::CheckPidPermission(int32_t pid)
2035 {
2036 CALL_DEBUG_ENTER;
2037 int32_t checkingPid = GetCallingPid();
2038 if (checkingPid != pid) {
2039 MMI_HILOGE("check pid failed, input pid:%{public}d, but checking pid:%{public}d", pid, checkingPid);
2040 return RET_ERR;
2041 }
2042 return RET_OK;
2043 }
2044
EnableCombineKey(bool enable)2045 int32_t MMIService::EnableCombineKey(bool enable)
2046 {
2047 CALL_DEBUG_ENTER;
2048 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_COMBINATION_KEY)
2049 int32_t ret = delegateTasks_.PostSyncTask(
2050 [this, enable] {
2051 return this->UpdateCombineKeyState(enable);
2052 }
2053 );
2054 if (ret != RET_OK) {
2055 MMI_HILOGE("Set key down duration failed:%{public}d", ret);
2056 return ret;
2057 }
2058 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_COMBINATION_KEY
2059 return RET_OK;
2060 }
2061
2062 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_COMBINATION_KEY)
UpdateSettingsXml(const std::string & businessId,int32_t delay)2063 int32_t MMIService::UpdateSettingsXml(const std::string &businessId, int32_t delay)
2064 {
2065 std::shared_ptr<KeyCommandHandler> eventKeyCommandHandler = InputHandler->GetKeyCommandHandler();
2066 CHKPR(eventKeyCommandHandler, RET_ERR);
2067 return eventKeyCommandHandler->UpdateSettingsXml(businessId, delay);
2068 }
2069 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_COMBINATION_KEY
2070
SetKeyDownDuration(const std::string & businessId,int32_t delay)2071 int32_t MMIService::SetKeyDownDuration(const std::string &businessId, int32_t delay)
2072 {
2073 CALL_INFO_TRACE;
2074 #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_COMBINATION_KEY)
2075 int32_t ret = delegateTasks_.PostSyncTask(
2076 [this, businessId, delay] {
2077 return this->UpdateSettingsXml(businessId, delay);
2078 }
2079 );
2080 if (ret != RET_OK) {
2081 MMI_HILOGE("Set key down duration failed:%{public}d", ret);
2082 return ret;
2083 }
2084 #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_COMBINATION_KEY
2085 return RET_OK;
2086 }
2087
2088 #ifdef OHOS_BUILD_ENABLE_POINTER
ReadTouchpadScrollSwich(bool & switchFlag)2089 int32_t MMIService::ReadTouchpadScrollSwich(bool &switchFlag)
2090 {
2091 MouseEventHdr->GetTouchpadScrollSwitch(switchFlag);
2092 return RET_OK;
2093 }
2094
ReadTouchpadScrollDirection(bool & switchFlag)2095 int32_t MMIService::ReadTouchpadScrollDirection(bool &switchFlag)
2096 {
2097 MouseEventHdr->GetTouchpadScrollDirection(switchFlag);
2098 return RET_OK;
2099 }
2100
ReadTouchpadTapSwitch(bool & switchFlag)2101 int32_t MMIService::ReadTouchpadTapSwitch(bool &switchFlag)
2102 {
2103 MouseEventHdr->GetTouchpadTapSwitch(switchFlag);
2104 return RET_OK;
2105 }
2106
ReadTouchpadPointerSpeed(int32_t & speed)2107 int32_t MMIService::ReadTouchpadPointerSpeed(int32_t &speed)
2108 {
2109 MouseEventHdr->GetTouchpadPointerSpeed(speed);
2110 return RET_OK;
2111 }
2112
ReadTouchpadPinchSwitch(bool & switchFlag)2113 int32_t MMIService::ReadTouchpadPinchSwitch(bool &switchFlag)
2114 {
2115 TOUCH_EVENT_HDR->GetTouchpadPinchSwitch(switchFlag);
2116 return RET_OK;
2117 }
2118
ReadTouchpadSwipeSwitch(bool & switchFlag)2119 int32_t MMIService::ReadTouchpadSwipeSwitch(bool &switchFlag)
2120 {
2121 TOUCH_EVENT_HDR->GetTouchpadSwipeSwitch(switchFlag);
2122 return RET_OK;
2123 }
2124
ReadTouchpadRightMenuType(int32_t & type)2125 int32_t MMIService::ReadTouchpadRightMenuType(int32_t &type)
2126 {
2127 MouseEventHdr->GetTouchpadRightClickType(type);
2128 return RET_OK;
2129 }
2130
ReadTouchpadRotateSwitch(bool & rotateSwitch)2131 int32_t MMIService::ReadTouchpadRotateSwitch(bool &rotateSwitch)
2132 {
2133 TOUCH_EVENT_HDR->GetTouchpadRotateSwitch(rotateSwitch);
2134 return RET_OK;
2135 }
2136
2137 #endif // OHOS_BUILD_ENABLE_POINTER
2138
SetTouchpadScrollSwitch(bool switchFlag)2139 int32_t MMIService::SetTouchpadScrollSwitch(bool switchFlag)
2140 {
2141 CALL_INFO_TRACE;
2142 #if defined OHOS_BUILD_ENABLE_POINTER
2143 int32_t ret = delegateTasks_.PostSyncTask(
2144 [switchFlag] {
2145 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetTouchpadScrollSwitch(switchFlag);
2146 }
2147 );
2148 if (ret != RET_OK) {
2149 MMI_HILOGE("Set touchpad scroll switch failed, return:%{public}d", ret);
2150 return ret;
2151 }
2152 #endif // OHOS_BUILD_ENABLE_POINTER
2153 return RET_OK;
2154 }
2155
GetTouchpadScrollSwitch(bool & switchFlag)2156 int32_t MMIService::GetTouchpadScrollSwitch(bool &switchFlag)
2157 {
2158 CALL_INFO_TRACE;
2159 #ifdef OHOS_BUILD_ENABLE_POINTER
2160 int32_t ret = delegateTasks_.PostSyncTask(
2161 [this, &switchFlag] {
2162 return this->ReadTouchpadScrollSwich(switchFlag);
2163 }
2164 );
2165 if (ret != RET_OK) {
2166 MMI_HILOGE("Get touchpad scroll switch failed, return:%{public}d", ret);
2167 return ret;
2168 }
2169 #endif // OHOS_BUILD_ENABLE_POINTER
2170 return RET_OK;
2171 }
2172
SetTouchpadScrollDirection(bool state)2173 int32_t MMIService::SetTouchpadScrollDirection(bool state)
2174 {
2175 CALL_INFO_TRACE;
2176 #if defined OHOS_BUILD_ENABLE_POINTER
2177 int32_t ret = delegateTasks_.PostSyncTask(
2178 [state] {
2179 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetTouchpadScrollDirection(state);
2180 }
2181 );
2182 if (ret != RET_OK) {
2183 MMI_HILOGE("Set touchpad scroll direction switch failed, return:%{public}d", ret);
2184 return ret;
2185 }
2186 #endif // OHOS_BUILD_ENABLE_POINTER
2187 return RET_OK;
2188 }
2189
GetTouchpadScrollDirection(bool & state)2190 int32_t MMIService::GetTouchpadScrollDirection(bool &state)
2191 {
2192 CALL_INFO_TRACE;
2193 #ifdef OHOS_BUILD_ENABLE_POINTER
2194 int32_t ret = delegateTasks_.PostSyncTask(
2195 [this, &state] {
2196 return this->ReadTouchpadScrollDirection(state);
2197 }
2198 );
2199 if (ret != RET_OK) {
2200 MMI_HILOGE("Get touchpad scroll direction switch failed, return:%{public}d", ret);
2201 return ret;
2202 }
2203 #endif // OHOS_BUILD_ENABLE_POINTER
2204 return RET_OK;
2205 }
2206
SetTouchpadTapSwitch(bool switchFlag)2207 int32_t MMIService::SetTouchpadTapSwitch(bool switchFlag)
2208 {
2209 CALL_INFO_TRACE;
2210 #if defined OHOS_BUILD_ENABLE_POINTER
2211 int32_t ret = delegateTasks_.PostSyncTask(
2212 [switchFlag] {
2213 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetTouchpadTapSwitch(switchFlag);
2214 }
2215 );
2216 if (ret != RET_OK) {
2217 MMI_HILOGE("Set touchpad tap switch failed, return:%{public}d", ret);
2218 return ret;
2219 }
2220 #endif // OHOS_BUILD_ENABLE_POINTER
2221 return RET_OK;
2222 }
2223
GetTouchpadTapSwitch(bool & switchFlag)2224 int32_t MMIService::GetTouchpadTapSwitch(bool &switchFlag)
2225 {
2226 CALL_INFO_TRACE;
2227 #ifdef OHOS_BUILD_ENABLE_POINTER
2228 int32_t ret = delegateTasks_.PostSyncTask(
2229 [this, &switchFlag] {
2230 return this->ReadTouchpadTapSwitch(switchFlag);
2231 }
2232 );
2233 if (ret != RET_OK) {
2234 MMI_HILOGE("Get touchpad tap switch failed, return:%{public}d", ret);
2235 return ret;
2236 }
2237 #endif // OHOS_BUILD_ENABLE_POINTER
2238 return RET_OK;
2239 }
2240
SetTouchpadPointerSpeed(int32_t speed)2241 int32_t MMIService::SetTouchpadPointerSpeed(int32_t speed)
2242 {
2243 CALL_INFO_TRACE;
2244 #if defined OHOS_BUILD_ENABLE_POINTER
2245 int32_t ret = delegateTasks_.PostSyncTask(
2246 [speed] {
2247 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetTouchpadPointerSpeed(speed);
2248 }
2249 );
2250 if (ret != RET_OK) {
2251 MMI_HILOGE("Set touchpad speed failed, return:%{public}d", ret);
2252 return ret;
2253 }
2254 #endif // OHOS_BUILD_ENABLE_POINTER
2255 return RET_OK;
2256 }
2257
GetTouchpadPointerSpeed(int32_t & speed)2258 int32_t MMIService::GetTouchpadPointerSpeed(int32_t &speed)
2259 {
2260 CALL_INFO_TRACE;
2261 #ifdef OHOS_BUILD_ENABLE_POINTER
2262 int32_t ret = delegateTasks_.PostSyncTask(
2263 [this, &speed] {
2264 return this->ReadTouchpadPointerSpeed(speed);
2265 }
2266 );
2267 if (ret != RET_OK) {
2268 MMI_HILOGE("Get touchpad speed failed, return:%{public}d", ret);
2269 return ret;
2270 }
2271 #endif // OHOS_BUILD_ENABLE_POINTER
2272 return RET_OK;
2273 }
2274
SetTouchpadPinchSwitch(bool switchFlag)2275 int32_t MMIService::SetTouchpadPinchSwitch(bool switchFlag)
2276 {
2277 CALL_INFO_TRACE;
2278 #if defined OHOS_BUILD_ENABLE_POINTER
2279 int32_t ret = delegateTasks_.PostSyncTask(
2280 [switchFlag] {
2281 return ::OHOS::DelayedSingleton<TouchEventNormalize>::GetInstance()->SetTouchpadPinchSwitch(switchFlag);
2282 }
2283 );
2284 if (ret != RET_OK) {
2285 MMI_HILOGE("Set touch pad pinch switch failed, return:%{public}d", ret);
2286 return ret;
2287 }
2288 #endif // OHOS_BUILD_ENABLE_POINTER
2289 return RET_OK;
2290 }
2291
GetTouchpadPinchSwitch(bool & switchFlag)2292 int32_t MMIService::GetTouchpadPinchSwitch(bool &switchFlag)
2293 {
2294 CALL_INFO_TRACE;
2295 #ifdef OHOS_BUILD_ENABLE_POINTER
2296 int32_t ret = delegateTasks_.PostSyncTask(
2297 [this, &switchFlag] {
2298 return this->ReadTouchpadPinchSwitch(switchFlag);
2299 }
2300 );
2301 if (ret != RET_OK) {
2302 MMI_HILOGE("Get touch pad pinch switch failed, return:%{public}d", ret);
2303 return ret;
2304 }
2305 #endif // OHOS_BUILD_ENABLE_POINTER
2306 return RET_OK;
2307 }
2308
SetTouchpadSwipeSwitch(bool switchFlag)2309 int32_t MMIService::SetTouchpadSwipeSwitch(bool switchFlag)
2310 {
2311 CALL_INFO_TRACE;
2312 #if defined OHOS_BUILD_ENABLE_POINTER
2313 int32_t ret = delegateTasks_.PostSyncTask(
2314 [switchFlag] {
2315 return ::OHOS::DelayedSingleton<TouchEventNormalize>::GetInstance()->SetTouchpadSwipeSwitch(switchFlag);
2316 }
2317 );
2318 if (ret != RET_OK) {
2319 MMI_HILOGE("Set touchpad swipe switch failed, return:%{public}d", ret);
2320 return ret;
2321 }
2322 #endif // OHOS_BUILD_ENABLE_POINTER
2323 return RET_OK;
2324 }
2325
GetTouchpadSwipeSwitch(bool & switchFlag)2326 int32_t MMIService::GetTouchpadSwipeSwitch(bool &switchFlag)
2327 {
2328 CALL_INFO_TRACE;
2329 #ifdef OHOS_BUILD_ENABLE_POINTER
2330 int32_t ret = delegateTasks_.PostSyncTask(
2331 [this, &switchFlag] {
2332 return this->ReadTouchpadSwipeSwitch(switchFlag);
2333 }
2334 );
2335 if (ret != RET_OK) {
2336 MMI_HILOGE("Get touchpad swipe switch failed, return:%{public}d", ret);
2337 return ret;
2338 }
2339 #endif // OHOS_BUILD_ENABLE_POINTER
2340 return RET_OK;
2341 }
2342
SetTouchpadRightClickType(int32_t type)2343 int32_t MMIService::SetTouchpadRightClickType(int32_t type)
2344 {
2345 CALL_INFO_TRACE;
2346 #if defined OHOS_BUILD_ENABLE_POINTER
2347 int32_t ret = delegateTasks_.PostSyncTask(
2348 [type] {
2349 return ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance()->SetTouchpadRightClickType(type);
2350 }
2351 );
2352 if (ret != RET_OK) {
2353 MMI_HILOGE("Set touchpad right button menu type failed, return:%{public}d", ret);
2354 return ret;
2355 }
2356 #endif // OHOS_BUILD_ENABLE_POINTER
2357 return RET_OK;
2358 }
2359
GetTouchpadRightClickType(int32_t & type)2360 int32_t MMIService::GetTouchpadRightClickType(int32_t &type)
2361 {
2362 CALL_INFO_TRACE;
2363 #ifdef OHOS_BUILD_ENABLE_POINTER
2364 int32_t ret = delegateTasks_.PostSyncTask(
2365 [this, &type] {
2366 return this->ReadTouchpadRightMenuType(type);
2367 }
2368 );
2369 if (ret != RET_OK) {
2370 MMI_HILOGE("Get touchpad right button menu type failed, return:%{public}d", ret);
2371 return ret;
2372 }
2373 #endif // OHOS_BUILD_ENABLE_POINTER
2374 return RET_OK;
2375 }
2376
SetTouchpadRotateSwitch(bool rotateSwitch)2377 int32_t MMIService::SetTouchpadRotateSwitch(bool rotateSwitch)
2378 {
2379 CALL_INFO_TRACE;
2380 #if defined OHOS_BUILD_ENABLE_POINTER
2381 int32_t ret = delegateTasks_.PostSyncTask(
2382 [rotateSwitch] {
2383 return ::OHOS::DelayedSingleton<TouchEventNormalize>::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch);
2384 }
2385 );
2386 if (ret != RET_OK) {
2387 MMI_HILOGE("Set touchpad rotate switch failed, ret:%{public}d", ret);
2388 return ret;
2389 }
2390 #endif // OHOS_BUILD_ENABLE_POINTER
2391 return RET_OK;
2392 }
2393
GetTouchpadRotateSwitch(bool & rotateSwitch)2394 int32_t MMIService::GetTouchpadRotateSwitch(bool &rotateSwitch)
2395 {
2396 CALL_INFO_TRACE;
2397 #ifdef OHOS_BUILD_ENABLE_POINTER
2398 int32_t ret = delegateTasks_.PostSyncTask(
2399 [this, &rotateSwitch] {
2400 return this->ReadTouchpadRotateSwitch(rotateSwitch);
2401 }
2402 );
2403 if (ret != RET_OK) {
2404 MMI_HILOGE("Get touchpad rotate switch failed, ret:%{public}d", ret);
2405 return RET_ERR;
2406 }
2407 #endif // OHOS_BUILD_ENABLE_POINTER
2408 return RET_OK;
2409 }
2410
SetShieldStatus(int32_t shieldMode,bool isShield)2411 int32_t MMIService::SetShieldStatus(int32_t shieldMode, bool isShield)
2412 {
2413 CALL_INFO_TRACE;
2414 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
2415 int32_t ret = delegateTasks_.PostSyncTask(
2416 [this, shieldMode, isShield] {
2417 return sMsgHandler_.SetShieldStatus(shieldMode, isShield);
2418 }
2419 );
2420 if (ret != RET_OK) {
2421 MMI_HILOGE("Set shield event interception state failed, return %{public}d", ret);
2422 return ret;
2423 }
2424 #endif // OHOS_BUILD_ENABLE_KEYBOARD
2425 return RET_OK;
2426 }
2427
GetShieldStatus(int32_t shieldMode,bool & isShield)2428 int32_t MMIService::GetShieldStatus(int32_t shieldMode, bool &isShield)
2429 {
2430 CALL_INFO_TRACE;
2431 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
2432 int32_t ret = delegateTasks_.PostSyncTask(
2433 [this, shieldMode, &isShield] {
2434 return sMsgHandler_.GetShieldStatus(shieldMode, isShield);
2435 }
2436 );
2437 if (ret != RET_OK) {
2438 MMI_HILOGE("Failed to set shield event interception status, ret:%{public}d", ret);
2439 return ret;
2440 }
2441 #endif // OHOS_BUILD_ENABLE_KEYBOARD
2442 return RET_OK;
2443 }
2444
GetKeyState(std::vector<int32_t> & pressedKeys,std::map<int32_t,int32_t> & specialKeysState)2445 int32_t MMIService::GetKeyState(std::vector<int32_t> &pressedKeys, std::map<int32_t, int32_t> &specialKeysState)
2446 {
2447 CALL_DEBUG_ENTER;
2448 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
2449 int32_t ret = delegateTasks_.PostSyncTask(
2450 [this, &pressedKeys, &specialKeysState] {
2451 return this->OnGetKeyState(pressedKeys, specialKeysState);
2452 }
2453 );
2454 if (ret != RET_OK) {
2455 MMI_HILOGE("Get pressed keys failed, return:%{public}d", ret);
2456 return ret;
2457 }
2458 #endif // OHOS_BUILD_ENABLE_KEYBOARD
2459 return RET_OK;
2460 }
2461
Authorize(bool isAuthorize)2462 int32_t MMIService::Authorize(bool isAuthorize)
2463 {
2464 CALL_DEBUG_ENTER;
2465 int32_t ret = delegateTasks_.PostSyncTask(
2466 [this, isAuthorize] {
2467 return this->OnAuthorize(isAuthorize);
2468 }
2469 );
2470 if (ret != RET_OK) {
2471 MMI_HILOGE("OnAuthorize failed, ret:%{public}d", ret);
2472 return ret;
2473 }
2474 return RET_OK;
2475 }
2476
OnAuthorize(bool isAuthorize)2477 int32_t MMIService::OnAuthorize(bool isAuthorize)
2478 {
2479 return sMsgHandler_.OnAuthorize(isAuthorize);
2480 }
2481
CancelInjection()2482 int32_t MMIService::CancelInjection()
2483 {
2484 CALL_DEBUG_ENTER;
2485 int32_t ret = delegateTasks_.PostSyncTask(
2486 [this] {
2487 return this->OnCancelInjection();
2488 }
2489 );
2490 if (ret != RET_OK) {
2491 MMI_HILOGE("OnCancelInjection failed, ret:%{public}d", ret);
2492 return ret;
2493 }
2494 return RET_OK;
2495 }
2496
OnCancelInjection()2497 int32_t MMIService::OnCancelInjection()
2498 {
2499 return sMsgHandler_.OnCancelInjection();
2500 }
2501
HasIrEmitter(bool & hasIrEmitter)2502 int32_t MMIService::HasIrEmitter(bool &hasIrEmitter)
2503 {
2504 CALL_DEBUG_ENTER;
2505 int32_t ret = delegateTasks_.PostSyncTask(
2506 [this, &hasIrEmitter] {
2507 return this->OnHasIrEmitter(hasIrEmitter);
2508 }
2509 );
2510 if (ret != RET_OK) {
2511 MMI_HILOGE("OnHasIrEmitter failed, ret:%{public}d", ret);
2512 return ret;
2513 }
2514 return RET_OK;
2515 }
2516
GetInfraredFrequencies(std::vector<InfraredFrequency> & requencys)2517 int32_t MMIService::GetInfraredFrequencies(std::vector<InfraredFrequency>& requencys)
2518 {
2519 CALL_DEBUG_ENTER;
2520 int32_t ret = delegateTasks_.PostSyncTask(
2521 [this, &requencys] {
2522 return this->OnGetInfraredFrequencies(requencys);
2523 }
2524 );
2525 if (ret != RET_OK) {
2526 MMI_HILOGE("OnGetInfraredFrequencies failed, returnCode:%{public}d", ret);
2527 return ret;
2528 }
2529 return RET_OK;
2530 }
2531
TransmitInfrared(int64_t number,std::vector<int64_t> & pattern)2532 int32_t MMIService::TransmitInfrared(int64_t number, std::vector<int64_t>& pattern)
2533 {
2534 CALL_DEBUG_ENTER;
2535 int32_t ret = delegateTasks_.PostSyncTask(
2536 [this, number, &pattern] {
2537 return this->OnTransmitInfrared(number, pattern);
2538 }
2539 );
2540 if (ret != RET_OK) {
2541 MMI_HILOGE("OnTransmitInfrared failed, returnCode:%{public}d", ret);
2542 return ret;
2543 }
2544 return RET_OK;
2545 }
2546
OnHasIrEmitter(bool & hasIrEmitter)2547 int32_t MMIService::OnHasIrEmitter(bool &hasIrEmitter)
2548 {
2549 hasIrEmitter = false;
2550 return RET_OK;
2551 }
2552
OnGetInfraredFrequencies(std::vector<InfraredFrequency> & frequencies)2553 int32_t MMIService::OnGetInfraredFrequencies(std::vector<InfraredFrequency> &frequencies)
2554 {
2555 MMI_HILOGI("start get infrared frequency");
2556 std::vector<InfraredFrequencyInfo> infos;
2557 InfraredEmitterController::GetInstance()->GetFrequencies(infos);
2558 for (auto &item : infos) {
2559 InfraredFrequency info;
2560 info.min_ = item.min_;
2561 info.max_ = item.max_;
2562 frequencies.push_back(info);
2563 }
2564 std::string context = "";
2565 int32_t size = static_cast<int32_t>(frequencies.size());
2566 for (int32_t i = 0; i < size; i++) {
2567 context = context + "frequencies[" + std::to_string(i) + "]. max=" + std::to_string(frequencies[i].max_) +
2568 ",min=" + std::to_string(frequencies[i].min_) + ";";
2569 }
2570 MMI_HILOGD("data from hdf context:%{public}s", context.c_str());
2571 return RET_OK;
2572 }
2573
OnTransmitInfrared(int64_t infraredFrequency,std::vector<int64_t> & pattern)2574 int32_t MMIService::OnTransmitInfrared(int64_t infraredFrequency, std::vector<int64_t> &pattern)
2575 {
2576 std::string context = "infraredFrequency:" + std::to_string(infraredFrequency) + ";";
2577 int32_t size = static_cast<int32_t>(pattern.size());
2578 for (int32_t i = 0; i < size; i++) {
2579 context = context + "index:" + std::to_string(i) + ": pattern:" + std::to_string(pattern[i]) + ";";
2580 }
2581 InfraredEmitterController::GetInstance()->Transmit(infraredFrequency, pattern);
2582 MMI_HILOGI("TransmitInfrared para context:%{public}s", context.c_str());
2583 return RET_OK;
2584 }
2585
SetPixelMapData(int32_t infoId,void * pixelMap)2586 int32_t MMIService::SetPixelMapData(int32_t infoId, void* pixelMap)
2587 {
2588 CALL_DEBUG_ENTER;
2589 CHKPR(pixelMap, ERROR_NULL_POINTER);
2590 int32_t ret = delegateTasks_.PostSyncTask(
2591 [this, infoId, pixelMap] {
2592 return sMsgHandler_.SetPixelMapData(infoId, pixelMap);
2593 }
2594 );
2595 if (ret != RET_OK) {
2596 MMI_HILOGE("Failed to set pixelmap, ret:%{public}d", ret);
2597 return ret;
2598 }
2599 return RET_OK;
2600 }
2601
SetCurrentUser(int32_t userId)2602 int32_t MMIService::SetCurrentUser(int32_t userId)
2603 {
2604 CALL_DEBUG_ENTER;
2605 int32_t ret = delegateTasks_.PostSyncTask(
2606 [userId] {
2607 return ::OHOS::MMI::IInputWindowsManager::GetInstance()->SetCurrentUser(userId);
2608 }
2609 );
2610 if (ret != RET_OK) {
2611 MMI_HILOGE("Failed to set current user, ret:%{public}d", ret);
2612 return ret;
2613 }
2614 return RET_OK;
2615 }
2616
AddVirtualInputDevice(std::shared_ptr<InputDevice> device,int32_t & deviceId)2617 int32_t MMIService::AddVirtualInputDevice(std::shared_ptr<InputDevice> device, int32_t &deviceId)
2618 {
2619 CALL_DEBUG_ENTER;
2620 CHKPR(device, ERROR_NULL_POINTER);
2621 int32_t ret = delegateTasks_.PostSyncTask(
2622 [device, &deviceId] {
2623 return ::OHOS::MMI::InputDeviceManager::GetInstance()->AddVirtualInputDevice(device, deviceId);
2624 }
2625 );
2626 if (ret != RET_OK) {
2627 MMI_HILOGE("AddVirtualInputDevice failed:%{public}d", ret);
2628 }
2629 return ret;
2630 }
2631
RemoveVirtualInputDevice(int32_t deviceId)2632 int32_t MMIService::RemoveVirtualInputDevice(int32_t deviceId)
2633 {
2634 CALL_DEBUG_ENTER;
2635 int32_t ret = delegateTasks_.PostSyncTask(
2636 [deviceId] {
2637 return ::OHOS::MMI::InputDeviceManager::GetInstance()->RemoveVirtualInputDevice(deviceId);
2638 }
2639 );
2640 if (ret != RET_OK) {
2641 MMI_HILOGE("RemoveVirtualInputDevice failed:%{public}d", ret);
2642 }
2643 return ret;
2644 }
2645
EnableHardwareCursorStats(bool enable)2646 int32_t MMIService::EnableHardwareCursorStats(bool enable)
2647 {
2648 CALL_DEBUG_ENTER;
2649 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
2650 int32_t pid = GetCallingPid();
2651 int32_t ret = delegateTasks_.PostSyncTask(
2652 [pid, enable] {
2653 return IPointerDrawingManager::GetInstance()->EnableHardwareCursorStats(pid, enable);
2654 }
2655 );
2656 if (ret != RET_OK) {
2657 MMI_HILOGE("Enable hardware cursor stats failed, ret:%{public}d", ret);
2658 return ret;
2659 }
2660 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
2661 return RET_OK;
2662 }
2663
GetHardwareCursorStats(uint32_t & frameCount,uint32_t & vsyncCount)2664 int32_t MMIService::GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount)
2665 {
2666 CALL_DEBUG_ENTER;
2667 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
2668 int32_t pid = GetCallingPid();
2669 int32_t ret = delegateTasks_.PostSyncTask(
2670 [pid, &frameCount, &vsyncCount] {
2671 return IPointerDrawingManager::GetInstance()->GetHardwareCursorStats(pid, frameCount, vsyncCount);
2672 }
2673 );
2674 if (ret != RET_OK) {
2675 MMI_HILOGE("Get hardware cursor stats failed, ret:%{public}d", ret);
2676 return ret;
2677 }
2678 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
2679 return RET_OK;
2680 }
2681
2682 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
GetPointerSnapshot(void * pixelMapPtr)2683 int32_t MMIService::GetPointerSnapshot(void *pixelMapPtr)
2684 {
2685 CALL_INFO_TRACE;
2686 #if defined OHOS_BUILD_ENABLE_POINTER
2687 MMI_HILOGI("Get pointer snapshot from process(%{public}d)", GetCallingPid());
2688 int32_t ret = delegateTasks_.PostSyncTask(std::bind(
2689 std::bind(&IPointerDrawingManager::GetPointerSnapshot, IPointerDrawingManager::GetInstance(), pixelMapPtr)));
2690 if (ret != RET_OK) {
2691 MMI_HILOGE("Get the pointer snapshot failed, ret: %{public}d", ret);
2692 return ret;
2693 }
2694 #endif // OHOS_BUILD_ENABLE_POINTER
2695 return RET_OK;
2696 }
2697 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR
2698
2699 #ifdef OHOS_BUILD_ENABLE_ANCO
AncoAddChannel(sptr<IAncoChannel> channel)2700 int32_t MMIService::AncoAddChannel(sptr<IAncoChannel> channel)
2701 {
2702 int32_t ret = delegateTasks_.PostSyncTask([channel]() {
2703 return WIN_MGR->AncoAddChannel(channel);
2704 });
2705 if (ret != RET_OK) {
2706 MMI_HILOGE("AncoAddChannel fail, error:%{public}d", ret);
2707 }
2708 return ret;
2709 }
2710
AncoRemoveChannel(sptr<IAncoChannel> channel)2711 int32_t MMIService::AncoRemoveChannel(sptr<IAncoChannel> channel)
2712 {
2713 int32_t ret = delegateTasks_.PostSyncTask([channel]() {
2714 return WIN_MGR->AncoRemoveChannel(channel);
2715 });
2716 if (ret != RET_OK) {
2717 MMI_HILOGE("AncoRemoveChannel fail, error:%{public}d", ret);
2718 }
2719 return ret;
2720 }
2721 #endif // OHOS_BUILD_ENABLE_ANCO
2722
TransferBinderClientSrv(const sptr<IRemoteObject> & binderClientObject)2723 int32_t MMIService::TransferBinderClientSrv(const sptr<IRemoteObject> &binderClientObject)
2724 {
2725 CALL_DEBUG_ENTER;
2726 int32_t pid = GetCallingPid();
2727 int32_t ret =
2728 delegateTasks_.PostSyncTask(
2729 [this, pid, binderClientObject] {
2730 return sMsgHandler_.OnTransferBinderClientSrv(binderClientObject, pid);
2731 }
2732 );
2733 MMI_HILOGI("TransferBinderClientSrv result:%{public}d", ret);
2734 return ret;
2735 }
2736
CalculateFuntionRunningTime(std::function<void ()> func,const std::string & flag)2737 void MMIService::CalculateFuntionRunningTime(std::function<void()> func, const std::string &flag)
2738 {
2739 std::function<void (void *)> printLog = std::bind(&MMIService::PrintLog, this, flag, THREAD_BLOCK_TIMER_SPAN_S,
2740 getpid(), gettid());
2741 int32_t id = HiviewDFX::XCollie::GetInstance().SetTimer(flag, THREAD_BLOCK_TIMER_SPAN_S, printLog, nullptr,
2742 HiviewDFX::XCOLLIE_FLAG_NOOP);
2743 func();
2744 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
2745 }
2746
PrintLog(const std::string & flag,int32_t duration,int32_t pid,int32_t tid)2747 void MMIService::PrintLog(const std::string &flag, int32_t duration, int32_t pid, int32_t tid)
2748 {
2749 std::string dfxThreadBlockMsg { "MMIBlockTask name:" };
2750 dfxThreadBlockMsg += flag;
2751 dfxThreadBlockMsg += ", duration time:";
2752 dfxThreadBlockMsg += std::to_string(duration);
2753 dfxThreadBlockMsg += ", pid:";
2754 dfxThreadBlockMsg += std::to_string(pid);
2755 dfxThreadBlockMsg += ", tid:";
2756 dfxThreadBlockMsg += std::to_string(tid);
2757 MMI_HILOGW("DfxThreadBlockMsg:%{public}s", dfxThreadBlockMsg.c_str());
2758 OHOS::HiviewDFX::DfxDumpCatcher dumpCatcher;
2759 dumpCatcher.DumpCatch(pid, tid, dfxThreadBlockMsg, MAX_FRAME_NUMS, false);
2760 }
2761
SkipPointerLayer(bool isSkip)2762 int32_t MMIService::SkipPointerLayer(bool isSkip)
2763 {
2764 CALL_INFO_TRACE;
2765 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
2766 int32_t ret = delegateTasks_.PostSyncTask(
2767 [isSkip] {
2768 return IPointerDrawingManager::GetInstance()->SkipPointerLayer(isSkip);
2769 }
2770 );
2771 if (ret != RET_OK) {
2772 MMI_HILOGE("Skip pointer layerfailed, return:%{public}d", ret);
2773 return ret;
2774 }
2775 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
2776 return RET_OK;
2777 }
2778 } // namespace MMI
2779 } // namespace OHOS
2780