From a7c3b1f7d2c287581cddd6d45f750a390a0f015d Mon Sep 17 00:00:00 2001 From: weixin_45932406 Date: Tue, 9 Sep 2025 15:15:55 +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 | 15 ++- .../include/bundlemgr/bundle_mgr_proxy.h | 18 ++- .../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 | 42 +++++++ .../bundlemgr/src/bundle_mgr_host_impl.cpp | 40 +++++- .../acts_bms_kit_system_test.cpp | 116 +++++++++++++++++- 11 files changed, 311 insertions(+), 17 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 92acf4bd41..bc33a3b7f6 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 @@ -224,6 +224,7 @@ enum class BundleMgrInterfaceCode : uint32_t { GET_PLUGIN_INFO = 198, RESET_ALL_AOT = 199, GET_TEST_RUNNER = 200, + 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 62a746e19e..aee15bb1ae 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 @@ -834,6 +834,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. @@ -905,7 +912,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 adb73983d0..2a7e7730f6 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 @@ -1068,7 +1068,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. @@ -1115,6 +1115,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 4872660a23..8bae3e7f34 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 @@ -1009,7 +1009,7 @@ public: #endif virtual sptr GetBundleMgrExtProxy() override; - + virtual ErrCode SetDebugMode(bool isDebug) override; virtual bool VerifySystemApi(int32_t beginApiVersion = Constants::INVALID_API_VERSION) override; @@ -1034,7 +1034,7 @@ public: virtual ErrCode GetSpecifiedDistributionType(const std::string &bundleName, std::string &specifiedDistributionType) override; - + virtual ErrCode BatchGetSpecifiedDistributionType(const std::vector &bundleNames, std::vector &specifiedDistributionTypes) override; @@ -1206,6 +1206,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. @@ -1243,10 +1253,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 ad58b7d28f..64903ef270 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 @@ -710,6 +710,9 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa case static_cast(BundleMgrInterfaceCode::GET_TEST_RUNNER): errCode = HandleGetTestRunner(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); @@ -4893,7 +4896,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"); @@ -4945,5 +4948,25 @@ ErrCode BundleMgrHost::HandleGetTestRunner(MessageParcel &data, MessageParcel &r } 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 91a8ce4182..f239650e72 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 @@ -6024,7 +6024,7 @@ ErrCode BundleMgrProxy::GetAllBundleCacheStat(const sptr } return ret; } - + ErrCode BundleMgrProxy::GetAllBundleCacheStatExec(const sptr processCacheCallback) { APP_LOGI("start"); @@ -6037,7 +6037,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 6a43f361b7..7ab4454b20 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1052,6 +1052,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 656e12a848..82b5d71103 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -1126,6 +1126,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 f302d0be27..90e87f3ac6 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -10150,6 +10150,48 @@ 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; + } + uint32_t launchFlag = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_ONLY_WITH_LAUNCHER_ABILITY); + if (((static_cast(flags) & launchFlag) == launchFlag) && (innerInfo.IsHideDesktopIcon())) { + LOG_D(BMS_TAG_QUERY, "bundleName %{public}s is hide desktopIcon", bundleName.c_str()); + continue; + } + uint32_t cloudFlag = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_CLOUD_KIT); + if (((static_cast(flags) & cloudFlag) == cloudFlag) && + !innerInfo.GetCloudFileSyncEnabled() && + !innerInfo.GetCloudStructuredDataSyncEnabled()) { + APP_LOGD("bundle %{public}s does not enable cloud sync", bundleName.c_str()); + 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 9f41bc4732..ca1b2b8e0b 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -4210,7 +4210,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()) { @@ -4345,7 +4345,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; @@ -5285,6 +5285,40 @@ 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_LOGI("start for user:%{public}d, flags:%{public}d", userId, 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_INSTALLED_BUNDLE_LIST)) { + 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_APPEXECFWK_NULL_PTR; + } + auto ret = dataMgr->GetAllBundleNames(flags, userId, bundleNames); + if (withExtBundle && isBrokerServiceExisted_) { + auto bmsExtensionClient = std::make_shared(); + std::vector bundleInfos; + ErrCode res = bmsExtensionClient->GetBundleInfos(flags & + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_ONLY_WITH_LAUNCHER_ABILITY), bundleInfos, userId); + if (res == ERR_OK) { + std::for_each(bundleInfos.begin(), bundleInfos.end(), [&bundleNames](const auto& bundleInfo) { + bundleNames.push_back(bundleInfo.name); + }); + return ERR_OK; + } + } + return ret; +} + ErrCode BundleMgrHostImpl::QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName &element, int32_t flags, int32_t appIndex, ExtensionAbilityInfo &extensionAbilityInfo, int32_t userId) { @@ -6019,7 +6053,7 @@ bool BundleMgrHostImpl::SendQueryBundleInfoEvent( query.callingUid = callingUid; query.callingBundleName = callingBundleName; query.callingAppId = callingAppId; - + InsertQueryEventInfo(errCode, query); auto infos = GetQueryEventInfo(errCode); // check report now 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 8a235fabaf..0fb4c9d8f5 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); @@ -8473,6 +8473,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 @@ -10757,20 +10863,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); @@ -10778,7 +10884,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