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 bd56f0025b7ebdab0a2bd27ed08d5b4144f6adc5..bf7ff947d9ce43d59aee8e143b9f01cd85a82dbe 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -334,9 +334,6 @@ napi_value JsInputMethodEngineSetting::JsConstructor(napi_env env, napi_callback IMSA_HILOGE("JsInputMethodEngineSetting napi_wrap failed: %{public}d", status); return nullptr; } - if (setting->loop_ == nullptr) { - napi_get_uv_event_loop(env, &setting->loop_); - } return thisVar; }; @@ -885,36 +882,6 @@ void JsInputMethodEngineSetting::ReceivePrivateCommand( eventHandler->PostTask(task, type, 0, AppExecFwk::EventQueue::Priority::VIP); } -uv_work_t *JsInputMethodEngineSetting::GetUVwork(const std::string &type, EntrySetter entrySetter) -{ - IMSA_HILOGD("run in, type: %{public}s.", type.c_str()); - UvEntry *entry = nullptr; - { - std::lock_guard lock(mutex_); - - if (jsCbMap_[type].empty()) { - IMSA_HILOGD("%{public}s cb-vector is empty.", type.c_str()); - return nullptr; - } - entry = new (std::nothrow) UvEntry(jsCbMap_[type], type); - if (entry == nullptr) { - IMSA_HILOGE("entry is nullptr!"); - return nullptr; - } - if (entrySetter != nullptr) { - entrySetter(*entry); - } - } - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - IMSA_HILOGE("work is nullptr!"); - delete entry; - return nullptr; - } - work->data = entry; - return work; -} - std::shared_ptr JsInputMethodEngineSetting::GetEventHandler() { std::lock_guard lock(eventHandlerMutex_); @@ -951,18 +918,6 @@ bool JsInputMethodEngineSetting::IsCallbackRegistered(const std::string &type) return true; } -void JsInputMethodEngineSetting::FreeWorkIfFail(int ret, uv_work_t *work) -{ - if (ret == 0 || work == nullptr) { - return; - } - - UvEntry *data = static_cast(work->data); - delete data; - delete work; - IMSA_HILOGE("uv_queue_work failed retCode: %{public}d!", ret); -} - bool JsInputMethodEngineSetting::PostTaskToEventHandler(std::function task, const std::string &taskName) { auto eventHandler = GetEventHandler(); 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 024776dcec736f1c61ebc95859b473381c7ebc04..2cba6facd01efc09b459c6c609d25cc671e3cd40 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h @@ -120,9 +120,6 @@ private: using EntrySetter = std::function; static std::shared_ptr GetEventHandler(); std::shared_ptr GetEntry(const std::string &type, EntrySetter entrySetter = nullptr); - uv_work_t *GetUVwork(const std::string &type, EntrySetter entrySetter = nullptr); - void FreeWorkIfFail(int ret, uv_work_t *work); - uv_loop_s *loop_ = nullptr; std::recursive_mutex mutex_; std::map>> jsCbMap_; static std::mutex engineMutex_; diff --git a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp index df4a5d71cd187d2c4d2617a78bf4dcdad3e0e432..7130042046f77eb8f1b808796873281538d27c28 100644 --- a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp @@ -136,9 +136,6 @@ napi_value JsKeyboardDelegateSetting::JsConstructor(napi_env env, napi_callback_ IMSA_HILOGE("failed to wrap: %{public}d!", status); return nullptr; } - if (delegate->loop_ == nullptr) { - napi_get_uv_event_loop(env, &delegate->loop_); - } return thisVar; }; @@ -647,36 +644,6 @@ void JsKeyboardDelegateSetting::OnEditorAttributeChange(const InputAttribute &in eventHandler->PostTask(task, type, 0, AppExecFwk::EventQueue::Priority::VIP); } -uv_work_t *JsKeyboardDelegateSetting::GetUVwork(const std::string &type, EntrySetter entrySetter) -{ - IMSA_HILOGD("start, type: %{public}s", type.c_str()); - UvEntry *entry = nullptr; - { - std::lock_guard lock(mutex_); - - if (jsCbMap_[type].empty()) { - IMSA_HILOGD("%{public}s cb-vector is empty.", type.c_str()); - return nullptr; - } - entry = new (std::nothrow) UvEntry(jsCbMap_[type], type); - if (entry == nullptr) { - IMSA_HILOGE("entry is nullptr!"); - return nullptr; - } - if (entrySetter != nullptr) { - entrySetter(*entry); - } - } - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - IMSA_HILOGE("work is nullptr!"); - delete entry; - return nullptr; - } - work->data = entry; - return work; -} - std::shared_ptr JsKeyboardDelegateSetting::GetEventHandler() { std::lock_guard lock(eventHandlerMutex_); diff --git a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.h b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.h index 315ecdadf5ad32f7fb26803a02b4d18c4a08bad6..7c39991a625f9c0bf19ca883642394da0b57d0cd 100644 --- a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.h +++ b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.h @@ -96,11 +96,9 @@ private: using EntrySetter = std::function; static std::shared_ptr GetEventHandler(); std::shared_ptr GetEntry(const std::string &type, EntrySetter entrySetter = nullptr); - uv_work_t *GetUVwork(const std::string &type, EntrySetter entrySetter = nullptr); static void DealKeyEvent(const std::shared_ptr &keyEvent, const std::shared_ptr &keyEventEntry, const std::shared_ptr &keyCodeEntry, const sptr &consumer); - uv_loop_s *loop_ = nullptr; std::recursive_mutex mutex_; std::map>> jsCbMap_; static std::mutex keyboardMutex_; diff --git a/frameworks/js/napi/inputmethodability/js_panel.cpp b/frameworks/js/napi/inputmethodability/js_panel.cpp index d448f4020f5b0ef2f95c613124d813afe7ed7ffc..bbd07a3ed798a4f7e70253586b5fc12010218633 100644 --- a/frameworks/js/napi/inputmethodability/js_panel.cpp +++ b/frameworks/js/napi/inputmethodability/js_panel.cpp @@ -752,7 +752,14 @@ bool JsPanelRect::Read(napi_env env, napi_value object, LayoutParams &layoutPara bool JsImmersiveEffect::Read(napi_env env, napi_value object, ImmersiveEffect &effect) { - auto ret = JsUtil::Object::ReadProperty(env, object, "gradientHeight", effect.gradientHeight); + int32_t gradientHeight = 0; + auto ret = JsUtil::Object::ReadProperty(env, object, "gradientHeight", gradientHeight); + if (!ret || gradientHeight < 0) { + IMSA_HILOGE("ret is false or gradientHeight is invalid, gradientHeight:%{public}d", gradientHeight); + return false; + } + + effect.gradientHeight = static_cast(gradientHeight); int32_t gradientMode = 0; ret = ret && JsUtil::Object::ReadProperty(env, object, "gradientMode", gradientMode); if (gradientMode < static_cast(GradientMode::NONE) || diff --git a/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp b/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp index 97fddfc4b6ea11a9f6fa06d588a6cc6b6e37e513..3a57d65fefde75e2df1fce3c7371251edfaa641d 100644 --- a/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp +++ b/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp @@ -22,6 +22,7 @@ namespace OHOS { namespace MiscServices { std::shared_ptr PanelListenerImpl::instance_{ nullptr }; std::mutex PanelListenerImpl::listenerMutex_; +constexpr uint8_t SIE_CHANGE_PARAM_COUNT = 2; std::shared_ptr PanelListenerImpl::GetInstance() { if (instance_ == nullptr) { @@ -134,7 +135,7 @@ void PanelListenerImpl::OnSizeChange( keyboardArea.right); auto task = [entry]() { auto getWindowSizeParams = [entry](napi_env env, napi_value *args, uint8_t argc) -> bool { - if (argc == 0) { + if (argc < SIE_CHANGE_PARAM_COUNT) { return false; } napi_value windowSize = JsWindowSize::Write(env, entry->size); @@ -144,7 +145,7 @@ void PanelListenerImpl::OnSizeChange( return true; }; // 2 means 'sizeChange' has 2 params - JsCallbackHandler::Traverse({ entry->cbCopy }, { 2, getWindowSizeParams }); + JsCallbackHandler::Traverse({ entry->cbCopy }, { SIE_CHANGE_PARAM_COUNT, getWindowSizeParams }); }; eventHandler->PostTask(task, event, 0, AppExecFwk::EventQueue::Priority::VIP); } diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp index 58e99f28c7693906bf32700b6edd4cfe5bf5f845..ef4b77dba9a9a203801d38e6dbbfd467ab04c6aa 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp @@ -315,10 +315,6 @@ napi_value JsGetInputMethodController::JsConstructor(napi_env env, napi_callback return nullptr; } - if (controllerObject->loop_ == nullptr) { - napi_get_uv_event_loop(env, &controllerObject->loop_); - } - return thisVar; } diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h index da9589ba8ffa2d9cfb2d62308c5fedd121c608f8..d6cb69c54cf6d47e465600c2d44d80ab1f5946bf 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h @@ -264,7 +264,6 @@ private: }; using EntrySetter = std::function; std::shared_ptr GetEntry(const std::string &type, EntrySetter entrySetter = nullptr); - uv_loop_s *loop_ = nullptr; std::recursive_mutex mutex_; std::map>> jsCbMap_; static std::mutex controllerMutex_; 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 010f3e381eca40f0aa919cda00138ac7b411312e..b18d452755b1253e0ee91c81111d04415926423c 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp @@ -101,9 +101,6 @@ napi_value JsGetInputMethodSetting::JsConstructor(napi_env env, napi_callback_in IMSA_HILOGE("failed to wrap: %{public}d", status); return nullptr; } - if (delegate->loop_ == nullptr) { - napi_get_uv_event_loop(env, &delegate->loop_); - } return thisVar; } diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h index b8ca51f1a7d2d4df535dfea8aa509a874a9c4ee5..a6b9149cbe27723af727fcc4d8f1417c428562e7 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h @@ -185,7 +185,6 @@ private: static thread_local napi_ref IMSRef_; static std::mutex eventHandlerMutex_; static std::shared_ptr handler_; - uv_loop_s *loop_ = nullptr; std::recursive_mutex mutex_; std::map>> jsCbMap_; static std::mutex msMutex_; diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index 737d2e7a2a2b1e18dc109494b8aae445c40213ba..08c72d7453ba59ea1433e860453e755c125b42f5 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -289,6 +289,11 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, std::string &out) if (maxLen <= 0) { return status; } + + if (maxLen > STR_MAX_LENGTH) { + IMSA_HILOGE("string length is too long."); + return napi_generic_failure; + } IMSA_HILOGD("napi_value -> std::string get length %{public}zu", maxLen); char *buf = new (std::nothrow) char[maxLen + STR_TAIL_LENGTH]; if (buf != nullptr) { @@ -548,8 +553,8 @@ napi_status JsUtils::GetMessageHandlerCallbackParam(napi_value *argv, IMSA_HILOGE("argv is nullptr!."); return napi_generic_failure; } - if (size < ARGC_ONE) { - IMSA_HILOGE("argv size is less than 1!."); + if (size <= ARGC_ONE) { + IMSA_HILOGE("argv size is less than 2!."); return napi_generic_failure; } if (jsMessageHandler == nullptr) { diff --git a/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp b/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp index 1a9f320981bb2ba40b04b76ece0c91241a63c26c..0c2a4b2e9b7778c52d817fb6fda6ca21cdaa07db 100644 --- a/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp +++ b/frameworks/kits/extension/src/js_inputmethod_extension_context.cpp @@ -101,21 +101,23 @@ private: // only support one or two or three params PARAM_CHECK_RETURN(env, argc == ARGC_ONE || argc == ARGC_TWO || argc == ARGC_THREE, "number of param should in [1,3]", TYPE_NONE, CreateJsUndefined(env)); - PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "param want type must be Want", - TYPE_NONE, JsUtil::Const::Null(env)); + PARAM_CHECK_RETURN(env, JsUtil::GetType(env, argv[0]) == napi_object, "param want type must be Want", TYPE_NONE, + JsUtil::Const::Null(env)); decltype(argc) unwrapArgc = 0; AAFwk::Want want; OHOS::AppExecFwk::UnwrapWant(env, argv[INDEX_ZERO], want); - IMSA_HILOGI("%{public}s bundleName: %{public}s abilityName: %{public}s.", __func__, want.GetBundle().c_str(), + IMSA_HILOGI("bundleName:%{public}s abilityName:%{public}s", want.GetBundle().c_str(), want.GetElement().GetAbilityName().c_str()); unwrapArgc++; AAFwk::StartOptions startOptions; - napi_valuetype valueType = napi_undefined; - napi_typeof(env, argv[INDEX_ONE], &valueType); - if (argc > ARGC_ONE && valueType == napi_object) { - IMSA_HILOGI("OnStartAbility start options is used."); - AppExecFwk::UnwrapStartOptions(env, argv[INDEX_ONE], startOptions); - unwrapArgc++; + if (argc > ARGC_ONE) { + napi_valuetype valueType = napi_undefined; + napi_typeof(env, argv[INDEX_ONE], &valueType); + if (valueType == napi_object) { + IMSA_HILOGI("OnStartAbility start options is used."); + AppExecFwk::UnwrapStartOptions(env, argv[INDEX_ONE], startOptions); + unwrapArgc++; + } } napi_value lastParam = argc > unwrapArgc ? argv[unwrapArgc] : nullptr; napi_value result = nullptr; diff --git a/frameworks/native/inputmethod_ability/src/ime_mirror_manager.cpp b/frameworks/native/inputmethod_ability/src/ime_mirror_manager.cpp index d5a1a7103d1a23408a58fd2ef3305ccad57ca9e5..f727ed85e3572854693bd94a3b8be9c68f373ee4 100644 --- a/frameworks/native/inputmethod_ability/src/ime_mirror_manager.cpp +++ b/frameworks/native/inputmethod_ability/src/ime_mirror_manager.cpp @@ -30,6 +30,10 @@ void ImeMirrorManager::SetImeMirrorEnable(bool isRegistered) bool ImeMirrorManager::SubscribeSaStart(std::function handler, int32_t saId) { + if (handler == nullptr) { + IMSA_HILOGE("handler is nullptr"); + return false; + } { std::lock_guard lockGuard(listenerMapMutex_); if (saMgrListenerMap_.find(saId) != saMgrListenerMap_.end()) { diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index a919161a4131e7c8bcc530fefcdfb64c25f2f326..d72fa032ce6daa0bdf7f3bdbf88940c7b8decd26 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -31,6 +31,7 @@ constexpr uint32_t INVALID_WINDOW_ID = 0; constexpr int32_t INVALID_VALUE = -1; constexpr size_t MAX_PRIVATE_COMMAND_SIZE = 32 * 1024; // 32K constexpr size_t MAX_PRIVATE_COMMAND_COUNT = 5; +constexpr size_t MAX_SYS_PRIVATE_COMMAND_COUNT = MAX_PRIVATE_COMMAND_COUNT + 1; constexpr size_t MAX_VALUE_MAP_COUNT = 256; constexpr size_t MAX_ARRAY_BUFFER_MSG_ID_SIZE = 256; // 256B constexpr size_t MAX_ARRAY_BUFFER_MSG_PARAM_SIZE = 128 * 1024; // 128KB @@ -423,7 +424,7 @@ struct TextConfig { { size_t privateCommandSize = privateCommand.size(); size_t maxSize = - IsSystemPrivateCommand(privateCommand) ? (MAX_PRIVATE_COMMAND_COUNT + 1) : MAX_PRIVATE_COMMAND_COUNT; + IsSystemPrivateCommand(privateCommand) ? MAX_SYS_PRIVATE_COMMAND_COUNT : MAX_PRIVATE_COMMAND_COUNT; if (privateCommandSize == 0 || privateCommandSize > maxSize) { IMSA_HILOGE("privateCommand size must more than 0 and less than 5."); return false; diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index d0986b2e425cfb2a4d53813e14432ed57cd441c9..d8408fcbeaa0bcf3ffe27d147e490ada0ab8c83e 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -68,6 +68,13 @@ InputMethodController::InputMethodController() } InputMethodController::~InputMethodController() { } +#ifdef OHOS_IMF_TEST +void InputMethodController::SetImsaProxyForTest(sptr proxy) +{ + std::lock_guard autoLock(abilityLock_); + abilityManager_ = proxy; +} +#endif // OHOS_IMF_TEST sptr InputMethodController::GetInstance() { @@ -804,7 +811,6 @@ int32_t InputMethodController::OnCursorUpdate(CursorInfo cursorInfo) agent->OnCursorUpdate(cursorInfo.left, cursorInfo.top, cursorInfo.height); return ErrorCode::NO_ERROR; }); - return ErrorCode::NO_ERROR; } int32_t InputMethodController::OnSelectionChange(std::u16string text, int start, int end) @@ -843,7 +849,6 @@ int32_t InputMethodController::OnSelectionChange(std::u16string text, int start, agent->OnSelectionChange(testString, selectOldBegin, selectOldEnd, selectNewBegin, selectNewEnd); return ErrorCode::NO_ERROR; }); - return ErrorCode::NO_ERROR; } int32_t InputMethodController::OnConfigurationChange(Configuration info) @@ -877,11 +882,13 @@ int32_t InputMethodController::OnConfigurationChange(Configuration info) SetInputReady(agents, imeInfos); } + auto agent = GetAgent(); + if (agent == nullptr) { + IMSA_HILOGE("agent is nullptr!"); + return ErrorCode::ERROR_IME_NOT_STARTED; + } InputAttributeInner inner = InputMethodTools::GetInstance().AttributeToInner(attribute); - return SendRequestToAllAgents([&inner](std::shared_ptr agent) -> int32_t { - agent->OnAttributeChange(inner); - return ErrorCode::NO_ERROR; - }); + agent->OnAttributeChange(inner); return ErrorCode::NO_ERROR; } @@ -1899,6 +1906,10 @@ int32_t InputMethodController::SendRequestToAllAgents(std::function command; + if (size > MAX_SYS_PRIVATE_COMMAND_COUNT) { + IMSA_HILOGE("privateCommand size is too large: %{public}zu", size); + return IME_ERR_PARAMCHECK; + } + std::unordered_map command; for (size_t i = 0; i < size; i++) { if (privateCommand[i] == nullptr) { IMSA_HILOGE("privateCommand[%zu] is nullptr", i); diff --git a/interfaces/inner_api/inputmethod_controller/BUILD.gn b/interfaces/inner_api/inputmethod_controller/BUILD.gn index 41f0843a539e1c1ab8d056f9d48c72bb9c0bfbca..87a05c06541bbe86dd855b97ff3d73a8113bb1e3 100644 --- a/interfaces/inner_api/inputmethod_controller/BUILD.gn +++ b/interfaces/inner_api/inputmethod_controller/BUILD.gn @@ -262,7 +262,6 @@ ohos_source_set("imc_response_channel_stub") { ohos_shared_library("inputmethod_client") { branch_protector_ret = "pac_ret" - sanitize = { boundary_sanitize = true cfi = true @@ -417,6 +416,12 @@ ohos_static_library("inputmethod_client_static") { "samgr:samgr_proxy", ] + if (testonly) { + defines = [ + "OHOS_IMF_TEST" + ] + } + client_output_values = get_target_outputs(":input_client_interface") sources += filter_include(client_output_values, [ 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 8a72a7a27428ccd7d9ec7b76c72495ac1d6ce462..faf71602b171a1ff7059e566e3a6c8830fe850fc 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -979,7 +979,9 @@ public: * @since 18 */ IMF_API int32_t RegisterWindowScaleCallbackHandler(WindowScaleCallback&& callback); - +#ifdef OHOS_IMF_TEST + void SetImsaProxyForTest(sptr proxy); +#endif // OHOS_IMF_TEST private: InputMethodController(); ~InputMethodController(); diff --git a/services/file/src/file_operator.cpp b/services/file/src/file_operator.cpp index e55aa6ad5aaa0b6a4f80865acf3caccbfd1a3a3f..d9b85e61447f81309dd01ba9a13542b9f1e3c122 100644 --- a/services/file/src/file_operator.cpp +++ b/services/file/src/file_operator.cpp @@ -63,7 +63,7 @@ bool FileOperator::IsValidPath(const std::string &filePath) IMSA_HILOGE("FilePath contains './'"); return false; } - if (filePath[0] != '/') { + if (!filePath.empty() && filePath[0] != '/') { IMSA_HILOGE("FilePath is not an absolute path"); return false; } diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 0ec8638643d95d111beb4355a493c9b42a2cffea..89c006b0572d9963467735b5ec3e9cf7b9c1e6e9 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -124,7 +124,7 @@ public: int32_t OnRegisterProxyIme(const sptr &core, const sptr &agent, int32_t pid); int32_t OnUnRegisteredProxyIme(UnRegisteredType type, const sptr &core, pid_t pid); int32_t OnBindImeMirror(const sptr &core, const sptr &agent); - int32_t OnUnBindImeMirror(); + int32_t OnUnbindImeMirror(); int32_t UpdateLargeMemorySceneState(const int32_t memoryState); int32_t OnRegisterProxyIme( uint64_t displayId, const sptr &core, const sptr &agent); @@ -287,7 +287,7 @@ private: uint32_t GetScbStartCount(); void ResetRestartTasks(); int32_t SendAllReadyImeToClient( - std::shared_ptr ImeDatas, const std::shared_ptr &clientInfo); + std::shared_ptr data, const std::shared_ptr &clientInfo); void SetImeConnection(const sptr &connection); sptr GetImeConnection(); void ClearImeConnection(const sptr &connection); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 5b6e6a3f5225cb3dcece483885f347f8a66f088f..4dcb864ef7be9f17423c0d9e2be607d4f129ce98 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -318,7 +318,10 @@ int32_t InputMethodSystemAbility::OnExtension(const std::string &extension, Mess { IMSA_HILOGI("extension=%{public}s", extension.c_str()); if (extension == "restore") { - (void)data.ReadFileDescriptor(); + int32_t fd = data.ReadFileDescriptor(); + if (fd >= 0) { + close(fd); + } std::string bundleName = GetRestoreBundleName(data); if (!IsValidBundleName(bundleName)) { IMSA_HILOGE("bundleName=%{public}s is invalid", bundleName.c_str()); @@ -646,7 +649,7 @@ ErrCode InputMethodSystemAbility::StartInput(const InputClientInfoInner &inputCl { AttachStateGuard guard(*this); InputClientInfo inputClientInfo = InputMethodTools::GetInstance().InnerToInputClientInfo(inputClientInfoInner); - auto ret = StartInputInner(const_cast(inputClientInfo), agents, imeInfos); + auto ret = StartInputInner(inputClientInfo, agents, imeInfos); std::string bundleName = ""; if (!imeInfos.empty()) { bundleName = imeInfos[0].bundleName; @@ -913,7 +916,7 @@ ErrCode InputMethodSystemAbility::BindImeMirror(const sptr &co auto session = UserSessionManager::GetInstance().GetUserSession(userId); if (session == nullptr) { IMSA_HILOGE("%{public}d session is nullptr!", userId); - return ErrorCode::ERROR_NULL_POINTER; + return ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND; } return session->OnBindImeMirror(core, agent); } @@ -938,7 +941,7 @@ ErrCode InputMethodSystemAbility::UnbindImeMirror() IMSA_HILOGE("%{public}d session is nullptr!", userId); return ErrorCode::ERROR_NULL_POINTER; } - return session->OnUnBindImeMirror(); + return session->OnUnbindImeMirror(); } ErrCode InputMethodSystemAbility::InitConnect() diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index fa470129829b70ab10e5774495665727d76ddc52..0eb926d581078060d52537fcb72e0c9f4cd620df 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -651,6 +651,11 @@ int32_t PerUserSession::BindClientWithIme( return ErrorCode::ERROR_IMSA_CLIENT_INPUT_READY_FAILED; } } + + if (type == ImeType::IME_MIRROR) { + return ErrorCode::NO_ERROR; + } + clientGroup->UpdateClientInfo(clientInfo->client->AsObject(), { { UpdateFlag::BINDIMETYPE, type }, { UpdateFlag::ISSHOWKEYBOARD, clientInfo->isShowKeyboard }, { UpdateFlag::STATE, ClientState::ACTIVE }, { UpdateFlag::BIND_IME_PID, data->pid} }); @@ -885,7 +890,7 @@ int32_t PerUserSession::OnBindImeMirror(const sptr &core, cons } return ErrorCode::NO_ERROR; } -int32_t PerUserSession::OnUnBindImeMirror() +int32_t PerUserSession::OnUnbindImeMirror() { IMSA_HILOGD("[ImeMirrorTag]start"); auto clientInfo = GetCurrentClientInfo(); @@ -1704,7 +1709,7 @@ int32_t PerUserSession::RequestIme(const std::shared_ptr &data, Request IMSA_HILOGD("proxy enable."); return exec(); } - if (data == nullptr || data->imeStateManager == nullptr) { + if (data == nullptr || data->core == nullptr || data->imeStateManager == nullptr) { IMSA_HILOGE("data is nullptr!"); return ErrorCode::NO_ERROR; } diff --git a/test/common/src/keyboard_listener_test_impl.cpp b/test/common/src/keyboard_listener_test_impl.cpp index 1690e2f245871b08267648da5db0650a1af1a7c2..b1896dd22b4b44e91895b0661a1ce7b94e303739 100644 --- a/test/common/src/keyboard_listener_test_impl.cpp +++ b/test/common/src/keyboard_listener_test_impl.cpp @@ -83,6 +83,7 @@ void KeyboardListenerTestImpl::ResetParam() inputAttribute_.inputPattern = 0; inputAttribute_.enterKeyType = 0; inputAttribute_.inputOption = 0; + funcKey_ = -1; } bool KeyboardListenerTestImpl::WaitKeyEvent(int32_t keyCode) diff --git a/test/unittest/cpp_test/BUILD.gn b/test/unittest/cpp_test/BUILD.gn index f4881ad1013865eed968c142de3e8f47b3f40f8e..ec109c2671e8794c296d0baaaa8a7bdbd1fdda8c 100644 --- a/test/unittest/cpp_test/BUILD.gn +++ b/test/unittest/cpp_test/BUILD.gn @@ -1134,6 +1134,7 @@ ohos_unittest("VirtualListenerTest") { external_deps += [ "window_manager:libwm" ] } } + ohos_unittest("ImeSystemChannelTest") { branch_protector_ret = "pac_ret" sanitize = { @@ -1220,15 +1221,21 @@ ohos_unittest("ImeControllerCpaiTest") { include_dirs = [ "${inputmethod_path}/interfaces/kits/c", "${inputmethod_path}/frameworks/ndk/include", + "${inputmethod_path}/test/unittest/cpp_test/mock", + ] + + defines = [ + "OHOS_IMF_TEST" ] deps = [ - "${inputmethod_path}/frameworks/ndk:ohinputmethod", + "${inputmethod_path}/frameworks/ndk:ohinputmethod_static", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", ] external_deps = [ "googletest:gtest_main", + "googletest:gmock", "hilog:libhilog", "input:libmmi-client", ] diff --git a/test/unittest/cpp_test/mock/mock_input_method_system_ability_proxy.h b/test/unittest/cpp_test/mock/mock_input_method_system_ability_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..c2063be0931a0c7544fcfa7f0ed2ead859c40ea9 --- /dev/null +++ b/test/unittest/cpp_test/mock/mock_input_method_system_ability_proxy.h @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2025 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 MOCK_INPUT_METHOD_SYSTEM_ABILITY_PROXY_H +#define MOCK_INPUT_METHOD_SYSTEM_ABILITY_PROXY_H +#include + +#include "input_method_system_ability_proxy.h" +#include "mock_iremote_object.h" +namespace OHOS { +namespace MiscServices { +class MockInputMethodSystemAbilityProxy : public InputMethodSystemAbilityProxy { +public: + MockInputMethodSystemAbilityProxy() : InputMethodSystemAbilityProxy(nullptr) { }; + MOCK_METHOD(int32_t, StartInput, + (const InputClientInfoInner &inputClientInfoInner, std::vector> &agents, + std::vector &imeInfos), + (override)); + MOCK_METHOD(int32_t, ReleaseInput, (const sptr &client, uint32_t sessionId), (override)); +}; +} // namespace MiscServices +} // namespace OHOS +#endif // MOCK_INPUT_METHOD_SYSTEM_ABILITY_PROXY_H \ No newline at end of file diff --git a/test/unittest/cpp_test/src/identity_checker_test.cpp b/test/unittest/cpp_test/src/identity_checker_test.cpp index bee3587e192a9d6326d9d7a711706cadc6d305e3..c56dd80b3be5c78224618688d1b3a0d4c8a975df 100644 --- a/test/unittest/cpp_test/src/identity_checker_test.cpp +++ b/test/unittest/cpp_test/src/identity_checker_test.cpp @@ -867,6 +867,7 @@ TEST_F(IdentityCheckerTest, OnExtension_dataIsEmpty_ReturnsBadParam) TEST_F(IdentityCheckerTest, OnExtension_BundleNameIsInvalid_ReturnsBadParam) { MessageParcel data; + data.WriteFileDescriptor(1); data.WriteString("[{\"type\":\"default_input_method\",\"detail\":\"com.invalid.bundleName\"}]"); MessageParcel reply; EXPECT_EQ(service_->OnExtension("restore", data, reply), ErrorCode::ERROR_BAD_PARAMETERS); diff --git a/test/unittest/cpp_test/src/ime_mirror_demo.cpp b/test/unittest/cpp_test/src/ime_mirror_demo.cpp index 751e41c02c8170d015060f4b6390ff54c4f249a6..e56c0009db22377bf94882861bf4a5b041069c0b 100644 --- a/test/unittest/cpp_test/src/ime_mirror_demo.cpp +++ b/test/unittest/cpp_test/src/ime_mirror_demo.cpp @@ -26,20 +26,41 @@ public: void OnKeyboardStatus(bool isShow) override { }; void OnInputStart() override { - IMSA_HILOGI("[ImeMirrorLog] OnInputStart"); + inputStartCount_++; + IMSA_HILOGI("[ImeMirrorLog] OnInputStart count, inputStartCount_:%{public}u", inputStartCount_.load()); } int32_t OnInputStop() override { - IMSA_HILOGI("[ImeMirrorLog] OnInputStop"); + inputStopCount_++; + IMSA_HILOGI("[ImeMirrorLog] OnInputStop, inputStopCount_:%{public}u", inputStopCount_.load()); return 0; } void OnInputFinish() override { - IMSA_HILOGI("[ImeMirrorLog] OnInputFinish"); - } + inputFinishCount_++; + IMSA_HILOGI("[ImeMirrorLog] OnInputFinish inputFinishCount_:%{public}u", inputFinishCount_.load()); + } void OnSetCallingWindow(uint32_t windowId) override { } void OnSetSubtype(const SubProperty &property) override { } void ReceivePrivateCommand(const std::unordered_map &privateCommand) override { } + void PrintCount() + { + IMSA_HILOGI( + "[ImeMirrorLog] inputStartCount_:%{public}u, inputFinishCount_:%{public}u, inputStopCount_:%{public}u", + inputStartCount_.load(), inputFinishCount_.load(), inputStopCount_.load()); + }; + + void ResetCount() + { + inputStartCount_ = 0; + inputFinishCount_ = 0; + inputStopCount_ = 0; + } + +private: + std::atomic inputStartCount_ = 0; + std::atomic inputFinishCount_ = 0; + std::atomic inputStopCount_ = 0; }; class KeyboardListenerImpl : public KeyboardListener { public: @@ -61,18 +82,24 @@ public: } void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) override { - IMSA_HILOGI("[ImeMirrorLog] OnCursorUpdate positionX:%{public}d,positionY:%{public}d,height:%{public}d", - positionX, positionY, height); - } + cursorUpdateCount_++; + IMSA_HILOGI("[ImeMirrorLog] OnCursorUpdate positionX:%{public}d,positionY:%{public}d,height:%{public}d, " + "cursorUpdateCount_:%{public}u", + positionX, positionY, height, cursorUpdateCount_.load()); + } void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) override { + selectionChangeCount_++; IMSA_HILOGI("[ImeMirrorLog] OnSelectionChange " - "oldBegin:%{public}d,oldEnd:%{public}d,newBegin:%{public}d,newEnd:%{public}d", - oldBegin, oldEnd, newBegin, newEnd); + "oldBegin:%{public}d,oldEnd:%{public}d,newBegin:%{public}d,newEnd:%{public}d, " + "selectionChangeCount_:%{public}u", + oldBegin, oldEnd, newBegin, newEnd, selectionChangeCount_.load()); } void OnTextChange(const std::string &text) override { - IMSA_HILOGI("[ImeMirrorLog] OnTextChange text:%{public}s", text.c_str()); + textChangeCount_++; + IMSA_HILOGI("[ImeMirrorLog] OnTextChange text:%{public}s, textChangeCount_:%{public}u", text.c_str(), + textChangeCount_.load()); } void OnEditorAttributeChange(const InputAttribute &inputAttribute) override { @@ -82,8 +109,40 @@ public: void OnFunctionKey(int32_t funcKey) override { - IMSA_HILOGI("[ImeMirrorLog] OnFunctionKey funcKey:%{public}d", funcKey); + if (funcKey < 0 || funcKey > static_cast(EnterKeyType::NEW_LINE)) { + IMSA_HILOGE("[ImeMirrorLog] invalid funcKey:%{public}d", funcKey); + return; + } + functionKeyCount_[funcKey]++; + IMSA_HILOGI("[ImeMirrorLog] OnFunctionKey funcKey:%{public}d, functionKeyCount_:%{public}u", funcKey, + functionKeyCount_[funcKey].load()); } + + void PrintCount() + { + IMSA_HILOGI("[ImeMirrorLog] selectionChangeCount_:%{public}u, textChangeCount_:%{public}u, " + "cursorUpdateCount_:%{public}u", + selectionChangeCount_.load(), textChangeCount_.load(), cursorUpdateCount_.load()); + for (size_t index = 0; index <= static_cast(EnterKeyType::NEW_LINE); index++) { + IMSA_HILOGI("[ImeMirrorLog] funcKey:%{public}zu, count:%{public}u", index, functionKeyCount_[index].load()); + } + } + + void ResetCount() + { + selectionChangeCount_ = 0; + textChangeCount_ = 0; + cursorUpdateCount_ = 0; + for (size_t index = 0; index <= static_cast(EnterKeyType::NEW_LINE); index++) { + functionKeyCount_[index] = 0; + } + } + +private: + std::atomic selectionChangeCount_ = 0; + std::atomic textChangeCount_ = 0; + std::atomic functionKeyCount_[static_cast(EnterKeyType::NEW_LINE) + 1] = { 0 }; + std::atomic cursorUpdateCount_ = 0; }; int32_t GetAgentUid() @@ -101,12 +160,13 @@ int32_t GetAgentUid() } return *systemConfig.proxyImeUidList.begin(); } + int main() { - std::shared_ptr imeListener = make_shared(); + std::shared_ptr imeListener = make_shared(); auto instance = InputMethodAbilityInterface::GetInstance(); instance.SetImeListener(imeListener); - std::shared_ptr kdListener = make_shared(); + std::shared_ptr kdListener = make_shared(); instance.SetKdListener(kdListener); char input = '0'; int32_t ret = 0; @@ -131,6 +191,15 @@ int main() ret = instance.InsertText("ime mirror demo"); IMSA_HILOGI("[ImeMirrorLog] InsertText finish ret = %{public}d", ret); break; + case 'c': + imeListener->PrintCount(); + kdListener->PrintCount(); + break; + case 'r': + imeListener->ResetCount(); + kdListener->ResetCount(); + IMSA_HILOGI("[ImeMirrorLog] retset count success"); + break; default: IMSA_HILOGE("[ImeMirrorLog] input error"); } diff --git a/test/unittest/cpp_test/src/ime_mirror_test.cpp b/test/unittest/cpp_test/src/ime_mirror_test.cpp index 57b5074d9685dc27c672656d783c128db83aaec2..cf728bbeac318ad1642b19cc91a9ca74b899cd44 100644 --- a/test/unittest/cpp_test/src/ime_mirror_test.cpp +++ b/test/unittest/cpp_test/src/ime_mirror_test.cpp @@ -27,6 +27,8 @@ #include "scope_utils.h" #include "sys_cfg_parser.h" #include "text_listener.h" +#include "ime_setting_listener_test_impl.h" +#include "ime_event_monitor_manager_impl.h" using namespace testing::ext; using namespace testing::mt; @@ -44,6 +46,24 @@ public: TddUtil::StorageSelfTokenID(); TddUtil::InitWindow(true); imc_ = InputMethodController::GetInstance(); + + TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, "ImeProxyTest")); + auto listener = std::make_shared(); + ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener( + EVENT_IME_HIDE_MASK | EVENT_IME_SHOW_MASK | EVENT_IME_CHANGE_MASK, listener); + + ImeSettingListenerTestImpl::ResetParam(); + TddUtil::SetTestTokenID( + TddUtil::AllocTestTokenID(true, "ImeProxyTest", { "ohos.permission.CONNECT_IME_ABILITY" })); + TddUtil::EnabledAllIme(); + SubProperty subProp; + subProp.name = "com.example.testIme"; + subProp.id = "InputMethodExtAbility"; + auto ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, subProp.name, subProp.id); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(ImeSettingListenerTestImpl::WaitImeChange(subProp)); + TddUtil::RestoreSelfTokenID(); + // native sa permission TddUtil::GrantNativePermission(); SystemConfig systemConfig; @@ -83,12 +103,12 @@ public: TaskManager::GetInstance().Reset(); } - static int32_t Attach() + static int32_t Attach(bool isShowKeyboard = true) { TextConfig config; config.cursorInfo = { .left = 0, .top = 1, .width = 0.5, .height = 1.2 }; sptr testListener = new TextListener(); - auto ret = imc_->Attach(testListener, true, config); + auto ret = imc_->Attach(testListener, isShowKeyboard, config); return ret; } static void Close() @@ -162,7 +182,7 @@ HWTEST_F(ImeMirrorTest, BindImeMirrorAndVerifyTextSelectionConfig_success, TestS EXPECT_EQ(ret, ErrorCode::NO_ERROR); InputAttribute attr; attr.enterKeyType = static_cast(EnterKeyType::GO); - EXPECT_TRUE(KeyboardListenerTestImpl::WaitEditorAttributeChange(attr)); + EXPECT_FALSE(KeyboardListenerTestImpl::WaitEditorAttributeChange(attr)); ret = ImeMirrorTest::imc_->SendFunctionKey(static_cast(EnterKeyType::NEW_LINE)); EXPECT_EQ(ret, ErrorCode::NO_ERROR); @@ -193,6 +213,10 @@ HWTEST_F(ImeMirrorTest, BindImeMirrorAndVerifyPasswordTextHandling_fail, TestSiz EXPECT_EQ(ret, ErrorCode::NO_ERROR); // Secure text should not be received by proxy EXPECT_FALSE(KeyboardListenerTestImpl::WaitTextChange("secure123")); + + ret = ImeMirrorTest::imc_->SendFunctionKey(static_cast(EnterKeyType::NEW_LINE)); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(KeyboardListenerTestImpl::WaitFunctionKey(static_cast(EnterKeyType::NEW_LINE))); } CloseAndUnregisterProxy(); @@ -271,8 +295,9 @@ HWTEST_F(ImeMirrorTest, UnregisterProxyDuringTextInput_success, TestSize.Level1) EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_FALSE(KeyboardListenerTestImpl::WaitTextChange("after unregister")); + InputMethodEngineListenerImpl::ResetParam(); Close(); - EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish()); + EXPECT_FALSE(InputMethodEngineListenerImpl::WaitInputFinish()); } /** @@ -337,6 +362,34 @@ HWTEST_F(ImeMirrorTest, RegisterAfterAttach_success, TestSize.Level1) Close(); } +/** + * @tc.name: BindImeMirror_WillNotChangeClientAndImeBinding + * @tc.desc: BindImeMirror should not change client and ime binding relationship + * @tc.type: FUNC + */ +HWTEST_F(ImeMirrorTest, BindImeMirror_WillNotChangeClientAndImeBinding, TestSize.Level1) +{ + IMSA_HILOGI("ImeMirrorTest::BindImeMirror_WillNotChangeClientAndImeBinding start"); + + // Step 1: Perform Attach first without bind + auto ret = Attach(false); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(InputMethodEngineListenerImpl::WaitInputStart()); + + // Step 2: bind ime mirror after Attach + { + UidScope uidScope(agentUid_); + ret = InputMethodAbilityInterface::GetInstance().BindImeMirror(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart()); + } + + ret = imc_->ShowTextInput(); + EXPECT_FALSE(InputMethodEngineListenerImpl::WaitKeyboardStatus(true)); + + CloseAndUnregisterProxy(); +} + /** * @tc.name: multiThreadAttachRegisterTest_001 * @tc.desc: test ime Attach and Register ime mirror ime in multi-thread diff --git a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp index 4a914cee2d1ebece54fa9163a80a6f81af9decb6..a97156348b55b0a62524e36ad7740218e9f7d735 100644 --- a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp +++ b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp @@ -18,11 +18,16 @@ #include "global.h" #include "native_inputmethod_types.h" +#include "mock_input_method_system_ability_proxy.h" +#include "input_method_controller.h" using namespace testing::ext; using namespace OHOS; +using namespace OHOS::MiscServices; +using namespace testing; class InputMethodControllerCapiTest : public testing::Test { }; namespace { +constexpr size_t MAX_SYS_PRIVATE_COMMAND_COUNT = 6; /** * @tc.name: TestCursorInfo_001 * @tc.desc: create and destroy TestCursorInfo success @@ -1452,6 +1457,42 @@ HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_SendPrivateCommand_0 EXPECT_EQ(ret, IME_ERR_NULL_POINTER); } +/** + * @tc.name: SendPrivateCommandWithInvalidCommandCount + * @tc.desc: input parameters is invalid + * @tc.type: FUNC + */ +HWTEST_F(InputMethodControllerCapiTest, SendPrivateCommandWithInvalidCommand, TestSize.Level0) +{ + auto textEditorProxy = OH_TextEditorProxy_Create(); + EXPECT_NE(nullptr, textEditorProxy); + ConstructTextEditorProxy(textEditorProxy); + + auto options = OH_AttachOptions_Create(true); + EXPECT_NE(nullptr, options); + InputMethod_InputMethodProxy *inputMethodProxy = nullptr; + + sptr ability = new (std::nothrow) MockInputMethodSystemAbilityProxy(); + InputMethodController::GetInstance()->SetImsaProxyForTest(ability); + ON_CALL(*ability, StartInput(_, _, _)).WillByDefault(Return(ErrorCode::NO_ERROR)); + ON_CALL(*ability, ReleaseInput(_, _)).WillByDefault(Return(ErrorCode::NO_ERROR)); + EXPECT_EQ(IME_ERR_OK, OH_InputMethodController_Attach(textEditorProxy, options, &inputMethodProxy)); + + InputMethod_PrivateCommand *privateCommand[MAX_SYS_PRIVATE_COMMAND_COUNT + 1] = { nullptr }; + auto ret = + OH_InputMethodProxy_SendPrivateCommand(inputMethodProxy, privateCommand, MAX_SYS_PRIVATE_COMMAND_COUNT + 1); + EXPECT_EQ(ret, IME_ERR_PARAMCHECK); + + size_t size = 1; + ret = OH_InputMethodProxy_SendPrivateCommand(inputMethodProxy, privateCommand, size); + EXPECT_EQ(ret, IME_ERR_NULL_POINTER); + + EXPECT_EQ(IME_ERR_OK, OH_InputMethodController_Detach(inputMethodProxy)); + InputMethodController::GetInstance()->SetImsaProxyForTest(nullptr); + + OH_AttachOptions_Destroy(options); + OH_TextEditorProxy_Destroy(textEditorProxy); +} /** * @tc.name: TestAttachWithNullParam_001 * @tc.desc: input parameters is nullptr diff --git a/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp b/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp index 99bc205a6bbfd200c4a6246a2508b5c8beeec377..f4dfe801e7463611bce2a3a10211e836835a4756 100644 --- a/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp +++ b/test/unittest/cpp_test/src/text_listener_inner_api_test.cpp @@ -17,8 +17,6 @@ #define protected public #include "input_method_controller.h" #undef private - -#include #include #include #include diff --git a/test/unittest/cpp_test/src/virtual_listener_test.cpp b/test/unittest/cpp_test/src/virtual_listener_test.cpp index 380506b0b7a63f51b456f87b6cc51006d2fb4ffe..17f661da510678c86db246c78bf936d67170c621 100644 --- a/test/unittest/cpp_test/src/virtual_listener_test.cpp +++ b/test/unittest/cpp_test/src/virtual_listener_test.cpp @@ -16,7 +16,6 @@ #define protected public #include "input_method_controller.h" #undef private -#include #include #include #include diff --git a/test/unittest/resource/ohos_test/ohos_test.xml b/test/unittest/resource/ohos_test/ohos_test.xml index 92a36907fcb5605446cc01d32757b975dbdcd883..66d8a7e4b7a3a81f00e0eaee4e92d9ba6c4957af 100644 --- a/test/unittest/resource/ohos_test/ohos_test.xml +++ b/test/unittest/resource/ohos_test/ohos_test.xml @@ -190,8 +190,11 @@