From 80f770cdfb14a53e01ec52331a2ae7032cb35778 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Sat, 8 Jun 2024 14:52:40 +0800 Subject: [PATCH] Signed-off-by: ma-shaoyin Changes to be committed: --- .../js_input_method_engine_setting.cpp | 9 +++++++-- .../inputmethodability/js_input_method_engine_setting.h | 2 +- .../inputmethod_ability/src/input_method_ability.cpp | 5 ++--- .../include/input_method_engine_listener.h | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp index 15cf127d..11e36aed 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -840,14 +840,19 @@ void JsInputMethodEngineSetting::FreeWorkIfFail(int ret, uv_work_t *work) IMSA_HILOGE("uv_queue_work failed retCode:%{public}d", ret); } -void JsInputMethodEngineSetting::PostTaskToEventHandler(std::function task, const std::string &taskName) +bool JsInputMethodEngineSetting::PostTaskToEventHandler(std::function task, const std::string &taskName) { auto eventHandler = GetEventHandler(); if (eventHandler == nullptr) { IMSA_HILOGE("eventHandler is nullptr!"); - return; + return false; + } + if (eventHandler == AppExecFwk::EventHandler::Current()) { + IMSA_HILOGE("in current thread!"); + return false; } handler_->PostTask(task, taskName); + return true; } } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h index 9adb0659..b3ec7ccb 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h @@ -56,7 +56,7 @@ public: void OnSetSubtype(const SubProperty &property) override; void OnSecurityChange(int32_t security) override; void ReceivePrivateCommand(const std::unordered_map &privateCommand) override; - void PostTaskToEventHandler(std::function task, const std::string &taskName) override; + bool PostTaskToEventHandler(std::function task, const std::string &taskName) override; private: struct PanelContext : public AsyncCall::Context { diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index fa5523b8..b02243d6 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -256,11 +256,10 @@ int32_t InputMethodAbility::StartInput(const InputClientInfo &clientInfo, bool i startInputProcessHandler->SetValue(isCallbackFinished); }; isPendingShowKeyboard_ = clientInfo.isShowKeyboard; - if (imeListener_ != nullptr) { - imeListener_->PostTaskToEventHandler(task, "startInput"); + if (imeListener_ != nullptr && imeListener_->PostTaskToEventHandler(task, "startInput")) { startInputProcessHandler->GetValue(); } else { - IMSA_HILOGE("imeListener_ is nullptr."); + IMSA_HILOGE("imeListener_ is nullptr, or post task failed!"); } return clientInfo.isShowKeyboard ? ShowKeyboard() : ErrorCode::NO_ERROR; } diff --git a/interfaces/inner_api/inputmethod_ability/include/input_method_engine_listener.h b/interfaces/inner_api/inputmethod_ability/include/input_method_engine_listener.h index 39ef96f8..e55b0264 100644 --- a/interfaces/inner_api/inputmethod_ability/include/input_method_engine_listener.h +++ b/interfaces/inner_api/inputmethod_ability/include/input_method_engine_listener.h @@ -38,8 +38,9 @@ public: { return false; } - virtual void PostTaskToEventHandler(std::function task, const std::string &taskName) + virtual bool PostTaskToEventHandler(std::function task, const std::string &taskName) { + return true; } }; } // namespace MiscServices