diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h index b30ef526b9ce2193345189ba228c6af4a2dab1be..ddefa5788955328f8174c703af19db439e2ad3ad 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h @@ -47,6 +47,7 @@ constexpr int8_t ALL_VERSIONCODE = -1; constexpr int8_t INVALID_UDID = -1; constexpr int8_t DEFAULT_INSTALLERID = -1; constexpr int8_t DEFAULT_APP_INDEX = 0; +constexpr size_t MAX_FILE_TYPES_SIZE = 1024; // uid and gid constexpr int32_t INVALID_UID = -1; @@ -98,6 +99,7 @@ constexpr const char* PERMISSION_UNINSTALL_PLUGIN = "ohos.permission.UNINSTALL_P constexpr const char* PERMISSION_PERFORM_LOCAL_DEBUG = "ohos.permission.PERFORM_LOCAL_DEBUG"; constexpr const char* PERMISSION_GET_ABILITY_INFO = "ohos.permission.GET_ABILITY_INFO"; constexpr const char* PERMISSION_BMS_INTERACT_ACROSS_LOCAL_ACCOUNTS = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS"; +constexpr const char* PERMISSION_MANAGE_SELF_SKILLS = "ohos.permission.MANAGE_SELF_SKILLS"; enum class AppType { SYSTEM_APP = 0, diff --git a/interfaces/inner_api/appexecfwk_base/src/skill.cpp b/interfaces/inner_api/appexecfwk_base/src/skill.cpp index c170fe80f9e719843d2db6f542cec708c56329c3..82172f64a7dac2d4848a892d84c50b08714f25a2 100644 --- a/interfaces/inner_api/appexecfwk_base/src/skill.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/skill.cpp @@ -50,11 +50,10 @@ constexpr const char* PARAM_SEPARATOR = "?"; constexpr const char* PORT_SEPARATOR = ":"; constexpr const char* SCHEME_SEPARATOR = "://"; constexpr const char* PATH_SEPARATOR = "/"; -constexpr const char* TYPE_WILDCARD = "*/*"; const char WILDCARD = '*'; constexpr const char* TYPE_ONLY_MATCH_WILDCARD = "reserved/wildcard"; const char* LINK_FEATURE = "linkFeature"; -const char* GENERAL_OBJECT = "general.object"; + const uint32_t PROTOCOL_OFFSET = 3; }; // namespace @@ -468,7 +467,7 @@ bool Skill::MatchType(const std::string &type, const std::string &skillUriType) // only match */* or general.object if (type == TYPE_ONLY_MATCH_WILDCARD) { - return skillUriType == TYPE_WILDCARD || skillUriType == GENERAL_OBJECT; + return skillUriType == ServiceConstants::TYPE_WILDCARD || skillUriType == ServiceConstants::GENERAL_OBJECT; } bool containsUtd = false; @@ -477,7 +476,7 @@ bool Skill::MatchType(const std::string &type, const std::string &skillUriType) return matchUtdRet; } - if (type == TYPE_WILDCARD || skillUriType == TYPE_WILDCARD) { + if (type == ServiceConstants::TYPE_WILDCARD || skillUriType == ServiceConstants::TYPE_WILDCARD) { // param is */* or config is */* return true; } diff --git a/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h b/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h index c75fc0c7eeb03c56e935582ae9ab61a6b45b4adc..75ab429922fe089c060ee83ed61c2fc6a0d0a0c6 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundle_framework_core_ipc_interface_code.h @@ -227,6 +227,7 @@ enum class BundleMgrInterfaceCode : uint32_t { CLEAN_BUNDLE_CACHE_FILES_FOR_SELF = 201, IS_DEBUGGABLE_APPLICATION = 202, GET_ALL_BUNDLE_NAMES = 203, + SET_ABILITY_FILE_TYPES_FOR_SELF = 204, }; /* SAID: 401-85 Interface No.85 subservice also provides the following interfaces */ diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h index 34f2d5a3a00cbd2df652dd8b465b29018d28663b..ec7890505df54e072e1d4fb1e2e2aa53589de398 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h @@ -940,6 +940,7 @@ private: ErrCode HandleGetAllShortcutInfoForSelf(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetPluginInfo(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetTestRunner(MessageParcel &data, MessageParcel &reply); + ErrCode HandleSetAbilityFileTypesForSelf(MessageParcel &data, MessageParcel &reply); private: /** * @brief Write a parcelabe vector objects to the proxy node. diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h index fe27220db94662bb4836166f8d397ec253c35f79..3ed178d9067f9ee8f1ccab6a1f4893989361a49a 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h @@ -1884,6 +1884,11 @@ public: { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } + virtual ErrCode SetAbilityFileTypesForSelf(const std::string &moduleName, const std::string &abilityName, + const std::vector &fileTypes) + { + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + } }; #define WRITE_PARCEL(func) \ diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h index 06878c3b918bcbf5468e803479261cada6b1c22a..70da86fb84932584910344664982f910fd72c6e5 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h @@ -1279,6 +1279,8 @@ public: virtual ErrCode GetTestRunner(const std::string &bundleName, const std::string &moduleName, ModuleTestRunner &testRunner) override; + virtual ErrCode SetAbilityFileTypesForSelf(const std::string &moduleName, const std::string &abilityName, + const std::vector &fileTypes) override; private: /** * @brief Send a command message from the proxy object. diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp index e263f4e6e0becdefb94a8457d5119bc2563a1e78..26561830917ea4c5bcc47e8eeed82a5def4c4155 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp @@ -5009,5 +5009,19 @@ ErrCode BundleMgrHost::HandleGetAllBundleNames(MessageParcel &data, MessageParce } return ERR_OK; } + +ErrCode BundleMgrHost::HandleSetAbilityFileTypesForSelf(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + std::string moduleName = data.ReadString(); + std::string abilityName = data.ReadString(); + std::vector fileTypes; + if (!data.ReadStringVector(&fileTypes)) { + APP_LOGE("ReadStringVector failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + ErrCode ret = SetAbilityFileTypesForSelf(moduleName, abilityName, fileTypes); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp index f973df156964dd0d4ef2b69a78d8b135ecbb5c75..02a3f6b620ed2a373d3be4cb50a8b8609907b043 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp @@ -6587,5 +6587,39 @@ ErrCode BundleMgrProxy::GetTestRunner( } return ERR_OK; } + +ErrCode BundleMgrProxy::SetAbilityFileTypesForSelf(const std::string &moduleName, const std::string &abilityName, + const std::vector &fileTypes) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + LOG_NOFUNC_I(BMS_TAG_QUERY, "SetAbilityFileTypesForSelf -m:%{public}s, -a:%{public}s", + moduleName.c_str(), abilityName.c_str()); + if (moduleName.empty() || abilityName.empty() || + fileTypes.empty() || fileTypes.size() > Constants::MAX_FILE_TYPES_SIZE) { + LOG_NOFUNC_E(BMS_TAG_QUERY, "invalid param"); + return ERR_BUNDLE_MANAGER_PARAM_ERROR; + } + + MessageParcel data; + (void)data.SetMaxCapacity(Constants::CAPACITY_SIZE); + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOG_NOFUNC_E(BMS_TAG_QUERY, "SetAbilityFileTypesForSelf write InterfaceToken failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteString(moduleName)) { + LOG_NOFUNC_E(BMS_TAG_QUERY, "SetAbilityFileTypesForSelf write moduleName failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteString(abilityName)) { + LOG_NOFUNC_E(BMS_TAG_QUERY, "SetAbilityFileTypesForSelf write abilityName failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteStringVector(fileTypes)) { + LOG_NOFUNC_E(BMS_TAG_QUERY, "SetAbilityFileTypesForSelf write fileTypes failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + return SendTransactCmd(BundleMgrInterfaceCode::SET_ABILITY_FILE_TYPES_FOR_SELF, data); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 446ee0de21761052bd89fcc00e2962c7b3de7c2d..fbb3083fd366eefd49b54f4616d6a743e3f3f846 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -800,6 +800,7 @@ private: void SetFirstInstallTime(const std::string &bundleName, const int64_t &time, InnerBundleInfo &info); bool SaveFirstInstallBundleInfo(const std::string &bundleName, const int32_t userId, bool isPreInstallApp, const InnerBundleUserInfo &innerBundleUserInfo); + void UpdateDynamicSkills(); ErrCode MarkInstallFinish(); bool IsArkWeb(const std::string &bundleName) const; void UninstallDebugAppSandbox(const std::string &bundleName, const int32_t uid, diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index 488462aa338d4e2fda05ecfbea151ab9302078c3..78bf21f2c566e29e00dbaefce0e802b04df3050f 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1187,7 +1187,8 @@ public: const int32_t userId, PluginBundleInfo &pluginBundleInfo); bool SetBundleUserInfoRemovable(const std::string bundleName, int32_t userId, bool removable); ErrCode GetTestRunner(const std::string &bundleName, const std::string &moduleName, ModuleTestRunner &testRunner); - + ErrCode SetAbilityFileTypesForSelf(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, const std::vector &fileTypes); private: /** * @brief Init transferStates. diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index f3ad23960ea60165cd2bf409af8e1059f71f2b79..ee111f0a1a3e7cc1ddc1b10b594fec0f86f1bea3 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1195,7 +1195,8 @@ public: const int32_t userId, PluginBundleInfo &pluginBundleInfo) override; virtual ErrCode GetTestRunner(const std::string &bundleName, const std::string &moduleName, ModuleTestRunner &testRunner) override; - + virtual ErrCode SetAbilityFileTypesForSelf(const std::string &moduleName, const std::string &abilityName, + const std::vector &fileTypes) override; private: bool GetLabelByBundleName(const std::string &bundleName, int32_t userId, std::string &label); bool GetAllBundleLabel(int32_t userId, std::string &labels); diff --git a/services/bundlemgr/include/bundle_service_constants.h b/services/bundlemgr/include/bundle_service_constants.h index 3b3cbebcfc5343c12dd17487dfbafe021cee4a30..09615c062c2d97d3f24c112bc9ba164d83f78183 100644 --- a/services/bundlemgr/include/bundle_service_constants.h +++ b/services/bundlemgr/include/bundle_service_constants.h @@ -71,6 +71,7 @@ constexpr const char* BASE = "/base/"; constexpr const char* CLONE = "clone"; constexpr const char* PLUS_SIGN = "+"; constexpr const char* MINUS_SIGN = "-"; +constexpr const char* DOT_SIGN = "."; constexpr const char* DATABASE = "/database/"; constexpr const char* SHAREFILES = "/sharefiles/"; constexpr const char* LOG = "/log/"; @@ -148,6 +149,11 @@ constexpr const char* PERMISSION_SUPPORT_PLUGIN = "ohos.permission.kernel.SUPPOR constexpr const char* PERMISSION_MANAGE_STORAGE = "ohos.permission.atomicService.MANAGE_STORAGE"; constexpr const char* FLAG_HOME_INTENT_FROM_SYSTEM = "flag.home.intent.from.system"; +constexpr const char* ACTION_VIEW_DATA = "ohos.want.action.viewData"; +constexpr const char* FILE = "file"; +constexpr const char* FILE_OPEN = "FileOpen"; +constexpr const char* TYPE_WILDCARD = "*/*"; +const char* GENERAL_OBJECT = "general.object"; // max number of haps under one direction constexpr uint8_t MAX_HAP_NUMBER = 128; constexpr const char* DATA_ABILITY_URI_PREFIX = "dataability://"; diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index 0c5e6a0a7bc51ddce03a3a9178aefa9f5a89d54f..24f9ef6aa752a5e20945738d8e2b5bfd10ef9d5b 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -600,6 +600,7 @@ public: { skillInfos_.emplace(key, skills); } + void UpdateDynamicSkills(); /** * @brief Insert extension skillInfos. * @param key bundleName.moduleName.extensionName @@ -1316,10 +1317,7 @@ public: /** * @brief Obtains all skillInfos. */ - const std::map> &GetInnerSkillInfos() const - { - return skillInfos_; - } + const std::map> GetInnerSkillInfos() const; /** * @brief Fetch all extensionAbilityInfos, can be modify. */ @@ -2357,6 +2355,8 @@ public: void UpdateHasCloudkitConfig(); int32_t GetModuleSize() const; bool GetModuleDeduplicateHar() const; + ErrCode SetAbilityFileTypesForSelf(const std::string &moduleName, const std::string &abilityName, + const std::vector &fileTypes); private: bool IsExistLauncherAbility() const; @@ -2385,6 +2385,8 @@ private: void PrintSetEnabledInfo(bool isEnabled, int32_t userId, int32_t appIndex, const std::string &bundleName, const std::string &caller) const; void GetPreInstallApplicationFlags(ApplicationInfo &appInfo) const; + std::string GetAbilityKey(const std::string &bundleName, const std::string &moduleName, const std::string &abilityName) const; + void AppendDynamicSkillsIfExist(AbilityInfo &abilityInfo) const; bool isSandboxApp_ = false; // Auxiliary property, which is used when the application @@ -2440,6 +2442,7 @@ private: std::map baseAbilityInfos_; std::map> skillInfos_; + std::map> dynamicAbilitySkills_; std::map innerBundleUserInfos_; std::map baseExtensionInfos_; diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 875a4746fb8d2eb8367f48200f1b06e1142291cc..1a9cfeba718cd8033940890ed766b0f72b492fdc 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1520,6 +1520,7 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector RemoveOldExtensionDirs(); /* process quick fix when install new moudle */ ProcessQuickFixWhenInstallNewModule(installParam, newInfos); + UpdateDynamicSkills(); VerifyDomain(); PatchDataMgr::GetInstance().ProcessPatchInfo(bundleName_, inBundlePaths, newInfos.begin()->second.GetVersionCode(), AppPatchType::INTERNAL, installParam.isPatch); @@ -6624,6 +6625,16 @@ void BaseBundleInstaller::PrepareSkillUri(const std::vector &skills, } #endif +void BaseBundleInstaller::UpdateDynamicSkills() +{ + InnerBundleInfo info; + if (!GetTempBundleInfo(info)) { + LOG_E(BMS_TAG_INSTALLER, "GetTempBundleInfo failed, bundleName: %{public}s", bundleName_.c_str()); + return; + } + info.UpdateDynamicSkills(); +} + void BaseBundleInstaller::VerifyDomain() { #ifdef APP_DOMAIN_VERIFY_ENABLED diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index d4c4232c84cd0a4c6a9d33c74041e2e1c30db235..1e9812a6e6347efd5ea3ec40a740f237879c0677 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -1293,7 +1293,9 @@ bool BundleDataMgr::QueryAbilityInfoWithFlags(const std::optional & info.metadata.clear(); } if ((static_cast(flags) & GET_ABILITY_INFO_WITH_SKILL) != GET_ABILITY_INFO_WITH_SKILL) { - info.skills.clear(); + info.skills.clear(); // to do + } else { + innerBundleInfo.AppendDynamicSkillsIfExist(info); } if ((static_cast(flags) & GET_ABILITY_INFO_WITH_APPLICATION) == GET_ABILITY_INFO_WITH_APPLICATION) { innerBundleInfo.GetApplicationInfo( @@ -1361,7 +1363,9 @@ ErrCode BundleDataMgr::QueryAbilityInfoWithFlagsV9(const std::optional(flags) & static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_WITH_SKILL)) != static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_WITH_SKILL)) { - info.skills.clear(); + info.skills.clear(); // to do + } else { + innerBundleInfo.AppendDynamicSkillsIfExist(info); } if ((static_cast(flags) & static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION)) == static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION)) { @@ -1672,7 +1676,7 @@ void BundleDataMgr::GetMatchAbilityInfos(const Want &want, int32_t flags, const if (CheckAbilityInfoFlagExist(flags, GET_ABILITY_INFO_SYSTEMAPP_ONLY) && !info.IsSystemApp()) { return; } - const std::map> &skillInfos = info.GetInnerSkillInfos(); + const std::map> skillInfos = info.GetInnerSkillInfos(); for (const auto &abilityInfoPair : info.GetInnerAbilityInfos()) { bool isPrivateType = MatchPrivateType( want, abilityInfoPair.second.supportExtNames, abilityInfoPair.second.supportMimeTypes, paramMimeTypes); @@ -1705,7 +1709,9 @@ void BundleDataMgr::GetMatchAbilityInfos(const Want &want, int32_t flags, const abilityinfo.metadata.clear(); } if (!CheckAbilityInfoFlagExist(flags, GET_ABILITY_INFO_WITH_SKILL)) { - abilityinfo.skills.clear(); + abilityinfo.skills.clear(); // to do + } else { + info.AppendDynamicSkillsIfExist(abilityinfo); } if (CheckAbilityInfoFlagExist(flags, GET_ABILITY_INFO_WITH_SKILL_URI)) { AddSkillUrisInfo(skillsPair->second, abilityinfo.skillUri, skillIndex, matchUriIndex); @@ -1777,7 +1783,9 @@ void BundleDataMgr::EmplaceAbilityInfo(const InnerBundleInfo &info, const std::v if ((static_cast(flags) & static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_WITH_SKILL)) != static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_WITH_SKILL)) { - abilityInfo.skills.clear(); + abilityInfo.skills.clear(); // to do + } else { + info.AppendDynamicSkillsIfExist(abilityInfo); } if ((static_cast(flags) & static_cast(GetAbilityInfoFlag::GET_ABILITY_INFO_WITH_SKILL_URI)) == @@ -1808,7 +1816,7 @@ void BundleDataMgr::GetMatchAbilityInfosV9(const Want &want, int32_t flags, cons LOG_W(BMS_TAG_QUERY, "target not system app"); return; } - const std::map> &skillInfos = info.GetInnerSkillInfos(); + const std::map> skillInfos = info.GetInnerSkillInfos(); for (const auto &abilityInfoPair : info.GetInnerAbilityInfos()) { AbilityInfo abilityinfo = InnerAbilityInfo::ConvertToAbilityInfo(abilityInfoPair.second); auto skillsPair = skillInfos.find(abilityInfoPair.first); @@ -2042,7 +2050,7 @@ void BundleDataMgr::GetMultiLauncherAbilityInfo(const Want& want, int64_t installTime, std::vector& abilityInfos) const { int32_t count = 0; - const std::map> &skillInfos = info.GetInnerSkillInfos(); + const std::map> skillInfos = info.GetInnerSkillInfos(); for (const auto& abilityInfoPair : info.GetInnerAbilityInfos()) { auto skillsPair = skillInfos.find(abilityInfoPair.first); if (skillsPair == skillInfos.end()) { @@ -11407,5 +11415,17 @@ ErrCode BundleDataMgr::GetTestRunner(const std::string &bundleName, const std::s BundleParser bundleParser; return bundleParser.ParseTestRunner(moduleInfo->hapPath, testRunner); } + +ErrCode BundleDataMgr::SetAbilityFileTypesForSelf(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, const std::vector &fileTypes) +{ + std::unique_lock lock(bundleInfoMutex_); + auto item = bundleInfos_.find(bundleName); + if (item == bundleInfos_.end()) { + APP_LOGE("-n %{public}s not exist", bundleName.c_str()); + return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; + } + return item->second.SetAbilityFileTypesForSelf(moduleName, abilityName, fileTypes); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 2a42a0e1d411525fb56e1b19175480df768fe262..80358cf8220cdaa09f162a31232278c81750eae3 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -6153,5 +6153,39 @@ ErrCode BundleMgrHostImpl::GetTestRunner(const std::string &bundleName, const st } return dataMgr->GetTestRunner(bundleName, moduleName, testRunner); } + +ErrCode BundleMgrHostImpl::SetAbilityFileTypesForSelf(const std::string &moduleName, const std::string &abilityName, + const std::vector &fileTypes) +{ + LOG_I(BMS_TAG_QUERY, "SetAbilityFileTypesForSelf -m:%{public}s, -a:%{public}s", + moduleName.c_str(), abilityName.c_str()); + if (moduleName.empty() || abilityName.empty() || + fileTypes.empty() || fileTypes.size() > Constants::MAX_FILE_TYPES_SIZE) { + LOG_E(BMS_TAG_QUERY, "invalid param"); + return ERR_BUNDLE_MANAGER_PARAM_ERROR; + } + + if (!BundlePermissionMgr::IsSystemApp()) { + LOG_E(BMS_TAG_QUERY, "non-system app calling system api"); + return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; + } + if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_MANAGE_SELF_SKILLS)) { + LOG_E(BMS_TAG_QUERY, "permission denied"); + return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; + } + + auto dataMgr = GetDataMgrFromService(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr null"); + return ERR_APPEXECFWK_NULL_PTR; + } + std::string bundleName; + ErrCode ret = dataMgr->GetNameForUid(IPCSkeleton::GetCallingUid(), bundleName); + if (ret != ERR_OK) { + APP_LOGE("GetNameForUid failed:%{public}d", ret); + return ret; + } + return dataMgr->SetAbilityFileTypesForSelf(bundleName, moduleName, abilityName, fileTypes); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/default_app/default_app_mgr.cpp b/services/bundlemgr/src/default_app/default_app_mgr.cpp index 7e28ac4f212ec14ce12f80e7ab97d9be6161052e..16f657921b924a16d7ec424960bc4d0efb23bcf5 100644 --- a/services/bundlemgr/src/default_app/default_app_mgr.cpp +++ b/services/bundlemgr/src/default_app/default_app_mgr.cpp @@ -58,7 +58,6 @@ constexpr const char* WORD = "WORD"; constexpr const char* EXCEL = "EXCEL"; constexpr const char* PPT = "PPT"; constexpr const char* EMAIL = "EMAIL"; -constexpr const char* ACTION_VIEW_DATA = "ohos.want.action.viewData"; constexpr const char* APP_TYPES_KEY[] = { IMAGE, AUDIO, VIDEO, PDF, WORD, EXCEL, PPT }; @@ -421,7 +420,7 @@ void DefaultAppMgr::HandleRemoveUser(int32_t userId) const bool DefaultAppMgr::IsBrowserWant(const Want& want) const { - bool matchAction = want.GetAction() == ACTION_VIEW_DATA; + bool matchAction = want.GetAction() == ServiceConstants::ACTION_VIEW_DATA; if (!matchAction) { LOG_D(BMS_TAG_DEFAULT, "Action does not match, not browser want"); return false; @@ -461,7 +460,7 @@ std::string DefaultAppMgr::GetTypeFromWant(const Want& want) const if (IsEmailWant(want)) { return EMAIL; } - if (want.GetAction() != ACTION_VIEW_DATA) { + if (want.GetAction() != ServiceConstants::ACTION_VIEW_DATA) { return Constants::EMPTY_STRING; } std::string uri = Skill::GetOptParamUri(want.GetUriString()); @@ -674,7 +673,7 @@ bool DefaultAppMgr::MatchAppType(const std::string& type, const std::vector& skills) const { LOG_D(BMS_TAG_DEFAULT, "begin to verify browser skills"); Want httpWant; - httpWant.SetAction(ACTION_VIEW_DATA); + httpWant.SetAction(ServiceConstants::ACTION_VIEW_DATA); httpWant.AddEntity(ENTITY_BROWSER); httpWant.SetUri(HTTP); Want httpsWant; - httpsWant.SetAction(ACTION_VIEW_DATA); + httpsWant.SetAction(ServiceConstants::ACTION_VIEW_DATA); httpsWant.AddEntity(ENTITY_BROWSER); httpsWant.SetUri(HTTPS); for (const Skill& skill : skills) { @@ -723,7 +722,7 @@ bool DefaultAppMgr::IsEmailSkillsValid(const std::vector& skills) const bool DefaultAppMgr::MatchUtd(const std::string& utd, const std::vector& skills) const { LOG_D(BMS_TAG_DEFAULT, "utd : %{public}s", utd.c_str()); - if (MatchActionAndType(ACTION_VIEW_DATA, utd, skills)) { + if (MatchActionAndType(ServiceConstants::ACTION_VIEW_DATA, utd, skills)) { return true; } LOG_E(BMS_TAG_DEFAULT, "match utd failed"); diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index 9f5713b3ffec1ada446b807c15b714c54247d665..2ee5ae5ce360dee0acec8596fa3aab8d268517a2 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -41,6 +41,7 @@ constexpr const char* BASE_BUNDLE_INFO = "baseBundleInfo"; constexpr const char* BASE_ABILITY_INFO = "baseAbilityInfos"; constexpr const char* INNER_MODULE_INFO = "innerModuleInfos"; constexpr const char* SKILL_INFOS = "skillInfos"; +constexpr const char* DYNAMIC_ABILITY_SKILLS = "dynamicAbilitySkills"; constexpr const char* USER_ID = "userId_"; constexpr const char* APP_FEATURE = "appFeature"; constexpr const char* NAME = "name"; @@ -162,6 +163,7 @@ constexpr const char* MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR = "abilityStageSr constexpr const char* MODULE_BOOL_SET = "boolSet"; constexpr uint32_t PREINSTALL_SOURCE_CLEAN_MASK = ~0B1110; constexpr int32_t CPM_KEY_NOT_EXIST = 0x7A000005; +constexpr size_t MAX_FILE_TYPE_SIZE = 500; inline CompileMode ConvertCompileMode(const std::string& compileMode) { @@ -344,6 +346,7 @@ InnerBundleInfo &InnerBundleInfo::operator=(const InnerBundleInfo &info) this->shortcutInfos_ = info.shortcutInfos_; this->baseAbilityInfos_ = info.baseAbilityInfos_; this->skillInfos_ = info.skillInfos_; + this->dynamicAbilitySkills_ = info.dynamicAbilitySkills_; this->innerBundleUserInfos_ = info.innerBundleUserInfos_; this->bundlePackInfo_ = std::make_shared(); if (info.bundlePackInfo_ != nullptr) { @@ -528,6 +531,7 @@ void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const jsonObject[INNER_MODULE_INFO] = innerModuleInfos_; jsonObject[INNER_SHARED_MODULE_INFO] = innerSharedModuleInfos_; jsonObject[SKILL_INFOS] = skillInfos_; + jsonObject[DYNAMIC_ABILITY_SKILLS] = dynamicAbilitySkills_; jsonObject[USER_ID] = userId_; jsonObject[APP_FEATURE] = appFeature_; jsonObject[MODULE_FORMS] = formInfos_; @@ -1388,6 +1392,14 @@ int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject) true, parseResult, ArrayType::NOT_ARRAY); + GetValueIfFindKey>>(jsonObject, + jsonObjectEnd, + DYNAMIC_ABILITY_SKILLS, + dynamicAbilitySkills_, + JsonType::OBJECT, + false, + parseResult, + ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, USER_ID, @@ -1817,6 +1829,26 @@ std::optional InnerBundleInfo::FindExtensionInfo( return std::nullopt; } +const std::map> InnerBundleInfo::GetInnerSkillInfos() const +{ + std::map> mergedSkills = skillInfos_; + for (const auto &[key, dynamicSkills] : dynamicAbilitySkills_) { + mergedSkills[key].insert(mergedSkills[key].end(), dynamicSkills.begin(), dynamicSkills.end()); + } + return mergedSkills; +} + +void InnerBundleInfo::UpdateDynamicSkills() +{ + for (auto dynamicIter = dynamicAbilitySkills_.begin(); dynamicIter != dynamicAbilitySkills_.end();) { + auto abilityIter = baseAbilityInfos_.find(dynamicIter->first); + if (abilityIter == baseAbilityInfos_.end()) { + // ability not exist, delete + dynamicIter = dynamicAbilitySkills_.erase(dynamicIter); + } + } +} + bool InnerBundleInfo::AddModuleInfo(const InnerBundleInfo &newInfo) { if (newInfo.currentPackage_.empty()) { @@ -2828,7 +2860,9 @@ void InnerBundleInfo::GetBundleWithAbilitiesV9( } if ((static_cast(flags) & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SKILL)) != static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SKILL)) { - abilityInfo.skills.clear(); + abilityInfo.skills.clear(); // to do + } else { + AppendDynamicSkillsIfExist(abilityInfo); } hapModuleInfo.abilityInfos.emplace_back(abilityInfo); @@ -2881,7 +2915,9 @@ void InnerBundleInfo::GetBundleWithAbilities( } abilityInfo.enabled = isEnabled; if ((static_cast(flags) & GET_BUNDLE_WITH_SKILL) != GET_BUNDLE_WITH_SKILL) { - abilityInfo.skills.clear(); + abilityInfo.skills.clear(); // to do + } else { + AppendDynamicSkillsIfExist(abilityInfo); } abilityInfo.appIndex = appIndex; bundleInfo.abilityInfos.emplace_back(abilityInfo); @@ -5515,5 +5551,64 @@ bool InnerBundleInfo::GetModuleDeduplicateHar() const } return hasDedupLicateHarInHsp; } + +std::string InnerBundleInfo::GetAbilityKey( + const std::string &bundleName, const std::string &moduleName, const std::string &abilityName) const +{ + return bundleName + ServiceConstants::DOT_SIGN + moduleName + ServiceConstants::DOT_SIGN + abilityName; +} + +void InnerBundleInfo::AppendDynamicSkillsIfExist(AbilityInfo &abilityInfo) const +{ + if (dynamicAbilitySkills_.empty()) { + return; + } + std::string abilityKey = GetAbilityKey(abilityInfo.bundleName, abilityInfo.moduleName, abilityInfo.name); + auto item = dynamicAbilitySkills_.find(abilityKey); + if (item != dynamicAbilitySkills_.end()) { + abilityInfo.skills.insert(abilityInfo.skills.end(), item->second.begin(), item->second.end()); + } +} + +ErrCode InnerBundleInfo::SetAbilityFileTypesForSelf(const std::string &moduleName, const std::string &abilityName, + const std::vector &fileTypes) +{ + auto moduleInfo = innerModuleInfos_.find(moduleName); + if (moduleInfo == innerModuleInfos_.end()) { + APP_LOGE("-m %{public}s not exist", moduleName.c_str()); + return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST; + } + std::string abilityKey = GetAbilityKey(GetBundleName(), moduleName, abilityName); + auto item = baseAbilityInfos_.find(abilityKey); + if (item == baseAbilityInfos_.end()) { + APP_LOGE("-a %{public}s not exist", abilityName.c_str()); + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + if (moduleName != item->second.moduleName || abilityName != item->second.name) { + APP_LOGE("-a %{public}s not exist", abilityName.c_str()); + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + std::vector skills; + Skill skill; + skill.actions = {ServiceConstants::ACTION_VIEW_DATA}; + for (const std::string &fileType : fileTypes) { + if (fileType.empty() || fileType.size() > MAX_FILE_TYPE_SIZE) { + APP_LOGE("invalid fileType"); + return ERR_BUNDLE_MANAGER_INVALID_PARAM; + } + if (fileType == ServiceConstants::TYPE_WILDCARD || fileType == ServiceConstants::GENERAL_OBJECT) { + APP_LOGE("not allowed fileType:%{public}s", fileType.c_str()); + return ERR_BUNDLE_MANAGER_INVALID_PARAM; + } + SkillUri skillUri; + skillUri.scheme = ServiceConstants::FILE; + skillUri.type = fileType; + skillUri.linkFeature = ServiceConstants::FILE_OPEN; + skill.uris.emplace_back(skillUri); + } + skills.emplace_back(skill); + dynamicAbilitySkills_[abilityKey] = skills; + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS