• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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     void SetKey(const std::string& key);
131 
132     /**
133      * @brief Obtains the notification request set by ANS.
134      *
135      * @return Returns NotificationRequest object.
136      */
137     NotificationRequest GetNotificationRequest() const;
138 
139     /**
140      * @brief Obtains the notification request point set by ANS.
141      *
142      * @return Returns NotificationRequest sptr.
143      */
144     sptr<NotificationRequest> GetNotificationRequestPoint() const;
145 
146     /**
147      * @brief Obtains the time notification was posted.
148      *
149      * @return Returns the time notificationRequest was posted.
150      */
151     int64_t GetPostTime() const;
152 
153     /**
154      * @brief Obtains the sound uri.
155      *
156      * @return Returns the sound set by ANS.
157      */
158     Uri GetSound() const;
159 
160     /**
161      * @brief Obtains the UID of the notification creator.
162      *
163      * @return Returns the UID of the notification creator.
164      */
165     int32_t GetUid() const;
166 
167     /**
168      * @brief Obtains the PID of the notification creator.
169      *
170      * @return Returns the PID of the notification creator.
171      */
172     pid_t GetPid() const;
173 
174     /**
175      * @brief Checks whether this notification is unremovable.
176      * @return Returns true if this notification is unremovable; returns false otherwise.
177      */
178     bool IsUnremovable() const;
179 
180     /**
181      * @brief Obtains the vibration style for this notifications.
182      *
183      * @return Returns the vibration style.
184      */
185     std::vector<int64_t> GetVibrationStyle() const;
186 
187     /**
188      * @brief This notification is part of a group or not.
189      *
190      * @return Returns true if this notification is part of a group.
191      */
192     bool IsGroup() const;
193 
194     /**
195      * @brief Checks whether this notification is displayed as a floating icon on top of the screen.
196      *
197      * @return Returns true if this notification is displayed as a floating icon; returns false otherwise.
198      */
199     bool IsFloatingIcon() const;
200 
201     /**
202      * @brief Obtains the remind type of a notification.
203      * @return Returns the remind type of a notification.
204      */
205     NotificationConstant::RemindType GetRemindType() const;
206 
207     /**
208      * @brief Whether to support remove allowed.
209      * @return Returns the current remove allowed status.
210      */
211     bool IsRemoveAllowed() const;
212 
213     /**
214      * @brief Gets the notification source.
215      * @return Returns the notification slot type.
216      */
217     NotificationConstant::SourceType GetSourceType() const;
218 
219     /**
220      * @brief Gets the device id of the notification source.
221      *
222      * @return Returns the device id.
223      */
224     std::string GetDeviceId() const;
225 
226     /**
227      * @brief Obtains the UserId of the notification creator.
228      *
229      * @return Returns the UserId of the notification creator.
230      */
231     int32_t GetUserId() const;
232 
233     /**
234      * @brief Obtains the instance key of the notification creator.
235      *
236      * @return Returns the instance key of the notification creator.
237      */
238     std::string GetInstanceKey() const;
239 
240     /**
241      * @brief Obtains the UserId of the notification receiver.
242      *
243      * @return Returns the UserId of the notification receiver.
244      */
245     int32_t GetRecvUserId() const;
246 
247     /**
248      * @brief Dumps a string representation of the object.
249      *
250      * @return Returns a string representation of the object.
251      */
252     std::string Dump() const;
253 
254     /**
255      * @brief Marshals a Notification object into a Parcel.
256      *
257      * @param parcel Indicates the Parcel object for marshalling.
258      * @return Returns true if the marshalling is successful; returns false otherwise.
259      */
260     bool Marshalling(Parcel &parcel) const;
261 
262     /**
263      * @brief Unmarshals a Notification object from a Parcel.
264      *
265      * @param Indicates the Parcel object for unmarshalling.
266      * @return Returns true if the unmarshalling is successful; returns false otherwise.
267      */
268     static Notification *Unmarshalling(Parcel &parcel);
269 
270     /**
271      * @brief Obtains the update timer id.
272      *
273      * @return Returns the id of the notification update timer.
274      */
275     uint64_t GetUpdateTimer() const;
276 
277     /**
278      * @brief Obtains the update timer id.
279      *
280      * @param updateTimerId the id of the notification update timer.
281      */
282     void SetUpdateTimer(uint64_t updateTimerId);
283 
284     /**
285      * @brief Obtains the finish timer id of notification.
286      *
287      * @return Returns the id of the notification finish timer.
288      */
289     uint64_t GetFinishTimer() const;
290 
291     /**
292      * @brief Obtains the finish timer id.
293      *
294      * @param finishTimerId the id of the notification finish timer.
295      */
296     void SetFinishTimer(uint64_t finishTimerId);
297 
298     /**
299      * @brief Obtains the archive timer id of notification.
300      *
301      * @return Returns the id of the notification archive timer.
302      */
303     uint64_t GetArchiveTimer() const;
304 
305     /**
306      * @brief Obtains the archive timer id.
307      *
308      * @param archiveTimerId the id of the notification archive timer.
309      */
310     void SetArchiveTimer(uint64_t archiveTimerId);
311 
312     /**
313      * @brief Obtains the autoDeleted timer id of notification.
314      *
315      * @return Returns the id of the notification autoDeleted timer.
316      */
317     uint64_t GetAutoDeletedTimer() const;
318 
319     /**
320      * @brief Obtains the autoDeleted timer id.
321      *
322      * @param autoDeletedTimerId the id of the notification archive autoDeleted.
323      */
324     void SetAutoDeletedTimer(uint64_t autoDeletedTimerId);
325 
326 private:
327     Notification();
328     void SetEnableSound(const bool &enable);
329     void SetEnableLight(const bool &enable);
330     void SetEnableVibration(const bool &enable);
331     void SetLedLightColor(const int32_t &color);
332     void SetLockScreenVisbleness(const NotificationConstant::VisiblenessType &visbleness);
333     void SetPostTime(const int64_t &time);
334     void SetSound(const Uri &sound);
335     void SetVibrationStyle(const std::vector<int64_t> &style);
336     void SetRemindType(const NotificationConstant::RemindType &reminType);
337     void SetRemoveAllowed(bool removeAllowed);
338     void SetSourceType(NotificationConstant::SourceType sourceType);
339     bool ReadFromParcel(Parcel &parcel);
340     void ReadFromParcelBool(Parcel &parcel);
341     void ReadFromParcelString(Parcel &parcel);
342     void ReadFromParcelInt32(Parcel &parcel);
343     void ReadFromParcelInt64(Parcel &parcel);
344     void ReadFromParcelUint64(Parcel &parcel);
345     bool ReadFromParcelParcelable(Parcel &parcel);
346     bool MarshallingBool(Parcel &parcel) const;
347     bool MarshallingString(Parcel &parcel) const;
348     bool MarshallingInt32(Parcel &parcel) const;
349     bool MarshallingInt64(Parcel &parcel) const;
350     bool MarshallingUint64(Parcel &parcel) const;
351     bool MarshallingParcelable(Parcel &parcel) const;
352 
353 private:
354     bool enableSound_ {false};
355     bool enableLight_ {false};
356     bool enableVibration_ {false};
357     bool isRemoveAllowed_ {true};
358     std::string key_ {""};
359     std::string deviceId_ {""};
360     int32_t ledLightColor_ {0};
361     NotificationConstant::VisiblenessType lockscreenVisibleness_ {NotificationConstant::VisiblenessType::NO_OVERRIDE};
362     NotificationConstant::RemindType remindType_ {NotificationConstant::RemindType::NONE};
363     NotificationConstant::SourceType sourceType_ {NotificationConstant::SourceType::TYPE_NORMAL};
364     sptr<NotificationRequest> request_ {nullptr};
365     int64_t postTime_ {0};
366     uint64_t updateTimerId_ {0};
367     uint64_t finishTimerId_ {0};
368     uint64_t archiveTimerId_ {0};
369     std::shared_ptr<Uri> sound_ {nullptr};
370     std::vector<int64_t> vibrationStyle_ {};
371     uint64_t autoDeletedTimerId_ {0};
372 
373     friend class AdvancedNotificationService;
374     friend class NotificationSlotFilter;
375     friend class DisturbFilter;
376 };
377 }  // namespace Notification
378 }  // namespace OHOS
379 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_H
380