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_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_H 18 19 #include "notification_request.h" 20 #include "parcel.h" 21 #include "uri.h" 22 23 namespace OHOS { 24 namespace Notification { 25 class Notification final : public Parcelable { 26 public: 27 /** 28 * @brief A constructor used to create a Notification instance by existing NotificationRequest object. 29 * 30 * @param request Indicates the existing NotificationRequest object. 31 */ 32 Notification(const sptr<NotificationRequest> &request); 33 34 /** 35 * @brief A constructor used to create a Notification instance by existing NotificationRequest object. 36 * 37 * @param deviceId Indicates the device id. 38 * @param request Indicates the existing NotificationRequest object. 39 */ 40 Notification(const std::string &deviceId, const sptr<NotificationRequest> &request); 41 42 /** 43 * @brief A constructor used to create a Notification instance by copying parameters from an existing one. 44 * 45 * @param other Indicates the Notification object. 46 */ 47 Notification(const Notification &other); 48 49 ~Notification(); 50 51 /** 52 * @brief Obtains whether to enable the notification light when a notification is received on the device, provided 53 * that this device has a notification light. 54 * 55 * @return Returns true if led light color is set. 56 */ 57 bool EnableLight() const; 58 59 /** 60 * @brief Obtains the sound enabled or not, set by ANS. 61 * 62 * @return Returns true if sound is set. 63 */ 64 bool EnableSound() const; 65 66 /** 67 * @brief Obtains the vibrate enabled or not, set by ANS. 68 * 69 * @return Returns true if vibrate style is set. 70 */ 71 bool EnableVibrate() const; 72 73 /** 74 * @brief Obtains the bundle's name which publish this notification. 75 * 76 * @return Returns the bundle's name. 77 */ 78 std::string GetBundleName() const; 79 80 /** 81 * @brief Obtains the bundle's name which create this notification. 82 * 83 * @return Returns the creator bundle name. 84 */ 85 std::string GetCreateBundle() const; 86 87 /** 88 * @brief Obtains the label of this notification. 89 * 90 * @return Returns the label. 91 */ 92 std::string GetLabel() const; 93 94 /** 95 * @brief Obtains the color of the notification light in a NotificationSlot object 96 * 97 * @return Returns the color of the notification light. 98 */ 99 int32_t GetLedLightColor() const; 100 101 /** 102 * @brief Sets the notification display effect, including whether to display this notification on the lock screen, 103 * and how it will be presented if displayed. 104 * 105 * @return Returns the display effect of this notification on the lock screen. 106 */ 107 NotificationConstant::VisiblenessType GetLockscreenVisibleness() const; 108 109 /** 110 * @brief The ID passed to setGroup(), or the override, or null. 111 * 112 * @return Returns the string of group. 113 */ 114 std::string GetGroup() const; 115 116 /** 117 * @brief Obtains the id of the notification. 118 * 119 * @return Returns the id supplied to NotificationManager::Notify(int, NotificationRequest). 120 */ 121 int32_t GetId() const; 122 123 /** 124 * @brief A key for this notification record. 125 * 126 * @return Returns a unique instance key. 127 */ 128 std::string GetKey() const; 129 130 /** 131 * @brief Obtains the notification request set by ANS. 132 * 133 * @return Returns NotificationRequest object. 134 */ 135 NotificationRequest GetNotificationRequest() const; 136 137 /** 138 * @brief Obtains the notification request point set by ANS. 139 * 140 * @return Returns NotificationRequest sptr. 141 */ 142 sptr<NotificationRequest> GetNotificationRequestPoint() const; 143 144 /** 145 * @brief Obtains the time notification was posted. 146 * 147 * @return Returns the time notificationRequest was posted. 148 */ 149 int64_t GetPostTime() const; 150 151 /** 152 * @brief Obtains the sound uri. 153 * 154 * @return Returns the sound set by ANS. 155 */ 156 Uri GetSound() const; 157 158 /** 159 * @brief Obtains the UID of the notification creator. 160 * 161 * @return Returns the UID of the notification creator. 162 */ 163 int32_t GetUid() const; 164 165 /** 166 * @brief Obtains the PID of the notification creator. 167 * 168 * @return Returns the PID of the notification creator. 169 */ 170 pid_t GetPid() const; 171 172 /** 173 * @brief Checks whether this notification is unremovable. 174 * @return Returns true if this notification is unremovable; returns false otherwise. 175 */ 176 bool IsUnremovable() const; 177 178 /** 179 * @brief Obtains the vibration style for this notifications. 180 * 181 * @return Returns the vibration style. 182 */ 183 std::vector<int64_t> GetVibrationStyle() const; 184 185 /** 186 * @brief This notification is part of a group or not. 187 * 188 * @return Returns true if this notification is part of a group. 189 */ 190 bool IsGroup() const; 191 192 /** 193 * @brief Checks whether this notification is displayed as a floating icon on top of the screen. 194 * 195 * @return Returns true if this notification is displayed as a floating icon; returns false otherwise. 196 */ 197 bool IsFloatingIcon() const; 198 199 /** 200 * @brief Obtains the remind type of a notification. 201 * @return Returns the remind type of a notification. 202 */ 203 NotificationConstant::RemindType GetRemindType() const; 204 205 /** 206 * @brief Whether to support remove allowed. 207 * @return Returns the current remove allowed status. 208 */ 209 bool IsRemoveAllowed() const; 210 211 /** 212 * @brief Gets the notification source. 213 * @return Returns the notification slot type. 214 */ 215 NotificationConstant::SourceType GetSourceType() const; 216 217 /** 218 * @brief Gets the device id of the notification source. 219 * 220 * @return Returns the device id. 221 */ 222 std::string GetDeviceId() const; 223 224 /** 225 * @brief Obtains the UserId of the notification creator. 226 * 227 * @return Returns the UserId of the notification creator. 228 */ 229 int32_t GetUserId() const; 230 231 /** 232 * @brief Obtains the instance key of the notification creator. 233 * 234 * @return Returns the instance key of the notification creator. 235 */ 236 int32_t GetInstanceKey() const; 237 238 /** 239 * @brief Obtains the UserId of the notification receiver. 240 * 241 * @return Returns the UserId of the notification receiver. 242 */ 243 int32_t GetRecvUserId() const; 244 245 /** 246 * @brief Dumps a string representation of the object. 247 * 248 * @return Returns a string representation of the object. 249 */ 250 std::string Dump() const; 251 252 /** 253 * @brief Marshals a Notification object into a Parcel. 254 * 255 * @param parcel Indicates the Parcel object for marshalling. 256 * @return Returns true if the marshalling is successful; returns false otherwise. 257 */ 258 bool Marshalling(Parcel &parcel) const; 259 260 /** 261 * @brief Unmarshals a Notification object from a Parcel. 262 * 263 * @param Indicates the Parcel object for unmarshalling. 264 * @return Returns true if the unmarshalling is successful; returns false otherwise. 265 */ 266 static Notification *Unmarshalling(Parcel &parcel); 267 268 /** 269 * @brief Obtains the update timer id. 270 * 271 * @return Returns the id of the notification update timer. 272 */ 273 uint64_t GetUpdateTimer() const; 274 275 /** 276 * @brief Obtains the update timer id. 277 * 278 * @param updateTimerId the id of the notification update timer. 279 */ 280 void SetUpdateTimer(uint64_t updateTimerId); 281 282 /** 283 * @brief Obtains the finish timer id of notification. 284 * 285 * @return Returns the id of the notification finish timer. 286 */ 287 uint64_t GetFinishTimer() const; 288 289 /** 290 * @brief Obtains the finish timer id. 291 * 292 * @param finishTimerId the id of the notification finish timer. 293 */ 294 void SetFinishTimer(uint64_t finishTimerId); 295 296 /** 297 * @brief Obtains the archive timer id of notification. 298 * 299 * @return Returns the id of the notification archive timer. 300 */ 301 uint64_t GetArchiveTimer() const; 302 303 /** 304 * @brief Obtains the archive timer id. 305 * 306 * @param archiveTimerId the id of the notification archive timer. 307 */ 308 void SetArchiveTimer(uint64_t archiveTimerId); 309 310 /** 311 * @brief Obtains the autoDeleted timer id of notification. 312 * 313 * @return Returns the id of the notification autoDeleted timer. 314 */ 315 uint64_t GetAutoDeletedTimer() const; 316 317 /** 318 * @brief Obtains the autoDeleted timer id. 319 * 320 * @param autoDeletedTimerId the id of the notification archive autoDeleted. 321 */ 322 void SetAutoDeletedTimer(uint64_t autoDeletedTimerId); 323 324 private: 325 Notification(); 326 void SetEnableSound(const bool &enable); 327 void SetEnableLight(const bool &enable); 328 void SetEnableVibration(const bool &enable); 329 void SetLedLightColor(const int32_t &color); 330 void SetLockScreenVisbleness(const NotificationConstant::VisiblenessType &visbleness); 331 void SetPostTime(const int64_t &time); 332 void SetSound(const Uri &sound); 333 void SetVibrationStyle(const std::vector<int64_t> &style); 334 void SetRemindType(const NotificationConstant::RemindType &reminType); 335 void SetRemoveAllowed(bool removeAllowed); 336 void SetSourceType(NotificationConstant::SourceType sourceType); 337 bool ReadFromParcel(Parcel &parcel); 338 void ReadFromParcelBool(Parcel &parcel); 339 void ReadFromParcelString(Parcel &parcel); 340 void ReadFromParcelInt32(Parcel &parcel); 341 void ReadFromParcelInt64(Parcel &parcel); 342 void ReadFromParcelUint64(Parcel &parcel); 343 bool ReadFromParcelParcelable(Parcel &parcel); 344 bool MarshallingBool(Parcel &parcel) const; 345 bool MarshallingString(Parcel &parcel) const; 346 bool MarshallingInt32(Parcel &parcel) const; 347 bool MarshallingInt64(Parcel &parcel) const; 348 bool MarshallingUint64(Parcel &parcel) const; 349 bool MarshallingParcelable(Parcel &parcel) const; 350 351 private: 352 bool enableSound_ {false}; 353 bool enableLight_ {false}; 354 bool enableVibration_ {false}; 355 bool isRemoveAllowed_ {true}; 356 std::string key_ {""}; 357 std::string deviceId_ {""}; 358 int32_t ledLightColor_ {0}; 359 NotificationConstant::VisiblenessType lockscreenVisibleness_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; 360 NotificationConstant::RemindType remindType_ {NotificationConstant::RemindType::NONE}; 361 NotificationConstant::SourceType sourceType_ {NotificationConstant::SourceType::TYPE_NORMAL}; 362 sptr<NotificationRequest> request_ {nullptr}; 363 int64_t postTime_ {0}; 364 uint64_t updateTimerId_ {0}; 365 uint64_t finishTimerId_ {0}; 366 uint64_t archiveTimerId_ {0}; 367 std::shared_ptr<Uri> sound_ {nullptr}; 368 std::vector<int64_t> vibrationStyle_ {}; 369 uint64_t autoDeletedTimerId_ {0}; 370 371 friend class AdvancedNotificationService; 372 friend class NotificationSlotFilter; 373 friend class DisturbFilter; 374 }; 375 } // namespace Notification 376 } // namespace OHOS 377 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_H 378