!1539 【bugfix】修改密码编辑框拉起密码键盘时输入法应用异常退出重新拉起普通键盘问题。

Merge pull request !1539 from mashaoyin/master
This commit is contained in:
openharmony_ci 2024-10-26 11:04:24 +00:00 committed by Gitee
commit c8baa0d9da
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 42 additions and 12 deletions

View File

@ -145,6 +145,8 @@ public:
bool CheckPwdInputPatternConv(InputClientInfo &clientInfo);
int32_t RestoreCurrentIme();
int32_t SetInputType();
std::shared_ptr<ImeNativeCfg> GetImeNativeCfg(int32_t userId, const std::string &bundleName,
const std::string &subName);
private:
struct ResetManager {
@ -239,6 +241,7 @@ private:
bool StopExitingCurrentIme();
bool HandleFirstStart(const std::shared_ptr<ImeNativeCfg> &ime, bool isStopCurrentIme);
bool HandleStartImeTimeout(const std::shared_ptr<ImeNativeCfg> &ime);
bool CheckInputTypeToStart(std::shared_ptr<ImeNativeCfg> &imeToStart);
std::mutex imeStartLock_;
BlockData<bool> isImeStarted_{ MAX_IME_START_TIME, false };

View File

@ -854,19 +854,16 @@ int32_t InputMethodSystemAbility::SwitchInputType(int32_t userId, const SwitchIn
IMSA_HILOGE("%{public}d session is nullptr!", userId);
return ErrorCode::ERROR_NULL_POINTER;
}
auto targetImeProperty = ImeInfoInquirer::GetInstance().GetImeProperty(userId, switchInfo.bundleName);
if (targetImeProperty == nullptr) {
IMSA_HILOGE("GetImeProperty [%{public}d, %{public}s] failed!", userId, switchInfo.bundleName.c_str());
auto targetIme = session->GetImeNativeCfg(userId, switchInfo.bundleName, switchInfo.subName);
if (targetIme == nullptr) {
IMSA_HILOGE("targetIme is nullptr!");
return ErrorCode::ERROR_NULL_POINTER;
}
std::string targetName = switchInfo.bundleName + "/" + targetImeProperty->id;
ImeNativeCfg targetIme = { targetName, switchInfo.bundleName, switchInfo.subName, targetImeProperty->id };
InputTypeManager::GetInstance().Set(true, { switchInfo.bundleName, switchInfo.subName });
if (!session->StartIme(std::make_shared<ImeNativeCfg>(targetIme))) {
if (!session->StartIme(targetIme)) {
IMSA_HILOGE("start input method failed!");
InputTypeManager::GetInstance().Set(false);
return ErrorCode::ERROR_IME_START_FAILED;
}
InputTypeManager::GetInstance().Set(true, { switchInfo.bundleName, switchInfo.subName });
int32_t ret = session->SwitchSubtype({ .name = switchInfo.bundleName, .id = switchInfo.subName });
if (ret != ErrorCode::NO_ERROR) {
InputTypeManager::GetInstance().Set(false);

View File

@ -993,10 +993,13 @@ bool PerUserSession::IsSameClient(sptr<IInputClient> source, sptr<IInputClient>
bool PerUserSession::StartCurrentIme(bool isStopCurrentIme)
{
auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_);
auto imeToStart = ImeInfoInquirer::GetInstance().GetImeToStart(userId_);
IMSA_HILOGD("currentIme: %{public}s, imeToStart: %{public}s.", currentIme->imeId.c_str(),
imeToStart->imeId.c_str());
std::shared_ptr<ImeNativeCfg> imeToStart = nullptr;
if (!CheckInputTypeToStart(imeToStart)) {
auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_);
imeToStart = ImeInfoInquirer::GetInstance().GetImeToStart(userId_);
IMSA_HILOGD("currentIme: %{public}s, imeToStart: %{public}s.", currentIme->imeId.c_str(),
imeToStart->imeId.c_str());
}
if (!StartIme(imeToStart, isStopCurrentIme)) {
IMSA_HILOGE("failed to start ime!");
InputMethodSysEvent::GetInstance().InputmethodFaultReporter(ErrorCode::ERROR_IME_START_FAILED,
@ -1717,5 +1720,32 @@ bool PerUserSession::CheckPwdInputPatternConv(InputClientInfo &newClientInfo)
IMSA_HILOGI("new input pattern is normal.");
return exClientInfo->config.inputAttribute.GetSecurityFlag();
}
std::shared_ptr<ImeNativeCfg> PerUserSession::GetImeNativeCfg(int32_t userId, const std::string &bundleName,
const std::string &subName)
{
auto targetImeProperty = ImeInfoInquirer::GetInstance().GetImeProperty(userId, bundleName);
if (targetImeProperty == nullptr) {
IMSA_HILOGE("GetImeProperty [%{public}d, %{public}s] failed!", userId, bundleName.c_str());
return nullptr;
}
std::string targetName = bundleName + "/" + targetImeProperty->id;
ImeNativeCfg targetIme = { targetName, bundleName, subName, targetImeProperty->id };
return std::make_shared<ImeNativeCfg>(targetIme);
}
bool PerUserSession::CheckInputTypeToStart(std::shared_ptr<ImeNativeCfg> &imeToStart)
{
if (!InputTypeManager::GetInstance().IsStarted()) {
return false;
}
auto currentInputTypeIme = InputTypeManager::GetInstance().GetCurrentIme();
if (currentInputTypeIme.bundleName.empty()) {
auto currentInputType = InputTypeManager::GetInstance().GetCurrentInputType();
InputTypeManager::GetInstance().GetImeByInputType(currentInputType, currentInputTypeIme);
}
imeToStart = GetImeNativeCfg(userId_, currentInputTypeIme.bundleName, currentInputTypeIme.subName);
return true;
}
} // namespace MiscServices
} // namespace OHOS