diff --git a/frameworks/native/inputmethod_controller/include/input_method_property.h b/frameworks/native/inputmethod_controller/include/input_method_property.h index b5301b3a..457d9e91 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_property.h +++ b/frameworks/native/inputmethod_controller/include/input_method_property.h @@ -47,6 +47,7 @@ struct FullImeInfo { bool isNewIme{ false }; uint32_t tokenId{ 0 }; std::string appId; + uint32_t versionCode; Property prop; std::vector subProps; }; diff --git a/services/adapter/settings_data_provider/src/security_mode_parser.cpp b/services/adapter/settings_data_provider/src/security_mode_parser.cpp index 437f6fb2..6e92da89 100644 --- a/services/adapter/settings_data_provider/src/security_mode_parser.cpp +++ b/services/adapter/settings_data_provider/src/security_mode_parser.cpp @@ -124,8 +124,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 defaultFullImeList; @@ -139,7 +141,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; } diff --git a/services/include/ime_info_inquirer.h b/services/include/ime_info_inquirer.h index 8aa71af9..89e782cb 100644 --- a/services/include/ime_info_inquirer.h +++ b/services/include/ime_info_inquirer.h @@ -81,6 +81,7 @@ public: std::shared_ptr FindTargetSubtypeByCondition(const std::vector &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 &prop, bool isBrief = false); int32_t GetInputMethodConfig(const int32_t userId, AppExecFwk::ElementName &inputMethodConfig); int32_t ListInputMethod(int32_t userId, InputMethodStatus status, std::vector &props, bool enableOn); @@ -105,7 +106,7 @@ private: SubProperty GetExtends(const std::vector &metaData); 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 GetImeInfoFromCache(const int32_t userId, const std::string &bundleName, const std::string &subName); std::shared_ptr GetImeInfoFromBundleMgr( diff --git a/services/include/sys_cfg_parser.h b/services/include/sys_cfg_parser.h index d8fce9e3..c7b5c51f 100644 --- a/services/include/sys_cfg_parser.h +++ b/services/include/sys_cfg_parser.h @@ -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; } }; diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index 553fad62..1b3a8bf3 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -1063,8 +1063,10 @@ int32_t ImeInfoInquirer::GetFullImeInfo( GetStringById(extInfos[0].bundleName, extInfos[0].moduleName, extInfos[0].applicationInfo.labelId, 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 +1132,44 @@ 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; } - BundleInfo bundleInfo; auto ret = bundleMgr->GetBundleInfo( bundleName, static_cast(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; } } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cpp_test/mock/ime_info_inquirer.cpp b/test/unittest/cpp_test/mock/ime_info_inquirer.cpp index d2f2a292..9dc955e1 100644 --- a/test/unittest/cpp_test/mock/ime_info_inquirer.cpp +++ b/test/unittest/cpp_test/mock/ime_info_inquirer.cpp @@ -42,10 +42,16 @@ std::shared_ptr 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 \ No newline at end of file diff --git a/test/unittest/cpp_test/mock/ime_info_inquirer.h b/test/unittest/cpp_test/mock/ime_info_inquirer.h index d33b0312..827098b2 100644 --- a/test/unittest/cpp_test/mock/ime_info_inquirer.h +++ b/test/unittest/cpp_test/mock/ime_info_inquirer.h @@ -33,6 +33,7 @@ public: std::shared_ptr GetCurrentInputMethod(int32_t userId); std::shared_ptr 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 defaultIme_;