From 64313e6069fac0c1fbf3bb71881cc1f90fdfef4f Mon Sep 17 00:00:00 2001 From: cy7717 Date: Sat, 30 Mar 2024 23:13:13 +0800 Subject: [PATCH] mod Signed-off-by: cy7717 --- .../js_get_input_method_setting.cpp | 8 +- .../include/event_status_manager.h | 6 +- .../include/ime_event_monitor_manager_impl.h | 14 +- .../input_method_system_ability_proxy.h | 2 +- .../src/ime_event_monitor_manager.cpp | 35 ++-- .../src/ime_event_monitor_manager_impl.cpp | 93 +++++++---- .../src/input_method_controller.cpp | 18 +-- .../src/input_method_system_ability_proxy.cpp | 5 +- .../include/ime_event_listener.h | 4 +- .../include/ime_event_monitor_manager.h | 15 +- .../include/input_method_controller.h | 2 +- .../include/i_input_method_system_ability.h | 2 +- .../include/input_method_system_ability.h | 2 +- services/src/input_method_system_ability.cpp | 6 +- .../src/input_method_system_ability_stub.cpp | 6 +- .../imeeventmonitormanager_fuzzer.cpp | 8 +- .../inputmethodcontroller_fuzzer.cpp | 7 +- .../cpp_test/src/identity_checker_test.cpp | 27 ++-- .../src/ime_event_monitor_manager_test.cpp | 150 +++++++++--------- test/unittest/cpp_test/src/ime_proxy_test.cpp | 2 +- .../cpp_test/src/input_method_panel_test.cpp | 73 +++++---- .../cpp_test/src/input_method_switch_test.cpp | 2 +- .../cpp_test/src/newIme_switch_test.cpp | 2 +- 23 files changed, 247 insertions(+), 242 deletions(-) diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp index 186f98b5..d6da3888 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp @@ -37,8 +37,8 @@ constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_MAX = 6; thread_local napi_ref JsGetInputMethodSetting::IMSRef_ = nullptr; const std::string JsGetInputMethodSetting::IMS_CLASS_NAME = "InputMethodSetting"; -const std::unordered_map EVENT_TYPE{ { "imeChange", IME_CHANGE }, { "imeShow", IME_SHOW }, - { "imeHide", IME_HIDE } }; +const std::unordered_map EVENT_TYPE{ { "imeChange", EVENT_IME_CHANGE_MASK }, + { "imeShow", EVENT_IME_SHOW_MASK }, { "imeHide", EVENT_IME_HIDE_MASK } }; std::mutex JsGetInputMethodSetting::msMutex_; std::shared_ptr JsGetInputMethodSetting::inputMethod_{ nullptr }; napi_value JsGetInputMethodSetting::Init(napi_env env, napi_value exports) @@ -491,7 +491,7 @@ napi_value JsGetInputMethodSetting::Subscribe(napi_env env, napi_callback_info i } std::shared_ptr callback = std::make_shared(env, argv[ARGC_ONE], std::this_thread::get_id()); - auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ iter->second }, inputMethod_); + auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(iter->second, inputMethod_); if (ret == ErrorCode::NO_ERROR) { engine->RegisterListener(argv[ARGC_ONE], type, callback); } else { @@ -572,7 +572,7 @@ napi_value JsGetInputMethodSetting::UnSubscribe(napi_env env, napi_callback_info return nullptr; } if (isUpdateFlag) { - auto ret = ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener({ iter->second }, inputMethod_); + auto ret = ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener(iter->second, inputMethod_); IMSA_HILOGI("UpdateListenEventFlag, ret: %{public}d, type: %{public}s", ret, type.c_str()); } napi_value result = nullptr; diff --git a/frameworks/native/inputmethod_controller/include/event_status_manager.h b/frameworks/native/inputmethod_controller/include/event_status_manager.h index dd169a68..9e95943b 100644 --- a/frameworks/native/inputmethod_controller/include/event_status_manager.h +++ b/frameworks/native/inputmethod_controller/include/event_status_manager.h @@ -24,15 +24,15 @@ class EventStatusManager { public: inline static bool IsImeShowOn(uint32_t eventFlag) { - return (eventFlag & (1u << EventType::IME_SHOW)) == (1u << EventType::IME_SHOW); + return (eventFlag & EVENT_IME_SHOW_MASK) == EVENT_IME_SHOW_MASK; } inline static bool IsImeChangeOn(uint32_t eventFlag) { - return (eventFlag & (1u << EventType::IME_CHANGE)) == (1u << EventType::IME_CHANGE); + return (eventFlag & EVENT_IME_CHANGE_MASK) == EVENT_IME_CHANGE_MASK; } inline static bool IsImeHideOn(uint32_t eventFlag) { - return (eventFlag & (1u << EventType::IME_HIDE)) == (1u << EventType::IME_HIDE); + return (eventFlag & EVENT_IME_HIDE_MASK) == EVENT_IME_HIDE_MASK; } }; } // namespace MiscServices diff --git a/frameworks/native/inputmethod_controller/include/ime_event_monitor_manager_impl.h b/frameworks/native/inputmethod_controller/include/ime_event_monitor_manager_impl.h index 312408a6..4979372d 100644 --- a/frameworks/native/inputmethod_controller/include/ime_event_monitor_manager_impl.h +++ b/frameworks/native/inputmethod_controller/include/ime_event_monitor_manager_impl.h @@ -27,20 +27,20 @@ namespace MiscServices { class ImeEventMonitorManagerImpl { public: static ImeEventMonitorManagerImpl &GetInstance(); - int32_t RegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener); - int32_t UnRegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener); + int32_t RegisterImeEventListener(uint32_t eventFlag, const std::shared_ptr &listener); + int32_t UnRegisterImeEventListener(uint32_t eventFlag, const std::shared_ptr &listener); int32_t OnImeChange(const Property &property, const SubProperty &subProperty); int32_t OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info); private: ImeEventMonitorManagerImpl(); ~ImeEventMonitorManagerImpl(); - - std::set> GetListeners(EventType type); + static constexpr uint32_t MAX_EVENT_NUM = 3; + int32_t OnImeShow(const ImeWindowInfo &info); + int32_t OnImeHide(const ImeWindowInfo &info); + std::set> GetListeners(uint32_t eventMask); std::mutex lock_; - std::map>> listeners_{}; + std::map>> listeners_{}; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h b/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h index cfcdea06..746bcee4 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -65,7 +65,7 @@ public: int32_t ListCurrentInputMethodSubtype(std::vector &subProps) override; int32_t ListInputMethodSubtype(const std::string &name, std::vector &subProps) override; int32_t PanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info) override; - int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType) override; + int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) override; bool IsCurrentIme() override; bool IsInputTypeSupported(InputType type) override; int32_t StartInputType(InputType type) override; diff --git a/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager.cpp b/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager.cpp index a0e0caa6..2807f169 100644 --- a/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager.cpp +++ b/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager.cpp @@ -22,7 +22,6 @@ namespace OHOS { namespace MiscServices { -const std::set ImeEventMonitorManager::EVENT_TYPE{ IME_SHOW, IME_HIDE }; ImeEventMonitorManager::ImeEventMonitorManager() { } @@ -38,41 +37,31 @@ ImeEventMonitorManager &ImeEventMonitorManager::GetInstance() } int32_t ImeEventMonitorManager::RegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener) + uint32_t eventFlag, const std::shared_ptr &listener) { - if (!IsParamValid(types, listener)) { + if (!IsParamValid(eventFlag, listener)) { + IMSA_HILOGE("param is invalid"); return ErrorCode::ERROR_BAD_PARAMETERS; } - return ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(types, listener); + return ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(eventFlag & ALL_EVENT_MASK, listener); } int32_t ImeEventMonitorManager::UnRegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener) + uint32_t eventFlag, const std::shared_ptr &listener) { - if (!IsParamValid(types, listener)) { + if (!IsParamValid(eventFlag, listener)) { + IMSA_HILOGE("param is invalid"); return ErrorCode::ERROR_BAD_PARAMETERS; } - return ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener(types, listener); + return ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener(eventFlag & ALL_EVENT_MASK, listener); } - -bool ImeEventMonitorManager::IsParamValid( - const std::set &types, const std::shared_ptr &listener) +bool ImeEventMonitorManager::IsParamValid(uint32_t eventFlag, const std::shared_ptr &listener) { - if (listener == nullptr) { - IMSA_HILOGE("listener is nullptr"); + if (eventFlag == 0) { + IMSA_HILOGE("eventFlag is 0"); return false; } - if (types.empty()) { - IMSA_HILOGE("no eventType"); - return false; - } - if (types.size() > EVENT_NUM) { - IMSA_HILOGE("over eventNum"); - return false; - } - auto it = std::find_if( - types.begin(), types.end(), [](EventType type) { return EVENT_TYPE.find(type) == EVENT_TYPE.end(); }); - return it == types.end(); + return listener != nullptr; } } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp b/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp index e19163e5..d81a7c40 100644 --- a/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp +++ b/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager_impl.cpp @@ -36,32 +36,45 @@ ImeEventMonitorManagerImpl &ImeEventMonitorManagerImpl::GetInstance() } int32_t ImeEventMonitorManagerImpl::RegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener) + uint32_t eventFlag, const std::shared_ptr &listener) { std::lock_guard lock(lock_); - for (const auto &type : types) { - auto it = listeners_.find(type); - if (it == listeners_.end()) { - auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(type, true); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("UpdateListenEventFlag failed: %{public}d", ret); - return ret; - } - listeners_.insert({ type, { listener } }); - } else { - it->second.insert(listener); + uint32_t currentEventFlag = 0; + for (const auto &listenerTemp : listeners_) { + currentEventFlag |= listenerTemp.first; + } + auto finalEventFlag = currentEventFlag | eventFlag; + auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(finalEventFlag, eventFlag, true); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("UpdateListenEventFlag failed: %{public}d", ret); + return ret; + } + for (uint32_t i = 0; i < MAX_EVENT_NUM; i++) { + auto eventMask = eventFlag & (1u << (MAX_EVENT_NUM - (i + 1))); + if (eventMask == 0) { + continue; } + auto it = listeners_.find(eventMask); + if (it == listeners_.end()) { + listeners_.insert({ eventMask, { listener } }); + continue; + } + it->second.insert(listener); } return ErrorCode::NO_ERROR; } int32_t ImeEventMonitorManagerImpl::UnRegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener) + uint32_t eventFlag, const std::shared_ptr &listener) { - bool isAbsentParam = false; std::lock_guard lock(lock_); - for (const auto &type : types) { - auto it = listeners_.find(type); + bool isAbsentParam = false; + for (uint32_t i = 0; i < MAX_EVENT_NUM; i++) { + auto eventMask = eventFlag & (1u << (MAX_EVENT_NUM - (i + 1))); + if (eventMask == 0) { + continue; + } + auto it = listeners_.find(eventMask); if (it == listeners_.end()) { isAbsentParam = true; continue; @@ -73,19 +86,24 @@ int32_t ImeEventMonitorManagerImpl::UnRegisterImeEventListener( } it->second.erase(iter); if (it->second.empty()) { - auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(type, false); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("UpdateListenEventFlag failed: %{public}d", ret); - } listeners_.erase(it); } } + uint32_t finalEventFlag = 0; + for (const auto &listenerTemp : listeners_) { + finalEventFlag |= listenerTemp.first; + } + auto ret = InputMethodController::GetInstance()->UpdateListenEventFlag(finalEventFlag, eventFlag, false); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("UpdateListenEventFlag failed: %{public}d", ret); + return ret; + } return isAbsentParam ? ErrorCode::ERROR_BAD_PARAMETERS : ErrorCode::NO_ERROR; } int32_t ImeEventMonitorManagerImpl::OnImeChange(const Property &property, const SubProperty &subProperty) { - auto listeners = GetListeners(EventType::IME_CHANGE); + auto listeners = GetListeners(EVENT_IME_CHANGE_MASK); for (const auto &listener : listeners) { listener->OnImeChange(property, subProperty); } @@ -94,22 +112,37 @@ int32_t ImeEventMonitorManagerImpl::OnImeChange(const Property &property, const int32_t ImeEventMonitorManagerImpl::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info) { - auto type = status == InputWindowStatus::HIDE ? EventType::IME_HIDE : EventType::IME_SHOW; - auto listeners = GetListeners(type); + if (status == InputWindowStatus::HIDE) { + return OnImeHide(info); + } + if (status == InputWindowStatus::SHOW) { + return OnImeShow(info); + } + return ErrorCode::ERROR_BAD_PARAMETERS; +} + +int32_t ImeEventMonitorManagerImpl::OnImeShow(const ImeWindowInfo &info) +{ + auto listeners = GetListeners(EVENT_IME_SHOW_MASK); for (const auto &listener : listeners) { - if (type == EventType::IME_HIDE) { - listener->OnImeHide(info); - } else { - listener->OnImeShow(info); - } + listener->OnImeShow(info); } return ErrorCode::NO_ERROR; } -std::set> ImeEventMonitorManagerImpl::GetListeners(EventType type) +int32_t ImeEventMonitorManagerImpl::OnImeHide(const ImeWindowInfo &info) +{ + auto listeners = GetListeners(EVENT_IME_HIDE_MASK); + for (const auto &listener : listeners) { + listener->OnImeHide(info); + } + return ErrorCode::NO_ERROR; +} + +std::set> ImeEventMonitorManagerImpl::GetListeners(uint32_t eventMask) { std::lock_guard lock(lock_); - auto it = listeners_.find(type); + auto it = listeners_.find(eventMask); if (it == listeners_.end()) { return {}; } diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 222c1b23..6bc0fe65 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -44,8 +44,6 @@ std::mutex InputMethodController::instanceLock_; constexpr int32_t LOOP_COUNT = 5; constexpr int64_t DELAY_TIME = 100; constexpr int32_t ACE_DEAL_TIME_OUT = 200; -const std::unordered_map EVENT_TYPE{ { "imeChange", IME_CHANGE }, { "imeShow", IME_SHOW }, - { "imeHide", IME_HIDE } }; InputMethodController::InputMethodController() { IMSA_HILOGD("IMC structure"); @@ -82,27 +80,21 @@ int32_t InputMethodController::RestoreListenEventFlag() IMSA_HILOGE("proxy is nullptr"); return ErrorCode::ERROR_SERVICE_START_FAILED; } - return proxy->UpdateListenEventFlag(clientInfo_, IME_NONE); + // 0 represent no need to check permission + return proxy->UpdateListenEventFlag(clientInfo_, 0); } -int32_t InputMethodController::UpdateListenEventFlag(EventType eventType, bool isOn) +int32_t InputMethodController::UpdateListenEventFlag(uint32_t finalEventFlag, uint32_t eventFlag, bool isOn) { auto oldEventFlag = clientInfo_.eventFlag; - if (isOn) { - clientInfo_.eventFlag |= (1u << eventType); - } else { - clientInfo_.eventFlag &= (~(1u << eventType)); - } - if (oldEventFlag == clientInfo_.eventFlag) { - return ErrorCode::NO_ERROR; - } + clientInfo_.eventFlag = finalEventFlag; auto proxy = GetSystemAbilityProxy(); if (proxy == nullptr && isOn) { IMSA_HILOGE("proxy is nullptr"); clientInfo_.eventFlag = oldEventFlag; return ErrorCode::ERROR_SERVICE_START_FAILED; } - auto ret = proxy->UpdateListenEventFlag(clientInfo_, eventType); + auto ret = proxy->UpdateListenEventFlag(clientInfo_, eventFlag); if (ret != ErrorCode::NO_ERROR && isOn) { clientInfo_.eventFlag = oldEventFlag; } diff --git a/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp b/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp index 3320986e..30ee9382 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -201,11 +201,10 @@ int32_t InputMethodSystemAbilityProxy::PanelStatusChange(const InputWindowStatus }); } -int32_t InputMethodSystemAbilityProxy::UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType) +int32_t InputMethodSystemAbilityProxy::UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) { return SendRequest(static_cast(InputMethodInterfaceCode::UPDATE_LISTEN_EVENT_FLAG), - [&clientInfo, eventType]( - MessageParcel &data) { return ITypesUtil::Marshal(data, clientInfo, static_cast(eventType)); }); + [&clientInfo, eventFlag](MessageParcel &data) { return ITypesUtil::Marshal(data, clientInfo, eventFlag); }); } bool InputMethodSystemAbilityProxy::IsCurrentIme() diff --git a/interfaces/inner_api/inputmethod_controller/include/ime_event_listener.h b/interfaces/inner_api/inputmethod_controller/include/ime_event_listener.h index a73ffd04..7e32b67b 100644 --- a/interfaces/inner_api/inputmethod_controller/include/ime_event_listener.h +++ b/interfaces/inner_api/inputmethod_controller/include/ime_event_listener.h @@ -21,7 +21,9 @@ namespace OHOS { namespace MiscServices { -enum EventType : uint32_t { IME_CHANGE = 0, IME_SHOW = 1, IME_HIDE = 2, IME_NONE }; +constexpr uint32_t EVENT_IME_CHANGE_MASK = 1u; +constexpr uint32_t EVENT_IME_SHOW_MASK = 1u << 1u; +constexpr uint32_t EVENT_IME_HIDE_MASK = 1u << 2u; class ImeEventListener { public: virtual ~ImeEventListener() = default; diff --git a/interfaces/inner_api/inputmethod_controller/include/ime_event_monitor_manager.h b/interfaces/inner_api/inputmethod_controller/include/ime_event_monitor_manager.h index e855bf38..755e0a60 100644 --- a/interfaces/inner_api/inputmethod_controller/include/ime_event_monitor_manager.h +++ b/interfaces/inner_api/inputmethod_controller/include/ime_event_monitor_manager.h @@ -40,33 +40,30 @@ public: * * This function is used to Register Ime Event Listener, only IME_SHOW and IME_HIDE supported at present * - * @param types Indicates the event type. + * @param eventFlag Indicates the flag of the ime event to be registered * @param listener Indicates the the listener to be registered. * @return Returns 0 for success, others for failure. * @since 12 */ - IMF_API int32_t RegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener); + IMF_API int32_t RegisterImeEventListener(uint32_t eventFlag, const std::shared_ptr &listener); /** * @brief UnRegister Ime Event Listener. * * This function is used to UnRegister Ime Event Listener, only IME_SHOW and IME_HIDE supported at present * - * @param types Indicates the event type. + * @param types Indicates the flag of the ime event to be unRegistered * @param listener Indicates the the listener to be unregistered. * @return Returns 0 for success, others for failure. * @since 12 */ - IMF_API int32_t UnRegisterImeEventListener( - const std::set &types, const std::shared_ptr &listener); + IMF_API int32_t UnRegisterImeEventListener(uint32_t eventFlag, const std::shared_ptr &listener); private: - static constexpr uint32_t EVENT_NUM = 2; - static const std::set EVENT_TYPE; + static constexpr uint32_t ALL_EVENT_MASK = EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK; ImeEventMonitorManager(); ~ImeEventMonitorManager(); - bool IsParamValid(const std::set &types, const std::shared_ptr &listener); + bool IsParamValid(uint32_t eventFlag, const std::shared_ptr &listener); }; } // namespace MiscServices } // namespace OHOS diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index 1e657afd..8bb93c4c 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -684,7 +684,7 @@ public: * @since 11 */ IMF_API int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown); - int32_t UpdateListenEventFlag(EventType eventType, bool isOn); + int32_t UpdateListenEventFlag(uint32_t finalEventFlag, uint32_t eventFlag, bool isOn); private: InputMethodController(); diff --git a/services/include/i_input_method_system_ability.h b/services/include/i_input_method_system_ability.h index cc9b0d5f..9d323c0f 100644 --- a/services/include/i_input_method_system_ability.h +++ b/services/include/i_input_method_system_ability.h @@ -65,7 +65,7 @@ public: virtual int32_t SwitchInputMethod( const std::string &bundleName, const std::string &name, SwitchTrigger trigger) = 0; virtual int32_t PanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info) = 0; - virtual int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType) = 0; + virtual int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) = 0; virtual bool IsCurrentIme() = 0; virtual bool IsInputTypeSupported(InputType type) = 0; virtual int32_t StartInputType(InputType type) = 0; diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index f932c441..4f6d9dd6 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -75,7 +75,7 @@ public: int32_t SetCoreAndAgent(const sptr &core, const sptr &agent) override; int32_t UnRegisteredProxyIme(UnRegisteredType type, const sptr &core) override; int32_t PanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info) override; - int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType) override; + int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) override; bool IsCurrentIme() override; bool IsInputTypeSupported(InputType type) override; int32_t StartInputType(InputType type) override; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 92a7543b..9ed0084b 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -445,10 +445,10 @@ int32_t InputMethodSystemAbility::PanelStatusChange(const InputWindowStatus &sta return userSession_->OnPanelStatusChange(status, info); } -int32_t InputMethodSystemAbility::UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType) +int32_t InputMethodSystemAbility::UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) { - IMSA_HILOGI("eventType: %{public}u, eventFlag: %{public}u", eventType, clientInfo.eventFlag); - if (eventType == IME_SHOW || eventType == IME_HIDE) { + IMSA_HILOGI("finalEventFlag: %{public}u, eventFlag: %{public}u", clientInfo.eventFlag, eventFlag); + if (EventStatusManager::IsImeHideOn(eventFlag) || EventStatusManager::IsImeShowOn(eventFlag)) { if (!identityChecker_->IsSystemApp(IPCSkeleton::GetCallingFullTokenID()) && !identityChecker_->IsNativeSa(IPCSkeleton::GetCallingTokenID())) { IMSA_HILOGE("not system application"); diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index 9556174f..8fb5109d 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -267,12 +267,12 @@ int32_t InputMethodSystemAbilityStub::PanelStatusChangeOnRemote(MessageParcel &d int32_t InputMethodSystemAbilityStub::UpdateListenEventFlagOnRemote(MessageParcel &data, MessageParcel &reply) { InputClientInfo clientInfo; - uint32_t type = 0; - if (!ITypesUtil::Unmarshal(data, clientInfo, type)) { + uint32_t eventFlag = 0; + if (!ITypesUtil::Unmarshal(data, clientInfo, eventFlag)) { IMSA_HILOGE("Unmarshal failed"); return ErrorCode::ERROR_EX_PARCELABLE; } - int32_t ret = UpdateListenEventFlag(clientInfo, static_cast(type)); + int32_t ret = UpdateListenEventFlag(clientInfo, eventFlag); return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } diff --git a/test/fuzztest/imeeventmonitormanager_fuzzer/imeeventmonitormanager_fuzzer.cpp b/test/fuzztest/imeeventmonitormanager_fuzzer/imeeventmonitormanager_fuzzer.cpp index a16a0809..a713402f 100644 --- a/test/fuzztest/imeeventmonitormanager_fuzzer/imeeventmonitormanager_fuzzer.cpp +++ b/test/fuzztest/imeeventmonitormanager_fuzzer/imeeventmonitormanager_fuzzer.cpp @@ -24,15 +24,15 @@ constexpr size_t THRESHOLD = 10; void FuzzRegisterImeEventListener(const uint8_t *rawData, size_t size) { auto listener = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ static_cast(size) }, nullptr); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ static_cast(size) }, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(static_cast(size), nullptr); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(static_cast(size), listener); } void FuzzUnRegisterImeEventListener(const uint8_t *rawData, size_t size) { auto listener = std::make_shared(); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ static_cast(size) }, nullptr); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ static_cast(size) }, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(static_cast(size), nullptr); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(static_cast(size), listener); } /* Fuzzer entry point */ diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp index f9abe00e..c184443d 100644 --- a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp +++ b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp @@ -92,7 +92,8 @@ void TestOnConfigurationChange(sptr imc) imc->GetInputPattern(inputPattern); } -void TestSwitchInputMethod(SwitchTrigger fuzzedTrigger, sptr imc, const std::string& fuzzedString) +void TestSwitchInputMethod( + SwitchTrigger fuzzedTrigger, sptr imc, const std::string &fuzzedString) { imc->SwitchInputMethod(fuzzedTrigger, fuzzedString, fuzzedString); imc->ShowOptionalInputMethod(); @@ -127,8 +128,8 @@ void TestShowSomething(sptr imc) void TestUpdateListenEventFlag(sptr imc, uint32_t fuzzedUint32) { - imc->UpdateListenEventFlag(static_cast(fuzzedUint32), true); - imc->UpdateListenEventFlag(static_cast(fuzzedUint32), false); + imc->UpdateListenEventFlag(static_cast(fuzzedUint32), static_cast(fuzzedUint32), true); + imc->UpdateListenEventFlag(static_cast(fuzzedUint32), static_cast(fuzzedUint32), false); } void TestAttach(sptr imc, int32_t fuzzedInt32) diff --git a/test/unittest/cpp_test/src/identity_checker_test.cpp b/test/unittest/cpp_test/src/identity_checker_test.cpp index 08a83932..e1985106 100644 --- a/test/unittest/cpp_test/src/identity_checker_test.cpp +++ b/test/unittest/cpp_test/src/identity_checker_test.cpp @@ -575,16 +575,13 @@ HWTEST_F(IdentityCheckerTest, testUpdateListenEventFlag_001, TestSize.Level0) IMSA_HILOGI("IdentityCheckerTest testUpdateListenEventFlag_001 start"); service_->identityChecker_ = identityCheckerImpl_; InputClientInfo clientInfo{}; - EventType eventType = IME_SHOW; - int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_SHOW_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION); - eventType = IME_HIDE; - ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_HIDE_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION); - eventType = IME_CHANGE; - ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_CHANGE_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); } @@ -601,16 +598,13 @@ HWTEST_F(IdentityCheckerTest, testUpdateListenEventFlag_002, TestSize.Level0) IdentityCheckerTest::IdentityCheckerMock::isSystemApp_ = true; IdentityCheckerTest::IdentityCheckerMock::isNativeSa_ = false; InputClientInfo clientInfo{}; - EventType eventType = IME_SHOW; - int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_SHOW_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); - eventType = IME_HIDE; - ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_HIDE_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); - eventType = IME_CHANGE; - ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_CHANGE_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); } @@ -627,16 +621,13 @@ HWTEST_F(IdentityCheckerTest, testUpdateListenEventFlag_003, TestSize.Level0) IdentityCheckerTest::IdentityCheckerMock::isSystemApp_ = false; IdentityCheckerTest::IdentityCheckerMock::isNativeSa_ = true; InputClientInfo clientInfo{}; - EventType eventType = IME_SHOW; - int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_SHOW_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); - eventType = IME_HIDE; - ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_HIDE_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); - eventType = IME_CHANGE; - ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType); + ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, EVENT_IME_CHANGE_MASK); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); } diff --git a/test/unittest/cpp_test/src/ime_event_monitor_manager_test.cpp b/test/unittest/cpp_test/src/ime_event_monitor_manager_test.cpp index 6aeb8f32..fc77b1ed 100644 --- a/test/unittest/cpp_test/src/ime_event_monitor_manager_test.cpp +++ b/test/unittest/cpp_test/src/ime_event_monitor_manager_test.cpp @@ -65,61 +65,65 @@ void ImeEventMonitorManagerTest::TearDown() /** * @tc.name: testRegisterImeEventListener_001 -* @tc.desc: type size over max +* @tc.desc: eventType is 0 * @tc.type: FUNC */ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_001, TestSize.Level0) { IMSA_HILOGI("testRegisterImeEventListener_001 start."); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_HIDE, EventType::IME_SHOW, EventType::IME_CHANGE, static_cast(10) }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(0, listener); EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); } /** * @tc.name: testUnRegisterImeEventListener_002 -* @tc.desc: type size over max +* @tc.desc: eventFlag is 0 * @tc.type: FUNC */ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_002, TestSize.Level0) { IMSA_HILOGI("testUnRegisterImeEventListener_002 start."); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener( - { EventType::IME_HIDE, EventType::IME_SHOW, EventType::IME_CHANGE, static_cast(10) }, listener); + auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(0, listener); EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); } /** * @tc.name: testRegisterImeEventListener_003 -* @tc.desc: type is error +* @tc.desc: eventFlag is 15 * @tc.type: FUNC */ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_003, TestSize.Level0) { - IMSA_HILOGI("testRegisterImeEventListener_003 start."); + IMSA_HILOGI("testUnRegisterImeEventListener_003 start."); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener); - EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); - EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(15, listener); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_HIDE_MASK); + ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); + it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_SHOW_MASK); + ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); } /** -* @tc.name: testUnRegisterImeEventListener_004 -* @tc.desc: type is error +* @tc.name: testRegisterImeEventListener_004 +* @tc.desc: eventFlag is 5 * @tc.type: FUNC */ -HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_004, TestSize.Level0) +HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_004, TestSize.Level0) { - IMSA_HILOGI("testUnRegisterImeEventListener_004 start."); + IMSA_HILOGI("testRegisterImeEventListener_004 start."); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener( - { EventType::IME_HIDE, EventType::IME_CHANGE }, listener); - EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); - EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(5, listener); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_HIDE_MASK); + ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); + EXPECT_EQ(it->second.size(), 1); } /** @@ -130,7 +134,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_004, TestSiz HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_005, TestSize.Level0) { IMSA_HILOGI("testRegisterImeEventListener_005 start."); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, nullptr); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, nullptr); EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); } @@ -143,7 +147,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_005, TestSize. HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_006, TestSize.Level0) { IMSA_HILOGI("testUnRegisterImeEventListener_006 start."); - auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, nullptr); + auto ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, nullptr); EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); } @@ -158,7 +162,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_007, TestSize. IMSA_HILOGI("testRegisterImeEventListener_007 start."); TddUtil::RestoreSelfTokenID(); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); } @@ -172,13 +176,13 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_008, TestSiz { IMSA_HILOGI("testUnRegisterImeEventListener_008 start."); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 4); TddUtil::RestoreSelfTokenID(); - ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); + EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 0); } @@ -192,11 +196,11 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_009, TestSize. { IMSA_HILOGI("testRegisterImeEventListener_009 start."); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 4); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_HIDE_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 1); auto iter = it->second.find(listener); @@ -205,7 +209,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_009, TestSize. /** * @tc.name: testRegisterImeEventListener_010 -* @tc.desc: one listener register all event +* @tc.desc: one listener register EVENT_IME_HIDE_MASK|EVENT_IME_SHOW_MASK * @tc.type: FUNC */ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_010, TestSize.Level0) @@ -213,17 +217,17 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_010, TestSize. IMSA_HILOGI("testRegisterImeEventListener_010 start."); auto listener = std::make_shared(); auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_HIDE, EventType::IME_SHOW }, listener); + EVENT_IME_HIDE_MASK | EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_HIDE_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 1); auto iter = it->second.find(listener); EXPECT_NE(iter, it->second.end()); - it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW); + it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_SHOW_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 1); iter = it->second.find(listener); @@ -232,7 +236,7 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_010, TestSize. /** * @tc.name: testRegisterImeEventListener_011 -* @tc.desc: one listener register three same event +* @tc.desc: one listener register EVENT_IME_SHOW_MASK|EVENT_IME_HIDE_MASK|EVENT_IME_CHANGE_MASK * @tc.type: FUNC */ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_011, TestSize.Level0) @@ -240,15 +244,12 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_011, TestSize. IMSA_HILOGI("testRegisterImeEventListener_011 start."); auto listener = std::make_shared(); auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_SHOW, EventType::IME_SHOW }, listener); + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK | EVENT_IME_CHANGE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); - EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW); - ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); - ASSERT_EQ(it->second.size(), 1); - auto iter = it->second.find(listener); - EXPECT_NE(iter, it->second.end()); + EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6); + EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_CHANGE_MASK); + ASSERT_EQ(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); } /** @@ -262,21 +263,21 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_012, TestSize. auto listener = std::make_shared(); auto listener1 = std::make_shared(); auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener); + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener1); + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener1); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_HIDE_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 2); auto iter = it->second.find(listener); EXPECT_NE(iter, it->second.end()); iter = it->second.find(listener1); EXPECT_NE(iter, it->second.end()); - it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW); + it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_SHOW_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 2); iter = it->second.find(listener); @@ -295,23 +296,22 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_013, TestSize. IMSA_HILOGI("testRegisterImeEventListener_013 start."); auto listener = std::make_shared(); auto listener1 = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_SHOW }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener1); + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener1); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_SHOW_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 2); auto iter = it->second.find(listener); EXPECT_NE(iter, it->second.end()); iter = it->second.find(listener1); EXPECT_NE(iter, it->second.end()); - it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_HIDE); + it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_HIDE_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 1); iter = it->second.find(listener1); @@ -327,11 +327,11 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_014, TestSiz { IMSA_HILOGI("testUnRegisterImeEventListener_014 start."); auto listener = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener); + ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 0); @@ -347,11 +347,11 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_015, TestSiz IMSA_HILOGI("testUnRegisterImeEventListener_015 start."); auto listener = std::make_shared(); auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener); + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); - ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener); + ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); @@ -367,12 +367,12 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_016, TestSiz IMSA_HILOGI("testUnRegisterImeEventListener_016 start."); auto listener = std::make_shared(); auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener); + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener); + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_TRUE(ImeEventMonitorManagerImpl::GetInstance().listeners_.empty()); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 0); @@ -388,17 +388,17 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_017, TestSiz IMSA_HILOGI("testUnRegisterImeEventListener_017 start."); auto listener = std::make_shared(); auto listener1 = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1); + ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener1); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener); + ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_SHOW_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 1); auto iter = it->second.find(listener1); @@ -415,17 +415,17 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_018, TestSiz IMSA_HILOGI("testUnRegisterImeEventListener_018 start."); auto listener = std::make_shared(); auto listener1 = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1); + ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener1); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener); + ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_SHOW_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 2); auto iter = it->second.find(listener); @@ -444,17 +444,17 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_019, TestSiz auto listener = std::make_shared(); auto listener1 = std::make_shared(); auto listener2 = std::make_shared(); - auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); + auto ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1); + ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener1); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener2); + ret = ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener2); EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 2); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 1); - auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EventType::IME_SHOW); + auto it = ImeEventMonitorManagerImpl::GetInstance().listeners_.find(EVENT_IME_SHOW_MASK); ASSERT_NE(it, ImeEventMonitorManagerImpl::GetInstance().listeners_.end()); ASSERT_EQ(it->second.size(), 2); auto iter = it->second.find(listener); @@ -473,9 +473,10 @@ HWTEST_F(ImeEventMonitorManagerTest, testRegisterImeEventListener_020, TestSize. IMSA_HILOGI("testRegisterImeEventListener_020 start."); auto listener = std::make_shared(); auto listener1 = std::make_shared(); - auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener); + auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(EVENT_IME_CHANGE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW, IME_HIDE }, listener1); + ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener1); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 7); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 3); @@ -491,17 +492,18 @@ HWTEST_F(ImeEventMonitorManagerTest, testUnRegisterImeEventListener_021, TestSiz IMSA_HILOGI("testUnRegisterImeEventListener_021 start."); auto listener = std::make_shared(); auto listener1 = std::make_shared(); - auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener); + auto ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(EVENT_IME_CHANGE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); + ret = ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW, IME_HIDE }, listener1); + ret = ImeEventMonitorManager::GetInstance().RegisterImeEventListener( + EVENT_IME_SHOW_MASK | EVENT_IME_HIDE_MASK, listener1); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 7); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 3); - ret = ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener({ EventType::IME_CHANGE }, listener); + ret = ImeEventMonitorManagerImpl::GetInstance().UnRegisterImeEventListener(EVENT_IME_CHANGE_MASK, listener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_EQ(InputMethodController::GetInstance()->clientInfo_.eventFlag, 6); EXPECT_EQ(ImeEventMonitorManagerImpl::GetInstance().listeners_.size(), 2); diff --git a/test/unittest/cpp_test/src/ime_proxy_test.cpp b/test/unittest/cpp_test/src/ime_proxy_test.cpp index ec9a292a..ae2a14a7 100644 --- a/test/unittest/cpp_test/src/ime_proxy_test.cpp +++ b/test/unittest/cpp_test/src/ime_proxy_test.cpp @@ -140,7 +140,7 @@ private: TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, "ImeProxyTest")); auto listener = std::make_shared(); ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener( - { EventType::IME_CHANGE, EventType::IME_HIDE, EventType::IME_SHOW }, listener); + EVENT_IME_HIDE_MASK | EVENT_IME_SHOW_MASK | EVENT_IME_CHANGE_MASK, listener); TddUtil::RestoreSelfTokenID(); } }; diff --git a/test/unittest/cpp_test/src/input_method_panel_test.cpp b/test/unittest/cpp_test/src/input_method_panel_test.cpp index 826bc7bd..244acb54 100644 --- a/test/unittest/cpp_test/src/input_method_panel_test.cpp +++ b/test/unittest/cpp_test/src/input_method_panel_test.cpp @@ -810,8 +810,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0) // set system app TddUtil::SetTestTokenID(testTokenId_); auto listener = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app InputWindowInfo info{ "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ }; @@ -832,8 +832,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0) InputMethodPanelTest::ImcPanelHideInfoCheck(info); // set system app TddUtil::SetTestTokenID(testTokenId_); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app } @@ -849,8 +849,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0) // set system app TddUtil::SetTestTokenID(testTokenId_); auto listener = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app InputWindowInfo info{ "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ }; @@ -872,8 +872,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0) InputMethodPanelTest::ImcPanelHideInfoCheck(info); // set system app TddUtil::SetTestTokenID(testTokenId_); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app InputMethodPanelTest::inputMethodPanel_->panelFlag_ = FLG_FIXED; @@ -890,8 +890,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0) // set system app TddUtil::SetTestTokenID(testTokenId_); auto listener = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app InputMethodPanelTest::inputMethodPanel_->panelFlag_ = FLG_CANDIDATE_COLUMN; @@ -910,8 +910,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0) InputMethodPanelTest::ImcPanelHideNumCheck(0); // set system app TddUtil::SetTestTokenID(testTokenId_); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app InputMethodPanelTest::inputMethodPanel_->panelFlag_ = FLG_FIXED; @@ -928,8 +928,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0) // set system app TddUtil::SetTestTokenID(testTokenId_); auto listener = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app InputMethodPanelTest::ImcPanelListeningTestRestore(); @@ -947,8 +947,8 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0) InputMethodPanelTest::ImcPanelHideNumCheck(0); // set system app TddUtil::SetTestTokenID(testTokenId_); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel system app } @@ -966,11 +966,11 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0) auto listener1 = std::make_shared(); auto listener2 = std::make_shared(); auto listener3 = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener1); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener2); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener2); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener3); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener1); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener1); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener2); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener2); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener3); TddUtil::RestoreSelfTokenID(); // cancel native sa // set current ime @@ -989,11 +989,11 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0) // set native sa TddUtil::GrantNativePermission(); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener1); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener1); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener2); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener2); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener3); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener1); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener1); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener2); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener2); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener3); TddUtil::RestoreSelfTokenID(); // cancel native sa } @@ -1011,11 +1011,11 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_006, TestSize.Level0) auto listener1 = std::make_shared(); auto listener2 = std::make_shared(); auto listener3 = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener1); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_HIDE }, listener1); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener2); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener({ EventType::IME_SHOW }, listener3); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener1); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener1); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK, listener1); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener2); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_SHOW_MASK, listener3); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener1); TddUtil::RestoreSelfTokenID(); // cancel native sa // UnRegister one IME_SHOW listener @@ -1036,9 +1036,9 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_006, TestSize.Level0) // UnRegister all listener // set native sa TddUtil::GrantNativePermission(); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener2); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_SHOW }, listener3); - ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener({ EventType::IME_HIDE }, listener1); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener2); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_SHOW_MASK, listener3); + ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener(EVENT_IME_HIDE_MASK, listener1); TddUtil::RestoreSelfTokenID(); // cancel native sa InputMethodPanelTest::ImcPanelListeningTestRestore(); @@ -1067,8 +1067,7 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_007, TestSize.Level0) // set native sa TddUtil::GrantNativePermission(); auto listener = std::make_shared(); - ImeEventMonitorManager::GetInstance().RegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener); + ImeEventMonitorManager::GetInstance().RegisterImeEventListener(EVENT_IME_HIDE_MASK | EVENT_IME_SHOW_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel native sa InputMethodPanelTest::ImcPanelListeningTestRestore(); @@ -1089,7 +1088,7 @@ HWTEST_F(InputMethodPanelTest, testImcPanelListening_007, TestSize.Level0) // set native sa TddUtil::GrantNativePermission(); ImeEventMonitorManager::GetInstance().UnRegisterImeEventListener( - { EventType::IME_SHOW, EventType::IME_HIDE }, listener); + EVENT_IME_HIDE_MASK | EVENT_IME_SHOW_MASK, listener); TddUtil::RestoreSelfTokenID(); // cancel native sa InputMethodPanelTest::ImcPanelListeningTestRestore(); diff --git a/test/unittest/cpp_test/src/input_method_switch_test.cpp b/test/unittest/cpp_test/src/input_method_switch_test.cpp index cd11b524..d7e4bc42 100644 --- a/test/unittest/cpp_test/src/input_method_switch_test.cpp +++ b/test/unittest/cpp_test/src/input_method_switch_test.cpp @@ -86,7 +86,7 @@ void InputMethodSwitchTest::SetUpTestCase(void) TddUtil::AllocTestTokenID(true, "ohos.inputMethod.test", { "ohos.permission.CONNECT_IME_ABILITY" })); imc_ = InputMethodController::GetInstance(); auto listener = std::make_shared(); - ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener); + ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(EVENT_IME_CHANGE_MASK, listener); } void InputMethodSwitchTest::TearDownTestCase(void) diff --git a/test/unittest/cpp_test/src/newIme_switch_test.cpp b/test/unittest/cpp_test/src/newIme_switch_test.cpp index e6e3aa80..78b6c988 100644 --- a/test/unittest/cpp_test/src/newIme_switch_test.cpp +++ b/test/unittest/cpp_test/src/newIme_switch_test.cpp @@ -79,7 +79,7 @@ void NewImeSwitchTest::SetUpTestCase(void) TddUtil::AllocTestTokenID(true, "ohos.inputMethod.test", { "ohos.permission.CONNECT_IME_ABILITY" })); imc_ = InputMethodController::GetInstance(); auto listener = std::make_shared(); - ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener({ EventType::IME_CHANGE }, listener); + ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(EVENT_IME_CHANGE_MASK, listener); } void NewImeSwitchTest::TearDownTestCase(void)