!1481 [Bug]: 修复GetStringById&更新default full判断 挑单5.0release

Merge pull request !1481 from wangdongqi/OpenHarmony-5.0-Release
This commit is contained in:
openharmony_ci 2024-09-19 11:26:17 +00:00 committed by Gitee
commit 1d38e10fa0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 111 additions and 29 deletions

View File

@ -112,6 +112,7 @@ enum {
ERROR_SYSTEM_CMD_CHANNEL_ERROR = 42,
ERROR_INVALID_PRIVATE_COMMAND = 43,
ERROR_OS_ACCOUNT = 44,
ERROR_RES_ERROR = 46,
};
}; // namespace ErrorCode

View File

@ -47,6 +47,7 @@ struct FullImeInfo {
bool isNewIme{ false };
uint32_t tokenId{ 0 };
std::string appId;
uint32_t versionCode;
Property prop;
std::vector<SubProperty> subProps;
};

View File

@ -125,8 +125,10 @@ bool SecurityModeParser::IsDefaultFullMode(const std::string &bundleName, int32_
return true;
}
std::string appId;
if (!ImeInfoInquirer::GetInstance().GetImeAppId(userId, bundleName, appId)) {
IMSA_HILOGE("%{public}s failed to get app id", bundleName.c_str());
uint32_t versionCode;
if (!ImeInfoInquirer::GetInstance().GetImeAppId(userId, bundleName, appId)
|| !ImeInfoInquirer::GetInstance().GetImeVersionCode(userId, bundleName, versionCode)) {
IMSA_HILOGE("%{public}s failed to get appId and versionCode", bundleName.c_str());
return false;
}
std::vector<DefaultFullImeInfo> defaultFullImeList;
@ -140,7 +142,12 @@ bool SecurityModeParser::IsDefaultFullMode(const std::string &bundleName, int32_
IMSA_HILOGD("not default FULL");
return false;
}
bool isDefaultFull = !IsExpired(ime->expirationTime);
bool isDefaultFull = false;
if (ime->expirationVersionCode > 0) {
isDefaultFull = !IsExpired(ime->expirationTime) || versionCode < ime->expirationVersionCode;
} else {
isDefaultFull = !IsExpired(ime->expirationTime);
}
IMSA_HILOGI("ime: %{public}s, isDefaultFull: %{public}d", bundleName.c_str(), isDefaultFull);
return isDefaultFull;
}

View File

@ -41,6 +41,11 @@ enum class Condition {
CHINESE,
};
enum class ImeTargetString {
LABEL = 0,
DESCRIPTION,
};
struct Subtype : public Serializable {
std::string label;
std::string id;
@ -82,6 +87,7 @@ public:
std::shared_ptr<SubProperty> FindTargetSubtypeByCondition(const std::vector<SubProperty> &subProps,
const Condition &condition);
bool GetImeAppId(int32_t userId, const std::string &bundleName, std::string &appId);
bool GetImeVersionCode(int32_t userId, const std::string &bundleName, uint32_t &versionCode);
int32_t GetDefaultInputMethod(const int32_t userId, std::shared_ptr<Property> &prop, bool isBrief = false);
int32_t GetInputMethodConfig(const int32_t userId, AppExecFwk::ElementName &inputMethodConfig);
int32_t ListInputMethod(int32_t userId, InputMethodStatus status, std::vector<Property> &props, bool enableOn);
@ -104,9 +110,12 @@ private:
~ImeInfoInquirer() = default;
OHOS::sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgr();
SubProperty GetExtends(const std::vector<OHOS::AppExecFwk::Metadata> &metaData);
std::string GetTargetString(
const AppExecFwk::ExtensionAbilityInfo &extension, ImeTargetString target, int32_t userId);
int32_t GetAppLabelFromRes(const AppExecFwk::ExtensionAbilityInfo &extension, std::string &label);
std::string GetStringById(const std::string &bundleName, const std::string &moduleName, const uint32_t labelId,
const int32_t userId);
bool GetAppIdByBundleName(int32_t userId, const std::string &bundleName, std::string &appId);
bool GetBundleInfoByBundleName(int32_t userId, const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo);
std::shared_ptr<ImeInfo> GetImeInfoFromCache(const int32_t userId, const std::string &bundleName,
const std::string &subName);
std::shared_ptr<ImeInfo> GetImeInfoFromBundleMgr(

View File

@ -100,10 +100,12 @@ struct SysPanelAdjustCfg : public Serializable {
struct DefaultFullImeInfo : public Serializable {
std::string appId;
std::string expirationTime;
uint32_t expirationVersionCode{ 0 };
bool Unmarshal(cJSON *node) override
{
bool ret = GetValue(node, GET_NAME(appIdentifier), appId);
ret &= GetValue(node, GET_NAME(expirationTime), expirationTime);
GetValue(node, GET_NAME(expirationVersionCode), expirationVersionCode);
return ret;
}
};

View File

@ -49,6 +49,7 @@ constexpr const char *TEMPORARY_INPUT_METHOD_METADATA_NAME = "ohos.extension.tem
constexpr uint32_t SUBTYPE_PROFILE_NUM = 1;
constexpr const char *DEFAULT_IME_KEY = "persist.sys.default_ime";
constexpr int32_t CONFIG_LEN = 128;
constexpr uint32_t DEFAULT_BMS_VALUE = 0;
} // namespace
ImeInfoInquirer &ImeInfoInquirer::GetInstance()
{
@ -167,8 +168,7 @@ std::shared_ptr<ImeInfo> ImeInfoInquirer::GetImeInfoFromBundleMgr(
auto info = std::make_shared<ImeInfo>();
info->prop.name = extInfos[0].bundleName;
info->prop.id = extInfos[0].name;
info->prop.label =
GetStringById(extInfos[0].bundleName, extInfos[0].moduleName, extInfos[0].applicationInfo.labelId, userId);
info->prop.label = GetTargetString(extInfos[0], ImeTargetString::LABEL, userId);
info->prop.labelId = extInfos[0].applicationInfo.labelId;
info->prop.iconId = extInfos[0].applicationInfo.iconId;
@ -237,9 +237,8 @@ std::vector<InputMethodInfo> ImeInfoInquirer::ListInputMethodInfo(const int32_t
std::vector<InputMethodInfo> properties;
for (const auto &extension : extensionInfos) {
auto applicationInfo = extension.applicationInfo;
auto label = GetStringById(extension.bundleName, extension.moduleName, applicationInfo.labelId, userId);
auto description =
GetStringById(extension.bundleName, extension.moduleName, applicationInfo.descriptionId, userId);
auto label = GetTargetString(extension, ImeTargetString::LABEL, userId);
auto description = GetTargetString(extension, ImeTargetString::DESCRIPTION, userId);
InputMethodInfo property;
property.mPackageName = extension.bundleName;
property.mAbilityName = extension.name;
@ -295,14 +294,8 @@ int32_t ImeInfoInquirer::ListInputMethod(const int32_t userId, std::vector<Prope
continue;
}
std::string label;
std::string resPath = extension.hapPath.empty() ? extension.resourcePath : extension.hapPath;
auto resMgr = GetResMgr(resPath);
if (resMgr != nullptr) {
auto errValue = resMgr->GetStringById(extension.applicationInfo.labelId, label);
if (errValue != RState::SUCCESS) {
IMSA_HILOGE("GetStringById failed, bundleName:%{public}s, id:%{public}d", extension.bundleName.c_str(),
extension.applicationInfo.labelId);
}
if (GetAppLabelFromRes(extension, label) != ErrorCode::NO_ERROR) {
IMSA_HILOGE("GetAppLabelFromRes failed");
}
props.push_back({ .name = extension.bundleName,
.id = extension.name,
@ -674,8 +667,7 @@ std::shared_ptr<Property> ImeInfoInquirer::GetImeProperty(
}
Property prop = { .name = extInfos[0].bundleName,
.id = extName.empty() ? extInfos[0].name : extName,
.label =
GetStringById(extInfos[0].bundleName, extInfos[0].moduleName, extInfos[0].applicationInfo.labelId, userId),
.label = GetTargetString(extInfos[0], ImeTargetString::LABEL, userId),
.labelId = extInfos[0].applicationInfo.labelId,
.iconId = extInfos[0].applicationInfo.iconId };
return std::make_shared<Property>(prop);
@ -1059,12 +1051,13 @@ int32_t ImeInfoInquirer::GetFullImeInfo(
imeInfo.tokenId = extInfos[0].applicationInfo.accessTokenId;
imeInfo.prop.name = extInfos[0].bundleName;
imeInfo.prop.id = extInfos[0].name;
imeInfo.prop.label =
GetStringById(extInfos[0].bundleName, extInfos[0].moduleName, extInfos[0].applicationInfo.labelId, userId);
imeInfo.prop.label = GetTargetString(extInfos[0], ImeTargetString::LABEL, userId);
imeInfo.prop.labelId = extInfos[0].applicationInfo.labelId;
imeInfo.prop.iconId = extInfos[0].applicationInfo.iconId;
if (!GetAppIdByBundleName(userId, imeInfo.prop.name, imeInfo.appId)) {
IMSA_HILOGE("%{public}s failed to get app id", imeInfo.prop.name.c_str());
BundleInfo bundleInfo;
if (GetBundleInfoByBundleName(userId, imeInfo.prop.name, bundleInfo)) {
imeInfo.appId = bundleInfo.signatureInfo.appIdentifier;
imeInfo.versionCode = bundleInfo.versionCode;
}
return ErrorCode::NO_ERROR;
}
@ -1130,25 +1123,87 @@ bool ImeInfoInquirer::GetImeAppId(int32_t userId, const std::string &bundleName,
appId = imeInfo.appId;
return true;
}
return GetAppIdByBundleName(userId, bundleName, appId);
BundleInfo bundleInfo;
if (!GetBundleInfoByBundleName(userId, bundleName, bundleInfo)) {
return false;
}
appId = bundleInfo.signatureInfo.appIdentifier;
return !appId.empty();
}
bool ImeInfoInquirer::GetAppIdByBundleName(int32_t userId, const std::string &bundleName, std::string &appId)
bool ImeInfoInquirer::GetImeVersionCode(int32_t userId, const std::string &bundleName, uint32_t &versionCode)
{
FullImeInfo imeInfo;
if (FullImeInfoManager::GetInstance().Get(bundleName, userId, imeInfo)) {
versionCode = imeInfo.versionCode;
return true;
}
BundleInfo bundleInfo;
if (!GetBundleInfoByBundleName(userId, bundleName, bundleInfo)) {
return false;
}
versionCode = bundleInfo.versionCode;
return true;
}
bool ImeInfoInquirer::GetBundleInfoByBundleName(
int32_t userId, const std::string &bundleName, AppExecFwk::BundleInfo &bundleInfo)
{
auto bundleMgr = GetBundleMgr();
if (bundleMgr == nullptr) {
IMSA_HILOGE("failed to get bundleMgr");
return false;
}
OHOS::AppExecFwk::BundleInfo bundleInfo;
auto ret = bundleMgr->GetBundleInfo(
bundleName, static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO), bundleInfo, userId);
if (!ret) {
IMSA_HILOGE("failed to get bundle info");
return false;
}
appId = bundleInfo.signatureInfo.appIdentifier;
return !appId.empty();
return true;
}
std::string ImeInfoInquirer::GetTargetString(
const AppExecFwk::ExtensionAbilityInfo &extension, ImeTargetString target, int32_t userId)
{
if (target == ImeTargetString::LABEL) {
if (extension.labelId != DEFAULT_BMS_VALUE) {
return GetStringById(extension.bundleName, extension.moduleName, extension.labelId, userId);
}
IMSA_HILOGD("Extension label is empty, get application label");
std::string label;
if (GetAppLabelFromRes(extension, label) != ErrorCode::NO_ERROR) {
IMSA_HILOGE("GetAppLabelFromRes failed");
}
return label;
}
if (target == ImeTargetString::DESCRIPTION) {
if (extension.descriptionId != DEFAULT_BMS_VALUE) {
return GetStringById(extension.bundleName, extension.moduleName, extension.descriptionId, userId);
}
IMSA_HILOGD("extension description is empty, get application description");
return GetStringById(extension.bundleName, extension.applicationInfo.descriptionResource.moduleName,
extension.applicationInfo.descriptionResource.id, userId);
}
IMSA_HILOGD("No match target string");
return "";
}
int32_t ImeInfoInquirer::GetAppLabelFromRes(const AppExecFwk::ExtensionAbilityInfo &extension, std::string &label)
{
std::string resPath = extension.hapPath.empty() ? extension.resourcePath : extension.hapPath;
auto resMgr = GetResMgr(resPath);
if (resMgr == nullptr) {
IMSA_HILOGE("failed to get resMgr");
return ErrorCode::NO_ERROR;
}
auto errValue = resMgr->GetStringById(extension.applicationInfo.labelId, label);
if (errValue != RState::SUCCESS) {
IMSA_HILOGE("GetStringById failed, bundleName:%{public}s, id:%{public}d", extension.bundleName.c_str(),
extension.applicationInfo.labelId);
return ErrorCode::ERROR_RES_ERROR;
}
return ErrorCode::NO_ERROR;
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -42,10 +42,16 @@ std::shared_ptr<Property> ImeInfoInquirer::GetDefaultImeCfgProp()
return defaultImeProperty_;
}
bool GetImeAppId(int32_t userId, const std::string &bundleName, std::string &appId)
bool ImeInfoInquirer::GetImeAppId(int32_t userId, const std::string &bundleName, std::string &appId)
{
appId = MOCK_APP_ID;
return true;
}
bool ImeInfoInquirer::GetImeVersionCode(int32_t userId, const std::string &bundleName, uint32_t &versionCode)
{
versionCode = 0;
return true;
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -33,6 +33,7 @@ public:
std::shared_ptr<Property> GetCurrentInputMethod(int32_t userId);
std::shared_ptr<Property> GetDefaultImeCfgProp();
bool GetImeAppId(int32_t userId, const std::string &bundleName, std::string &appId);
bool GetImeVersionCode(int32_t userId, const std::string &bundleName, uint32_t &versionCode);
private:
static std::shared_ptr<ImeInfo> defaultIme_;