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