1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_EVENT_MANAGER_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_EVENT_MANAGER_H 18 19 #include "common_event_subscriber.h" 20 #include "reminder_data_manager.h" 21 #include "system_ability_status_change_stub.h" 22 #include "notification_subscriber.h" 23 24 #include <memory> 25 26 namespace OHOS { 27 namespace Notification { 28 class ReminderEventManager { 29 public: 30 explicit ReminderEventManager(std::shared_ptr<ReminderDataManager> &reminderDataManager); ~ReminderEventManager()31 virtual ~ReminderEventManager() {}; 32 ReminderEventManager(ReminderEventManager &other) = delete; 33 ReminderEventManager& operator = (const ReminderEventManager &other) = delete; 34 35 private: 36 void init(std::shared_ptr<ReminderDataManager> &reminderDataManager) const; 37 void SubscribeSystemAbility(std::shared_ptr<ReminderDataManager> &reminderDataManager) const; 38 39 class ReminderEventSubscriber : public EventFwk::CommonEventSubscriber { 40 public: 41 ReminderEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, 42 std::shared_ptr<ReminderDataManager> &reminderDataManager); 43 virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); 44 45 private: 46 sptr<NotificationBundleOption> GetBundleOption(const OHOS::EventFwk::Want &want) const; 47 void HandlePackageRemove(const EventFwk::Want &want) const; 48 void HandleProcessDied(const EventFwk::Want &want) const; 49 std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr; 50 }; 51 52 class ReminderEventCustomSubscriber : public EventFwk::CommonEventSubscriber { 53 public: 54 ReminderEventCustomSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, 55 std::shared_ptr<ReminderDataManager> &reminderDataManager); 56 virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); 57 58 private: 59 std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr; 60 }; 61 62 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 63 public: 64 explicit SystemAbilityStatusChangeListener(std::shared_ptr<ReminderDataManager> &reminderDataManager); ~SystemAbilityStatusChangeListener()65 ~SystemAbilityStatusChangeListener() {}; 66 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 67 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 68 private: 69 std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr; 70 }; 71 72 class ReminderNotificationSubscriber : public NotificationSubscriber { 73 public: 74 explicit ReminderNotificationSubscriber(std::shared_ptr<ReminderDataManager> &reminderDataManager); 75 ~ReminderNotificationSubscriber() override; 76 void OnConnected() override; 77 void OnDisconnected() override; 78 void OnCanceled(const std::shared_ptr<Notification> &request, 79 const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) override; 80 void OnConsumed(const std::shared_ptr<Notification> &request, 81 const std::shared_ptr<NotificationSortingMap> &sortingMap) override; 82 void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override; 83 void OnDied() override; 84 void OnDoNotDisturbDateChange( 85 const std::shared_ptr<NotificationDoNotDisturbDate> &date) override; 86 void OnEnabledNotificationChanged( 87 const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override; 88 void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) override; 89 void OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> &callbackData) override; 90 void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>> &requestList, 91 const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override; 92 private: 93 std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr; 94 }; 95 96 static std::shared_ptr<ReminderNotificationSubscriber> subscriber_; 97 }; 98 } // namespace OHOS 99 } // namespace Notification 100 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_EVENT_MANAGER_H 101