mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-27 17:01:21 +00:00
mod
Signed-off-by: cy7717 <chenyu301@huawei.com>
This commit is contained in:
parent
81c9c32268
commit
69d51f6cab
@ -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<OHOS::AppExecFwk::ExtensionAbilityInfo> &infos);
|
||||
std::vector<std::string> GetEnableData(int32_t userId);
|
||||
|
||||
ImeConfig imeConfig_;
|
||||
std::mutex currentImeInfoLock_;
|
||||
|
@ -344,59 +344,60 @@ int32_t ImeInfoInquirer::ListInputMethod(const int32_t userId, std::vector<Prope
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
std::vector<std::string> ImeInfoInquirer::GetEnableData(int32_t userId)
|
||||
{
|
||||
std::vector<std::string> 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<Property> &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<std::string> 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<Property> &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<std::string> 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<Property> 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user