• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 OHOS_NOTIFICATION_UTILS_H
17 #define OHOS_NOTIFICATION_UTILS_H
18 
19 #include "cj_ffi/cj_common_ffi.h"
20 #include "cj_lambda.h"
21 #include "notification_constant.h"
22 #include "notification_capsule.h"
23 #include "notification_slot.h"
24 #include "notification_request.h"
25 #include "notification_constant.h"
26 #include "notification_content.h"
27 #include "notification_flags.h"
28 #include "notification_helper.h"
29 #include "notification_multiline_content.h"
30 #include "notification_normal_content.h"
31 #include "notification_picture_content.h"
32 #include "notification_long_text_content.h"
33 #include "notification_local_live_view_button.h"
34 #include "notification_local_live_view_content.h"
35 #include "notification_progress.h"
36 #include "notification_time.h"
37 #include "pixel_map_impl.h"
38 
39 #include "ans_notification.h"
40 #include "singleton.h"
41 #include "securec.h"
42 
43 extern "C" {
44     struct CNotificationBasicContentV2 {
45         char* title;
46         char* text;
47         char* additionalText;
48         int64_t lockscreenPicture;
49     };
50 
51     struct CNotificationLongTextContentV2 {
52         char* title;
53         char* text;
54         char* additionalText;
55         int64_t lockscreenPicture;
56         char* longText;
57         char* briefText;
58         char* expandedTitle;
59     };
60 
61     struct CNotificationMultiLineContentV2 {
62         char* title;
63         char* text;
64         char* additionalText;
65         int64_t lockscreenPicture;
66         char* briefText;
67         char* longTitle;
68         CArrString lines;
69     };
70 
71     struct CNotificationPictureContentV2 {
72         char* title;
73         char* text;
74         char* additionalText;
75         int64_t lockscreenPicture;
76         char* briefText;
77         char* expandedTitle;
78         int64_t picture;
79     };
80 
81     struct CNotificationCapsuleV2 {
82         char* title;
83         int64_t icon;
84         char* backgroundColor;
85     };
86 
87     struct CNotificationButtonV2 {
88         CArrString names;
89         CArrI64 icons;
90     };
91 
92     struct CNotificationTimeV2 {
93         int32_t initialTime;
94         bool isCountDown;
95         bool isPaused;
96         bool isInTitle;
97     };
98 
99     struct CNotificationProgressV2 {
100         int32_t maxValue;
101         int32_t currentValue;
102         bool isPercentage;
103     };
104 
105     struct CNotificationSystemLiveViewContentV2 {
106         char* title;
107         char* text;
108         char* additionalText;
109         int64_t lockscreenPicture;
110         int32_t typeCode;
111         CNotificationCapsuleV2 capsule;
112         CNotificationButtonV2 button;
113         CNotificationTimeV2 time;
114         CNotificationProgressV2 progress;
115     };
116 
117     struct CNotificationContentV2 {
118         int32_t notificationContentType;
119         CNotificationBasicContentV2* normal;
120         CNotificationLongTextContentV2* longText;
121         CNotificationMultiLineContentV2* multiLine;
122         CNotificationPictureContentV2* picture;
123         CNotificationSystemLiveViewContentV2* systemLiveView;
124     };
125 
126     struct CDistributedOptionsV2 {
127         bool isDistributed;
128         CArrString supportDisplayDevices;
129         CArrString supportOperateDevices;
130     };
131 
132     enum class ContentTypeV2 {
133         NOTIFICATION_CONTENT_BASIC_TEXT,
134         NOTIFICATION_CONTENT_LONG_TEXT,
135         NOTIFICATION_CONTENT_PICTURE,
136         NOTIFICATION_CONTENT_CONVERSATION,
137         NOTIFICATION_CONTENT_MULTILINE,
138         NOTIFICATION_CONTENT_LOCAL_LIVE_VIEW,
139         NOTIFICATION_CONTENT_LIVE_VIEW
140     };
141 
142     enum class SlotTypeV2 {
143         UNKNOWN_TYPE = 0,
144         SOCIAL_COMMUNICATION = 1,
145         SERVICE_INFORMATION = 2,
146         CONTENT_INFORMATION = 3,
147         LIVE_VIEW = 4,
148         CUSTOMER_SERVICE = 5,
149         OTHER_TYPES = 0xFFFF,
150     };
151 
152     enum class SlotLevel {
153         LEVEL_NONE = 0,       // the notification function is disabled.
154         LEVEL_MIN = 1,        // the notifications function is disabled on the notification panel,
155                             // with no banner or prompt tone
156         LEVEL_LOW = 2,        // the notifications are displayed on the notification panel,
157                             // with no banner or prompt tone
158         LEVEL_DEFAULT = 3,    // the notification function is enabled and notifications are displayed,
159                             // on the notification panel, with a banner and a prompt tone.
160         LEVEL_HIGH = 4,       // the notifications are displayed on the notification panel,
161                             // with a banner and a prompt tone
162         LEVEL_UNDEFINED = 0xFFFF,  // the notification does not define an level.
163     };
164 
165     enum class FlagStatus {
166         NONE = 0,
167         OPEN = 1,
168         CLOSE = 2,
169     };
170 
171     struct CNotificationFlagsV2 {
172         int32_t soundEnabled = 0;
173         int32_t vibrationEnabled = 0;
174     };
175 
176     struct CNotificationRequestV2 {
177         CNotificationContentV2 notificationContent;
178         int32_t id;
179         int32_t notificationSlotType;
180         bool isOngoing;
181         bool isUnremovable;
182         int64_t deliveryTime;
183         bool tapDismissed;
184         int64_t autoDeletedTime;
185         uint32_t color;
186         bool colorEnabled;
187         bool isAlertOnce;
188         bool isStopwatch;
189         bool isCountDown;
190         bool isFloatingIcon;
191         char* label;
192         int32_t badgeIconStyle;
193         bool showDeliveryTime;
194         int64_t smallIcon;
195         int64_t largeIcon;
196         char* creatorBundleName;
197         int32_t creatorUid;
198         int32_t creatorPid;
199         int32_t creatorUserId;
200         char* hashCode;
201         char* groupName;
202         CDistributedOptionsV2* distributedOption;
203         CNotificationFlagsV2 notificationFlags;
204         uint32_t badgeNumber;
205         char* appMessageId;
206     };
207 
208     struct CArrayNotificationRequestV2 {
209         CNotificationRequestV2** head;
210         int64_t size;
211     };
212 
213     struct CNotificationSlotV2 {
214         int32_t notificationType;
215         int32_t level;
216         char* desc;
217         bool badgeFlag;
218         bool bypassDnd;
219         int32_t lockscreenVisibility;
220         bool vibrationEnabled;
221         char* sound;
222         bool lightEnabled;
223         int32_t lightColor;
224         CArrI64 vibrationValues;
225         bool enabled;
226     };
227 
228     struct CArrayNotificationSlotsV2 {
229         CNotificationSlotV2* head;
230         int64_t size;
231     };
232 
233     struct CNotificationBundleOptionV2 {
234         char* bundle;
235         int32_t uid;
236     };
237 }
238 
239 namespace OHOS {
240 namespace CJSystemapi {
241 namespace Notification {
242 constexpr int32_t STR_MAX_SIZE = 204;
243 constexpr int32_t LONG_STR_MAX_SIZE = 1028;
244 constexpr int32_t ERR_OK = 0;
245 constexpr uint32_t MAX_ICON_SIZE = 192 * 1024;
246 constexpr int32_t SHORT_STR_SIZE = 1024;
247 constexpr int32_t LONG_STR_SIZE = 3072;
248 
249 char *MallocCString(const std::string &origin);
250 bool GetNotificationSupportDisplayDevicesV2(
251     CDistributedOptionsV2* distributedOption,
252     OHOS::Notification::NotificationRequest request);
253 bool GetNotificationSupportOperateDevicesV2(
254     CDistributedOptionsV2* distributedOption,
255     OHOS::Notification::NotificationRequest request);
256 bool GetNotificationRequestDistributedOptionsV2(
257     CDistributedOptionsV2* distributedOption,
258     OHOS::Notification::NotificationRequest request);
259 bool GetNotificationRequestByNumberV2(
260     CNotificationRequestV2 cjRequest, OHOS::Notification::NotificationRequest &request);
261 bool GetNotificationRequestByStringV2(
262     CNotificationRequestV2 cjRequest, OHOS::Notification::NotificationRequest &request);
263 bool GetNotificationRequestByBoolV2(
264     CNotificationRequestV2 cjRequest, OHOS::Notification::NotificationRequest &request);
265 bool GetNotificationRequestByCustomV2(
266     CNotificationRequestV2 cjRequest, OHOS::Notification::NotificationRequest &request);
267 bool GetNotificationBasicContentDetailedV2(CNotificationBasicContentV2* contentResult,
268     std::shared_ptr<OHOS::Notification::NotificationBasicContent> basicContent);
269 bool GetNotificationBasicContentV2(CNotificationBasicContentV2* contentResult,
270     OHOS::Notification::NotificationRequest &request);
271 bool GetNotificationLongTextContentDetailedV2(CNotificationLongTextContentV2* contentResult,
272     std::shared_ptr<OHOS::Notification::NotificationLongTextContent> &longContent);
273 bool GetNotificationLongTextContentV2(CNotificationLongTextContentV2* contentResult,
274     OHOS::Notification::NotificationRequest &request);
275 bool GetNotificationPictureContentDetailedV2(CNotificationPictureContentV2* contentResult,
276     std::shared_ptr<OHOS::Notification::NotificationPictureContent> &pictureContent);
277 bool GetNotificationPictureContentV2(CNotificationPictureContentV2* contentResult,
278     OHOS::Notification::NotificationRequest &request);
279 bool GetNotificationMultiLineContentLinesV2(CNotificationMultiLineContentV2* result,
280     std::shared_ptr<OHOS::Notification::NotificationMultiLineContent> &multiLineContent);
281 bool GetNotificationMultiLineContentV2(CNotificationMultiLineContentV2* contentResult,
282     OHOS::Notification::NotificationRequest &request);
283 bool GetNotificationLocalLiveViewCapsuleV2(CNotificationSystemLiveViewContentV2* contentResult,
284     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
285 bool GetNotificationLocalLiveViewButtonV2(CNotificationSystemLiveViewContentV2* contentResult,
286     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
287 bool GetNotificationLocalLiveViewProgressV2(CNotificationSystemLiveViewContentV2* contentResult,
288     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
289 bool GetNotificationLocalLiveViewTimeV2(CNotificationSystemLiveViewContentV2* contentResult,
290     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
291 bool GetNotificationLocalLiveViewContentDetailedV2(CNotificationSystemLiveViewContentV2* contentResult,
292     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
293 bool GetNotificationLocalLiveViewContentV2(CNotificationSystemLiveViewContentV2* contentResult,
294     OHOS::Notification::NotificationRequest &request);
295 bool SlotTypeCJToCV2(const SlotTypeV2 &inType, OHOS::Notification::NotificationConstant::SlotType &outType);
296 bool SlotTypeCToCJV2(const OHOS::Notification::NotificationConstant::SlotType &inType, SlotTypeV2 &outType);
297 bool SlotLevelCToCJV2(const OHOS::Notification::NotificationSlot::NotificationLevel &inLevel, SlotLevel &outLevel);
298 bool ContentTypeCJToCV2(const ContentTypeV2 &inType, OHOS::Notification::NotificationContent::Type &outType);
299 bool ContentTypeCToCJV2(const OHOS::Notification::NotificationContent::Type &inType, ContentTypeV2 &outType);
300 bool GetNotificationSlotTypeV2(int32_t slotType, OHOS::Notification::NotificationRequest &request);
301 bool GetNotificationContentV2(CNotificationContentV2 &content, OHOS::Notification::NotificationRequest &request);
302 bool GetNotificationSmallIconV2(int64_t smallIcon, OHOS::Notification::NotificationRequest &request);
303 bool GetNotificationLargeIconV2(int64_t largeIcon, OHOS::Notification::NotificationRequest &request);
304 bool SetNotificationSlotV2(const OHOS::Notification::NotificationSlot &slot, CNotificationSlotV2 &notificationSlot);
305 void SetNotificationRequestByStringV2(const OHOS::Notification::NotificationRequest *request,
306     CNotificationRequestV2 &notificationRequest);
307 bool SetNotificationRequestByNumberV2(const OHOS::Notification::NotificationRequest *request,
308     CNotificationRequestV2 &notificationRequest);
309 void SetNotificationRequestByBoolV2(const OHOS::Notification::NotificationRequest *request,
310     CNotificationRequestV2 &notificationRequest);
311 void SetNotificationRequestByPixelMapV2(const OHOS::Notification::NotificationRequest *request,
312     CNotificationRequestV2 &notificationRequest);
313 bool SetNotificationBasicContentV2(const OHOS::Notification::NotificationBasicContent *basicContent,
314     CNotificationBasicContentV2* normal);
315 bool SetNotificationLongTextContentV2(OHOS::Notification::NotificationBasicContent *basicContent,
316     CNotificationLongTextContentV2* longText);
317 bool SetNotificationPictureContentV2(OHOS::Notification::NotificationBasicContent *basicContent,
318     CNotificationPictureContentV2* picture);
319 bool SetNotificationMultiLineContentV2(OHOS::Notification::NotificationBasicContent *basicContent,
320     CNotificationMultiLineContentV2* multiLine);
321 bool SetCapsuleV2(const OHOS::Notification::NotificationCapsule &capsule, CNotificationCapsuleV2 &cCapsule);
322 bool SetButtonV2(const OHOS::Notification::NotificationLocalLiveViewButton &button, CNotificationButtonV2 &cButton);
323 bool SetNotificationLocalLiveViewContentDetailedV2(
324     OHOS::Notification::NotificationLocalLiveViewContent *localLiveViewContent,
325     CNotificationSystemLiveViewContentV2* systemLiveView);
326 bool SetNotificationLocalLiveViewContentV2(OHOS::Notification::NotificationBasicContent *basicContent,
327     CNotificationSystemLiveViewContentV2* systemLiveView);
328 bool SetNotificationContentDetailedV2(const ContentTypeV2 &type,
329     const std::shared_ptr<OHOS::Notification::NotificationContent> &content,
330     CNotificationContentV2 &notificationContent);
331 bool SetNotificationContentV2(const std::shared_ptr<OHOS::Notification::NotificationContent> &content,
332     CNotificationContentV2 &notificationContent);
333 bool SetNotificationFlagsV2(const std::shared_ptr<OHOS::Notification::NotificationFlags> &flags,
334     CNotificationFlagsV2 &notificationFlags);
335 bool SetNotificationRequestByCustomV2(const OHOS::Notification::NotificationRequest *request,
336     CNotificationRequestV2 &notificationRequest);
337 bool SetNotificationRequestV2(const OHOS::Notification::NotificationRequest *request,
338     CNotificationRequestV2 &notificationRequest);
339 }
340 } // namespace CJSystemapi
341 } // namespace OHOS
342 
343 #endif // OHOS_NOTIFICATION_UTILS_H