1 /*
2  * Copyright (c) 2021-2024 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_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
18 
19 #include "ans_subscriber_interface.h"
20 #include "distributed_notification_service_ipc_interface_code.h"
21 #include "iremote_stub.h"
22 
23 namespace OHOS {
24 namespace Notification {
25 class AnsSubscriberStub : public IRemoteStub<AnsSubscriberInterface> {
26 public:
27     AnsSubscriberStub();
28     ~AnsSubscriberStub() override;
29     DISALLOW_COPY_AND_MOVE(AnsSubscriberStub);
30 
31     /**
32      * @brief Handle remote request.
33      *
34      * @param data Indicates the input parcel.
35      * @param reply Indicates the output parcel.
36      * @param option Indicates the message option.
37      * @return Returns ERR_OK on success, others on failure.
38      */
39     virtual int32_t OnRemoteRequest(
40         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
41 
42     /**
43      * @brief The callback function for the subscriber to establish a connection.
44      */
45     void OnConnected() override;
46 
47     /**
48      * @brief The callback function for subscriber disconnected.
49      */
50     void OnDisconnected() override;
51 
52     /**
53      * @brief The callback function on a notification published.
54      *
55      * @param notification Indicates the consumed notification.
56      * @param notificationMap Indicates the NotificationSortingMap object.
57      */
58     void OnConsumed(
59         const sptr<Notification> &notification, const sptr<NotificationSortingMap> &notificationMap) override;
60 
61     void OnConsumedList(const std::vector<sptr<Notification>> &notifications,
62         const sptr<NotificationSortingMap> &notificationMap) override;
63 
64     /**
65      * @brief The callback function on a notification canceled.
66      *
67      * @param notification Indicates the canceled notification.
68      * @param notificationMap Indicates the NotificationSortingMap object.
69      * @param deleteReason Indicates the delete reason.
70      */
71     void OnCanceled(const sptr<Notification> &notification, const sptr<NotificationSortingMap> &notificationMap,
72         int32_t deleteReason) override;
73 
74     void OnCanceledList(const std::vector<sptr<Notification>> &notifications,
75         const sptr<NotificationSortingMap> &notificationMap, int32_t deleteReason) override;
76 
77     /**
78      * @brief The callback function on the notifications updated.
79      *
80      * @param notificationMap Indicates the NotificationSortingMap object.
81      */
82     void OnUpdated(const sptr<NotificationSortingMap> &notificationMap) override;
83 
84     /**
85      * @brief The callback function on the do not disturb date changed.
86      *
87      * @param date Indicates the NotificationDoNotDisturbDate object.
88      */
89     void OnDoNotDisturbDateChange(const sptr<NotificationDoNotDisturbDate> &date) override;
90 
91     /**
92      * @brief The callback function on the notification enabled flag changed.
93      *
94      * @param callbackData Indicates the EnabledNotificationCallbackData object.
95      */
96     void OnEnabledNotificationChanged(const sptr<EnabledNotificationCallbackData> &callbackData) override;
97 
98     /**
99      * @brief The callback function on the badge number changed.
100      *
101      * @param badgeData Indicates the BadgeNumberCallbackData object.
102      */
103     void OnBadgeChanged(const sptr<BadgeNumberCallbackData> &badgeData) override;
104 
105     /**
106      * @brief The callback function on the badge enabled state changed.
107      *
108      * @param callbackData Indicates the EnabledNotificationCallbackData object.
109      */
110     void OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> &callbackData) override;
111 
112 private:
113 
114     ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply);
115     ErrCode HandleOnDisconnected(MessageParcel &data, MessageParcel &reply);
116     ErrCode HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply);
117     ErrCode HandleOnConsumedListMap(MessageParcel &data, MessageParcel &reply);
118     ErrCode HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply);
119     ErrCode HandleOnCanceledListMap(MessageParcel &data, MessageParcel &reply);
120     ErrCode HandleOnUpdated(MessageParcel &data, MessageParcel &reply);
121     ErrCode HandleOnDoNotDisturbDateChange(MessageParcel &data, MessageParcel &reply);
122     ErrCode HandleOnEnabledNotificationChanged(MessageParcel &data, MessageParcel &reply);
123     ErrCode HandleOnBadgeChanged(MessageParcel &data, MessageParcel &reply);
124     ErrCode HandleOnBadgeEnabledChanged(MessageParcel &data, MessageParcel &reply);
125     template<typename T>
126     bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &data);
127 };
128 }  // namespace Notification
129 }  // namespace OHOS
130 
131 #endif  // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
132