• 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 CNotificationBasicContent {
45         char* title;
46         char* text;
47         char* additionalText;
48         int64_t lockscreenPicture;
49     };
50 
51     struct CNotificationLongTextContent {
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 CNotificationMultiLineContent {
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 CNotificationPictureContent {
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 CNotificationCapsule {
82         char* title;
83         int64_t icon;
84         char* backgroundColor;
85     };
86 
87     struct CNotificationButton {
88         CArrString names;
89         CArrI64 icons;
90     };
91 
92     struct CNotificationTime {
93         int32_t initialTime;
94         bool isCountDown;
95         bool isPaused;
96         bool isInTitle;
97     };
98 
99     struct CNotificationProgress {
100         int32_t maxValue;
101         int32_t currentValue;
102         bool isPercentage;
103     };
104 
105     struct CNotificationSystemLiveViewContent {
106         char* title;
107         char* text;
108         char* additionalText;
109         int64_t lockscreenPicture;
110         int32_t typeCode;
111         CNotificationCapsule capsule;
112         CNotificationButton button;
113         CNotificationTime time;
114         CNotificationProgress progress;
115     };
116 
117     struct CNotificationContent {
118         int32_t notificationContentType;
119         CNotificationBasicContent* normal;
120         CNotificationLongTextContent* longText;
121         CNotificationMultiLineContent* multiLine;
122         CNotificationPictureContent* picture;
123         CNotificationSystemLiveViewContent* systemLiveView;
124     };
125 
126     struct CDistributedOptions {
127         bool isDistributed;
128         CArrString supportDisplayDevices;
129         CArrString supportOperateDevices;
130     };
131 
132     enum class ContentType {
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 SlotType {
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 CNotificationFlags {
172         int32_t soundEnabled = 0;
173         int32_t vibrationEnabled = 0;
174     };
175 
176     struct CNotificationRequest {
177         CNotificationContent 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         CDistributedOptions* distributedOption;
203         CNotificationFlags notificationFlags;
204         uint32_t badgeNumber;
205         char* appMessageId;
206     };
207 
208     struct CArrayNotificationRequest {
209         CNotificationRequest** head;
210         int64_t size;
211     };
212 
213     struct CNotificationSlot {
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 CArrayNotificationSlots {
229         CNotificationSlot* head;
230         int64_t size;
231     };
232 
233     struct CNotificationBundleOption {
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 GetNotificationSupportDisplayDevices(
251     CDistributedOptions* distributedOption,
252     OHOS::Notification::NotificationRequest request);
253 bool GetNotificationSupportOperateDevices(
254     CDistributedOptions* distributedOption,
255     OHOS::Notification::NotificationRequest request);
256 bool GetNotificationRequestDistributedOptions(
257     CDistributedOptions* distributedOption,
258     OHOS::Notification::NotificationRequest request);
259 bool GetNotificationRequestByNumber(CNotificationRequest cjRequest, OHOS::Notification::NotificationRequest &request);
260 bool GetNotificationRequestByString(CNotificationRequest cjRequest, OHOS::Notification::NotificationRequest &request);
261 bool GetNotificationRequestByBool(CNotificationRequest cjRequest, OHOS::Notification::NotificationRequest &request);
262 bool GetNotificationRequestByCustom(CNotificationRequest cjRequest, OHOS::Notification::NotificationRequest &request);
263 bool GetNotificationBasicContentDetailed(CNotificationBasicContent* contentResult,
264     std::shared_ptr<OHOS::Notification::NotificationBasicContent> basicContent);
265 bool GetNotificationBasicContent(CNotificationBasicContent* contentResult,
266     OHOS::Notification::NotificationRequest &request);
267 bool GetNotificationLongTextContentDetailed(CNotificationLongTextContent* contentResult,
268     std::shared_ptr<OHOS::Notification::NotificationLongTextContent> &longContent);
269 bool GetNotificationLongTextContent(CNotificationLongTextContent* contentResult,
270     OHOS::Notification::NotificationRequest &request);
271 bool GetNotificationPictureContentDetailed(CNotificationPictureContent* contentResult,
272     std::shared_ptr<OHOS::Notification::NotificationPictureContent> &pictureContent);
273 bool GetNotificationPictureContent(CNotificationPictureContent* contentResult,
274     OHOS::Notification::NotificationRequest &request);
275 bool GetNotificationMultiLineContentLines(CNotificationMultiLineContent* result,
276     std::shared_ptr<OHOS::Notification::NotificationMultiLineContent> &multiLineContent);
277 bool GetNotificationMultiLineContent(CNotificationMultiLineContent* contentResult,
278     OHOS::Notification::NotificationRequest &request);
279 bool GetNotificationLocalLiveViewCapsule(CNotificationSystemLiveViewContent* contentResult,
280     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
281 bool GetNotificationLocalLiveViewButton(CNotificationSystemLiveViewContent* contentResult,
282     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
283 bool GetNotificationLocalLiveViewProgress(CNotificationSystemLiveViewContent* contentResult,
284     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
285 bool GetNotificationLocalLiveViewTime(CNotificationSystemLiveViewContent* contentResult,
286     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
287 bool GetNotificationLocalLiveViewContentDetailed(CNotificationSystemLiveViewContent* contentResult,
288     std::shared_ptr<OHOS::Notification::NotificationLocalLiveViewContent> &content);
289 bool GetNotificationLocalLiveViewContent(CNotificationSystemLiveViewContent* contentResult,
290     OHOS::Notification::NotificationRequest &request);
291 bool SlotTypeCJToC(const SlotType &inType, OHOS::Notification::NotificationConstant::SlotType &outType);
292 bool SlotTypeCToCJ(const OHOS::Notification::NotificationConstant::SlotType &inType, SlotType &outType);
293 bool SlotLevelCToCJ(const OHOS::Notification::NotificationSlot::NotificationLevel &inLevel, SlotLevel &outLevel);
294 bool ContentTypeCJToC(const ContentType &inType, OHOS::Notification::NotificationContent::Type &outType);
295 bool ContentTypeCToCJ(const OHOS::Notification::NotificationContent::Type &inType, ContentType &outType);
296 bool GetNotificationSlotType(int32_t slotType, OHOS::Notification::NotificationRequest &request);
297 bool GetNotificationContent(CNotificationContent &content, OHOS::Notification::NotificationRequest &request);
298 bool GetNotificationSmallIcon(int64_t smallIcon, OHOS::Notification::NotificationRequest &request);
299 bool GetNotificationLargeIcon(int64_t largeIcon, OHOS::Notification::NotificationRequest &request);
300 bool SetNotificationSlot(const OHOS::Notification::NotificationSlot &slot, CNotificationSlot &notificationSlot);
301 void SetNotificationRequestByString(const OHOS::Notification::NotificationRequest *request,
302     CNotificationRequest &notificationRequest);
303 bool SetNotificationRequestByNumber(const OHOS::Notification::NotificationRequest *request,
304     CNotificationRequest &notificationRequest);
305 void SetNotificationRequestByBool(const OHOS::Notification::NotificationRequest *request,
306     CNotificationRequest &notificationRequest);
307 void SetNotificationRequestByPixelMap(const OHOS::Notification::NotificationRequest *request,
308     CNotificationRequest &notificationRequest);
309 bool SetNotificationBasicContent(const OHOS::Notification::NotificationBasicContent *basicContent,
310     CNotificationBasicContent* normal);
311 bool SetNotificationLongTextContent(OHOS::Notification::NotificationBasicContent *basicContent,
312     CNotificationLongTextContent* longText);
313 bool SetNotificationPictureContent(OHOS::Notification::NotificationBasicContent *basicContent,
314     CNotificationPictureContent* picture);
315 bool SetNotificationMultiLineContent(OHOS::Notification::NotificationBasicContent *basicContent,
316     CNotificationMultiLineContent* multiLine);
317 bool SetCapsule(const OHOS::Notification::NotificationCapsule &capsule, CNotificationCapsule &cCapsule);
318 bool SetButton(const OHOS::Notification::NotificationLocalLiveViewButton &button, CNotificationButton &cButton);
319 bool SetNotificationLocalLiveViewContentDetailed(
320     OHOS::Notification::NotificationLocalLiveViewContent *localLiveViewContent,
321     CNotificationSystemLiveViewContent* systemLiveView);
322 bool SetNotificationLocalLiveViewContent(OHOS::Notification::NotificationBasicContent *basicContent,
323     CNotificationSystemLiveViewContent* systemLiveView);
324 bool SetNotificationContentDetailed(const ContentType &type,
325     const std::shared_ptr<OHOS::Notification::NotificationContent> &content,
326     CNotificationContent &notificationContent);
327 bool SetNotificationContent(const std::shared_ptr<OHOS::Notification::NotificationContent> &content,
328     CNotificationContent &notificationContent);
329 bool SetNotificationFlags(const std::shared_ptr<OHOS::Notification::NotificationFlags> &flags,
330     CNotificationFlags &notificationFlags);
331 bool SetNotificationRequestByCustom(const OHOS::Notification::NotificationRequest *request,
332     CNotificationRequest &notificationRequest);
333 bool SetNotificationRequest(const OHOS::Notification::NotificationRequest *request,
334     CNotificationRequest &notificationRequest);
335 }
336 } // namespace CJSystemapi
337 } // namespace OHOS
338 
339 #endif // OHOS_NOTIFICATION_UTILS_H