From 17128836966bc5b896f46e6033bd894b1ba66a77 Mon Sep 17 00:00:00 2001 From: zero-cyc Date: Mon, 7 Feb 2022 14:57:21 +0800 Subject: [PATCH] chenlien@huawei.com Signed-off-by: zero-cyc Change-Id: Iabe47fea74be5549a3cb14433e326c74ad407355 --- .../core/common/include/ans_inner_errors.h | 1 + frameworks/ans/native/src/notification.cpp | 8 +++++ .../test/moduletest/ans_fw_module_test.cpp | 2 +- .../ans/native/include/notification.h | 6 ++++ .../ans/src/advanced_notification_service.cpp | 30 ++++++++----------- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/frameworks/ans/core/common/include/ans_inner_errors.h b/frameworks/ans/core/common/include/ans_inner_errors.h index c205fea2c..d8a4581b0 100644 --- a/frameworks/ans/core/common/include/ans_inner_errors.h +++ b/frameworks/ans/core/common/include/ans_inner_errors.h @@ -72,6 +72,7 @@ enum ErrorCode : uint32_t { ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, ERR_ANS_DISTRIBUTED_OPERATION_FAILED, ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, + ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED, }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/native/src/notification.cpp b/frameworks/ans/native/src/notification.cpp index 4b8e26125..b94a72e22 100644 --- a/frameworks/ans/native/src/notification.cpp +++ b/frameworks/ans/native/src/notification.cpp @@ -161,6 +161,14 @@ pid_t Notification::GetPid() const return request_->GetCreatorPid(); } +bool Notification::IsUnremovable() const +{ + if (request_ == nullptr) { + return false; + } + return request_->IsUnremovable(); +} + std::vector Notification::GetVibrationStyle() const { return vibrationStyle_; diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index dd1e6b12f..ec094df77 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -2451,7 +2451,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07600, Function EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); - EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->IsRemoveAllowed(), false); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->IsUnremovable(), true); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetSourceType(), NotificationConstant::SourceType::TYPE_CONTINUOUS); EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); diff --git a/interfaces/innerkits/ans/native/include/notification.h b/interfaces/innerkits/ans/native/include/notification.h index a12b7f4a0..a187b9534 100644 --- a/interfaces/innerkits/ans/native/include/notification.h +++ b/interfaces/innerkits/ans/native/include/notification.h @@ -164,6 +164,12 @@ public: */ pid_t GetPid() const; + /** + * Checks whether this notification is unremovable. + * @return true if this notification is unremovable; returns false otherwise. + */ + bool IsUnremovable() const; + /** * @brief Obtains the vibration style for this notifications. if * diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index cb95e52d1..11d9f816a 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1108,9 +1108,6 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptr ¬ification, bool isCancel) { for (auto record : notificationList_) { - if (!record->notification->IsRemoveAllowed()) { - continue; - } if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && (record->notification->GetLabel() == label) && @@ -1119,8 +1116,8 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptrdeviceId.empty() #endif ) { - if (!isCancel && record->request->IsUnremovable()) { - return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; + if (!isCancel && !record->notification->IsRemoveAllowed()) { + return ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED; } notification = record->notification; // delete or delete all, call the function @@ -1139,12 +1136,9 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList( const std::string &key, sptr ¬ification, bool isCancel) { for (auto record : notificationList_) { - if (!record->notification->IsRemoveAllowed() && isCancel) { - continue; - } if (record->notification->GetKey() == key) { - if (!isCancel && record->request->IsUnremovable()) { - return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; + if (!isCancel && !record->notification->IsRemoveAllowed()) { + return ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED; } notification = record->notification; // delete or delete all, call the function @@ -1163,10 +1157,10 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationListForDeleteAll( const std::string &key, sptr ¬ification) { for (auto record : notificationList_) { - if (!record->notification->IsRemoveAllowed()) { - continue; - } if (record->notification->GetKey() == key) { + if (!record->notification->IsRemoveAllowed()) { + return ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED; + } if (record->request->IsUnremovable()) { return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; } @@ -1509,14 +1503,13 @@ ErrCode AdvancedNotificationService::PublishContinuousTaskNotification(const spt if (result != ERR_OK) { return result; } - + request->SetUnremovable(true); std::shared_ptr record = std::make_shared(); record->request = request; record->bundleOption = bundleOption; record->notification = new Notification(request); if (record->notification != nullptr) { record->notification->SetSourceType(NotificationConstant::SourceType::TYPE_CONTINUOUS); - record->notification->SetRemoveAllowed(false); } handler_->PostSyncTask(std::bind([&]() { @@ -1969,8 +1962,8 @@ ErrCode AdvancedNotificationService::RemoveNotification( (record->deviceId.empty()) && #endif (record->notification->GetId() == notificationId) && (record->notification->GetLabel() == label)) { - if (record->request->IsUnremovable()) { - result = ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; + if (!record->notification->IsRemoveAllowed()) { + result = ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED; break; } #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED @@ -2152,6 +2145,9 @@ ErrCode AdvancedNotificationService::RemoveGroupByBundle( handler_->PostSyncTask(std::bind([&]() { std::vector> removeList; for (auto record : notificationList_) { + if (!record->notification->IsRemoveAllowed()) { + continue; + } if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && (record->bundleOption->GetUid() == bundle->GetUid()) && !record->request->IsUnremovable() && #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED -- Gitee