1 /* 2 * Copyright (c) 2021-2022 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_SLOT_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SLOT_H 18 19 #include "notification_content.h" 20 #include "notification_request.h" 21 #include "parcel.h" 22 #include "uri.h" 23 24 namespace OHOS { 25 namespace Notification { 26 class NotificationSlot : public Parcelable { 27 public: 28 enum NotificationLevel { 29 LEVEL_NONE, // the notification function is disabled. 30 LEVEL_MIN, // the notifications function is disabled on the notification panel, 31 // with no banner or prompt tone 32 LEVEL_LOW, // the notifications are displayed on the notification panel, 33 // with no banner or prompt tone 34 LEVEL_DEFAULT, // the notification function is enabled and notifications are displayed, 35 // on the notification panel, with a banner and a prompt tone. 36 LEVEL_HIGH, // the notifications are displayed on the notification panel, 37 // with a banner and a prompt tone 38 LEVEL_UNDEFINED, // the notification does not define an level. 39 }; 40 41 /** 42 * @brief A constructor used to initialize the type of a NotificationSlot object. 43 * 44 * @param type Specifies the type of the NotificationSlot object, 45 */ 46 NotificationSlot(NotificationConstant::SlotType type = NotificationConstant::SlotType::CUSTOM); 47 48 ~NotificationSlot(); 49 50 /** 51 * @brief Obtains whether the notification light is enabled in a NotificationSlot object, 52 * which is set by SetEnableLight(bool). 53 * 54 * @return Returns true if the notification light is enabled; returns false otherwise. 55 */ 56 bool CanEnableLight() const; 57 58 /** 59 * @brief Specifies whether to enable the notification light when a notification is received on the device, 60 * provided that this device has a notification light. 61 * @note SetEnableLight must be set before the NotificationHelper:AddNotificationSlot(NotificationSlot) method is 62 * called. Otherwise, the settings will not take effect. 63 * 64 * @param isLightEnabled Specifies whether to enable the pulse notification light. 65 * The value true indicates to enable the notification light, 66 * and the value false indicates not to enable it. 67 */ 68 void SetEnableLight(bool isLightEnabled); 69 70 /** 71 * @brief Obtains the vibration status of a NotificationSlot object, 72 * which is set by SetEnableVibration(bool). 73 * 74 * @return Returns true if vibration is enabled; returns false otherwise. 75 */ 76 bool CanVibrate() const; 77 78 /** 79 * @brief Sets whether to enable vibration when a notification is received. 80 * @note SetEnableVibration(bool) must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) 81 * method is called. Otherwise, the settings will not take effect. 82 * 83 * @param vibration Indicates whether to enable vibration when a notification is received. 84 * If the value is true, vibration is enabled; if the value is false, vibration is disabled. 85 */ 86 void SetEnableVibration(bool vibration); 87 88 /** 89 * @brief Obtains the description of a NotificationSlot object, which is set by SetDescription(string). 90 * 91 * @return Returns the description of the NotificationSlot object. 92 */ 93 std::string GetDescription() const; 94 95 /** 96 * @brief Sets the description for a NotificationSlot object. 97 * @note The setting of setDescription is effective regardless of whether a NotificationSlot object has been created 98 * by NotificationHelper::AddNotificationSlot(NotificationSlot). 99 * 100 * @param description describes the NotificationSlot object. 101 * The description is visible to users and its length must not exceed 1000 characters 102 * (the excessive part is automatically truncated). 103 */ 104 void SetDescription(const std::string &description); 105 106 /** 107 * @brief Obtains the ID of a NotificationSlot object. 108 * 109 * @return Returns the ID of the NotificationSlot object, 110 * which is set by NotificationSlot(string, string, NotificationLevel). 111 */ 112 std::string GetId() const; 113 114 /** 115 * @brief Obtains the color of the notification light in a NotificationSlot object, 116 * which is set by SetLedLightColor(int32_t). 117 * 118 * @return Returns the color of the notification light. 119 */ 120 int32_t GetLedLightColor() const; 121 122 /** 123 * @brief Sets the color of the notification light to flash when a notification is received on the device, 124 * provided that this device has a notification light and setEnableLight is called with the value true. 125 * @note SetLedLightColor must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is 126 * called. Otherwise, the settings will not take effect. 127 * 128 * @param color Indicates the color of the notification light. 129 */ 130 void SetLedLightColor(int32_t color); 131 132 /** 133 * @brief Obtains the level of a NotificationSlot object, which is set by SetLevel(NotificationLevel). 134 * 135 * @return Returns the level of the NotificationSlot object. 136 */ 137 NotificationLevel GetLevel() const; 138 139 /** 140 * @brief Sets the level of a NotificationSlot object. 141 * @note SetLevel must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is called. 142 * Otherwise, the settings will not take effect. 143 * 144 * @param level Specifies the level of the NotificationSlot object, which determines the notification display 145 * effect. The value can be LEVEL_NONE, LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, or LEVEL_HIGH. 146 */ 147 void SetLevel(NotificationLevel level); 148 149 /** 150 * @brief Sets the slotflags of a NotificationSlot object. 151 * @note SetSlotFlags must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) 152 * method is called. 153 * Otherwise, the settings will not take effect. 154 * 155 * @param slotFlags Specifies the slotflags of the NotificationSlot object, 156 * @note which determines the notification display effect. 157 * The value can be LEVEL_NONE, LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, or LEVEL_HIGH. 158 */ 159 void SetSlotFlags(uint32_t slotFlags); 160 161 /** 162 * @brief Obtains the slotflags of a NotificationSlot object, which is set by SetSlotFlags(uint32_t slotFlags). 163 * 164 * @return Returns the slotflags of the NotificationSlot object. 165 */ 166 uint32_t GetSlotFlags() const; 167 168 /** 169 * @brief Obtains the type of a NotificationSlot object, which is set by SetType(SlotType). 170 * 171 * @return Returns the Type of the NotificationSlot object. 172 */ 173 NotificationConstant::SlotType GetType() const; 174 175 /** 176 * @brief Sets the type of a NotificationSlot object. 177 * @note Settype must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is called. 178 * Otherwise, the settings will not take effect. 179 * 180 * @param type Specifies the type of the NotificationSlot object, which determines the notification remind mode. 181 * The value can be DEFAULT, SOCIAL_COMMUNICATION, SERVICE_REMINDER, CONTENT_INFORMATION, or OTHER. 182 */ 183 void SetType(NotificationConstant::SlotType type); 184 185 /** 186 * @brief Obtains the notification display effect of a NotificationSlot object on the lock screen, 187 * which is set by SetLockscreenVisibleness(int32_t). 188 * @note This method specifies different effects for displaying notifications on the lock screen in order to protect 189 * user privacy. The setting takes effect only when the lock screen notifications function is enabled for an 190 * application in system notification settings. 191 * 192 * @return Returns the notification display effect of the NotificationSlot object on the lock screen. 193 */ 194 NotificationConstant::VisiblenessType GetLockScreenVisibleness() const; 195 196 /** 197 * @brief Sets whether and how to display notifications on the lock screen. 198 * 199 * @param visibleness Specifies the notification display effect on the lock screen, which can be set to 200 * NO_OVERRIDE, PUBLIC, PRIVATE, or SECRET. 201 */ 202 void SetLockscreenVisibleness(NotificationConstant::VisiblenessType visibleness); 203 204 /** 205 * @brief Obtains the name of a NotificationSlot object. 206 * 207 * @return Returns the name of the NotificationSlot object, which is set by SetName(string). 208 */ 209 std::string GetName() const; 210 211 /** 212 * @brief Obtains the prompt tone of a NotificationSlot object, which is set by SetSound(Uri). 213 * 214 * @return Returns the prompt tone of the NotificationSlot object. 215 */ 216 Uri GetSound() const; 217 218 /** 219 * @brief Sets a prompt tone for a NotificationSlot object, which will be played after a notification is received. 220 * @note SetSound must be set before the NotificationHelper:AddNotificationSlot(NotificationSlot) method is called. 221 * Otherwise, the settings will not take effect. 222 * 223 * @param sound Specifies the path for the prompt tone. 224 */ 225 void SetSound(const Uri &sound); 226 227 /** 228 * @brief Obtains the vibration style of notifications in this NotificationSlot. 229 * 230 * @return Returns the vibration style of this NotificationSlot. 231 */ 232 std::vector<int64_t> GetVibrationStyle() const; 233 234 /** 235 * @brief Sets the vibration style for notifications in this NotificationSlot. 236 * @note If an empty array or null is passed to this method, the system then calls 237 * SetEnableVibration(bool) with the input parameter set to false. 238 * If a valid value is passed to this method, the system calls SetEnableVibration(bool) with the input 239 * parameter set to true. This method takes effect only before 240 * NotificationHelper::AddNotificationSlot(NotificationSlot) is called. 241 * 242 * @param vibration Indicates the vibration style to set. 243 */ 244 void SetVibrationStyle(const std::vector<int64_t> &vibration); 245 246 /** 247 * @brief Obtains whether DND mode is bypassed for a NotificationSlot object, 248 * which is set by EnableBypassDnd(bool). 249 * 250 * @return Returns true if DND mode is bypassed; returns false otherwise. 251 */ 252 bool IsEnableBypassDnd() const; 253 254 /** 255 * @brief Sets whether to bypass Do not disturb (DND) mode in the system. 256 * @note The setting of EnableBypassDnd takes effect only when the Allow interruptions function 257 * is enabled for an application in system notification settings. 258 * 259 * @param isBypassDnd Specifies whether to bypass DND mode for an application. 260 * If the value is true, DND mode is bypassed; 261 * if the value is false, DND mode is not bypassed. 262 */ 263 void EnableBypassDnd(bool isBypassDnd); 264 265 /** 266 * @brief Obtains the application icon badge status of a NotificationSlot object, 267 * which is set by EnableBadge(bool). 268 * 269 * @return Returns true if the application icon badge is enabled; returns false otherwise. 270 */ 271 bool IsShowBadge() const; 272 273 /** 274 * @brief Sets whether to display application icon badges (digits or dots in the corner of the application icon) 275 * on the home screen after a notification is received. 276 * @note EnableBadge must be set before the NotificationHelper:AddNotificationSlot(NotificationSlot) method is 277 * called. Otherwise, the settings will not take effect. 278 * 279 * @param isShowBadge Specifies whether to display the application icon badge. 280 * If the value is true, the application icon badge is enabled; 281 * if the value is false, the application icon badge is disabled.. 282 */ 283 void EnableBadge(bool isShowBadge); 284 285 /** 286 * @brief Set whether the application slot enable. 287 * @note If the slot enable status is false, the notification cannot be publish. 288 * 289 * @param enabled Specifies whether to enable slot. 290 */ 291 void SetEnable(bool enabled); 292 293 /** 294 * @brief Obtains whether the application slot is enabled. 295 * 296 * @return Returns true if the slot enabled; returns false otherwise. 297 */ 298 bool GetEnable() const; 299 300 /** 301 * @brief Set whether the application slot is force control. 302 * @note If the slot is force control, the notification ability is not affected by the bundle. 303 * 304 * @param isForceControl Specifies whether is force control. 305 */ 306 void SetForceControl(bool isForceControl); 307 308 /** 309 * @brief Obtains whether the application slot is force control. 310 * 311 * @return Returns true if the slot is force control; returns false otherwise. 312 */ 313 bool GetForceControl() const; 314 315 /** 316 * @brief Dumps a string representation of the object. 317 * 318 * @return Returns a string representation of the object. 319 */ 320 std::string Dump() const; 321 322 /** 323 * @brief Marshals a NotificationSlot object into a Parcel. 324 * 325 * @param parcel Indicates the Parcel object for marshalling. 326 * @return Returns true if the marshalling is successful; returns false otherwise. 327 */ 328 virtual bool Marshalling(Parcel &parcel) const override; 329 330 /** 331 * @brief Unmarshals a NotificationSlot object from a Parcel. 332 * 333 * @param parcel Indicates the Parcel object for unmarshalling. 334 * @return Returns the NotificationSlot object. 335 */ 336 static NotificationSlot *Unmarshalling(Parcel &parcel); 337 338 private: 339 /** 340 * @brief Read NotificationSlot object from a Parcel. 341 * 342 * @param parcel Indicates the Parcel object for unmarshalling. 343 * @return Returns true if succeed; returns false otherwise. 344 */ 345 bool ReadFromParcel(Parcel &parcel); 346 347 /** 348 * @brief Merge the contents of vector and output a string 349 * 350 * @param mergeVector Indicates the vector which will be merged 351 * @return Returns the string that has contents of the vector 352 */ 353 std::string MergeVectorToString(const std::vector<int64_t> &mergeVector) const; 354 355 /** 356 * @brief If string length exceed 1000 characters, the excessive part is automatically truncated. 357 * 358 * @param in Indicates the sting which will be truncated 359 * @return Returns the string that has been truncated. 360 */ 361 std::string TruncateString(const std::string &in); 362 363 /** 364 * @brief Sets the name of a NotificationSlot object. 365 * @note The setting of SetName is effective regardless of whether a NotificationSlot object has been created by 366 * NotificationHelper:AddNotificationSlot(NotificationSlot). 367 * 368 * @param name Specifies the name of the NotificationSlot object. 369 * The name is visible to users, and its length must not exceed 1000 characters 370 * (the excessive part is automatically truncated). 371 */ 372 void SetName(const std::string &name); 373 374 private: 375 std::string id_ {}; 376 std::string name_ {}; 377 bool isLightEnabled_ {false}; 378 bool isVibrationEnabled_ {false}; 379 bool isShowBadge_ {true}; 380 bool isBypassDnd_ {false}; 381 std::string description_ {}; 382 int32_t lightColor_ {0}; 383 NotificationLevel level_ {LEVEL_DEFAULT}; 384 NotificationConstant::SlotType type_ {}; 385 NotificationConstant::VisiblenessType lockScreenVisibleness_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; 386 Uri sound_; 387 std::vector<int64_t> vibrationValues_ {}; 388 bool enabled_ {true}; 389 uint32_t slotFlags_{0}; 390 bool isForceControl_ {false}; 391 392 // no object in parcel 393 static constexpr int32_t VALUE_NULL = -1; 394 // object exist in parcel 395 static constexpr int32_t VALUE_OBJECT = 1; 396 }; 397 } // namespace Notification 398 } // namespace OHOS 399 400 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_SLOT_H 401