!4984 bm工具适配禁用ability的资源信息

Merge pull request !4984 from wangtiantian/resource_bm
This commit is contained in:
openharmony_ci 2023-11-14 04:03:27 +00:00 committed by Gitee
commit 79444cebc8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 57 additions and 11 deletions

View File

@ -847,6 +847,7 @@ public:
std::string &profile) const;
bool GetFingerprints(const std::string &bundleName, std::vector<std::string> &fingerPrints) const;
ErrCode GetInnerBundleInfoByUid(const int uid, InnerBundleInfo &innerBundleInfo) const;
std::string GetModuleNameByBundleAndAbility(const std::string& bundleName, const std::string& abilityName);
private:
/**

View File

@ -5733,5 +5733,27 @@ bool BundleDataMgr::IsUpdateInnerBundleInfoSatisified(const InnerBundleInfo &old
{
return !oldInfo.HasEntry() || oldInfo.GetEntryInstallationFree() || newInfo.HasEntry();
}
std::string BundleDataMgr::GetModuleNameByBundleAndAbility(
const std::string& bundleName, const std::string& abilityName)
{
if (bundleName.empty() || abilityName.empty()) {
APP_LOGE("bundleName or abilityName is empty");
return std::string();
}
std::shared_lock<std::shared_mutex> lock(bundleInfoMutex_);
auto innerBundleInfo = bundleInfos_.find(bundleName);
if (innerBundleInfo == bundleInfos_.end()) {
APP_LOGE("can not find bundle %{public}s.", bundleName.c_str());
return std::string();
}
auto abilityInfo = innerBundleInfo->second.FindAbilityInfoV9(Constants::EMPTY_STRING, abilityName);
if (!abilityInfo) {
APP_LOGE("bundleName:%{public}s, abilityName:%{public}s can find moduleName",
bundleName.c_str(), abilityName.c_str());
return std::string();
}
return abilityInfo->moduleName;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -1640,10 +1640,7 @@ ErrCode BundleMgrHostImpl::SetAbilityEnabled(const AbilityInfo &abilityInfo, boo
}
std::string moduleName = abilityInfo.moduleName;
if (moduleName.empty()) {
AbilityInfo info;
if (GetAbilityInfo(abilityInfo.bundleName, abilityInfo.name, info)) {
moduleName = info.moduleName;
}
moduleName = dataMgr->GetModuleNameByBundleAndAbility(abilityInfo.bundleName, abilityInfo.name);
}
BundleResourceHelper::SetAbilityEnabled(abilityInfo.bundleName, moduleName, abilityInfo.name, isEnabled, userId);
EventReport::SendComponentStateSysEvent(abilityInfo.bundleName, abilityInfo.name, userId, isEnabled, false);

View File

@ -118,10 +118,10 @@ bool BundleResourceCallback::OnBundleStatusChanged(
APP_LOGE("bundleName is empty");
return false;
}
if (userId != Constants::START_USERID) {
if (userId != Constants::DEFAULT_USERID) {
int32_t currentUserId = AccountHelper::GetCurrentActiveUserId();
if (currentUserId != userId) {
APP_LOGE("userId: %{public}d, currentUserId :%{public}d", userId, currentUserId);
if ((currentUserId > 0) && (currentUserId != userId)) {
APP_LOGE("userId: %{public}d, currentUserId :%{public}d not same", userId, currentUserId);
return false;
}
}
@ -154,11 +154,10 @@ bool BundleResourceCallback::OnAbilityStatusChanged(const std::string &bundleNam
APP_LOGE("bundleName or moduleName or abilityName is empty");
return false;
}
if (userId != Constants::START_USERID) {
if (userId != Constants::DEFAULT_USERID) {
int32_t currentUserId = AccountHelper::GetCurrentActiveUserId();
if (currentUserId != userId) {
APP_LOGE("wtt userId: %{public}d, currentUserId :%{public}d not same", userId, currentUserId);
if ((currentUserId > 0) && (currentUserId != userId)) {
APP_LOGE("userId: %{public}d, currentUserId :%{public}d not same", userId, currentUserId);
return false;
}
}

View File

@ -3681,6 +3681,33 @@ HWTEST_F(BmsBundleDataMgrTest, ExplicitQueryAbilityInfoV9_0300, Function | Small
EXPECT_EQ(testRet, ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST);
}
/**
* @tc.number: GetModuleNameByBundleAndAbility_0100
* @tc.name: GetModuleNameByBundleAndAbility
* @tc.desc: GetModuleNameByBundleAndAbility
*/
HWTEST_F(BmsBundleDataMgrTest, GetModuleNameByBundleAndAbility_0100, Function | SmallTest | Level0)
{
std::string moduleName = GetBundleDataMgr()->GetModuleNameByBundleAndAbility("", ABILITY_NAME_TEST);
EXPECT_TRUE(moduleName.empty());
moduleName = GetBundleDataMgr()->GetModuleNameByBundleAndAbility(BUNDLE_NAME_TEST, "");
EXPECT_TRUE(moduleName.empty());
moduleName = GetBundleDataMgr()->GetModuleNameByBundleAndAbility(BUNDLE_NAME_TEST, ABILITY_NAME_TEST);
EXPECT_TRUE(moduleName.empty());
MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST);
moduleName = GetBundleDataMgr()->GetModuleNameByBundleAndAbility(BUNDLE_NAME_TEST, MODULE_NAME_TEST);
EXPECT_TRUE(moduleName.empty());
moduleName = GetBundleDataMgr()->GetModuleNameByBundleAndAbility(BUNDLE_NAME_TEST, ABILITY_NAME_TEST);
EXPECT_EQ(moduleName, MODULE_NAME_TEST);
MockUninstallBundle(BUNDLE_NAME_TEST);
}
/**
* @tc.number: FilterAbilityInfosByModuleName_0100
* @tc.name: test FilterAbilityInfosByModuleName