diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index a4656c99d39806820a5fd612fc03a6e61ef993d9..e4df501014e5e00504e80db142c91ddb8644b54d 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -1443,7 +1443,10 @@ void InputMethodAbility::OnClientInactive(const sptr &channel) } return false; }); - ClearBindInfo(channel); + // cannot clear inputAttribute,otherwise it will affect hicar + ClearDataChannel(channel); + ClearAttachOptions(); + ClearBindClientInfo(); } void InputMethodAbility::NotifyKeyboardHeight(uint32_t panelHeight, PanelFlag panelFlag) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 980e9839186cc90e8a4cf8f9b95709f459de3a5a..5ed4fa1bb1b27b2f2aaa0f3a2550d64ba5d68b95 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -273,10 +273,13 @@ int32_t InputMethodSystemAbility::RestoreInputmethod(std::string &bundleName) } int32_t userId = GetCallingUserId(); - auto result = EnableIme(userId, bundleName); - if (result != ErrorCode::NO_ERROR) { - IMSA_HILOGE("EnableIme failed"); - return ErrorCode::ERROR_ENABLE_IME; + auto defaultIme = ImeInfoInquirer::GetInstance().GetDefaultIme(); + if (defaultIme.bundleName != bundleName) { + auto result = EnableIme(userId, bundleName); + if (result != ErrorCode::NO_ERROR) { + IMSA_HILOGE("EnableIme failed"); + return ErrorCode::ERROR_ENABLE_IME; + } } auto session = UserSessionManager::GetInstance().GetUserSession(userId); 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 cd15f0fce2d71944aa6b6aafa94a6a7ac55e8558..626084f5b3404414122776b525576c5db355cefb 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -2134,8 +2134,7 @@ HWTEST_F(InputMethodAbilityTest, testClearBindInfo, TestSize.Level0) options.isSimpleKeyboardEnabled = true; inputMethodAbility_.SetAttachOptions(options); inputMethodAbility_.OnClientInactive(inputMethodAbility_.dataChannelObject_); - InputAttribute nullAttribute = {}; - EXPECT_TRUE(inputMethodAbility_.GetInputAttribute() == nullAttribute); + EXPECT_TRUE(inputMethodAbility_.GetBindClientInfo().name.empty()); EXPECT_TRUE(inputMethodAbility_.dataChannelObject_ == nullptr); InputMethodAbilityTest::GetIMCDetachIMA(); } 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 b198e434cba7dd2f4fb84d5328c7a3269a014a6d..2f2ca61f8dd61d2bc7bd54871564a57676ee5297 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 @@ -625,6 +625,38 @@ HWTEST_F(InputMethodPrivateMemberTest, SA_testReleaseInput_001, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER); } +/** + * @tc.name: III_TestRestoreInputMethod_001 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: chenyu + */ +HWTEST_F(InputMethodPrivateMemberTest, III_TestRestoreInputMethod_001, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest III_TestRestoreInputMethod_001 TEST START"); + std::string bundleName = ""; + auto ret = service_->RestoreInputmethod(bundleName); + EXPECT_EQ(ret, ErrorCode::ERROR_ENABLE_IME); + + auto currentProp = InputMethodController::GetInstance()->GetCurrentInputMethod(); + ret = service_->RestoreInputmethod(currentProp->name); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + auto defaultIme = ImeInfoInquirer::GetInstance().GetDefaultIme(); + ret = service_->RestoreInputmethod(defaultIme.bundleName); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + bundleName = "com.example.newTestIme"; + ret = service_->RestoreInputmethod(bundleName); + EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_REBOOT_OLD_IME_NOT_STOP); + + auto userId = service_->GetCallingUserId(); + UserSessionManager::GetInstance().RemoveUserSession(userId); + ret = service_->RestoreInputmethod(defaultIme.bundleName); + EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); +} + /** * @tc.name: III_TestGetCurrentInputMethodSubtype_001 * @tc.desc: diff --git a/test/unittest/resource/ohos_test/ohos_test.xml b/test/unittest/resource/ohos_test/ohos_test.xml index ef089ce739dc7f7cf3dc77d6ac4112240626e857..3d572b906343f8e5cf7e05adbc1a787bfaf80e5b 100644 --- a/test/unittest/resource/ohos_test/ohos_test.xml +++ b/test/unittest/resource/ohos_test/ohos_test.xml @@ -176,6 +176,11 @@