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(t); + } + else if constexpr (std::is_same_v) { + resultSet->GetInt(columnIndex, value); + } + else if constexpr (std::is_same_v) { + int32_t t = 0; + resultSet->GetInt(columnIndex, t); + value = static_cast(t); + } + else if constexpr (std::is_same_v) { + int32_t t = 0; + resultSet->GetInt(columnIndex, t); + value = static_cast(t); + } +} +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H \ No newline at end of file diff --git a/interfaces/inner_api/reminder_table.h b/services/ans/include/reminder_table.h similarity index 100% rename from interfaces/inner_api/reminder_table.h rename to services/ans/include/reminder_table.h diff --git a/interfaces/inner_api/reminder_table_old.h b/services/ans/include/reminder_table_old.h similarity index 100% rename from interfaces/inner_api/reminder_table_old.h rename to services/ans/include/reminder_table_old.h diff --git a/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index ad6cbc098ac410561c8bf5d27160a51319e97b6c..829e0990eff0194db863a81077e004d2d3d29a42 100644 --- a/services/ans/src/advanced_notification_reminder_service.cpp +++ b/services/ans/src/advanced_notification_reminder_service.cpp @@ -67,8 +67,8 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi ANSR_LOGD("is system app: %{public}d", AccessTokenHelper::IsSystemApp()); reminder->SetSystemApp(AccessTokenHelper::IsSystemApp()); sptr notificationRequest = reminder->GetNotificationRequest(); - reminder->InitCreatorBundleName(bundle); - reminder->InitCreatorUid(IPCSkeleton::GetCallingUid()); + reminder->SetCreatorBundleName(bundle); + reminder->SetCreatorUid(IPCSkeleton::GetCallingUid()); if (reminder->GetWantAgentInfo() == nullptr || reminder->GetMaxScreenWantAgentInfo() == nullptr) { ANSR_LOGE("wantagent info is nullptr"); return ERR_ANS_INVALID_PARAM; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 29606043eda613e2566fc5640a0144d3819a7c1e..2b0d44afd531254f641101a3308b67e9a9e49a52 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -178,7 +178,7 @@ ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const uint std::lock_guard locker(ReminderDataManager::MUTEX); ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); calendar->AddExcludeDate(date); - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } return ERR_OK; } @@ -195,7 +195,7 @@ ErrCode ReminderDataManager::DelExcludeDates(const int32_t reminderId, std::lock_guard locker(ReminderDataManager::MUTEX); ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); calendar->DelExcludeDates(); - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } return ERR_OK; } @@ -428,7 +428,7 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrUpdateOrInsert((*it), bundleOption); + store_->UpdateOrInsert((*it)); } } @@ -621,7 +621,7 @@ void ReminderDataManager::CloseRemindersByGroupId(const int32_t &oldReminderId, if (IsMatchedForGroupIdAndPkgName(reminder, packageName, groupId)) { reminder->SetExpired(true); reminder->SetStateToInActive(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); ResetStates(TimerType::TRIGGER_TIMER); ANSR_LOGD("Cancel reminders by groupid, reminder is %{public}s", reminder->Dump().c_str()); } @@ -642,7 +642,7 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b } reminder->OnClose(true); RemoveFromShowedReminders(reminder); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); if (cancelNotification) { CancelNotification(reminder); } @@ -882,7 +882,7 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde // Set the notification SoundEnabled and VibrationEnabled by soltType advancedNotificationService_->SetRequestBySlotType(notificationRequest, bundleOption); advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); } void ReminderDataManager::UpdateAndSaveReminderLocked( @@ -890,9 +890,9 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( { std::lock_guard lock(ReminderDataManager::MUTEX); reminder->InitReminderId(); - reminder->InitUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); - reminder->InitUid(bundleOption->GetUid()); - reminder->InitBundleName(bundleOption->GetBundleName()); + reminder->SetUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); + reminder->SetUid(bundleOption->GetUid()); + reminder->SetBundleName(bundleOption->GetBundleName()); if (reminder->GetTriggerTimeInMilli() == ReminderRequest::INVALID_LONG_LONG_VALUE) { ANSR_LOGW("now publish reminder is expired. reminder is =%{public}s", @@ -910,7 +910,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( ANSR_LOGD("Containers(vector) add. reminderId=%{public}d", reminderId); reminderVector_.push_back(reminder); totalCount_++; - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } void ReminderDataManager::SetService(sptr &advancedNotificationService) @@ -1107,13 +1107,13 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co if (advancedNotificationService_ == nullptr) { ANSR_LOGE("ShowReminder fail"); reminder->OnShow(false, isSysTimeChanged, false); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return; } if (!IsAllowedNotify(reminder)) { ANSR_LOGE("Not allow to notify."); reminder->OnShow(false, isSysTimeChanged, false); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return; } bool toPlaySound = isNeedToPlaySound && ShouldAlert(reminder) ? true : false; @@ -1142,7 +1142,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } HandleSameNotificationIdShowing(reminder); } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); if (isNeedToStartNext) { StartRecentReminder(); @@ -1197,7 +1197,7 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) StopTimerLocked(TimerType::ALERTING_TIMER); } reminder->OnSnooze(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); // 2) Show the notification dialog in the systemUI sptr bundleOption = FindNotificationBundleOption(reminderId); @@ -1232,13 +1232,13 @@ void ReminderDataManager::StartRecentReminder() } if (activeReminderId_ != -1) { activeReminder_->OnStop(); - store_->UpdateOrInsert(activeReminder_, FindNotificationBundleOption(activeReminderId_)); + store_->UpdateOrInsert(activeReminder_); StopTimerLocked(TimerType::TRIGGER_TIMER); } ANSR_LOGI("Start recent reminder"); StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); reminder->OnStart(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); } void ReminderDataManager::StopAlertingReminder(const sptr &reminder) @@ -1338,7 +1338,7 @@ sptr ReminderDataManager::GetRecentReminderLocked() } it = reminderVector_.erase(it); totalCount_--; - store_->Delete(reminderId); + store_->Delete(reminderId, (*it)->GetReminderType()); } return nullptr; } @@ -1380,10 +1380,10 @@ sptr ReminderDataManager::HandleRefreshReminder(const uint8_t & if (triggerTimeBefore != triggerTimeAfter || reminder->GetReminderId() == alertingReminderId_) { CloseReminder(reminder, true); } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return nullptr; } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + store_->UpdateOrInsert(reminder); return reminder; } @@ -1418,7 +1418,7 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrOnSameNotificationIdCovered(); RemoveFromShowedReminders(*it); - store_->UpdateOrInsert((*it), FindNotificationBundleOption((*it)->GetReminderId())); + store_->UpdateOrInsert((*it)); } } } @@ -1768,7 +1768,7 @@ void ReminderDataManager::RemoveReminderLocked(const int32_t &reminderId) ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); it = reminderVector_.erase(it); totalCount_--; - store_->Delete(reminderId); + store_->Delete(reminderId, (*it)->GetReminderType()); break; } else { ++it; diff --git a/frameworks/ans/src/reminder_store.cpp b/services/ans/src/reminder_store.cpp similarity index 54% rename from frameworks/ans/src/reminder_store.cpp rename to services/ans/src/reminder_store.cpp index 565bcd382fad2791ee5c9ea5591d3d645c46083b..66c98843113691b177659023f4f7c98331102e2b 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/services/ans/src/reminder_store.cpp @@ -39,8 +39,6 @@ const int32_t REMINDER_RDB_VERSION_V5 = 5; const int32_t REMINDER_RDB_VERSION = 6; } -const int32_t ReminderStore::STATE_OK = 0; -const int32_t ReminderStore::STATE_FAIL = -1; const std::string ReminderStore::REMINDER_DB_DIR = "/data/service/el1/public/notification/"; const std::string ReminderStore::REMINDER_DB_NAME = "notification.db"; @@ -262,7 +260,7 @@ void ReminderStore::ReminderStoreDataCallBack::AddRdbColum(NativeRdb::RdbStore& } } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Init() +int32_t ReminderStore::Init() { ANSR_LOGD("Reminder store init."); if (access(REMINDER_DB_DIR.c_str(), F_OK) != 0) { @@ -272,13 +270,22 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Init() return STATE_FAIL; } } - - ReminderTable::InitDbColumns(); + ReminderBaseTable::InitDbColumns(); ReminderTimerTable::InitDbColumns(); ReminderAlarmTable::InitDbColumns(); ReminderCalendarTable::InitDbColumns(); + baseStrategy_ = std::make_shared(); + + strategys_.clear(); + std::shared_ptr strategy = std::make_shared(); + strategys_.emplace(static_cast(ReminderRequest::ReminderType::ALARM), strategy); + strategy = std::make_shared(); + strategys_.emplace(static_cast(ReminderRequest::ReminderType::CALENDAR), strategy); + strategy = std::make_shared(); + strategys_.emplace(static_cast(ReminderRequest::ReminderType::TIMER), strategy); + std::string dbConfig = REMINDER_DB_DIR + REMINDER_DB_NAME; NativeRdb::RdbStoreConfig config(dbConfig); config.SetSecurityLevel(NativeRdb::SecurityLevel::S1); @@ -293,44 +300,28 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Init() return InitData(); } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const int32_t reminderId) +int32_t ReminderStore::Delete(const int32_t reminderId, const ReminderRequest::ReminderType type) { - if (rdbStore_ == nullptr) { + if (rdbStore_ == nullptr || baseStrategy_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } std::string condition = ReminderBaseTable::REMINDER_ID + " = " + std::to_string(reminderId); rdbStore_->BeginTransaction(); - int32_t delRows = STATE_FAIL; - std::vector whereArgs; - int32_t ret = rdbStore_->Delete(delRows, ReminderBaseTable::TABLE_NAME, condition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderBaseTable::TABLE_NAME.c_str(), reminderId); - rdbStore_->RollBack(); - return STATE_FAIL; - } - delRows = STATE_FAIL; - ret = rdbStore_->Delete(delRows, ReminderAlarmTable::TABLE_NAME, condition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderAlarmTable::TABLE_NAME.c_str(), reminderId); + int32_t ret = baseStrategy_->Delete(rdbStore_, condition); + if (ret != STATE_OK) { rdbStore_->RollBack(); return STATE_FAIL; } - delRows = STATE_FAIL; - ret = rdbStore_->Delete(delRows, ReminderCalendarTable::TABLE_NAME, condition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderCalendarTable::TABLE_NAME.c_str(), reminderId); + auto iter = strategys_.find(static_cast(type)); + if (iter == strategys_.end() || iter->second == nullptr) { + ANSR_LOGE("Not find reminder[%{public}d] strategy.", static_cast(type)); rdbStore_->RollBack(); return STATE_FAIL; } - delRows = STATE_FAIL; - ret = rdbStore_->Delete(delRows, ReminderTimerTable::TABLE_NAME, condition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed, reminderId = %{public}d", - ReminderTimerTable::TABLE_NAME.c_str(), reminderId); + auto strategy = iter->second; + ret = strategy->Delete(rdbStore_, condition); + if (ret != STATE_OK) { rdbStore_->RollBack(); return STATE_FAIL; } @@ -338,8 +329,7 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const int32_t return STATE_OK; } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::string& pkg, const int32_t userId, - const int32_t uid) +int32_t ReminderStore::Delete(const std::string& pkg, const int32_t userId, const int32_t uid) { std::string assoConditon = "(SELECT " + ReminderBaseTable::REMINDER_ID + " FROM " + ReminderBaseTable::TABLE_NAME + " WHERE " + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::PACKAGE_NAME + " = '" + pkg @@ -357,7 +347,7 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::str return Delete(baseCondtion, assoConditon); } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::DeleteUser(const int32_t userId) +int32_t ReminderStore::DeleteUser(const int32_t userId) { std::string assoConditon = "(SELECT " + ReminderBaseTable::REMINDER_ID + " FROM " + ReminderBaseTable::TABLE_NAME + " WHERE " + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::USER_ID + " = " @@ -367,133 +357,64 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::DeleteUser(const int3 return Delete(baseCondtion, assoConditon); } -int32_t ReminderStore::UpdateOrInsert( - const sptr& reminder, const sptr& bundleOption) +int32_t ReminderStore::UpdateOrInsert(const sptr& reminder) { - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); + if (reminder == nullptr) { + ANSR_LOGE("Invalid reminder."); return STATE_FAIL; } - if (bundleOption == nullptr) { - ANSR_LOGE("BundleOption is null."); + if (rdbStore_ == nullptr || baseStrategy_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - if (IsReminderExist(reminder)) { - return Update(reminder, bundleOption); + if (IsReminderExist(reminder->GetReminderId())) { + return Update(reminder); } else { - return Insert(reminder, bundleOption); + return Insert(reminder); } } int32_t ReminderStore::GetMaxId() { - if (rdbStore_ == nullptr) { + if (rdbStore_ == nullptr || baseStrategy_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - std::string queryCondition = "SELECT " + ReminderBaseTable::REMINDER_ID + std::string sql = "SELECT " + ReminderBaseTable::REMINDER_ID + " FROM " + ReminderBaseTable::TABLE_NAME + " ORDER BY " + ReminderBaseTable::REMINDER_ID + " DESC"; - auto queryResultSet = Query(queryCondition); - if (queryResultSet == nullptr) { + auto resultSet = rdbStore_->QuerySql(sql); + if (resultSet == nullptr) { ANSR_LOGE("QueryResultSet is null."); return STATE_FAIL; } int32_t resultNum = 0; - queryResultSet->GetRowCount(resultNum); + resultSet->GetRowCount(resultNum); if (resultNum == 0) { ANSR_LOGI("QueryResultSet is zero."); return STATE_FAIL; } - queryResultSet->GoToNextRow(); + resultSet->GoToNextRow(); int32_t maxId = STATE_FAIL; - int32_t result = queryResultSet->GetInt(0, maxId); - if (result != NativeRdb::E_OK) { - ANSR_LOGE("Query operation failed, result %{public}d.", result); + int32_t ret = resultSet->GetInt(0, maxId); + if (ret != NativeRdb::E_OK) { + ANSR_LOGE("Query operation failed, result %{public}d.", ret); } - ANSR_LOGD("MaxId: %{public}d.", maxId); return maxId; } -__attribute__((no_sanitize("cfi"))) std::vector> ReminderStore::GetAllValidReminders() +std::vector> ReminderStore::GetAllValidReminders() { std::string sql = "SELECT " + ReminderBaseTable::SELECT_COLUMNS + " FROM " + ReminderBaseTable::TABLE_NAME + " WHERE " + ReminderBaseTable::IS_EXPIRED + " = 'false' ORDER BY " + ReminderBaseTable::TRIGGER_TIME + " ASC"; - ANSR_LOGD("GetAllValidReminders sql =%{public}s", sql.c_str()); return GetReminders(sql); } -void ReminderStore::GetUInt8Val(const std::shared_ptr& resultSet, - const std::string& name, uint8_t& value) -{ - int32_t val; - GetInt32Val(resultSet, name, val); - value = static_cast(val); -} - -void ReminderStore::GetUInt16Val(const std::shared_ptr& resultSet, - const std::string& name, uint16_t& value) -{ - int32_t val; - GetInt32Val(resultSet, name, val); - value = static_cast(val); -} - -void ReminderStore::GetInt32Val(const std::shared_ptr& resultSet, - const std::string& name, int32_t& value) -{ - value = 0; - int32_t columnIndex = -1; - resultSet->GetColumnIndex(name, columnIndex); - if (columnIndex == -1) { - ANSR_LOGE("the column %{public}s does not exsit.", name.c_str()); - return; - } - resultSet->GetInt(columnIndex, value); -} - -void ReminderStore::GetInt64Val(const std::shared_ptr& resultSet, - const std::string& name, int64_t& value) -{ - value = 0; - int32_t columnIndex = -1; - resultSet->GetColumnIndex(name, columnIndex); - if (columnIndex == -1) { - ANSR_LOGE("the column %{public}s does not exsit.", name.c_str()); - return; - } - resultSet->GetLong(columnIndex, value); -} - -void ReminderStore::GetUInt64Val(const std::shared_ptr& resultSet, - const std::string& name, uint64_t& value) -{ - int64_t val; - GetInt64Val(resultSet, name, val); - value = static_cast(val); -} - -void ReminderStore::GetStringVal(const std::shared_ptr& resultSet, - const std::string& name, std::string& value) -{ - int32_t columnIndex = -1; - resultSet->GetColumnIndex(name, columnIndex); - if (columnIndex == -1) { - ANSR_LOGE("the column %{public}s does not exsit.", name.c_str()); - return; - } - resultSet->GetString(columnIndex, value); -} - -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::InitData() +int32_t ReminderStore::InitData() { ANSR_LOGD("Reminder data init."); - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return STATE_FAIL; - } // delete all the reminders which IS_EXPIRED is true. std::string deleteCondition = ReminderBaseTable::IS_EXPIRED + " is true"; DeleteBase(deleteCondition); @@ -511,70 +432,32 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::InitData() return STATE_OK; } -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::DeleteBase(const std::string& deleteCondition) -{ - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return STATE_FAIL; - } - int32_t deletedRows = STATE_FAIL; - std::vector whereArgs; - int32_t ret = rdbStore_->Delete(deletedRows, ReminderBaseTable::TABLE_NAME, deleteCondition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete operation failed, deleteConditon: %{public}s," \ - "result: %{public}d.", deleteCondition.c_str(), ret); - } - ANSR_LOGD("Delete operation done, deleteConditon: %{public}s," \ - "deleted rows: %{public}d.", deleteCondition.c_str(), deletedRows); - return deletedRows; -} - -__attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::string& baseCondition, - const std::string& assoConditon) +int32_t ReminderStore::Delete(const std::string& baseCondition, const std::string& assoConditon) { - if (rdbStore_ == nullptr) { + if (rdbStore_ == nullptr || baseStrategy_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } rdbStore_->BeginTransaction(); - // delete reminder_calendar - std::string sql = "DELETE FROM " + ReminderCalendarTable::TABLE_NAME + " WHERE " - + ReminderCalendarTable::TABLE_NAME + "." + ReminderCalendarTable::REMINDER_ID - + " IN " + assoConditon; - int32_t ret = rdbStore_->ExecuteSql(sql); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed", ReminderCalendarTable::TABLE_NAME.c_str()); - rdbStore_->RollBack(); - return STATE_FAIL; - } - - // delete reminder_alarm - sql = "DELETE FROM " + ReminderAlarmTable::TABLE_NAME + " WHERE " - + ReminderAlarmTable::TABLE_NAME + "." + ReminderAlarmTable::REMINDER_ID - + " IN " + assoConditon; - ret = rdbStore_->ExecuteSql(sql); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed", ReminderCalendarTable::TABLE_NAME.c_str()); - rdbStore_->RollBack(); - return STATE_FAIL; - } - - // delete reminder_timer - sql = "DELETE FROM " + ReminderTimerTable::TABLE_NAME + " WHERE " - + ReminderTimerTable::TABLE_NAME + "." + ReminderTimerTable::REMINDER_ID - + " IN " + assoConditon; - ret = rdbStore_->ExecuteSql(sql); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed", ReminderTimerTable::TABLE_NAME.c_str()); - rdbStore_->RollBack(); - return STATE_FAIL; + // delete reminder_* + for (auto& [type, strategy] : strategys_) { + if (strategy == nullptr) { + ANSR_LOGE("Not find reminder[%{public}d] strategy.", static_cast(type)); + rdbStore_->RollBack(); + return STATE_FAIL; + } + std::string condition = strategy->GetTableName() + "." + ReminderBaseTable::REMINDER_ID + + " IN " + assoConditon; + int32_t ret = strategy->Delete(rdbStore_, condition); + if (ret != STATE_OK) { + rdbStore_->RollBack(); + return STATE_FAIL; + } } // delete reminder_base - sql = "DELETE FROM " + ReminderBaseTable::TABLE_NAME + " WHERE " + baseCondition; - ret = rdbStore_->ExecuteSql(sql); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Delete from %{public}s failed", ReminderCalendarTable::TABLE_NAME.c_str()); + int32_t ret = baseStrategy_->Delete(rdbStore_, baseCondition); + if (ret != STATE_OK) { rdbStore_->RollBack(); return STATE_FAIL; } @@ -582,55 +465,26 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::str return STATE_OK; } -int32_t ReminderStore::Insert( - const sptr& reminder, const sptr& bundleOption) +int32_t ReminderStore::Insert(const sptr& reminder) { - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return STATE_FAIL; - } - int64_t rowId = STATE_FAIL; - NativeRdb::ValuesBucket baseValues; - ReminderRequest::AppendValuesBucket(reminder, bundleOption, baseValues); - rdbStore_->BeginTransaction(); // insert reminder_base - int32_t ret = rdbStore_->Insert(rowId, ReminderBaseTable::TABLE_NAME, baseValues); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Insert reminder_base operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + int32_t ret = baseStrategy_->Insert(rdbStore_, reminder); + if (ret != STATE_OK) { rdbStore_->RollBack(); return STATE_FAIL; } - // insert reminder_alarm or reminder_calendar - NativeRdb::ValuesBucket values; - rowId = STATE_FAIL; - switch (reminder->GetReminderType()) { - case ReminderRequest::ReminderType::CALENDAR: { - ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); - ret = rdbStore_->Insert(rowId, ReminderCalendarTable::TABLE_NAME, values); - break; - } - case ReminderRequest::ReminderType::ALARM: { - ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); - ret = rdbStore_->Insert(rowId, ReminderAlarmTable::TABLE_NAME, values); - break; - } - case ReminderRequest::ReminderType::TIMER: { - ReminderRequestTimer::AppendValuesBucket(reminder, bundleOption, values); - ret = rdbStore_->Insert(rowId, ReminderTimerTable::TABLE_NAME, values); - break; - } - default: { - ANSR_LOGE("Insert reminder_base operation failed, unkown type."); - ret = STATE_FAIL; - break; - } + // insert reminder_* + auto iter = strategys_.find(static_cast(reminder->GetReminderType())); + if (iter == strategys_.end() || iter->second == nullptr) { + ANSR_LOGE("Not find reminder[%{public}d] strategy.", static_cast(reminder->GetReminderType())); + rdbStore_->RollBack(); + return STATE_FAIL; } - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Insert operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + auto strategy = iter->second; + ret = strategy->Insert(rdbStore_, reminder); + if (ret != STATE_OK) { rdbStore_->RollBack(); return STATE_FAIL; } @@ -639,55 +493,29 @@ int32_t ReminderStore::Insert( return STATE_OK; } -int32_t ReminderStore::Update( - const sptr& reminder, const sptr& bundleOption) +int32_t ReminderStore::Update(const sptr& reminder) { - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return STATE_FAIL; - } - int32_t rowId = STATE_FAIL; - NativeRdb::ValuesBucket baseValues; - ReminderRequest::AppendValuesBucket(reminder, bundleOption, baseValues); - std::string updateCondition = ReminderBaseTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); rdbStore_->BeginTransaction(); // update reminder_base - std::vector whereArgs; - int32_t ret = rdbStore_->Update(rowId, ReminderBaseTable::TABLE_NAME, baseValues, updateCondition, whereArgs); - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Update reminder_base operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + int32_t ret = baseStrategy_->Update(rdbStore_, reminder); + if (ret != STATE_OK) { rdbStore_->RollBack(); return STATE_FAIL; } - // update reminder_alarm or reminder_calendar - NativeRdb::ValuesBucket values; - rowId = STATE_FAIL; - switch (reminder->GetReminderType()) { - case ReminderRequest::ReminderType::CALENDAR: - ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); - ret = rdbStore_->Update(rowId, ReminderCalendarTable::TABLE_NAME, values, updateCondition, whereArgs); - break; - case ReminderRequest::ReminderType::ALARM: - ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); - ret = rdbStore_->Update(rowId, ReminderAlarmTable::TABLE_NAME, values, updateCondition, whereArgs); - break; - case ReminderRequest::ReminderType::TIMER: - ReminderRequestTimer::AppendValuesBucket(reminder, bundleOption, values); - ret = rdbStore_->Update(rowId, ReminderTimerTable::TABLE_NAME, values, updateCondition, whereArgs); - break; - default: - ANSR_LOGE("Insert reminder_base operation failed, unkown type."); - ret = STATE_FAIL; - break; + // update reminder_* + auto iter = strategys_.find(static_cast(reminder->GetReminderType())); + if (iter == strategys_.end() || iter->second == nullptr) { + ANSR_LOGE("Not find reminder[%{public}d] strategy.", static_cast(reminder->GetReminderType())); + rdbStore_->RollBack(); + return STATE_FAIL; } - if (ret != NativeRdb::E_OK) { - ANSR_LOGE("Update operation failed, result: %{public}d, reminderId=%{public}d.", - ret, reminder->GetReminderId()); + auto strategy = iter->second; + ret = strategy->Update(rdbStore_, reminder); + if (ret != STATE_OK) { rdbStore_->RollBack(); return STATE_FAIL; } @@ -696,40 +524,41 @@ int32_t ReminderStore::Update( return STATE_OK; } -bool ReminderStore::IsReminderExist(const sptr& reminder) +bool ReminderStore::IsReminderExist(const int32_t reminderId) { NativeRdb::AbsRdbPredicates absRdbPredicates(ReminderBaseTable::TABLE_NAME); - absRdbPredicates.EqualTo(ReminderBaseTable::REMINDER_ID, std::to_string(reminder->GetReminderId())); - auto queryResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); - if (queryResultSet == nullptr) { + absRdbPredicates.EqualTo(ReminderBaseTable::REMINDER_ID, std::to_string(reminderId)); + auto resultSet = rdbStore_->Query(absRdbPredicates, std::vector()); + if (resultSet == nullptr) { ANSR_LOGE("QueryResultSet is null."); return false; } int32_t resultNum; - queryResultSet->GetRowCount(resultNum); + resultSet->GetRowCount(resultNum); return resultNum != 0; } -std::vector> ReminderStore::GetReminders(const std::string& queryCondition) +std::vector> ReminderStore::GetReminders(const std::string& condition) { std::vector> reminders; - if (rdbStore_ == nullptr) { + if (rdbStore_ == nullptr || baseStrategy_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); return reminders; } - auto queryResultSet = Query(queryCondition); - if (queryResultSet == nullptr) { + + auto resultSet = rdbStore_->QuerySql(condition); + if (resultSet == nullptr) { return reminders; } bool isAtLastRow = false; - queryResultSet->IsAtLastRow(isAtLastRow); + resultSet->IsAtLastRow(isAtLastRow); while (!isAtLastRow) { - queryResultSet->GoToNextRow(); - sptr reminder = BuildReminder(queryResultSet); + resultSet->GoToNextRow(); + sptr reminder = BuildReminder(resultSet); if (reminder != nullptr) { reminders.push_back(reminder); } - queryResultSet->IsAtLastRow(isAtLastRow); + resultSet->IsAtLastRow(isAtLastRow); } ANSR_LOGD("Size=%{public}zu", reminders.size()); return reminders; @@ -738,73 +567,23 @@ std::vector> ReminderStore::GetReminders(const std::string sptr ReminderStore::BuildReminder(const std::shared_ptr& resultBase) { int32_t reminderId; + ReminderStrategy::GetRdbValue(resultBase, ReminderBaseTable::REMINDER_ID, reminderId); int32_t reminderType; - GetInt32Val(resultBase, ReminderBaseTable::REMINDER_ID, reminderId); - GetInt32Val(resultBase, ReminderBaseTable::REMINDER_TYPE, reminderType); - - sptr reminder = nullptr; - std::shared_ptr resultSet; - switch (reminderType) { - case (static_cast(ReminderRequest::ReminderType::TIMER)): { - reminder = new (std::nothrow) ReminderRequestTimer(reminderId); - resultSet = Query(ReminderTimerTable::TABLE_NAME, ReminderTimerTable::SELECT_COLUMNS, reminderId); - break; - } - case (static_cast(ReminderRequest::ReminderType::CALENDAR)): { - reminder = new (std::nothrow) ReminderRequestCalendar(reminderId); - resultSet = Query(ReminderCalendarTable::TABLE_NAME, ReminderCalendarTable::SELECT_COLUMNS, reminderId); - break; - } - case (static_cast(ReminderRequest::ReminderType::ALARM)): { - reminder = new (std::nothrow) ReminderRequestAlarm(reminderId); - resultSet = Query(ReminderAlarmTable::TABLE_NAME, ReminderAlarmTable::SELECT_COLUMNS, reminderId); - break; - } - default: { - ANSR_LOGE("ReminderType from database is error, reminderType %{public}d.", reminderType); - break; - } + ReminderStrategy::GetRdbValue(resultBase, ReminderBaseTable::REMINDER_TYPE, reminderType); + + auto iter = strategys_.find(reminderType); + if (iter == strategys_.end() || iter->second == nullptr) { + ANSR_LOGE("Not find reminder[%{public}d] strategy.", reminderType); + return nullptr; } + auto strategy = iter->second; + sptr reminder = strategy->GenReminder(rdbStore_, resultBase, reminderId); if (reminder != nullptr) { - reminder->RecoverFromDbBase(resultBase); - reminder->RecoverFromDb(resultSet); ANSR_LOGI("BuildReminder success."); } else { ANSR_LOGW("BuildReminder fail."); } return reminder; } - -std::shared_ptr ReminderStore::Query(const std::string& tableName, const std::string& colums, - const int32_t reminderId) -{ - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return nullptr; - } - std::string queryCondition = "SELECT " + colums + " FROM " + tableName - + " WHERE " + ReminderBaseTable::REMINDER_ID + " = " + std::to_string(reminderId); - auto queryResultSet = Query(queryCondition); - if (queryResultSet == nullptr) { - return nullptr; - } - int32_t resultNum = 0; - queryResultSet->GetRowCount(resultNum); - if (resultNum == 0) { - return nullptr; - } - queryResultSet->GoToNextRow(); - return queryResultSet; -} - -std::shared_ptr ReminderStore::Query(const std::string& queryCondition) const -{ - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return nullptr; - } - std::vector whereArgs; - return rdbStore_->QuerySql(queryCondition, whereArgs); -} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/reminder_store_strategy.cpp b/services/ans/src/reminder_store_strategy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3cc8a0b3e966e8bbf9cf18ddcba5a09cbae89678 --- /dev/null +++ b/services/ans/src/reminder_store_strategy.cpp @@ -0,0 +1,471 @@ +/* + * 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. + */ + +#include "reminder_store_strategy.h" + +#include "ans_log_wrapper.h" +#include "reminder_store.h" +#include "reminder_table.h" +#include "reminder_request_alarm.h" +#include "reminder_request_timer.h" +#include "reminder_request_calendar.h" + +namespace OHOS { +namespace Notification { +std::shared_ptr ReminderStrategy::Select(std::shared_ptr rdbStore, + const std::string& tableName, const std::string& colums, const int32_t reminderId) +{ + std::string condition = "SELECT " + colums + " FROM " + tableName + + " WHERE " + ReminderBaseTable::REMINDER_ID + " = " + std::to_string(reminderId); + auto resultSet = rdbStore->QuerySql(condition); + if (resultSet == nullptr) { + return nullptr; + } + int32_t resultNum = 0; + resultSet->GetRowCount(resultNum); + if (resultNum == 0) { + return nullptr; + } + resultSet->GoToNextRow(); + return resultSet; +} + +inline int32_t ReminderStrategy::Insert(std::shared_ptr rdbStore, + const std::string& tableName, const NativeRdb::ValuesBucket& values) +{ + int64_t rowId = ReminderStore::STATE_FAIL; + int32_t ret = rdbStore->Insert(rowId, tableName, values); + if (ret != NativeRdb::E_OK) { + ANSR_LOGE("Insert into %{public}s failed, error: %{public}d", tableName.c_str(), ret); + return ReminderStore::STATE_FAIL; + } + return ReminderStore::STATE_OK; +} + +inline int32_t ReminderStrategy::Update(std::shared_ptr rdbStore, const std::string& tableName, + const NativeRdb::ValuesBucket& values, const std::string& whereClause) +{ + int32_t rowId = ReminderStore::STATE_FAIL; + int32_t ret = rdbStore->Update(rowId, tableName, values, whereClause); + if (ret != NativeRdb::E_OK) { + ANSR_LOGE("Update %{public}s failed, error: %{public}d", tableName.c_str(), ret); + return ReminderStore::STATE_FAIL; + } + return ReminderStore::STATE_OK; +} + +inline int32_t ReminderStrategy::Delete(std::shared_ptr rdbStore, + const std::string& tableName, const std::string& whereClause) +{ + int32_t rowId = ReminderStore::STATE_FAIL; + int32_t ret = rdbStore->Delete(rowId, tableName, whereClause); + if (ret != NativeRdb::E_OK) { + ANSR_LOGE("Delete from %{public}s failed, error: %{public}d", tableName.c_str(), ret); + return ReminderStore::STATE_FAIL; + } + return ReminderStore::STATE_OK; +} + +int32_t ReminderBaseStrategy::Insert(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + GenValuesBucket(reminder, values); + return ReminderStrategy::Insert(rdbStore, ReminderBaseTable::TABLE_NAME, values); +} + +int32_t ReminderBaseStrategy::Update(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + GenValuesBucket(reminder, values); + std::string condition = ReminderBaseTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); + return ReminderStrategy::Update(rdbStore, ReminderBaseTable::TABLE_NAME, values, condition); +} + +int32_t ReminderBaseStrategy::Delete(std::shared_ptr rdbStore, const std::string& whereClause) +{ + return ReminderStrategy::Delete(rdbStore, ReminderBaseTable::TABLE_NAME, whereClause); +} + +std::string ReminderBaseStrategy::GetTableName() const +{ + return ReminderBaseTable::TABLE_NAME; +} + +void ReminderBaseStrategy::Recover(sptr& reminder, + const std::shared_ptr& resultSet) +{ + RecoverBase(reminder, resultSet); + reminder->InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent + std::string strValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::WANT_AGENT, strValue); + reminder->DeserializeWantAgent(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::MAX_SCREEN_WANT_AGENT, strValue); + reminder->DeserializeMaxWantAgent(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TAP_DISMISSED, strValue); + reminder->SetTapDismissed(strValue == "true"); + + int64_t lValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::AUTO_DELETED_TIME, lValue); + reminder->SetAutoDeletedTime(lValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::GROUP_ID, strValue); + reminder->SetGroupId(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CUSTOM_RING_URI, strValue); + reminder->SetCustomRingUri(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CREATOR_BUNDLE_NAME, strValue); + reminder->SetCreatorBundleName(strValue); + int32_t value; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CREATOR_UID, value); + reminder->SetCreatorUid(value); +} + +void ReminderBaseStrategy::RecoverBase(sptr& reminder, + const std::shared_ptr& resultSet) +{ + int32_t value; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::REMINDER_ID, value); + reminder->SetReminderId(value); + + std::string strValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::PACKAGE_NAME, strValue); + reminder->SetBundleName(strValue); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::USER_ID, value); + reminder->SetUserId(value); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::UID, value); + reminder->SetUid(value); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SYSTEM_APP, strValue); + reminder->SetSystemApp(strValue == "true"); + + uint64_t lValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::REMINDER_TIME, lValue); + reminder->SetReminderTimeInMilli(lValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TRIGGER_TIME, lValue); + reminder->SetTriggerTimeInMilli(lValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TIME_INTERVAL, lValue); + reminder->SetTimeInterval(lValue); + + uint8_t sValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SNOOZE_TIMES, sValue); + reminder->SetSnoozeTimes(sValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::DYNAMIC_SNOOZE_TIMES, sValue); + reminder->SetSnoozeTimesDynamic(sValue); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::RING_DURATION, lValue); + reminder->SetRingDuration(lValue); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::IS_EXPIRED, strValue); + reminder->SetExpired(strValue == "true"); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::STATE, sValue); + reminder->SetState(sValue); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::ACTION_BUTTON_INFO, strValue); + reminder->DeserializeButtonInfo(strValue); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CUSTOM_BUTTON_URI, strValue); + reminder->SetCustomButtonUri(strValue); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SLOT_ID, value); + reminder->SetSlotType(static_cast(value)); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SNOOZE_SLOT_ID, value); + reminder->SetSnoozeSlotType(static_cast(value)); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::NOTIFICATION_ID, value); + reminder->SetNotificationId(value); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::TITLE, strValue); + reminder->SetTitle(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CONTENT, strValue); + reminder->SetContent(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SNOOZE_CONTENT, strValue); + reminder->SetSnoozeContent(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::EXPIRED_CONTENT, strValue); + reminder->SetExpiredContent(strValue); +} + +void ReminderBaseStrategy::GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values) +{ + 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->SerializeButtonInfo()); + 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()); + values.PutString(ReminderBaseTable::WANT_AGENT, reminder->SerializeWantAgent()); + values.PutString(ReminderBaseTable::MAX_SCREEN_WANT_AGENT, reminder->SerializeMaxWantAgent()); + 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()); +} + +std::shared_ptr ReminderAlarmStrategy::Select(std::shared_ptr rdbStore, + const int32_t reminderId) +{ + return ReminderStrategy::Select(rdbStore, ReminderAlarmTable::TABLE_NAME, + ReminderAlarmTable::SELECT_COLUMNS, reminderId); +} + +int32_t ReminderAlarmStrategy::Insert(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + GenValuesBucket(reminder, values); + return ReminderStrategy::Insert(rdbStore, ReminderAlarmTable::TABLE_NAME, values); +} + +int32_t ReminderAlarmStrategy::Update(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + std::string condition = ReminderAlarmTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); + GenValuesBucket(reminder, values); + return ReminderStrategy::Update(rdbStore, ReminderAlarmTable::TABLE_NAME, values, condition); +} + +int32_t ReminderAlarmStrategy::Delete(std::shared_ptr rdbStore, const std::string& whereClause) +{ + return ReminderStrategy::Delete(rdbStore, ReminderAlarmTable::TABLE_NAME, whereClause); +} + +sptr ReminderAlarmStrategy::GenReminder(std::shared_ptr rdbStore, + const std::shared_ptr& resultBaseSet, const int32_t reminderId) +{ + sptr reminder = new (std::nothrow) ReminderRequestAlarm(reminderId); + if (reminder == nullptr) { + return nullptr; + } + auto resultSet = ReminderAlarmStrategy::Select(rdbStore, reminderId); + if (resultSet == nullptr) { + return nullptr; + } + ReminderBaseStrategy::Recover(reminder, resultBaseSet); + + ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); + + uint8_t value; + ReminderStrategy::GetRdbValue(resultSet, ReminderAlarmTable::ALARM_HOUR, value); + alarm->SetHour(value); + ReminderStrategy::GetRdbValue(resultSet, ReminderAlarmTable::ALARM_MINUTE, value); + alarm->SetMinute(value); + ReminderStrategy::GetRdbValue(resultSet, ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, value); + reminder->SetRepeatDaysOfWeek(value); + return reminder; +} + +std::string ReminderAlarmStrategy::GetTableName() const +{ + return ReminderAlarmTable::TABLE_NAME; +} + +void ReminderAlarmStrategy::GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values) +{ + ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); + values.PutInt(ReminderAlarmTable::REMINDER_ID, reminder->GetReminderId()); + values.PutInt(ReminderAlarmTable::ALARM_HOUR, alarm->GetHour()); + values.PutInt(ReminderAlarmTable::ALARM_MINUTE, alarm->GetMinute()); + values.PutInt(ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, alarm->GetRepeatDaysOfWeek()); +} + +std::shared_ptr ReminderCalendarStrategy::Select(std::shared_ptr rdbStore, + const int32_t reminderId) +{ + return ReminderStrategy::Select(rdbStore, ReminderCalendarTable::TABLE_NAME, + ReminderCalendarTable::SELECT_COLUMNS, reminderId); +} + +int32_t ReminderCalendarStrategy::Insert(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + GenValuesBucket(reminder, values); + return ReminderStrategy::Insert(rdbStore, ReminderCalendarTable::TABLE_NAME, values); +} + +int32_t ReminderCalendarStrategy::Update(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + std::string condition = ReminderCalendarTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); + GenValuesBucket(reminder, values); + return ReminderStrategy::Update(rdbStore, ReminderCalendarTable::TABLE_NAME, values, condition); +} + +int32_t ReminderCalendarStrategy::Delete(std::shared_ptr rdbStore, const std::string& whereClause) +{ + return ReminderStrategy::Delete(rdbStore, ReminderCalendarTable::TABLE_NAME, whereClause); +} + +sptr ReminderCalendarStrategy::GenReminder(std::shared_ptr rdbStore, + const std::shared_ptr& resultBaseSet, const int32_t reminderId) +{ + sptr reminder = new (std::nothrow) ReminderRequestCalendar(reminderId); + if (reminder == nullptr) { + return nullptr; + } + auto resultSet = ReminderCalendarStrategy::Select(rdbStore, reminderId); + if (resultSet == nullptr) { + return nullptr; + } + ReminderBaseStrategy::Recover(reminder, resultBaseSet); + + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + + uint16_t value; + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_YEAR, value); + calendar->SetFirstDesignateYear(value); + + uint8_t sValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_MONTH, sValue); + calendar->SetFirstDesignageMonth(sValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::FIRST_DESIGNATE_DAY, sValue); + calendar->SetFirstDesignateDay(sValue); + + uint64_t dateTime; + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::CALENDAR_DATE_TIME, dateTime); + calendar->SetDateTime(dateTime); + + uint64_t endDateTime; + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::CALENDAR_END_DATE_TIME, endDateTime); + if (endDateTime != 0 && endDateTime >= dateTime) { + calendar->SetEndDateTime(endDateTime); + } else { + calendar->SetEndDateTime(dateTime); + } + + int32_t nValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::REPEAT_DAYS, nValue); + calendar->SetRepeatDay(static_cast(nValue)); + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::REPEAT_MONTHS, value); + calendar->SetRepeatMonth(value); + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, sValue); + reminder->SetRepeatDaysOfWeek(sValue); + + std::string strValue; + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::RRULE_WANT_AGENT, strValue); + calendar->DeserializationRRule(strValue); + ReminderStrategy::GetRdbValue(resultSet, ReminderCalendarTable::EXCLUDE_DATES, strValue); + calendar->DeserializationExcludeDates(strValue); + + return reminder; +} + +std::string ReminderCalendarStrategy::GetTableName() const +{ + return ReminderCalendarTable::TABLE_NAME; +} + +void ReminderCalendarStrategy::GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values) +{ + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + values.PutInt(ReminderCalendarTable::REMINDER_ID, reminder->GetReminderId()); + values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_YEAR, calendar->GetFirstDesignateYear()); + values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_MONTH, calendar->GetFirstDesignageMonth()); + values.PutInt(ReminderCalendarTable::FIRST_DESIGNATE_DAY, calendar->GetFirstDesignateDay()); + values.PutLong(ReminderCalendarTable::CALENDAR_DATE_TIME, calendar->GetDateTime()); + values.PutLong(ReminderCalendarTable::CALENDAR_END_DATE_TIME, calendar->GetEndDateTime()); + values.PutInt(ReminderCalendarTable::REPEAT_DAYS, calendar->GetRepeatDay()); + values.PutInt(ReminderCalendarTable::REPEAT_MONTHS, calendar->GetRepeatMonth()); + values.PutInt(ReminderCalendarTable::REPEAT_DAYS_OF_WEEK, calendar->GetRepeatDaysOfWeek()); + values.PutString(ReminderCalendarTable::RRULE_WANT_AGENT, calendar->SerializationRRule()); + values.PutString(ReminderCalendarTable::EXCLUDE_DATES, calendar->SerializationExcludeDates()); +} + +std::shared_ptr ReminderTimerStrategy::Select(std::shared_ptr rdbStore, + const int32_t reminderId) +{ + return ReminderStrategy::Select(rdbStore, ReminderTimerTable::TABLE_NAME, + ReminderTimerTable::SELECT_COLUMNS, reminderId); +} + +int32_t ReminderTimerStrategy::Insert(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + GenValuesBucket(reminder, values); + return ReminderStrategy::Insert(rdbStore, ReminderTimerTable::TABLE_NAME, values); +} + +int32_t ReminderTimerStrategy::Update(std::shared_ptr rdbStore, + const sptr& reminder) +{ + NativeRdb::ValuesBucket values; + std::string condition = ReminderTimerTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); + GenValuesBucket(reminder, values); + return ReminderStrategy::Update(rdbStore, ReminderTimerTable::TABLE_NAME, values, condition); +} + +int32_t ReminderTimerStrategy::Delete(std::shared_ptr rdbStore, const std::string& whereClause) +{ + return ReminderStrategy::Delete(rdbStore, ReminderTimerTable::TABLE_NAME, whereClause); +} + +sptr ReminderTimerStrategy::GenReminder(std::shared_ptr rdbStore, + const std::shared_ptr& resultBaseSet, const int32_t reminderId) +{ + sptr reminder = new (std::nothrow) ReminderRequestTimer(reminderId); + if (reminder == nullptr) { + return nullptr; + } + auto resultSet = ReminderTimerStrategy::Select(rdbStore, reminderId); + if (resultSet == nullptr) { + return nullptr; + } + ReminderBaseStrategy::Recover(reminder, resultBaseSet); + ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); + uint64_t value; + ReminderStrategy::GetRdbValue(resultSet, ReminderTimerTable::TRIGGER_SECOND, value); + timer->SetInitInfo(value); + + return reminder; +} + +std::string ReminderTimerStrategy::GetTableName() const +{ + return ReminderTimerTable::TABLE_NAME; +} + +void ReminderTimerStrategy::GenValuesBucket(const sptr& reminder, NativeRdb::ValuesBucket& values) +{ + ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); + values.PutInt(ReminderTimerTable::REMINDER_ID, reminder->GetReminderId()); + values.PutLong(ReminderTimerTable::TRIGGER_SECOND, timer->GetInitInfo()); + values.PutLong(ReminderTimerTable::START_DATE_TIME, 0); + values.PutLong(ReminderTimerTable::END_DATE_TIME, 0); +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/src/reminder_table.cpp b/services/ans/src/reminder_table.cpp similarity index 100% rename from frameworks/ans/src/reminder_table.cpp rename to services/ans/src/reminder_table.cpp diff --git a/frameworks/ans/src/reminder_table_old.cpp b/services/ans/src/reminder_table_old.cpp similarity index 100% rename from frameworks/ans/src/reminder_table_old.cpp rename to services/ans/src/reminder_table_old.cpp diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index fecb9b7897d0c34c03730329750b0c564f82ea46..acc3aa706dc728579db28e724bab585092d40cac 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/ans/test/unittest/reminder_data_manager_test.cpp @@ -369,7 +369,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_015, Level1) manager->HandleRefreshReminder(0, reminder); manager->HandleSameNotificationIdShowing(reminder); manager->Init(true); - manager->InitUserId(); + manager->SetUserId(); manager->GetImmediatelyShowRemindersLocked(vec); manager->IsAllowedNotify(reminder); manager->IsAllowedNotify(nullptr); @@ -421,7 +421,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_016, Level1) std::shared_ptr buttonDataShareUpdate1 = std::make_shared(); reminder1->SetSystemApp(true); - reminder1->InitUserId(100); + reminder1->SetUserId(100); buttonDataShareUpdate1->uri = "datashareTest://com.acts.dataShareTest"; buttonDataShareUpdate1->equalTo = "namestringli" "iddouble3.0statusbooltrue"; @@ -651,12 +651,12 @@ HWTEST_F(ReminderDataManagerTest, IsBelongToSameAppTest_001, Level1) HWTEST_F(ReminderDataManagerTest, CheckIsSameAppTest_001, Level1) { sptr reminder = new ReminderRequestTimer(10); - reminder->InitCreatorBundleName("test"); - reminder->InitUserId(-1); + reminder->SetCreatorBundleName("test"); + reminder->SetUserId(-1); sptr option = new NotificationBundleOption("test", -1); EXPECT_TRUE(manager->CheckIsSameApp(reminder, option)); - reminder->InitCreatorBundleName("test1"); + reminder->SetCreatorBundleName("test1"); EXPECT_FALSE(manager->CheckIsSameApp(reminder, option)); } @@ -723,15 +723,15 @@ HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); sptr reminder = new ReminderRequestCalendar(10); - reminder->InitCreatorBundleName("test1"); - reminder->InitUserId(-1); + reminder->SetCreatorBundleName("test1"); + reminder->SetUserId(-1); reminder->reminderId_ = 100; manager->reminderVector_.push_back(reminder); sptr option = new NotificationBundleOption("test", -1); result = manager->CheckExcludeDateParam(100, option); EXPECT_TRUE(result == nullptr); - reminder->InitCreatorBundleName("test"); + reminder->SetCreatorBundleName("test"); reminder->reminderType_ = ReminderRequest::ReminderType::TIMER; result = manager->CheckExcludeDateParam(100, option); EXPECT_TRUE(result == nullptr); @@ -797,19 +797,19 @@ HWTEST_F(ReminderDataManagerTest, CancelAllReminders_00001, Level1) HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) { sptr reminder1 = new ReminderRequestTimer(static_cast(50)); - reminder1->InitCreatorBundleName("test_getvalid"); - reminder1->InitCreatorUid(98765); - reminder1->InitBundleName("test_getvalid"); - reminder1->InitUid(98765); + reminder1->SetCreatorBundleName("test_getvalid"); + reminder1->SetCreatorUid(98765); + reminder1->SetBundleName("test_getvalid"); + reminder1->SetUid(98765); sptr option1 = new NotificationBundleOption("test_getvalid", 98765); manager->PublishReminder(reminder1, option1); reminder1->SetExpired(false); sptr reminder2 = new ReminderRequestTimer(51); - reminder2->InitCreatorBundleName("test_getvalid"); - reminder2->InitCreatorUid(98765); - reminder2->InitBundleName("test_getvalid"); - reminder2->InitUid(98765); + reminder2->SetCreatorBundleName("test_getvalid"); + reminder2->SetCreatorUid(98765); + reminder2->SetBundleName("test_getvalid"); + reminder2->SetUid(98765); reminder2->SetExpired(true); sptr option2 = new NotificationBundleOption("test_getvalid", 98765); manager->PublishReminder(reminder2, option2); @@ -828,11 +828,11 @@ HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) HWTEST_F(ReminderDataManagerTest, IsMatched_00001, Level1) { sptr reminder = new ReminderRequestTimer(50); - reminder->InitCreatorBundleName("test_IsMatched"); - reminder->InitCreatorUid(98765); - reminder->InitBundleName("test_IsMatched"); - reminder->InitUid(98765); - reminder->InitUserId(100); + reminder->SetCreatorBundleName("test_IsMatched"); + reminder->SetCreatorUid(98765); + reminder->SetBundleName("test_IsMatched"); + reminder->SetUid(98765); + reminder->SetUserId(100); bool ret = manager->IsMatched(reminder, "test_IsMatched", 101, 98765); EXPECT_EQ(ret, false); ret = manager->IsMatched(reminder, "allPackages", 100, 98765); diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp index 1b5cd73e955447110fcc26ff75536dc20bfaa45a..176a8cce4e4965bce2fe5791c2efa6da8661e74e 100644 --- a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp @@ -44,8 +44,8 @@ namespace OHOS { bool enabled = *data % ENABLE; reminderRequest.SetExpired(enabled); reminderRequest.InitReminderId(); - reminderRequest.InitUserId(reminderId); - reminderRequest.InitUid(reminderId); + reminderRequest.SetUserId(reminderId); + reminderRequest.SetUid(reminderId); reminderRequest.IsExpired(); reminderRequest.IsShowing(); reminderRequest.OnClose(enabled);