diff --git a/frameworks/proxy/BUILD.gn b/frameworks/proxy/BUILD.gn index 662dcfe9a89fd708eec22f27027e4476fa995207..5ced4ce5f59ccdd154c8fdc1450cc3a9b9a3c5d2 100644 --- a/frameworks/proxy/BUILD.gn +++ b/frameworks/proxy/BUILD.gn @@ -378,6 +378,62 @@ ohos_unittest("InputManagerTest") { external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } +ohos_unittest("InputManagerManualTest") { + module_out_path = module_output_path + include_dirs = [ + "//utils/native/base/include", + "//third_party/googletest/googletest/include", + "${mmi_path}/frameworks/util/common", + "${mmi_path}/frameworks/util/common/include", + "${mmi_path}/frameworks/util/network", + "${mmi_path}/frameworks/util/network/include", + "${mmi_path}/frameworks/util/socket", + "${mmi_path}/frameworks/util/socket/include", + "${mmi_path}/frameworks/proxy/event_handle", + "${mmi_path}/frameworks/proxy/event_handle/include", + "${mmi_path}/frameworks/proxy/module_loader", + "${mmi_path}/frameworks/proxy/module_loader/include", + "${mmi_path}/common/include", + "${mmi_path}/interfaces/native/innerkits/common/include", + "${mmi_path}/interfaces/native/innerkits/proxy/include", + "${mmi_path}/interfaces/native/innerkits/event/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + ] + + if (is_mmi_have_libinput) { + include_dirs += [ "$root_out_dir/diff_libinput_mmi/src" ] + } + + cflags = [ "-DOHOS_BUILD" ] + + if (is_mmi_have_debug) { + cflags += [ "-DOHOS_BUILD_MMI_DEBUG" ] + } + + if (is_mmi_have_libinput) { + cflags += [ "-DOHOS_BUILD_LIBINPUT" ] + } + + if (is_mmi_have_hdf) { + cflags += [ "-DOHOS_BUILD_HDF" ] + } + + if (is_mmi_have_ai) { + cflags += [ "-DOHOS_BUILD_AI" ] + } + + sources = [ "events/test/input_manager_manual_test.cpp" ] + + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/frameworks/util:libmmi-util", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + ohos_unittest("PointerEventTest") { module_out_path = module_output_path include_dirs = [ diff --git a/frameworks/proxy/event_handle/src/input_manager_impl.cpp b/frameworks/proxy/event_handle/src/input_manager_impl.cpp index ea0889a7b12f7e76ac5976b5392744ebeead57c3..e601bbfa923312a3be4e7b315d45145bcbcd136b 100644 --- a/frameworks/proxy/event_handle/src/input_manager_impl.cpp +++ b/frameworks/proxy/event_handle/src/input_manager_impl.cpp @@ -57,29 +57,36 @@ void InputManagerImpl::UpdateDisplayInfo(const std::vector MMI_LOGD("InputManagerImpl::UpdateDisplayInfo leave!"); } -void InputManagerImpl::SetInputEventFilter(std::function)> filter) +int32_t InputManagerImpl::AddInputEventFilter(std::function)> filter) { + MMI_LOGT("enter"); if (eventFilterService_ == nullptr) { eventFilterService_ = new EventFilterService(); + MMI_LOGD("new EventFilterService"); } if (eventFilterService_ == nullptr) { MMI_LOGE("eventFilterService_ is nullptr"); - return; + return RET_ERR; } eventFilterService_->SetPointerEventPtr(filter); static bool hasSendToMmiServer = false; if (!hasSendToMmiServer) { - int32_t ret = MultimodalInputConnectManager::GetInstance()->SetInputEventFilter(eventFilterService_); + int32_t ret = MultimodalInputConnectManager::GetInstance()->AddInputEventFilter(eventFilterService_); if (ret == RET_OK) { hasSendToMmiServer = true; - MMI_LOGI("SetInputEventFilter has send to server success"); + MMI_LOGI("AddInputEventFilter has send to server success"); + return RET_OK; } else { - MMI_LOGE("SetInputEventFilter has send to server fail, ret = %{public}d", ret); + MMI_LOGE("AddInputEventFilter has send to server fail, ret = %{public}d", ret); + return RET_ERR; } } + + MMI_LOGT("leave, success with hasSendToMmiServer is already true"); + return RET_OK; } void InputManagerImpl::SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer) diff --git a/frameworks/proxy/events/src/input_manager.cpp b/frameworks/proxy/events/src/input_manager.cpp index 128471b09d66ebd83c094411ae743291fc38119f..fc078df648dc9731d4d791271464cb2c6a3e6217 100644 --- a/frameworks/proxy/events/src/input_manager.cpp +++ b/frameworks/proxy/events/src/input_manager.cpp @@ -45,7 +45,10 @@ void InputManager::UpdateDisplayInfo(const std::vector &phy InputManagerImpl::GetInstance()->UpdateDisplayInfo(physicalDisplays, logicalDisplays); } -void InputManager::SetInputEventFilter(std::function filter)>) {} +int32_t InputManager::AddInputEventFilter(std::function)> filter) +{ + return InputManagerImpl::GetInstance()->AddInputEventFilter(filter); +} void InputManager::SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer) { diff --git a/frameworks/proxy/events/test/input_manager_manual_test.cpp b/frameworks/proxy/events/test/input_manager_manual_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3489ab27a086a1eabbc62b490d56179266e2acae --- /dev/null +++ b/frameworks/proxy/events/test/input_manager_manual_test.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "define_multimodal.h" +#include "error_multimodal.h" +#include "input_event_monitor_manager.h" +#include "input_handler_manager.h" +#include "input_manager.h" +#include "interceptor_manager.h" +#include "key_event_pre.h" +#include "multimodal_event_handler.h" +#include "pointer_event.h" +#include "proto.h" +#include "run_shell_util.h" + +namespace { +using namespace testing::ext; +using namespace OHOS; +using namespace MMI; +namespace { +constexpr int32_t TIME_WAIT_FOR_OP = 500; +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManagerManualTest" }; +} + +class InputManagerManualTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + + void SetUp(); + void TearDown() {} + +protected: + void AddInputEventFilter(); + void SimulateInputEventHelper(int32_t globalX, int32_t globalY, int32_t expectVal); +private: + int32_t callbackRet = 0; +}; + +void InputManagerManualTest::SetUp() +{ + callbackRet = 0; +} + +void InputManagerManualTest::AddInputEventFilter() +{ + MMI_LOGT("enter"); + auto callback = [this](std::shared_ptr pointer) -> bool { + MMI_LOGT("enter"); + if (pointer == nullptr) { + MMI_LOGE("pointer is null"); + return false; + } + + const std::vector ids = pointer->GetPointersIdList(); + if (ids.empty()) { + MMI_LOGE("ids is empty"); + return false; + } + + const int firstPointerId = ids[0]; + PointerEvent::PointerItem item; + if (!pointer->GetPointerItem(firstPointerId, item)) { + MMI_LOGE("GetPointerItem(%{public}d) fail", firstPointerId); + return false; + } + + const int32_t x = item.GetGlobalX(); + const int32_t y = item.GetGlobalY(); + if (x == 10 && y == 10) { + MMI_LOGI("The values of X and y are both 10, which meets the expectation and callbackRet is set to 1"); + callbackRet = 1; + return true; + } + + MMI_LOGI("The values of X and y are not 10, which meets the expectation and callbackRet is set to 2"); + callbackRet = 2; + return false; + }; + + int ret = InputManager::GetInstance()->AddInputEventFilter(callback); + ASSERT_EQ(ret, RET_OK); + MMI_LOGT("leave"); +} + +void InputManagerManualTest::SimulateInputEventHelper(int32_t globalX, int32_t globalY, int32_t expectVal) +{ + MMI_LOGT("enter"); + const int32_t pointerId = 0; + PointerEvent::PointerItem item; + item.SetPointerId(pointerId); + item.SetGlobalX(globalX); + item.SetGlobalY(globalY); + + auto pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetSourceType(-1); + pointerEvent->SetPointerId(pointerId); + + MMI_LOGI("Call InputManager::SimulateInputEvent"); + InputManager::GetInstance()->SimulateInputEvent(pointerEvent); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + EXPECT_EQ(callbackRet, expectVal); + MMI_LOGT("leave"); +} + +HWTEST_F(InputManagerManualTest, HandlePointerEventFilter_001, TestSize.Level1) +{ + MMI_LOGT("enter"); + AddInputEventFilter(); + SimulateInputEventHelper(10, 10, 1); // set global x and global y are 10, will expect value is 1 + SimulateInputEventHelper(0, 0, 2); // set global x and global y are not 10, will expect value is 2 +} +} \ No newline at end of file diff --git a/interfaces/native/innerkits/event/include/input_manager_impl.h b/interfaces/native/innerkits/event/include/input_manager_impl.h index 37e2075dac6c0ea4f76659375170ccb947e04b7e..47a6411f6ef23bdab6a5e4840ed59cc9a41bc665 100644 --- a/interfaces/native/innerkits/event/include/input_manager_impl.h +++ b/interfaces/native/innerkits/event/include/input_manager_impl.h @@ -35,7 +35,7 @@ public: void UpdateDisplayInfo(const std::vector &physicalDisplays, const std::vector &logicalDisplays); // 建议本地调用,可IPC - void SetInputEventFilter(std::function filter)>); // 只能本地 + int32_t AddInputEventFilter(std::function)> filter); void SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer); diff --git a/interfaces/native/innerkits/proxy/include/input_manager.h b/interfaces/native/innerkits/proxy/include/input_manager.h index e628dd73754de3fb0350731259c079862322f1bb..d5f610ff581a38e4d0a396b0c116ca316ae16910 100644 --- a/interfaces/native/innerkits/proxy/include/input_manager.h +++ b/interfaces/native/innerkits/proxy/include/input_manager.h @@ -34,7 +34,7 @@ public: void UpdateDisplayInfo(const std::vector &physicalDisplays, const std::vector &logicalDisplays); // 建议本地调用,可IPC - void SetInputEventFilter(std::function filter)>); // 只能本地 + int32_t AddInputEventFilter(std::function)> filter); void SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer); diff --git a/service/connect_manager/include/i_multimodal_input_connect.h b/service/connect_manager/include/i_multimodal_input_connect.h index a7e4e2aca6225afff43024eeb6103025332b883e..960f7a5201276fd03d6549fd45c0068a50e2ca34 100644 --- a/service/connect_manager/include/i_multimodal_input_connect.h +++ b/service/connect_manager/include/i_multimodal_input_connect.h @@ -28,7 +28,7 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.multimodalinput.IConnectManager"); virtual int32_t AllocSocketFd(const std::string &programName, const int moduleType, int &socketFd) = 0; - virtual int32_t SetInputEventFilter(sptr filter) = 0; + virtual int32_t AddInputEventFilter(sptr filter) = 0; enum { ALLOC_SOCKET_FD = 0, diff --git a/service/connect_manager/include/i_multimodal_input_connect_stub.h b/service/connect_manager/include/i_multimodal_input_connect_stub.h index 220302ad9654d62088ebb434127aa0fb0c3c45f0..4a5c58c31097a9f304be6a470ceb43e7b04a9f9e 100644 --- a/service/connect_manager/include/i_multimodal_input_connect_stub.h +++ b/service/connect_manager/include/i_multimodal_input_connect_stub.h @@ -37,7 +37,7 @@ protected: int32_t GetCallingUid() const; int32_t GetCallingPid() const; virtual int32_t HandleAllocSocketFd(MessageParcel &data, MessageParcel &reply) = 0; - int32_t StubSetInputEventFilter(MessageParcel& data, MessageParcel& reply); + int32_t StubAddInputEventFilter(MessageParcel& data, MessageParcel& reply); private: static const int SYSTEM_UID = 1000; diff --git a/service/connect_manager/include/multimodal_input_connect_manager.h b/service/connect_manager/include/multimodal_input_connect_manager.h index 5b3f4082938084f2fb6e6572ea587a61d19f99fe..1405f7df7326d6081a0193f8101fd4c08efc9d7e 100644 --- a/service/connect_manager/include/multimodal_input_connect_manager.h +++ b/service/connect_manager/include/multimodal_input_connect_manager.h @@ -31,7 +31,7 @@ public: static std::shared_ptr GetInstance(); int32_t AllocSocketPair(const int moduleType); int GetClientSocketFdOfAllocedSocketPair() const; - int32_t SetInputEventFilter(sptr filter); + int32_t AddInputEventFilter(sptr filter); private: MultimodalInputConnectManager() = default; MultimodalInputConnectManager(const MultimodalInputConnectManager &manager) = delete; diff --git a/service/connect_manager/include/multimodal_input_connect_proxy.h b/service/connect_manager/include/multimodal_input_connect_proxy.h index 67406405f17f456c4ec284b16eafdb538db456a0..c76349ed3a8791b24fad438298fbe318536969b4 100644 --- a/service/connect_manager/include/multimodal_input_connect_proxy.h +++ b/service/connect_manager/include/multimodal_input_connect_proxy.h @@ -30,7 +30,7 @@ public: explicit MultimodalInputConnectProxy(const sptr &impl); virtual ~MultimodalInputConnectProxy() override; virtual int32_t AllocSocketFd(const std::string &programName, const int moduleType, int &socketFd) override; - virtual int32_t SetInputEventFilter(sptr filter) override; + virtual int32_t AddInputEventFilter(sptr filter) override; private: static inline BrokerDelegator delegator_; }; diff --git a/service/connect_manager/include/multimodal_input_connect_service.h b/service/connect_manager/include/multimodal_input_connect_service.h index 9ed33e035990b032f0f8355bd9b938dc8a6c0d09..6bf44adc822c5cc3421df38b0429816dc933bdeb 100644 --- a/service/connect_manager/include/multimodal_input_connect_service.h +++ b/service/connect_manager/include/multimodal_input_connect_service.h @@ -36,7 +36,7 @@ public: void OnStop() override; void OnDump() override; virtual int32_t AllocSocketFd(const std::string &programName, const int moduleType, int &socketFd) override; - virtual int32_t SetInputEventFilter(sptr filter) override; + virtual int32_t AddInputEventFilter(sptr filter) override; protected: virtual int32_t HandleAllocSocketFd(MessageParcel &data, MessageParcel &reply) override; diff --git a/service/connect_manager/src/i_multimodal_input_connect_stub.cpp b/service/connect_manager/src/i_multimodal_input_connect_stub.cpp index d48e4945260ee02c25940b8179a35d81e60b0b7a..f6460dddfd43df2e91b844797675c63434b027b1 100644 --- a/service/connect_manager/src/i_multimodal_input_connect_stub.cpp +++ b/service/connect_manager/src/i_multimodal_input_connect_stub.cpp @@ -44,7 +44,7 @@ int32_t IMultimodalInputConnectStub::OnRemoteRequest( case static_cast(IMultimodalInputConnect::ALLOC_SOCKET_FD): return HandleAllocSocketFd(data, reply); case static_cast(IMultimodalInputConnect::SET_EVENT_POINTER_FILTER): - return StubSetInputEventFilter(data, reply); + return StubAddInputEventFilter(data, reply); default: MMI_LOGE("unknown code: %{public}u, go switch defaut", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -68,12 +68,15 @@ int32_t IMultimodalInputConnectStub::GetCallingPid() const return IPCSkeleton::GetCallingPid(); } -int32_t IMultimodalInputConnectStub::StubSetInputEventFilter(MessageParcel& data, MessageParcel& reply) +int32_t IMultimodalInputConnectStub::StubAddInputEventFilter(MessageParcel& data, MessageParcel& reply) { + MMI_LOGT("enter"); int32_t ret = RET_OK; do { - if (GetCallingUid() != SYSTEM_UID) { + const int32_t uid = GetCallingUid(); + if (uid != SYSTEM_UID && uid != ROOT_UID) { + MMI_LOGE("uid is not root or system"); ret = SASERVICE_PERMISSION_FAIL; break; } @@ -92,11 +95,17 @@ int32_t IMultimodalInputConnectStub::StubSetInputEventFilter(MessageParcel& data break; } - ret = SetInputEventFilter(filter); + MMI_LOGT("filter iface_cast succeeded"); + + ret = AddInputEventFilter(filter); } while (0); - reply.WriteInt32(ret); + if (!reply.WriteInt32(ret)) { + MMI_LOGE("WriteInt32(%{public}d) fail", ret); + return IPC_STUB_WRITE_PARCEL_ERR; + } + MMI_LOGT("leave, ret = %{public}d", ret); return RET_OK; } } // namespace MMI diff --git a/service/connect_manager/src/multimodal_input_connect_manager.cpp b/service/connect_manager/src/multimodal_input_connect_manager.cpp index e4f2bdec670cc1d926971b01cdf64a506edd22dc..dd8894843641769bea419259a4914d11e5afd2bc 100644 --- a/service/connect_manager/src/multimodal_input_connect_manager.cpp +++ b/service/connect_manager/src/multimodal_input_connect_manager.cpp @@ -69,15 +69,15 @@ int MultimodalInputConnectManager::GetClientSocketFdOfAllocedSocketPair() const return socketFd_; } -int32_t MultimodalInputConnectManager::SetInputEventFilter(sptr filter) +int32_t MultimodalInputConnectManager::AddInputEventFilter(sptr filter) { std::lock_guard guard(lock_); if (multimodalInputConnectService_ == nullptr) { MMI_LOGE("multimodalInputConnectService_ is nullptr"); - return false; + return RET_ERR; } - return multimodalInputConnectService_->SetInputEventFilter(filter); + return multimodalInputConnectService_->AddInputEventFilter(filter); } bool MultimodalInputConnectManager::ConnectMultimodalInputService() diff --git a/service/connect_manager/src/multimodal_input_connect_proxy.cpp b/service/connect_manager/src/multimodal_input_connect_proxy.cpp index b81c96eb4b95a0f1466741fdf5afaf51eb1409e3..328a2c8a0f094f906b6576e9a666d4a8c4d55a59 100644 --- a/service/connect_manager/src/multimodal_input_connect_proxy.cpp +++ b/service/connect_manager/src/multimodal_input_connect_proxy.cpp @@ -78,7 +78,7 @@ int32_t MultimodalInputConnectProxy::AllocSocketFd(const std::string &programNam return RET_OK; } -int32_t MultimodalInputConnectProxy::SetInputEventFilter(sptr filter) +int32_t MultimodalInputConnectProxy::AddInputEventFilter(sptr filter) { MMI_LOGE("enter"); MessageParcel data; diff --git a/service/connect_manager/src/multimodal_input_connect_service.cpp b/service/connect_manager/src/multimodal_input_connect_service.cpp index 5805b9edffceb92c6c2fe8a8f1de91b28d185c92..bf9cd0034bcb0a9c11f78ae6d342b7bb66c719f7 100644 --- a/service/connect_manager/src/multimodal_input_connect_service.cpp +++ b/service/connect_manager/src/multimodal_input_connect_service.cpp @@ -56,22 +56,10 @@ int32_t MultimodalInputConnectService::AllocSocketFd(const std::string &programN return RET_OK; } -int32_t MultimodalInputConnectService::SetInputEventFilter(sptr filter) +int32_t MultimodalInputConnectService::AddInputEventFilter(sptr filter) { - MMI_LOGI("enter"); - if (udsServer_ == nullptr) { - MMI_LOGE("called, udsServer_ is nullptr."); - return RET_ERR; - } - - const int32_t ret = udsServer_->SetInputEventFilter(filter); - if (ret != RET_OK) { - MMI_LOGE("call SetInputEventFilter return %{public}d.", ret); - return RET_ERR; - } - - MMI_LOGI("leave, success."); - return RET_OK; + MMI_LOGF("enter, this code is discarded, and it runs with Weston"); + return RET_ERR; } MultimodalInputConnectService::MultimodalInputConnectService() diff --git a/service/event_dispatch/include/event_dispatch.h b/service/event_dispatch/include/event_dispatch.h index 1e53c5d574177b35786180dcfdf0cd46776fc451..4b2a451fabb551427428b6a3f387d30f9fefd6b3 100644 --- a/service/event_dispatch/include/event_dispatch.h +++ b/service/event_dispatch/include/event_dispatch.h @@ -29,7 +29,7 @@ class EventDispatch : public std::enable_shared_from_this { public: EventDispatch(); virtual ~EventDispatch(); - virtual int32_t SetInputEventFilter(sptr filter); + virtual int32_t AddInputEventFilter(sptr filter); int32_t DispatchGestureNewEvent(UDSServer& udsServer, libinput_event *event, std::shared_ptr pointer, const uint64_t preHandlerTime); int32_t DispatchGestureEvent(UDSServer& udsServer, libinput_event *event, EventGesture& gesture, @@ -71,9 +71,6 @@ protected: int32_t touchDownFocusSurfaceId_ = 0; EventPackage eventPackage_; StandardEventHandler standardEvent_; - std::mutex lockInputEventFilter_; - sptr filter_ {nullptr}; - sptr eventFilterRecipient_ {nullptr}; #ifdef DEBUG_CODE_TEST private: const size_t windowCount_ = 2; diff --git a/service/event_dispatch/src/event_dispatch.cpp b/service/event_dispatch/src/event_dispatch.cpp index b18a4b1b61afb16c9df8e3ba9ed8bd6feb883430..9c07db66b0b7fe1a69acecaf8480923033f89189 100644 --- a/service/event_dispatch/src/event_dispatch.cpp +++ b/service/event_dispatch/src/event_dispatch.cpp @@ -16,6 +16,7 @@ #include "event_dispatch.h" #include #include "ability_launch_manager.h" +#include "event_filter_wrap.h" #include "input_event_data_transformation.h" #include "input_event_monitor_manager.h" #include "input_handler_manager_global.h" @@ -24,8 +25,6 @@ #include "outer_interface.h" #include "system_event_handler.h" #include "util.h" -#include "event_filter_death_recipient.h" - namespace OHOS::MMI { namespace { @@ -350,11 +349,7 @@ int32_t OHOS::MMI::EventDispatch::DispatchTabletToolEvent(UDSServer& udsServer, bool OHOS::MMI::EventDispatch::HandlePointerEventFilter(std::shared_ptr point) { - std::lock_guard guard(lockInputEventFilter_); - if (filter_ != nullptr && filter_->HandlePointerEvent(point)) { - return true; - } - return false; + return EventFilterWrap::GetInstance().HandlePointerEventFilter(point); } int32_t OHOS::MMI::EventDispatch::handlePointerEvent(std::shared_ptr point) @@ -831,27 +826,9 @@ int32_t OHOS::MMI::EventDispatch::DispatchKeyEvent(UDSServer& udsServer, libinpu return ret; } -int32_t OHOS::MMI::EventDispatch::SetInputEventFilter(sptr filter) +int32_t OHOS::MMI::EventDispatch::AddInputEventFilter(sptr filter) { - std::lock_guard guard(lockInputEventFilter_); - filter_ = filter; - - if (filter_ != nullptr) { - std::weak_ptr weakPtr = shared_from_this(); - auto deathCallback = [weakPtr](const wptr &object) { - auto sharedPtr = weakPtr.lock(); - if (sharedPtr) { - sharedPtr->SetInputEventFilter(nullptr); - } - }; - - eventFilterRecipient_ = new EventFilterDeathRecipient(deathCallback); - - auto client = filter->AsObject().GetRefPtr(); - client->AddDeathRecipient(eventFilterRecipient_); - } - - return RET_OK; + return EventFilterWrap::GetInstance().AddInputEventFilter(filter); } int32_t OHOS::MMI::EventDispatch::DispatchGestureNewEvent(UDSServer& udsServer, libinput_event *event, diff --git a/service/event_filter_binder/BUILD.gn b/service/event_filter_binder/BUILD.gn index 9e702a589273334c986d1af080abb24da26cc802..db61b64aa3dad6658655cdff673b6d7db4a62189 100644 --- a/service/event_filter_binder/BUILD.gn +++ b/service/event_filter_binder/BUILD.gn @@ -52,6 +52,7 @@ ohos_source_set("mmi_event_filter_proxy") { "${event_filter_path}/src/event_filter_death_recipient.cpp", "${event_filter_path}/src/event_filter_parcel.cpp", "${event_filter_path}/src/event_filter_proxy.cpp", + "${event_filter_path}/src/event_filter_wrap.cpp", ] public_configs = [ ":mmi_event_filter_config" ] diff --git a/service/event_filter_binder/include/event_filter_stub.h b/service/event_filter_binder/include/event_filter_stub.h index 4ca7ce2dbd6b7a3159da8f51c56112f1bf3cbc68..ffe4fcba31bdd41fac9317a99d9e28ac730c4e0a 100644 --- a/service/event_filter_binder/include/event_filter_stub.h +++ b/service/event_filter_binder/include/event_filter_stub.h @@ -29,7 +29,7 @@ public: virtual ~EventFilterStub() = default; int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& options) override; protected: - bool StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply); + int32_t StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply); }; } // namespace MMI } // namespace OHOS diff --git a/service/event_filter_binder/include/event_filter_wrap.h b/service/event_filter_binder/include/event_filter_wrap.h new file mode 100644 index 0000000000000000000000000000000000000000..f75ef04dab5c8339851407b6958466fb94423e15 --- /dev/null +++ b/service/event_filter_binder/include/event_filter_wrap.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_EVENT_FILTER_WRAP_H +#define OHOS_EVENT_FILTER_WRAP_H + +#include +#include "i_event_filter.h" +#include "singleton.h" + +namespace OHOS { +namespace MMI { +class EventFilterWrap : public Singleton { +public: + EventFilterWrap(); + ~EventFilterWrap(); + int32_t AddInputEventFilter(sptr filter); + bool HandlePointerEventFilter(std::shared_ptr point); +private: + std::mutex lockInputEventFilter_; + sptr filter_ {nullptr}; +}; +} // namespace MMI +} // namespace OHOS +#endif // OHOS_EVENT_FILTER_WRAP_H diff --git a/service/event_filter_binder/src/event_filter_proxy.cpp b/service/event_filter_binder/src/event_filter_proxy.cpp index 2df9e7a1e8e89b0e1ef923ef80d3be00fe763aaa..3fc93d5f329b095602b7b455ef6413d3b01710df 100644 --- a/service/event_filter_binder/src/event_filter_proxy.cpp +++ b/service/event_filter_binder/src/event_filter_proxy.cpp @@ -38,7 +38,7 @@ EventFilterProxy::~EventFilterProxy() bool EventFilterProxy::HandlePointerEvent(const std::shared_ptr event) { - MMI_LOGE("enter"); + MMI_LOGT("enter"); MessageParcel data; MessageParcel reply; MessageOption option; @@ -53,7 +53,7 @@ bool EventFilterProxy::HandlePointerEvent(const std::shared_ptr ev return false; } - if (event->WriteToParcel(data)) { + if (!event->WriteToParcel(data)) { MMI_LOGE("Failed to write event to req"); return false; } @@ -65,16 +65,16 @@ bool EventFilterProxy::HandlePointerEvent(const std::shared_ptr ev return false; } - MMI_LOGE("have recieve message from server"); + MMI_LOGT("have recieve message from server"); - int result = reply.ReadInt32(); - MMI_LOGE("result = %{public}d", result); - if (result != RET_OK) { - MMI_LOGE("responce return error: %{public}d", result); + bool result = false; + if (!reply.ReadBool(result)) { + MMI_LOGE("reply ReadBool fail"); return false; } - return true; + MMI_LOGT("leave"); + return result; } } // namespace MMI } // namespace OHOS diff --git a/service/event_filter_binder/src/event_filter_stub.cpp b/service/event_filter_binder/src/event_filter_stub.cpp index ab115fd97cf642cd27ddae823de6e67ba8440944..ad6ba20062e08bd4f423437f0bed7ce24be4294b 100644 --- a/service/event_filter_binder/src/event_filter_stub.cpp +++ b/service/event_filter_binder/src/event_filter_stub.cpp @@ -47,20 +47,28 @@ int32_t EventFilterStub::OnRemoteRequest( } } -bool EventFilterStub::StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply) -{ +int32_t EventFilterStub::StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply) +{ + MMI_LOGT("enter"); std::shared_ptr event = PointerEvent::Create(); if (event == nullptr) { MMI_LOGE("event is nullptr."); - return false; + return RET_ERR; } if (!event->ReadFromParcel(data)) { MMI_LOGE("read data error."); - return false; + return RET_ERR; + } + + bool ret = HandlePointerEvent(event); + if (!reply.WriteBool(ret)) { + MMI_LOGE("WriteBool(%{public}d) fail", ret); + return RET_ERR; } - return HandlePointerEvent(event); + MMI_LOGT("leave"); + return RET_OK; } } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/event_filter_binder/src/event_filter_wrap.cpp b/service/event_filter_binder/src/event_filter_wrap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..05f7889a3c128207f6902b8439b65ed3c4f7fb44 --- /dev/null +++ b/service/event_filter_binder/src/event_filter_wrap.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "event_filter_wrap.h" +#include "log.h" + +namespace OHOS { +namespace MMI { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventFilterWrap" }; +} + +EventFilterWrap::EventFilterWrap() +{ + MMI_LOGT("enter"); +} + +EventFilterWrap::~EventFilterWrap() +{ + MMI_LOGT("enter"); +} + +int32_t EventFilterWrap::AddInputEventFilter(sptr filter) +{ + MMI_LOGT("enter"); + std::lock_guard guard(lockInputEventFilter_); + filter_ = filter; + + MMI_LOGT("leave"); + return RET_OK; +} + +bool EventFilterWrap::HandlePointerEventFilter(std::shared_ptr point) +{ + MMI_LOGT("enter"); + std::lock_guard guard(lockInputEventFilter_); + if (filter_ == nullptr) { + MMI_LOGD("filter_ is nullptr"); + return false; + } + + if (filter_->HandlePointerEvent(point)) { + MMI_LOGD("call HandlePointerEvent return true"); + return true; + } + + MMI_LOGT("leave"); + return false; +} +} // namespace MMI +} // namespace OHOS diff --git a/service/event_handle/include/input_event_handler.h b/service/event_handle/include/input_event_handler.h index 8e5f40946c9809113de331dcd02385995cb2fd63..b9c44df31368ef75a60533340c9bdddf32abdeff 100644 --- a/service/event_handle/include/input_event_handler.h +++ b/service/event_handle/include/input_event_handler.h @@ -37,7 +37,7 @@ public: void RegistnotifyDeviceChange(NotifyDeviceChange cb); int32_t OnMouseEventTimerHanler(std::shared_ptr mouse_event); UDSServer *GetUDSServer(); - int32_t SetInputEventFilter(sptr filter); + int32_t AddInputEventFilter(sptr filter); protected: int32_t OnEventDeviceAdded(multimodal_libinput_event& event); int32_t OnEventDeviceRemoved(multimodal_libinput_event& event); diff --git a/service/event_handle/src/input_event_handler.cpp b/service/event_handle/src/input_event_handler.cpp index 47fb26c344b822832a7ae1bb9ecb892a25bb8df9..1b68957307fd7515dfecc065966ce7278bc1a005 100644 --- a/service/event_handle/src/input_event_handler.cpp +++ b/service/event_handle/src/input_event_handler.cpp @@ -264,9 +264,9 @@ OHOS::MMI::UDSServer* OHOS::MMI::InputEventHandler::GetUDSServer() return udsServer_; } -int32_t OHOS::MMI::InputEventHandler::SetInputEventFilter(sptr filter) +int32_t OHOS::MMI::InputEventHandler::AddInputEventFilter(sptr filter) { - return eventDispatch_.SetInputEventFilter(filter); + return eventDispatch_.AddInputEventFilter(filter); } int32_t OHOS::MMI::InputEventHandler::OnEventDeviceAdded(multimodal_libinput_event &ev) diff --git a/service/module_loader/include/mmi_service.h b/service/module_loader/include/mmi_service.h index 463617fbf5ea87e264e6962b3339d475ef847144..a8624814c7d4bf0ccbe4adb953880770b494ef68 100644 --- a/service/module_loader/include/mmi_service.h +++ b/service/module_loader/include/mmi_service.h @@ -48,7 +48,7 @@ public: virtual void OnStop() override; virtual void OnDump() override; virtual int32_t AllocSocketFd(const std::string &programName, const int moduleType, int &socketFd) override; - virtual int32_t SetInputEventFilter(sptr filter) override; + virtual int32_t AddInputEventFilter(sptr filter) override; protected: virtual void OnConnected(SessionPtr s) override; diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index 8a0020b9d41a53b394c7b3f13a9451021ea50ac0..4669f45e6318c4d6f3baf845a7e82868fd5c2242 100644 --- a/service/module_loader/src/mmi_service.cpp +++ b/service/module_loader/src/mmi_service.cpp @@ -329,14 +329,14 @@ int32_t MMIService::HandleAllocSocketFd(MessageParcel& data, MessageParcel& repl return RET_OK; } -int32_t MMIService::SetInputEventFilter(sptr filter) +int32_t MMIService::AddInputEventFilter(sptr filter) { if (inputEventHdr_ == nullptr) { MMI_LOGE("inputEventHdr_ is nullptr"); return NULL_POINTER; } - return inputEventHdr_->SetInputEventFilter(filter); + return inputEventHdr_->AddInputEventFilter(filter); } void MMIService::OnTimer()