• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 time notification was posted.
139      *
140      * @return Returns the time notificationRequest was posted.
141      */
142     int64_t GetPostTime() const;
143 
144     /**
145      * @brief Obtains the sound uri.
146      *
147      * @return Returns the sound set by ANS.
148      */
149     Uri GetSound() const;
150 
151     /**
152      * @brief Obtains the UID of the notification creator.
153      *
154      * @return Returns the UID of the notification creator.
155      */
156     int32_t GetUid() const;
157 
158     /**
159      * @brief Obtains the PID of the notification creator.
160      *
161      * @return Returns the PID of the notification creator.
162      */
163     pid_t GetPid() const;
164 
165     /**
166      * @brief Checks whether this notification is unremovable.
167      * @return Returns true if this notification is unremovable; returns false otherwise.
168      */
169     bool IsUnremovable() const;
170 
171     /**
172      * @brief Obtains the vibration style for this notifications.
173      *
174      * @return Returns the vibration style.
175      */
176     std::vector<int64_t> GetVibrationStyle() const;
177 
178     /**
179      * @brief This notification is part of a group or not.
180      *
181      * @return Returns true if this notification is part of a group.
182      */
183     bool IsGroup() const;
184 
185     /**
186      * @brief Checks whether this notification is displayed as a floating icon on top of the screen.
187      *
188      * @return Returns true if this notification is displayed as a floating icon; returns false otherwise.
189      */
190     bool IsFloatingIcon() const;
191 
192     /**
193      * @brief Obtains the remind type of a notification.
194      * @return Returns the remind type of a notification.
195      */
196     NotificationConstant::RemindType GetRemindType() const;
197 
198     /**
199      * @brief Whether to support remove allowed.
200      * @return Returns the current remove allowed status.
201      */
202     bool IsRemoveAllowed() const;
203 
204     /**
205      * @brief Gets the notification source.
206      * @return Returns the notification slot type.
207      */
208     NotificationConstant::SourceType GetSourceType() const;
209 
210     /**
211      * @brief Gets the device id of the notification source.
212      *
213      * @return Returns the device id.
214      */
215     std::string GetDeviceId() const;
216 
217     /**
218      * @brief Obtains the UserId of the notification creator.
219      *
220      * @return Returns the UserId of the notification creator.
221      */
222     int32_t GetUserId() const;
223 
224     /**
225      * @brief Dumps a string representation of the object.
226      *
227      * @return Returns a string representation of the object.
228      */
229     std::string Dump() const;
230 
231     /**
232      * @brief Marshals a Notification object into a Parcel.
233      *
234      * @param parcel Indicates the Parcel object for marshalling.
235      * @return Returns true if the marshalling is successful; returns false otherwise.
236      */
237     bool Marshalling(Parcel &parcel) const;
238 
239     /**
240      * @brief Unmarshals a Notification object from a Parcel.
241      *
242      * @param Indicates the Parcel object for unmarshalling.
243      * @return Returns true if the unmarshalling is successful; returns false otherwise.
244      */
245     static Notification *Unmarshalling(Parcel &parcel);
246 
247 private:
248     Notification();
249     void SetEnableSound(const bool &enable);
250     void SetEnableLight(const bool &enable);
251     void SetEnableVibration(const bool &enable);
252     void SetLedLightColor(const int32_t &color);
253     void SetLockScreenVisbleness(const NotificationConstant::VisiblenessType &visbleness);
254     void SetPostTime(const int64_t &time);
255     void SetSound(const Uri &sound);
256     void SetVibrationStyle(const std::vector<int64_t> &style);
257     void SetRemindType(const NotificationConstant::RemindType &reminType);
258     std::string GenerateNotificationKey(
259         const std::string &deviceId, int32_t userId, int32_t uid, const std::string &label, int32_t id);
260     void SetRemoveAllowed(bool removeAllowed);
261     void SetSourceType(NotificationConstant::SourceType sourceType);
262     bool ReadFromParcel(Parcel &parcel);
263     void ReadFromParcelBool(Parcel &parcel);
264     void ReadFromParcelString(Parcel &parcel);
265     void ReadFromParcelInt32(Parcel &parcel);
266     void ReadFromParcelInt64(Parcel &parcel);
267     void ReadFromParcelParcelable(Parcel &parcel);
268     bool MarshallingBool(Parcel &parcel) const;
269     bool MarshallingString(Parcel &parcel) const;
270     bool MarshallingInt32(Parcel &parcel) const;
271     bool MarshallingInt64(Parcel &parcel) const;
272     bool MarshallingParcelable(Parcel &parcel) const;
273 
274 private:
275     bool enableSound_ {false};
276     bool enableLight_ {false};
277     bool enableVibration_ {false};
278     bool isRemoveAllowed_ {true};
279     std::string key_ {""};
280     std::string deviceId_ {""};
281     int32_t ledLightColor_ {0};
282     NotificationConstant::VisiblenessType lockscreenVisibleness_ {NotificationConstant::VisiblenessType::NO_OVERRIDE};
283     NotificationConstant::RemindType remindType_ {NotificationConstant::RemindType::NONE};
284     NotificationConstant::SourceType sourceType_ {NotificationConstant::SourceType::TYPE_NORMAL};
285     sptr<NotificationRequest> request_ {nullptr};
286     int64_t postTime_ {0};
287     std::shared_ptr<Uri> sound_ {nullptr};
288     std::vector<int64_t> vibrationStyle_ {};
289 
290     friend class AdvancedNotificationService;
291     friend class NotificationSlotFilter;
292     friend class DisturbFilter;
293 };
294 }  // namespace Notification
295 }  // namespace OHOS
296 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_H