1 /*
2  * Copyright (c) 2023 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_LIVE_VIEW_CONTENT_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LIVE_VIEW_CONTENT_H
18 
19 #include "notification_basic_content.h"
20 #include "parcel.h"
21 #include "pixel_map.h"
22 #include "want_params.h"
23 
24 namespace OHOS {
25 namespace Notification {
26 using PictureMap = std::map<std::string, std::vector<std::shared_ptr<Media::PixelMap>>>;
27 using PictureMarshallingMap = std::map<std::string, std::vector<std::string>>;
28 class NotificationLiveViewContent : public NotificationBasicContent {
29 public:
30     static const uint32_t MAX_VERSION;
31     enum class LiveViewStatus {
32         LIVE_VIEW_CREATE,
33         LIVE_VIEW_INCREMENTAL_UPDATE,
34         LIVE_VIEW_END,
35         LIVE_VIEW_FULL_UPDATE,
36         LIVE_VIEW_BUTT
37     };
38 
39     NotificationLiveViewContent() = default;
40     ~NotificationLiveViewContent() override = default;
41     /**
42      * @brief Set the status of the liveView notification.
43      *
44      * @param status Indicates the status of liveView notification.
45      */
46     void SetLiveViewStatus(const LiveViewStatus status);
47 
48     /**
49      * @brief Obtains the status of the liveView notification.
50      *
51      * @return Returns the status that attached to this notification.
52      */
53     LiveViewStatus GetLiveViewStatus() const;
54 
55     /**
56      * @brief Set the version of the liveView notification.
57      *
58      * @param status Indicates the version of liveView notification.
59      */
60     void SetVersion(uint32_t version);
61 
62     /**
63      * @brief Obtains the version of the liveView notification.
64      *
65      * @return Returns the version that attached to this notification.
66      */
67     uint32_t GetVersion() const;
68 
69     /**
70      * @brief Sets extra parameters that are stored as key-value pairs for the notification content.
71      *
72      * @param extras Indicates the WantParams object containing the extra parameters in key-value pair format.
73      */
74     void SetExtraInfo(const std::shared_ptr<AAFwk::WantParams> &extras);
75 
76     /**
77      * @brief Obtains the WantParams object set in the notification content.
78      *
79      * @return Returns the WantParams object.
80      */
81     std::shared_ptr<AAFwk::WantParams> GetExtraInfo() const;
82 
83     /**
84      * @brief Sets extra picture parameters that are stored as key-value pairs for the notification content.
85      *
86      * @param picture Indicates the picture object containing the extra picture parameters in key-value pair format.
87      */
88     void SetPicture(const PictureMap &pictureMap);
89 
90     /**
91      * @brief Obtains the picture object map in the notification content.
92      *
93      * @return Returns the picture map object.
94      */
95     PictureMap GetPicture() const;
96 
97     /**
98      * @brief Returns a string representation of the object.
99      *
100      * @return Returns a string representation of the object.
101      */
102     std::string Dump() override;
103 
104     /**
105      * @brief Converts a NotificationLiveViewContent object into a Json.
106      *
107      * @param jsonObject Indicates the Json object.
108      * @return Returns true if succeed; returns false otherwise.
109      */
110     bool ToJson(nlohmann::json &jsonObject) const override;
111 
112     /**
113      * @brief Creates a NotificationLiveViewContent object from a Json.
114      *
115      * @param jsonObject Indicates the Json object.
116      * @return Returns the NotificationLiveViewContent object.
117      */
118     static NotificationLiveViewContent *FromJson(const nlohmann::json &jsonObject);
119 
120     /**
121      * @brief Creates a picture object from a Json.
122      *
123      * @param jsonObject Indicates the Json object.
124      */
125     void ConvertPictureFromJson(const nlohmann::json &jsonObject);
126 
127     /**
128      * @brief Marshal a object into a Parcel.
129      * @param parcel the object into the parcel.
130      * @return Returns true if succeed; returns false otherwise.
131      */
132     bool Marshalling(Parcel &parcel) const override;
133 
134     /**
135      * @brief Unmarshal object from a Parcel.
136      *
137      * @param parcel Indicates the parcel object.
138      * @return Returns the NotificationLiveViewContent object.
139      */
140     static NotificationLiveViewContent *Unmarshalling(Parcel &parcel);
141 
142     bool MarshallingPictureMap(Parcel &parcel) const;
143 
144     void FillPictureMarshallingMap();
145 
146     void ClearPictureMarshallingMap();
147 
148     void ClearPictureMap();
149 
150     PictureMarshallingMap GetPictureMarshallingMap() const;
151 
152     void SetIsOnlyLocalUpdate(const bool &isOnlyLocalUpdate);
153 
154     bool GetIsOnlyLocalUpdate() const;
155 
156 protected:
157     /**
158      * @brief Read a NotificationLiveViewContent object from a Parcel.
159      *
160      * @param parcel Indicates the parcel object.
161      * @return Returns true if succeed; returns false otherwise.
162      */
163     bool ReadFromParcel(Parcel &parcel) override;
164 
165 private:
166     bool PictureToJson(nlohmann::json &jsonObject) const;
167     LiveViewStatus liveViewStatus_ {};
168     uint32_t version_ {MAX_VERSION};
169     std::shared_ptr<AAFwk::WantParams> extraInfo_ {};
170     PictureMap pictureMap_ {};
171     PictureMarshallingMap pictureMarshallingMap_ {};
172     bool isOnlyLocalUpdate_ = false;
173 };
174 }  // namespace Notification
175 }  // namespace OHOS
176 
177 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LIVE_VIEW_CONTENT_H
178