diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp
index ad1b23517cf34a3b63c8a159b2261e1eacc41052..6c3ee3c6ac36cf6d2ec81e96b4936d2961d81690 100644
--- a/frameworks/ans/src/reminder_request.cpp
+++ b/frameworks/ans/src/reminder_request.cpp
@@ -15,8 +15,6 @@
#include "reminder_request.h"
-#include "reminder_table.h"
-#include "reminder_table_old.h"
#include "ans_const_define.h"
#include "ans_log_wrapper.h"
#include "bundle_mgr_interface.h"
@@ -50,12 +48,7 @@ const int32_t INDENT = -1;
}
int32_t ReminderRequest::GLOBAL_ID = 0;
-const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0;
-const uint16_t ReminderRequest::INVALID_U16_VALUE = 0;
-const uint16_t ReminderRequest::MILLI_SECONDS = 1000;
-const uint16_t ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS = 1000;
const uint32_t ReminderRequest::MIN_TIME_INTERVAL_IN_MILLI = 5 * 60 * 1000;
-const uint8_t ReminderRequest::INVALID_U8_VALUE = 0;
const uint8_t ReminderRequest::REMINDER_STATUS_INACTIVE = 0;
const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1;
const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2;
@@ -78,11 +71,6 @@ const std::string ReminderRequest::SEP_WANT_AGENT = "";
const std::string ReminderRequest::SEP_BUTTON_VALUE_TYPE = "";
const std::string ReminderRequest::SEP_BUTTON_VALUE = "";
const std::string ReminderRequest::SEP_BUTTON_VALUE_BLOB = "";
-const uint8_t ReminderRequest::DAYS_PER_WEEK = 7;
-const uint8_t ReminderRequest::MONDAY = 1;
-const uint8_t ReminderRequest::SUNDAY = 7;
-const uint8_t ReminderRequest::HOURS_PER_DAY = 24;
-const uint16_t ReminderRequest::SECONDS_PER_HOUR = 3600;
template
void GetJsonValue(const nlohmann::json& root, const std::string& name, T& value)
@@ -116,6 +104,12 @@ ReminderRequest::ReminderRequest()
InitServerObj();
}
+ReminderRequest::ReminderRequest(const int32_t reminderId)
+{
+ reminderId_ = reminderId;
+ InitServerObj();
+}
+
ReminderRequest::ReminderRequest(const ReminderRequest &other)
{
this->content_ = other.content_;
@@ -149,496 +143,370 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other)
this->creatorBundleName_ = other.creatorBundleName_;
}
-ReminderRequest::ReminderRequest(int32_t reminderId)
+ReminderRequest::ReminderRequest(ReminderType reminderType)
{
- reminderId_ = reminderId;
+ reminderType_ = reminderType;
InitServerObj();
}
-ReminderRequest::ReminderRequest(ReminderType reminderType)
+int32_t ReminderRequest::GetReminderId() const
{
- reminderType_ = reminderType;
- InitServerObj();
+ return reminderId_;
}
-bool ReminderRequest::CanRemove() const
+void ReminderRequest::SetReminderId(int32_t reminderId)
{
- if ((state_ & (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE)) == 0) {
- return true;
- }
- return false;
+ reminderId_ = reminderId;
}
-bool ReminderRequest::CanShow() const
+std::string ReminderRequest::GetBundleName() const
{
- // when system time change by user manually, and the reminde is to show immediately,
- // the show reminder just need to be triggered by ReminderDataManager#RefreshRemindersLocked(uint8_t).
- // we need to make the REMINDER_EVENT_ALARM_ALERT do nothing.
- uint64_t nowInstantMilli = GetNowInstantMilli();
- if (nowInstantMilli == 0) {
- return false;
- }
- if (nowInstantMilli < (GetReminderTimeInMilli() + MIN_TIME_INTERVAL_IN_MILLI)) {
- return false;
- }
- return true;
+ return bundleName_;
}
-std::string ReminderRequest::Dump() const
+void ReminderRequest::SetBundleName(const std::string& bundleName)
{
- const time_t nextTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS);
- std::string dateTimeInfo = GetTimeInfoInner(nextTriggerTime, TimeFormat::YMDHMS, true);
- return "Reminder["
- "reminderId=" + std::to_string(reminderId_) +
- ", type=" + std::to_string(static_cast(reminderType_)) +
- ", state=" + GetState(state_) +
- ", nextTriggerTime=" + dateTimeInfo.c_str() +
- "]";
+ bundleName_ = bundleName;
}
-ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type,
- const std::string &resource, const std::shared_ptr &buttonWantAgent,
- const std::shared_ptr &buttonDataShareUpdate)
+int32_t ReminderRequest::GetUserId() const
{
- if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE) && (type != ActionButtonType::CUSTOM)) {
- ANSR_LOGI("Button type is not support: %{public}d.", static_cast(type));
- return *this;
- }
- ActionButtonInfo actionButtonInfo;
- actionButtonInfo.type = type;
- actionButtonInfo.title = title;
- actionButtonInfo.resource = resource;
- actionButtonInfo.wantAgent = buttonWantAgent;
- actionButtonInfo.dataShareUpdate = buttonDataShareUpdate;
+ return userId_;
+}
- actionButtonMap_.insert(std::pair(type, actionButtonInfo));
- return *this;
+void ReminderRequest::SetUserId(const int32_t userId)
+{
+ userId_ = userId;
}
-ReminderRequest& ReminderRequest::SetContent(const std::string &content)
+int32_t ReminderRequest::GetUid() const
{
- content_ = content;
- return *this;
+ return uid_;
}
-ReminderRequest& ReminderRequest::SetExpiredContent(const std::string &expiredContent)
+void ReminderRequest::SetUid(const int32_t uid)
{
- expiredContent_ = expiredContent;
- return *this;
+ uid_ = uid;
}
-void ReminderRequest::SetExpired(bool isExpired)
+bool ReminderRequest::IsSystemApp() const
{
- isExpired_ = isExpired;
+ return isSystemApp_;
}
-void ReminderRequest::InitCreatorBundleName(const std::string &creatorBundleName)
+void ReminderRequest::SetSystemApp(const bool isSystem)
{
- creatorBundleName_ = creatorBundleName;
+ isSystemApp_ = isSystem;
}
-void ReminderRequest::InitCreatorUid(const int32_t creatorUid)
+ReminderRequest::ReminderType ReminderRequest::GetReminderType() const
{
- creatorUid_ = creatorUid;
+ return reminderType_;
}
-void ReminderRequest::InitReminderId()
+uint64_t ReminderRequest::GetReminderTimeInMilli() const
{
- std::lock_guard lock(std::mutex);
- if (GLOBAL_ID < 0) {
- ANSR_LOGW("GLOBAL_ID overdule");
- GLOBAL_ID = 0;
- }
- reminderId_ = ++GLOBAL_ID;
- ANSR_LOGI("reminderId_=%{public}d", reminderId_);
+ return reminderTimeInMilli_;
}
-void ReminderRequest::InitUserId(const int32_t &userId)
+void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli)
{
- userId_ = userId;
+ reminderTimeInMilli_ = reminderTimeInMilli;
}
-void ReminderRequest::InitUid(const int32_t &uid)
+uint64_t ReminderRequest::GetTriggerTimeInMilli() const
{
- uid_ = uid;
+ return triggerTimeInMilli_;
}
-void ReminderRequest::InitBundleName(const std::string &bundleName)
+void ReminderRequest::SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli)
{
- bundleName_ = bundleName;
+ triggerTimeInMilli_ = triggerTimeInMilli;
}
-bool ReminderRequest::IsExpired() const
+uint64_t ReminderRequest::GetTimeInterval() const
{
- return isExpired_;
+ return timeIntervalInMilli_ / MILLI_SECONDS;
}
-bool ReminderRequest::IsShowing() const
+void ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds)
{
- if ((state_ & REMINDER_STATUS_SHOWING) != 0) {
- return true;
+ uint64_t timeIntervalInMilli = timeIntervalInSeconds * MILLI_SECONDS;
+ if (timeIntervalInMilli > UINT64_MAX) {
+ ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range");
+ timeIntervalInMilli_ = 0;
+ } else {
+ timeIntervalInMilli_ = std::max(MIN_TIME_INTERVAL_IN_MILLI, timeIntervalInMilli);
}
- return false;
}
-void ReminderRequest::OnClose(bool updateNext)
+uint8_t ReminderRequest::GetSnoozeTimes() const
{
- if ((state_ & REMINDER_STATUS_SHOWING) == 0) {
- ANSR_LOGE("onClose, the state of reminder is incorrect, state:%{public}s", GetState(state_).c_str());
- return;
- }
- SetState(false, REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE, "onClose()");
- if ((state_ & REMINDER_STATUS_ALERTING) != 0) {
- SetState(false, REMINDER_STATUS_ALERTING, "onClose");
- }
- if (updateNext) {
- uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
- if (nextTriggerTime == INVALID_LONG_LONG_VALUE) {
- isExpired_ = true;
- } else {
- SetTriggerTimeInMilli(nextTriggerTime);
- snoozeTimesDynamic_ = snoozeTimes_;
- }
- }
+ return snoozeTimes_;
}
-bool ReminderRequest::OnDateTimeChange()
+void ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes)
{
- uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
- return HandleSysTimeChange(triggerTimeInMilli_, nextTriggerTime);
+ snoozeTimes_ = snoozeTimes;
+ SetSnoozeTimesDynamic(snoozeTimes);
}
-bool ReminderRequest::HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime)
+uint8_t ReminderRequest::GetSnoozeTimesDynamic() const
{
- if (isExpired_) {
- return false;
- }
- uint64_t now = GetNowInstantMilli();
- if (now == 0) {
- ANSR_LOGE("get now time failed.");
- return false;
- }
- if (oriTriggerTime == 0 && optTriggerTime < now) {
- ANSR_LOGW("trigger time is less than now time.");
- return false;
- }
- bool showImmediately = false;
- if (optTriggerTime != INVALID_LONG_LONG_VALUE && (optTriggerTime <= oriTriggerTime || oriTriggerTime == 0)) {
- // case1. switch to a previous time
- SetTriggerTimeInMilli(optTriggerTime);
- snoozeTimesDynamic_ = snoozeTimes_;
- } else {
- if (oriTriggerTime <= now) {
- // case2. switch to a future time, trigger time is less than now time.
- // when the reminder show immediately, trigger time will update in onShow function.
- snoozeTimesDynamic_ = 0;
- showImmediately = true;
- } else {
- // case3. switch to a future time, trigger time is larger than now time.
- showImmediately = false;
- }
- }
- return showImmediately;
+ return snoozeTimesDynamic_;
}
-bool ReminderRequest::HandleTimeZoneChange(
- uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime)
+void ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes)
{
- if (isExpired_) {
- return false;
- }
- ANSR_LOGD("Handle timezone change, old:%{public}" PRIu64 ", new:%{public}" PRIu64 "",
- oldZoneTriggerTime, newZoneTriggerTime);
- if (oldZoneTriggerTime == newZoneTriggerTime) {
- return false;
- }
- bool showImmediately = false;
- if (optTriggerTime != INVALID_LONG_LONG_VALUE && oldZoneTriggerTime < newZoneTriggerTime) {
- // case1. timezone change to smaller
- SetTriggerTimeInMilli(optTriggerTime);
- snoozeTimesDynamic_ = snoozeTimes_;
- } else {
- // case2. timezone change to larger
- time_t now;
- (void)time(&now); // unit is seconds.
- if (static_cast(now) < 0) {
- ANSR_LOGE("Get now time error");
- return false;
- }
- if (newZoneTriggerTime <= GetDurationSinceEpochInMilli(now)) {
- snoozeTimesDynamic_ = 0;
- showImmediately = true;
- } else {
- SetTriggerTimeInMilli(newZoneTriggerTime);
- showImmediately = false;
- }
- }
- return showImmediately;
+ snoozeTimesDynamic_ = snooziTimes;
}
-void ReminderRequest::OnSameNotificationIdCovered()
+uint16_t ReminderRequest::GetRingDuration() const
{
- SetState(false, REMINDER_STATUS_ALERTING | REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE,
- "OnSameNotificationIdCovered");
+ return ringDurationInMilli_ / MILLI_SECONDS;
}
-void ReminderRequest::OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify)
+void ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds)
{
- if ((state_ & (REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE)) != 0) {
- SetState(false, REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE, "onShow()");
- }
- if (isSysTimeChanged) {
- uint64_t nowInstantMilli = GetNowInstantMilli();
- if (nowInstantMilli == 0) {
- ANSR_LOGW("Onshow, get now time error");
- }
- reminderTimeInMilli_ = nowInstantMilli;
- } else {
- reminderTimeInMilli_ = triggerTimeInMilli_;
- }
- UpdateNextReminder(false);
- if (allowToNotify) {
- SetState(true, REMINDER_STATUS_SHOWING, "OnShow");
- if (isPlaySoundOrVibration) {
- SetState(true, REMINDER_STATUS_ALERTING, "OnShow");
- }
- UpdateNotificationStateForAlert();
- }
+ uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS;
+ ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION);
}
-void ReminderRequest::OnShowFail()
+bool ReminderRequest::IsExpired() const
{
- SetState(false, REMINDER_STATUS_SHOWING, "OnShowFailed()");
+ return isExpired_;
}
-bool ReminderRequest::OnSnooze()
+void ReminderRequest::SetExpired(const bool isExpired)
{
- if ((state_ & REMINDER_STATUS_SNOOZE) != 0) {
- ANSR_LOGW("onSnooze, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
- return false;
- }
- if ((state_ & REMINDER_STATUS_ALERTING) != 0) {
- SetState(false, REMINDER_STATUS_ALERTING, "onSnooze()");
- }
- SetSnoozeTimesDynamic(GetSnoozeTimes());
- if (!UpdateNextReminder(true)) {
- return false;
- }
- UpdateNotificationStateForSnooze();
- if (timeIntervalInMilli_ > 0) {
- SetState(true, REMINDER_STATUS_SNOOZE, "onSnooze()");
- }
- return true;
+ isExpired_ = isExpired;
}
-void ReminderRequest::OnStart()
+uint8_t ReminderRequest::GetState() const
{
- if ((state_ & REMINDER_STATUS_ACTIVE) != 0) {
- ANSR_LOGE(
- "start failed, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
- return;
- }
- if (isExpired_) {
- ANSR_LOGE("start failed, the reminder is expired");
- return;
- }
- SetState(true, REMINDER_STATUS_ACTIVE, "OnStart()");
+ return state_;
}
-void ReminderRequest::OnStop()
+void ReminderRequest::SetState(const uint8_t state)
{
- ANSR_LOGI("Stop the previous active reminder, %{public}s", this->Dump().c_str());
- if ((state_ & REMINDER_STATUS_ACTIVE) == 0) {
- ANSR_LOGW("onStop, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
- return;
- }
- SetState(false, REMINDER_STATUS_ACTIVE, "OnStop");
+ state_ = state;
}
-bool ReminderRequest::OnTerminate()
+std::string ReminderRequest::GetCustomButtonUri() const
{
- if ((state_ & REMINDER_STATUS_ALERTING) == 0) {
- ANSR_LOGW("onTerminate, the state of reminder is %{public}s", (GetState(state_)).c_str());
- return false;
- }
- SetState(false, REMINDER_STATUS_ALERTING, "onTerminate");
- UpdateNotificationStateForAlert();
- return true;
+ return customButtonUri_;
}
-bool ReminderRequest::OnTimeZoneChange()
+void ReminderRequest::SetCustomButtonUri(const std::string& uri)
{
- time_t oldZoneTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS);
- struct tm *localOriTime = localtime(&oldZoneTriggerTime);
- if (localOriTime == nullptr) {
- ANSR_LOGE("oldZoneTriggerTime is null");
- return false;
- }
- time_t newZoneTriggerTime = mktime(localOriTime);
- uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
- return HandleTimeZoneChange(
- triggerTimeInMilli_, GetDurationSinceEpochInMilli(newZoneTriggerTime), nextTriggerTime);
+ customButtonUri_ = uri;
}
-int64_t ReminderRequest::RecoverInt64FromDb(const std::shared_ptr &resultSet,
- const std::string &columnName, const DbRecoveryType &columnType)
+NotificationConstant::SlotType ReminderRequest::GetSlotType() const
{
- if (resultSet == nullptr) {
- ANSR_LOGE("ResultSet is null");
- return 0;
- }
- switch (columnType) {
- case (DbRecoveryType::INT): {
- int32_t value;
- ReminderStore::GetInt32Val(resultSet, columnName, value);
- return static_cast(value);
- }
- case (DbRecoveryType::LONG): {
- int64_t value;
- ReminderStore::GetInt64Val(resultSet, columnName, value);
- return value;
- }
- default: {
- ANSR_LOGD("ColumnType not support.");
- break;
- }
- }
- ANSR_LOGE("Recover data error");
- return 0;
+ return slotType_;
}
-void ReminderRequest::RecoverBasicFromDb(const std::shared_ptr& resultSet)
+void ReminderRequest::SetSlotType(const NotificationConstant::SlotType slotType)
{
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::REMINDER_ID, reminderId_);
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::PACKAGE_NAME, bundleName_);
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::USER_ID, userId_);
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::UID, uid_);
+ slotType_ = slotType;
+}
- std::string isSysApp;
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::SYSTEM_APP, isSysApp);
- isSystemApp_ = isSysApp == "true" ? true : false;
+NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const
+{
+ return snoozeSlotType_;
+}
- int32_t reminderType;
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::REMINDER_TYPE, reminderType);
- reminderType_ = ReminderType(reminderType);
+void ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType)
+{
+ snoozeSlotType_ = snoozeSlotType;
+}
- ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::REMINDER_TIME, reminderTimeInMilli_);
- ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::TRIGGER_TIME, triggerTimeInMilli_);
+int32_t ReminderRequest::GetNotificationId() const
+{
+ return notificationId_;
+}
- uint64_t timeIntervalInSecond = 0;
- ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::TIME_INTERVAL, timeIntervalInSecond);
- SetTimeInterval(timeIntervalInSecond);
+void ReminderRequest::SetNotificationId(const int32_t notificationId)
+{
+ notificationId_ = notificationId;
+}
- ReminderStore::GetUInt8Val(resultSet, ReminderBaseTable::SNOOZE_TIMES, snoozeTimes_);
- ReminderStore::GetUInt8Val(resultSet, ReminderBaseTable::DYNAMIC_SNOOZE_TIMES, snoozeTimesDynamic_);
+std::string ReminderRequest::GetTitle() const
+{
+ return title_;
+}
- uint64_t ringDurationInSecond;
- ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::RING_DURATION, ringDurationInSecond);
- SetRingDuration(ringDurationInSecond);
+void ReminderRequest::SetTitle(const std::string& title)
+{
+ title_ = title;
+}
- std::string isExpired;
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::IS_EXPIRED, isExpired);
- isExpired_ = isExpired == "true" ? true : false;
+std::string ReminderRequest::GetContent() const
+{
+ return content_;
+}
- ReminderStore::GetUInt8Val(resultSet, ReminderBaseTable::STATE, state_);
+void ReminderRequest::SetContent(const std::string& content)
+{
+ content_ = content;
+}
- // action buttons
- RecoverActionButton(resultSet);
+std::string ReminderRequest::GetSnoozeContent() const
+{
+ return snoozeContent_;
+}
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CUSTOM_BUTTON_URI, customButtonUri_);
+void ReminderRequest::SetSnoozeContent(const std::string& snoozeContent)
+{
+ snoozeContent_ = snoozeContent;
+}
- int32_t slotType;
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::SLOT_ID, slotType);
- slotType_ = NotificationConstant::SlotType(slotType);
+std::string ReminderRequest::GetExpiredContent() const
+{
+ return expiredContent_;
+}
- int32_t snoozeSlotType;
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::SNOOZE_SLOT_ID, snoozeSlotType);
- snoozeSlotType_ = NotificationConstant::SlotType(snoozeSlotType);
+void ReminderRequest::SetExpiredContent(const std::string& expiredContent)
+{
+ expiredContent_ = expiredContent;
+}
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::NOTIFICATION_ID, notificationId_);
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::TITLE, title_);
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CONTENT, content_);
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::SNOOZE_CONTENT, snoozeContent_);
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::EXPIRED_CONTENT, expiredContent_);
+bool ReminderRequest::IsTapDismissed() const
+{
+ return tapDismissed_;
+}
- InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent
+void ReminderRequest::SetTapDismissed(bool tapDismissed)
+{
+ tapDismissed_ = tapDismissed;
}
-void ReminderRequest::RecoverFromDbBase(const std::shared_ptr& resultSet)
+int64_t ReminderRequest::GetAutoDeletedTime() const
{
- if (resultSet == nullptr) {
- ANSR_LOGE("ResultSet is null");
- return;
- }
- RecoverBasicFromDb(resultSet);
+ return autoDeletedTime_;
+}
- std::string wantAgent;
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::WANT_AGENT, wantAgent);
- RecoverWantAgent(wantAgent, 0);
+void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime)
+{
+ autoDeletedTime_ = autoDeletedTime;
+}
- std::string maxScreenWantAgent;
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::MAX_SCREEN_WANT_AGENT, maxScreenWantAgent);
- RecoverWantAgent(maxScreenWantAgent, 1);
+std::string ReminderRequest::GetGroupId() const
+{
+ return groupId_;
+}
- std::string tapDismissed;
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::TAP_DISMISSED, tapDismissed);
- tapDismissed_ = tapDismissed == "true" ? true : false;
+void ReminderRequest::SetGroupId(const std::string& groupId)
+{
+ groupId_ = groupId;
+}
- ReminderStore::GetInt64Val(resultSet, ReminderBaseTable::AUTO_DELETED_TIME, autoDeletedTime_);
+std::string ReminderRequest::GetCustomRingUri() const
+{
+ return customRingUri_;
+}
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::GROUP_ID, groupId_);
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CUSTOM_RING_URI, customRingUri_);
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CREATOR_BUNDLE_NAME, creatorBundleName_);
- ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::CREATOR_UID, creatorUid_);
+void ReminderRequest::SetCustomRingUri(const std::string& uri)
+{
+ customRingUri_ = uri;
}
-void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString)
+std::string ReminderRequest::GetCreatorBundleName() const
{
- if (!nlohmann::json::accept(jsonString)) {
- ANSR_LOGW("not a json string!");
- return;
- }
- nlohmann::json root = nlohmann::json::parse(jsonString, nullptr, false);
- if (root.is_discarded()) {
- ANSR_LOGW("parse json data failed!");
- return;
- }
- std::string type;
- GetJsonValue(root, "type", type);
- if (!IsVaildButtonType(type)) {
- ANSR_LOGW("unkown button type!");
- return;
- }
- std::string title;
- GetJsonValue(root, "title", title);
- std::string resource;
- GetJsonValue(root, "resource", resource);
- auto buttonWantAgent = std::make_shared();
- if (root.contains("wantAgent") && !root["wantAgent"].empty()) {
- nlohmann::json wantAgent = root["wantAgent"];
- GetJsonValue(wantAgent, "pkgName", buttonWantAgent->pkgName);
- GetJsonValue(wantAgent, "abilityName", buttonWantAgent->abilityName);
- }
- auto buttonDataShareUpdate = std::make_shared();
- if (root.contains("dataShareUpdate") && !root["dataShareUpdate"].empty()) {
- nlohmann::json dataShareUpdate = root["dataShareUpdate"];
- GetJsonValue(dataShareUpdate, "uri", buttonDataShareUpdate->uri);
- GetJsonValue(dataShareUpdate, "equalTo", buttonDataShareUpdate->equalTo);
- GetJsonValue(dataShareUpdate, "valuesBucket", buttonDataShareUpdate->valuesBucket);
+ return creatorBundleName_;
+}
+
+void ReminderRequest::SetCreatorBundleName(const std::string& creatorBundleName)
+{
+ creatorBundleName_ = creatorBundleName;
+}
+
+int32_t ReminderRequest::GetCreatorUid() const
+{
+ return creatorUid_;
+}
+
+void ReminderRequest::SetCreatorUid(const int32_t creatorUid)
+{
+ creatorUid_ = creatorUid;
+}
+
+uint8_t ReminderRequest::GetRepeatDaysOfWeek() const
+{
+ return repeatDaysOfWeek_;
+}
+
+void ReminderRequest::SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek)
+{
+ repeatDaysOfWeek_ = repeatDaysOfWeek;
+}
+
+std::shared_ptr ReminderRequest::GetWantAgentInfo() const
+{
+ return wantAgentInfo_;
+}
+
+void ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo)
+{
+ if (wantAgentInfo != nullptr) {
+ wantAgentInfo_ = wantAgentInfo;
}
- SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)),
- resource, buttonWantAgent, buttonDataShareUpdate);
}
-void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet)
+std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const
+{
+ return maxScreenWantAgentInfo_;
+}
+
+void ReminderRequest::SetMaxScreenWantAgentInfo(
+ const std::shared_ptr &maxScreenWantAgentInfo)
{
- if (resultSet == nullptr) {
- ANSR_LOGE("ResultSet is null");
- return;
+ maxScreenWantAgentInfo_ = maxScreenWantAgentInfo;
+}
+
+sptr ReminderRequest::GetNotificationRequest() const
+{
+ return notificationRequest_;
+}
+
+std::string ReminderRequest::SerializeButtonInfo() const
+{
+ std::string info = "";
+ bool isFirst = true;
+ for (auto button : actionButtonMap_) {
+ if (!isFirst) {
+ info += SEP_BUTTON_MULTI;
+ }
+ ActionButtonInfo buttonInfo = button.second;
+ nlohmann::json root;
+ root["type"] = std::to_string(static_cast(button.first));
+ root["title"] = buttonInfo.title;
+ root["resource"] = buttonInfo.resource;
+ if (buttonInfo.wantAgent != nullptr) {
+ nlohmann::json wantAgentfriends;
+ wantAgentfriends["pkgName"] = buttonInfo.wantAgent->pkgName;
+ wantAgentfriends["abilityName"] = buttonInfo.wantAgent->abilityName;
+ root["wantAgent"] = wantAgentfriends;
+ }
+
+ if (buttonInfo.dataShareUpdate != nullptr) {
+ nlohmann::json dataShareUpdatefriends;
+ dataShareUpdatefriends["uri"] = buttonInfo.dataShareUpdate->uri;
+ dataShareUpdatefriends["equalTo"] = buttonInfo.dataShareUpdate->equalTo;
+ dataShareUpdatefriends["valuesBucket"] = buttonInfo.dataShareUpdate->valuesBucket;
+ root["dataShareUpdate"] = dataShareUpdatefriends;
+ }
+ std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace);
+ info += str;
+ isFirst = false;
}
- std::string actionButtonInfo;
- ReminderStore::GetStringVal(resultSet, ReminderBaseTable::ACTION_BUTTON_INFO, actionButtonInfo);
- std::vector multiButton = StringSplit(actionButtonInfo, SEP_BUTTON_MULTI);
+ return info;
+}
+
+void ReminderRequest::DeserializeButtonInfo(const std::string& buttonInfo)
+{
+ std::vector multiButton = StringSplit(buttonInfo, SEP_BUTTON_MULTI);
for (auto button : multiButton) {
std::vector singleButton = StringSplit(button, SEP_BUTTON_SINGLE);
if (singleButton.size() <= SINGLE_BUTTON_INVALID) {
@@ -671,402 +539,595 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptr ReminderRequest::StringSplit(std::string source, const std::string &split)
+std::string ReminderRequest::SerializeWantAgent() const
{
- std::vector result;
- if (source.empty()) {
- return result;
- }
- size_t pos = 0;
- while ((pos = source.find(split)) != std::string::npos) {
- std::string token = source.substr(0, pos);
- if (!token.empty()) {
- result.push_back(token);
- }
- source.erase(0, pos + split.length());
- }
- if (!source.empty()) {
- result.push_back(source);
+ std::string pkgName;
+ std::string abilityName;
+ std::string uri;
+ std::string parameters;
+ if (wantAgentInfo_ != nullptr) {
+ pkgName = wantAgentInfo_->pkgName;
+ abilityName = wantAgentInfo_->abilityName;
+ uri = wantAgentInfo_->uri;
+ AAFwk::WantParamWrapper wrapper(wantAgentInfo_->parameters);
+ parameters = wrapper.ToString();
}
- return result;
+ nlohmann::json wantInfo;
+ wantInfo["pkgName"] = pkgName;
+ wantInfo["abilityName"] = abilityName;
+ wantInfo["uri"] = uri;
+ wantInfo["parameters"] = parameters;
+ std::string info = wantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace);
+ return info;
}
-void ReminderRequest::RecoverWantAgentByJson(const std::string& wantAgentInfo, const uint8_t& type)
+void ReminderRequest::DeserializeWantAgent(const std::string& wantInfo)
{
- nlohmann::json root = nlohmann::json::parse(wantAgentInfo, nullptr, false);
- if (root.is_discarded()) {
- ANSR_LOGW("parse json data failed");
+ if (nlohmann::json::accept(wantInfo)) {
+ RecoverWantAgentByJson(wantInfo, 0);
return;
}
- if (!root.contains("pkgName") || !root["pkgName"].is_string() ||
- !root.contains("abilityName") || !root["abilityName"].is_string() ||
- !root.contains("uri") || !root["uri"].is_string() ||
- !root.contains("parameters") || !root["parameters"].is_string()) {
+ std::vector info = StringSplit(wantInfo, ReminderRequest::SEP_WANT_AGENT);
+ uint8_t minLen = 2;
+ if (info.size() < minLen) {
+ ANSR_LOGW("RecoverWantAgent fail");
return;
}
+ ANSR_LOGD("pkg=%{public}s, ability=%{public}s", info.at(0).c_str(), info.at(1).c_str());
+ auto wai = std::make_shared();
+ wai->pkgName = info.at(0);
+ wai->abilityName = info.at(1);
+ if (info.size() > minLen) {
+ wai->uri = info.at(WANT_AGENT_URI_INDEX);
+ }
+ SetWantAgentInfo(wai);
+}
- std::string pkgName = root.at("pkgName").get();
- std::string abilityName = root.at("abilityName").get();
- std::string uri = root.at("uri").get();
- std::string parameters = root.at("parameters").get();
- switch (type) {
- case WANT_AGENT_FLAG: {
- auto wai = std::make_shared();
- wai->pkgName = pkgName;
- wai->abilityName = abilityName;
- wai->uri = uri;
- wai->parameters = AAFwk::WantParamWrapper::ParseWantParams(parameters);
- SetWantAgentInfo(wai);
- break;
- }
- case MAX_WANT_AGENT_FLAG: {
- auto maxScreenWantAgentInfo = std::make_shared();
- maxScreenWantAgentInfo->pkgName = pkgName;
- maxScreenWantAgentInfo->abilityName = abilityName;
- SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo);
- break;
- }
- default: {
- ANSR_LOGW("RecoverWantAgent type not support");
- break;
- }
+std::string ReminderRequest::SerializeMaxWantAgent() const
+{
+ std::string pkgName;
+ std::string abilityName;
+ std::string uri;
+ std::string parameters;
+ if (maxScreenWantAgentInfo_ != nullptr) {
+ pkgName = maxScreenWantAgentInfo_->pkgName;
+ abilityName = maxScreenWantAgentInfo_->abilityName;
+ uri = "";
+ parameters = "";
}
+ nlohmann::json maxWantInfo;
+ maxWantInfo["pkgName"] = pkgName;
+ maxWantInfo["abilityName"] = abilityName;
+ maxWantInfo["uri"] = uri;
+ maxWantInfo["parameters"] = parameters;
+ std::string info = maxWantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace);
+ return info;
}
-void ReminderRequest::RecoverWantAgent(const std::string &wantAgentInfo, const uint8_t &type)
+void ReminderRequest::DeserializeMaxWantAgent(const std::string& maxWantInfo)
{
- if (nlohmann::json::accept(wantAgentInfo)) {
- RecoverWantAgentByJson(wantAgentInfo, type);
+ if (nlohmann::json::accept(maxWantInfo)) {
+ RecoverWantAgentByJson(maxWantInfo, 1);
return;
}
- std::vector info = StringSplit(wantAgentInfo, ReminderRequest::SEP_WANT_AGENT);
+ std::vector info = StringSplit(maxWantInfo, ReminderRequest::SEP_WANT_AGENT);
uint8_t minLen = 2;
if (info.size() < minLen) {
ANSR_LOGW("RecoverWantAgent fail");
return;
}
ANSR_LOGD("pkg=%{public}s, ability=%{public}s", info.at(0).c_str(), info.at(1).c_str());
- switch (type) {
- case 0: {
- auto wai = std::make_shared();
- wai->pkgName = info.at(0);
- wai->abilityName = info.at(1);
- if (info.size() > minLen) {
- wai->uri = info.at(WANT_AGENT_URI_INDEX);
- }
- SetWantAgentInfo(wai);
- break;
- }
- case 1: {
- auto maxScreenWantAgentInfo = std::make_shared();
- maxScreenWantAgentInfo->pkgName = info.at(0);
- maxScreenWantAgentInfo->abilityName = info.at(1);
- SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo);
- break;
- }
- default: {
- ANSR_LOGW("RecoverWantAgent type not support");
- break;
- }
+ auto maxScreenWantAgentInfo = std::make_shared();
+ maxScreenWantAgentInfo->pkgName = info.at(0);
+ maxScreenWantAgentInfo->abilityName = info.at(1);
+ SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo);
+}
+
+
+
+
+
+
+bool ReminderRequest::CanRemove() const
+{
+ if ((state_ & (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE)) == 0) {
+ return true;
}
+ return false;
}
-ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo(
- const std::shared_ptr &maxScreenWantAgentInfo)
+bool ReminderRequest::CanShow() const
{
- maxScreenWantAgentInfo_ = maxScreenWantAgentInfo;
- return *this;
+ // when system time change by user manually, and the reminde is to show immediately,
+ // the show reminder just need to be triggered by ReminderDataManager#RefreshRemindersLocked(uint8_t).
+ // we need to make the REMINDER_EVENT_ALARM_ALERT do nothing.
+ uint64_t nowInstantMilli = GetNowInstantMilli();
+ if (nowInstantMilli == 0) {
+ return false;
+ }
+ if (nowInstantMilli < (GetReminderTimeInMilli() + MIN_TIME_INTERVAL_IN_MILLI)) {
+ return false;
+ }
+ return true;
}
-ReminderRequest& ReminderRequest::SetNotificationId(int32_t notificationId)
+std::string ReminderRequest::Dump() const
{
- notificationId_ = notificationId;
- return *this;
+ const time_t nextTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS);
+ std::string dateTimeInfo = GetTimeInfoInner(nextTriggerTime, TimeFormat::YMDHMS, true);
+ return "Reminder["
+ "reminderId=" + std::to_string(reminderId_) +
+ ", type=" + std::to_string(static_cast(reminderType_)) +
+ ", state=" + GetState(state_) +
+ ", nextTriggerTime=" + dateTimeInfo.c_str() +
+ "]";
}
-ReminderRequest& ReminderRequest::SetGroupId(const std::string &groupId)
+ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type,
+ const std::string &resource, const std::shared_ptr &buttonWantAgent,
+ const std::shared_ptr &buttonDataShareUpdate)
{
- groupId_ = groupId;
+ if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE) && (type != ActionButtonType::CUSTOM)) {
+ ANSR_LOGI("Button type is not support: %{public}d.", static_cast(type));
+ return *this;
+ }
+ ActionButtonInfo actionButtonInfo;
+ actionButtonInfo.type = type;
+ actionButtonInfo.title = title;
+ actionButtonInfo.resource = resource;
+ actionButtonInfo.wantAgent = buttonWantAgent;
+ actionButtonInfo.dataShareUpdate = buttonDataShareUpdate;
+
+ actionButtonMap_.insert(std::pair(type, actionButtonInfo));
return *this;
}
-ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotType &slotType)
+void ReminderRequest::InitReminderId()
{
- slotType_ = slotType;
- return *this;
+ std::lock_guard lock(std::mutex);
+ if (GLOBAL_ID < 0) {
+ ANSR_LOGW("GLOBAL_ID overdule");
+ GLOBAL_ID = 0;
+ }
+ reminderId_ = ++GLOBAL_ID;
+ ANSR_LOGI("reminderId_=%{public}d", reminderId_);
}
-ReminderRequest& ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType)
+bool ReminderRequest::IsShowing() const
{
- snoozeSlotType_ = snoozeSlotType;
- return *this;
+ if ((state_ & REMINDER_STATUS_SHOWING) != 0) {
+ return true;
+ }
+ return false;
}
-ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent)
+void ReminderRequest::OnClose(bool updateNext)
{
- snoozeContent_ = snoozeContent;
- return *this;
+ if ((state_ & REMINDER_STATUS_SHOWING) == 0) {
+ ANSR_LOGE("onClose, the state of reminder is incorrect, state:%{public}s", GetState(state_).c_str());
+ return;
+ }
+ SetState(false, REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE, "onClose()");
+ if ((state_ & REMINDER_STATUS_ALERTING) != 0) {
+ SetState(false, REMINDER_STATUS_ALERTING, "onClose");
+ }
+ if (updateNext) {
+ uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
+ if (nextTriggerTime == INVALID_LONG_LONG_VALUE) {
+ isExpired_ = true;
+ } else {
+ SetTriggerTimeInMilli(nextTriggerTime);
+ snoozeTimesDynamic_ = snoozeTimes_;
+ }
+ }
}
-ReminderRequest& ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes)
+bool ReminderRequest::OnDateTimeChange()
{
- snoozeTimes_ = snoozeTimes;
- SetSnoozeTimesDynamic(snoozeTimes);
- return *this;
+ uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
+ return HandleSysTimeChange(triggerTimeInMilli_, nextTriggerTime);
}
-ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes)
+bool ReminderRequest::HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime)
{
- snoozeTimesDynamic_ = snooziTimes;
- return *this;
+ if (isExpired_) {
+ return false;
+ }
+ uint64_t now = GetNowInstantMilli();
+ if (now == 0) {
+ ANSR_LOGE("get now time failed.");
+ return false;
+ }
+ if (oriTriggerTime == 0 && optTriggerTime < now) {
+ ANSR_LOGW("trigger time is less than now time.");
+ return false;
+ }
+ bool showImmediately = false;
+ if (optTriggerTime != INVALID_LONG_LONG_VALUE && (optTriggerTime <= oriTriggerTime || oriTriggerTime == 0)) {
+ // case1. switch to a previous time
+ SetTriggerTimeInMilli(optTriggerTime);
+ snoozeTimesDynamic_ = snoozeTimes_;
+ } else {
+ if (oriTriggerTime <= now) {
+ // case2. switch to a future time, trigger time is less than now time.
+ // when the reminder show immediately, trigger time will update in onShow function.
+ snoozeTimesDynamic_ = 0;
+ showImmediately = true;
+ } else {
+ // case3. switch to a future time, trigger time is larger than now time.
+ showImmediately = false;
+ }
+ }
+ return showImmediately;
}
-ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds)
+bool ReminderRequest::HandleTimeZoneChange(
+ uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime)
{
- if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) {
- ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range");
- timeIntervalInMilli_ = 0;
+ if (isExpired_) {
+ return false;
+ }
+ ANSR_LOGD("Handle timezone change, old:%{public}" PRIu64 ", new:%{public}" PRIu64 "",
+ oldZoneTriggerTime, newZoneTriggerTime);
+ if (oldZoneTriggerTime == newZoneTriggerTime) {
+ return false;
+ }
+ bool showImmediately = false;
+ if (optTriggerTime != INVALID_LONG_LONG_VALUE && oldZoneTriggerTime < newZoneTriggerTime) {
+ // case1. timezone change to smaller
+ SetTriggerTimeInMilli(optTriggerTime);
+ snoozeTimesDynamic_ = snoozeTimes_;
} else {
- uint64_t timeIntervalInMilli = timeIntervalInSeconds * MILLI_SECONDS;
- if (timeIntervalInMilli > 0 && timeIntervalInMilli < MIN_TIME_INTERVAL_IN_MILLI) {
- ANSR_LOGW("SetTimeInterval, replace to set %{public}u, for the given is 0<%{public}" PRIu64 "<%{public}u",
- MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS, timeIntervalInSeconds,
- MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS);
- timeIntervalInMilli_ = MIN_TIME_INTERVAL_IN_MILLI;
+ // case2. timezone change to larger
+ time_t now;
+ (void)time(&now); // unit is seconds.
+ if (static_cast(now) < 0) {
+ ANSR_LOGE("Get now time error");
+ return false;
+ }
+ if (newZoneTriggerTime <= GetDurationSinceEpochInMilli(now)) {
+ snoozeTimesDynamic_ = 0;
+ showImmediately = true;
} else {
- timeIntervalInMilli_ = timeIntervalInMilli;
+ SetTriggerTimeInMilli(newZoneTriggerTime);
+ showImmediately = false;
}
}
- return *this;
+ return showImmediately;
}
-ReminderRequest& ReminderRequest::SetTitle(const std::string &title)
+void ReminderRequest::OnSameNotificationIdCovered()
{
- title_ = title;
- return *this;
+ SetState(false, REMINDER_STATUS_ALERTING | REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE,
+ "OnSameNotificationIdCovered");
}
-void ReminderRequest::SetTriggerTimeInMilli(uint64_t triggerTimeInMilli)
+void ReminderRequest::OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify)
{
- triggerTimeInMilli_ = triggerTimeInMilli;
+ if ((state_ & (REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE)) != 0) {
+ SetState(false, REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE, "onShow()");
+ }
+ if (isSysTimeChanged) {
+ uint64_t nowInstantMilli = GetNowInstantMilli();
+ if (nowInstantMilli == 0) {
+ ANSR_LOGW("Onshow, get now time error");
+ }
+ reminderTimeInMilli_ = nowInstantMilli;
+ } else {
+ reminderTimeInMilli_ = triggerTimeInMilli_;
+ }
+ UpdateNextReminder(false);
+ if (allowToNotify) {
+ SetState(true, REMINDER_STATUS_SHOWING, "OnShow");
+ if (isPlaySoundOrVibration) {
+ SetState(true, REMINDER_STATUS_ALERTING, "OnShow");
+ }
+ UpdateNotificationStateForAlert();
+ }
}
-ReminderRequest& ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo)
+void ReminderRequest::OnShowFail()
{
- if (wantAgentInfo != nullptr) {
- wantAgentInfo_ = wantAgentInfo;
- }
- return *this;
+ SetState(false, REMINDER_STATUS_SHOWING, "OnShowFailed()");
}
-bool ReminderRequest::ShouldShowImmediately() const
+bool ReminderRequest::OnSnooze()
{
- uint64_t nowInstantMilli = GetNowInstantMilli();
- if (nowInstantMilli == 0) {
+ if ((state_ & REMINDER_STATUS_SNOOZE) != 0) {
+ ANSR_LOGW("onSnooze, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
return false;
}
- if (triggerTimeInMilli_ > nowInstantMilli) {
+ if ((state_ & REMINDER_STATUS_ALERTING) != 0) {
+ SetState(false, REMINDER_STATUS_ALERTING, "onSnooze()");
+ }
+ SetSnoozeTimesDynamic(GetSnoozeTimes());
+ if (!UpdateNextReminder(true)) {
return false;
}
+ UpdateNotificationStateForSnooze();
+ if (timeIntervalInMilli_ > 0) {
+ SetState(true, REMINDER_STATUS_SNOOZE, "onSnooze()");
+ }
return true;
}
-std::map ReminderRequest::GetActionButtons(
- ) const
-{
- return actionButtonMap_;
-}
-
-std::string ReminderRequest::GetCreatorBundleName() const
-{
- return creatorBundleName_;
-}
-
-int32_t ReminderRequest::GetCreatorUid() const
-{
- return creatorUid_;
-}
-
-std::string ReminderRequest::GetContent() const
-{
- return content_;
-}
-
-std::string ReminderRequest::GetExpiredContent() const
-{
- return expiredContent_;
-}
-
-std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const
-{
- return maxScreenWantAgentInfo_;
-}
-
-int32_t ReminderRequest::GetNotificationId() const
-{
- return notificationId_;
-}
-
-std::string ReminderRequest::GetGroupId() const
+void ReminderRequest::OnStart()
{
- return groupId_;
+ if ((state_ & REMINDER_STATUS_ACTIVE) != 0) {
+ ANSR_LOGE(
+ "start failed, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
+ return;
+ }
+ if (isExpired_) {
+ ANSR_LOGE("start failed, the reminder is expired");
+ return;
+ }
+ SetState(true, REMINDER_STATUS_ACTIVE, "OnStart()");
}
-sptr ReminderRequest::GetNotificationRequest() const
+void ReminderRequest::OnStop()
{
- return notificationRequest_;
+ ANSR_LOGI("Stop the previous active reminder, %{public}s", this->Dump().c_str());
+ if ((state_ & REMINDER_STATUS_ACTIVE) == 0) {
+ ANSR_LOGW("onStop, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str());
+ return;
+ }
+ SetState(false, REMINDER_STATUS_ACTIVE, "OnStop");
}
-int32_t ReminderRequest::GetReminderId() const
+bool ReminderRequest::OnTerminate()
{
- return reminderId_;
+ if ((state_ & REMINDER_STATUS_ALERTING) == 0) {
+ ANSR_LOGW("onTerminate, the state of reminder is %{public}s", (GetState(state_)).c_str());
+ return false;
+ }
+ SetState(false, REMINDER_STATUS_ALERTING, "onTerminate");
+ UpdateNotificationStateForAlert();
+ return true;
}
-uint64_t ReminderRequest::GetReminderTimeInMilli() const
+bool ReminderRequest::OnTimeZoneChange()
{
- return reminderTimeInMilli_;
+ time_t oldZoneTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS);
+ struct tm *localOriTime = localtime(&oldZoneTriggerTime);
+ if (localOriTime == nullptr) {
+ ANSR_LOGE("oldZoneTriggerTime is null");
+ return false;
+ }
+ time_t newZoneTriggerTime = mktime(localOriTime);
+ uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false);
+ return HandleTimeZoneChange(
+ triggerTimeInMilli_, GetDurationSinceEpochInMilli(newZoneTriggerTime), nextTriggerTime);
}
-void ReminderRequest::SetReminderId(int32_t reminderId)
+int64_t ReminderRequest::RecoverInt64FromDb(const std::shared_ptr &resultSet,
+ const std::string &columnName, const DbRecoveryType &columnType)
{
- reminderId_ = reminderId;
+ if (resultSet == nullptr) {
+ ANSR_LOGE("ResultSet is null");
+ return 0;
+ }
+ switch (columnType) {
+ case (DbRecoveryType::INT): {
+ int32_t value;
+ ReminderStore::GetInt32Val(resultSet, columnName, value);
+ return static_cast(value);
+ }
+ case (DbRecoveryType::LONG): {
+ int64_t value;
+ ReminderStore::GetInt64Val(resultSet, columnName, value);
+ return value;
+ }
+ default: {
+ ANSR_LOGD("ColumnType not support.");
+ break;
+ }
+ }
+ ANSR_LOGE("Recover data error");
+ return 0;
}
-void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli)
+void ReminderRequest::RecoverBasicFromDb(const std::shared_ptr& resultSet)
{
- reminderTimeInMilli_ = reminderTimeInMilli;
-}
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::REMINDER_ID, reminderId_);
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::PACKAGE_NAME, bundleName_);
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::USER_ID, userId_);
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::UID, uid_);
-ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds)
-{
- uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS;
- ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION);
- return *this;
-}
+ std::string isSysApp;
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::SYSTEM_APP, isSysApp);
+ isSystemApp_ = isSysApp == "true" ? true : false;
-NotificationConstant::SlotType ReminderRequest::GetSlotType() const
-{
- return slotType_;
-}
+ int32_t reminderType;
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::REMINDER_TYPE, reminderType);
+ reminderType_ = ReminderType(reminderType);
-NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const
-{
- return snoozeSlotType_;
-}
+ ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::REMINDER_TIME, reminderTimeInMilli_);
+ ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::TRIGGER_TIME, triggerTimeInMilli_);
-std::string ReminderRequest::GetSnoozeContent() const
-{
- return snoozeContent_;
-}
+ uint64_t timeIntervalInSecond = 0;
+ ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::TIME_INTERVAL, timeIntervalInSecond);
+ SetTimeInterval(timeIntervalInSecond);
-uint8_t ReminderRequest::GetSnoozeTimes() const
-{
- return snoozeTimes_;
-}
+ ReminderStore::GetUInt8Val(resultSet, ReminderBaseTable::SNOOZE_TIMES, snoozeTimes_);
+ ReminderStore::GetUInt8Val(resultSet, ReminderBaseTable::DYNAMIC_SNOOZE_TIMES, snoozeTimesDynamic_);
-uint8_t ReminderRequest::GetSnoozeTimesDynamic() const
-{
- return snoozeTimesDynamic_;
-}
+ uint64_t ringDurationInSecond;
+ ReminderStore::GetUInt64Val(resultSet, ReminderBaseTable::RING_DURATION, ringDurationInSecond);
+ SetRingDuration(ringDurationInSecond);
-uint8_t ReminderRequest::GetState() const
-{
- return state_;
-}
+ std::string isExpired;
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::IS_EXPIRED, isExpired);
+ isExpired_ = isExpired == "true" ? true : false;
-uint64_t ReminderRequest::GetTimeInterval() const
-{
- return timeIntervalInMilli_ / MILLI_SECONDS;
-}
+ ReminderStore::GetUInt8Val(resultSet, ReminderBaseTable::STATE, state_);
-std::string ReminderRequest::GetTitle() const
-{
- return title_;
-}
+ // action buttons
+ RecoverActionButton(resultSet);
-uint64_t ReminderRequest::GetTriggerTimeInMilli() const
-{
- return triggerTimeInMilli_;
-}
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CUSTOM_BUTTON_URI, customButtonUri_);
-int32_t ReminderRequest::GetUserId() const
-{
- return userId_;
-}
+ int32_t slotType;
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::SLOT_ID, slotType);
+ slotType_ = NotificationConstant::SlotType(slotType);
-int32_t ReminderRequest::GetUid() const
-{
- return uid_;
-}
+ int32_t snoozeSlotType;
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::SNOOZE_SLOT_ID, snoozeSlotType);
+ snoozeSlotType_ = NotificationConstant::SlotType(snoozeSlotType);
-std::string ReminderRequest::GetBundleName() const
-{
- return bundleName_;
-}
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::NOTIFICATION_ID, notificationId_);
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::TITLE, title_);
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CONTENT, content_);
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::SNOOZE_CONTENT, snoozeContent_);
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::EXPIRED_CONTENT, expiredContent_);
-void ReminderRequest::SetSystemApp(bool isSystem)
-{
- isSystemApp_ = isSystem;
+ InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent
}
-bool ReminderRequest::IsSystemApp() const
+void ReminderRequest::RecoverFromDbBase(const std::shared_ptr& resultSet)
{
- return isSystemApp_;
-}
+ if (resultSet == nullptr) {
+ ANSR_LOGE("ResultSet is null");
+ return;
+ }
+ RecoverBasicFromDb(resultSet);
-void ReminderRequest::SetTapDismissed(bool tapDismissed)
-{
- tapDismissed_ = tapDismissed;
-}
+ std::string wantAgent;
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::WANT_AGENT, wantAgent);
+ RecoverWantAgent(wantAgent, 0);
-bool ReminderRequest::IsTapDismissed() const
-{
- return tapDismissed_;
-}
+ std::string maxScreenWantAgent;
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::MAX_SCREEN_WANT_AGENT, maxScreenWantAgent);
+ RecoverWantAgent(maxScreenWantAgent, 1);
-void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime)
-{
- autoDeletedTime_ = autoDeletedTime;
-}
+ std::string tapDismissed;
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::TAP_DISMISSED, tapDismissed);
+ tapDismissed_ = tapDismissed == "true" ? true : false;
-int64_t ReminderRequest::GetAutoDeletedTime() const
-{
- return autoDeletedTime_;
-}
+ ReminderStore::GetInt64Val(resultSet, ReminderBaseTable::AUTO_DELETED_TIME, autoDeletedTime_);
-void ReminderRequest::SetCustomButtonUri(const std::string &uri)
-{
- customButtonUri_ = uri;
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::GROUP_ID, groupId_);
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CUSTOM_RING_URI, customRingUri_);
+ ReminderStore::GetStringVal(resultSet, ReminderBaseTable::CREATOR_BUNDLE_NAME, creatorBundleName_);
+ ReminderStore::GetInt32Val(resultSet, ReminderBaseTable::CREATOR_UID, creatorUid_);
}
-std::string ReminderRequest::GetCustomButtonUri() const
+void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString)
{
- return customButtonUri_;
+ if (!nlohmann::json::accept(jsonString)) {
+ ANSR_LOGW("not a json string!");
+ return;
+ }
+ nlohmann::json root = nlohmann::json::parse(jsonString, nullptr, false);
+ if (root.is_discarded()) {
+ ANSR_LOGW("parse json data failed!");
+ return;
+ }
+ std::string type;
+ GetJsonValue(root, "type", type);
+ if (!IsVaildButtonType(type)) {
+ ANSR_LOGW("unkown button type!");
+ return;
+ }
+ std::string title;
+ GetJsonValue(root, "title", title);
+ std::string resource;
+ GetJsonValue(root, "resource", resource);
+ auto buttonWantAgent = std::make_shared();
+ if (root.contains("wantAgent") && !root["wantAgent"].empty()) {
+ nlohmann::json wantAgent = root["wantAgent"];
+ GetJsonValue(wantAgent, "pkgName", buttonWantAgent->pkgName);
+ GetJsonValue(wantAgent, "abilityName", buttonWantAgent->abilityName);
+ }
+ auto buttonDataShareUpdate = std::make_shared();
+ if (root.contains("dataShareUpdate") && !root["dataShareUpdate"].empty()) {
+ nlohmann::json dataShareUpdate = root["dataShareUpdate"];
+ GetJsonValue(dataShareUpdate, "uri", buttonDataShareUpdate->uri);
+ GetJsonValue(dataShareUpdate, "equalTo", buttonDataShareUpdate->equalTo);
+ GetJsonValue(dataShareUpdate, "valuesBucket", buttonDataShareUpdate->valuesBucket);
+ }
+ SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)),
+ resource, buttonWantAgent, buttonDataShareUpdate);
}
-void ReminderRequest::SetCustomRingUri(const std::string &uri)
+std::vector ReminderRequest::StringSplit(std::string source, const std::string &split)
{
- customRingUri_ = uri;
+ std::vector result;
+ if (source.empty()) {
+ return result;
+ }
+ size_t pos = 0;
+ while ((pos = source.find(split)) != std::string::npos) {
+ std::string token = source.substr(0, pos);
+ if (!token.empty()) {
+ result.push_back(token);
+ }
+ source.erase(0, pos + split.length());
+ }
+ if (!source.empty()) {
+ result.push_back(source);
+ }
+ return result;
}
-std::string ReminderRequest::GetCustomRingUri() const
+void ReminderRequest::RecoverWantAgentByJson(const std::string& wantAgentInfo, const uint8_t& type)
{
- return customRingUri_;
-}
+ nlohmann::json root = nlohmann::json::parse(wantAgentInfo, nullptr, false);
+ if (root.is_discarded()) {
+ ANSR_LOGW("parse json data failed");
+ return;
+ }
+ if (!root.contains("pkgName") || !root["pkgName"].is_string() ||
+ !root.contains("abilityName") || !root["abilityName"].is_string() ||
+ !root.contains("uri") || !root["uri"].is_string() ||
+ !root.contains("parameters") || !root["parameters"].is_string()) {
+ return;
+ }
-std::shared_ptr ReminderRequest::GetWantAgentInfo() const
-{
- return wantAgentInfo_;
+ std::string pkgName = root.at("pkgName").get();
+ std::string abilityName = root.at("abilityName").get();
+ std::string uri = root.at("uri").get();
+ std::string parameters = root.at("parameters").get();
+ switch (type) {
+ case WANT_AGENT_FLAG: {
+ auto wai = std::make_shared();
+ wai->pkgName = pkgName;
+ wai->abilityName = abilityName;
+ wai->uri = uri;
+ wai->parameters = AAFwk::WantParamWrapper::ParseWantParams(parameters);
+ SetWantAgentInfo(wai);
+ break;
+ }
+ case MAX_WANT_AGENT_FLAG: {
+ auto maxScreenWantAgentInfo = std::make_shared();
+ maxScreenWantAgentInfo->pkgName = pkgName;
+ maxScreenWantAgentInfo->abilityName = abilityName;
+ SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo);
+ break;
+ }
+ default: {
+ ANSR_LOGW("RecoverWantAgent type not support");
+ break;
+ }
+ }
}
-ReminderRequest::ReminderType ReminderRequest::GetReminderType() const
+bool ReminderRequest::ShouldShowImmediately() const
{
- return reminderType_;
+ uint64_t nowInstantMilli = GetNowInstantMilli();
+ if (nowInstantMilli == 0) {
+ return false;
+ }
+ if (triggerTimeInMilli_ > nowInstantMilli) {
+ return false;
+ }
+ return true;
}
-uint16_t ReminderRequest::GetRingDuration() const
+std::map ReminderRequest::GetActionButtons(
+ ) const
{
- return ringDurationInMilli_ / MILLI_SECONDS;
+ return actionButtonMap_;
}
bool ReminderRequest::UpdateNextReminder()
@@ -1411,40 +1472,6 @@ std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const
return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS, true);
}
-std::string ReminderRequest::GetButtonInfo() const
-{
- std::string info = "";
- bool isFirst = true;
- for (auto button : actionButtonMap_) {
- if (!isFirst) {
- info += SEP_BUTTON_MULTI;
- }
- ActionButtonInfo buttonInfo = button.second;
- nlohmann::json root;
- root["type"] = std::to_string(static_cast(button.first));
- root["title"] = buttonInfo.title;
- root["resource"] = buttonInfo.resource;
- if (buttonInfo.wantAgent != nullptr) {
- nlohmann::json wantAgentfriends;
- wantAgentfriends["pkgName"] = buttonInfo.wantAgent->pkgName;
- wantAgentfriends["abilityName"] = buttonInfo.wantAgent->abilityName;
- root["wantAgent"] = wantAgentfriends;
- }
-
- if (buttonInfo.dataShareUpdate != nullptr) {
- nlohmann::json dataShareUpdatefriends;
- dataShareUpdatefriends["uri"] = buttonInfo.dataShareUpdate->uri;
- dataShareUpdatefriends["equalTo"] = buttonInfo.dataShareUpdate->equalTo;
- dataShareUpdatefriends["valuesBucket"] = buttonInfo.dataShareUpdate->valuesBucket;
- root["dataShareUpdate"] = dataShareUpdatefriends;
- }
- std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace);
- info += str;
- isFirst = false;
- }
- return info;
-}
-
uint64_t ReminderRequest::GetNowInstantMilli() const
{
time_t now;
@@ -1909,87 +1936,6 @@ int32_t ReminderRequest::GetUserId(const int32_t &uid)
return userId;
}
-void ReminderRequest::AppendWantAgentValuesBucket(const sptr& reminder,
- NativeRdb::ValuesBucket& values)
-{
- std::string pkgName;
- std::string abilityName;
- std::string uri;
- std::string parameters;
- auto wantAgentInfo = reminder->GetWantAgentInfo();
- if (wantAgentInfo != nullptr) {
- pkgName = wantAgentInfo->pkgName;
- abilityName = wantAgentInfo->abilityName;
- uri = wantAgentInfo->uri;
- AAFwk::WantParamWrapper wrapper(wantAgentInfo->parameters);
- parameters = wrapper.ToString();
- }
- nlohmann::json wantInfo;
- wantInfo["pkgName"] = pkgName;
- wantInfo["abilityName"] = abilityName;
- wantInfo["uri"] = uri;
- wantInfo["parameters"] = parameters;
- std::string info = wantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace);
- values.PutString(ReminderBaseTable::WANT_AGENT, info);
-
- auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo();
- if (maxScreenWantAgentInfo != nullptr) {
- pkgName = maxScreenWantAgentInfo->pkgName;
- abilityName = maxScreenWantAgentInfo->abilityName;
- uri = "";
- parameters = "";
- }
- nlohmann::json maxWantInfo;
- maxWantInfo["pkgName"] = pkgName;
- maxWantInfo["abilityName"] = abilityName;
- maxWantInfo["uri"] = uri;
- maxWantInfo["parameters"] = parameters;
- info = maxWantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace);
- values.PutString(ReminderBaseTable::MAX_SCREEN_WANT_AGENT, info);
-}
-
-void ReminderRequest::AppendValuesBucket(const sptr &reminder,
- const sptr &bundleOption, NativeRdb::ValuesBucket &values, bool oldVersion)
-{
- values.PutInt(ReminderBaseTable::REMINDER_ID, reminder->GetReminderId());
- values.PutString(ReminderBaseTable::PACKAGE_NAME, reminder->GetBundleName());
- values.PutInt(ReminderBaseTable::USER_ID, reminder->GetUserId());
- values.PutInt(ReminderBaseTable::UID, reminder->GetUid());
- values.PutString(ReminderBaseTable::SYSTEM_APP, reminder->IsSystemApp() ? "true" : "false");
- values.PutInt(ReminderBaseTable::REMINDER_TYPE, static_cast(reminder->GetReminderType()));
- values.PutLong(ReminderBaseTable::REMINDER_TIME, reminder->GetReminderTimeInMilli());
- values.PutLong(ReminderBaseTable::TRIGGER_TIME, reminder->GetTriggerTimeInMilli());
- values.PutLong(ReminderBaseTable::TIME_INTERVAL, reminder->GetTimeInterval());
- values.PutInt(ReminderBaseTable::SNOOZE_TIMES, reminder->GetSnoozeTimes());
- values.PutInt(ReminderBaseTable::DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic());
- values.PutLong(ReminderBaseTable::RING_DURATION, reminder->GetRingDuration());
- values.PutString(ReminderBaseTable::IS_EXPIRED, reminder->IsExpired() ? "true" : "false");
- values.PutInt(ReminderBaseTable::STATE, reminder->GetState());
- values.PutString(ReminderBaseTable::ACTION_BUTTON_INFO, reminder->GetButtonInfo());
- values.PutString(ReminderBaseTable::CUSTOM_BUTTON_URI, reminder->GetCustomButtonUri());
- values.PutInt(ReminderBaseTable::SLOT_ID, reminder->GetSlotType());
- values.PutInt(ReminderBaseTable::SNOOZE_SLOT_ID, reminder->GetSnoozeSlotType());
- values.PutInt(ReminderBaseTable::NOTIFICATION_ID, reminder->GetNotificationId());
- values.PutString(ReminderBaseTable::TITLE, reminder->GetTitle());
- values.PutString(ReminderBaseTable::CONTENT, reminder->GetContent());
- values.PutString(ReminderBaseTable::SNOOZE_CONTENT, reminder->GetSnoozeContent());
- values.PutString(ReminderBaseTable::EXPIRED_CONTENT, reminder->GetExpiredContent());
-
- if (oldVersion) {
- values.PutString(ReminderBaseTable::WANT_AGENT, reminder->GetWantAgentStr());
- values.PutString(ReminderBaseTable::MAX_SCREEN_WANT_AGENT, reminder->GetMaxWantAgentStr());
- } else {
- AppendWantAgentValuesBucket(reminder, values);
- }
-
- values.PutString(ReminderBaseTable::TAP_DISMISSED, reminder->IsTapDismissed() ? "true" : "false");
- values.PutLong(ReminderBaseTable::AUTO_DELETED_TIME, reminder->GetAutoDeletedTime());
- values.PutString(ReminderBaseTable::GROUP_ID, reminder->GetGroupId());
- values.PutString(ReminderBaseTable::CUSTOM_RING_URI, reminder->GetCustomRingUri());
- values.PutString(ReminderBaseTable::CREATOR_BUNDLE_NAME, reminder->GetCreatorBundleName());
- values.PutInt(ReminderBaseTable::CREATOR_UID, reminder->GetCreatorUid());
-}
-
int64_t ReminderRequest::GetNextDaysOfWeek(const time_t now, const time_t target) const
{
struct tm nowTime;
diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/ans/src/reminder_request_alarm.cpp
index 8a08f7a5523b8629f5111748fe3d14a22f8aba11..8a4bb61cfeab5a5c3e12144efdea824caff3491c 100644
--- a/frameworks/ans/src/reminder_request_alarm.cpp
+++ b/frameworks/ans/src/reminder_request_alarm.cpp
@@ -22,7 +22,6 @@
namespace OHOS {
namespace Notification {
-const uint8_t ReminderRequestAlarm::MINUTES_PER_HOUR = 60;
const int8_t ReminderRequestAlarm::DEFAULT_SNOOZE_TIMES = 3;
ReminderRequestAlarm::ReminderRequestAlarm(uint8_t hour, uint8_t minute, const std::vector daysOfWeek)
@@ -197,49 +196,5 @@ bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel)
}
return false;
}
-
-void ReminderRequestAlarm::RecoverFromOldVersion(const std::shared_ptr &resultSet)
-{
- ReminderRequest::RecoverFromOldVersion(resultSet);
-
- // hour
- hour_ =
- static_cast(RecoverInt64FromDb(resultSet, ReminderTable::ALARM_HOUR,
- DbRecoveryType::INT));
-
- // minute
- minute_ =
- static_cast(RecoverInt64FromDb(resultSet, ReminderTable::ALARM_MINUTE,
- DbRecoveryType::INT));
-}
-
-void ReminderRequestAlarm::RecoverFromDb(const std::shared_ptr& resultSet)
-{
- if (resultSet == nullptr) {
- ANSR_LOGE("ResultSet is null");
- return;
- }
- ReminderStore::GetUInt8Val(resultSet, ReminderAlarmTable::ALARM_HOUR, hour_);
- ReminderStore::GetUInt8Val(resultSet, ReminderAlarmTable::ALARM_MINUTE, minute_);
- ReminderStore::GetUInt8Val(resultSet, ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek_);
-}
-
-void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder,
- const sptr &bundleOption, NativeRdb::ValuesBucket &values)
-{
- uint8_t hour = 0;
- uint8_t minute = 0;
- uint8_t repeatDaysOfWeek = 0;
- if (reminder->GetReminderType() == ReminderRequest::ReminderType::ALARM) {
- ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr());
- hour = alarm->GetHour();
- minute = alarm->GetMinute();
- repeatDaysOfWeek = alarm->GetRepeatDaysOfWeek();
- }
- values.PutInt(ReminderAlarmTable::REMINDER_ID, reminder->GetReminderId());
- values.PutInt(ReminderAlarmTable::ALARM_HOUR, hour);
- values.PutInt(ReminderAlarmTable::ALARM_MINUTE, minute);
- values.PutInt(ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek);
-}
}
}
\ No newline at end of file
diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/ans/src/reminder_request_calendar.cpp
index 83a3ed7f01a27a3e2cb3d599cdb4667ce572477a..d2062005bd2a1c95c8c7b9dcb33f7f5e34b299c6 100644
--- a/frameworks/ans/src/reminder_request_calendar.cpp
+++ b/frameworks/ans/src/reminder_request_calendar.cpp
@@ -655,134 +655,6 @@ bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel)
return false;
}
-void ReminderRequestCalendar::RecoverFromOldVersion(const std::shared_ptr &resultSet)
-{
- ReminderRequest::RecoverFromOldVersion(resultSet);
-
- // repeatDay
- repeatDay_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_DAYS,
- DbRecoveryType::INT));
-
- // repeatMonth
- repeatMonth_ =
- static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_MONTHS,
- DbRecoveryType::INT));
-
- // firstDesignateYear
- firstDesignateYear_ =
- static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_YEAR,
- DbRecoveryType::INT));
-
- // firstDesignateMonth
- firstDesignateMonth_ =
- static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_MONTH,
- DbRecoveryType::INT));
-
- // firstDesignateDay
- firstDesignateDay_ =
- static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_DAY,
- DbRecoveryType::INT));
-
- // year
- year_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_YEAR,
- DbRecoveryType::INT));
-
- // month
- month_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MONTH,
- DbRecoveryType::INT));
-
- // day
- day_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_DAY,
- DbRecoveryType::INT));
-
- // hour
- hour_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_HOUR,
- DbRecoveryType::INT));
-
- // minute
- minute_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MINUTE,
- DbRecoveryType::INT));
-}
-
-void ReminderRequestCalendar::RecoverFromDb(const std::shared_ptr& resultSet)
-{
- if (resultSet == nullptr) {
- ANSR_LOGE("ResultSet is null");
- return;
- }
- ReminderStore::GetUInt16Val(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_YEAR, firstDesignateYear_);
- ReminderStore::GetUInt8Val(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth_);
- ReminderStore::GetUInt8Val(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_DAY, firstDesignateDay_);
-
- uint64_t dateTime;
- ReminderStore::GetUInt64Val(resultSet, ReminderCalendarTable::CALENDAR_DATE_TIME, dateTime);
- SetDateTime(dateTime);
-
- uint64_t endDateTime;
- ReminderStore::GetUInt64Val(resultSet, ReminderCalendarTable::CALENDAR_END_DATE_TIME, endDateTime);
- if (endDateTime != 0 && endDateTime >= dateTime) {
- SetEndDateTime(endDateTime);
- } else {
- SetEndDateTime(startDateTime_);
- }
-
- int32_t repeatDay;
- ReminderStore::GetInt32Val(resultSet, ReminderCalendarTable::REPEAT_DAYS, repeatDay);
- repeatDay_ = static_cast(repeatDay);
-
- ReminderStore::GetUInt16Val(resultSet, ReminderCalendarTable::REPEAT_MONTHS, repeatMonth_);
- ReminderStore::GetUInt8Val(resultSet, ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek_);
-
- std::string rruleWantAgent;
- ReminderStore::GetStringVal(resultSet, ReminderCalendarTable::RRULE_WANT_AGENT, rruleWantAgent);
- DeserializationRRule(rruleWantAgent);
-
- std::string excludeDates;
- ReminderStore::GetStringVal(resultSet, ReminderCalendarTable::EXCLUDE_DATES, excludeDates);
- DeserializationExcludeDates(excludeDates);
-}
-
-void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder,
- const sptr &bundleOption, NativeRdb::ValuesBucket &values)
-{
- uint16_t firstDesignateYear = 0;
- uint8_t firstDesignateMonth = 0;
- uint8_t firstDesignateDay = 0;
- uint64_t dateTime = 0;
- uint32_t repeatDay = 0;
- uint16_t repeatMonth = 0;
- uint8_t repeatDaysOfWeek = 0;
- uint64_t endDateTime = 0;
- std::string rruleWantAgent;
- std::string excludeDates;
- if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) {
- ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr());
- if (calendar != nullptr) {
- repeatDay = calendar->GetRepeatDay();
- repeatMonth = calendar->GetRepeatMonth();
- firstDesignateYear = calendar->GetFirstDesignateYear();
- firstDesignateMonth = calendar->GetFirstDesignageMonth();
- firstDesignateDay = calendar->GetFirstDesignateDay();
- dateTime = calendar->GetDateTime();
- repeatDaysOfWeek = calendar->GetRepeatDaysOfWeek();
- endDateTime = calendar->GetEndDateTime();
- rruleWantAgent = calendar->SerializationRRule();
- excludeDates = calendar->SerializationExcludeDates();
- }
- }
- values.PutInt(ReminderCalendarTable::REMINDER_ID, reminder->GetReminderId());
- values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_YEAR, firstDesignateYear);
- values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth);
- values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_DAY, firstDesignateDay);
- values.PutLong(ReminderCalendarTable::CALENDAR_DATE_TIME, dateTime);
- values.PutLong(ReminderCalendarTable::CALENDAR_END_DATE_TIME, endDateTime);
- values.PutInt(ReminderCalendarTable::REPEAT_DAYS, repeatDay);
- values.PutInt(ReminderCalendarTable::REPEAT_MONTHS, repeatMonth);
- values.PutInt(ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, repeatDaysOfWeek);
- values.PutString(ReminderCalendarTable::RRULE_WANT_AGENT, rruleWantAgent);
- values.PutString(ReminderCalendarTable::EXCLUDE_DATES, excludeDates);
-}
-
void ReminderRequestCalendar::SetDateTime(const uint64_t time)
{
time_t t = static_cast(time / MILLI_SECONDS);
diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/ans/src/reminder_request_timer.cpp
index 6881b6261f6bbd2b490c77ad26e0c243dcb9ff4a..bb964e9c1722c4fc7c5f98c894f7185d155eefa7 100644
--- a/frameworks/ans/src/reminder_request_timer.cpp
+++ b/frameworks/ans/src/reminder_request_timer.cpp
@@ -150,28 +150,5 @@ bool ReminderRequestTimer::ReadFromParcel(Parcel &parcel)
}
return false;
}
-
-void ReminderRequestTimer::RecoverFromDb(const std::shared_ptr& resultSet)
-{
- if (resultSet == nullptr) {
- ANSR_LOGE("ResultSet is null");
- return;
- }
- ReminderStore::GetUInt64Val(resultSet, ReminderTimerTable::TRIGGER_SECOND, countDownTimeInSeconds_);
-}
-
-void ReminderRequestTimer::AppendValuesBucket(const sptr &reminder,
- const sptr &bundleOption, NativeRdb::ValuesBucket &values)
-{
- uint64_t seconds = 0;
- if (reminder->GetReminderType() == ReminderRequest::ReminderType::TIMER) {
- ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr());
- seconds = timer->GetInitInfo();
- }
- values.PutInt(ReminderTimerTable::REMINDER_ID, reminder->GetReminderId());
- values.PutLong(ReminderTimerTable::TRIGGER_SECOND, seconds);
- values.PutLong(ReminderTimerTable::START_DATE_TIME, 0);
- values.PutLong(ReminderTimerTable::END_DATE_TIME, 0);
-}
}
}
diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp
index b1fd3e023e48c0236466116a5a8056a00ca27c44..89efc3d9a9dcab3153faff7c0a9ea9410048c3f9 100644
--- a/frameworks/ans/test/unittest/reminder_request_test.cpp
+++ b/frameworks/ans/test/unittest/reminder_request_test.cpp
@@ -1160,12 +1160,12 @@ HWTEST_F(ReminderRequestTest, AddActionButtons_00001, Function | SmallTest | Lev
}
/**
- * @tc.name: InitUserId_00001
- * @tc.desc: Test InitUserId parameters.
+ * @tc.name: SetUserId_00001
+ * @tc.desc: Test SetUserId parameters.
* @tc.type: FUNC
* @tc.require: issueI65R21
*/
-HWTEST_F(ReminderRequestTest, InitUserId_00001, Function | SmallTest | Level1)
+HWTEST_F(ReminderRequestTest, SetUserId_00001, Function | SmallTest | Level1)
{
std::shared_ptr reminderRequestChild = std::make_shared();
ASSERT_NE(nullptr, reminderRequestChild);
@@ -1174,8 +1174,8 @@ HWTEST_F(ReminderRequestTest, InitUserId_00001, Function | SmallTest | Level1)
std::string function = "this is function";
int32_t userId = 1;
int32_t uid = 2;
- reminderRequestChild->InitUserId(userId);
- reminderRequestChild->InitUid(uid);
+ reminderRequestChild->SetUserId(userId);
+ reminderRequestChild->SetUid(uid);
reminderRequestChild->SetState(deSet, newState, function);
uint8_t result1 = reminderRequestChild->GetState();
EXPECT_EQ(result1, 2);
@@ -1202,8 +1202,8 @@ HWTEST_F(ReminderRequestTest, OnStart_00001, Function | SmallTest | Level1)
std::string function = "this is function";
int32_t userId = 1;
int32_t uid = 2;
- reminderRequestChild->InitUserId(userId);
- reminderRequestChild->InitUid(uid);
+ reminderRequestChild->SetUserId(userId);
+ reminderRequestChild->SetUid(uid);
reminderRequestChild->SetState(deSet, newState, function);
reminderRequestChild->OnStart();
reminderRequestChild->OnStop();
@@ -1823,30 +1823,30 @@ HWTEST_F(ReminderRequestTest, SetGroupId_00001, Function | SmallTest | Level1)
}
/**
- * @tc.name: InitBundleName_00001
- * @tc.desc: Test InitBundleName with normal parameters.
+ * @tc.name: SetBundleName_00001
+ * @tc.desc: Test SetBundleName with normal parameters.
* @tc.type: FUNC
* @tc.require: issueI89858
*/
-HWTEST_F(ReminderRequestTest, InitBundleName_00001, Function | SmallTest | Level1)
+HWTEST_F(ReminderRequestTest, SetBundleName_00001, Function | SmallTest | Level1)
{
auto rrc = std::make_shared();
std::string bundleName = "com.example.myapplication";
- rrc->InitBundleName(bundleName);
+ rrc->SetBundleName(bundleName);
EXPECT_EQ(rrc->GetBundleName(), bundleName);
}
/**
- * @tc.name: InitBundleName_00002
- * @tc.desc: Test InitBundleName with special parameters.
+ * @tc.name: SetBundleName_00002
+ * @tc.desc: Test SetBundleName with special parameters.
* @tc.type: FUNC
* @tc.require: issueI89858
*/
-HWTEST_F(ReminderRequestTest, InitBundleName_00002, Function | SmallTest | Level1)
+HWTEST_F(ReminderRequestTest, SetBundleName_00002, Function | SmallTest | Level1)
{
auto rrc = std::make_shared();
std::string bundleName = "com.example.myapplication.~!@#$%^&*()";
- rrc->InitBundleName(bundleName);
+ rrc->SetBundleName(bundleName);
EXPECT_EQ(rrc->GetBundleName(), bundleName);
}
@@ -1918,30 +1918,30 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00300, Function | SmallTe
}
/**
- * @tc.name: InitCreatorBundleName_00001
- * @tc.desc: Test InitCreatorBundleName with normal parameters.
+ * @tc.name: SetCreatorBundleName_00001
+ * @tc.desc: Test SetCreatorBundleName with normal parameters.
* @tc.type: FUNC
* @tc.require: issue#I8R55M
*/
-HWTEST_F(ReminderRequestTest, InitCreatorBundleName_00001, Function | SmallTest | Level1)
+HWTEST_F(ReminderRequestTest, SetCreatorBundleName_00001, Function | SmallTest | Level1)
{
auto rrc = std::make_shared();
std::string bundleName = "com.example.myapplication";
- rrc->InitCreatorBundleName(bundleName);
+ rrc->SetCreatorBundleName(bundleName);
EXPECT_EQ(rrc->GetCreatorBundleName(), bundleName);
}
/**
- * @tc.name: InitCreatorBundleName_00002
- * @tc.desc: Test InitCreatorBundleName with special parameters.
+ * @tc.name: SetCreatorBundleName_00002
+ * @tc.desc: Test SetCreatorBundleName with special parameters.
* @tc.type: FUNC
* @tc.require: issue#I8R55M
*/
-HWTEST_F(ReminderRequestTest, InitCreatorBundleName_00002, Function | SmallTest | Level1)
+HWTEST_F(ReminderRequestTest, SetCreatorBundleName_00002, Function | SmallTest | Level1)
{
auto rrc = std::make_shared();
std::string bundleName = "com.example.myapplication.~!@#$%^&*()";
- rrc->InitCreatorBundleName(bundleName);
+ rrc->SetCreatorBundleName(bundleName);
EXPECT_EQ(rrc->GetCreatorBundleName(), bundleName);
}
@@ -2297,18 +2297,18 @@ HWTEST_F(ReminderRequestTest, RecoverActionButtonJsonMode_00003, Function | Smal
}
/**
- * @tc.name: InitCreatorUid_00001
- * @tc.desc: Test InitCreatorUid.
+ * @tc.name: SetCreatorUid_00001
+ * @tc.desc: Test SetCreatorUid.
* @tc.type: FUNC
* @tc.require: issue#I94VJT
*/
-HWTEST_F(ReminderRequestTest, InitCreatorUid_00001, Function | SmallTest | Level1)
+HWTEST_F(ReminderRequestTest, SetCreatorUid_00001, Function | SmallTest | Level1)
{
auto rrc = std::make_shared();
- rrc->InitCreatorUid(100);
+ rrc->SetCreatorUid(100);
EXPECT_EQ(rrc->GetCreatorUid(), 100);
- rrc->InitCreatorUid(-1);
+ rrc->SetCreatorUid(-1);
EXPECT_EQ(rrc->GetCreatorUid(), -1);
EXPECT_EQ(ReminderRequest::GetAppIndex(20020152), 0);
diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h
index 0198c3b2e9117e73f47bcdfda287ddba18a1c898..73a980ae62c2fce9a3a2d5e1abc158d2c3172221 100644
--- a/interfaces/inner_api/reminder_request.h
+++ b/interfaces/inner_api/reminder_request.h
@@ -258,502 +258,690 @@ public:
std::string abilityName = "";
};
+public:
+ /**
+ * @brief This constructor should only be used in background proxy service process
+ * when reminder instance recovery from database.
+ *
+ * @param reminderId Indicates reminder id.
+ */
+ explicit ReminderRequest(const int32_t reminderId);
+ virtual ~ReminderRequest() override {}
+
/**
* @brief Copy construct from an exist reminder.
*
* @param Indicates the exist reminder.
*/
explicit ReminderRequest(const ReminderRequest &other);
+ ReminderRequest& operator = (const ReminderRequest &other);
+public:
/**
- * @brief This constructor should only be used in background proxy service process
- * when reminder instance recovery from database.
+ * @brief Obtains the reminder id.
*
- * @param reminderId Indicates reminder id.
+ * @return Returns the reminder id.
*/
- explicit ReminderRequest(int32_t reminderId);
- ReminderRequest& operator = (const ReminderRequest &other);
- virtual ~ReminderRequest() override {};
+ int32_t GetReminderId() const;
/**
- * @brief Marshal a NotificationRequest object into a Parcel.
+ * @brief Sets the reminder id.
*
- * @param parcel the object into the parcel
+ * @param reminderId Indicates the reminder id.
*/
- virtual bool Marshalling(Parcel &parcel) const override;
+ void SetReminderId(int32_t reminderId);
/**
- * @brief Unmarshal object from a Parcel.
+ * @brief Obtains the reminder bundle name of the notification owner.
*
- * @return the NotificationRequest
+ * @return Returns the reminder bundle name of the notification owner.
*/
- static ReminderRequest *Unmarshalling(Parcel &parcel);
- virtual bool ReadFromParcel(Parcel &parcel);
+ std::string GetBundleName() const;
/**
- * @brief If the reminder is showing on the notification panel, it should not be removed automatically.
+ * @brief Sets the reminder bundle name of the notification owner.
*
- * @return true if it can be removed automatically.
+ * @param bundleName Indicates the bundle name which the reminder belong to.
*/
- bool CanRemove() const;
+ void SetBundleName(const std::string& bundleName);
- bool CanShow() const;
+ /**
+ * @brief Obtains the user id.
+ *
+ * @return Returns the user id.
+ */
+ int32_t GetUserId() const;
/**
- * @brief Obtains all the information of the reminder.
+ * @brief Sets reminder userId when publish reminder success.
*
- * @return Information of the reminder.
+ * When package remove, user id is sended by wantAgent, but we cannot get the uid according user id as the
+ * package has been removed, and the bundleOption can not be create with correct uid. so we need to record
+ * the user id, and use it to judge which user the reminder belong to.
+ *
+ * @param userId Indicates the userId which the reminder belong to.
*/
- std::string Dump() const;
+ void SetUserId(const int32_t userId);
/**
- * @brief Obtains the configured action buttons.
+ * @brief Obtains the uid.
*
- * @return map of action buttons.
+ * @return Returns the uid.
*/
- std::map GetActionButtons() const;
+ int32_t GetUid() const;
/**
- * @brief Obtains creator bundle name
+ * @brief Sets reminder uid when publish reminder success.
*
- * @return creator bundle name
+ * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be
+ * ready. So we need to record the uid in order to create correct bundleOption.
+ *
+ * @param uid Indicates the uid which the reminder belong to.
*/
- std::string GetCreatorBundleName() const;
+ void SetUid(const int32_t uid);
/**
- * @brief Obtains creator uid
+ * @brief Check the reminder creator is a system application.
*
- * @return creator uid
+ * @return Returns true if this reminder creator is a system application; returns false otherwise.
*/
- int32_t GetCreatorUid() const;
+ bool IsSystemApp() const;
/**
- * @brief Obtains the configured content.
+ * @brief Set the reminder creator is a system app.
*
- * @return content text.
+ * @param isSystem is a system app.
*/
- std::string GetContent() const;
+ void SetSystemApp(const bool isSystem);
/**
- * @brief Obtains the configured expired content.
+ * @brief Obtains the reminder type.
*
- * @return expired content text.
+ * @return Returns the reminder type.
*/
- std::string GetExpiredContent() const;
+ ReminderType GetReminderType() const;
- std::shared_ptr GetMaxScreenWantAgentInfo() const;
+ /**
+ * @brief Obtains the reminder time in milli.
+ *
+ * @return Returns the reminder time in milli.
+ */
+ uint64_t GetReminderTimeInMilli() const;
/**
- * @brief Obtains notification id.
+ * @brief Set the reminder time in milli.
*
- * @return notification id.
+ * @param reminderTimeInMilli Indicates the reminder time in milli.
*/
- int32_t GetNotificationId() const;
+ void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli);
/**
- * @brief Obtains group id.
+ * @brief Obtains the trigger time in milli.
*
- * @return group id.
+ * @return Returns the trigger time in milli.
*/
- std::string GetGroupId() const;
+ uint64_t GetTriggerTimeInMilli() const;
/**
- * @brief Obtains notification request.
+ * @brief Sets the trigger time in milli..
*
- * @return notification request instance.
+ * @param triggerTimeInMilli Indicates the trigger time in milli.
*/
- sptr GetNotificationRequest() const;
+ void SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli);
/**
- * @brief Obtains reminder id.
+ * @brief Obtains the time interval in seconds.
*
- * @return reminder id.
+ * @return Returns the time interval in seconds.
*/
- int32_t GetReminderId() const;
+ uint64_t GetTimeInterval() const;
- uint64_t GetReminderTimeInMilli() const;
+ /**
+ * @brief Sets the Time Interval for this reminder, in seconds. The default value is 0.
+ *
+ * @note The minimum snooze interval is 5 minute. If the snooze interval is set to a value greater
+ * than 0 and less than 5 minutes, the system converts it to 5 minutes by default.
+ *
+ * This method does not take effect on the reminders for countdown timers.
+ *
+ * @param timeIntervalInSeconds Indicates the snooze interval to set. If the value is less or equals to 0,
+ * the reminder will not be snoozed.
+ */
+ void SetTimeInterval(const uint64_t timeIntervalInSeconds);
/**
- * @brief Obtains reminder type.
+ * @brief Obtains the snooze times.
*
- * @return reminder type.
+ * @return Returns the snooze times.
*/
- ReminderType GetReminderType() const;
+ uint8_t GetSnoozeTimes() const;
+
+ /**
+ * @brief Set the number of snooze times for this reminder.
+ *
+ * @note If the value of snoozeTimes is less than or equals to 0, this reminder is a one-shot
+ * reminder and will not be snoozed.
+ *
+ * It the value of snoozeTimes is greater than 0, for example, snoozeTimes=3, this reminder
+ * will be snoozed three times after the first alarm, that is, this reminder will be triggered
+ * for four times.
+ *
+ * This method does not take affect on the reminders for countdown timers.
+ *
+ * @param snoozeTimes Indicates the number of times that the reminder will be snoozed.
+ */
+ void SetSnoozeTimes(const uint8_t snoozeTimes);
+
+ /**
+ * @brief Obtains the snooze times dynamic.
+ *
+ * @return Returns the snooze times dynamic.
+ */
+ uint8_t GetSnoozeTimesDynamic() const;
+
+ /**
+ * @brief Set the number of snooze times dynamic.
+ *
+ * @param snooziTimes Indicates the number of snooze times dynamic.
+ */
+ void SetSnoozeTimesDynamic(const uint8_t snooziTimes);
/**
* @brief Obtains the ringing or vibration duration configured for this reminder.
*
- * @return uint16_t The ringing or vibration duration in seconds.
+ * @return Returns the ringing or vibration duration configured for this reminder.
*/
uint16_t GetRingDuration() const;
/**
- * @brief Obtains slot type.
+ * @brief Sets the ringing or vibration duration for this reminder, in seconds.
*
- * @return slot type.
+ * @param ringDurationInSeconds Indicates the duration. The default is 1 second.
*/
- NotificationConstant::SlotType GetSlotType() const;
+ void SetRingDuration(const uint64_t ringDurationInSeconds);
/**
- * @brief Obtains snoozeSlot type.
+ * @brief Check the reminder is expired or not.
*
- * @return snoozeSlot type.
+ * @return Returns true if the reminder is expired; returns false otherwise.
*/
- NotificationConstant::SlotType GetSnoozeSlotType() const;
+ bool IsExpired() const;
- std::string GetSnoozeContent() const;
- uint8_t GetSnoozeTimes() const;
- uint8_t GetSnoozeTimesDynamic() const;
+ /**
+ * @brief Sets reminder is expired or not.
+ *
+ * @param isExpired Indicates the reminder is expired or not.
+ */
+ void SetExpired(const bool isExpired);
+
+ /**
+ * @brief Obtains the reminder state.
+ *
+ * @return Returns the reminder state.
+ */
uint8_t GetState() const;
/**
- * @brief Obtains the Time Interval in seconds.
+ * @brief Sets reminder state.
*
- * @return uint64_t Time Interval in seconds.
+ * @param state Indicates the reminder state.
*/
- uint64_t GetTimeInterval() const;
+ void SetState(const uint8_t state);
/**
- * @brief Obtains title.
+ * @brief Obtains the custom button uri.
*
- * @return title.
+ * @return Returns the custom button uri.
*/
- std::string GetTitle() const;
+ std::string GetCustomButtonUri() const;
/**
- * @brief Obtains trigger time in milli.
+ * @brief Sets the custom button uri.
*
- * @return trigger time.
+ * @param uri Indicates the custom button uri.
*/
- uint64_t GetTriggerTimeInMilli() const;
+ void SetCustomButtonUri(const std::string& uri);
- int32_t GetUserId() const;
- int32_t GetUid() const;
+ /**
+ * @brief Obtains the notification slot type.
+ *
+ * @return Returns the notification slot type.
+ */
+ NotificationConstant::SlotType GetSlotType() const;
/**
- * @brief Obtains bundle name
+ * @brief Sets the notification slot type.
*
- * @return bundle name
+ * @param slotType Indicates the notification slot type.
*/
- std::string GetBundleName() const;
+ void SetSlotType(const NotificationConstant::SlotType slotType);
/**
- * @brief Set the app system.
+ * @brief Obtains the notification snoozeSlot type.
*
+ * @return Returns the notification snoozeSlot type.
*/
- void SetSystemApp(bool isSystem);
+ NotificationConstant::SlotType GetSnoozeSlotType() const;
/**
- * @brief Check the app is system or not.
+ * @brief Sets the notification snoozeSlot type.
*
- * @return true is the app is system.
+ * @param snoozeSlotType Indicates the notification snoozeSlot type.
*/
- bool IsSystemApp() const;
+ void SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType);
/**
- * @brief Obtains want agent information.
+ * @brief Obtains the notification id.
*
- * @return want agent information.
+ * @return Returns the notification id.
*/
- std::shared_ptr GetWantAgentInfo() const;
+ int32_t GetNotificationId() const;
/**
- * @brief Inites reminder creator bundle name when publish reminder success.
+ * @brief Sets the notification id.
*
- * @param creatorBundleName Indicates the creator bundle name which the reminder belong to
+ * @param notificationId Indicates the notification id.
*/
- void InitCreatorBundleName(const std::string &creatorBundleName);
+ void SetNotificationId(int32_t notificationId);
/**
- * @brief Inites reminder creator uid when publish reminder success.
+ * @brief Obtains the reminder title.
*
- * @param uid Indicates the creator uid which the reminder belong to
+ * @return Returns the reminder title.
*/
- void InitCreatorUid(const int32_t creatorUid);
+ std::string GetTitle() const;
/**
- * @brief Inits reminder id when publish reminder success.
- * Assign a unique reminder id for each reminder.
+ * @brief Sets the reminder title.
+ *
+ * @param title Indicates the reminder title.
*/
- void InitReminderId();
+ void SetTitle(const std::string& title);
/**
- * @brief Inits reminder userId when publish reminder success.
+ * @brief Obtains the configured content.
*
- * When package remove, user id is sended by wantAgent, but we cannot get the uid according user id as the
- * package has been removed, and the bundleOption can not be create with correct uid. so we need to record
- * the user id, and use it to judge which user the reminder belong to.
+ * @return Returns the configured content.
+ */
+ std::string GetContent() const;
+
+ /**
+ * @brief Sets the reminder content.
*
- * @param userId Indicates the userId which the reminder belong to.
+ * @param content Indicates the content text.
*/
- void InitUserId(const int32_t &userId);
+ void SetContent(const std::string& content);
/**
- * @brief Inites reminder uid when publish reminder success.
+ * @brief Obtains the configured snooze content.
*
- * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be
- * ready. So we need to record the uid in order to create correct bundleOption.
+ * @return Returns the configured snooze content.
+ */
+ std::string GetSnoozeContent() const;
+
+ /**
+ * @brief Sets the reminder snooze content.
*
- * @param uid Indicates the uid which the reminder belong to.
+ * @param snoozeContent Indicates the reminder snooze content.
*/
- void InitUid(const int32_t &uid);
+ void SetSnoozeContent(const std::string& snoozeContent);
/**
- * @brief Inites reminder bundle name when publish reminder success.
+ * @brief Obtains the configured expired content.
*
- * @param bundleName Indicates the bundle name which the reminder belong to
+ * @return Returns the configured expired content.
*/
- void InitBundleName(const std::string &bundleName);
+ std::string GetExpiredContent() const;
/**
- * @brief Check the reminder is alerting or not.
+ * @brief Sets the reminder expired content.
*
- * @return true if the reminder is playing sound or vibrating.
+ * @param expiredContent Indicates the reminder expired content.
*/
- bool IsAlerting() const;
+ void SetExpiredContent(const std::string& expiredContent);
/**
- * @brief Check the reminder is expired or not.
+ * @brief Checks whether the reminder will be automatically dismissed after being tapped.
*
- * @return true is the reminder is expired.
+ * @return Returns true if the reminder will be automatically dismissed; returns false otherwise.
*/
- bool IsExpired() const;
+ bool IsTapDismissed() const;
/**
- * @brief Check the reminder is showing on the panel.
+ * @brief Sets whether to automatically dismiss a reminder after being tapped.
*
- * @return true if the reminder is showing on the panel.
+ * @param isDismissed Specifies whether a reminder will be automatically dismissed after being tapped.
*/
- bool IsShowing() const;
+ void SetTapDismissed(const bool tapDismissed);
/**
- * @brief Closes the reminder by manual.
+ * @brief Obtains the period during which a reminder is deleted.
*
- * 1) Resets the state of "Alering/Showing/Snooze"
- * 2) Resets snoozeTimesDynamic_ if update to next trigger time, otherwise set reminder to expired.
+ * @return Returns the period in milliseconds.
+ */
+ int64_t GetAutoDeletedTime() const;
+
+ /**
+ * @brief Sets the time to delete a reminder.
*
- * @param updateNext Whether to update to next reminder.
+ * @param autoDeletedTime Indicates the time in milliseconds.
+ * The default value is 0, indicating that the reminder will not be automatically deleted.
*/
- void OnClose(bool updateNext);
+ void SetAutoDeletedTime(const int64_t autoDeletedTime);
/**
- * @brief When date/time change, reminder need to refresh next trigger time.
+ * @brief Obtains the reminder group id.
*
- * @return true if need to show reminder immediately.
+ * @return Returns the reminder group id.
*/
- virtual bool OnDateTimeChange();
+ std::string GetGroupId() const;
/**
- * When shown notification is covered by a new notification with the same id, we should remove
- * the state of showing, so that the reminder can be removed automatically when it is expired.
+ * @brief Sets the group id.
+ *
+ * @param groupId Indicates the group id.
*/
- void OnSameNotificationIdCovered();
+ void SetGroupId(const std::string& groupId);
/**
- * Set the reminder state is InActive, so that it will be removed when expired
+ * @brief Obtains the custom ring uri.
+ *
+ * @return Returns the custom ring uri.
*/
- void SetStateToInActive();
+ std::string GetCustomRingUri() const;
+
+ /**
+ * @brief Sets the custom ring uri.
+ *
+ * @param uri Indicates the custom ring uri.
+ */
+ void SetCustomRingUri(const std::string &uri);
/**
- * @brief Shows the reminder on panel. TriggerTime will be updated to next.
+ * @brief Obtains the reminder bundle name of the reminder creator.
*
- * @param isPlaySoundOrVibration true means it is play sound or vibration.
- * @param isSysTimeChanged true means it is called when the system time is changed by user, otherwise false.
- * @param allowToNotify true means that the notification will be shown as normal, otherwise false.
+ * @return Returns the reminder bundle name of the reminder creator.
*/
- void OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify);
+ std::string GetCreatorBundleName() const;
/**
- * @brief Reset the state of "Showing" when the reminder is shown failed.
+ * @brief Sets the reminder bundle name of the reminder creator.
+ *
+ * @param creatorBundleName Indicates the reminder bundle name of the reminder creator.
*/
- void OnShowFail();
+ void SetCreatorBundleName(const std::string& creatorBundleName);
/**
- * @brief Snooze the reminder by manual.
+ * @brief Obtains the reminder uid of the reminder creator.
*
- * 1) Updates the trigger time to the next one.
- * 2) Updates the notification content for "Snooze".
- * 3) Switches the state from "Showing[, Alerting]" to "Snooze".
+ * @return Returns the reminder uid of the reminder creator.
*/
- bool OnSnooze();
+ int32_t GetCreatorUid() const;
/**
- * @brief Starts the reminder
+ * @brief Sets the reminder uid of the reminder creator.
*
- * Sets the state from "Inactive" to "Active".
+ * @param uid Indicates the reminder uid of the reminder creator.
*/
- void OnStart();
+ void SetCreatorUid(const int32_t creatorUid);
/**
- * @brief Stops the reminder.
+ * @brief Obtains the repeat days of week.
*
- * Sets the state from "Active" to "Inactive".
+ * @return Returns the repeat days of week.
*/
- void OnStop();
+ uint8_t GetRepeatDaysOfWeek() const;
/**
- * @brief Terminate the alerting reminder, which is executed when the ring duration is over.
+ * @brief Sets the repeat days of week.
*
- * 1) Disables the state of "Alerting".
- * 2) Updates the notification content for "Alert".
+ * @param repeatDaysOfWeek Indicates the repeat days of week.
+ */
+ void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek);
+
+public:
+ /**
+ * @brief Obtains the want agent information.
*
- * @return false if alerting state has already been set false before calling the method.
+ * @return Returns the want agent information.
*/
- bool OnTerminate();
+ std::shared_ptr GetWantAgentInfo() const;
/**
- * @brief When timezone change, reminder need to refresh next trigger time.
+ * @brief Sets the want agent information.
*
- * @return true if need to show reminder immediately.
+ * @param wantAgentInfo Indicates the want agent information.
*/
- virtual bool OnTimeZoneChange();
+ void SetWantAgentInfo(const std::shared_ptr &wantAgentInfo);
- void RecoverBasicFromOldVersion(const std::shared_ptr& resultSet);
- virtual void RecoverFromOldVersion(const std::shared_ptr& resultSet);
+ /**
+ * @brief Obtains the max want agent information.
+ *
+ * @return Returns the max want agent information.
+ */
+ std::shared_ptr GetMaxScreenWantAgentInfo() const;
/**
- * @brief Recovery reminder instance from database record.
+ * @brief Sets the max want agent information.
*
- * @param resultSet Indicates the resultSet with pointer to the row of record data.
+ * @param maxScreenWantAgentInfo Indicates the max want agent information.
*/
- void RecoverFromDbBase(const std::shared_ptr& resultSet);
- virtual void RecoverFromDb(const std::shared_ptr& resultSet) {};
+ void SetMaxScreenWantAgentInfo(const std::shared_ptr &maxScreenWantAgentInfo);
/**
- * @brief Sets action button.
+ * @brief Obtains notification request.
*
- * @param title Indicates the title of the button.
- * @param type Indicates the type of the button.
- * @param resource Indicates the resource of the button.
- * @return Current reminder self.
+ * @return notification request instance.
*/
- ReminderRequest& SetActionButton(const std::string &title, const ActionButtonType &type,
- const std::string &resource, const std::shared_ptr &buttonWantAgent = nullptr,
- const std::shared_ptr &buttonDataShareUpdate = nullptr);
+ sptr GetNotificationRequest() const;
+public:
/**
- * @brief Sets reminder content.
+ * @brief Obtains the reminder button info as string to rdb.
*
- * @param content Indicates content text.
- * @return Current reminder self.
+ * @return Returns the reminder bundle name of the notification owner
*/
- ReminderRequest& SetContent(const std::string &content);
+ std::string SerializeButtonInfo() const;
/**
- * @brief Sets reminder is expired or not.
+ * @brief Sets reminder button info from rdb(string).
+ */
+ void DeserializeButtonInfo(const std::string& buttonInfo);
+
+ /**
+ * @brief Obtains the reminder want agent info as string to rdb.
*
- * @param isExpired Indicates the reminder is expired or not.
+ * @return Returns the reminder bundle name of the notification owner
+ */
+ std::string SerializeWantAgent() const;
+
+ /**
+ * @brief Sets reminder want agent info from rdb(string).
*/
- void SetExpired(bool isExpired);
+ void DeserializeWantAgent(const std::string& wantInfo);
/**
- * @brief Sets expired content.
+ * @brief Obtains the reminder max want agent info as string to rdb.
*
- * @param expiredContent Indicates expired content.
- * @return Current reminder self.
+ * @return Returns the reminder bundle name of the notification owner
*/
- ReminderRequest& SetExpiredContent(const std::string &expiredContent);
+ std::string SerializeMaxWantAgent() const;
+
+ /**
+ * @brief Sets reminder max want agent info from rdb(string).
+ */
+ void DeserializeMaxWantAgent(const std::string& maxWantInfo);
+
+
+
+
+
+
+
- ReminderRequest& SetMaxScreenWantAgentInfo(const std::shared_ptr &maxScreenWantAgentInfo);
/**
- * @brief Sets notification id.
+ * @brief Marshal a NotificationRequest object into a Parcel.
*
- * @param notificationId Indicates notification id.
- * @return Current reminder self.
+ * @param parcel the object into the parcel
*/
- ReminderRequest& SetNotificationId(int32_t notificationId);
+ virtual bool Marshalling(Parcel &parcel) const override;
/**
- * @brief Sets group id.
+ * @brief Unmarshal object from a Parcel.
*
- * @param notificationId Indicates group id.
- * @return Current reminder self.
+ * @return the NotificationRequest
*/
- ReminderRequest& SetGroupId(const std::string &groupId);
+ static ReminderRequest *Unmarshalling(Parcel &parcel);
+ virtual bool ReadFromParcel(Parcel &parcel);
/**
- * @brief Sets reminder id.
+ * @brief If the reminder is showing on the notification panel, it should not be removed automatically.
*
- * @param reminderId Indicates reminder id.
+ * @return true if it can be removed automatically.
*/
- void SetReminderId(int32_t reminderId);
+ bool CanRemove() const;
- void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli);
+ bool CanShow() const;
/**
- * @brief Sets the ringing or vibration duration for this reminder, in seconds.
+ * @brief Obtains all the information of the reminder.
*
- * @param ringDurationInSeconds Indicates the duration. The default is 1 second.
- * @return Current reminder self.
+ * @return Information of the reminder.
*/
- ReminderRequest& SetRingDuration(const uint64_t ringDurationInSeconds);
+ std::string Dump() const;
/**
- * @brief Sets slot type.
+ * @brief Obtains the configured action buttons.
*
- * @param slotType Indicates slot type.
- * @return Current reminder self.
+ * @return map of action buttons.
*/
- ReminderRequest& SetSlotType(const NotificationConstant::SlotType &slotType);
- ReminderRequest& SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType);
- ReminderRequest& SetSnoozeContent(const std::string &snoozeContent);
+ std::map GetActionButtons() const;
/**
- * @brief Set the number of snooze times for this reminder.
+ * @brief Inits reminder id when publish reminder success.
+ * Assign a unique reminder id for each reminder.
+ */
+ void InitReminderId();
+
+ /**
+ * @brief Check the reminder is alerting or not.
*
- * @note If the value of snoozeTimes is less than or equals to 0, this reminder is a one-shot
- * reminder and will not be snoozed.
+ * @return true if the reminder is playing sound or vibrating.
+ */
+ bool IsAlerting() const;
+
+ /**
+ * @brief Check the reminder is showing on the panel.
*
- * It the value of snoozeTimes is greater than 0, for example, snoozeTimes=3, this reminder
- * will be snoozed three times after the first alarm, that is, this reminder will be triggered
- * for four times.
+ * @return true if the reminder is showing on the panel.
+ */
+ bool IsShowing() const;
+
+ /**
+ * @brief Closes the reminder by manual.
*
- * This method does not take affect on the reminders for countdown timers.
+ * 1) Resets the state of "Alering/Showing/Snooze"
+ * 2) Resets snoozeTimesDynamic_ if update to next trigger time, otherwise set reminder to expired.
*
- * @param snoozeTimes Indicates the number of times that the reminder will be snoozed.
- * @return ReminderRequest& Current reminder self.
+ * @param updateNext Whether to update to next reminder.
*/
- ReminderRequest& SetSnoozeTimes(const uint8_t snoozeTimes);
+ void OnClose(bool updateNext);
- ReminderRequest& SetSnoozeTimesDynamic(const uint8_t snooziTimes);
+ /**
+ * @brief When date/time change, reminder need to refresh next trigger time.
+ *
+ * @return true if need to show reminder immediately.
+ */
+ virtual bool OnDateTimeChange();
/**
- * @brief Sets the Time Interval for this reminder, in seconds. The default value is 0.
+ * When shown notification is covered by a new notification with the same id, we should remove
+ * the state of showing, so that the reminder can be removed automatically when it is expired.
+ */
+ void OnSameNotificationIdCovered();
+
+ /**
+ * Set the reminder state is InActive, so that it will be removed when expired
+ */
+ void SetStateToInActive();
+
+ /**
+ * @brief Shows the reminder on panel. TriggerTime will be updated to next.
*
- * @note The minimum snooze interval is 5 minute. If the snooze interval is set to a value greater
- * than 0 and less than 5 minutes, the system converts it to 5 minutes by default.
+ * @param isPlaySoundOrVibration true means it is play sound or vibration.
+ * @param isSysTimeChanged true means it is called when the system time is changed by user, otherwise false.
+ * @param allowToNotify true means that the notification will be shown as normal, otherwise false.
+ */
+ void OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify);
+
+ /**
+ * @brief Reset the state of "Showing" when the reminder is shown failed.
+ */
+ void OnShowFail();
+
+ /**
+ * @brief Snooze the reminder by manual.
*
- * This method does not take effect on the reminders for countdown timers.
+ * 1) Updates the trigger time to the next one.
+ * 2) Updates the notification content for "Snooze".
+ * 3) Switches the state from "Showing[, Alerting]" to "Snooze".
+ */
+ bool OnSnooze();
+
+ /**
+ * @brief Starts the reminder
*
- * @param timeIntervalInSeconds Indicates the snooze interval to set. If the value is less or equals to 0,
- * the reminder will not be snoozed.
- * @return ReminderRequest& Current reminder self.
+ * Sets the state from "Inactive" to "Active".
*/
- ReminderRequest& SetTimeInterval(const uint64_t timeIntervalInSeconds);
+ void OnStart();
/**
- * @brief Sets title.
+ * @brief Stops the reminder.
*
- * @param title Indicates title.
- * @return Current reminder self.
+ * Sets the state from "Active" to "Inactive".
*/
- ReminderRequest& SetTitle(const std::string &title);
+ void OnStop();
/**
- * @brief Sets trigger time.
+ * @brief Terminate the alerting reminder, which is executed when the ring duration is over.
+ *
+ * 1) Disables the state of "Alerting".
+ * 2) Updates the notification content for "Alert".
*
- * @param triggerTimeInMilli Indicates trigger time in milli.
+ * @return false if alerting state has already been set false before calling the method.
*/
- void SetTriggerTimeInMilli(uint64_t triggerTimeInMilli);
+ bool OnTerminate();
/**
- * @brief Sets want agent information.
+ * @brief When timezone change, reminder need to refresh next trigger time.
*
- * @param wantAgentInfo Indicates want agent information.
+ * @return true if need to show reminder immediately.
+ */
+ virtual bool OnTimeZoneChange();
+
+ void RecoverBasicFromOldVersion(const std::shared_ptr& resultSet);
+ virtual void RecoverFromOldVersion(const std::shared_ptr& resultSet);
+
+ /**
+ * @brief Recovery reminder instance from database record.
+ *
+ * @param resultSet Indicates the resultSet with pointer to the row of record data.
+ */
+ void RecoverFromDbBase(const std::shared_ptr& resultSet);
+ virtual void RecoverFromDb(const std::shared_ptr& resultSet) {};
+
+ /**
+ * @brief Sets action button.
+ *
+ * @param title Indicates the title of the button.
+ * @param type Indicates the type of the button.
+ * @param resource Indicates the resource of the button.
* @return Current reminder self.
*/
- ReminderRequest& SetWantAgentInfo(const std::shared_ptr &wantAgentInfo);
+ ReminderRequest& SetActionButton(const std::string &title, const ActionButtonType &type,
+ const std::string &resource, const std::shared_ptr &buttonWantAgent = nullptr,
+ const std::shared_ptr &buttonDataShareUpdate = nullptr);
bool ShouldShowImmediately() const;
@@ -804,62 +992,6 @@ public:
std::string GetWantAgentStr();
std::string GetMaxWantAgentStr();
- /**
- * @brief Sets tapDismissed.
- *
- * @param tapDismissed Indicates tapDismissed.
- */
- void SetTapDismissed(bool tapDismissed);
-
- /**
- * @brief Gets tapDismissed.
- *
- * @return True if tapDismissed.
- */
- bool IsTapDismissed() const;
-
- /**
- * @brief Sets autoDeletedTime.
- *
- * @param autoDeletedTime Indicates autoDeletedTime.
- */
- void SetAutoDeletedTime(int64_t autoDeletedTime);
-
- /**
- * @brief Gets autoDeletedTime.
- *
- * @return AutoDeletedTime.
- */
- int64_t GetAutoDeletedTime() const;
-
- /**
- * @brief Sets custom button uri.
- *
- * @param uri Indicates uri.
- */
- void SetCustomButtonUri(const std::string &uri);
-
- /**
- * @brief Gets custom button uri.
- *
- * @return custom button uri.
- */
- std::string GetCustomButtonUri() const;
-
- /**
- * @brief Gets custom ring uri.
- *
- * @return custom ring uri.
- */
- std::string GetCustomRingUri() const;
-
- /**
- * @brief Sets custom ring uri.
- *
- * @param uri Indicates uri.
- */
- void SetCustomRingUri(const std::string &uri);
-
/**
* @brief Update notification attributes.
*
@@ -897,19 +1029,24 @@ public:
bool oldVersion = false);
static std::vector StringSplit(std::string source, const std::string &split);
- static int32_t GLOBAL_ID;
- static const uint64_t INVALID_LONG_LONG_VALUE;
- static const uint16_t INVALID_U16_VALUE;
- static const uint8_t INVALID_U8_VALUE;
- static const uint16_t MILLI_SECONDS;
- static const uint16_t SAME_TIME_DISTINGUISH_MILLISECONDS;
+public:
+ static constexpr uint64_t INVALID_LONG_LONG_VALUE = 0;
+ static constexpr uint16_t MILLI_SECONDS = 1000;
+ static constexpr uint16_t SAME_TIME_DISTINGUISH_MILLISECONDS = 1000;
static const std::string NOTIFICATION_LABEL;
- static const uint8_t MONDAY;
- static const uint8_t SUNDAY;
- static const uint8_t DAYS_PER_WEEK;
- static const uint8_t HOURS_PER_DAY;
- static const uint16_t SECONDS_PER_HOUR;
- static const uint8_t MINUTES_PER_HOUR;
+
+protected:
+ static constexpr uint16_t SECONDS_PER_HOUR = 3600;
+ static constexpr uint8_t HOURS_PER_DAY = 24;
+ static constexpr uint8_t MINUTES_PER_HOUR = 60;
+
+private:
+ static constexpr uint8_t MONDAY = 1;
+ static constexpr uint8_t SUNDAY = 7;
+ static constexpr uint8_t DAYS_PER_WEEK = 7;
+
+public:
+ static int32_t GLOBAL_ID;
/**
* @brief Show the reminder with a notification.
*/
@@ -993,7 +1130,6 @@ protected:
*/
int64_t GetNextDaysOfWeek(const time_t now, const time_t target) const;
void SetRepeatDaysOfWeek(bool set, const std::vector &daysOfWeek);
- uint8_t GetRepeatDaysOfWeek() const;
time_t GetTriggerTimeWithDST(const time_t now, const time_t nextTriggerTime) const;
uint64_t GetTriggerTime(const time_t now, const time_t nextTriggerTime) const;
uint64_t GetNowInstantMilli() const;
diff --git a/interfaces/inner_api/reminder_request_alarm.h b/interfaces/inner_api/reminder_request_alarm.h
index d82f093a39a5024e33fc984115f208a692c304eb..29db4f0894168f24ab6f9480e8f135cfb0ce25d8 100644
--- a/interfaces/inner_api/reminder_request_alarm.h
+++ b/interfaces/inner_api/reminder_request_alarm.h
@@ -121,7 +121,6 @@ private:
uint64_t GetNextTriggerTime(bool forceToGetNext) const;
bool IsRepeatReminder() const;
- static const uint8_t MINUTES_PER_HOUR;
static const int8_t DEFAULT_SNOOZE_TIMES;
uint8_t hour_ = {0};
diff --git a/interfaces/inner_api/reminder_request_calendar.h b/interfaces/inner_api/reminder_request_calendar.h
index f6f2add7353f077c9c5f79e99a33632d523a2bda..01e947aa71188e78c8a2c7f1865b6267a6536f35 100644
--- a/interfaces/inner_api/reminder_request_calendar.h
+++ b/interfaces/inner_api/reminder_request_calendar.h
@@ -274,6 +274,7 @@ private:
static constexpr uint16_t SOLAR_YEAR = 400;
static constexpr uint8_t LEAP_PARAM_MIN = 4;
static constexpr uint8_t LEAP_PARAM_MAX = 100;
+ static constexpr uint8_t INVALID_U8_VALUE = 0;
};
}
}
diff --git a/interfaces/inner_api/reminder_store.h b/services/ans/include/reminder_store.h
similarity index 63%
rename from interfaces/inner_api/reminder_store.h
rename to services/ans/include/reminder_store.h
index ac81e8e25d1b448cec5f4f4d8a590378338f4eb1..1926a8efaf2446cddb1aa3ca9cbdd00f6b99dfec 100644
--- a/interfaces/inner_api/reminder_store.h
+++ b/services/ans/include/reminder_store.h
@@ -17,13 +17,12 @@
#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H
#include
+#include
-#include "notification_bundle_option.h"
#include "reminder_request.h"
-#include "rdb_errno.h"
-#include "rdb_helper.h"
+#include "reminder_store_strategy.h"
+#include "rdb_store.h"
#include "rdb_open_callback.h"
-#include "rdb_store_config.h"
namespace OHOS {
namespace Notification {
@@ -33,34 +32,54 @@ public:
virtual ~ReminderStore() {};
public:
+ /**
+ * @brief init reminder store
+ */
int32_t Init();
- int32_t Delete(const int32_t reminderId);
+
+ /**
+ * @brief delete reminder from rdb by reminder id
+ * @param reminderId Indicates delete reminder id
+ * @param type Indicates delete reminder type
+ */
+ int32_t Delete(const int32_t reminderId, const ReminderRequest::ReminderType type);
+
+ /**
+ * @brief delete reminder from rdb by bundleName, userId, uid
+ * @param pkg Indicates bundle name
+ * @param userId Indicates userId
+ * @param uid Indicates uid
+ */
int32_t Delete(const std::string& pkg, const int32_t userId, const int32_t uid);
+
+ /**
+ * @brief delete reminder from rdb by userId
+ * @param userId Indicates userId
+ */
int32_t DeleteUser(const int32_t userId);
- int32_t UpdateOrInsert(const sptr& reminder, const sptr& bundleOption);
+
+ /**
+ * @brief update or insert reminder to rdb
+ * @param reminder Indicates reminder
+ */
+ int32_t UpdateOrInsert(const sptr& reminder);
+
+ /**
+ * @brief get max reminder id from rdb
+ */
int32_t GetMaxId();
+
+ /**
+ * @brief select all reminder from rdb
+ */
std::vector> GetAllValidReminders();
public:
- static void GetUInt8Val(const std::shared_ptr& resultSet,
- const std::string& name, uint8_t& value);
- static void GetUInt16Val(const std::shared_ptr& resultSet,
- const std::string& name, uint16_t& value);
- static void GetInt32Val(const std::shared_ptr& resultSet,
- const std::string& name, int32_t& value);
- static void GetInt64Val(const std::shared_ptr& resultSet,
- const std::string& name, int64_t& value);
- static void GetUInt64Val(const std::shared_ptr& resultSet,
- const std::string& name, uint64_t& value);
- static void GetStringVal(const std::shared_ptr& resultSet,
- const std::string& name, std::string& value);
-
- static const int32_t STATE_OK;
- static const int32_t STATE_FAIL;
+ static constexpr int32_t STATE_OK = 0;
+ static constexpr int32_t STATE_FAIL = -1;
static const std::string REMINDER_DB_DIR;
static const std::string REMINDER_DB_NAME;
- static const std::string REMINDER_DB_TABLE;
private:
/**
@@ -72,21 +91,19 @@ private:
* @return int32_t result code.
*/
int32_t InitData();
- int32_t DeleteBase(const std::string& deleteCondition);
+
+ int32_t Insert(const sptr& reminder);
+ int32_t Update(const sptr& reminder);
int32_t Delete(const std::string& baseCondition, const std::string& assoConditon);
- int32_t Insert(const sptr& reminder, const sptr& bundleOption);
- int32_t Update(const sptr& reminder, const sptr& bundleOption);
- bool IsReminderExist(const sptr& reminder);
+ bool IsReminderExist(const int32_t reminderId);
std::vector> GetReminders(const std::string& queryCondition);
sptr BuildReminder(const std::shared_ptr& resultBase);
- std::shared_ptr Query(const std::string& tableName, const std::string& colums,
- const int32_t reminderId);
- std::shared_ptr Query(const std::string& queryCondition) const;
-
private:
- std::shared_ptr rdbStore_ = nullptr;
+ std::shared_ptr rdbStore_{ nullptr };
+ std::shared_ptr baseStrategy_{ nullptr };
+ std::unordered_map> strategys_; // read only, write by Init()
private:
class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback {
diff --git a/services/ans/include/reminder_store_strategy.h b/services/ans/include/reminder_store_strategy.h
new file mode 100644
index 0000000000000000000000000000000000000000..543b664eb1aa2622cf128458cacde3e5a9e2cc0e
--- /dev/null
+++ b/services/ans/include/reminder_store_strategy.h
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H
+#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H
+
+#include
+#include
+
+#include "reminder_request.h"
+#include "rdb_store.h"
+
+namespace OHOS {
+namespace Notification {
+class ReminderStrategy {
+public:
+ template
+ static void GetRdbValue(const std::shared_ptr& resultSet,
+ const std::string& name, T& value);
+
+public:
+ virtual std::shared_ptr Select(std::shared_ptr rdbStore,
+ const int32_t reminderId) = 0;
+ virtual int32_t Insert(std::shared_ptr rdbStore, const sptr& reminder) = 0;
+ virtual int32_t Update(std::shared_ptr rdbStore, const sptr& reminder) = 0;
+ virtual int32_t Delete(std::shared_ptr rdbStore, const std::string& whereClause) = 0;
+
+ virtual sptr GenReminder(std::shared_ptr rdbStore,
+ const std::shared_ptr& resultBaseSet, const int32_t reminderId) = 0;
+ virtual std::string GetTableName() const = 0;
+
+protected:
+ std::shared_ptr Select(std::shared_ptr rdbStore,
+ const std::string& tableName, const std::string& colums, const int32_t reminderId);
+ int32_t Insert(std::shared_ptr rdbStore, const std::string& tableName,
+ const NativeRdb::ValuesBucket& values);
+ int32_t Update(std::shared_ptr rdbStore, const std::string& tableName,
+ const NativeRdb::ValuesBucket& values, const std::string& whereClause);
+ int32_t Delete(std::shared_ptr rdbStore, const std::string& tableName,
+ const std::string& whereClause);
+};
+
+class ReminderBaseStrategy : public ReminderStrategy {
+public:
+ std::shared_ptr Select(std::shared_ptr rdbStore,
+ const int32_t reminderId) override
+ {
+ return nullptr;
+ }
+ int32_t Insert(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Update(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Delete(std::shared_ptr rdbStore, const std::string& whereClause) override;
+
+ sptr GenReminder(std::shared_ptr rdbStore,
+ const std::shared_ptr& resultBaseSet, const int32_t reminderId) override
+ {
+ return nullptr;
+ }
+ std::string GetTableName() const override;
+
+public:
+ static void Recover(sptr& reminder, const std::shared_ptr& resultSet);
+
+private:
+ void GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values);
+
+ static void RecoverBase(sptr& reminder, const std::shared_ptr& resultSet);
+};
+
+class ReminderAlarmStrategy : public ReminderStrategy {
+public:
+ std::shared_ptr Select(std::shared_ptr rdbStore,
+ const int32_t reminderId) override;
+ int32_t Insert(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Update(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Delete(std::shared_ptr rdbStore, const std::string& whereClause) override;
+
+ sptr GenReminder(std::shared_ptr rdbStore,
+ const std::shared_ptr& resultBaseSet, const int32_t reminderId) override;
+ std::string GetTableName() const override;
+
+private:
+ void GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values);
+};
+
+class ReminderCalendarStrategy : public ReminderStrategy {
+public:
+ std::shared_ptr Select(std::shared_ptr rdbStore,
+ const int32_t reminderId) override;
+ int32_t Insert(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Update(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Delete(std::shared_ptr rdbStore, const std::string& whereClause) override;
+
+ sptr GenReminder(std::shared_ptr rdbStore,
+ const std::shared_ptr& resultBaseSet, const int32_t reminderId) override;
+ std::string GetTableName() const override;
+
+private:
+ void GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values);
+};
+
+class ReminderTimerStrategy : public ReminderStrategy {
+public:
+ std::shared_ptr Select(std::shared_ptr rdbStore,
+ const int32_t reminderId) override;
+ int32_t Insert(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Update(std::shared_ptr rdbStore, const sptr& reminder) override;
+ int32_t Delete(std::shared_ptr rdbStore, const std::string& whereClause) override;
+
+ sptr GenReminder(std::shared_ptr rdbStore,
+ const std::shared_ptr& resultBaseSet, const int32_t reminderId) override;
+ std::string GetTableName() const override;
+
+private:
+ void GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values);
+};
+
+template
+void ReminderStrategy::GetRdbValue(const std::shared_ptr& resultSet,
+ const std::string& name, T& value)
+{
+ value = T();
+ int32_t columnIndex = -1;
+ resultSet->GetColumnIndex(name, columnIndex);
+ if (columnIndex == -1) {
+ ANSR_LOGE("the column %{public}s does not exsit.", name.c_str());
+ return;
+ }
+ if constexpr (std::is_same_v) {
+ resultSet->GetString(columnIndex, value);
+ }
+ else if constexpr (std::is_same_v) {
+ resultSet->GetLong(columnIndex, value);
+ }
+ else if constexpr (std::is_same_v) {
+ int64_t t = 0;
+ resultSet->GetLong(columnIndex, t);
+ value = static_cast