diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index f48ccfb59f30edcf1654b0b7c91ccdd1a05cf56c..beba5fa04ed5db1bbd15280f74d9fc8ba2fc30a7 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -1545,15 +1545,14 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const } jsonObject["distributedOptions"] = optObj; - if (!notificationFlags_) { - return false; - } - nlohmann::json flagsObj; - if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { - ANS_LOGE("Cannot convert notificationFlags to JSON"); - return false; + if (notificationFlags_) { + nlohmann::json flagsObj; + if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { + ANS_LOGE("Cannot convert notificationFlags to JSON"); + return false; + } + jsonObject["notificationFlags"] = flagsObj; } - jsonObject["notificationFlags"] = flagsObj; return true; } diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index fc1d0c27c842d028fcb732c200f1e954209c7d3a..f58b8f4e70b1f95b79deeea6b187cff60866e81f 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1229,6 +1229,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09600, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, Function | SmallTest | Level1) { + EXPECT_EQ( + (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); TestAddSlot(NotificationConstant::SlotType::OTHER); bool allowed = true; EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify( @@ -1243,6 +1245,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09800, Function | SmallTest | Level1) { + EXPECT_EQ( + (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); std::vector> notifications; bool allowed = true; EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify(