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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_H 17#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_H 18 19#include "ans_manager_interface.h" 20#include "ans_subscriber_stub.h" 21#include "notification_request.h" 22#include "notification_sorting.h" 23#include "notification_sorting_map.h" 24 25namespace OHOS { 26namespace Notification { 27class NotificationSubscriber : public std::enable_shared_from_this<NotificationSubscriber> { 28public: 29 NotificationSubscriber(); 30 31 virtual ~NotificationSubscriber(); 32 33 /** 34 * @brief Called back when a notification is canceled. 35 * 36 * @param request Indicates the canceled Notification object. 37 * @param sortingMap Indicates the sorting map used by the current subscriber 38 * to obtain notification ranking information. 39 * @param deleteReason Indicates the reason for the deletion. For details, see NotificationConstant. 40 **/ 41 virtual void OnCanceled(const std::shared_ptr<Notification> &request, 42 const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) = 0; 43 44 /** 45 * @brief Called back when the subscriber is connected to the Advanced Notification Service (ANS). 46 **/ 47 virtual void OnConnected() = 0; 48 49 /** 50 * @brief Called back when the subscriber receives a new notification. 51 * 52 * @param request Indicates the received Notification object. 53 * @param sortingMap Indicates the sorting map used by the current subscriber to obtain 54 * notification ranking information. 55 **/ 56 virtual void OnConsumed( 57 const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap) = 0; 58 59 /** 60 * @brief Called back when the subscriber is disconnected from the ANS. 61 **/ 62 virtual void OnDisconnected() = 0; 63 64 /** 65 * @brief Called back when the ranking information about the current notification changes. 66 * 67 * @param sortingMap Indicates the sorting map used to obtain notification ranking information. 68 **/ 69 virtual void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) = 0; 70 71 /** 72 * @brief Called back when connection to the ANS has died. 73 **/ 74 virtual void OnDied() = 0; 75 76 /** 77 * @brief Called when the Do Not Disturb date changes. 78 * 79 * @param date Indicates the current Do Not Disturb date. 80 **/ 81 virtual void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) = 0; 82 83 /** 84 * @brief Called when the notification permission changes. 85 * 86 * @param callbackData Indicates the properties of the application that notification permission has changed. 87 **/ 88 virtual void OnEnabledNotificationChanged(const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) = 0; 89 90 /** 91 * @brief The callback function on the badge number changed. 92 * 93 * @param badgeData Indicates the BadgeNumberCallbackData object. 94 */ 95 virtual void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) = 0; 96 97 /** 98 * @brief The callback function on the badge enabled state changed. 99 * 100 * @param callbackData Indicates the properties of the application that badge enabled state has changed. 101 */ 102 virtual void OnBadgeEnabledChanged(const sptr<EnabledNotificationCallbackData> &callbackData) = 0; 103 104 /** 105 * @brief The callback function on the badge number changed. 106 * 107 * @param badgeData Indicates the BadgeNumberCallbackData object. 108 */ 109 virtual void OnBatchCanceled(const std::vector<std::shared_ptr<Notification>> &requestList, 110 const std::shared_ptr<NotificationSortingMap> &sortingMap, int32_t deleteReason) = 0; 111 112 virtual bool HasOnBatchCancelCallback() 113 { 114 return false; 115 } 116 117 void SetDeviceType(const std::string &deviceType); 118 119 std::string GetDeviceType() const; 120 std::shared_ptr<NotificationSubscriber> GetSharedPtr() const; 121 122#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED 123 bool ProcessSyncDecision(const std::string &deviceType, std::shared_ptr<Notification> ¬ification) const; 124#endif 125 126private: 127#ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED 128 NotificationConstant::FlagStatus DowngradeReminder( 129 const NotificationConstant::FlagStatus &oldFlags, const NotificationConstant::FlagStatus &judgeFlags) const; 130#endif 131 132private: 133 std::string deviceType_; 134}; 135} // namespace Notification 136} // namespace OHOS 137 138#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SUBSCRIBER_H 139