From 70545bd4ae81528102a7a11aa70ffca385a824bf Mon Sep 17 00:00:00 2001 From: ImCaO Date: Wed, 20 Aug 2025 11:08:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=BD=BB=E9=87=8F=E7=BA=A7=E6=8E=A5=E5=8F=A3=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib67bb390662e22183ccb1f2006b13a932ea19651 --- ...bundle_framework_core_ipc_interface_code.h | 1 + .../include/bundlemgr/bundle_mgr_host.h | 7 ++++ .../include/bundlemgr/bundle_mgr_proxy.h | 9 +++++ .../src/bundlemgr/bundle_mgr_host.cpp | 22 ++++++++++++ .../src/bundlemgr/bundle_mgr_proxy.cpp | 35 +++++++++++++++++++ services/bundlemgr/include/bundle_data_mgr.h | 8 +++++ .../bundlemgr/include/bundle_mgr_host_impl.h | 8 +++++ services/bundlemgr/src/bundle_data_mgr.cpp | 23 ++++++++++++ .../bundlemgr/src/bundle_mgr_host_impl.cpp | 16 +++++++++ 9 files changed, 129 insertions(+) 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 fa43eea1e5..1128448bb3 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 @@ -221,6 +221,7 @@ enum class BundleMgrInterfaceCode : uint32_t { BATCH_GET_ADDITIONAL_INFO = 195, BATCH_GET_BUNDLE_STATS = 196, GET_SHORTCUT_INFO_BY_APPINDEX = 197, + GET_ALL_BUNDLE_NAMES = 198, }; /* 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 1d940bb76e..aad1fd00a0 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 @@ -915,6 +915,13 @@ private: ErrCode HandleGreatOrEqualTargetAPIVersion(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetShortcutVisibleForSelf(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetAllShortcutInfoForSelf(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handles the GetAllBundleNames 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 HandleGetAllBundleNames(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_proxy.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h index ece541e8d2..36620e63fd 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 @@ -1245,6 +1245,15 @@ public: virtual bool GreatOrEqualTargetAPIVersion(const int32_t platformVersion, const int32_t minorVersion, const int32_t patchVersion) override; + + /** + * @brief Obtains all bundle names of a specified user. + * @param bundleNames Indicates the vector of the bundle names. + * @param includeDisabled Indicates whether to include disabled applications. + * @param userId Indicates the user ID. + * @return Returns ERR_OK if the operation is successful; returns other error codes otherwise. + */ + virtual ErrCode GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) 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 682a25889b..12a3fe536d 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 @@ -701,6 +701,9 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa case static_cast(BundleMgrInterfaceCode::GREAT_OR_EQUAL_API_TARGET_VERSION): errCode = HandleGreatOrEqualTargetAPIVersion(data, reply); break; + case static_cast(BundleMgrInterfaceCode::GET_ALL_BUNDLE_NAMES): + errCode = HandleGetAllBundleNames(data, reply); + break; default : APP_LOGW("bundleMgr host receives unknown code %{public}u", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -4875,5 +4878,24 @@ ErrCode BundleMgrHost::HandleGreatOrEqualTargetAPIVersion(MessageParcel &data, M } return ERR_OK; } + +ErrCode BundleMgrHost::HandleGetAllBundleNames(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + int32_t userId = data.ReadInt32(); + bool includeDisabled = data.ReadBool(); + std::vector bundleNames; + ErrCode ret = GetAllBundleNames(bundleNames, includeDisabled, userId); + if (!reply.WriteInt32(ret)) { + APP_LOGE("GetAllBundleNames write failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + reply.SetDataCapacity(MAX_CAPACITY_BUNDLES); + if (ret == ERR_OK && !reply.WriteStringVector(bundleNames)) { + APP_LOGE("Write all bundleNames results failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + 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 5f4937e3eb..1a46781cab 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 @@ -6374,5 +6374,40 @@ bool BundleMgrProxy::GreatOrEqualTargetAPIVersion(const int32_t platformVersion, } return reply.ReadBool(); } + +ErrCode BundleMgrProxy::GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + APP_LOGD("start to get all bundle names for user %{public}d", userId); + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + APP_LOGE("fail to GetAllBundleNames due to write InterfaceToken fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteBool(includeDisabled)) { + APP_LOGE("fail to GetAllBundleNames due to write userId fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt32(userId)) { + APP_LOGE("fail to GetAllBundleNames due to write userId fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + MessageParcel reply; + if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ALL_BUNDLE_NAMES, data, reply)) { + APP_LOGE("fail to send transact command"); + return ERR_APPEXECFWK_IPC_ERROR; + } + ErrCode ret = reply.ReadInt32(); + if (ret != ERR_OK) { + APP_LOGE("get all bundle names failed with error code %{public}d", ret); + return ret; + } + if (!reply.ReadStringVector(&bundleNames)) { + APP_LOGE("fail to read GetAllBundleNames from reply"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + APP_LOGD("get all bundle names successfully, count: %{public}zu", bundleNames.size()); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index f06c2d5c74..44b06d5dff 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1167,6 +1167,14 @@ public: void FilterShortcutJson(nlohmann::json &jsonResult); ErrCode IsSystemApp(const std::string &bundleName, bool &isSystemApp); void UpdateDesktopShortcutInfo(const std::string &bundleName); + /** + * @brief Obtains all bundle names of a specified user. + * @param bundleNames Indicates the vector of the bundle names. + * @param includeDisabled Indicates whether to include disabled applications. + * @param userId Indicates the user ID. + * @return Returns ERR_OK if successfully obtained; returns error code otherwise. + */ + ErrCode GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId); private: /** diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index 8e98379d06..cc89fae944 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1136,6 +1136,14 @@ public: virtual ErrCode RegisterPluginEventCallback(const sptr &pluginEventCallback) override; virtual ErrCode UnregisterPluginEventCallback(const sptr &pluginEventCallback) override; virtual ErrCode GetAllShortcutInfoForSelf(std::vector &shortcutInfos) override; + /** + * @brief Obtains all bundle names of a specified user. + * @param Indicates the vector of the bundle names. + * @param includeDisabled Indicates whether to include disabled applications. + * @param userId Indicates the user ID. + * @return Returns ERR_OK if successfully obtained; returns error code otherwise. + */ + virtual ErrCode GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) override; private: bool GetLabelByBundleName(const std::string &bundleName, int32_t userId, std::string &label); diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index aa973b472e..8edcc2ec66 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -11184,5 +11184,28 @@ void BundleDataMgr::UpdateDesktopShortcutInfo(const std::string &bundleName) } shortcutStorage_->UpdateDesktopShortcutInfo(bundleName, shortcutInfos); } + +ErrCode BundleDataMgr::GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) +{ + int32_t requestUserId = GetUserId(userId); + if (requestUserId == Constants::INVALID_USERID) { + APP_LOGE("Input invalid userid, userId:%{public}d", userId); + return ERR_BUNDLE_MANAGER_INVALID_USER_ID; + } + + std::shared_lock lock(bundleInfoMutex_); + for (const auto &[bundleName, innerInfo] : bundleInfos_) { + if (innerInfo.GetResponseUserId(requestUserId) == Constants::INVALID_USERID) { + continue; + } + if (includeDisabled || (!innerInfo.IsDisabled() && innerInfo.GetApplicationEnabled(requestUserId))) { + bundleNames.emplace_back(bundleName); + } + } + + APP_LOGD("Found %{public}zu bundle(s) for user %{public}d with includeDisabled=%{public}d", + bundleNames.size(), userId, includeDisabled); + return ERR_OK; +} } // 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 b97019e379..1f272cc12c 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -5779,5 +5779,21 @@ bool BundleMgrHostImpl::GreatOrEqualTargetAPIVersion(const int32_t platformVersi } return dataMgr->GreatOrEqualTargetAPIVersion(platformVersion, minorVersion, patchVersion); } + +ErrCode BundleMgrHostImpl::GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) +{ + APP_LOGD("start to get all bundle names for user %{public}d", userId); + if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)) { + APP_LOGE("verify calling permission failed"); + return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; + } + + auto dataMgr = GetDataMgrFromService(); + if (dataMgr == nullptr) { + APP_LOGE("DataMgr is nullptr"); + return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + } + return dataMgr->GetAllBundleNames(bundleNames, includeDisabled, userId); +} } // namespace AppExecFwk } // namespace OHOS -- Gitee From cdb54664f9a76e2b0ce1725afe4e12aa608d1330 Mon Sep 17 00:00:00 2001 From: ImCaO Date: Thu, 21 Aug 2025 15:31:40 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=BD=BB=E9=87=8F=E7=BA=A7=E6=8E=A5=E5=8F=A3=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=8C=85=E5=90=8D2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8ca74387faa1f9daef7b294c78a78f3716e886cb --- .../appexecfwk_base/include/bundle_info.h | 1 + .../include/bundlemgr/bundle_mgr_proxy.h | 4 +-- .../src/bundlemgr/bundle_mgr_host.cpp | 4 +-- .../src/bundlemgr/bundle_mgr_proxy.cpp | 22 +++++++------- .../include/bms_extension_data_mgr.h | 1 + .../include/bundle_mgr_ext.h | 4 +++ .../src/bms_extension_data_mgr.cpp | 15 ++++++++++ .../bms_extension/bms_extension_client.h | 6 ++++ services/bundlemgr/include/bundle_data_mgr.h | 4 +-- .../bundlemgr/include/bundle_mgr_host_impl.h | 4 +-- .../bms_extension/bms_extension_client.cpp | 11 +++++++ services/bundlemgr/src/bundle_data_mgr.cpp | 30 +++++++++++++++---- .../bundlemgr/src/bundle_mgr_host_impl.cpp | 6 ++-- 13 files changed, 85 insertions(+), 27 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_info.h b/interfaces/inner_api/appexecfwk_base/include/bundle_info.h index c7a5d1e16c..ab3bdd0582 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_info.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_info.h @@ -66,6 +66,7 @@ enum class GetBundleInfoFlag { GET_BUNDLE_INFO_OF_ANY_USER = 0x00002000, GET_BUNDLE_INFO_EXCLUDE_CLONE = 0x00004000, GET_BUNDLE_INFO_WITH_CLOUD_KIT = 0x00008000, + GET_BUNDLE_INFO_WITH_BROKER = 0x00010000, }; struct RequestPermissionUsedScene : public Parcelable { 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 36620e63fd..f9e142d282 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 @@ -1249,11 +1249,11 @@ public: /** * @brief Obtains all bundle names of a specified user. * @param bundleNames Indicates the vector of the bundle names. - * @param includeDisabled Indicates whether to include disabled applications. + * @param flags Indicates the flags to control the bundle list. * @param userId Indicates the user ID. * @return Returns ERR_OK if the operation is successful; returns other error codes otherwise. */ - virtual ErrCode GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) override; + virtual ErrCode GetAllBundleNames(std::vector &bundleNames, uint32_t flags, int32_t userId) 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 12a3fe536d..2473e9940a 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 @@ -4882,10 +4882,10 @@ ErrCode BundleMgrHost::HandleGreatOrEqualTargetAPIVersion(MessageParcel &data, M ErrCode BundleMgrHost::HandleGetAllBundleNames(MessageParcel &data, MessageParcel &reply) { HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + uint32_t flags = data.ReadUint32(); int32_t userId = data.ReadInt32(); - bool includeDisabled = data.ReadBool(); std::vector bundleNames; - ErrCode ret = GetAllBundleNames(bundleNames, includeDisabled, userId); + ErrCode ret = GetAllBundleNames(bundleNames, flags, userId); if (!reply.WriteInt32(ret)) { APP_LOGE("GetAllBundleNames write failed"); return ERR_APPEXECFWK_PARCEL_ERROR; 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 1a46781cab..6db5e19438 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 @@ -6375,38 +6375,38 @@ bool BundleMgrProxy::GreatOrEqualTargetAPIVersion(const int32_t platformVersion, return reply.ReadBool(); } -ErrCode BundleMgrProxy::GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) +ErrCode BundleMgrProxy::GetAllBundleNames(std::vector &bundleNames, uint32_t flags, int32_t userId) { + APP_LOGD("GetAllBundleNames: userId: %{public}d", userId); HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); - APP_LOGD("start to get all bundle names for user %{public}d", userId); MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { - APP_LOGE("fail to GetAllBundleNames due to write InterfaceToken fail"); + APP_LOGE("Fail to GetAllBundleNames due to write InterfaceToken fail"); return ERR_APPEXECFWK_PARCEL_ERROR; } - if (!data.WriteBool(includeDisabled)) { - APP_LOGE("fail to GetAllBundleNames due to write userId fail"); + if (!data.WriteUint32(flags)) { + APP_LOGE("Fail to GetAllBundleNames due to write flags fail"); return ERR_APPEXECFWK_PARCEL_ERROR; } if (!data.WriteInt32(userId)) { - APP_LOGE("fail to GetAllBundleNames due to write userId fail"); + APP_LOGE("Fail to GetAllBundleNames due to write userId fail"); return ERR_APPEXECFWK_PARCEL_ERROR; } MessageParcel reply; if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ALL_BUNDLE_NAMES, data, reply)) { - APP_LOGE("fail to send transact command"); - return ERR_APPEXECFWK_IPC_ERROR; + APP_LOGE("Fail to GetAllBundleNames from server"); + return ERR_BUNDLE_MANAGER_IPC_TRANSACTION; } ErrCode ret = reply.ReadInt32(); if (ret != ERR_OK) { - APP_LOGE("get all bundle names failed with error code %{public}d", ret); + APP_LOGE("Reply err : %{public}d", ret); return ret; } if (!reply.ReadStringVector(&bundleNames)) { - APP_LOGE("fail to read GetAllBundleNames from reply"); + APP_LOGE("Fail to GetAllBundleNames from reply"); return ERR_APPEXECFWK_PARCEL_ERROR; } - APP_LOGD("get all bundle names successfully, count: %{public}zu", bundleNames.size()); + APP_LOGD("GetAllBundleNames: ret: %{public}d, count: %{public}zu", ret, bundleNames.size()); return ERR_OK; } } // namespace AppExecFwk 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 1217e3fb5c..6206eccd83 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 @@ -82,6 +82,7 @@ public: ErrCode GetBundleNamesForUidExt(const int32_t uid, std::vector &bundleNames); ErrCode RegisterPreInstallWithCard(); bool IsMCFlagSet(); + ErrCode GetAllBundleNames(std::vector &bundleNames); private: bool OpenHandler(); static void *handler_; 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 b7cc3a9a6e..77bc9a8c00 100644 --- a/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h +++ b/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h @@ -182,6 +182,10 @@ public: { return false; } + virtual ErrCode GetAllBundleNames(std::vector &bundleNames) + { + 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 6915d62e2b..dda6052f84 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 @@ -670,5 +670,20 @@ bool BmsExtensionDataMgr::IsMCFlagSet() } return bundleMgrExtPtr->IsMCFlagSet(); } + +ErrCode BmsExtensionDataMgr::GetAllBundleNames(std::vector &bundleNames) +{ + if ((Init() != ERR_OK) || handler_ == nullptr) { + APP_LOGW("init 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->GetAllBundleNames(bundleNames); +} } // AppExecFwk } // OHOS diff --git a/services/bundlemgr/include/bms_extension/bms_extension_client.h b/services/bundlemgr/include/bms_extension/bms_extension_client.h index f78b839d3e..09f149ac1b 100644 --- a/services/bundlemgr/include/bms_extension/bms_extension_client.h +++ b/services/bundlemgr/include/bms_extension/bms_extension_client.h @@ -72,6 +72,12 @@ public: ErrCode GetAllBundleResourceInfo(const uint32_t flags, std::vector &bundleResourceInfos); ErrCode GetAllLauncherAbilityResourceInfo(const uint32_t flags, std::vector &launcherAbilityResourceInfos); + /** + * @brief Obtains all bundle names from broker service. + * @param bundleNames Indicates the vector of the bundle names. + * @return Returns ERR_OK if the operation is successful; returns other error codes otherwise. + */ + ErrCode GetAllBundleNames(std::vector &bundleNames) const; private: void ModifyLauncherAbilityInfo(AbilityInfo &abilityInfo) const; diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index 44b06d5dff..75324cb495 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1170,11 +1170,11 @@ public: /** * @brief Obtains all bundle names of a specified user. * @param bundleNames Indicates the vector of the bundle names. - * @param includeDisabled Indicates whether to include disabled applications. + * @param flags Indicates the flags to control the bundle list. * @param userId Indicates the user ID. * @return Returns ERR_OK if successfully obtained; returns error code otherwise. */ - ErrCode GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId); + ErrCode GetAllBundleNames(std::vector &bundleNames, uint32_t flags, int32_t userId); private: /** diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index cc89fae944..17124d975e 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1139,11 +1139,11 @@ public: /** * @brief Obtains all bundle names of a specified user. * @param Indicates the vector of the bundle names. - * @param includeDisabled Indicates whether to include disabled applications. + * @param flags Indicates the flags to control the bundle list. * @param userId Indicates the user ID. * @return Returns ERR_OK if successfully obtained; returns error code otherwise. */ - virtual ErrCode GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) override; + virtual ErrCode GetAllBundleNames(std::vector &bundleNames, uint32_t flags, int32_t userId) override; private: bool GetLabelByBundleName(const std::string &bundleName, int32_t userId, std::string &label); diff --git a/services/bundlemgr/src/bms_extension/bms_extension_client.cpp b/services/bundlemgr/src/bms_extension/bms_extension_client.cpp index 220cd6303d..0f1fb706ef 100644 --- a/services/bundlemgr/src/bms_extension/bms_extension_client.cpp +++ b/services/bundlemgr/src/bms_extension/bms_extension_client.cpp @@ -464,6 +464,17 @@ ErrCode BmsExtensionClient::GetAllLauncherAbilityResourceInfo(const uint32_t fla return bmsExtensionImpl_->GetAllLauncherAbilityResourceInfo(flags, launcherAbilityResourceInfos); } +ErrCode BmsExtensionClient::GetAllBundleNames(std::vector &bundleNames) const +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + LOG_D(BMS_TAG_QUERY, "start to query all bundle names from bms extension"); + if (bmsExtensionImpl_ == nullptr) { + APP_LOGW("bmsExtensionImpl_ is null"); + return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + } + return bmsExtensionImpl_->GetAllBundleNames(bundleNames); +} + const std::shared_ptr BmsExtensionClient::GetDataMgr() const { return DelayedSingleton::GetInstance()->GetDataMgr(); diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 8edcc2ec66..938c690660 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -11185,7 +11185,7 @@ void BundleDataMgr::UpdateDesktopShortcutInfo(const std::string &bundleName) shortcutStorage_->UpdateDesktopShortcutInfo(bundleName, shortcutInfos); } -ErrCode BundleDataMgr::GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) +ErrCode BundleDataMgr::GetAllBundleNames(std::vector &bundleNames, uint32_t flags, int32_t userId) { int32_t requestUserId = GetUserId(userId); if (requestUserId == Constants::INVALID_USERID) { @@ -11198,13 +11198,33 @@ ErrCode BundleDataMgr::GetAllBundleNames(std::vector &bundleNames, if (innerInfo.GetResponseUserId(requestUserId) == Constants::INVALID_USERID) { continue; } - if (includeDisabled || (!innerInfo.IsDisabled() && innerInfo.GetApplicationEnabled(requestUserId))) { - bundleNames.emplace_back(bundleName); + if ((flags & + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE)) == + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE)) { + if (innerInfo.IsDisabled() || !innerInfo.GetApplicationEnabled(requestUserId)) { + continue; + } } + bundleNames.emplace_back(bundleName); } - APP_LOGD("Found %{public}zu bundle(s) for user %{public}d with includeDisabled=%{public}d", - bundleNames.size(), userId, includeDisabled); + if ((flags & + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_BROKER)) != + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_BROKER)) { + if (DelayedSingleton::GetInstance()->IsBrokerServiceStarted()) { + APP_LOGD("Querying bundle names from broker service."); + std::vector brokerBundleNames; + auto bmsExtensionClient = std::make_shared(); + ErrCode ret = bmsExtensionClient->GetAllBundleNames(brokerBundleNames); + if (ret == ERR_OK) { + bundleNames.insert(bundleNames.end(), brokerBundleNames.begin(), brokerBundleNames.end()); + } else { + APP_LOGW("Failed to get bundle names from broker, errcode: %{public}d", ret); + } + } + } + APP_LOGD("Found %{public}zu bundle(s) for user %{public}d with flags=%{public}u", + bundleNames.size(), userId, flags); return ERR_OK; } } // namespace AppExecFwk diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 1f272cc12c..41379d4269 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -5780,10 +5780,10 @@ bool BundleMgrHostImpl::GreatOrEqualTargetAPIVersion(const int32_t platformVersi return dataMgr->GreatOrEqualTargetAPIVersion(platformVersion, minorVersion, patchVersion); } -ErrCode BundleMgrHostImpl::GetAllBundleNames(std::vector &bundleNames, bool includeDisabled, int32_t userId) +ErrCode BundleMgrHostImpl::GetAllBundleNames(std::vector &bundleNames, uint32_t flags, int32_t userId) { APP_LOGD("start to get all bundle names for user %{public}d", userId); - if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)) { + if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_INSTALLED_BUNDLE_LIST)) { APP_LOGE("verify calling permission failed"); return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; } @@ -5793,7 +5793,7 @@ ErrCode BundleMgrHostImpl::GetAllBundleNames(std::vector &bundleNam APP_LOGE("DataMgr is nullptr"); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; } - return dataMgr->GetAllBundleNames(bundleNames, includeDisabled, userId); + return dataMgr->GetAllBundleNames(bundleNames, flags, userId); } } // namespace AppExecFwk } // namespace OHOS -- Gitee From 5fc37f2b0990b0ca840fedc00cf06692d357e52f Mon Sep 17 00:00:00 2001 From: ImCaO Date: Tue, 26 Aug 2025 14:56:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E8=BD=BB=E9=87=8F=E7=BA=A7=E6=8E=A5=E5=8F=A3=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=8C=85=E5=90=8D3.0=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4ext=E4=B8=AD=E6=96=B0=E5=A2=9E=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E6=94=B9=E7=94=A8=E5=8E=9F=E6=9C=89=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=8E=B7=E5=8F=96ext=E7=9A=84=E5=8C=85=E5=90=8D?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I507ecd08fc8cf2b9c0073294b2a88189ef5a4a83 --- .../include/bms_extension_data_mgr.h | 1 - .../include/bundle_mgr_ext.h | 4 --- .../src/bms_extension_data_mgr.cpp | 15 ----------- .../bms_extension/bms_extension_client.h | 6 ----- .../bms_extension/bms_extension_client.cpp | 11 -------- services/bundlemgr/src/bundle_data_mgr.cpp | 25 +++++++++++-------- 6 files changed, 15 insertions(+), 47 deletions(-) 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 6206eccd83..1217e3fb5c 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 @@ -82,7 +82,6 @@ public: ErrCode GetBundleNamesForUidExt(const int32_t uid, std::vector &bundleNames); ErrCode RegisterPreInstallWithCard(); bool IsMCFlagSet(); - ErrCode GetAllBundleNames(std::vector &bundleNames); private: bool OpenHandler(); static void *handler_; 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 77bc9a8c00..b7cc3a9a6e 100644 --- a/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h +++ b/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h @@ -182,10 +182,6 @@ public: { return false; } - virtual ErrCode GetAllBundleNames(std::vector &bundleNames) - { - 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 dda6052f84..6915d62e2b 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 @@ -670,20 +670,5 @@ bool BmsExtensionDataMgr::IsMCFlagSet() } return bundleMgrExtPtr->IsMCFlagSet(); } - -ErrCode BmsExtensionDataMgr::GetAllBundleNames(std::vector &bundleNames) -{ - if ((Init() != ERR_OK) || handler_ == nullptr) { - APP_LOGW("init 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->GetAllBundleNames(bundleNames); -} } // AppExecFwk } // OHOS diff --git a/services/bundlemgr/include/bms_extension/bms_extension_client.h b/services/bundlemgr/include/bms_extension/bms_extension_client.h index 09f149ac1b..f78b839d3e 100644 --- a/services/bundlemgr/include/bms_extension/bms_extension_client.h +++ b/services/bundlemgr/include/bms_extension/bms_extension_client.h @@ -72,12 +72,6 @@ public: ErrCode GetAllBundleResourceInfo(const uint32_t flags, std::vector &bundleResourceInfos); ErrCode GetAllLauncherAbilityResourceInfo(const uint32_t flags, std::vector &launcherAbilityResourceInfos); - /** - * @brief Obtains all bundle names from broker service. - * @param bundleNames Indicates the vector of the bundle names. - * @return Returns ERR_OK if the operation is successful; returns other error codes otherwise. - */ - ErrCode GetAllBundleNames(std::vector &bundleNames) const; private: void ModifyLauncherAbilityInfo(AbilityInfo &abilityInfo) const; diff --git a/services/bundlemgr/src/bms_extension/bms_extension_client.cpp b/services/bundlemgr/src/bms_extension/bms_extension_client.cpp index 0f1fb706ef..220cd6303d 100644 --- a/services/bundlemgr/src/bms_extension/bms_extension_client.cpp +++ b/services/bundlemgr/src/bms_extension/bms_extension_client.cpp @@ -464,17 +464,6 @@ ErrCode BmsExtensionClient::GetAllLauncherAbilityResourceInfo(const uint32_t fla return bmsExtensionImpl_->GetAllLauncherAbilityResourceInfo(flags, launcherAbilityResourceInfos); } -ErrCode BmsExtensionClient::GetAllBundleNames(std::vector &bundleNames) const -{ - HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); - LOG_D(BMS_TAG_QUERY, "start to query all bundle names from bms extension"); - if (bmsExtensionImpl_ == nullptr) { - APP_LOGW("bmsExtensionImpl_ is null"); - return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; - } - return bmsExtensionImpl_->GetAllBundleNames(bundleNames); -} - const std::shared_ptr BmsExtensionClient::GetDataMgr() const { return DelayedSingleton::GetInstance()->GetDataMgr(); diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 938c690660..1912262738 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -11198,32 +11198,37 @@ ErrCode BundleDataMgr::GetAllBundleNames(std::vector &bundleNames, if (innerInfo.GetResponseUserId(requestUserId) == Constants::INVALID_USERID) { continue; } - if ((flags & - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE)) == - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE)) { + if (!(flags & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE))) { if (innerInfo.IsDisabled() || !innerInfo.GetApplicationEnabled(requestUserId)) { continue; } } bundleNames.emplace_back(bundleName); } + lock.unlock(); if ((flags & - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_BROKER)) != + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_BROKER)) == static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_BROKER)) { if (DelayedSingleton::GetInstance()->IsBrokerServiceStarted()) { - APP_LOGD("Querying bundle names from broker service."); - std::vector brokerBundleNames; + APP_LOGD("Querying bundle infos from broker service to get bundle names."); + std::vector brokerBundleInfos; auto bmsExtensionClient = std::make_shared(); - ErrCode ret = bmsExtensionClient->GetAllBundleNames(brokerBundleNames); + ErrCode ret = bmsExtensionClient->GetBundleInfos(flags, brokerBundleInfos, userId); if (ret == ERR_OK) { - bundleNames.insert(bundleNames.end(), brokerBundleNames.begin(), brokerBundleNames.end()); + for (const auto& bundleInfo : brokerBundleInfos) { + if (!bundleInfo.name.empty()) { + bundleNames.emplace_back(bundleInfo.name); + } + } } else { - APP_LOGW("Failed to get bundle names from broker, errcode: %{public}d", ret); + APP_LOGW("Failed to get bundle infos from broker, errcode: %{public}d", ret); } } } - APP_LOGD("Found %{public}zu bundle(s) for user %{public}d with flags=%{public}u", + std::sort(bundleNames.begin(), bundleNames.end()); + bundleNames.erase(std::unique(bundleNames.begin(), bundleNames.end()), bundleNames.end()); + APP_LOGD("Found %{public}zu total unique bundle(s) for user %{public}d with flags=%{public}u", bundleNames.size(), userId, flags); return ERR_OK; } -- Gitee