From b1aa3e12f6d08b0543092b8b26bf0d8bd6ac326e Mon Sep 17 00:00:00 2001 From: weixin_45932406 Date: Sat, 30 Aug 2025 16:21:41 +0800 Subject: [PATCH] add getAllBundleNames Signed-off-by: zhaogan --- ...bundle_framework_core_ipc_interface_code.h | 1 + .../include/bundlemgr/bundle_mgr_host.h | 9 +- .../include/bundlemgr/bundle_mgr_interface.h | 17 ++- .../include/bundlemgr/bundle_mgr_proxy.h | 20 ++- .../src/bundlemgr/bundle_mgr_host.cpp | 25 +++- .../src/bundlemgr/bundle_mgr_proxy.cpp | 44 ++++++- services/bundlemgr/include/bundle_data_mgr.h | 8 ++ .../bundlemgr/include/bundle_mgr_host_impl.h | 10 ++ services/bundlemgr/src/bundle_data_mgr.cpp | 30 +++++ .../bundlemgr/src/bundle_mgr_host_impl.cpp | 57 ++++++++- .../acts_bms_kit_system_test.cpp | 116 +++++++++++++++++- 11 files changed, 316 insertions(+), 21 deletions(-) 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 2281a5bd3e..c75fc0c7ee 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 @@ -226,6 +226,7 @@ enum class BundleMgrInterfaceCode : uint32_t { GET_TEST_RUNNER = 200, CLEAN_BUNDLE_CACHE_FILES_FOR_SELF = 201, IS_DEBUGGABLE_APPLICATION = 202, + GET_ALL_BUNDLE_NAMES = 203, }; /* 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 9aa3356b36..34f2d5a3a0 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 @@ -843,6 +843,13 @@ private: ErrCode HandleCreateBundleDataDirWithEl(MessageParcel &data, MessageParcel &reply); ErrCode HandleMigrateData(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); /** * @brief Handles the GetAllPreinstalledApplicationInfos function called from a IBundleMgr proxy object. * @param data Indicates the data to be read. @@ -914,7 +921,7 @@ private: ErrCode HandleIsBundleInstalled(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetCompatibleDeviceTypeNative(MessageParcel &data, MessageParcel &reply); - + ErrCode HandleGetCompatibleDeviceType(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetBundleNameByAppId(MessageParcel &data, MessageParcel &reply); 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 25884cd7ed..fe27220db9 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 @@ -784,7 +784,7 @@ public: { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } - + /** * @brief Clears cache data of a specified size. * @param cacheSize Indicates the size of the cache data is to be cleared. @@ -1084,7 +1084,7 @@ public: { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } - + /** * @brief Obtains the CommonEventInfo objects provided by an event key on the device. * @param eventKey Indicates the event of the subscribe. @@ -1131,6 +1131,19 @@ public: { return false; } + /** + * @brief Obtains all bundle names of a specified user. + * @param flags Indicates the flags to control the bundle list. + * @param userId Indicates the user ID. + * @param bundleNames Indicates the vector of the bundle names. + * @param withExtBundle Indicates whether to include the extension bundle. + * @return Returns ERR_OK if the operation is successful; returns other error codes otherwise. + */ + virtual ErrCode GetAllBundleNames(const uint32_t flags, int32_t userId, bool withExtBundle, + std::vector &bundleNames) + { + return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + } /** * @brief Get app privilege level. * @param bundleName Indicates the bundle name of the app privilege level. 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 27a6c29eb9..06878c3b91 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 @@ -577,7 +577,7 @@ public: int32_t userId = Constants::UNSPECIFIED_USERID, int32_t appIndex = 0) override; virtual ErrCode CleanBundleCacheFilesForSelf(const sptr cleanCacheCallback) override; - + /** * @brief Clears application running data of a specified application through the proxy object. * @param bundleName Indicates the bundle name of the application whose data is to be cleared. @@ -1019,7 +1019,7 @@ public: #endif virtual sptr GetBundleMgrExtProxy() override; - + virtual ErrCode SetDebugMode(bool isDebug) override; virtual bool VerifySystemApi(int32_t beginApiVersion = Constants::INVALID_API_VERSION) override; @@ -1044,7 +1044,7 @@ public: virtual ErrCode GetSpecifiedDistributionType(const std::string &bundleName, std::string &specifiedDistributionType) override; - + virtual ErrCode BatchGetSpecifiedDistributionType(const std::vector &bundleNames, std::vector &specifiedDistributionTypes) override; @@ -1216,6 +1216,16 @@ public: */ virtual bool GetBundleInfosForContinuation(int32_t flags, std::vector &bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID) override; + /** + * @brief Obtains all bundle names of a specified user. + * @param flags Indicates the flags to control the bundle list. + * @param userId Indicates the user ID. + * @param bundleNames Indicates the vector of the bundle names. + * @param withExtBundle Indicates whether to include the extension bundle. + * @return Returns ERR_OK if the operation is successful; returns other error codes otherwise. + */ + virtual ErrCode GetAllBundleNames(const uint32_t flags, int32_t userId, bool withExtBundle, + std::vector &bundleNames) override; /** * @brief Get a list of application package names that continue the specified package name. @@ -1253,10 +1263,10 @@ public: virtual ErrCode GetPluginAbilityInfo(const std::string &hostBundleName, const std::string &pluginBundleName, const std::string &pluginModuleName, const std::string &pluginAbilityName, const int32_t userId, AbilityInfo &abilityInfo) override; - + virtual ErrCode GetPluginHapModuleInfo(const std::string &hostBundleName, const std::string &pluginBundleName, const std::string &pluginModuleName, const int32_t userId, HapModuleInfo &hapModuleInfo) override; - + virtual ErrCode SetShortcutVisibleForSelf(const std::string &shortcutId, bool visible) override; virtual ErrCode GetAllShortcutInfoForSelf(std::vector &shortcutInfos) override; 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 be3ce0d3b3..e263f4e6e0 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 @@ -716,6 +716,9 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa case static_cast(BundleMgrInterfaceCode::IS_DEBUGGABLE_APPLICATION): errCode = HandleIsDebuggableApplication(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); @@ -4913,7 +4916,7 @@ ErrCode BundleMgrHost::HandleGreatOrEqualTargetAPIVersion(MessageParcel &data, M int32_t platformVersion = data.ReadInt32(); int32_t minorVersion = data.ReadInt32(); int32_t patchVersion = data.ReadInt32(); - + bool ret = GreatOrEqualTargetAPIVersion(platformVersion, minorVersion, patchVersion); if (!reply.WriteBool(ret)) { APP_LOGE("WriteBool failed"); @@ -4986,5 +4989,25 @@ ErrCode BundleMgrHost::HandleIsDebuggableApplication(MessageParcel &data, Messag } return ERR_OK; } + +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 withExtBundle = data.ReadBool(); + std::vector bundleNames; + ErrCode ret = GetAllBundleNames(flags, userId, withExtBundle, bundleNames); + 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 305cedd7e0..f973df1569 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 @@ -6078,7 +6078,7 @@ ErrCode BundleMgrProxy::GetAllBundleCacheStat(const sptr } return ret; } - + ErrCode BundleMgrProxy::GetAllBundleCacheStatExec(const sptr processCacheCallback) { APP_LOGI("start"); @@ -6091,7 +6091,7 @@ ErrCode BundleMgrProxy::GetAllBundleCacheStatExec(const sptr &plu BundleMgrInterfaceCode::GET_PLUGIN_INFOS_FOR_SELF, data, pluginBundleInfos); } +ErrCode BundleMgrProxy::GetAllBundleNames(const uint32_t flags, int32_t userId, bool withExtBundle, + std::vector &bundleNames) +{ + APP_LOGD("GetAllBundleNames: userId: %{public}d", userId); + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + APP_LOGE("Fail to GetAllBundleNames due to write InterfaceToken fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + 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"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteBool(withExtBundle)) { + APP_LOGE("Fail to GetAllBundleNames due to write withExtBundle fail"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + MessageParcel reply; + if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ALL_BUNDLE_NAMES, data, reply)) { + APP_LOGE("Fail to GetAllBundleNames from server"); + return ERR_BUNDLE_MANAGER_IPC_TRANSACTION; + } + ErrCode ret = reply.ReadInt32(); + if (ret != ERR_OK) { + APP_LOGE("Reply err : %{public}d", ret); + return ret; + } + if (!reply.ReadStringVector(&bundleNames)) { + APP_LOGE("Fail to GetAllBundleNames from reply"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + APP_LOGD("GetAllBundleNames size: %{public}zu", bundleNames.size()); + return ERR_OK; +} + ErrCode BundleMgrProxy::GetAllBundleDirs(int32_t userId, std::vector &bundleDirs) { HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index 5f6da2dd34..d776350750 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1055,6 +1055,14 @@ public: */ ErrCode CanOpenLink( const std::string &link, bool &canOpen) const; + /** + * @brief Obtains all bundle names of a specified user. + * @param flags Indicates the flags to control the bundle list. + * @param userId Indicates the user ID. + * @param bundleNames Indicates the vector of the bundle names. + * @return Returns ERR_OK if successfully obtained; returns error code otherwise. + */ + ErrCode GetAllBundleNames(uint32_t flags, int32_t userId, std::vector &bundleNames); ErrCode GetAllBundleInfoByDeveloperId(const std::string &developerId, std::vector &bundleInfos, int32_t userId); ErrCode GetDeveloperIds(const std::string &appDistributionType, diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index 10a4c0aecb..f3ad23960e 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1139,6 +1139,16 @@ public: bool isExisted, int32_t appIndex = 0) override; virtual bool GreatOrEqualTargetAPIVersion(int32_t platformVersion, int32_t minorVersion, int32_t patchVersion) override; + /** + * @brief Obtains all bundle names of a specified user. + * @param flags Indicates the flags to control the bundle list. + * @param userId Indicates the user ID. + * @param bundleNames Indicates the vector of the bundle names. + * @param withExtBundle Indicates whether to include extension bundles. + * @return Returns ERR_OK if successfully obtained; returns error code otherwise. + */ + virtual ErrCode GetAllBundleNames(const uint32_t flags, int32_t userId, bool withExtBundle, + std::vector &bundleNames) override; /** * @brief Obtains continuable BundleInfo of all bundles available in the system. diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 201091a905..81ac2b276c 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -10139,6 +10139,36 @@ std::string BundleDataMgr::AppIdAndAppIdentifierTransform(const std::string appI return it->second.GetAppId(); } +ErrCode BundleDataMgr::GetAllBundleNames(uint32_t flags, int32_t userId, std::vector &bundleNames) +{ + 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; + } + + bool ofAnyUserFlag = (flags & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_OF_ANY_USER)) != 0; + std::shared_lock lock(bundleInfoMutex_); + for (const auto &[bundleName, innerInfo] : bundleInfos_) { + if (innerInfo.GetApplicationBundleType() == BundleType::SHARED) { + LOG_D(BMS_TAG_QUERY, "%{public}s is not app or atomic, ignore", bundleName.c_str()); + continue; + } + int32_t responseUserId = innerInfo.GetResponseUserId(requestUserId); + auto flag = GET_BASIC_APPLICATION_INFO; + if ((flags & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE)) + == static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE)) { + flag = GET_APPLICATION_INFO_WITH_DISABLE; + } + if ((CheckInnerBundleInfoWithFlags(innerInfo, flag, responseUserId) != ERR_OK) && + (!ofAnyUserFlag || innerInfo.GetInnerBundleUserInfos().empty())) { + continue; + } + bundleNames.emplace_back(bundleName); + } + return ERR_OK; +} + ErrCode BundleDataMgr::GetSignatureInfoByBundleName(const std::string &bundleName, SignatureInfo &signatureInfo) const { std::shared_lock lock(bundleInfoMutex_); diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 550c9eda3d..5b22326103 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -2013,7 +2013,7 @@ bool BundleMgrHostImpl::CleanBundleDataFiles(const std::string &bundleName, cons callingUid, callingBundleName); return false; } - + (void)dataMgr->GetBundleNameForUid(callingUid, callingBundleName); if (!BundlePermissionMgr::IsSystemApp()) { APP_LOGE("ohos.permission.REMOVE_CACHE_FILES system api denied"); @@ -4241,7 +4241,7 @@ ErrCode BundleMgrHostImpl::BatchGetAdditionalInfo(const std::vector APP_LOGE("dataMgr is nullptr"); return ERR_APPEXECFWK_NULL_PTR; } - + for (const std::string &bundleName : bundleNames) { AppExecFwk::BundleAdditionalInfo additionalInfo; if (bundleName.empty()) { @@ -4377,7 +4377,7 @@ bool BundleMgrHostImpl::GetLabelByBundleName(const std::string &bundleName, int3 APP_LOGE("dataMgr is nullptr"); return false; } - + if (!dataMgr->HasAppOrAtomicServiceInUser(bundleName, userId)) { APP_LOGE("find fail"); return false; @@ -5317,6 +5317,53 @@ ErrCode BundleMgrHostImpl::GetLaunchWant(Want &want) return dataMgr->GetLaunchWantForBundle(bundleName, want, userId); } +ErrCode BundleMgrHostImpl::GetAllBundleNames(const uint32_t flags, int32_t userId, bool withExtBundle, + std::vector &bundleNames) +{ + APP_LOGD("start to get all bundle names for user %{public}d", userId); + if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_INSTALLED_BUNDLE_LIST)) { + APP_LOGE("verify calling permission failed"); + return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; + } + if (!BundlePermissionMgr::IsSystemApp()) { + APP_LOGE("non-system app calling system api"); + return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; + } + + if (withExtBundle && isBrokerServiceExisted_) { + auto bmsExtensionClient = std::make_shared(); + std::vector bundleInfos; + auto simpleFlag = [](uint32_t flags) { + // Define a mask that includes all the bits to be cleared + auto mask = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_MENU) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ROUTER_MAP) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SKILL); + // Clear the bits corresponding to the mask + return static_cast(flags) & (~mask); + }; + ErrCode ret = bmsExtensionClient->GetBundleInfos(simpleFlag(flags), bundleInfos, userId); + if (ret == ERR_OK) { + std::for_each(bundleInfos.begin(), bundleInfos.end(), [&bundleNames](const auto& bundleInfo) { + bundleNames.push_back(bundleInfo.name); + }); + } + } + + auto dataMgr = GetDataMgrFromService(); + if (dataMgr == nullptr) { + APP_LOGE("DataMgr is nullptr"); + return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; + } + return dataMgr->GetAllBundleNames(flags, userId, bundleNames); +} + ErrCode BundleMgrHostImpl::QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName &element, int32_t flags, int32_t appIndex, ExtensionAbilityInfo &extensionAbilityInfo, int32_t userId) { @@ -6051,7 +6098,7 @@ bool BundleMgrHostImpl::SendQueryBundleInfoEvent( query.callingUid = callingUid; query.callingBundleName = callingBundleName; query.callingAppId = callingAppId; - + InsertQueryEventInfo(errCode, query); auto infos = GetQueryEventInfo(errCode); // check report now @@ -6063,7 +6110,7 @@ bool BundleMgrHostImpl::SendQueryBundleInfoEvent( EraseQueryEventInfo(errCode); return true; } - + size_t infoSize = infos.size(); if (infoSize <= 0) { return false; diff --git a/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp b/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp index d33ef69cf9..db35cfd67e 100644 --- a/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp +++ b/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp @@ -235,7 +235,7 @@ class TestGetAllBundleCacheCallBack : public ProcessCacheCallbackHost { public: uint64_t GetCacheStat() override; }; - + uint64_t TestGetAllBundleCacheCallBack::GetCacheStat() { sleep(3); @@ -8544,6 +8544,112 @@ HWTEST_F(ActsBmsKitSystemTest, GetAppProvisionInfo_0002, Function | SmallTest | EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; } +/** + * @tc.number: GetAllBundleNames_0001 + * @tc.name: test GetAllBundleNames interface for userId 0 + * @tc.desc: 1. call GetAllBundleNames + */ +HWTEST_F(ActsBmsKitSystemTest, GetAllBundleNames_0001, Function | MediumTest | Level1) +{ + sptr bundleMgrProxy = GetBundleMgrProxy(); + ASSERT_NE(bundleMgrProxy, nullptr); + std::vector bundleNames; + uint32_t flags = 0; + int32_t userId = 0; + ErrCode ret = bundleMgrProxy->GetAllBundleNames(flags, userId, true, bundleNames); + EXPECT_EQ(ret, ERR_OK); + EXPECT_FALSE(bundleNames.empty()); +} + +/** + * @tc.number: GetAllBundleNames_0002 + * @tc.name: test GetAllBundleNames interface for userId 100 + * @tc.desc: 1. call GetAllBundleNames + */ +HWTEST_F(ActsBmsKitSystemTest, GetAllBundleNames_0002, Function | MediumTest | Level1) +{ + sptr bundleMgrProxy = GetBundleMgrProxy(); + ASSERT_NE(bundleMgrProxy, nullptr); + std::vector bundleNames; + uint32_t flags = 0; + int32_t userId = 100; + ErrCode ret = bundleMgrProxy->GetAllBundleNames(flags, userId, true, bundleNames); + EXPECT_EQ(ret, ERR_OK); + EXPECT_FALSE(bundleNames.empty()); +} + +/** + * @tc.number: GetAllBundleNames_0003 + * @tc.name: test GetAllBundleNames interface for invalid userId + * @tc.desc: 1. call GetAllBundleNames + */ +HWTEST_F(ActsBmsKitSystemTest, GetAllBundleNames_0003, Function | MediumTest | Level1) +{ + sptr bundleMgrProxy = GetBundleMgrProxy(); + ASSERT_NE(bundleMgrProxy, nullptr); + std::vector bundleNames; + uint32_t flags = 0; + int32_t userId = 199999; + ErrCode ret = bundleMgrProxy->GetAllBundleNames(flags, userId, true, bundleNames); + EXPECT_NE(ret, ERR_OK); + EXPECT_TRUE(bundleNames.empty()); +} + +/** + * @tc.number: GetAllBundleNames_0004 + * @tc.name: test GetAllBundleNames interface for disabled app + * @tc.desc: 1. call GetAllBundleNames + */ +HWTEST_F(ActsBmsKitSystemTest, GetAllBundleNames_0004, Function | MediumTest | Level1) +{ + std::vector resvec; + std::string bundleFilePath = THIRD_BUNDLE_PATH + "bundleClient1.hap"; + std::string appName = "com.example.ohosproject.hmservice"; + Install(bundleFilePath, InstallFlag::REPLACE_EXISTING, resvec); + CommonTool commonTool; + std::string installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + sptr bundleMgrProxy = GetBundleMgrProxy(); + ASSERT_NE(bundleMgrProxy, nullptr); + auto setResult = bundleMgrProxy->SetApplicationEnabled(appName, false, USERID); + EXPECT_EQ(setResult, ERR_OK); + + // Test GET_BUNDLE_INFO_DEFAULT flag, the disabled app is not included + std::vector bundleNames; + uint32_t flags = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_DEFAULT); + auto ret1 = bundleMgrProxy->GetAllBundleNames(flags, USERID, true, bundleNames); + EXPECT_EQ(ret1, ERR_OK); + EXPECT_FALSE(bundleNames.empty()); + auto it = std::find(bundleNames.begin(), bundleNames.end(), appName); + EXPECT_EQ(it, bundleNames.end()); + + // Test GET_BUNDLE_INFO_WITH_DISABLE flag, the disabled app is included + std::vector bundleNamesWithDisabled; + uint32_t flagsWithDisabled = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE); + auto ret2 = bundleMgrProxy->GetAllBundleNames(flagsWithDisabled, USERID, true, bundleNamesWithDisabled); + EXPECT_EQ(ret2, ERR_OK); + EXPECT_FALSE(bundleNamesWithDisabled.empty()); + auto it2 = std::find(bundleNamesWithDisabled.begin(), bundleNamesWithDisabled.end(), appName); + EXPECT_NE(it2, bundleNamesWithDisabled.end()); + + auto resetResult = bundleMgrProxy->SetApplicationEnabled(appName, true, USERID); + EXPECT_EQ(resetResult, ERR_OK); + + // Test GET_BUNDLE_INFO_WITH_ABILITIES flag, the enabled app is included + std::vector bundleNames2; + uint32_t flags2 = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_DEFAULT); + auto ret3 = bundleMgrProxy->GetAllBundleNames(flags2, USERID, true, bundleNames2); + EXPECT_EQ(ret3, ERR_OK); + EXPECT_FALSE(bundleNames2.empty()); + auto it3 = std::find(bundleNames2.begin(), bundleNames2.end(), appName); + EXPECT_NE(it3, bundleNames2.end()); + + resvec.clear(); + Uninstall(appName, resvec); + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; +} + /** * @tc.number: GetSpecifiedDistributionType_0001 * @tc.name: test GetSpecifiedDistributionType proxy @@ -10825,20 +10931,20 @@ HWTEST_F(ActsBmsKitSystemTest, GetAllBundleCacheStat_0001, Function | MediumTest std::cout << "START GetAllBundleCacheStat_0001" << std::endl; sptr bundleMgrProxy = GetBundleMgrProxy(); EXPECT_NE(bundleMgrProxy, nullptr); - + ErrCode ret = ERR_OK; sptr getCache1 = nullptr; // test param is nullptr ret = bundleMgrProxy->GetAllBundleCacheStat(getCache1); EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_PARAM_ERROR); - + // test one calling getCache1 = new (std::nothrow) TestGetAllBundleCacheCallBack(); EXPECT_NE(getCache1, nullptr); ret = bundleMgrProxy->GetAllBundleCacheStat(getCache1); EXPECT_EQ(ret, ERR_OK); sleep(5); - + // test multi calling sptr getCache2 = new (std::nothrow) TestGetAllBundleCacheCallBack(); EXPECT_NE(getCache2, nullptr); @@ -10846,7 +10952,7 @@ HWTEST_F(ActsBmsKitSystemTest, GetAllBundleCacheStat_0001, Function | MediumTest EXPECT_NE(getCache2, nullptr); sptr getCache4 = new (std::nothrow) TestGetAllBundleCacheCallBack(); EXPECT_NE(getCache2, nullptr); - + ret = bundleMgrProxy->GetAllBundleCacheStat(getCache2); EXPECT_EQ(ret, ERR_OK); ret = bundleMgrProxy->GetAllBundleCacheStat(getCache3); -- Gitee