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 369f70995e2f5ad87ef603088860f798777a9e83..524594175c32eceaaaa9d44a077c3cb7b2aba67a 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 @@ -196,6 +196,7 @@ enum class BundleMgrInterfaceCode : uint32_t { GET_ALL_BUNDLE_CACHE = 171, CLEAN_ALL_BUNDLE_CACHE = 172, GET_SIMPLE_APP_INFO_FOR_UID = 173, + GET_BUNDLE_ARCHIVE_INFO_EXT = 178, }; /* 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 3f329a0744a5b1899ef3a1506ffd01fbe003109d..2d1db71c068c21927a7dd8b93205ec09c7320f81 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 @@ -56,6 +56,13 @@ private: * @return Returns ERR_OK if called successfully; returns error code otherwise. */ ErrCode HandleGetApplicationInfoWithIntFlagsV9(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handles the GetApplicationInfoV9 function called from a IBundleMgr proxy object. + * @param data Indicates the data to be read. + * @param reply Indicates the reply to be sent; + * @return Returns ERR_OK if called successfully; returns error code otherwise. + */ + ErrCode HandleGetBundleArchiveInfoExt(MessageParcel &data, MessageParcel &reply); /** * @brief Handles the GetApplicationInfos function called from a IBundleMgr proxy object. * @param data Indicates the data to be read. 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 0ac8200c180245e3ce3128cff551ee0e88d6847e..474b5a8e37ea636d8ccadde44be9bb06ced1d4fa 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 @@ -658,6 +658,19 @@ public: { return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; } + /** + * @brief Obtains information about an application bundle contained in an ohos Ability Package (HAP). + * @param hapFilePath Indicates the absolute file path of the HAP. + * @param fd Indicates the FileDescriptor. + * @param flags Indicates the information contained in the BundleInfo object to be returned. + * @param bundleInfo Indicates the obtained BundleInfo object. + * @return Returns ERR_OK if this function is successfully called; returns errCode otherwise. + */ + virtual ErrCode GetBundleArchiveInfoExt( + const std::string &hapFilePath, int32_t fd, int32_t flags, BundleInfo &bundleInfo) + { + return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + } /** * @brief Obtain the HAP module info of a specific ability. * @param abilityInfo Indicates the ability. 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 0b5c612e3c3f8c954a05cc99d20b7a6c567e1c45..5f4e6e1bb960870b74be234ffdbe2ecc6864740b 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 @@ -485,6 +485,16 @@ public: */ virtual ErrCode GetBundleArchiveInfoV9( const std::string &hapFilePath, int32_t flags, BundleInfo &bundleInfo) override; + /** + * @brief Obtains information about an application bundle contained in an ohos Ability Package (HAP). + * @param hapFilePath Indicates the absolute file path of the HAP. + * @param fd Indicates the FileDescriptor. + * @param flags Indicates the information contained in the BundleInfo object to be returned. + * @param bundleInfo Indicates the obtained BundleInfo object. + * @return Returns ERR_OK if this function is successfully called; returns errCode otherwise. + */ + virtual ErrCode GetBundleArchiveInfoExt( + const std::string &hapFilePath, int32_t fd, int32_t flags, BundleInfo &bundleInfo) override; /** * @brief Obtain the HAP module info of a specific ability through the proxy object. * @param abilityInfo Indicates the ability. 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 85b7bd51aa81e2e05d656ce38e90996e3db5159a..130aadc6b248284f778a90458225eaa86a3f2bc6 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 @@ -116,6 +116,9 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa case static_cast(BundleMgrInterfaceCode::GET_APPLICATION_INFO_WITH_INT_FLAGS_V9): errCode = this->HandleGetApplicationInfoWithIntFlagsV9(data, reply); break; + case static_cast(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_EXT): + errCode = this->HandleGetBundleArchiveInfoExt(data, reply); + break; case static_cast(BundleMgrInterfaceCode::GET_APPLICATION_INFOS_WITH_INT_FLAGS): errCode = this->HandleGetApplicationInfosWithIntFlags(data, reply); break; @@ -701,6 +704,29 @@ ErrCode BundleMgrHost::HandleGetApplicationInfoWithIntFlagsV9(MessageParcel &dat return ERR_OK; } +ErrCode BundleMgrHost::HandleGetBundleArchiveInfoExt(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + std::string hapFilePath = data.ReadString(); + int32_t fd = data.ReadFileDescriptor(); + int32_t flags = data.ReadInt32(); + APP_LOGD("hapFilePath %{private}s, fd %{public}d", hapFilePath.c_str(), fd); + + BundleInfo info; + ErrCode ret = GetBundleArchiveInfoExt(hapFilePath, fd, flags, info); + if (!reply.WriteInt32(ret)) { + APP_LOGE("write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (ret == ERR_OK) { + if (!reply.WriteParcelable(&info)) { + APP_LOGE("write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + return ERR_OK; +} + ErrCode BundleMgrHost::HandleGetApplicationInfos(MessageParcel &data, MessageParcel &reply) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); 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 53b2c317edf50c773d34c4fc7f45edb9bd87c459..a4c3d8e2a921fcb2cf656eb10c58fa3e24beba5c 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 @@ -1519,6 +1519,37 @@ ErrCode BundleMgrProxy::GetBundleArchiveInfoV9(const std::string &hapFilePath, i BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_WITH_INT_FLAGS_V9, data, bundleInfo); } +ErrCode BundleMgrProxy::GetBundleArchiveInfoExt( + const std::string &hapFilePath, int32_t fd, int32_t flags, BundleInfo &bundleInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + APP_LOGD("begin to GetBundleArchiveInfoV9 with int flags of %{private}s", hapFilePath.c_str()); + if (hapFilePath.empty()) { + APP_LOGE("fail to GetBundleArchiveInfoV9 due to params empty"); + return ERR_BUNDLE_MANAGER_INVALID_HAP_PATH; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + APP_LOGE("fail to GetBundleArchiveInfoV9 due to write InterfaceToken fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteString(hapFilePath)) { + APP_LOGE("fail to GetBundleArchiveInfoV9 due to write hapFilePath fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteFileDescriptor(fd)) { + APP_LOGE("fail to GetBundleArchiveInfo due to write FileDescriptor fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt32(flags)) { + APP_LOGE("fail to GetBundleArchiveInfoV9 due to write flags fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return GetParcelableInfoWithErrCode( + BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_EXT, data, bundleInfo); +} + bool BundleMgrProxy::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); diff --git a/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h b/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h index 39a981b21169fde69bd6e67b4bf95d32e99b8e9c..4a586eeb43f8a7f689518ae58c162e3e7a828c46 100644 --- a/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h +++ b/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h @@ -76,6 +76,7 @@ public: bool DetermineCloneNum(const std::string &bundleName, const std::string &appIdentifier, int32_t &cloneNum); std::string GetCompatibleDeviceType(const std::string &bundleName); bool IsNeedToSkipPreBundleInstall(); + ErrCode GetBundleArchiveInfoExt(const std::string &hapFilePath, int32_t fd, BundleInfo &bundleInfo); private: bool OpenHandler(); static BmsExtension bmsExtension_; diff --git a/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h b/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h index d6e1557bc6a0d4e723328dfd6da82dca8856a5de..2c0a4bb69da6e4d76432d93d031ae88cf4f9ca6a 100644 --- a/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h +++ b/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h @@ -160,6 +160,11 @@ public: { return false; } + virtual ErrCode GetBundleArchiveInfoExt(const std::string &hapFilePath, int32_t fd, + BundleInfo &bundleInfo) + { + return ERR_BUNDLE_MANAGER_EXTENSION_DEFAULT_ERR; + } }; } // AppExecFwk diff --git a/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp b/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp index a94d83fe9555115d60d8e394eaa11d95fce495ac..23cf93f6c221f0c2563c2e746bccff241c150142 100644 --- a/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp +++ b/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp @@ -578,5 +578,21 @@ bool BmsExtensionDataMgr::IsNeedToSkipPreBundleInstall() } return bundleMgrExtPtr->IsNeedToSkipPreBundleInstall(); } + +ErrCode BmsExtensionDataMgr::GetBundleArchiveInfoExt( + const std::string &hapFilePath, int32_t fd, BundleInfo &bundleInfo) +{ + if ((Init() != ERR_OK) || handler_ == nullptr) { + APP_LOGW("link failed"); + return ERR_BUNDLE_MANAGER_EXTENSION_INTERNAL_ERR; + } + auto bundleMgrExtPtr = + BundleMgrExtRegister::GetInstance().GetBundleMgrExt(bmsExtension_.bmsExtensionBundleMgr.extensionName); + if (bundleMgrExtPtr == nullptr) { + APP_LOGW("GetBundleMgrExt failed"); + return ERR_BUNDLE_MANAGER_EXTENSION_INTERNAL_ERR; + } + return bundleMgrExtPtr->GetBundleArchiveInfoExt(hapFilePath, fd, bundleInfo); +} } // AppExecFwk } // OHOS diff --git a/interfaces/kits/js/bundle_manager/bundle_manager.cpp b/interfaces/kits/js/bundle_manager/bundle_manager.cpp index abd7bb1aeb7cec6ff9bf2ab532aaa23b68b545de..b72ed984f61dc7418ac8c4cecb094afb1a32642e 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager.cpp +++ b/interfaces/kits/js/bundle_manager/bundle_manager.cpp @@ -181,6 +181,17 @@ static ErrCode InnerGetBundleArchiveInfo(std::string &hapFilePath, int32_t flags return ERROR_BUNDLE_SERVICE_EXCEPTION; } ErrCode ret = iBundleMgr->GetBundleArchiveInfoV9(hapFilePath, flags, bundleInfo); + if (!(ret == SUCCESS || ret == ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED || + ret == ERR_BUNDLE_MANAGER_PERMISSION_DENIED)) { + int32_t fd = open(hapFilePath.c_str(), O_RDONLY); + if (fd >= 0) { + ErrCode retExt = iBundleMgr->GetBundleArchiveInfoExt(hapFilePath, fd, flags, bundleInfo); + close(fd); + if (retExt == SUCCESS) { + ret = retExt; + } + } + } APP_LOGD("GetBundleArchiveInfoV9 ErrCode : %{public}d", ret); return CommonFunc::ConvertErrCode(ret); } diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index d9a3ef6f0bc2825b8578985a4027e12b6a8dd23e..fe25070520a81bdf8d7bc3a4bd2dfa621ae1e112 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1051,6 +1051,8 @@ public: virtual ErrCode GetDirByBundleNameAndAppIndex(const std::string &bundleName, const int32_t appIndex, std::string &dataDir) override; virtual ErrCode GetAllBundleDirs(int32_t userId, std::vector &bundleDirs) override; + virtual ErrCode GetBundleArchiveInfoExt(const std::string &hapFilePath, int32_t fd, + int32_t flags, BundleInfo &bundleInfo) override; private: const std::shared_ptr GetDataMgrFromService(); diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 471483904548670b204c078435d3689530a1a04d..17b8b28451c1b437abc3c2be18c06fbe7d72a53d 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -1207,6 +1207,23 @@ ErrCode BundleMgrHostImpl::GetBundleArchiveInfoV9( return ERR_OK; } +ErrCode BundleMgrHostImpl::GetBundleArchiveInfoExt( + const std::string &hapFilePath, int32_t fd, int32_t flags, BundleInfo &bundleInfo) +{ + APP_LOGD("start GetBundleArchiveInfoV9, hapFilePath : %{private}s, flags : %{public}d", + hapFilePath.c_str(), flags); + if (!BundlePermissionMgr::IsSystemApp()) { + APP_LOGE("non-system app calling system api"); + return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; + } + if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)) { + APP_LOGE("verify permission failed"); + return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; + } + BmsExtensionDataMgr bmsExtensionDataMgr; + return bmsExtensionDataMgr.GetBundleArchiveInfoExt(hapFilePath, fd, bundleInfo); +} + ErrCode BundleMgrHostImpl::GetBundleArchiveInfoBySandBoxPath(const std::string &hapFilePath, int32_t flags, BundleInfo &bundleInfo, bool fromV9) {