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..2620bd8c0d50d35bcbca52baba61c16a9df949c1 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 38f9a165c38ead7079f92af6786ce38a1f0512f7..152551e1eac47dc923a2714f1365b54f768b396b 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 010a85219571cf397fae68a9836417f7bb341435..b2e3a5d8ee90d27cb4e26f3624f3cf95b7c5f17f 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 228d15d355d355b550fa96820a127572032710da..bf162c82c7e556a5cae878d0e957faf0b3f6ce70 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 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..9e83db979df97384052af6ca2d603d2e35620798 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