From 8e4fd1239ddb24194abd92bb47377c8d283ced76 Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Sun, 22 Jun 2025 17:38:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=9C=E6=B9=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8D=8F=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- services/ans/src/bundle_manager_helper.cpp | 33 ++++++++++--------- .../smart_reminder_center.cpp | 11 +++++-- .../src/helper/bundle_resource_helper.cpp | 27 ++++++++------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index 406f26e9e..22b58573a 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -23,6 +23,7 @@ #include "ans_const_define.h" #include "ans_log_wrapper.h" #include "notification_analytics_util.h" +#include "os_account_manager_helper.h" namespace OHOS { namespace Notification { @@ -273,11 +274,15 @@ bool BundleManagerHelper::GetBundleInfoV9( if (bundleMgr_ == nullptr) { return false; } - bool ret = false; std::string identity = IPCSkeleton::ResetCallingIdentity(); - ret = bundleMgr_->GetBundleInfoV9(bundle, flag, bundleInfo, userId); + int32_t ret = bundleMgr_->GetBundleInfoV9(bundle, flag, bundleInfo, userId); IPCSkeleton::SetCallingIdentity(identity); - return ret; + if (ret != ERR_OK) { + ANS_LOGE("Bundle failed %{public}s %{public}d %{public}d %{public}d.", bundle.c_str(), + flag, userId, ret); + return false; + } + return true; } ErrCode BundleManagerHelper::GetApplicationInfo(const std::string &bundleName, int32_t flags, int32_t userId, @@ -299,21 +304,19 @@ ErrCode BundleManagerHelper::GetApplicationInfo(const std::string &bundleName, i bool BundleManagerHelper::CheckSystemApp(const std::string& bundleName, int32_t userId) { - AppExecFwk::ApplicationInfo appInfo; - int32_t flags = static_cast(AppExecFwk::GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT); - ErrCode result = GetApplicationInfo(bundleName, flags, userId, appInfo); - if (result != ERR_OK) { - ANS_LOGE("Get installed bundle failed %{public}d.", result); - return false; + if (userId == SUBSCRIBE_USER_INIT) { + OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId); } - - if (appInfo.bundleType != AppExecFwk::BundleType::APP) { - ANS_LOGD("Get not app %{public}s %{public}d", bundleName.c_str(), appInfo.bundleType); - return true; + AppExecFwk::BundleInfo bundleInfo; + int32_t flags = static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION); + if (!GetBundleInfoV9(bundleName, flags, bundleInfo, userId)) { + ANS_LOGE("Get installed bundle failed."); + return false; } - ANS_LOGI("Get installed bundle %{public}s %{public}d.", bundleName.c_str(), appInfo.isSystemApp); - return appInfo.isSystemApp; + ANS_LOGI("Get installed bundle %{public}s %{public}d.", bundleName.c_str(), + bundleInfo.applicationInfo.isSystemApp); + return bundleInfo.applicationInfo.isSystemApp; } ErrCode BundleManagerHelper::GetBundleResourceInfo(const std::string &bundleName, diff --git a/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp b/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp index 0ef62a08c..b62dd8482 100644 --- a/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp +++ b/services/ans/src/notification_smart_reminder/smart_reminder_center.cpp @@ -32,6 +32,7 @@ #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER #include "notification_extension_wrapper.h" #endif +#include "os_account_manager_helper.h" namespace OHOS { namespace Notification { @@ -450,16 +451,20 @@ void SmartReminderCenter::FillRequestExtendInfo(const string &deviceType, Device { std::string bundleName = request->GetOwnerBundleName(); int32_t userId = request->GetOwnerUserId(); + if (userId == SUBSCRIBE_USER_INIT) { + OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId); + } std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); if (bundleManager != nullptr) { - int32_t flags = static_cast(AppExecFwk::GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT); - AppExecFwk::ApplicationInfo appInfo; - if (bundleManager->GetApplicationInfo(bundleName, flags, userId, appInfo) != ERR_OK) { + int32_t flags = static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION); + AppExecFwk::BundleInfo bundleInfo; + if (!bundleManager->GetBundleInfoV9(bundleName, flags, bundleInfo, userId)) { ANS_LOGE("FillRequestExtendInfo, GetApplicationInfo error, type = %{public}s, bundleName = %{public}s", deviceType.c_str(), bundleName.c_str()); return; } + AppExecFwk::ApplicationInfo appInfo = bundleInfo.applicationInfo; AppExecFwk::BundleResourceInfo bundleResourceInfo; if (bundleManager->GetBundleResourceInfo(bundleName, bundleResourceInfo, appInfo.appIndex) != ERR_OK) { ANS_LOGE("FillRequestExtendInfo, GetBundleResourceInfo error, type = %{public}s, bundleName = %{public}s", diff --git a/services/distributed/src/helper/bundle_resource_helper.cpp b/services/distributed/src/helper/bundle_resource_helper.cpp index d9f12f4ae..dec9d5cbe 100644 --- a/services/distributed/src/helper/bundle_resource_helper.cpp +++ b/services/distributed/src/helper/bundle_resource_helper.cpp @@ -156,21 +156,24 @@ ErrCode BundleResourceHelper::GetApplicationInfo(const std::string &appName, int bool BundleResourceHelper::CheckSystemApp(const std::string& bundleName, int32_t userId) { - AppExecFwk::ApplicationInfo appInfo; - int32_t flags = static_cast(AppExecFwk::GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT); - ErrCode result = GetApplicationInfo(bundleName, flags, userId, appInfo); - if (result != ERR_OK) { - ANS_LOGE("Get installed bundle failed %{public}d.", result); + AppExecFwk::BundleInfo bundleInfo; + int32_t flags = static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION); + + std::lock_guard lock(connectionMutex_); + Connect(); + if (bundleMgr_ == nullptr) { return false; } - - if (appInfo.bundleType != AppExecFwk::BundleType::APP) { - ANS_LOGD("Get not app %{public}s %{public}d", bundleName.c_str(), appInfo.bundleType); - return true; + std::string identity = IPCSkeleton::ResetCallingIdentity(); + int32_t result = bundleMgr_->GetBundleInfoV9(bundleName, flags, bundleInfo, userId); + IPCSkeleton::SetCallingIdentity(identity); + if (result != ERR_OK) { + ANS_LOGW("Get installed bundle %{public}s failed.", bundleName.c_str()); + return false; } - - ANS_LOGI("Get installed bundle %{public}s %{public}d.", bundleName.c_str(), appInfo.isSystemApp); - return appInfo.isSystemApp; + ANS_LOGI("Get installed bundle %{public}s %{public}d.", bundleName.c_str(), + bundleInfo.applicationInfo.isSystemApp); + return bundleInfo.applicationInfo.isSystemApp; } } } -- Gitee