From 0b07301f0164deda0c8ea2160f0e3d456578882a Mon Sep 17 00:00:00 2001 From: xdongs Date: Fri, 28 Mar 2025 09:24:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=A2=83=E6=98=93=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E4=B8=8D=E9=80=9A=E7=9F=A5=E4=BD=BF=E8=83=BD=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xdongs --- services/ans/include/bundle_manager_helper.h | 11 +++++++++++ .../advanced_notification_publish_service.cpp | 12 +++++++++++- services/ans/src/bundle_manager_helper.cpp | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/services/ans/include/bundle_manager_helper.h b/services/ans/include/bundle_manager_helper.h index 0ef10e9a2..65d07cf44 100644 --- a/services/ans/include/bundle_manager_helper.h +++ b/services/ans/include/bundle_manager_helper.h @@ -134,6 +134,17 @@ public: */ bool CheckApiCompatibility(const std::string &bundleName, const int32_t &uid); + /** + * @brief GetBundleInfoV9. + * @param bundle bundle name. + * @param flag query condation. + * @param bundleInfo bundle info. + * @param userId userId. + * @return Returns the query result if succeed, retrun 0(main index) otherwise. + */ + bool GetBundleInfoV9(const std::string bundle, const int32_t flag, + AppExecFwk::BundleInfo &bundleInfo, const int32_t userId); + private: void Connect(); void Disconnect(); diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index dc58883cd..17e8f6c33 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -75,6 +75,8 @@ constexpr const char *CONTACT_DATA = "datashare:///com.ohos.contactsdataability/ constexpr const char *SUPPORT_INTEGELLIGENT_SCENE = "true"; constexpr int32_t OPERATION_TYPE_COMMON_EVENT = 4; const static std::string BUNDLE_NAME_ZYT = "com.zhuoyi.appstore.lite"; +const static std::string BUNDLE_NAME_ABROAD = "com.easy.transfer.abroad"; +const static std::string INSTALL_SOURCE_EASYABROAD = "com.easy.abroad"; constexpr int32_t BADGE_NUM_LIMIT = 0; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( @@ -1041,7 +1043,15 @@ ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { return ERR_ANS_PERMISSION_DENIED; } - if (bundleName == BUNDLE_NAME_ZYT) { + if (bundleName == BUNDLE_NAME_ZYT || bundleName == BUNDLE_NAME_ABROAD) { + ANS_LOGI("RequestEnableNotification zyt or abroad"); + return ERR_ANS_NOT_ALLOWED; + } + + AppExecFwk::BundleInfo bundleInfo; + BundleManagerHelper::GetInstance()->GetBundleInfoV9(bundleName, 1, bundleInfo, 0); + if (bundleInfo.applicationInfo.installSource == INSTALL_SOURCE_EASYABROAD) { + ANS_LOGI("RequestEnableNotification abroad app"); return ERR_ANS_NOT_ALLOWED; } sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundleName, uid); diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index a5c34e305..85d29f1fb 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -259,5 +259,22 @@ int32_t BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle } return uid; } + +bool BundleManagerHelper::GetBundleInfoV9( + const std::string bundle, const int32_t flag, + AppExecFwk::BundleInfo &bundleInfo, const int32_t userId) +{ + std::lock_guard lock(connectionMutex_); + Connect(); + + if (bundleMgr_ == nullptr) { + return false; + } + bool ret = false; + std::string identity = IPCSkeleton::ResetCallingIdentity(); + ret = bundleMgr_->GetBundleInfoV9(bundle, flag, bundleInfo, userId); + IPCSkeleton::SetCallingIdentity(identity); + return ret; +} } // namespace Notification } // namespace OHOS -- Gitee