• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_MEDIA_CONTENT_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_MEDIA_CONTENT_H
18 
19 #include "notification_basic_content.h"
20 #include "parcel.h"
21 
22 namespace OHOS {
23 namespace Notification {
24 class AVToken;
25 
26 class NotificationMediaContent : public NotificationBasicContent {
27 public:
28     NotificationMediaContent() = default;
29 
30     ~NotificationMediaContent() = default;
31 
32     /**
33      * @brief Attaches a specified AVToken to this media playback notification.
34      * After an AVToken is attached, this notification can interact with the associated AVSession
35      * so that users can control media playback in this notification.
36      *
37      * @param avToken Indicates the AVToken to attach.
38      */
39     void SetAVToken(const std::shared_ptr<AVToken> &avToken);
40 
41     /**
42      * @brief Obtains the AVToken attached to this media playback notification.
43      *
44      * @return Returns the AVToken that attached to this notification.
45      */
46     const std::shared_ptr<AVToken> GetAVToken() const;
47 
48     /**
49      * @brief Sets up to three NotificationActionButton objects to be shown in this media playback notification.
50      * Before publishing this notification, you should also call
51      * NotificationRequest::addActionButton(NotificationActionButton) to add specified NotificationActionButton objects
52      * for this notification so that this method can take effect. The added action buttons will be assigned sequence
53      * numbers in the order they were added. The sequence numbers specified in the value of actions for this method
54      * must match those assigned to added action buttons. Otherwise, the notification will fail to publish. By default,
55      * the sequence number starts from 0. If you want to show three action buttons, the value of actions should be 0,
56      * 1, 2.
57      *
58      * @param actions Indicates the list of sequence numbers representing the NotificationActionButton objects
59      * to be shown in this notification.
60      */
61     void SetShownActions(const std::vector<uint32_t> &actions);
62 
63     /**
64      * @brief Obtains the list of sequence numbers representing the NotificationActionButton objects
65      * to be shown in this media playback notification.
66      *
67      * @return Returns the list of the action buttons to be shown.
68      */
69     std::vector<uint32_t> GetShownActions() const;
70 
71     /**
72      * @brief Returns a string representation of the object.
73      *
74      * @return Returns a string representation of the object.
75      */
76     std::string Dump() override;
77 
78     /**
79      * @brief Converts a NotificationMediaContent object into a Json.
80      *
81      * @param jsonObject Indicates the Json object.
82      * @return Returns true if succeed; returns false otherwise.
83      */
84     virtual bool ToJson(nlohmann::json &jsonObject) const override;
85 
86     /**
87      * @brief Creates a NotificationMediaContent object from a Json.
88      *
89      * @param jsonObject Indicates the Json object.
90      * @return Returns the NotificationMediaContent object.
91      */
92     static NotificationMediaContent *FromJson(const nlohmann::json &jsonObject);
93 
94     /**
95      * @brief Marshal a object into a Parcel.
96      * @param parcel the object into the parcel.
97      * @return Returns true if succeed; returns false otherwise.
98      */
99     virtual bool Marshalling(Parcel &parcel) const override;
100 
101     /**
102      * @brief Unmarshal object from a Parcel.
103      *
104      * @param parcel Indicates the parcel object.
105      * @return Returns the NotificationMediaContent object.
106      */
107     static NotificationMediaContent *Unmarshalling(Parcel &parcel);
108 
109 protected:
110     /**
111      * @brief Read a NotificationMediaContent object from a Parcel.
112      *
113      * @param parcel Indicates the parcel object.
114      * @return Returns true if succeed; returns false otherwise.
115      */
116     bool ReadFromParcel(Parcel &parcel) override;
117 
118 private:
119     std::shared_ptr<AVToken> avToken_ {};
120     std::vector<uint32_t> sequenceNumbers_ {};
121 };
122 }  // namespace Notification
123 }  // namespace OHOS
124 
125 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_MEDIA_CONTENT_H