diff --git a/services/include/ime_info_inquirer.h b/services/include/ime_info_inquirer.h index 3f270a16..e56c6838 100644 --- a/services/include/ime_info_inquirer.h +++ b/services/include/ime_info_inquirer.h @@ -112,7 +112,6 @@ private: void ParseSubProp(const nlohmann::json &jsonSubProp, SubProperty &subProp); void ParseLanguage(const std::string &locale, std::string &language); bool QueryImeExtInfos(const int32_t userId, std::vector &infos); - std::vector GetEnableData(int32_t userId); ImeConfig imeConfig_; std::mutex currentImeInfoLock_; diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index bd78034d..f13b53e1 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -344,59 +344,60 @@ int32_t ImeInfoInquirer::ListInputMethod(const int32_t userId, std::vector ImeInfoInquirer::GetEnableData(int32_t userId) -{ - std::vector enableVec; - auto ret = EnableImeDataParser::GetInstance()->GetEnableData(EnableImeDataParser::ENABLE_IME, enableVec, userId); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("Get enable data failed, ret: %{public}d", ret); - return enableVec; - } - auto info = GetDefaultImeInfo(userId); - if (info != nullptr) { - enableVec.insert(enableVec.begin(), info->prop.name); - } - return enableVec; -} - int32_t ImeInfoInquirer::ListEnabledInputMethod(const int32_t userId, std::vector &props, bool enableOn) { - IMSA_HILOGD("userId: %{public}d, enableOn: %{public}d", userId, enableOn); + IMSA_HILOGD("userId: %{public}d", userId); int32_t ret = ListInputMethod(userId, props); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("userId: %{public}d listInputMethod failed", userId); return ret; } - if (!enableOn) { - return ErrorCode::NO_ERROR; - } - auto enableVec = GetEnableData(userId); - if (enableVec.empty()) { - return ErrorCode::ERROR_ENABLE_IME; - } - auto newEnd = std::remove_if(props.begin(), props.end(), [&enableVec](const auto &prop) { - return std::find(enableVec.begin(), enableVec.end(), prop.name) == enableVec.end(); - }); - props.erase(newEnd, props.end()); + if (enableOn) { + IMSA_HILOGD("enable on"); + std::vector enableVec; + ret = EnableImeDataParser::GetInstance()->GetEnableData(EnableImeDataParser::ENABLE_IME, enableVec, userId); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("Get enable data failed;"); + return ret; + } + auto info = GetDefaultImeInfo(userId); + if (info != nullptr) { + enableVec.insert(enableVec.begin(), info->prop.name); + } + auto newEnd = std::remove_if(props.begin(), props.end(), [&enableVec](const auto &prop) { + return std::find(enableVec.begin(), enableVec.end(), prop.name) == enableVec.end(); + }); + props.erase(newEnd, props.end()); + } return ErrorCode::NO_ERROR; } int32_t ImeInfoInquirer::ListDisabledInputMethod(const int32_t userId, std::vector &props, bool enableOn) { - IMSA_HILOGD("userId: %{public}d, enableOn: %{public}d", userId, enableOn); + IMSA_HILOGD("userId: %{public}d", userId); if (!enableOn) { + IMSA_HILOGD("Enable mode off, get disabled ime."); return ErrorCode::NO_ERROR; } + auto ret = ListInputMethod(userId, props); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("userId: %{public}d listInputMethod failed", userId); return ret; } - auto enableVec = GetEnableData(userId); - if (enableVec.empty()) { - return ErrorCode::ERROR_ENABLE_IME; + + std::vector enableVec; + ret = EnableImeDataParser::GetInstance()->GetEnableData(EnableImeDataParser::ENABLE_IME, enableVec, userId); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("Get enable data failed;"); + return ret; } + auto info = GetDefaultImeInfo(userId); + if (info != nullptr) { + enableVec.insert(enableVec.begin(), info->prop.name); + } + auto newEnd = std::remove_if(props.begin(), props.end(), [&enableVec](const auto &prop) { return std::find(enableVec.begin(), enableVec.end(), prop.name) != enableVec.end(); }); @@ -408,15 +409,15 @@ int32_t ImeInfoInquirer::GetNextSwitchInfo(SwitchInfo &switchInfo, int32_t userI { std::vector props; auto ret = ListEnabledInputMethod(userId, props, enableOn); - if (ret != ErrorCode::NO_ERROR || props.empty()) { - IMSA_HILOGE("userId: %{public}d ListEnabledInputMethod failed, ret: %{public}d", userId, ret); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("userId: %{public}d ListEnabledInputMethod failed", userId); return ret; } auto currentImeBundle = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId)->bundleName; auto iter = std::find_if(props.begin(), props.end(), [¤tImeBundle](const Property &property) { return property.name == currentImeBundle; }); if (iter == props.end()) { - IMSA_HILOGE("Can not found current ime"); + IMSA_HILOGE("Can not found current ime in enable list"); auto info = GetDefaultImeInfo(userId); if (info != nullptr) { switchInfo.bundleName = info->prop.name; @@ -426,7 +427,7 @@ int32_t ImeInfoInquirer::GetNextSwitchInfo(SwitchInfo &switchInfo, int32_t userI return ErrorCode::ERROR_PACKAGE_MANAGER; } auto nextIter = std::next(iter); - switchInfo.bundleName = nextIter == props.end() ? props[0].name : nextIter->name; + switchInfo.bundleName = nextIter == props.end() ? props[0].name: nextIter->name; IMSA_HILOGD("Next ime: %{public}s", switchInfo.bundleName.c_str()); return ErrorCode::NO_ERROR; }