/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_SUBSCRIBER_MANAGER_H #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_SUBSCRIBER_MANAGER_H #include #include #include #include "errors.h" #include "event_handler.h" #include "event_runner.h" #include "ffrt.h" #include "nocopyable.h" #include "refbase.h" #include "singleton.h" #include "ans_subscriber_interface.h" #include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" #include "notification_sorting_map.h" #include "notification_subscribe_info.h" namespace OHOS { namespace Notification { class NotificationSubscriberManager : public DelayedSingleton { public: struct SubscriberRecord; /** * @brief Add a subscriber. * * @param subscriber Indicates the AnsSubscriberInterface object. * @param subscribeInfo Indicates the NotificationSubscribeInfo object. * @return Indicates the result code. */ ErrCode AddSubscriber(const sptr &subscriber, const sptr &subscribeInfo); /** * @brief Remove a subscriber. * * @param subscriber Indicates the AnsSubscriberInterface object. * @param subscribeInfo Indicates the NotificationSubscribeInfo object. * @return Indicates the result code. */ ErrCode RemoveSubscriber( const sptr &subscriber, const sptr &subscribeInfo); /** * @brief Notify all subscribers on counsumed. * * @param notification Indicates the Notification object. * @param notificationMap Indicates the NotificationSortingMap object. */ void NotifyConsumed(const sptr ¬ification, const sptr ¬ificationMap); void BatchNotifyConsumed(const std::vector> ¬ifications, const sptr ¬ificationMap, const std::shared_ptr &record); /** * @brief Notify all subscribers on canceled. * * @param notification Indicates the Notification object. * @param notificationMap Indicates the NotificationSortingMap object. * @param deleteReason Indicates the delete reason. */ void NotifyCanceled(const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason); void BatchNotifyCanceled(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason); /** * @brief Notify all subscribers on updated. * * @param notificationMap Indicates the NotificationSortingMap object. */ void NotifyUpdated(const sptr ¬ificationMap); /** * @brief Notify all subscribers on dnd date changed. * * @param userId Indicates which user need consume the update nofitication * @param date Indicates the NotificationDoNotDisturbDate object. */ void NotifyDoNotDisturbDateChanged(const int32_t &userId, const sptr &date); void NotifyEnabledNotificationChanged(const sptr &callbackData); /** * @brief Notify all subscribers on badge enabled state changed. * * @param callbackData Indicates the EnabledNotificationCallbackData object. */ void NotifyBadgeEnabledChanged(const sptr &callbackData); /** * @brief Obtains the death event. * * @param object Indicates the death object. */ void OnRemoteDied(const wptr &object); /** * @brief Set badge number. * * @param uid The application's uid. * @param bundleName The application's bundle name. * @param badgeNumber The badge number. */ void SetBadgeNumber(const sptr &badgeData); /** * @brief Reset ffrt queue */ void ResetFfrtQueue(); void RegisterOnSubscriberAddCallback(std::function &)> callback); void UnRegisterOnSubscriberAddCallback(); std::list> GetSubscriberRecords(); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED bool GetIsEnableEffectedRemind(); #endif private: std::shared_ptr FindSubscriberRecord(const wptr &object); std::shared_ptr FindSubscriberRecord(const sptr &subscriber); std::shared_ptr CreateSubscriberRecord(const sptr &subscriber); void AddRecordInfo( std::shared_ptr &record, const sptr &subscribeInfo); void RemoveRecordInfo( std::shared_ptr &record, const sptr &subscribeInfo); ErrCode AddSubscriberInner( const sptr &subscriber, const sptr &subscribeInfo); ErrCode RemoveSubscriberInner( const sptr &subscriber, const sptr &subscribeInfo); void NotifyConsumedInner( const sptr ¬ification, const sptr ¬ificationMap); void BatchNotifyConsumedInner(const std::vector> ¬ifications, const sptr ¬ificationMap, const std::shared_ptr &record); void NotifyCanceledInner(const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason); void BatchNotifyCanceledInner(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason); void NotifyUpdatedInner(const sptr ¬ificationMap); void NotifyDoNotDisturbDateChangedInner(const int32_t &userId, const sptr &date); void NotifyEnabledNotificationChangedInner(const sptr &callbackData); void NotifyBadgeEnabledChangedInner(const sptr &callbackData); bool IsSystemUser(int32_t userId); bool IsSubscribedBysubscriber( const std::shared_ptr &record, const sptr ¬ification); private: std::list> subscriberRecordList_ {}; std::shared_ptr runner_ {}; std::shared_ptr handler_ {}; sptr ansSubscriberProxy_ {}; sptr recipient_ {}; std::shared_ptr notificationSubQueue_ = nullptr; std::function &)> onSubscriberAddCallback_ = nullptr; DECLARE_DELAYED_SINGLETON(NotificationSubscriberManager); DISALLOW_COPY_AND_MOVE(NotificationSubscriberManager); }; } // namespace Notification } // namespace OHOS #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_SUBSCRIBER_MANAGER_H