diff --git a/services/ans/include/bundle_manager_helper.h b/services/ans/include/bundle_manager_helper.h index 0ef10e9a2516dcc28e995544e47dbff98da85070..65d07cf44a4effa0362f53c2020e26e86847041b 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 dc58883cdda70f54f5615b549c3cad5456242a88..17e8f6c3363670005ffe6c6f509d879a64f68715 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 a5c34e305b7f50fe4adc1c2c45fd803854476142..85d29f1fb89570b19b39a5036e49707aecccbcb1 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