diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 9dbb6e96b6e9d895fe9c0cc1671e27faef0cd95b..90ce7593486c13fca27bddeca10d05d167fa7a98 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -2645,10 +2645,10 @@ std::string NotificationRequest::GenerateUniqueKey() std::stringstream stream; if (IsAgentNotification()) { - stream << ownerUserId_ << keySpliter << ownerBundleName_ << keySpliter << + stream << ownerUid_ << keySpliter << ownerBundleName_ << keySpliter << ownerUserId_ << keySpliter << typeFlag << keySpliter << appMessageId_; } else { - stream << creatorUserId_ << keySpliter << creatorBundleName_ << keySpliter << + stream << creatorUid_ << keySpliter << creatorBundleName_ << keySpliter << creatorUserId_ << keySpliter << typeFlag << keySpliter << appMessageId_; } return stream.str(); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index f4850b9d4c3b68feb1a085ac0f45dbd67a18b7c0..c798012bf9fa89f9d9587b973c4dfb9f0b9390d0 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -85,6 +85,7 @@ ErrCode AnsNotification::AddNotificationSlots(const std::vector proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -95,6 +96,7 @@ ErrCode AnsNotification::RemoveNotificationSlot(const NotificationConstant::Slot ErrCode AnsNotification::RemoveAllSlots() { + ANS_LOGI("enter RemoveAllSlots"); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -179,14 +181,14 @@ ErrCode AnsNotification::SetNotificationSlotFlagsAsBundle(const NotificationBund ErrCode AnsNotification::PublishNotification(const NotificationRequest &request) { - ANS_LOGD("enter"); + ANS_LOGI("enter PublishNotification"); return PublishNotification(std::string(), request); } ErrCode AnsNotification::PublishNotification(const std::string &label, const NotificationRequest &request) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - ANS_LOGD("enter"); + ANS_LOGI("enter PublishNotification"); if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) { ANS_LOGE("Refuse to publish the notification without valid content"); @@ -242,6 +244,7 @@ ErrCode AnsNotification::CancelNotification(int32_t notificationId) ErrCode AnsNotification::CancelNotification(const std::string &label, int32_t notificationId) { + ANS_LOGI("enter CancelNotification,notificationId:%{public}d", notificationId); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); sptr proxy = GetAnsManagerProxy(); if (!proxy) { @@ -268,6 +271,7 @@ ErrCode AnsNotification::CancelAllNotifications() ErrCode AnsNotification::CancelAsBundle( int32_t notificationId, const std::string &representativeBundle, int32_t userId) { + ANS_LOGI("enter CancelAsBundle,notificationId:%{public}d", notificationId); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -279,6 +283,7 @@ ErrCode AnsNotification::CancelAsBundle( ErrCode AnsNotification::CancelAsBundle( const NotificationBundleOption &bundleOption, int32_t notificationId) { + ANS_LOGI("enter CancelAsBundle,notificationId:%{public}d", notificationId); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -347,6 +352,7 @@ ErrCode AnsNotification::CanPublishNotificationAsBundle(const std::string &repre ErrCode AnsNotification::PublishNotificationAsBundle( const std::string &representativeBundle, const NotificationRequest &request) { + ANS_LOGI("enter PublishNotificationAsBundle"); if (representativeBundle.empty()) { ANS_LOGE("Refuse to publish the notification whit invalid representativeBundle"); return ERR_ANS_INVALID_PARAM; @@ -626,6 +632,8 @@ ErrCode AnsNotification::TriggerLocalLiveView(const NotificationBundleOption &bu ErrCode AnsNotification::RemoveNotification(const std::string &key, int32_t removeReason) { + ANS_LOGI("enter RemoveNotification,key:%{public}s,removeReason:%{public}d", + key.c_str(), removeReason); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (key.empty()) { ANS_LOGW("Input key is empty."); @@ -643,6 +651,8 @@ ErrCode AnsNotification::RemoveNotification(const std::string &key, int32_t remo ErrCode AnsNotification::RemoveNotification(const NotificationBundleOption &bundleOption, const int32_t notificationId, const std::string &label, int32_t removeReason) { + ANS_LOGI("enter RemoveNotification,bundle:%{public}s,Id:%{public}d,reason:%{public}d", + bundleOption.GetBundleName().c_str(), notificationId, removeReason); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (bundleOption.GetBundleName().empty()) { ANS_LOGE("Invalid bundle name."); @@ -661,6 +671,7 @@ ErrCode AnsNotification::RemoveNotification(const NotificationBundleOption &bund ErrCode AnsNotification::RemoveAllNotifications(const NotificationBundleOption &bundleOption) { + ANS_LOGI("enter RemoveAllNotifications,bundleName:%{public}s", bundleOption.GetBundleName().c_str()); if (bundleOption.GetBundleName().empty()) { ANS_LOGE("Invalid bundle name."); return ERR_ANS_INVALID_PARAM; @@ -678,6 +689,7 @@ ErrCode AnsNotification::RemoveAllNotifications(const NotificationBundleOption & ErrCode AnsNotification::RemoveNotifications(const std::vector hashcodes, int32_t removeReason) { + ANS_LOGI("enter RemoveNotifications,removeReason:%{public}d", removeReason); if (hashcodes.empty()) { ANS_LOGE("Hashcodes is empty"); return ERR_ANS_INVALID_PARAM; @@ -694,6 +706,7 @@ ErrCode AnsNotification::RemoveNotifications(const std::vector hash ErrCode AnsNotification::RemoveNotificationsByBundle(const NotificationBundleOption &bundleOption) { + ANS_LOGI("enter RemoveNotificationsByBundle,bundleName:%{public}s", bundleOption.GetBundleName().c_str()); if (bundleOption.GetBundleName().empty()) { ANS_LOGE("Invalid bundle name."); return ERR_ANS_INVALID_PARAM; @@ -711,6 +724,7 @@ ErrCode AnsNotification::RemoveNotificationsByBundle(const NotificationBundleOpt ErrCode AnsNotification::RemoveNotifications() { + ANS_LOGI("enter RemoveNotifications"); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -921,6 +935,7 @@ ErrCode AnsNotification::GetShowBadgeEnabled(bool &enabled) ErrCode AnsNotification::CancelGroup(const std::string &groupName) { + ANS_LOGI("enter CancelGroup,groupName:%{public}s", groupName.c_str()); if (groupName.empty()) { ANS_LOGE("Invalid group name."); return ERR_ANS_INVALID_PARAM; @@ -938,6 +953,7 @@ ErrCode AnsNotification::CancelGroup(const std::string &groupName) ErrCode AnsNotification::RemoveGroupByBundle( const NotificationBundleOption &bundleOption, const std::string &groupName) { + ANS_LOGI("enter RemoveGroupByBundle,bundleName:%{public}s", bundleOption.GetBundleName().c_str()); if (bundleOption.GetBundleName().empty() || groupName.empty()) { ANS_LOGE("Invalid parameter."); return ERR_ANS_INVALID_PARAM; @@ -1011,6 +1027,7 @@ ErrCode AnsNotification::AddDoNotDisturbProfiles(const std::vector> &profiles) { + ANS_LOGI("enter RemoveDoNotDisturbProfiles"); if (profiles.empty()) { ANS_LOGW("The profiles is empty."); return ERR_ANS_INVALID_PARAM; @@ -1047,6 +1064,7 @@ ErrCode AnsNotification::IsNeedSilentInDoNotDisturbMode(const std::string &phone ErrCode AnsNotification::PublishContinuousTaskNotification(const NotificationRequest &request) { + ANS_LOGI("enter PublishContinuousTaskNotification"); if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) { ANS_LOGE("Refuse to publish the notification without valid content"); return ERR_ANS_INVALID_PARAM; @@ -1090,6 +1108,7 @@ ErrCode AnsNotification::PublishContinuousTaskNotification(const NotificationReq ErrCode AnsNotification::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) { + ANS_LOGI("enter CancelContinuousTaskNotification,notificationId:%{public}d", notificationId); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -1194,6 +1213,7 @@ void AnsNotification::Reconnect() ErrCode AnsNotification::PublishReminder(ReminderRequest &reminder) { + ANS_LOGI("enter PublishReminder"); sptr tarReminder = nullptr; switch (reminder.GetReminderType()) { case (ReminderRequest::ReminderType::TIMER): { @@ -1231,6 +1251,7 @@ ErrCode AnsNotification::PublishReminder(ReminderRequest &reminder) ErrCode AnsNotification::CancelReminder(const int32_t reminderId) { + ANS_LOGI("enter CancelReminder"); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -1241,6 +1262,7 @@ ErrCode AnsNotification::CancelReminder(const int32_t reminderId) ErrCode AnsNotification::CancelAllReminders() { + ANS_LOGI("enter CancelAllReminders"); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -1473,6 +1495,7 @@ ErrCode AnsNotification::SetNotificationsEnabledForAllBundles(const int32_t &use ErrCode AnsNotification::RemoveNotifications(const int32_t &userId) { + ANS_LOGI("enter RemoveNotifications"); if (userId <= SUBSCRIBE_USER_INIT) { ANS_LOGE("Input userId is invalid."); return ERR_ANS_INVALID_PARAM; @@ -1634,6 +1657,7 @@ ErrCode AnsNotification::GetSyncNotificationEnabledWithoutApp(const int32_t user ErrCode AnsNotification::SetBadgeNumber(int32_t badgeNumber) { + ANS_LOGI("enter SetBadgeNumber"); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("SetBadgeNumber fail."); @@ -1645,6 +1669,7 @@ ErrCode AnsNotification::SetBadgeNumber(int32_t badgeNumber) ErrCode AnsNotification::SetBadgeNumberByBundle(const NotificationBundleOption &bundleOption, int32_t badgeNumber) { + ANS_LOGI("enter SetBadgeNumberByBundle"); if (bundleOption.GetBundleName().empty()) { ANS_LOGE("Invalid bundle name."); return ERR_ANS_INVALID_PARAM; @@ -1764,6 +1789,8 @@ ErrCode AnsNotification::SetSmartReminderEnabled(const std::string &deviceType, ErrCode AnsNotification::CancelAsBundleWithAgent(const NotificationBundleOption &bundleOption, const int32_t id) { + ANS_LOGI("enter CancelAsBundleWithAgent,bundleName:%{public}s,id:%{public}d", + bundleOption.GetBundleName().c_str(), id); sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("GetAnsManagerProxy fail."); diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 46784ae24630065d1bf1667badcae2c2995f8fc7..4e3dacbe3ba696788fadc5125d80b4d7bd3682a4 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1340,6 +1340,7 @@ private: ErrCode DuplicateMsgControl(const sptr &request); void RemoveExpiredUniqueKey(); bool IsDuplicateMsg(const std::string &uniqueKey); + void DeleteDuplicateMsgs(const sptr &bundleOption); ErrCode PublishRemoveDuplicateEvent(const std::shared_ptr &record); ErrCode UpdateSlotAuthInfo(const std::shared_ptr &record); std::vector GetBundlesOfActiveUser(); diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 50404f2a7a359f831d649cae7c7f58b6913bc320..1042b75ea74e4d705b85045698798f95c39f32b6 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -2448,6 +2448,25 @@ ErrCode AdvancedNotificationService::DuplicateMsgControl(const sptr &bundleOption) +{ + if (bundleOption == nullptr) { + ANS_LOGE("bundleOption is nullptr"); + } + const char *keySpliter = "_"; + std::stringstream stream; + stream << bundleOption->GetUid() << keySpliter << bundleOption->GetBundleName() << keySpliter; + std::string uniqueKeyHead = stream.str(); + auto iter = uniqueKeyList_.begin(); + while (iter != uniqueKeyList_.end()) { + if ((*iter).second.find(uniqueKeyHead) == 0) { + iter = uniqueKeyList_.erase(iter); + } else { + ++iter; + } + } +} + void AdvancedNotificationService::RemoveExpiredUniqueKey() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index ee8e7740220b065d80678f309f82dcc2d2a8a7d2..2e0e2185a4c0abe352357d6fa9b27c457530c3bd 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -571,6 +571,7 @@ void AdvancedNotificationService::OnBundleRemoved(const sptrRemoveAnsBundleDbInfo(bundleOption); RemoveDoNotDisturbProfileTrustList(bundleOption); + DeleteDuplicateMsgs(bundleOption); })); NotificationPreferences::GetInstance()->RemoveEnabledDbByBundle(bundleOption); #ifdef ENABLE_ANS_EXT_WRAPPER