1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef EVENT_FILTER_HANDLER_H 17 #define EVENT_FILTER_HANDLER_H 18 19 #include "event_filter_death_recipient.h" 20 #include "i_event_filter.h" 21 #include "i_input_event_handler.h" 22 23 namespace OHOS { 24 namespace MMI { 25 class EventFilterHandler final : public IInputEventHandler, public std::enable_shared_from_this<EventFilterHandler> { 26 public: 27 EventFilterHandler() = default; 28 DISALLOW_COPY_AND_MOVE(EventFilterHandler); 29 ~EventFilterHandler() override = default; 30 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 31 void HandleKeyEvent(const std::shared_ptr<KeyEvent> keyEvent) override; 32 #endif // OHOS_BUILD_ENABLE_KEYBOARD 33 #ifdef OHOS_BUILD_ENABLE_POINTER 34 void HandlePointerEvent(const std::shared_ptr<PointerEvent> pointerEvent) override; 35 #endif // OHOS_BUILD_ENABLE_POINTER 36 #ifdef OHOS_BUILD_ENABLE_TOUCH 37 void HandleTouchEvent(const std::shared_ptr<PointerEvent> pointerEvent) override; 38 #endif // OHOS_BUILD_ENABLE_TOUCH 39 int32_t AddInputEventFilter(sptr<IEventFilter> filter, int32_t filterId, int32_t priority, uint32_t deviceTags, 40 int32_t clientPid); 41 int32_t RemoveInputEventFilter(int32_t filterId, int32_t clientPid); 42 void Dump(int32_t fd, const std::vector<std::string> &args); 43 bool HandleKeyEventFilter(std::shared_ptr<KeyEvent> event); 44 bool HandlePointerEventFilter(std::shared_ptr<PointerEvent> event); 45 bool CheckCapability(uint32_t deviceTags, std::shared_ptr<PointerEvent> event); 46 private: 47 bool TouchPadKnuckleDoubleClickHandle(std::shared_ptr<KeyEvent> event); 48 private: 49 std::mutex lockFilter_; 50 struct FilterInfo { 51 const sptr<IEventFilter> filter; 52 sptr<IRemoteObject::DeathRecipient> deathRecipient { nullptr }; 53 const int32_t filterId; 54 const int32_t priority; 55 const uint32_t deviceTags; 56 const int32_t clientPid; IsSameClientFilterInfo57 bool IsSameClient(int32_t id, int32_t pid) const { return ((filterId == id) && (clientPid == pid)); } 58 }; 59 std::list<FilterInfo> filters_; 60 }; 61 } // namespace MMI 62 } // namespace OHOS 63 #endif // EVENT_FILTER_HANDLER_H