From 2d2e46ea64eb51843204440c350a1283a19cb6bf Mon Sep 17 00:00:00 2001 From: xdongs Date: Fri, 23 May 2025 10:22:03 +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 - .../ans/include/notification_extension_wrapper.h | 3 +++ services/ans/src/advanced_notification_utils.cpp | 6 ------ .../ans/src/enable_manager/enable_manager.cpp | 6 +++--- .../ans/src/notification_extension_wrapper.cpp | 16 ++++++++++++++++ .../advanced_notification_utils_test.cpp | 11 ----------- .../notification_extension_wrapper_test.cpp | 12 ++++++++++++ 7 files changed, 34 insertions(+), 21 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..2620bd8c0 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 (*NOTIFICATIONDIALOGCONTROL)(); #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 NotificationDialogControl(); #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; + NOTIFICATIONDIALOGCONTROL notificationDialogControl_ = nullptr; bool isRegisterDataSettingObserver = false; #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index 38f9a165c..152551e1e 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -1980,11 +1980,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/enable_manager/enable_manager.cpp b/services/ans/src/enable_manager/enable_manager.cpp index 010a85219..b2e3a5d8e 100644 --- a/services/ans/src/enable_manager/enable_manager.cpp +++ b/services/ans/src/enable_manager/enable_manager.cpp @@ -30,6 +30,7 @@ #include "notification_bundle_option.h" #include "notification_analytics_util.h" #include "os_account_manager_helper.h" +#include "notification_extension_wrapper.h" namespace OHOS { namespace Notification { @@ -39,7 +40,6 @@ const static std::string BUNDLE_NAME_ZYT = "com.zhuoyi.appstore.lite"; const static std::string BUNDLE_NAME_ABROAD = "com.easy.abroad"; const static std::string INSTALL_SOURCE_EASYABROAD = "com.easy.abroad"; constexpr int32_t ZERO_USER_ID = 0; -constexpr const char *SAMPLE_MEACHINE = "const.dfx.enable_retail"; ErrCode AdvancedNotificationService::RequestEnableNotification(const std::string &deviceId, const sptr &callback) @@ -143,7 +143,7 @@ ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std:: NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; } - if (GetSystemBoolParameter(SAMPLE_MEACHINE, false)) { + if (!EXTENTION_WRAPPER->NotificationDialogControl()) { return ERR_ANS_NOT_ALLOWED; } @@ -328,7 +328,7 @@ ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; } - if (GetSystemBoolParameter(SAMPLE_MEACHINE, false)) { + if (!EXTENTION_WRAPPER->NotificationDialogControl()) { return ERR_ANS_NOT_ALLOWED; } diff --git a/services/ans/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index 228d15d35..bf162c82c 100644 --- a/services/ans/src/notification_extension_wrapper.cpp +++ b/services/ans/src/notification_extension_wrapper.cpp @@ -95,6 +95,11 @@ void ExtensionWrapper::InitExtentionWrapper() initSummary_(UpdateUnifiedGroupInfo); } #endif + notificationDialogControl_ = (NOTIFICATIONDIALOGCONTROL)dlsym(extensionWrapperHandle_, "NotificationDialogControl"); + if (notificationDialogControl_ == nullptr) { + ANS_LOGE("extension wrapper symbol failed, error: %{public}s", dlerror()); + return; + } ANS_LOGD("extension wrapper init success"); } @@ -211,6 +216,17 @@ void ExtensionWrapper::UpdateByBundle(const std::string bundleName, int deleteRe updateByBundle_(bundleName, deleteType); } +bool ExtensionWrapper::NotificationDialogControl() +{ + if (notificationDialogControl_ == nullptr) { + ANS_LOGE("isSampleDevice_ is null"); + return true; + } + bool result = notificationDialogControl_(); + ANS_LOGI("notificationDialogControl_ 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..9e83db979 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, NotificationDialogControl_Test, TestSize.Level0) +{ + ExtensionWrapper wrapper; + bool result = wrapper.NotificationDialogControl(); + EXPECT_EQ(true, result); + + auto mockNotificationDialogControl = []() { return true; }; + wrapper.notificationDialogControl_ = mockNotificationDialogControl; + result = wrapper.NotificationDialogControl(); + EXPECT_EQ(true, result); +} } //namespace Notification } //namespace OHOS \ No newline at end of file -- Gitee