From 988d7ac126da31906cd618fe3cc170916ef8e9f7 Mon Sep 17 00:00:00 2001 From: xdongs Date: Fri, 28 Mar 2025 09:24:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E5=A2=83=E6=98=93=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=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 fe068b353..95c020073 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"; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( const sptr &bundleOption, bool enabled) @@ -1018,7 +1020,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 2605e2ada..d86bc32c7 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