From 74dae8963372a37343a99bd6d4812a74dabdbcdd Mon Sep 17 00:00:00 2001 From: wangdengjia Date: Tue, 19 Oct 2021 10:28:17 +0800 Subject: [PATCH] IssueNo:#I4ECO2 Description:add GetBundleInfosNoReplication interface Sig:appexecfwk Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangdengjia Change-Id: I67dce53c28887cd12e59ba4a21baefb1c47670fc --- .../bundle_lite/include/bundle_info_utils.h | 1 + .../include/bundlems_slite_client.h | 2 + .../bundle_lite/src/bundle_info_utils.cpp | 44 +++++++++++++++++++ .../src/slite/bundle_manager_inner.cpp | 5 +++ .../src/slite/bundlems_slite_client.cpp | 8 ++++ .../bundlemgr_lite/bundle_service_interface.h | 1 + .../bundlemgr_lite/slite/bundle_install_msg.h | 14 ++++++ services/bundlemgr_lite/include/bundle_map.h | 1 + .../include/bundle_mgr_slite_feature.h | 1 + .../include/gt_bundle_manager_service.h | 1 + services/bundlemgr_lite/src/bundle_map.cpp | 33 ++++++++++++++ .../src/bundle_mgr_slite_feature.cpp | 6 +++ .../src/gt_bundle_manager_service.cpp | 8 ++++ 13 files changed, 125 insertions(+) diff --git a/frameworks/bundle_lite/include/bundle_info_utils.h b/frameworks/bundle_lite/include/bundle_info_utils.h index 6043c2a..92af185 100755 --- a/frameworks/bundle_lite/include/bundle_info_utils.h +++ b/frameworks/bundle_lite/include/bundle_info_utils.h @@ -21,6 +21,7 @@ namespace OHOS { struct BundleInfoUtils { static void CopyBundleInfo(int32_t flags, BundleInfo *des, BundleInfo src); + static void CopyBundleInfoNoReplication(int32_t flags, BundleInfo *des, BundleInfo src); static bool SetBundleInfoBundleName(BundleInfo *bundleInfo, const char *bundleName); static bool SetBundleInfoVendor(BundleInfo *bundleInfo, const char *vendor); static bool SetBundleInfoLabel(BundleInfo *bundleInfo, const char *label); diff --git a/frameworks/bundle_lite/include/bundlems_slite_client.h b/frameworks/bundle_lite/include/bundlems_slite_client.h index 5df0768..c0c0eb8 100755 --- a/frameworks/bundle_lite/include/bundlems_slite_client.h +++ b/frameworks/bundle_lite/include/bundlems_slite_client.h @@ -53,6 +53,8 @@ public: void UpdateBundleInfoList() const; + uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) const; + private: BundleMsClient() = default; diff --git a/frameworks/bundle_lite/src/bundle_info_utils.cpp b/frameworks/bundle_lite/src/bundle_info_utils.cpp index b166e94..0f891ea 100755 --- a/frameworks/bundle_lite/src/bundle_info_utils.cpp +++ b/frameworks/bundle_lite/src/bundle_info_utils.cpp @@ -84,6 +84,50 @@ void BundleInfoUtils::CopyBundleInfo(int32_t flags, BundleInfo *des, BundleInfo #endif } +void BundleInfoUtils::CopyBundleInfoNoReplication(int32_t flags, BundleInfo *des, BundleInfo src) +{ + if (des == nullptr) { + return; + } + des->bundleName = src.bundleName; + des->label = src.label; + des->versionName = src.versionName; + des->bigIconPath = src.bigIconPath; + des->codePath = src.codePath; + des->dataPath = src.dataPath; + des->vendor = src.vendor; + if (src.numOfModule != 0) { + des->numOfModule = src.numOfModule; + des->moduleInfos = src.moduleInfos; + } + des->isSystemApp = src.isSystemApp; + des->versionCode = src.versionCode; + des->compatibleApi = src.compatibleApi; + des->targetApi = src.targetApi; + des->appId = src.appId; +#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER + des->isKeepAlive = src.isKeepAlive; + des->isNativeApp = src.isNativeApp; + des->uid = src.uid; + des->gid = src.gid; + if (flags == GET_BUNDLE_WITH_ABILITIES) { + SetBundleInfoAbilityInfos(des, src.abilityInfos, src.numOfAbility); + } else { + des->abilityInfos = nullptr; + des->numOfAbility = 0; + } +#else + des->smallIconPath = src.smallIconPath; + if (flags == GET_BUNDLE_WITH_ABILITIES) { + if (src.abilityInfo != nullptr) { + des->abilityInfo = src.abilityInfo; + } + } else { + des->abilityInfo = nullptr; + } +#endif +} + bool BundleInfoUtils::SetBundleInfoBundleName(BundleInfo *bundleInfo, const char *bundleName) { if (bundleInfo == nullptr || bundleName == nullptr) { diff --git a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp index f1d2ea4..a2fd4c2 100755 --- a/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp +++ b/frameworks/bundle_lite/src/slite/bundle_manager_inner.cpp @@ -38,4 +38,9 @@ void UpdateBundleInfoList(void) { OHOS::BundleMsClient::GetInstance().UpdateBundleInfoList(); } + +uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) +{ + return OHOS::BundleMsClient::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); +} } diff --git a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp index c6abb20..667af82 100755 --- a/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp +++ b/frameworks/bundle_lite/src/slite/bundlems_slite_client.cpp @@ -196,4 +196,12 @@ void BundleMsClient::UpdateBundleInfoList () const } bmsProxy_->UpdateBundleInfoList(); } + +uint8_t BundleMsClient::GetBundleInfosNoReplication (const int flags, BundleInfo **bundleInfos, int32_t *len) const +{ + if (!Initialize()) { + return -1; + } + return bmsProxy_->GetBundleInfosNoReplication(flags, bundleInfos, len); +} } // namespace OHOS diff --git a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h index bde7a0c..f385265 100755 --- a/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h +++ b/interfaces/innerkits/bundlemgr_lite/bundle_service_interface.h @@ -53,6 +53,7 @@ struct BmsSliteInterface { uint32_t (*GetBundleSize)(const char *bundleName); bool (*RegisterInstallerCallback)(InstallerCallback installerCallback); void (*UpdateBundleInfoList)(); + uint8_t (*GetBundleInfosNoReplication)(const int flags, BundleInfo **bundleInfos, int32_t *len); }; #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h index 5d59a31..6fca894 100644 --- a/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h +++ b/interfaces/innerkits/bundlemgr_lite/slite/bundle_install_msg.h @@ -81,6 +81,20 @@ bool RegisterInstallerCallback(InstallerCallback installerCallback); */ void UpdateBundleInfoList(void); + /** + * @brief Obtains the {@link BundleInfo} of all bundles with no replication in the system. + * + * @param flags Specifies whether each of the obtained {@link BundleInfo} objects can contain {@link AbilityInfo}. + * The value 1 indicates that it can contain {@link AbilityInfo}, and 0 indicates that + * it cannot. + * @param bundleInfos Indicates the double pointer to the obtained {@link BundleInfo} objects. + * @param len Indicates the pointer to the number of {@link BundleInfo} objects obtained. + * @return Returns {@link ERR_OK} if this function is successfully called; returns another error code defined in + * {@link AppexecfwkErrors} otherwise. + * + */ +uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); + #ifdef __cplusplus #if __cplusplus } diff --git a/services/bundlemgr_lite/include/bundle_map.h b/services/bundlemgr_lite/include/bundle_map.h index c68b4c0..7a72cc1 100644 --- a/services/bundlemgr_lite/include/bundle_map.h +++ b/services/bundlemgr_lite/include/bundle_map.h @@ -35,6 +35,7 @@ public: bool Update(BundleInfo *bundleInfo); BundleInfo *Get(const char *bundleName) const; uint8_t GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const; + uint8_t GetBundleInfosNoReplication(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const; uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo) const; void Erase(const char *bundleName); void EraseAll(); diff --git a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h index e8aa04a..d9ff3bc 100755 --- a/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h +++ b/services/bundlemgr_lite/include/bundle_mgr_slite_feature.h @@ -39,6 +39,7 @@ public: static uint32_t GetBundleSize (const char *bundleName); static bool RegisterInstallerCallback(InstallerCallback installerCallback); static void UpdateBundleInfoList(); + static uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); static BundleMgrSliteFeature *GetInstance() { diff --git a/services/bundlemgr_lite/include/gt_bundle_manager_service.h b/services/bundlemgr_lite/include/gt_bundle_manager_service.h index bb4779a..68f9de3 100755 --- a/services/bundlemgr_lite/include/gt_bundle_manager_service.h +++ b/services/bundlemgr_lite/include/gt_bundle_manager_service.h @@ -61,6 +61,7 @@ public: uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo); uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len); + uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); void ScanPackages(); BundleInfo *QueryBundleInfo(const char *bundleName); void RemoveBundleInfo(const char *bundleName); diff --git a/services/bundlemgr_lite/src/bundle_map.cpp b/services/bundlemgr_lite/src/bundle_map.cpp index 628ef71..767ae11 100755 --- a/services/bundlemgr_lite/src/bundle_map.cpp +++ b/services/bundlemgr_lite/src/bundle_map.cpp @@ -204,6 +204,39 @@ uint8_t BundleMap::GetBundleInfos(int32_t flags, BundleInfo **bundleInfos, int32 return ERR_OK; } +uint8_t BundleMap::GetBundleInfosNoReplication(int32_t flags, BundleInfo **bundleInfos, int32_t *len) const +{ + if (bundleInfos == nullptr) { + return ERR_APPEXECFWK_QUERY_PARAMETER_ERROR; + } +#ifdef OHOS_APPEXECFWK_BMS_BUNDLEMANAGER + MutexAcquire(&g_bundleListMutex, 0); +#else + MutexAcquire(&g_bundleListMutex, BUNDLELIST_MUTEX_TIMEOUT); +#endif + if (bundleInfos_->IsEmpty()) { + MutexRelease(&g_bundleListMutex); + return ERR_APPEXECFWK_QUERY_NO_INFOS; + } + + BundleInfo *infos = reinterpret_cast(AdapterMalloc(sizeof(BundleInfo) * bundleInfos_->Size())); + if (infos == nullptr || memset_s(infos, sizeof(BundleInfo) * bundleInfos_->Size(), 0, + sizeof(BundleInfo) * bundleInfos_->Size()) != EOK) { + AdapterFree(infos); + MutexRelease(&g_bundleListMutex); + return ERR_APPEXECFWK_QUERY_INFOS_INIT_ERROR; + } + *bundleInfos = infos; + + for (auto node = bundleInfos_->Begin(); node != bundleInfos_->End(); node = node->next_) { + BundleInfoUtils::CopyBundleInfoNoReplication(flags, infos++, *(node->value_)); + } + + *len = bundleInfos_->Size(); + MutexRelease(&g_bundleListMutex); + return ERR_OK; +} + uint8_t BundleMap::GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo) const { if (bundleName == nullptr) { diff --git a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp index cb2bb5c..5772f79 100755 --- a/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_mgr_slite_feature.cpp @@ -36,6 +36,7 @@ BundleMgrSliteFeatureImpl g_bmsSliteImpl = { .GetBundleSize = BundleMgrSliteFeature::GetBundleSize, .RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback, .UpdateBundleInfoList = BundleMgrSliteFeature::UpdateBundleInfoList, + .GetBundleInfosNoReplication = BundleMgrSliteFeature::GetBundleInfosNoReplication, DEFAULT_IUNKNOWN_ENTRY_END }; @@ -144,4 +145,9 @@ void BundleMgrSliteFeature::UpdateBundleInfoList() { OHOS::GtManagerService::GetInstance().UpdateBundleInfoList(); } + +uint8_t BundleMgrSliteFeature::GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) +{ + return OHOS::GtManagerService::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len); +} } // namespace OHOS diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index c0c0166..a62f305 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -245,6 +245,14 @@ uint8_t GtManagerService::GetBundleInfos(const int flags, BundleInfo **bundleInf return bundleMap_->GetBundleInfos(flags, bundleInfos, len); } +uint8_t GtManagerService::GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len) +{ + if (bundleMap_ == nullptr) { + return ERR_APPEXECFWK_OBJECT_NULL; + } + return bundleMap_->GetBundleInfosNoReplication(flags, bundleInfos, len); +} + bool GtManagerService::RegisterInstallerCallback(InstallerCallback installerCallback) { if (installerCallback == nullptr) {