diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 5d831e96dcd02018847913340bec533bd98930d0..4804e594975f4929eeafe1e71894aa12f3ba599a 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -812,8 +812,9 @@ private: NotificationConstant::RemindType GetRemindType(); ErrCode DoDistributedPublish( const sptr bundleOption, const std::shared_ptr record); - ErrCode DoDistributedDelete(const std::string deviceId, const sptr notification); - std::string GetNotificationDeviceId(const std::string &key); + ErrCode DoDistributedDelete( + const std::string deviceId, const std::string bundleName, const sptr notification); + void GetDistributedInfo(const std::string &key, std::string &deviceId, std::string &bundleName); bool CheckDistributedNotificationType(const sptr &request); void OnDistributedPublish( const std::string &deviceId, const std::string &bundleName, sptr &request); diff --git a/services/ans/include/notification_record.h b/services/ans/include/notification_record.h index d14c3d36f9f0c013aedea7b622e35ba9f7e9433b..f80c6c7033d0bdc49ba55d4154817fb446262689 100644 --- a/services/ans/include/notification_record.h +++ b/services/ans/include/notification_record.h @@ -34,6 +34,7 @@ struct NotificationRecord { sptr slot; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED std::string deviceId; + std::string bundleName; #endif // DISTRIBUTED_NOTIFICATION_SUPPORTED }; } // namespace Notification diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index c05880924bc0f887649547666cf6b7d500903cbf..b0165c39d1031b4a5fbf0c0c74d33516f5f8ab42 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -411,7 +411,7 @@ ErrCode AdvancedNotificationService::CancelPreparedNotification( sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete("", notification); + DoDistributedDelete("", "", notification); #endif } })); @@ -644,7 +644,9 @@ ErrCode AdvancedNotificationService::CancelAll() std::vector keys = GetNotificationKeys(bundleOption); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - std::string deviceId = GetNotificationDeviceId(key); + std::string deviceId; + std::string bundleName; + GetDistributedInfo(key, deviceId, bundleName); #endif result = RemoveFromNotificationList(key, notification, true); if (result != ERR_OK) { @@ -657,7 +659,7 @@ ErrCode AdvancedNotificationService::CancelAll() sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(deviceId, notification); + DoDistributedDelete(deviceId, bundleName, notification); #endif } } @@ -983,7 +985,9 @@ ErrCode AdvancedNotificationService::Delete(const std::string &key) handler_->PostSyncTask(std::bind([&]() { sptr notification = nullptr; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - std::string deviceId = GetNotificationDeviceId(key); + std::string deviceId; + std::string bundleName; + GetDistributedInfo(key, deviceId, bundleName); #endif result = RemoveFromNotificationList(key, notification); if (result != ERR_OK) { @@ -996,7 +1000,7 @@ ErrCode AdvancedNotificationService::Delete(const std::string &key) sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(deviceId, notification); + DoDistributedDelete(deviceId, bundleName, notification); #endif } })); @@ -1026,7 +1030,9 @@ ErrCode AdvancedNotificationService::DeleteByBundle(const sptr keys = GetNotificationKeys(bundle); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - std::string deviceId = GetNotificationDeviceId(key); + std::string deviceId; + std::string bundleName; + GetDistributedInfo(key, deviceId, bundleName); #endif sptr notification = nullptr; @@ -1041,7 +1047,7 @@ ErrCode AdvancedNotificationService::DeleteByBundle(const sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(deviceId, notification); + DoDistributedDelete(deviceId, bundleName, notification); #endif } } @@ -1071,7 +1077,9 @@ ErrCode AdvancedNotificationService::DeleteAll() std::vector keys = GetNotificationKeys(nullptr); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - std::string deviceId = GetNotificationDeviceId(key); + std::string deviceId; + std::string bundleName; + GetDistributedInfo(key, deviceId, bundleName); #endif sptr notification = nullptr; @@ -1086,7 +1094,7 @@ ErrCode AdvancedNotificationService::DeleteAll() sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(deviceId, notification); + DoDistributedDelete(deviceId, bundleName, notification); #endif } } @@ -2240,7 +2248,7 @@ void AdvancedNotificationService::OnBundleRemoved(const sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete("", notification); + DoDistributedDelete("", "", notification); #endif } } @@ -2345,6 +2353,7 @@ ErrCode AdvancedNotificationService::RemoveNotification( #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED std::string deviceId; + std::string bundleName; #endif for (auto record : notificationList_) { if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && @@ -2359,6 +2368,7 @@ ErrCode AdvancedNotificationService::RemoveNotification( } #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED deviceId = record->deviceId; + bundleName = record->bundleName; #endif notification = record->notification; notificationRequest = record->request; @@ -2374,7 +2384,7 @@ ErrCode AdvancedNotificationService::RemoveNotification( sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(deviceId, notification); + DoDistributedDelete(deviceId, bundleName, notification); #endif } @@ -2428,7 +2438,7 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(record->deviceId, record->notification); + DoDistributedDelete(record->deviceId, record->bundleName, record->notification); #endif } @@ -2505,7 +2515,7 @@ ErrCode AdvancedNotificationService::CancelGroup(const std::string &groupName) sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(record->deviceId, record->notification); + DoDistributedDelete(record->deviceId, record->bundleName, record->notification); #endif } } @@ -2561,7 +2571,7 @@ ErrCode AdvancedNotificationService::RemoveGroupByBundle( sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(record->deviceId, record->notification); + DoDistributedDelete(record->deviceId, record->bundleName, record->notification); #endif } } @@ -2927,14 +2937,16 @@ NotificationConstant::RemindType AdvancedNotificationService::GetRemindType() } } -std::string AdvancedNotificationService::GetNotificationDeviceId(const std::string &key) +void AdvancedNotificationService::GetDistributedInfo( + const std::string &key, std::string &deviceId, std::string &bundleName) { for (auto record : notificationList_) { if (record->notification->GetKey() == key) { - return record->deviceId; + deviceId = record->deviceId; + bundleName = record->bundleName; + break; } } - return std::string(); } ErrCode AdvancedNotificationService::DoDistributedPublish( @@ -2970,7 +2982,7 @@ ErrCode AdvancedNotificationService::DoDistributedPublish( } ErrCode AdvancedNotificationService::DoDistributedDelete( - const std::string deviceId, const sptr notification) + const std::string deviceId, const std::string bundleName, const sptr notification) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (!notification->GetNotificationRequest().GetNotificationDistributedOptions().IsDistributed()) { @@ -2981,7 +2993,7 @@ ErrCode AdvancedNotificationService::DoDistributedDelete( notification->GetBundleName(), notification->GetLabel(), notification->GetId()); } else { return DistributedNotificationManager::GetInstance()->DeleteRemoteNotification( - deviceId, notification->GetBundleName(), notification->GetLabel(), notification->GetId()); + deviceId, bundleName, notification->GetLabel(), notification->GetId()); } return ERR_OK; @@ -3043,6 +3055,7 @@ void AdvancedNotificationService::OnDistributedPublish( record->notification = new Notification(deviceId, request); record->bundleOption = bundleOption; record->deviceId = deviceId; + record->bundleName = bundleName; SetNotificationRemindType(record->notification, false); ErrCode result = AssignValidNotificationSlot(record); @@ -3107,6 +3120,7 @@ void AdvancedNotificationService::OnDistributedUpdate( record->notification = new Notification(deviceId, request); record->bundleOption = bundleOption; record->deviceId = deviceId; + record->bundleName = bundleName; SetNotificationRemindType(record->notification, false); ErrCode result = AssignValidNotificationSlot(record); @@ -3163,8 +3177,8 @@ void AdvancedNotificationService::OnDistributedDelete( sptr notification = nullptr; for (auto record : notificationList_) { if ((record->deviceId == recordDeviceId) && - ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && - (FOUNDATION_BUNDLE_NAME == bundleOption->GetBundleName())) && + ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) || + (record->bundleName == bundleName)) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && (record->notification->GetLabel() == label) && (record->notification->GetId() == id)) { notification = record->notification; @@ -3327,7 +3341,9 @@ ErrCode AdvancedNotificationService::DeleteAllByUser(const int32_t &userId) std::vector keys = GetNotificationKeys(nullptr); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - std::string deviceId = GetNotificationDeviceId(key); + std::string deviceId; + std::string bundleName; + GetDistributedInfo(key, deviceId, bundleName); #endif sptr notification = nullptr; @@ -3342,7 +3358,7 @@ ErrCode AdvancedNotificationService::DeleteAllByUser(const int32_t &userId) sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(deviceId, notification); + DoDistributedDelete(deviceId, bundleName, notification); #endif } } @@ -3525,7 +3541,9 @@ void AdvancedNotificationService::OnBundleDataCleared(const sptr keys = GetNotificationKeys(bundleOption); for (auto key : keys) { #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - std::string deviceId = GetNotificationDeviceId(key); + std::string deviceId; + std::string bundleName; + GetDistributedInfo(key, deviceId, bundleName); #endif sptr notification = nullptr; @@ -3540,7 +3558,7 @@ void AdvancedNotificationService::OnBundleDataCleared(const sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DoDistributedDelete(deviceId, notification); + DoDistributedDelete(deviceId, bundleName, notification); #endif } }