1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "notification_request.h"
17
18 #include "ans_const_define.h"
19 #include "ans_inner_errors.h"
20 #include "ans_image_util.h"
21 #include "ans_log_wrapper.h"
22 #include "errors.h"
23 #include "notification_live_view_content.h"
24 #include "refbase.h"
25 #include "want_agent_helper.h"
26 #include "want_params_wrapper.h"
27 #include "notification_action_button.h"
28 #include <memory>
29
30 namespace OHOS {
31 namespace Notification {
32 const std::string NotificationRequest::CLASSIFICATION_ALARM {"alarm"};
33 const std::string NotificationRequest::CLASSIFICATION_CALL {"call"};
34 const std::string NotificationRequest::CLASSIFICATION_EMAIL {"email"};
35 const std::string NotificationRequest::CLASSIFICATION_ERROR {"err"};
36 const std::string NotificationRequest::CLASSIFICATION_EVENT {"event"};
37 const std::string NotificationRequest::CLASSIFICATION_MESSAGE {"msg"};
38 const std::string NotificationRequest::CLASSIFICATION_NAVIGATION {"navigation"};
39 const std::string NotificationRequest::CLASSIFICATION_PROGRESS {"progress"};
40 const std::string NotificationRequest::CLASSIFICATION_PROMO {"promo"};
41 const std::string NotificationRequest::CLASSIFICATION_RECOMMENDATION {"recommendation"};
42 const std::string NotificationRequest::CLASSIFICATION_REMINDER {"reminder"};
43 const std::string NotificationRequest::CLASSIFICATION_SERVICE {"service"};
44 const std::string NotificationRequest::CLASSIFICATION_SOCIAL {"social"};
45 const std::string NotificationRequest::CLASSIFICATION_STATUS {"status"};
46 const std::string NotificationRequest::CLASSIFICATION_SYSTEM {"sys"};
47 const std::string NotificationRequest::CLASSIFICATION_TRANSPORT {"transport"};
48
49 const uint32_t NotificationRequest::COLOR_DEFAULT {0};
50
51 const uint32_t NotificationRequest::COLOR_MASK {0xFF000000};
52 const std::size_t NotificationRequest::MAX_USER_INPUT_HISTORY {5};
53 const std::size_t NotificationRequest::MAX_ACTION_BUTTONS {3};
54 const std::size_t NotificationRequest::MAX_MESSAGE_USERS {1000};
55
56 constexpr int32_t MAX_MAP_SIZE = 1000;
57
NotificationRequest(int32_t notificationId)58 NotificationRequest::NotificationRequest(int32_t notificationId) : notificationId_(notificationId)
59 {
60 createTime_ = GetNowSysTime();
61 deliveryTime_ = GetNowSysTime();
62 }
63
NotificationRequest(const NotificationRequest & other)64 NotificationRequest::NotificationRequest(const NotificationRequest &other)
65 {
66 CopyBase(other);
67 CopyOther(other);
68 }
69
operator =(const NotificationRequest & other)70 NotificationRequest &NotificationRequest::operator=(const NotificationRequest &other)
71 {
72 CopyBase(other);
73 CopyOther(other);
74
75 return *this;
76 }
77
~NotificationRequest()78 NotificationRequest::~NotificationRequest()
79 {}
80
IsInProgress() const81 bool NotificationRequest::IsInProgress() const
82 {
83 return inProgress_;
84 }
85
SetInProgress(bool isOngoing)86 void NotificationRequest::SetInProgress(bool isOngoing)
87 {
88 inProgress_ = isOngoing;
89 }
90
IsUnremovable() const91 bool NotificationRequest::IsUnremovable() const
92 {
93 return unremovable_;
94 }
95
SetUnremovable(bool isUnremovable)96 void NotificationRequest::SetUnremovable(bool isUnremovable)
97 {
98 unremovable_ = isUnremovable;
99 }
100
SetBadgeNumber(uint32_t number)101 void NotificationRequest::SetBadgeNumber(uint32_t number)
102 {
103 badgeNumber_ = number;
104 }
105
GetBadgeNumber() const106 uint32_t NotificationRequest::GetBadgeNumber() const
107 {
108 return badgeNumber_;
109 }
110
SetNotificationControlFlags(uint32_t notificationControlFlags)111 void NotificationRequest::SetNotificationControlFlags(uint32_t notificationControlFlags)
112 {
113 notificationControlFlags_ = notificationControlFlags;
114 }
115
GetNotificationControlFlags() const116 uint32_t NotificationRequest::GetNotificationControlFlags() const
117 {
118 return notificationControlFlags_;
119 }
120
SetNotificationId(int32_t notificationId)121 void NotificationRequest::SetNotificationId(int32_t notificationId)
122 {
123 notificationId_ = notificationId;
124 }
125
GetNotificationId() const126 int32_t NotificationRequest::GetNotificationId() const
127 {
128 return notificationId_;
129 }
130
SetWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> & wantAgent)131 void NotificationRequest::SetWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent)
132 {
133 wantAgent_ = wantAgent;
134 }
135
GetWantAgent() const136 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> NotificationRequest::GetWantAgent() const
137 {
138 return wantAgent_;
139 }
140
SetRemovalWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> & wantAgent)141 void NotificationRequest::SetRemovalWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent)
142 {
143 removalWantAgent_ = wantAgent;
144 }
145
GetRemovalWantAgent() const146 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> NotificationRequest::GetRemovalWantAgent() const
147 {
148 return removalWantAgent_;
149 }
150
SetMaxScreenWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> & wantAgent)151 void NotificationRequest::SetMaxScreenWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent)
152 {
153 maxScreenWantAgent_ = wantAgent;
154 }
155
GetMaxScreenWantAgent() const156 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> NotificationRequest::GetMaxScreenWantAgent() const
157 {
158 return maxScreenWantAgent_;
159 }
160
SetAdditionalData(const std::shared_ptr<AAFwk::WantParams> & extras)161 void NotificationRequest::SetAdditionalData(const std::shared_ptr<AAFwk::WantParams> &extras)
162 {
163 additionalParams_ = extras;
164 }
165
GetAdditionalData() const166 const std::shared_ptr<AAFwk::WantParams> NotificationRequest::GetAdditionalData() const
167 {
168 return additionalParams_;
169 }
170
SetDeliveryTime(int64_t deliveryTime)171 void NotificationRequest::SetDeliveryTime(int64_t deliveryTime)
172 {
173 deliveryTime_ = deliveryTime;
174 }
175
GetDeliveryTime() const176 int64_t NotificationRequest::GetDeliveryTime() const
177 {
178 return deliveryTime_;
179 }
180
IsShowDeliveryTime() const181 bool NotificationRequest::IsShowDeliveryTime() const
182 {
183 return (deliveryTime_ != 0) && showDeliveryTime_;
184 }
185
SetShowDeliveryTime(bool showDeliveryTime)186 void NotificationRequest::SetShowDeliveryTime(bool showDeliveryTime)
187 {
188 showDeliveryTime_ = showDeliveryTime;
189 }
190
AddActionButton(const std::shared_ptr<NotificationActionButton> & actionButton)191 void NotificationRequest::AddActionButton(const std::shared_ptr<NotificationActionButton> &actionButton)
192 {
193 if (!actionButton) {
194 ANS_LOGW("actionButton can not be null");
195 return;
196 }
197
198 if (actionButtons_.size() >= NotificationRequest::MAX_ACTION_BUTTONS) {
199 ANS_LOGW("three action buttons have been already added");
200 return;
201 }
202
203 actionButtons_.emplace_back(actionButton);
204 }
205
GetActionButtons() const206 const std::vector<std::shared_ptr<NotificationActionButton>> NotificationRequest::GetActionButtons() const
207 {
208 return actionButtons_;
209 }
210
ClearActionButtons()211 void NotificationRequest::ClearActionButtons()
212 {
213 actionButtons_.clear();
214 }
215
IsPermitSystemGeneratedContextualActionButtons() const216 bool NotificationRequest::IsPermitSystemGeneratedContextualActionButtons() const
217 {
218 return permitted_;
219 }
220
SetPermitSystemGeneratedContextualActionButtons(bool permitted)221 void NotificationRequest::SetPermitSystemGeneratedContextualActionButtons(bool permitted)
222 {
223 permitted_ = permitted;
224 }
225
IsAgentNotification() const226 bool NotificationRequest::IsAgentNotification() const
227 {
228 return isAgent_;
229 }
230
SetIsAgentNotification(bool isAgent)231 void NotificationRequest::SetIsAgentNotification(bool isAgent)
232 {
233 isAgent_ = isAgent;
234 }
235
AddMessageUser(const std::shared_ptr<MessageUser> & messageUser)236 void NotificationRequest::AddMessageUser(const std::shared_ptr<MessageUser> &messageUser)
237 {
238 if (!messageUser) {
239 ANS_LOGI("messageUser can not be null");
240 return;
241 }
242
243 messageUsers_.emplace_back(messageUser);
244 }
245
GetMessageUsers() const246 const std::vector<std::shared_ptr<MessageUser>> NotificationRequest::GetMessageUsers() const
247 {
248 return messageUsers_;
249 }
250
IsAlertOneTime() const251 bool NotificationRequest::IsAlertOneTime() const
252 {
253 return alertOneTime_;
254 }
255
SetAlertOneTime(bool isAlertOnce)256 void NotificationRequest::SetAlertOneTime(bool isAlertOnce)
257 {
258 alertOneTime_ = isAlertOnce;
259 }
260
SetAutoDeletedTime(int64_t deletedTime)261 void NotificationRequest::SetAutoDeletedTime(int64_t deletedTime)
262 {
263 autoDeletedTime_ = deletedTime;
264 }
265
GetAutoDeletedTime() const266 int64_t NotificationRequest::GetAutoDeletedTime() const
267 {
268 return autoDeletedTime_;
269 }
270
SetUpdateDeadLine(int64_t updateDeadLine)271 void NotificationRequest::SetUpdateDeadLine(int64_t updateDeadLine)
272 {
273 updateDeadLine_ = updateDeadLine;
274 }
275
GetUpdateDeadLine() const276 int64_t NotificationRequest::GetUpdateDeadLine() const
277 {
278 return updateDeadLine_;
279 }
280
SetFinishDeadLine(int64_t finishDeadLine)281 void NotificationRequest::SetFinishDeadLine(int64_t finishDeadLine)
282 {
283 finishDeadLine_ = finishDeadLine;
284 }
285
GetFinishDeadLine() const286 int64_t NotificationRequest::GetFinishDeadLine() const
287 {
288 return finishDeadLine_;
289 }
290
SetArchiveDeadLine(int64_t archiveDeadLine)291 void NotificationRequest::SetArchiveDeadLine(int64_t archiveDeadLine)
292 {
293 archiveDeadLine_ = archiveDeadLine;
294 }
295
GetArchiveDeadLine() const296 int64_t NotificationRequest::GetArchiveDeadLine() const
297 {
298 return archiveDeadLine_;
299 }
300
SetLittleIcon(const std::shared_ptr<Media::PixelMap> & littleIcon)301 void NotificationRequest::SetLittleIcon(const std::shared_ptr<Media::PixelMap> &littleIcon)
302 {
303 littleIcon_ = littleIcon;
304 }
305
GetLittleIcon() const306 const std::shared_ptr<Media::PixelMap> NotificationRequest::GetLittleIcon() const
307 {
308 return littleIcon_;
309 }
310
SetBigIcon(const std::shared_ptr<Media::PixelMap> & bigIcon)311 void NotificationRequest::SetBigIcon(const std::shared_ptr<Media::PixelMap> &bigIcon)
312 {
313 bigIcon_ = bigIcon;
314 }
315
ResetBigIcon() const316 void NotificationRequest::ResetBigIcon() const
317 {
318 bigIcon_ = nullptr;
319 }
320
GetBigIcon() const321 const std::shared_ptr<Media::PixelMap> NotificationRequest::GetBigIcon() const
322 {
323 return bigIcon_;
324 }
325
SetOverlayIcon(const std::shared_ptr<Media::PixelMap> & overlayIcon)326 void NotificationRequest::SetOverlayIcon(const std::shared_ptr<Media::PixelMap> &overlayIcon)
327 {
328 overlayIcon_ = overlayIcon;
329 }
330
GetOverlayIcon() const331 const std::shared_ptr<Media::PixelMap> NotificationRequest::GetOverlayIcon() const
332 {
333 return overlayIcon_;
334 }
335
SetClassification(const std::string & classification)336 void NotificationRequest::SetClassification(const std::string &classification)
337 {
338 classification_ = classification;
339 }
340
GetClassification() const341 std::string NotificationRequest::GetClassification() const
342 {
343 return classification_;
344 }
345
SetColor(uint32_t color)346 void NotificationRequest::SetColor(uint32_t color)
347 {
348 color_ = color;
349 if (NotificationRequest::COLOR_DEFAULT != color_) {
350 color_ = color_ | NotificationRequest::COLOR_MASK;
351 }
352 }
353
GetColor() const354 uint32_t NotificationRequest::GetColor() const
355 {
356 return color_;
357 }
358
IsColorEnabled() const359 bool NotificationRequest::IsColorEnabled() const
360 {
361 if (!colorEnabled_) {
362 return false;
363 }
364
365 // no valid content
366 if (!notificationContent_) {
367 ANS_LOGI("no valid notification content");
368 return false;
369 }
370
371 // not a media content
372 if (NotificationContent::Type::MEDIA != notificationContentType_) {
373 ANS_LOGI("not a media notification content");
374 return false;
375 }
376
377 auto basicContent = notificationContent_->GetNotificationContent();
378 auto mediaContent = std::static_pointer_cast<NotificationMediaContent>(basicContent);
379 if (!mediaContent->GetAVToken()) {
380 ANS_LOGI("AVToken has not been attached");
381 return false;
382 }
383
384 return true;
385 }
386
SetColorEnabled(bool colorEnabled)387 void NotificationRequest::SetColorEnabled(bool colorEnabled)
388 {
389 colorEnabled_ = colorEnabled;
390 }
391
SetContent(const std::shared_ptr<NotificationContent> & content)392 void NotificationRequest::SetContent(const std::shared_ptr<NotificationContent> &content)
393 {
394 notificationContent_ = content;
395
396 if (notificationContent_) {
397 notificationContentType_ = notificationContent_->GetContentType();
398 return;
399 }
400
401 notificationContentType_ = NotificationContent::Type::NONE;
402 }
403
GetContent() const404 const std::shared_ptr<NotificationContent> NotificationRequest::GetContent() const
405 {
406 return notificationContent_;
407 }
408
GetNotificationType() const409 NotificationContent::Type NotificationRequest::GetNotificationType() const
410 {
411 return notificationContentType_;
412 }
413
IsCountdownTimer() const414 bool NotificationRequest::IsCountdownTimer() const
415 {
416 return isCountdown_;
417 }
418
SetCountdownTimer(bool isCountDown)419 void NotificationRequest::SetCountdownTimer(bool isCountDown)
420 {
421 isCountdown_ = isCountDown;
422 }
423
SetGroupAlertType(NotificationRequest::GroupAlertType type)424 void NotificationRequest::SetGroupAlertType(NotificationRequest::GroupAlertType type)
425 {
426 groupAlertType_ = type;
427 }
428
GetGroupAlertType() const429 NotificationRequest::GroupAlertType NotificationRequest::GetGroupAlertType() const
430 {
431 return groupAlertType_;
432 }
433
IsGroupOverview() const434 bool NotificationRequest::IsGroupOverview() const
435 {
436 return groupOverview_;
437 }
438
SetGroupOverview(bool overView)439 void NotificationRequest::SetGroupOverview(bool overView)
440 {
441 groupOverview_ = overView;
442 }
443
SetGroupName(const std::string & groupName)444 void NotificationRequest::SetGroupName(const std::string &groupName)
445 {
446 groupName_ = groupName;
447 }
448
GetGroupName() const449 std::string NotificationRequest::GetGroupName() const
450 {
451 return groupName_;
452 }
453
IsOnlyLocal() const454 bool NotificationRequest::IsOnlyLocal() const
455 {
456 return onlyLocal_;
457 }
458
SetOnlyLocal(bool flag)459 void NotificationRequest::SetOnlyLocal(bool flag)
460 {
461 onlyLocal_ = flag;
462 }
463
SetSettingsText(const std::string & text)464 void NotificationRequest::SetSettingsText(const std::string &text)
465 {
466 if ((NotificationContent::Type::LONG_TEXT == notificationContentType_) ||
467 (NotificationContent::Type::PICTURE == notificationContentType_)) {
468 ANS_LOGW("This method is invalid if the notification content type has been set to LONG_TEXT or PICTURE.");
469 return;
470 }
471
472 settingsText_ = text;
473 }
474
GetSettingsText() const475 std::string NotificationRequest::GetSettingsText() const
476 {
477 return settingsText_;
478 }
479
GetCreateTime() const480 int64_t NotificationRequest::GetCreateTime() const
481 {
482 return createTime_;
483 }
484
SetCreateTime(int64_t createTime)485 void NotificationRequest::SetCreateTime(int64_t createTime)
486 {
487 createTime_ = createTime;
488 }
489
IsShowStopwatch() const490 bool NotificationRequest::IsShowStopwatch() const
491 {
492 return showStopwatch_;
493 }
494
SetShowStopwatch(bool isShow)495 void NotificationRequest::SetShowStopwatch(bool isShow)
496 {
497 showStopwatch_ = isShow;
498 }
499
SetSlotType(NotificationConstant::SlotType slotType)500 void NotificationRequest::SetSlotType(NotificationConstant::SlotType slotType)
501 {
502 slotType_ = slotType;
503 }
504
GetSlotType() const505 NotificationConstant::SlotType NotificationRequest::GetSlotType() const
506 {
507 return slotType_;
508 }
509
SetSortingKey(const std::string & key)510 void NotificationRequest::SetSortingKey(const std::string &key)
511 {
512 sortingKey_ = key;
513 }
514
GetSortingKey() const515 std::string NotificationRequest::GetSortingKey() const
516 {
517 return sortingKey_;
518 }
519
SetStatusBarText(const std::string & text)520 void NotificationRequest::SetStatusBarText(const std::string &text)
521 {
522 statusBarText_ = text;
523 }
524
GetStatusBarText() const525 std::string NotificationRequest::GetStatusBarText() const
526 {
527 return statusBarText_;
528 }
529
IsTapDismissed() const530 bool NotificationRequest::IsTapDismissed() const
531 {
532 return tapDismissed_;
533 }
534
SetTapDismissed(bool isDismissed)535 void NotificationRequest::SetTapDismissed(bool isDismissed)
536 {
537 tapDismissed_ = isDismissed;
538 }
539
SetVisibleness(NotificationConstant::VisiblenessType type)540 void NotificationRequest::SetVisibleness(NotificationConstant::VisiblenessType type)
541 {
542 visiblenessType_ = type;
543 }
544
GetVisibleness() const545 NotificationConstant::VisiblenessType NotificationRequest::GetVisibleness() const
546 {
547 return visiblenessType_;
548 }
549
SetBadgeIconStyle(NotificationRequest::BadgeStyle style)550 void NotificationRequest::SetBadgeIconStyle(NotificationRequest::BadgeStyle style)
551 {
552 badgeStyle_ = style;
553 }
554
GetBadgeIconStyle() const555 NotificationRequest::BadgeStyle NotificationRequest::GetBadgeIconStyle() const
556 {
557 return badgeStyle_;
558 }
559
SetShortcutId(const std::string & shortcutId)560 void NotificationRequest::SetShortcutId(const std::string &shortcutId)
561 {
562 shortcutId_ = shortcutId;
563 }
564
GetShortcutId() const565 std::string NotificationRequest::GetShortcutId() const
566 {
567 return shortcutId_;
568 }
569
SetFloatingIcon(bool floatingIcon)570 void NotificationRequest::SetFloatingIcon(bool floatingIcon)
571 {
572 floatingIcon_ = floatingIcon;
573 }
574
IsFloatingIcon() const575 bool NotificationRequest::IsFloatingIcon() const
576 {
577 return floatingIcon_;
578 }
579
SetProgressBar(int32_t progress,int32_t progressMax,bool indeterminate)580 void NotificationRequest::SetProgressBar(int32_t progress, int32_t progressMax, bool indeterminate)
581 {
582 progressValue_ = progress;
583 progressMax_ = progressMax;
584 progressIndeterminate_ = indeterminate;
585 }
586
GetProgressMax() const587 int32_t NotificationRequest::GetProgressMax() const
588 {
589 return progressMax_;
590 }
591
GetProgressValue() const592 int32_t NotificationRequest::GetProgressValue() const
593 {
594 return progressValue_;
595 }
596
IsProgressIndeterminate() const597 bool NotificationRequest::IsProgressIndeterminate() const
598 {
599 return progressIndeterminate_;
600 }
601
SetNotificationUserInputHistory(const std::vector<std::string> & text)602 void NotificationRequest::SetNotificationUserInputHistory(const std::vector<std::string> &text)
603 {
604 if (text.empty()) {
605 userInputHistory_.clear();
606 return;
607 }
608
609 auto vsize = std::min(NotificationRequest::MAX_USER_INPUT_HISTORY, text.size());
610 userInputHistory_.assign(text.begin(), text.begin() + vsize);
611 }
612
GetNotificationUserInputHistory() const613 std::vector<std::string> NotificationRequest::GetNotificationUserInputHistory() const
614 {
615 return userInputHistory_;
616 }
617
GetNotificationHashCode() const618 std::string NotificationRequest::GetNotificationHashCode() const
619 {
620 if (creatorBundleName_.empty() || (creatorUid_ == 0) || ownerBundleName_.empty()) {
621 return "";
622 }
623
624 return std::to_string(notificationId_) + "_" + creatorBundleName_ + "_" + std::to_string(creatorUid_) + "_" +
625 ownerBundleName_;
626 }
627
SetOwnerBundleName(const std::string & ownerName)628 void NotificationRequest::SetOwnerBundleName(const std::string &ownerName)
629 {
630 ownerBundleName_ = ownerName;
631 }
632
GetOwnerBundleName() const633 std::string NotificationRequest::GetOwnerBundleName() const
634 {
635 return ownerBundleName_;
636 }
637
SetCreatorBundleName(const std::string & creatorName)638 void NotificationRequest::SetCreatorBundleName(const std::string &creatorName)
639 {
640 creatorBundleName_ = creatorName;
641 }
642
GetCreatorBundleName() const643 std::string NotificationRequest::GetCreatorBundleName() const
644 {
645 return creatorBundleName_;
646 }
647
SetCreatorPid(pid_t pid)648 void NotificationRequest::SetCreatorPid(pid_t pid)
649 {
650 creatorPid_ = pid;
651 }
652
GetCreatorPid() const653 pid_t NotificationRequest::GetCreatorPid() const
654 {
655 return creatorPid_;
656 }
657
SetCreatorUid(int32_t uid)658 void NotificationRequest::SetCreatorUid(int32_t uid)
659 {
660 creatorUid_ = uid;
661 }
662
GetCreatorUid() const663 int32_t NotificationRequest::GetCreatorUid() const
664 {
665 return creatorUid_;
666 }
667
SetOwnerUid(int32_t uid)668 void NotificationRequest::SetOwnerUid(int32_t uid)
669 {
670 ownerUid_ = uid;
671 }
672
GetOwnerUid() const673 int32_t NotificationRequest::GetOwnerUid() const
674 {
675 return ownerUid_;
676 }
677
SetLabel(const std::string & label)678 void NotificationRequest::SetLabel(const std::string &label)
679 {
680 label_ = label;
681 }
682
GetLabel() const683 std::string NotificationRequest::GetLabel() const
684 {
685 return label_;
686 }
687
SetDistributed(bool distribute)688 void NotificationRequest::SetDistributed(bool distribute)
689 {
690 distributedOptions_.SetDistributed(distribute);
691 }
692
SetDevicesSupportDisplay(const std::vector<std::string> & devices)693 void NotificationRequest::SetDevicesSupportDisplay(const std::vector<std::string> &devices)
694 {
695 distributedOptions_.SetDevicesSupportDisplay(devices);
696 }
697
SetDevicesSupportOperate(const std::vector<std::string> & devices)698 void NotificationRequest::SetDevicesSupportOperate(const std::vector<std::string> &devices)
699 {
700 distributedOptions_.SetDevicesSupportOperate(devices);
701 }
702
GetNotificationDistributedOptions() const703 NotificationDistributedOptions NotificationRequest::GetNotificationDistributedOptions() const
704 {
705 return distributedOptions_;
706 }
707
SetCreatorUserId(int32_t userId)708 void NotificationRequest::SetCreatorUserId(int32_t userId)
709 {
710 creatorUserId_ = userId;
711 }
712
GetCreatorUserId() const713 int32_t NotificationRequest::GetCreatorUserId() const
714 {
715 return creatorUserId_;
716 }
717
SetCreatorInstanceKey(int32_t key)718 void NotificationRequest::SetCreatorInstanceKey(int32_t key)
719 {
720 creatorInstanceKey_ = key;
721 }
722
GetCreatorInstanceKey() const723 int32_t NotificationRequest::GetCreatorInstanceKey() const
724 {
725 return creatorInstanceKey_;
726 }
727
SetAppInstanceKey(const std::string & key)728 void NotificationRequest::SetAppInstanceKey(const std::string &key)
729 {
730 appInstanceKey_ = key;
731 }
732
GetAppInstanceKey() const733 std::string NotificationRequest::GetAppInstanceKey() const
734 {
735 return appInstanceKey_;
736 }
737
SetOwnerUserId(int32_t userId)738 void NotificationRequest::SetOwnerUserId(int32_t userId)
739 {
740 ownerUserId_ = userId;
741 }
742
GetOwnerUserId() const743 int32_t NotificationRequest::GetOwnerUserId() const
744 {
745 return ownerUserId_;
746 }
747
SetHashCodeGenerateType(uint32_t type)748 void NotificationRequest::SetHashCodeGenerateType(uint32_t type)
749 {
750 hashCodeGenerateType_ = type;
751 }
752
GetHashCodeGenerateType() const753 uint32_t NotificationRequest::GetHashCodeGenerateType() const
754 {
755 return hashCodeGenerateType_;
756 }
757
SetCollaboratedReminderFlag(uint32_t reminderFlag)758 void NotificationRequest::SetCollaboratedReminderFlag(uint32_t reminderFlag)
759 {
760 collaboratedReminderFlag_ = reminderFlag;
761 }
762
GetCollaboratedReminderFlag() const763 uint32_t NotificationRequest::GetCollaboratedReminderFlag() const
764 {
765 return collaboratedReminderFlag_;
766 }
767
ResetLittleIcon() const768 void NotificationRequest::ResetLittleIcon() const
769 {
770 littleIcon_ = nullptr;
771 }
772
ResetOverLayIcon() const773 void NotificationRequest::ResetOverLayIcon() const
774 {
775 overlayIcon_ = nullptr;
776 }
777
Dump()778 std::string NotificationRequest::Dump()
779 {
780 return "NotificationRequest{ "
781 "notificationId = " + std::to_string(notificationId_) +
782 ", slotType = " + std::to_string(static_cast<int32_t>(slotType_)) +
783 ", createTime = " + std::to_string(createTime_) + ", deliveryTime = " + std::to_string(deliveryTime_) +
784 ", autoDeletedTime = " + std::to_string(autoDeletedTime_) + ", settingsText = " + settingsText_ +
785 ", creatorBundleName = " + creatorBundleName_ +
786 ", creatorPid = " + std::to_string(static_cast<int32_t>(creatorPid_)) +
787 ", creatorUid = " + std::to_string(static_cast<int32_t>(creatorUid_)) +
788 ", ownerBundleName = " + ownerBundleName_ +
789 ", ownerUid = " + std::to_string(static_cast<int32_t>(ownerUid_)) +
790 ", groupName = " + groupName_ + ", statusBarText = " + statusBarText_ + ", label = " + label_ +
791 ", shortcutId = " + shortcutId_ + ", sortingKey = " + sortingKey_ +
792 ", groupAlertType = " + std::to_string(static_cast<int32_t>(groupAlertType_)) +
793 ", color = " + std::to_string(color_) + ", badgeNumber = " + std::to_string(badgeNumber_) +
794 ", visiblenessType = " + std::to_string(static_cast<int32_t>(visiblenessType_)) +
795 ", progressValue = " + std::to_string(progressValue_) + ", progressMax = " + std::to_string(progressMax_) +
796 ", badgeStyle = " + std::to_string(static_cast<int32_t>(badgeStyle_)) +
797 ", classification = " + classification_ +
798 ", notificationContentType = " + std::to_string(static_cast<int32_t>(notificationContentType_)) +
799 ", notificationControlFlags = " + std::to_string(notificationControlFlags_) +
800 ", showDeliveryTime = " + (showDeliveryTime_ ? "true" : "false") +
801 ", tapDismissed = " + (tapDismissed_ ? "true" : "false") +
802 ", colorEnabled = " + (colorEnabled_ ? "true" : "false") +
803 ", alertOneTime = " + (alertOneTime_ ? "true" : "false") +
804 ", showStopwatch = " + (showStopwatch_ ? "true" : "false") +
805 ", isCountdown = " + (isCountdown_ ? "true" : "false") +
806 ", inProgress = " + (inProgress_ ? "true" : "false") +
807 ", groupOverview = " + (groupOverview_ ? "true" : "false") +
808 ", isRemoveAllowed = " + (isRemoveAllowed_ ? "true" : "false") +
809 ", progressIndeterminate = " + (progressIndeterminate_ ? "true" : "false") +
810 ", unremovable = " + (unremovable_ ? "true" : "false") +
811 ", floatingIcon = " + (floatingIcon_ ? "true" : "false") +
812 ", onlyLocal = " + (onlyLocal_ ? "true" : "false") + ", permitted = " + (permitted_ ? "true" : "false") +
813 ", isAgent = " + (isAgent_ ? "true" : "false") +
814 ", updateOnly = " + (updateOnly_ ? "true" : "false") +
815 ", isForceDistributed = " + (forceDistributed_ ? "true" : "false") +
816 ", isNotDistributed = " + (notDistributed_ ? "true" : "false") +
817 ", removalWantAgent = " + (removalWantAgent_ ? "not null" : "null") +
818 ", maxScreenWantAgent = " + (maxScreenWantAgent_ ? "not null" : "null") +
819 ", additionalParams = " + (additionalParams_ ? "not null" : "null") +
820 ", littleIcon = " + (littleIcon_ ? "not null" : "null") +
821 ", bigIcon = " + (bigIcon_ ? "not null" : "null") +
822 ", overlayIcon = " + (overlayIcon_ ? "not null" : "null") +
823 ", notificationContent = " + (notificationContent_ ? notificationContent_->Dump() : "null") +
824 ", notificationTemplate = " + (notificationTemplate_ ? "not null" : "null") +
825 ", actionButtons = " + (!actionButtons_.empty() ? actionButtons_.at(0)->Dump() : "empty") +
826 ", messageUsers = " + (!messageUsers_.empty() ? messageUsers_.at(0)->Dump() : "empty") +
827 ", userInputHistory = " + (!userInputHistory_.empty() ? userInputHistory_.at(0) : "empty") +
828 ", distributedOptions = " + distributedOptions_.Dump() +
829 ", notificationFlags = " + (notificationFlags_ ? "not null" : "null") +
830 ", notificationFlagsOfDevices = " + (notificationFlagsOfDevices_ ? "not null" : "null") +
831 ", notificationBundleOption = " + (notificationBundleOption_ != nullptr ? "not null" : "null") +
832 ", agentBundle = " + (agentBundle_ != nullptr ? "not null" : "null") +
833 ", creatorUserId = " + std::to_string(creatorUserId_) + ", ownerUserId = " + std::to_string(ownerUserId_) +
834 ", receiverUserId = " + std::to_string(receiverUserId_) + ", updateDeadLine = " +
835 std::to_string(updateDeadLine_) + ", finishDeadLine = " + std::to_string(finishDeadLine_) +
836 ", sound = " + sound_ + ", distributed = " + std::to_string(distributedCollaborate_) + ":" +
837 distributedHashCode_ + " flag: " + std::to_string(collaboratedReminderFlag_) + ", unifiedGroupInfo_ = " +
838 (unifiedGroupInfo_ ? unifiedGroupInfo_->Dump() : "null")+ " }";
839 }
840
ToJson(nlohmann::json & jsonObject) const841 bool NotificationRequest::ToJson(nlohmann::json &jsonObject) const
842 {
843 jsonObject["version"] = 1;
844
845 jsonObject["id"] = notificationId_;
846 jsonObject["color"] = color_;
847 jsonObject["deliveryTime"] = deliveryTime_;
848 jsonObject["autoDeletedTime"] = autoDeletedTime_;
849
850 jsonObject["creatorBundleName"] = creatorBundleName_;
851 jsonObject["ownerBundleName"] = ownerBundleName_;
852 jsonObject["groupName"] = groupName_;
853 jsonObject["label"] = label_;
854 jsonObject["classification"] = classification_;
855
856 jsonObject["slotType"] = static_cast<int32_t>(slotType_);
857 jsonObject["notificationSlotType"] = static_cast<int32_t>(slotType_);
858 jsonObject["badgeIconStyle"] = static_cast<int32_t>(badgeStyle_);
859 jsonObject["notificationContentType"] = static_cast<int32_t>(notificationContentType_);
860
861 jsonObject["showDeliveryTime"] = showDeliveryTime_;
862 jsonObject["tapDismissed"] = tapDismissed_;
863 jsonObject["colorEnabled"] = colorEnabled_;
864 jsonObject["isOngoing"] = inProgress_;
865 jsonObject["isAlertOnce"] = alertOneTime_;
866 jsonObject["isStopwatch"] = showStopwatch_;
867 jsonObject["isCountdown"] = isCountdown_;
868 jsonObject["isUnremovable"] = unremovable_;
869 jsonObject["isAgent"] = isAgent_;
870 jsonObject["isFloatingIcon"] = floatingIcon_;
871 jsonObject["updateOnly"] = updateOnly_;
872 jsonObject["distributedCollaborate"] = distributedCollaborate_;
873
874 jsonObject["creatorBundleName"] = creatorBundleName_;
875 jsonObject["creatorUid"] = creatorUid_;
876 jsonObject["creatorPid"] = creatorPid_;
877 jsonObject["creatorUserId"] = creatorUserId_;
878 jsonObject["ownerUserId"] = ownerUserId_;
879 jsonObject["ownerUid"] = ownerUid_;
880 jsonObject["receiverUserId"] = receiverUserId_;
881 jsonObject["creatorInstanceKey"] = creatorInstanceKey_;
882 jsonObject["appInstanceKey"] = appInstanceKey_;
883 jsonObject["notificationControlFlags"] = notificationControlFlags_;
884 jsonObject["updateDeadLine"] = updateDeadLine_;
885 jsonObject["finishDeadLine"] = finishDeadLine_;
886 jsonObject["hashCodeGenerateType"] = hashCodeGenerateType_;
887 jsonObject["collaboratedReminderFlag"] = collaboratedReminderFlag_;
888 jsonObject["distributedHashCode"] = distributedHashCode_;
889
890 if (!ConvertObjectsToJson(jsonObject)) {
891 ANS_LOGE("Cannot convert objects to JSON");
892 return false;
893 }
894
895 return true;
896 }
897
FromJson(const nlohmann::json & jsonObject)898 NotificationRequest *NotificationRequest::FromJson(const nlohmann::json &jsonObject)
899 {
900 if (jsonObject.is_null() or !jsonObject.is_object()) {
901 ANS_LOGE("Invalid JSON object");
902 return nullptr;
903 }
904
905 auto pRequest = new (std::nothrow) NotificationRequest();
906 if (pRequest == nullptr) {
907 ANS_LOGE("Failed to create request instance");
908 return nullptr;
909 }
910
911 const auto &jsonEnd = jsonObject.cend();
912 if (jsonObject.find("version") != jsonEnd && jsonObject.at("version").is_number_integer()) {
913 jsonObject.at("version").get<int32_t>();
914 }
915
916 ConvertJsonToNum(pRequest, jsonObject);
917
918 ConvertJsonToString(pRequest, jsonObject);
919
920 ConvertJsonToEnum(pRequest, jsonObject);
921
922 ConvertJsonToBool(pRequest, jsonObject);
923
924 if (jsonObject.find("wantAgent") != jsonEnd && jsonObject.at("wantAgent").is_string()) {
925 auto wantAgentValue = jsonObject.at("wantAgent").get<std::string>();
926 int32_t targetUid = -1;
927 if (pRequest->GetOwnerUid() != DEFAULT_UID) {
928 targetUid = pRequest->GetOwnerUid();
929 }
930 ANS_LOGI("wantAgent Fromjson, uid = %{public}d ", targetUid);
931 pRequest->wantAgent_ = AbilityRuntime::WantAgent::WantAgentHelper::FromString(wantAgentValue, targetUid);
932 }
933
934 if (!ConvertJsonToNotificationContent(pRequest, jsonObject)) {
935 delete pRequest;
936 pRequest = nullptr;
937 return nullptr;
938 }
939
940 if (!ConvertJsonToNotificationActionButton(pRequest, jsonObject)) {
941 delete pRequest;
942 pRequest = nullptr;
943 return nullptr;
944 }
945
946 if (jsonObject.find("extraInfo") != jsonEnd && jsonObject.at("extraInfo").is_string()) {
947 auto extraInfoStr = jsonObject.at("extraInfo").get<std::string>();
948 if (!extraInfoStr.empty()) {
949 AAFwk::WantParams params = AAFwk::WantParamWrapper::ParseWantParams(extraInfoStr);
950 pRequest->additionalParams_ = std::make_shared<AAFwk::WantParams>(params);
951 }
952 }
953
954 ConvertJsonToPixelMap(pRequest, jsonObject);
955
956 if (!ConvertJsonToNotificationDistributedOptions(pRequest, jsonObject)) {
957 delete pRequest;
958 pRequest = nullptr;
959 return nullptr;
960 }
961
962 if (!ConvertJsonToNotificationFlags(pRequest, jsonObject)) {
963 delete pRequest;
964 pRequest = nullptr;
965 return nullptr;
966 }
967
968 if (!ConvertJsonToNotificationBundleOption(pRequest, jsonObject)) {
969 delete pRequest;
970 pRequest = nullptr;
971 return nullptr;
972 }
973
974 ConvertJsonToAgentBundle(pRequest, jsonObject);
975
976 return pRequest;
977 }
978
Marshalling(Parcel & parcel) const979 bool NotificationRequest::Marshalling(Parcel &parcel) const
980 {
981 // write int
982 if (!parcel.WriteInt32(notificationId_)) {
983 ANS_LOGE("Failed to write notification Id");
984 return false;
985 }
986
987 if (!parcel.WriteUint32(color_)) {
988 ANS_LOGE("Failed to write color");
989 return false;
990 }
991
992 if (!parcel.WriteUint32(badgeNumber_)) {
993 ANS_LOGE("Failed to write badge number");
994 return false;
995 }
996
997 if (!parcel.WriteInt32(progressValue_)) {
998 ANS_LOGE("Failed to write progress value");
999 return false;
1000 }
1001
1002 if (!parcel.WriteInt32(progressMax_)) {
1003 ANS_LOGE("Failed to write progress max");
1004 return false;
1005 }
1006
1007 if (!parcel.WriteInt64(createTime_)) {
1008 ANS_LOGE("Failed to write create time");
1009 return false;
1010 }
1011
1012 if (!parcel.WriteInt64(deliveryTime_)) {
1013 ANS_LOGE("Failed to write delivery time");
1014 return false;
1015 }
1016
1017 if (!parcel.WriteInt64(autoDeletedTime_)) {
1018 ANS_LOGE("Failed to write auto deleted time");
1019 return false;
1020 }
1021
1022 if (!parcel.WriteInt32(static_cast<int32_t>(creatorPid_))) {
1023 ANS_LOGE("Failed to write creator pid");
1024 return false;
1025 }
1026
1027 if (!parcel.WriteInt32(static_cast<int32_t>(creatorUid_))) {
1028 ANS_LOGE("Failed to write creator uid");
1029 return false;
1030 }
1031
1032 if (!parcel.WriteInt32(static_cast<int32_t>(ownerUid_))) {
1033 ANS_LOGE("Failed to write owner uid");
1034 return false;
1035 }
1036
1037 if (!parcel.WriteInt32(static_cast<int32_t>(creatorUserId_))) {
1038 ANS_LOGE("Failed to write creator userId");
1039 return false;
1040 }
1041
1042 if (!parcel.WriteInt32(static_cast<int32_t>(ownerUserId_))) {
1043 ANS_LOGE("Failed to write owner userId");
1044 return false;
1045 }
1046
1047 if (!parcel.WriteInt32(static_cast<int32_t>(receiverUserId_))) {
1048 ANS_LOGE("Failed to write receiver userId");
1049 return false;
1050 }
1051
1052 if (!parcel.WriteInt32(static_cast<int32_t>(creatorInstanceKey_))) {
1053 ANS_LOGE("Failed to write creator instance key");
1054 return false;
1055 }
1056
1057 if (!parcel.WriteUint32(notificationControlFlags_)) {
1058 ANS_LOGE("Failed to write notification control flags.");
1059 return false;
1060 }
1061
1062 if (!parcel.WriteUint32(publishDelayTime_)) {
1063 ANS_LOGE("Failed to write publish delay time");
1064 return false;
1065 }
1066
1067 if (!parcel.WriteUint32(hashCodeGenerateType_)) {
1068 ANS_LOGE("Failed to write hash code generatetype");
1069 return false;
1070 }
1071
1072 if (!parcel.WriteUint32(collaboratedReminderFlag_)) {
1073 ANS_LOGE("Failed to write collaborated reminderflag");
1074 return false;
1075 }
1076
1077 // write std::string
1078 if (!parcel.WriteString(appInstanceKey_)) {
1079 ANS_LOGE("Failed to write instance key");
1080 return false;
1081 }
1082
1083 if (!parcel.WriteString(settingsText_)) {
1084 ANS_LOGE("Failed to write settings text");
1085 return false;
1086 }
1087
1088 if (!parcel.WriteString(creatorBundleName_)) {
1089 ANS_LOGE("Failed to write creator bundle name");
1090 return false;
1091 }
1092
1093 if (!parcel.WriteString(ownerBundleName_)) {
1094 ANS_LOGE("Failed to write owner bundle name");
1095 return false;
1096 }
1097
1098 if (!parcel.WriteString(groupName_)) {
1099 ANS_LOGE("Failed to write group name");
1100 return false;
1101 }
1102
1103 if (!parcel.WriteString(statusBarText_)) {
1104 ANS_LOGE("Failed to write status bar text");
1105 return false;
1106 }
1107
1108 if (!parcel.WriteString(label_)) {
1109 ANS_LOGE("Failed to write label");
1110 return false;
1111 }
1112
1113 if (!parcel.WriteString(shortcutId_)) {
1114 ANS_LOGE("Failed to write shortcut Id");
1115 return false;
1116 }
1117
1118 if (!parcel.WriteString(sortingKey_)) {
1119 ANS_LOGE("Failed to write sorting key");
1120 return false;
1121 }
1122
1123 if (!parcel.WriteString(classification_)) {
1124 ANS_LOGE("Failed to write classification");
1125 return false;
1126 }
1127
1128 if (!parcel.WriteString(appMessageId_)) {
1129 ANS_LOGE("Failed to write appMessageId");
1130 return false;
1131 }
1132
1133 if (!parcel.WriteString(sound_)) {
1134 ANS_LOGE("Failed to write sound");
1135 return false;
1136 }
1137
1138 if (!parcel.WriteString(distributedHashCode_)) {
1139 ANS_LOGE("Failed to write sound");
1140 return false;
1141 }
1142
1143 // write enum
1144 if (!parcel.WriteInt32(static_cast<int32_t>(slotType_))) {
1145 ANS_LOGE("Failed to write slot type");
1146 return false;
1147 }
1148
1149 if (!parcel.WriteInt32(static_cast<int32_t>(groupAlertType_))) {
1150 ANS_LOGE("Failed to write group alert type");
1151 return false;
1152 }
1153
1154 if (!parcel.WriteInt32(static_cast<int32_t>(visiblenessType_))) {
1155 ANS_LOGE("Failed to write visibleness type");
1156 return false;
1157 }
1158
1159 if (!parcel.WriteInt32(static_cast<int32_t>(badgeStyle_))) {
1160 ANS_LOGE("Failed to write badge type");
1161 return false;
1162 }
1163
1164 if (!parcel.WriteInt32(static_cast<int32_t>(notificationContentType_))) {
1165 ANS_LOGE("Failed to write notification content type");
1166 return false;
1167 }
1168
1169 // write bool
1170 if (!parcel.WriteBool(showDeliveryTime_)) {
1171 ANS_LOGE("Failed to write flag indicating whether to show delivery time");
1172 return false;
1173 }
1174
1175 if (!parcel.WriteBool(tapDismissed_)) {
1176 ANS_LOGE("Failed to write flag tap dismissed");
1177 return false;
1178 }
1179
1180 if (!parcel.WriteBool(colorEnabled_)) {
1181 ANS_LOGE("Failed to write flag indicating whether to enable background color");
1182 return false;
1183 }
1184
1185 if (!parcel.WriteBool(alertOneTime_)) {
1186 ANS_LOGE("Failed to write flag indicating whether to have this notification alert only once");
1187 return false;
1188 }
1189
1190 if (!parcel.WriteBool(showStopwatch_)) {
1191 ANS_LOGE("Failed to write flag show stop watch");
1192 return false;
1193 }
1194
1195 if (!parcel.WriteBool(isCountdown_)) {
1196 ANS_LOGE("Failed to write flag indicating whether to show the notification creation time as a countdown timer");
1197 return false;
1198 }
1199
1200 if (!parcel.WriteBool(inProgress_)) {
1201 ANS_LOGE("Failed to write flag indicating whether in progress");
1202 return false;
1203 }
1204
1205 if (!parcel.WriteBool(groupOverview_)) {
1206 ANS_LOGE("Failed to write flag indicating whether to use this notification as the overview of its group");
1207 return false;
1208 }
1209
1210 if (!parcel.WriteBool(progressIndeterminate_)) {
1211 ANS_LOGE("Failed to write progress indeterminate");
1212 return false;
1213 }
1214
1215 if (!parcel.WriteBool(unremovable_)) {
1216 ANS_LOGE("Failed to write flag indicating whether unremovable");
1217 return false;
1218 }
1219
1220 if (!parcel.WriteBool(floatingIcon_)) {
1221 ANS_LOGE("Failed to write flag floating icon");
1222 return false;
1223 }
1224
1225 if (!parcel.WriteBool(onlyLocal_)) {
1226 ANS_LOGE("Failed to write flag only local");
1227 return false;
1228 }
1229
1230 if (!parcel.WriteBool(permitted_)) {
1231 ANS_LOGE("Failed to write flag indicating whether to allow the platform to \
1232 generate contextual NotificationActionButton objects");
1233 return false;
1234 }
1235
1236 if (!parcel.WriteBool(isAgent_)) {
1237 ANS_LOGE("Failed to write flag indicating whether an agent notification");
1238 return false;
1239 }
1240
1241 if (!parcel.WriteBool(isRemoveAllowed_)) {
1242 ANS_LOGE("Failed to write flag isRemoveAllowed");
1243 return false;
1244 }
1245
1246 if (!parcel.WriteBool(forceDistributed_)) {
1247 ANS_LOGE("Failed to write flag forceDistributed");
1248 return false;
1249 }
1250
1251 if (!parcel.WriteBool(notDistributed_)) {
1252 ANS_LOGE("Failed to write flag notDistributed");
1253 return false;
1254 }
1255
1256 // write objects which managed by std::shared_ptr
1257 bool valid {false};
1258
1259 valid = wantAgent_ ? true : false;
1260 if (!parcel.WriteBool(valid)) {
1261 ANS_LOGE("Failed to write the flag which indicate whether wantAgent is null");
1262 return false;
1263 }
1264
1265 if (valid) {
1266 if (!parcel.WriteParcelable(wantAgent_.get())) {
1267 ANS_LOGE("Failed to write wantAgent");
1268 return false;
1269 }
1270 }
1271
1272 valid = removalWantAgent_ ? true : false;
1273 if (!parcel.WriteBool(valid)) {
1274 ANS_LOGE("Failed to write the flag which indicate whether removalWantAgent is null");
1275 return false;
1276 }
1277
1278 if (valid) {
1279 if (!parcel.WriteParcelable(removalWantAgent_.get())) {
1280 ANS_LOGE("Failed to write removalWantAgent");
1281 return false;
1282 }
1283 }
1284
1285 valid = maxScreenWantAgent_ ? true : false;
1286 if (!parcel.WriteBool(valid)) {
1287 ANS_LOGE("Failed to write the flag which indicate whether maxScreenWantAgent is null");
1288 return false;
1289 }
1290
1291 if (valid) {
1292 if (!parcel.WriteParcelable(maxScreenWantAgent_.get())) {
1293 ANS_LOGE("Failed to write maxScreenWantAgent");
1294 return false;
1295 }
1296 }
1297
1298 valid = additionalParams_ ? true : false;
1299 if (!parcel.WriteBool(valid)) {
1300 ANS_LOGE("Failed to write the flag which indicate whether additionalParams is null");
1301 return false;
1302 }
1303
1304 if (valid) {
1305 if (!parcel.WriteParcelable(additionalParams_.get())) {
1306 ANS_LOGE("Failed to write additionalParams");
1307 return false;
1308 }
1309 }
1310
1311 valid = littleIcon_ ? true : false;
1312 if (!parcel.WriteBool(valid)) {
1313 ANS_LOGE("Failed to write the flag which indicate whether littleIcon is null");
1314 return false;
1315 }
1316
1317 if (valid) {
1318 if (!parcel.WriteParcelable(littleIcon_.get())) {
1319 ANS_LOGE("Failed to write littleIcon");
1320 return false;
1321 }
1322 }
1323
1324 valid = bigIcon_ ? true : false;
1325 if (!parcel.WriteBool(valid)) {
1326 ANS_LOGE("Failed to write the flag which indicate whether bigIcon is null");
1327 return false;
1328 }
1329
1330 if (valid) {
1331 if (!parcel.WriteParcelable(bigIcon_.get())) {
1332 ANS_LOGE("Failed to write bigIcon");
1333 return false;
1334 }
1335 }
1336
1337 valid = overlayIcon_ ? true : false;
1338 if (!parcel.WriteBool(valid)) {
1339 ANS_LOGE("Failed to write the flag which indicate whether overlayIcon is null");
1340 return false;
1341 }
1342
1343 if (valid) {
1344 if (!parcel.WriteParcelable(overlayIcon_.get())) {
1345 ANS_LOGE("Failed to write overlayIcon");
1346 return false;
1347 }
1348 }
1349
1350 valid = notificationContent_ ? true : false;
1351 if (!parcel.WriteBool(valid)) {
1352 ANS_LOGE("Failed to write the flag which indicate whether notificationContent is null");
1353 return false;
1354 }
1355
1356 if (valid) {
1357 if (!parcel.WriteParcelable(notificationContent_.get())) {
1358 ANS_LOGE("Failed to write notificationContent");
1359 return false;
1360 }
1361 }
1362
1363 // write std::vector
1364 if (!parcel.WriteUint64(actionButtons_.size())) {
1365 ANS_LOGE("Failed to write the size of actionButtons");
1366 return false;
1367 }
1368
1369 for (auto it = actionButtons_.begin(); it != actionButtons_.end(); ++it) {
1370 if (!parcel.WriteParcelable(it->get())) {
1371 ANS_LOGE("Failed to write actionButton");
1372 return false;
1373 }
1374 }
1375
1376 if (!parcel.WriteBool(isCoverActionButtons_)) {
1377 ANS_LOGE("Failed to write isCoverActionButtons_");
1378 return false;
1379 }
1380
1381 if (!parcel.WriteBool(isUpdateByOwnerAllowed_)) {
1382 ANS_LOGE("Failed to write isUpdateByOwnerAllowed_");
1383 return false;
1384 }
1385
1386 if (!parcel.WriteBool(distributedCollaborate_)) {
1387 ANS_LOGE("Failed to write distributedCollaborate_");
1388 return false;
1389 }
1390
1391 if (!parcel.WriteBool(updateOnly_)) {
1392 ANS_LOGE("Failed to write updateOnly_");
1393 return false;
1394 }
1395
1396 if (!parcel.WriteUint64(messageUsers_.size())) {
1397 ANS_LOGE("Failed to write the size of messageUsers");
1398 return false;
1399 }
1400
1401 for (auto it = messageUsers_.begin(); it != messageUsers_.end(); ++it) {
1402 if (!parcel.WriteParcelable(it->get())) {
1403 ANS_LOGE("Failed to write messageUser");
1404 return false;
1405 }
1406 }
1407
1408 if (!parcel.WriteStringVector(userInputHistory_)) {
1409 ANS_LOGE("Failed to write userInputHistory");
1410 return false;
1411 }
1412
1413 if (!parcel.WriteParcelable(&distributedOptions_)) {
1414 ANS_LOGE("Failed to write distributedOptions");
1415 return false;
1416 }
1417
1418 valid = notificationTemplate_ ? true : false;
1419 if (!parcel.WriteBool(valid)) {
1420 ANS_LOGE("Failed to write the flag which indicate whether publicNotification is null");
1421 return false;
1422 }
1423
1424 if (valid) {
1425 if (!parcel.WriteParcelable(notificationTemplate_.get())) {
1426 ANS_LOGE("Failed to write notificationTemplate");
1427 return false;
1428 }
1429 }
1430
1431 valid = notificationFlags_ ? true : false;
1432 if (!parcel.WriteBool(valid)) {
1433 ANS_LOGE("Failed to write flags for the notification");
1434 return false;
1435 }
1436
1437 if (valid) {
1438 if (!parcel.WriteParcelable(notificationFlags_.get())) {
1439 ANS_LOGE("Failed to write notification flags");
1440 return false;
1441 }
1442 }
1443
1444 valid = notificationFlagsOfDevices_ ? true : false;
1445 if (!parcel.WriteBool(valid)) {
1446 ANS_LOGE("Failed to write notification device flags cause invalid sptr");
1447 return false;
1448 }
1449
1450 if (valid) {
1451 if (!parcel.WriteInt32(static_cast<int32_t>(notificationFlagsOfDevices_->size()))) {
1452 ANS_LOGE("Failed to write notification devices flags size");
1453 return false;
1454 }
1455 for (auto deviceFlag : *notificationFlagsOfDevices_) {
1456 if (!parcel.WriteString(deviceFlag.first)) {
1457 ANS_LOGE("Failed to write notification devices flags key");
1458 return false;
1459 }
1460 if (!parcel.WriteParcelable(deviceFlag.second.get())) {
1461 ANS_LOGE("Failed to write notification devices flags value");
1462 return false;
1463 }
1464 }
1465 }
1466
1467 valid = unifiedGroupInfo_ ? true : false;
1468 if (!parcel.WriteBool(valid)) {
1469 ANS_LOGE("Failed to write unifiedGroupInfo for the notification");
1470 return false;
1471 }
1472
1473 if (valid) {
1474 if (!parcel.WriteParcelable(unifiedGroupInfo_.get())) {
1475 ANS_LOGE("Failed to write notification unifiedGroupInfo");
1476 return false;
1477 }
1478 }
1479
1480 valid = notificationBundleOption_ != nullptr ? true : false;
1481 if (!parcel.WriteBool(valid)) {
1482 ANS_LOGE("Failed to write bundleOption for the notification");
1483 return false;
1484 }
1485
1486 if (valid) {
1487 if (!parcel.WriteParcelable(notificationBundleOption_.get())) {
1488 ANS_LOGE("Failed to write notification bundleOption");
1489 return false;
1490 }
1491 }
1492
1493 valid = agentBundle_ != nullptr ? true : false;
1494 if (!parcel.WriteBool(valid)) {
1495 ANS_LOGE("Failed to write agentBundle for the notification");
1496 return false;
1497 }
1498
1499 if (valid) {
1500 if (!parcel.WriteParcelable(agentBundle_.get())) {
1501 ANS_LOGE("Failed to write notification agentBundle");
1502 return false;
1503 }
1504 }
1505
1506 if (!parcel.WriteInt64(updateDeadLine_)) {
1507 ANS_LOGE("Failed to write max update time");
1508 return false;
1509 }
1510
1511 if (!parcel.WriteInt64(finishDeadLine_)) {
1512 ANS_LOGE("Failed to write max finish time");
1513 return false;
1514 }
1515
1516 return true;
1517 }
1518
Unmarshalling(Parcel & parcel)1519 NotificationRequest *NotificationRequest::Unmarshalling(Parcel &parcel)
1520 {
1521 auto objptr = new (std::nothrow) NotificationRequest();
1522 if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
1523 delete objptr;
1524 objptr = nullptr;
1525 }
1526
1527 return objptr;
1528 }
1529
ReadFromParcel(Parcel & parcel)1530 bool NotificationRequest::ReadFromParcel(Parcel &parcel)
1531 {
1532 notificationId_ = parcel.ReadInt32();
1533 color_ = parcel.ReadUint32();
1534 badgeNumber_ = parcel.ReadUint32();
1535 progressValue_ = parcel.ReadInt32();
1536 progressMax_ = parcel.ReadInt32();
1537 createTime_ = parcel.ReadInt64();
1538 deliveryTime_ = parcel.ReadInt64();
1539 autoDeletedTime_ = parcel.ReadInt64();
1540
1541 creatorPid_ = static_cast<pid_t>(parcel.ReadInt32());
1542 creatorUid_ = parcel.ReadInt32();
1543 ownerUid_ = parcel.ReadInt32();
1544 creatorUserId_ = parcel.ReadInt32();
1545 ownerUserId_ = parcel.ReadInt32();
1546 receiverUserId_ = parcel.ReadInt32();
1547 creatorInstanceKey_ = parcel.ReadInt32();
1548 notificationControlFlags_ = parcel.ReadUint32();
1549 publishDelayTime_ = parcel.ReadUint32();
1550 hashCodeGenerateType_ = parcel.ReadUint32();
1551 collaboratedReminderFlag_ = parcel.ReadUint32();
1552
1553 if (!parcel.ReadString(appInstanceKey_)) {
1554 ANS_LOGE("Failed to read Instance key");
1555 return false;
1556 }
1557
1558 if (!parcel.ReadString(settingsText_)) {
1559 ANS_LOGE("Failed to read settings text");
1560 return false;
1561 }
1562
1563 if (!parcel.ReadString(creatorBundleName_)) {
1564 ANS_LOGE("Failed to read creator bundle name");
1565 return false;
1566 }
1567
1568 if (!parcel.ReadString(ownerBundleName_)) {
1569 ANS_LOGE("Failed to read owner bundle name");
1570 return false;
1571 }
1572
1573 if (!parcel.ReadString(groupName_)) {
1574 ANS_LOGE("Failed to read group name");
1575 return false;
1576 }
1577
1578 if (!parcel.ReadString(statusBarText_)) {
1579 ANS_LOGE("Failed to read status bar text");
1580 return false;
1581 }
1582
1583 if (!parcel.ReadString(label_)) {
1584 ANS_LOGE("Failed to read label");
1585 return false;
1586 }
1587
1588 if (!parcel.ReadString(shortcutId_)) {
1589 ANS_LOGE("Failed to read shortcut Id");
1590 return false;
1591 }
1592
1593 if (!parcel.ReadString(sortingKey_)) {
1594 ANS_LOGE("Failed to read sorting key");
1595 return false;
1596 }
1597
1598 if (!parcel.ReadString(classification_)) {
1599 ANS_LOGE("Failed to read classification");
1600 return false;
1601 }
1602
1603 if (!parcel.ReadString(appMessageId_)) {
1604 ANS_LOGE("Failed to read appMessageId");
1605 return false;
1606 }
1607
1608 if (!parcel.ReadString(sound_)) {
1609 ANS_LOGE("Failed to read sound");
1610 return false;
1611 }
1612
1613 if (!parcel.ReadString(distributedHashCode_)) {
1614 ANS_LOGE("Failed to read distributedHashCode");
1615 return false;
1616 }
1617
1618 int32_t slotTypeValue = parcel.ReadInt32();
1619 if (slotTypeValue < 0 ||
1620 slotTypeValue >= static_cast<int>(NotificationConstant::SlotType::ILLEGAL_TYPE)) {
1621 ANS_LOGE("Invalid slot type value :%{public}d. It should be in [0 , %{public}d).",
1622 slotTypeValue, static_cast<int>(NotificationConstant::SlotType::ILLEGAL_TYPE));
1623 return false;
1624 }
1625 slotType_ = static_cast<NotificationConstant::SlotType>(slotTypeValue);
1626 int32_t groupAlertTypeValue = parcel.ReadInt32();
1627 if (groupAlertTypeValue < 0 ||
1628 groupAlertTypeValue >= static_cast<int>(NotificationRequest::GroupAlertType::ILLEGAL_TYPE)) {
1629 ANS_LOGE("Invalid groupAlert type value :%{public}d. It should be in [0 , %{public}d).",
1630 groupAlertTypeValue, static_cast<int>(NotificationRequest::GroupAlertType::ILLEGAL_TYPE));
1631 return false;
1632 }
1633 groupAlertType_ = static_cast<NotificationRequest::GroupAlertType>(groupAlertTypeValue);
1634 int32_t visiblenessTypeValue = parcel.ReadInt32();
1635 if (visiblenessTypeValue < 0 ||
1636 visiblenessTypeValue >= static_cast<int>(NotificationConstant::VisiblenessType::ILLEGAL_TYPE)) {
1637 ANS_LOGE("Invalid visibleness type value :%{public}d. It should be in [0 , %{public}d).",
1638 visiblenessTypeValue, static_cast<int>(NotificationConstant::VisiblenessType::ILLEGAL_TYPE));
1639 return false;
1640 }
1641 visiblenessType_ = static_cast<NotificationConstant::VisiblenessType>(visiblenessTypeValue);
1642 int32_t badgeStyleValue = parcel.ReadInt32();
1643 if (badgeStyleValue < 0) {
1644 ANS_LOGE("Invalid badge style value :%{public}d. It should be greater than 0.", badgeStyleValue);
1645 return false;
1646 }
1647 if (badgeStyleValue >= static_cast<int>(NotificationRequest::BadgeStyle::ILLEGAL_TYPE)) {
1648 badgeStyleValue = static_cast<int>(NotificationRequest::BadgeStyle::NONE);
1649 ANS_LOGE("The badge style value is too large, set it to the default enumeration value: %{public}d.",
1650 static_cast<int>(NotificationRequest::BadgeStyle::NONE));
1651 }
1652 badgeStyle_ = static_cast<NotificationRequest::BadgeStyle>(badgeStyleValue);
1653 int32_t notificationContentTypeValue = parcel.ReadInt32();
1654 if (notificationContentTypeValue <= static_cast<int>(NotificationContent::Type::NONE) ||
1655 notificationContentTypeValue >= static_cast<int>(NotificationContent::Type::ILLEGAL_TYPE)) {
1656 ANS_LOGE("Invalid notification content type value :%{public}d. It should be in (%{public}d , %{public}d)",
1657 notificationContentTypeValue, static_cast<int>(NotificationContent::Type::NONE),
1658 static_cast<int>(NotificationContent::Type::ILLEGAL_TYPE));
1659 return false;
1660 }
1661 notificationContentType_ = static_cast<NotificationContent::Type>(notificationContentTypeValue);
1662
1663 showDeliveryTime_ = parcel.ReadBool();
1664 tapDismissed_ = parcel.ReadBool();
1665 colorEnabled_ = parcel.ReadBool();
1666 alertOneTime_ = parcel.ReadBool();
1667 showStopwatch_ = parcel.ReadBool();
1668 isCountdown_ = parcel.ReadBool();
1669 inProgress_ = parcel.ReadBool();
1670 groupOverview_ = parcel.ReadBool();
1671 progressIndeterminate_ = parcel.ReadBool();
1672 unremovable_ = parcel.ReadBool();
1673 floatingIcon_ = parcel.ReadBool();
1674 onlyLocal_ = parcel.ReadBool();
1675 permitted_ = parcel.ReadBool();
1676 isAgent_ = parcel.ReadBool();
1677 isRemoveAllowed_ = parcel.ReadBool();
1678 forceDistributed_ = parcel.ReadBool();
1679 notDistributed_ = parcel.ReadBool();
1680
1681 bool valid {false};
1682
1683 valid = parcel.ReadBool();
1684 if (valid) {
1685 wantAgent_ = std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>(
1686 parcel.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>());
1687 if (!wantAgent_) {
1688 ANS_LOGE("Failed to read wantAgent");
1689 return false;
1690 }
1691 }
1692
1693 valid = parcel.ReadBool();
1694 if (valid) {
1695 removalWantAgent_ = std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>(
1696 parcel.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>());
1697 if (!removalWantAgent_) {
1698 ANS_LOGE("Failed to read removalWantAgent");
1699 return false;
1700 }
1701 }
1702
1703 valid = parcel.ReadBool();
1704 if (valid) {
1705 maxScreenWantAgent_ = std::shared_ptr<AbilityRuntime::WantAgent::WantAgent>(
1706 parcel.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>());
1707 if (!maxScreenWantAgent_) {
1708 ANS_LOGE("Failed to read maxScreenWantAgent");
1709 return false;
1710 }
1711 }
1712
1713 valid = parcel.ReadBool();
1714 if (valid) {
1715 additionalParams_ = std::shared_ptr<AAFwk::WantParams>(parcel.ReadParcelable<AAFwk::WantParams>());
1716 if (!additionalParams_) {
1717 ANS_LOGE("Failed to read additionalParams");
1718 return false;
1719 }
1720 }
1721
1722 valid = parcel.ReadBool();
1723 if (valid) {
1724 littleIcon_ = std::shared_ptr<Media::PixelMap>(parcel.ReadParcelable<Media::PixelMap>());
1725 }
1726
1727 valid = parcel.ReadBool();
1728 if (valid) {
1729 bigIcon_ = std::shared_ptr<Media::PixelMap>(parcel.ReadParcelable<Media::PixelMap>());
1730 if (!bigIcon_) {
1731 ANS_LOGE("Failed to read bigIcon");
1732 return false;
1733 }
1734 }
1735
1736 valid = parcel.ReadBool();
1737 if (valid) {
1738 overlayIcon_ = std::shared_ptr<Media::PixelMap>(parcel.ReadParcelable<Media::PixelMap>());
1739 if (!overlayIcon_) {
1740 ANS_LOGE("Failed to read overlayIcon");
1741 return false;
1742 }
1743 }
1744
1745 valid = parcel.ReadBool();
1746 if (valid) {
1747 notificationContent_ = std::shared_ptr<NotificationContent>(parcel.ReadParcelable<NotificationContent>());
1748 if (!notificationContent_) {
1749 ANS_LOGE("Failed to read notificationContent");
1750 return false;
1751 }
1752 }
1753
1754 auto vsize = parcel.ReadUint64();
1755 vsize = (vsize < NotificationRequest::MAX_ACTION_BUTTONS) ? vsize : NotificationRequest::MAX_ACTION_BUTTONS;
1756 for (uint64_t it = 0; it < vsize; ++it) {
1757 auto member = std::shared_ptr<NotificationActionButton>(parcel.ReadParcelable<NotificationActionButton>());
1758 if (member == nullptr) {
1759 actionButtons_.clear();
1760 ANS_LOGE("Failed to read actionButton");
1761 return false;
1762 }
1763
1764 actionButtons_.emplace_back(member);
1765 }
1766
1767 isCoverActionButtons_ = parcel.ReadBool();
1768 isUpdateByOwnerAllowed_ = parcel.ReadBool();
1769 distributedCollaborate_ = parcel.ReadBool();
1770 updateOnly_ = parcel.ReadBool();
1771
1772 vsize = parcel.ReadUint64();
1773 vsize = (vsize < NotificationRequest::MAX_MESSAGE_USERS) ? vsize : NotificationRequest::MAX_MESSAGE_USERS;
1774 for (uint64_t it = 0; it < vsize; ++it) {
1775 auto member = std::shared_ptr<MessageUser>(parcel.ReadParcelable<MessageUser>());
1776 if (member == nullptr) {
1777 ANS_LOGE("Failed to read messageUser");
1778 messageUsers_.clear();
1779 return false;
1780 }
1781
1782 messageUsers_.emplace_back(member);
1783 }
1784
1785 if (!parcel.ReadStringVector(&userInputHistory_)) {
1786 ANS_LOGE("Failed to read userInputHistory");
1787 return false;
1788 }
1789
1790 auto pOpt = parcel.ReadParcelable<NotificationDistributedOptions>();
1791 if (pOpt == nullptr) {
1792 ANS_LOGE("Failed to read distributedOptions");
1793 return false;
1794 }
1795 distributedOptions_ = *pOpt;
1796 delete pOpt;
1797 pOpt = nullptr;
1798
1799 valid = parcel.ReadBool();
1800 if (valid) {
1801 notificationTemplate_ = std::shared_ptr<NotificationTemplate>(parcel.ReadParcelable<NotificationTemplate>());
1802 if (!notificationTemplate_) {
1803 ANS_LOGE("Failed to read notificationTemplate");
1804 return false;
1805 }
1806 }
1807
1808 valid = parcel.ReadBool();
1809 if (valid) {
1810 notificationFlags_ = std::shared_ptr<NotificationFlags>(parcel.ReadParcelable<NotificationFlags>());
1811 if (!notificationFlags_) {
1812 ANS_LOGE("Failed to read notificationFlags");
1813 return false;
1814 }
1815 }
1816
1817 valid = parcel.ReadBool();
1818 if (valid) {
1819 notificationFlagsOfDevices_ = std::make_shared<std::map<std::string, std::shared_ptr<NotificationFlags>>>();
1820 int32_t mapSize = parcel.ReadInt32();
1821 mapSize = (mapSize < MAX_MAP_SIZE) ? mapSize : MAX_MAP_SIZE;
1822 for (int32_t seq = 0; seq < mapSize; seq++) {
1823 std::string deviceType = parcel.ReadString();
1824 std::shared_ptr<NotificationFlags> notificationFlags =
1825 std::shared_ptr<NotificationFlags>(parcel.ReadParcelable<NotificationFlags>());
1826 (*notificationFlagsOfDevices_)[deviceType] = notificationFlags;
1827 }
1828 }
1829
1830 valid = parcel.ReadBool();
1831 if (valid) {
1832 unifiedGroupInfo_ =
1833 std::shared_ptr<NotificationUnifiedGroupInfo>(parcel.ReadParcelable<NotificationUnifiedGroupInfo>());
1834 if (!unifiedGroupInfo_) {
1835 ANS_LOGE("Failed to read unifiedGroupInfo+");
1836 return false;
1837 }
1838 }
1839
1840 valid = parcel.ReadBool();
1841 if (valid) {
1842 notificationBundleOption_ =
1843 std::shared_ptr<NotificationBundleOption>(parcel.ReadParcelable<NotificationBundleOption>());
1844 if (!notificationBundleOption_) {
1845 ANS_LOGE("Failed to read notificationBundleOption");
1846 return false;
1847 }
1848 }
1849
1850 valid = parcel.ReadBool();
1851 if (valid) {
1852 agentBundle_ =
1853 std::shared_ptr<NotificationBundleOption>(parcel.ReadParcelable<NotificationBundleOption>());
1854 if (!agentBundle_) {
1855 ANS_LOGE("Failed to read agentBundle");
1856 return false;
1857 }
1858 }
1859
1860 updateDeadLine_ = parcel.ReadInt64();
1861 finishDeadLine_ = parcel.ReadInt64();
1862
1863 return true;
1864 }
1865
GetNowSysTime()1866 int64_t NotificationRequest::GetNowSysTime()
1867 {
1868 std::chrono::time_point<std::chrono::system_clock> nowSys = std::chrono::system_clock::now();
1869 auto epoch = nowSys.time_since_epoch();
1870 auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
1871 int64_t duration = value.count();
1872 return duration;
1873 }
1874
SetTemplate(const std::shared_ptr<NotificationTemplate> & templ)1875 void NotificationRequest::SetTemplate(const std::shared_ptr<NotificationTemplate> &templ)
1876 {
1877 notificationTemplate_ = templ;
1878 }
1879
GetTemplate() const1880 std::shared_ptr<NotificationTemplate> NotificationRequest::GetTemplate() const
1881 {
1882 return notificationTemplate_;
1883 }
1884
SetFlags(const std::shared_ptr<NotificationFlags> & flags)1885 void NotificationRequest::SetFlags(const std::shared_ptr<NotificationFlags> &flags)
1886 {
1887 notificationFlags_ = flags;
1888 }
1889
GetFlags() const1890 std::shared_ptr<NotificationFlags> NotificationRequest::GetFlags() const
1891 {
1892 return notificationFlags_;
1893 }
1894
SetDeviceFlags(const std::shared_ptr<std::map<std::string,std::shared_ptr<NotificationFlags>>> & mapFlags)1895 void NotificationRequest::SetDeviceFlags(
1896 const std::shared_ptr<std::map<std::string, std::shared_ptr<NotificationFlags>>> &mapFlags)
1897 {
1898 notificationFlagsOfDevices_ = mapFlags;
1899 }
1900
GetDeviceFlags() const1901 std::shared_ptr<std::map<std::string, std::shared_ptr<NotificationFlags>>> NotificationRequest::GetDeviceFlags() const
1902 {
1903 return notificationFlagsOfDevices_;
1904 }
1905
1906
SetBundleOption(const std::shared_ptr<NotificationBundleOption> & bundleOption)1907 void NotificationRequest::SetBundleOption(const std::shared_ptr<NotificationBundleOption> &bundleOption)
1908 {
1909 notificationBundleOption_ = bundleOption;
1910 }
1911
GetBundleOption() const1912 std::shared_ptr<NotificationBundleOption> NotificationRequest::GetBundleOption() const
1913 {
1914 return notificationBundleOption_;
1915 }
1916
SetAgentBundle(const std::shared_ptr<NotificationBundleOption> & agentBundle)1917 void NotificationRequest::SetAgentBundle(const std::shared_ptr<NotificationBundleOption> &agentBundle)
1918 {
1919 agentBundle_ = agentBundle;
1920 }
1921
GetAgentBundle() const1922 std::shared_ptr<NotificationBundleOption> NotificationRequest::GetAgentBundle() const
1923 {
1924 return agentBundle_;
1925 }
1926
SetReceiverUserId(int32_t userId)1927 void NotificationRequest::SetReceiverUserId(int32_t userId)
1928 {
1929 receiverUserId_ = userId;
1930 }
1931
GetReceiverUserId() const1932 int32_t NotificationRequest::GetReceiverUserId() const
1933 {
1934 if (receiverUserId_ == SUBSCRIBE_USER_INIT) {
1935 if (ownerUserId_ == SUBSCRIBE_USER_INIT) {
1936 return creatorUserId_;
1937 }
1938 return ownerUserId_;
1939 }
1940 return receiverUserId_;
1941 }
1942
IsRemoveAllowed() const1943 bool NotificationRequest::IsRemoveAllowed() const
1944 {
1945 return isRemoveAllowed_;
1946 }
1947
SetRemoveAllowed(bool isRemoveAllowed)1948 void NotificationRequest::SetRemoveAllowed(bool isRemoveAllowed)
1949 {
1950 isRemoveAllowed_ = isRemoveAllowed;
1951 }
1952
IsForceDistributed() const1953 bool NotificationRequest::IsForceDistributed() const
1954 {
1955 return forceDistributed_;
1956 }
1957
SetForceDistributed(bool forceDistributed)1958 void NotificationRequest::SetForceDistributed(bool forceDistributed)
1959 {
1960 forceDistributed_ = forceDistributed;
1961 }
1962
IsNotDistributed() const1963 bool NotificationRequest::IsNotDistributed() const
1964 {
1965 return notDistributed_;
1966 }
1967
SetNotDistributed(bool notDistributed)1968 void NotificationRequest::SetNotDistributed(bool notDistributed)
1969 {
1970 notDistributed_ = notDistributed;
1971 }
1972
IsSystemApp() const1973 bool NotificationRequest::IsSystemApp() const
1974 {
1975 return isSystemApp_;
1976 }
1977
SetIsSystemApp(bool isSystemApp)1978 void NotificationRequest::SetIsSystemApp(bool isSystemApp)
1979 {
1980 isSystemApp_ = isSystemApp;
1981 }
1982
CopyBase(const NotificationRequest & other)1983 void NotificationRequest::CopyBase(const NotificationRequest &other)
1984 {
1985 this->notificationId_ = other.notificationId_;
1986 this->color_ = other.color_;
1987 this->badgeNumber_ = other.badgeNumber_;
1988 this->notificationControlFlags_ = other.notificationControlFlags_;
1989 this->progressValue_ = other.progressValue_;
1990 this->progressMax_ = other.progressMax_;
1991 this->createTime_ = other.createTime_;
1992 this->deliveryTime_ = other.deliveryTime_;
1993 this->autoDeletedTime_ = other.autoDeletedTime_;
1994 this->updateDeadLine_ = other.updateDeadLine_;
1995 this->finishDeadLine_ = other.finishDeadLine_;
1996
1997 this->creatorPid_ = other.creatorPid_;
1998 this->creatorUid_ = other.creatorUid_;
1999 this->ownerUid_ = other.ownerUid_;
2000 this->creatorUserId_ = other.creatorUserId_;
2001 this->ownerUserId_ = other.ownerUserId_;
2002 this->receiverUserId_ = other.receiverUserId_;
2003 this->creatorInstanceKey_ = other.creatorInstanceKey_;
2004 this->appInstanceKey_ = other.appInstanceKey_;
2005 this->isAgent_ = other.isAgent_;
2006 this->isRemoveAllowed_ = other.isRemoveAllowed_;
2007 this->forceDistributed_ = other.forceDistributed_;
2008 this->notDistributed_ = other.notDistributed_;
2009 this->isSystemApp_ = other.isSystemApp_;
2010 this->isCoverActionButtons_ = other.isCoverActionButtons_;
2011 this->isUpdateByOwnerAllowed_ = other.isUpdateByOwnerAllowed_;
2012 this->distributedCollaborate_ = other.distributedCollaborate_;
2013 this->updateOnly_ = other.updateOnly_;
2014
2015 this->slotType_ = other.slotType_;
2016 this->settingsText_ = other.settingsText_;
2017 this->creatorBundleName_ = other.creatorBundleName_;
2018 this->ownerBundleName_ = other.ownerBundleName_;
2019 this->groupName_ = other.groupName_;
2020 this->statusBarText_ = other.statusBarText_;
2021 this->label_ = other.label_;
2022 this->shortcutId_ = other.shortcutId_;
2023 this->sortingKey_ = other.sortingKey_;
2024 this->classification_ = other.classification_;
2025 this->appMessageId_ = other.appMessageId_;
2026 this->sound_ = other.sound_;
2027 this->distributedHashCode_ = other.distributedHashCode_;
2028
2029 this->groupAlertType_ = other.groupAlertType_;
2030 this->visiblenessType_ = other.visiblenessType_;
2031 this->badgeStyle_ = other.badgeStyle_;
2032 this->notificationContentType_ = other.notificationContentType_;
2033 }
2034
CopyOther(const NotificationRequest & other)2035 void NotificationRequest::CopyOther(const NotificationRequest &other)
2036 {
2037 this->showDeliveryTime_ = other.showDeliveryTime_;
2038 this->tapDismissed_ = other.tapDismissed_;
2039 this->colorEnabled_ = other.colorEnabled_;
2040 this->alertOneTime_ = other.alertOneTime_;
2041 this->showStopwatch_ = other.showStopwatch_;
2042 this->isCountdown_ = other.isCountdown_;
2043 this->inProgress_ = other.inProgress_;
2044 this->groupOverview_ = other.groupOverview_;
2045 this->progressIndeterminate_ = other.progressIndeterminate_;
2046 this->unremovable_ = other.unremovable_;
2047 this->floatingIcon_ = other.floatingIcon_;
2048 this->onlyLocal_ = other.onlyLocal_;
2049 this->permitted_ = other.permitted_;
2050
2051 this->wantAgent_ = other.wantAgent_;
2052 this->removalWantAgent_ = other.removalWantAgent_;
2053 this->maxScreenWantAgent_ = other.maxScreenWantAgent_;
2054 this->additionalParams_ = other.additionalParams_;
2055 this->littleIcon_ = other.littleIcon_;
2056 this->bigIcon_ = other.bigIcon_;
2057 this->overlayIcon_ = other.overlayIcon_;
2058 this->notificationContent_ = other.notificationContent_;
2059
2060 this->actionButtons_ = other.actionButtons_;
2061 this->messageUsers_ = other.messageUsers_;
2062 this->userInputHistory_ = other.userInputHistory_;
2063
2064 this->distributedOptions_ = other.distributedOptions_;
2065
2066 this->notificationTemplate_ = other.notificationTemplate_;
2067 this->notificationFlags_ = other.notificationFlags_;
2068 this->agentBundle_ = other.agentBundle_;
2069 this->unifiedGroupInfo_ = other.unifiedGroupInfo_;
2070 this->notificationBundleOption_ = other.notificationBundleOption_;
2071 this->notificationFlagsOfDevices_ = other.notificationFlagsOfDevices_;
2072 this->publishDelayTime_ = other.publishDelayTime_;
2073 this->hashCodeGenerateType_ = other.hashCodeGenerateType_;
2074 this->collaboratedReminderFlag_ = other.collaboratedReminderFlag_;
2075 }
2076
ConvertObjectsToJson(nlohmann::json & jsonObject) const2077 bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const
2078 {
2079 jsonObject["wantAgent"] = wantAgent_ ? AbilityRuntime::WantAgent::WantAgentHelper::ToString(wantAgent_) : "";
2080
2081 nlohmann::json contentObj;
2082 if (notificationContent_) {
2083 if (!NotificationJsonConverter::ConvertToJson(notificationContent_.get(), contentObj)) {
2084 ANS_LOGE("Cannot convert notificationContent to JSON");
2085 return false;
2086 }
2087 }
2088 jsonObject["content"] = contentObj;
2089
2090 nlohmann::json buttonsArr = nlohmann::json::array();
2091 for (auto &btn : actionButtons_) {
2092 if (!btn) {
2093 continue;
2094 }
2095
2096 nlohmann::json btnObj;
2097 if (!NotificationJsonConverter::ConvertToJson(btn.get(), btnObj)) {
2098 ANS_LOGE("Cannot convert actionButton to JSON");
2099 return false;
2100 }
2101
2102 buttonsArr.emplace_back(btnObj);
2103 }
2104 jsonObject["actionButtons"] = buttonsArr;
2105
2106 std::string extraInfoStr;
2107 if (additionalParams_) {
2108 AAFwk::WantParamWrapper wWrapper(*additionalParams_);
2109 extraInfoStr = wWrapper.ToString();
2110 }
2111 jsonObject["extraInfo"] = extraInfoStr;
2112 jsonObject["smallIcon"] = AnsImageUtil::PackImage(littleIcon_);
2113 jsonObject["largeIcon"] = AnsImageUtil::PackImage(bigIcon_);
2114 jsonObject["overlayIcon"] = overlayIcon_ ? AnsImageUtil::PackImage(overlayIcon_) : "";
2115
2116 nlohmann::json optObj;
2117 if (!NotificationJsonConverter::ConvertToJson(&distributedOptions_, optObj)) {
2118 ANS_LOGE("Cannot convert distributedOptions to JSON");
2119 return false;
2120 }
2121 jsonObject["distributedOptions"] = optObj;
2122
2123 if (notificationFlags_) {
2124 nlohmann::json flagsObj;
2125 if (!NotificationJsonConverter::ConvertToJson(notificationFlags_.get(), flagsObj)) {
2126 ANS_LOGE("Cannot convert notificationFlags to JSON");
2127 return false;
2128 }
2129 jsonObject["notificationFlags"] = flagsObj;
2130 }
2131
2132 if (notificationBundleOption_ != nullptr) {
2133 nlohmann::json bundleOptionObj;
2134 if (!NotificationJsonConverter::ConvertToJson(notificationBundleOption_.get(), bundleOptionObj)) {
2135 ANS_LOGE("Cannot convert notificationBundleOption to JSON.");
2136 return false;
2137 }
2138 jsonObject["notificationBundleOption"] = bundleOptionObj;
2139 }
2140
2141 if (agentBundle_ != nullptr) {
2142 nlohmann::json bundleOptionObj;
2143 if (!NotificationJsonConverter::ConvertToJson(agentBundle_.get(), bundleOptionObj)) {
2144 ANS_LOGE("Cannot convert agentBundle to JSON.");
2145 return false;
2146 }
2147 jsonObject["agentBundle"] = bundleOptionObj;
2148 }
2149
2150 return true;
2151 }
2152
ConvertJsonToNumExt(NotificationRequest * target,const nlohmann::json & jsonObject)2153 void NotificationRequest::ConvertJsonToNumExt(
2154 NotificationRequest *target, const nlohmann::json &jsonObject)
2155 {
2156 const auto &jsonEnd = jsonObject.cend();
2157
2158 if (jsonObject.find("updateDeadLine") != jsonEnd && jsonObject.at("updateDeadLine").is_number_integer()) {
2159 target->updateDeadLine_ = jsonObject.at("updateDeadLine").get<int64_t>();
2160 }
2161
2162 if (jsonObject.find("finishDeadLine") != jsonEnd && jsonObject.at("finishDeadLine").is_number_integer()) {
2163 target->finishDeadLine_ = jsonObject.at("finishDeadLine").get<int64_t>();
2164 }
2165
2166 if (jsonObject.find("ownerUserId") != jsonEnd && jsonObject.at("ownerUserId").is_number_integer()) {
2167 target->ownerUserId_ = jsonObject.at("ownerUserId").get<int32_t>();
2168 }
2169
2170 if (jsonObject.find("ownerUid") != jsonEnd && jsonObject.at("ownerUid").is_number_integer()) {
2171 target->ownerUid_ = jsonObject.at("ownerUid").get<int32_t>();
2172 }
2173
2174 if (jsonObject.find("notificationControlFlags") != jsonEnd &&
2175 jsonObject.at("notificationControlFlags").is_number_integer()) {
2176 target->notificationControlFlags_ = jsonObject.at("notificationControlFlags").get<uint32_t>();
2177 }
2178 }
2179
ConvertJsonToNum(NotificationRequest * target,const nlohmann::json & jsonObject)2180 void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nlohmann::json &jsonObject)
2181 {
2182 if (target == nullptr) {
2183 ANS_LOGE("Invalid input parameter");
2184 return;
2185 }
2186
2187 const auto &jsonEnd = jsonObject.cend();
2188
2189 if (jsonObject.find("id") != jsonEnd && jsonObject.at("id").is_number_integer()) {
2190 target->notificationId_ = jsonObject.at("id").get<int32_t>();
2191 }
2192
2193 if (jsonObject.find("color") != jsonEnd && jsonObject.at("color").is_number_integer()) {
2194 target->color_ = jsonObject.at("color").get<uint32_t>();
2195 }
2196
2197 if (jsonObject.find("deliveryTime") != jsonEnd && jsonObject.at("deliveryTime").is_number_integer()) {
2198 target->deliveryTime_ = jsonObject.at("deliveryTime").get<int64_t>();
2199 }
2200
2201 if (jsonObject.find("autoDeletedTime") != jsonEnd && jsonObject.at("autoDeletedTime").is_number_integer()) {
2202 target->autoDeletedTime_ = jsonObject.at("autoDeletedTime").get<int64_t>();
2203 }
2204
2205 if (jsonObject.find("creatorUid") != jsonEnd && jsonObject.at("creatorUid").is_number_integer()) {
2206 target->creatorUid_ = jsonObject.at("creatorUid").get<int32_t>();
2207 }
2208
2209 if (jsonObject.find("creatorPid") != jsonEnd && jsonObject.at("creatorPid").is_number_integer()) {
2210 target->creatorPid_ = jsonObject.at("creatorPid").get<int32_t>();
2211 }
2212
2213 if (jsonObject.find("creatorUserId") != jsonEnd && jsonObject.at("creatorUserId").is_number_integer()) {
2214 target->creatorUserId_ = jsonObject.at("creatorUserId").get<int32_t>();
2215 }
2216
2217 if (jsonObject.find("receiverUserId") != jsonEnd && jsonObject.at("receiverUserId").is_number_integer()) {
2218 target->receiverUserId_ = jsonObject.at("receiverUserId").get<int32_t>();
2219 }
2220
2221 if (jsonObject.find("creatorInstanceKey") != jsonEnd && jsonObject.at("creatorInstanceKey").is_number_integer()) {
2222 target->creatorInstanceKey_ = jsonObject.at("creatorInstanceKey").get<int32_t>();
2223 }
2224
2225 if (jsonObject.find("badgeNumber") != jsonEnd && jsonObject.at("badgeNumber").is_number_integer()) {
2226 target->badgeNumber_ = jsonObject.at("badgeNumber").get<uint32_t>();
2227 }
2228 if (jsonObject.find("hashCodeGenerateType") != jsonEnd &&
2229 jsonObject.at("hashCodeGenerateType").is_number_integer()) {
2230 target->hashCodeGenerateType_ = jsonObject.at("hashCodeGenerateType").get<uint32_t>();
2231 }
2232 if (jsonObject.find("collaboratedReminderFlag") != jsonEnd &&
2233 jsonObject.at("collaboratedReminderFlag").is_number_integer()) {
2234 target->collaboratedReminderFlag_ = jsonObject.at("collaboratedReminderFlag").get<uint32_t>();
2235 }
2236
2237 ConvertJsonToNumExt(target, jsonObject);
2238 }
2239
ConvertJsonToString(NotificationRequest * target,const nlohmann::json & jsonObject)2240 void NotificationRequest::ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject)
2241 {
2242 if (target == nullptr) {
2243 ANS_LOGE("Invalid input parameter");
2244 return;
2245 }
2246
2247 const auto &jsonEnd = jsonObject.cend();
2248
2249 if (jsonObject.find("appInstanceKey") != jsonEnd && jsonObject.at("appInstanceKey").is_string()) {
2250 target->appInstanceKey_ = jsonObject.at("appInstanceKey").get<std::string>();
2251 }
2252
2253 if (jsonObject.find("creatorBundleName") != jsonEnd && jsonObject.at("creatorBundleName").is_string()) {
2254 target->creatorBundleName_ = jsonObject.at("creatorBundleName").get<std::string>();
2255 }
2256
2257 if (jsonObject.find("ownerBundleName") != jsonEnd && jsonObject.at("ownerBundleName").is_string()) {
2258 target->ownerBundleName_ = jsonObject.at("ownerBundleName").get<std::string>();
2259 }
2260
2261 if (jsonObject.find("groupName") != jsonEnd && jsonObject.at("groupName").is_string()) {
2262 target->groupName_ = jsonObject.at("groupName").get<std::string>();
2263 }
2264
2265 if (jsonObject.find("label") != jsonEnd && jsonObject.at("label").is_string()) {
2266 target->label_ = jsonObject.at("label").get<std::string>();
2267 }
2268
2269 if (jsonObject.find("classification") != jsonEnd && jsonObject.at("classification").is_string()) {
2270 target->classification_ = jsonObject.at("classification").get<std::string>();
2271 }
2272
2273 if (jsonObject.find("creatorBundleName") != jsonEnd && jsonObject.at("creatorBundleName").is_string()) {
2274 target->creatorBundleName_ = jsonObject.at("creatorBundleName").get<std::string>();
2275 }
2276
2277 if (jsonObject.find("distributedHashCode") != jsonEnd && jsonObject.at("distributedHashCode").is_string()) {
2278 target->distributedHashCode_ = jsonObject.at("distributedHashCode").get<std::string>();
2279 }
2280 }
2281
ConvertJsonToEnum(NotificationRequest * target,const nlohmann::json & jsonObject)2282 void NotificationRequest::ConvertJsonToEnum(NotificationRequest *target, const nlohmann::json &jsonObject)
2283 {
2284 if (target == nullptr) {
2285 ANS_LOGE("Invalid input parameter");
2286 return;
2287 }
2288
2289 const auto &jsonEnd = jsonObject.cend();
2290
2291 if (jsonObject.find("slotType") != jsonEnd && jsonObject.at("slotType").is_number_integer()) {
2292 auto slotTypeValue = jsonObject.at("slotType").get<int32_t>();
2293 target->slotType_ = static_cast<NotificationConstant::SlotType>(slotTypeValue);
2294 }
2295
2296 if (jsonObject.find("badgeIconStyle") != jsonEnd && jsonObject.at("badgeIconStyle").is_number_integer()) {
2297 auto badgeStyleValue = jsonObject.at("badgeIconStyle").get<int32_t>();
2298 target->badgeStyle_ = static_cast<NotificationRequest::BadgeStyle>(badgeStyleValue);
2299 }
2300
2301 if (jsonObject.find("notificationContentType") != jsonEnd &&
2302 jsonObject.at("notificationContentType").is_number_integer()) {
2303 auto notificationContentType = jsonObject.at("notificationContentType").get<int32_t>();
2304 target->notificationContentType_ = static_cast<NotificationContent::Type>(notificationContentType);
2305 }
2306 }
2307
ConvertJsonToBool(NotificationRequest * target,const nlohmann::json & jsonObject)2308 void NotificationRequest::ConvertJsonToBool(NotificationRequest *target, const nlohmann::json &jsonObject)
2309 {
2310 if (target == nullptr) {
2311 ANS_LOGE("Invalid input parameter");
2312 return;
2313 }
2314
2315 const auto &jsonEnd = jsonObject.cend();
2316
2317 if (jsonObject.find("showDeliveryTime") != jsonEnd && jsonObject.at("showDeliveryTime").is_boolean()) {
2318 target->showDeliveryTime_ = jsonObject.at("showDeliveryTime").get<bool>();
2319 }
2320
2321 if (jsonObject.find("tapDismissed") != jsonEnd && jsonObject.at("tapDismissed").is_boolean()) {
2322 target->tapDismissed_ = jsonObject.at("tapDismissed").get<bool>();
2323 }
2324
2325 if (jsonObject.find("colorEnabled") != jsonEnd && jsonObject.at("colorEnabled").is_boolean()) {
2326 target->colorEnabled_ = jsonObject.at("colorEnabled").get<bool>();
2327 }
2328
2329 if (jsonObject.find("isOngoing") != jsonEnd && jsonObject.at("isOngoing").is_boolean()) {
2330 target->inProgress_ = jsonObject.at("isOngoing").get<bool>();
2331 }
2332
2333 if (jsonObject.find("isAlertOnce") != jsonEnd && jsonObject.at("isAlertOnce").is_boolean()) {
2334 target->alertOneTime_ = jsonObject.at("isAlertOnce").get<bool>();
2335 }
2336
2337 if (jsonObject.find("isStopwatch") != jsonEnd && jsonObject.at("isStopwatch").is_boolean()) {
2338 target->showStopwatch_ = jsonObject.at("isStopwatch").get<bool>();
2339 }
2340
2341 if (jsonObject.find("isCountdown") != jsonEnd && jsonObject.at("isCountdown").is_boolean()) {
2342 target->isCountdown_ = jsonObject.at("isCountdown").get<bool>();
2343 }
2344
2345 if (jsonObject.find("isUnremovable") != jsonEnd && jsonObject.at("isUnremovable").is_boolean()) {
2346 target->unremovable_ = jsonObject.at("isUnremovable").get<bool>();
2347 }
2348
2349 if (jsonObject.find("isFloatingIcon") != jsonEnd && jsonObject.at("isFloatingIcon").is_boolean()) {
2350 target->floatingIcon_ = jsonObject.at("isFloatingIcon").get<bool>();
2351 }
2352
2353 if (jsonObject.find("updateOnly") != jsonEnd && jsonObject.at("updateOnly").is_boolean()) {
2354 target->updateOnly_ = jsonObject.at("updateOnly").get<bool>();
2355 }
2356
2357 if (jsonObject.find("distributedCollaborate") != jsonEnd && jsonObject.at("distributedCollaborate").is_boolean()) {
2358 target->distributedCollaborate_ = jsonObject.at("distributedCollaborate").get<bool>();
2359 }
2360
2361 ConvertJsonToBoolExt(target, jsonObject);
2362 }
2363
ConvertJsonToBoolExt(NotificationRequest * target,const nlohmann::json & jsonObject)2364 void NotificationRequest::ConvertJsonToBoolExt(NotificationRequest *target, const nlohmann::json &jsonObject)
2365 {
2366 const auto &jsonEnd = jsonObject.cend();
2367
2368 if (jsonObject.find("isAgent") != jsonEnd && jsonObject.at("isAgent").is_boolean()) {
2369 target->isAgent_ = jsonObject.at("isAgent").get<bool>();
2370 }
2371 }
2372
ConvertJsonToPixelMap(NotificationRequest * target,const nlohmann::json & jsonObject)2373 void NotificationRequest::ConvertJsonToPixelMap(NotificationRequest *target, const nlohmann::json &jsonObject)
2374 {
2375 if (target == nullptr) {
2376 ANS_LOGE("Invalid input parameter");
2377 return;
2378 }
2379
2380 const auto &jsonEnd = jsonObject.cend();
2381
2382 if (jsonObject.find("smallIcon") != jsonEnd && jsonObject.at("smallIcon").is_string()) {
2383 auto littleIconStr = jsonObject.at("smallIcon").get<std::string>();
2384 target->littleIcon_ = AnsImageUtil::UnPackImage(littleIconStr);
2385 }
2386
2387 if (jsonObject.find("largeIcon") != jsonEnd && jsonObject.at("largeIcon").is_string()) {
2388 auto bigIconStr = jsonObject.at("largeIcon").get<std::string>();
2389 target->bigIcon_ = AnsImageUtil::UnPackImage(bigIconStr);
2390 }
2391
2392 if (jsonObject.find("overlayIcon") != jsonEnd && jsonObject.at("overlayIcon").is_string()) {
2393 auto overlayIconStr = jsonObject.at("overlayIcon").get<std::string>();
2394 target->overlayIcon_ = AnsImageUtil::UnPackImage(overlayIconStr);
2395 }
2396 }
2397
ConvertJsonToNotificationContent(NotificationRequest * target,const nlohmann::json & jsonObject)2398 bool NotificationRequest::ConvertJsonToNotificationContent(
2399 NotificationRequest *target, const nlohmann::json &jsonObject)
2400 {
2401 if (target == nullptr) {
2402 ANS_LOGE("Invalid input parameter");
2403 return false;
2404 }
2405
2406 const auto &jsonEnd = jsonObject.cend();
2407
2408 if (jsonObject.find("content") != jsonEnd) {
2409 auto contentObj = jsonObject.at("content");
2410 if (!contentObj.is_null()) {
2411 auto pContent = NotificationJsonConverter::ConvertFromJson<NotificationContent>(contentObj);
2412 if (pContent == nullptr) {
2413 ANS_LOGE("Failed to parse notification content!");
2414 return false;
2415 }
2416
2417 target->notificationContent_ = std::shared_ptr<NotificationContent>(pContent);
2418 }
2419 }
2420
2421 return true;
2422 }
2423
ConvertJsonToNotificationActionButton(NotificationRequest * target,const nlohmann::json & jsonObject)2424 bool NotificationRequest::ConvertJsonToNotificationActionButton(
2425 NotificationRequest *target, const nlohmann::json &jsonObject)
2426 {
2427 if (target == nullptr) {
2428 ANS_LOGE("Invalid input parameter");
2429 return false;
2430 }
2431 int32_t targetUid = -1;
2432 if (target->GetOwnerUid() != DEFAULT_UID) {
2433 targetUid = target->GetOwnerUid();
2434 }
2435 ANS_LOGI("wantAgent Fromjson, uid = %{public}d ", targetUid);
2436
2437 const auto &jsonEnd = jsonObject.cend();
2438
2439 if (jsonObject.find("actionButtons") != jsonEnd) {
2440 auto buttonArr = jsonObject.at("actionButtons");
2441 for (auto &btnObj : buttonArr) {
2442 auto pBtn = NotificationActionButton::ConvertNotificationActionButton(targetUid, btnObj);
2443 if (pBtn == nullptr) {
2444 ANS_LOGE("Failed to parse actionButton!");
2445 return false;
2446 }
2447
2448 target->actionButtons_.emplace_back(pBtn);
2449 }
2450 }
2451
2452 return true;
2453 }
2454
ConvertJsonToNotificationDistributedOptions(NotificationRequest * target,const nlohmann::json & jsonObject)2455 bool NotificationRequest::ConvertJsonToNotificationDistributedOptions(
2456 NotificationRequest *target, const nlohmann::json &jsonObject)
2457 {
2458 if (target == nullptr) {
2459 ANS_LOGE("Invalid input parameter");
2460 return false;
2461 }
2462
2463 const auto &jsonEnd = jsonObject.cend();
2464
2465 if (jsonObject.find("distributedOptions") != jsonEnd) {
2466 auto optObj = jsonObject.at("distributedOptions");
2467 if (!optObj.is_null()) {
2468 auto *pOpt = NotificationJsonConverter::ConvertFromJson<NotificationDistributedOptions>(optObj);
2469 if (pOpt == nullptr) {
2470 ANS_LOGE("Failed to parse distributedOptions!");
2471 return false;
2472 }
2473
2474 target->distributedOptions_ = *pOpt;
2475 delete pOpt;
2476 }
2477 }
2478
2479 return true;
2480 }
2481
ConvertJsonToNotificationFlags(NotificationRequest * target,const nlohmann::json & jsonObject)2482 bool NotificationRequest::ConvertJsonToNotificationFlags(
2483 NotificationRequest *target, const nlohmann::json &jsonObject)
2484 {
2485 if (target == nullptr) {
2486 ANS_LOGE("Invalid input parameter");
2487 return false;
2488 }
2489
2490 const auto &jsonEnd = jsonObject.cend();
2491
2492 if (jsonObject.find("notificationFlags") != jsonEnd) {
2493 auto flagsObj = jsonObject.at("notificationFlags");
2494 if (!flagsObj.is_null()) {
2495 auto *pFlags = NotificationJsonConverter::ConvertFromJson<NotificationFlags>(flagsObj);
2496 if (pFlags == nullptr) {
2497 ANS_LOGE("Failed to parse notificationFlags!");
2498 return false;
2499 }
2500
2501 target->notificationFlags_ = std::shared_ptr<NotificationFlags>(pFlags);
2502 }
2503 }
2504
2505 return true;
2506 }
2507
ConvertJsonToNotificationBundleOption(NotificationRequest * target,const nlohmann::json & jsonObject)2508 bool NotificationRequest::ConvertJsonToNotificationBundleOption(
2509 NotificationRequest *target, const nlohmann::json &jsonObject)
2510 {
2511 if (target == nullptr) {
2512 ANS_LOGE("Invalid input parameter.");
2513 return false;
2514 }
2515
2516 const auto &jsonEnd = jsonObject.cend();
2517
2518 if (jsonObject.find("notificationBundleOption") != jsonEnd) {
2519 auto bundleOptionObj = jsonObject.at("notificationBundleOption");
2520 if (!bundleOptionObj.is_null()) {
2521 auto *pBundleOption = NotificationJsonConverter::ConvertFromJson<NotificationBundleOption>(bundleOptionObj);
2522 if (pBundleOption == nullptr) {
2523 ANS_LOGE("Failed to parse notificationBundleOption!");
2524 return false;
2525 }
2526
2527 target->notificationBundleOption_ = std::shared_ptr<NotificationBundleOption>(pBundleOption);
2528 }
2529 }
2530
2531 return true;
2532 }
2533
ConvertJsonToAgentBundle(NotificationRequest * target,const nlohmann::json & jsonObject)2534 bool NotificationRequest::ConvertJsonToAgentBundle(
2535 NotificationRequest *target, const nlohmann::json &jsonObject)
2536 {
2537 if (target == nullptr) {
2538 ANS_LOGE("Invalid input parameter.");
2539 return false;
2540 }
2541
2542 const auto &jsonEnd = jsonObject.cend();
2543
2544 if (jsonObject.find("agentBundle") != jsonEnd) {
2545 auto bundleOptionObj = jsonObject.at("agentBundle");
2546 if (!bundleOptionObj.is_null()) {
2547 auto *pBundleOption = NotificationJsonConverter::ConvertFromJson<NotificationBundleOption>(bundleOptionObj);
2548 if (pBundleOption == nullptr) {
2549 ANS_LOGE("Failed to parse agentBundle!");
2550 return false;
2551 }
2552
2553 target->agentBundle_ = std::shared_ptr<NotificationBundleOption>(pBundleOption);
2554 }
2555 }
2556
2557 return true;
2558 }
2559
IsCommonLiveView() const2560 bool NotificationRequest::IsCommonLiveView() const
2561 {
2562 return (slotType_ == NotificationConstant::SlotType::LIVE_VIEW) &&
2563 (notificationContentType_ == NotificationContent::Type::LIVE_VIEW);
2564 }
2565
IsSystemLiveView() const2566 bool NotificationRequest::IsSystemLiveView() const
2567 {
2568 return (slotType_ == NotificationConstant::SlotType::LIVE_VIEW) &&
2569 (notificationContentType_ == NotificationContent::Type::LOCAL_LIVE_VIEW);
2570 }
2571
CheckVersion(const sptr<NotificationRequest> & oldRequest) const2572 ErrCode NotificationRequest::CheckVersion(const sptr<NotificationRequest> &oldRequest) const
2573 {
2574 auto content = notificationContent_->GetNotificationContent();
2575 auto liveView = std::static_pointer_cast<NotificationLiveViewContent>(content);
2576 auto oldContent = oldRequest->GetContent()->GetNotificationContent();
2577 auto oldLiveView = std::static_pointer_cast<NotificationLiveViewContent>(oldContent);
2578
2579 if (oldLiveView->GetVersion() == NotificationLiveViewContent::MAX_VERSION) {
2580 return ERR_OK;
2581 }
2582 if (liveView->GetVersion() == NotificationLiveViewContent::MAX_VERSION) {
2583 ANS_LOGE("Invalid version, creator bundle name %{public}s, id %{public}d, "
2584 "old version %{public}u, new version %{public}u.", GetCreatorBundleName().c_str(),
2585 GetNotificationId(), oldLiveView->GetVersion(), liveView->GetVersion());
2586 return ERR_ANS_EXPIRED_NOTIFICATION;
2587 }
2588 if (oldLiveView->GetVersion() >= liveView->GetVersion()) {
2589 ANS_LOGE("Live view has finished, creator bundle name %{public}s, id %{public}d, "
2590 "old version %{public}u, new version %{public}u.", GetCreatorBundleName().c_str(),
2591 GetNotificationId(), oldLiveView->GetVersion(), liveView->GetVersion());
2592 return ERR_ANS_EXPIRED_NOTIFICATION;
2593 }
2594 return ERR_OK;
2595 }
2596
CheckNotificationRequest(const sptr<NotificationRequest> & oldRequest) const2597 ErrCode NotificationRequest::CheckNotificationRequest(const sptr<NotificationRequest> &oldRequest) const
2598 {
2599 if (!IsCommonLiveView()) {
2600 if ((oldRequest != nullptr) && oldRequest->IsCommonLiveView()) {
2601 ANS_LOGE("Invalid new request param, slot type %{public}d, content type %{public}d.",
2602 GetSlotType(), GetNotificationType());
2603 return ERR_ANS_INVALID_PARAM;
2604 }
2605 return ERR_OK;
2606 }
2607
2608 using StatusType = NotificationLiveViewContent::LiveViewStatus;
2609 auto content = notificationContent_->GetNotificationContent();
2610 auto liveView = std::static_pointer_cast<NotificationLiveViewContent>(content);
2611 auto status = liveView->GetLiveViewStatus();
2612 if (oldRequest == nullptr) {
2613 if (status != StatusType::LIVE_VIEW_CREATE) {
2614 ANS_LOGE("Doesn't exist live view, bundle name %{public}s, id %{public}d.",
2615 GetCreatorBundleName().c_str(), GetNotificationId());
2616 return ERR_ANS_NOTIFICATION_NOT_EXISTS;
2617 }
2618 return ERR_OK;
2619 }
2620
2621 if (!oldRequest->IsCommonLiveView()) {
2622 ANS_LOGE("Invalid old request param, slot type %{public}d, content type %{public}d.",
2623 oldRequest->GetSlotType(), oldRequest->GetNotificationType());
2624 return ERR_ANS_INVALID_PARAM;
2625 }
2626
2627 if (status == StatusType::LIVE_VIEW_CREATE) {
2628 ANS_LOGW("Repeat create live view, bundle name %{public}s, id %{public}d.",
2629 GetCreatorBundleName().c_str(), GetNotificationId());
2630 return ERR_ANS_REPEAT_CREATE;
2631 }
2632
2633 auto oldContent = oldRequest->GetContent()->GetNotificationContent();
2634 auto oldLiveView = std::static_pointer_cast<NotificationLiveViewContent>(oldContent);
2635 auto oldStatus = oldLiveView->GetLiveViewStatus();
2636 if (oldStatus == StatusType::LIVE_VIEW_END) {
2637 ANS_LOGW("Live view has finished, bundle name %{public}s, id %{public}d.",
2638 GetCreatorBundleName().c_str(), GetNotificationId());
2639 return ERR_ANS_END_NOTIFICATION;
2640 }
2641
2642 return CheckVersion(oldRequest);
2643 }
2644
FillMissingParameters(const sptr<NotificationRequest> & oldRequest)2645 void NotificationRequest::FillMissingParameters(const sptr<NotificationRequest> &oldRequest)
2646 {
2647 if (!IsCommonLiveView() || (oldRequest == nullptr)) {
2648 return;
2649 }
2650
2651 updateDeadLine_ = oldRequest->updateDeadLine_;
2652 finishDeadLine_ = oldRequest->finishDeadLine_;
2653 if (autoDeletedTime_ == NotificationConstant::INVALID_AUTO_DELETE_TIME) {
2654 autoDeletedTime_ = oldRequest->autoDeletedTime_;
2655 }
2656 if (wantAgent_ == nullptr) {
2657 wantAgent_ = oldRequest->wantAgent_;
2658 }
2659
2660 auto content = notificationContent_->GetNotificationContent();
2661 auto newLiveViewContent = std::static_pointer_cast<NotificationLiveViewContent>(content);
2662 if (newLiveViewContent->GetLiveViewStatus() ==
2663 NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE) {
2664 return;
2665 }
2666 auto newExtraInfo = newLiveViewContent->GetExtraInfo();
2667 auto oldContent = oldRequest->GetContent()->GetNotificationContent();
2668 auto oldLiveViewContent = std::static_pointer_cast<NotificationLiveViewContent>(oldContent);
2669 auto oldExtraInfo = oldLiveViewContent->GetExtraInfo();
2670 if (newExtraInfo == nullptr) {
2671 newLiveViewContent->SetExtraInfo(oldExtraInfo);
2672 } else if (oldExtraInfo != nullptr) {
2673 newExtraInfo->Remove("eventControl");
2674 auto oldKeySet = oldExtraInfo->KeySet();
2675 for (const auto &key : oldKeySet) {
2676 if (!newExtraInfo->HasParam(key)) {
2677 newExtraInfo->SetParam(key, oldExtraInfo->GetParam(key));
2678 }
2679 }
2680 }
2681
2682 auto oldIsOnlyLocalUpdate = oldLiveViewContent->GetIsOnlyLocalUpdate();
2683 if (oldIsOnlyLocalUpdate!= newLiveViewContent->GetIsOnlyLocalUpdate()) {
2684 newLiveViewContent->SetIsOnlyLocalUpdate(oldIsOnlyLocalUpdate);
2685 }
2686
2687 auto newPicture = newLiveViewContent->GetPicture();
2688 bool isSet = false;
2689 for (const auto &pictureRecord : oldLiveViewContent->GetPicture()) {
2690 if (newPicture.find(pictureRecord.first) != newPicture.end()) {
2691 continue;
2692 }
2693 newPicture[pictureRecord.first] = pictureRecord.second;
2694 isSet = true;
2695 }
2696 if (isSet) {
2697 newLiveViewContent->SetPicture(newPicture);
2698 }
2699 }
2700
GetBaseKey(const std::string & deviceId)2701 std::string NotificationRequest::GetBaseKey(const std::string &deviceId)
2702 {
2703 const char *keySpliter = "_";
2704
2705 if (distributedCollaborate_) {
2706 ANS_LOGI("NotificationRequest use collaborate!");
2707 return label_ + distributedHashCode_;
2708 }
2709
2710 std::stringstream stream;
2711 uint32_t hashCodeGeneratetype = GetHashCodeGenerateType();
2712 if (IsAgentNotification()) {
2713 if (hashCodeGeneratetype == 1) {
2714 stream << appInstanceKey_ << keySpliter << deviceId << keySpliter <<
2715 creatorUserId_ << keySpliter << creatorUid_ << keySpliter <<
2716 ownerUserId_ << keySpliter << label_ << keySpliter << notificationId_;
2717 } else {
2718 stream << appInstanceKey_ << keySpliter << deviceId << keySpliter <<
2719 ownerUserId_ << keySpliter << ownerUid_ << keySpliter <<
2720 ownerBundleName_ << keySpliter << label_ << keySpliter << notificationId_;
2721 }
2722 } else {
2723 stream << appInstanceKey_ << keySpliter << deviceId << keySpliter <<
2724 creatorUserId_ << keySpliter << creatorUid_ << keySpliter <<
2725 creatorBundleName_ << keySpliter << label_ << keySpliter << notificationId_;
2726 }
2727 return stream.str();
2728 }
2729
GetKey()2730 std::string NotificationRequest::GetKey()
2731 {
2732 std::stringstream stream;
2733 const char *keySpliter = "_";
2734 stream << REQUEST_STORAGE_KEY_PREFIX << keySpliter << GetBaseKey("");
2735 return stream.str();
2736 }
2737
GetSecureKey()2738 std::string NotificationRequest::GetSecureKey()
2739 {
2740 std::stringstream stream;
2741 const char *keySpliter = "_";
2742 stream << REQUEST_STORAGE_SECURE_KEY_PREFIX << keySpliter << GetBaseKey("");
2743 return stream.str();
2744 }
2745
CheckImageOverSizeForPixelMap(const std::shared_ptr<Media::PixelMap> & pixelMap,uint32_t maxSize)2746 bool NotificationRequest::CheckImageOverSizeForPixelMap(
2747 const std::shared_ptr<Media::PixelMap> &pixelMap, uint32_t maxSize)
2748 {
2749 if (pixelMap == nullptr) {
2750 return false;
2751 }
2752
2753 auto size = static_cast<uint32_t>(pixelMap->GetByteCount());
2754 return size > maxSize;
2755 }
2756
CheckImageSizeForConverSation(std::shared_ptr<NotificationBasicContent> & content)2757 ErrCode NotificationRequest::CheckImageSizeForConverSation(std::shared_ptr<NotificationBasicContent> &content)
2758 {
2759 auto conversationalContent = std::static_pointer_cast<NotificationConversationalContent>(content);
2760 auto picture = conversationalContent->GetMessageUser().GetPixelMap();
2761 if (CheckImageOverSizeForPixelMap(picture, MAX_ICON_SIZE)) {
2762 ANS_LOGE("The size of picture in ConversationalContent's message user exceeds limit");
2763 return ERR_ANS_ICON_OVER_SIZE;
2764 }
2765
2766 auto messages = conversationalContent->GetAllConversationalMessages();
2767 for (auto &msg : messages) {
2768 if (!msg) {
2769 continue;
2770 }
2771 auto img = msg->GetSender().GetPixelMap();
2772 if (CheckImageOverSizeForPixelMap(img, MAX_ICON_SIZE)) {
2773 ANS_LOGE("The size of picture in ConversationalContent's message exceeds limit");
2774 return ERR_ANS_ICON_OVER_SIZE;
2775 }
2776 }
2777 return ERR_OK;
2778 }
2779
CheckImageSizeForPicture(std::shared_ptr<NotificationBasicContent> & content)2780 ErrCode NotificationRequest::CheckImageSizeForPicture(std::shared_ptr<NotificationBasicContent> &content)
2781 {
2782 auto pictureContent = std::static_pointer_cast<NotificationPictureContent>(content);
2783 auto bigPicture = pictureContent->GetBigPicture();
2784 if (CheckImageOverSizeForPixelMap(bigPicture, MAX_PICTURE_SIZE)) {
2785 ANS_LOGE("The size of big picture in PictureContent exceeds limit");
2786 return ERR_ANS_PICTURE_OVER_SIZE;
2787 }
2788 return ERR_OK;
2789 }
2790
CheckImageSizeForLiveView(std::shared_ptr<NotificationBasicContent> & content)2791 ErrCode NotificationRequest::CheckImageSizeForLiveView(std::shared_ptr<NotificationBasicContent> &content)
2792 {
2793 auto liveViewContent = std::static_pointer_cast<NotificationLiveViewContent>(content);
2794 auto pictureMap = liveViewContent->GetPicture();
2795 for (const auto &pixelMapRecord : pictureMap) {
2796 if (pixelMapRecord.second.empty()) {
2797 ANS_LOGE("Picture key exist, but picture content is empty.");
2798 return ERR_ANS_INVALID_PARAM;
2799 }
2800 if (pixelMapRecord.second.size() > MAX_LIVE_VIEW_ICON_NUM) {
2801 ANS_LOGE("Picture key exist, but picture content count exceeds limit.");
2802 return ERR_ANS_INVALID_PARAM;
2803 }
2804 for (const auto &pixelMap : pixelMapRecord.second) {
2805 if (CheckImageOverSizeForPixelMap(pixelMap, MAX_ICON_SIZE)) {
2806 ANS_LOGE("The size of big picture in PictureContent exceeds limit.");
2807 return ERR_ANS_ICON_OVER_SIZE;
2808 }
2809 }
2810 }
2811 return ERR_OK;
2812 }
2813
CheckImageSizeForContent() const2814 ErrCode NotificationRequest::CheckImageSizeForContent() const
2815 {
2816 auto content = GetContent();
2817 if (content == nullptr) {
2818 ANS_LOGE("Invalid content in NotificationRequest");
2819 return ERR_OK;
2820 }
2821
2822 auto basicContent = GetContent()->GetNotificationContent();
2823 if (basicContent == nullptr) {
2824 ANS_LOGE("Invalid content in NotificationRequest");
2825 return ERR_OK;
2826 }
2827
2828 if (GetSlotType() == NotificationConstant::SlotType::LIVE_VIEW) {
2829 auto result = CheckLockScreenPictureSizeForLiveView(basicContent);
2830 if (result != ERR_OK) {
2831 return result;
2832 }
2833 }
2834
2835 auto contentType = GetNotificationType();
2836 switch (contentType) {
2837 case NotificationContent::Type::CONVERSATION:
2838 return CheckImageSizeForConverSation(basicContent);
2839 case NotificationContent::Type::PICTURE:
2840 return CheckImageSizeForPicture(basicContent);
2841 case NotificationContent::Type::LIVE_VIEW:
2842 return CheckImageSizeForLiveView(basicContent);
2843 default:
2844 return ERR_OK;
2845 }
2846 }
2847
HasUserInputButton()2848 bool NotificationRequest::HasUserInputButton()
2849 {
2850 for (std::shared_ptr<NotificationActionButton> button : actionButtons_) {
2851 if (button->GetUserInput() != nullptr) {
2852 return true;
2853 }
2854 }
2855 return false;
2856 }
2857
SetIsCoverActionButtons(bool isCoverActionButtons)2858 void NotificationRequest::SetIsCoverActionButtons(bool isCoverActionButtons)
2859 {
2860 isCoverActionButtons_ = isCoverActionButtons;
2861 }
2862
IsCoverActionButtons() const2863 bool NotificationRequest::IsCoverActionButtons() const
2864 {
2865 return isCoverActionButtons_;
2866 }
2867
SetAppMessageId(const std::string & appMessageId)2868 void NotificationRequest::SetAppMessageId(const std::string &appMessageId)
2869 {
2870 appMessageId_ = appMessageId;
2871 }
2872
GetAppMessageId() const2873 std::string NotificationRequest::GetAppMessageId() const
2874 {
2875 return appMessageId_;
2876 }
2877
SetSound(const std::string & sound)2878 void NotificationRequest::SetSound(const std::string &sound)
2879 {
2880 sound_ = sound;
2881 }
2882
GetSound() const2883 std::string NotificationRequest::GetSound() const
2884 {
2885 return sound_;
2886 }
2887
GenerateUniqueKey()2888 std::string NotificationRequest::GenerateUniqueKey()
2889 {
2890 const char *keySpliter = "_";
2891 int typeFlag = 0;
2892 if (GetSlotType() == NotificationConstant::SlotType::LIVE_VIEW) {
2893 typeFlag = 1;
2894 }
2895
2896 std::stringstream stream;
2897 if (IsAgentNotification()) {
2898 stream << ownerUid_ << keySpliter << ownerBundleName_ << keySpliter << ownerUserId_ << keySpliter <<
2899 typeFlag << keySpliter << appMessageId_;
2900 } else {
2901 stream << creatorUid_ << keySpliter << creatorBundleName_ << keySpliter << creatorUserId_ << keySpliter <<
2902 typeFlag << keySpliter << appMessageId_;
2903 }
2904 return stream.str();
2905 }
2906
SetUnifiedGroupInfo(const std::shared_ptr<NotificationUnifiedGroupInfo> & unifiedGroupInfo)2907 void NotificationRequest::SetUnifiedGroupInfo(const std::shared_ptr<NotificationUnifiedGroupInfo> &unifiedGroupInfo)
2908 {
2909 unifiedGroupInfo_ = unifiedGroupInfo;
2910 }
2911
GetUnifiedGroupInfo() const2912 std::shared_ptr<NotificationUnifiedGroupInfo> NotificationRequest::GetUnifiedGroupInfo() const
2913 {
2914 return unifiedGroupInfo_;
2915 }
2916
CheckLockScreenPictureSizeForLiveView(std::shared_ptr<NotificationBasicContent> & content)2917 ErrCode NotificationRequest::CheckLockScreenPictureSizeForLiveView(std::shared_ptr<NotificationBasicContent> &content)
2918 {
2919 auto lockScreenPicture = content->GetLockScreenPicture();
2920 if (CheckImageOverSizeForPixelMap(lockScreenPicture, MAX_PICTURE_SIZE)) {
2921 ANS_LOGE("The size of lockScreen picture in live view exceeds limit");
2922 return ERR_ANS_PICTURE_OVER_SIZE;
2923 }
2924 return ERR_OK;
2925 }
2926
SetPublishDelayTime(uint32_t delayTime)2927 void NotificationRequest::SetPublishDelayTime(uint32_t delayTime)
2928 {
2929 publishDelayTime_ = delayTime;
2930 }
2931
GetPublishDelayTime() const2932 uint32_t NotificationRequest::GetPublishDelayTime() const
2933 {
2934 return publishDelayTime_;
2935 }
2936
SetUpdateByOwnerAllowed(bool isUpdateByOwnerAllowed)2937 void NotificationRequest::SetUpdateByOwnerAllowed(bool isUpdateByOwnerAllowed)
2938 {
2939 isUpdateByOwnerAllowed_ = isUpdateByOwnerAllowed;
2940 }
2941
IsUpdateByOwnerAllowed() const2942 bool NotificationRequest::IsUpdateByOwnerAllowed() const
2943 {
2944 return isUpdateByOwnerAllowed_;
2945 }
2946
SetUpdateOnly(bool updateOnly)2947 void NotificationRequest::SetUpdateOnly(bool updateOnly)
2948 {
2949 updateOnly_ = updateOnly;
2950 }
2951
IsUpdateOnly() const2952 bool NotificationRequest::IsUpdateOnly() const
2953 {
2954 return updateOnly_;
2955 }
2956
GetLittleIconType() const2957 const std::string NotificationRequest::GetLittleIconType() const
2958 {
2959 return littleIconType_;
2960 }
2961
GetDistributedCollaborate() const2962 bool NotificationRequest::GetDistributedCollaborate() const
2963 {
2964 return distributedCollaborate_;
2965 }
2966
SetDistributedCollaborate(bool distributedCollaborate)2967 void NotificationRequest::SetDistributedCollaborate(bool distributedCollaborate)
2968 {
2969 distributedCollaborate_ = distributedCollaborate;
2970 }
2971
GetDistributedHashCode() const2972 const std::string NotificationRequest::GetDistributedHashCode() const
2973 {
2974 return distributedHashCode_;
2975 }
2976
SetDistributedHashCode(const std::string hashCode)2977 void NotificationRequest::SetDistributedHashCode(const std::string hashCode)
2978 {
2979 distributedHashCode_ = hashCode;
2980 }
2981
AdddeviceStatu(const std::string & deviceType,const std::string deviceStatu)2982 void NotificationRequest::AdddeviceStatu(const std::string &deviceType,
2983 const std::string deviceStatu)
2984 {
2985 deviceStatus_[deviceType] = deviceStatu;
2986 }
2987
GetdeviceStatus() const2988 const std::map<std::string, std::string> NotificationRequest::GetdeviceStatus() const
2989 {
2990 return deviceStatus_;
2991 }
2992 } // namespace Notification
2993 } // namespace OHOS
2994