From 08d60e817525946a32263fb17301630cf3d06e23 Mon Sep 17 00:00:00 2001 From: xdongs Date: Thu, 22 May 2025 11:43:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E5=BA=97=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E7=A7=BB=E5=8A=A8=E5=88=B0=E9=97=AD=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xdongs --- .../ans/include/advanced_notification_service.h | 1 - .../include/notification_extension_wrapper.h | 3 +++ .../advanced_notification_publish_service.cpp | 5 ++--- .../ans/src/advanced_notification_utils.cpp | 7 ------- .../ans/src/notification_extension_wrapper.cpp | 17 +++++++++++++++++ .../advanced_notification_utils_test.cpp | 11 ----------- .../notification_extension_wrapper_test.cpp | 12 ++++++++++++ 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 22749641b..a36a3dcf7 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 af1a6e457..cd2bc5286 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 4b749402d..b1bb67956 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 327c53182..ee4a19b0c 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 228d15d35..f5801e0ef 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 5e14c074a..0cb0c6e1a 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 0274c7972..ffc71f493 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 -- Gitee