diff --git a/frameworks/core/common/include/ans_const_define.h b/frameworks/core/common/include/ans_const_define.h index 7977b9b393e3578775e9cb9723c5d9c164b382fc..dad7159d648411b7723e587af060a6e37473f2b6 100644 --- a/frameworks/core/common/include/ans_const_define.h +++ b/frameworks/core/common/include/ans_const_define.h @@ -46,6 +46,7 @@ constexpr int32_t MAX_STATUS_VECTOR_NUM = 1000; constexpr uint32_t MAX_CANCELED_PARCELABLE_VECTOR_NUM = 200; constexpr int32_t DEFAULT_UID = 0; +constexpr int32_t DEFAULT_PID = 0; constexpr int64_t INVALID_PROFILE_ID = -1; constexpr int32_t SUBSCRIBE_USER_INIT = -1; constexpr int32_t SUBSCRIBE_USER_ALL = -2; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 7dc063413c2ff7e3de4b1fc7db53abf7bc5a96eb..b0dc400dca254ff0dd8ea069d1973b6777a15e70 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1270,12 +1270,13 @@ public: /** * @brief Remove Local Live Notifications */ - ErrCode RemoveSystemLiveViewNotifications(const std::string& bundleName, const int32_t uid); + ErrCode RemoveSystemLiveViewNotifications(const std::string& bundleName, + const int32_t uid, const int32_t pid); /** * @brief Remove Local Live Notifications created by sa. */ - ErrCode RemoveSystemLiveViewNotificationsOfSa(int32_t uid); + ErrCode RemoveSystemLiveViewNotificationsOfSa(int32_t uid, int32_t pid); /** * @brief Set the notification flags by soltType. diff --git a/services/ans/include/live_publish_process.h b/services/ans/include/live_publish_process.h index 43c70effbd5608d48df942910493a88364193d75..69de06bf60d87711bec471243ca4fbdab1565fe8 100644 --- a/services/ans/include/live_publish_process.h +++ b/services/ans/include/live_publish_process.h @@ -27,16 +27,28 @@ public: static std::shared_ptr GetInstance(); AnsStatus PublishPreWork(const sptr &request, bool isUpdateByOwnerAllowed) override; ErrCode PublishNotificationByApp(const sptr &request) override; - void EraseLiveViewSubsciber(int32_t uid); - void AddLiveViewSubscriber(int32_t uid); + void EraseLiveViewSubsciber(int32_t uid, int32_t pid); + void AddLiveViewSubscriber(int32_t uid, int32_t pid); bool CheckLocalLiveViewSubscribed( const sptr &request, bool isUpdateByOwnerAllowed, int32_t uid); private: + struct UIDPID { + int uid_; + int pid_; + + bool operator<(const UIDPID& other) const + { + if (uid_ != other.uid_) { + return uid_ < other.uid_; + } + return pid_ < other.pid_; + } + }; bool CheckLocalLiveViewAllowed(const sptr &request, bool isUpdateByOwnerAllowed); bool GetLiveViewSubscribeState(int32_t uid); - std::set localLiveViewSubscribedList_; + std::set localLiveViewSubscribedList_; ffrt::mutex liveViewMutext_; static std::shared_ptr instance_; static ffrt::mutex instanceMutex_; diff --git a/services/ans/include/notification_local_live_view_subscriber_manager.h b/services/ans/include/notification_local_live_view_subscriber_manager.h index 87d0b463546b1a98957ab31ec4767fa98b31021a..af97127b06da16f13b7fcd71665e4a51146c6549 100644 --- a/services/ans/include/notification_local_live_view_subscriber_manager.h +++ b/services/ans/include/notification_local_live_view_subscriber_manager.h @@ -74,7 +74,7 @@ public: * * @param object Indicates the death object. */ - void OnRemoteDied(const wptr &object); + void OnRemoteDied(const wptr &object, std::int32_t pid); /** * @brief Reset ffrt queue @@ -92,7 +92,7 @@ private: const sptr &bundleOption); ErrCode AddSubscriberInner(const sptr &subscriber, - const sptr &bundleOption); + const sptr &bundleOption, int32_t pid); ErrCode RemoveSubscriberInner(const sptr &subscriber, const sptr &subscribeInfo); diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index 9306d9218cbe99fe51608011387c8a645669a40a..f9aa03b6d8ab21f67cabeebb159ffdf0cc4afd69 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -16,6 +16,7 @@ #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_SUBSCRIBER_MANAGER_H #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_SUBSCRIBER_MANAGER_H +#include #include #include #include @@ -115,7 +116,7 @@ public: * * @param object Indicates the death object. */ - void OnRemoteDied(const wptr &object); + void OnRemoteDied(const wptr &object, int32_t pid); /** * @brief Set badge number. @@ -169,7 +170,7 @@ private: void RemoveRecordInfo( std::shared_ptr &record, const sptr &subscribeInfo); ErrCode AddSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo); + const sptr &subscriber, const sptr &subscribeInfo, int32_t &pid); ErrCode RemoveSubscriberInner( const sptr &subscriber, const sptr &subscribeInfo); diff --git a/services/ans/include/remote_death_recipient.h b/services/ans/include/remote_death_recipient.h index da1b9563b8f8da8d8eb3d8bb7884e8588f370162..5b0d6e6eabe9ad9f072192f19b0a27753c68c01b 100644 --- a/services/ans/include/remote_death_recipient.h +++ b/services/ans/include/remote_death_recipient.h @@ -19,6 +19,7 @@ #include "iremote_object.h" #include "refbase.h" +#include "ans_const_define.h" namespace OHOS { namespace Notification { @@ -28,9 +29,11 @@ public: * The constructor. * @param callback Indicates the callback. */ - explicit RemoteDeathRecipient(std::function &)> callback) + explicit RemoteDeathRecipient(std::function &, int32_t)> callback, + int32_t pid) { callback_ = callback; + pid_ = pid; } /** @@ -48,12 +51,13 @@ public: void OnRemoteDied(const wptr &object) { if (callback_ != nullptr) { - callback_(object); + callback_(object, pid_); } } private: - std::function &)> callback_; + std::function &, int32_t)> callback_; + std::int32_t pid_ = DEFAULT_PID; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_publish/live_publish_process.cpp b/services/ans/src/advanced_notification_publish/live_publish_process.cpp index cdc9608b93ef996d74b1b21927009d1525475a87..05593c2ef0ea237b6d2413b772db5439b305ad70 100644 --- a/services/ans/src/advanced_notification_publish/live_publish_process.cpp +++ b/services/ans/src/advanced_notification_publish/live_publish_process.cpp @@ -125,24 +125,26 @@ bool LivePublishProcess::CheckLocalLiveViewAllowed( return true; } -void LivePublishProcess::AddLiveViewSubscriber(int32_t uid) +void LivePublishProcess::AddLiveViewSubscriber(int32_t uid, int32_t pid) { - localLiveViewSubscribedList_.emplace(uid); + localLiveViewSubscribedList_.insert({uid, pid}); } -void LivePublishProcess::EraseLiveViewSubsciber(int32_t uid) +void LivePublishProcess::EraseLiveViewSubsciber(int32_t uid, int32_t pid) { std::lock_guard lock(liveViewMutext_); - localLiveViewSubscribedList_.erase(uid); + localLiveViewSubscribedList_.erase({uid, pid}); } bool LivePublishProcess::GetLiveViewSubscribeState(int32_t uid) { std::lock_guard lock(liveViewMutext_); - if (localLiveViewSubscribedList_.find(uid) == localLiveViewSubscribedList_.end()) { - return false; + for (const auto& entry : localLiveViewSubscribedList_) { + if (entry.uid_ == uid) { + return true; + } } - return true; + return false; } } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_subscriber_service.cpp b/services/ans/src/advanced_notification_subscriber_service.cpp index c51956e3946cdca1b7d27721780ee104374b16ea..d79bb0b59d44b24e0c5023ae6a57248a9a8cdc92 100644 --- a/services/ans/src/advanced_notification_subscriber_service.cpp +++ b/services/ans/src/advanced_notification_subscriber_service.cpp @@ -129,8 +129,9 @@ ErrCode AdvancedNotificationService::SubscribeSelf(const sptr &s if (errCode == ERR_OK) { int32_t callingUid = IPCSkeleton::GetCallingUid(); + int32_t callingPid = IPCSkeleton::GetCallingPid(); ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { - LivePublishProcess::GetInstance()->AddLiveViewSubscriber(callingUid); + LivePublishProcess::GetInstance()->AddLiveViewSubscriber(callingUid, callingPid); })); notificationSvrQueue_->wait(handler); } diff --git a/services/ans/src/bundle_manager_helper.cpp b/services/ans/src/bundle_manager_helper.cpp index 02b697c7356e67357ac8c36a8da5a662c646ee99..3eca436ec31c32c99814d4e9dcd377ac2b9aea54 100644 --- a/services/ans/src/bundle_manager_helper.cpp +++ b/services/ans/src/bundle_manager_helper.cpp @@ -30,7 +30,7 @@ namespace Notification { BundleManagerHelper::BundleManagerHelper() { deathRecipient_ = new (std::nothrow) - RemoteDeathRecipient(std::bind(&BundleManagerHelper::OnRemoteDied, this, std::placeholders::_1)); + RemoteDeathRecipient(std::bind(&BundleManagerHelper::OnRemoteDied, this, std::placeholders::_1), 0); if (deathRecipient_ == nullptr) { ANS_LOGE("Failed to create RemoteDeathRecipient instance"); } diff --git a/services/ans/src/notification_local_live_view_subscriber_manager.cpp b/services/ans/src/notification_local_live_view_subscriber_manager.cpp index 3e440491c3e774730e40fd94d7c6fdaf17e69878..303770ccf35cee50d33d3a3e301e4f5d03aabbc5 100644 --- a/services/ans/src/notification_local_live_view_subscriber_manager.cpp +++ b/services/ans/src/notification_local_live_view_subscriber_manager.cpp @@ -43,12 +43,6 @@ NotificationLocalLiveViewSubscriberManager::NotificationLocalLiveViewSubscriberM { ANS_LOGD("called"); notificationButtonQueue_ = std::make_shared("NotificationLocalLiveViewMgr"); - recipient_ = new (std::nothrow) - RemoteDeathRecipient(std::bind(&NotificationLocalLiveViewSubscriberManager::OnRemoteDied, - this, std::placeholders::_1)); - if (recipient_ == nullptr) { - ANS_LOGE("null recipient"); - } } NotificationLocalLiveViewSubscriberManager::~NotificationLocalLiveViewSubscriberManager() @@ -92,10 +86,11 @@ ErrCode NotificationLocalLiveViewSubscriberManager::AddLocalLiveViewSubscriber( return result; } ANS_LOGD("start"); + int32_t pid = IPCSkeleton::GetCallingPid(); ffrt::task_handle handler = - notificationButtonQueue_->submit_h(std::bind([this, &subscriber, &bundleOption, &result]() { + notificationButtonQueue_->submit_h(std::bind([this, &subscriber, &bundleOption, &pid, &result]() { ANS_LOGD("called"); - result = this->AddSubscriberInner(subscriber, bundleOption); + result = this->AddSubscriberInner(subscriber, bundleOption, pid); })); notificationButtonQueue_->wait(handler); ANS_LOGD("end"); @@ -144,20 +139,20 @@ void NotificationLocalLiveViewSubscriberManager::NotifyTriggerResponse(const spt ANS_LOGD("end"); } -void NotificationLocalLiveViewSubscriberManager::OnRemoteDied(const wptr &object) +void NotificationLocalLiveViewSubscriberManager::OnRemoteDied(const wptr &object, const std::int32_t pid) { ANS_LOGD("called"); if (notificationButtonQueue_ == nullptr) { ANS_LOGE("null queue"); return; } - ffrt::task_handle handler = notificationButtonQueue_->submit_h(std::bind([this, object]() { + ffrt::task_handle handler = notificationButtonQueue_->submit_h(std::bind([this, object, pid]() { ANS_LOGD("called"); std::shared_ptr record = FindSubscriberRecord(object); if (record != nullptr) { ANS_LOGI("removed. uid = %{public}d", record->userId); AdvancedNotificationService::GetInstance()->RemoveSystemLiveViewNotifications( - record->bundleName, record->userId); + record->bundleName, record->userId, pid); buttonRecordList_.remove(record); } })); @@ -210,7 +205,8 @@ std::shared_ptr &subscriber, const sptr &bundleOption) + const sptr &subscriber, + const sptr &bundleOption, int32_t pid) { NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); std::shared_ptr record = FindSubscriberRecord(subscriber); @@ -221,11 +217,17 @@ ErrCode NotificationLocalLiveViewSubscriberManager::AddSubscriberInner( return ERR_ANS_NO_MEMORY; } buttonRecordList_.push_back(record); - - record->subscriber->AsObject()->AddDeathRecipient(recipient_); + sptr recipient = new (std::nothrow) + RemoteDeathRecipient(std::bind(&NotificationLocalLiveViewSubscriberManager::OnRemoteDied, + this, std::placeholders::_1, std::placeholders::_2), pid); + if (recipient == nullptr) { + ANS_LOGE("null recipient"); + return ERR_ANS_NO_MEMORY; + } + record->subscriber->AsObject()->AddDeathRecipient(recipient); record->subscriber->OnConnected(); - ANS_LOGI("subscriber is connected."); + ANS_LOGI("%{public}d_%{public}d subscriber is connected.", bundleOption->GetUid(), pid); } return ERR_OK; diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index e908a02dc819ac6720f39ed1f466785360f75852..32cd6ea8b33fb4baaad05f30b422b7db8ac47d8d 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -16,6 +16,7 @@ #include "notification_subscriber_manager.h" #include +#include #include #include @@ -62,11 +63,6 @@ NotificationSubscriberManager::NotificationSubscriberManager() { ANS_LOGD("called"); notificationSubQueue_ = std::make_shared("NotificationSubscriberMgr"); - recipient_ = new (std::nothrow) - RemoteDeathRecipient(std::bind(&NotificationSubscriberManager::OnRemoteDied, this, std::placeholders::_1)); - if (recipient_ == nullptr) { - ANS_LOGE("Failed to create RemoteDeathRecipient instance"); - } } NotificationSubscriberManager::~NotificationSubscriberManager() @@ -120,9 +116,10 @@ ErrCode NotificationSubscriberManager::AddSubscriber( ANS_LOGE("null queue"); return result; } - - ffrt::task_handle handler = notificationSubQueue_->submit_h(std::bind([this, &subscriber, &subInfo, &result]() { - result = this->AddSubscriberInner(subscriber, subInfo); + int32_t pid = IPCSkeleton::GetCallingPid(); + ffrt::task_handle handler = notificationSubQueue_->submit_h(std::bind([ + this, &subscriber, &subInfo, &pid, &result]() { + result = this->AddSubscriberInner(subscriber, subInfo, pid); })); notificationSubQueue_->wait(handler); @@ -326,21 +323,22 @@ void NotificationSubscriberManager::NotifyBadgeEnabledChanged(const sptrsubmit(func); } -void NotificationSubscriberManager::OnRemoteDied(const wptr &object) +void NotificationSubscriberManager::OnRemoteDied(const wptr &object, int32_t pid) { ANS_LOGD("called"); if (notificationSubQueue_ == nullptr) { ANS_LOGE("null queue"); return; } - ffrt::task_handle handler = notificationSubQueue_->submit_h(std::bind([this, object]() { + ffrt::task_handle handler = notificationSubQueue_->submit_h(std::bind([this, object, pid]() { ANS_LOGD("ffrt enter!"); std::shared_ptr record = FindSubscriberRecord(object); if (record != nullptr) { auto subscriberUid = record->subscriberUid; ANS_LOGI("subscriber removed . subscriberUid = %{public}d", record->subscriberUid); subscriberRecordList_.remove(record); - AdvancedNotificationService::GetInstance()->RemoveSystemLiveViewNotificationsOfSa(record->subscriberUid); + AdvancedNotificationService::GetInstance()->RemoveSystemLiveViewNotificationsOfSa( + record->subscriberUid, pid); } })); notificationSubQueue_->wait(handler); @@ -431,7 +429,7 @@ void NotificationSubscriberManager::RemoveRecordInfo( } ErrCode NotificationSubscriberManager::AddSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &subscribeInfo, int32_t &pid) { NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); std::shared_ptr record = FindSubscriberRecord(subscriber); @@ -442,11 +440,17 @@ ErrCode NotificationSubscriberManager::AddSubscriberInner( return ERR_ANS_NO_MEMORY; } subscriberRecordList_.push_back(record); - - record->subscriber->AsObject()->AddDeathRecipient(recipient_); + sptr recipient = new (std::nothrow) + RemoteDeathRecipient(std::bind(&NotificationSubscriberManager::OnRemoteDied, + this, std::placeholders::_1, std::placeholders::_2), pid); + if (recipient == nullptr) { + ANS_LOGE("null recipient"); + return ERR_ANS_NO_MEMORY; + } + record->subscriber->AsObject()->AddDeathRecipient(recipient); record->subscriber->OnConnected(); - ANS_LOGD("subscriber connected"); + ANS_LOGI("subscriber connected"); } AddRecordInfo(record, subscribeInfo); diff --git a/services/ans/src/system_live_view/advanced_notification_system_live_view_service.cpp b/services/ans/src/system_live_view/advanced_notification_system_live_view_service.cpp index 6566b0be776ca912c5105ebb67564e14be8df7ab..448af1435b40aee8432951e5cdab866e6ffc6700 100644 --- a/services/ans/src/system_live_view/advanced_notification_system_live_view_service.cpp +++ b/services/ans/src/system_live_view/advanced_notification_system_live_view_service.cpp @@ -27,6 +27,7 @@ #include "notification_constant.h" #include "notification_local_live_view_subscriber_manager.h" #include "live_publish_process.h" +#include namespace OHOS { namespace Notification { @@ -128,8 +129,9 @@ ErrCode AdvancedNotificationService::SubscribeLocalLiveView( } while (0); if (errCode == ERR_OK) { int32_t callingUid = IPCSkeleton::GetCallingUid(); + int32_t callingPid = IPCSkeleton::GetCallingPid(); ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { - LivePublishProcess::GetInstance()->AddLiveViewSubscriber(callingUid); + LivePublishProcess::GetInstance()->AddLiveViewSubscriber(callingUid, callingPid); })); notificationSvrQueue_->wait(handler); } @@ -138,7 +140,7 @@ ErrCode AdvancedNotificationService::SubscribeLocalLiveView( } ErrCode AdvancedNotificationService::RemoveSystemLiveViewNotifications( - const std::string& bundleName, const int32_t uid) + const std::string& bundleName, const int32_t uid, const int32_t pid) { std::vector> recordList; if (notificationSvrQueue_ == nullptr) { @@ -147,7 +149,7 @@ ErrCode AdvancedNotificationService::RemoveSystemLiveViewNotifications( } ErrCode result = ERR_OK; ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { - LivePublishProcess::GetInstance()->EraseLiveViewSubsciber(uid); + LivePublishProcess::GetInstance()->EraseLiveViewSubsciber(uid, pid); GetTargetRecordList(uid, NotificationConstant::SlotType::LIVE_VIEW, NotificationContent::Type::LOCAL_LIVE_VIEW, recordList); GetCommonTargetRecordList(uid, NotificationConstant::SlotType::LIVE_VIEW, @@ -163,7 +165,7 @@ ErrCode AdvancedNotificationService::RemoveSystemLiveViewNotifications( return result; } -ErrCode AdvancedNotificationService::RemoveSystemLiveViewNotificationsOfSa(int32_t uid) +ErrCode AdvancedNotificationService::RemoveSystemLiveViewNotificationsOfSa(int32_t uid, int32_t pid) { { std::lock_guard lock(delayNotificationMutext_); @@ -180,7 +182,7 @@ ErrCode AdvancedNotificationService::RemoveSystemLiveViewNotificationsOfSa(int32 ErrCode result = ERR_OK; ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { - LivePublishProcess::GetInstance()->EraseLiveViewSubsciber(uid); + LivePublishProcess::GetInstance()->EraseLiveViewSubsciber(uid, pid); std::vector> recordList; for (auto item : notificationList_) { if (item->notification->GetNotificationRequest().GetCreatorUid() == uid && diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index d67d348bb88bd471f23f6545046b99ef8c222fdf..e4369c65d5321d9d142c27dd4c7eac2dde5c2f63 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -366,8 +366,9 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03300, record->notification = notification; advancedNotificationService_->notificationList_.push_back(record); int32_t uid = 0; - ASSERT_EQ((int)advancedNotificationService_->RemoveSystemLiveViewNotificationsOfSa(uid), - (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ((int)advancedNotificationService_->RemoveSystemLiveViewNotificationsOfSa(uid, pid), + (int)ERR_OK); } /** @@ -3372,7 +3373,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00017, record->notification = notification; advancedNotificationService_->notificationList_.push_back(record); int32_t uid = 0; - ASSERT_EQ(advancedNotificationService_->RemoveSystemLiveViewNotifications(bundleName, uid), ERR_OK); + int32_t pid = 0; + ASSERT_EQ(advancedNotificationService_->RemoveSystemLiveViewNotifications(bundleName, uid, pid), ERR_OK); GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_00017 test end"; } @@ -3387,7 +3389,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00018, GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_00018 test start"; std::string bundleName = "testBundle"; int32_t uid = 0; - ASSERT_EQ(advancedNotificationService_->RemoveSystemLiveViewNotifications(bundleName, uid), + int32_t pid = 0; + ASSERT_EQ(advancedNotificationService_->RemoveSystemLiveViewNotifications(bundleName, uid, pid), ERR_ANS_NOTIFICATION_NOT_EXISTS); GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_00018 test end"; } @@ -3418,7 +3421,9 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00019, advancedNotificationService_->notificationList_.push_back(record); advancedNotificationService_->notificationSvrQueue_ = nullptr; int32_t uid = 0; - ASSERT_EQ(advancedNotificationService_->RemoveSystemLiveViewNotifications(bundleName, uid), ERR_ANS_INVALID_PARAM); + int32_t pid = 0; + ASSERT_EQ(advancedNotificationService_->RemoveSystemLiveViewNotifications(bundleName, uid, pid), + ERR_ANS_INVALID_PARAM); GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_00019 test end"; } /** diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_system_live_view_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_system_live_view_service_test.cpp index 8b4ee9eb446ab58e91bc67548d8e440a9c0b9447..9f25b4c8c8b839f724906ccf796259e473076ca0 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_system_live_view_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_system_live_view_service_test.cpp @@ -179,6 +179,7 @@ HWTEST_F(AdvancedNotificationSysLiveviewServiceTest, RemoveSystemLiveViewNotific Function | SmallTest | Level1) { int32_t uid = SYSTEM_APP_UID; + int32_t pid = 0; sptr bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, uid); sptr request = new (std::nothrow) NotificationRequest(); request->SetCreatorUid(uid); @@ -193,7 +194,7 @@ HWTEST_F(AdvancedNotificationSysLiveviewServiceTest, RemoveSystemLiveViewNotific advancedNotificationService_->AddToDelayNotificationList(record1); advancedNotificationService_->AddToNotificationList(record); - auto ret = advancedNotificationService_->RemoveSystemLiveViewNotificationsOfSa(uid); + auto ret = advancedNotificationService_->RemoveSystemLiveViewNotificationsOfSa(uid, pid); auto key = record->notification->GetKey(); ASSERT_EQ(false, advancedNotificationService_->IsNotificationExistsInDelayList(key)); diff --git a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp index 1ae25ab5a39c94208790b80db1563727336ce4fc..3d1225f84c8535219a7b34ecb60e0fd66d292e23 100644 --- a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp @@ -196,7 +196,8 @@ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, OnRemoteDied_001, Funct ASSERT_EQ(size, 1); wptr obj = subscriber_->AsObject(); - notificationLocalLiveViewSubscriberManager_->OnRemoteDied(obj); + int32_t pid = 0; + notificationLocalLiveViewSubscriberManager_->OnRemoteDied(obj, pid); size = notificationLocalLiveViewSubscriberManager_->buttonRecordList_.size(); ASSERT_EQ(size, 0); @@ -215,7 +216,8 @@ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, OnRemoteDied_002, Funct notificationLocalLiveViewSubscriberManager_->notificationButtonQueue_ = nullptr; wptr obj = subscriber_->AsObject(); - notificationLocalLiveViewSubscriberManager_->OnRemoteDied(obj); + int32_t pid = 0; + notificationLocalLiveViewSubscriberManager_->OnRemoteDied(obj, pid); size = notificationLocalLiveViewSubscriberManager_->buttonRecordList_.size(); ASSERT_EQ(size, 1); } diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp index 2a85a65037f4139112d70969cf5aca54000bc67c..527d492a2cdc7979225d402af794e3e314557184 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp @@ -138,7 +138,8 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, NotificationSubscriberManager_ std::make_shared(); ASSERT_NE(nullptr, notificationSubscriberManager); wptr object = nullptr; - notificationSubscriberManager->OnRemoteDied(object); + int32_t pid = 0; + notificationSubscriberManager->OnRemoteDied(object, pid); } /** diff --git a/services/ans/test/unittest/notification_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_test.cpp index ec975480f9b52cf5cc78364b11e91b7b7aa8c396..eda53600f5cba24f75b2f8bb555b08d565af453b 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_test.cpp @@ -558,7 +558,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyConsumed_001, Function | Small NotificationSubscriberManager notificationSubscriberManager; sptr info(new NotificationSubscribeInfo()); - ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info), (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info, pid), (int)ERR_OK); notificationSubscriberManager.NotifyConsumed(notification, notificationMap); std::this_thread::sleep_for(std::chrono::milliseconds(400)); isCallback = testAnsSubscriber->GetCallBack(); @@ -713,7 +714,8 @@ HWTEST_F(NotificationSubscriberManagerTest, BatchNotifyCanceledInner_001, Functi NotificationSubscriberManager notificationSubscriberManager; sptr info(new NotificationSubscribeInfo()); - ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info), (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info, pid), (int)ERR_OK); //brach need nullptr notificationSubscriberManager.subscriberRecordList_.push_back(nullptr); @@ -744,7 +746,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyDoNotDisturbDateChangedInner_0 info->AddAppUserId(101); info->AddAppName(bundle); - ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info), (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info, pid), (int)ERR_OK); notificationSubscriberManager.NotifyDoNotDisturbDateChangedInner(101, date, bundle); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -774,7 +777,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyEnabledNotificationChangedInne sptr info(new NotificationSubscribeInfo()); info->AddAppUserId(100); info->AddAppName(bundle); - ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info), (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info, pid), (int)ERR_OK); notificationSubscriberManager.NotifyEnabledNotificationChangedInner(callback); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -806,7 +810,8 @@ HWTEST_F(NotificationSubscriberManagerTest, SetBadgeNumber_001, Function | Small sptr info(new NotificationSubscribeInfo()); info->AddAppUserId(100); info->AddAppName(bundle); - ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info), (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info, pid), (int)ERR_OK); notificationSubscriberManager.SetBadgeNumber(badge); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -829,7 +834,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyApplicationInfoNeedChanged_001 NotificationSubscriberManager notificationSubscriberManager; sptr info(new NotificationSubscribeInfo()); info->SetNeedNotifyApplication(true); - ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info), (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info, pid), (int)ERR_OK); notificationSubscriberManager.NotifyApplicationInfoNeedChanged("test"); std::this_thread::sleep_for(std::chrono::milliseconds(200)); @@ -853,7 +859,8 @@ HWTEST_F(NotificationSubscriberManagerTest, DistributeOperation_001, Function | NotificationSubscriberManager notificationSubscriberManager; sptr info(new NotificationSubscribeInfo()); info->SetNeedNotifyResponse(true); - ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info), (int)ERR_OK); + int32_t pid = 0; + ASSERT_EQ(notificationSubscriberManager.AddSubscriberInner(subscriber, info, pid), (int)ERR_OK); sptr request = new (std::nothrow) NotificationRequest(); notificationSubscriberManager.DistributeOperation(operationInfo, request); @@ -900,7 +907,8 @@ HWTEST_F(NotificationSubscriberManagerTest, OnRemoteDied_001, Function | SmallTe { notificationSubscriberManager_->notificationSubQueue_ = nullptr; wptr obj = nullptr; - notificationSubscriberManager_->OnRemoteDied(obj); + int32_t pid = 0; + notificationSubscriberManager_->OnRemoteDied(obj, pid); EXPECT_NE(notificationSubscriberManager_, nullptr); } /** @@ -930,7 +938,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyConsumedInner_002, Function | sptr subscriber(new (std::nothrow) MockAnsSubscriberTest()); const sptr subscribeInfo = new NotificationSubscribeInfo(); subscribeInfo->AddAppUserId(SUBSCRIBE_USER_ALL); - notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo); + int32_t pid = 0; + notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo, pid); sptr request = new NotificationRequest(); request->SetCreatorUid(DEFAULT_UID); request->SetOwnerBundleName("test1"); @@ -954,7 +963,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyConsumedInner_003, Function | sptr subscriber(new (std::nothrow) MockAnsSubscriberTest()); const sptr subscribeInfo = new NotificationSubscribeInfo(); subscribeInfo->AddAppUserId(SUBSCRIBE_USER_ALL); - notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo); + int32_t pid = 0; + notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo, pid); sptr request = new NotificationRequest(); request->SetCreatorUid(DEFAULT_UID); request->SetOwnerBundleName("test1"); @@ -982,7 +992,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyConsumedInner_004, Function | sptr subscriber(new (std::nothrow) MockAnsSubscriberTest()); const sptr subscribeInfo = new NotificationSubscribeInfo(); subscribeInfo->AddAppUserId(SUBSCRIBE_USER_ALL); - notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo); + int32_t pid = 0; + notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo, pid); sptr request = new NotificationRequest(); request->SetCreatorUid(DEFAULT_UID); request->SetOwnerBundleName("test1"); @@ -1006,7 +1017,8 @@ HWTEST_F(NotificationSubscriberManagerTest, NotifyConsumedInner_005, Function | sptr subscriber(new (std::nothrow) MockAnsSubscriberTest()); const sptr subscribeInfo = new NotificationSubscribeInfo(); subscribeInfo->AddAppUserId(SUBSCRIBE_USER_ALL); - notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo); + int32_t pid = 0; + notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo, pid); sptr request = new NotificationRequest(); request->SetCreatorUid(DEFAULT_UID); request->SetOwnerBundleName("test1"); @@ -1050,7 +1062,8 @@ HWTEST_F(NotificationSubscriberManagerTest, GetIsEnableEffectedRemind_002, Funct const sptr subscribeInfo = new NotificationSubscribeInfo(); subscribeInfo->AddAppUserId(SUBSCRIBE_USER_ALL); subscribeInfo->AddDeviceType(NotificationConstant::PC_DEVICE_TYPE); - notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo); + int32_t pid = 0; + notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo, pid); auto ret = notificationSubscriberManager.GetIsEnableEffectedRemind(); @@ -1084,7 +1097,8 @@ HWTEST_F(NotificationSubscriberManagerTest, IsDeviceTypeSubscriberd_002, Functio const sptr subscribeInfo = new NotificationSubscribeInfo(); subscribeInfo->AddAppUserId(SUBSCRIBE_USER_ALL); subscribeInfo->AddDeviceType(deviceType); - notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo); + int32_t pid = 0; + notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo, pid); auto ret = notificationSubscriberManager.IsDeviceTypeSubscriberd(deviceType); @@ -1104,7 +1118,8 @@ HWTEST_F(NotificationSubscriberManagerTest, IsDeviceTypeAffordConsume_001, Funct const sptr subscribeInfo = new NotificationSubscribeInfo(); subscribeInfo->AddAppUserId(SUBSCRIBE_USER_ALL); subscribeInfo->AddDeviceType(deviceType); - notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo); + int32_t pid = 0; + notificationSubscriberManager.AddSubscriberInner(subscriber, subscribeInfo, pid); sptr request = new NotificationRequest(); bool result = false; diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index bca321d9435146119f9b5902b2591d4c6d57791c..4fa09d66acfb4cbfc6cd2d621d2b75bf29ad5d8b 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp @@ -162,8 +162,10 @@ namespace OHOS { service->ExcuteCancelAll(bundleOption, fuzzData->ConsumeIntegral()); service->ExcuteDelete(stringData, fuzzData->ConsumeIntegral()); service->HandleBadgeEnabledChanged(bundleOption, enabled); - service->RemoveSystemLiveViewNotifications(bundleName, fuzzData->ConsumeIntegral()); - service->RemoveSystemLiveViewNotificationsOfSa(fuzzData->ConsumeIntegral()); + service->RemoveSystemLiveViewNotifications(bundleName, + fuzzData->ConsumeIntegral(), fuzzData->ConsumeIntegral()); + service->RemoveSystemLiveViewNotificationsOfSa( + fuzzData->ConsumeIntegral(), fuzzData->ConsumeIntegral()); service->TriggerLocalLiveView(bundleOption, fuzzData->ConsumeIntegral(), buttonOption); service->RemoveNotificationBySlot(bundleOption, slot, fuzzData->ConsumeIntegral()); service->IsNeedSilentInDoNotDisturbMode(phoneNumber, fuzzData->ConsumeIntegral()); diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index 1af0671f71acc87aa962d7cd3fe496cab28c85f0..c13bbb63c6cb83d8d1e5bd21ff53ae06bece8a76 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -166,8 +166,10 @@ namespace OHOS { service->ExcuteCancelAll(bundleOption, fuzzData->ConsumeIntegral()); service->ExcuteDelete(stringData, fuzzData->ConsumeIntegral()); service->HandleBadgeEnabledChanged(bundleOption, enabled); - service->RemoveSystemLiveViewNotifications(bundleName, fuzzData->ConsumeIntegral()); - service->RemoveSystemLiveViewNotificationsOfSa(fuzzData->ConsumeIntegral()); + service->RemoveSystemLiveViewNotifications(bundleName, + fuzzData->ConsumeIntegral(), fuzzData->ConsumeIntegral()); + service->RemoveSystemLiveViewNotificationsOfSa( + fuzzData->ConsumeIntegral(), fuzzData->ConsumeIntegral()); service->TriggerLocalLiveView(bundleOption, fuzzData->ConsumeIntegral(), buttonOption); service->RemoveNotificationBySlot(bundleOption, slot, fuzzData->ConsumeIntegral()); service->IsNeedSilentInDoNotDisturbMode(phoneNumber, fuzzData->ConsumeIntegral());