1 /*
2 * Copyright (c) 2021-2022 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 "reminder_request.h"
17
18 #include "ans_log_wrapper.h"
19 #include "bundle_mgr_interface.h"
20 #include "if_system_ability_manager.h"
21 #include "ipc_skeleton.h"
22 #include "iservice_registry.h"
23 #include "os_account_manager.h"
24 #include "reminder_store.h"
25 #include "system_ability_definition.h"
26 #include "want_agent_helper.h"
27
28 namespace OHOS {
29 namespace Notification {
30 namespace {
31 const int32_t BASE_YEAR = 1900;
32 }
33
34 int32_t ReminderRequest::GLOBAL_ID = 0;
35 const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0;
36 const uint16_t ReminderRequest::INVALID_U16_VALUE = 0;
37 const uint16_t ReminderRequest::MILLI_SECONDS = 1000;
38 const uint16_t ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS = 1000;
39 const uint32_t ReminderRequest::MIN_TIME_INTERVAL_IN_MILLI = 5 * 60 * 1000;
40 const uint8_t ReminderRequest::INVALID_U8_VALUE = 0;
41 const uint8_t ReminderRequest::REMINDER_STATUS_INACTIVE = 0;
42 const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1;
43 const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2;
44 const uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4;
45 const uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8;
46 const std::string ReminderRequest::NOTIFICATION_LABEL = "REMINDER_AGENT";
47 const std::string ReminderRequest::REMINDER_EVENT_ALARM_ALERT = "ohos.event.notification.reminder.ALARM_ALERT";
48 const std::string ReminderRequest::REMINDER_EVENT_CLOSE_ALERT = "ohos.event.notification.reminder.CLOSE_ALERT";
49 const std::string ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT = "ohos.event.notification.reminder.SNOOZE_ALERT";
50 const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.notification.reminder.ALERT_TIMEOUT";
51 const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION =
52 "ohos.event.notification.reminder.REMOVE_NOTIFICATION";
53 const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID";
54 const std::string ReminderRequest::SEP_BUTTON_SINGLE = "<SEP,/>";
55 const std::string ReminderRequest::SEP_BUTTON_MULTI = "<SEP#/>";
56 const std::string ReminderRequest::SEP_WANT_AGENT = "<SEP#/>";
57 const int32_t ReminderRequest::SUNDAY = 7;
58
59 // For database recovery.
60 const std::string ReminderRequest::REMINDER_ID = "reminder_id";
61 const std::string ReminderRequest::PKG_NAME = "package_name";
62 const std::string ReminderRequest::USER_ID = "user_id";
63 const std::string ReminderRequest::UID = "uid";
64 const std::string ReminderRequest::APP_LABEL = "app_label";
65 const std::string ReminderRequest::REMINDER_TYPE = "reminder_type";
66 const std::string ReminderRequest::REMINDER_TIME = "reminder_time";
67 const std::string ReminderRequest::TRIGGER_TIME = "trigger_time";
68 const std::string ReminderRequest::RTC_TRIGGER_TIME = "rtc_trigger_time";
69 const std::string ReminderRequest::TIME_INTERVAL = "time_interval";
70 const std::string ReminderRequest::SNOOZE_TIMES = "snooze_times";
71 const std::string ReminderRequest::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times";
72 const std::string ReminderRequest::RING_DURATION = "ring_duration";
73 const std::string ReminderRequest::IS_EXPIRED = "is_expired";
74 const std::string ReminderRequest::IS_ACTIVE = "is_active";
75 const std::string ReminderRequest::STATE = "state";
76 const std::string ReminderRequest::ZONE_ID = "zone_id";
77 const std::string ReminderRequest::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout";
78 const std::string ReminderRequest::ACTION_BUTTON_INFO = "button_info";
79 const std::string ReminderRequest::SLOT_ID = "slot_id";
80 const std::string ReminderRequest::NOTIFICATION_ID = "notification_id";
81 const std::string ReminderRequest::TITLE = "title";
82 const std::string ReminderRequest::CONTENT = "content";
83 const std::string ReminderRequest::SNOOZE_CONTENT = "snooze_content";
84 const std::string ReminderRequest::EXPIRED_CONTENT = "expired_content";
85 const std::string ReminderRequest::AGENT = "agent";
86 const std::string ReminderRequest::MAX_SCREEN_AGENT = "maxScreen_agent";
87
88 std::string ReminderRequest::sqlOfAddColumns = "";
89 std::vector<std::string> ReminderRequest::columns;
90
ReminderRequest()91 ReminderRequest::ReminderRequest()
92 {
93 InitServerObj();
94 }
95
ReminderRequest(const ReminderRequest & other)96 ReminderRequest::ReminderRequest(const ReminderRequest &other)
97 {
98 this->content_ = other.content_;
99 this->expiredContent_ = other.expiredContent_;
100 this->snoozeContent_ = other.snoozeContent_;
101 this->displayContent_ = other.displayContent_;
102 this->title_ = other.title_;
103 this->isExpired_ = other.isExpired_;
104 this->snoozeTimes_ = other.snoozeTimes_;
105 this->snoozeTimesDynamic_ = other.snoozeTimesDynamic_;
106 this->state_ = other.state_;
107 this->notificationId_ = other.notificationId_;
108 this->reminderId_ = other.reminderId_;
109 this->reminderTimeInMilli_ = other.reminderTimeInMilli_;
110 this->ringDurationInMilli_ = other.ringDurationInMilli_;
111 this->triggerTimeInMilli_ = other.triggerTimeInMilli_;
112 this->timeIntervalInMilli_ = other.timeIntervalInMilli_;
113 this->reminderType_ = other.reminderType_;
114 this->slotType_ = other.slotType_;
115 this->notificationRequest_ = other.notificationRequest_;
116 this->wantAgentInfo_ = other.wantAgentInfo_;
117 this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_;
118 this->actionButtonMap_ = other.actionButtonMap_;
119 }
120
ReminderRequest(int32_t reminderId)121 ReminderRequest::ReminderRequest(int32_t reminderId)
122 {
123 reminderId_ = reminderId;
124 InitServerObj();
125 }
126
ReminderRequest(ReminderType reminderType)127 ReminderRequest::ReminderRequest(ReminderType reminderType)
128 {
129 reminderType_ = reminderType;
130 InitServerObj();
131 }
132
CanRemove() const133 bool ReminderRequest::CanRemove() const
134 {
135 if ((state_ & (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE)) == 0) {
136 return true;
137 }
138 return false;
139 }
140
CanShow() const141 bool ReminderRequest::CanShow() const
142 {
143 // when system time change by user manually, and the reminde is to show immediately,
144 // the show reminder just need to be triggered by ReminderDataManager#RefreshRemindersLocked(uint8_t).
145 // we need to make the REMINDER_EVENT_ALARM_ALERT do nothing.
146 uint64_t nowInstantMilli = GetNowInstantMilli();
147 if (nowInstantMilli == 0) {
148 return false;
149 }
150 if ((nowInstantMilli - GetReminderTimeInMilli()) < MIN_TIME_INTERVAL_IN_MILLI) {
151 return false;
152 }
153 return true;
154 }
155
Dump() const156 std::string ReminderRequest::Dump() const
157 {
158 const time_t nextTriggerTime = static_cast<time_t>(triggerTimeInMilli_ / MILLI_SECONDS);
159 std::string dateTimeInfo = GetTimeInfoInner(nextTriggerTime, TimeFormat::YMDHMS);
160 return "Reminder["
161 "reminderId=" + std::to_string(reminderId_) +
162 ", type=" + std::to_string(static_cast<uint8_t>(reminderType_)) +
163 ", state=" + GetState(state_) +
164 ", nextTriggerTime=" + dateTimeInfo.c_str() +
165 "]";
166 }
167
SetActionButton(const std::string & title,const ActionButtonType & type)168 ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type)
169 {
170 if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE)) {
171 ANSR_LOGI("Button type only support: %{public}d or %{public}d",
172 static_cast<uint8_t>(ActionButtonType::CLOSE), static_cast<uint8_t>(ActionButtonType::SNOOZE));
173 return *this;
174 }
175 ActionButtonInfo actionButtonInfo;
176 actionButtonInfo.type = type;
177 actionButtonInfo.title = title;
178 actionButtonMap_.insert(std::pair<ActionButtonType, ActionButtonInfo>(type, actionButtonInfo));
179 return *this;
180 }
181
SetContent(const std::string & content)182 ReminderRequest& ReminderRequest::SetContent(const std::string &content)
183 {
184 content_ = content;
185 return *this;
186 }
187
SetExpiredContent(const std::string & expiredContent)188 ReminderRequest& ReminderRequest::SetExpiredContent(const std::string &expiredContent)
189 {
190 expiredContent_ = expiredContent;
191 return *this;
192 }
193
SetExpired(bool isExpired)194 void ReminderRequest::SetExpired(bool isExpired)
195 {
196 isExpired_ = isExpired;
197 }
198
InitReminderId()199 void ReminderRequest::InitReminderId()
200 {
201 std::lock_guard<std::mutex> lock(std::mutex);
202 if (GLOBAL_ID < 0) {
203 ANSR_LOGW("GLOBAL_ID overdule");
204 GLOBAL_ID = 0;
205 }
206 reminderId_ = ++GLOBAL_ID;
207 ANSR_LOGI("reminderId_=%{public}d", reminderId_);
208 }
209
InitUserId(const int32_t & userId)210 void ReminderRequest::InitUserId(const int32_t &userId)
211 {
212 userId_ = userId;
213 }
214
InitUid(const int32_t & uid)215 void ReminderRequest::InitUid(const int32_t &uid)
216 {
217 uid_ = uid;
218 }
219
IsExpired() const220 bool ReminderRequest::IsExpired() const
221 {
222 return isExpired_;
223 }
224
IsShowing() const225 bool ReminderRequest::IsShowing() const
226 {
227 if ((state_ & REMINDER_STATUS_SHOWING) != 0) {
228 return true;
229 }
230 return false;
231 }
232
OnClose(bool updateNext)233 void ReminderRequest::OnClose(bool updateNext)
234 {
235 if ((state_ & REMINDER_STATUS_SHOWING) == 0) {
236 ANSR_LOGE("onClose, the state of reminder is incorrect, state:%{public}s", GetState(state_).c_str());
237 return;
238 }
239 SetState(false, REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE, "onClose()");
240 if ((state_ & REMINDER_STATUS_ALERTING) != 0) {
241 SetState(false, REMINDER_STATUS_ALERTING, "onClose");
242 }
243 if (updateNext) {
244 uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
245 if (nextTriggerTime == INVALID_LONG_LONG_VALUE) {
246 isExpired_ = true;
247 } else {
248 SetTriggerTimeInMilli(nextTriggerTime);
249 snoozeTimesDynamic_ = snoozeTimes_;
250 }
251 }
252 }
253
OnDateTimeChange()254 bool ReminderRequest::OnDateTimeChange()
255 {
256 uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
257 return HandleSysTimeChange(triggerTimeInMilli_, nextTriggerTime);
258 }
259
HandleSysTimeChange(uint64_t oriTriggerTime,uint64_t optTriggerTime)260 bool ReminderRequest::HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime)
261 {
262 if (isExpired_) {
263 return false;
264 }
265 bool showImmediately = false;
266 if (optTriggerTime != INVALID_LONG_LONG_VALUE && optTriggerTime <= oriTriggerTime) {
267 // case1. switch to a previous time
268 SetTriggerTimeInMilli(optTriggerTime);
269 snoozeTimesDynamic_ = snoozeTimes_;
270 } else {
271 uint64_t now = GetNowInstantMilli();
272 if (now == 0) {
273 return false;
274 }
275 if (oriTriggerTime <= now) {
276 // case2. switch to a future time, trigger time is less than now time.
277 // when the reminder show immediately, trigger time will update in onShow function.
278 snoozeTimesDynamic_ = 0;
279 showImmediately = true;
280 } else {
281 // case3. switch to a future time, trigger time is larger than now time.
282 showImmediately = false;
283 }
284 }
285 return showImmediately;
286 }
287
HandleTimeZoneChange(uint64_t oldZoneTriggerTime,uint64_t newZoneTriggerTime,uint64_t optTriggerTime)288 bool ReminderRequest::HandleTimeZoneChange(
289 uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime)
290 {
291 if (isExpired_) {
292 return false;
293 }
294 ANSR_LOGD("Handle timezone change, oldZoneTriggerTime:%{public}" PRIu64 "\
295 , newZoneTriggerTime:%{public}" PRIu64 "", oldZoneTriggerTime, newZoneTriggerTime);
296 if (oldZoneTriggerTime == newZoneTriggerTime) {
297 return false;
298 }
299 bool showImmediately = false;
300 if (optTriggerTime != INVALID_LONG_LONG_VALUE && oldZoneTriggerTime < newZoneTriggerTime) {
301 // case1. timezone change to smaller
302 SetTriggerTimeInMilli(optTriggerTime);
303 snoozeTimesDynamic_ = snoozeTimes_;
304 } else {
305 // case2. timezone change to larger
306 time_t now;
307 (void)time(&now); // unit is seconds.
308 if (static_cast<int64_t>(now) < 0) {
309 ANSR_LOGE("Get now time error");
310 return false;
311 }
312 if (newZoneTriggerTime <= GetDurationSinceEpochInMilli(now)) {
313 snoozeTimesDynamic_ = 0;
314 showImmediately = true;
315 } else {
316 SetTriggerTimeInMilli(newZoneTriggerTime);
317 showImmediately = false;
318 }
319 }
320 return showImmediately;
321 }
322
OnSameNotificationIdCovered()323 void ReminderRequest::OnSameNotificationIdCovered()
324 {
325 SetState(false, REMINDER_STATUS_ALERTING | REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE,
326 "OnSameNotificationIdCovered");
327 }
328
OnShow(bool isPlaySoundOrVibration,bool isSysTimeChanged,bool allowToNotify)329 void ReminderRequest::OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify)
330 {
331 if ((state_ & (REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE)) != 0) {
332 SetState(false, REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE, "onShow()");
333 }
334 if (isSysTimeChanged) {
335 uint64_t nowInstantMilli = GetNowInstantMilli();
336 if (nowInstantMilli == 0) {
337 ANSR_LOGW("Onshow, get now time error");
338 }
339 reminderTimeInMilli_ = nowInstantMilli;
340 } else {
341 reminderTimeInMilli_ = triggerTimeInMilli_;
342 }
343 UpdateNextReminder(false);
344 if (allowToNotify) {
345 SetState(true, REMINDER_STATUS_SHOWING, "OnShow");
346 if (isPlaySoundOrVibration) {
347 SetState(true, REMINDER_STATUS_ALERTING, "OnShow");
348 }
349 UpdateNotificationStateForAlert();
350 }
351 }
352
OnShowFail()353 void ReminderRequest::OnShowFail()
354 {
355 SetState(false, REMINDER_STATUS_SHOWING, "OnShowFailed()");
356 }
357
OnSnooze()358 bool ReminderRequest::OnSnooze()
359 {
360 if ((state_ & REMINDER_STATUS_SNOOZE) != 0) {
361 ANSR_LOGW("onSnooze, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
362 return false;
363 }
364 if ((state_ & REMINDER_STATUS_ALERTING) != 0) {
365 SetState(false, REMINDER_STATUS_ALERTING, "onSnooze()");
366 }
367 if (!UpdateNextReminder(true)) {
368 return false;
369 }
370 UpdateNotificationStateForSnooze();
371 if (timeIntervalInMilli_ > 0) {
372 SetState(true, REMINDER_STATUS_SNOOZE, "onSnooze()");
373 }
374 return true;
375 }
376
OnStart()377 void ReminderRequest::OnStart()
378 {
379 if ((state_ & REMINDER_STATUS_ACTIVE) != 0) {
380 ANSR_LOGE(
381 "start failed, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
382 return;
383 }
384 if (isExpired_) {
385 ANSR_LOGE("start failed, the reminder is expired");
386 return;
387 }
388 SetState(true, REMINDER_STATUS_ACTIVE, "OnStart()");
389 }
390
OnStop()391 void ReminderRequest::OnStop()
392 {
393 ANSR_LOGI("Stop the previous active reminder, %{public}s", this->Dump().c_str());
394 if ((state_ & REMINDER_STATUS_ACTIVE) == 0) {
395 ANSR_LOGW("onStop, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
396 return;
397 }
398 SetState(false, REMINDER_STATUS_ACTIVE, "OnStop");
399 }
400
OnTerminate()401 bool ReminderRequest::OnTerminate()
402 {
403 if ((state_ & REMINDER_STATUS_ALERTING) == 0) {
404 ANSR_LOGW("onTerminate, the state of reminder is %{public}s", (GetState(state_)).c_str());
405 return false;
406 }
407 SetState(false, REMINDER_STATUS_ALERTING, "onTerminate");
408 UpdateNotificationStateForAlert();
409 return true;
410 }
411
OnTimeZoneChange()412 bool ReminderRequest::OnTimeZoneChange()
413 {
414 time_t oldZoneTriggerTime = static_cast<time_t>(triggerTimeInMilli_ / MILLI_SECONDS);
415 struct tm oriTime;
416 (void)gmtime_r(&oldZoneTriggerTime, &oriTime);
417 time_t newZoneTriggerTime = mktime(&oriTime);
418 uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
419 return HandleTimeZoneChange(
420 triggerTimeInMilli_, GetDurationSinceEpochInMilli(newZoneTriggerTime), nextTriggerTime);
421 }
422
RecoverInt64FromDb(const std::shared_ptr<NativeRdb::AbsSharedResultSet> & resultSet,const std::string & columnName,const DbRecoveryType & columnType)423 int64_t ReminderRequest::RecoverInt64FromDb(const std::shared_ptr<NativeRdb::AbsSharedResultSet> &resultSet,
424 const std::string &columnName, const DbRecoveryType &columnType)
425 {
426 if (resultSet == nullptr) {
427 ANSR_LOGE("ResultSet is null");
428 return 0;
429 }
430 switch (columnType) {
431 case (DbRecoveryType::INT): {
432 int32_t value;
433 resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value);
434 return static_cast<int64_t>(value);
435 }
436 case (DbRecoveryType::LONG): {
437 int64_t value;
438 resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value);
439 return value;
440 }
441 default: {
442 ANSR_LOGD("ColumnType not support.");
443 break;
444 }
445 }
446 ANSR_LOGE("Recover data error");
447 return 0;
448 }
449
RecoverFromDb(const std::shared_ptr<NativeRdb::AbsSharedResultSet> & resultSet)450 void ReminderRequest::RecoverFromDb(const std::shared_ptr<NativeRdb::AbsSharedResultSet> &resultSet)
451 {
452 if (resultSet == nullptr) {
453 ANSR_LOGE("ResultSet is null");
454 return;
455 }
456
457 // reminderId
458 resultSet->GetInt(ReminderStore::GetColumnIndex(REMINDER_ID), reminderId_);
459
460 // userId
461 resultSet->GetInt(ReminderStore::GetColumnIndex(USER_ID), userId_);
462
463 // bundleName
464 resultSet->GetString(ReminderStore::GetColumnIndex(PKG_NAME), bundleName_);
465
466 // uid
467 resultSet->GetInt(ReminderStore::GetColumnIndex(UID), uid_);
468
469 // reminderType
470 int32_t reminderType;
471 resultSet->GetInt(ReminderStore::GetColumnIndex(REMINDER_TYPE), reminderType);
472 reminderType_ = ReminderType(reminderType);
473
474 // reminderTime
475 reminderTimeInMilli_ =
476 static_cast<uint64_t>(RecoverInt64FromDb(resultSet, REMINDER_TIME, DbRecoveryType::LONG));
477
478 // triggerTime
479 triggerTimeInMilli_ =
480 static_cast<uint64_t>(RecoverInt64FromDb(resultSet, TRIGGER_TIME, DbRecoveryType::LONG));
481
482 // timeInterval
483 uint64_t timeIntervalInSecond =
484 static_cast<uint64_t>(RecoverInt64FromDb(resultSet, TIME_INTERVAL, DbRecoveryType::LONG));
485 SetTimeInterval(timeIntervalInSecond);
486
487 // snoozeTimes
488 snoozeTimes_ = static_cast<uint8_t>(RecoverInt64FromDb(resultSet, SNOOZE_TIMES, DbRecoveryType::INT));
489
490 // dynamicSnoozeTimes
491 snoozeTimesDynamic_ =
492 static_cast<uint8_t>(RecoverInt64FromDb(resultSet, DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT));
493
494 // ringDuration
495 uint64_t ringDurationInSecond =
496 static_cast<uint64_t>(RecoverInt64FromDb(resultSet, RING_DURATION, DbRecoveryType::LONG));
497 SetRingDuration(ringDurationInSecond);
498
499 // isExpired
500 std::string isExpired;
501 resultSet->GetString(ReminderStore::GetColumnIndex(IS_EXPIRED), isExpired);
502 isExpired_ = isExpired == "true" ? true : false;
503
504 // state
505 state_ = static_cast<uint8_t>(RecoverInt64FromDb(resultSet, STATE, DbRecoveryType::INT));
506
507 // action buttons
508 RecoverActionButton(resultSet);
509
510 // slotType
511 int32_t slotType;
512 resultSet->GetInt(ReminderStore::GetColumnIndex(SLOT_ID), slotType);
513 slotType_ = NotificationConstant::SlotType(slotType);
514
515 // notification id
516 resultSet->GetInt(ReminderStore::GetColumnIndex(NOTIFICATION_ID), notificationId_);
517
518 // title
519 resultSet->GetString(ReminderStore::GetColumnIndex(TITLE), title_);
520
521 // content
522 resultSet->GetString(ReminderStore::GetColumnIndex(CONTENT), content_);
523
524 // snoozeContent
525 resultSet->GetString(ReminderStore::GetColumnIndex(SNOOZE_CONTENT), snoozeContent_);
526
527 // expiredContent
528 resultSet->GetString(ReminderStore::GetColumnIndex(EXPIRED_CONTENT), expiredContent_);
529
530 InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent
531
532 // wantAgent
533 std::string wantAgent;
534 resultSet->GetString(ReminderStore::GetColumnIndex(AGENT), wantAgent);
535 RecoverWantAgent(wantAgent, 0);
536
537 // maxScreenWantAgent
538 std::string maxScreenWantAgent;
539 resultSet->GetString(ReminderStore::GetColumnIndex(MAX_SCREEN_AGENT), maxScreenWantAgent);
540 RecoverWantAgent(wantAgent, 1);
541 }
542
RecoverActionButton(const std::shared_ptr<NativeRdb::AbsSharedResultSet> & resultSet)543 void ReminderRequest::RecoverActionButton(const std::shared_ptr<NativeRdb::AbsSharedResultSet> &resultSet)
544 {
545 if (resultSet == nullptr) {
546 ANSR_LOGE("ResultSet is null");
547 return;
548 }
549 std::string actionButtonInfo;
550 resultSet->GetString(ReminderStore::GetColumnIndex(ACTION_BUTTON_INFO), actionButtonInfo);
551 std::vector<std::string> multiButton = StringSplit(actionButtonInfo, SEP_BUTTON_MULTI);
552 for (auto button : multiButton) {
553 std::vector<std::string> singleButton = StringSplit(button, SEP_BUTTON_SINGLE);
554 SetActionButton(singleButton.at(1), ActionButtonType(std::stoi(singleButton.at(0), nullptr)));
555 }
556 }
557
StringSplit(std::string source,const std::string & split) const558 std::vector<std::string> ReminderRequest::StringSplit(std::string source, const std::string &split) const
559 {
560 std::vector<std::string> result;
561 if (source.empty()) {
562 return result;
563 }
564 size_t pos = 0;
565 while ((pos = source.find(split)) != std::string::npos) {
566 std::string token = source.substr(0, pos);
567 if (!token.empty()) {
568 result.push_back(token);
569 }
570 source.erase(0, pos + split.length());
571 }
572 if (!source.empty()) {
573 result.push_back(source);
574 }
575 return result;
576 }
577
RecoverWantAgent(const std::string & wantAgentInfo,const uint8_t & type)578 void ReminderRequest::RecoverWantAgent(const std::string &wantAgentInfo, const uint8_t &type)
579 {
580 std::vector<std::string> info = StringSplit(wantAgentInfo, ReminderRequest::SEP_WANT_AGENT);
581 uint8_t minLen = 2;
582 if (info.size() < minLen) {
583 ANSR_LOGW("RecoverWantAgent fail");
584 return;
585 }
586 ANSR_LOGD("pkg=%{public}s, ability=%{public}s", info.at(0).c_str(), info.at(1).c_str());
587 switch (type) {
588 case 0: {
589 auto wai = std::make_shared<ReminderRequest::WantAgentInfo>();
590 wai->pkgName = info.at(0);
591 wai->abilityName = info.at(1);
592 SetWantAgentInfo(wai);
593 break;
594 }
595 case 1: {
596 auto maxScreenWantAgentInfo = std::make_shared<ReminderRequest::MaxScreenAgentInfo>();
597 maxScreenWantAgentInfo->pkgName = info.at(0);
598 maxScreenWantAgentInfo->abilityName = info.at(1);
599 SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo);
600 break;
601 }
602 default: {
603 ANSR_LOGW("RecoverWantAgent type not support");
604 break;
605 }
606 }
607 }
608
SetMaxScreenWantAgentInfo(const std::shared_ptr<MaxScreenAgentInfo> & maxScreenWantAgentInfo)609 ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo(
610 const std::shared_ptr<MaxScreenAgentInfo> &maxScreenWantAgentInfo)
611 {
612 maxScreenWantAgentInfo_ = maxScreenWantAgentInfo;
613 return *this;
614 }
615
SetNotificationId(int32_t notificationId)616 ReminderRequest& ReminderRequest::SetNotificationId(int32_t notificationId)
617 {
618 notificationId_ = notificationId;
619 return *this;
620 }
621
SetSlotType(const NotificationConstant::SlotType & slotType)622 ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotType &slotType)
623 {
624 slotType_ = slotType;
625 return *this;
626 }
627
SetSnoozeContent(const std::string & snoozeContent)628 ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent)
629 {
630 snoozeContent_ = snoozeContent;
631 return *this;
632 }
633
SetSnoozeTimes(const uint8_t snoozeTimes)634 ReminderRequest& ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes)
635 {
636 snoozeTimes_ = snoozeTimes;
637 SetSnoozeTimesDynamic(snoozeTimes);
638 return *this;
639 }
640
SetSnoozeTimesDynamic(const uint8_t snooziTimes)641 ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes)
642 {
643 snoozeTimesDynamic_ = snooziTimes;
644 return *this;
645 }
646
SetTimeInterval(const uint64_t timeIntervalInSeconds)647 ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds)
648 {
649 if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) {
650 ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range");
651 timeIntervalInMilli_ = 0;
652 } else {
653 uint64_t timeIntervalInMilli = timeIntervalInSeconds * MILLI_SECONDS;
654 if (timeIntervalInMilli > 0 && timeIntervalInMilli < MIN_TIME_INTERVAL_IN_MILLI) {
655 ANSR_LOGW("SetTimeInterval, replace to set %{public}u, for the given is 0<%{public}" PRIu64 "<%{public}u",
656 MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS, timeIntervalInSeconds,
657 MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS);
658 timeIntervalInMilli_ = MIN_TIME_INTERVAL_IN_MILLI;
659 } else {
660 timeIntervalInMilli_ = timeIntervalInMilli;
661 }
662 }
663 return *this;
664 }
665
SetTitle(const std::string & title)666 ReminderRequest& ReminderRequest::SetTitle(const std::string &title)
667 {
668 title_ = title;
669 return *this;
670 }
671
SetTriggerTimeInMilli(uint64_t triggerTimeInMilli)672 void ReminderRequest::SetTriggerTimeInMilli(uint64_t triggerTimeInMilli)
673 {
674 triggerTimeInMilli_ = triggerTimeInMilli;
675 }
676
SetWantAgentInfo(const std::shared_ptr<WantAgentInfo> & wantAgentInfo)677 ReminderRequest& ReminderRequest::SetWantAgentInfo(const std::shared_ptr<WantAgentInfo> &wantAgentInfo)
678 {
679 wantAgentInfo_ = wantAgentInfo;
680 return *this;
681 }
682
ShouldShowImmediately() const683 bool ReminderRequest::ShouldShowImmediately() const
684 {
685 uint64_t nowInstantMilli = GetNowInstantMilli();
686 if (nowInstantMilli == 0) {
687 return false;
688 }
689 if (triggerTimeInMilli_ > nowInstantMilli) {
690 return false;
691 }
692 return true;
693 }
694
GetActionButtons() const695 std::map<ReminderRequest::ActionButtonType, ReminderRequest::ActionButtonInfo> ReminderRequest::GetActionButtons(
696 ) const
697 {
698 return actionButtonMap_;
699 }
700
GetContent() const701 std::string ReminderRequest::GetContent() const
702 {
703 return content_;
704 }
705
GetExpiredContent() const706 std::string ReminderRequest::GetExpiredContent() const
707 {
708 return expiredContent_;
709 }
710
GetMaxScreenWantAgentInfo() const711 std::shared_ptr<ReminderRequest::MaxScreenAgentInfo> ReminderRequest::GetMaxScreenWantAgentInfo() const
712 {
713 return maxScreenWantAgentInfo_;
714 }
715
GetNotificationId() const716 int32_t ReminderRequest::GetNotificationId() const
717 {
718 return notificationId_;
719 }
720
GetNotificationRequest() const721 sptr<NotificationRequest> ReminderRequest::GetNotificationRequest() const
722 {
723 return notificationRequest_;
724 }
725
GetReminderId() const726 int32_t ReminderRequest::GetReminderId() const
727 {
728 return reminderId_;
729 }
730
GetReminderTimeInMilli() const731 uint64_t ReminderRequest::GetReminderTimeInMilli() const
732 {
733 return reminderTimeInMilli_;
734 }
735
SetReminderId(int32_t reminderId)736 void ReminderRequest::SetReminderId(int32_t reminderId)
737 {
738 reminderId_ = reminderId;
739 }
740
SetReminderTimeInMilli(const uint64_t reminderTimeInMilli)741 void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli)
742 {
743 reminderTimeInMilli_ = reminderTimeInMilli;
744 }
745
SetRingDuration(const uint64_t ringDurationInSeconds)746 ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds)
747 {
748 if ((ringDurationInSeconds == 0) || (ringDurationInSeconds > (UINT64_MAX / MILLI_SECONDS))) {
749 ANSR_LOGW("setRingDuration, replace to set (1s), for the given is out of legal range");
750 ringDurationInMilli_ = MILLI_SECONDS;
751 } else {
752 ringDurationInMilli_ = ringDurationInSeconds * MILLI_SECONDS;
753 }
754 return *this;
755 }
756
GetSlotType() const757 NotificationConstant::SlotType ReminderRequest::GetSlotType() const
758 {
759 return slotType_;
760 }
761
GetSnoozeContent() const762 std::string ReminderRequest::GetSnoozeContent() const
763 {
764 return snoozeContent_;
765 }
766
GetSnoozeTimes() const767 uint8_t ReminderRequest::GetSnoozeTimes() const
768 {
769 return snoozeTimes_;
770 }
771
GetSnoozeTimesDynamic() const772 uint8_t ReminderRequest::GetSnoozeTimesDynamic() const
773 {
774 return snoozeTimesDynamic_;
775 }
776
GetState() const777 uint8_t ReminderRequest::GetState() const
778 {
779 return state_;
780 }
781
GetTimeInterval() const782 uint64_t ReminderRequest::GetTimeInterval() const
783 {
784 return timeIntervalInMilli_ / MILLI_SECONDS;
785 }
786
GetTitle() const787 std::string ReminderRequest::GetTitle() const
788 {
789 return title_;
790 }
791
GetTriggerTimeInMilli() const792 uint64_t ReminderRequest::GetTriggerTimeInMilli() const
793 {
794 return triggerTimeInMilli_;
795 }
796
GetUserId() const797 int32_t ReminderRequest::GetUserId() const
798 {
799 return userId_;
800 }
801
GetUid() const802 int32_t ReminderRequest::GetUid() const
803 {
804 return uid_;
805 }
806
GetWantAgentInfo() const807 std::shared_ptr<ReminderRequest::WantAgentInfo> ReminderRequest::GetWantAgentInfo() const
808 {
809 return wantAgentInfo_;
810 }
811
GetReminderType() const812 ReminderRequest::ReminderType ReminderRequest::GetReminderType() const
813 {
814 return reminderType_;
815 }
816
GetRingDuration() const817 uint16_t ReminderRequest::GetRingDuration() const
818 {
819 return ringDurationInMilli_ / MILLI_SECONDS;
820 }
821
UpdateNextReminder()822 bool ReminderRequest::UpdateNextReminder()
823 {
824 return false;
825 }
826
SetNextTriggerTime()827 bool ReminderRequest::SetNextTriggerTime()
828 {
829 return false;
830 }
831
UpdateNotificationRequest(UpdateNotificationType type,std::string extra)832 void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std::string extra)
833 {
834 switch (type) {
835 case UpdateNotificationType::COMMON: {
836 ANSR_LOGI("UpdateNotification common information");
837 UpdateNotificationCommon();
838 break;
839 }
840 case UpdateNotificationType::REMOVAL_WANT_AGENT: {
841 ANSR_LOGI("UpdateNotification removal_want_agent");
842 AddRemovalWantAgent();
843 break;
844 }
845 case UpdateNotificationType::WANT_AGENT: {
846 ANSR_LOGI("UpdateNotification want_agent");
847 AppExecFwk::ElementName wantAgent("", wantAgentInfo_->pkgName, wantAgentInfo_->abilityName);
848 SetWantAgent(wantAgent);
849 break;
850 }
851 case UpdateNotificationType::MAX_SCREEN_WANT_AGENT: {
852 ANSR_LOGI("UpdateNotification max_screen_want_agent");
853 AppExecFwk::ElementName maxScreenWantAgent(
854 "", maxScreenWantAgentInfo_->pkgName, maxScreenWantAgentInfo_->abilityName);
855 SetMaxScreenWantAgent(maxScreenWantAgent);
856 break;
857 }
858 case UpdateNotificationType::BUNDLE_INFO: {
859 ANSR_LOGI("UpdateNotification hap information");
860 UpdateNotificationBundleInfo();
861 break;
862 }
863 case UpdateNotificationType::CONTENT: {
864 break;
865 }
866 default:
867 break;
868 }
869 }
870
Marshalling(Parcel & parcel) const871 bool ReminderRequest::Marshalling(Parcel &parcel) const
872 {
873 // write string
874 if (!parcel.WriteString(content_)) {
875 ANSR_LOGE("Failed to write content");
876 return false;
877 }
878 if (!parcel.WriteString(expiredContent_)) {
879 ANSR_LOGE("Failed to write expiredContent");
880 return false;
881 }
882 if (!parcel.WriteString(snoozeContent_)) {
883 ANSR_LOGE("Failed to write snoozeContent");
884 return false;
885 }
886 if (!parcel.WriteString(title_)) {
887 ANSR_LOGE("Failed to write title");
888 return false;
889 }
890 if (!parcel.WriteString(wantAgentInfo_->abilityName)) {
891 ANSR_LOGE("Failed to write wantAgentInfo`s abilityName");
892 return false;
893 }
894 if (!parcel.WriteString(wantAgentInfo_->pkgName)) {
895 ANSR_LOGE("Failed to write wantAgentInfo`s pkgName");
896 return false;
897 }
898 if (!parcel.WriteString(maxScreenWantAgentInfo_->abilityName)) {
899 ANSR_LOGE("Failed to write maxScreenWantAgentInfo`s abilityName");
900 return false;
901 }
902 if (!parcel.WriteString(maxScreenWantAgentInfo_->pkgName)) {
903 ANSR_LOGE("Failed to write maxScreenWantAgentInfo`s pkgName");
904 return false;
905 }
906
907 // write bool
908 if (!parcel.WriteBool(isExpired_)) {
909 ANSR_LOGE("Failed to write isExpired");
910 return false;
911 }
912
913 // write int
914 if (!parcel.WriteInt32(reminderId_)) {
915 ANSR_LOGE("Failed to write reminderId");
916 return false;
917 }
918 if (!parcel.WriteInt32(notificationId_)) {
919 ANSR_LOGE("Failed to write notificationId");
920 return false;
921 }
922 if (!parcel.WriteUint64(triggerTimeInMilli_)) {
923 ANSR_LOGE("Failed to write triggerTimeInMilli");
924 return false;
925 }
926 if (!parcel.WriteUint64(timeIntervalInMilli_)) {
927 ANSR_LOGE("Failed to write timeIntervalInMilli");
928 return false;
929 }
930 if (!parcel.WriteUint64(ringDurationInMilli_)) {
931 ANSR_LOGE("Failed to write ringDurationInMilli");
932 return false;
933 }
934 if (!parcel.WriteUint64(reminderTimeInMilli_)) {
935 ANSR_LOGE("Failed to write reminderTimeInMilli");
936 return false;
937 }
938 if (!parcel.WriteUint8(snoozeTimes_)) {
939 ANSR_LOGE("Failed to write snoozeTimes");
940 return false;
941 }
942 if (!parcel.WriteUint8(snoozeTimesDynamic_)) {
943 ANSR_LOGE("Failed to write snoozeTimesDynamic");
944 return false;
945 }
946 if (!parcel.WriteUint8(state_)) {
947 ANSR_LOGE("Failed to write state");
948 return false;
949 }
950
951 // write enum
952 if (!parcel.WriteUint8(static_cast<uint8_t>(reminderType_))) {
953 ANSR_LOGE("Failed to write reminder type");
954 return false;
955 }
956 if (!parcel.WriteInt32(static_cast<int32_t>(slotType_))) {
957 ANSR_LOGE("Failed to write slot type");
958 return false;
959 }
960
961 // write map
962 if (!parcel.WriteUint64(static_cast<uint64_t>(actionButtonMap_.size()))) {
963 ANSR_LOGE("Failed to write action button size");
964 return false;
965 }
966 for (auto button : actionButtonMap_) {
967 if (!parcel.WriteUint8(static_cast<uint8_t>(button.first))) {
968 ANSR_LOGE("Failed to write action button type");
969 return false;
970 }
971 if (!parcel.WriteString(static_cast<std::string>(button.second.title))) {
972 ANSR_LOGE("Failed to write action button title");
973 return false;
974 }
975 }
976 return true;
977 }
978
Unmarshalling(Parcel & parcel)979 ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel)
980 {
981 auto objptr = new (std::nothrow) ReminderRequest();
982 if (objptr == nullptr) {
983 ANSR_LOGE("Failed to create reminder due to no memory.");
984 return objptr;
985 }
986 if (!objptr->ReadFromParcel(parcel)) {
987 delete objptr;
988 objptr = nullptr;
989 }
990 return objptr;
991 }
992
ReadFromParcel(Parcel & parcel)993 bool ReminderRequest::ReadFromParcel(Parcel &parcel)
994 {
995 // read string
996 if (!parcel.ReadString(content_)) {
997 ANSR_LOGE("Failed to read content");
998 return false;
999 }
1000 if (!parcel.ReadString(expiredContent_)) {
1001 ANSR_LOGE("to read expiredContent");
1002 return false;
1003 }
1004 if (!parcel.ReadString(snoozeContent_)) {
1005 ANSR_LOGE("to read snoozeContent");
1006 return false;
1007 }
1008 if (!parcel.ReadString(title_)) {
1009 ANSR_LOGE("Failed to read title");
1010 return false;
1011 }
1012 if (!parcel.ReadString(wantAgentInfo_->abilityName)) {
1013 ANSR_LOGE("Failed to read wantAgentInfo`s abilityName");
1014 return false;
1015 }
1016 if (!parcel.ReadString(wantAgentInfo_->pkgName)) {
1017 ANSR_LOGE("Failed to read wantAgentInfo`s pkgName");
1018 return false;
1019 }
1020 if (!parcel.ReadString(maxScreenWantAgentInfo_->abilityName)) {
1021 ANSR_LOGE("Failed to read maxScreenWantAgentInfo`s abilityName");
1022 return false;
1023 }
1024 if (!parcel.ReadString(maxScreenWantAgentInfo_->pkgName)) {
1025 ANSR_LOGE("Failed to read maxScreenWantAgentInfo`s pkgName");
1026 return false;
1027 }
1028
1029 // read bool
1030 if (!parcel.ReadBool(isExpired_)) {
1031 ANSR_LOGE("Failed to read isExpired");
1032 return false;
1033 }
1034
1035 // read int
1036 int32_t tempReminderId = -1;
1037 if (!parcel.ReadInt32(tempReminderId)) {
1038 ANSR_LOGE("Failed to read tempReminderId");
1039 return false;
1040 }
1041 reminderId_ = (tempReminderId == -1) ? reminderId_ : tempReminderId;
1042
1043 if (!parcel.ReadInt32(notificationId_)) {
1044 ANSR_LOGE("Failed to read notificationId");
1045 return false;
1046 }
1047 if (!parcel.ReadUint64(triggerTimeInMilli_)) {
1048 ANSR_LOGE("Failed to read triggerTimeInMilli");
1049 return false;
1050 }
1051 if (!parcel.ReadUint64(timeIntervalInMilli_)) {
1052 ANSR_LOGE("Failed to read timeIntervalInMilli");
1053 return false;
1054 }
1055 if (!parcel.ReadUint64(ringDurationInMilli_)) {
1056 ANSR_LOGE("Failed to read ringDurationInMilli");
1057 return false;
1058 }
1059 if (!parcel.ReadUint64(reminderTimeInMilli_)) {
1060 ANSR_LOGE("Failed to read reminderTimeInMilli");
1061 return false;
1062 }
1063 if (!parcel.ReadUint8(snoozeTimes_)) {
1064 ANSR_LOGE("Failed to read snoozeTimes");
1065 return false;
1066 }
1067 if (!parcel.ReadUint8(snoozeTimesDynamic_)) {
1068 ANSR_LOGE("Failed to read snoozeTimesDynamic");
1069 return false;
1070 }
1071 if (!parcel.ReadUint8(state_)) {
1072 ANSR_LOGE("Failed to read state");
1073 return false;
1074 }
1075
1076 // read enum
1077 uint8_t reminderType = static_cast<uint8_t>(ReminderType::INVALID);
1078 if (!parcel.ReadUint8(reminderType)) {
1079 ANSR_LOGE("Failed to read reminderType");
1080 return false;
1081 }
1082 reminderType_ = static_cast<ReminderType>(reminderType);
1083
1084 int32_t slotType = static_cast<int32_t>(NotificationConstant::SlotType::OTHER);
1085 if (!parcel.ReadInt32(slotType)) {
1086 ANSR_LOGE("Failed to read slotType");
1087 return false;
1088 }
1089 slotType_ = static_cast<NotificationConstant::SlotType>(slotType);
1090
1091 // read map
1092 uint64_t buttonMapSize = 0;
1093 if (!parcel.ReadUint64(buttonMapSize)) {
1094 ANSR_LOGE("Failed to read buttonMapSize");
1095 return false;
1096 }
1097 for (uint64_t i = 0; i < buttonMapSize; i++) {
1098 uint8_t buttonType = static_cast<uint8_t>(ActionButtonType::INVALID);
1099 if (!parcel.ReadUint8(buttonType)) {
1100 ANSR_LOGE("Failed to read buttonType");
1101 return false;
1102 }
1103 ActionButtonType type = static_cast<ActionButtonType>(buttonType);
1104 std::string title = parcel.ReadString();
1105 ActionButtonInfo info;
1106 info.type = type;
1107 info.title = title;
1108 actionButtonMap_.insert(std::pair<ActionButtonType, ActionButtonInfo>(type, info));
1109 }
1110 if (!InitNotificationRequest()) {
1111 return false;
1112 }
1113 return true;
1114 }
1115
InitNotificationRequest()1116 bool ReminderRequest::InitNotificationRequest()
1117 {
1118 ANSR_LOGI("Init notification");
1119 notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_);
1120 if (notificationRequest_ == nullptr) {
1121 ANSR_LOGE("Failed to create notification.");
1122 return false;
1123 }
1124 displayContent_ = content_;
1125 AddActionButtons(true);
1126 return true;
1127 }
1128
InitServerObj()1129 void ReminderRequest::InitServerObj()
1130 {
1131 wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared<WantAgentInfo>() : wantAgentInfo_;
1132 maxScreenWantAgentInfo_ =
1133 maxScreenWantAgentInfo_ == nullptr ? std::make_shared<MaxScreenAgentInfo>() : maxScreenWantAgentInfo_;
1134 }
1135
IsAlerting() const1136 bool ReminderRequest::IsAlerting() const
1137 {
1138 return (state_ & REMINDER_STATUS_ALERTING) != 0;
1139 }
1140
GetDurationSinceEpochInMilli(const time_t target)1141 uint64_t ReminderRequest::GetDurationSinceEpochInMilli(const time_t target)
1142 {
1143 auto tarEndTimePoint = std::chrono::system_clock::from_time_t(target);
1144 auto tarDuration = std::chrono::duration_cast<std::chrono::milliseconds>(tarEndTimePoint.time_since_epoch());
1145 int64_t tarDate = tarDuration.count();
1146 if (tarDate < 0) {
1147 ANSR_LOGW("tarDuration is less than 0.");
1148 return INVALID_LONG_LONG_VALUE;
1149 }
1150 return static_cast<uint64_t>(tarDate);
1151 }
1152
GetDateTimeInfo(const time_t & timeInSecond) const1153 std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const
1154 {
1155 return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS);
1156 }
1157
GetButtonInfo() const1158 std::string ReminderRequest::GetButtonInfo() const
1159 {
1160 std::string info = "";
1161 bool isFirst = true;
1162 for (auto button : actionButtonMap_) {
1163 if (!isFirst) {
1164 info += SEP_BUTTON_MULTI;
1165 }
1166 ActionButtonInfo buttonInfo = button.second;
1167 info += std::to_string(static_cast<uint8_t>(button.first)) + SEP_BUTTON_SINGLE + buttonInfo.title;
1168 isFirst = false;
1169 }
1170 return info;
1171 }
1172
GetNowInstantMilli() const1173 uint64_t ReminderRequest::GetNowInstantMilli() const
1174 {
1175 time_t now;
1176 (void)time(&now); // unit is seconds.
1177 if (static_cast<int64_t>(now) < 0) {
1178 ANSR_LOGE("Get now time error");
1179 return 0;
1180 }
1181 return GetDurationSinceEpochInMilli(now);
1182 }
1183
GetShowTime(const uint64_t showTime) const1184 std::string ReminderRequest::GetShowTime(const uint64_t showTime) const
1185 {
1186 if (reminderType_ == ReminderType::TIMER) {
1187 return "";
1188 }
1189 return GetTimeInfoInner(static_cast<time_t>(showTime / MILLI_SECONDS), TimeFormat::HM);
1190 }
1191
GetTimeInfoInner(const time_t & timeInSecond,const TimeFormat & format) const1192 std::string ReminderRequest::GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format) const
1193 {
1194 const uint8_t dateTimeLen = 80;
1195 char dateTimeBuffer[dateTimeLen];
1196 struct tm timeInfo;
1197 (void)localtime_r(&timeInSecond, &timeInfo);
1198 switch (format) {
1199 case TimeFormat::YMDHMS: {
1200 (void)strftime(dateTimeBuffer, dateTimeLen, "%Y-%m-%d %H:%M:%S", &timeInfo);
1201 break;
1202 }
1203 case TimeFormat::HM: {
1204 (void)strftime(dateTimeBuffer, dateTimeLen, "%H:%M", &timeInfo);
1205 break;
1206 }
1207 default: {
1208 ANSR_LOGW("Time format not support.");
1209 break;
1210 }
1211 }
1212 std::string dateTimeInfo(dateTimeBuffer);
1213 return dateTimeInfo;
1214 }
1215
GetState(const uint8_t state) const1216 std::string ReminderRequest::GetState(const uint8_t state) const
1217 {
1218 std::string stateInfo = "'";
1219 if (state == REMINDER_STATUS_INACTIVE) {
1220 stateInfo += "Inactive";
1221 } else {
1222 bool hasSeparator = false;
1223 if ((state & REMINDER_STATUS_ACTIVE) != 0) {
1224 stateInfo += "Active";
1225 hasSeparator = true;
1226 }
1227 if ((state & REMINDER_STATUS_ALERTING) != 0) {
1228 if (hasSeparator) {
1229 stateInfo += ",";
1230 }
1231 stateInfo += "Alerting";
1232 hasSeparator = true;
1233 }
1234 if ((state & REMINDER_STATUS_SHOWING) != 0) {
1235 if (hasSeparator) {
1236 stateInfo += ",";
1237 }
1238 stateInfo += "Showing";
1239 hasSeparator = true;
1240 }
1241 if ((state & REMINDER_STATUS_SNOOZE) != 0) {
1242 if (hasSeparator) {
1243 stateInfo += ",";
1244 }
1245 stateInfo += "Snooze";
1246 }
1247 stateInfo += "'";
1248 }
1249 return stateInfo;
1250 }
1251
AddActionButtons(const bool includeSnooze)1252 void ReminderRequest::AddActionButtons(const bool includeSnooze)
1253 {
1254 int32_t requestCode = 10;
1255 std::vector<AbilityRuntime::WantAgent::WantAgentConstant::Flags> flags;
1256 flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG);
1257 for (auto button : actionButtonMap_) {
1258 auto want = std::make_shared<OHOS::AAFwk::Want>();
1259 auto type = button.first;
1260 if (type == ActionButtonType::CLOSE) {
1261 want->SetAction(REMINDER_EVENT_CLOSE_ALERT);
1262 ANSR_LOGD("Add action button, type is close");
1263 }
1264 if (type == ActionButtonType::SNOOZE) {
1265 if (includeSnooze) {
1266 want->SetAction(REMINDER_EVENT_SNOOZE_ALERT);
1267 ANSR_LOGD("Add action button, type is snooze");
1268 } else {
1269 ANSR_LOGD("Not add action button, type is snooze, as includeSnooze is false");
1270 continue;
1271 }
1272 }
1273 want->SetParam(PARAM_REMINDER_ID, reminderId_);
1274 std::vector<std::shared_ptr<AAFwk::Want>> wants;
1275 wants.push_back(want);
1276 auto title = static_cast<std::string>(button.second.title);
1277 AbilityRuntime::WantAgent::WantAgentInfo buttonWantAgentInfo(
1278 requestCode,
1279 AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT,
1280 flags,
1281 wants,
1282 nullptr
1283 );
1284
1285 std::string identity = IPCSkeleton::ResetCallingIdentity();
1286 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> buttonWantAgent =
1287 AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_);
1288 IPCSkeleton::SetCallingIdentity(identity);
1289
1290 std::shared_ptr<NotificationActionButton> actionButton
1291 = NotificationActionButton::Create(nullptr, title, buttonWantAgent);
1292 notificationRequest_->AddActionButton(actionButton);
1293 }
1294 }
1295
AddRemovalWantAgent()1296 void ReminderRequest::AddRemovalWantAgent()
1297 {
1298 int32_t requestCode = 10;
1299 std::vector<AbilityRuntime::WantAgent::WantAgentConstant::Flags> flags;
1300 flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG);
1301 auto want = std::make_shared<OHOS::AAFwk::Want>();
1302 want->SetAction(REMINDER_EVENT_REMOVE_NOTIFICATION);
1303 want->SetParam(PARAM_REMINDER_ID, reminderId_);
1304 std::vector<std::shared_ptr<AAFwk::Want>> wants;
1305 wants.push_back(want);
1306 AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo(
1307 requestCode,
1308 AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT,
1309 flags,
1310 wants,
1311 nullptr
1312 );
1313
1314 std::string identity = IPCSkeleton::ResetCallingIdentity();
1315 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
1316 AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_);
1317 IPCSkeleton::SetCallingIdentity(identity);
1318
1319 notificationRequest_->SetRemovalWantAgent(wantAgent);
1320 }
1321
CreateWantAgent(AppExecFwk::ElementName & element) const1322 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> ReminderRequest::CreateWantAgent(
1323 AppExecFwk::ElementName &element) const
1324 {
1325 int32_t requestCode = 10;
1326 std::vector<AbilityRuntime::WantAgent::WantAgentConstant::Flags> flags;
1327 flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG);
1328 auto want = std::make_shared<OHOS::AAFwk::Want>();
1329 want->SetElement(element);
1330 std::vector<std::shared_ptr<AAFwk::Want>> wants;
1331 wants.push_back(want);
1332 AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo(
1333 requestCode,
1334 AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY,
1335 flags,
1336 wants,
1337 nullptr
1338 );
1339 std::string identity = IPCSkeleton::ResetCallingIdentity();
1340 auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_);
1341 IPCSkeleton::SetCallingIdentity(identity);
1342 return wantAgent;
1343 }
1344
SetMaxScreenWantAgent(AppExecFwk::ElementName & element)1345 void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element)
1346 {
1347 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = CreateWantAgent(element);
1348 notificationRequest_->SetMaxScreenWantAgent(wantAgent);
1349 }
1350
SetWantAgent(AppExecFwk::ElementName & element)1351 void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element)
1352 {
1353 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = CreateWantAgent(element);
1354 notificationRequest_->SetWantAgent(wantAgent);
1355 }
1356
SetState(bool deSet,const uint8_t newState,std::string function)1357 void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string function)
1358 {
1359 uint8_t oldState = state_;
1360 if (deSet) {
1361 state_ |= newState;
1362 } else {
1363 state_ &= static_cast<uint8_t>(~newState);
1364 }
1365 ANSR_LOGI("Switch the reminder(reminderId=%{public}d) state, from %{public}s to %{public}s, called by %{public}s",
1366 reminderId_, GetState(oldState).c_str(), GetState(state_).c_str(), function.c_str());
1367 }
1368
UpdateActionButtons(const bool & setSnooze)1369 void ReminderRequest::UpdateActionButtons(const bool &setSnooze)
1370 {
1371 if (notificationRequest_ == nullptr) {
1372 ANSR_LOGE("updateActionButtons failed, the notificationRequest is null");
1373 return;
1374 }
1375 notificationRequest_->ClearActionButtons();
1376 if (setSnooze || snoozeTimesDynamic_ == snoozeTimes_) {
1377 AddActionButtons(false);
1378 } else {
1379 AddActionButtons(true);
1380 }
1381 }
1382
UpdateNextReminder(const bool & force)1383 bool ReminderRequest::UpdateNextReminder(const bool &force)
1384 {
1385 bool result = true;
1386 if (force) {
1387 uint64_t nowInstantMilli = GetNowInstantMilli();
1388 if (nowInstantMilli == 0) {
1389 result = false;
1390 } else {
1391 triggerTimeInMilli_ = nowInstantMilli + timeIntervalInMilli_;
1392 snoozeTimesDynamic_ = snoozeTimes_;
1393 if (timeIntervalInMilli_ != 0) {
1394 isExpired_ = false;
1395 }
1396 }
1397 } else {
1398 result = UpdateNextReminder();
1399 }
1400 std::string info = result ? "success" : "no next";
1401 ANSR_LOGI("updateNextReminder(id=%{public}d, %{public}s): force=%{public}d, trigger time is: %{public}s",
1402 reminderId_, info.c_str(), force,
1403 GetDateTimeInfo(static_cast<time_t>(triggerTimeInMilli_ / MILLI_SECONDS)).c_str());
1404 return result;
1405 }
1406
UpdateNotificationCommon()1407 void ReminderRequest::UpdateNotificationCommon()
1408 {
1409 time_t now;
1410 (void)time(&now); // unit is seconds.
1411 notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now));
1412 notificationRequest_->SetLabel(NOTIFICATION_LABEL);
1413 notificationRequest_->SetShowDeliveryTime(true);
1414 notificationRequest_->SetTapDismissed(true);
1415 notificationRequest_->SetSlotType(slotType_);
1416 auto notificationNormalContent = std::make_shared<NotificationNormalContent>();
1417 notificationNormalContent->SetText(displayContent_);
1418 notificationNormalContent->SetTitle(title_);
1419 auto notificationContent = std::make_shared<NotificationContent>(notificationNormalContent);
1420 notificationRequest_->SetContent(notificationContent);
1421 if ((reminderType_ == ReminderRequest::ReminderType::TIMER) ||
1422 (reminderType_ == ReminderRequest::ReminderType::ALARM)) {
1423 notificationRequest_->SetUnremovable(true);
1424 }
1425 auto flags = std::make_shared<NotificationFlags>();
1426 flags->SetSoundEnabled(NotificationConstant::FlagStatus::CLOSE);
1427 flags->SetVibrationEnabled(NotificationConstant::FlagStatus::CLOSE);
1428 notificationRequest_->SetFlags(flags);
1429 }
1430
UpdateNotificationBundleInfo()1431 void ReminderRequest::UpdateNotificationBundleInfo()
1432 {
1433 std::string ownerBundleName = notificationRequest_->GetOwnerBundleName();
1434 if (!(ownerBundleName.empty())) {
1435 return;
1436 }
1437 ANSR_LOGD("ownerBundleName=%{public}s, bundleName_=%{public}s",
1438 ownerBundleName.c_str(), bundleName_.c_str());
1439 notificationRequest_->SetOwnerBundleName(bundleName_);
1440 notificationRequest_->SetCreatorBundleName(bundleName_);
1441 notificationRequest_->SetCreatorUid(uid_);
1442 ErrCode errCode = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_);
1443 if (errCode != ERR_OK) {
1444 ANSR_LOGE("GetOsAccountLocalIdFromUid fail.");
1445 return;
1446 }
1447 notificationRequest_->SetCreatorUserId(userId_);
1448 }
1449
UpdateNotificationContent(const bool & setSnooze)1450 void ReminderRequest::UpdateNotificationContent(const bool &setSnooze)
1451 {
1452 if (notificationRequest_ == nullptr) {
1453 ANSR_LOGE("updateNotificationContent failed, the notificationRequest is null");
1454 return;
1455 }
1456 std::string extendContent = "";
1457 if (setSnooze) {
1458 if (timeIntervalInMilli_ != 0) {
1459 // snooze the reminder by manual
1460 extendContent = GetShowTime(triggerTimeInMilli_) +
1461 (snoozeContent_ == "" ? "" : (" (" + snoozeContent_ + ")"));
1462 notificationRequest_->SetTapDismissed(false);
1463 } else {
1464 // the reminder is expired now, when timeInterval is 0
1465 extendContent = GetShowTime(reminderTimeInMilli_) +
1466 (expiredContent_ == "" ? "" : (" (" + expiredContent_ + ")"));
1467 }
1468 } else if (IsAlerting()) {
1469 // the reminder is alerting, or ring duration is 0
1470 extendContent = GetShowTime(reminderTimeInMilli_);
1471 } else if (snoozeTimesDynamic_ != snoozeTimes_) {
1472 // the reminder is snoozing by period artithmetic, when the ring duration is over.
1473 extendContent = GetShowTime(triggerTimeInMilli_) +
1474 (snoozeContent_ == "" ? "" : (" (" + snoozeContent_ + ")"));
1475 notificationRequest_->SetTapDismissed(false);
1476 } else {
1477 // the reminder has already snoozed by period arithmetic, when the ring duration is over.
1478 extendContent = GetShowTime(reminderTimeInMilli_) +
1479 (expiredContent_ == "" ? "" : (" (" + expiredContent_ + ")"));
1480 }
1481 displayContent_ = content_ + " " + extendContent;
1482 ANSR_LOGD("Display content=%{public}s", displayContent_.c_str());
1483 }
1484
UpdateNotificationStateForAlert()1485 void ReminderRequest::UpdateNotificationStateForAlert()
1486 {
1487 ANSR_LOGD("UpdateNotification content and buttons");
1488 UpdateNotificationContent(false);
1489 UpdateActionButtons(false);
1490 }
1491
UpdateNotificationStateForSnooze()1492 void ReminderRequest::UpdateNotificationStateForSnooze()
1493 {
1494 ANSR_LOGD("UpdateNotification content and buttons");
1495 UpdateNotificationContent(true);
1496 UpdateActionButtons(true);
1497 }
1498
GetActualTime(const TimeTransferType & type,int32_t cTime)1499 int32_t ReminderRequest::GetActualTime(const TimeTransferType &type, int32_t cTime)
1500 {
1501 switch (type) {
1502 case (TimeTransferType::YEAR): // year
1503 return BASE_YEAR + cTime;
1504 case (TimeTransferType::MONTH): // month
1505 return 1 + cTime;
1506 case (TimeTransferType::WEEK): { // week
1507 return cTime == 0 ? SUNDAY : cTime;
1508 }
1509 default:
1510 return -1;
1511 }
1512 }
1513
GetCTime(const TimeTransferType & type,int32_t actualTime)1514 int32_t ReminderRequest::GetCTime(const TimeTransferType &type, int32_t actualTime)
1515 {
1516 switch (type) {
1517 case (TimeTransferType::YEAR): // year
1518 return actualTime - BASE_YEAR;
1519 case (TimeTransferType::MONTH): // month
1520 return actualTime - 1;
1521 case (TimeTransferType::WEEK): { // week
1522 return actualTime == SUNDAY ? 0 : actualTime;
1523 }
1524 default:
1525 return -1;
1526 }
1527 }
1528
GetUid(const int32_t & userId,const std::string & bundleName)1529 int32_t ReminderRequest::GetUid(const int32_t &userId, const std::string &bundleName)
1530 {
1531 AppExecFwk::ApplicationInfo info;
1532 sptr<ISystemAbilityManager> systemAbilityManager
1533 = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1534 if (systemAbilityManager == nullptr) {
1535 ANSR_LOGE("Failed to get uid due to get systemAbilityManager is null.");
1536 return -1;
1537 }
1538 sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
1539 sptr<AppExecFwk::IBundleMgr> bundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
1540 bundleMgr->GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, info);
1541 ANSR_LOGD("uid=%{public}d", info.uid);
1542 return static_cast<int32_t>(info.uid);
1543 }
1544
GetUserId(const int32_t & uid)1545 int32_t ReminderRequest::GetUserId(const int32_t &uid)
1546 {
1547 int32_t userId = -1;
1548 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
1549 ANSR_LOGD("userId=%{public}d", userId);
1550 return userId;
1551 }
1552
AppendValuesBucket(const sptr<ReminderRequest> & reminder,const sptr<NotificationBundleOption> & bundleOption,NativeRdb::ValuesBucket & values)1553 void ReminderRequest::AppendValuesBucket(const sptr<ReminderRequest> &reminder,
1554 const sptr<NotificationBundleOption> &bundleOption, NativeRdb::ValuesBucket &values)
1555 {
1556 values.PutInt(REMINDER_ID, reminder->GetReminderId());
1557 values.PutString(PKG_NAME, bundleOption->GetBundleName());
1558 values.PutInt(USER_ID, reminder->GetUserId());
1559 values.PutInt(UID, reminder->GetUid());
1560 values.PutString(APP_LABEL, ""); // no use, compatible with old version.
1561 values.PutInt(REMINDER_TYPE, static_cast<int32_t>(reminder->GetReminderType()));
1562 values.PutLong(REMINDER_TIME, reminder->GetReminderTimeInMilli());
1563 values.PutLong(TRIGGER_TIME, reminder->GetTriggerTimeInMilli());
1564 values.PutLong(
1565 RTC_TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); // no use, compatible with old version.
1566 values.PutLong(TIME_INTERVAL, reminder->GetTimeInterval());
1567 values.PutInt(SNOOZE_TIMES, reminder->GetSnoozeTimes());
1568 values.PutInt(DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic());
1569 values.PutLong(RING_DURATION, reminder->GetRingDuration());
1570 values.PutString(IS_EXPIRED, reminder->IsExpired() ? "true" : "false");
1571 values.PutString(IS_ACTIVE, ""); // no use, compatible with old version.
1572 values.PutInt(STATE, reminder->GetState());
1573 values.PutString(ZONE_ID, ""); // no use, compatible with old version.
1574 values.PutString(HAS_SCHEDULED_TIMEOUT, ""); // no use, compatible with old version.
1575 values.PutString(ACTION_BUTTON_INFO, reminder->GetButtonInfo());
1576 values.PutInt(SLOT_ID, reminder->GetSlotType());
1577 values.PutInt(NOTIFICATION_ID, reminder->GetNotificationId());
1578 values.PutString(TITLE, reminder->GetTitle());
1579 values.PutString(CONTENT, reminder->GetContent());
1580 values.PutString(SNOOZE_CONTENT, reminder->GetSnoozeContent());
1581 values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent());
1582 auto wantAgentInfo = reminder->GetWantAgentInfo();
1583 if (wantAgentInfo == nullptr) {
1584 std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null";
1585 values.PutString(AGENT, info);
1586 } else {
1587 values.PutString(AGENT, wantAgentInfo->pkgName
1588 + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName);
1589 }
1590 auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo();
1591 if (maxScreenWantAgentInfo == nullptr) {
1592 std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null";
1593 values.PutString(MAX_SCREEN_AGENT, info);
1594 } else {
1595 values.PutString(MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName
1596 + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName);
1597 }
1598 }
1599
InitDbColumns()1600 void ReminderRequest::InitDbColumns()
1601 {
1602 AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", false);
1603 AddColumn(PKG_NAME, "TEXT NOT NULL", false);
1604 AddColumn(USER_ID, "INT NOT NULL", false);
1605 AddColumn(UID, "INT NOT NULL", false);
1606 AddColumn(APP_LABEL, "TEXT", false);
1607 AddColumn(REMINDER_TYPE, "INT NOT NULL", false);
1608 AddColumn(REMINDER_TIME, "BIGINT NOT NULL", false);
1609 AddColumn(TRIGGER_TIME, "BIGINT NOT NULL", false);
1610 AddColumn(RTC_TRIGGER_TIME, "BIGINT NOT NULL", false);
1611 AddColumn(TIME_INTERVAL, "BIGINT NOT NULL", false);
1612 AddColumn(SNOOZE_TIMES, "INT NOT NULL", false);
1613 AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL", false);
1614 AddColumn(RING_DURATION, "BIGINT NOT NULL", false);
1615 AddColumn(IS_EXPIRED, "TEXT NOT NULL", false);
1616 AddColumn(IS_ACTIVE, "TEXT NOT NULL", false);
1617 AddColumn(STATE, "INT NOT NULL", false);
1618 AddColumn(ZONE_ID, "TEXT", false);
1619 AddColumn(HAS_SCHEDULED_TIMEOUT, "TEXT", false);
1620 AddColumn(ACTION_BUTTON_INFO, "TEXT", false);
1621 AddColumn(SLOT_ID, "INT", false);
1622 AddColumn(NOTIFICATION_ID, "INT NOT NULL", false);
1623 AddColumn(TITLE, "TEXT", false);
1624 AddColumn(CONTENT, "TEXT", false);
1625 AddColumn(SNOOZE_CONTENT, "TEXT", false);
1626 AddColumn(EXPIRED_CONTENT, "TEXT", false);
1627 AddColumn(AGENT, "TEXT", false);
1628 AddColumn(MAX_SCREEN_AGENT, "TEXT", false);
1629 }
1630
AddColumn(const std::string & name,const std::string & type,const bool & isEnd)1631 void ReminderRequest::AddColumn(
1632 const std::string &name, const std::string &type, const bool &isEnd)
1633 {
1634 columns.push_back(name);
1635 if (!isEnd) {
1636 sqlOfAddColumns += name + " " + type + ", ";
1637 } else {
1638 sqlOfAddColumns += name + " " + type;
1639 }
1640 }
1641 }
1642 }