1 /*
2 * Copyright (C) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "request_box.h"
17
18 #include "ans_image_util.h"
19 #include "ans_log_wrapper.h"
20 #include "distributed_liveview_all_scenarios_extension_wrapper.h"
21 #include "distributed_local_config.h"
22 #include "notification_constant.h"
23
24 static int32_t MAX_LINES_NUM = 7;
25
26 namespace OHOS {
27 namespace Notification {
28
NotificationRequestBox()29 NotificationRequestBox::NotificationRequestBox()
30 {
31 if (box_ == nullptr) {
32 return;
33 }
34 box_->SetMessageType(PUBLISH_NOTIFICATION);
35 }
36
NotificationRequestBox(std::shared_ptr<TlvBox> box)37 NotificationRequestBox::NotificationRequestBox(std::shared_ptr<TlvBox> box) : BoxBase(box)
38 {
39 }
40
41 #ifdef DISTRIBUTED_FEATURE_MASTER
SetNotificationHashCode(const std::string & hasdCode)42 bool NotificationRequestBox::SetNotificationHashCode(const std::string& hasdCode)
43 {
44 if (box_ == nullptr) {
45 return false;
46 }
47 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_HASHCODE, hasdCode));
48 }
49
SetSlotType(int32_t type)50 bool NotificationRequestBox::SetSlotType(int32_t type)
51 {
52 if (box_ == nullptr) {
53 return false;
54 }
55 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_SLOT_TYPE, type));
56 }
57
SetContentType(int32_t type)58 bool NotificationRequestBox::SetContentType(int32_t type)
59 {
60 if (box_ == nullptr) {
61 return false;
62 }
63 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_CONTENT_TYPE, type));
64 }
65
SetAppMessageId(const std::string & appMessageId)66 bool NotificationRequestBox::SetAppMessageId(const std::string& appMessageId)
67 {
68 if (box_ == nullptr) {
69 return false;
70 }
71 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_APP_MESSAGE_ID, appMessageId));
72 }
73
SetReminderFlag(int32_t flag)74 bool NotificationRequestBox::SetReminderFlag(int32_t flag)
75 {
76 if (box_ == nullptr) {
77 return false;
78 }
79 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_REMINDERFLAG, flag));
80 }
81
SetCreatorBundleName(const std::string & bundleName)82 bool NotificationRequestBox::SetCreatorBundleName(const std::string& bundleName)
83 {
84 if (box_ == nullptr) {
85 return false;
86 }
87 return box_->PutValue(std::make_shared<TlvItem>(BUNDLE_NAME, bundleName));
88 }
89
SetNotificationTitle(const std::string & title)90 bool NotificationRequestBox::SetNotificationTitle(const std::string& title)
91 {
92 if (box_ == nullptr) {
93 return false;
94 }
95 uint32_t maxLength = static_cast<uint32_t>(DistributedLocalConfig::GetInstance().GetTitleLength());
96 if (title.size() > maxLength) {
97 ANS_LOGI("SetNotificationTitle truncate %{public}zu %{public}u", title.size(), maxLength);
98 std::string subTitle = title.substr(0, maxLength);
99 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_TITLE, subTitle));
100 }
101 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_TITLE, title));
102 }
103
SetNotificationText(const std::string & text)104 bool NotificationRequestBox::SetNotificationText(const std::string& text)
105 {
106 if (box_ == nullptr) {
107 return false;
108 }
109 uint32_t maxLength = static_cast<uint32_t>(DistributedLocalConfig::GetInstance().GetContentLength());
110 if (text.size() > maxLength) {
111 ANS_LOGI("SetNotificationText truncate %{public}zu %{public}u", text.size(), maxLength);
112 std::string subText = text.substr(0, maxLength);
113 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_CONTENT, subText));
114 }
115 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_CONTENT, text));
116 }
117
SetNotificationAdditionalText(const std::string & text)118 bool NotificationRequestBox::SetNotificationAdditionalText(const std::string& text)
119 {
120 if (box_ == nullptr) {
121 return false;
122 }
123 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_ADDITIONAL_TEXT, text));
124 }
125
SetNotificationBriefText(const std::string & text)126 bool NotificationRequestBox::SetNotificationBriefText(const std::string& text)
127 {
128 if (box_ == nullptr) {
129 return false;
130 }
131 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_BRIEF_TEXT, text));
132 }
133
SetNotificationExpandedTitle(const std::string & text)134 bool NotificationRequestBox::SetNotificationExpandedTitle(const std::string& text)
135 {
136 if (box_ == nullptr) {
137 return false;
138 }
139 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_EXPANDED_TITLE, text));
140 }
141
SetNotificationLongText(const std::string & text)142 bool NotificationRequestBox::SetNotificationLongText(const std::string& text)
143 {
144 if (box_ == nullptr) {
145 return false;
146 }
147 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_LONG_TITLE, text));
148 }
149
SetAllLineLength(const int32_t & length)150 bool NotificationRequestBox::SetAllLineLength(const int32_t& length)
151 {
152 if (box_ == nullptr) {
153 return false;
154 }
155 return box_->PutValue(std::make_shared<TlvItem>(ALL_LINES_LENGTH, length));
156 }
157
SetNotificationAllLines(const std::vector<std::string> & allLines)158 bool NotificationRequestBox::SetNotificationAllLines(const std::vector<std::string>& allLines)
159 {
160 if (box_ == nullptr) {
161 return false;
162 }
163 int32_t index = 0;
164 for (auto& line : allLines) {
165 if (box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_ALL_LINES_START_INDEX + index, line))) {
166 index++;
167 }
168 }
169 return SetAllLineLength(index);
170 }
171
SetNotificationBigPicture(const std::shared_ptr<Media::PixelMap> & bigPicture)172 bool NotificationRequestBox::SetNotificationBigPicture(const std::shared_ptr<Media::PixelMap>& bigPicture)
173 {
174 return true;
175 }
176
SetNotificationActionName(const std::string & actionName)177 bool NotificationRequestBox::SetNotificationActionName(const std::string& actionName)
178 {
179 if (box_ == nullptr) {
180 return false;
181 }
182 return box_->PutValue(std::make_shared<TlvItem>(ACTION_BUTTON_NAME, actionName));
183 }
184
SetNotificationUserInput(const std::string & userInput)185 bool NotificationRequestBox::SetNotificationUserInput(const std::string& userInput)
186 {
187 if (box_ == nullptr) {
188 return false;
189 }
190 return box_->PutValue(std::make_shared<TlvItem>(ACTION_USER_INPUT, userInput));
191 }
192
SetSmallIcon(const std::shared_ptr<Media::PixelMap> & smallIcon)193 bool NotificationRequestBox::SetSmallIcon(const std::shared_ptr<Media::PixelMap>& smallIcon)
194 {
195 if (box_ == nullptr) {
196 return false;
197 }
198 std::vector<uint8_t> buffer;
199 DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewPiexlMap2BinFile(smallIcon, buffer);
200 ANS_LOGD("SetSmallIcon buffer size: %{public}d", static_cast<int32_t>(buffer.size()));
201 const unsigned char* begin = buffer.data();
202 return box_->PutValue(std::make_shared<TlvItem>(BUNDLE_ICON, begin, buffer.size()));
203 }
204
SetBigIcon(const std::shared_ptr<Media::PixelMap> & bigIcon,int32_t deviceType)205 bool NotificationRequestBox::SetBigIcon(const std::shared_ptr<Media::PixelMap>& bigIcon,
206 int32_t deviceType)
207 {
208 if (box_ == nullptr) {
209 return false;
210 }
211
212 if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) {
213 std::string icon;
214 std::string copyIcon = AnsImageUtil::PackImage(bigIcon);
215 auto copyPixelMap = AnsImageUtil::UnPackImage(copyIcon);
216 if (!AnsImageUtil::ImageScale(copyPixelMap, DEFAULT_ICON_WITHE, DEFAULT_ICON_HEIGHT)) {
217 return false;
218 }
219 icon = AnsImageUtil::PackImage(copyPixelMap);
220 ANS_LOGD("SetBigIcon %{public}zu, %{public}zu", copyIcon.size(), icon.size());
221 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_BIG_ICON, icon));
222 }
223 std::vector<uint8_t> buffer;
224 DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewPiexlMap2BinFile(bigIcon, buffer);
225 ANS_LOGD("SetBigIcon buffer size: %{public}d", static_cast<int32_t>(buffer.size()));
226 const unsigned char* begin = buffer.data();
227 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_BIG_ICON, begin, buffer.size()));
228 }
229
SetOverlayIcon(const std::shared_ptr<Media::PixelMap> & overlayIcon,int32_t deviceType)230 bool NotificationRequestBox::SetOverlayIcon(const std::shared_ptr<Media::PixelMap>& overlayIcon,
231 int32_t deviceType)
232 {
233 if (box_ == nullptr) {
234 return false;
235 }
236
237 if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) {
238 std::string icon;
239 std::string copyIcon = AnsImageUtil::PackImage(overlayIcon);
240 auto copyPixelMap = AnsImageUtil::UnPackImage(copyIcon);
241 if (!AnsImageUtil::ImageScale(copyPixelMap, DEFAULT_ICON_WITHE, DEFAULT_ICON_HEIGHT)) {
242 return false;
243 }
244 icon = AnsImageUtil::PackImage(copyPixelMap);
245 ANS_LOGD("SetOverlayIcon %{public}zu, %{public}zu", copyIcon.size(), icon.size());
246 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_OVERLAY_ICON, icon));
247 }
248 std::vector<uint8_t> buffer;
249 DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewPiexlMap2BinFile(overlayIcon, buffer);
250 ANS_LOGD("SetOverlayIcon buffer size: %{public}d", static_cast<int32_t>(buffer.size()));
251 const unsigned char* begin = buffer.data();
252 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_OVERLAY_ICON, begin, buffer.size()));
253 }
254
SetCommonLiveView(const std::vector<uint8_t> & byteSequence)255 bool NotificationRequestBox::SetCommonLiveView(const std::vector<uint8_t>& byteSequence)
256 {
257 if (box_ == nullptr) {
258 return false;
259 }
260 const unsigned char* begin = byteSequence.data();
261 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_COMMON_LIVEVIEW,
262 begin, byteSequence.size()));
263 }
264
SetFinishTime(int64_t time)265 bool NotificationRequestBox::SetFinishTime(int64_t time)
266 {
267 if (box_ == nullptr) {
268 return false;
269 }
270 return box_->PutValue(std::make_shared<TlvItem>(FINISH_DEADLINE_TIME, time));
271 }
272
SetAutoDeleteTime(int64_t time)273 bool NotificationRequestBox::SetAutoDeleteTime(int64_t time)
274 {
275 if (box_ == nullptr) {
276 return false;
277 }
278 return box_->PutValue(std::make_shared<TlvItem>(AUTO_DELETE_TIME, time));
279 }
280
281
SetReceiverUserId(const int32_t & userId)282 bool NotificationRequestBox::SetReceiverUserId(const int32_t& userId)
283 {
284 if (box_ == nullptr) {
285 return false;
286 }
287 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_RECEIVE_USERID, userId));
288 }
289
SetBoxExtendInfo(const std::string & extendInfo)290 bool NotificationRequestBox::SetBoxExtendInfo(const std::string& extendInfo)
291 {
292 if (box_ == nullptr) {
293 return false;
294 }
295 return box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_EXTENDINFO, extendInfo));
296 }
297
SetDeviceUserId(const int32_t & userId)298 bool NotificationRequestBox::SetDeviceUserId(const int32_t& userId)
299 {
300 if (box_ == nullptr) {
301 return false;
302 }
303 return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_USERID, userId));
304 }
305
SetDeviceId(const std::string & deviceId)306 bool NotificationRequestBox::SetDeviceId(const std::string& deviceId)
307 {
308 if (box_ == nullptr) {
309 return false;
310 }
311 return box_->PutValue(std::make_shared<TlvItem>(LOCAL_DEVICE_ID, deviceId));
312 }
313
SetActionButtonsLength(const int32_t length)314 bool NotificationRequestBox::SetActionButtonsLength(const int32_t length)
315 {
316 if (box_ == nullptr) {
317 return false;
318 }
319 return box_->PutValue(std::make_shared<TlvItem>(ACTION_BUTTONS_LENGTH, length));
320 }
321
SetActionButtonsTitle(const std::vector<std::string> & buttonsTitle)322 bool NotificationRequestBox::SetActionButtonsTitle(const std::vector<std::string>& buttonsTitle)
323 {
324 if (box_ == nullptr) {
325 return false;
326 }
327 int32_t index = 0;
328 for (auto& buttonTitle : buttonsTitle) {
329 if (box_->PutValue(
330 std::make_shared<TlvItem>(ACTION_BUTTONS_TITILE_INDEX + index, buttonTitle))) {
331 index++;
332 }
333 }
334 return SetActionButtonsLength(index);
335 }
336
SetNotificationBasicInfo(const std::string & basicInfo)337 bool NotificationRequestBox::SetNotificationBasicInfo(const std::string& basicInfo)
338 {
339 if (box_ == nullptr) {
340 return false;
341 }
342 box_->PutValue(std::make_shared<TlvItem>(NOTIFICATION_BASIC_INFO, basicInfo));
343 return true;
344 }
345 #else
GetNotificationHashCode(std::string & hasdCode) const346 bool NotificationRequestBox::GetNotificationHashCode(std::string& hasdCode) const
347 {
348 if (box_ == nullptr) {
349 return false;
350 }
351 return box_->GetStringValue(NOTIFICATION_HASHCODE, hasdCode);
352 }
353
GetSlotType(int32_t & type) const354 bool NotificationRequestBox::GetSlotType(int32_t& type) const
355 {
356 if (box_ == nullptr) {
357 return false;
358 }
359 return box_->GetInt32Value(NOTIFICATION_SLOT_TYPE, type);
360 }
361
GetContentType(int32_t & type) const362 bool NotificationRequestBox::GetContentType(int32_t& type) const
363 {
364 if (box_ == nullptr) {
365 return false;
366 }
367 return box_->GetInt32Value(NOTIFICATION_CONTENT_TYPE, type);
368 }
369
GetCreatorBundleName(std::string & bundleName) const370 bool NotificationRequestBox::GetCreatorBundleName(std::string& bundleName) const
371 {
372 if (box_ == nullptr) {
373 return false;
374 }
375 return box_->GetStringValue(BUNDLE_NAME, bundleName);
376 }
377
GetReminderFlag(int32_t & flag) const378 bool NotificationRequestBox::GetReminderFlag(int32_t& flag) const
379 {
380 if (box_ == nullptr) {
381 return false;
382 }
383 return box_->GetInt32Value(NOTIFICATION_REMINDERFLAG, flag);
384 }
385
GetNotificationTitle(std::string & title) const386 bool NotificationRequestBox::GetNotificationTitle(std::string& title) const
387 {
388 if (box_ == nullptr) {
389 return false;
390 }
391 return box_->GetStringValue(NOTIFICATION_TITLE, title);
392 }
393
GetNotificationText(std::string & text) const394 bool NotificationRequestBox::GetNotificationText(std::string& text) const
395 {
396 if (box_ == nullptr) {
397 return false;
398 }
399 return box_->GetStringValue(NOTIFICATION_CONTENT, text);
400 }
401
GetNotificationAdditionalText(std::string & text) const402 bool NotificationRequestBox::GetNotificationAdditionalText(std::string& text) const
403 {
404 if (box_ == nullptr) {
405 return false;
406 }
407 return box_->GetStringValue(NOTIFICATION_ADDITIONAL_TEXT, text);
408 }
409
GetNotificationBriefText(std::string & text) const410 bool NotificationRequestBox::GetNotificationBriefText(std::string& text) const
411 {
412 if (box_ == nullptr) {
413 return false;
414 }
415 return box_->GetStringValue(NOTIFICATION_BRIEF_TEXT, text);
416 }
417
GetNotificationExpandedTitle(std::string & text) const418 bool NotificationRequestBox::GetNotificationExpandedTitle(std::string& text) const
419 {
420 if (box_ == nullptr) {
421 return false;
422 }
423 return box_->GetStringValue(NOTIFICATION_EXPANDED_TITLE, text);
424 }
425
GetNotificationLongText(std::string & text) const426 bool NotificationRequestBox::GetNotificationLongText(std::string& text) const
427 {
428 if (box_ == nullptr) {
429 return false;
430 }
431 return box_->GetStringValue(NOTIFICATION_LONG_TITLE, text);
432 }
433
GetAllLineLength(int32_t & length) const434 bool NotificationRequestBox::GetAllLineLength(int32_t& length) const
435 {
436 if (box_ == nullptr) {
437 return false;
438 }
439 return box_->GetInt32Value(ALL_LINES_LENGTH, length);
440 }
441
GetNotificationAllLines(std::vector<std::string> & allLines) const442 bool NotificationRequestBox::GetNotificationAllLines(std::vector<std::string>& allLines) const
443 {
444 int32_t length = 0;
445 if (!GetAllLineLength(length)) {
446 return false;
447 }
448
449 if (length < 0 || length > MAX_LINES_NUM) {
450 ANS_LOGD("Invalid lines %{public}d.", length);
451 return false;
452 }
453
454 for (int i = 0; i < length; i++) {
455 std::string line;
456 if (box_->GetStringValue(NOTIFICATION_ALL_LINES_START_INDEX + i, line)) {
457 allLines.push_back(line);
458 }
459 }
460 return true;
461 }
462
GetNotificationBigPicture(std::shared_ptr<Media::PixelMap> & bigPicture) const463 bool NotificationRequestBox::GetNotificationBigPicture(std::shared_ptr<Media::PixelMap>& bigPicture) const
464 {
465 return true;
466 }
467
GetNotificationActionName(std::string & actionName) const468 bool NotificationRequestBox::GetNotificationActionName(std::string& actionName) const
469 {
470 if (box_ == nullptr) {
471 return false;
472 }
473 return box_->GetStringValue(ACTION_BUTTON_NAME, actionName);
474 }
475
GetNotificationUserInput(std::string & userInput) const476 bool NotificationRequestBox::GetNotificationUserInput(std::string& userInput) const
477 {
478 if (box_ == nullptr) {
479 return false;
480 }
481 return box_->GetStringValue(ACTION_USER_INPUT, userInput);
482 }
483
GetSmallIcon(std::shared_ptr<Media::PixelMap> & smallIcon) const484 bool NotificationRequestBox::GetSmallIcon(std::shared_ptr<Media::PixelMap>& smallIcon) const
485 {
486 if (box_ == nullptr) {
487 return false;
488 }
489 std::vector<uint8_t> buffer;
490 bool res = box_->GetBytes(BUNDLE_ICON, buffer);
491 ANS_LOGD("GetSmallIcon buffer size: %{public}d", static_cast<int32_t>(buffer.size()));
492 if (!res || buffer.size() <= 0) {
493 return false;
494 }
495 DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewBinFile2PiexlMap(smallIcon, buffer);
496 if (smallIcon == nullptr) {
497 return false;
498 }
499 return true;
500 }
501
GetBigIcon(std::shared_ptr<Media::PixelMap> & bigIcon,const int32_t deviceType) const502 bool NotificationRequestBox::GetBigIcon(std::shared_ptr<Media::PixelMap>& bigIcon, const int32_t deviceType) const
503 {
504 if (box_ == nullptr) {
505 return false;
506 }
507 if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) {
508 std::string bigIconContent;
509 if (!box_->GetStringValue(NOTIFICATION_BIG_ICON, bigIconContent)) {
510 return false;
511 }
512 ANS_LOGD("GetBigIcon %{public}zu", bigIconContent.size());
513 bigIcon = AnsImageUtil::UnPackImage(bigIconContent);
514 } else {
515 std::vector<uint8_t> buffer;
516 bool res = box_->GetBytes(NOTIFICATION_BIG_ICON, buffer);
517 ANS_LOGD("GetBigIcon buffer size: %{public}d", static_cast<int32_t>(buffer.size()));
518 if (!res || buffer.size() <= 0) {
519 return false;
520 }
521 DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewBinFile2PiexlMap(bigIcon, buffer);
522 }
523 if (bigIcon == nullptr) {
524 return false;
525 }
526 return true;
527 }
528
GetOverlayIcon(std::shared_ptr<Media::PixelMap> & overlayIcon,const int32_t deviceType) const529 bool NotificationRequestBox::GetOverlayIcon(
530 std::shared_ptr<Media::PixelMap>& overlayIcon, const int32_t deviceType) const
531 {
532 if (box_ == nullptr) {
533 return false;
534 }
535 if (deviceType == DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH) {
536 std::string overlayContent;
537 if (!box_->GetStringValue(NOTIFICATION_OVERLAY_ICON, overlayContent)) {
538 return false;
539 }
540 ANS_LOGD("GetOverlayIcon %{public}zu", overlayContent.size());
541 overlayIcon = AnsImageUtil::UnPackImage(overlayContent);
542 } else {
543 std::vector<uint8_t> buffer;
544 bool res = box_->GetBytes(NOTIFICATION_OVERLAY_ICON, buffer);
545 ANS_LOGD("GetOverlayIcon buffer size: %{public}d", static_cast<int32_t>(buffer.size()));
546 if (!res || buffer.size() <= 0) {
547 return false;
548 }
549 DISTRIBUTED_LIVEVIEW_ALL_SCENARIOS_EXTENTION_WRAPPER->UpdateLiveviewBinFile2PiexlMap(overlayIcon, buffer);
550 }
551 if (overlayIcon == nullptr) {
552 return false;
553 }
554 return true;
555 }
556
GetCommonLiveView(std::vector<uint8_t> & byteSequence) const557 bool NotificationRequestBox::GetCommonLiveView(std::vector<uint8_t>& byteSequence) const
558 {
559 if (box_ == nullptr) {
560 return false;
561 }
562 return box_->GetBytes(NOTIFICATION_COMMON_LIVEVIEW, byteSequence);
563 }
564
GetFinishTime(int64_t & time) const565 bool NotificationRequestBox::GetFinishTime(int64_t& time) const
566 {
567 if (box_ == nullptr) {
568 return false;
569 }
570 return box_->GetInt64Value(FINISH_DEADLINE_TIME, time);
571 }
572
GetAutoDeleteTime(int64_t & time) const573 bool NotificationRequestBox::GetAutoDeleteTime(int64_t& time) const
574 {
575 if (box_ == nullptr) {
576 return false;
577 }
578 return box_->GetInt64Value(AUTO_DELETE_TIME, time);
579 }
580
GetAppMessageId(std::string & appMessageId) const581 bool NotificationRequestBox::GetAppMessageId(std::string& appMessageId) const
582 {
583 if (box_ == nullptr) {
584 return false;
585 }
586 return box_->GetStringValue(NOTIFICATION_APP_MESSAGE_ID, appMessageId);
587 }
588
GetBoxExtendInfo(std::string & extendInfo) const589 bool NotificationRequestBox::GetBoxExtendInfo(std::string& extendInfo) const
590 {
591 if (box_ == nullptr) {
592 return false;
593 }
594 return box_->GetStringValue(NOTIFICATION_EXTENDINFO, extendInfo);
595 }
596
GetReceiverUserId(int32_t & userId) const597 bool NotificationRequestBox::GetReceiverUserId(int32_t& userId) const
598 {
599 if (box_ == nullptr) {
600 return false;
601 }
602 return box_->GetInt32Value(NOTIFICATION_RECEIVE_USERID, userId);
603 }
604
GetDeviceUserId(int32_t & userId) const605 bool NotificationRequestBox::GetDeviceUserId(int32_t& userId) const
606 {
607 if (box_ == nullptr) {
608 return false;
609 }
610 return box_->GetInt32Value(LOCAL_DEVICE_USERID, userId);
611 }
612
GetDeviceId(std::string & deviceId) const613 bool NotificationRequestBox::GetDeviceId(std::string& deviceId) const
614 {
615 if (box_ == nullptr) {
616 return false;
617 }
618 return box_->GetStringValue(LOCAL_DEVICE_ID, deviceId);
619 }
620
GetActionButtonsLength(int32_t & length) const621 bool NotificationRequestBox::GetActionButtonsLength(int32_t& length) const
622 {
623 if (box_ == nullptr) {
624 return false;
625 }
626 return box_->GetInt32Value(ACTION_BUTTONS_LENGTH, length);
627 }
628
GetActionButtonsTitle(std::vector<std::string> & buttonsTitle) const629 bool NotificationRequestBox::GetActionButtonsTitle(std::vector<std::string>& buttonsTitle) const
630 {
631 if (box_ == nullptr) {
632 return false;
633 }
634 int32_t length = 0;
635 if (!GetActionButtonsLength(length) || length > NotificationConstant::MAX_BTN_NUM) {
636 return false;
637 }
638 for (int i = 0; i < length; i++) {
639 std::string buttonTitle = "";
640 box_->GetStringValue(ACTION_BUTTONS_TITILE_INDEX + i, buttonTitle);
641 buttonsTitle.push_back(buttonTitle);
642 }
643 return true;
644 }
645
GetNotificationBasicInfo(std::string & basicInfo) const646 bool NotificationRequestBox::GetNotificationBasicInfo(std::string& basicInfo) const
647 {
648 if (box_ == nullptr) {
649 return false;
650 }
651 box_->GetStringValue(NOTIFICATION_BASIC_INFO, basicInfo);
652 return true;
653 }
654 #endif
655 }
656 }
657
658