From 2f7b38bfac6008d2c371b4906f9acc543a160528 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Tue, 15 Jul 2025 14:28:56 +0800 Subject: [PATCH] mod for simplekeyboard Signed-off-by: cy7717 --- .../src/input_method_ability.cpp | 7 +- services/include/peruser_session.h | 2 - services/src/input_method_system_ability.cpp | 4 - services/src/peruser_session.cpp | 87 ++++---- test/unittest/cpp_test/BUILD.gn | 23 +- .../src/input_method_ability_test.cpp | 26 ++- .../src/input_method_private_member_test.cpp | 196 ++++++++++++------ 7 files changed, 222 insertions(+), 123 deletions(-) diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index b05eff733..d5ebb1e42 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -588,10 +588,7 @@ int32_t InputMethodAbility::InvokeStartInputCallback(const TextTotalConfig &text } AttachOptions options; options.requestKeyboardReason = textConfig.requestKeyboardReason; - options.isSimpleKeyboardEnabled = (textConfig.inputAttribute.IsSecurityImeFlag() || - textConfig.inputAttribute.IsOneTimeCodeFlag() || !IsDefaultIme()) ? - false : - textConfig.isSimpleKeyboardEnabled; + options.isSimpleKeyboardEnabled = IsDefaultIme() ? textConfig.isSimpleKeyboardEnabled : false; InvokeAttachOptionsCallback(options, isNotifyInputStart || !isNotify_); if (isNotifyInputStart || !isNotify_) { isNotify_ = true; @@ -1195,7 +1192,7 @@ int32_t InputMethodAbility::NotifyPanelStatus(bool isUseParameterFlag, PanelFlag sysPanelStatus.isPanelRaised = false; sysPanelStatus.needFuncButton = false; } - if (GetAttachOptions().isSimpleKeyboardEnabled) { + if (GetAttachOptions().isSimpleKeyboardEnabled && !GetInputAttribute().IsOneTimeCodeFlag()) { sysPanelStatus.needFuncButton = false; } auto systemChannel = GetSystemCmdChannelProxy(); diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 908ea4a45..ff2a811bf 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -159,7 +159,6 @@ public: bool IsNumkeyAutoInputApp(const std::string &bundleName); std::pair GetCurrentInputPattern(); bool IsPreconfiguredDefaultImeSpecified(const InputClientInfo &inputClientInfo); - bool IsSimpleKeyboardEnabled(); bool IsImeSwitchForbidden(); std::pair StartPreconfiguredDefaultIme( uint64_t callingDisplayId, const ImeExtendInfo &imeExtendInfo = {}, bool isStopCurrentIme = false); @@ -239,7 +238,6 @@ private: bool WaitForCurrentImeStop(); void NotifyImeStopFinished(); - bool GetCurrentUsingImeId(ImeIdentification &imeId); bool CanStartIme(); int32_t ChangeToDefaultImeIfNeed( const std::shared_ptr &ime, std::shared_ptr &imeToStart); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index cdfe8bb98..36508d4e2 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -2378,10 +2378,6 @@ int32_t InputMethodSystemAbility::StartInputType(int32_t userId, InputType type) IMSA_HILOGI("only need input type in default display"); return ErrorCode::NO_ERROR; } - if (session->IsSimpleKeyboardEnabled() && type == InputType::CAMERA_INPUT) { - IMSA_HILOGI("current client simple keyboard enabled, not start camera input"); - return ErrorCode::ERROR_SCENE_UNSUPPORTED; - } ImeIdentification ime; int32_t ret = InputTypeManager::GetInstance().GetImeByInputType(type, ime); if (ret != ErrorCode::NO_ERROR) { diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 84248735d..0463b5428 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1125,9 +1125,25 @@ std::shared_ptr PerUserSession::GetRealCurrentIme(bool needMinGuar } } if (IsPreconfiguredDefaultImeSpecified(*clientInfo)) { - return ImeInfoInquirer::GetInstance().GetDefaultImeCfg(); + auto preconfiguredIme = ImeInfoInquirer::GetInstance().GetDefaultImeCfg(); + auto defaultIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); + if (preconfiguredIme != nullptr && defaultIme != nullptr && defaultIme->imeId == preconfiguredIme->imeId) { + return defaultIme; + } + if (preconfiguredIme != nullptr) { + return preconfiguredIme; + } + } + } +#ifdef IMF_SCREENLOCK_MGR_ENABLE + if (ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked()) { + auto preconfiguredIme = ImeInfoInquirer::GetInstance().GetDefaultImeCfg(); + auto defaultIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); + if (preconfiguredIme != nullptr && (defaultIme == nullptr || defaultIme->imeId != preconfiguredIme->imeId)) { + ImeCfgManager::GetInstance().ModifyTempScreenLockImeCfg(userId_, preconfiguredIme->imeId); } } +#endif return needMinGuarantee ? ImeInfoInquirer::GetInstance().GetImeToStart(userId_) : ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); } @@ -1199,24 +1215,6 @@ int32_t PerUserSession::StartCurrentIme(bool isStopCurrentIme) return ErrorCode::NO_ERROR; } -bool PerUserSession::GetCurrentUsingImeId(ImeIdentification &imeId) -{ - if (InputTypeManager::GetInstance().IsStarted()) { - IMSA_HILOGI("get right click on state current ime."); - auto currentIme = InputTypeManager::GetInstance().GetCurrentIme(); - imeId = currentIme; - return true; - } - auto currentImeCfg = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); - if (currentImeCfg == nullptr) { - IMSA_HILOGE("currentImeCfg is nullptr!"); - return false; - } - imeId.bundleName = currentImeCfg->bundleName; - imeId.subName = currentImeCfg->extName; - return true; -} - bool PerUserSession::CanStartIme() { return (IsSaReady(MEMORY_MANAGER_SA_ID) && IsWmsReady() && @@ -1504,25 +1502,25 @@ int32_t PerUserSession::RestoreCurrentImeSubType(uint64_t callingDisplayId) return ErrorCode::NO_ERROR; } auto typeIme = InputTypeManager::GetInstance().GetCurrentIme(); - auto cfgIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); - if (cfgIme->bundleName != typeIme.bundleName) { - IMSA_HILOGD("diff ime, not deal, restore ime when attach."); + InputTypeManager::GetInstance().Set(false); + auto imeData = GetReadyImeData(ImeType::IME); + if (imeData == nullptr) { + IMSA_HILOGD("has no ready ime, not deal."); return ErrorCode::NO_ERROR; } - auto imeData = GetReadyImeData(ImeType::IME); - InputTypeManager::GetInstance().Set(false); - if (imeData == nullptr || imeData->ime.first != cfgIme->bundleName || imeData->ime.second != cfgIme->extName) { + if (imeData->ime.first != typeIme.bundleName) { + IMSA_HILOGD("ready ime:%{public}s is not input type ime:%{public}s, not deal.", imeData->ime.first.c_str(), + typeIme.bundleName.c_str()); return ErrorCode::NO_ERROR; } - SubProperty subProp; - subProp.name = cfgIme->bundleName; - subProp.id = cfgIme->subName; - auto subPropTemp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(userId_); - if (subPropTemp != nullptr) { - subProp = *subPropTemp; + auto defaultIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); + std::string subName; + if (defaultIme != nullptr && imeData->ime.first == defaultIme->bundleName) { + IMSA_HILOGD("readyIme is input type ime, same to default ime:%{public}s.", typeIme.bundleName.c_str()); + subName = defaultIme->subName; } - IMSA_HILOGD("same ime, restore subtype: %{public}s.", cfgIme->subName.c_str()); - return SwitchSubtype(subProp); + IMSA_HILOGD("restore subtype: %{public}s/%{public}s.", imeData->ime.first.c_str(), subName.c_str()); + return NotifySubTypeChangedToIme(imeData->ime.first, subName); } bool PerUserSession::IsCurrentImeByPid(int32_t pid) @@ -2419,19 +2417,6 @@ bool PerUserSession::IsPreconfiguredDefaultImeSpecified(const InputClientInfo &i inputClientInfo.config.isSimpleKeyboardEnabled || inputClientInfo.config.inputAttribute.IsOneTimeCodeFlag(); } -bool PerUserSession::IsSimpleKeyboardEnabled() -{ - auto clientGroup = GetClientGroup(ImeType::IME); - auto clientInfo = clientGroup != nullptr ? clientGroup->GetCurrentClientInfo() : nullptr; - if (clientInfo == nullptr) { - return false; - } - return (clientInfo->config.inputAttribute.IsSecurityImeFlag() || - clientInfo->config.inputAttribute.IsOneTimeCodeFlag()) ? - false : - clientInfo->config.isSimpleKeyboardEnabled; -} - std::pair PerUserSession::GetImeUsedBeforeScreenLocked() { std::lock_guard lock(imeUsedLock_); @@ -2484,8 +2469,16 @@ std::pair PerUserSession::StartPreconfiguredD auto ret = StartIme(std::make_shared(preDefaultIme), isStopCurrentIme); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("start ime failed, ret: %{public}d!", ret); + return std::make_pair(ret, StartPreDefaultImeStatus::TO_START); + } + std::string subName; + auto defaultIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_); + if (defaultIme != nullptr && defaultIme->imeId == preDefaultIme.imeId) { + NotifyImeChangedToClients(); + subName = defaultIme->subName; } - return std::make_pair(ret, StartPreDefaultImeStatus::TO_START); + NotifySubTypeChangedToIme(preDefaultIme.bundleName, subName); + return std::make_pair(ErrorCode::NO_ERROR, StartPreDefaultImeStatus::TO_START); } void PerUserSession::NotifyOnInputStopFinished() diff --git a/test/unittest/cpp_test/BUILD.gn b/test/unittest/cpp_test/BUILD.gn index 7c2b9b6b0..5d18c1b0e 100644 --- a/test/unittest/cpp_test/BUILD.gn +++ b/test/unittest/cpp_test/BUILD.gn @@ -64,6 +64,7 @@ ohos_unittest("InputMethodControllerTest") { "${inputmethod_path}/services:inputmethod_service_static", "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ @@ -199,6 +200,7 @@ ohos_unittest("InputMethodAbilityTest") { "${inputmethod_path}/services/json:imf_json_static", "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ @@ -253,6 +255,7 @@ ohos_unittest("InputMethodServiceTest") { "${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/ohos_test:copy_ohos_test", ] external_deps = [ @@ -310,6 +313,8 @@ ohos_unittest("InputMethodDfxTest") { "${inputmethod_path}/services:inputmethod_service_static", "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/bundle_dependencies/extImfBundle:extImf", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ @@ -373,6 +378,8 @@ ohos_unittest("InputMethodPanelTest") { "${inputmethod_path}/services:inputmethod_service_static", "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/bundle_dependencies/extImfBundle:extImf", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ @@ -499,6 +506,9 @@ ohos_unittest("InputMethodSwitchTest") { "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/bundle_dependencies/extImfBundle:extImf", + "${inputmethod_path}/test/unittest/resource/bundle_dependencies/newTestIme:newTestIme", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ @@ -567,6 +577,8 @@ ohos_unittest("InputMethodPrivateMemberTest") { "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", "${inputmethod_path}/services:inputmethod_service_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 = [ @@ -628,6 +640,7 @@ ohos_unittest("InputMethodEditorTest") { "${inputmethod_path}/services/json:imf_json_static", "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ @@ -687,6 +700,8 @@ ohos_unittest("NewImeSwitchTest") { "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", "${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/ohos_test:copy_ohos_test", ] external_deps = [ @@ -1365,6 +1380,7 @@ ohos_unittest("ImfHisysEventReporterTest") { deps = [ "${inputmethod_path}/common/imf_hisysevent:imf_hisysevent", "${inputmethod_path}/services/json:imf_json_static", + "${inputmethod_path}/test/unittest/resource/ohos_test:copy_ohos_test", ] external_deps = [ @@ -1435,7 +1451,10 @@ ohos_unittest("InputMethodManagerCommandTest") { deps = [ "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", - "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client" ] + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", + "${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", @@ -1470,6 +1489,8 @@ ohos_unittest("ImeEnabledInfoManagerTest") { "${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 = [ 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 052e8724e..b95bef728 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -425,13 +425,37 @@ HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatus2, TestSize.Level0) ret = inputMethodAbility_.NotifyPanelStatus(false); EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); - + ret = inputMethodAbility_.NotifyPanelStatus(true, FLG_FIXED); EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); AttachOptions options; options.isSimpleKeyboardEnabled = true; inputMethodAbility_.SetAttachOptions(options); + InputAttribute inputAttribute; + inputAttribute.inputPattern = InputAttribute::PATTERN_ONE_TIME_CODE; + inputMethodAbility_.SetInputAttribute(inputAttribute); + ret = inputMethodAbility_.NotifyPanelStatus(false); + EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); + + options.isSimpleKeyboardEnabled = true; + inputMethodAbility_.SetAttachOptions(options); + inputAttribute.inputPattern = InputAttribute::PATTERN_NEWPASSWORD; + inputMethodAbility_.SetInputAttribute(inputAttribute); + ret = inputMethodAbility_.NotifyPanelStatus(false); + EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); + + options.isSimpleKeyboardEnabled = false; + inputMethodAbility_.SetAttachOptions(options); + inputAttribute.inputPattern = InputAttribute::PATTERN_ONE_TIME_CODE; + inputMethodAbility_.SetInputAttribute(inputAttribute); + ret = inputMethodAbility_.NotifyPanelStatus(false); + EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); + + options.isSimpleKeyboardEnabled = false; + inputMethodAbility_.SetAttachOptions(options); + inputAttribute.inputPattern = InputAttribute::PATTERN_NEWPASSWORD; + inputMethodAbility_.SetInputAttribute(inputAttribute); ret = inputMethodAbility_.NotifyPanelStatus(false); EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); } 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 1e174f4e1..d56e08653 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 @@ -1832,47 +1832,6 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_SpecialScenarioCheck, TestSize.Level0) EXPECT_FALSE(allow); } -/** - * @tc.name: SA_IsSimpleKeyboardEnabled - * @tc.desc: SA_IsSimpleKeyboardEnabled - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(InputMethodPrivateMemberTest, SA_IsSimpleKeyboardEnabled, TestSize.Level0) -{ - IMSA_HILOGI("InputMethodPrivateMemberTest::SA_IsSimpleKeyboardEnabled start."); - PerUserSession session(MAIN_USER_ID); - // has current client info - auto group = std::make_shared(DEFAULT_DISPLAY_ID, nullptr); - sptr client = new (std::nothrow) InputClientServiceImpl(); - group->currentClient_ = client; - auto info = std::make_shared(); - info->config.isSimpleKeyboardEnabled = false; - info->config.inputAttribute.inputPattern = InputAttribute::PATTERN_TEXT; - group->mapClients_.insert_or_assign(client->AsObject(), info); - session.clientGroupMap_.insert_or_assign(DEFAULT_DISPLAY_ID, group); - auto ret = session.IsSimpleKeyboardEnabled(); - EXPECT_FALSE(ret); - - info->config.isSimpleKeyboardEnabled = true; - group->mapClients_.insert_or_assign(client->AsObject(), info); - session.clientGroupMap_.insert_or_assign(DEFAULT_DISPLAY_ID, group); - ret = session.IsSimpleKeyboardEnabled(); - EXPECT_TRUE(ret); - - info->config.inputAttribute.inputPattern = InputAttribute::PATTERN_ONE_TIME_CODE; - group->mapClients_.insert_or_assign(client->AsObject(), info); - session.clientGroupMap_.insert_or_assign(DEFAULT_DISPLAY_ID, group); - ret = session.IsSimpleKeyboardEnabled(); - EXPECT_FALSE(ret); - - info->config.inputAttribute.inputPattern = InputAttribute::PATTERN_PASSWORD; - group->mapClients_.insert_or_assign(client->AsObject(), info); - session.clientGroupMap_.insert_or_assign(DEFAULT_DISPLAY_ID, group); - ret = session.IsSimpleKeyboardEnabled(); - EXPECT_FALSE(ret); -} - /** * @tc.name: SA_IsScreenLockOrSecurityFlag * @tc.desc: SA_IsScreenLockOrSecurityFlag @@ -2057,7 +2016,6 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_GetRealCurrentIme_002, TestSize.Level0 ASSERT_NE(realPreIme, nullptr); InputTypeManager::GetInstance().isTypeCfgReady_ = true; ImeIdentification inputTypeIme{ realPreIme->name, "" }; - InputTypeManager::GetInstance().inputTypes_.insert_or_assign(InputType::ONE_TIME_CODE, inputTypeIme); InputTypeManager::GetInstance().inputTypes_.insert_or_assign(InputType::SECURITY_INPUT, inputTypeIme); std::string bundleName1 = "bundleName1"; @@ -2097,49 +2055,50 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_GetRealCurrentIme_002, TestSize.Level0 HWTEST_F(InputMethodPrivateMemberTest, SA_GetRealCurrentIme_003, TestSize.Level0) { IMSA_HILOGI("InputMethodPrivateMemberTest::SA_GetRealCurrentIme_003 start."); - ImeInfoInquirer::GetInstance().systemConfig_.defaultImeScreenList.clear(); - std::shared_ptr realPreIme = nullptr; - InputMethodController::GetInstance()->GetDefaultInputMethod(realPreIme); - ASSERT_NE(realPreIme, nullptr); - InputTypeManager::GetInstance().isTypeCfgReady_ = true; - ImeIdentification inputTypeIme{ realPreIme->name, "" }; - InputTypeManager::GetInstance().inputTypes_.insert_or_assign(InputType::ONE_TIME_CODE, inputTypeIme); - InputTypeManager::GetInstance().inputTypes_.insert_or_assign(InputType::SECURITY_INPUT, inputTypeIme); - + // input type not start, has current client, input type is NONE, isSimpleKeyboardEnabled is true + InputTypeManager::GetInstance().isStarted_ = false; std::string bundleName1 = "bundleName1"; std::string extName1 = "extName1"; + std::string subName1 = "subName1"; ImeEnabledCfg cfg; ImeEnabledInfo enabledInfo{ bundleName1, extName1, EnabledStatus::BASIC_MODE }; enabledInfo.extraInfo.isDefaultIme = true; + enabledInfo.extraInfo.currentSubName = subName1; cfg.enabledInfos.push_back(enabledInfo); ImeEnabledInfoManager::GetInstance().imeEnabledCfg_.insert_or_assign(MAIN_USER_ID, cfg); - std::string bundleName2 = "bundleName2"; - std::string extName2 = "extName2"; - ImeInfoInquirer::GetInstance().systemConfig_.defaultInputMethod = bundleName2 + "/" + extName2; - - InputTypeManager::GetInstance().isStarted_ = false; auto session = std::make_shared(MAIN_USER_ID); auto group = std::make_shared(DEFAULT_DISPLAY_ID, nullptr); sptr client = new (std::nothrow) InputClientServiceImpl(); group->currentClient_ = client; auto info = std::make_shared(); - // has current client, input type is NONE, isSimpleKeyboardEnabled is true info->config.inputAttribute.inputPattern = 0; info->config.isSimpleKeyboardEnabled = true; group->mapClients_.insert_or_assign(client->AsObject(), info); session->clientGroupMap_.insert_or_assign(DEFAULT_DISPLAY_ID, group); - auto ime = session->GetRealCurrentIme(true); + + // preconfigured is nullptr + ImeInfoInquirer::GetInstance().systemConfig_.defaultInputMethod = "abnormal"; + auto ime = session->GetRealCurrentIme(false); ASSERT_NE(ime, nullptr); - EXPECT_EQ(ime->bundleName, bundleName2); + EXPECT_EQ(ime->bundleName, bundleName1); + EXPECT_EQ(ime->subName, subName1); - // has current client, input type is NONE, default ime not specified, needMinGuarantee is true - info->config.isSimpleKeyboardEnabled = false; - group->mapClients_.insert_or_assign(client->AsObject(), info); - session->clientGroupMap_.insert_or_assign(DEFAULT_DISPLAY_ID, group); + // preconfigured is not nullptr, preconfigured ime same with default ime + ImeInfoInquirer::GetInstance().systemConfig_.defaultInputMethod = bundleName1 + "/" + extName1; + ime = session->GetRealCurrentIme(true); + ASSERT_NE(ime, nullptr); + EXPECT_EQ(ime->bundleName, bundleName1); + EXPECT_EQ(ime->subName, subName1); + + // preconfigured is not nullptr, preconfigured ime not same with default ime + std::string bundleName2 = "bundleName2"; + std::string extName2 = "extName2"; + ImeInfoInquirer::GetInstance().systemConfig_.defaultInputMethod = bundleName2 + "/" + extName2; ime = session->GetRealCurrentIme(true); ASSERT_NE(ime, nullptr); EXPECT_EQ(ime->bundleName, bundleName2); + EXPECT_TRUE(ime->subName.empty()); } /** @@ -2483,5 +2442,116 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_TestRestartIme003, TestSize.Level0) usleep(WAIT_FOR_THREAD_SCHEDULE * MS_TO_US); EXPECT_EQ(session->restartTasks_, 0); } + +/** + * @tc.name: SA_RestoreCurrentImeSubType + * @tc.desc: SA_RestoreCurrentImeSubType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputMethodPrivateMemberTest, SA_RestoreCurrentImeSubType, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest::SA_RestoreCurrentImeSubType start."); + InputTypeManager::GetInstance().isStarted_ = true; + std::string bundleName = "bundleName"; + std::string extName = "extName"; + std::string subName = "subName"; + ImeEnabledCfg cfg; + ImeEnabledInfo enabledInfo{ bundleName, extName, EnabledStatus::BASIC_MODE }; + enabledInfo.extraInfo.isDefaultIme = true; + enabledInfo.extraInfo.currentSubName = subName; + cfg.enabledInfos.push_back(enabledInfo); + ImeEnabledInfoManager::GetInstance().imeEnabledCfg_.insert_or_assign(MAIN_USER_ID, cfg); + + auto session = std::make_shared(MAIN_USER_ID); + // has no ready ime + session->imeData_.clear(); + auto ret = session->RestoreCurrentImeSubType(0); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(InputTypeManager::GetInstance().isStarted_); + + // has ready ime, ready ime not same with inputType ime + InputTypeManager::GetInstance().isStarted_ = true; + std::string bundleName1 = "bundleName1"; + std::string extName1 = "extName1"; + InputTypeManager::GetInstance().currentTypeIme_.bundleName = bundleName1; + auto imeData = std::make_shared(nullptr, nullptr, nullptr, 10); + imeData->imeStatus = ImeStatus::READY; + imeData->ime = std::make_pair(bundleName, extName); + session->imeData_.insert_or_assign(ImeType::IME, imeData); + ret = session->RestoreCurrentImeSubType(0); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(InputTypeManager::GetInstance().isStarted_); + + // has ready ime, ready ime same with inputType ime, ready ime same with default ime + InputTypeManager::GetInstance().isStarted_ = true; + InputTypeManager::GetInstance().currentTypeIme_.bundleName = bundleName; + ret = session->RestoreCurrentImeSubType(0); + EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED); + EXPECT_FALSE(InputTypeManager::GetInstance().isStarted_); + + // has ready ime, ready ime same with inputType ime, ready ime not same with default ime + InputTypeManager::GetInstance().isStarted_ = true; + InputTypeManager::GetInstance().currentTypeIme_.bundleName = bundleName1; + imeData->ime = std::make_pair(bundleName1, extName1); + session->imeData_.insert_or_assign(ImeType::IME, imeData); + ret = session->RestoreCurrentImeSubType(0); + EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED); + EXPECT_FALSE(InputTypeManager::GetInstance().isStarted_); +} + +/** + * @tc.name: SA_GetRealCurrentIme_004 + * @tc.desc: SA_GetRealCurrentIme_004 + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputMethodPrivateMemberTest, SA_GetRealCurrentIme_004, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest::SA_GetRealCurrentIme_004 start."); + // input type not start, has no current client, screen locked + std::string cmdResult; + std::string cmd = "power-shell suspend"; + TddUtil::ExecuteCmd(cmd, cmdResult); + sleep(1); + InputTypeManager::GetInstance().isStarted_ = false; + auto session = std::make_shared(MAIN_USER_ID); + session->clientGroupMap_.clear(); + + std::string bundleName1 = "bundleName1"; + std::string extName1 = "extName1"; + std::string subName1 = "subName1"; + std::string bundleName2 = "bundleName2"; + std::string extName2 = "extName2"; + ImeEnabledCfg cfg; + ImeEnabledInfo enabledInfo{ bundleName1, extName1, EnabledStatus::BASIC_MODE }; + ImeEnabledInfo enabledInfo1{ bundleName2, extName2, EnabledStatus::BASIC_MODE }; + enabledInfo.extraInfo.isDefaultIme = true; + enabledInfo.extraInfo.currentSubName = subName1; + cfg.enabledInfos.push_back(enabledInfo); + cfg.enabledInfos.push_back(enabledInfo1); + ImeEnabledInfoManager::GetInstance().imeEnabledCfg_.insert_or_assign(MAIN_USER_ID, cfg); + + // preconfigured ime nullptr + ImeInfoInquirer::GetInstance().systemConfig_.defaultInputMethod = "abnormal"; + auto ime = session->GetRealCurrentIme(false); + ASSERT_NE(ime, nullptr); + EXPECT_EQ(ime->bundleName, bundleName1); + EXPECT_EQ(ime->subName, subName1); + + // preconfigured ime exist, default ime exist, preconfigured ime same with default ime + ImeInfoInquirer::GetInstance().systemConfig_.defaultInputMethod = bundleName1 + "/" + extName1; + ime = session->GetRealCurrentIme(false); + ASSERT_NE(ime, nullptr); + EXPECT_EQ(ime->bundleName, bundleName1); + EXPECT_EQ(ime->subName, subName1); + + // preconfigured ime exist, default ime exist, preconfigured ime not same with default ime + ImeInfoInquirer::GetInstance().systemConfig_.defaultInputMethod = bundleName2 + "/" + extName2; + ime = session->GetRealCurrentIme(false); + ASSERT_NE(ime, nullptr); + EXPECT_EQ(ime->bundleName, bundleName2); + EXPECT_TRUE(ime->subName.empty()); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file -- Gitee