1 /*
2  * Copyright (c) 2021 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_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H
17 #define BND_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H
18 
19 #include "ans_manager_interface.h"
20 #include "ans_subscriber_stub.h"
21 #include "ans_subscriber_local_live_view_stub.h"
22 #include "notification_request.h"
23 #include "notification_sorting.h"
24 #include "notification_sorting_map.h"
25 
26 namespace OHOS {
27 namespace Notification {
28 class NotificationLocalLiveViewSubscriber {
29 public:
30     NotificationLocalLiveViewSubscriber();
31 
32     virtual ~NotificationLocalLiveViewSubscriber();
33 
34     /**
35      * @brief Called back when the subscriber is connected to the Advanced Notification Service (ANS).
36      **/
37     virtual void OnConnected() = 0;
38 
39     /**
40      * @brief Called back when the subscriber is disconnected from the ANS.
41      **/
42     virtual void OnDisconnected() = 0;
43 
44     virtual void OnResponse(int32_t notificationId, sptr<NotificationButtonOption> buttonOption) = 0;
45 
46     /**
47      * @brief Called back when connection to the ANS has died.
48      **/
49     virtual void OnDied() = 0;
50 
51 private:
52     class SubscriberLocalLiveViewImpl final : public AnsSubscriberLocalLiveViewStub {
53     public:
54         class DeathRecipient final : public IRemoteObject::DeathRecipient {
55         public:
56             DeathRecipient(SubscriberLocalLiveViewImpl &subscriberImpl);
57 
58             ~DeathRecipient();
59 
60             void OnRemoteDied(const wptr<IRemoteObject> &object) override;
61 
62         private:
63             SubscriberLocalLiveViewImpl &subscriberImpl_;
64         };
65 
66     public:
67         SubscriberLocalLiveViewImpl(NotificationLocalLiveViewSubscriber &subscriber);
~SubscriberLocalLiveViewImpl()68         ~SubscriberLocalLiveViewImpl() {};
69 
70         void OnConnected() override;
71 
72         void OnDisconnected() override;
73 
74         void OnResponse(int32_t notificationId, sptr<NotificationButtonOption> buttonOption) override;
75 
76         sptr<AnsManagerInterface> GetAnsManagerProxy();
77 
78     public:
79         NotificationLocalLiveViewSubscriber &subscriber_;
80         sptr<DeathRecipient> recipient_ {nullptr};
81     };
82 
83 private:
84     const sptr<SubscriberLocalLiveViewImpl> GetImpl() const;
85 
86 private:
87     sptr<SubscriberLocalLiveViewImpl> impl_ = nullptr;
88 
89     friend class AnsNotification;
90 };
91 }  // namespace Notification
92 }  // namespace OHOS
93 
94 #endif  // BND_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H