From bed4ec02e59c8a46bd9f000136083253825a4686 Mon Sep 17 00:00:00 2001 From: hemenghao Date: Sat, 23 Aug 2025 14:33:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=84=E8=93=9D=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hemenghao --- frameworks/cj/src/utils.cpp | 1 - .../js_input_method_engine_setting.cpp | 4 +- .../js_keyboard_delegate_setting.cpp | 4 +- .../js/napi/inputmethodability/js_panel.cpp | 2 +- .../js_text_input_client_engine.cpp | 4 +- .../js/napi/inputmethodclient/async_call.cpp | 2 +- .../js_get_input_method_controller.cpp | 21 +- .../js_get_input_method_setting.cpp | 4 +- .../js/napi/inputmethodclient/js_utils.cpp | 2 +- .../source/inputmethodlist.ets | 2 +- .../js_keyboard_panel_manager.cpp | 2 +- .../include/input_method_ability.h | 2 +- .../src/input_method_ability.cpp | 6 +- .../src/input_method_panel.cpp | 23 +- .../include/input_method_utils.h | 19 +- .../src/ime_system_channel.cpp | 12 +- .../src/input_data_channel_service_impl.cpp | 12 +- .../src/input_method_utils.cpp | 3 +- .../include/ime_system_channel.h | 9 +- .../include/input_method_controller.h | 4 +- .../kits/c/inputmethod_attach_options_capi.h | 6 +- .../c/inputmethod_inputmethod_proxy_capi.h | 4 +- interfaces/kits/c/inputmethod_types_capi.h | 2 +- services/BUILD.gn | 2 +- .../common/src/settings_data_utils.cpp | 10 +- .../src/enable_upgrade_manager.cpp | 11 +- .../src/ime_enabled_info_manager.cpp | 17 +- .../src/numkey_apps_manager.cpp | 7 +- .../window_adapter/src/window_adapter.cpp | 8 +- .../src/wms_connection_observer.cpp | 3 +- .../resources/base/element/string.json | 2 +- services/file/src/file_operator.cpp | 8 +- .../include/identity_checker_impl.h | 2 +- services/include/ime_cfg_manager.h | 3 +- services/include/notify_service_impl.h | 10 +- services/json/src/serializable.cpp | 10 +- services/src/client_group.cpp | 49 ++-- services/src/freeze_manager.cpp | 3 +- services/src/full_ime_info_manager.cpp | 4 +- services/src/im_common_event_manager.cpp | 2 + services/src/ime_info_inquirer.cpp | 21 +- services/src/input_method_system_ability.cpp | 107 ++++---- services/src/notify_service_impl.cpp | 6 +- services/src/peruser_session.cpp | 2 +- .../src/ime_setting_listener_test_impl.cpp | 24 +- .../src/input_method_engine_listener_impl.cpp | 6 +- .../commonevent_fuzzer/commonevent_fuzzer.cpp | 13 +- .../controlchannelstub_fuzzer/BUILD.gn | 2 + .../enableupgrademanager_fuzzer.cpp | 1 - .../imeeventmonitormanager_fuzzer/BUILD.gn | 2 + .../inputmethodcontroller_fuzzer.cpp | 128 +++------ .../inputmethodsystemability_fuzzer.cpp | 5 +- .../systemcmdchannelstub_fuzzer.cpp | 15 +- test/unittest/BUILD.gn | 1 - test/unittest/cpp_test/BUILD.gn | 253 +++++++----------- .../common/include/identity_checker_mock.h | 8 +- .../cpp_test/src/identity_checker_test.cpp | 1 - .../cpp_test/src/ima_text_edit_test.cpp | 2 +- .../src/input_method_ability_test.cpp | 58 ++-- .../src/input_method_controller_test.cpp | 66 ++++- .../src/input_method_manager_command_test.cpp | 17 +- .../cpp_test/src/input_method_panel_test.cpp | 13 +- .../src/input_method_private_member_test.cpp | 196 +++++++------- .../cpp_test/src/input_method_switch_test.cpp | 5 +- .../cpp_test/src/newIme_switch_test.cpp | 54 ++++ .../unittest/resource/ohos_test/ohos_test.xml | 8 + .../ime/src/input_method_manager_command.cpp | 7 +- 67 files changed, 618 insertions(+), 704 deletions(-) diff --git a/frameworks/cj/src/utils.cpp b/frameworks/cj/src/utils.cpp index 76dd91e43..746fa73bc 100644 --- a/frameworks/cj/src/utils.cpp +++ b/frameworks/cj/src/utils.cpp @@ -83,7 +83,6 @@ const std::map Utils::ERROR_CODE_MAP = { { ErrorCode::ERROR_IME_NOT_FOUND, EXCEPTION_IME_NOT_FOUND }, { ErrorCode::ERROR_OPERATE_SYSTEM_IME, EXCEPTION_OPERATE_DEFAULTIME }, { ErrorCode::ERROR_SWITCH_IME, EXCEPTION_IMMS }, - { ErrorCode::ERROR_IMA_DATA_CHANNEL_ABNORMAL, EXCEPTION_IMCLIENT }, { ErrorCode::ERROR_IMA_INVALID_IMMERSIVE_EFFECT, EXCEPTION_INVALID_IMMERSIVE_EFFECT }, { ErrorCode::ERROR_IMA_PRECONDITION_REQUIRED, EXCEPTION_PRECONDITION_REQUIRED }, }; 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 bf7ff947d..a3d3d3f37 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -595,12 +595,12 @@ napi_value JsInputMethodEngineSetting::UnSubscribe(napi_env env, napi_callback_i JsUtils::ThrowException(env, JsUtils::Convert(ErrorCode::ERROR_NOT_DEFAULT_IME), "default ime check failed", TYPE_NONE); } - // if the second param is not napi_function/napi_null/napi_undefined, return. + // if the second param is not napi_function/napi_null/napi_undefined, return auto paramType = JsUtil::GetType(env, argv[1]); if (paramType != napi_function && paramType != napi_null && paramType != napi_undefined) { return nullptr; } - // if the second param is napi_function, delete it, else delete all. + // if the second param is napi_function, delete it, else delete all argv[1] = paramType == napi_function ? argv[1] : nullptr; IMSA_HILOGD("unsubscribe type: %{public}s.", type.c_str()); diff --git a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp index c8ee56ef1..d26fb1211 100644 --- a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp @@ -260,12 +260,12 @@ napi_value JsKeyboardDelegateSetting::UnSubscribe(napi_env env, napi_callback_in return nullptr; } - // if the second param is not napi_function/napi_null/napi_undefined, return. + // if the second param is not napi_function/napi_null/napi_undefined, return auto paramType = JsUtil::GetType(env, argv[1]); if (paramType != napi_function && paramType != napi_null && paramType != napi_undefined) { return nullptr; } - // if the second param is napi_function, delete it, else delete all. + // if the second param is napi_function, delete it, else delete all argv[1] = paramType == napi_function ? argv[1] : nullptr; IMSA_HILOGD("unsubscribe type: %{public}s.", type.c_str()); diff --git a/frameworks/js/napi/inputmethodability/js_panel.cpp b/frameworks/js/napi/inputmethodability/js_panel.cpp index bbd07a3ed..e3bd1a4b2 100644 --- a/frameworks/js/napi/inputmethodability/js_panel.cpp +++ b/frameworks/js/napi/inputmethodability/js_panel.cpp @@ -496,7 +496,7 @@ napi_value JsPanel::UnSubscribe(napi_env env, napi_callback_info info) PARAM_CHECK_RETURN(env, JsUtil::GetValue(env, argv[0], type), "type must be string!", TYPE_NONE, nullptr); PARAM_CHECK_RETURN(env, EventChecker::IsValidEventType(EventSubscribeModule::PANEL, type), "type should be show/hide/sizeChange!", TYPE_NONE, nullptr); - // if the second param is not napi_function/napi_null/napi_undefined, return. + // if the second param is not napi_function/napi_null/napi_undefined, return auto paramType = JsUtil::GetType(env, argv[1]); PARAM_CHECK_RETURN(env, (paramType == napi_function || paramType == napi_null || paramType == napi_undefined), "callback should be function or null or undefined!", TYPE_NONE, nullptr); diff --git a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp index 0bac05f5a..7a5589f70 100644 --- a/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp +++ b/frameworks/js/napi/inputmethodability/js_text_input_client_engine.cpp @@ -1408,12 +1408,12 @@ napi_value JsTextInputClientEngine::UnSubscribe(napi_env env, napi_callback_info IMSA_HILOGE("unsubscribe failed, type: %{public}s!", type.c_str()); return nullptr; } - // if the second param is not napi_function/napi_null/napi_undefined, return. + // if the second param is not napi_function/napi_null/napi_undefined, return auto paramType = JsUtil::GetType(env, argv[1]); if (paramType != napi_function && paramType != napi_null && paramType != napi_undefined) { return nullptr; } - // if the second param is napi_function, delete it, else delete all. + // if the second param is napi_function, delete it, else delete all argv[1] = paramType == napi_function ? argv[1] : nullptr; IMSA_HILOGD("unsubscribe type: %{public}s.", type.c_str()); diff --git a/frameworks/js/napi/inputmethodclient/async_call.cpp b/frameworks/js/napi/inputmethodclient/async_call.cpp index a29ad8b41..3101028c0 100644 --- a/frameworks/js/napi/inputmethodclient/async_call.cpp +++ b/frameworks/js/napi/inputmethodclient/async_call.cpp @@ -27,7 +27,7 @@ constexpr size_t ARGC_MAX = 6; constexpr int32_t MAX_WAIT_TIME = 500; // ms static inline uint64_t GetTimeStamp() { - return duration_cast(system_clock::now().time_since_epoch()).count(); + return duration_cast(steady_clock::now().time_since_epoch()).count(); } AsyncCall::AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr context, size_t maxParamCount) : env_(env) 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 ef4b77dba..11f0dbdda 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp @@ -472,12 +472,12 @@ napi_value JsGetInputMethodController::UnSubscribe(napi_env env, napi_callback_i return nullptr; } - // if the second param is not napi_function/napi_null/napi_undefined, return. + // if the second param is not napi_function/napi_null/napi_undefined, return auto paramType = JsUtil::GetType(env, argv[1]); if (paramType != napi_function && paramType != napi_null && paramType != napi_undefined) { return nullptr; } - // if the second param is napi_function, delete it, else delete all. + // if the second param is napi_function, delete it, else delete all argv[1] = paramType == napi_function ? argv[1] : nullptr; IMSA_HILOGD("unsubscribe type: %{public}s.", type.c_str()); @@ -645,11 +645,7 @@ napi_value JsGetInputMethodController::Attach(napi_env env, napi_callback_info i } // requestKeyboardReason not must if (argc > 2) { - napi_valuetype valueType = napi_undefined; - napi_typeof(env, argv[2], &valueType); - if (valueType != napi_function) { - JsUtil::GetValue(env, argv[2], ctxt->requestKeyboardReason); - } + JsUtil::GetValue(env, argv[2], ctxt->requestKeyboardReason); } ctxt->info = { std::chrono::system_clock::now(), ctxt->attribute}; attachQueue_.Push(ctxt->info); @@ -723,15 +719,10 @@ napi_value JsGetInputMethodController::GetAttachOptionsValue( NAPI_CALL(env, napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, &data)); int32_t requestKeyboardReason = 0; if (argc > 0) { - napi_valuetype valueType = napi_undefined; - napi_typeof(env, argv[0], &valueType); - if (valueType != napi_function) { - JsUtil::GetValue(env, argv[0], requestKeyboardReason); - } + JsUtil::GetValue(env, argv[0], requestKeyboardReason); } IMSA_HILOGI("run in. requestKeyboardReason=%{public}d", requestKeyboardReason); attachOptions.requestKeyboardReason = static_cast(requestKeyboardReason); - return result; } @@ -755,8 +746,8 @@ napi_value JsGetInputMethodController::DiscardTypingText(napi_env env, napi_call { InputMethodSyncTrace tracer("JsGetInputMethodController_DiscardTypingText"); return HandleSoftKeyboard( - env, info - , [] { + env, info, + [] { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { IMSA_HILOGE("GetInstance return nullptr!"); 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 b18d45275..f3bca6c04 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp @@ -673,12 +673,12 @@ napi_value JsGetInputMethodSetting::UnSubscribe(napi_env env, napi_callback_info return nullptr; } - // if the second param is not napi_function/napi_null/napi_undefined, return. + // if the second param is not napi_function/napi_null/napi_undefined, return auto paramType = JsUtil::GetType(env, argv[1]); if (paramType != napi_function && paramType != napi_null && paramType != napi_undefined) { return nullptr; } - // if the second param is napi_function, delete it, else delete all. + // if the second param is napi_function, delete it, else delete all argv[1] = paramType == napi_function ? argv[1] : nullptr; IMSA_HILOGD("unsubscribe type: %{public}s.", type.c_str()); diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index 08c72d745..eb1c266ef 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -533,7 +533,7 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, std::vector return status; } if (data == nullptr && length == 0) { - IMSA_HILOGE("Empty ArrayBuffer!"); + IMSA_HILOGI("Empty ArrayBuffer!"); out.clear(); return napi_ok; } diff --git a/frameworks/js/napi/inputmethodlist/source/inputmethodlist.ets b/frameworks/js/napi/inputmethodlist/source/inputmethodlist.ets index ebb95b762..1e0e0fdfe 100644 --- a/frameworks/js/napi/inputmethodlist/source/inputmethodlist.ets +++ b/frameworks/js/napi/inputmethodlist/source/inputmethodlist.ets @@ -143,7 +143,7 @@ export struct InputMethodListDialog { let context = getContext(this) as common.UIAbilityContext; try { let activeSubTypeStr = await settings.getValue(context, settings.input.ACTIVATED_INPUT_METHOD_SUB_MODE); - let activeSubType: Array = JSON.parse(activeSubTypeStr); + let activeSubType: SubType[] = JSON.parse(activeSubTypeStr); if (activeSubType) { console.info(`${TAG} activeSubType: ${JSON.stringify(activeSubType)}`); for (let i = 0; i < this.inputMethods.length; i++) { diff --git a/frameworks/js/napi/keyboardpanelmanager/js_keyboard_panel_manager.cpp b/frameworks/js/napi/keyboardpanelmanager/js_keyboard_panel_manager.cpp index fc786bf16..ae9e63052 100644 --- a/frameworks/js/napi/keyboardpanelmanager/js_keyboard_panel_manager.cpp +++ b/frameworks/js/napi/keyboardpanelmanager/js_keyboard_panel_manager.cpp @@ -150,7 +150,7 @@ napi_value JsKeyboardPanelManager::UnSubscribe(napi_env env, napi_callback_info if (paramType != napi_function && paramType != napi_null && paramType != napi_undefined) { return nullptr; } - // if the second param is napi_function, delete it, else delete all. + // if the second param is napi_function, delete it, else delete all argv[1] = paramType == napi_function ? argv[1] : nullptr; IMSA_HILOGD("unsubscribe type: %{public}s.", type.c_str()); diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index 778412302..754919b20 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -246,7 +246,7 @@ private: std::mutex bindClientInfoLock_; HiSysEventClientInfo bindClientInfo_; - bool isNotify_ = false; + bool isInputStartNotified_ = false; ImeMirrorManager imeMirrorMgr_; bool IsDisplayChanged(uint64_t oldDisplayId, uint64_t newDisplayId); diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 7a942331f..127c3fca9 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -653,9 +653,9 @@ int32_t InputMethodAbility::InvokeStartInputCallback(const TextTotalConfig &text AttachOptions options; options.requestKeyboardReason = textConfig.requestKeyboardReason; options.isSimpleKeyboardEnabled = textConfig.isSimpleKeyboardEnabled; - InvokeAttachOptionsCallback(options, isNotifyInputStart || !isNotify_); - if (isNotifyInputStart || !isNotify_) { - isNotify_ = true; + InvokeAttachOptionsCallback(options, isNotifyInputStart || !isInputStartNotified_); + if (isNotifyInputStart || !isInputStartNotified_) { + isInputStartNotified_ = true; IMSA_HILOGD("OnInputStart begin"); imeListener_->OnInputStart(); } diff --git a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp index 995f7b528..bdbf0c206 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp @@ -71,17 +71,19 @@ int32_t InputMethodPanel::CreatePanel( IMSA_HILOGE("create window failed: %{public}d!", wmError); return ErrorCode::ERROR_OPERATE_PANEL; } - isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled(); if (SetPanelProperties() != ErrorCode::NO_ERROR) { wmError = window_->Destroy(); IMSA_HILOGI("destroy window end, wmError is %{public}d.", wmError); return ErrorCode::ERROR_OPERATE_PANEL; } windowId_ = window_->GetWindowId(); - IMSA_HILOGI("success, type/flag/windowId/isScbEnable_: %{public}d/%{public}d/%{public}u/%{public}d.", - static_cast(panelType_), static_cast(panelFlag_), windowId_, isScbEnable_); - if (panelInfo.panelType == SOFT_KEYBOARD && isScbEnable_) { - RegisterKeyboardPanelInfoChangeListener(); + IMSA_HILOGI("success, type/flag/windowId: %{public}d/%{public}d/%{public}u.", static_cast(panelType_), + static_cast(panelFlag_), windowId_); + if (panelInfo.panelType == SOFT_KEYBOARD) { + isScbEnable_ = Rosen::SceneBoardJudgement::IsSceneBoardEnabled(); + if (isScbEnable_) { + RegisterKeyboardPanelInfoChangeListener(); + } } return ErrorCode::NO_ERROR; } @@ -320,11 +322,9 @@ void InputMethodPanel::RectifyResizeParams(LayoutParams ¶ms, const DisplaySi std::min(static_cast(displaySize.landscape.height) * FIXED_SOFT_KEYBOARD_PANEL_RATIO, static_cast(params.landscapeRect.height_)); params.portraitRect.width_ = - std::min(static_cast(displaySize.portrait.width), - static_cast(params.portraitRect.width_)); + std::min(displaySize.portrait.width, params.portraitRect.width_); params.landscapeRect.width_ = - std::min(static_cast(displaySize.landscape.width), - static_cast(params.landscapeRect.width_)); + std::min(displaySize.landscape.width, params.landscapeRect.width_); } void InputMethodPanel::UpdateRectParams( @@ -403,7 +403,8 @@ int32_t InputMethodPanel::ResizePanel(uint32_t width, uint32_t height) return ErrorCode::ERROR_BAD_PARAMETERS; } auto currentParams = GetEnhancedLayoutParams(); - LayoutParams targetParams = { currentParams.landscape.rect, currentParams.portrait.rect }; + LayoutParams targetParams = { .landscapeRect = currentParams.landscape.rect, + .portraitRect = currentParams.portrait.rect }; auto ret = GetResizeParams(targetParams.portraitRect, targetParams.landscapeRect, width, height); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to GetResizeParams, ret: %{public}d", ret); @@ -1882,7 +1883,7 @@ int32_t InputMethodPanel::SetImmersiveMode(ImmersiveMode mode) return ErrorCode::NO_ERROR; } if (ret != WMError::WM_OK) { - IMSA_HILOGE("ChangeKeyboardViewMode failed, ret: %{public}d", ret); + IMSA_HILOGE("ChangeKeyboardEffectOption failed, ret: %{public}d", ret); return ErrorCode::ERROR_WINDOW_MANAGER; } StoreImmersiveMode(mode); diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index d72fa032c..64ecf6535 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -193,7 +193,6 @@ enum Trigger : int32_t { IMF, END }; - struct PanelStatusInfo { PanelInfo panelInfo; bool visible { false }; @@ -306,6 +305,14 @@ enum PrivateDataValueType : int32_t { VALUE_TYPE_NUMBER }; using PrivateDataValue = std::variant; + +enum class RequestKeyboardReason : int32_t { + NONE = 0, // no event reason + MOUSE = 1, // user triggered mouse event + TOUCH = 2, // user triggered touch event + OTHER = 20 // other reason +}; + using ValueMap = std::unordered_map; struct Value : public Parcelable { @@ -325,14 +332,6 @@ struct KeyEventValue : public Parcelable { std::shared_ptr event; }; - -enum class RequestKeyboardReason : int32_t { - NONE = 0, // no event reason - MOUSE = 1, // user triggered mouse event - TOUCH = 2, // user triggered touch event - OTHER = 20 // other reason -}; - struct TextTotalConfig { public: InputAttribute inputAttribute = {}; @@ -485,7 +484,6 @@ enum class InputType : int32_t { SECURITY_INPUT, VOICE_INPUT, VOICEKB_INPUT, - ONE_TIME_CODE = 13, END }; @@ -516,7 +514,6 @@ struct ArrayBuffer : public Parcelable { { return jsArgc == arrayBuffer.jsArgc && msgId == arrayBuffer.msgId && msgParam == arrayBuffer.msgParam; } - bool ReadFromParcel(Parcel &in); bool Marshalling(Parcel &out) const; static ArrayBuffer *Unmarshalling(Parcel &in); diff --git a/frameworks/native/inputmethod_controller/src/ime_system_channel.cpp b/frameworks/native/inputmethod_controller/src/ime_system_channel.cpp index 40b4b585f..0c7c8ea85 100644 --- a/frameworks/native/inputmethod_controller/src/ime_system_channel.cpp +++ b/frameworks/native/inputmethod_controller/src/ime_system_channel.cpp @@ -78,7 +78,7 @@ sptr ImeSystemCmdChannel::GetSystemAbilityProxy() systemAbility_ = iface_cast(systemAbility); return systemAbility_; } - +// LCOV_EXCL_START void ImeSystemCmdChannel::OnRemoteSaDied(const wptr &remote) { IMSA_HILOGI("input method service death."); @@ -88,7 +88,7 @@ void ImeSystemCmdChannel::OnRemoteSaDied(const wptr &remote) } ClearSystemCmdAgent(); } - +// LCOV_EXCL_STOP int32_t ImeSystemCmdChannel::ConnectSystemCmd(const sptr &listener) { IMSA_HILOGD("start."); @@ -208,7 +208,7 @@ int32_t ImeSystemCmdChannel::ReceivePrivateCommand( cmdlistener->ReceivePrivateCommand(privateCommand); return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_START int32_t ImeSystemCmdChannel::SendPrivateCommand(const std::unordered_map &privateCommand) { IMSA_HILOGD("start."); @@ -227,7 +227,7 @@ int32_t ImeSystemCmdChannel::SendPrivateCommand(const std::unordered_map extensionInfos, ExtensionAbilityInfo &extInfo) { @@ -276,7 +276,7 @@ void ImeSystemCmdChannel::GetExtensionInfo( } } } - +// LCOV_EXCL_STOP int32_t ImeSystemCmdChannel::GetDefaultImeCfg(std::shared_ptr &property) { IMSA_HILOGD("InputMethodAbility::GetDefaultImeCfg start."); diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp index 3fe14bf35..a7d50f49d 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp @@ -28,7 +28,7 @@ namespace MiscServices { InputDataChannelServiceImpl::InputDataChannelServiceImpl() {} InputDataChannelServiceImpl::~InputDataChannelServiceImpl() {} - +// LCOV_EXCL_START ErrCode InputDataChannelServiceImpl::InsertText( const std::string &text, uint64_t msgId, const sptr &agent) { @@ -114,7 +114,7 @@ ErrCode InputDataChannelServiceImpl::GetTextIndexAtCursor(uint64_t msgId, const instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } - +// LCOV_EXCL_STOP ErrCode InputDataChannelServiceImpl::GetEnterKeyType(int32_t &keyType) { auto instance = InputMethodController::GetInstance(); @@ -159,7 +159,7 @@ ErrCode InputDataChannelServiceImpl::SendKeyboardStatus(int32_t status) } return ERR_OK; } - +// LCOV_EXCL_START ErrCode InputDataChannelServiceImpl::SendFunctionKey(int32_t funcKey, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); @@ -228,7 +228,7 @@ ErrCode InputDataChannelServiceImpl::HandleExtendAction( instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } - +// LCOV_EXCL_STOP ErrCode InputDataChannelServiceImpl::NotifyPanelStatusInfo(const PanelStatusInfoInner &info) { PanelStatusInfo panelStatusInfo = InputMethodTools::GetInstance().InnerToPanelStatusInfo(info); @@ -263,7 +263,7 @@ ErrCode InputDataChannelServiceImpl::SendPrivateCommand(const Value &value) } return instance->ReceivePrivateCommand(privateCommand); } - +// LCOV_EXCL_START ErrCode InputDataChannelServiceImpl::SetPreviewText( const std::string &text, const RangeInner &rangeInner, uint64_t msgId, const sptr &agent) { @@ -291,7 +291,7 @@ ErrCode InputDataChannelServiceImpl::FinishTextPreview(uint64_t msgId, const spt instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } - +// LCOV_EXCL_STOP ErrCode InputDataChannelServiceImpl::SendMessage(const ArrayBuffer &arraybuffer) { auto instance = InputMethodController::GetInstance(); diff --git a/frameworks/native/inputmethod_controller/src/input_method_utils.cpp b/frameworks/native/inputmethod_controller/src/input_method_utils.cpp index b982d9bc6..080a217fc 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_utils.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_utils.cpp @@ -107,7 +107,8 @@ bool TextTotalConfigInner::ReadFromParcel(Parcel &in) return false; } commandValue = *commandValueInfo; - requestKeyboardReason = static_cast(in.ReadInt32()); + int32_t requestKeyboardReasonData = in.ReadInt32(); + requestKeyboardReason = static_cast(requestKeyboardReasonData); abilityToken = (static_cast(&in))->ReadRemoteObject(); isSimpleKeyboardEnabled = in.ReadBool(); return true; diff --git a/interfaces/inner_api/inputmethod_controller/include/ime_system_channel.h b/interfaces/inner_api/inputmethod_controller/include/ime_system_channel.h index db38c7d8f..b649aa91a 100644 --- a/interfaces/inner_api/inputmethod_controller/include/ime_system_channel.h +++ b/interfaces/inner_api/inputmethod_controller/include/ime_system_channel.h @@ -77,15 +77,16 @@ public: const std::unordered_map &privateCommand) override; /** - * @brief Get smart menu config from default input method. - * - * This function is used to get smart menu config from default input method. + * @brief Get smart menue config from default input method. * + * This function is used to get smart menue config from default input method. + *. * @return string. * @since 12 */ IMF_API std::string GetSmartMenuCfg(); - int32_t ReceivePrivateCommand(const std::unordered_map &privateCommand) override; + int32_t ReceivePrivateCommand( + const std::unordered_map &privateCommand) override; int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus); void OnConnectCmdReady(const sptr &agentObject); IMF_API int32_t GetDefaultImeCfg(std::shared_ptr &property); 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 012b94f60..1ea657d0d 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -233,7 +233,7 @@ public: * text selection,windowId. * @param type Indicates the type of caller. * @return Returns 0 for success, others for failure. - * @since 15 + * @since 16 */ IMF_API int32_t Attach(sptr listener, const AttachOptions &attachOptions, const TextConfig &textConfig, ClientType type = ClientType::INNER_KIT); @@ -254,7 +254,7 @@ public: * * @param attachOptions Indicates the attachOptions, such as requestKeyboardReason * @return Returns 0 for success, others for failure. - * @since 15 + * @since 16 */ IMF_API int32_t ShowTextInput(const AttachOptions &attachOptions, ClientType type = ClientType::INNER_KIT); /** diff --git a/interfaces/kits/c/inputmethod_attach_options_capi.h b/interfaces/kits/c/inputmethod_attach_options_capi.h index 268e3cb02..19dc30fdd 100644 --- a/interfaces/kits/c/inputmethod_attach_options_capi.h +++ b/interfaces/kits/c/inputmethod_attach_options_capi.h @@ -63,7 +63,7 @@ InputMethod_AttachOptions *OH_AttachOptions_Create(bool showKeyboard); * @param requestKeyboardReason the reason for showKeyboard. * @return If the creation succeeds, a pointer to the newly created {@link InputMethod_AttachOptions} * instance is returned. If the creation fails, NULL is returned, possible cause is insufficient memory. - * @since 15 + * @since 16 */ InputMethod_AttachOptions *OH_AttachOptions_CreateWithRequestKeyboardReason( bool showKeyboard, InputMethod_RequestKeyboardReason requestKeyboardReason); @@ -96,9 +96,9 @@ InputMethod_ErrorCode OH_AttachOptions_IsShowKeyboard(InputMethod_AttachOptions * be get value from * @return Returns a specific error code. * {@link IME_ERR_OK} - success. - * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. If options is NULL, or requestKeyboardReason is NULL. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. * Specific error codes can be referenced {@link InputMethod_ErrorCode}. - * @since 15 + * @since 16 */ InputMethod_ErrorCode OH_AttachOptions_GetRequestKeyboardReason( InputMethod_AttachOptions *options, int *requestKeyboardReason); diff --git a/interfaces/kits/c/inputmethod_inputmethod_proxy_capi.h b/interfaces/kits/c/inputmethod_inputmethod_proxy_capi.h index 61e3e4a91..f608dd9d3 100644 --- a/interfaces/kits/c/inputmethod_inputmethod_proxy_capi.h +++ b/interfaces/kits/c/inputmethod_inputmethod_proxy_capi.h @@ -79,9 +79,9 @@ InputMethod_ErrorCode OH_InputMethodProxy_ShowKeyboard(InputMethod_InputMethodPr * {@link IME_ERR_IMCLIENT} - input method client error. * {@link IME_ERR_IMMS} - input method manager service error. * {@link IME_ERR_DETACHED} - input method client detached. - * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. If inputMethodProxy is NULL, or options is NULL. + * {@link IME_ERR_NULL_POINTER} - unexpected null pointer. * Specific error codes can be referenced {@link InputMethod_ErrorCode}. - * @since 15 + * @since 16 */ InputMethod_ErrorCode OH_InputMethodProxy_ShowTextInput( InputMethod_InputMethodProxy *inputMethodProxy, InputMethod_AttachOptions *options); diff --git a/interfaces/kits/c/inputmethod_types_capi.h b/interfaces/kits/c/inputmethod_types_capi.h index 0a8a4e3b5..1cd39e05a 100644 --- a/interfaces/kits/c/inputmethod_types_capi.h +++ b/interfaces/kits/c/inputmethod_types_capi.h @@ -321,7 +321,7 @@ typedef enum InputMethod_ErrorCode { /** * @brief The value type of request keyboard. * - * @since 15 + * @since 16 */ typedef enum InputMethod_RequestKeyboardReason { /** diff --git a/services/BUILD.gn b/services/BUILD.gn index 7561e6210..d206c42f4 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -247,8 +247,8 @@ ohos_static_library("inputmethod_service_static") { "resource_schedule_service:ressched_client", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libdm_lite", "window_manager:libwsutils", + "window_manager:libdm_lite", ] defines = [] diff --git a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp index ee0d181d2..23518a17e 100644 --- a/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp +++ b/services/adapter/settings_data_provider/common/src/settings_data_utils.cpp @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include "settings_data_utils.h" +#include #include "iservice_registry.h" #include "system_ability_definition.h" @@ -60,7 +60,7 @@ int32_t SettingsDataUtils::CreateAndRegisterObserver( } return RegisterObserver(observer); } - +// LCOV_EXCL_START int32_t SettingsDataUtils::RegisterObserver(const std::string &uriProxy, const std::string &key, const SettingsDataObserver::CallbackFunc &func, sptr &observer) { @@ -71,7 +71,7 @@ int32_t SettingsDataUtils::RegisterObserver(const std::string &uriProxy, const s } return RegisterObserver(observer); } - +// LCOV_EXCL_STOP int32_t SettingsDataUtils::RegisterObserver(const sptr &observer) { if (observer == nullptr) { @@ -148,7 +148,7 @@ Uri SettingsDataUtils::GenerateTargetUri(const std::string &uriProxy, const std: Uri uri(uriProxy + "&key=" + key); return uri; } - +// LCOV_EXCL_START bool SettingsDataUtils::SetStringValue(const std::string &uriProxy, const std::string &key, const std::string &value) { IMSA_HILOGD("start."); @@ -213,7 +213,7 @@ int32_t SettingsDataUtils::GetStringValue(const std::string &uriProxy, const std resultSet->Close(); return ret; } - +// LCOV_EXCL_STOP sptr SettingsDataUtils::GetToken() { std::lock_guard autoLock(remoteObjMutex_); diff --git a/services/adapter/settings_data_provider/src/enable_upgrade_manager.cpp b/services/adapter/settings_data_provider/src/enable_upgrade_manager.cpp index dfade9891..103ce6ec0 100644 --- a/services/adapter/settings_data_provider/src/enable_upgrade_manager.cpp +++ b/services/adapter/settings_data_provider/src/enable_upgrade_manager.cpp @@ -131,7 +131,8 @@ int32_t EnableUpgradeManager::ParseEnabledTable( int32_t EnableUpgradeManager::GetFullExperienceTable(int32_t userId, std::set &bundleNames) { std::string content; - int32_t ret = SettingsDataUtils::GetInstance().GetStringValue(SETTING_URI_PROXY, SettingsDataUtils::SECURITY_MODE, content); + int32_t ret = SettingsDataUtils::GetInstance().GetStringValue(SETTING_URI_PROXY, + SettingsDataUtils::SECURITY_MODE, content); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGW("%{public}d get full experience table failed:%{public}d.", userId, ret); return ret; @@ -210,7 +211,7 @@ int32_t EnableUpgradeManager::PaddedByBundleMgr( } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_START void EnableUpgradeManager::UpdateGlobalEnabledTable(int32_t userId, const ImeEnabledCfg &newEnabledCfg) { if (!ImeInfoInquirer::GetInstance().GetSystemConfig().enableInputMethodFeature) { @@ -257,7 +258,7 @@ void EnableUpgradeManager::UpdateGlobalEnabledTable(int32_t userId, const ImeEna } SetGlobalEnabledTable(newGlobalContent); } - +// LCOV_EXCL_STOP int32_t EnableUpgradeManager::GetGlobalTableUserId(const std::string &valueStr) { auto root = cJSON_Parse(valueStr.c_str()); @@ -292,7 +293,7 @@ std::string EnableUpgradeManager::GenerateGlobalContent(int32_t userId, const st } return newGlobalContent; } - +// LCOV_EXCL_START bool EnableUpgradeManager::SetGlobalEnabledTable(const std::string &content) { return SetEnabledTable(SETTING_URI_PROXY, content); @@ -308,7 +309,7 @@ bool EnableUpgradeManager::SetEnabledTable(const std::string &uriProxy, const st { return SettingsDataUtils::GetInstance().SetStringValue(uriProxy, SettingsDataUtils::ENABLE_IME, content); } - +// LCOV_EXCL_STOP int32_t EnableUpgradeManager::GetImePersistCfg(int32_t userId, ImePersistInfo &persisInfo) { if (!FileOperator::IsExist(IME_CFG_FILE_PATH)) { diff --git a/services/adapter/settings_data_provider/src/ime_enabled_info_manager.cpp b/services/adapter/settings_data_provider/src/ime_enabled_info_manager.cpp index d5cf7027b..3ca12e370 100644 --- a/services/adapter/settings_data_provider/src/ime_enabled_info_manager.cpp +++ b/services/adapter/settings_data_provider/src/ime_enabled_info_manager.cpp @@ -26,6 +26,7 @@ namespace OHOS { namespace MiscServices { using namespace std::chrono; +constexpr const char *SYSTEM_SPECIAL_IME = "com.huawei.hmos.hiwrite"; ImeEnabledInfoManager &ImeEnabledInfoManager::GetInstance() { static ImeEnabledInfoManager instance; @@ -185,7 +186,7 @@ int32_t ImeEnabledInfoManager::CheckUpdate( } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_START int32_t ImeEnabledInfoManager::Update( int32_t userId, const std::string &bundleName, const std::string &extensionName, EnabledStatus status) { @@ -225,7 +226,7 @@ int32_t ImeEnabledInfoManager::Update( } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_STOP int32_t ImeEnabledInfoManager::GetEnabledState(int32_t userId, const std::string &bundleName, EnabledStatus &status) { std::lock_guard lock(operateLock_); @@ -234,7 +235,7 @@ int32_t ImeEnabledInfoManager::GetEnabledState(int32_t userId, const std::string IMSA_HILOGW("%{public}d bundleName is empty.", userId); return ErrorCode::ERROR_BAD_PARAMETERS; } - if (bundleName == ImeInfoInquirer::GetInstance().GetSystemSpecialIme()) { + if (bundleName == SYSTEM_SPECIAL_IME) { status = EnabledStatus::FULL_EXPERIENCE_MODE; return ErrorCode::NO_ERROR; } @@ -384,7 +385,7 @@ void ImeEnabledInfoManager::ClearEnabledCache(int32_t userId) std::lock_guard cfgLock(imeEnabledCfgLock_); imeEnabledCfg_.erase(userId); } - +// LCOV_EXCL_START int32_t ImeEnabledInfoManager::GetEnabledCfg( int32_t userId, const std::vector &imeInfos, ImeEnabledCfg &cfg) { @@ -458,7 +459,7 @@ int32_t ImeEnabledInfoManager::CorrectByBundleMgr( } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_STOP EnabledStatus ImeEnabledInfoManager::ComputeEnabledStatus(const std::string &bundleName, EnabledStatus initStatus) { if (!HasEnabledSwitch()) { @@ -590,7 +591,7 @@ void ImeEnabledInfoManager::OnFullExperienceTableChanged(int32_t userId) IMSA_HILOGI("%{public}d full experience table changed.", userId); ImeEnabledInfoManager::GetInstance().Update(userId, defaultIme.bundleName, defaultIme.extName, newStatus); } - +// LCOV_EXCL_START int32_t ImeEnabledInfoManager::SetCurrentIme( int32_t userId, const std::string &imeId, const std::string &subName, bool isSetByUser) { @@ -600,7 +601,7 @@ int32_t ImeEnabledInfoManager::SetCurrentIme( return ErrorCode::NO_ERROR; } ImeEnabledCfg enabledCfg; - if (bundleName == ImeInfoInquirer::GetInstance().GetSystemSpecialIme()) { + if (bundleName == SYSTEM_SPECIAL_IME) { auto ret = GetEnabledCacheWithCorrect(userId, enabledCfg); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("%{public}d get enable info failed:%{public}d.", userId, ret); @@ -724,7 +725,7 @@ std::shared_ptr ImeEnabledInfoManager::GetCurrentImeCfg(int32_t us IMSA_HILOGI("%{public}d not set default ime.", userId); return std::make_shared(); } - +// LCOV_EXCL_STOP bool ImeEnabledInfoManager::IsDefaultImeSet(int32_t userId) { std::lock_guard lock(operateLock_); diff --git a/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp b/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp index e83c290d6..e69777385 100644 --- a/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp +++ b/services/adapter/settings_data_provider/src/numkey_apps_manager.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace MiscServices { -// LCOV_EXCL_START #define CHECK_FEATURE_DISABLED_RETURN(retVal) \ do { \ if (!isFeatureEnabled_) { \ @@ -34,7 +33,7 @@ NumkeyAppsManager &NumkeyAppsManager::GetInstance() static NumkeyAppsManager numkeyAppsManager; return numkeyAppsManager; } - +// LCOV_EXCL_START NumkeyAppsManager::~NumkeyAppsManager() { if (observers_.empty()) { @@ -168,7 +167,7 @@ int32_t NumkeyAppsManager::UpdateUserBlockList(int32_t userId) return ret; } std::lock_guard lock(blockListLock_); - usersBlockList_[userId] = blockList; + usersBlockList_.insert_or_assign(userId, blockList); IMSA_HILOGI("success, list size: %{public}zu", blockList.size()); return ErrorCode::NO_ERROR; } @@ -244,7 +243,7 @@ int32_t NumkeyAppsManager::RegisterUserBlockListData(int32_t userId) } IMSA_HILOGI("end, userId: %{public}d ", userId); std::lock_guard lock(observersLock_); - observers_[userId] = observer; + observers_.insert_or_assign(userId, observer); return ErrorCode::NO_ERROR; } diff --git a/services/adapter/window_adapter/src/window_adapter.cpp b/services/adapter/window_adapter/src/window_adapter.cpp index a1b3f1478..72d8bdbd8 100644 --- a/services/adapter/window_adapter/src/window_adapter.cpp +++ b/services/adapter/window_adapter/src/window_adapter.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace MiscServices { using namespace OHOS::Rosen; using WMError = OHOS::Rosen::WMError; - +// LCOV_EXCL_START WindowAdapter::~WindowAdapter() { } @@ -35,7 +35,7 @@ WindowAdapter &WindowAdapter::GetInstance() static WindowAdapter windowAdapter; return windowAdapter; } - +// LCOV_EXCL_STOP void WindowAdapter::GetFocusInfo(OHOS::Rosen::FocusChangeInfo &focusInfo, uint64_t displayId) { #ifdef SCENE_BOARD_ENABLE @@ -65,7 +65,7 @@ bool WindowAdapter::GetCallingWindowInfo( return false; #endif } - +// LCOV_EXCL_START void WindowAdapter::RegisterCallingWindowInfoChangedListener(const WindowDisplayChangeHandler &handle) { #ifdef SCENE_BOARD_ENABLE @@ -78,7 +78,7 @@ void WindowAdapter::RegisterCallingWindowInfoChangedListener(const WindowDisplay IMSA_HILOGI("register focus changed listener ret: %{public}d", wmErr); #endif } - +// LCOV_EXCL_STOP bool WindowAdapter::ListWindowInfo(std::vector> &windowInfos) { #ifdef SCENE_BOARD_ENABLE diff --git a/services/adapter/wms_connection_monitor/src/wms_connection_observer.cpp b/services/adapter/wms_connection_monitor/src/wms_connection_observer.cpp index c644912a6..07be39a17 100644 --- a/services/adapter/wms_connection_monitor/src/wms_connection_observer.cpp +++ b/services/adapter/wms_connection_monitor/src/wms_connection_observer.cpp @@ -18,6 +18,7 @@ #include "global.h" namespace OHOS { namespace MiscServices { +// LCOV_EXCL_START std::mutex WmsConnectionObserver::lock_; std::set WmsConnectionObserver::connectedUserId_; void WmsConnectionObserver::OnConnected(int32_t userId, int32_t screenId) @@ -53,7 +54,7 @@ void WmsConnectionObserver::Remove(int32_t userId) } connectedUserId_.erase(it); } - +// LCOV_EXCL_STOP bool WmsConnectionObserver::IsWmsConnected(int32_t userId) { std::lock_guard lock(lock_); diff --git a/services/dialog/AppScope/resources/base/element/string.json b/services/dialog/AppScope/resources/base/element/string.json index 6ff87e0a1..0f92d3c7e 100644 --- a/services/dialog/AppScope/resources/base/element/string.json +++ b/services/dialog/AppScope/resources/base/element/string.json @@ -2,7 +2,7 @@ "string": [ { "name": "app_name", - "value": "InputMethodChooseDialog" + "value": "inputmethodchoosedialog" } ] } diff --git a/services/file/src/file_operator.cpp b/services/file/src/file_operator.cpp index d9b85e614..299e0151e 100644 --- a/services/file/src/file_operator.cpp +++ b/services/file/src/file_operator.cpp @@ -33,7 +33,7 @@ bool FileOperator::Create(const std::string &path, mode_t mode) } return true; } - +// LCOV_EXCL_STOP bool FileOperator::IsExist(const std::string &path) { return access(path.c_str(), F_OK) == SUCCESS; @@ -52,7 +52,7 @@ bool FileOperator::Read(const std::string &path, std::string &content) } return true; } - +// LCOV_EXCL_START bool FileOperator::IsValidPath(const std::string &filePath) { if (filePath.find("../") != std::string::npos) { @@ -85,6 +85,7 @@ bool FileOperator::CheckImeCfgFilePath(const std::string &path) bool FileOperator::Write(const std::string &path, const std::string &content, uint32_t flags, mode_t mode) { + IMSA_HILOGD("content: %{public}s.", content.c_str()); const char* fopenMode; if (flags & O_TRUNC) { fopenMode = "w"; @@ -120,7 +121,7 @@ bool FileOperator::Write(const std::string &path, const std::string &content, ui return true; } - +// LCOV_EXCL_STOP bool FileOperator::Read(const std::string &path, const std::string &key, std::string &content) { if (key.empty()) { @@ -178,6 +179,5 @@ std::string FileOperator::GetRealPath(const char *path) } return std::string(realPath); } -// LCOV_EXCL_STOP } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/identity_checker/include/identity_checker_impl.h b/services/identity_checker/include/identity_checker_impl.h index d7bc6752d..51bab088a 100644 --- a/services/identity_checker/include/identity_checker_impl.h +++ b/services/identity_checker/include/identity_checker_impl.h @@ -28,8 +28,8 @@ public: bool IsBundleNameValid(uint32_t tokenId, const std::string &validBundleName) override; bool HasPermission(uint32_t tokenId, const std::string &permission) override; bool IsBroker(Security::AccessToken::AccessTokenID tokenId) override; - bool IsFormShell(Security::AccessToken::AccessTokenID tokenId) override; bool IsNativeSa(Security::AccessToken::AccessTokenID tokenId) override; + bool IsFormShell(Security::AccessToken::AccessTokenID tokenId) override; std::string GetBundleNameByToken(uint32_t tokenId) override; bool IsFocusedUIExtension(uint32_t callingTokenId, sptr abilityToken = nullptr) override; uint64_t GetDisplayIdByWindowId(int32_t callingWindowId) override; diff --git a/services/include/ime_cfg_manager.h b/services/include/ime_cfg_manager.h index 37839761d..b9f8541eb 100644 --- a/services/include/ime_cfg_manager.h +++ b/services/include/ime_cfg_manager.h @@ -20,9 +20,10 @@ #include "input_method_utils.h" #include "serializable.h" +#include "event_handler.h" #include "ime_enabled_info_manager.h" #include "enable_upgrade_manager.h" -#include "event_handler.h" + namespace OHOS { namespace MiscServices { diff --git a/services/include/notify_service_impl.h b/services/include/notify_service_impl.h index 0eae446fc..43e0cc208 100644 --- a/services/include/notify_service_impl.h +++ b/services/include/notify_service_impl.h @@ -24,14 +24,16 @@ namespace OHOS { namespace MiscServices { -class OnInputStopNotifyServiceImpl final : public OnInputStopNotifyStub, - public std::enable_shared_from_this { +class OnInputStopNotifyServiceImpl final : public OnInputStopNotifyStub { DISALLOW_COPY_AND_MOVE(OnInputStopNotifyServiceImpl); public: - OnInputStopNotifyServiceImpl(); - virtual ~OnInputStopNotifyServiceImpl(); + explicit OnInputStopNotifyServiceImpl(pid_t pid) : pid_(pid) { } + virtual ~OnInputStopNotifyServiceImpl() = default; ErrCode NotifyOnInputStopFinished() override; + +private: + pid_t pid_; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/json/src/serializable.cpp b/services/json/src/serializable.cpp index de2ede6a4..63da72272 100644 --- a/services/json/src/serializable.cpp +++ b/services/json/src/serializable.cpp @@ -21,7 +21,7 @@ bool Serializable::Unmarshall(const std::string &content) { auto root = cJSON_Parse(content.c_str()); if (root == NULL) { - IMSA_HILOGE("content parse failed!"); + IMSA_HILOGE("%{public}s: parse failed!", content.c_str()); return false; } auto ret = Unmarshal(root); @@ -72,7 +72,7 @@ bool Serializable::GetValue(cJSON *node, const std::string &name, int32_t &value value = subNode->valueint; return true; } - +// LCOV_EXCL_START bool Serializable::GetValue(cJSON *node, const std::string &name, uint32_t &value) { auto subNode = GetSubNode(node, name); @@ -99,7 +99,7 @@ bool Serializable::GetValue(cJSON *node, const std::string &name, bool &value) value = subNode->type == cJSON_True; return true; } - +// LCOV_EXCL_STOP bool Serializable::GetValue(cJSON *node, const std::string &name, Serializable &value) { auto object = GetSubNode(node, name); @@ -109,7 +109,7 @@ bool Serializable::GetValue(cJSON *node, const std::string &name, Serializable & } return value.Unmarshal(object); } - +// LCOV_EXCL_START bool Serializable::GetValue(cJSON *node, const std::string &name, std::vector> &values) { auto arrNode = GetSubNode(node, name); @@ -136,7 +136,7 @@ bool Serializable::GetValue(cJSON *node, const std::string &name, std::vector &client, const std: } } } - +// LCOV_EXCL_START std::shared_ptr ClientGroup::GetClientInfo(pid_t pid) { auto iter = std::find_if( @@ -162,7 +162,7 @@ std::shared_ptr ClientGroup::GetClientInfo(pid_t pid) std::lock_guard lock(mtx_); return iter->second; } - +// LCOV_EXCL_STOP std::shared_ptr ClientGroup::GetCurrentClientInfo() { auto client = GetCurrentClient(); @@ -172,7 +172,7 @@ std::shared_ptr ClientGroup::GetCurrentClientInfo() } return GetClientInfo(client->AsObject()); } - +// LCOV_EXCL_START int64_t ClientGroup::GetCurrentClientPid() { auto clientInfo = GetCurrentClientInfo(); @@ -197,7 +197,7 @@ int64_t ClientGroup::GetInactiveClientPid() } return clientInfo->pid; } - +// LCOV_EXCL_STOP bool ClientGroup::IsClientExist(sptr inputClient) { std::lock_guard lock(mtx_); @@ -234,7 +234,7 @@ sptr ClientGroup::GetInactiveClient() std::lock_guard lock(inactiveClientLock_); return inactiveClient_; } - +// LCOV_EXCL_START void ClientGroup::SetInactiveClient(sptr client) { IMSA_HILOGD("set inactive client."); @@ -258,6 +258,22 @@ bool ClientGroup::IsCurClientFocused(int32_t pid, int32_t uid) return clientInfo->pid == pid && clientInfo->uid == uid; } +bool ClientGroup::IsCurClientUnFocused(int32_t pid, int32_t uid) +{ + auto clientInfo = GetCurrentClientInfo(); + if (clientInfo == nullptr) { + IMSA_HILOGE("failed to get cur client info!"); + return false; + } + auto identityChecker = std::make_shared(); + if (clientInfo->uiExtensionTokenId != IMF_INVALID_TOKENID + && !identityChecker->IsFocusedUIExtension(clientInfo->uiExtensionTokenId)) { + IMSA_HILOGI("UIExtension UnFocused."); + return true; + } + return clientInfo->pid == pid && clientInfo->uid == uid; +} +// LCOV_EXCL_STOP int32_t ClientGroup::NotifyInputStartToClients(uint32_t callingWndId, int32_t requestKeyboardReason) { IMSA_HILOGD("NotifyInputStartToClients enter"); @@ -297,7 +313,7 @@ int32_t ClientGroup::NotifyInputStopToClients() } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_START int32_t ClientGroup::NotifyPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info) { auto clientMap = GetClientMap(); @@ -323,7 +339,7 @@ int32_t ClientGroup::NotifyPanelStatusChange(const InputWindowStatus &status, co } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_STOP int32_t ClientGroup::NotifyImeChangeToClients(const Property &property, const SubProperty &subProperty) { auto clientMap = GetClientMap(); @@ -343,22 +359,6 @@ int32_t ClientGroup::NotifyImeChangeToClients(const Property &property, const Su return ErrorCode::NO_ERROR; } -bool ClientGroup::IsCurClientUnFocused(int32_t pid, int32_t uid) -{ - auto clientInfo = GetCurrentClientInfo(); - if (clientInfo == nullptr) { - IMSA_HILOGE("failed to get cur client info!"); - return false; - } - auto identityChecker = std::make_shared(); - if (clientInfo->uiExtensionTokenId != IMF_INVALID_TOKENID - && !identityChecker->IsFocusedUIExtension(clientInfo->uiExtensionTokenId)) { - IMSA_HILOGI("UIExtension UnFocused."); - return true; - } - return clientInfo->pid == pid && clientInfo->uid == uid; -} - std::shared_ptr ClientGroup::GetClientInfo(sptr inputClient) { if (inputClient == nullptr) { @@ -384,7 +384,7 @@ bool ClientGroup::IsSameClient(sptr source, sptr des { return source != nullptr && dest != nullptr && source->AsObject() == dest->AsObject(); } - +// LCOV_EXCL_START void ClientGroup::OnClientDied(sptr remote) { std::lock_guard lock(clientDiedLock_); @@ -393,5 +393,6 @@ void ClientGroup::OnClientDied(sptr remote) } clientDiedHandler_(remote); } +// LCOV_EXCL_STOP } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/src/freeze_manager.cpp b/services/src/freeze_manager.cpp index 25985075c..3769e6a4d 100644 --- a/services/src/freeze_manager.cpp +++ b/services/src/freeze_manager.cpp @@ -60,7 +60,7 @@ void FreezeManager::ReportRss(bool shouldFreeze, pid_t pid) IMSA_HILOGD("report RSS should freeze: %{public}d.", shouldFreeze); ResourceSchedule::ResSchedClient::GetInstance().ReportData(type, status, payload); } - +// LCOV_EXCL_START void FreezeManager::TemporaryActiveIme() { std::lock_guard lock(mutex_); @@ -73,6 +73,7 @@ void FreezeManager::TemporaryActiveIme() ReportRss(false, pid_); ReportRss(true, pid_); } +// LCOV_EXCL_STOP } // namespace MiscServices } // namespace OHOS #endif // FREEZE_MANAGER_H \ No newline at end of file diff --git a/services/src/full_ime_info_manager.cpp b/services/src/full_ime_info_manager.cpp index eb2d26ee3..73095cb39 100644 --- a/services/src/full_ime_info_manager.cpp +++ b/services/src/full_ime_info_manager.cpp @@ -59,7 +59,7 @@ FullImeInfoManager &FullImeInfoManager::GetInstance() static FullImeInfoManager instance; return instance; } - +// LCOV_EXCL_START int32_t FullImeInfoManager::RegularInit() { std::vector>> fullImeInfos; @@ -75,7 +75,7 @@ int32_t FullImeInfoManager::RegularInit() } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_STOP int32_t FullImeInfoManager::Switch(int32_t userId) { std::vector infos; diff --git a/services/src/im_common_event_manager.cpp b/services/src/im_common_event_manager.cpp index 9aa87fb1c..b6053d3ac 100644 --- a/services/src/im_common_event_manager.cpp +++ b/services/src/im_common_event_manager.cpp @@ -337,6 +337,8 @@ void ImCommonEventManager::EventSubscriber::HandlePackageEvent(int32_t messageId IMSA_HILOGE("invalid user id, messageId:%{public}d", messageId); return; } + IMSA_HILOGD( + "messageId:%{public}d, bundleName:%{public}s, userId:%{public}d", messageId, bundleName.c_str(), userId); if (messageId == MessageID::MSG_ID_PACKAGE_REMOVED) { if (!FullImeInfoManager::GetInstance().Has(userId, bundleName)) { return; diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index 73d83a1e7..656b579f0 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -169,8 +169,8 @@ std::shared_ptr ImeInfoInquirer::GetImeInfoFromCache(const int32_t user return info; } -std::shared_ptr ImeInfoInquirer::GetImeInfoFromBundleMgr( - const int32_t userId, const std::string &bundleName, const std::string &subName) +std::shared_ptr ImeInfoInquirer::GetImeInfoFromBundleMgr(const int32_t userId, const std::string &bundleName, + const std::string &subName) { IMSA_HILOGD("userId: %{public}d, bundleName: %{public}s, subName: %{public}s.", userId, bundleName.c_str(), subName.c_str()); @@ -578,10 +578,6 @@ int32_t ImeInfoInquirer::ListInputMethodSubtype(const int32_t userId, const Exte int32_t ImeInfoInquirer::ParseSubtype(const OHOS::AppExecFwk::ExtensionAbilityInfo &extInfo, std::vector &subtypes) { - if (extInfo.metadata.empty()) { - IMSA_HILOGE("metadata is empty!"); - return ErrorCode::ERROR_BAD_PARAMETERS; - } auto iter = std::find_if(extInfo.metadata.begin(), extInfo.metadata.end(), [](const Metadata &metadata) { return metadata.name == SUBTYPE_PROFILE_METADATA_NAME; }); if (iter == extInfo.metadata.end()) { @@ -842,15 +838,6 @@ std::shared_ptr ImeInfoInquirer::GetDefaultImeInfo(int32_t userId) return info; } -std::string ImeInfoInquirer::GetSystemSpecialIme() -{ - if (!systemConfig_.systemSpecialInputMethod.empty()) { - IMSA_HILOGD("systemSpecialInputMethod: %{public}s.", systemConfig_.systemSpecialInputMethod.c_str()); - return systemConfig_.systemSpecialInputMethod; - } - return ""; -} - ImeNativeCfg ImeInfoInquirer::GetDefaultIme() { ImeNativeCfg imeCfg; @@ -1098,7 +1085,7 @@ bool ImeInfoInquirer::IsInputMethod(int32_t userId, const std::string &bundleNam } return false; } - + bool ImeInfoInquirer::IsTempInputMethod(const ExtensionAbilityInfo &extInfo) { auto iter = std::find_if(extInfo.metadata.begin(), extInfo.metadata.end(), @@ -1268,4 +1255,4 @@ bool ImeInfoInquirer::GetCompatibleDeviceType( return true; } } // namespace MiscServices -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index af92b18f9..694bcb94f 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -73,7 +73,7 @@ constexpr const char *UNLOAD_SA_TASK = "unloadInputMethodSaTask"; constexpr int64_t DELAY_UNLOAD_SA_TIME = 20000; // 20s constexpr int32_t REFUSE_UNLOAD_DELAY_TIME = 1000; // 1s #endif - +const constexpr char *IMMERSIVE_EFFECT_CAP_NAME = "immersive_effect"; InputMethodSystemAbility::InputMethodSystemAbility(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate), state_(ServiceRunningState::STATE_NOT_START) { @@ -190,7 +190,7 @@ int32_t InputMethodSystemAbility::OnRemoteRequest( #endif return ret; } - +// LCOV_EXCL_START void InputMethodSystemAbility::OnStart() { IMSA_HILOGI("InputMethodSystemAbility::OnStart start."); @@ -216,14 +216,14 @@ void InputMethodSystemAbility::OnStart() } IMSA_HILOGE("init failed. try again 10s later!"); } + HiviewDFX::XCollie::GetInstance().CancelTimer(id); InitHiTrace(); InputMethodSyncTrace tracer("InputMethodController Attach trace."); InputmethodDump::GetInstance().AddDumpAllMethod([this](int fd) { this->DumpAllMethod(fd); }); - HiviewDFX::XCollie::GetInstance().CancelTimer(id); IMSA_HILOGI("start imsa service success."); return; } - +// LCOV_EXCL_STOP bool InputMethodSystemAbility::IsValidBundleName(const std::string &bundleName) { if (bundleName.empty()) { @@ -241,7 +241,7 @@ bool InputMethodSystemAbility::IsValidBundleName(const std::string &bundleName) return prop.name == bundleName; }); } - +// LCOV_EXCL_START std::string InputMethodSystemAbility::GetRestoreBundleName(MessageParcel &data) { std::string jsonString = data.ReadString(); @@ -332,7 +332,7 @@ int32_t InputMethodSystemAbility::OnExtension(const std::string &extension, Mess } return 0; } - +// LCOV_EXCL_STOP int InputMethodSystemAbility::Dump(int fd, const std::vector &args) { IMSA_HILOGD("InputMethodSystemAbility::Dump start."); @@ -367,7 +367,7 @@ void InputMethodSystemAbility::DumpAllMethod(int fd) // LCOV_EXCL_START int32_t InputMethodSystemAbility::Init() { - IMSA_HILOGI("InputMethodSystemAbility::Init start."); + IMSA_HILOGI("publish start"); #ifdef IMF_ON_DEMAND_START_STOP_SA_ENABLE ImeCfgManager::GetInstance().Init(); ImeInfoInquirer::GetInstance().InitSystemConfig(); @@ -392,7 +392,7 @@ int32_t InputMethodSystemAbility::Init() InitMonitors(); return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_STOP void InputMethodSystemAbility::UpdateUserInfo(int32_t userId) { IMSA_HILOGI("%{public}d switch to %{public}d.", userId_, userId); @@ -401,7 +401,7 @@ void InputMethodSystemAbility::UpdateUserInfo(int32_t userId) InputMethodSysEvent::GetInstance().SetUserId(userId_); NumkeyAppsManager::GetInstance().OnUserSwitched(userId_); } - +// LCOV_EXCL_START int32_t InputMethodSystemAbility::OnIdle(const SystemAbilityOnDemandReason &idleReason) { IMSA_HILOGI("OnIdle start."); @@ -419,9 +419,9 @@ void InputMethodSystemAbility::OnStop() { IMSA_HILOGI("OnStop start."); ImeStateManager::SetEventHandler(nullptr); + ImeCfgManager::GetInstance().SetEventHandler(nullptr); UserSessionManager::GetInstance().SetEventHandler(nullptr); ImeEnabledInfoManager::GetInstance().SetEventHandler(nullptr); - ImeCfgManager::GetInstance().SetEventHandler(nullptr); serviceHandler_ = nullptr; state_ = ServiceRunningState::STATE_NOT_START; Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 0, INPUT_METHOD_SYSTEM_ABILITY_ID); @@ -463,7 +463,7 @@ void InputMethodSystemAbility::Initialize() OnCurrentImeStatusChanged(userId, bundleName, newStatus); }); isScbEnable_.store(Rosen::SceneBoardJudgement::IsSceneBoardEnabled()); - IMSA_HILOGI("InputMethodSystemAbility::Initialize end."); + IMSA_HILOGI("Initialize end"); } void InputMethodSystemAbility::RestartSessionIme(std::shared_ptr &session) @@ -483,7 +483,7 @@ void InputMethodSystemAbility::RestartSessionIme(std::shared_ptr #endif StopImeInBackground(); } - +// LCOV_EXCL_START std::shared_ptr InputMethodSystemAbility::GetSessionFromMsg(const Message *msg) { if (msg == nullptr || msg->msgContent_ == nullptr) { @@ -498,7 +498,7 @@ std::shared_ptr InputMethodSystemAbility::GetSessionFromMsg(cons } return session; } - +// LCOV_EXCL_STOP int32_t InputMethodSystemAbility::PrepareForOperateKeyboard(std::shared_ptr &session) { AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); @@ -516,7 +516,7 @@ int32_t InputMethodSystemAbility::PrepareForOperateKeyboard(std::shared_ptr &info) { @@ -538,7 +538,7 @@ int32_t InputMethodSystemAbility::SwitchByCondition(const Condition &condition, session->GetSwitchQueue().Push(switchInfo); return OnSwitchInputMethod(userId_, switchInfo, SwitchTrigger::IMSA); } - +// LCOV_EXCL_STOP void InputMethodSystemAbility::SubscribeCommonEvent() { sptr imCommonEventManager = ImCommonEventManager::GetInstance(); @@ -552,7 +552,7 @@ void InputMethodSystemAbility::SubscribeCommonEvent() auto callback = [this]() { SubscribeCommonEvent(); }; serviceHandler_->PostTask(callback, INIT_INTERVAL); } - +// LCOV_EXCL_START int32_t InputMethodSystemAbility::PrepareInput(int32_t userId, InputClientInfo &clientInfo) { InputMethodSyncTrace tracer("InputMethodSystemAbility PrepareInput"); @@ -604,7 +604,7 @@ int32_t InputMethodSystemAbility::GenerateClientInfo(int32_t userId, InputClient } return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_STOP ErrCode InputMethodSystemAbility::ReleaseInput(const sptr& client, uint32_t sessionId) { if (client == nullptr) { @@ -668,7 +668,7 @@ ErrCode InputMethodSystemAbility::StartInput(const InputClientInfoInner &inputCl .SetErrCode(ret) .Build(); ImsaHiSysEventReporter::GetInstance().ReportEvent(ImfEventType::CLIENT_ATTACH, *evenInfo); - IMSA_HILOGE("HiSysEvent report end!"); + IMSA_HILOGD("HiSysEvent report end!"); return ret; } @@ -678,7 +678,7 @@ int32_t InputMethodSystemAbility::StartInputInner( auto userId = GetCallingUserId(); AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); if (!identityChecker_->IsBroker(tokenId) && !identityChecker_->IsFocused(IPCSkeleton::GetCallingPid(), tokenId, - IdentityChecker::INVALID_PID, true, inputClientInfo.config.abilityToken)) { + IdentityChecker::INVALID_PID, true, inputClientInfo.config.abilityToken)) { return ErrorCode::ERROR_CLIENT_NOT_FOCUSED; } auto session = UserSessionManager::GetInstance().GetUserSession(userId); @@ -858,7 +858,7 @@ ErrCode InputMethodSystemAbility::SetCoreAndAgent(const sptr & return session->OnSetCoreAndAgent(core, agent); } -int32_t InputMethodSystemAbility::RegisterProxyIme( +ErrCode InputMethodSystemAbility::RegisterProxyIme( uint64_t displayId, const sptr &core, const sptr &agent) { if (!ImeInfoInquirer::GetInstance().IsEnableAppAgent()) { @@ -878,7 +878,7 @@ int32_t InputMethodSystemAbility::RegisterProxyIme( return session->OnRegisterProxyIme(displayId, core, agent); } -int32_t InputMethodSystemAbility::UnregisterProxyIme(uint64_t displayId) +ErrCode InputMethodSystemAbility::UnregisterProxyIme(uint64_t displayId) { if (!ImeInfoInquirer::GetInstance().IsEnableAppAgent()) { IMSA_HILOGE("current device does not support app agent"); @@ -1044,7 +1044,7 @@ ErrCode InputMethodSystemAbility::UpdateListenEventFlag(const InputClientInfoInn } return session->OnUpdateListenEventFlag(clientInfo); } - +// LCOV_EXCL_START ErrCode InputMethodSystemAbility::SetCallingWindow(uint32_t windowId, const sptr& client) { IMSA_HILOGD("IMF SA setCallingWindow enter"); @@ -1065,7 +1065,7 @@ ErrCode InputMethodSystemAbility::SetCallingWindow(uint32_t windowId, const sptr auto callingDisplayId = identityChecker_->GetDisplayIdByWindowId(windowId); return session->OnSetCallingWindow(windowId, callingDisplayId, client); } - +// LCOV_EXCL_STOP ErrCode InputMethodSystemAbility::GetInputStartInfo(bool& isInputStart, uint32_t& callingWndId, int32_t &requestKeyboardReason) { @@ -1133,7 +1133,7 @@ ErrCode InputMethodSystemAbility::IsSystemApp(bool& resultValue) resultValue = identityChecker_->IsSystemApp(IPCSkeleton::GetCallingFullTokenID()); return ERR_OK; } - +// LCOV_EXCL_START ErrCode InputMethodSystemAbility::IsCapacitySupport(int32_t capacity, bool &isSupport) { IMSA_HILOGI("capacity:%{public}d", capacity); @@ -1142,10 +1142,10 @@ ErrCode InputMethodSystemAbility::IsCapacitySupport(int32_t capacity, bool &isSu return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; } - isSupport = ImeInfoInquirer::GetInstance().IsCapacitySupport("immersive_effect"); + isSupport = ImeInfoInquirer::GetInstance().IsCapacitySupport(IMMERSIVE_EFFECT_CAP_NAME); return ERR_OK; } - +// LCOV_EXCL_STOP int32_t InputMethodSystemAbility::IsDefaultImeFromTokenId(int32_t userId, uint32_t tokenId) { auto prop = std::make_shared(); @@ -1418,7 +1418,7 @@ bool InputMethodSystemAbility::IsNeedSwitch(int32_t userId, const std::string &b currentImeCfg->bundleName.c_str(), currentImeCfg->subName.c_str(), bundleName.c_str(), subName.c_str()); if ((subName.empty() && bundleName == currentImeCfg->bundleName) || (!subName.empty() && subName == currentImeCfg->subName && currentImeCfg->bundleName == bundleName)) { - IMSA_HILOGI("no need to switch."); + IMSA_HILOGI("no need to switch"); return false; } return true; @@ -1728,7 +1728,7 @@ int32_t InputMethodSystemAbility::OnUserRemoved(const Message *msg) NumkeyAppsManager::GetInstance().OnUserRemoved(userId); return ErrorCode::NO_ERROR; } - +// LCOV_EXCL_START int32_t InputMethodSystemAbility::OnUserStop(const Message *msg) { auto session = GetSessionFromMsg(msg); @@ -1775,11 +1775,12 @@ int32_t InputMethodSystemAbility::HandleUpdateLargeMemoryState(const Message *ms return session->UpdateLargeMemorySceneState(memoryState); } +// LCOV_EXCL_STOP int32_t InputMethodSystemAbility::HandlePackageEvent(const Message *msg) { MessageParcel *data = msg->msgContent_; if (data == nullptr) { - IMSA_HILOGD("data is nullptr"); + IMSA_HILOGD("data is nullptr."); return ErrorCode::ERROR_NULL_POINTER; } int32_t userId = 0; @@ -1946,7 +1947,7 @@ void InputMethodSystemAbility::DealSwitchRequest() // 0 means delay time is 0. serviceHandler_->PostTask(switchTask, "SwitchImeTask", 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); } - +// LCOV_EXCL_STOP int32_t InputMethodSystemAbility::SwitchMode() { auto bundleName = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName; @@ -1983,7 +1984,7 @@ int32_t InputMethodSystemAbility::SwitchLanguage() auto condition = info->subProp.language == "chinese" ? Condition::ENGLISH : Condition::CHINESE; return SwitchByCondition(condition, info); } - +// LCOV_EXCL_START int32_t InputMethodSystemAbility::SwitchType() { SwitchInfo nextSwitchInfo = { std::chrono::system_clock::now(), "", "" }; @@ -2028,7 +2029,7 @@ void InputMethodSystemAbility::InitMonitors() IMSA_HILOGI("init Pasteboard monitor, ret: %{public}d.", ret); InitSystemLanguageMonitor(); } - +// LCOV_EXCL_STOP void InputMethodSystemAbility::HandleDataShareReady() { IMSA_HILOGI("run in."); @@ -2059,12 +2060,10 @@ int32_t InputMethodSystemAbility::InitKeyEventMonitor() { IMSA_HILOGI("InputMethodSystemAbility::InitKeyEventMonitor start."); auto handler = [this]() { - auto switchTrigger = [this](uint32_t keyCode) { - return SwitchByCombinationKey(keyCode); - }; + auto switchTrigger = [this](uint32_t keyCode) { return SwitchByCombinationKey(keyCode);}; int32_t ret = KeyboardEvent::GetInstance().AddKeyEventMonitor(switchTrigger); - IMSA_HILOGI( - "SubscribeKeyboardEvent add monitor: %{public}s.", ret == ErrorCode::NO_ERROR ? "success" : "failed"); + IMSA_HILOGI("SubscribeKeyboardEvent add monitor: %{public}s.", + ret == ErrorCode::NO_ERROR ? "success" : "failed"); // Check device capslock status and ime cfg corrent, when device power-up. HandleImeCfgCapsState(); }; @@ -2086,7 +2085,7 @@ bool InputMethodSystemAbility::InitWmsMonitor() } return imCommonEventManager->SubscribeWindowManagerService([this]() { HandleWmsStarted(); }); } -// LCOV_EXCL_STOP + bool InputMethodSystemAbility::InitMemMgrMonitor() { auto imCommonEventManager = ImCommonEventManager::GetInstance(); @@ -2104,7 +2103,7 @@ void InputMethodSystemAbility::InitWmsConnectionMonitor() isConnected ? HandleWmsConnected(userId, screenId) : HandleWmsDisconnected(userId, screenId); }); } - +// LCOV_EXCL_START void InputMethodSystemAbility::HandlePasteboardStarted() { IMSA_HILOGI("pasteboard started"); @@ -2140,7 +2139,7 @@ bool InputMethodSystemAbility::InitPasteboardMonitor() HandlePasteboardStarted(); }); } - +// LCOV_EXCL_STOP void InputMethodSystemAbility::InitSystemLanguageMonitor() { SystemParamAdapter::GetInstance().WatchParam(SystemParamAdapter::SYSTEM_LANGUAGE_KEY); @@ -2153,6 +2152,7 @@ void InputMethodSystemAbility::InitFocusChangedMonitor() HandleFocusChanged(isOnFocused, displayId, pid, uid); }); } +// LCOV_EXCL_START void InputMethodSystemAbility::InitWindowDisplayChangedMonitor() { IMSA_HILOGD("enter."); @@ -2213,7 +2213,7 @@ void InputMethodSystemAbility::OnCurrentImeStatusChanged( } session->AddRestartIme(); } - +// LCOV_EXCL_STOP int32_t InputMethodSystemAbility::GetSecurityMode(int32_t &security) { IMSA_HILOGD("InputMethodSystemAbility start."); @@ -2241,8 +2241,7 @@ int32_t InputMethodSystemAbility::GetSecurityMode(int32_t &security) ErrCode InputMethodSystemAbility::UnRegisteredProxyIme(int32_t type, const sptr &core) { pid_t pid = IPCSkeleton::GetCallingPid(); - pid_t uid = IPCSkeleton::GetCallingUid(); - if (!identityChecker_->IsValidVirtualIme(uid)) { + if (!identityChecker_->IsValidVirtualIme(IPCSkeleton::GetCallingUid())) { IMSA_HILOGE("not native sa!"); return ErrorCode::ERROR_STATUS_PERMISSION_DENIED; } @@ -2302,7 +2301,6 @@ int32_t InputMethodSystemAbility::CheckSwitchPermission(int32_t userId, const Sw return ErrorCode::NO_ERROR; } IMSA_HILOGE("have not PERMISSION_CONNECT_IME_ABILITY!"); - // switchInfo.subName.empty() check temporarily reserved for application adaptation, will be deleted soon if (IsCurrentIme(userId, tokenId)) { return ErrorCode::NO_ERROR; } @@ -2336,7 +2334,7 @@ bool InputMethodSystemAbility::IsStartInputTypePermitted(int32_t userId) return identityChecker_->IsFocused(IPCSkeleton::GetCallingPid(), tokenId) && session->IsBoundToClient(GetCallingDisplayId()); } - +// LCOV_EXCL_START int32_t InputMethodSystemAbility::ConnectSystemCmd(const sptr &channel, sptr &agent) { auto tokenId = IPCSkeleton::GetCallingTokenID(); @@ -2352,7 +2350,7 @@ int32_t InputMethodSystemAbility::ConnectSystemCmd(const sptr &ch } return session->OnConnectSystemCmd(channel, agent); } - +// LCOV_EXCL_STOP void InputMethodSystemAbility::HandleWmsConnected(int32_t userId, int32_t screenId) { if (userId == userId_) { @@ -2457,6 +2455,7 @@ void InputMethodSystemAbility::HandleMemStarted() // singleton IMSA_HILOGI("MemMgr start."); Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 1, INPUT_METHOD_SYSTEM_ABILITY_ID); + Memory::MemMgrClient::GetInstance().SetCritical(getpid(), true, INPUT_METHOD_SYSTEM_ABILITY_ID); SystemParamAdapter::GetInstance().WatchParam(SystemParamAdapter::MEMORY_WATERMARK_KEY); auto session = UserSessionManager::GetInstance().GetUserSession(userId_); RestartSessionIme(session); @@ -2626,7 +2625,7 @@ bool InputMethodSystemAbility::ModifyImeCfgWithWrongCaps() correctImeName.c_str(), correctIme->id.c_str()); return true; } -// LCOV_EXCL_STOP + bool InputMethodSystemAbility::GetDeviceFunctionKeyState(int32_t functionKey, bool &isEnable) { auto multiInputMgr = MMI::InputManager::GetInstance(); @@ -2642,7 +2641,7 @@ bool InputMethodSystemAbility::GetDeviceFunctionKeyState(int32_t functionKey, bo } return true; } - +// LCOV_EXCL_STOP void InputMethodSystemAbility::HandleImeCfgCapsState() { if (!isBundleScanFinished_.load()) { @@ -2774,7 +2773,7 @@ int32_t InputMethodSystemAbility::GetAlternativeIme(int32_t userId, std::string ime = props[0].name + "/" + props[0].id; return ErrorCode::NO_ERROR; } - IMSA_HILOGD("GetListEnableInputMethodIme is failed!"); + IMSA_HILOGE("GetListEnableInputMethodIme is failed!"); status = InputMethodStatus::DISABLE; ret = ListInputMethod(status, props); if (ret != ErrorCode::NO_ERROR || props.empty()) { @@ -2789,18 +2788,17 @@ int32_t InputMethodSystemAbility::GetAlternativeIme(int32_t userId, std::string IMSA_HILOGE("GetAlternativeIme is failed!"); return ErrorCode::ERROR_NOT_IME; } - -int32_t InputMethodSystemAbility::SendPrivateData( - const Value &value) +// LCOV_EXCL_START +ErrCode InputMethodSystemAbility::SendPrivateData(const Value &value) { std::unordered_map privateCommand; privateCommand = value.valueMap; if (privateCommand.empty()) { - IMSA_HILOGE("privateCommand is empty!"); + IMSA_HILOGE("PrivateCommand is empty!"); return ErrorCode::ERROR_PRIVATE_COMMAND_IS_EMPTY; } if (!identityChecker_->IsSpecialSaUid()) { - IMSA_HILOGE("uid failed, not permission!"); + IMSA_HILOGE("Uid failed, not permission!"); return ErrorCode::ERROR_STATUS_PERMISSION_DENIED; } auto session = UserSessionManager::GetInstance().GetUserSession(userId_); @@ -2862,5 +2860,6 @@ void InputMethodSystemAbility::OnSysMemChanged() } session->TryStartIme(); } +// LCOV_EXCL_STOP } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/src/notify_service_impl.cpp b/services/src/notify_service_impl.cpp index 09de895f8..bcc36b0b2 100644 --- a/services/src/notify_service_impl.cpp +++ b/services/src/notify_service_impl.cpp @@ -21,12 +21,14 @@ namespace OHOS { namespace MiscServices { -OnInputStopNotifyServiceImpl::OnInputStopNotifyServiceImpl() {} -OnInputStopNotifyServiceImpl::~OnInputStopNotifyServiceImpl() {} ErrCode OnInputStopNotifyServiceImpl::NotifyOnInputStopFinished() { IMSA_HILOGI("NotifyOnInputStopFinished is start!"); + if (pid_ != IPCSkeleton::GetCallingPid()) { + IMSA_HILOGI("pid is invalid!"); + return ErrorCode::ERROR_STATUS_PERMISSION_DENIED; + } auto userId = OsAccountAdapter::GetOsAccountLocalIdFromUid(IPCSkeleton::GetCallingUid()); if (userId == OsAccountAdapter::INVALID_USER_ID) { return ErrorCode::ERROR_EX_ILLEGAL_STATE; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index ab28232a5..f7ee654d9 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -690,7 +690,7 @@ void PerUserSession::StopClientInput( if (isAsync == true) { ret = clientInfo->client->OnInputStopAsync(isStopInactiveClient); } else { - auto onInputStopObject = new (std::nothrow) OnInputStopNotifyServiceImpl(); + auto onInputStopObject = new (std::nothrow) OnInputStopNotifyServiceImpl(clientInfo->pid); if (onInputStopObject == nullptr) { IMSA_HILOGE("Failed to create onInputStopObject."); return; diff --git a/test/common/src/ime_setting_listener_test_impl.cpp b/test/common/src/ime_setting_listener_test_impl.cpp index 6293549c6..149a3076b 100644 --- a/test/common/src/ime_setting_listener_test_impl.cpp +++ b/test/common/src/ime_setting_listener_test_impl.cpp @@ -15,8 +15,6 @@ #include "ime_setting_listener_test_impl.h" -#include "global.h" - namespace OHOS { namespace MiscServices { constexpr int32_t SWITCH_IME_WAIT_TIME = 3; @@ -57,36 +55,32 @@ bool ImeSettingListenerTestImpl::WaitPanelShow() bool ImeSettingListenerTestImpl::WaitImeChange() { std::unique_lock lock(imeSettingListenerLock_); - imeSettingListenerCv_.wait_for(lock, std::chrono::seconds(SWITCH_IME_WAIT_TIME), []() { - return isImeChange_; - }); + imeSettingListenerCv_.wait_for(lock, std::chrono::seconds(1), []() { return isImeChange_; }); return isImeChange_; } bool ImeSettingListenerTestImpl::WaitTargetImeChange(const std::string &bundleName) { std::unique_lock lock(imeSettingListenerLock_); - imeSettingListenerCv_.wait_for(lock, std::chrono::seconds(SWITCH_IME_WAIT_TIME), [&bundleName]() { - return bundleName == property_.name; - }); + do { + // 3 means 3 seconds. + imeSettingListenerCv_.wait_for(lock, std::chrono::seconds(SWITCH_IME_WAIT_TIME), + [&bundleName]() { return bundleName == property_.name; }); + } while (bundleName != property_.name); return isImeChange_ && bundleName == property_.name; } bool ImeSettingListenerTestImpl::WaitImeChange(const SubProperty &subProperty) { std::unique_lock lock(imeSettingListenerLock_); - imeSettingListenerCv_.wait_for(lock, std::chrono::seconds(SWITCH_IME_WAIT_TIME), [&subProperty]() { - return subProperty_.id == subProperty.id && subProperty_.name == subProperty.name; - }); + imeSettingListenerCv_.wait_for(lock, std::chrono::seconds(1), + [&subProperty]() { return subProperty_.id == subProperty.id && subProperty_.name == subProperty.name; }); return subProperty_.id == subProperty.id && subProperty_.name == subProperty.name; } void ImeSettingListenerTestImpl::OnImeChange(const Property &property, const SubProperty &subProperty) { std::unique_lock lock(imeSettingListenerLock_); - IMSA_HILOGI("ImeSettingListenerTestImpl, property name: %{public}s, property id: %{public}s, subProp id: " - "%{public}s", - property.name.c_str(), property.id.c_str(), subProperty.id.c_str()); isImeChange_ = true; subProperty_ = subProperty; property_ = property; @@ -96,7 +90,6 @@ void ImeSettingListenerTestImpl::OnImeChange(const Property &property, const Sub void ImeSettingListenerTestImpl::OnImeShow(const ImeWindowInfo &info) { std::unique_lock lock(imeSettingListenerLock_); - IMSA_HILOGI("ImeSettingListenerTestImpl"); status_ = InputWindowStatus::SHOW; imeSettingListenerCv_.notify_one(); } @@ -104,7 +97,6 @@ void ImeSettingListenerTestImpl::OnImeShow(const ImeWindowInfo &info) void ImeSettingListenerTestImpl::OnImeHide(const ImeWindowInfo &info) { std::unique_lock lock(imeSettingListenerLock_); - IMSA_HILOGI("ImeSettingListenerTestImpl"); status_ = InputWindowStatus::HIDE; imeSettingListenerCv_.notify_one(); } diff --git a/test/common/src/input_method_engine_listener_impl.cpp b/test/common/src/input_method_engine_listener_impl.cpp index 81eb48ff6..86068ad8f 100644 --- a/test/common/src/input_method_engine_listener_impl.cpp +++ b/test/common/src/input_method_engine_listener_impl.cpp @@ -68,7 +68,7 @@ void InputMethodEngineListenerImpl::OnSetSubtype(const SubProperty &property) void InputMethodEngineListenerImpl::OnInputFinish() { - IMSA_HILOGI("InputMethodEngineListenerImpl"); + IMSA_HILOGI("OnInputFinish"); isInputFinish_ = true; imeListenerCv_.notify_one(); } @@ -76,14 +76,14 @@ void InputMethodEngineListenerImpl::OnInputFinish() void InputMethodEngineListenerImpl::ReceivePrivateCommand( const std::unordered_map &privateCommand) { - IMSA_HILOGI("InputMethodEngineListenerImpl"); + IMSA_HILOGI("ReceivePrivateCommand"); privateCommand_ = privateCommand; imeListenerCv_.notify_one(); } bool InputMethodEngineListenerImpl::IsEnable() { - IMSA_HILOGI("InputMethodEngineListenerImpl isEnable: %{public}d", isEnable_); + IMSA_HILOGD("test::isEnable: %{public}d", isEnable_); return isEnable_; } diff --git a/test/fuzztest/commonevent_fuzzer/commonevent_fuzzer.cpp b/test/fuzztest/commonevent_fuzzer/commonevent_fuzzer.cpp index 0c482c3ec..a64b2770a 100644 --- a/test/fuzztest/commonevent_fuzzer/commonevent_fuzzer.cpp +++ b/test/fuzztest/commonevent_fuzzer/commonevent_fuzzer.cpp @@ -79,7 +79,7 @@ void FuzzSwitchOperation(const uint8_t *data, size_t size) sptr core = new InputMethodCoreServiceImpl(); sptr stub = new SystemCmdChannelServiceImpl(); auto info = std::make_shared(); - + MessageParcel messData; messData.WriteRemoteObject(stub->AsObject()); sptr remoteObject = messData.ReadRemoteObject(); @@ -92,20 +92,23 @@ void FuzzSwitchOperation(const uint8_t *data, size_t size) DelayedSingleton::GetInstance()->InitWmsConnectionMonitor(); DelayedSingleton::GetInstance()->IsValidBundleName(fuzzedString); DelayedSingleton::GetInstance()->UpdateUserInfo(fuzzedInt32); - + DelayedSingleton::GetInstance()->RegisterProxyIme(fuzzedUint64, core, remoteObject); + DelayedSingleton::GetInstance()->Switch(fuzzedInt32, fuzzedString, info); + DelayedSingleton::GetInstance()->SwitchExtension(fuzzedInt32, info); + DelayedSingleton::GetInstance()->SwitchSubType(fuzzedInt32, info); DelayedSingleton::GetInstance()->SwitchByCombinationKey(fuzzedUint32); DelayedSingleton::GetInstance()->HandleFocusChanged(fuzzedBool, fuzzedUint64, fuzzedInt32, fuzzedInt32); } - + void FuzzHandleOperation(const uint8_t *data, size_t size) { FuzzedDataProvider provider(data, size); auto fuzzedInt32 = provider.ConsumeIntegral(); InputType inputType = static_cast(size); InputClientInfo clientInfo {}; - + auto fuzzedBool = static_cast(data[0] % 2); std::string fuzzedString(reinterpret_cast(data), size); @@ -114,7 +117,7 @@ void FuzzHandleOperation(const uint8_t *data, size_t size) DelayedSingleton::GetInstance()->HandleOsAccountStarted(); DelayedSingleton::GetInstance()->HandleMemStarted(); DelayedSingleton::GetInstance()->HandleWmsStarted(); - + DelayedSingleton::GetInstance()->HandleWmsConnected(fuzzedInt32, fuzzedInt32); DelayedSingleton::GetInstance()->HandleScbStarted(fuzzedInt32, fuzzedInt32); DelayedSingleton::GetInstance()->HandleWmsDisconnected(fuzzedInt32, fuzzedInt32); diff --git a/test/fuzztest/controlchannelstub_fuzzer/BUILD.gn b/test/fuzztest/controlchannelstub_fuzzer/BUILD.gn index 0ee0423fd..d0c82f713 100644 --- a/test/fuzztest/controlchannelstub_fuzzer/BUILD.gn +++ b/test/fuzztest/controlchannelstub_fuzzer/BUILD.gn @@ -35,6 +35,8 @@ ohos_fuzztest("ControlChannelStubFuzzTest") { ] sources = [ + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_info.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_utils.cpp", "${inputmethod_path}/services/src/input_control_channel_service_impl.cpp", "controlchannelstub_fuzzer.cpp", ] diff --git a/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.cpp b/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.cpp index cff04537f..a88f15318 100644 --- a/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.cpp +++ b/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.cpp @@ -81,7 +81,6 @@ void FuzzFullImeInfo(const uint8_t *data, size_t size) FullImeInfo imeInfo = { .isNewIme = fuzzedBool, .tokenId = fuzzUint32, .appId = fuzzedString, .versionCode = fuzzUint32 }; infos.push_back(imeInfo); - FullImeInfoManager::GetInstance().RegularInit(); FullImeInfoManager::GetInstance().Switch(fuzzInt32); FullImeInfoManager::GetInstance().Update(); FullImeInfoManager::GetInstance().Delete(fuzzInt32); diff --git a/test/fuzztest/imeeventmonitormanager_fuzzer/BUILD.gn b/test/fuzztest/imeeventmonitormanager_fuzzer/BUILD.gn index 2f304578d..10bf572d3 100644 --- a/test/fuzztest/imeeventmonitormanager_fuzzer/BUILD.gn +++ b/test/fuzztest/imeeventmonitormanager_fuzzer/BUILD.gn @@ -40,6 +40,8 @@ ohos_fuzztest("ImeEventMonitorManagerFuzzTest") { "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", "${inputmethod_path}/test/common:inputmethod_test_common", ] + + external_deps = [ "input:libmmi-client" ] } ############################################################################### diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp index 0e77a1bdf..8d5f710ce 100644 --- a/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp +++ b/test/fuzztest/inputmethodcontroller_fuzzer/inputmethodcontroller_fuzzer.cpp @@ -77,10 +77,11 @@ void TestDispatchKeyEvent(sptr imc, int32_t fuzzedInt32) } imc->Attach(textListener); imc->isBound_.store(true); - imc->isEditable_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; std::shared_ptr keyEvent = MMI::KeyEvent::Create(); + if (keyEvent == nullptr) { + return; + } keyEvent->SetKeyAction(fuzzedInt32); keyEvent->SetKeyCode(fuzzedInt32); imc->DispatchKeyEvent(keyEvent, [](std::shared_ptr &keyEvent, bool isConsumed) {}); @@ -95,8 +96,6 @@ void TestOnSelectionChange(sptr imc, std::u16string fuzze } imc->Attach(textListener); imc->isBound_.store(true); - imc->isEditable_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; CursorInfo cursorInfo; cursorInfo.height = fuzzedDouble; @@ -116,7 +115,6 @@ void TestOnConfigurationChange(sptr imc) } imc->Attach(textListener); imc->isBound_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; Configuration info; EnterKeyType keyType = EnterKeyType::DONE; @@ -144,49 +142,12 @@ void TestSetCallingWindow(sptr imc, uint32_t fuzzedUInt32 return; } imc->Attach(textListener); - imc->isBound_.store(true); - imc->isEditable_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; imc->SetCallingWindow(fuzzedUInt32); imc->ShowSoftKeyboard(); imc->HideSoftKeyboard(); } -void TestShowSomething(sptr imc) -{ - sptr textListener = new TextListener(); - if (textListener == nullptr) { - return; - } - imc->Attach(textListener); - imc->isBound_.store(true); - imc->isEditable_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; - imc->ShowCurrentInput(); - imc->HideCurrentInput(); - - imc->ShowTextInput(); - imc->Attach(textListener); - imc->isBound_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; - imc->HideTextInput(); - - imc->GetCurrentInputMethod(); - imc->GetCurrentInputMethodSubtype(); - - imc->StopInputSession(); - imc->Attach(textListener); - imc->isBound_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; - imc->Close(); - imc->WasAttached(); - imc->clientInfo_.state = ClientState::ACTIVE; - imc->IsEditable(); - imc->clientInfo_.state = ClientState::ACTIVE; - imc->IsBound(); -} - void TestUpdateListenEventFlag(sptr imc, uint32_t fuzzedUint32) { imc->UpdateListenEventFlag(static_cast(fuzzedUint32), static_cast(fuzzedUint32), true); @@ -207,32 +168,10 @@ void TestAttach(sptr imc, int32_t fuzzedInt32) imc->Attach(textListener, false, inputAttribute); } -void FUZZHideInput(sptr imc) -{ - sptr client = new (std::nothrow) InputClientServiceImpl(); - imc->HideInput(client); - imc->RequestHideInput(); -} - -void FUZZShowInput(sptr imc) -{ - sptr client = new (std::nothrow) InputClientServiceImpl(); - imc->ShowInput(client); - imc->RequestShowInput(); -} - void FUZZRestore(sptr imc) { - sptr textListener = new TextListener(); - if (textListener == nullptr) { - return; - } - imc->Attach(textListener); imc->RestoreListenEventFlag(); imc->RestoreListenInfoInSaDied(); - imc->isBound_.store(true); - imc->isEditable_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; imc->RestoreClientInfoInSaDied(); } @@ -258,14 +197,6 @@ void FUZZPrintLogIfAceTimeout(sptr imc, int64_t start) imc->PrintLogIfAceTimeout(start); } -void FUZZSendPrivateData(sptr imc, const std::string &fuzzedString) -{ - std::unordered_map fuzzedPrivateCommand; - PrivateDataValue privateDataValue = std::string(fuzzedString); - fuzzedPrivateCommand.emplace("value", privateDataValue); - imc->SendPrivateData(fuzzedPrivateCommand); -} - void FUZZGetInputStartInfo(sptr imc, bool &dataBool, uint32_t &callingWndId, int32_t &int32Value, const std::string &fuzzedString) { @@ -319,14 +250,10 @@ void FUZZSetControllerListener(sptr imc, imc->GetInputMethodConfig(inputMethodConfig); imc->OnRemoteSaDied(agentObject); imc->ListCurrentInputMethodSubtype(subProps); - imc->isBound_.store(true); - imc->isEditable_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; imc->SendPrivateCommand(privateCommand); imc->Reset(); imc->IsDefaultImeSet(); } - void TestShowTextInputInner(sptr imc, const uint8_t *data, size_t size) { sptr textListener = new TextListener(); @@ -338,28 +265,13 @@ void TestShowTextInputInner(sptr imc, const uint8_t *data std::vector msgParam; msgParam.push_back(*data); std::unordered_map privateCommand; - PrivateDataValue privateDataValue1 = fuzzedString; - PrivateDataValue privateDataValue2 = static_cast(fuzzedBool); - PrivateDataValue privateDataValue3 = PRIVATEDATAVALUE; - privateCommand.emplace("value1", privateDataValue1); - privateCommand.emplace("value2", privateDataValue2); - privateCommand.emplace("value3", privateDataValue3); - ArrayBuffer arrayBuffer; - arrayBuffer.jsArgc = size; - arrayBuffer.msgId = fuzzedString; - arrayBuffer.msgParam = msgParam; imc->Attach(textListener); - imc->isBound_.store(true); - imc->clientInfo_.state = ClientState::ACTIVE; AttachOptions attachOptions; attachOptions.isShowKeyboard = fuzzedBool; - attachOptions.isSimpleKeyboardEnabled = fuzzedBool; attachOptions.requestKeyboardReason = RequestKeyboardReason::NONE; ClientType clientType = ClientType::INNER_KIT; imc->ShowTextInputInner(attachOptions, clientType); imc->isEditable_.store(true); - imc->SendMessage(arrayBuffer); - imc->RecvMessage(arrayBuffer); imc->SendPrivateData(privateCommand); } @@ -382,6 +294,9 @@ void FUZZOnTextChangedListener(const uint8_t *data, size_t size) std::shared_ptr runner = AppExecFwk::EventRunner::Create("eventHandlerTextListener"); auto handler = std::make_shared(runner); sptr eventHandlerTextListener = new (std::nothrow) EventHandlerTextListenerImpl(handler); + if (eventHandlerTextListener == nullptr) { + return; + } std::unordered_map privateCommand; PrivateDataValue privateDataValue1 = fuzzedString; PrivateDataValue privateDataValue2 = static_cast(fuzzBool); @@ -410,12 +325,38 @@ void FUZZOnTextChangedListener(const uint8_t *data, size_t size) eventHandlerTextListener->FinishTextPreviewV2(); eventHandlerTextListener->SetPreviewTextV2(fuzzedU16String, range); } + +void FUZZCovered(sptr imc, const uint8_t *data, size_t size) +{ + std::string fuzzedString(reinterpret_cast(data), size); + std::vector msgParam; + msgParam.push_back(*data); + ArrayBuffer arrayBuffer; + arrayBuffer.jsArgc = size; + arrayBuffer.msgId = fuzzedString; + arrayBuffer.msgParam = msgParam; + imc->HideTextInput(); + imc->GetCurrentInputMethod(); + imc->GetCurrentInputMethodSubtype(); + imc->ShowCurrentInput(); + imc->HideCurrentInput(); + imc->ShowTextInput(); + imc->HideTextInput(); + imc->GetCurrentInputMethod(); + imc->GetCurrentInputMethodSubtype(); + imc->SendMessage(arrayBuffer); + imc->RecvMessage(arrayBuffer); + imc->Close(); +} } // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { /* Run your code on data */ + if (data == nullptr || size == 0) { + return 0; + } FuzzedDataProvider provider(data, size); std::string fuzzedString(data, data + size); std::u16string fuzzedU16String = u"insert text"; @@ -437,17 +378,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::TestSwitchInputMethod(fuzzedTrigger, imc, fuzzedString); OHOS::TestSetCallingWindow(imc, fuzzedUint32); OHOS::TestDispatchKeyEvent(imc, fuzzedInt32); - OHOS::TestShowSomething(imc); - OHOS::FUZZHideInput(imc); - OHOS::FUZZShowInput(imc); OHOS::FUZZRestore(imc); OHOS::InputType(imc); OHOS::FUZZIsPanelShown(imc, data); OHOS::FUZZPrintLogIfAceTimeout(imc, fuzzedint64); OHOS::TestUpdateListenEventFlag(imc, fuzzedUint32); - OHOS::FUZZSendPrivateData(imc, fuzzedString); OHOS::FUZZGetInputStartInfo(imc, fuzzedBool, fuzzedUint32, fuzzedInt32, fuzzedString); OHOS::FUZZSetControllerListener(imc, fuzzedUint32, fuzzedString, fuzzedBool); OHOS::TestShowTextInputInner(imc, data, size); + OHOS::FUZZCovered(imc, data, size); return 0; } diff --git a/test/fuzztest/inputmethodsystemability_fuzzer/inputmethodsystemability_fuzzer.cpp b/test/fuzztest/inputmethodsystemability_fuzzer/inputmethodsystemability_fuzzer.cpp index 5b099bdf3..da4553ddd 100644 --- a/test/fuzztest/inputmethodsystemability_fuzzer/inputmethodsystemability_fuzzer.cpp +++ b/test/fuzztest/inputmethodsystemability_fuzzer/inputmethodsystemability_fuzzer.cpp @@ -27,15 +27,14 @@ #include "fuzzer/FuzzedDataProvider.h" #include "global.h" #include "ime_cfg_manager.h" -#include "ime_enabled_info_manager.h" #include "input_method_controller.h" -#include "input_method_core_service_impl.h" #include "inputmethodsystemability_fuzzer.h" +#include "input_method_core_service_impl.h" +#include "system_cmd_channel_service_impl.h" #include "iservice_registry.h" #include "message_parcel.h" #include "nativetoken_kit.h" #include "system_ability_definition.h" -#include "system_cmd_channel_service_impl.h" #include "text_listener.h" #include "token_setproc.h" diff --git a/test/fuzztest/systemcmdchannelstub_fuzzer/systemcmdchannelstub_fuzzer.cpp b/test/fuzztest/systemcmdchannelstub_fuzzer/systemcmdchannelstub_fuzzer.cpp index abddf70a0..05dcddecf 100644 --- a/test/fuzztest/systemcmdchannelstub_fuzzer/systemcmdchannelstub_fuzzer.cpp +++ b/test/fuzztest/systemcmdchannelstub_fuzzer/systemcmdchannelstub_fuzzer.cpp @@ -26,7 +26,6 @@ using namespace OHOS::MiscServices; namespace OHOS { constexpr size_t THRESHOLD = 10; constexpr int32_t OFFSET = 4; -constexpr int32_t PRIVATEDATAVALUE = 100; const std::u16string AGENTSTUB_INTERFACE_TOKEN = u"OHOS.MiscServices.ISystemCmdChannel"; uint32_t ConvertToUint32(const uint8_t *ptr) { @@ -39,23 +38,14 @@ uint32_t ConvertToUint32(const uint8_t *ptr) bool FuzzSystemCmdChannelStub(const uint8_t *rawData, size_t size) { FuzzedDataProvider provider(rawData, size); - InputType fuzzedBool = static_cast(rawData[0] % 2); + InputType inputType = static_cast(provider.ConsumeIntegral()); auto fuzzedUint32 = provider.ConsumeIntegral(); uint32_t code = ConvertToUint32(rawData); rawData = rawData + OFFSET; size = size - OFFSET; - SysPanelStatus sysPanelStatus = {fuzzedBool, 0, fuzzedUint32, fuzzedUint32}; - - std::unordered_map privateCommand; - PrivateDataValue privateDataValue1 = std::string("stringValue"); - PrivateDataValue privateDataValue2 = static_cast(fuzzedBool); - PrivateDataValue privateDataValue3 = PRIVATEDATAVALUE; - privateCommand.emplace("value1", privateDataValue1); - privateCommand.emplace("value2", privateDataValue2); - privateCommand.emplace("value3", privateDataValue3); - + SysPanelStatus sysPanelStatus = {inputType, 0, fuzzedUint32, fuzzedUint32}; MessageParcel data; data.WriteInterfaceToken(AGENTSTUB_INTERFACE_TOKEN); data.WriteBuffer(rawData, size); @@ -64,7 +54,6 @@ bool FuzzSystemCmdChannelStub(const uint8_t *rawData, size_t size) MessageOption option; sptr stub = new SystemCmdChannelServiceImpl(); - stub->SendPrivateCommand(privateCommand); stub->NotifyPanelStatus(sysPanelStatus); stub->OnRemoteRequest(code, data, reply, option); return true; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 7833747e3..a8fba2964 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -49,7 +49,6 @@ group("unittest") { "cpp_test:NewImeSwitchTest", "cpp_test:NumKeyAppsManagerTest", "cpp_test:OnDemandStartStopSaTest", - "cpp_test:SaTaskManagerTest", "cpp_test:StringUtilsTest", "cpp_test:TaskManagerTest", "cpp_test:TextListenerInnerApiTest", diff --git a/test/unittest/cpp_test/BUILD.gn b/test/unittest/cpp_test/BUILD.gn index ec109c267..7d0294ea0 100644 --- a/test/unittest/cpp_test/BUILD.gn +++ b/test/unittest/cpp_test/BUILD.gn @@ -582,9 +582,9 @@ ohos_unittest("InputMethodPrivateMemberTest") { ] external_deps = [ + "ability_runtime:ability_connect_callback_stub", "ability_runtime:ability_manager", "ability_runtime:runtime", - "ability_runtime:ability_connect_callback_stub", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", @@ -731,6 +731,43 @@ ohos_unittest("NewImeSwitchTest") { } } +ohos_unittest("NumKeyAppsManagerTest") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path + include_dirs = [ "${inputmethod_path}/common/include" ] + sources = [ "src/numkey_apps_manager_test.cpp" ] + + configs = [ ":module_private_config" ] + deps = [ + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", + "${inputmethod_path}/services:inputmethod_service_static", + "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", + "${inputmethod_path}/services/file:imf_file_static", + "${inputmethod_path}/services/json:imf_json_static", + "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "config_policy:configpolicy_util", + "data_share:datashare_common", + "data_share:datashare_consumer", + "googletest:gtest_main", + "hilog:libhilog", + "init:libbeget_proxy", + "init:libbegetutil", + "input:libmmi-client", + "resource_management:global_resmgr", + ] +} + ohos_unittest("IdentityCheckerTest") { branch_protector_ret = "pac_ret" sanitize = { @@ -846,23 +883,14 @@ ohos_unittest("ImeProxyAgentImeTest") { module_out_path = module_output_path sources = [ - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_info.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_tools.cpp", "${inputmethod_path}/services/src/sys_cfg_parser.cpp", - "${inputmethod_path}/test/common/src/keyboard_listener_test_impl.cpp", "src/ime_proxy_agent_ime_test.cpp", ] configs = [ ":module_private_config" ] deps = [ - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_control_channel_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_method_core_stub", "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_client_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_method_agent_proxy", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", "${inputmethod_path}/services:inputmethod_service", "${inputmethod_path}/services/file:imf_file_static", @@ -1441,7 +1469,7 @@ ohos_unittest("WindowAdapterTest") { } } -ohos_unittest("InputMethodManagerCommandTest") { +ohos_unittest("ImaTextEditTest") { branch_protector_ret = "pac_ret" sanitize = { cfi = true @@ -1451,81 +1479,54 @@ ohos_unittest("InputMethodManagerCommandTest") { module_out_path = module_output_path sources = [ - "${inputmethod_path}/tools/ime/src/input_method_manager_command.cpp", - "src/input_method_manager_command_test.cpp", - ] - - include_dirs = [ - "include", - "${inputmethod_path}/tools/ime/include", - "${inputmethod_path}/common/include", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", - ] - - deps = [ - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", - "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", - "${inputmethod_path}/test/unittest/resource/bundle_dependencies/newTestIme:newTestIme", - "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", - ] - - external_deps = [ - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "hilog:libhilog", - "input:libmmi-client", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_info.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_service_impl.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp", + "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_tools.cpp", + "${inputmethod_path}/test/common/src/keyboard_listener_test_impl.cpp", + "src/ima_text_edit_test.cpp", ] - if (window_manager_use_sceneboard) { - external_deps += [ "window_manager:libwm_lite" ] - } else { - external_deps += [ "window_manager:libwm" ] - } -} - -ohos_unittest("ImeEnabledInfoManagerTest") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - module_out_path = module_output_path - include_dirs = [ "${inputmethod_path}/common/include" ] - sources = [ "src/ime_enabled_info_manager_test.cpp" ] - configs = [ ":module_private_config" ] + deps = [ + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_control_channel_proxy", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_method_core_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_client_stub", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_method_agent_proxy", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", - "${inputmethod_path}/services:inputmethod_service_static", - "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", - "${inputmethod_path}/services/file:imf_file_static", - "${inputmethod_path}/services/json:imf_json_static", + "${inputmethod_path}/services:inputmethod_service", + "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", - "${inputmethod_path}/test/unittest/resource/bundle_dependencies/newTestIme:newTestIme", + "${inputmethod_path}/test/unittest/resource/bundle_dependencies/editorBox:editorBox", "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ "ability_base:want", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:runtime", + "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", - "config_policy:configpolicy_util", - "data_share:datashare_common", - "data_share:datashare_consumer", "googletest:gtest_main", + "graphic_2d:librender_service_client", + "graphic_2d:window_animation", "hilog:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", "input:libmmi-client", - "resource_management:global_resmgr", + "ipc:ipc_single", + "napi:ace_napi", + "safwk:system_ability_fwk", + "window_manager:libdm", ] + if (window_manager_use_sceneboard) { external_deps += [ "window_manager:libwm_lite" ] } else { external_deps += [ "window_manager:libwm" ] } - if (build_selinux) { external_deps += [ "selinux_adapter:librestorecon" ] cflags = [ "-DWITH_SELINUX" ] @@ -1556,7 +1557,7 @@ ohos_unittest("StringUtilsTest") { ] } -ohos_unittest("NumKeyAppsManagerTest") { +ohos_unittest("InputMethodManagerCommandTest") { branch_protector_ret = "pac_ret" sanitize = { cfi = true @@ -1564,36 +1565,41 @@ ohos_unittest("NumKeyAppsManagerTest") { debug = false } module_out_path = module_output_path - include_dirs = [ "${inputmethod_path}/common/include" ] - sources = [ "src/numkey_apps_manager_test.cpp" ] - configs = [ ":module_private_config" ] + sources = [ + "${inputmethod_path}/tools/ime/src/input_method_manager_command.cpp", + "src/input_method_manager_command_test.cpp", + ] + + include_dirs = [ + "include", + "${inputmethod_path}/tools/ime/include", + "${inputmethod_path}/common/include", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", + ] + deps = [ - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", - "${inputmethod_path}/services:inputmethod_service_static", - "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", - "${inputmethod_path}/services/file:imf_file_static", - "${inputmethod_path}/services/json:imf_json_static", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/bundle_dependencies/newTestIme:newTestIme", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ - "ability_base:want", "bundle_framework:appexecfwk_core", "c_utils:utils", - "config_policy:configpolicy_util", - "data_share:datashare_common", - "data_share:datashare_consumer", - "googletest:gtest_main", "hilog:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", "input:libmmi-client", - "resource_management:global_resmgr", ] + + if (window_manager_use_sceneboard) { + external_deps += [ "window_manager:libwm_lite" ] + } else { + external_deps += [ "window_manager:libwm" ] + } } -ohos_unittest("SaTaskManagerTest") { +ohos_unittest("ImeEnabledInfoManagerTest") { branch_protector_ret = "pac_ret" sanitize = { cfi = true @@ -1601,110 +1607,35 @@ ohos_unittest("SaTaskManagerTest") { debug = false } module_out_path = module_output_path - include_dirs = [ - "${inputmethod_path}/common/include", - "${inputmethod_path}/frameworks/native/inputmethod_ability/include/actions", - "${inputmethod_path}/services/task_manager/include", - "${inputmethod_path}/services/task_manager/include/actions", - "${inputmethod_path}/services/task_manager/include/tasks", - ] - sources = [ - "${inputmethod_path}/frameworks/native/common/src/service_response_data.cpp", - "${inputmethod_path}/services/task_manager/src/actions/sa_action.cpp", - "${inputmethod_path}/services/task_manager/src/actions/sa_action_wait.cpp", - "${inputmethod_path}/services/task_manager/src/requester_manager.cpp", - "${inputmethod_path}/services/task_manager/src/sa_task_manager.cpp", - "${inputmethod_path}/services/task_manager/src/tasks/sa_task.cpp", - "src/sa_task_manager_test.cpp", - ] + include_dirs = [ "${inputmethod_path}/common/include" ] + sources = [ "src/ime_enabled_info_manager_test.cpp" ] configs = [ ":module_private_config" ] deps = [ - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:ima_response_channel_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:ima_response_channel_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:ima_response_channel_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:imc_response_channel_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:imc_response_channel_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:imc_response_channel_stub", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", "${inputmethod_path}/services:inputmethod_service_static", "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", "${inputmethod_path}/services/file:imf_file_static", "${inputmethod_path}/services/json:imf_json_static", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/bundle_dependencies/newTestIme:newTestIme", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ "ability_base:want", - "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", "config_policy:configpolicy_util", "data_share:datashare_common", "data_share:datashare_consumer", "googletest:gtest_main", - "hicollie:libhicollie", "hilog:libhilog", "init:libbeget_proxy", "init:libbegetutil", "input:libmmi-client", "resource_management:global_resmgr", ] -} - -ohos_unittest("ImaTextEditTest") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - module_out_path = module_output_path - - sources = [ - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_info.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp", - "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_tools.cpp", - "${inputmethod_path}/test/common/src/keyboard_listener_test_impl.cpp", - "src/ima_text_edit_test.cpp", - ] - - configs = [ ":module_private_config" ] - - deps = [ - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_control_channel_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:input_method_core_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_client_stub", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:input_method_agent_proxy", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", - "${inputmethod_path}/services:inputmethod_service", - "${inputmethod_path}/test/common:inputmethod_test_common", - "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", - "${inputmethod_path}/test/unittest/resource/bundle_dependencies/editorBox:editorBox", - "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "ability_runtime:runtime", - "access_token:libaccesstoken_sdk", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "googletest:gtest_main", - "graphic_2d:librender_service_client", - "graphic_2d:window_animation", - "hilog:libhilog", - "input:libmmi-client", - "ipc:ipc_single", - "napi:ace_napi", - "safwk:system_ability_fwk", - "window_manager:libdm", - ] - if (window_manager_use_sceneboard) { external_deps += [ "window_manager:libwm_lite" ] } else { diff --git a/test/unittest/cpp_test/common/include/identity_checker_mock.h b/test/unittest/cpp_test/common/include/identity_checker_mock.h index 62c38c2ce..7db9d79b8 100644 --- a/test/unittest/cpp_test/common/include/identity_checker_mock.h +++ b/test/unittest/cpp_test/common/include/identity_checker_mock.h @@ -51,7 +51,7 @@ public: } bool IsFormShell(Security::AccessToken::AccessTokenID tokenId) override { - return IsFormShell_; + return isFormShell_; } std::string GetBundleNameByToken(uint32_t tokenId) override { @@ -72,8 +72,8 @@ public: isBundleNameValid_ = false; hasPermission_ = false; isBroker_ = false; + isFormShell_ = false; isNativeSa_ = false; - IsFormShell_ = false; isSpecialSaUid_ = false; bundleName_ = ""; } @@ -118,7 +118,7 @@ private: static bool hasPermission_; static bool isBroker_; static bool isNativeSa_; - static bool IsFormShell_; + static bool isFormShell_; static bool isSpecialSaUid_; static std::string bundleName_; }; @@ -128,7 +128,7 @@ bool IdentityCheckerMock::isBundleNameValid_ { false }; bool IdentityCheckerMock::hasPermission_ { false }; bool IdentityCheckerMock::isBroker_ { false }; bool IdentityCheckerMock::isNativeSa_ { false }; -bool IdentityCheckerMock::IsFormShell_ { false }; +bool IdentityCheckerMock::isFormShell_ { false }; bool IdentityCheckerMock::isSpecialSaUid_ { false }; std::string IdentityCheckerMock::bundleName_; } // namespace MiscServices diff --git a/test/unittest/cpp_test/src/identity_checker_test.cpp b/test/unittest/cpp_test/src/identity_checker_test.cpp index 0357de838..953acc765 100644 --- a/test/unittest/cpp_test/src/identity_checker_test.cpp +++ b/test/unittest/cpp_test/src/identity_checker_test.cpp @@ -813,7 +813,6 @@ 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/ima_text_edit_test.cpp b/test/unittest/cpp_test/src/ima_text_edit_test.cpp index 8dc8eca6a..bbdb8f4a8 100644 --- a/test/unittest/cpp_test/src/ima_text_edit_test.cpp +++ b/test/unittest/cpp_test/src/ima_text_edit_test.cpp @@ -444,7 +444,6 @@ HWTEST_F(ImaTextEditTest, ImaTextEditTest_ClearRspHandlers, TestSize.Level0) channelWrap->ClearRspHandlers(); }; std::thread delayThread(delayTask); - delayThread.detach(); channelWrap->AddRspHandler(GetForwardRsp, false); channelWrap->AddRspHandler(GetForwardRsp, false); @@ -452,6 +451,7 @@ HWTEST_F(ImaTextEditTest, ImaTextEditTest_ClearRspHandlers, TestSize.Level0) auto ret = channelWrap->WaitResponse(handler, nullptr); EXPECT_EQ(ret, ErrorCode::ERROR_IMA_DATA_CHANNEL_ABNORMAL); EXPECT_TRUE(WaitGetForwardRspAbnormal(2)); + delayThread.detach(); } /** diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index 6e8086070..c339c83b6 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -72,8 +72,8 @@ public: static int32_t currentImeUid_; static sptr imsa_; static sptr imsaProxy_; - static constexpr int MAXRUNCOUNT = 100; - static constexpr int THREAD_NUM = 5; + static constexpr int32_t MAXRUNCOUNT = 100; + static constexpr int32_t THREAD_NUM = 5; static void TestOnConnectSystemCmd(); static std::atomic multiThreadExecTotalNum_; @@ -169,7 +169,6 @@ public: auto currentIme = property != nullptr ? property->name : "default.inputmethod.unittest"; currentImeTokenId_ = TddUtil::GetTestTokenID(currentIme); currentImeUid_ = TddUtil::GetUid(currentIme); - inputMethodAbility_.abilityManager_ = imsaProxy_; TddUtil::InitCurrentImePermissionInfo(); IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_); @@ -389,9 +388,6 @@ HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize. auto ret = coreProxy->ShowKeyboard(static_cast(RequestKeyboardReason::NONE)); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - ret = coreProxy->InitInputControlChannel(nullptr); - EXPECT_EQ(ERR_INVALID_DATA, ret); - std::this_thread::sleep_for(std::chrono::seconds(1)); EXPECT_EQ(showKeyboard_, true); } @@ -556,7 +552,7 @@ HWTEST_F(InputMethodAbilityTest, testStartInput, TestSize.Level0) clientInfo.channel = channelStub; auto ret = inputMethodAbility_.StartInput(clientInfo, false); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(inputMethodAbility_.isNotify_); + EXPECT_TRUE(inputMethodAbility_.isInputStartNotified_); } /** @@ -653,10 +649,6 @@ HWTEST_F(InputMethodAbilityTest, testMoveCursor, TestSize.Level0) auto ret = inputMethodAbility_.MoveCursor(keyCode); // move cursor right }); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_TRUE(TextListener::WaitMoveCursor(keyCode)); - - ret = InputMethodAbilityInterface::GetInstance().MoveCursor(keyCode); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(TextListener::WaitMoveCursor(keyCode)); } /** @@ -728,14 +720,7 @@ HWTEST_F(InputMethodAbilityTest, testDeleteText, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_TRUE(TextListener::WaitDeleteBackward(deleteForwardLenth)); - ret = InputMethodAbilityInterface::GetInstance().DeleteForward(deleteForwardLenth); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(TextListener::WaitDeleteBackward(deleteForwardLenth)); - int32_t deleteBackwardLenth = 2; - ret = InputMethodAbilityInterface::GetInstance().DeleteBackward(deleteBackwardLenth); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_TRUE(TextListener::WaitDeleteForward(deleteBackwardLenth)); ret = inputMethodAbility_.DeleteBackward(deleteBackwardLenth); EXPECT_EQ(ret, ErrorCode::NO_ERROR); EXPECT_TRUE(TextListener::WaitDeleteForward(deleteBackwardLenth)); @@ -1214,7 +1199,7 @@ HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_002, TestSize.Level0) HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_003, TestSize.Level0) { IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_003 START"); - imc_->Attach(textListener_); + imc_->Attach(textListener_, false); PanelInfo panelInfo = {}; panelInfo.panelType = STATUS_BAR; auto panel = std::make_shared(); @@ -1777,10 +1762,10 @@ HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_003, TestSize.Level0) } /** - *@tc.name: testGetInputMethodState_001 - *@tc.desc: IMA - *@tc.type: FUNC - *@tc.require: + * @tc.name: testGetInputMethodState_001 + * @tc.desc: IMA + * @tc.type: FUNC + * @tc.require: */ HWTEST_F(InputMethodAbilityTest, testGetInputMethodState_001, TestSize.Level0) { @@ -2164,19 +2149,6 @@ HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_011, TestSize.Level0) InputMethodAbilityTest::GetIMCDetachIMA(); } -/** - * @tc.name: testInitPasteBoardstart_001 - * @tc.desc: testInitPasteBoardstart_001 - * @tc.type: FUNC - */ -HWTEST_F(InputMethodAbilityTest, testInitPasteBoardstart_001, TestSize.Level1) -{ - IMSA_HILOGI("InputMethodAbilityTest testInitPasteBoardstart_001 START"); - ASSERT_NE(imsa_, nullptr); - auto ret = imsa_->InitPasteboardMonitor(); - EXPECT_TRUE(ret); - imsa_->HandlePasteboardStarted(); -} /** * @tc.name: testInvokeAttachOptionsCallback * @tc.desc: testInvokeAttachOptionsCallback @@ -2202,6 +2174,20 @@ HWTEST_F(InputMethodAbilityTest, testInvokeAttachOptionsCallback, TestSize.Level EXPECT_FALSE(ret); } +/** + * @tc.name: testInitPasteBoardstart_001 + * @tc.desc: testInitPasteBoardstart_001 + * @tc.type: FUNC + */ +HWTEST_F(InputMethodAbilityTest, testInitPasteBoardstart_001, TestSize.Level1) +{ + IMSA_HILOGI("InputMethodAbilityTest testInitPasteBoardstart_001 START"); + ASSERT_NE(imsa_, nullptr); + auto ret = imsa_->InitPasteboardMonitor(); + EXPECT_TRUE(ret); + imsa_->HandlePasteboardStarted(); +} + /** * @tc.name: testClearBindInfo * @tc.desc: testClearBindInfo diff --git a/test/unittest/cpp_test/src/input_method_controller_test.cpp b/test/unittest/cpp_test/src/input_method_controller_test.cpp index 5df383aab..02caa18ce 100644 --- a/test/unittest/cpp_test/src/input_method_controller_test.cpp +++ b/test/unittest/cpp_test/src/input_method_controller_test.cpp @@ -61,7 +61,6 @@ #include "key_event_util.h" #include "keyboard_listener.h" #include "message_parcel.h" -#include "notify_service_impl.h" #include "scope_utils.h" #include "system_ability.h" #include "system_ability_definition.h" @@ -135,6 +134,9 @@ public: static void CheckTextConfig(const TextConfig &config); static void ResetKeyboardListenerTextConfig(); static void EditorContentMultiTest(); + static sptr GetController(); + static sptr GetTextListener(); + static std::mutex controllerMutex_; static sptr inputMethodController_; static InputMethodAbility &inputMethodAbility_; static sptr imsa_; @@ -142,11 +144,13 @@ public: static std::shared_ptr keyEvent_; static std::shared_ptr imeListener_; static std::shared_ptr controllerListener_; + static std::mutex textListenerMutex_; static sptr textListener_; static std::mutex keyboardListenerMutex_; static std::condition_variable keyboardListenerCv_; static BlockData> blockKeyEvent_; static BlockData> blockFullKeyEvent_; + static BlockData isNotifyFinished_; static std::mutex onRemoteSaDiedMutex_; static std::condition_variable onRemoteSaDiedCv_; static sptr deathRecipient_; @@ -168,7 +172,7 @@ public: static constexpr int32_t TASK_DELAY_TIME = 10; static constexpr int32_t EACH_THREAD_CIRCULATION_TIME = 100; static constexpr int32_t THREAD_NUM = 5; - static int32_t multiThreadExecTotalNum_; + static std::atomic multiThreadExecTotalNum_; class KeyboardListenerImpl : public KeyboardListener { public: @@ -246,6 +250,7 @@ public: } }; }; +std::mutex InputMethodControllerTest::controllerMutex_; sptr InputMethodControllerTest::inputMethodController_; InputMethodAbility &InputMethodControllerTest::inputMethodAbility_ = InputMethodAbility::GetInstance(); sptr InputMethodControllerTest::imsa_; @@ -253,6 +258,7 @@ sptr InputMethodControllerTest::imsaProxy_; std::shared_ptr InputMethodControllerTest::keyEvent_; std::shared_ptr InputMethodControllerTest::imeListener_; std::shared_ptr InputMethodControllerTest::controllerListener_; +std::mutex InputMethodControllerTest::textListenerMutex_; sptr InputMethodControllerTest::textListener_; CursorInfo InputMethodControllerTest::cursorInfo_ = {}; int32_t InputMethodControllerTest::oldBegin_ = 0; @@ -272,13 +278,16 @@ BlockData> InputMethodControllerTest::blockKeyEve BlockData> InputMethodControllerTest::blockFullKeyEvent_ { InputMethodControllerTest::KEY_EVENT_DELAY_TIME, nullptr }; +BlockData InputMethodControllerTest::isNotifyFinished_ { + false, PerUserSession::MAX_NOTIFY_TIME +}; bool InputMethodControllerTest::doesKeyEventConsume_ { false }; bool InputMethodControllerTest::doesFUllKeyEventConsume_ { false }; std::condition_variable InputMethodControllerTest::keyEventCv_; std::mutex InputMethodControllerTest::keyEventLock_; bool InputMethodControllerTest::consumeResult_ { false }; std::shared_ptr InputMethodControllerTest::textConfigHandler_ { nullptr }; -int32_t InputMethodControllerTest::multiThreadExecTotalNum_{ 0 }; +std::atomic InputMethodControllerTest::multiThreadExecTotalNum_{ 0 }; void InputMethodControllerTest::SetUpTestCase(void) { @@ -539,16 +548,32 @@ void InputMethodControllerTest::EditorContentMultiTest() { for (int32_t i = 0; i < EACH_THREAD_CIRCULATION_TIME; i++) { InputAttribute inputAttribute = { .isTextPreviewSupported = true }; - inputMethodController_->Attach(textListener_, false, inputAttribute); + auto controller = GetController(); + ASSERT_NE(controller, nullptr); + auto listener = GetTextListener(); + ASSERT_NE(listener, nullptr); + controller->Attach(listener, false, inputAttribute); std::u16string text = Str8ToStr16("testSelect"); int start = 1; int end = 2; - inputMethodController_->OnSelectionChange(text, start, end); - inputMethodController_->OnInputStop(); - multiThreadExecTotalNum_++; + controller->OnSelectionChange(text, start, end); + controller->OnInputStop(); + multiThreadExecTotalNum_.fetch_add(1, std::memory_order_relaxed); } } +sptr InputMethodControllerTest::GetController() +{ + std::lock_guard lock(controllerMutex_); + return inputMethodController_; +} + +sptr InputMethodControllerTest::GetTextListener() +{ + std::lock_guard lock(textListenerMutex_); + return textListener_; +} + /** * @tc.name: testIMCAttach001 * @tc.desc: IMC Attach. @@ -2121,7 +2146,7 @@ HWTEST_F(InputMethodControllerTest, TestSetSimpleKeyboardEnabled, TestSize.Level HWTEST_F(InputMethodControllerTest, TestNotifyOnInputStopFinished001, TestSize.Level0) { IMSA_HILOGI("TestNotifyOnInputStopFinished001 START"); - sptr proxy = new (std::nothrow) OnInputStopNotifyServiceImpl(); + sptr proxy = new (std::nothrow) OnInputStopNotifyServiceImpl(getpid()); ASSERT_NE(proxy, nullptr); std::shared_ptr channelProxy = std::make_shared(proxy); auto sessionTemp = std::make_shared(0, nullptr); @@ -2130,10 +2155,29 @@ HWTEST_F(InputMethodControllerTest, TestNotifyOnInputStopFinished001, TestSize.L EXPECT_EQ(ret, ErrorCode::NO_ERROR); UserSessionManager::GetInstance().userSessions_.clear(); } + +/** + * @tc.name: testOnInputStopAsync + * @tc.desc: Bind IMSA. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodControllerTest, TestOnInputStopAsync, TestSize.Level0) +{ + IMSA_HILOGI("TestOnInputStopAsync START"); + auto sessionTemp = std::make_shared(0, nullptr); + sptr client = new (std::nothrow) InputClientServiceImpl(); + InputClientInfo clientInfo = { .client = client }; + std::shared_ptr sharedClientInfo = std::make_shared(clientInfo); + isNotifyFinished_.SetValue(false); + sessionTemp->StopClientInput(sharedClientInfo, false, false); + isNotifyFinished_.SetValue(true); + sessionTemp->StopClientInput(sharedClientInfo, false, false); + EXPECT_TRUE(isNotifyFinished_.GetValue()); +} /** * @tc.name: TestResponseDataChannel - * @tc.desc: Test ResponseDataChannel + * @tc.desc: Test ResponseDataChannel: agent channel isnullptr * @tc.type: FUNC */ HWTEST_F(InputMethodControllerTest, TestResponseDataChannel, TestSize.Level0) @@ -2154,10 +2198,10 @@ HWTEST_F(InputMethodControllerTest, TestResponseDataChannel, TestSize.Level0) HWTEST_F(InputMethodControllerTest, TestEditorContentLock, TestSize.Level0) { IMSA_HILOGI("InputMethodControllerTest::TestEditorContentLock START"); - multiThreadExecTotalNum_ = 0; + multiThreadExecTotalNum_.store(0); SET_THREAD_NUM(InputMethodControllerTest::THREAD_NUM); GTEST_RUN_TASK(InputMethodControllerTest::EditorContentMultiTest); - EXPECT_EQ(multiThreadExecTotalNum_, THREAD_NUM * EACH_THREAD_CIRCULATION_TIME); + EXPECT_EQ(multiThreadExecTotalNum_.load(), THREAD_NUM * EACH_THREAD_CIRCULATION_TIME); } /** diff --git a/test/unittest/cpp_test/src/input_method_manager_command_test.cpp b/test/unittest/cpp_test/src/input_method_manager_command_test.cpp index 3a026f107..efa1c7f74 100644 --- a/test/unittest/cpp_test/src/input_method_manager_command_test.cpp +++ b/test/unittest/cpp_test/src/input_method_manager_command_test.cpp @@ -201,22 +201,9 @@ HWTEST_F(InputMethodManagerCommandTest, ExeCmd_0010, TestSize.Level1) IMSA_HILOGI("InputMethodManagerCommandTest ExeCmd_0010 START"); sleep(2); std::string result; - auto ret = TddUtil::ExecuteCmd("ime -e", result); + auto ret = TddUtil::ExecuteCmd("ime -e \"\"", result); EXPECT_TRUE(ret); - EXPECT_EQ("\nInput Method Manager Command Line Tool\n" - "Usage: ime [OPTION] [ARGUMENT]\n\n" - "Options:\n" - " -e [-b | -f] Enable the specified input method to specified mode.\n" - " If the -b/-f option is not set, the default value is -b.\n" - " Current operation cannot be applied to the preconfigured" - " default input method.\n" - " -d Disable the specified input method.\n" - " -s Switch to the specified input method.\n" - " In the lock screen or password input box scenario," - " switching to other input methods is not allowed.\n" - " -g Get current input method.\n" - " -l List all input methods.\n" - " -h Show this help message.\n", result); + EXPECT_EQ("Error: Invalid argument!\n", result); } /** 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 5ec49b7a5..f1ebe9353 100644 --- a/test/unittest/cpp_test/src/input_method_panel_test.cpp +++ b/test/unittest/cpp_test/src/input_method_panel_test.cpp @@ -384,10 +384,8 @@ void InputMethodPanelTest::ImcPanelHideNumCheck(uint32_t num) EXPECT_EQ(ret, std::cv_status::timeout); return; } - bool ret = - imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), [&num] { - return num == imeHideCallbackNum_; - }); + bool ret = imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME), + [&num] { return num <= imeHideCallbackNum_; }); EXPECT_TRUE(ret); } @@ -2412,7 +2410,7 @@ HWTEST_F(InputMethodPanelTest, testPortraitAdjustmentNeeded, TestSize.Level0) * @tc.desc: Test testLargegradientHeight * @tc.type: FUNC */ -HWTEST_F(InputMethodPanelTest, testLargegradientHeight, TestSize.Level0) +HWTEST_F(InputMethodPanelTest, testLargegradientHeight, TestSize.Level1) { auto inputMethodPanel = std::make_shared(); KeyboardLayoutParams param; @@ -2430,6 +2428,7 @@ HWTEST_F(InputMethodPanelTest, testLargegradientHeight, TestSize.Level0) ret = inputMethodPanel->FullScreenPrepare(param, inputMethodPanel->immersiveEffect_); EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_RANGE); } + /** * @tc.name: testLandscapeAdjustmentNeeded * @tc.desc: Test testLandscapeAdjustmentNeeded @@ -2598,9 +2597,9 @@ HWTEST_F(InputMethodPanelTest, RestoreConfigWhenAdjustFails, TestSize.Level1) * @tc.desc: Test InitAdjustInfo * @tc.type: FUNC */ -HWTEST_F(InputMethodPanelTest, TestInitAdjustInfo, TestSize.Level1) +HWTEST_F(InputMethodPanelTest, TestInitAdjustInfo, TestSize.Level0) { - IMSA_HILOGI("InputMethodPanelTest::TestInitAdjustInfo"); + IMSA_HILOGI("InputMethodPanelTest::TestInitAdjustInfo."); auto panel = std::make_shared(); InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0; panel->isAdjustInfoInitialized_ = false; diff --git a/test/unittest/cpp_test/src/input_method_private_member_test.cpp b/test/unittest/cpp_test/src/input_method_private_member_test.cpp index b22bb83fa..3588f87e5 100644 --- a/test/unittest/cpp_test/src/input_method_private_member_test.cpp +++ b/test/unittest/cpp_test/src/input_method_private_member_test.cpp @@ -14,7 +14,6 @@ */ #define private public #define protected public -#include "client_group.h" #include "full_ime_info_manager.h" #include "ime_cfg_manager.h" #include "ime_info_inquirer.h" @@ -45,6 +44,10 @@ #include "iinput_method_agent.h" #include "iinput_method_core.h" #include "ime_cfg_manager.h" +#include "input_client_stub.h" +#include "input_method_agent_proxy.h" +#include "input_method_agent_stub.h" +#include "input_method_core_stub.h" #include "im_common_event_manager.h" #include "input_method_agent_service_impl.h" #include "input_method_core_service_impl.h" @@ -79,9 +82,6 @@ constexpr int32_t WAIT_ATTACH_FINISH_DELAY = 50; constexpr uint32_t MAX_ATTACH_COUNT = 100000; std::atomic InputMethodPrivateMemberTest::tryLockFailCount_ = 0; std::shared_ptr InputMethodPrivateMemberTest::session_ = nullptr; -constexpr const char *EVENT_LARGE_MEMORY_STATUS_CHANGED = "usual.event.memmgr.large_memory_status_changed"; -constexpr const char *EVENT_MEMORY_STATE = "memory_state"; -constexpr const char *EVENT_PARAM_UID = "uid"; void InputMethodPrivateMemberTest::TestImfStartIme() { auto imeToStart = std::make_shared(); @@ -92,6 +92,10 @@ void InputMethodPrivateMemberTest::TestImfStartIme() IMSA_HILOGI("tryLockFailCount_ is %{public}d.", tryLockFailCount_.load()); } } +constexpr const char *EVENT_LARGE_MEMORY_STATUS_CHANGED = "usual.event.memmgr.large_memory_status_changed"; +constexpr const char *EVENT_MEMORY_STATE = "memory_state"; +constexpr const char *EVENT_PARAM_UID = "uid"; + void InputMethodPrivateMemberTest::SetUpTestCase(void) { std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -601,6 +605,26 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_008, TestSize.L } } +/** + * @tc.name: SA_SwitchByCombinationKey_Handler + * @tc.desc: SwitchType():handler is nullptr + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_Handler, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_Handler TEST START"); + auto userId = TddUtil::GetCurrentUserId(); + service_->userId_ = userId; + service_->DealSwitchRequest(); + EXPECT_NE(service_->serviceHandler_, nullptr); + std::shared_ptr tempHandler = service_->serviceHandler_; + service_->serviceHandler_ = nullptr; + service_->DealSwitchRequest(); + EXPECT_EQ(service_->serviceHandler_, nullptr); + service_->serviceHandler_ = tempHandler; +} + /** * @tc.name: SA_testReleaseInput_001 * @tc.desc: client is nullptr @@ -628,16 +652,16 @@ HWTEST_F(InputMethodPrivateMemberTest, III_TestRestoreInputMethod_001, TestSize. std::string bundleName = ""; auto ret = service_->RestoreInputmethod(bundleName); EXPECT_EQ(ret, ErrorCode::ERROR_ENABLE_IME); - + auto userId = service_->GetCallingUserId(); auto currentProp = ImeInfoInquirer::GetInstance().GetCurrentInputMethod(userId); ret = service_->RestoreInputmethod(currentProp->name); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - + auto defaultIme = ImeInfoInquirer::GetInstance().GetDefaultIme(); ret = service_->RestoreInputmethod(defaultIme.bundleName); - EXPECT_TRUE(ret == ErrorCode::NO_ERROR ||ret == ErrorCode::ERROR_IMSA_REBOOT_OLD_IME_NOT_STOP); - + EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_IMSA_REBOOT_OLD_IME_NOT_STOP); + bundleName = "com.example.newTestIme"; EnabledStatus status = EnabledStatus::DISABLED; ImeInfoInquirer::GetInstance().systemConfig_.enableInputMethodFeature = true; @@ -908,7 +932,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestGetDefaultInputMethod_001, TestSize.L auto ret = ImeInfoInquirer::GetInstance().GetDefaultInputMethod(currentUserId, prop, false); EXPECT_EQ(ret, ErrorCode::NO_ERROR); } - + /** * @tc.name: TestGetDefaultInputMethod_002 * @tc.desc: TestGetDefaultInputMethod @@ -924,7 +948,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestGetDefaultInputMethod_002, TestSize.L auto ret = ImeInfoInquirer::GetInstance().GetDefaultInputMethod(currentUserId, prop, true); EXPECT_EQ(ret, ErrorCode::NO_ERROR); } - + /** * @tc.name: TestGetResMgr * @tc.desc: GetResMgr @@ -938,7 +962,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestGetResMgr, TestSize.Level0) auto ret = ImeInfoInquirer::GetInstance().GetResMgr("/test"); EXPECT_TRUE(ret != nullptr); } - + /** * @tc.name: TestQueryFullImeInfo * @tc.desc: QueryFullImeInfo @@ -953,7 +977,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestQueryFullImeInfo, TestSize.Level0) auto ret = ImeInfoInquirer::GetInstance().QueryFullImeInfo(currentUserId, infos); EXPECT_EQ(ret, ErrorCode::NO_ERROR); } - + /** * @tc.name: TestIsInputMethod * @tc.desc: IsInputMethod @@ -969,12 +993,12 @@ HWTEST_F(InputMethodPrivateMemberTest, TestIsInputMethod, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::NO_ERROR); } -/** -@tc.name: TestHandlePackageEvent -@tc.desc: TestHandlePackageEvent -@tc.type: FUNC -@tc.require: -*/ + /** + @tc.name: TestHandlePackageEvent + @tc.desc: TestHandlePackageEvent + @tc.type: FUNC + @tc.require: + */ HWTEST_F(InputMethodPrivateMemberTest, TestHandlePackageEvent, TestSize.Level0) { // msg is nullptr @@ -1001,7 +1025,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestHandlePackageEvent, TestSize.Level0) auto ret2 = service_->HandlePackageEvent(msg2.get()); EXPECT_EQ(ret2, ErrorCode::NO_ERROR); - // remove bundle not current ime + //remove bundle not current ime auto parcel3 = new (std::nothrow) MessageParcel(); service_->userId_ = userId; ImeCfgManager::GetInstance().imeConfigs_.push_back({ 60, "testBundleName/testExtName", "testSubName", false }); @@ -1118,8 +1142,8 @@ HWTEST_F(InputMethodPrivateMemberTest, TestServiceStartInputType, TestSize.Level } /** - * @tc.name: TestIsSupported - * @tc.desc: Test IsSupported + * @tc.name: TestServiceStartInputType + * @tc.desc: Test ServiceStartInputType * @tc.type: FUNC * @tc.require: */ @@ -1129,19 +1153,6 @@ HWTEST_F(InputMethodPrivateMemberTest, TestIsSupported, TestSize.Level0) EXPECT_FALSE(ret); } -/** - * @tc.name: TestGetImeByInputType - * @tc.desc: Test GetImeByInputType - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(InputMethodPrivateMemberTest, TestGetImeByInputType, TestSize.Level0) -{ - ImeIdentification ime; - auto ret = InputTypeManager::GetInstance().GetImeByInputType(InputType::NONE, ime); - EXPECT_EQ(ret, ErrorCode::ERROR_PARSE_CONFIG_FILE); -} - /** * @tc.name: TestOnUnRegisteredProxyIme * @tc.desc: Test OnUnRegisteredProxyIme @@ -1161,21 +1172,6 @@ HWTEST_F(InputMethodPrivateMemberTest, TestOnUnRegisteredProxyIme, TestSize.Leve EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); } -/** - * @tc.name: TestIsInputTypeSupported - * @tc.desc: Test IsInputTypeSupported - * @tc.type: FUNC - * @tc.require: issuesI794QF - */ -HWTEST_F(InputMethodPrivateMemberTest, TestIsInputTypeSupported, TestSize.Level0) -{ - IMSA_HILOGI("InputMethodPrivateMemberTest TestIsInputTypeSupported TEST START"); - InputType type = InputType::SECURITY_INPUT; - bool resultValue = false; - auto ret = service_->IsInputTypeSupported(static_cast(type), resultValue); - EXPECT_FALSE(ret); -} - /** * @tc.name: TestStartInputType * @tc.desc: Test StartInputType @@ -1354,7 +1350,6 @@ HWTEST_F(InputMethodPrivateMemberTest, BranchCoverage001, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); InputClientInfo clientInfo; - clientInfo.channel = nullptr; auto ret2 = service_->PrepareInput(INVALID_USER_ID, clientInfo); EXPECT_NE(ret2, ErrorCode::NO_ERROR); @@ -1599,7 +1594,6 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestPerUserSessionOnScreenUnlocked, Te userSession->imeData_.clear(); userSession->InitImeData({ imeCfg->bundleName, imeCfg->extName }); userSession->OnScreenUnlock(); - std::this_thread::sleep_for(std::chrono::seconds(1)); } /** @@ -1657,11 +1651,10 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestGetScreenLockIme, TestSize.Level0) ret = InputMethodPrivateMemberTest::service_->GetScreenLockIme(userId, ime); EXPECT_EQ(ret, ErrorCode::NO_ERROR); ImeInfoInquirer::GetInstance().systemConfig_ = systemConfig_0; - std::this_thread::sleep_for(std::chrono::seconds(1)); } /** - * @tc.name: Test_ClientGroup_UpdateClientInfo + * @tc.name: Test_PerUserSession_UpdateClientInfo * @tc.desc: Test UpdateClientInfo * @tc.type: FUNC * @tc.require:IBZ0Y6 @@ -1680,7 +1673,7 @@ HWTEST_F(InputMethodPrivateMemberTest, Test_ClientGroup_UpdateClientInfo, TestSi clientGroup->mapClients_.insert({ client->AsObject(), nullptr }); // client info is nullptr clientGroup->UpdateClientInfo(client->AsObject(), { { UpdateFlag::ISSHOWKEYBOARD, isShowKeyboard } }); - + auto info = std::make_shared(); clientGroup->mapClients_.insert_or_assign(client->AsObject(), info); // update abnormal @@ -2167,7 +2160,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestCompareExchange_001, TestSize.Level0) * @tc.name: TestIsLargeMemoryStateNeed_001 * @tc.desc: TestIsLargeMemoryStateNeed. * @tc.type: FUNC - * @tc.require: issuesIC7VH8 + * @tc.require: * @tc.author: */ HWTEST_F(InputMethodPrivateMemberTest, TestIsLargeMemoryStateNeed_001, TestSize.Level0) @@ -2186,7 +2179,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestIsLargeMemoryStateNeed_001, TestSize. * @tc.name: TestIsLargeMemoryStateNeed_002 * @tc.desc: Test IsLargeMemoryStateNeed. * @tc.type: FUNC - * @tc.require: issuesIC7VH8 + * @tc.require: * @tc.author: */ HWTEST_F(InputMethodPrivateMemberTest, TestIsLargeMemoryStateNeed_002, TestSize.Level0) @@ -2284,6 +2277,42 @@ HWTEST_F(InputMethodPrivateMemberTest, TestEventUpdateLargeMemoryState_001, Test subscriber->HandleLargeMemoryStateUpdate(data1); } +/** + * @tc.name: TestGetDisableNumKeyAppDeviceTypes + * @tc.desc: Test GetDisableNumKeyAppDeviceTypes. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputMethodPrivateMemberTest, TestGetDisableNumKeyAppDeviceTypes, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest TestGetDisableNumKeyAppDeviceTypes START"); + std::string testDeviceType = "testDeviceType"; + ImeInfoInquirer::GetInstance().systemConfig_.disableNumKeyAppDeviceTypes.clear(); + ImeInfoInquirer::GetInstance().systemConfig_.disableNumKeyAppDeviceTypes.insert(testDeviceType); + std::unordered_set ret = ImeInfoInquirer::GetInstance().GetDisableNumKeyAppDeviceTypes(); + EXPECT_FALSE(ret.empty()); + EXPECT_EQ(ret.count(testDeviceType), 1); +} + +/** + * @tc.name: TestGetCompatibleDeviceType + * @tc.desc: Test GetCompatibleDeviceType. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputMethodPrivateMemberTest, TestGetCompatibleDeviceType, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest TestGetCompatibleDeviceType START"); + std::string testBundleName = "testBundleName"; + std::string testDeviceType = "testDeviceType"; + bool ret = ImeInfoInquirer::GetInstance().GetCompatibleDeviceType(testBundleName, testDeviceType); + if (ret) { + EXPECT_NE(testDeviceType, "testDeviceType"); + } else { + EXPECT_EQ(testDeviceType, "testDeviceType"); + } +} + /** * @tc.name: TestAttachCount001 * @tc.desc: Test TestAttachCount001. @@ -2298,7 +2327,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestAttachCount001, TestSize.Level0) userSession->DecreaseAttachCount(); EXPECT_EQ(userSession->GetAttachCount(), 0); } - + /** * @tc.name: TestAttachCount002 * @tc.desc: Test TestAttachCount002 @@ -2317,7 +2346,7 @@ HWTEST_F(InputMethodPrivateMemberTest, TestAttachCount002, TestSize.Level0) } EXPECT_EQ(userSession->GetAttachCount(), 0); } - + /** * @tc.name: SA_TestGetSecurityInputType * @tc.desc: SA_TestGetSecurityInputType @@ -2331,48 +2360,11 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestGetSecurityInputType, TestSize.Lev inputClientInfo.config.inputAttribute.inputPattern = InputAttribute::PATTERN_PASSWORD; auto ret = InputMethodPrivateMemberTest::service_->GetSecurityInputType(inputClientInfo); EXPECT_EQ(ret, InputType::SECURITY_INPUT); - + inputClientInfo.config.inputAttribute.inputPattern = InputAttribute::PATTERN_TEXT; ret = InputMethodPrivateMemberTest::service_->GetSecurityInputType(inputClientInfo); EXPECT_EQ(ret, InputType::NONE); } - -/* - * @tc.name: TestGetDisableNumKeyAppDeviceTypes - * @tc.desc: Test GetDisableNumKeyAppDeviceTypes. - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(InputMethodPrivateMemberTest, TestGetDisableNumKeyAppDeviceTypes, TestSize.Level0) -{ - IMSA_HILOGI("InputMethodPrivateMemberTest TestGetDisableNumKeyAppDeviceTypes START"); - std::string testDeviceType = "testDeviceType"; - ImeInfoInquirer::GetInstance().systemConfig_.disableNumKeyAppDeviceTypes.clear(); - ImeInfoInquirer::GetInstance().systemConfig_.disableNumKeyAppDeviceTypes.insert(testDeviceType); - std::unordered_set ret = ImeInfoInquirer::GetInstance().GetDisableNumKeyAppDeviceTypes(); - EXPECT_FALSE(ret.empty()); - EXPECT_EQ(ret.count(testDeviceType), 1); -} - -/** - * @tc.name: TestGetCompatibleDeviceType - * @tc.desc: Test GetCompatibleDeviceType. - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(InputMethodPrivateMemberTest, TestGetCompatibleDeviceType, TestSize.Level0) -{ - IMSA_HILOGI("InputMethodPrivateMemberTest TestGetCompatibleDeviceType START"); - std::string testBundleName = "testBundleName"; - std::string testDeviceType = "testDeviceType"; - bool ret = ImeInfoInquirer::GetInstance().GetCompatibleDeviceType(testBundleName, testDeviceType); - if (ret) { - EXPECT_NE(testDeviceType, "testDeviceType"); - } else { - EXPECT_EQ(testDeviceType, "testDeviceType"); - } -} - /** * @tc.name: SA_TestRestartIme001 * @tc.desc: restart request will be discarded, and reartTasks will be reset @@ -2385,7 +2377,7 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestRestartIme001, TestSize.Level0) auto runner = AppExecFwk::EventRunner::Create("test_RestartIme"); auto eventHandler = std::make_shared(runner); auto session = std::make_shared(MAIN_USER_ID, eventHandler); - + // attach conflict with the first scb startup event // restart request will be discarded, and reartTasks will be reset session->IncreaseAttachCount(); @@ -2395,7 +2387,7 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestRestartIme001, TestSize.Level0) usleep(WAIT_FOR_THREAD_SCHEDULE * MS_TO_US); EXPECT_EQ(session->restartTasks_, 0); } - + /** * @tc.name: SA_TestRestartIme002 * @tc.desc: restart request will be delayed @@ -2408,7 +2400,7 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestRestartIme002, TestSize.Level0) auto runner = AppExecFwk::EventRunner::Create("test_RestartIme"); auto eventHandler = std::make_shared(runner); auto session = std::make_shared(MAIN_USER_ID, eventHandler); - + // attach conflict with no first scb startup event // restart request will be delayed session->IncreaseAttachCount(); @@ -2420,13 +2412,13 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestRestartIme002, TestSize.Level0) usleep(WAIT_FOR_THREAD_SCHEDULE * MS_TO_US); // restart request be delayed, restartTasks_ no change EXPECT_EQ(session->restartTasks_, 1); - + // attach finished session->DecreaseAttachCount(); usleep((WAIT_ATTACH_FINISH_DELAY + WAIT_FOR_THREAD_SCHEDULE) * MS_TO_US); EXPECT_EQ(session->restartTasks_, 0); } - + /** * @tc.name: SA_TestRestartIme003 * @tc.desc: attach finished, and execute restart immediately @@ -2439,7 +2431,7 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestRestartIme003, TestSize.Level0) auto runner = AppExecFwk::EventRunner::Create("test_RestartIme"); auto eventHandler = std::make_shared(runner); auto session = std::make_shared(MAIN_USER_ID, eventHandler); - + // attach finished, and execute restart immediately EXPECT_EQ(session->GetAttachCount(), 0); session->AddRestartIme(); 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 58bed87a1..2eace773f 100644 --- a/test/unittest/cpp_test/src/input_method_switch_test.cpp +++ b/test/unittest/cpp_test/src/input_method_switch_test.cpp @@ -435,6 +435,7 @@ HWTEST_F(InputMethodSwitchTest, testCombinationKeySwitchIme_001, TestSize.Level0 auto ret = TddUtil::ExecuteCmd(cmd, result); EXPECT_TRUE(ret); EXPECT_TRUE(ImeSettingListenerTestImpl::WaitImeChange()); + imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, property->name, ""); } /** @@ -454,6 +455,7 @@ HWTEST_F(InputMethodSwitchTest, testCombinationKeySwitchIme_002, TestSize.Level0 auto ret = TddUtil::ExecuteCmd(cmd, result); EXPECT_TRUE(ret); EXPECT_TRUE(ImeSettingListenerTestImpl::WaitImeChange()); + imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, property->name, ""); } /** @@ -469,7 +471,7 @@ HWTEST_F(InputMethodSwitchTest, testCombinationKeySwitchIme_003, TestSize.Level0 ImeSettingListenerTestImpl::ResetParam(); std::shared_ptr property = imc_->GetCurrentInputMethod(); std::vector props; - imc_->ListInputMethod(props); + imc_->ListInputMethod(true, props); std::string result; static std::string cmd = "uinput -K -d 2077 -d 2050 -u 2050 -u 2077"; for (auto iter = 0; iter < props.size(); ++iter) { @@ -479,6 +481,7 @@ HWTEST_F(InputMethodSwitchTest, testCombinationKeySwitchIme_003, TestSize.Level0 EXPECT_TRUE(ImeSettingListenerTestImpl::WaitTargetImeChange(property->name)); std::shared_ptr curProperty = imc_->GetCurrentInputMethod(); EXPECT_EQ(property->name, curProperty->name); + imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, property->name, ""); } } // namespace MiscServices } // namespace OHOS diff --git a/test/unittest/cpp_test/src/newIme_switch_test.cpp b/test/unittest/cpp_test/src/newIme_switch_test.cpp index daac1e3c1..4d301097c 100644 --- a/test/unittest/cpp_test/src/newIme_switch_test.cpp +++ b/test/unittest/cpp_test/src/newIme_switch_test.cpp @@ -353,5 +353,59 @@ HWTEST_F(NewImeSwitchTest, testSwitchInputMethod_005, TestSize.Level0) auto ret = imc_->SwitchInputMethod(SwitchTrigger::SYSTEM_APP, bundleName); EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED); } + +/** + * @tc.name: testSwitchInputMethod_tmpImeSwitch + * @tc.desc: test tmp ime switch + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(NewImeSwitchTest, testSwitchInputMethod_tmpImeSwitch, TestSize.Level0) +{ + ImeSettingListenerTestImpl::ResetParam(); + TddUtil::SetTestTokenID( + TddUtil::AllocTestTokenID(true, "ohos.inputMethod.test", { "ohos.permission.CONNECT_IME_ABILITY" })); + IMSA_HILOGI("newIme testSwitchInputMethod_tmpImeSwitch Test START"); + // userSetIme: bundleName + auto ret = imc_->SwitchInputMethod(SwitchTrigger::SYSTEM_APP, bundleName); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(ImeSettingListenerTestImpl::WaitImeChange()); + auto userSetIme = imc_->GetCurrentInputMethod(); + ASSERT_NE(userSetIme, nullptr); + EXPECT_EQ(userSetIme->name, bundleName); + + // password, start tmp ime + TddUtil::GetFocused(); + InputAttribute inputAttribute = { .inputPattern = InputAttribute::PATTERN_PASSWORD_NUMBER }; + ret = imc_->Attach(nullptr, false, inputAttribute); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + TddUtil::GetUnfocused(); + + // set tmp ime identity + std::shared_ptr property; + ret = imc_->GetDefaultInputMethod(property); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ASSERT_NE(property, nullptr); + TddUtil::SetTestTokenID(TddUtil::GetTestTokenID(property->name)); + + // tmp ime can switch subtype, but userSetIme can not be changed and imeChange can not be triggered + ImeSettingListenerTestImpl::ResetParam(); + ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, property->name); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(ImeSettingListenerTestImpl::WaitImeChange()); + userSetIme = imc_->GetCurrentInputMethod(); + ASSERT_NE(userSetIme, nullptr); + EXPECT_EQ(userSetIme->name, bundleName); + + // tmp ime can switch other ime + ImeSettingListenerTestImpl::ResetParam(); + ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, bundleName); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(ImeSettingListenerTestImpl::WaitImeChange()); + userSetIme = imc_->GetCurrentInputMethod(); + ASSERT_NE(userSetIme, nullptr); + EXPECT_EQ(userSetIme->name, bundleName); +} } // namespace MiscServices } // namespace OHOS diff --git a/test/unittest/resource/ohos_test/ohos_test.xml b/test/unittest/resource/ohos_test/ohos_test.xml index 0580fa92e..a9beb029a 100644 --- a/test/unittest/resource/ohos_test/ohos_test.xml +++ b/test/unittest/resource/ohos_test/ohos_test.xml @@ -135,6 +135,14 @@