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 #include "notification_request.h"
17
18 #include "ans_image_util.h"
19 #include "ans_log_wrapper.h"
20 #include "want_agent_helper.h"
21 #include "want_params_wrapper.h"
22
23 namespace OHOS {
24 namespace Notification {
25 const std::string NotificationRequest::CLASSIFICATION_ALARM {"alarm"};
26 const std::string NotificationRequest::CLASSIFICATION_CALL {"call"};
27 const std::string NotificationRequest::CLASSIFICATION_EMAIL {"email"};
28 const std::string NotificationRequest::CLASSIFICATION_ERROR {"err"};
29 const std::string NotificationRequest::CLASSIFICATION_EVENT {"event"};
30 const std::string NotificationRequest::CLASSIFICATION_MESSAGE {"msg"};
31 const std::string NotificationRequest::CLASSIFICATION_NAVIGATION {"navigation"};
32 const std::string NotificationRequest::CLASSIFICATION_PROGRESS {"progress"};
33 const std::string NotificationRequest::CLASSIFICATION_PROMO {"promo"};
34 const std::string NotificationRequest::CLASSIFICATION_RECOMMENDATION {"recommendation"};
35 const std::string NotificationRequest::CLASSIFICATION_REMINDER {"reminder"};
36 const std::string NotificationRequest::CLASSIFICATION_SERVICE {"service"};
37 const std::string NotificationRequest::CLASSIFICATION_SOCIAL {"social"};
38 const std::string NotificationRequest::CLASSIFICATION_STATUS {"status"};
39 const std::string NotificationRequest::CLASSIFICATION_SYSTEM {"sys"};
40 const std::string NotificationRequest::CLASSIFICATION_TRANSPORT {"transport"};
41
42 const uint32_t NotificationRequest::COLOR_DEFAULT {0};
43
44 const uint32_t NotificationRequest::COLOR_MASK {0xFF000000};
45 const std::size_t NotificationRequest::MAX_USER_INPUT_HISTORY {5};
46 const std::size_t NotificationRequest::MAX_ACTION_BUTTONS {3};
47 const std::size_t NotificationRequest::MAX_MESSAGE_USERS {1000};
48
NotificationRequest(int32_t notificationId)49 NotificationRequest::NotificationRequest(int32_t notificationId) : notificationId_(notificationId)
50 {
51 createTime_ = GetNowSysTime();
52 deliveryTime_ = GetNowSysTime();
53 }
54
NotificationRequest(const NotificationRequest & other)55 NotificationRequest::NotificationRequest(const NotificationRequest &other)
56 {
57 CopyBase(other);
58 CopyOther(other);
59 }
60
operator =(const NotificationRequest & other)61 NotificationRequest &NotificationRequest::operator=(const NotificationRequest &other)
62 {
63 CopyBase(other);
64 CopyOther(other);
65
66 return *this;
67 }
68
~NotificationRequest()69 NotificationRequest::~NotificationRequest()
70 {}
71
IsInProgress() const72 bool NotificationRequest::IsInProgress() const
73 {
74 return inProgress_;
75 }
76
SetInProgress(bool isOngoing)77 void NotificationRequest::SetInProgress(bool isOngoing)
78 {
79 inProgress_ = isOngoing;
80 }
81
IsUnremovable() const82 bool NotificationRequest::IsUnremovable() const
83 {
84 return unremovable_;
85 }
86
SetUnremovable(bool isUnremovable)87 void NotificationRequest::SetUnremovable(bool isUnremovable)
88 {
89 unremovable_ = isUnremovable;
90 }
91
SetBadgeNumber(uint32_t number)92 void NotificationRequest::SetBadgeNumber(uint32_t number)
93 {
94 badgeNumber_ = number;
95 }
96
GetBadgeNumber() const97 uint32_t NotificationRequest::GetBadgeNumber() const
98 {
99 return badgeNumber_;
100 }
101
SetNotificationId(int32_t notificationId)102 void NotificationRequest::SetNotificationId(int32_t notificationId)
103 {
104 notificationId_ = notificationId;
105 }
106
GetNotificationId() const107 int32_t NotificationRequest::GetNotificationId() const
108 {
109 return notificationId_;
110 }
111
SetWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> & wantAgent)112 void NotificationRequest::SetWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent)
113 {
114 wantAgent_ = wantAgent;
115 }
116
GetWantAgent() const117 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> NotificationRequest::GetWantAgent() const
118 {
119 return wantAgent_;
120 }
121
SetRemovalWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> & wantAgent)122 void NotificationRequest::SetRemovalWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent)
123 {
124 removalWantAgent_ = wantAgent;
125 }
126
GetRemovalWantAgent() const127 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> NotificationRequest::GetRemovalWantAgent() const
128 {
129 return removalWantAgent_;
130 }
131
SetMaxScreenWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> & wantAgent)132 void NotificationRequest::SetMaxScreenWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent)
133 {
134 maxScreenWantAgent_ = wantAgent;
135 }
136
GetMaxScreenWantAgent() const137 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> NotificationRequest::GetMaxScreenWantAgent() const
138 {
139 return maxScreenWantAgent_;
140 }
141
SetAdditionalData(const std::shared_ptr<AAFwk::WantParams> & extras)142 void NotificationRequest::SetAdditionalData(const std::shared_ptr<AAFwk::WantParams> &extras)
143 {
144 additionalParams_ = extras;
145 }
146
GetAdditionalData() const147 const std::shared_ptr<AAFwk::WantParams> NotificationRequest::GetAdditionalData() const
148 {
149 return additionalParams_;
150 }
151
SetDeliveryTime(int64_t deliveryTime)152 void NotificationRequest::SetDeliveryTime(int64_t deliveryTime)
153 {
154 deliveryTime_ = deliveryTime;
155 }
156
GetDeliveryTime() const157 int64_t NotificationRequest::GetDeliveryTime() const
158 {
159 return deliveryTime_;
160 }
161
IsShowDeliveryTime() const162 bool NotificationRequest::IsShowDeliveryTime() const
163 {
164 return (deliveryTime_ != 0) && showDeliveryTime_;
165 }
166
SetShowDeliveryTime(bool showDeliveryTime)167 void NotificationRequest::SetShowDeliveryTime(bool showDeliveryTime)
168 {
169 showDeliveryTime_ = showDeliveryTime;
170 }
171
AddActionButton(const std::shared_ptr<NotificationActionButton> & actionButton)172 void NotificationRequest::AddActionButton(const std::shared_ptr<NotificationActionButton> &actionButton)
173 {
174 if (!actionButton) {
175 ANS_LOGW("actionButton can not be null");
176 return;
177 }
178
179 if (actionButtons_.size() >= NotificationRequest::MAX_ACTION_BUTTONS) {
180 ANS_LOGW("three action buttons have been already added");
181 return;
182 }
183
184 actionButtons_.emplace_back(actionButton);
185 }
186
GetActionButtons() const187 const std::vector<std::shared_ptr<NotificationActionButton>> NotificationRequest::GetActionButtons() const
188 {
189 return actionButtons_;
190 }
191
ClearActionButtons()192 void NotificationRequest::ClearActionButtons()
193 {
194 actionButtons_.clear();
195 }
196
IsPermitSystemGeneratedContextualActionButtons() const197 bool NotificationRequest::IsPermitSystemGeneratedContextualActionButtons() const
198 {
199 return permitted_;
200 }
201
SetPermitSystemGeneratedContextualActionButtons(bool permitted)202 void NotificationRequest::SetPermitSystemGeneratedContextualActionButtons(bool permitted)
203 {
204 permitted_ = permitted;
205 }
206
IsAgentNotification() const207 bool NotificationRequest::IsAgentNotification() const
208 {
209 return isAgent_;
210 }
211
SetIsAgentNotification(bool isAgent)212 void NotificationRequest::SetIsAgentNotification(bool isAgent)
213 {
214 isAgent_ = isAgent;
215 }
216
AddMessageUser(const std::shared_ptr<MessageUser> & messageUser)217 void NotificationRequest::AddMessageUser(const std::shared_ptr<MessageUser> &messageUser)
218 {
219 if (!messageUser) {
220 ANS_LOGI("messageUser can not be null");
221 return;
222 }
223
224 messageUsers_.emplace_back(messageUser);
225 }
226
GetMessageUsers() const227 const std::vector<std::shared_ptr<MessageUser>> NotificationRequest::GetMessageUsers() const
228 {
229 return messageUsers_;
230 }
231
IsAlertOneTime() const232 bool NotificationRequest::IsAlertOneTime() const
233 {
234 return alertOneTime_;
235 }
236
SetAlertOneTime(bool isAlertOnce)237 void NotificationRequest::SetAlertOneTime(bool isAlertOnce)
238 {
239 alertOneTime_ = isAlertOnce;
240 }
241
SetAutoDeletedTime(int64_t deletedTime)242 void NotificationRequest::SetAutoDeletedTime(int64_t deletedTime)
243 {
244 autoDeletedTime_ = deletedTime;
245 }
246
GetAutoDeletedTime() const247 int64_t NotificationRequest::GetAutoDeletedTime() const
248 {
249 return autoDeletedTime_;
250 }
251
SetLittleIcon(const std::shared_ptr<Media::PixelMap> & littleIcon)252 void NotificationRequest::SetLittleIcon(const std::shared_ptr<Media::PixelMap> &littleIcon)
253 {
254 littleIcon_ = littleIcon;
255 }
256
GetLittleIcon() const257 const std::shared_ptr<Media::PixelMap> NotificationRequest::GetLittleIcon() const
258 {
259 return littleIcon_;
260 }
261
SetBigIcon(const std::shared_ptr<Media::PixelMap> & bigIcon)262 void NotificationRequest::SetBigIcon(const std::shared_ptr<Media::PixelMap> &bigIcon)
263 {
264 bigIcon_ = bigIcon;
265 }
266
GetBigIcon() const267 const std::shared_ptr<Media::PixelMap> NotificationRequest::GetBigIcon() const
268 {
269 return bigIcon_;
270 }
271
SetClassification(const std::string & classification)272 void NotificationRequest::SetClassification(const std::string &classification)
273 {
274 classification_ = classification;
275 }
276
GetClassification() const277 std::string NotificationRequest::GetClassification() const
278 {
279 return classification_;
280 }
281
SetColor(uint32_t color)282 void NotificationRequest::SetColor(uint32_t color)
283 {
284 color_ = color;
285 if (NotificationRequest::COLOR_DEFAULT != color_) {
286 color_ = color_ | NotificationRequest::COLOR_MASK;
287 }
288 }
289
GetColor() const290 uint32_t NotificationRequest::GetColor() const
291 {
292 return color_;
293 }
294
IsColorEnabled() const295 bool NotificationRequest::IsColorEnabled() const
296 {
297 if (!colorEnabled_) {
298 return false;
299 }
300
301 // no valid content
302 if (!notificationContent_) {
303 ANS_LOGI("no valid notification content");
304 return false;
305 }
306
307 // not a media content
308 if (NotificationContent::Type::MEDIA != notificationContentType_) {
309 ANS_LOGI("not a media notification content");
310 return false;
311 }
312
313 auto basicContent = notificationContent_->GetNotificationContent();
314 auto mediaContent = std::static_pointer_cast<NotificationMediaContent>(basicContent);
315 if (!mediaContent->GetAVToken()) {
316 ANS_LOGI("AVToken has not been attached");
317 return false;
318 }
319
320 return true;
321 }
322
SetColorEnabled(bool colorEnabled)323 void NotificationRequest::SetColorEnabled(bool colorEnabled)
324 {
325 colorEnabled_ = colorEnabled;
326 }
327
SetContent(const std::shared_ptr<NotificationContent> & content)328 void NotificationRequest::SetContent(const std::shared_ptr<NotificationContent> &content)
329 {
330 notificationContent_ = content;
331
332 if (notificationContent_) {
333 notificationContentType_ = notificationContent_->GetContentType();
334 return;
335 }
336
337 notificationContentType_ = NotificationContent::Type::NONE;
338 }
339
GetContent() const340 const std::shared_ptr<NotificationContent> NotificationRequest::GetContent() const
341 {
342 return notificationContent_;
343 }
344
GetNotificationType() const345 NotificationContent::Type NotificationRequest::GetNotificationType() const
346 {
347 return notificationContentType_;
348 }
349
IsCountdownTimer() const350 bool NotificationRequest::IsCountdownTimer() const
351 {
352 return isCountdown_;
353 }
354
SetCountdownTimer(bool isCountDown)355 void NotificationRequest::SetCountdownTimer(bool isCountDown)
356 {
357 isCountdown_ = isCountDown;
358 }
359
SetGroupAlertType(NotificationRequest::GroupAlertType type)360 void NotificationRequest::SetGroupAlertType(NotificationRequest::GroupAlertType type)
361 {
362 groupAlertType_ = type;
363 }
364
GetGroupAlertType() const365 NotificationRequest::GroupAlertType NotificationRequest::GetGroupAlertType() const
366 {
367 return groupAlertType_;
368 }
369
IsGroupOverview() const370 bool NotificationRequest::IsGroupOverview() const
371 {
372 return groupOverview_;
373 }
374
SetGroupOverview(bool overView)375 void NotificationRequest::SetGroupOverview(bool overView)
376 {
377 groupOverview_ = overView;
378 }
379
SetGroupName(const std::string & groupName)380 void NotificationRequest::SetGroupName(const std::string &groupName)
381 {
382 groupName_ = groupName;
383 }
384
GetGroupName() const385 std::string NotificationRequest::GetGroupName() const
386 {
387 return groupName_;
388 }
389
IsOnlyLocal() const390 bool NotificationRequest::IsOnlyLocal() const
391 {
392 return onlyLocal_;
393 }
394
SetOnlyLocal(bool flag)395 void NotificationRequest::SetOnlyLocal(bool flag)
396 {
397 onlyLocal_ = flag;
398 }
399
SetSettingsText(const std::string & text)400 void NotificationRequest::SetSettingsText(const std::string &text)
401 {
402 if ((NotificationContent::Type::LONG_TEXT == notificationContentType_) ||
403 (NotificationContent::Type::PICTURE == notificationContentType_)) {
404 ANS_LOGW("This method is invalid if the notification content type has been set to LONG_TEXT or PICTURE.");
405 return;
406 }
407
408 settingsText_ = text;
409 }
410
GetSettingsText() const411 std::string NotificationRequest::GetSettingsText() const
412 {
413 return settingsText_;
414 }
415
GetCreateTime() const416 int64_t NotificationRequest::GetCreateTime() const
417 {
418 return createTime_;
419 }
420
IsShowStopwatch() const421 bool NotificationRequest::IsShowStopwatch() const
422 {
423 return showStopwatch_;
424 }
425
SetShowStopwatch(bool isShow)426 void NotificationRequest::SetShowStopwatch(bool isShow)
427 {
428 showStopwatch_ = isShow;
429 }
430
SetSlotType(NotificationConstant::SlotType slotType)431 void NotificationRequest::SetSlotType(NotificationConstant::SlotType slotType)
432 {
433 slotType_ = slotType;
434 }
435
GetSlotType() const436 NotificationConstant::SlotType NotificationRequest::GetSlotType() const
437 {
438 return slotType_;
439 }
440
SetSortingKey(const std::string & key)441 void NotificationRequest::SetSortingKey(const std::string &key)
442 {
443 sortingKey_ = key;
444 }
445
GetSortingKey() const446 std::string NotificationRequest::GetSortingKey() const
447 {
448 return sortingKey_;
449 }
450
SetStatusBarText(const std::string & text)451 void NotificationRequest::SetStatusBarText(const std::string &text)
452 {
453 statusBarText_ = text;
454 }
455
GetStatusBarText() const456 std::string NotificationRequest::GetStatusBarText() const
457 {
458 return statusBarText_;
459 }
460
IsTapDismissed() const461 bool NotificationRequest::IsTapDismissed() const
462 {
463 return tapDismissed_;
464 }
465
SetTapDismissed(bool isDismissed)466 void NotificationRequest::SetTapDismissed(bool isDismissed)
467 {
468 tapDismissed_ = isDismissed;
469 }
470
SetVisibleness(NotificationConstant::VisiblenessType type)471 void NotificationRequest::SetVisibleness(NotificationConstant::VisiblenessType type)
472 {
473 visiblenessType_ = type;
474 }
475
GetVisibleness() const476 NotificationConstant::VisiblenessType NotificationRequest::GetVisibleness() const
477 {
478 return visiblenessType_;
479 }
480
SetBadgeIconStyle(NotificationRequest::BadgeStyle style)481 void NotificationRequest::SetBadgeIconStyle(NotificationRequest::BadgeStyle style)
482 {
483 badgeStyle_ = style;
484 }
485
GetBadgeIconStyle() const486 NotificationRequest::BadgeStyle NotificationRequest::GetBadgeIconStyle() const
487 {
488 return badgeStyle_;
489 }
490
SetShortcutId(const std::string & shortcutId)491 void NotificationRequest::SetShortcutId(const std::string &shortcutId)
492 {
493 shortcutId_ = shortcutId;
494 }
495
GetShortcutId() const496 std::string NotificationRequest::GetShortcutId() const
497 {
498 return shortcutId_;
499 }
500
SetFloatingIcon(bool floatingIcon)501 void NotificationRequest::SetFloatingIcon(bool floatingIcon)
502 {
503 floatingIcon_ = floatingIcon;
504 }
505
IsFloatingIcon() const506 bool NotificationRequest::IsFloatingIcon() const
507 {
508 return floatingIcon_;
509 }
510
SetProgressBar(int32_t progress,int32_t progressMax,bool indeterminate)511 void NotificationRequest::SetProgressBar(int32_t progress, int32_t progressMax, bool indeterminate)
512 {
513 progressValue_ = progress;
514 progressMax_ = progressMax;
515 progressIndeterminate_ = indeterminate;
516 }
517
GetProgressMax() const518 int32_t NotificationRequest::GetProgressMax() const
519 {
520 return progressMax_;
521 }
522
GetProgressValue() const523 int32_t NotificationRequest::GetProgressValue() const
524 {
525 return progressValue_;
526 }
527
IsProgressIndeterminate() const528 bool NotificationRequest::IsProgressIndeterminate() const
529 {
530 return progressIndeterminate_;
531 }
532
SetNotificationUserInputHistory(const std::vector<std::string> & text)533 void NotificationRequest::SetNotificationUserInputHistory(const std::vector<std::string> &text)
534 {
535 if (text.empty()) {
536 userInputHistory_.clear();
537 return;
538 }
539
540 auto vsize = std::min(NotificationRequest::MAX_USER_INPUT_HISTORY, text.size());
541 userInputHistory_.assign(text.begin(), text.begin() + vsize);
542 }
543
GetNotificationUserInputHistory() const544 std::vector<std::string> NotificationRequest::GetNotificationUserInputHistory() const
545 {
546 return userInputHistory_;
547 }
548
GetNotificationHashCode() const549 std::string NotificationRequest::GetNotificationHashCode() const
550 {
551 if (creatorBundleName_.empty() || (creatorUid_ == 0) || ownerBundleName_.empty()) {
552 return "";
553 }
554
555 return std::to_string(notificationId_) + "_" + creatorBundleName_ + "_" + std::to_string(creatorUid_) + "_" +
556 ownerBundleName_;
557 }
558
SetOwnerBundleName(const std::string & ownerName)559 void NotificationRequest::SetOwnerBundleName(const std::string &ownerName)
560 {
561 ownerBundleName_ = ownerName;
562 }
563
GetOwnerBundleName() const564 std::string NotificationRequest::GetOwnerBundleName() const
565 {
566 return ownerBundleName_;
567 }
568
SetCreatorBundleName(const std::string & creatorName)569 void NotificationRequest::SetCreatorBundleName(const std::string &creatorName)
570 {
571 creatorBundleName_ = creatorName;
572 }
573
GetCreatorBundleName() const574 std::string NotificationRequest::GetCreatorBundleName() const
575 {
576 return creatorBundleName_;
577 }
578
SetCreatorPid(pid_t pid)579 void NotificationRequest::SetCreatorPid(pid_t pid)
580 {
581 creatorPid_ = pid;
582 }
583
GetCreatorPid() const584 pid_t NotificationRequest::GetCreatorPid() const
585 {
586 return creatorPid_;
587 }
588
SetCreatorUid(int32_t uid)589 void NotificationRequest::SetCreatorUid(int32_t uid)
590 {
591 creatorUid_ = uid;
592 }
593
GetCreatorUid() const594 int32_t NotificationRequest::GetCreatorUid() const
595 {
596 return creatorUid_;
597 }
598
SetOwnerUid(int32_t uid)599 void NotificationRequest::SetOwnerUid(int32_t uid)
600 {
601 ownerUid_ = uid;
602 }
603
GetOwnerUid() const604 int32_t NotificationRequest::GetOwnerUid() const
605 {
606 return ownerUid_;
607 }
608
SetLabel(const std::string & label)609 void NotificationRequest::SetLabel(const std::string &label)
610 {
611 label_ = label;
612 }
613
GetLabel() const614 std::string NotificationRequest::GetLabel() const
615 {
616 return label_;
617 }
618
SetDistributed(bool distribute)619 void NotificationRequest::SetDistributed(bool distribute)
620 {
621 distributedOptions_.SetDistributed(distribute);
622 }
623
SetDevicesSupportDisplay(const std::vector<std::string> & devices)624 void NotificationRequest::SetDevicesSupportDisplay(const std::vector<std::string> &devices)
625 {
626 distributedOptions_.SetDevicesSupportDisplay(devices);
627 }
628
SetDevicesSupportOperate(const std::vector<std::string> & devices)629 void NotificationRequest::SetDevicesSupportOperate(const std::vector<std::string> &devices)
630 {
631 distributedOptions_.SetDevicesSupportOperate(devices);
632 }
633
GetNotificationDistributedOptions() const634 NotificationDistributedOptions NotificationRequest::GetNotificationDistributedOptions() const
635 {
636 return distributedOptions_;
637 }
638
SetCreatorUserId(int32_t userId)639 void NotificationRequest::SetCreatorUserId(int32_t userId)
640 {
641 creatorUserId_ = userId;
642 }
643
GetCreatorUserId() const644 int32_t NotificationRequest::GetCreatorUserId() const
645 {
646 return creatorUserId_;
647 }
648
SetOwnerUserId(int32_t userId)649 void NotificationRequest::SetOwnerUserId(int32_t userId)
650 {
651 ownerUserId_ = userId;
652 }
653
GetOwnerUserId() const654 int32_t NotificationRequest::GetOwnerUserId() const
655 {
656 return ownerUserId_;
657 }
658
Dump()659 std::string NotificationRequest::Dump()
660 {
661 return "NotificationRequest{ "
662 "notificationId = " + std::to_string(notificationId_) +
663 ", slotType = " + std::to_string(static_cast<int32_t>(slotType_)) +
664 ", createTime = " + std::to_string(createTime_) + ", deliveryTime = " + std::to_string(deliveryTime_) +
665 ", autoDeletedTime = " + std::to_string(autoDeletedTime_) + ", settingsText = " + settingsText_ +
666 ", creatorBundleName = " + creatorBundleName_ +
667 ", creatorPid = " + std::to_string(static_cast<int32_t>(creatorPid_)) +
668 ", creatorUid = " + std::to_string(static_cast<int32_t>(creatorUid_)) +
669 ", ownerBundleName = " + ownerBundleName_ +
670 ", ownerUid = " + std::to_string(static_cast<int32_t>(ownerUid_)) +
671 ", groupName = " + groupName_ +
672 ", statusBarText = " + statusBarText_ + ", label = " + label_ + ", shortcutId = " + shortcutId_ +
673 ", sortingKey = " + sortingKey_ +
674 ", groupAlertType = " + std::to_string(static_cast<int32_t>(groupAlertType_)) +
675 ", color = " + std::to_string(color_) + ", badgeNumber = " + std::to_string(badgeNumber_) +
676 ", visiblenessType = " + std::to_string(static_cast<int32_t>(visiblenessType_)) +
677 ", progressValue = " + std::to_string(progressValue_) + ", progressMax = " + std::to_string(progressMax_) +
678 ", badgeStyle = " + std::to_string(static_cast<int32_t>(badgeStyle_)) +
679 ", classification = " + classification_ +
680 ", notificationContentType = " + std::to_string(static_cast<int32_t>(notificationContentType_)) +
681 ", showDeliveryTime = " + (showDeliveryTime_ ? "true" : "false") +
682 ", tapDismissed = " + (tapDismissed_ ? "true" : "false") +
683 ", colorEnabled = " + (colorEnabled_ ? "true" : "false") +
684 ", alertOneTime = " + (alertOneTime_ ? "true" : "false") +
685 ", showStopwatch = " + (showStopwatch_ ? "true" : "false") +
686 ", isCountdown = " + (isCountdown_ ? "true" : "false") +
687 ", inProgress = " + (inProgress_ ? "true" : "false") +
688 ", groupOverview = " + (groupOverview_ ? "true" : "false") +
689 ", isRemoveAllowed = " + (isRemoveAllowed_ ? "true" : "false") +
690 ", progressIndeterminate = " + (progressIndeterminate_ ? "true" : "false") +
691 ", unremovable = " + (unremovable_ ? "true" : "false") +
692 ", floatingIcon = " + (floatingIcon_ ? "true" : "false") +
693 ", onlyLocal = " + (onlyLocal_ ? "true" : "false") + ", permitted = " + (permitted_ ? "true" : "false") +
694 ", isAgent = " + (isAgent_ ? "true" : "false") +
695 ", removalWantAgent = " + (removalWantAgent_ ? "not null" : "null") +
696 ", maxScreenWantAgent = " + (maxScreenWantAgent_ ? "not null" : "null") +
697 ", additionalParams = " + (additionalParams_ ? "not null" : "null") +
698 ", littleIcon = " + (littleIcon_ ? "not null" : "null") +
699 ", bigIcon = " + (bigIcon_ ? "not null" : "null") +
700 ", notificationContent = " + (notificationContent_ ? notificationContent_->Dump() : "null") +
701 ", notificationTemplate = " + (notificationTemplate_ ? "not null" : "null") +
702 ", actionButtons = " + (!actionButtons_.empty() ? actionButtons_.at(0)->Dump() : "empty") +
703 ", messageUsers = " + (!messageUsers_.empty() ? messageUsers_.at(0)->Dump() : "empty") +
704 ", userInputHistory = " + (!userInputHistory_.empty() ? userInputHistory_.at(0) : "empty") +
705 ", distributedOptions = " + distributedOptions_.Dump() +
706 ", notificationFlags = " + (notificationFlags_ ? "not null" : "null") +
707 ", creatorUserId = " + std::to_string(creatorUserId_) +
708 ", ownerUserId = " + std::to_string(ownerUserId_) +
709 ", receiverUserId = " + std::to_string(receiverUserId_) +
710 " }";
711 }
712
ToJson(nlohmann::json & jsonObject) const713 bool NotificationRequest::ToJson(nlohmann::json &jsonObject) const
714 {
715 jsonObject["version"] = 1;
716
717 jsonObject["id"] = notificationId_;
718 jsonObject["color"] = color_;
719 jsonObject["deliveryTime"] = deliveryTime_;
720 jsonObject["autoDeletedTime"] = autoDeletedTime_;
721
722 jsonObject["creatorBundleName"] = creatorBundleName_;
723 jsonObject["ownerBundleName"] = ownerBundleName_;
724 jsonObject["groupName"] = groupName_;
725 jsonObject["label"] = label_;
726 jsonObject["classification"] = classification_;
727
728 jsonObject["slotType"] = static_cast<int32_t>(slotType_);
729 jsonObject["badgeIconStyle"] = static_cast<int32_t>(badgeStyle_);
730
731 jsonObject["showDeliveryTime"] = showDeliveryTime_;
732 jsonObject["tapDismissed"] = tapDismissed_;
733 jsonObject["colorEnabled"] = colorEnabled_;
734 jsonObject["isOngoing"] = inProgress_;
735 jsonObject["isAlertOnce"] = alertOneTime_;
736 jsonObject["isStopwatch"] = showStopwatch_;
737 jsonObject["isCountdown"] = isCountdown_;
738 jsonObject["isUnremovable"] = unremovable_;
739 jsonObject["isFloatingIcon"] = floatingIcon_;
740
741 jsonObject["creatorBundleName"] = creatorBundleName_;
742 jsonObject["creatorUid"] = creatorUid_;
743 jsonObject["creatorPid"] = creatorPid_;
744 jsonObject["creatorUserId"] = creatorUserId_;
745 jsonObject["receiverUserId"] = receiverUserId_;
746
747 if (!ConvertObjectsToJson(jsonObject)) {
748 ANS_LOGE("Cannot convert objects to JSON");
749 return false;
750 }
751
752 return true;
753 }
754
FromJson(const nlohmann::json & jsonObject)755 NotificationRequest *NotificationRequest::FromJson(const nlohmann::json &jsonObject)
756 {
757 if (jsonObject.is_null() or !jsonObject.is_object()) {
758 ANS_LOGE("Invalid JSON object");
759 return nullptr;
760 }
761
762 auto pRequest = new (std::nothrow) NotificationRequest();
763 if (pRequest == nullptr) {
764 ANS_LOGE("Failed to create request instance");
765 return nullptr;
766 }
767
768 const auto &jsonEnd = jsonObject.cend();
769 if (jsonObject.find("version") != jsonEnd && jsonObject.at("version").is_number_integer()) {
770 jsonObject.at("version").get<int32_t>();
771 }
772
773 ConvertJsonToNum(pRequest, jsonObject);
774
775 ConvertJsonToString(pRequest, jsonObject);
776
777 ConvertJsonToEnum(pRequest, jsonObject);
778
779 ConvertJsonToBool(pRequest, jsonObject);
780
781 if (jsonObject.find("wantAgent") != jsonEnd && jsonObject.at("wantAgent").is_string()) {
782 auto wantAgentValue = jsonObject.at("wantAgent").get<std::string>();
783 pRequest->wantAgent_ = AbilityRuntime::WantAgent::WantAgentHelper::FromString(wantAgentValue);
784 }
785
786 if (!ConvertJsonToNotificationContent(pRequest, jsonObject)) {
787 delete pRequest;
788 pRequest = nullptr;
789 return nullptr;
790 }
791
792 if (!ConvertJsonToNotificationActionButton(pRequest, jsonObject)) {
793 delete pRequest;
794 pRequest = nullptr;
795 return nullptr;
796 }
797
798 if (jsonObject.find("extraInfo") != jsonEnd && jsonObject.at("extraInfo").is_string()) {
799 auto extraInfoStr = jsonObject.at("extraInfo").get<std::string>();
800 if (!extraInfoStr.empty()) {
801 AAFwk::WantParams params = AAFwk::WantParamWrapper::ParseWantParams(extraInfoStr);
802 pRequest->additionalParams_ = std::make_shared<AAFwk::WantParams>(params);
803 }
804 }
805
806 ConvertJsonToPixelMap(pRequest, jsonObject);
807
808 if (!ConvertJsonToNotificationDistributedOptions(pRequest, jsonObject)) {
809 delete pRequest;
810 pRequest = nullptr;
811 return nullptr;
812 }
813
814 if (!ConvertJsonToNotificationFlags(pRequest, jsonObject)) {
815 delete pRequest;
816 pRequest = nullptr;
817 return nullptr;
818 }
819
820 return pRequest;
821 }
822
Marshalling(Parcel & parcel) const823 bool NotificationRequest::Marshalling(Parcel &parcel) const
824 {
825 // write int
826 if (!parcel.WriteInt32(notificationId_)) {
827 ANS_LOGE("Failed to write notification Id");
828 return false;
829 }
830
831 if (!parcel.WriteUint32(color_)) {
832 ANS_LOGE("Failed to write color");
833 return false;
834 }
835
836 if (!parcel.WriteUint32(badgeNumber_)) {
837 ANS_LOGE("Failed to write badge number");
838 return false;
839 }
840
841 if (!parcel.WriteInt32(progressValue_)) {
842 ANS_LOGE("Failed to write progress value");
843 return false;
844 }
845
846 if (!parcel.WriteInt32(progressMax_)) {
847 ANS_LOGE("Failed to write progress max");
848 return false;
849 }
850
851 if (!parcel.WriteInt64(createTime_)) {
852 ANS_LOGE("Failed to write create time");
853 return false;
854 }
855
856 if (!parcel.WriteInt64(deliveryTime_)) {
857 ANS_LOGE("Failed to write delivery time");
858 return false;
859 }
860
861 if (!parcel.WriteInt64(autoDeletedTime_)) {
862 ANS_LOGE("Failed to write auto deleted time");
863 return false;
864 }
865
866 if (!parcel.WriteInt32(static_cast<int32_t>(creatorPid_))) {
867 ANS_LOGE("Failed to write creator pid");
868 return false;
869 }
870
871 if (!parcel.WriteInt32(static_cast<int32_t>(creatorUid_))) {
872 ANS_LOGE("Failed to write creator uid");
873 return false;
874 }
875
876 if (!parcel.WriteInt32(static_cast<int32_t>(ownerUid_))) {
877 ANS_LOGE("Failed to write owner uid");
878 return false;
879 }
880
881 if (!parcel.WriteInt32(static_cast<int32_t>(creatorUserId_))) {
882 ANS_LOGE("Failed to write creator userId");
883 return false;
884 }
885
886 if (!parcel.WriteInt32(static_cast<int32_t>(ownerUserId_))) {
887 ANS_LOGE("Failed to write owner userId");
888 return false;
889 }
890
891 if (!parcel.WriteInt32(static_cast<int32_t>(receiverUserId_))) {
892 ANS_LOGE("Failed to write receiver userId");
893 return false;
894 }
895
896 // write std::string
897 if (!parcel.WriteString(settingsText_)) {
898 ANS_LOGE("Failed to write settings text");
899 return false;
900 }
901
902 if (!parcel.WriteString(creatorBundleName_)) {
903 ANS_LOGE("Failed to write creator bundle name");
904 return false;
905 }
906
907 if (!parcel.WriteString(ownerBundleName_)) {
908 ANS_LOGE("Failed to write owner bundle name");
909 return false;
910 }
911
912 if (!parcel.WriteString(groupName_)) {
913 ANS_LOGE("Failed to write group name");
914 return false;
915 }
916
917 if (!parcel.WriteString(statusBarText_)) {
918 ANS_LOGE("Failed to write status bar text");
919 return false;
920 }
921
922 if (!parcel.WriteString(label_)) {
923 ANS_LOGE("Failed to write label");
924 return false;
925 }
926
927 if (!parcel.WriteString(shortcutId_)) {
928 ANS_LOGE("Failed to write shortcut Id");
929 return false;
930 }
931
932 if (!parcel.WriteString(sortingKey_)) {
933 ANS_LOGE("Failed to write sorting key");
934 return false;
935 }
936
937 if (!parcel.WriteString(classification_)) {
938 ANS_LOGE("Failed to write classification");
939 return false;
940 }
941
942 // write enum
943 if (!parcel.WriteInt32(static_cast<int32_t>(slotType_))) {
944 ANS_LOGE("Failed to write slot type");
945 return false;
946 }
947
948 if (!parcel.WriteInt32(static_cast<int32_t>(groupAlertType_))) {
949 ANS_LOGE("Failed to write group alert type");
950 return false;
951 }
952
953 if (!parcel.WriteInt32(static_cast<int32_t>(visiblenessType_))) {
954 ANS_LOGE("Failed to write visibleness type");
955 return false;
956 }
957
958 if (!parcel.WriteInt32(static_cast<int32_t>(badgeStyle_))) {
959 ANS_LOGE("Failed to write badge type");
960 return false;
961 }
962
963 if (!parcel.WriteInt32(static_cast<int32_t>(notificationContentType_))) {
964 ANS_LOGE("Failed to write notification content type");
965 return false;
966 }
967
968 // write bool
969 if (!parcel.WriteBool(showDeliveryTime_)) {
970 ANS_LOGE("Failed to write flag indicating whether to show delivery time");
971 return false;
972 }
973
974 if (!parcel.WriteBool(tapDismissed_)) {
975 ANS_LOGE("Failed to write flag tap dismissed");
976 return false;
977 }
978
979 if (!parcel.WriteBool(colorEnabled_)) {
980 ANS_LOGE("Failed to write flag indicating whether to enable background color");
981 return false;
982 }
983
984 if (!parcel.WriteBool(alertOneTime_)) {
985 ANS_LOGE("Failed to write flag indicating whether to have this notification alert only once");
986 return false;
987 }
988
989 if (!parcel.WriteBool(showStopwatch_)) {
990 ANS_LOGE("Failed to write flag show stop watch");
991 return false;
992 }
993
994 if (!parcel.WriteBool(isCountdown_)) {
995 ANS_LOGE("Failed to write flag indicating whether to show the notification creation time as a countdown timer");
996 return false;
997 }
998
999 if (!parcel.WriteBool(inProgress_)) {
1000 ANS_LOGE("Failed to write flag indicating whether in progress");
1001 return false;
1002 }
1003
1004 if (!parcel.WriteBool(groupOverview_)) {
1005 ANS_LOGE("Failed to write flag indicating whether to use this notification as the overview of its group");
1006 return false;
1007 }
1008
1009 if (!parcel.WriteBool(progressIndeterminate_)) {
1010 ANS_LOGE("Failed to write progress indeterminate");
1011 return false;
1012 }
1013
1014 if (!parcel.WriteBool(unremovable_)) {
1015 ANS_LOGE("Failed to write flag indicating whether unremovable");
1016 return false;
1017 }
1018
1019 if (!parcel.WriteBool(floatingIcon_)) {
1020 ANS_LOGE("Failed to write flag floating icon");
1021 return false;
1022 }
1023
1024 if (!parcel.WriteBool(onlyLocal_)) {
1025 ANS_LOGE("Failed to write flag only local");
1026 return false;
1027 }
1028
1029 if (!parcel.WriteBool(permitted_)) {
1030 ANS_LOGE("Failed to write flag indicating whether to allow the platform to \
1031 generate contextual NotificationActionButton objects");
1032 return false;
1033 }
1034
1035 if (!parcel.WriteBool(isAgent_)) {
1036 ANS_LOGE("Failed to write flag indicating whether an agent notification");
1037 return false;
1038 }
1039
1040 if (!parcel.WriteBool(isRemoveAllowed_)) {
1041 ANS_LOGE("Failed to write flag isRemoveAllowed");
1042 return false;
1043 }
1044
1045 // write objects which managed by std::shared_ptr
1046 bool valid {false};
1047
1048 valid = wantAgent_ ? true : false;
1049 if (!parcel.WriteBool(valid)) {
1050 ANS_LOGE("Failed to write the flag which indicate whether wantAgent is null");
1051 return false;
1052 }
1053
1054 if (valid) {
1055 if (!parcel.WriteParcelable(wantAgent_.get())) {
1056 ANS_LOGE("Failed to write wantAgent");
1057 return false;
1058 }
1059 }
1060
1061 valid = removalWantAgent_ ? true : false;
1062 if (!parcel.WriteBool(valid)) {
1063 ANS_LOGE("Failed to write the flag which indicate whether removalWantAgent is null");
1064 return false;
1065 }
1066
1067 if (valid) {
1068 if (!parcel.WriteParcelable(removalWantAgent_.get())) {
1069 ANS_LOGE("Failed to write removalWantAgent");
1070 return false;
1071 }
1072 }
1073
1074 valid = maxScreenWantAgent_ ? true : false;
1075 if (!parcel.WriteBool(valid)) {
1076 ANS_LOGE("Failed to write the flag which indicate whether maxScreenWantAgent is null");
1077 return false;
1078 }
1079
1080 if (valid) {
1081 if (!parcel.WriteParcelable(maxScreenWantAgent_.get())) {
1082 ANS_LOGE("Failed to write maxScreenWantAgent");
1083 return false;
1084 }
1085 }
1086
1087 valid = additionalParams_ ? true : false;
1088 if (!parcel.WriteBool(valid)) {
1089 ANS_LOGE("Failed to write the flag which indicate whether additionalParams is null");
1090 return false;
1091 }
1092
1093 if (valid) {
1094 if (!parcel.WriteParcelable(additionalParams_.get())) {
1095 ANS_LOGE("Failed to write additionalParams");
1096 return false;
1097 }
1098 }
1099
1100 valid = littleIcon_ ? true : false;
1101 if (!parcel.WriteBool(valid)) {
1102 ANS_LOGE("Failed to write the flag which indicate whether littleIcon is null");
1103 return false;
1104 }
1105
1106 if (valid) {
1107 if (!parcel.WriteParcelable(littleIcon_.get())) {
1108 ANS_LOGE("Failed to write littleIcon");
1109 return false;
1110 }
1111 }
1112
1113 valid = bigIcon_ ? true : false;
1114 if (!parcel.WriteBool(valid)) {
1115 ANS_LOGE("Failed to write the flag which indicate whether bigIcon is null");
1116 return false;
1117 }
1118
1119 if (valid) {
1120 if (!parcel.WriteParcelable(bigIcon_.get())) {
1121 ANS_LOGE("Failed to write bigIcon");
1122 return false;
1123 }
1124 }
1125
1126 valid = notificationContent_ ? true : false;
1127 if (!parcel.WriteBool(valid)) {
1128 ANS_LOGE("Failed to write the flag which indicate whether notificationContent is null");
1129 return false;
1130 }
1131
1132 if (valid) {
1133 if (!parcel.WriteParcelable(notificationContent_.get())) {
1134 ANS_LOGE("Failed to write notificationContent");
1135 return false;
1136 }
1137 }
1138
1139 // write std::vector
1140 if (!parcel.WriteUint64(actionButtons_.size())) {
1141 ANS_LOGE("Failed to write the size of actionButtons");
1142 return false;
1143 }
1144
1145 for (auto it = actionButtons_.begin(); it != actionButtons_.end(); ++it) {
1146 if (!parcel.WriteParcelable(it->get())) {
1147 ANS_LOGE("Failed to write actionButton");
1148 return false;
1149 }
1150 }
1151
1152 if (!parcel.WriteUint64(messageUsers_.size())) {
1153 ANS_LOGE("Failed to write the size of messageUsers");
1154 return false;
1155 }
1156
1157 for (auto it = messageUsers_.begin(); it != messageUsers_.end(); ++it) {
1158 if (!parcel.WriteParcelable(it->get())) {
1159 ANS_LOGE("Failed to write messageUser");
1160 return false;
1161 }
1162 }
1163
1164 if (!parcel.WriteStringVector(userInputHistory_)) {
1165 ANS_LOGE("Failed to write userInputHistory");
1166 return false;
1167 }
1168
1169 if (!parcel.WriteParcelable(&distributedOptions_)) {
1170 ANS_LOGE("Failed to write distributedOptions");
1171 return false;
1172 }
1173
1174 valid = notificationTemplate_ ? true : false;
1175 if (!parcel.WriteBool(valid)) {
1176 ANS_LOGE("Failed to write the flag which indicate whether publicNotification is null");
1177 return false;
1178 }
1179
1180 if (valid) {
1181 if (!parcel.WriteParcelable(notificationTemplate_.get())) {
1182 ANS_LOGE("Failed to write notificationTemplate");
1183 return false;
1184 }
1185 }
1186
1187 valid = notificationFlags_ ? true : false;
1188 if (!parcel.WriteBool(valid)) {
1189 ANS_LOGE("Failed to write flags for the notification");
1190 return false;
1191 }
1192
1193 if (valid) {
1194 if (!parcel.WriteParcelable(notificationFlags_.get())) {
1195 ANS_LOGE("Failed to write notification flags");
1196 return false;
1197 }
1198 }
1199
1200 return true;
1201 }
1202
Unmarshalling(Parcel & parcel)1203 NotificationRequest *NotificationRequest::Unmarshalling(Parcel &parcel)
1204 {
1205 auto objptr = new (std::nothrow) NotificationRequest();
1206 if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
1207 delete objptr;
1208 objptr = nullptr;
1209 }
1210
1211 return objptr;
1212 }
1213
ReadFromParcel(Parcel & parcel)1214 bool NotificationRequest::ReadFromParcel(Parcel &parcel)
1215 {
1216 notificationId_ = parcel.ReadInt32();
1217 color_ = parcel.ReadUint32();
1218 badgeNumber_ = parcel.ReadUint32();
1219 progressValue_ = parcel.ReadInt32();
1220 progressMax_ = parcel.ReadInt32();
1221 createTime_ = parcel.ReadInt64();
1222 deliveryTime_ = parcel.ReadInt64();
1223 autoDeletedTime_ = parcel.ReadInt64();
1224
1225 creatorPid_ = static_cast<pid_t>(parcel.ReadInt32());
1226 creatorUid_ = parcel.ReadInt32();
1227 ownerUid_ = parcel.ReadInt32();
1228 creatorUserId_ = parcel.ReadInt32();
1229 ownerUserId_ = parcel.ReadInt32();
1230 receiverUserId_ = parcel.ReadInt32();
1231
1232 if (!parcel.ReadString(settingsText_)) {
1233 ANS_LOGE("Failed to read settings text");
1234 return false;
1235 }
1236
1237 if (!parcel.ReadString(creatorBundleName_)) {
1238 ANS_LOGE("Failed to read creator bundle name");
1239 return false;
1240 }
1241
1242 if (!parcel.ReadString(ownerBundleName_)) {
1243 ANS_LOGE("Failed to read owner bundle name");
1244 return false;
1245 }
1246
1247 if (!parcel.ReadString(groupName_)) {
1248 ANS_LOGE("Failed to read group name");
1249 return false;
1250 }
1251
1252 if (!parcel.ReadString(statusBarText_)) {
1253 ANS_LOGE("Failed to read status bar text");
1254 return false;
1255 }
1256
1257 if (!parcel.ReadString(label_)) {
1258 ANS_LOGE("Failed to read label");
1259 return false;
1260 }
1261
1262 if (!parcel.ReadString(shortcutId_)) {
1263 ANS_LOGE("Failed to read shortcut Id");
1264 return false;
1265 }
1266
1267 if (!parcel.ReadString(sortingKey_)) {
1268 ANS_LOGE("Failed to read sorting key");
1269 return false;
1270 }
1271
1272 if (!parcel.ReadString(classification_)) {
1273 ANS_LOGE("Failed to read classification");
1274 return false;
1275 }
1276
1277 slotType_ = static_cast<NotificationConstant::SlotType>(parcel.ReadInt32());
1278 groupAlertType_ = static_cast<NotificationRequest::GroupAlertType>(parcel.ReadInt32());
1279 visiblenessType_ = static_cast<NotificationConstant::VisiblenessType>(parcel.ReadInt32());
1280 badgeStyle_ = static_cast<NotificationRequest::BadgeStyle>(parcel.ReadInt32());
1281 notificationContentType_ = static_cast<NotificationContent::Type>(parcel.ReadInt32());
1282
1283 showDeliveryTime_ = parcel.ReadBool();
1284 tapDismissed_ = parcel.ReadBool();
1285 colorEnabled_ = parcel.ReadBool();
1286 alertOneTime_ = parcel.ReadBool();
1287 showStopwatch_ = parcel.ReadBool();
1288 isCountdown_ = parcel.ReadBool();
1289 inProgress_ = parcel.ReadBool();
1290 groupOverview_ = parcel.ReadBool();
1291 progressIndeterminate_ = parcel.ReadBool();
1292 unremovable_ = parcel.ReadBool();
1293 floatingIcon_ = parcel.ReadBool();
1294 onlyLocal_ = parcel.ReadBool();
1295 permitted_ = parcel.ReadBool();
1296 isAgent_ = parcel.ReadBool();
1297 isRemoveAllowed_ = parcel.ReadBool();
1298
1299 bool valid {false};
1300
1301 valid = parcel.ReadBool();
1302 if (valid) {
1303 wantAgent_ = std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>(
1304 parcel.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>());
1305 if (!wantAgent_) {
1306 ANS_LOGE("Failed to read wantAgent");
1307 return false;
1308 }
1309 }
1310
1311 valid = parcel.ReadBool();
1312 if (valid) {
1313 removalWantAgent_ = std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>(
1314 parcel.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>());
1315 if (!removalWantAgent_) {
1316 ANS_LOGE("Failed to read removalWantAgent");
1317 return false;
1318 }
1319 }
1320
1321 valid = parcel.ReadBool();
1322 if (valid) {
1323 maxScreenWantAgent_ = std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>(
1324 parcel.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>());
1325 if (!maxScreenWantAgent_) {
1326 ANS_LOGE("Failed to read maxScreenWantAgent");
1327 return false;
1328 }
1329 }
1330
1331 valid = parcel.ReadBool();
1332 if (valid) {
1333 additionalParams_ = std::shared_ptr<AAFwk::WantParams>(parcel.ReadParcelable<AAFwk::WantParams>());
1334 if (!additionalParams_) {
1335 ANS_LOGE("Failed to read additionalParams");
1336 return false;
1337 }
1338 }
1339
1340 valid = parcel.ReadBool();
1341 if (valid) {
1342 littleIcon_ = std::shared_ptr<Media::PixelMap>(parcel.ReadParcelable<Media::PixelMap>());
1343 if (!littleIcon_) {
1344 ANS_LOGE("Failed to read littleIcon");
1345 return false;
1346 }
1347 }
1348
1349 valid = parcel.ReadBool();
1350 if (valid) {
1351 bigIcon_ = std::shared_ptr<Media::PixelMap>(parcel.ReadParcelable<Media::PixelMap>());
1352 if (!bigIcon_) {
1353 ANS_LOGE("Failed to read bigIcon");
1354 return false;
1355 }
1356 }
1357
1358 valid = parcel.ReadBool();
1359 if (valid) {
1360 notificationContent_ = std::shared_ptr<NotificationContent>(parcel.ReadParcelable<NotificationContent>());
1361 if (!notificationContent_) {
1362 ANS_LOGE("Failed to read notificationContent");
1363 return false;
1364 }
1365 }
1366
1367 auto vsize = parcel.ReadUint64();
1368 vsize = (vsize < NotificationRequest::MAX_ACTION_BUTTONS) ? vsize : NotificationRequest::MAX_ACTION_BUTTONS;
1369 for (uint64_t it = 0; it < vsize; ++it) {
1370 auto member = parcel.ReadParcelable<NotificationActionButton>();
1371 if (member == nullptr) {
1372 actionButtons_.clear();
1373 ANS_LOGE("Failed to read actionButton");
1374 return false;
1375 }
1376
1377 actionButtons_.emplace_back(member);
1378 }
1379
1380 vsize = parcel.ReadUint64();
1381 vsize = (vsize < NotificationRequest::MAX_MESSAGE_USERS) ? vsize : NotificationRequest::MAX_MESSAGE_USERS;
1382 for (uint64_t it = 0; it < vsize; ++it) {
1383 auto member = std::shared_ptr<MessageUser>(parcel.ReadParcelable<MessageUser>());
1384 if (member == nullptr) {
1385 ANS_LOGE("Failed to read messageUser");
1386 messageUsers_.clear();
1387 return false;
1388 }
1389
1390 messageUsers_.emplace_back(member);
1391 }
1392
1393 if (!parcel.ReadStringVector(&userInputHistory_)) {
1394 ANS_LOGE("Failed to read userInputHistory");
1395 return false;
1396 }
1397
1398 auto pOpt = parcel.ReadParcelable<NotificationDistributedOptions>();
1399 if (pOpt == nullptr) {
1400 ANS_LOGE("Failed to read distributedOptions");
1401 return false;
1402 }
1403 distributedOptions_ = *pOpt;
1404 delete pOpt;
1405 pOpt = nullptr;
1406
1407 valid = parcel.ReadBool();
1408 if (valid) {
1409 notificationTemplate_ = std::shared_ptr<NotificationTemplate>(parcel.ReadParcelable<NotificationTemplate>());
1410 if (!notificationTemplate_) {
1411 ANS_LOGE("Failed to read notificationTemplate");
1412 return false;
1413 }
1414 }
1415
1416 valid = parcel.ReadBool();
1417 if (valid) {
1418 notificationFlags_ = std::shared_ptr<NotificationFlags>(parcel.ReadParcelable<NotificationFlags>());
1419 if (!notificationFlags_) {
1420 ANS_LOGE("Failed to read notificationFlags");
1421 return false;
1422 }
1423 }
1424
1425 return true;
1426 }
1427
GetNowSysTime()1428 int64_t NotificationRequest::GetNowSysTime()
1429 {
1430 std::chrono::time_point<std::chrono::system_clock> nowSys = std::chrono::system_clock::now();
1431 auto epoch = nowSys.time_since_epoch();
1432 auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
1433 int64_t duration = value.count();
1434 return duration;
1435 }
1436
SetTemplate(const std::shared_ptr<NotificationTemplate> & templ)1437 void NotificationRequest::SetTemplate(const std::shared_ptr<NotificationTemplate> &templ)
1438 {
1439 notificationTemplate_ = templ;
1440 }
1441
GetTemplate() const1442 std::shared_ptr<NotificationTemplate> NotificationRequest::GetTemplate() const
1443 {
1444 return notificationTemplate_;
1445 }
1446
SetFlags(const std::shared_ptr<NotificationFlags> & flags)1447 void NotificationRequest::SetFlags(const std::shared_ptr<NotificationFlags> &flags)
1448 {
1449 notificationFlags_ = flags;
1450 }
1451
GetFlags() const1452 std::shared_ptr<NotificationFlags> NotificationRequest::GetFlags() const
1453 {
1454 return notificationFlags_;
1455 }
1456
SetReceiverUserId(int32_t userId)1457 void NotificationRequest::SetReceiverUserId(int32_t userId)
1458 {
1459 receiverUserId_ = userId;
1460 }
1461
GetReceiverUserId() const1462 int32_t NotificationRequest::GetReceiverUserId() const
1463 {
1464 return receiverUserId_;
1465 }
1466
IsRemoveAllowed() const1467 bool NotificationRequest::IsRemoveAllowed() const
1468 {
1469 return isRemoveAllowed_;
1470 }
1471
SetRemoveAllowed(bool isRemoveAllowed)1472 void NotificationRequest::SetRemoveAllowed(bool isRemoveAllowed)
1473 {
1474 isRemoveAllowed_ = isRemoveAllowed;
1475 }
1476
CopyBase(const NotificationRequest & other)1477 void NotificationRequest::CopyBase(const NotificationRequest &other)
1478 {
1479 this->notificationId_ = other.notificationId_;
1480 this->color_ = other.color_;
1481 this->badgeNumber_ = other.badgeNumber_;
1482 this->progressValue_ = other.progressValue_;
1483 this->progressMax_ = other.progressMax_;
1484 this->createTime_ = other.createTime_;
1485 this->deliveryTime_ = other.deliveryTime_;
1486 this->autoDeletedTime_ = other.autoDeletedTime_;
1487
1488 this->creatorPid_ = other.creatorPid_;
1489 this->creatorUid_ = other.creatorUid_;
1490 this->ownerUid_ = other.ownerUid_;
1491 this->creatorUserId_ = other.creatorUserId_;
1492 this->ownerUserId_ = other.ownerUserId_;
1493 this->receiverUserId_ = other.receiverUserId_;
1494 this->isAgent_ = other.isAgent_;
1495 this->isRemoveAllowed_ = other.isRemoveAllowed_;
1496
1497 this->slotType_ = other.slotType_;
1498 this->settingsText_ = other.settingsText_;
1499 this->creatorBundleName_ = other.creatorBundleName_;
1500 this->ownerBundleName_ = other.ownerBundleName_;
1501 this->groupName_ = other.groupName_;
1502 this->statusBarText_ = other.statusBarText_;
1503 this->label_ = other.label_;
1504 this->shortcutId_ = other.shortcutId_;
1505 this->sortingKey_ = other.sortingKey_;
1506 this->classification_ = other.classification_;
1507
1508 this->groupAlertType_ = other.groupAlertType_;
1509 this->visiblenessType_ = other.visiblenessType_;
1510 this->badgeStyle_ = other.badgeStyle_;
1511 this->notificationContentType_ = other.notificationContentType_;
1512 }
1513
CopyOther(const NotificationRequest & other)1514 void NotificationRequest::CopyOther(const NotificationRequest &other)
1515 {
1516 this->showDeliveryTime_ = other.showDeliveryTime_;
1517 this->tapDismissed_ = other.tapDismissed_;
1518 this->colorEnabled_ = other.colorEnabled_;
1519 this->alertOneTime_ = other.alertOneTime_;
1520 this->showStopwatch_ = other.showStopwatch_;
1521 this->isCountdown_ = other.isCountdown_;
1522 this->inProgress_ = other.inProgress_;
1523 this->groupOverview_ = other.groupOverview_;
1524 this->progressIndeterminate_ = other.progressIndeterminate_;
1525 this->unremovable_ = other.unremovable_;
1526 this->floatingIcon_ = other.floatingIcon_;
1527 this->onlyLocal_ = other.onlyLocal_;
1528 this->permitted_ = other.permitted_;
1529
1530 this->wantAgent_ = other.wantAgent_;
1531 this->removalWantAgent_ = other.removalWantAgent_;
1532 this->maxScreenWantAgent_ = other.maxScreenWantAgent_;
1533 this->additionalParams_ = other.additionalParams_;
1534 this->littleIcon_ = other.littleIcon_;
1535 this->bigIcon_ = other.bigIcon_;
1536 this->notificationContent_ = other.notificationContent_;
1537
1538 this->actionButtons_ = other.actionButtons_;
1539 this->messageUsers_ = other.messageUsers_;
1540 this->userInputHistory_ = other.userInputHistory_;
1541
1542 this->distributedOptions_ = other.distributedOptions_;
1543
1544 this->notificationTemplate_ = other.notificationTemplate_;
1545 this->notificationFlags_ = other.notificationFlags_;
1546 }
1547
ConvertObjectsToJson(nlohmann::json & jsonObject) const1548 bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const
1549 {
1550 jsonObject["wantAgent"] = wantAgent_ ? AbilityRuntime::WantAgent::WantAgentHelper::ToString(wantAgent_) : "";
1551
1552 nlohmann::json contentObj;
1553 if (notificationContent_) {
1554 if (!NotificationJsonConverter::ConvertToJson(notificationContent_.get(), contentObj)) {
1555 ANS_LOGE("Cannot convert notificationContent to JSON");
1556 return false;
1557 }
1558 }
1559 jsonObject["content"] = contentObj;
1560
1561 nlohmann::json buttonsArr = nlohmann::json::array();
1562 for (auto &btn : actionButtons_) {
1563 if (!btn) {
1564 continue;
1565 }
1566
1567 nlohmann::json btnObj;
1568 if (!NotificationJsonConverter::ConvertToJson(btn.get(), btnObj)) {
1569 ANS_LOGE("Cannot convert actionButton to JSON");
1570 return false;
1571 }
1572
1573 buttonsArr.emplace_back(btnObj);
1574 }
1575 jsonObject["actionButtons"] = buttonsArr;
1576
1577 std::string extraInfoStr;
1578 if (additionalParams_) {
1579 AAFwk::WantParamWrapper wWrapper(*additionalParams_);
1580 extraInfoStr = wWrapper.ToString();
1581 }
1582 jsonObject["extraInfo"] = extraInfoStr;
1583
1584 jsonObject["smallIcon"] = AnsImageUtil::PackImage(littleIcon_);
1585 jsonObject["largeIcon"] = AnsImageUtil::PackImage(bigIcon_);
1586
1587 nlohmann::json optObj;
1588 if (!NotificationJsonConverter::ConvertToJson(&distributedOptions_, optObj)) {
1589 ANS_LOGE("Cannot convert distributedOptions to JSON");
1590 return false;
1591 }
1592 jsonObject["distributedOptions"] = optObj;
1593
1594 if (notificationFlags_) {
1595 nlohmann::json flagsObj;
1596 if (!NotificationJsonConverter::ConvertToJson(notificationFlags_.get(), flagsObj)) {
1597 ANS_LOGE("Cannot convert notificationFlags to JSON");
1598 return false;
1599 }
1600 jsonObject["notificationFlags"] = flagsObj;
1601 }
1602
1603 return true;
1604 }
1605
ConvertJsonToNum(NotificationRequest * target,const nlohmann::json & jsonObject)1606 void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nlohmann::json &jsonObject)
1607 {
1608 if (target == nullptr) {
1609 ANS_LOGE("Invalid input parameter");
1610 return;
1611 }
1612
1613 const auto &jsonEnd = jsonObject.cend();
1614
1615 if (jsonObject.find("id") != jsonEnd && jsonObject.at("id").is_number_integer()) {
1616 target->notificationId_ = jsonObject.at("id").get<int32_t>();
1617 }
1618
1619 if (jsonObject.find("color") != jsonEnd && jsonObject.at("color").is_number_integer()) {
1620 target->color_ = jsonObject.at("color").get<uint32_t>();
1621 }
1622
1623 if (jsonObject.find("deliveryTime") != jsonEnd && jsonObject.at("deliveryTime").is_number_integer()) {
1624 target->deliveryTime_ = jsonObject.at("deliveryTime").get<int64_t>();
1625 }
1626
1627 if (jsonObject.find("autoDeletedTime") != jsonEnd && jsonObject.at("autoDeletedTime").is_number_integer()) {
1628 target->autoDeletedTime_ = jsonObject.at("autoDeletedTime").get<int64_t>();
1629 }
1630
1631 if (jsonObject.find("creatorUid") != jsonEnd && jsonObject.at("creatorUid").is_number_integer()) {
1632 target->creatorUid_ = jsonObject.at("creatorUid").get<int32_t>();
1633 }
1634
1635 if (jsonObject.find("creatorPid") != jsonEnd && jsonObject.at("creatorPid").is_number_integer()) {
1636 target->creatorPid_ = jsonObject.at("creatorPid").get<int32_t>();
1637 }
1638
1639 if (jsonObject.find("creatorUserId") != jsonEnd && jsonObject.at("creatorUserId").is_number_integer()) {
1640 target->creatorUserId_ = jsonObject.at("creatorUserId").get<int32_t>();
1641 }
1642
1643 if (jsonObject.find("receiverUserId") != jsonEnd && jsonObject.at("receiverUserId").is_number_integer()) {
1644 target->receiverUserId_ = jsonObject.at("receiverUserId").get<int32_t>();
1645 }
1646
1647 if (jsonObject.find("badgeNumber") != jsonEnd && jsonObject.at("badgeNumber").is_number_integer()) {
1648 target->badgeNumber_ = jsonObject.at("badgeNumber").get<uint32_t>();
1649 }
1650 }
1651
ConvertJsonToString(NotificationRequest * target,const nlohmann::json & jsonObject)1652 void NotificationRequest::ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject)
1653 {
1654 if (target == nullptr) {
1655 ANS_LOGE("Invalid input parameter");
1656 return;
1657 }
1658
1659 const auto &jsonEnd = jsonObject.cend();
1660
1661 if (jsonObject.find("creatorBundleName") != jsonEnd && jsonObject.at("creatorBundleName").is_string()) {
1662 target->creatorBundleName_ = jsonObject.at("creatorBundleName").get<std::string>();
1663 }
1664
1665 if (jsonObject.find("ownerBundleName") != jsonEnd && jsonObject.at("ownerBundleName").is_string()) {
1666 target->ownerBundleName_ = jsonObject.at("ownerBundleName").get<std::string>();
1667 }
1668
1669 if (jsonObject.find("groupName") != jsonEnd && jsonObject.at("groupName").is_string()) {
1670 target->groupName_ = jsonObject.at("groupName").get<std::string>();
1671 }
1672
1673 if (jsonObject.find("label") != jsonEnd && jsonObject.at("label").is_string()) {
1674 target->label_ = jsonObject.at("label").get<std::string>();
1675 }
1676
1677 if (jsonObject.find("classification") != jsonEnd && jsonObject.at("classification").is_string()) {
1678 target->classification_ = jsonObject.at("classification").get<std::string>();
1679 }
1680
1681 if (jsonObject.find("creatorBundleName") != jsonEnd && jsonObject.at("creatorBundleName").is_string()) {
1682 target->creatorBundleName_ = jsonObject.at("creatorBundleName").get<std::string>();
1683 }
1684 }
1685
ConvertJsonToEnum(NotificationRequest * target,const nlohmann::json & jsonObject)1686 void NotificationRequest::ConvertJsonToEnum(NotificationRequest *target, const nlohmann::json &jsonObject)
1687 {
1688 if (target == nullptr) {
1689 ANS_LOGE("Invalid input parameter");
1690 return;
1691 }
1692
1693 const auto &jsonEnd = jsonObject.cend();
1694
1695 if (jsonObject.find("slotType") != jsonEnd && jsonObject.at("slotType").is_number_integer()) {
1696 auto slotTypeValue = jsonObject.at("slotType").get<int32_t>();
1697 target->slotType_ = static_cast<NotificationConstant::SlotType>(slotTypeValue);
1698 }
1699
1700 if (jsonObject.find("badgeIconStyle") != jsonEnd && jsonObject.at("badgeIconStyle").is_number_integer()) {
1701 auto badgeStyleValue = jsonObject.at("badgeIconStyle").get<int32_t>();
1702 target->badgeStyle_ = static_cast<NotificationRequest::BadgeStyle>(badgeStyleValue);
1703 }
1704 }
1705
ConvertJsonToBool(NotificationRequest * target,const nlohmann::json & jsonObject)1706 void NotificationRequest::ConvertJsonToBool(NotificationRequest *target, const nlohmann::json &jsonObject)
1707 {
1708 if (target == nullptr) {
1709 ANS_LOGE("Invalid input parameter");
1710 return;
1711 }
1712
1713 const auto &jsonEnd = jsonObject.cend();
1714
1715 if (jsonObject.find("showDeliveryTime") != jsonEnd && jsonObject.at("showDeliveryTime").is_boolean()) {
1716 target->showDeliveryTime_ = jsonObject.at("showDeliveryTime").get<bool>();
1717 }
1718
1719 if (jsonObject.find("tapDismissed") != jsonEnd && jsonObject.at("tapDismissed").is_boolean()) {
1720 target->tapDismissed_ = jsonObject.at("tapDismissed").get<bool>();
1721 }
1722
1723 if (jsonObject.find("colorEnabled") != jsonEnd && jsonObject.at("colorEnabled").is_boolean()) {
1724 target->colorEnabled_ = jsonObject.at("colorEnabled").get<bool>();
1725 }
1726
1727 if (jsonObject.find("isOngoing") != jsonEnd && jsonObject.at("isOngoing").is_boolean()) {
1728 target->inProgress_ = jsonObject.at("isOngoing").get<bool>();
1729 }
1730
1731 if (jsonObject.find("isAlertOnce") != jsonEnd && jsonObject.at("isAlertOnce").is_boolean()) {
1732 target->alertOneTime_ = jsonObject.at("isAlertOnce").get<bool>();
1733 }
1734
1735 if (jsonObject.find("isStopwatch") != jsonEnd && jsonObject.at("isStopwatch").is_boolean()) {
1736 target->showStopwatch_ = jsonObject.at("isStopwatch").get<bool>();
1737 }
1738
1739 if (jsonObject.find("isCountdown") != jsonEnd && jsonObject.at("isCountdown").is_boolean()) {
1740 target->isCountdown_ = jsonObject.at("isCountdown").get<bool>();
1741 }
1742
1743 if (jsonObject.find("isUnremovable") != jsonEnd && jsonObject.at("isUnremovable").is_boolean()) {
1744 target->unremovable_ = jsonObject.at("isUnremovable").get<bool>();
1745 }
1746
1747 if (jsonObject.find("isFloatingIcon") != jsonEnd && jsonObject.at("isFloatingIcon").is_boolean()) {
1748 target->floatingIcon_ = jsonObject.at("isFloatingIcon").get<bool>();
1749 }
1750 }
1751
ConvertJsonToPixelMap(NotificationRequest * target,const nlohmann::json & jsonObject)1752 void NotificationRequest::ConvertJsonToPixelMap(NotificationRequest *target, const nlohmann::json &jsonObject)
1753 {
1754 if (target == nullptr) {
1755 ANS_LOGE("Invalid input parameter");
1756 return;
1757 }
1758
1759 const auto &jsonEnd = jsonObject.cend();
1760
1761 if (jsonObject.find("smallIcon") != jsonEnd && jsonObject.at("smallIcon").is_string()) {
1762 auto littleIconStr = jsonObject.at("smallIcon").get<std::string>();
1763 target->littleIcon_ = AnsImageUtil::UnPackImage(littleIconStr);
1764 }
1765
1766 if (jsonObject.find("largeIcon") != jsonEnd && jsonObject.at("largeIcon").is_string()) {
1767 auto bigIconStr = jsonObject.at("largeIcon").get<std::string>();
1768 target->bigIcon_ = AnsImageUtil::UnPackImage(bigIconStr);
1769 }
1770 }
1771
ConvertJsonToNotificationContent(NotificationRequest * target,const nlohmann::json & jsonObject)1772 bool NotificationRequest::ConvertJsonToNotificationContent(
1773 NotificationRequest *target, const nlohmann::json &jsonObject)
1774 {
1775 if (target == nullptr) {
1776 ANS_LOGE("Invalid input parameter");
1777 return false;
1778 }
1779
1780 const auto &jsonEnd = jsonObject.cend();
1781
1782 if (jsonObject.find("content") != jsonEnd) {
1783 auto contentObj = jsonObject.at("content");
1784 if (!contentObj.is_null()) {
1785 auto pContent = NotificationJsonConverter::ConvertFromJson<NotificationContent>(contentObj);
1786 if (pContent == nullptr) {
1787 ANS_LOGE("Failed to parse notification content!");
1788 return false;
1789 }
1790
1791 target->notificationContent_ = std::shared_ptr<NotificationContent>(pContent);
1792 }
1793 }
1794
1795 return true;
1796 }
1797
ConvertJsonToNotificationActionButton(NotificationRequest * target,const nlohmann::json & jsonObject)1798 bool NotificationRequest::ConvertJsonToNotificationActionButton(
1799 NotificationRequest *target, const nlohmann::json &jsonObject)
1800 {
1801 if (target == nullptr) {
1802 ANS_LOGE("Invalid input parameter");
1803 return false;
1804 }
1805
1806 const auto &jsonEnd = jsonObject.cend();
1807
1808 if (jsonObject.find("actionButtons") != jsonEnd) {
1809 auto buttonArr = jsonObject.at("actionButtons");
1810 for (auto &btnObj : buttonArr) {
1811 auto pBtn = NotificationJsonConverter::ConvertFromJson<NotificationActionButton>(btnObj);
1812 if (pBtn == nullptr) {
1813 ANS_LOGE("Failed to parse actionButton!");
1814 return false;
1815 }
1816
1817 target->actionButtons_.emplace_back(pBtn);
1818 }
1819 }
1820
1821 return true;
1822 }
1823
ConvertJsonToNotificationDistributedOptions(NotificationRequest * target,const nlohmann::json & jsonObject)1824 bool NotificationRequest::ConvertJsonToNotificationDistributedOptions(
1825 NotificationRequest *target, const nlohmann::json &jsonObject)
1826 {
1827 if (target == nullptr) {
1828 ANS_LOGE("Invalid input parameter");
1829 return false;
1830 }
1831
1832 const auto &jsonEnd = jsonObject.cend();
1833
1834 if (jsonObject.find("distributedOptions") != jsonEnd) {
1835 auto optObj = jsonObject.at("distributedOptions");
1836 if (!optObj.is_null()) {
1837 auto pOpt = NotificationJsonConverter::ConvertFromJson<NotificationDistributedOptions>(optObj);
1838 if (pOpt == nullptr) {
1839 ANS_LOGE("Failed to parse distributedOptions!");
1840 return false;
1841 }
1842
1843 target->distributedOptions_ = *pOpt;
1844 }
1845 }
1846
1847 return true;
1848 }
1849
ConvertJsonToNotificationFlags(NotificationRequest * target,const nlohmann::json & jsonObject)1850 bool NotificationRequest::ConvertJsonToNotificationFlags(
1851 NotificationRequest *target, const nlohmann::json &jsonObject)
1852 {
1853 if (target == nullptr) {
1854 ANS_LOGE("Invalid input parameter");
1855 return false;
1856 }
1857
1858 const auto &jsonEnd = jsonObject.cend();
1859
1860 if (jsonObject.find("notificationFlags") != jsonEnd) {
1861 auto flagsObj = jsonObject.at("notificationFlags");
1862 if (!flagsObj.is_null()) {
1863 auto pFlags = NotificationJsonConverter::ConvertFromJson<NotificationFlags>(flagsObj);
1864 if (pFlags == nullptr) {
1865 ANS_LOGE("Failed to parse notificationFlags!");
1866 return false;
1867 }
1868
1869 target->notificationFlags_ = std::shared_ptr<NotificationFlags>(pFlags);
1870 }
1871 }
1872
1873 return true;
1874 }
1875 } // namespace Notification
1876 } // namespace OHOS
1877