diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 8d749c9d157960f313eecbef24b7cb7117eff4a2..3c23e55b50c8baffbe60afaab8b4e393515ac56e 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -138,6 +138,7 @@ public: void AddRestartIme(); bool IsProxyImeEnable(); + bool IsEnable(const std::shared_ptr &data); bool IsBoundToClient(uint64_t displayId); bool IsCurrentImeByPid(int32_t pid); int32_t RestoreCurrentImeSubType(uint64_t callingDisplayId); @@ -228,6 +229,7 @@ private: const std::shared_ptr &imeNativeCfg = nullptr); int32_t UpdateImeData(sptr core, sptr agent, pid_t pid); int32_t AddImeData(ImeType type, sptr core, sptr agent, pid_t pid); + void AddImeData(std::vector> &imeDataList, std::shared_ptr &imeData); void RemoveImeData(ImeType type); void RemoveImeData(pid_t pid); int32_t RemoveIme(ImeType type, pid_t pid); @@ -346,6 +348,7 @@ private: std::mutex connectionLock_{}; sptr connection_ = nullptr; std::atomic isBlockStartedByLowMem_ = false; + bool isFirstTime_ = false; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index ab28232a5195fc1e2dd4d4c6b3ba517028efcf4c..993d3f5006654cfc80208a30454ee7f4d87735b6 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1059,11 +1059,31 @@ int32_t PerUserSession::AddImeData(ImeType type, sptr core, sp } else if (type == ImeType::IME_MIRROR) { imeData->ime.first.append(GET_NAME(_IME_MIRROR)); } - imeDataList.push_back(imeData); + AddImeData(imeDataList, imeData); IMSA_HILOGI("add imeData with type: %{public}d name: %{public}s end", type, imeData->ime.first.c_str()); return ErrorCode::NO_ERROR; } +void PerUserSession::AddImeData(std::vector> &imeDataList, std::shared_ptr &imeData) +{ + if (imeDataList.empty()) { + imeDataList.push_back(imeData); + return; + } + if (!isFirstTime_) { + const auto &lastImeData = imeDataList.back(); + if (IsEnable(lastImeData) && !IsEnable(imeData)) { + imeDataList.insert(imeDataList.begin(), imeData); + } else { + imeDataList.push_back(imeData); + } + isFirstTime_ = true; + return; + } + imeDataList.push_back(imeData); + return; +} + std::shared_ptr PerUserSession::GetReadyImeData(ImeType type) { auto data = GetImeData(type); @@ -2849,5 +2869,15 @@ int32_t PerUserSession::PrepareImeInfos(ImeType type, std::vector &data) +{ + bool ret = false; + if (data == nullptr || data->core == nullptr) { + return false; + } + data->core->IsEnable(ret); + return ret; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cpp_test/src/ime_proxy_test.cpp b/test/unittest/cpp_test/src/ime_proxy_test.cpp index e55831229e1ff60b1d9153db12b1eeb54c6e5742..284666f78f088867f7dabea9bbb5b4726c604bfe 100644 --- a/test/unittest/cpp_test/src/ime_proxy_test.cpp +++ b/test/unittest/cpp_test/src/ime_proxy_test.cpp @@ -172,6 +172,21 @@ private: sptr ImeProxyTest::imc_; int32_t ImeProxyTest::uid_ { -1 }; +/** + * @tc.name: RegisteredProxyNotPermission + * @tc.desc: not in permission + * @tc.type: FUNC + */ +HWTEST_F(ImeProxyTest, RegisteredProxyNotPermission, TestSize.Level1) +{ + IMSA_HILOGI("ImeProxyTest::RegisteredProxyNotPermission"); + // RegisteredProxy not in ima bind + InputMethodEngineListenerImpl::ResetParam(); + InputMethodEngineListenerImpl::isEnable_ = true; + auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy(); + EXPECT_NE(ret, ErrorCode::NO_ERROR); +} + /** * @tc.name: RegisteredProxyNotInEditor_001 * @tc.desc: not in editor 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 b22bb83fa9afaba1318c677d24ded26470f3a2ae..01ee15501c5890042c370c676fe0594653fc9f51 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 @@ -2747,6 +2747,58 @@ HWTEST_F(InputMethodPrivateMemberTest, PerUserSession_AddImeData_001, TestSize.L EXPECT_EQ(it->second[1]->pid, pid1); } +/** + * @tc.name: PerUserSession_AddImeData_002 + * @tc.desc: PerUserSession_AddImeData_002 + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputMethodPrivateMemberTest, PerUserSession_AddImeData_002, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest::PerUserSession_AddImeData_002 start."); + auto userSession = std::make_shared(MAIN_USER_ID); + userSession->imeData_.clear(); + pid_t pid1 = 100; + sptr coreStub1 = new (std::nothrow) InputMethodCoreServiceImpl(); + sptr agentStub1 = new (std::nothrow) InputMethodAgentServiceImpl(); + userSession->isFirstTime_ = true; + auto ret = userSession->AddImeData(ImeType::PROXY_IME, coreStub1, agentStub1->AsObject(), pid1); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + auto it = userSession->imeData_.find(ImeType::PROXY_IME); + ASSERT_NE(it, userSession->imeData_.end()); + EXPECT_EQ(it->second.size(), 1); + + userSession->isFirstTime_ = false; + pid_t pid2 = 101; + sptr coreStub2 = new (std::nothrow) InputMethodCoreServiceImpl(); + sptr agentStub2 = new (std::nothrow) InputMethodAgentServiceImpl(); + auto imeData = std::make_shared(coreStub2, agentStub2, nullptr, pid2); + ret = userSession->AddImeData(ImeType::PROXY_IME, coreStub2, agentStub2->AsObject(), pid2); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + it = userSession->imeData_.find(ImeType::PROXY_IME); + ASSERT_NE(it, userSession->imeData_.end()); + EXPECT_EQ(it->second.size(), 2); + + userSession->isFirstTime_ = false; + ret = userSession->AddImeData(ImeType::PROXY_IME, coreStub1, agentStub1->AsObject(), pid1); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + it = userSession->imeData_.find(ImeType::PROXY_IME); + ASSERT_NE(it, userSession->imeData_.end()); + ASSERT_EQ(it->second.size(), 2); + EXPECT_EQ(it->second[1]->pid, pid1); + + sptr coreStub4 = new (std::nothrow) InputMethodCoreServiceImpl(); + sptr agentStub4 = new (std::nothrow) InputMethodAgentServiceImpl(); + userSession->isFirstTime_ = true; + pid_t pid4 = 104; + ret = userSession->AddImeData(ImeType::PROXY_IME, coreStub4, agentStub4->AsObject(), pid4); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + it = userSession->imeData_.find(ImeType::PROXY_IME); + ASSERT_NE(it, userSession->imeData_.end()); + ASSERT_EQ(it->second.size(), 3); + EXPECT_EQ(it->second[2]->pid, pid4); +} + /** * @tc.name: PerUserSession_GetImeData_001 * @tc.desc: imeData_ info abnormal 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 a97156348b55b0a62524e36ad7740218e9f7d735..a9157ca38173a942d6dc9f5773abaae8b899eb90 100644 --- a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp +++ b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp @@ -1457,42 +1457,6 @@ HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_SendPrivateCommand_0 EXPECT_EQ(ret, IME_ERR_NULL_POINTER); } -/** - * @tc.name: SendPrivateCommandWithInvalidCommandCount - * @tc.desc: input parameters is invalid - * @tc.type: FUNC - */ -HWTEST_F(InputMethodControllerCapiTest, SendPrivateCommandWithInvalidCommand, TestSize.Level0) -{ - auto textEditorProxy = OH_TextEditorProxy_Create(); - EXPECT_NE(nullptr, textEditorProxy); - ConstructTextEditorProxy(textEditorProxy); - - auto options = OH_AttachOptions_Create(true); - EXPECT_NE(nullptr, options); - InputMethod_InputMethodProxy *inputMethodProxy = nullptr; - - sptr ability = new (std::nothrow) MockInputMethodSystemAbilityProxy(); - InputMethodController::GetInstance()->SetImsaProxyForTest(ability); - ON_CALL(*ability, StartInput(_, _, _)).WillByDefault(Return(ErrorCode::NO_ERROR)); - ON_CALL(*ability, ReleaseInput(_, _)).WillByDefault(Return(ErrorCode::NO_ERROR)); - EXPECT_EQ(IME_ERR_OK, OH_InputMethodController_Attach(textEditorProxy, options, &inputMethodProxy)); - - InputMethod_PrivateCommand *privateCommand[MAX_SYS_PRIVATE_COMMAND_COUNT + 1] = { nullptr }; - auto ret = - OH_InputMethodProxy_SendPrivateCommand(inputMethodProxy, privateCommand, MAX_SYS_PRIVATE_COMMAND_COUNT + 1); - EXPECT_EQ(ret, IME_ERR_PARAMCHECK); - - size_t size = 1; - ret = OH_InputMethodProxy_SendPrivateCommand(inputMethodProxy, privateCommand, size); - EXPECT_EQ(ret, IME_ERR_NULL_POINTER); - - EXPECT_EQ(IME_ERR_OK, OH_InputMethodController_Detach(inputMethodProxy)); - InputMethodController::GetInstance()->SetImsaProxyForTest(nullptr); - - OH_AttachOptions_Destroy(options); - OH_TextEditorProxy_Destroy(textEditorProxy); -} /** * @tc.name: TestAttachWithNullParam_001 * @tc.desc: input parameters is nullptr