From bdcdf7ebd810be21b179174e4e9a9a9a33e58ec0 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Fri, 20 Jan 2023 12:36:31 +0800 Subject: [PATCH] fixed a0e3527 from https://gitee.com/fangJinliang1/notification_ans_standard/pulls/908 fix getSlot return Signed-off-by: fangJinliang1 Change-Id: Ia60bff412c6cdd1e6d3d2a1098c048bead03a98e Signed-off-by: fangJinliang1 --- .../ans_innerkits_module_slot_test.cpp | 15 +++++---------- .../ans/src/advanced_notification_service.cpp | 18 ++++++------------ .../advanced_notification_service_test.cpp | 3 +-- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp index fc44ecde1..9c1c47416 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -99,8 +99,7 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00100, Fu EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION)); - EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, - NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot)); + EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot)); } /** @@ -144,8 +143,7 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00200, Fu EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::SERVICE_REMINDER)); - EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, - NotificationHelper::GetNotificationSlot(NotificationConstant::SERVICE_REMINDER, spSlot)); + EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SERVICE_REMINDER, spSlot)); } /** @@ -190,8 +188,7 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00300, Fu EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::CONTENT_INFORMATION)); - EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, - NotificationHelper::GetNotificationSlot(NotificationConstant::CONTENT_INFORMATION, spSlot)); + EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::CONTENT_INFORMATION, spSlot)); } /** @@ -235,8 +232,7 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00400, Fu EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::OTHER)); - EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, - NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); + EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); } /** @@ -284,8 +280,7 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00500, Fu EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::OTHER)); - EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, - NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); + EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); } /** diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 12ac1fbc1..00f495bec 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1345,14 +1345,11 @@ ErrCode AdvancedNotificationService::GetSlotByType( return ERR_ANS_INVALID_BUNDLE; } - ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { - result = NotificationPreferences::GetInstance().GetNotificationSlot(bundleOption, slotType, slot); - if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { - result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; - } + NotificationPreferences::GetInstance().GetNotificationSlot(bundleOption, slotType, slot); })); - return result; + // if get slot failed, it still return ok. + return ERR_OK; } ErrCode AdvancedNotificationService::RemoveSlotByType(const NotificationConstant::SlotType &slotType) @@ -1364,14 +1361,11 @@ ErrCode AdvancedNotificationService::RemoveSlotByType(const NotificationConstant return ERR_ANS_INVALID_BUNDLE; } - ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { - result = NotificationPreferences::GetInstance().RemoveNotificationSlot(bundleOption, slotType); - if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { - result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; - } + NotificationPreferences::GetInstance().RemoveNotificationSlot(bundleOption, slotType); })); - return result; + // if remove slot failed, it still return ok. + return ERR_OK; } ErrCode AdvancedNotificationService::GetAllActiveNotifications(std::vector> ¬ifications) diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index d631bddd0..dbbd270af 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -789,8 +789,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05200, HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05300, Function | SmallTest | Level1) { TestAddSlot(NotificationConstant::SlotType::OTHER); - EXPECT_EQ((int)advancedNotificationService_->RemoveSlotByType(NotificationConstant::CUSTOM), - (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); + EXPECT_EQ((int)advancedNotificationService_->RemoveSlotByType(NotificationConstant::CUSTOM), 0); } /** -- Gitee