diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 93ce0ab67e7923a256631c6fa85e503b777db6c9..09443c74d65eb5fbed279c403a124f6597f1f502 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1562,6 +1562,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); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 63624547c504c6fd6cd42c548e352cb6529da5f3..2aa284e2ff9b8ec84777cca32b61dda2231db861 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) @@ -1140,6 +1141,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."); @@ -1363,7 +1367,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 ce5c3d91318e33c1a9dd3dec783c828f1a82e518..9105ed040ad9defbe7902281dc9267317c16e353 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()) { \ @@ -2220,5 +2221,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 bb233a6a96f1cd6a34121ea1d0838af26b58d0f8..5e14c074a1b22a7ed0046eefaeab05f9503f4add 100644 --- a/services/ans/test/unittest/advanced_notification_utils_test.cpp +++ b/services/ans/test/unittest/advanced_notification_utils_test.cpp @@ -1084,5 +1084,17 @@ HWTEST_F(AnsUtilsTest, GetCommonTargetRecordList_0001, Function | SmallTest | Le NotificationContent::Type::LIVE_VIEW, recordList); ASSERT_EQ(recordList.size(), 1); } + +/** + * @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