From ac915690ba09843302d207a061087f227de041da Mon Sep 17 00:00:00 2001 From: ShortMessage Date: Wed, 9 Apr 2025 12:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9F=AD=E4=BF=A1=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E7=BC=96=E8=BE=91=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ShortMessage --- .../js_input_method_engine_setting.cpp | 144 +++++++++++++----- .../js_input_method_engine_setting.h | 3 + .../js_get_input_method_controller.cpp | 85 +++++++---- .../js_get_input_method_controller.h | 1 + .../include/input_attribute.h | 11 ++ .../include/input_method_utils.h | 2 + interfaces/kits/c/inputmethod_types_capi.h | 4 + .../include/input_method_system_ability.h | 3 +- services/include/input_type_manager.h | 2 + services/src/input_method_system_ability.cpp | 82 ++++++---- services/src/input_type_manager.cpp | 18 +++ .../src/input_method_ability_test.cpp | 20 ++- .../src/input_method_private_member_test.cpp | 3 +- .../src/inputmethod_controller_capi_test.cpp | 20 +++ .../cpp_test/src/json_operate_test.cpp | 11 +- 15 files changed, 304 insertions(+), 105 deletions(-) diff --git a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp index e606c68b6..8c8ba9d22 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -36,6 +36,37 @@ namespace MiscServices { constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_MAX = 6; +const int DESCRIPTOR_NUMBER = 30; +const int UNSPECIFIED_INDEX = 0; +const int GO_INDEX = 1; +const int SEARCH_INDEX = 2; +const int SEND_INDEX = 3; +const int NEXT_INDEX = 4; +const int DONE_INDEX = 5; +const int PREVIOUS_INDEX = 6; +const int NEW_LINE_INDEX = 7; +const int NONE_INDEX = 8; +const int TEXT_INDEX = 9; +const int NUMBER_INDEX = 10; +const int PHONE_INDEX = 11; +const int DATETIME_INDEX = 12; +const int EMAIL_ADDRESS_INDEX = 13; +const int URL_INDEX = 14; +const int VISIBLE_PASSWORD_INDEX = 15; +const int NUMBER_PASSWORD_INDEX = 16; +const int SCREEN_LOCK_PASSWORD_INDEX = 17; +const int USER_NAME_INDEX = 18; +const int NEW_PASSWORD_INDEX = 19; +const int NUMBER_DECIMAL_INDEX = 20; +const int ONE_TIME_CODE_INDEX = 21; +const int IME_ENGINE_INDEX = 22; +const int IME_ABILITY_INDEX = 23; +const int PANELTYPE_INDEX = 24; +const int PANELFLAG_INDEX = 25; +const int DIRECTION_INDEX = 26; +const int EXTEND_ACTION_INDEX = 27; +const int SECURITY_MODE_INDEX = 28; +const int IMMERSIVE_MODE_INDEX = 29; const std::string JsInputMethodEngineSetting::IMES_CLASS_NAME = "InputMethodEngine"; thread_local napi_ref JsInputMethodEngineSetting::IMESRef_ = nullptr; @@ -46,50 +77,81 @@ std::shared_ptr JsInputMethodEngineSetting::handler_{ napi_value JsInputMethodEngineSetting::Init(napi_env env, napi_value exports) { - napi_property_descriptor descriptor[] = { - DECLARE_NAPI_PROPERTY( - "ENTER_KEY_TYPE_UNSPECIFIED", GetJsConstProperty(env, static_cast(EnterKeyType::UNSPECIFIED))), - DECLARE_NAPI_PROPERTY("ENTER_KEY_TYPE_GO", GetJsConstProperty(env, static_cast(EnterKeyType::GO))), - DECLARE_NAPI_PROPERTY( - "ENTER_KEY_TYPE_SEARCH", GetJsConstProperty(env, static_cast(EnterKeyType::SEARCH))), - DECLARE_NAPI_PROPERTY( - "ENTER_KEY_TYPE_SEND", GetJsConstProperty(env, static_cast(EnterKeyType::SEND))), - DECLARE_NAPI_PROPERTY( - "ENTER_KEY_TYPE_NEXT", GetJsConstProperty(env, static_cast(EnterKeyType::NEXT))), - DECLARE_NAPI_PROPERTY( - "ENTER_KEY_TYPE_DONE", GetJsConstProperty(env, static_cast(EnterKeyType::DONE))), - DECLARE_NAPI_PROPERTY( - "ENTER_KEY_TYPE_PREVIOUS", GetJsConstProperty(env, static_cast(EnterKeyType::PREVIOUS))), - DECLARE_NAPI_PROPERTY( - "ENTER_KEY_TYPE_NEWLINE", GetJsConstProperty(env, static_cast(EnterKeyType::NEW_LINE))), - DECLARE_NAPI_PROPERTY("PATTERN_NULL", GetIntJsConstProperty(env, static_cast(TextInputType::NONE))), - DECLARE_NAPI_PROPERTY("PATTERN_TEXT", GetJsConstProperty(env, static_cast(TextInputType::TEXT))), - DECLARE_NAPI_PROPERTY("PATTERN_NUMBER", GetJsConstProperty(env, static_cast(TextInputType::NUMBER))), - DECLARE_NAPI_PROPERTY("PATTERN_PHONE", GetJsConstProperty(env, static_cast(TextInputType::PHONE))), - DECLARE_NAPI_PROPERTY( - "PATTERN_DATETIME", GetJsConstProperty(env, static_cast(TextInputType::DATETIME))), - DECLARE_NAPI_PROPERTY( - "PATTERN_EMAIL", GetJsConstProperty(env, static_cast(TextInputType::EMAIL_ADDRESS))), - DECLARE_NAPI_PROPERTY("PATTERN_URI", GetJsConstProperty(env, static_cast(TextInputType::URL))), - DECLARE_NAPI_PROPERTY( - "PATTERN_PASSWORD", GetJsConstProperty(env, static_cast(TextInputType::VISIBLE_PASSWORD))), - DECLARE_NAPI_PROPERTY( - "PATTERN_PASSWORD_NUMBER", GetJsConstProperty(env, static_cast(TextInputType::NUMBER_PASSWORD))), - DECLARE_NAPI_PROPERTY("PATTERN_PASSWORD_SCREEN_LOCK", - GetJsConstProperty(env, static_cast(TextInputType::SCREEN_LOCK_PASSWORD))), - DECLARE_NAPI_FUNCTION("getInputMethodEngine", GetInputMethodEngine), - DECLARE_NAPI_FUNCTION("getInputMethodAbility", GetInputMethodAbility), - DECLARE_NAPI_STATIC_PROPERTY("PanelType", GetJsPanelTypeProperty(env)), - DECLARE_NAPI_STATIC_PROPERTY("PanelFlag", GetJsPanelFlagProperty(env)), - DECLARE_NAPI_STATIC_PROPERTY("Direction", GetJsDirectionProperty(env)), - DECLARE_NAPI_STATIC_PROPERTY("ExtendAction", GetJsExtendActionProperty(env)), - DECLARE_NAPI_STATIC_PROPERTY("SecurityMode", GetJsSecurityModeProperty(env)), - DECLARE_NAPI_STATIC_PROPERTY("ImmersiveMode", GetJsImmersiveModeProperty(env)), - }; + napi_property_descriptor descriptor[DESCRIPTOR_NUMBER]; + InitPart1(env, descriptor); + InitPart2(env, descriptor); + InitPart3(env, descriptor); NAPI_CALL( env, napi_define_properties(env, exports, sizeof(descriptor) / sizeof(napi_property_descriptor), descriptor)); return InitProperty(env, exports); -}; +} + +napi_value JsInputMethodEngineSetting::InitPart1(napi_env env, napi_property_descriptor *descriptor) +{ + descriptor[UNSPECIFIED_INDEX] = DECLARE_NAPI_PROPERTY( + "ENTER_KEY_TYPE_UNSPECIFIED", GetJsConstProperty(env, static_cast(EnterKeyType::UNSPECIFIED))); + descriptor[GO_INDEX] = DECLARE_NAPI_PROPERTY("ENTER_KEY_TYPE_GO", + GetJsConstProperty(env, static_cast(EnterKeyType::GO))); + descriptor[SEARCH_INDEX] = DECLARE_NAPI_PROPERTY( + "ENTER_KEY_TYPE_SEARCH", GetJsConstProperty(env, static_cast(EnterKeyType::SEARCH))); + descriptor[SEND_INDEX] = DECLARE_NAPI_PROPERTY( + "ENTER_KEY_TYPE_SEND", GetJsConstProperty(env, static_cast(EnterKeyType::SEND))); + descriptor[NEXT_INDEX] = DECLARE_NAPI_PROPERTY( + "ENTER_KEY_TYPE_NEXT", GetJsConstProperty(env, static_cast(EnterKeyType::NEXT))); + descriptor[DONE_INDEX] = DECLARE_NAPI_PROPERTY( + "ENTER_KEY_TYPE_DONE", GetJsConstProperty(env, static_cast(EnterKeyType::DONE))); + descriptor[PREVIOUS_INDEX] = DECLARE_NAPI_PROPERTY( + "ENTER_KEY_TYPE_PREVIOUS", GetJsConstProperty(env, static_cast(EnterKeyType::PREVIOUS))); + descriptor[NEW_LINE_INDEX] = DECLARE_NAPI_PROPERTY( + "ENTER_KEY_TYPE_NEWLINE", GetJsConstProperty(env, static_cast(EnterKeyType::NEW_LINE))); + return nullptr; +} + +napi_value JsInputMethodEngineSetting::InitPart2(napi_env env, napi_property_descriptor *descriptor) +{ + descriptor[NONE_INDEX] = DECLARE_NAPI_PROPERTY("PATTERN_NULL", + GetIntJsConstProperty(env, static_cast(TextInputType::NONE))); + descriptor[TEXT_INDEX] = DECLARE_NAPI_PROPERTY("PATTERN_TEXT", + GetJsConstProperty(env, static_cast(TextInputType::TEXT))); + descriptor[NUMBER_INDEX] = DECLARE_NAPI_PROPERTY("PATTERN_NUMBER", + GetJsConstProperty(env, static_cast(TextInputType::NUMBER))); + descriptor[PHONE_INDEX] = DECLARE_NAPI_PROPERTY("PATTERN_PHONE", + GetJsConstProperty(env, static_cast(TextInputType::PHONE))); + descriptor[DATETIME_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_DATETIME", GetJsConstProperty(env, static_cast(TextInputType::DATETIME))); + descriptor[EMAIL_ADDRESS_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_EMAIL", GetJsConstProperty(env, static_cast(TextInputType::EMAIL_ADDRESS))); + descriptor[URL_INDEX] = DECLARE_NAPI_PROPERTY("PATTERN_URI", + GetJsConstProperty(env, static_cast(TextInputType::URL))); + descriptor[VISIBLE_PASSWORD_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_PASSWORD", GetJsConstProperty(env, static_cast(TextInputType::VISIBLE_PASSWORD))); + descriptor[NUMBER_PASSWORD_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_PASSWORD_NUMBER", GetJsConstProperty(env, static_cast(TextInputType::NUMBER_PASSWORD))); + descriptor[SCREEN_LOCK_PASSWORD_INDEX] = DECLARE_NAPI_PROPERTY("PATTERN_PASSWORD_SCREEN_LOCK", + GetJsConstProperty(env, static_cast(TextInputType::SCREEN_LOCK_PASSWORD))); + descriptor[USER_NAME_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_USER_NAME", GetJsConstProperty(env, static_cast(TextInputType::USER_NAME))); + descriptor[NEW_PASSWORD_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_NEW_PASSWORD", GetJsConstProperty(env, static_cast(TextInputType::NEW_PASSWORD))); + descriptor[NUMBER_DECIMAL_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_NUMBER_DECIMA", GetJsConstProperty(env, static_cast(TextInputType::NUMBER_DECIMAL))); + descriptor[ONE_TIME_CODE_INDEX] = DECLARE_NAPI_PROPERTY( + "PATTERN_ONE_TIME_CODE", GetJsConstProperty(env, static_cast(TextInputType::ONE_TIME_CODE))); + descriptor[IME_ENGINE_INDEX] = DECLARE_NAPI_FUNCTION("getInputMethodEngine", GetInputMethodEngine); + descriptor[IME_ABILITY_INDEX] = DECLARE_NAPI_FUNCTION("getInputMethodAbility", GetInputMethodAbility); + return nullptr; +} + +napi_value JsInputMethodEngineSetting::InitPart3(napi_env env, napi_property_descriptor *descriptor) +{ + descriptor[PANELTYPE_INDEX] = DECLARE_NAPI_STATIC_PROPERTY("PanelType", GetJsPanelTypeProperty(env)); + descriptor[PANELFLAG_INDEX] = DECLARE_NAPI_STATIC_PROPERTY("PanelFlag", GetJsPanelFlagProperty(env)); + descriptor[DIRECTION_INDEX] = DECLARE_NAPI_STATIC_PROPERTY("Direction", GetJsDirectionProperty(env)); + descriptor[EXTEND_ACTION_INDEX] = DECLARE_NAPI_STATIC_PROPERTY("ExtendAction", GetJsExtendActionProperty(env)); + descriptor[SECURITY_MODE_INDEX] = DECLARE_NAPI_STATIC_PROPERTY("SecurityMode", GetJsSecurityModeProperty(env)); + descriptor[IMMERSIVE_MODE_INDEX] = DECLARE_NAPI_STATIC_PROPERTY("ImmersiveMode", GetJsImmersiveModeProperty(env)); + return nullptr; +} napi_value JsInputMethodEngineSetting::InitProperty(napi_env env, napi_value exports) { diff --git a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h index 7b73cf7ff..34d986fcd 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h @@ -40,6 +40,9 @@ public: JsInputMethodEngineSetting() = default; ~JsInputMethodEngineSetting() override = default; static napi_value Init(napi_env env, napi_value exports); + static napi_value InitPart1(napi_env env, napi_property_descriptor *descriptor); + static napi_value InitPart2(napi_env env, napi_property_descriptor *descriptor); + static napi_value InitPart3(napi_env env, napi_property_descriptor *descriptor); static napi_value InitProperty(napi_env env, napi_value exports); static napi_value GetInputMethodEngine(napi_env env, napi_callback_info info); static napi_value GetInputMethodAbility(napi_env env, napi_callback_info info); 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 16cb08caa..d842e9ed4 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp @@ -32,6 +32,22 @@ namespace MiscServices { constexpr size_t ARGC_ZERO = 0; constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; +const int TEXT_INPUT_TYPE_NUMBER = 15; +const int NONE_INDEX = 0; +const int TEXT_INDEX = 1; +const int MULTILINE_INDEX = 2; +const int NUMBER_INDEX = 3; +const int PHONE_INDEX = 4; +const int DATETIME_INDEX = 5; +const int EMAIL_ADDRESS_INDEX = 6; +const int URL_INDEX = 7; +const int VISIBLE_PASSWORD_INDEX = 8; +const int NUMBER_PASSWORD_INDEX = 9; +const int SCREEN_LOCK_PASSWORD_INDEX = 10; +const int USER_NAME_INDEX = 11; +const int NEW_PASSWORD_INDEX = 12; +const int NUMBER_DECIMAL_INDEX = 13; +const int ONE_TIME_CODE_INDEX = 14; constexpr int32_t MAX_WAIT_TIME_MESSAGE_HANDLER = 2000; constexpr int32_t MAX_WAIT_TIME_ATTACH = 2000; const std::set EVENT_TYPE{ @@ -152,40 +168,49 @@ napi_value JsGetInputMethodController::GetJsEnterKeyTypeProperty(napi_env env) return enterKeyType; } +napi_value JsGetInputMethodController::CreateTextInputTypeValues(napi_env env, napi_value *values) +{ + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::NONE), &values[NONE_INDEX])); + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::TEXT), &values[TEXT_INDEX])); + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::MULTILINE), &values[MULTILINE_INDEX])); + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::NUMBER), &values[NUMBER_INDEX])); + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::PHONE), &values[PHONE_INDEX])); + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::DATETIME), &values[DATETIME_INDEX])); + NAPI_CALL(env, napi_create_int32(env, + static_cast(TextInputType::EMAIL_ADDRESS), &values[EMAIL_ADDRESS_INDEX])); + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::URL), &values[URL_INDEX])); + NAPI_CALL(env, napi_create_int32(env, + static_cast(TextInputType::VISIBLE_PASSWORD), &values[VISIBLE_PASSWORD_INDEX])); + NAPI_CALL(env, napi_create_int32(env, + static_cast(TextInputType::NUMBER_PASSWORD), &values[NUMBER_PASSWORD_INDEX])); + NAPI_CALL(env, napi_create_int32(env, + static_cast(TextInputType::SCREEN_LOCK_PASSWORD), &values[SCREEN_LOCK_PASSWORD_INDEX])); + NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::USER_NAME), &values[USER_NAME_INDEX])); + NAPI_CALL(env, napi_create_int32(env, + static_cast(TextInputType::NEW_PASSWORD), &values[NEW_PASSWORD_INDEX])); + NAPI_CALL(env, napi_create_int32(env, + static_cast(TextInputType::NUMBER_DECIMAL), &values[NUMBER_DECIMAL_INDEX])); + NAPI_CALL(env, napi_create_int32(env, + static_cast(TextInputType::ONE_TIME_CODE), &values[ONE_TIME_CODE_INDEX])); + return nullptr; +} + napi_value JsGetInputMethodController::GetJsTextInputTypeProperty(napi_env env) { napi_value textInputType = nullptr; - napi_value typeNone = nullptr; - napi_value typeText = nullptr; - napi_value typeMultiline = nullptr; - napi_value typeNumber = nullptr; - napi_value typePhone = nullptr; - napi_value typeDatatime = nullptr; - napi_value typeEmailAddress = nullptr; - napi_value typeUrl = nullptr; - napi_value typeVisiblePassword = nullptr; - napi_value typeNumberPassword = nullptr; - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::NONE), &typeNone)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::TEXT), &typeText)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::MULTILINE), &typeMultiline)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::NUMBER), &typeNumber)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::PHONE), &typePhone)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::DATETIME), &typeDatatime)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::EMAIL_ADDRESS), &typeEmailAddress)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::URL), &typeUrl)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::VISIBLE_PASSWORD), &typeVisiblePassword)); - NAPI_CALL(env, napi_create_int32(env, static_cast(TextInputType::NUMBER_PASSWORD), &typeNumberPassword)); + napi_value values[TEXT_INPUT_TYPE_NUMBER]; + CreateTextInputTypeValues(env, values); + NAPI_CALL(env, napi_create_object(env, &textInputType)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "NONE", typeNone)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "TEXT", typeText)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "MULTILINE", typeMultiline)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "NUMBER", typeNumber)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "PHONE", typePhone)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "DATETIME", typeDatatime)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "EMAIL_ADDRESS", typeEmailAddress)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "URL", typeUrl)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "VISIBLE_PASSWORD", typeVisiblePassword)); - NAPI_CALL(env, napi_set_named_property(env, textInputType, "NUMBER_PASSWORD", typeNumberPassword)); + + const char* names[] = {"NONE", "TEXT", "MULTILINE", "NUMBER", "PHONE", "DATETIME", "EMAIL_ADDRESS", "URL", + "VISIBLE_PASSWORD", "NUMBER_PASSWORD", "SCREEN_LOCK_PASSWORD", "USER_NAME", "NEW_PASSWORD", "NUMBER_DECIMAL", + "ONE_TIME_CODE"}; + + for (int i = 0; i < TEXT_INPUT_TYPE_NUMBER; i++) { + NAPI_CALL(env, napi_set_named_property(env, textInputType, names[i], values[i])); + } + return textInputType; } diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h index 2964e1fef..b32865bcd 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h @@ -233,6 +233,7 @@ private: static napi_value GetAttachOptionsValue(napi_env env, napi_callback_info cbinfo, AttachOptions &attachOptions); static napi_value GetJsKeyboardStatusProperty(napi_env env); static napi_value GetJsEnterKeyTypeProperty(napi_env env); + static napi_value CreateTextInputTypeValues(napi_env env, napi_value *values); static napi_value GetJsTextInputTypeProperty(napi_env env); static napi_value GetJsDirectionProperty(napi_env env); static napi_value GetJsExtendActionProperty(napi_env env); diff --git a/frameworks/native/inputmethod_controller/include/input_attribute.h b/frameworks/native/inputmethod_controller/include/input_attribute.h index 764e03890..67fec81ad 100644 --- a/frameworks/native/inputmethod_controller/include/input_attribute.h +++ b/frameworks/native/inputmethod_controller/include/input_attribute.h @@ -29,6 +29,7 @@ struct InputAttribute { static const int32_t PATTERN_PASSWORD_NUMBER = 0x00000008; static const int32_t PATTERN_PASSWORD_SCREEN_LOCK = 0x00000009; static const int32_t PATTERN_NEWPASSWORD = 0x0000000b; + static const int32_t PATTERN_ONE_TIME_CODE = 0x0000000d; int32_t inputPattern = 0; int32_t enterKeyType = 0; int32_t inputOption = 0; @@ -60,6 +61,16 @@ struct InputAttribute { PATTERN_PASSWORD_NUMBER == inputPattern || PATTERN_NEWPASSWORD == inputPattern; } + bool GetOneTimeCodeFlag() const + { + return inputPattern == PATTERN_ONE_TIME_CODE; + } + + bool GetSpecialFlag() const + { + return GetSecurityFlag() || GetOneTimeCodeFlag(); + } + bool operator==(const InputAttribute &info) const { return inputPattern == info.inputPattern && enterKeyType == info.enterKeyType && diff --git a/frameworks/native/inputmethod_controller/include/input_method_utils.h b/frameworks/native/inputmethod_controller/include/input_method_utils.h index fb9e5ce40..e3c21dda1 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_utils.h +++ b/frameworks/native/inputmethod_controller/include/input_method_utils.h @@ -59,6 +59,7 @@ enum class TextInputType { USER_NAME, NEW_PASSWORD, NUMBER_DECIMAL, + ONE_TIME_CODE, }; enum class Direction { @@ -297,6 +298,7 @@ enum class InputType : int32_t { SECURITY_INPUT, VOICE_INPUT, VOICEKB_INPUT, + ONE_TIME_CODE = 13, END }; diff --git a/interfaces/kits/c/inputmethod_types_capi.h b/interfaces/kits/c/inputmethod_types_capi.h index cde9f3525..0a8a4e3b5 100644 --- a/interfaces/kits/c/inputmethod_types_capi.h +++ b/interfaces/kits/c/inputmethod_types_capi.h @@ -215,6 +215,10 @@ typedef enum InputMethod_TextInputType { * The text input type is NUMBER DECIMAL. */ IME_TEXT_INPUT_TYPE_NUMBER_DECIMAL = 12, + /** + * The text input type is ONE TIME CODE. + */ + IME_TEXT_INPUT_TYPE_ONE_TIME_CODE = 13, } InputMethod_TextInputType; /** diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 0d5f715af..82715911e 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -171,7 +171,7 @@ private: bool IsCurrentIme(int32_t userId); int32_t StartInputType(int32_t userId, InputType type); // if switch input type need to switch ime, then no need to hide panel first. - void NeedHideWhenSwitchInputType(int32_t userId, bool &needHide); + void NeedHideWhenSwitchInputType(int32_t userId, bool &needHide, InputType type); bool GetDeviceFunctionKeyState(int32_t functionKey, bool &isEnable); bool ModifyImeCfgWithWrongCaps(); void HandleBundleScanFinished(); @@ -185,6 +185,7 @@ private: std::pair GetCurrentImeInfoForHiSysEvent(int32_t userId); int32_t GetScreenLockIme(std::string &ime); int32_t GetAlternativeIme(std::string &ime); + int32_t SpecialModeImeStarted(int32_t &userId, InputClientInfo &inputClientInfo); #ifdef IMF_ON_DEMAND_START_STOP_SA_ENABLE int64_t GetTickCount(); void ResetDelayUnloadTask(uint32_t code = 0); diff --git a/services/include/input_type_manager.h b/services/include/input_type_manager.h index 7a2a2374c..0df78c5ed 100644 --- a/services/include/input_type_manager.h +++ b/services/include/input_type_manager.h @@ -47,6 +47,8 @@ public: bool IsCameraImeStarted(); bool IsVoiceImeStarted(); bool IsVoiceKbImeStarted(); + bool IsOneTimeCodeImeStarted(); + bool IsSpecialImeStarted(); InputType GetCurrentInputType(); void Set(bool isStarted, const ImeIdentification ¤tIme = {}); ImeIdentification GetCurrentIme(); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index afac34530..ff9d1e816 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -619,28 +619,13 @@ int32_t InputMethodSystemAbility::StartInputInner( int32_t InputMethodSystemAbility::CheckInputTypeOption(int32_t userId, InputClientInfo &inputClientInfo) { - IMSA_HILOGI("SecurityFlag: %{public}d, IsSameTextInput: %{public}d, IsStarted: %{public}d, " - "IsSecurityImeStarted: %{public}d.", - inputClientInfo.config.inputAttribute.GetSecurityFlag(), !inputClientInfo.isNotifyInputStart, - InputTypeManager::GetInstance().IsStarted(), InputTypeManager::GetInstance().IsSecurityImeStarted()); - if (inputClientInfo.config.inputAttribute.GetSecurityFlag()) { - if (!InputTypeManager::GetInstance().IsStarted()) { - IMSA_HILOGD("SecurityFlag, input type is not started, start."); - // if need to switch ime, no need to hide panel first. - NeedHideWhenSwitchInputType(userId, inputClientInfo.needHide); - return StartInputType(userId, InputType::SECURITY_INPUT); - } - if (!inputClientInfo.isNotifyInputStart) { - IMSA_HILOGD("SecurityFlag, same textField, input type is started, not deal."); - return ErrorCode::NO_ERROR; - } - if (!InputTypeManager::GetInstance().IsSecurityImeStarted()) { - IMSA_HILOGD("SecurityFlag, new textField, input type is started, but it is not security, switch."); - NeedHideWhenSwitchInputType(userId, inputClientInfo.needHide); - return StartInputType(userId, InputType::SECURITY_INPUT); - } - IMSA_HILOGD("SecurityFlag, other condition, not deal."); - return ErrorCode::NO_ERROR; + IMSA_HILOGI("SpeciaFlag: %{public}d, IsSameTextInput: %{public}d, IsStarted: %{public}d," + "IsSpecialImeStarted: %{public}d.", inputClientInfo.config.inputAttribute.GetSpecialFlag(), + !inputClientInfo.isNotifyInputStart, InputTypeManager::GetInstance().IsStarted(), + InputTypeManager::GetInstance().IsSpecialImeStarted()); + if (inputClientInfo.config.inputAttribute.GetSpecialFlag()) { + auto ret = SpecialModeImeStarted(userId, inputClientInfo); + return ret; } if (!inputClientInfo.isNotifyInputStart) { IMSA_HILOGD("NormalFlag, same textField, not deal."); @@ -2155,7 +2140,7 @@ int32_t InputMethodSystemAbility::StartInputType(int32_t userId, InputType type) if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGW("not find input type: %{public}d.", type); // add for not adapter for SECURITY_INPUT - if (type == InputType::SECURITY_INPUT) { + if (type == InputType::SECURITY_INPUT || type == InputType::ONE_TIME_CODE) { return session->RestoreCurrentIme(); } return ret; @@ -2163,20 +2148,24 @@ int32_t InputMethodSystemAbility::StartInputType(int32_t userId, InputType type) SwitchInfo switchInfo = { std::chrono::system_clock::now(), ime.bundleName, ime.subName }; session->GetSwitchQueue().Push(switchInfo); IMSA_HILOGI("start input type: %{public}d.", type); - return type == InputType::SECURITY_INPUT ? OnStartInputType(userId, switchInfo, false) - : OnStartInputType(userId, switchInfo, true); + return (type == InputType::SECURITY_INPUT || type == InputType::ONE_TIME_CODE) ? + OnStartInputType(userId, switchInfo, false) : OnStartInputType(userId, switchInfo, true); } -void InputMethodSystemAbility::NeedHideWhenSwitchInputType(int32_t userId, bool &needHide) +void InputMethodSystemAbility::NeedHideWhenSwitchInputType(int32_t userId, bool &needHide, InputType type) { ImeIdentification ime; - InputTypeManager::GetInstance().GetImeByInputType(InputType::SECURITY_INPUT, ime); + InputTypeManager::GetInstance().GetImeByInputType(type, ime); auto currentImeCfg = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId); if (currentImeCfg == nullptr) { IMSA_HILOGI("currentImeCfg is nullptr"); return; } - needHide = currentImeCfg->bundleName == ime.bundleName; + if (currentImeCfg->bundleName != ime.bundleName) { + needHide = true; + } else { + needHide = false; + } } void InputMethodSystemAbility::HandleBundleScanFinished() @@ -2414,5 +2403,42 @@ int32_t InputMethodSystemAbility::GetAlternativeIme(std::string &ime) IMSA_HILOGE("GetAlternativeIme is failed!"); return ErrorCode::ERROR_NOT_IME; } + +int32_t InputMethodSystemAbility::SpecialModeImeStarted(int32_t &userId, InputClientInfo &inputClientInfo) +{ + InputType type = InputType::NONE; + if (inputClientInfo.config.inputAttribute.GetOneTimeCodeFlag()) { + type = InputType::ONE_TIME_CODE; + } else if (inputClientInfo.config.inputAttribute.GetSecurityFlag()) { + type = InputType::SECURITY_INPUT; + } + IMSA_HILOGI("InputType:[%{public}d.", inputClientInfo.config.inputAttribute.inputPattern); + if (!InputTypeManager::GetInstance().IsStarted()) { + IMSA_HILOGD("SpecialFlag, input type is not started, start."); + // if need to switch ime, no need to hide panel first. + NeedHideWhenSwitchInputType(userId, inputClientInfo.needHide, type); + return StartInputType(userId, type); + } + if (!inputClientInfo.isNotifyInputStart) { + IMSA_HILOGD("SpecialFlag, same textField, input type is started, not deal."); + return ErrorCode::NO_ERROR; + } + if (type == InputType::SECURITY_INPUT) { + if (!InputTypeManager::GetInstance().IsSecurityImeStarted()) { + IMSA_HILOGD("securityFlag, new textField, input type is started, but it is not security, switch."); + NeedHideWhenSwitchInputType(userId, inputClientInfo.needHide, type); + return StartInputType(userId, type); + } + } + if (type == InputType::ONE_TIME_CODE) { + if (!InputTypeManager::GetInstance().IsOneTimeCodeImeStarted()) { + IMSA_HILOGD("OneTimeCodeFlag, new textField, input type is started, but it is not OneTimeCode, switch."); + NeedHideWhenSwitchInputType(userId, inputClientInfo.needHide, type); + return StartInputType(userId, type); + } + } + IMSA_HILOGD("SpecialFlag, other condition, not deal."); + return ErrorCode::NO_ERROR; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/src/input_type_manager.cpp b/services/src/input_type_manager.cpp index 81f236ae6..1409dc924 100644 --- a/services/src/input_type_manager.cpp +++ b/services/src/input_type_manager.cpp @@ -118,6 +118,21 @@ bool InputTypeManager::IsVoiceKbImeStarted() inputTypes_[InputType::VOICEKB_INPUT] == GetCurrentIme(); } +bool InputTypeManager::IsOneTimeCodeImeStarted() +{ + if (!IsStarted()) { + return false; + } + + std::lock_guard lock(typesLock_); + return inputTypes_.find(InputType::ONE_TIME_CODE) != inputTypes_.end() && + inputTypes_[InputType::ONE_TIME_CODE] == GetCurrentIme(); +} + +bool InputTypeManager::IsSpecialImeStarted() +{ + return IsOneTimeCodeImeStarted() || IsSecurityImeStarted(); +} InputType InputTypeManager::GetCurrentInputType() { if (IsSecurityImeStarted()) { @@ -132,6 +147,9 @@ InputType InputTypeManager::GetCurrentInputType() if (IsVoiceKbImeStarted()) { return InputType::VOICEKB_INPUT; } + if (IsOneTimeCodeImeStarted()) { + return InputType::ONE_TIME_CODE; + } return InputType::NONE; } 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 78c4a94a5..3441ab472 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -275,6 +275,23 @@ HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0) EXPECT_TRUE(outAttribute.GetSecurityFlag()); } +/** + * @tc.name: testSerializedInputAttribute001 + * @tc.desc: Checkout the serialization of InputAttribute. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute001, TestSize.Level0) +{ + InputAttribute inAttribute; + inAttribute.inputPattern = InputAttribute::PATTERN_ONE_TIME_CODE; + MessageParcel data; + EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data)); + InputAttribute outAttribute; + EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data)); + EXPECT_TRUE(outAttribute.GetSpecialFlag()); + EXPECT_TRUE(outAttribute.GetOneTimeCodeFlag()); +} + /** * @tc.name: testSerializedInputAttribute * @tc.desc: Checkout the serialization of InputAttribute. @@ -1525,6 +1542,7 @@ HWTEST_F(InputMethodAbilityTest, BranchCoverage002, TestSize.Level0) std::string vailidString = ""; std::shared_ptr info; bool needHide = false; + InputType type = InputType::NONE; auto ret = imsa_->OnStartInputType(vailidUserId, switchInfo, true); EXPECT_NE(ret, ErrorCode::NO_ERROR); @@ -1533,7 +1551,7 @@ HWTEST_F(InputMethodAbilityTest, BranchCoverage002, TestSize.Level0) ret = imsa_->SwitchExtension(vailidUserId, info); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); ret = imsa_->SwitchSubType(vailidUserId, info); - imsa_->NeedHideWhenSwitchInputType(vailidUserId, needHide); + imsa_->NeedHideWhenSwitchInputType(vailidUserId, needHide, type); EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); ret = imsa_->SwitchInputType(vailidUserId, switchInfo); EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND); 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 851db291e..25916b895 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 @@ -1247,8 +1247,9 @@ HWTEST_F(InputMethodPrivateMemberTest, BranchCoverage002, TestSize.Level0) EXPECT_EQ(ret2, ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND); bool needHide = false; + InputType type = InputType::NONE; auto ret3 = service_->IsCurrentIme(INVALID_USER_ID); - service_->NeedHideWhenSwitchInputType(INVALID_USER_ID, needHide); + service_->NeedHideWhenSwitchInputType(INVALID_USER_ID, needHide, type); EXPECT_FALSE(ret3); } diff --git a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp index a74ff2b25..e215a5c08 100644 --- a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp +++ b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp @@ -144,6 +144,26 @@ HWTEST_F(InputMethodControllerCapiTest, TestTextConfig_001, TestSize.Level0) OH_TextConfig_Destroy(config); } + +/** + * @tc.name: TestTextConfig_002 + * @tc.desc: create and destroy TestTextConfig success + * @tc.type: FUNC + */ +HWTEST_F(InputMethodControllerCapiTest, TestTextConfig_002, TestSize.Level0) +{ + auto config = OH_TextConfig_Create(); + ASSERT_NE(nullptr, config); + + // test set and get inputType + InputMethod_TextInputType expInputType = IME_TEXT_INPUT_TYPE_ONE_TIME_CODE; + InputMethod_TextInputType actInputType = IME_TEXT_INPUT_TYPE_NONE; + EXPECT_EQ(IME_ERR_OK, OH_TextConfig_SetInputType(config, expInputType)); + EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetInputType(config, &actInputType)); + EXPECT_EQ(expInputType, actInputType); + OH_TextConfig_Destroy(config); +} + void GetTextConfigFunc(InputMethod_TextEditorProxy *proxy, InputMethod_TextConfig *config) { } void InsertTextFunc(InputMethod_TextEditorProxy *proxy, const char16_t *text, size_t length) { } void DeleteForwardFunc(InputMethod_TextEditorProxy *proxy, int32_t length) { } diff --git a/test/unittest/cpp_test/src/json_operate_test.cpp b/test/unittest/cpp_test/src/json_operate_test.cpp index fb9f242a6..4d6bec21d 100644 --- a/test/unittest/cpp_test/src/json_operate_test.cpp +++ b/test/unittest/cpp_test/src/json_operate_test.cpp @@ -68,8 +68,10 @@ public: "\"defaultInputMethod\":\"bundleName/extName\"}, " "\"supportedInputTypeList\":[{\"inputType\":0,\"bundleName\":" "\"testBundleName\", " - "\"subtypeId\":\"testSubtypeId\"},{\"inputType\":1,\"bundleName\":" - "\"\", \"subtypeId\":\"\"}]}"; + "\"subtypeId\":\"testSubtypeId\"},{\"inputType\":13,\"bundleName\":" + "\"\", \"subtypeId\":\"\"},{\"inputType\":13,\"bundleName\":" + "\"testBundleName\", " +"\"subtypeId\":\"testSubtypeId\"}]}"; static constexpr const char *SYS_PANEL_ADJUST = "{\"sysPanelAdjust\":" "[{\"style\": [\"fix\",\"default\",\"landscape\"]," "\"top\": 1,\"left\": 2,\"right\": 3,\"bottom\": 4}]}"; @@ -274,13 +276,16 @@ HWTEST_F(JsonOperateTest, testParseInputType001, TestSize.Level0) auto ret = inputTypeCfg.Unmarshall(INPUT_SYS_CGF); ASSERT_TRUE(ret); auto inputType = inputTypeCfg.inputType; - ASSERT_EQ(inputType.size(), 2); + ASSERT_EQ(inputType.size(), 3); EXPECT_EQ(inputType[0].type, InputType::CAMERA_INPUT); EXPECT_EQ(inputType[0].subName, "testSubtypeId"); EXPECT_EQ(inputType[0].bundleName, "testBundleName"); EXPECT_EQ(inputType[1].type, InputType::SECURITY_INPUT); EXPECT_EQ(inputType[1].subName, ""); EXPECT_EQ(inputType[1].bundleName, ""); + EXPECT_EQ(inputType[2].type, InputType::ONE_TIME_CODE); + EXPECT_EQ(inputType[2].subName, "testSubtypeId"); + EXPECT_EQ(inputType[2].bundleName, "testBundleName"); } /** -- Gitee