• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SERVICES_REMINDER_INCLUDE_REMINDER_EVENT_MANAGER_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_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     int32_t GetUid(const OHOS::EventFwk::Want &want) const;
48     void HandlePackageRemove(const EventFwk::Want &want) const;
49     void HandleProcessDied(const EventFwk::Want &want) const;
50     std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr;
51 };
52 
53 class ReminderEventCustomSubscriber : public EventFwk::CommonEventSubscriber {
54 public:
55     ReminderEventCustomSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo,
56         std::shared_ptr<ReminderDataManager> &reminderDataManager);
57     virtual void OnReceiveEvent(const EventFwk::CommonEventData &data);
58 
59 private:
60     std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr;
61 };
62 
63 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
64 public:
65     explicit SystemAbilityStatusChangeListener(std::shared_ptr<ReminderDataManager> &reminderDataManager);
~SystemAbilityStatusChangeListener()66     ~SystemAbilityStatusChangeListener() {};
67     virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
68     virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
69 private:
70     std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr;
71 };
72 
73 class ReminderNotificationSubscriber : public NotificationSubscriber {
74 public:
75     explicit ReminderNotificationSubscriber(std::shared_ptr<ReminderDataManager> &reminderDataManager);
76     ~ReminderNotificationSubscriber() override;
77     void OnConnected() override;
78     void OnDisconnected() override;
79     void OnCanceled(const std::shared_ptr<Notification> &request,
80         const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) override;
81     void OnConsumed(const std::shared_ptr<Notification> &request,
82         const std::shared_ptr<NotificationSortingMap> &sortingMap) override;
83     void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override;
84     void OnDied() override;
85     void OnDoNotDisturbDateChange(
86         const std::shared_ptr<NotificationDoNotDisturbDate> &date) override;
87     void OnEnabledNotificationChanged(
88         const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override;
89     void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) override;
90     void OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> &callbackData) override;
91     void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>> &requestList,
92         const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) override;
93 private:
94     std::shared_ptr<ReminderDataManager> reminderDataManager_ = nullptr;
95 };
96 
97     static std::shared_ptr<ReminderNotificationSubscriber> subscriber_;
98 };
99 }  // namespace OHOS
100 }  // namespace Notification
101 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_EVENT_MANAGER_H
102