From 344181e31c8e089bddf1be4088f6909e91c36206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BA=B7=E5=BA=B7?= Date: Tue, 28 Mar 2023 11:33:11 +0800 Subject: [PATCH] =?UTF-8?q?fixed=200590289=20from=20https://gitee.com/liao?= =?UTF-8?q?kk/notification=5Fdistributed=5Fnotification=5Fservice/pulls/95?= =?UTF-8?q?8=20=E8=87=AA=E5=AE=9A=E4=B9=89=E4=BA=8B=E4=BB=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖康康 --- services/ans/include/reminder_event_manager.h | 10 ++++++ services/ans/src/reminder_event_manager.cpp | 33 +++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/services/ans/include/reminder_event_manager.h b/services/ans/include/reminder_event_manager.h index dbc625f26..15a7972e7 100644 --- a/services/ans/include/reminder_event_manager.h +++ b/services/ans/include/reminder_event_manager.h @@ -47,6 +47,16 @@ private: std::shared_ptr reminderDataManager_ = nullptr; }; +class ReminderEventCustomSubscriber : public EventFwk::CommonEventSubscriber { +public: + ReminderEventCustomSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, + std::shared_ptr &reminderDataManager); + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); + +private: + std::shared_ptr reminderDataManager_ = nullptr; +}; + class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { public: explicit SystemAbilityStatusChangeListener(std::shared_ptr &reminderDataManager); diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index 1a9c2b265..4d814a9b4 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -35,11 +35,17 @@ ReminderEventManager::ReminderEventManager(std::shared_ptr void ReminderEventManager::init(std::shared_ptr &reminderDataManager) const { + MatchingSkills customMatchingSkills; + customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); + customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); + customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); + customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); + customMatchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION); + CommonEventSubscribeInfo customSubscriberInfo(customMatchingSkills); + customSubscriberInfo.SetPermission("ohos.permission.GRANT_SENSITIVE_PERMISSIONS"); + auto customSubscriber = std::make_shared(customSubscriberInfo, reminderDataManager); + MatchingSkills matchingSkills; - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); - matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); @@ -52,7 +58,8 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa auto subscriber = std::make_shared(subscriberInfo, reminderDataManager); std::string identity = IPCSkeleton::ResetCallingIdentity(); - if (CommonEventManager::SubscribeCommonEvent(subscriber)) { + if (CommonEventManager::SubscribeCommonEvent(subscriber) && + CommonEventManager::SubscribeCommonEvent(customSubscriber)) { ANSR_LOGD("SubscribeCommonEvent ok"); } else { ANSR_LOGD("SubscribeCommonEvent fail"); @@ -83,7 +90,14 @@ ReminderEventManager::ReminderEventSubscriber::ReminderEventSubscriber( reminderDataManager_ = reminderDataManager; } -void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) +ReminderEventManager::ReminderEventCustomSubscriber::ReminderEventCustomSubscriber( + const CommonEventSubscribeInfo &subscriberInfo, + std::shared_ptr &reminderDataManager) : CommonEventSubscriber(subscriberInfo) +{ + reminderDataManager_ = reminderDataManager; +} + +void ReminderEventManager::ReminderEventCustomSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) { Want want = data.GetWant(); std::string action = want.GetAction(); @@ -108,6 +122,13 @@ void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFw reminderDataManager_->CloseReminder(want, false); return; } +} + +void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) +{ + Want want = data.GetWant(); + std::string action = want.GetAction(); + ANSR_LOGI("Recieved common event:%{public}s", action.c_str()); if (action == CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) { reminderDataManager_->Init(true); return; -- Gitee