1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#include "server_msg_handler.h" 17c29fa5a6Sopenharmony_ci 18c29fa5a6Sopenharmony_ci#include <cinttypes> 19c29fa5a6Sopenharmony_ci#include "ipc_skeleton.h" 20c29fa5a6Sopenharmony_ci 21c29fa5a6Sopenharmony_ci#include "ability_manager_client.h" 22c29fa5a6Sopenharmony_ci#include "anr_manager.h" 23c29fa5a6Sopenharmony_ci#include "authorization_dialog.h" 24c29fa5a6Sopenharmony_ci#include "authorize_helper.h" 25c29fa5a6Sopenharmony_ci#include "bytrace_adapter.h" 26c29fa5a6Sopenharmony_ci#include "client_death_handler.h" 27c29fa5a6Sopenharmony_ci#include "display_event_monitor.h" 28c29fa5a6Sopenharmony_ci#include "event_dump.h" 29c29fa5a6Sopenharmony_ci#include "event_interceptor_handler.h" 30c29fa5a6Sopenharmony_ci#include "event_monitor_handler.h" 31c29fa5a6Sopenharmony_ci#include "event_log_helper.h" 32c29fa5a6Sopenharmony_ci#include "hos_key_event.h" 33c29fa5a6Sopenharmony_ci#include "input_device_manager.h" 34c29fa5a6Sopenharmony_ci#include "input_event.h" 35c29fa5a6Sopenharmony_ci#include "input_event_data_transformation.h" 36c29fa5a6Sopenharmony_ci#include "input_event_handler.h" 37c29fa5a6Sopenharmony_ci#include "i_input_windows_manager.h" 38c29fa5a6Sopenharmony_ci#include "i_pointer_drawing_manager.h" 39c29fa5a6Sopenharmony_ci#include "key_event_normalize.h" 40c29fa5a6Sopenharmony_ci#include "key_event_value_transformation.h" 41c29fa5a6Sopenharmony_ci#include "key_subscriber_handler.h" 42c29fa5a6Sopenharmony_ci#include "libinput_adapter.h" 43c29fa5a6Sopenharmony_ci#include "parameters.h" 44c29fa5a6Sopenharmony_ci#include "switch_subscriber_handler.h" 45c29fa5a6Sopenharmony_ci#include "time_cost_chk.h" 46c29fa5a6Sopenharmony_ci#include "touch_drawing_manager.h" 47c29fa5a6Sopenharmony_ci 48c29fa5a6Sopenharmony_ci#undef MMI_LOG_DOMAIN 49c29fa5a6Sopenharmony_ci#define MMI_LOG_DOMAIN MMI_LOG_SERVER 50c29fa5a6Sopenharmony_ci#undef MMI_LOG_TAG 51c29fa5a6Sopenharmony_ci#define MMI_LOG_TAG "ServerMsgHandler" 52c29fa5a6Sopenharmony_ci 53c29fa5a6Sopenharmony_cinamespace OHOS { 54c29fa5a6Sopenharmony_cinamespace MMI { 55c29fa5a6Sopenharmony_cinamespace { 56c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 57c29fa5a6Sopenharmony_ciconstexpr int32_t SECURITY_COMPONENT_SERVICE_ID { 3050 }; 58c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 59c29fa5a6Sopenharmony_ciconstexpr int32_t SEND_NOTICE_OVERTIME { 5 }; 60c29fa5a6Sopenharmony_ci[[ maybe_unused ]] constexpr int32_t DEFAULT_POINTER_ID { 10000 }; 61c29fa5a6Sopenharmony_ciconst int32_t ROTATE_POLICY = system::GetIntParameter("const.window.device.rotate_policy", 0); 62c29fa5a6Sopenharmony_ciconst std::string PRODUCT_TYPE = system::GetParameter("const.product.devicetype", "unknown"); 63c29fa5a6Sopenharmony_ciconst std::string PRODUCT_TYPE_PC = "2in1"; 64c29fa5a6Sopenharmony_ci[[ maybe_unused ]] constexpr int32_t WINDOW_ROTATE { 0 }; 65c29fa5a6Sopenharmony_ciconstexpr int32_t COMMON_PERMISSION_CHECK_ERROR { 201 }; 66c29fa5a6Sopenharmony_ci} // namespace 67c29fa5a6Sopenharmony_ci 68c29fa5a6Sopenharmony_civoid ServerMsgHandler::Init(UDSServer &udsServer) 69c29fa5a6Sopenharmony_ci{ 70c29fa5a6Sopenharmony_ci udsServer_ = &udsServer; 71c29fa5a6Sopenharmony_ci MsgCallback funs[] = { 72c29fa5a6Sopenharmony_ci {MmiMessageId::DISPLAY_INFO, [this] (SessionPtr sess, NetPacket &pkt) { 73c29fa5a6Sopenharmony_ci return this->OnDisplayInfo(sess, pkt); }}, 74c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) 75c29fa5a6Sopenharmony_ci {MmiMessageId::WINDOW_AREA_INFO, [this] (SessionPtr sess, NetPacket &pkt) { 76c29fa5a6Sopenharmony_ci return this->OnWindowAreaInfo(sess, pkt); }}, 77c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING 78c29fa5a6Sopenharmony_ci {MmiMessageId::WINDOW_INFO, [this] (SessionPtr sess, NetPacket &pkt) { 79c29fa5a6Sopenharmony_ci return this->OnWindowGroupInfo(sess, pkt); }}, 80c29fa5a6Sopenharmony_ci {MmiMessageId::WINDOW_STATE_ERROR_CALLBACK, [this] (SessionPtr sess, NetPacket &pkt) { 81c29fa5a6Sopenharmony_ci return this->RegisterWindowStateErrorCallback(sess, pkt); }}, 82c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 83c29fa5a6Sopenharmony_ci {MmiMessageId::SCINFO_CONFIG, [this] (SessionPtr sess, NetPacket &pkt) { 84c29fa5a6Sopenharmony_ci return this->OnEnhanceConfig(sess, pkt); }}, 85c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 86c29fa5a6Sopenharmony_ci 87c29fa5a6Sopenharmony_ci }; 88c29fa5a6Sopenharmony_ci for (auto &it : funs) { 89c29fa5a6Sopenharmony_ci if (!RegistrationEvent(it)) { 90c29fa5a6Sopenharmony_ci MMI_HILOGW("Failed to register event errCode:%{public}d", EVENT_REG_FAIL); 91c29fa5a6Sopenharmony_ci continue; 92c29fa5a6Sopenharmony_ci } 93c29fa5a6Sopenharmony_ci } 94c29fa5a6Sopenharmony_ci AUTHORIZE_HELPER->Init(clientDeathHandler_); 95c29fa5a6Sopenharmony_ci} 96c29fa5a6Sopenharmony_ci 97c29fa5a6Sopenharmony_civoid ServerMsgHandler::OnMsgHandler(SessionPtr sess, NetPacket& pkt) 98c29fa5a6Sopenharmony_ci{ 99c29fa5a6Sopenharmony_ci CHKPV(sess); 100c29fa5a6Sopenharmony_ci auto id = pkt.GetMsgId(); 101c29fa5a6Sopenharmony_ci TimeCostChk chk("ServerMsgHandler::OnMsgHandler", "overtime 300(us)", MAX_OVER_TIME, id); 102c29fa5a6Sopenharmony_ci BytraceAdapter::StartSocketHandle(static_cast<int32_t>(id)); 103c29fa5a6Sopenharmony_ci auto callback = GetMsgCallback(id); 104c29fa5a6Sopenharmony_ci if (callback == nullptr) { 105c29fa5a6Sopenharmony_ci MMI_HILOGE("Unknown msg id:%{public}d, errCode:%{public}d", id, UNKNOWN_MSG_ID); 106c29fa5a6Sopenharmony_ci return; 107c29fa5a6Sopenharmony_ci } 108c29fa5a6Sopenharmony_ci auto ret = (*callback)(sess, pkt); 109c29fa5a6Sopenharmony_ci BytraceAdapter::StopSocketHandle(); 110c29fa5a6Sopenharmony_ci if (ret < 0) { 111c29fa5a6Sopenharmony_ci MMI_HILOGE("Msg handling failed. id:%{public}d, errCode:%{public}d", id, ret); 112c29fa5a6Sopenharmony_ci } 113c29fa5a6Sopenharmony_ci} 114c29fa5a6Sopenharmony_ci 115c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD 116c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent, int32_t pid, bool isNativeInject) 117c29fa5a6Sopenharmony_ci{ 118c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 119c29fa5a6Sopenharmony_ci CHKPR(keyEvent, ERROR_NULL_POINTER); 120c29fa5a6Sopenharmony_ci LogTracer lt(keyEvent->GetId(), keyEvent->GetEventType(), keyEvent->GetKeyAction()); 121c29fa5a6Sopenharmony_ci if (isNativeInject) { 122c29fa5a6Sopenharmony_ci if (PRODUCT_TYPE != PRODUCT_TYPE_PC) { 123c29fa5a6Sopenharmony_ci MMI_HILOGW("Current device has no permission"); 124c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 125c29fa5a6Sopenharmony_ci } 126c29fa5a6Sopenharmony_ci bool screenLocked = DISPLAY_MONITOR->GetScreenLocked(); 127c29fa5a6Sopenharmony_ci if (screenLocked) { 128c29fa5a6Sopenharmony_ci MMI_HILOGW("Screen locked, no permission"); 129c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 130c29fa5a6Sopenharmony_ci } 131c29fa5a6Sopenharmony_ci auto iter = authorizationCollection_.find(pid); 132c29fa5a6Sopenharmony_ci if ((iter == authorizationCollection_.end()) || (iter->second == AuthorizationStatus::UNAUTHORIZED)) { 133c29fa5a6Sopenharmony_ci auto state = AUTHORIZE_HELPER->GetAuthorizeState(); 134c29fa5a6Sopenharmony_ci if (state != AuthorizeState::STATE_UNAUTHORIZE) { 135c29fa5a6Sopenharmony_ci MMI_HILOGI("The process is already being processed,s:%{public}d,pid:%{public}d,inputPid:%{public}d", 136c29fa5a6Sopenharmony_ci state, AUTHORIZE_HELPER->GetAuthorizePid(), pid); 137c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 138c29fa5a6Sopenharmony_ci } 139c29fa5a6Sopenharmony_ci CurrentPID_ = pid; 140c29fa5a6Sopenharmony_ci InjectionType_ = InjectionType::KEYEVENT; 141c29fa5a6Sopenharmony_ci keyEvent_ = keyEvent; 142c29fa5a6Sopenharmony_ci LaunchAbility(); 143c29fa5a6Sopenharmony_ci AuthorizeExitCallback fnCallback = [&] (int32_t pid) { 144c29fa5a6Sopenharmony_ci MMI_HILOGI("User not authorized to inject pid:%{public}d", pid); 145c29fa5a6Sopenharmony_ci }; 146c29fa5a6Sopenharmony_ci AUTHORIZE_HELPER->AddAuthorizeProcess(CurrentPID_, fnCallback); 147c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 148c29fa5a6Sopenharmony_ci } 149c29fa5a6Sopenharmony_ci CurrentPID_ = pid; 150c29fa5a6Sopenharmony_ci if (iter->second == AuthorizationStatus::UNAUTHORIZED) { 151c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 152c29fa5a6Sopenharmony_ci } 153c29fa5a6Sopenharmony_ci } 154c29fa5a6Sopenharmony_ci int32_t keyIntention = KeyItemsTransKeyIntention(keyEvent->GetKeyItems()); 155c29fa5a6Sopenharmony_ci keyEvent->SetKeyIntention(keyIntention); 156c29fa5a6Sopenharmony_ci auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); 157c29fa5a6Sopenharmony_ci CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); 158c29fa5a6Sopenharmony_ci inputEventNormalizeHandler->HandleKeyEvent(keyEvent); 159c29fa5a6Sopenharmony_ci if (EventLogHelper::IsBetaVersion() && !keyEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { 160c29fa5a6Sopenharmony_ci MMI_HILOGD("Inject keyCode:%{private}d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); 161c29fa5a6Sopenharmony_ci } else { 162c29fa5a6Sopenharmony_ci MMI_HILOGD("Inject keyCode:%d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); 163c29fa5a6Sopenharmony_ci } 164c29fa5a6Sopenharmony_ci return RET_OK; 165c29fa5a6Sopenharmony_ci} 166c29fa5a6Sopenharmony_ci 167c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnGetFunctionKeyState(int32_t funcKey, bool &state) 168c29fa5a6Sopenharmony_ci{ 169c29fa5a6Sopenharmony_ci CALL_INFO_TRACE; 170c29fa5a6Sopenharmony_ci const auto &keyEvent = KeyEventHdr->GetKeyEvent(); 171c29fa5a6Sopenharmony_ci CHKPR(keyEvent, ERROR_NULL_POINTER); 172c29fa5a6Sopenharmony_ci state = keyEvent->GetFunctionKey(funcKey); 173c29fa5a6Sopenharmony_ci MMI_HILOGD("Get the function key:%{public}d status as %{public}s", funcKey, state ? "open" : "close"); 174c29fa5a6Sopenharmony_ci return RET_OK; 175c29fa5a6Sopenharmony_ci} 176c29fa5a6Sopenharmony_ci 177c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnSetFunctionKeyState(int32_t funcKey, bool enable) 178c29fa5a6Sopenharmony_ci{ 179c29fa5a6Sopenharmony_ci CALL_INFO_TRACE; 180c29fa5a6Sopenharmony_ci auto device = INPUT_DEV_MGR->GetKeyboardDevice(); 181c29fa5a6Sopenharmony_ci CHKPR(device, ERROR_NULL_POINTER); 182c29fa5a6Sopenharmony_ci if (LibinputAdapter::DeviceLedUpdate(device, funcKey, enable) != RET_OK) { 183c29fa5a6Sopenharmony_ci MMI_HILOGE("Failed to set the keyboard led"); 184c29fa5a6Sopenharmony_ci return RET_ERR; 185c29fa5a6Sopenharmony_ci } 186c29fa5a6Sopenharmony_ci int32_t state = libinput_get_funckey_state(device, funcKey); 187c29fa5a6Sopenharmony_ci 188c29fa5a6Sopenharmony_ci auto keyEvent = KeyEventHdr->GetKeyEvent(); 189c29fa5a6Sopenharmony_ci CHKPR(keyEvent, ERROR_NULL_POINTER); 190c29fa5a6Sopenharmony_ci int32_t ret = keyEvent->SetFunctionKey(funcKey, state); 191c29fa5a6Sopenharmony_ci if (ret != funcKey) { 192c29fa5a6Sopenharmony_ci MMI_HILOGE("Failed to enable the function key"); 193c29fa5a6Sopenharmony_ci return RET_ERR; 194c29fa5a6Sopenharmony_ci } 195c29fa5a6Sopenharmony_ci MMI_HILOGD("Update function key:%{public}d succeed", funcKey); 196c29fa5a6Sopenharmony_ci return RET_OK; 197c29fa5a6Sopenharmony_ci} 198c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD 199c29fa5a6Sopenharmony_ci 200c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 201c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent, int32_t pid, 202c29fa5a6Sopenharmony_ci bool isNativeInject, bool isShell) 203c29fa5a6Sopenharmony_ci{ 204c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 205c29fa5a6Sopenharmony_ci CHKPR(pointerEvent, ERROR_NULL_POINTER); 206c29fa5a6Sopenharmony_ci LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); 207c29fa5a6Sopenharmony_ci if (isNativeInject) { 208c29fa5a6Sopenharmony_ci if (PRODUCT_TYPE != PRODUCT_TYPE_PC) { 209c29fa5a6Sopenharmony_ci MMI_HILOGW("Current device has no permission"); 210c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 211c29fa5a6Sopenharmony_ci } 212c29fa5a6Sopenharmony_ci bool screenLocked = DISPLAY_MONITOR->GetScreenLocked(); 213c29fa5a6Sopenharmony_ci if (screenLocked) { 214c29fa5a6Sopenharmony_ci MMI_HILOGW("Screen locked, no permission"); 215c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 216c29fa5a6Sopenharmony_ci } 217c29fa5a6Sopenharmony_ci auto iter = authorizationCollection_.find(pid); 218c29fa5a6Sopenharmony_ci if ((iter == authorizationCollection_.end()) || (iter->second == AuthorizationStatus::UNAUTHORIZED)) { 219c29fa5a6Sopenharmony_ci auto state = AUTHORIZE_HELPER->GetAuthorizeState(); 220c29fa5a6Sopenharmony_ci if (state != AuthorizeState::STATE_UNAUTHORIZE) { 221c29fa5a6Sopenharmony_ci MMI_HILOGI("The process is already being processed,s:%{public}d,pid:%{public}d,inputPid:%{public}d", 222c29fa5a6Sopenharmony_ci state, AUTHORIZE_HELPER->GetAuthorizePid(), pid); 223c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 224c29fa5a6Sopenharmony_ci } 225c29fa5a6Sopenharmony_ci CurrentPID_ = pid; 226c29fa5a6Sopenharmony_ci InjectionType_ = InjectionType::POINTEREVENT; 227c29fa5a6Sopenharmony_ci pointerEvent_ = pointerEvent; 228c29fa5a6Sopenharmony_ci LaunchAbility(); 229c29fa5a6Sopenharmony_ci AuthorizeExitCallback fnCallback = [&] (int32_t pid) { 230c29fa5a6Sopenharmony_ci MMI_HILOGI("User not authorized to inject pid:%{public}d", pid); 231c29fa5a6Sopenharmony_ci }; 232c29fa5a6Sopenharmony_ci AUTHORIZE_HELPER->AddAuthorizeProcess(CurrentPID_, fnCallback); 233c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 234c29fa5a6Sopenharmony_ci } 235c29fa5a6Sopenharmony_ci CurrentPID_ = pid; 236c29fa5a6Sopenharmony_ci if (iter->second == AuthorizationStatus::UNAUTHORIZED) { 237c29fa5a6Sopenharmony_ci return COMMON_PERMISSION_CHECK_ERROR; 238c29fa5a6Sopenharmony_ci } 239c29fa5a6Sopenharmony_ci } 240c29fa5a6Sopenharmony_ci return OnInjectPointerEventExt(pointerEvent, isShell); 241c29fa5a6Sopenharmony_ci} 242c29fa5a6Sopenharmony_ci 243c29fa5a6Sopenharmony_cibool ServerMsgHandler::IsNavigationWindowInjectEvent(std::shared_ptr<PointerEvent> pointerEvent) 244c29fa5a6Sopenharmony_ci{ 245c29fa5a6Sopenharmony_ci return pointerEvent->GetZOrder() > 0; 246c29fa5a6Sopenharmony_ci} 247c29fa5a6Sopenharmony_ci 248c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnInjectPointerEventExt(const std::shared_ptr<PointerEvent> pointerEvent, bool isShell) 249c29fa5a6Sopenharmony_ci{ 250c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 251c29fa5a6Sopenharmony_ci CHKPR(pointerEvent, ERROR_NULL_POINTER); 252c29fa5a6Sopenharmony_ci EndLogTraceId(pointerEvent->GetId()); 253c29fa5a6Sopenharmony_ci pointerEvent->UpdateId(); 254c29fa5a6Sopenharmony_ci LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); 255c29fa5a6Sopenharmony_ci auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); 256c29fa5a6Sopenharmony_ci CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); 257c29fa5a6Sopenharmony_ci switch (pointerEvent->GetSourceType()) { 258c29fa5a6Sopenharmony_ci case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { 259c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH 260c29fa5a6Sopenharmony_ci if (!FixTargetWindowId(pointerEvent, pointerEvent->GetPointerAction(), isShell)) { 261c29fa5a6Sopenharmony_ci return RET_ERR; 262c29fa5a6Sopenharmony_ci } 263c29fa5a6Sopenharmony_ci inputEventNormalizeHandler->HandleTouchEvent(pointerEvent); 264c29fa5a6Sopenharmony_ci if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY) && 265c29fa5a6Sopenharmony_ci !IsNavigationWindowInjectEvent(pointerEvent)) { 266c29fa5a6Sopenharmony_ci TOUCH_DRAWING_MGR->TouchDrawHandler(pointerEvent); 267c29fa5a6Sopenharmony_ci } 268c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH 269c29fa5a6Sopenharmony_ci break; 270c29fa5a6Sopenharmony_ci } 271c29fa5a6Sopenharmony_ci case PointerEvent::SOURCE_TYPE_MOUSE: 272c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_JOYSTICK 273c29fa5a6Sopenharmony_ci case PointerEvent::SOURCE_TYPE_JOYSTICK: 274c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_JOYSTICK 275c29fa5a6Sopenharmony_ci case PointerEvent::SOURCE_TYPE_TOUCHPAD: { 276c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER 277c29fa5a6Sopenharmony_ci int32_t ret = AccelerateMotion(pointerEvent); 278c29fa5a6Sopenharmony_ci if (ret != RET_OK) { 279c29fa5a6Sopenharmony_ci MMI_HILOGE("Failed to accelerate motion, error:%{public}d", ret); 280c29fa5a6Sopenharmony_ci return ret; 281c29fa5a6Sopenharmony_ci } 282c29fa5a6Sopenharmony_ci UpdatePointerEvent(pointerEvent); 283c29fa5a6Sopenharmony_ci inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); 284c29fa5a6Sopenharmony_ci CHKPR(pointerEvent, ERROR_NULL_POINTER); 285c29fa5a6Sopenharmony_ci if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { 286c29fa5a6Sopenharmony_ci break; 287c29fa5a6Sopenharmony_ci } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER)) { 288c29fa5a6Sopenharmony_ci IPointerDrawingManager::GetInstance()->SetPointerVisible(getpid(), false, 0, false); 289c29fa5a6Sopenharmony_ci } else if (((pointerEvent->GetPointerAction() < PointerEvent::POINTER_ACTION_PULL_DOWN) || 290c29fa5a6Sopenharmony_ci (pointerEvent->GetPointerAction() > PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW)) && 291c29fa5a6Sopenharmony_ci !IPointerDrawingManager::GetInstance()->IsPointerVisible()) { 292c29fa5a6Sopenharmony_ci IPointerDrawingManager::GetInstance()->SetPointerVisible(getpid(), true, 0, false); 293c29fa5a6Sopenharmony_ci } 294c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER 295c29fa5a6Sopenharmony_ci break; 296c29fa5a6Sopenharmony_ci } 297c29fa5a6Sopenharmony_ci default: { 298c29fa5a6Sopenharmony_ci MMI_HILOGW("Source type is unknown, source:%{public}d", pointerEvent->GetSourceType()); 299c29fa5a6Sopenharmony_ci break; 300c29fa5a6Sopenharmony_ci } 301c29fa5a6Sopenharmony_ci } 302c29fa5a6Sopenharmony_ci return SaveTargetWindowId(pointerEvent, isShell); 303c29fa5a6Sopenharmony_ci} 304c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 305c29fa5a6Sopenharmony_ci 306c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER 307c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::AccelerateMotion(std::shared_ptr<PointerEvent> pointerEvent) 308c29fa5a6Sopenharmony_ci{ 309c29fa5a6Sopenharmony_ci if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT) || 310c29fa5a6Sopenharmony_ci (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) || 311c29fa5a6Sopenharmony_ci ((pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE) && 312c29fa5a6Sopenharmony_ci (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE) && 313c29fa5a6Sopenharmony_ci (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_BUTTON_DOWN))) { 314c29fa5a6Sopenharmony_ci return RET_OK; 315c29fa5a6Sopenharmony_ci } 316c29fa5a6Sopenharmony_ci PointerEvent::PointerItem pointerItem {}; 317c29fa5a6Sopenharmony_ci if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { 318c29fa5a6Sopenharmony_ci MMI_HILOGE("Pointer event is corrupted"); 319c29fa5a6Sopenharmony_ci return RET_ERR; 320c29fa5a6Sopenharmony_ci } 321c29fa5a6Sopenharmony_ci CursorPosition cursorPos = WIN_MGR->GetCursorPos(); 322c29fa5a6Sopenharmony_ci if (cursorPos.displayId < 0) { 323c29fa5a6Sopenharmony_ci MMI_HILOGE("No display"); 324c29fa5a6Sopenharmony_ci return RET_ERR; 325c29fa5a6Sopenharmony_ci } 326c29fa5a6Sopenharmony_ci Offset offset { 327c29fa5a6Sopenharmony_ci .dx = pointerItem.GetRawDx(), 328c29fa5a6Sopenharmony_ci .dy = pointerItem.GetRawDy(), 329c29fa5a6Sopenharmony_ci }; 330c29fa5a6Sopenharmony_ci auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); 331c29fa5a6Sopenharmony_ci CHKPR(displayInfo, ERROR_NULL_POINTER); 332c29fa5a6Sopenharmony_ci#ifndef OHOS_BUILD_EMULATOR 333c29fa5a6Sopenharmony_ci if (TOUCH_DRAWING_MGR->IsWindowRotation()) { 334c29fa5a6Sopenharmony_ci CalculateOffset(displayInfo->direction, offset); 335c29fa5a6Sopenharmony_ci } 336c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_EMULATOR 337c29fa5a6Sopenharmony_ci int32_t ret = RET_OK; 338c29fa5a6Sopenharmony_ci if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER)) { 339c29fa5a6Sopenharmony_ci ret = HandleMotionAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), 340c29fa5a6Sopenharmony_ci &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, 341c29fa5a6Sopenharmony_ci MouseTransformProcessor::GetTouchpadSpeed(), static_cast<int32_t>(DeviceType::DEVICE_KLV)); 342c29fa5a6Sopenharmony_ci } else { 343c29fa5a6Sopenharmony_ci ret = HandleMotionAccelerateMouse(&offset, WIN_MGR->GetMouseIsCaptureMode(), 344c29fa5a6Sopenharmony_ci &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, 345c29fa5a6Sopenharmony_ci MouseTransformProcessor::GetPointerSpeed(), static_cast<int32_t>(DeviceType::DEVICE_KLV)); 346c29fa5a6Sopenharmony_ci } 347c29fa5a6Sopenharmony_ci if (ret != RET_OK) { 348c29fa5a6Sopenharmony_ci MMI_HILOGE("Failed to accelerate pointer motion, error:%{public}d", ret); 349c29fa5a6Sopenharmony_ci return ret; 350c29fa5a6Sopenharmony_ci } 351c29fa5a6Sopenharmony_ci WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); 352c29fa5a6Sopenharmony_ci if (EventLogHelper::IsBetaVersion() && !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { 353c29fa5a6Sopenharmony_ci MMI_HILOGD("Cursor move to (x:%{public}.2f, y:%{public}.2f, DisplayId:%{public}d)", 354c29fa5a6Sopenharmony_ci cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); 355c29fa5a6Sopenharmony_ci } else { 356c29fa5a6Sopenharmony_ci MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", 357c29fa5a6Sopenharmony_ci cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); 358c29fa5a6Sopenharmony_ci } 359c29fa5a6Sopenharmony_ci return RET_OK; 360c29fa5a6Sopenharmony_ci} 361c29fa5a6Sopenharmony_ci 362c29fa5a6Sopenharmony_civoid ServerMsgHandler::CalculateOffset(Direction direction, Offset &offset) 363c29fa5a6Sopenharmony_ci{ 364c29fa5a6Sopenharmony_ci std::negate<double> neg; 365c29fa5a6Sopenharmony_ci if (direction == DIRECTION90) { 366c29fa5a6Sopenharmony_ci double tmp = offset.dx; 367c29fa5a6Sopenharmony_ci offset.dx = offset.dy; 368c29fa5a6Sopenharmony_ci offset.dy = neg(tmp); 369c29fa5a6Sopenharmony_ci } else if (direction == DIRECTION180) { 370c29fa5a6Sopenharmony_ci offset.dx = neg(offset.dx); 371c29fa5a6Sopenharmony_ci offset.dy = neg(offset.dy); 372c29fa5a6Sopenharmony_ci } else if (direction == DIRECTION270) { 373c29fa5a6Sopenharmony_ci double tmp = offset.dx; 374c29fa5a6Sopenharmony_ci offset.dx = neg(offset.dy); 375c29fa5a6Sopenharmony_ci offset.dy = tmp; 376c29fa5a6Sopenharmony_ci } 377c29fa5a6Sopenharmony_ci} 378c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER 379c29fa5a6Sopenharmony_ci 380c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 381c29fa5a6Sopenharmony_civoid ServerMsgHandler::UpdatePointerEvent(std::shared_ptr<PointerEvent> pointerEvent) 382c29fa5a6Sopenharmony_ci{ 383c29fa5a6Sopenharmony_ci if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT) || 384c29fa5a6Sopenharmony_ci (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE)) { 385c29fa5a6Sopenharmony_ci return; 386c29fa5a6Sopenharmony_ci } 387c29fa5a6Sopenharmony_ci PointerEvent::PointerItem pointerItem {}; 388c29fa5a6Sopenharmony_ci if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { 389c29fa5a6Sopenharmony_ci MMI_HILOGE("Pointer event is corrupted"); 390c29fa5a6Sopenharmony_ci return; 391c29fa5a6Sopenharmony_ci } 392c29fa5a6Sopenharmony_ci auto mouseInfo = WIN_MGR->GetMouseInfo(); 393c29fa5a6Sopenharmony_ci pointerItem.SetDisplayX(mouseInfo.physicalX); 394c29fa5a6Sopenharmony_ci pointerItem.SetDisplayY(mouseInfo.physicalY); 395c29fa5a6Sopenharmony_ci pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem); 396c29fa5a6Sopenharmony_ci pointerEvent->SetTargetDisplayId(mouseInfo.displayId); 397c29fa5a6Sopenharmony_ci} 398c29fa5a6Sopenharmony_ci 399c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::SaveTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, bool isShell) 400c29fa5a6Sopenharmony_ci{ 401c29fa5a6Sopenharmony_ci CHKPR(pointerEvent, ERROR_NULL_POINTER); 402c29fa5a6Sopenharmony_ci if ((pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && 403c29fa5a6Sopenharmony_ci (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN || 404c29fa5a6Sopenharmony_ci pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_ENTER)) { 405c29fa5a6Sopenharmony_ci int32_t pointerId = pointerEvent->GetPointerId(); 406c29fa5a6Sopenharmony_ci PointerEvent::PointerItem pointerItem; 407c29fa5a6Sopenharmony_ci if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { 408c29fa5a6Sopenharmony_ci MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); 409c29fa5a6Sopenharmony_ci return RET_ERR; 410c29fa5a6Sopenharmony_ci } 411c29fa5a6Sopenharmony_ci int32_t targetWindowId = pointerEvent->GetTargetWindowId(); 412c29fa5a6Sopenharmony_ci if (isShell) { 413c29fa5a6Sopenharmony_ci shellTargetWindowIds_[pointerId] = targetWindowId; 414c29fa5a6Sopenharmony_ci } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { 415c29fa5a6Sopenharmony_ci accessTargetWindowIds_[pointerId] = targetWindowId; 416c29fa5a6Sopenharmony_ci } else { 417c29fa5a6Sopenharmony_ci nativeTargetWindowIds_[pointerId] = targetWindowId; 418c29fa5a6Sopenharmony_ci } 419c29fa5a6Sopenharmony_ci } 420c29fa5a6Sopenharmony_ci if ((pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && 421c29fa5a6Sopenharmony_ci (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP || 422c29fa5a6Sopenharmony_ci pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_EXIT)) { 423c29fa5a6Sopenharmony_ci int32_t pointerId = pointerEvent->GetPointerId(); 424c29fa5a6Sopenharmony_ci if (isShell) { 425c29fa5a6Sopenharmony_ci shellTargetWindowIds_.erase(pointerId); 426c29fa5a6Sopenharmony_ci } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { 427c29fa5a6Sopenharmony_ci accessTargetWindowIds_.erase(pointerId); 428c29fa5a6Sopenharmony_ci } else { 429c29fa5a6Sopenharmony_ci nativeTargetWindowIds_.erase(pointerId); 430c29fa5a6Sopenharmony_ci } 431c29fa5a6Sopenharmony_ci } 432c29fa5a6Sopenharmony_ci return RET_OK; 433c29fa5a6Sopenharmony_ci} 434c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 435c29fa5a6Sopenharmony_ci 436c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH 437c29fa5a6Sopenharmony_cibool ServerMsgHandler::FixTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, 438c29fa5a6Sopenharmony_ci int32_t action, bool isShell) 439c29fa5a6Sopenharmony_ci{ 440c29fa5a6Sopenharmony_ci CHKPF(pointerEvent); 441c29fa5a6Sopenharmony_ci int32_t targetWindowId = -1; 442c29fa5a6Sopenharmony_ci int32_t pointerId = pointerEvent->GetPointerId(); 443c29fa5a6Sopenharmony_ci PointerEvent::PointerItem pointerItem; 444c29fa5a6Sopenharmony_ci if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { 445c29fa5a6Sopenharmony_ci MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); 446c29fa5a6Sopenharmony_ci return false; 447c29fa5a6Sopenharmony_ci } 448c29fa5a6Sopenharmony_ci if (pointerEvent->GetTargetWindowId() > 0) { 449c29fa5a6Sopenharmony_ci return true; 450c29fa5a6Sopenharmony_ci } 451c29fa5a6Sopenharmony_ci if (isShell) { 452c29fa5a6Sopenharmony_ci auto iter = shellTargetWindowIds_.find(pointerEvent->GetPointerId()); 453c29fa5a6Sopenharmony_ci if (iter != shellTargetWindowIds_.end()) { 454c29fa5a6Sopenharmony_ci targetWindowId = iter->second; 455c29fa5a6Sopenharmony_ci } 456c29fa5a6Sopenharmony_ci } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { 457c29fa5a6Sopenharmony_ci auto iter = accessTargetWindowIds_.find(pointerEvent->GetPointerId()); 458c29fa5a6Sopenharmony_ci if (iter != accessTargetWindowIds_.end()) { 459c29fa5a6Sopenharmony_ci targetWindowId = iter->second; 460c29fa5a6Sopenharmony_ci } 461c29fa5a6Sopenharmony_ci } else { 462c29fa5a6Sopenharmony_ci auto iter = nativeTargetWindowIds_.find(pointerEvent->GetPointerId()); 463c29fa5a6Sopenharmony_ci if (iter != nativeTargetWindowIds_.end()) { 464c29fa5a6Sopenharmony_ci targetWindowId = iter->second; 465c29fa5a6Sopenharmony_ci } 466c29fa5a6Sopenharmony_ci } 467c29fa5a6Sopenharmony_ci MMI_HILOGD("TargetWindowId:%{public}d %{public}d", pointerEvent->GetTargetWindowId(), targetWindowId); 468c29fa5a6Sopenharmony_ci if (action == PointerEvent::POINTER_ACTION_HOVER_ENTER || 469c29fa5a6Sopenharmony_ci action == PointerEvent::POINTER_ACTION_DOWN || targetWindowId < 0) { 470c29fa5a6Sopenharmony_ci MMI_HILOGD("Down event or targetWindowId less 0 is not need fix window id"); 471c29fa5a6Sopenharmony_ci return true; 472c29fa5a6Sopenharmony_ci } 473c29fa5a6Sopenharmony_ci auto pointerIds = pointerEvent->GetPointerIds(); 474c29fa5a6Sopenharmony_ci if (pointerIds.empty()) { 475c29fa5a6Sopenharmony_ci MMI_HILOGE("GetPointerIds is empty"); 476c29fa5a6Sopenharmony_ci return false; 477c29fa5a6Sopenharmony_ci } 478c29fa5a6Sopenharmony_ci pointerEvent->SetTargetWindowId(targetWindowId); 479c29fa5a6Sopenharmony_ci pointerItem.SetTargetWindowId(targetWindowId); 480c29fa5a6Sopenharmony_ci pointerEvent->UpdatePointerItem(pointerId, pointerItem); 481c29fa5a6Sopenharmony_ci return true; 482c29fa5a6Sopenharmony_ci} 483c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH 484c29fa5a6Sopenharmony_ci 485c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnUiExtentionWindowInfo(NetPacket &pkt, WindowInfo& info) 486c29fa5a6Sopenharmony_ci{ 487c29fa5a6Sopenharmony_ci uint32_t num = 0; 488c29fa5a6Sopenharmony_ci pkt >> num; 489c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 490c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read display info failed"); 491c29fa5a6Sopenharmony_ci return RET_ERR; 492c29fa5a6Sopenharmony_ci } 493c29fa5a6Sopenharmony_ci for (uint32_t i = 0; i < num; i++) { 494c29fa5a6Sopenharmony_ci WindowInfo extensionInfo; 495c29fa5a6Sopenharmony_ci pkt >> extensionInfo.id >> extensionInfo.pid >> extensionInfo.uid >> extensionInfo.area 496c29fa5a6Sopenharmony_ci >> extensionInfo.defaultHotAreas >> extensionInfo.pointerHotAreas >> extensionInfo.agentWindowId 497c29fa5a6Sopenharmony_ci >> extensionInfo.flags >> extensionInfo.action >> extensionInfo.displayId >> extensionInfo.zOrder 498c29fa5a6Sopenharmony_ci >> extensionInfo.pointerChangeAreas >> extensionInfo.transform >> extensionInfo.windowInputType 499c29fa5a6Sopenharmony_ci >> extensionInfo.privacyMode >> extensionInfo.windowType >> extensionInfo.privacyUIFlag 500c29fa5a6Sopenharmony_ci >> extensionInfo.rectChangeBySystem; 501c29fa5a6Sopenharmony_ci info.uiExtentionWindowInfo.push_back(extensionInfo); 502c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 503c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read extention window info failed"); 504c29fa5a6Sopenharmony_ci return RET_ERR; 505c29fa5a6Sopenharmony_ci } 506c29fa5a6Sopenharmony_ci } 507c29fa5a6Sopenharmony_ci return RET_OK; 508c29fa5a6Sopenharmony_ci} 509c29fa5a6Sopenharmony_ci 510c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnDisplayInfo(SessionPtr sess, NetPacket &pkt) 511c29fa5a6Sopenharmony_ci{ 512c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 513c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 514c29fa5a6Sopenharmony_ci DisplayGroupInfo displayGroupInfo; 515c29fa5a6Sopenharmony_ci pkt >> displayGroupInfo.width >> displayGroupInfo.height >> 516c29fa5a6Sopenharmony_ci displayGroupInfo.focusWindowId >> displayGroupInfo.currentUserId; 517c29fa5a6Sopenharmony_ci uint32_t num = 0; 518c29fa5a6Sopenharmony_ci pkt >> num; 519c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 520c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read display info failed"); 521c29fa5a6Sopenharmony_ci return RET_ERR; 522c29fa5a6Sopenharmony_ci } 523c29fa5a6Sopenharmony_ci for (uint32_t i = 0; i < num; i++) { 524c29fa5a6Sopenharmony_ci WindowInfo info; 525c29fa5a6Sopenharmony_ci int32_t byteCount = 0; 526c29fa5a6Sopenharmony_ci pkt >> info.id >> info.pid >> info.uid >> info.area >> info.defaultHotAreas 527c29fa5a6Sopenharmony_ci >> info.pointerHotAreas >> info.agentWindowId >> info.flags >> info.action 528c29fa5a6Sopenharmony_ci >> info.displayId >> info.zOrder >> info.pointerChangeAreas >> info.transform 529c29fa5a6Sopenharmony_ci >> info.windowInputType >> info.privacyMode >> info.windowType >> byteCount; 530c29fa5a6Sopenharmony_ci 531c29fa5a6Sopenharmony_ci OnUiExtentionWindowInfo(pkt, info); 532c29fa5a6Sopenharmony_ci pkt >> info.rectChangeBySystem; 533c29fa5a6Sopenharmony_ci displayGroupInfo.windowsInfo.push_back(info); 534c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 535c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read display info failed"); 536c29fa5a6Sopenharmony_ci return RET_ERR; 537c29fa5a6Sopenharmony_ci } 538c29fa5a6Sopenharmony_ci } 539c29fa5a6Sopenharmony_ci pkt >> num; 540c29fa5a6Sopenharmony_ci for (uint32_t i = 0; i < num; i++) { 541c29fa5a6Sopenharmony_ci DisplayInfo info; 542c29fa5a6Sopenharmony_ci pkt >> info.id >> info.x >> info.y >> info.width >> info.height >> info.dpi >> info.name 543c29fa5a6Sopenharmony_ci >> info.uniq >> info.direction >> info.displayDirection >> info.displayMode >> info.transform; 544c29fa5a6Sopenharmony_ci displayGroupInfo.displaysInfo.push_back(info); 545c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 546c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read display info failed"); 547c29fa5a6Sopenharmony_ci return RET_ERR; 548c29fa5a6Sopenharmony_ci } 549c29fa5a6Sopenharmony_ci } 550c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 551c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read display info failed"); 552c29fa5a6Sopenharmony_ci return RET_ERR; 553c29fa5a6Sopenharmony_ci } 554c29fa5a6Sopenharmony_ci WIN_MGR->UpdateDisplayInfoExtIfNeed(displayGroupInfo, true); 555c29fa5a6Sopenharmony_ci return RET_OK; 556c29fa5a6Sopenharmony_ci} 557c29fa5a6Sopenharmony_ci 558c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) 559c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnWindowAreaInfo(SessionPtr sess, NetPacket &pkt) 560c29fa5a6Sopenharmony_ci{ 561c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 562c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 563c29fa5a6Sopenharmony_ci int32_t temp = 0; 564c29fa5a6Sopenharmony_ci int32_t pid = 0; 565c29fa5a6Sopenharmony_ci int32_t windowId = 0; 566c29fa5a6Sopenharmony_ci pkt >> temp >> pid >> windowId; 567c29fa5a6Sopenharmony_ci WindowArea area = static_cast<WindowArea>(temp); 568c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 569c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read display info failed"); 570c29fa5a6Sopenharmony_ci return RET_ERR; 571c29fa5a6Sopenharmony_ci } 572c29fa5a6Sopenharmony_ci WIN_MGR->SetWindowPointerStyle(area, pid, windowId); 573c29fa5a6Sopenharmony_ci return RET_OK; 574c29fa5a6Sopenharmony_ci} 575c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING 576c29fa5a6Sopenharmony_ci 577c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnWindowGroupInfo(SessionPtr sess, NetPacket &pkt) 578c29fa5a6Sopenharmony_ci{ 579c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 580c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 581c29fa5a6Sopenharmony_ci WindowGroupInfo windowGroupInfo; 582c29fa5a6Sopenharmony_ci pkt >> windowGroupInfo.focusWindowId >> windowGroupInfo.displayId; 583c29fa5a6Sopenharmony_ci uint32_t num = 0; 584c29fa5a6Sopenharmony_ci pkt >> num; 585c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 586c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read window group info failed"); 587c29fa5a6Sopenharmony_ci return RET_ERR; 588c29fa5a6Sopenharmony_ci } 589c29fa5a6Sopenharmony_ci for (uint32_t i = 0; i < num; i++) { 590c29fa5a6Sopenharmony_ci WindowInfo info; 591c29fa5a6Sopenharmony_ci pkt >> info.id >> info.pid >> info.uid >> info.area >> info.defaultHotAreas 592c29fa5a6Sopenharmony_ci >> info.pointerHotAreas >> info.agentWindowId >> info.flags >> info.action 593c29fa5a6Sopenharmony_ci >> info.displayId >> info.zOrder >> info.pointerChangeAreas >> info.transform 594c29fa5a6Sopenharmony_ci >> info.windowInputType >> info.privacyMode >> info.windowType; 595c29fa5a6Sopenharmony_ci OnUiExtentionWindowInfo(pkt, info); 596c29fa5a6Sopenharmony_ci pkt >> info.rectChangeBySystem; 597c29fa5a6Sopenharmony_ci windowGroupInfo.windowsInfo.push_back(info); 598c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 599c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read display info failed"); 600c29fa5a6Sopenharmony_ci return RET_ERR; 601c29fa5a6Sopenharmony_ci } 602c29fa5a6Sopenharmony_ci } 603c29fa5a6Sopenharmony_ci WIN_MGR->UpdateWindowInfo(windowGroupInfo); 604c29fa5a6Sopenharmony_ci return RET_OK; 605c29fa5a6Sopenharmony_ci} 606c29fa5a6Sopenharmony_ci 607c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::RegisterWindowStateErrorCallback(SessionPtr sess, NetPacket &pkt) 608c29fa5a6Sopenharmony_ci{ 609c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 610c29fa5a6Sopenharmony_ci int32_t pid = sess->GetPid(); 611c29fa5a6Sopenharmony_ci WIN_MGR->SetWindowStateNotifyPid(pid); 612c29fa5a6Sopenharmony_ci MMI_HILOGI("pid:%{public}d", pid); 613c29fa5a6Sopenharmony_ci return RET_OK; 614c29fa5a6Sopenharmony_ci} 615c29fa5a6Sopenharmony_ci 616c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 617c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnEnhanceConfig(SessionPtr sess, NetPacket &pkt) 618c29fa5a6Sopenharmony_ci{ 619c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 620c29fa5a6Sopenharmony_ci int32_t userId = sess->GetUid(); 621c29fa5a6Sopenharmony_ci if (userId != SECURITY_COMPONENT_SERVICE_ID) { 622c29fa5a6Sopenharmony_ci MMI_HILOGE("Session is not security component service"); 623c29fa5a6Sopenharmony_ci return RET_ERR; 624c29fa5a6Sopenharmony_ci } 625c29fa5a6Sopenharmony_ci uint32_t num = 0; 626c29fa5a6Sopenharmony_ci pkt >> num; 627c29fa5a6Sopenharmony_ci uint8_t cfg[num]; 628c29fa5a6Sopenharmony_ci for (uint32_t i = 0; i < num; i++) { 629c29fa5a6Sopenharmony_ci pkt >> cfg[i]; 630c29fa5a6Sopenharmony_ci } 631c29fa5a6Sopenharmony_ci 632c29fa5a6Sopenharmony_ci if (pkt.ChkRWError()) { 633c29fa5a6Sopenharmony_ci MMI_HILOGE("Packet read scinfo config failed"); 634c29fa5a6Sopenharmony_ci return RET_ERR; 635c29fa5a6Sopenharmony_ci } 636c29fa5a6Sopenharmony_ci int32_t result = Security::SecurityComponent::SecCompEnhanceKit::SetEnhanceCfg(cfg, num); 637c29fa5a6Sopenharmony_ci if (result != 0) { 638c29fa5a6Sopenharmony_ci return RET_ERR; 639c29fa5a6Sopenharmony_ci } 640c29fa5a6Sopenharmony_ci return RET_OK; 641c29fa5a6Sopenharmony_ci} 642c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 643c29fa5a6Sopenharmony_ci 644c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) 645c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, 646c29fa5a6Sopenharmony_ci HandleEventType eventType, int32_t priority, uint32_t deviceTags) 647c29fa5a6Sopenharmony_ci{ 648c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 649c29fa5a6Sopenharmony_ci MMI_HILOGD("handlerType:%{public}d", handlerType); 650c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR 651c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::INTERCEPTOR) { 652c29fa5a6Sopenharmony_ci auto interceptorHandler = InputHandler->GetInterceptorHandler(); 653c29fa5a6Sopenharmony_ci CHKPR(interceptorHandler, ERROR_NULL_POINTER); 654c29fa5a6Sopenharmony_ci return interceptorHandler->AddInputHandler(handlerType, eventType, priority, deviceTags, sess); 655c29fa5a6Sopenharmony_ci } 656c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_INTERCEPTOR 657c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR 658c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::MONITOR) { 659c29fa5a6Sopenharmony_ci auto monitorHandler = InputHandler->GetMonitorHandler(); 660c29fa5a6Sopenharmony_ci CHKPR(monitorHandler, ERROR_NULL_POINTER); 661c29fa5a6Sopenharmony_ci return monitorHandler->AddInputHandler(handlerType, eventType, sess); 662c29fa5a6Sopenharmony_ci } 663c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR 664c29fa5a6Sopenharmony_ci return RET_OK; 665c29fa5a6Sopenharmony_ci} 666c29fa5a6Sopenharmony_ci 667c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, 668c29fa5a6Sopenharmony_ci HandleEventType eventType, int32_t priority, uint32_t deviceTags) 669c29fa5a6Sopenharmony_ci{ 670c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 671c29fa5a6Sopenharmony_ci MMI_HILOGD("OnRemoveInputHandler handlerType:%{public}d eventType:%{public}u", handlerType, eventType); 672c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR 673c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::INTERCEPTOR) { 674c29fa5a6Sopenharmony_ci auto interceptorHandler = InputHandler->GetInterceptorHandler(); 675c29fa5a6Sopenharmony_ci CHKPR(interceptorHandler, ERROR_NULL_POINTER); 676c29fa5a6Sopenharmony_ci interceptorHandler->RemoveInputHandler(handlerType, eventType, priority, deviceTags, sess); 677c29fa5a6Sopenharmony_ci } 678c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_INTERCEPTOR 679c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR 680c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::MONITOR) { 681c29fa5a6Sopenharmony_ci auto monitorHandler = InputHandler->GetMonitorHandler(); 682c29fa5a6Sopenharmony_ci CHKPR(monitorHandler, ERROR_NULL_POINTER); 683c29fa5a6Sopenharmony_ci monitorHandler->RemoveInputHandler(handlerType, eventType, sess); 684c29fa5a6Sopenharmony_ci ANRMgr->RemoveTimersByType(sess, ANR_MONITOR); 685c29fa5a6Sopenharmony_ci } 686c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR 687c29fa5a6Sopenharmony_ci return RET_OK; 688c29fa5a6Sopenharmony_ci} 689c29fa5a6Sopenharmony_ci 690c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, 691c29fa5a6Sopenharmony_ci std::vector<int32_t> actionsType) 692c29fa5a6Sopenharmony_ci{ 693c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 694c29fa5a6Sopenharmony_ci MMI_HILOGD("handlerType:%{public}d", handlerType); 695c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR 696c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::MONITOR) { 697c29fa5a6Sopenharmony_ci auto monitorHandler = InputHandler->GetMonitorHandler(); 698c29fa5a6Sopenharmony_ci CHKPR(monitorHandler, ERROR_NULL_POINTER); 699c29fa5a6Sopenharmony_ci return monitorHandler->AddInputHandler(handlerType, actionsType, sess); 700c29fa5a6Sopenharmony_ci } 701c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR 702c29fa5a6Sopenharmony_ci return RET_OK; 703c29fa5a6Sopenharmony_ci} 704c29fa5a6Sopenharmony_ci 705c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, 706c29fa5a6Sopenharmony_ci std::vector<int32_t> actionsType) 707c29fa5a6Sopenharmony_ci{ 708c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 709c29fa5a6Sopenharmony_ci MMI_HILOGD("OnRemoveInputHandler handlerType:%{public}d", handlerType); 710c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR 711c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::MONITOR) { 712c29fa5a6Sopenharmony_ci auto monitorHandler = InputHandler->GetMonitorHandler(); 713c29fa5a6Sopenharmony_ci CHKPR(monitorHandler, ERROR_NULL_POINTER); 714c29fa5a6Sopenharmony_ci monitorHandler->RemoveInputHandler(handlerType, actionsType, sess); 715c29fa5a6Sopenharmony_ci ANRMgr->RemoveTimersByType(sess, ANR_MONITOR); 716c29fa5a6Sopenharmony_ci } 717c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR 718c29fa5a6Sopenharmony_ci return RET_OK; 719c29fa5a6Sopenharmony_ci} 720c29fa5a6Sopenharmony_ci 721c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR 722c29fa5a6Sopenharmony_ci 723c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnAddGestureMonitor(SessionPtr sess, InputHandlerType handlerType, 724c29fa5a6Sopenharmony_ci HandleEventType eventType, TouchGestureType gestureType, int32_t fingers) 725c29fa5a6Sopenharmony_ci{ 726c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR 727c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::MONITOR) { 728c29fa5a6Sopenharmony_ci auto monitorHandler = InputHandler->GetMonitorHandler(); 729c29fa5a6Sopenharmony_ci CHKPR(monitorHandler, ERROR_NULL_POINTER); 730c29fa5a6Sopenharmony_ci return monitorHandler->AddInputHandler(handlerType, eventType, sess, gestureType, fingers); 731c29fa5a6Sopenharmony_ci } 732c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR 733c29fa5a6Sopenharmony_ci return RET_OK; 734c29fa5a6Sopenharmony_ci} 735c29fa5a6Sopenharmony_ci 736c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnRemoveGestureMonitor(SessionPtr sess, InputHandlerType handlerType, 737c29fa5a6Sopenharmony_ci HandleEventType eventType, TouchGestureType gestureType, int32_t fingers) 738c29fa5a6Sopenharmony_ci{ 739c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR 740c29fa5a6Sopenharmony_ci if (handlerType == InputHandlerType::MONITOR) { 741c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 742c29fa5a6Sopenharmony_ci auto monitorHandler = InputHandler->GetMonitorHandler(); 743c29fa5a6Sopenharmony_ci CHKPR(monitorHandler, ERROR_NULL_POINTER); 744c29fa5a6Sopenharmony_ci monitorHandler->RemoveInputHandler(handlerType, eventType, sess, gestureType, fingers); 745c29fa5a6Sopenharmony_ci } 746c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR 747c29fa5a6Sopenharmony_ci return RET_OK; 748c29fa5a6Sopenharmony_ci} 749c29fa5a6Sopenharmony_ci 750c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR 751c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnMarkConsumed(SessionPtr sess, int32_t eventId) 752c29fa5a6Sopenharmony_ci{ 753c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 754c29fa5a6Sopenharmony_ci auto monitorHandler = InputHandler->GetMonitorHandler(); 755c29fa5a6Sopenharmony_ci CHKPR(monitorHandler, ERROR_NULL_POINTER); 756c29fa5a6Sopenharmony_ci monitorHandler->MarkConsumed(eventId, sess); 757c29fa5a6Sopenharmony_ci return RET_OK; 758c29fa5a6Sopenharmony_ci} 759c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR 760c29fa5a6Sopenharmony_ci 761c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) 762c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnMoveMouse(int32_t offsetX, int32_t offsetY) 763c29fa5a6Sopenharmony_ci{ 764c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 765c29fa5a6Sopenharmony_ci if (MouseEventHdr->NormalizeMoveMouse(offsetX, offsetY)) { 766c29fa5a6Sopenharmony_ci auto pointerEvent = MouseEventHdr->GetPointerEvent(); 767c29fa5a6Sopenharmony_ci CHKPR(pointerEvent, ERROR_NULL_POINTER); 768c29fa5a6Sopenharmony_ci auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); 769c29fa5a6Sopenharmony_ci CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); 770c29fa5a6Sopenharmony_ci inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); 771c29fa5a6Sopenharmony_ci MMI_HILOGD("Mouse movement message processed successfully"); 772c29fa5a6Sopenharmony_ci } 773c29fa5a6Sopenharmony_ci return RET_OK; 774c29fa5a6Sopenharmony_ci} 775c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING 776c29fa5a6Sopenharmony_ci 777c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD 778c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnSubscribeKeyEvent(IUdsServer *server, int32_t pid, 779c29fa5a6Sopenharmony_ci int32_t subscribeId, const std::shared_ptr<KeyOption> option) 780c29fa5a6Sopenharmony_ci{ 781c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 782c29fa5a6Sopenharmony_ci CHKPR(server, ERROR_NULL_POINTER); 783c29fa5a6Sopenharmony_ci auto sess = server->GetSessionByPid(pid); 784c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 785c29fa5a6Sopenharmony_ci auto subscriberHandler = InputHandler->GetSubscriberHandler(); 786c29fa5a6Sopenharmony_ci CHKPR(subscriberHandler, ERROR_NULL_POINTER); 787c29fa5a6Sopenharmony_ci return subscriberHandler->SubscribeKeyEvent(sess, subscribeId, option); 788c29fa5a6Sopenharmony_ci} 789c29fa5a6Sopenharmony_ci 790c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) 791c29fa5a6Sopenharmony_ci{ 792c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 793c29fa5a6Sopenharmony_ci CHKPR(server, ERROR_NULL_POINTER); 794c29fa5a6Sopenharmony_ci auto sess = server->GetSessionByPid(pid); 795c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 796c29fa5a6Sopenharmony_ci auto subscriberHandler = InputHandler->GetSubscriberHandler(); 797c29fa5a6Sopenharmony_ci CHKPR(subscriberHandler, ERROR_NULL_POINTER); 798c29fa5a6Sopenharmony_ci return subscriberHandler->UnsubscribeKeyEvent(sess, subscribeId); 799c29fa5a6Sopenharmony_ci} 800c29fa5a6Sopenharmony_ci 801c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnSubscribeHotkey(IUdsServer *server, int32_t pid, 802c29fa5a6Sopenharmony_ci int32_t subscribeId, const std::shared_ptr<KeyOption> option) 803c29fa5a6Sopenharmony_ci{ 804c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 805c29fa5a6Sopenharmony_ci CHKPR(server, ERROR_NULL_POINTER); 806c29fa5a6Sopenharmony_ci auto sess = server->GetSessionByPid(pid); 807c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 808c29fa5a6Sopenharmony_ci auto subscriberHandler = InputHandler->GetSubscriberHandler(); 809c29fa5a6Sopenharmony_ci CHKPR(subscriberHandler, ERROR_NULL_POINTER); 810c29fa5a6Sopenharmony_ci return subscriberHandler->SubscribeHotkey(sess, subscribeId, option); 811c29fa5a6Sopenharmony_ci} 812c29fa5a6Sopenharmony_ci 813c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnUnsubscribeHotkey(IUdsServer *server, int32_t pid, int32_t subscribeId) 814c29fa5a6Sopenharmony_ci{ 815c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 816c29fa5a6Sopenharmony_ci CHKPR(server, ERROR_NULL_POINTER); 817c29fa5a6Sopenharmony_ci auto sess = server->GetSessionByPid(pid); 818c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 819c29fa5a6Sopenharmony_ci auto subscriberHandler = InputHandler->GetSubscriberHandler(); 820c29fa5a6Sopenharmony_ci CHKPR(subscriberHandler, ERROR_NULL_POINTER); 821c29fa5a6Sopenharmony_ci return subscriberHandler->UnsubscribeHotkey(sess, subscribeId); 822c29fa5a6Sopenharmony_ci} 823c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD 824c29fa5a6Sopenharmony_ci 825c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_SWITCH 826c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnSubscribeSwitchEvent( 827c29fa5a6Sopenharmony_ci IUdsServer *server, int32_t pid, int32_t subscribeId, int32_t switchType) 828c29fa5a6Sopenharmony_ci{ 829c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 830c29fa5a6Sopenharmony_ci CHKPR(server, ERROR_NULL_POINTER); 831c29fa5a6Sopenharmony_ci auto sess = server->GetSessionByPid(pid); 832c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 833c29fa5a6Sopenharmony_ci auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); 834c29fa5a6Sopenharmony_ci CHKPR(subscriberHandler, ERROR_NULL_POINTER); 835c29fa5a6Sopenharmony_ci return subscriberHandler->SubscribeSwitchEvent(sess, subscribeId, switchType); 836c29fa5a6Sopenharmony_ci} 837c29fa5a6Sopenharmony_ci 838c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnUnsubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) 839c29fa5a6Sopenharmony_ci{ 840c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 841c29fa5a6Sopenharmony_ci CHKPR(server, ERROR_NULL_POINTER); 842c29fa5a6Sopenharmony_ci auto sess = server->GetSessionByPid(pid); 843c29fa5a6Sopenharmony_ci CHKPR(sess, ERROR_NULL_POINTER); 844c29fa5a6Sopenharmony_ci auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); 845c29fa5a6Sopenharmony_ci CHKPR(subscriberHandler, ERROR_NULL_POINTER); 846c29fa5a6Sopenharmony_ci return subscriberHandler->UnsubscribeSwitchEvent(sess, subscribeId); 847c29fa5a6Sopenharmony_ci} 848c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_SWITCH 849c29fa5a6Sopenharmony_ci 850c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD) 851c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::AddInputEventFilter(sptr<IEventFilter> filter, 852c29fa5a6Sopenharmony_ci int32_t filterId, int32_t priority, uint32_t deviceTags, int32_t clientPid) 853c29fa5a6Sopenharmony_ci{ 854c29fa5a6Sopenharmony_ci auto filterHandler = InputHandler->GetFilterHandler(); 855c29fa5a6Sopenharmony_ci CHKPR(filterHandler, ERROR_NULL_POINTER); 856c29fa5a6Sopenharmony_ci return filterHandler->AddInputEventFilter(filter, filterId, priority, deviceTags, clientPid); 857c29fa5a6Sopenharmony_ci} 858c29fa5a6Sopenharmony_ci 859c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::RemoveInputEventFilter(int32_t clientPid, int32_t filterId) 860c29fa5a6Sopenharmony_ci{ 861c29fa5a6Sopenharmony_ci auto filterHandler = InputHandler->GetFilterHandler(); 862c29fa5a6Sopenharmony_ci CHKPR(filterHandler, ERROR_NULL_POINTER); 863c29fa5a6Sopenharmony_ci return filterHandler->RemoveInputEventFilter(clientPid, filterId); 864c29fa5a6Sopenharmony_ci} 865c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD 866c29fa5a6Sopenharmony_ci 867c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD 868c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::SetShieldStatus(int32_t shieldMode, bool isShield) 869c29fa5a6Sopenharmony_ci{ 870c29fa5a6Sopenharmony_ci return KeyEventHdr->SetShieldStatus(shieldMode, isShield); 871c29fa5a6Sopenharmony_ci} 872c29fa5a6Sopenharmony_ci 873c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::GetShieldStatus(int32_t shieldMode, bool &isShield) 874c29fa5a6Sopenharmony_ci{ 875c29fa5a6Sopenharmony_ci return KeyEventHdr->GetShieldStatus(shieldMode, isShield); 876c29fa5a6Sopenharmony_ci} 877c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD 878c29fa5a6Sopenharmony_ci 879c29fa5a6Sopenharmony_civoid ServerMsgHandler::LaunchAbility() 880c29fa5a6Sopenharmony_ci{ 881c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 882c29fa5a6Sopenharmony_ci OHOS::MMI::AuthorizationDialog authorizationDialog; 883c29fa5a6Sopenharmony_ci authorizationDialog.ConnectSystemUi(); 884c29fa5a6Sopenharmony_ci} 885c29fa5a6Sopenharmony_ci 886c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnAuthorize(bool isAuthorize) 887c29fa5a6Sopenharmony_ci{ 888c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 889c29fa5a6Sopenharmony_ci if (isAuthorize) { 890c29fa5a6Sopenharmony_ci auto ret = authorizationCollection_.insert(std::make_pair(CurrentPID_, AuthorizationStatus::AUTHORIZED)); 891c29fa5a6Sopenharmony_ci if (!ret.second) { 892c29fa5a6Sopenharmony_ci MMI_HILOGE("pid:%{public}d has already triggered authorization", CurrentPID_); 893c29fa5a6Sopenharmony_ci } 894c29fa5a6Sopenharmony_ci InjectNoticeInfo noticeInfo; 895c29fa5a6Sopenharmony_ci noticeInfo.pid = CurrentPID_; 896c29fa5a6Sopenharmony_ci AddInjectNotice(noticeInfo); 897c29fa5a6Sopenharmony_ci auto result = AUTHORIZE_HELPER->AddAuthorizeProcess(CurrentPID_, 898c29fa5a6Sopenharmony_ci [&] (int32_t pid) { 899c29fa5a6Sopenharmony_ci CloseInjectNotice(pid); 900c29fa5a6Sopenharmony_ci }); 901c29fa5a6Sopenharmony_ci if (result != RET_OK) { 902c29fa5a6Sopenharmony_ci MMI_HILOGI("Authorize process failed, pid:%{public}d", CurrentPID_); 903c29fa5a6Sopenharmony_ci } 904c29fa5a6Sopenharmony_ci MMI_HILOGD("Agree to apply injection,pid:%{public}d", CurrentPID_); 905c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD 906c29fa5a6Sopenharmony_ci if (InjectionType_ == InjectionType::KEYEVENT) { 907c29fa5a6Sopenharmony_ci OnInjectKeyEvent(keyEvent_, CurrentPID_, true); 908c29fa5a6Sopenharmony_ci } 909c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD 910c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 911c29fa5a6Sopenharmony_ci if (InjectionType_ == InjectionType::POINTEREVENT) { 912c29fa5a6Sopenharmony_ci OnInjectPointerEvent(pointerEvent_, CurrentPID_, true, false); 913c29fa5a6Sopenharmony_ci } 914c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 915c29fa5a6Sopenharmony_ci return ERR_OK; 916c29fa5a6Sopenharmony_ci } 917c29fa5a6Sopenharmony_ci AUTHORIZE_HELPER->CancelAuthorize(CurrentPID_); 918c29fa5a6Sopenharmony_ci auto ret = authorizationCollection_.insert(std::make_pair(CurrentPID_, AuthorizationStatus::UNAUTHORIZED)); 919c29fa5a6Sopenharmony_ci if (!ret.second) { 920c29fa5a6Sopenharmony_ci MMI_HILOGE("pid:%{public}d has already triggered authorization", CurrentPID_); 921c29fa5a6Sopenharmony_ci } 922c29fa5a6Sopenharmony_ci MMI_HILOGD("Reject application injection,pid:%{public}d", CurrentPID_); 923c29fa5a6Sopenharmony_ci return ERR_OK; 924c29fa5a6Sopenharmony_ci} 925c29fa5a6Sopenharmony_ci 926c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnCancelInjection() 927c29fa5a6Sopenharmony_ci{ 928c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 929c29fa5a6Sopenharmony_ci auto iter = authorizationCollection_.find(CurrentPID_); 930c29fa5a6Sopenharmony_ci if (iter != authorizationCollection_.end()) { 931c29fa5a6Sopenharmony_ci authorizationCollection_.erase(iter); 932c29fa5a6Sopenharmony_ci AUTHORIZE_HELPER->CancelAuthorize(CurrentPID_); 933c29fa5a6Sopenharmony_ci auto state = AUTHORIZE_HELPER->GetAuthorizeState(); 934c29fa5a6Sopenharmony_ci if (state != AuthorizeState::STATE_UNAUTHORIZE) { 935c29fa5a6Sopenharmony_ci CloseInjectNotice(CurrentPID_); 936c29fa5a6Sopenharmony_ci } 937c29fa5a6Sopenharmony_ci MMI_HILOGD("Cancel application authorization,pid:%{public}d", CurrentPID_); 938c29fa5a6Sopenharmony_ci CurrentPID_ = -1; 939c29fa5a6Sopenharmony_ci InjectionType_ = InjectionType::UNKNOWN; 940c29fa5a6Sopenharmony_ci keyEvent_ = nullptr; 941c29fa5a6Sopenharmony_ci pointerEvent_ = nullptr; 942c29fa5a6Sopenharmony_ci } 943c29fa5a6Sopenharmony_ci return ERR_OK; 944c29fa5a6Sopenharmony_ci} 945c29fa5a6Sopenharmony_ci 946c29fa5a6Sopenharmony_civoid ServerMsgHandler::SetWindowInfo(int32_t infoId, WindowInfo &info) 947c29fa5a6Sopenharmony_ci{ 948c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 949c29fa5a6Sopenharmony_ci if (transparentWins_.find(infoId) == transparentWins_.end()) { 950c29fa5a6Sopenharmony_ci MMI_HILOGE("The infoId is Invalid, infoId:%{public}d", infoId); 951c29fa5a6Sopenharmony_ci return; 952c29fa5a6Sopenharmony_ci } 953c29fa5a6Sopenharmony_ci info.pixelMap = transparentWins_[infoId].get(); 954c29fa5a6Sopenharmony_ci} 955c29fa5a6Sopenharmony_ci 956c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::SetPixelMapData(int32_t infoId, void *pixelMap) __attribute__((no_sanitize("cfi"))) 957c29fa5a6Sopenharmony_ci{ 958c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 959c29fa5a6Sopenharmony_ci if (infoId < 0 || pixelMap == nullptr) { 960c29fa5a6Sopenharmony_ci MMI_HILOGE("The infoId is invalid or pixelMap is nullptr"); 961c29fa5a6Sopenharmony_ci return ERR_INVALID_VALUE; 962c29fa5a6Sopenharmony_ci } 963c29fa5a6Sopenharmony_ci 964c29fa5a6Sopenharmony_ci WIN_MGR->SetPixelMapData(infoId, pixelMap); 965c29fa5a6Sopenharmony_ci return RET_OK; 966c29fa5a6Sopenharmony_ci} 967c29fa5a6Sopenharmony_ci 968c29fa5a6Sopenharmony_cibool ServerMsgHandler::InitInjectNoticeSource() 969c29fa5a6Sopenharmony_ci{ 970c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 971c29fa5a6Sopenharmony_ci MMI_HILOGD("Init InjectNoticeSource enter"); 972c29fa5a6Sopenharmony_ci if (injectNotice_ == nullptr) { 973c29fa5a6Sopenharmony_ci injectNotice_ = std::make_shared<InjectNoticeManager>(); 974c29fa5a6Sopenharmony_ci } 975c29fa5a6Sopenharmony_ci MMI_HILOGD("Injectnotice StartNoticeAbility ok"); 976c29fa5a6Sopenharmony_ci if (!injectNotice_->IsAbilityStart()) { 977c29fa5a6Sopenharmony_ci MMI_HILOGD("Injectnotice StartNoticeAbility begin"); 978c29fa5a6Sopenharmony_ci bool isStart = injectNotice_->StartNoticeAbility(); 979c29fa5a6Sopenharmony_ci if (!isStart) { 980c29fa5a6Sopenharmony_ci MMI_HILOGE("Injectnotice StartNoticeAbility isStart:%{public}d", isStart); 981c29fa5a6Sopenharmony_ci return false; 982c29fa5a6Sopenharmony_ci } 983c29fa5a6Sopenharmony_ci MMI_HILOGD("Injectnotice StartNoticeAbility ok"); 984c29fa5a6Sopenharmony_ci } 985c29fa5a6Sopenharmony_ci auto connection = injectNotice_->GetConnection(); 986c29fa5a6Sopenharmony_ci CHKPF(connection); 987c29fa5a6Sopenharmony_ci if (!connection->IsConnected()) { 988c29fa5a6Sopenharmony_ci MMI_HILOGD("Injectnotice ConnectNoticeSrv begin"); 989c29fa5a6Sopenharmony_ci bool isConnect = injectNotice_->ConnectNoticeSrv(); 990c29fa5a6Sopenharmony_ci if (!isConnect) { 991c29fa5a6Sopenharmony_ci MMI_HILOGD("Injectnotice ConnectNoticeSrv isConnect:%{public}d", isConnect); 992c29fa5a6Sopenharmony_ci return false; 993c29fa5a6Sopenharmony_ci } 994c29fa5a6Sopenharmony_ci MMI_HILOGD("Injectnotice ConnectNoticeSrv ok"); 995c29fa5a6Sopenharmony_ci } 996c29fa5a6Sopenharmony_ci MMI_HILOGD("Injectnotice InitInjectNoticeSource ok"); 997c29fa5a6Sopenharmony_ci return true; 998c29fa5a6Sopenharmony_ci} 999c29fa5a6Sopenharmony_ci 1000c29fa5a6Sopenharmony_cibool ServerMsgHandler::AddInjectNotice(const InjectNoticeInfo ¬iceInfo) 1001c29fa5a6Sopenharmony_ci{ 1002c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 1003c29fa5a6Sopenharmony_ci bool isInit = InitInjectNoticeSource(); 1004c29fa5a6Sopenharmony_ci if (!isInit) { 1005c29fa5a6Sopenharmony_ci MMI_HILOGE("InitinjectNotice_ Source error"); 1006c29fa5a6Sopenharmony_ci return false; 1007c29fa5a6Sopenharmony_ci } 1008c29fa5a6Sopenharmony_ci MMI_HILOGD("SendNotice submit begin"); 1009c29fa5a6Sopenharmony_ci ffrt::submit([this, noticeInfo] { 1010c29fa5a6Sopenharmony_ci MMI_HILOGD("SendNotice submit enter"); 1011c29fa5a6Sopenharmony_ci CHKPV(injectNotice_); 1012c29fa5a6Sopenharmony_ci auto pConnect = injectNotice_->GetConnection(); 1013c29fa5a6Sopenharmony_ci CHKPV(pConnect); 1014c29fa5a6Sopenharmony_ci int32_t timeSecond = 0; 1015c29fa5a6Sopenharmony_ci while (timeSecond <= SEND_NOTICE_OVERTIME) { 1016c29fa5a6Sopenharmony_ci bool isConnect = pConnect->IsConnected(); 1017c29fa5a6Sopenharmony_ci MMI_HILOGD("SendNotice %{public}d", isConnect); 1018c29fa5a6Sopenharmony_ci if (isConnect) { 1019c29fa5a6Sopenharmony_ci MMI_HILOGD("SendNotice begin"); 1020c29fa5a6Sopenharmony_ci pConnect->SendNotice(noticeInfo); 1021c29fa5a6Sopenharmony_ci break; 1022c29fa5a6Sopenharmony_ci } 1023c29fa5a6Sopenharmony_ci timeSecond += 1; 1024c29fa5a6Sopenharmony_ci sleep(1); 1025c29fa5a6Sopenharmony_ci } 1026c29fa5a6Sopenharmony_ci MMI_HILOGD("SendNotice submit leave"); 1027c29fa5a6Sopenharmony_ci }); 1028c29fa5a6Sopenharmony_ci return true; 1029c29fa5a6Sopenharmony_ci} 1030c29fa5a6Sopenharmony_ci 1031c29fa5a6Sopenharmony_cibool ServerMsgHandler::CloseInjectNotice(int32_t pid) 1032c29fa5a6Sopenharmony_ci{ 1033c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 1034c29fa5a6Sopenharmony_ci bool isInit = InitInjectNoticeSource(); 1035c29fa5a6Sopenharmony_ci if (!isInit) { 1036c29fa5a6Sopenharmony_ci MMI_HILOGE("InitinjectNotice_ Source error"); 1037c29fa5a6Sopenharmony_ci return false; 1038c29fa5a6Sopenharmony_ci } 1039c29fa5a6Sopenharmony_ci MMI_HILOGD("CloseNotice submit begin"); 1040c29fa5a6Sopenharmony_ci InjectNoticeInfo noticeInfo; 1041c29fa5a6Sopenharmony_ci noticeInfo.pid = pid; 1042c29fa5a6Sopenharmony_ci ffrt::submit([this, noticeInfo] { 1043c29fa5a6Sopenharmony_ci MMI_HILOGD("CloseNotice submit enter"); 1044c29fa5a6Sopenharmony_ci CHKPV(injectNotice_); 1045c29fa5a6Sopenharmony_ci auto pConnect = injectNotice_->GetConnection(); 1046c29fa5a6Sopenharmony_ci CHKPV(pConnect); 1047c29fa5a6Sopenharmony_ci int32_t timeSecond = 0; 1048c29fa5a6Sopenharmony_ci while (timeSecond <= SEND_NOTICE_OVERTIME) { 1049c29fa5a6Sopenharmony_ci bool isConnect = pConnect->IsConnected(); 1050c29fa5a6Sopenharmony_ci MMI_HILOGD("CloseNotice %{public}d", isConnect); 1051c29fa5a6Sopenharmony_ci if (isConnect) { 1052c29fa5a6Sopenharmony_ci MMI_HILOGD("CloseNotice begin"); 1053c29fa5a6Sopenharmony_ci pConnect->CancelNotice(noticeInfo); 1054c29fa5a6Sopenharmony_ci break; 1055c29fa5a6Sopenharmony_ci } 1056c29fa5a6Sopenharmony_ci timeSecond += 1; 1057c29fa5a6Sopenharmony_ci sleep(1); 1058c29fa5a6Sopenharmony_ci } 1059c29fa5a6Sopenharmony_ci MMI_HILOGD("CloseNotice submit leave"); 1060c29fa5a6Sopenharmony_ci }); 1061c29fa5a6Sopenharmony_ci return true; 1062c29fa5a6Sopenharmony_ci} 1063c29fa5a6Sopenharmony_ci 1064c29fa5a6Sopenharmony_ciint32_t ServerMsgHandler::OnTransferBinderClientSrv(const sptr<IRemoteObject> &binderClientObject, int32_t pid) 1065c29fa5a6Sopenharmony_ci{ 1066c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 1067c29fa5a6Sopenharmony_ci bool bRet = clientDeathHandler_.RegisterClientDeathRecipient(binderClientObject, pid); 1068c29fa5a6Sopenharmony_ci if (!bRet) { 1069c29fa5a6Sopenharmony_ci MMI_HILOGE("Failed to registerClientDeathRecipient"); 1070c29fa5a6Sopenharmony_ci return RET_ERR; 1071c29fa5a6Sopenharmony_ci } 1072c29fa5a6Sopenharmony_ci return ERR_OK; 1073c29fa5a6Sopenharmony_ci} 1074c29fa5a6Sopenharmony_ci} // namespace MMI 1075c29fa5a6Sopenharmony_ci} // namespace OHOS 1076