1 /* 2 * Copyright (c) 2023-2025 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 BND_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H 17 #define BND_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H 18 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 23 #include "errors.h" 24 #include "event_handler.h" 25 #include "event_runner.h" 26 #include "ffrt.h" 27 #include "ians_subscriber_local_live_view.h" 28 #include "nocopyable.h" 29 #include "refbase.h" 30 #include "singleton.h" 31 32 #include "notification.h" 33 #include "notification_bundle_option.h" 34 #include "notification_constant.h" 35 #include "notification_request.h" 36 #include "notification_sorting_map.h" 37 #include "notification_subscribe_info.h" 38 39 namespace OHOS { 40 namespace Notification { 41 class NotificationLocalLiveViewSubscriberManager : public DelayedSingleton<NotificationLocalLiveViewSubscriberManager> { 42 public: 43 /** 44 * @brief Add a subscriber. 45 * 46 * @param subscriber Indicates the AnsSubscriberInterface object. 47 * @param subscribeInfo Indicates the NotificationSubscribeInfo object. 48 * @return Indicates the result code. 49 */ 50 ErrCode AddLocalLiveViewSubscriber(const sptr<IAnsSubscriberLocalLiveView> &subscriber, 51 const sptr<NotificationSubscribeInfo> &subscribeInfo); 52 53 /** 54 * @brief Remove a subscriber. 55 * 56 * @param subscriber Indicates the AnsSubscriberInterface object. 57 * @param subscribeInfo Indicates the NotificationSubscribeInfo object. 58 * @return Indicates the result code. 59 */ 60 ErrCode RemoveLocalLiveViewSubscriber(const sptr<IAnsSubscriberLocalLiveView> &subscriber, 61 const sptr<NotificationSubscribeInfo> &subscribeInfo); 62 63 /** 64 * @brief Notify all subscribers on canceled. 65 * 66 * @param notification Indicates the Notification object. 67 * @param buttonOption Indicates the buttonOption object. 68 */ 69 void NotifyTriggerResponse(const sptr<Notification> ¬ification, 70 const sptr<NotificationButtonOption> &buttonOption); 71 72 /** 73 * @brief Obtains the death event. 74 * 75 * @param object Indicates the death object. 76 */ 77 void OnRemoteDied(const wptr<IRemoteObject> &object); 78 79 /** 80 * @brief Reset ffrt queue 81 */ 82 void ResetFfrtQueue(); 83 84 private: 85 struct LocalLiveViewSubscriberRecord; 86 87 std::shared_ptr<LocalLiveViewSubscriberRecord> FindSubscriberRecord(const wptr<IRemoteObject> &object); 88 std::shared_ptr<LocalLiveViewSubscriberRecord> FindSubscriberRecord( 89 const sptr<IAnsSubscriberLocalLiveView> &subscriber); 90 std::shared_ptr<LocalLiveViewSubscriberRecord> CreateSubscriberRecord( 91 const sptr<IAnsSubscriberLocalLiveView> &subscriber, 92 const sptr<NotificationBundleOption> &bundleOption); 93 94 ErrCode AddSubscriberInner(const sptr<IAnsSubscriberLocalLiveView> &subscriber, 95 const sptr<NotificationBundleOption> &bundleOption); 96 ErrCode RemoveSubscriberInner(const sptr<IAnsSubscriberLocalLiveView> &subscriber, 97 const sptr<NotificationSubscribeInfo> &subscribeInfo); 98 99 void NotifyTriggerResponseInner(const sptr<Notification> ¬ification, 100 sptr<NotificationButtonOption> buttonOption); 101 bool IsSystemUser(int32_t userId); 102 103 private: 104 std::list<std::shared_ptr<LocalLiveViewSubscriberRecord>> buttonRecordList_ {}; 105 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner_ {}; 106 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_ {}; 107 sptr<IAnsSubscriberLocalLiveView> ansSubscriberProxy_ {}; 108 sptr<IRemoteObject::DeathRecipient> recipient_ {}; 109 std::shared_ptr<ffrt::queue> notificationButtonQueue_ = nullptr; 110 111 DECLARE_DELAYED_SINGLETON(NotificationLocalLiveViewSubscriberManager); 112 DISALLOW_COPY_AND_MOVE(NotificationLocalLiveViewSubscriberManager); 113 }; 114 } // namespace Notification 115 } // namespace OHOS 116 117 #endif // BND_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H