From e3e57a009b1de9a2a418f2aa2c786233d03146a9 Mon Sep 17 00:00:00 2001 From: xdongs Date: Tue, 6 May 2025 10:34:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E5=BA=97=E8=AE=BE=E5=A4=87=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E7=9F=A5=E4=BD=BF=E8=83=BD=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=20Signed-off-by:=20xdongs=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/ans/include/advanced_notification_service.h | 1 + .../src/advanced_notification_publish_service.cpp | 9 ++++++++- services/ans/src/advanced_notification_utils.cpp | 8 ++++++++ .../unittest/advanced_notification_utils_test.cpp | 12 ++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 697c470a4..05f1c035d 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1475,6 +1475,7 @@ private: const sptr bundleOption, const bool innerLake); void ClearSlotTypeData(const sptr &request, int32_t callingUid, int32_t sourceType); + bool GetSystemBoolParameter(const std::string &key, const bool defaultValue); private: static sptr instance_; diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index f34be910d..cc15e96db 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -80,6 +80,7 @@ const static std::string INSTALL_SOURCE_EASYABROAD = "com.easy.abroad"; constexpr int32_t BADGE_NUM_LIMIT = 0; constexpr int32_t CLEAR_SLOT_FROM_AVSEESAION = 1; constexpr int32_t CLEAR_SLOT_FROM_RSS = 2; +constexpr const char *SAMPLE_MEACHINE = "const.dfx.enable_retail"; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( const sptr &bundleOption, bool enabled) @@ -1088,6 +1089,9 @@ ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std:: NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; } + if (GetSystemBoolParameter(SAMPLE_MEACHINE, false)) { + return ERR_ANS_NOT_ALLOWED; + } if (!CreateDialogManager()) { ANS_LOGE("Create dialog manager failed."); @@ -1309,7 +1313,10 @@ ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; } - + if (GetSystemBoolParameter(SAMPLE_MEACHINE, false)) { + return ERR_ANS_NOT_ALLOWED; + } + if (!CreateDialogManager()) { ANS_LOGE("Create dialog manager failed."); message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Create dialog failed"); diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index 74c1c6816..459e4fff1 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -52,6 +52,7 @@ #include "notification_clone_disturb_service.h" #include "notification_clone_bundle_service.h" #include "advanced_notification_flow_control_service.h" +#include "parameters.h" #define CHECK_BUNDLE_OPTION_IS_INVALID(option) \ if (option == nullptr || option->GetBundleName().empty()) { \ @@ -1927,5 +1928,12 @@ void AdvancedNotificationService::UpdateCloneBundleInfo(const NotificationCloneB } })); } + +bool AdvancedNotificationService::GetSystemBoolParameter(const std::string &key, const bool defaultValue) +{ + bool result = OHOS::system::GetBoolParameter(key, defaultValue); + ANS_LOGI("GetBoolParameter key = %{public}s result = %{public}d", key.c_str(), result); + return result; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/advanced_notification_utils_test.cpp b/services/ans/test/unittest/advanced_notification_utils_test.cpp index c698b91e3..863c18917 100644 --- a/services/ans/test/unittest/advanced_notification_utils_test.cpp +++ b/services/ans/test/unittest/advanced_notification_utils_test.cpp @@ -450,5 +450,17 @@ HWTEST_F(AnsUtilsTest, UpdateCloneBundleInfo_00001, Function | SmallTest | Level cloneBundleInfo.SetSlotFlags(63); advancedNotificationService_->UpdateCloneBundleInfo(cloneBundleInfo); } + +/** + * @tc.name: GetSystemBoolParameter_0001 + * @tc.desc: Test GetSystemBoolParameter_0001 + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AnsUtilsTest, GetSystemBoolParameter_0001, Function | SmallTest | Level1) +{ + bool result = advancedNotificationService_->GetSystemBoolParameter("const.dfx.enable_retail", false); + ASSERT_EQ(result, false); +} } // namespace Notification } // namespace OHOS -- Gitee