From 9fbc2c5643f1e3a6521ac6bb6cb6fac534424899 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Fri, 25 Apr 2025 16:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AA=81=E7=A0=B4=E5=85=8D=E6=89=93=E6=89=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/src/notification_request.cpp | 18 +++++++++++++++ .../ans/test/unittest/notification_test.cpp | 3 ++- interfaces/inner_api/notification_request.h | 5 +++++ .../advanced_notification_publish_service.cpp | 8 +++++-- ...nced_notification_publish_service_test.cpp | 22 +++++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index a7b01c4c9..c55954d59 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -814,6 +814,7 @@ std::string NotificationRequest::Dump() ", updateOnly = " + (updateOnly_ ? "true" : "false") + ", isForceDistributed = " + (forceDistributed_ ? "true" : "false") + ", isNotDistributed = " + (notDistributed_ ? "true" : "false") + + ", isDoNotDisturbByPassed = " + (isDoNotDisturbByPassed_ ? "true" : "false") + ", removalWantAgent = " + (removalWantAgent_ ? "not null" : "null") + ", maxScreenWantAgent = " + (maxScreenWantAgent_ ? "not null" : "null") + ", additionalParams = " + (additionalParams_ ? "not null" : "null") + @@ -1253,6 +1254,11 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteBool(isDoNotDisturbByPassed_)) { + ANS_LOGE("Failed to write flag notDistributed"); + return false; + } + // write objects which managed by std::shared_ptr bool valid {false}; @@ -1677,6 +1683,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) isRemoveAllowed_ = parcel.ReadBool(); forceDistributed_ = parcel.ReadBool(); notDistributed_ = parcel.ReadBool(); + isDoNotDisturbByPassed_ = parcel.ReadBool(); bool valid {false}; @@ -1980,6 +1987,16 @@ void NotificationRequest::SetIsSystemApp(bool isSystemApp) isSystemApp_ = isSystemApp; } +bool NotificationRequest::IsDoNotDisturbByPassed() const +{ + return isDoNotDisturbByPassed_; +} + +void NotificationRequest::SetIsDoNotDisturbByPassed(bool isDoNotDisturbByPassed) +{ + isDoNotDisturbByPassed_ = isDoNotDisturbByPassed; +} + void NotificationRequest::CopyBase(const NotificationRequest &other) { this->notificationId_ = other.notificationId_; @@ -2007,6 +2024,7 @@ void NotificationRequest::CopyBase(const NotificationRequest &other) this->forceDistributed_ = other.forceDistributed_; this->notDistributed_ = other.notDistributed_; this->isSystemApp_ = other.isSystemApp_; + this->isDoNotDisturbByPassed_ = other.isDoNotDisturbByPassed_; this->isCoverActionButtons_ = other.isCoverActionButtons_; this->isUpdateByOwnerAllowed_ = other.isUpdateByOwnerAllowed_; this->distributedCollaborate_ = other.distributedCollaborate_; diff --git a/frameworks/ans/test/unittest/notification_test.cpp b/frameworks/ans/test/unittest/notification_test.cpp index 17937fcd6..8356e6f16 100644 --- a/frameworks/ans/test/unittest/notification_test.cpp +++ b/frameworks/ans/test/unittest/notification_test.cpp @@ -314,7 +314,8 @@ HWTEST_F(NotificationTest, Dump_00001, Function | SmallTest | Level1) "isCountdown = false, inProgress = false, groupOverview = false, isRemoveAllowed = true, " "progressIndeterminate = false, unremovable = false, floatingIcon = false, onlyLocal = false, " "permitted = true, isAgent = false, updateOnly = false, isForceDistributed = false, " - "isNotDistributed = false, removalWantAgent = null, maxScreenWantAgent = null, " + "isNotDistributed = false, isDoNotDisturbByPassed = false, " + "removalWantAgent = null, maxScreenWantAgent = null, " "additionalParams = null, littleIcon = null, bigIcon = null, overlayIcon = null, " "notificationContent = null, notificationTemplate = null, actionButtons = empty, " "messageUsers = empty, userInputHistory = empty, distributedOptions = " diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index ef96db025..846aca362 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -1255,6 +1255,10 @@ public: void SetIsSystemApp(bool isSystemApp); + bool IsDoNotDisturbByPassed() const; + + void SetIsDoNotDisturbByPassed(bool isDoNotDisturbByPassed); + bool IsCommonLiveView() const; bool IsSystemLiveView() const; @@ -1599,6 +1603,7 @@ private: bool forceDistributed_ {false}; bool notDistributed_ {false}; bool isSystemApp_ {false}; + bool isDoNotDisturbByPassed_ {false}; std::shared_ptr wantAgent_ {}; std::shared_ptr removalWantAgent_ {}; diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index c18ee2146..f34be910d 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -363,7 +363,9 @@ ErrCode AdvancedNotificationService::PublishNotificationForIndirectProxy(const s return; } - CheckDoNotDisturbProfile(record); + if (!request->IsDoNotDisturbByPassed()) { + CheckDoNotDisturbProfile(record); + } ChangeNotificationByControlFlags(record, isAgentController); if (IsSaCreateSystemLiveViewAsBundle(record, ipcUid) && (std::static_pointer_cast( @@ -2581,7 +2583,9 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrIsDoNotDisturbByPassed()) { + CheckDoNotDisturbProfile(record); + } ChangeNotificationByControlFlags(record, isAgentController); if (IsSaCreateSystemLiveViewAsBundle(record, ipcUid) && (std::static_pointer_cast( diff --git a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp index f717f0b2f..85d191fb7 100644 --- a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp @@ -277,6 +277,28 @@ HWTEST_F(AnsPublishServiceTest, Publish_00006, Function | SmallTest | Level1) ASSERT_EQ(ret, (int)ERROR_USER_NOT_EXIST); } +/** + * @tc.name: Publish_00007 + * @tc.desc: Test Publish + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AnsPublishServiceTest, Publish_00007, Function | SmallTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(); + std::string label = ""; + request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + request->SetOwnerUid(1); + request->SetIsAgentNotification(true); + request->SetIsDoNotDisturbByPassed(true); + MockIsOsAccountExists(true); + + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); + MockIsSystemApp(false); + auto ret = advancedNotificationService_->Publish(label, request); + ASSERT_EQ(ret, (int)ERR_OK); +} + /** * @tc.name: DeleteByBundle_00001 * @tc.desc: Test DeleteByBundle -- Gitee