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