diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 22749641bf662a6f06787c360ac70e2b33a962cd..a36a3dcf7364fd2d9076215d9cd64e4cf22772cc 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1572,7 +1572,6 @@ private: const bool easyAbroad); void ClearSlotTypeData(const sptr &request, int32_t callingUid, int32_t sourceType); ErrCode RegisterPushCallbackTokenCheck(); - bool GetSystemBoolParameter(const std::string &key, const bool defaultValue); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) diff --git a/services/ans/include/notification_extension_wrapper.h b/services/ans/include/notification_extension_wrapper.h index af1a6e457d61380635d3c47b4b475538f16c6c15..cd2bc52867da56610134a7b97f450374db28891b 100644 --- a/services/ans/include/notification_extension_wrapper.h +++ b/services/ans/include/notification_extension_wrapper.h @@ -42,6 +42,7 @@ public: typedef void (*UPDATE_BY_BUNDLE)(const std::string bundleName, int deleteType); typedef int32_t (*REMINDER_CONTROL)(const std::string &bundleName); typedef int32_t (*BANNER_CONTROL)(const std::string &bundleName); + typedef bool (*ISSAMPLEDEVICE)(); #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER typedef bool (*MODIFY_REMINDER_FLAGS)(const sptr &request); @@ -57,6 +58,7 @@ public: void UpdateByBundle(const std::string bundleName, int deleteType); int32_t ReminderControl(const std::string &bundleName); int32_t BannerControl(const std::string &bundleName); + bool IsSampleDevice(); #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER bool ModifyReminderFlags(const sptr &request); @@ -75,6 +77,7 @@ private: UPDATE_BY_BUNDLE updateByBundle_ = nullptr; REMINDER_CONTROL reminderControl_ = nullptr; BANNER_CONTROL bannerControl_ = nullptr; + ISSAMPLEDEVICE isSampleDevice_ = nullptr; bool isRegisterDataSettingObserver = false; #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 4b749402d169825cefcb0550fe263b380f8e974e..b1bb67956de4c1aa63eccb61efa07ae598667e15 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -80,7 +80,6 @@ const static std::string INSTALL_SOURCE_EASYABROAD = "com.easy.abroad"; constexpr int32_t ZERO_USER_ID = 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) @@ -1000,7 +999,7 @@ ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std:: NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; } - if (GetSystemBoolParameter(SAMPLE_MEACHINE, false)) { + if (EXTENTION_WRAPPER->IsSampleDevice()) { return ERR_ANS_NOT_ALLOWED; } @@ -1229,7 +1228,7 @@ ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; } - if (GetSystemBoolParameter(SAMPLE_MEACHINE, false)) { + if (EXTENTION_WRAPPER->IsSampleDevice()) { return ERR_ANS_NOT_ALLOWED; } diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index 327c531822cd8c9636193e1258ab86fd1c2d68c5..ee4a19b0c8604ae1d0323ddc64e3d5d46dd5c99b 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -52,7 +52,6 @@ #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()) { \ @@ -2228,11 +2227,5 @@ 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/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index 228d15d355d355b550fa96820a127572032710da..f5801e0ef3e2cfc674bb80382a7f63b77eeb4c1a 100644 --- a/services/ans/src/notification_extension_wrapper.cpp +++ b/services/ans/src/notification_extension_wrapper.cpp @@ -95,6 +95,12 @@ void ExtensionWrapper::InitExtentionWrapper() initSummary_(UpdateUnifiedGroupInfo); } #endif + + isSampleDevice_ = (ISSAMPLEDEVICE)dlsym(extensionWrapperHandle_, "IsSampleDevice"); + if (isSampleDevice_ == nullptr) { + ANS_LOGE("extension wrapper symbol failed, error: %{public}s", dlerror()); + return; + } ANS_LOGD("extension wrapper init success"); } @@ -211,6 +217,17 @@ void ExtensionWrapper::UpdateByBundle(const std::string bundleName, int deleteRe updateByBundle_(bundleName, deleteType); } +bool ExtensionWrapper::IsSampleDevice() +{ + if (isSampleDevice_ == nullptr) { + ANS_LOGE("isSampleDevice_ is null"); + return false; + } + bool result = isSampleDevice_(); + ANS_LOGI("isSampleDevice result = %{public}d", result); + return result; +} + int32_t ExtensionWrapper::convertToDelType(int32_t deleteReason) { int32_t delType = ACTIVE_DELETE; diff --git a/services/ans/test/unittest/advanced_notification_utils_test.cpp b/services/ans/test/unittest/advanced_notification_utils_test.cpp index 5e14c074a1b22a7ed0046eefaeab05f9503f4add..0cb0c6e1aee1f070be19c9bde7e79168d6a85d1b 100644 --- a/services/ans/test/unittest/advanced_notification_utils_test.cpp +++ b/services/ans/test/unittest/advanced_notification_utils_test.cpp @@ -1085,16 +1085,5 @@ HWTEST_F(AnsUtilsTest, GetCommonTargetRecordList_0001, Function | SmallTest | Le 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 diff --git a/services/ans/test/unittest/notification_extension_wrapper_test.cpp b/services/ans/test/unittest/notification_extension_wrapper_test.cpp index 0274c79726bdf3a21ebe491e402b8af29368d322..ffc71f49321e453fe48e75025d20054dee8afb5e 100644 --- a/services/ans/test/unittest/notification_extension_wrapper_test.cpp +++ b/services/ans/test/unittest/notification_extension_wrapper_test.cpp @@ -384,5 +384,17 @@ HWTEST_F(NotificationExtensionWrapperTest, convertToDelType_DisableNotificationR // Assert ASSERT_EQ(expectedDelType, actualDelType); } + +HWTEST_F(NotificationExtensionWrapperTest, IsSampleDevice_Test, TestSize.Level0) +{ + ExtensionWrapper wrapper; + bool result = wrapper.IsSampleDevice(); + EXPECT_EQ(false, result); + + auto mockIsSampleDevice = []() { return false; }; + wrapper.isSampleDevice_ = mockIsSampleDevice; + result = wrapper.IsSampleDevice(); + EXPECT_EQ(false, result); +} } //namespace Notification } //namespace OHOS \ No newline at end of file