1885b47fbSopenharmony_ci/* 2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License. 5885b47fbSopenharmony_ci * You may obtain a copy of the License at 6885b47fbSopenharmony_ci * 7885b47fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8885b47fbSopenharmony_ci * 9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and 13885b47fbSopenharmony_ci * limitations under the License. 14885b47fbSopenharmony_ci */ 15885b47fbSopenharmony_ci 16885b47fbSopenharmony_ci#include "accessibility_input_interceptor.h" 17885b47fbSopenharmony_ci#include "accessibility_keyevent_filter.h" 18885b47fbSopenharmony_ci#include "accessibility_mouse_autoclick.h" 19885b47fbSopenharmony_ci#include "accessibility_short_key.h" 20885b47fbSopenharmony_ci#include "accessibility_screen_touch.h" 21885b47fbSopenharmony_ci#include "accessibility_touch_guider.h" 22885b47fbSopenharmony_ci#include "accessibility_touchEvent_injector.h" 23885b47fbSopenharmony_ci#include "accessibility_zoom_gesture.h" 24885b47fbSopenharmony_ci#include "accessible_ability_manager_service.h" 25885b47fbSopenharmony_ci#include "hilog_wrapper.h" 26885b47fbSopenharmony_ci#include "key_event.h" 27885b47fbSopenharmony_ci#include "input_event.h" 28885b47fbSopenharmony_ci 29885b47fbSopenharmony_cinamespace OHOS { 30885b47fbSopenharmony_cinamespace Accessibility { 31885b47fbSopenharmony_cisptr<AccessibilityInputInterceptor> AccessibilityInputInterceptor::instance_ = nullptr; 32885b47fbSopenharmony_cisptr<AccessibilityInputInterceptor> AccessibilityInputInterceptor::GetInstance() 33885b47fbSopenharmony_ci{ 34885b47fbSopenharmony_ci HILOG_DEBUG(); 35885b47fbSopenharmony_ci 36885b47fbSopenharmony_ci if (!instance_) { 37885b47fbSopenharmony_ci instance_ = new(std::nothrow) AccessibilityInputInterceptor(); 38885b47fbSopenharmony_ci if (!instance_) { 39885b47fbSopenharmony_ci HILOG_ERROR("instance_ is null"); 40885b47fbSopenharmony_ci return nullptr; 41885b47fbSopenharmony_ci } 42885b47fbSopenharmony_ci } 43885b47fbSopenharmony_ci return instance_; 44885b47fbSopenharmony_ci} 45885b47fbSopenharmony_ci 46885b47fbSopenharmony_ciAccessibilityInputInterceptor::AccessibilityInputInterceptor() 47885b47fbSopenharmony_ci{ 48885b47fbSopenharmony_ci HILOG_DEBUG(); 49885b47fbSopenharmony_ci 50885b47fbSopenharmony_ci inputManager_ = MMI::InputManager::GetInstance(); 51885b47fbSopenharmony_ci eventHandler_ = std::make_shared<AppExecFwk::EventHandler>( 52885b47fbSopenharmony_ci Singleton<AccessibleAbilityManagerService>::GetInstance().GetMainRunner()); 53885b47fbSopenharmony_ci} 54885b47fbSopenharmony_ci 55885b47fbSopenharmony_ciAccessibilityInputInterceptor::~AccessibilityInputInterceptor() 56885b47fbSopenharmony_ci{ 57885b47fbSopenharmony_ci HILOG_DEBUG(); 58885b47fbSopenharmony_ci 59885b47fbSopenharmony_ci availableFunctions_ = 0; 60885b47fbSopenharmony_ci DestroyInterceptor(); 61885b47fbSopenharmony_ci DestroyTransmitters(); 62885b47fbSopenharmony_ci inputManager_ = nullptr; 63885b47fbSopenharmony_ci inputEventConsumer_ = nullptr; 64885b47fbSopenharmony_ci} 65885b47fbSopenharmony_ci 66885b47fbSopenharmony_cibool AccessibilityInputInterceptor::OnKeyEvent(MMI::KeyEvent &event) 67885b47fbSopenharmony_ci{ 68885b47fbSopenharmony_ci HILOG_DEBUG(); 69885b47fbSopenharmony_ci 70885b47fbSopenharmony_ci event.AddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT); 71885b47fbSopenharmony_ci std::shared_ptr<MMI::KeyEvent> keyEvent = std::make_shared<MMI::KeyEvent>(event); 72885b47fbSopenharmony_ci if (inputManager_) { 73885b47fbSopenharmony_ci inputManager_->SimulateInputEvent(keyEvent); 74885b47fbSopenharmony_ci } else { 75885b47fbSopenharmony_ci HILOG_ERROR("inputManager_ is null."); 76885b47fbSopenharmony_ci } 77885b47fbSopenharmony_ci return true; 78885b47fbSopenharmony_ci} 79885b47fbSopenharmony_ci 80885b47fbSopenharmony_cibool AccessibilityInputInterceptor::OnPointerEvent(MMI::PointerEvent &event) 81885b47fbSopenharmony_ci{ 82885b47fbSopenharmony_ci HILOG_DEBUG("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d", 83885b47fbSopenharmony_ci event.GetPointerAction(), event.GetSourceType(), event.GetPointerId()); 84885b47fbSopenharmony_ci 85885b47fbSopenharmony_ci event.AddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT); 86885b47fbSopenharmony_ci std::shared_ptr<MMI::PointerEvent> pointerEvent = std::make_shared<MMI::PointerEvent>(event); 87885b47fbSopenharmony_ci if (inputManager_) { 88885b47fbSopenharmony_ci inputManager_->SimulateInputEvent(pointerEvent); 89885b47fbSopenharmony_ci } else { 90885b47fbSopenharmony_ci HILOG_ERROR("inputManager_ is null."); 91885b47fbSopenharmony_ci } 92885b47fbSopenharmony_ci return true; 93885b47fbSopenharmony_ci} 94885b47fbSopenharmony_ci 95885b47fbSopenharmony_civoid AccessibilityInputInterceptor::OnMoveMouse(int32_t offsetX, int32_t offsetY) 96885b47fbSopenharmony_ci{ 97885b47fbSopenharmony_ci HILOG_DEBUG("offsetX:%{public}d, offsetY:%{public}d", offsetX, offsetY); 98885b47fbSopenharmony_ci if (inputManager_) { 99885b47fbSopenharmony_ci inputManager_->MoveMouse(offsetX, offsetY); 100885b47fbSopenharmony_ci } else { 101885b47fbSopenharmony_ci HILOG_ERROR("inputManager_ is null."); 102885b47fbSopenharmony_ci } 103885b47fbSopenharmony_ci} 104885b47fbSopenharmony_ci 105885b47fbSopenharmony_civoid AccessibilityInputInterceptor::SetAvailableFunctions(uint32_t availableFunctions) 106885b47fbSopenharmony_ci{ 107885b47fbSopenharmony_ci HILOG_INFO("function[%{public}d].", availableFunctions); 108885b47fbSopenharmony_ci 109885b47fbSopenharmony_ci if (((availableFunctions_ & FEATURE_SCREEN_MAGNIFICATION) != FEATURE_SCREEN_MAGNIFICATION) && 110885b47fbSopenharmony_ci (availableFunctions_ == availableFunctions) && ((availableFunctions & FEATURE_SCREEN_TOUCH) == 0)) { 111885b47fbSopenharmony_ci return; 112885b47fbSopenharmony_ci } 113885b47fbSopenharmony_ci availableFunctions_ = availableFunctions; 114885b47fbSopenharmony_ci DestroyTransmitters(); 115885b47fbSopenharmony_ci CreateTransmitters(); 116885b47fbSopenharmony_ci UpdateInterceptor(); 117885b47fbSopenharmony_ci} 118885b47fbSopenharmony_ci 119885b47fbSopenharmony_civoid AccessibilityInputInterceptor::CreateTransmitters() 120885b47fbSopenharmony_ci{ 121885b47fbSopenharmony_ci HILOG_DEBUG("function[%{public}u].", availableFunctions_); 122885b47fbSopenharmony_ci 123885b47fbSopenharmony_ci if (!availableFunctions_) { 124885b47fbSopenharmony_ci return; 125885b47fbSopenharmony_ci } 126885b47fbSopenharmony_ci 127885b47fbSopenharmony_ci if ((availableFunctions_ & FEATURE_MOUSE_KEY) && (!mouseKey_)) { 128885b47fbSopenharmony_ci mouseKey_ = new(std::nothrow) AccessibilityMouseKey(); 129885b47fbSopenharmony_ci if (mouseKey_) { 130885b47fbSopenharmony_ci mouseKey_->SetNext(instance_); 131885b47fbSopenharmony_ci } 132885b47fbSopenharmony_ci } 133885b47fbSopenharmony_ci 134885b47fbSopenharmony_ci if ((availableFunctions_ & FEATURE_MOUSE_AUTOCLICK) || 135885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_INJECT_TOUCH_EVENTS) || 136885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_TOUCH_EXPLORATION) || 137885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_SCREEN_MAGNIFICATION) || 138885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_SCREEN_TOUCH)) { 139885b47fbSopenharmony_ci CreatePointerEventTransmitters(); 140885b47fbSopenharmony_ci } 141885b47fbSopenharmony_ci 142885b47fbSopenharmony_ci if (availableFunctions_ & FEATURE_FILTER_KEY_EVENTS) { 143885b47fbSopenharmony_ci CreateKeyEventTransmitters(); 144885b47fbSopenharmony_ci } 145885b47fbSopenharmony_ci} 146885b47fbSopenharmony_ci 147885b47fbSopenharmony_civoid AccessibilityInputInterceptor::CreatePointerEventTransmitters() 148885b47fbSopenharmony_ci{ 149885b47fbSopenharmony_ci HILOG_DEBUG(); 150885b47fbSopenharmony_ci 151885b47fbSopenharmony_ci sptr<EventTransmission> header = nullptr; 152885b47fbSopenharmony_ci sptr<EventTransmission> current = nullptr; 153885b47fbSopenharmony_ci 154885b47fbSopenharmony_ci if (availableFunctions_& FEATURE_MOUSE_AUTOCLICK) { 155885b47fbSopenharmony_ci sptr<AccessibilityMouseAutoclick> mouseAutoclick = new(std::nothrow) AccessibilityMouseAutoclick(); 156885b47fbSopenharmony_ci if (!mouseAutoclick) { 157885b47fbSopenharmony_ci HILOG_ERROR("mouseAutoclick is null"); 158885b47fbSopenharmony_ci return; 159885b47fbSopenharmony_ci } 160885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, mouseAutoclick); 161885b47fbSopenharmony_ci } 162885b47fbSopenharmony_ci 163885b47fbSopenharmony_ci if (availableFunctions_& FEATURE_INJECT_TOUCH_EVENTS) { 164885b47fbSopenharmony_ci sptr<TouchEventInjector> touchEventInjector = new(std::nothrow) TouchEventInjector(); 165885b47fbSopenharmony_ci if (!touchEventInjector) { 166885b47fbSopenharmony_ci HILOG_ERROR("touchEventInjector is null"); 167885b47fbSopenharmony_ci return; 168885b47fbSopenharmony_ci } 169885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, touchEventInjector); 170885b47fbSopenharmony_ci Singleton<AccessibleAbilityManagerService>::GetInstance().SetTouchEventInjector(touchEventInjector); 171885b47fbSopenharmony_ci } 172885b47fbSopenharmony_ci 173885b47fbSopenharmony_ci if (availableFunctions_& FEATURE_SCREEN_MAGNIFICATION) { 174885b47fbSopenharmony_ci sptr<AccessibilityZoomGesture> zoomGesture = new(std::nothrow) AccessibilityZoomGesture(); 175885b47fbSopenharmony_ci if (!zoomGesture) { 176885b47fbSopenharmony_ci HILOG_ERROR("zoomGesture is null"); 177885b47fbSopenharmony_ci return; 178885b47fbSopenharmony_ci } 179885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, zoomGesture); 180885b47fbSopenharmony_ci } 181885b47fbSopenharmony_ci 182885b47fbSopenharmony_ci if (availableFunctions_& FEATURE_TOUCH_EXPLORATION) { 183885b47fbSopenharmony_ci sptr<TouchGuider> touchGuider = new(std::nothrow) TouchGuider(); 184885b47fbSopenharmony_ci if (!touchGuider) { 185885b47fbSopenharmony_ci HILOG_ERROR("touchGuider is null"); 186885b47fbSopenharmony_ci return; 187885b47fbSopenharmony_ci } 188885b47fbSopenharmony_ci touchGuider->StartUp(); 189885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, touchGuider); 190885b47fbSopenharmony_ci } 191885b47fbSopenharmony_ci 192885b47fbSopenharmony_ci if ((availableFunctions_ & FEATURE_SCREEN_TOUCH) && ((availableFunctions_ & FEATURE_TOUCH_EXPLORATION) == 0)) { 193885b47fbSopenharmony_ci sptr<AccessibilityScreenTouch> screenTouch = new(std::nothrow) AccessibilityScreenTouch(); 194885b47fbSopenharmony_ci if (!screenTouch) { 195885b47fbSopenharmony_ci HILOG_ERROR("screenTouch is null"); 196885b47fbSopenharmony_ci return; 197885b47fbSopenharmony_ci } 198885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, screenTouch); 199885b47fbSopenharmony_ci } 200885b47fbSopenharmony_ci 201885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, instance_); 202885b47fbSopenharmony_ci pointerEventTransmitters_ = header; 203885b47fbSopenharmony_ci} 204885b47fbSopenharmony_ci 205885b47fbSopenharmony_civoid AccessibilityInputInterceptor::CreateKeyEventTransmitters() 206885b47fbSopenharmony_ci{ 207885b47fbSopenharmony_ci HILOG_DEBUG(); 208885b47fbSopenharmony_ci 209885b47fbSopenharmony_ci sptr<EventTransmission> header = nullptr; 210885b47fbSopenharmony_ci sptr<EventTransmission> current = nullptr; 211885b47fbSopenharmony_ci 212885b47fbSopenharmony_ci if (availableFunctions_& FEATURE_FILTER_KEY_EVENTS) { 213885b47fbSopenharmony_ci sptr<KeyEventFilter> keyEventFilter = new(std::nothrow) KeyEventFilter(); 214885b47fbSopenharmony_ci if (!keyEventFilter) { 215885b47fbSopenharmony_ci HILOG_ERROR("keyEventFilter is null"); 216885b47fbSopenharmony_ci return; 217885b47fbSopenharmony_ci } 218885b47fbSopenharmony_ci Singleton<AccessibleAbilityManagerService>::GetInstance().SetKeyEventFilter(keyEventFilter); 219885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, keyEventFilter); 220885b47fbSopenharmony_ci } 221885b47fbSopenharmony_ci 222885b47fbSopenharmony_ci SetNextEventTransmitter(header, current, instance_); 223885b47fbSopenharmony_ci keyEventTransmitters_ = header; 224885b47fbSopenharmony_ci} 225885b47fbSopenharmony_ci 226885b47fbSopenharmony_civoid AccessibilityInputInterceptor::UpdateInterceptor() 227885b47fbSopenharmony_ci{ 228885b47fbSopenharmony_ci HILOG_DEBUG(); 229885b47fbSopenharmony_ci if (!inputManager_) { 230885b47fbSopenharmony_ci HILOG_ERROR("inputManger is null."); 231885b47fbSopenharmony_ci return; 232885b47fbSopenharmony_ci } 233885b47fbSopenharmony_ci 234885b47fbSopenharmony_ci if (interceptorId_ >= 0) { 235885b47fbSopenharmony_ci inputManager_->RemoveInterceptor(interceptorId_); 236885b47fbSopenharmony_ci interceptorId_ = -1; 237885b47fbSopenharmony_ci } 238885b47fbSopenharmony_ci 239885b47fbSopenharmony_ci if ((availableFunctions_ & FEATURE_MOUSE_AUTOCLICK) || 240885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_TOUCH_EXPLORATION) || 241885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_SCREEN_MAGNIFICATION) || 242885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_MOUSE_KEY) || 243885b47fbSopenharmony_ci (availableFunctions_ & FEATURE_SCREEN_TOUCH)) { 244885b47fbSopenharmony_ci inputEventConsumer_ = std::make_shared<AccessibilityInputEventConsumer>(); 245885b47fbSopenharmony_ci interceptorId_ = inputManager_->AddInterceptor(inputEventConsumer_); 246885b47fbSopenharmony_ci } else if (availableFunctions_ & FEATURE_FILTER_KEY_EVENTS) { 247885b47fbSopenharmony_ci inputEventConsumer_ = std::make_shared<AccessibilityInputEventConsumer>(); 248885b47fbSopenharmony_ci interceptorId_ = inputManager_->AddInterceptor(inputEventConsumer_, PRIORITY_EVENT, 249885b47fbSopenharmony_ci MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_KEYBOARD)); 250885b47fbSopenharmony_ci } 251885b47fbSopenharmony_ci HILOG_INFO("interceptorId:%{public}d", interceptorId_); 252885b47fbSopenharmony_ci} 253885b47fbSopenharmony_ci 254885b47fbSopenharmony_civoid AccessibilityInputInterceptor::DestroyInterceptor() 255885b47fbSopenharmony_ci{ 256885b47fbSopenharmony_ci HILOG_DEBUG("interceptorId:%{public}d.", interceptorId_); 257885b47fbSopenharmony_ci 258885b47fbSopenharmony_ci if (!inputManager_) { 259885b47fbSopenharmony_ci HILOG_ERROR("inputManager_ is null."); 260885b47fbSopenharmony_ci return; 261885b47fbSopenharmony_ci } 262885b47fbSopenharmony_ci if (interceptorId_ >= 0) { 263885b47fbSopenharmony_ci inputManager_->RemoveInterceptor(interceptorId_); 264885b47fbSopenharmony_ci } 265885b47fbSopenharmony_ci interceptorId_ = -1; 266885b47fbSopenharmony_ci} 267885b47fbSopenharmony_ci 268885b47fbSopenharmony_civoid AccessibilityInputInterceptor::DestroyTransmitters() 269885b47fbSopenharmony_ci{ 270885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(mutex_); 271885b47fbSopenharmony_ci HILOG_DEBUG(); 272885b47fbSopenharmony_ci 273885b47fbSopenharmony_ci if ((availableFunctions_ & FEATURE_MOUSE_KEY) != FEATURE_MOUSE_KEY) { 274885b47fbSopenharmony_ci if (mouseKey_) { 275885b47fbSopenharmony_ci mouseKey_->DestroyEvents(); 276885b47fbSopenharmony_ci mouseKey_ = nullptr; 277885b47fbSopenharmony_ci } 278885b47fbSopenharmony_ci } 279885b47fbSopenharmony_ci 280885b47fbSopenharmony_ci if (pointerEventTransmitters_ != nullptr) { 281885b47fbSopenharmony_ci pointerEventTransmitters_->DestroyEvents(); 282885b47fbSopenharmony_ci Singleton<AccessibleAbilityManagerService>::GetInstance().SetTouchEventInjector(nullptr); 283885b47fbSopenharmony_ci pointerEventTransmitters_= nullptr; 284885b47fbSopenharmony_ci } 285885b47fbSopenharmony_ci if (keyEventTransmitters_ != nullptr) { 286885b47fbSopenharmony_ci keyEventTransmitters_->DestroyEvents(); 287885b47fbSopenharmony_ci Singleton<AccessibleAbilityManagerService>::GetInstance().SetKeyEventFilter(nullptr); 288885b47fbSopenharmony_ci keyEventTransmitters_ = nullptr; 289885b47fbSopenharmony_ci } 290885b47fbSopenharmony_ci} 291885b47fbSopenharmony_ci 292885b47fbSopenharmony_civoid AccessibilityInputInterceptor::ProcessPointerEvent(std::shared_ptr<MMI::PointerEvent> event) 293885b47fbSopenharmony_ci{ 294885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(mutex_); 295885b47fbSopenharmony_ci HILOG_DEBUG(); 296885b47fbSopenharmony_ci 297885b47fbSopenharmony_ci if (mouseKey_) { 298885b47fbSopenharmony_ci mouseKey_->OnPointerEvent(*event); 299885b47fbSopenharmony_ci } 300885b47fbSopenharmony_ci 301885b47fbSopenharmony_ci if (!pointerEventTransmitters_) { 302885b47fbSopenharmony_ci HILOG_DEBUG("pointerEventTransmitters_ is empty."); 303885b47fbSopenharmony_ci const_cast<AccessibilityInputInterceptor*>(this)->OnPointerEvent(*event); 304885b47fbSopenharmony_ci return; 305885b47fbSopenharmony_ci } 306885b47fbSopenharmony_ci 307885b47fbSopenharmony_ci pointerEventTransmitters_->OnPointerEvent(*event); 308885b47fbSopenharmony_ci} 309885b47fbSopenharmony_ci 310885b47fbSopenharmony_civoid AccessibilityInputInterceptor::ProcessKeyEvent(std::shared_ptr<MMI::KeyEvent> event) 311885b47fbSopenharmony_ci{ 312885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(mutex_); 313885b47fbSopenharmony_ci HILOG_DEBUG(); 314885b47fbSopenharmony_ci 315885b47fbSopenharmony_ci if (mouseKey_) { 316885b47fbSopenharmony_ci bool result = mouseKey_->OnKeyEvent(*event); 317885b47fbSopenharmony_ci if (result) { 318885b47fbSopenharmony_ci HILOG_DEBUG("The event is mouse key event."); 319885b47fbSopenharmony_ci return; 320885b47fbSopenharmony_ci } 321885b47fbSopenharmony_ci } 322885b47fbSopenharmony_ci 323885b47fbSopenharmony_ci if (!keyEventTransmitters_) { 324885b47fbSopenharmony_ci HILOG_DEBUG("keyEventTransmitters_ is empty."); 325885b47fbSopenharmony_ci const_cast<AccessibilityInputInterceptor*>(this)->OnKeyEvent(*event); 326885b47fbSopenharmony_ci return; 327885b47fbSopenharmony_ci } 328885b47fbSopenharmony_ci 329885b47fbSopenharmony_ci keyEventTransmitters_->OnKeyEvent(*event); 330885b47fbSopenharmony_ci} 331885b47fbSopenharmony_ci 332885b47fbSopenharmony_civoid AccessibilityInputInterceptor::SetNextEventTransmitter(sptr<EventTransmission> &header, 333885b47fbSopenharmony_ci sptr<EventTransmission> ¤t, const sptr<EventTransmission> &next) 334885b47fbSopenharmony_ci{ 335885b47fbSopenharmony_ci HILOG_DEBUG(); 336885b47fbSopenharmony_ci 337885b47fbSopenharmony_ci if (current != nullptr) { 338885b47fbSopenharmony_ci current->SetNext(next); 339885b47fbSopenharmony_ci } else { 340885b47fbSopenharmony_ci header = next; 341885b47fbSopenharmony_ci } 342885b47fbSopenharmony_ci current = next; 343885b47fbSopenharmony_ci} 344885b47fbSopenharmony_ci 345885b47fbSopenharmony_ciAccessibilityInputEventConsumer::AccessibilityInputEventConsumer() 346885b47fbSopenharmony_ci{ 347885b47fbSopenharmony_ci HILOG_DEBUG(); 348885b47fbSopenharmony_ci eventHandler_ = std::make_shared<AppExecFwk::EventHandler>( 349885b47fbSopenharmony_ci Singleton<AccessibleAbilityManagerService>::GetInstance().GetMainRunner()); 350885b47fbSopenharmony_ci} 351885b47fbSopenharmony_ci 352885b47fbSopenharmony_ciAccessibilityInputEventConsumer::~AccessibilityInputEventConsumer() 353885b47fbSopenharmony_ci{ 354885b47fbSopenharmony_ci HILOG_DEBUG(); 355885b47fbSopenharmony_ci 356885b47fbSopenharmony_ci eventHandler_ = nullptr; 357885b47fbSopenharmony_ci} 358885b47fbSopenharmony_ci 359885b47fbSopenharmony_civoid AccessibilityInputEventConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const 360885b47fbSopenharmony_ci{ 361885b47fbSopenharmony_ci HILOG_DEBUG(); 362885b47fbSopenharmony_ci if (!keyEvent) { 363885b47fbSopenharmony_ci HILOG_WARN("keyEvent is null."); 364885b47fbSopenharmony_ci return; 365885b47fbSopenharmony_ci } 366885b47fbSopenharmony_ci 367885b47fbSopenharmony_ci auto interceptor = AccessibilityInputInterceptor::GetInstance(); 368885b47fbSopenharmony_ci if (!interceptor) { 369885b47fbSopenharmony_ci HILOG_ERROR("interceptor is null."); 370885b47fbSopenharmony_ci return; 371885b47fbSopenharmony_ci } 372885b47fbSopenharmony_ci 373885b47fbSopenharmony_ci if (!eventHandler_) { 374885b47fbSopenharmony_ci HILOG_ERROR("eventHandler is empty."); 375885b47fbSopenharmony_ci return; 376885b47fbSopenharmony_ci } 377885b47fbSopenharmony_ci 378885b47fbSopenharmony_ci auto task = [keyEvent, interceptor] {interceptor->ProcessKeyEvent(keyEvent);}; 379885b47fbSopenharmony_ci eventHandler_->PostTask(task, "InputKeyEvent"); 380885b47fbSopenharmony_ci} 381885b47fbSopenharmony_ci 382885b47fbSopenharmony_civoid AccessibilityInputEventConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const 383885b47fbSopenharmony_ci{ 384885b47fbSopenharmony_ci if (!pointerEvent) { 385885b47fbSopenharmony_ci HILOG_WARN("pointerEvent is null."); 386885b47fbSopenharmony_ci return; 387885b47fbSopenharmony_ci } 388885b47fbSopenharmony_ci HILOG_DEBUG("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d.", 389885b47fbSopenharmony_ci pointerEvent->GetPointerAction(), pointerEvent->GetSourceType(), pointerEvent->GetPointerId()); 390885b47fbSopenharmony_ci 391885b47fbSopenharmony_ci auto interceptor = AccessibilityInputInterceptor::GetInstance(); 392885b47fbSopenharmony_ci if (!interceptor) { 393885b47fbSopenharmony_ci HILOG_ERROR("interceptor is null."); 394885b47fbSopenharmony_ci return; 395885b47fbSopenharmony_ci } 396885b47fbSopenharmony_ci 397885b47fbSopenharmony_ci if (!eventHandler_) { 398885b47fbSopenharmony_ci HILOG_ERROR("eventHandler is empty."); 399885b47fbSopenharmony_ci return; 400885b47fbSopenharmony_ci } 401885b47fbSopenharmony_ci auto task = [pointerEvent, interceptor] {interceptor->ProcessPointerEvent(pointerEvent);}; 402885b47fbSopenharmony_ci eventHandler_->PostTask(task, "InputPointerEvent"); 403885b47fbSopenharmony_ci} 404885b47fbSopenharmony_ci} // namespace Accessibility 405885b47fbSopenharmony_ci} // namespace OHOS