From c8a7cd3a9d0bdb124b76fc67508f8ae0d1417090 Mon Sep 17 00:00:00 2001 From: wang19954 Date: Sat, 13 Sep 2025 09:48:50 +0800 Subject: [PATCH 1/2] IssueNo:#ICXT7J Description:fix dynamic clone bug Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- .../bundle_resource/bundle_resource_parser.h | 2 ++ .../bundle_resource_manager.cpp | 17 ++++++++++++++-- .../bundle_resource_parser.cpp | 20 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h b/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h index dddba70696..93e3c8ca64 100644 --- a/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h +++ b/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h @@ -41,6 +41,8 @@ public: // parse clone bundle resource info bool ParserCloneResourceInfo(const int32_t appIndex, std::vector &resourceInfos); + bool ParserCloneResourceInfo(const int32_t appIndex, ResourceInfo &resourceInfos); + bool ParseResourceInfosNoTheme(const int32_t userId, std::vector &resourceInfos); bool ParseIconResourceInfosWithTheme(const int32_t userId, std::vector &resourceInfos); diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp index 7b0f339dd7..eef9f4885b 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp @@ -737,6 +737,12 @@ bool BundleResourceManager::AddDynamicIconResource( resourceInfo.bundleName_ = bundleName; resourceInfo.appIndex_ = appIndex; if (userId != Constants::UNSPECIFIED_USERID) { + // process icon with badge + BundleResourceParser parser; + if ((appIndex > 0) && (!parser.ParserCloneResourceInfo(appIndex, resourceInfo))) { + APP_LOGE("parse clone resource failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + } if (!bundleResourceIconRdb_->AddResourceIconInfo(userId, IconResourceType::DYNAMIC_ICON, resourceInfo)) { APP_LOGE("add dynamic icon failed -n %{public}s -u %{public}d -a %{public}d", bundleName.c_str(), userId, appIndex); @@ -756,9 +762,16 @@ bool BundleResourceManager::AddDynamicIconResource( resourceInfo.appIndex_ = 0; ret &= bundleResourceIconRdb_->AddResourceIconInfo(user, IconResourceType::DYNAMIC_ICON, resourceInfo); auto appIndexes = dataMgr->GetCloneAppIndexes(bundleName, user); + // process icon with badge + BundleResourceParser parser; for (const auto &index : appIndexes) { - resourceInfo.appIndex_ = index; - ret &= bundleResourceIconRdb_->AddResourceIconInfo(user, IconResourceType::DYNAMIC_ICON, resourceInfo); + ResourceInfo newResourceInfo = resourceInfo; + newResourceInfo.appIndex_ = index; + if (!parser.ParserCloneResourceInfo(appIndex, newResourceInfo)) { + APP_LOGE("parse clone resource failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + } + ret &= bundleResourceIconRdb_->AddResourceIconInfo(user, IconResourceType::DYNAMIC_ICON, newResourceInfo); } } if (!ret) { diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp index 0a6b889cf1..9a80ccb56e 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp @@ -506,6 +506,26 @@ bool BundleResourceParser::ParserCloneResourceInfo( #endif } +bool BundleResourceParser::ParserCloneResourceInfo(const int32_t appIndex, ResourceInfo &resourceInfo) +{ + if (appIndex <= 0) { + APP_LOGE("-n %{public}s appIndex %{public}d is invalid", resourceInfo.GetKey().c_str(), appIndex); + return false; + } + std::vector resourceInfos; + resourceInfos.emplace_back(resourceInfo); + if (!ParserCloneResourceInfo(appIndex, resourceInfos)) { + APP_LOGE("-n %{public}s appIndex %{public}d parse badge failed", resourceInfo.GetKey().c_str(), appIndex); + return false; + } + if (resourceInfos.empty()) { + APP_LOGE("-n %{public}s appIndex %{public}d resourceInfo empty", resourceInfo.GetKey().c_str(), appIndex); + return false; + } + resourceInfo.icon_ = resourceInfos[0].icon_; + return true; +} + bool BundleResourceParser::ParseResourceInfosNoTheme( const int32_t userId, std::vector &resourceInfos) { -- Gitee From dd9c553d6a9a79d48007d3f21750eb40df3a7e34 Mon Sep 17 00:00:00 2001 From: wang19954 Date: Sat, 13 Sep 2025 10:22:39 +0800 Subject: [PATCH 2/2] IssueNo:#ICXT7J Description:add test case Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- .../bundle_resource_manager.cpp | 4 +- .../bundle_resource_parser.cpp | 14 +- .../bms_bundle_resource_test.cpp | 133 ++++++++++++++++++ 3 files changed, 140 insertions(+), 11 deletions(-) diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp index eef9f4885b..e7e8fd7207 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp @@ -767,9 +767,9 @@ bool BundleResourceManager::AddDynamicIconResource( for (const auto &index : appIndexes) { ResourceInfo newResourceInfo = resourceInfo; newResourceInfo.appIndex_ = index; - if (!parser.ParserCloneResourceInfo(appIndex, newResourceInfo)) { + if (!parser.ParserCloneResourceInfo(index, newResourceInfo)) { APP_LOGE("parse clone resource failed -n %{public}s -u %{public}d -a %{public}d", - bundleName.c_str(), userId, appIndex); + bundleName.c_str(), user, index); } ret &= bundleResourceIconRdb_->AddResourceIconInfo(user, IconResourceType::DYNAMIC_ICON, newResourceInfo); } diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp index 9a80ccb56e..fde6d85b43 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp @@ -514,16 +514,12 @@ bool BundleResourceParser::ParserCloneResourceInfo(const int32_t appIndex, Resou } std::vector resourceInfos; resourceInfos.emplace_back(resourceInfo); - if (!ParserCloneResourceInfo(appIndex, resourceInfos)) { - APP_LOGE("-n %{public}s appIndex %{public}d parse badge failed", resourceInfo.GetKey().c_str(), appIndex); - return false; - } - if (resourceInfos.empty()) { - APP_LOGE("-n %{public}s appIndex %{public}d resourceInfo empty", resourceInfo.GetKey().c_str(), appIndex); - return false; + if (ParserCloneResourceInfo(appIndex, resourceInfos) && !resourceInfos.empty()) { + resourceInfo.icon_ = resourceInfos[0].icon_; + return true; } - resourceInfo.icon_ = resourceInfos[0].icon_; - return true; + APP_LOGE("-n %{public}s appIndex %{public}d parse badge failed", resourceInfo.GetKey().c_str(), appIndex); + return false; } bool BundleResourceParser::ParseResourceInfosNoTheme( diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp index 94028b5faa..dcf1af1535 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp @@ -5537,6 +5537,135 @@ HWTEST_F(BmsBundleResourceTest, AddDynamicIconResource_0010, Function | SmallTes } } +/** + * @tc.number: AddDynamicIconResource_0020 + * Function: AddDynamicIconResource + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddDynamicIconResource + */ +HWTEST_F(BmsBundleResourceTest, AddDynamicIconResource_0020, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + ResourceInfo resourceInfo; + resourceInfo.icon_ = "111"; + bool ret = manager->AddDynamicIconResource(BUNDLE_NAME_NOT_EXIST, USERID, 1, resourceInfo); + EXPECT_TRUE(ret); + ret = manager->DeleteDynamicIconResource(BUNDLE_NAME_NOT_EXIST, USERID, 1); + EXPECT_TRUE(ret); + + BundleResourceRdb resourceRdb; + BundleResourceInfo info; + ret = manager->GetBundleResourceInfo(BUNDLE_NAME, + static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL), info); + EXPECT_TRUE(ret); + resourceInfo.icon_ = info.icon; + ret = manager->AddDynamicIconResource(BUNDLE_NAME_NOT_EXIST, USERID, 2, resourceInfo); + EXPECT_TRUE(ret); + ret = manager->DeleteDynamicIconResource(BUNDLE_NAME_NOT_EXIST, USERID, 2); + EXPECT_TRUE(ret); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: AddDynamicIconResource_0030 + * Function: AddDynamicIconResource + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddDynamicIconResource + */ +HWTEST_F(BmsBundleResourceTest, AddDynamicIconResource_0030, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + InnerBundleUserInfo innerBundleUserInfo; + innerBundleUserInfo.bundleUserInfo.userId = USERID; + InnerBundleCloneInfo innerBundleCloneInfo; + innerBundleCloneInfo.appIndex = 1; + innerBundleCloneInfo.userId = USERID; + innerBundleUserInfo.cloneInfos["1"] = innerBundleCloneInfo; + InnerBundleInfo bundleInfo; + bundleInfo.innerBundleUserInfos_["_100"] = innerBundleUserInfo; + savedDataMgr->bundleInfos_[BUNDLE_NAME_NOT_EXIST] = bundleInfo; + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + ResourceInfo resourceInfo; + resourceInfo.icon_ = "111"; + bool ret = manager->AddDynamicIconResource(BUNDLE_NAME_NOT_EXIST, Constants::UNSPECIFIED_USERID, 0, + resourceInfo); + EXPECT_TRUE(ret); + ret = manager->DeleteDynamicIconResource(BUNDLE_NAME_NOT_EXIST, Constants::UNSPECIFIED_USERID, 0); + EXPECT_TRUE(ret); + + BundleResourceRdb resourceRdb; + BundleResourceInfo info; + ret = manager->GetBundleResourceInfo(BUNDLE_NAME, + static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL), info); + EXPECT_TRUE(ret); + resourceInfo.icon_ = info.icon; + ret = manager->AddDynamicIconResource(BUNDLE_NAME_NOT_EXIST, Constants::UNSPECIFIED_USERID, 0, resourceInfo); + EXPECT_TRUE(ret); + ret = manager->DeleteDynamicIconResource(BUNDLE_NAME_NOT_EXIST, Constants::UNSPECIFIED_USERID, 0); + EXPECT_TRUE(ret); + } + + auto iter = savedDataMgr->bundleInfos_.find(BUNDLE_NAME_NOT_EXIST); + if (iter != savedDataMgr->bundleInfos_.end()) { + savedDataMgr->bundleInfos_.erase(iter); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: ParserCloneResourceInfo_0010 + * Function: ParserCloneResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ParserCloneResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, ParserCloneResourceInfo_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + ResourceInfo resourceInfo; + BundleResourceParser bundleResourceParser; + bool ret = bundleResourceParser.ParserCloneResourceInfo(0, resourceInfo); + EXPECT_FALSE(ret); + + resourceInfo.icon_ = "111"; + ret = bundleResourceParser.ParserCloneResourceInfo(1, resourceInfo); + EXPECT_FALSE(ret); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + BundleResourceInfo info; + ret = manager->GetBundleResourceInfo(BUNDLE_NAME, + static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL), info); + EXPECT_TRUE(ret); + resourceInfo.icon_ = info.icon; + } + + ret = bundleResourceParser.ParserCloneResourceInfo(2, resourceInfo); + EXPECT_TRUE(ret); + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + /** * @tc.number: AddAllResourceInfo_0010 * Function: AddAllResourceInfo @@ -5729,9 +5858,13 @@ HWTEST_F(BmsBundleResourceTest, AddCloneBundleResourceInfoWhenInstall_0010, Func EXPECT_FALSE(ret); ret = manager->AddCloneBundleResourceInfoWhenInstall(BUNDLE_NAME, USERID, 1, false); EXPECT_TRUE(ret); + ret = manager->DeleteCloneBundleResourceInfoWhenUninstall(BUNDLE_NAME, USERID, 1, false); + EXPECT_TRUE(ret); OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); ret = manager->AddCloneBundleResourceInfoWhenInstall(BUNDLE_NAME, USERID, 2, false); EXPECT_TRUE(ret); + ret = manager->DeleteCloneBundleResourceInfoWhenUninstall(BUNDLE_NAME, USERID, 2, false); + EXPECT_TRUE(ret); OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); } -- Gitee