From 0a545d5eba7b3e4e58ca84b1ddd237995c71c482 Mon Sep 17 00:00:00 2001 From: z00454238 Date: Sat, 14 Jun 2025 11:48:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=89=B9=E6=AE=8A=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=9C=BA=E6=99=AF=E9=80=BB=E8=BE=91=20Signed-off-by:?= =?UTF-8?q?=20z00454238=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/ans/src/notification.cpp | 20 ----------- .../ans/src/notification_subscriber.cpp | 7 ---- .../ans/test/unittest/notification_test.cpp | 2 +- interfaces/inner_api/notification.h | 9 ----- .../include/notification_extension_wrapper.h | 7 ++-- services/ans/libans.map | 1 + .../ans/src/advanced_notification_service.cpp | 17 ++------- .../ans/src/enable_manager/enable_manager.cpp | 16 +++++---- .../src/notification_extension_wrapper.cpp | 23 +++++++----- .../notification_extension_wrapper_test.cpp | 35 ------------------- 10 files changed, 35 insertions(+), 102 deletions(-) diff --git a/frameworks/ans/src/notification.cpp b/frameworks/ans/src/notification.cpp index 4377d7d03..b59bc43f0 100644 --- a/frameworks/ans/src/notification.cpp +++ b/frameworks/ans/src/notification.cpp @@ -62,7 +62,6 @@ Notification::Notification(const Notification &other) updateTimerId_ = other.updateTimerId_; finishTimerId_ = other.finishTimerId_; archiveTimerId_ = other.archiveTimerId_; - isPrivileged_ = other.isPrivileged_; } Notification::~Notification() @@ -255,11 +254,6 @@ std::string Notification::GetInstanceKey() const return request_->GetAppInstanceKey(); } -bool Notification::GetPrivileged() const -{ - return isPrivileged_; -} - bool Notification::MarshallingBool(Parcel &parcel) const { if (!parcel.WriteBool(enableLight_)) { @@ -282,11 +276,6 @@ bool Notification::MarshallingBool(Parcel &parcel) const return false; } - if (!parcel.WriteBool(isPrivileged_)) { - ANS_LOGE("Can't write isPrivileged"); - return false; - } - return true; } @@ -419,9 +408,6 @@ void Notification::ReadFromParcelBool(Parcel &parcel) // Read isRemoveAllowed_ isRemoveAllowed_ = parcel.ReadBool(); - - // Read isPrivileged_ - isPrivileged_ = parcel.ReadBool(); } void Notification::ReadFromParcelString(Parcel &parcel) @@ -552,11 +538,6 @@ void Notification::SetRemoveAllowed(bool removeAllowed) isRemoveAllowed_ = removeAllowed; } -void Notification::SetPrivileged(const bool &isPrivileged) -{ - isPrivileged_ = isPrivileged; -} - void Notification::SetSourceType(NotificationConstant::SourceType sourceType) { sourceType_ = sourceType; @@ -584,7 +565,6 @@ std::string Notification::Dump() const ", updateTimer = " + std::to_string(updateTimerId_) + ", finishTimer = " + std::to_string(finishTimerId_) + ", archiveTimer = " + std::to_string(archiveTimerId_) + - ", isPrivileged = " + (isPrivileged_ ? "true" : "false") + " }"; } diff --git a/frameworks/ans/src/notification_subscriber.cpp b/frameworks/ans/src/notification_subscriber.cpp index f789cf1ec..911249298 100644 --- a/frameworks/ans/src/notification_subscriber.cpp +++ b/frameworks/ans/src/notification_subscriber.cpp @@ -51,13 +51,6 @@ bool NotificationSubscriber::ProcessSyncDecision( return false; } -#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER - if (notification->GetPrivileged()) { - ANS_LOGI("No need to consume cause privileged reqeuest.") - return true; - } -#endif - auto flagsMap = request->GetDeviceFlags(); if (flagsMap == nullptr || flagsMap->size() <= 0) { return true; diff --git a/frameworks/ans/test/unittest/notification_test.cpp b/frameworks/ans/test/unittest/notification_test.cpp index b870f4cff..26b4674bd 100644 --- a/frameworks/ans/test/unittest/notification_test.cpp +++ b/frameworks/ans/test/unittest/notification_test.cpp @@ -324,7 +324,7 @@ HWTEST_F(NotificationTest, Dump_00001, Function | SmallTest | Level1) "notificationBundleOption = null, agentBundle = null, creatorUserId = -1, ownerUserId = -1, " "receiverUserId = -1, updateDeadLine = 0, finishDeadLine = 0, sound = , distributed = 0: " "flag: 0, unifiedGroupInfo_ = null }, postTime = 0, " - "sound = nullptr, vibrationStyle = [], updateTimer = 0, finishTimer = 0, archiveTimer = 0, isPrivileged = false }"; + "sound = nullptr, vibrationStyle = [], updateTimer = 0, finishTimer = 0, archiveTimer = 0 }"; EXPECT_EQ(rrc->Dump(), ret); } diff --git a/interfaces/inner_api/notification.h b/interfaces/inner_api/notification.h index 2813b2607..6683a1785 100644 --- a/interfaces/inner_api/notification.h +++ b/interfaces/inner_api/notification.h @@ -323,13 +323,6 @@ public: */ void SetAutoDeletedTimer(uint64_t autoDeletedTimerId); - /** - * @brief Obtains the privileged. - * - * @param Returns the privileged of the notification. - */ - bool GetPrivileged() const; - private: Notification(); void SetEnableSound(const bool &enable); @@ -342,7 +335,6 @@ private: void SetVibrationStyle(const std::vector &style); void SetRemindType(const NotificationConstant::RemindType &reminType); void SetRemoveAllowed(bool removeAllowed); - void SetPrivileged(const bool &isPrivileged); void SetSourceType(NotificationConstant::SourceType sourceType); bool ReadFromParcel(Parcel &parcel); void ReadFromParcelBool(Parcel &parcel); @@ -377,7 +369,6 @@ private: std::shared_ptr sound_ {nullptr}; std::vector vibrationStyle_ {}; uint64_t autoDeletedTimerId_ {0}; - bool isPrivileged_ {false}; friend class AdvancedNotificationService; friend class NotificationSlotFilter; diff --git a/services/ans/include/notification_extension_wrapper.h b/services/ans/include/notification_extension_wrapper.h index b8d3cf1f7..ae2e9a2e0 100644 --- a/services/ans/include/notification_extension_wrapper.h +++ b/services/ans/include/notification_extension_wrapper.h @@ -52,6 +52,8 @@ public: const int32_t &userId); typedef bool (*SET_DIALOG_OPENSUCCESS_TIMEINTERVAL)(const sptr& bundleOption, const int32_t &userId); + typedef void (*HANDLE_PRIVILEGE_MESSAGE)(const sptr& bundleOption, + const sptr &request, bool isAgentController); #endif ErrCode SyncAdditionConfig(const std::string& key, const std::string& value); @@ -67,10 +69,11 @@ public: bool NotificationDialogControl(); #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER - bool ModifyReminderFlags(const sptr &request); bool GetPrivilegeDialogPopped(const sptr& bundleOption, const int32_t &userId); bool SetDialogOpenSuccessTimeStamp(const sptr& bundleOption, const int32_t &userId); bool SetDialogOpenSuccessTimeInterval(const sptr& bundleOption, const int32_t &userId); + void HandlePrivilegeMessage(const sptr& bundleOption, + const sptr &request, bool isAgentController); #endif private: @@ -90,10 +93,10 @@ private: bool isRegisterDataSettingObserver = false; #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER - MODIFY_REMINDER_FLAGS modifyReminderFlags_ = nullptr; GET_PRIVILEGE_DIALOG_POPPED getPrivilegeDialogPopped_ = nullptr; SET_DIALOG_OPENSUCCESS_TIMESTAMP setDialogOpenSuccessTimeStamp_ = nullptr; SET_DIALOG_OPENSUCCESS_TIMEINTERVAL setDialogOpenSuccessTimeInterval_ = nullptr; + HANDLE_PRIVILEGE_MESSAGE handlePrivilegeMessage_ = nullptr; #endif }; diff --git a/services/ans/libans.map b/services/ans/libans.map index 7433ff4b7..b7d9cda6f 100644 --- a/services/ans/libans.map +++ b/services/ans/libans.map @@ -55,6 +55,7 @@ *GetAdditionalConfig*; *SetKvToDb*; *GetKvFromDb*; + *GetNotificationSlotFlagsForBundle*; local: *; }; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 3be89158f..1e402629a 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -670,6 +670,9 @@ ErrCode AdvancedNotificationService::PublishPreparedNotification(const sptrHandlePrivilegeMessage(bundleOption, request, isAgentController); +#endif HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_5, EventBranchId::BRANCH_1); #ifdef ENABLE_ANS_ADDITIONAL_CONTROL NotificationConstant::SlotType oldType = request->GetSlotType(); @@ -1075,20 +1078,6 @@ void AdvancedNotificationService::ChangeNotificationByControlFlags(const std::sh (notificationControlFlags & NotificationConstant::ReminderFlag::STATUSBAR_ICON_FLAG) != 0) { flags->SetStatusIconEnabled(false); } - -#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER - bool isPrivileged = EXTENTION_WRAPPER->ModifyReminderFlags(record->request); - if (isPrivileged) { - record->notification->SetPrivileged(true); - if (flags->IsSoundEnabled() == NotificationConstant::FlagStatus::OPEN) { - record->notification->SetEnableSound(true); - record->notification->SetSound(DEFAULT_NOTIFICATION_SOUND); - } - if (flags->IsVibrationEnabled() == NotificationConstant::FlagStatus::OPEN) { - record->notification->SetEnableVibration(true); - } - } -#endif } ErrCode AdvancedNotificationService::CheckPublishPreparedNotification( diff --git a/services/ans/src/enable_manager/enable_manager.cpp b/services/ans/src/enable_manager/enable_manager.cpp index 6023b6938..16d71a698 100644 --- a/services/ans/src/enable_manager/enable_manager.cpp +++ b/services/ans/src/enable_manager/enable_manager.cpp @@ -143,16 +143,18 @@ ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std:: int32_t userId = -1; OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); if (!EXTENTION_WRAPPER->GetPrivilegeDialogPopped(bundleOption, userId)) { -#endif ANS_LOGE("GetPrivilegeDialogPopped false."); - message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has popped"); + message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has no permission popped"); NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; -#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER } else { ANS_LOGI("duplicated popped."); message.Append(" duplicated popped."); } +#else + message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has popped"); + NotificationAnalyticsUtil::ReportModifyEvent(message); + return ERR_ANS_NOT_ALLOWED; #endif } if (!EXTENTION_WRAPPER->NotificationDialogControl()) { @@ -346,16 +348,18 @@ ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( int32_t userId = -1; OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); if (!EXTENTION_WRAPPER->GetPrivilegeDialogPopped(bundleOption, userId)) { -#endif ANS_LOGE("GetPrivilegeDialogPopped false."); - message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Haspopped true"); + message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has no permission popped"); NotificationAnalyticsUtil::ReportModifyEvent(message); return ERR_ANS_NOT_ALLOWED; -#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER } else { ANS_LOGI("duplicated popped."); message.Append(" duplicated popped."); } +#else + message.ErrorCode(ERR_ANS_NOT_ALLOWED).Append(" Has popped"); + NotificationAnalyticsUtil::ReportModifyEvent(message); + return ERR_ANS_NOT_ALLOWED; #endif } if (!EXTENTION_WRAPPER->NotificationDialogControl()) { diff --git a/services/ans/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index c8405b6e1..4e0028176 100644 --- a/services/ans/src/notification_extension_wrapper.cpp +++ b/services/ans/src/notification_extension_wrapper.cpp @@ -68,6 +68,12 @@ SYMBOL_EXPORT int32_t GetKvFromDb(const std::string &key, std::string &value, co { return NotificationPreferences::GetInstance()->GetKvFromDb(key, value, userId, retCode); } + +SYMBOL_EXPORT ErrCode GetNotificationSlotFlagsForBundle(const sptr &bundleOption, + uint32_t &slotFlags) +{ + return NotificationPreferences::GetInstance()->GetNotificationSlotFlagsForBundle(bundleOption, slotFlags); +} #endif #ifdef __cplusplus @@ -102,9 +108,9 @@ void ExtensionWrapper::InitExtentionWrapper() } #endif #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER - modifyReminderFlags_ = (MODIFY_REMINDER_FLAGS)dlsym(extensionWrapperHandle_, "ModifyReminderFlags"); - if (modifyReminderFlags_ == nullptr) { - ANS_LOGE("extension wrapper modifyReminderFlags symbol failed, error: %{public}s", dlerror()); + handlePrivilegeMessage_ = (HANDLE_PRIVILEGE_MESSAGE)dlsym(extensionWrapperHandle_, "HandlePrivilegeMessage"); + if (handlePrivilegeMessage_ == nullptr) { + ANS_LOGE("extension wrapper handlePrivilegeMessage_ symbol failed, error: %{public}s", dlerror()); return; } getPrivilegeDialogPopped_ = (GET_PRIVILEGE_DIALOG_POPPED)dlsym(extensionWrapperHandle_, "GetPrivilegeDialogPopped"); @@ -228,13 +234,14 @@ int32_t ExtensionWrapper::BannerControl(const std::string &bundleName) } #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER -bool ExtensionWrapper::ModifyReminderFlags(const sptr &request) +void ExtensionWrapper::HandlePrivilegeMessage(const sptr& bundleOption, + const sptr &request, bool isAgentController) { - if (modifyReminderFlags_ == nullptr) { - ANS_LOGE("ModifyReminderFlags wrapper symbol failed"); - return false; + if (handlePrivilegeMessage_ == nullptr) { + ANS_LOGE("HandlePrivilegeMessage wrapper symbol failed"); + return; } - return modifyReminderFlags_(request); + return handlePrivilegeMessage_(bundleOption, request, isAgentController); } bool ExtensionWrapper::GetPrivilegeDialogPopped(const sptr& bundleOption, diff --git a/services/ans/test/unittest/notification_extension_wrapper_test.cpp b/services/ans/test/unittest/notification_extension_wrapper_test.cpp index 9e83db979..1280c0110 100644 --- a/services/ans/test/unittest/notification_extension_wrapper_test.cpp +++ b/services/ans/test/unittest/notification_extension_wrapper_test.cpp @@ -76,11 +76,6 @@ HWTEST_F(NotificationExtensionWrapperTest, InitExtentionWrapper_Test, TestSize.L EXPECT_NE(extensionWrapper.bannerControl_, nullptr); #endif - // 验证modifyReminderFlags_是否被正确初始化 -#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER - EXPECT_NE(extensionWrapper.modifyReminderFlags_, nullptr); -#endif - // 验证initSummary_是否被正确初始化 #ifdef ENABLE_ANS_AGGREGATION EXPECT_NE(extensionWrapper.initSummary_, nullptr); @@ -261,36 +256,6 @@ HWTEST_F(NotificationExtensionWrapperTest, BannerControl_ValidBannerControl, Tes EXPECT_EQ(0, result); } -#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER -HWTEST_F(NotificationExtensionWrapperTest, ModifyReminderFlags_NullCase, TestSize.Level0) { - // Arrange - OHOS::Notification::ExtensionWrapper wrapper; - wrapper.modifyReminderFlags_ = nullptr; - auto request = new NotificationRequest(); - - // Act - bool result = wrapper.ModifyReminderFlags(request); - - // Assert - ASSERT_FALSE(result); -} - -HWTEST_F(NotificationExtensionWrapperTest, ModifyReminderFlags_SuccessCase, TestSize.Level0) { - // Arrange - OHOS::Notification::ExtensionWrapper wrapper; - bool (*mockFunc)(const sptr &) = [](const sptr &req) { - return true; - }; - wrapper.modifyReminderFlags_ = mockFunc; - auto request = new NotificationRequest(); - - // Act - bool result = wrapper.ModifyReminderFlags(request); - - // Assert - ASSERT_TRUE(result); -} -#endif HWTEST_F(NotificationExtensionWrapperTest, LocalControl_NullCase, TestSize.Level0) { // Arrange OHOS::Notification::ExtensionWrapper wrapper; -- Gitee