From dd702803b36d2a507ca024580d417d7f0e3a5296 Mon Sep 17 00:00:00 2001 From: gjq <329707880@qq.com> Date: Mon, 24 Jun 2024 22:28:29 +0800 Subject: [PATCH 1/3] refactor rdb Signed-off-by: gjq <329707880@qq.com> --- frameworks/ans/src/reminder_request.cpp | 1060 ++++++++--------- frameworks/ans/src/reminder_request_alarm.cpp | 44 - .../ans/src/reminder_request_calendar.cpp | 128 -- frameworks/ans/src/reminder_request_timer.cpp | 23 - interfaces/inner_api/reminder_request.h | 605 +++++----- .../ans/include}/reminder_store.h | 79 +- .../ans/include/reminder_store_strategy.h | 167 +++ .../ans/include}/reminder_table.h | 0 .../ans/include}/reminder_table_old.h | 0 .../ans/src/reminder_store.cpp | 451 ++----- services/ans/src/reminder_store_strategy.cpp | 454 +++++++ .../ans/src/reminder_table.cpp | 0 .../ans/src/reminder_table_old.cpp | 0 13 files changed, 1621 insertions(+), 1390 deletions(-) rename {interfaces/inner_api => services/ans/include}/reminder_store.h (63%) create mode 100644 services/ans/include/reminder_store_strategy.h rename {interfaces/inner_api => services/ans/include}/reminder_table.h (100%) rename {interfaces/inner_api => services/ans/include}/reminder_table_old.h (100%) rename {frameworks => services}/ans/src/reminder_store.cpp (53%) create mode 100644 services/ans/src/reminder_store_strategy.cpp rename {frameworks => services}/ans/src/reminder_table.cpp (100%) rename {frameworks => services}/ans/src/reminder_table_old.cpp (100%) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index ad1b23517..97a86004b 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -116,51 +116,510 @@ ReminderRequest::ReminderRequest() InitServerObj(); } +ReminderRequest::ReminderRequest(const int32_t reminderId) +{ + reminderId_ = reminderId; + InitServerObj(); +} + ReminderRequest::ReminderRequest(const ReminderRequest &other) { - this->content_ = other.content_; - this->expiredContent_ = other.expiredContent_; - this->snoozeContent_ = other.snoozeContent_; - this->displayContent_ = other.displayContent_; - this->title_ = other.title_; - this->isExpired_ = other.isExpired_; - this->isSystemApp_ = other.isSystemApp_; - this->snoozeTimes_ = other.snoozeTimes_; - this->snoozeTimesDynamic_ = other.snoozeTimesDynamic_; - this->state_ = other.state_; - this->notificationId_ = other.notificationId_; - this->reminderId_ = other.reminderId_; - this->reminderTimeInMilli_ = other.reminderTimeInMilli_; - this->ringDurationInMilli_ = other.ringDurationInMilli_; - this->triggerTimeInMilli_ = other.triggerTimeInMilli_; - this->timeIntervalInMilli_ = other.timeIntervalInMilli_; - this->reminderType_ = other.reminderType_; - this->slotType_ = other.slotType_; - this->snoozeSlotType_ = other.snoozeSlotType_; - this->notificationRequest_ = other.notificationRequest_; - this->wantAgentInfo_ = other.wantAgentInfo_; - this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; - this->actionButtonMap_ = other.actionButtonMap_; - this->tapDismissed_= other.tapDismissed_; - this->autoDeletedTime_ = other.autoDeletedTime_; - this->customButtonUri_ = other.customButtonUri_; - this->groupId_ = other.groupId_; - this->customRingUri_ = other.customRingUri_; - this->creatorBundleName_ = other.creatorBundleName_; + this->content_ = other.content_; + this->expiredContent_ = other.expiredContent_; + this->snoozeContent_ = other.snoozeContent_; + this->displayContent_ = other.displayContent_; + this->title_ = other.title_; + this->isExpired_ = other.isExpired_; + this->isSystemApp_ = other.isSystemApp_; + this->snoozeTimes_ = other.snoozeTimes_; + this->snoozeTimesDynamic_ = other.snoozeTimesDynamic_; + this->state_ = other.state_; + this->notificationId_ = other.notificationId_; + this->reminderId_ = other.reminderId_; + this->reminderTimeInMilli_ = other.reminderTimeInMilli_; + this->ringDurationInMilli_ = other.ringDurationInMilli_; + this->triggerTimeInMilli_ = other.triggerTimeInMilli_; + this->timeIntervalInMilli_ = other.timeIntervalInMilli_; + this->reminderType_ = other.reminderType_; + this->slotType_ = other.slotType_; + this->snoozeSlotType_ = other.snoozeSlotType_; + this->notificationRequest_ = other.notificationRequest_; + this->wantAgentInfo_ = other.wantAgentInfo_; + this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; + this->actionButtonMap_ = other.actionButtonMap_; + this->tapDismissed_= other.tapDismissed_; + this->autoDeletedTime_ = other.autoDeletedTime_; + this->customButtonUri_ = other.customButtonUri_; + this->groupId_ = other.groupId_; + this->customRingUri_ = other.customRingUri_; + this->creatorBundleName_ = other.creatorBundleName_; +} + +ReminderRequest::ReminderRequest(ReminderType reminderType) +{ + reminderType_ = reminderType; + InitServerObj(); +} + +int32_t ReminderRequest::GetReminderId() const +{ + return reminderId_; +} + +std::string ReminderRequest::GetBundleName() const +{ + return bundleName_; +} + +int32_t ReminderRequest::GetUserId() const +{ + return userId_; +} + +int32_t ReminderRequest::GetUid() const +{ + return uid_; +} + +bool ReminderRequest::IsSystemApp() const +{ + return isSystemApp_; +} + +ReminderRequest::ReminderType ReminderRequest::GetReminderType() const +{ + return reminderType_; +} + +uint64_t ReminderRequest::GetReminderTimeInMilli() const +{ + return reminderTimeInMilli_; +} + +uint64_t ReminderRequest::GetTriggerTimeInMilli() const +{ + return triggerTimeInMilli_; +} + +uint64_t ReminderRequest::GetTimeInterval() const +{ + return timeIntervalInMilli_ / MILLI_SECONDS; +} + +uint8_t ReminderRequest::GetSnoozeTimes() const +{ + return snoozeTimes_; +} + +uint8_t ReminderRequest::GetSnoozeTimesDynamic() const +{ + return snoozeTimesDynamic_; +} + +uint16_t ReminderRequest::GetRingDuration() const +{ + return ringDurationInMilli_ / MILLI_SECONDS; +} + +bool ReminderRequest::IsExpired() const +{ + return isExpired_; +} + +uint8_t ReminderRequest::GetState() const +{ + return state_; +} + +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; + } + return info; +} + +std::string ReminderRequest::GetCustomButtonUri() const +{ + return customButtonUri_; +} + +NotificationConstant::SlotType ReminderRequest::GetSlotType() const +{ + return slotType_; +} + +NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const +{ + return snoozeSlotType_; +} + +int32_t ReminderRequest::GetNotificationId() const +{ + return notificationId_; +} + +std::string ReminderRequest::GetTitle() const +{ + return title_; +} + +std::string ReminderRequest::GetContent() const +{ + return content_; +} + +std::string ReminderRequest::GetSnoozeContent() const +{ + return snoozeContent_; +} + +std::string ReminderRequest::GetExpiredContent() const +{ + return expiredContent_; +} + +std::string ReminderRequest::SerializeWantAgent() const +{ + 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(); + } + 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; +} + +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; +} + +bool ReminderRequest::IsTapDismissed() const +{ + return tapDismissed_; +} + +int64_t ReminderRequest::GetAutoDeletedTime() const +{ + return autoDeletedTime_; +} + +std::string ReminderRequest::GetGroupId() const +{ + return groupId_; +} + +std::string ReminderRequest::GetCustomRingUri() const +{ + return customRingUri_; +} + +std::string ReminderRequest::GetCreatorBundleName() const +{ + return creatorBundleName_; +} + +int32_t ReminderRequest::GetCreatorUid() const +{ + return creatorUid_; +} + +uint8_t ReminderRequest::GetRepeatDaysOfWeek() const +{ + return repeatDaysOfWeek_; +} + +void ReminderRequest::SetReminderId(int32_t reminderId) +{ + reminderId_ = reminderId; +} + +void ReminderRequest::InitBundleName(const std::string& bundleName) +{ + bundleName_ = bundleName; +} + +void ReminderRequest::InitUserId(const int32_t userId) +{ + userId_ = userId; +} + +void ReminderRequest::InitUid(const int32_t uid) +{ + uid_ = uid; +} + +void ReminderRequest::SetSystemApp(const bool isSystem) +{ + isSystemApp_ = isSystem; +} + +void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) +{ + reminderTimeInMilli_ = reminderTimeInMilli; +} + +void ReminderRequest::SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli) +{ + triggerTimeInMilli_ = triggerTimeInMilli; +} + +void ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) +{ + if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { + ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); + timeIntervalInMilli_ = 0; + } + 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; + } + else { + timeIntervalInMilli_ = timeIntervalInMilli; + } + } +} + +void ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) +{ + snoozeTimes_ = snoozeTimes; + SetSnoozeTimesDynamic(snoozeTimes); +} + +void ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) +{ + snoozeTimesDynamic_ = snooziTimes; +} + +void ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) +{ + uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS; + ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION); +} + +void ReminderRequest::SetExpired(const bool isExpired) +{ + isExpired_ = isExpired; +} + +void ReminderRequest::SetState(const uint8_t state) +{ + state_ = state; +} + +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) { + ANSR_LOGW("RecoverButton fail"); + return; + } + if (singleButton.size() == SINGLE_BUTTON_ONLY_ONE) { + std::string jsonString = singleButton.at(SINGLE_BUTTON_JSONSTRING); + RecoverActionButtonJsonMode(jsonString); + continue; + } + // old method Soon to be deleted + if (singleButton.size() < SINGLE_BUTTON_MIN_LEN) { + ANSR_LOGW("RecoverButton fail"); + return; + } + auto buttonWantAgent = std::make_shared(); + if (singleButton.size() == SINGLE_BUTTON_MAX_LEN) { + buttonWantAgent->pkgName = singleButton.at(BUTTON_PKG_INDEX); + buttonWantAgent->abilityName = singleButton.at(BUTTON_ABILITY_INDEX); + } + std::string resource = ""; + auto buttonDataShareUpdate = std::make_shared(); + SetActionButton(singleButton.at(BUTTON_TITLE_INDEX), + ActionButtonType(std::atoi(singleButton.at(BUTTON_TYPE_INDEX).c_str())), + resource, buttonWantAgent, buttonDataShareUpdate); + ANSR_LOGI("RecoverButton title:%{public}s, pkgName:%{public}s, abilityName:%{public}s", + singleButton.at(BUTTON_TITLE_INDEX).c_str(), buttonWantAgent->pkgName.c_str(), + buttonWantAgent->abilityName.c_str()); + } +} + +void ReminderRequest::SetCustomButtonUri(const std::string& uri) +{ + customButtonUri_ = uri; +} + +void ReminderRequest::SetSlotType(const NotificationConstant::SlotType slotType) +{ + slotType_ = slotType; +} + +void ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType) +{ + snoozeSlotType_ = snoozeSlotType; +} + +void ReminderRequest::SetNotificationId(const int32_t notificationId) +{ + notificationId_ = notificationId; +} + +void ReminderRequest::SetTitle(const std::string& title) +{ + title_ = title; +} + +void ReminderRequest::SetContent(const std::string& content) +{ + content_ = content; +} + +void ReminderRequest::SetSnoozeContent(const std::string& snoozeContent) +{ + snoozeContent_ = snoozeContent; +} + +void ReminderRequest::SetExpiredContent(const std::string& expiredContent) +{ + expiredContent_ = expiredContent; +} + +void ReminderRequest::DeserializeWantAgent(const std::string& wantInfo) +{ + if (nlohmann::json::accept(wantInfo)) { + RecoverWantAgentByJson(wantInfo, 0); + return; + } + 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); +} + +void ReminderRequest::DeserializeMaxWantAgent(const std::string& maxWantInfo) +{ + if (nlohmann::json::accept(maxWantInfo)) { + RecoverWantAgentByJson(maxWantInfo, 1); + return; + } + 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()); + auto maxScreenWantAgentInfo = std::make_shared(); + maxScreenWantAgentInfo->pkgName = info.at(0); + maxScreenWantAgentInfo->abilityName = info.at(1); + SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); } -ReminderRequest::ReminderRequest(int32_t reminderId) +void ReminderRequest::SetTapDismissed(bool tapDismissed) { - reminderId_ = reminderId; - InitServerObj(); + tapDismissed_ = tapDismissed; } -ReminderRequest::ReminderRequest(ReminderType reminderType) +void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime) { - reminderType_ = reminderType; - InitServerObj(); + autoDeletedTime_ = autoDeletedTime; +} + +void ReminderRequest::SetGroupId(const std::string& groupId) +{ + groupId_ = groupId; +} + +void ReminderRequest::SetCustomRingUri(const std::string& uri) +{ + customRingUri_ = uri; +} + +void ReminderRequest::InitCreatorBundleName(const std::string& creatorBundleName) +{ + creatorBundleName_ = creatorBundleName; } +void ReminderRequest::InitCreatorUid(const int32_t creatorUid) +{ + creatorUid_ = creatorUid; +} + +void ReminderRequest::SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek) +{ + repeatDaysOfWeek_ = repeatDaysOfWeek; +} + + + + + bool ReminderRequest::CanRemove() const { if ((state_ & (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE)) == 0) { @@ -215,33 +674,6 @@ ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, cons return *this; } -ReminderRequest& ReminderRequest::SetContent(const std::string &content) -{ - content_ = content; - return *this; -} - -ReminderRequest& ReminderRequest::SetExpiredContent(const std::string &expiredContent) -{ - expiredContent_ = expiredContent; - return *this; -} - -void ReminderRequest::SetExpired(bool isExpired) -{ - isExpired_ = isExpired; -} - -void ReminderRequest::InitCreatorBundleName(const std::string &creatorBundleName) -{ - creatorBundleName_ = creatorBundleName; -} - -void ReminderRequest::InitCreatorUid(const int32_t creatorUid) -{ - creatorUid_ = creatorUid; -} - void ReminderRequest::InitReminderId() { std::lock_guard lock(std::mutex); @@ -253,26 +685,6 @@ void ReminderRequest::InitReminderId() ANSR_LOGI("reminderId_=%{public}d", reminderId_); } -void ReminderRequest::InitUserId(const int32_t &userId) -{ - userId_ = userId; -} - -void ReminderRequest::InitUid(const int32_t &uid) -{ - uid_ = uid; -} - -void ReminderRequest::InitBundleName(const std::string &bundleName) -{ - bundleName_ = bundleName; -} - -bool ReminderRequest::IsExpired() const -{ - return isExpired_; -} - bool ReminderRequest::IsShowing() const { if ((state_ & REMINDER_STATUS_SHOWING) != 0) { @@ -630,47 +1042,6 @@ void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) resource, buttonWantAgent, buttonDataShareUpdate); } -void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) -{ - if (resultSet == nullptr) { - ANSR_LOGE("ResultSet is null"); - return; - } - std::string actionButtonInfo; - ReminderStore::GetStringVal(resultSet, ReminderBaseTable::ACTION_BUTTON_INFO, actionButtonInfo); - std::vector multiButton = StringSplit(actionButtonInfo, SEP_BUTTON_MULTI); - for (auto button : multiButton) { - std::vector singleButton = StringSplit(button, SEP_BUTTON_SINGLE); - if (singleButton.size() <= SINGLE_BUTTON_INVALID) { - ANSR_LOGW("RecoverButton fail"); - return; - } - if (singleButton.size() == SINGLE_BUTTON_ONLY_ONE) { - std::string jsonString = singleButton.at(SINGLE_BUTTON_JSONSTRING); - RecoverActionButtonJsonMode(jsonString); - continue; - } - // old method Soon to be deleted - if (singleButton.size() < SINGLE_BUTTON_MIN_LEN) { - ANSR_LOGW("RecoverButton fail"); - return; - } - auto buttonWantAgent = std::make_shared(); - if (singleButton.size() == SINGLE_BUTTON_MAX_LEN) { - buttonWantAgent->pkgName = singleButton.at(BUTTON_PKG_INDEX); - buttonWantAgent->abilityName = singleButton.at(BUTTON_ABILITY_INDEX); - } - std::string resource = ""; - auto buttonDataShareUpdate = std::make_shared(); - SetActionButton(singleButton.at(BUTTON_TITLE_INDEX), - ActionButtonType(std::atoi(singleButton.at(BUTTON_TYPE_INDEX).c_str())), - resource, buttonWantAgent, buttonDataShareUpdate); - ANSR_LOGI("RecoverButton title:%{public}s, pkgName:%{public}s, abilityName:%{public}s", - singleButton.at(BUTTON_TITLE_INDEX).c_str(), buttonWantAgent->pkgName.c_str(), - buttonWantAgent->abilityName.c_str()); - } -} - std::vector ReminderRequest::StringSplit(std::string source, const std::string &split) { std::vector result; @@ -712,145 +1083,34 @@ void ReminderRequest::RecoverWantAgentByJson(const std::string& wantAgentInfo, c 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; - } - } -} - -void ReminderRequest::RecoverWantAgent(const std::string &wantAgentInfo, const uint8_t &type) -{ - if (nlohmann::json::accept(wantAgentInfo)) { - RecoverWantAgentByJson(wantAgentInfo, type); - return; - } - std::vector info = StringSplit(wantAgentInfo, 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; - } - } -} - -ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( - const std::shared_ptr &maxScreenWantAgentInfo) -{ - maxScreenWantAgentInfo_ = maxScreenWantAgentInfo; - return *this; -} - -ReminderRequest& ReminderRequest::SetNotificationId(int32_t notificationId) -{ - notificationId_ = notificationId; - return *this; -} - -ReminderRequest& ReminderRequest::SetGroupId(const std::string &groupId) -{ - groupId_ = groupId; - return *this; -} - -ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotType &slotType) -{ - slotType_ = slotType; - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType) -{ - snoozeSlotType_ = snoozeSlotType; - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent) -{ - snoozeContent_ = snoozeContent; - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) -{ - snoozeTimes_ = snoozeTimes; - SetSnoozeTimesDynamic(snoozeTimes); - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) -{ - snoozeTimesDynamic_ = snooziTimes; - return *this; -} - -ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) -{ - if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { - ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); - timeIntervalInMilli_ = 0; - } 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; - } else { - timeIntervalInMilli_ = timeIntervalInMilli; + 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; } } - return *this; } -ReminderRequest& ReminderRequest::SetTitle(const std::string &title) +ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( + const std::shared_ptr &maxScreenWantAgentInfo) { - title_ = title; + maxScreenWantAgentInfo_ = maxScreenWantAgentInfo; return *this; } -void ReminderRequest::SetTriggerTimeInMilli(uint64_t triggerTimeInMilli) -{ - triggerTimeInMilli_ = triggerTimeInMilli; -} - ReminderRequest& ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo) { if (wantAgentInfo != nullptr) { @@ -877,198 +1137,21 @@ std::map R 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 -{ - return groupId_; -} - sptr ReminderRequest::GetNotificationRequest() const { return notificationRequest_; } -int32_t ReminderRequest::GetReminderId() const -{ - return reminderId_; -} - -uint64_t ReminderRequest::GetReminderTimeInMilli() const -{ - return reminderTimeInMilli_; -} - -void ReminderRequest::SetReminderId(int32_t reminderId) -{ - reminderId_ = reminderId; -} - -void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) -{ - reminderTimeInMilli_ = reminderTimeInMilli; -} - -ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) -{ - uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS; - ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION); - return *this; -} - -NotificationConstant::SlotType ReminderRequest::GetSlotType() const -{ - return slotType_; -} - -NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const -{ - return snoozeSlotType_; -} - -std::string ReminderRequest::GetSnoozeContent() const -{ - return snoozeContent_; -} - -uint8_t ReminderRequest::GetSnoozeTimes() const -{ - return snoozeTimes_; -} - -uint8_t ReminderRequest::GetSnoozeTimesDynamic() const -{ - return snoozeTimesDynamic_; -} - -uint8_t ReminderRequest::GetState() const -{ - return state_; -} - -uint64_t ReminderRequest::GetTimeInterval() const -{ - return timeIntervalInMilli_ / MILLI_SECONDS; -} - -std::string ReminderRequest::GetTitle() const -{ - return title_; -} - -uint64_t ReminderRequest::GetTriggerTimeInMilli() const -{ - return triggerTimeInMilli_; -} - -int32_t ReminderRequest::GetUserId() const -{ - return userId_; -} - -int32_t ReminderRequest::GetUid() const -{ - return uid_; -} - -std::string ReminderRequest::GetBundleName() const -{ - return bundleName_; -} - -void ReminderRequest::SetSystemApp(bool isSystem) -{ - isSystemApp_ = isSystem; -} - -bool ReminderRequest::IsSystemApp() const -{ - return isSystemApp_; -} - -void ReminderRequest::SetTapDismissed(bool tapDismissed) -{ - tapDismissed_ = tapDismissed; -} - -bool ReminderRequest::IsTapDismissed() const -{ - return tapDismissed_; -} - -void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime) -{ - autoDeletedTime_ = autoDeletedTime; -} - -int64_t ReminderRequest::GetAutoDeletedTime() const -{ - return autoDeletedTime_; -} - -void ReminderRequest::SetCustomButtonUri(const std::string &uri) -{ - customButtonUri_ = uri; -} - -std::string ReminderRequest::GetCustomButtonUri() const -{ - return customButtonUri_; -} - -void ReminderRequest::SetCustomRingUri(const std::string &uri) -{ - customRingUri_ = uri; -} - -std::string ReminderRequest::GetCustomRingUri() const -{ - return customRingUri_; -} - std::shared_ptr ReminderRequest::GetWantAgentInfo() const { return wantAgentInfo_; } -ReminderRequest::ReminderType ReminderRequest::GetReminderType() const -{ - return reminderType_; -} - -uint16_t ReminderRequest::GetRingDuration() const -{ - return ringDurationInMilli_ / MILLI_SECONDS; -} - bool ReminderRequest::UpdateNextReminder() { return false; @@ -1411,40 +1494,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 +1958,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 8a08f7a55..a59d6b804 100644 --- a/frameworks/ans/src/reminder_request_alarm.cpp +++ b/frameworks/ans/src/reminder_request_alarm.cpp @@ -197,49 +197,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 83a3ed7f0..d2062005b 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 6881b6261..bb964e9c1 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/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 0198c3b2e..5c21bb834 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -258,266 +258,470 @@ 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. - * - * @param reminderId Indicates reminder id. + * @brief Obtains 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. - * - * @param parcel the object into the parcel + * @brief Obtains bundle name */ - virtual bool Marshalling(Parcel &parcel) const override; + std::string GetBundleName() const; /** - * @brief Unmarshal object from a Parcel. - * - * @return the NotificationRequest + * @brief Obtains user id */ - static ReminderRequest *Unmarshalling(Parcel &parcel); - virtual bool ReadFromParcel(Parcel &parcel); + int32_t GetUserId() const; /** - * @brief If the reminder is showing on the notification panel, it should not be removed automatically. - * - * @return true if it can be removed automatically. + * @brief Obtains uid */ - bool CanRemove() const; + int32_t GetUid() const; - bool CanShow() const; + /** + * @brief Check whether the application is a system application. + */ + bool IsSystemApp() const; /** - * @brief Obtains all the information of the reminder. - * - * @return Information of the reminder. + * @brief Obtains reminder type. */ - std::string Dump() const; + ReminderType GetReminderType() const; /** - * @brief Obtains the configured action buttons. - * - * @return map of action buttons. + * @brief Obtains reminder time in milli. */ - std::map GetActionButtons() const; + uint64_t GetReminderTimeInMilli() const; /** - * @brief Obtains creator bundle name - * - * @return creator bundle name + * @brief Obtains trigger time in milli. */ - std::string GetCreatorBundleName() const; + uint64_t GetTriggerTimeInMilli() const; /** - * @brief Obtains creator uid - * - * @return creator uid + * @brief Obtains the Time Interval in seconds. */ - int32_t GetCreatorUid() const; + uint64_t GetTimeInterval() const; + + /** + * @brief Obtains the snooze times. + */ + uint8_t GetSnoozeTimes() const; + + /** + * @brief Obtains the snooze times dynamic. + */ + uint8_t GetSnoozeTimesDynamic() const; + + /** + * @brief Obtains the ringing or vibration duration configured for this reminder. + */ + uint16_t GetRingDuration() const; + + /** + * @brief Check the reminder is expired or not. + */ + bool IsExpired() const; + + /** + * @brief Obtains the reminder state. + */ + uint8_t GetState() const; + + /** + * @brief Obtains the reminder button info as string to rdb. + */ + std::string SerializeButtonInfo() const; + + /** + * @brief Gets custom button uri. + */ + std::string GetCustomButtonUri() const; + + /** + * @brief Obtains slot type. + */ + NotificationConstant::SlotType GetSlotType() const; + + /** + * @brief Obtains snoozeSlot type. + */ + NotificationConstant::SlotType GetSnoozeSlotType() const; + + /** + * @brief Obtains notification id. + */ + int32_t GetNotificationId() const; + + /** + * @brief Obtains title. + */ + std::string GetTitle() const; /** * @brief Obtains the configured content. - * - * @return content text. */ std::string GetContent() const; + /** + * @brief Obtains the configured snooze content. + */ + std::string GetSnoozeContent() const; + /** * @brief Obtains the configured expired content. - * - * @return expired content text. */ std::string GetExpiredContent() const; - std::shared_ptr GetMaxScreenWantAgentInfo() const; + /** + * @brief Obtains the reminder want agent info as string to rdb. + */ + std::string SerializeWantAgent() const; /** - * @brief Obtains notification id. - * - * @return notification id. + * @brief Obtains the reminder max want agent info as string to rdb. */ - int32_t GetNotificationId() const; + std::string SerializeMaxWantAgent() const; + + /** + * @brief Gets tapDismissed. + */ + bool IsTapDismissed() const; + + /** + * @brief Gets autoDeletedTime. + */ + int64_t GetAutoDeletedTime() const; /** * @brief Obtains group id. - * - * @return group id. */ std::string GetGroupId() const; /** - * @brief Obtains notification request. + * @brief Gets custom ring uri. + */ + std::string GetCustomRingUri() const; + + /** + * @brief Obtains creator bundle name. + */ + std::string GetCreatorBundleName() const; + + /** + * @brief Obtains creator uid. + */ + int32_t GetCreatorUid() const; + + /** + * @brief Obtains repeat days of week. + */ + uint8_t GetRepeatDaysOfWeek() const; + +public: + /** + * @brief Sets reminder id. * - * @return notification request instance. + * @param reminderId Indicates reminder id. */ - sptr GetNotificationRequest() const; + void SetReminderId(int32_t reminderId); /** - * @brief Obtains reminder id. + * @brief Inites reminder bundle name when publish reminder success. * - * @return reminder id. + * @param bundleName Indicates the bundle name which the reminder belong to */ - int32_t GetReminderId() const; + void InitBundleName(const std::string& bundleName); - uint64_t GetReminderTimeInMilli() const; + /** + * @brief Inits reminder userId when publish reminder success. + * + * 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. + */ + void InitUserId(const int32_t userId); /** - * @brief Obtains reminder type. + * @brief Inites reminder uid when publish reminder success. * - * @return reminder type. + * 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. */ - ReminderType GetReminderType() const; + void InitUid(const int32_t uid); /** - * @brief Obtains the ringing or vibration duration configured for this reminder. + * @brief Set the app system. + */ + void SetSystemApp(const bool isSystem); + + /** + * @brief Set reminder time in milli. + */ + void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); + + /** + * @brief Sets trigger time. * - * @return uint16_t The ringing or vibration duration in seconds. + * @param triggerTimeInMilli Indicates trigger time in milli. */ - uint16_t GetRingDuration() const; + void SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli); /** - * @brief Obtains slot type. + * @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. * - * @return slot type. + * @param timeIntervalInSeconds Indicates the snooze interval to set. If the value is less or equals to 0, + * the reminder will not be snoozed. */ - NotificationConstant::SlotType GetSlotType() const; + void SetTimeInterval(const uint64_t timeIntervalInSeconds); /** - * @brief Obtains snoozeSlot type. + * @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. * - * @return snoozeSlot type. + * 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. */ - NotificationConstant::SlotType GetSnoozeSlotType() const; + void SetSnoozeTimes(const uint8_t snoozeTimes); - std::string GetSnoozeContent() const; - uint8_t GetSnoozeTimes() const; - uint8_t GetSnoozeTimesDynamic() const; - uint8_t GetState() const; + /** + * @brief Set the number of snooze times dynamic + */ + void SetSnoozeTimesDynamic(const uint8_t snooziTimes); /** - * @brief Obtains the Time Interval in seconds. + * @brief Sets the ringing or vibration duration for this reminder, in seconds. * - * @return uint64_t Time Interval in seconds. + * @param ringDurationInSeconds Indicates the duration. The default is 1 second. */ - uint64_t GetTimeInterval() const; + void SetRingDuration(const uint64_t ringDurationInSeconds); /** - * @brief Obtains title. + * @brief Sets reminder is expired or not. * - * @return title. + * @param isExpired Indicates the reminder is expired or not. */ - std::string GetTitle() const; + void SetExpired(const bool isExpired); /** - * @brief Obtains trigger time in milli. + * @brief Sets reminder state. + */ + void SetState(const uint8_t state); + + /** + * @brief Sets reminder button info from rdb(string). + */ + void DeserializeButtonInfo(const std::string& buttonInfo); + + /** + * @brief Sets custom button uri. * - * @return trigger time. + * @param uri Indicates uri. */ - uint64_t GetTriggerTimeInMilli() const; + void SetCustomButtonUri(const std::string& uri); - int32_t GetUserId() const; - int32_t GetUid() const; + /** + * @brief Sets slot type. + * + * @param slotType Indicates slot type. + */ + void SetSlotType(const NotificationConstant::SlotType slotType); /** - * @brief Obtains bundle name + * @brief Sets snooze slot type. + */ + void SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType); + + /** + * @brief Sets notification id. * - * @return bundle name + * @param notificationId Indicates notification id. */ - std::string GetBundleName() const; + void SetNotificationId(int32_t notificationId); /** - * @brief Set the app system. + * @brief Sets title. * + * @param title Indicates title. */ - void SetSystemApp(bool isSystem); + void SetTitle(const std::string& title); /** - * @brief Check the app is system or not. + * @brief Sets reminder content. * - * @return true is the app is system. + * @param content Indicates content text. */ - bool IsSystemApp() const; + void SetContent(const std::string& content); /** - * @brief Obtains want agent information. + * @brief Sets reminder snooze content. + */ + void SetSnoozeContent(const std::string& snoozeContent); + + /** + * @brief Sets expired content. * - * @return want agent information. + * @param expiredContent Indicates expired content. */ - std::shared_ptr GetWantAgentInfo() const; + void SetExpiredContent(const std::string& expiredContent); + + /** + * @brief Sets reminder want agent info from rdb(string). + */ + void DeserializeWantAgent(const std::string& wantInfo); + + /** + * @brief Sets reminder max want agent info from rdb(string). + */ + void DeserializeMaxWantAgent(const std::string& maxWantInfo); + + /** + * @brief Sets tapDismissed. + * + * @param tapDismissed Indicates tapDismissed. + */ + void SetTapDismissed(const bool tapDismissed); + + /** + * @brief Sets autoDeletedTime. + * + * @param autoDeletedTime Indicates autoDeletedTime. + */ + void SetAutoDeletedTime(const int64_t autoDeletedTime); + + /** + * @brief Sets group id. + * + * @param notificationId Indicates group id. + */ + void SetGroupId(const std::string& groupId); /** * @brief Inites reminder creator bundle name when publish reminder success. * - * @param creatorBundleName Indicates the creator bundle name which the reminder belong to + * @param creatorBundleName Indicates the creator bundle name which the reminder belong to. */ - void InitCreatorBundleName(const std::string &creatorBundleName); + void InitCreatorBundleName(const std::string& creatorBundleName); /** * @brief Inites reminder creator uid when publish reminder success. * - * @param uid Indicates the creator uid which the reminder belong to + * @param uid Indicates the creator uid which the reminder belong to. */ void InitCreatorUid(const int32_t creatorUid); /** - * @brief Inits reminder id when publish reminder success. - * Assign a unique reminder id for each reminder. + * @brief Sets repeat days of week. */ - void InitReminderId(); + void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek); + + + + + + /** - * @brief Inits reminder userId when publish reminder success. + * @brief Marshal a NotificationRequest object into a Parcel. * - * 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 parcel the object into the parcel + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. * - * @param userId Indicates the userId which the reminder belong to. + * @return the NotificationRequest + */ + static ReminderRequest *Unmarshalling(Parcel &parcel); + virtual bool ReadFromParcel(Parcel &parcel); + + /** + * @brief If the reminder is showing on the notification panel, it should not be removed automatically. + * + * @return true if it can be removed automatically. */ - void InitUserId(const int32_t &userId); + bool CanRemove() const; + + bool CanShow() const; /** - * @brief Inites reminder uid when publish reminder success. + * @brief Obtains all the information of the reminder. * - * 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 Information of the reminder. + */ + std::string Dump() const; + + /** + * @brief Obtains the configured action buttons. * - * @param uid Indicates the uid which the reminder belong to. + * @return map of action buttons. */ - void InitUid(const int32_t &uid); + std::map GetActionButtons() const; + + std::shared_ptr GetMaxScreenWantAgentInfo() const; /** - * @brief Inites reminder bundle name when publish reminder success. + * @brief Obtains notification request. * - * @param bundleName Indicates the bundle name which the reminder belong to + * @return notification request instance. */ - void InitBundleName(const std::string &bundleName); + sptr GetNotificationRequest() const; /** - * @brief Check the reminder is alerting or not. + * @brief Obtains want agent information. * - * @return true if the reminder is playing sound or vibrating. + * @return want agent information. */ - bool IsAlerting() const; + std::shared_ptr GetWantAgentInfo() const; /** - * @brief Check the reminder is expired or not. + * @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. * - * @return true is the reminder is expired. + * @return true if the reminder is playing sound or vibrating. */ - bool IsExpired() const; + bool IsAlerting() const; /** * @brief Check the reminder is showing on the panel. @@ -631,121 +835,8 @@ public: const std::string &resource, const std::shared_ptr &buttonWantAgent = nullptr, const std::shared_ptr &buttonDataShareUpdate = nullptr); - /** - * @brief Sets reminder content. - * - * @param content Indicates content text. - * @return Current reminder self. - */ - ReminderRequest& SetContent(const std::string &content); - - /** - * @brief Sets reminder is expired or not. - * - * @param isExpired Indicates the reminder is expired or not. - */ - void SetExpired(bool isExpired); - - /** - * @brief Sets expired content. - * - * @param expiredContent Indicates expired content. - * @return Current reminder self. - */ - ReminderRequest& SetExpiredContent(const std::string &expiredContent); - ReminderRequest& SetMaxScreenWantAgentInfo(const std::shared_ptr &maxScreenWantAgentInfo); - /** - * @brief Sets notification id. - * - * @param notificationId Indicates notification id. - * @return Current reminder self. - */ - ReminderRequest& SetNotificationId(int32_t notificationId); - - /** - * @brief Sets group id. - * - * @param notificationId Indicates group id. - * @return Current reminder self. - */ - ReminderRequest& SetGroupId(const std::string &groupId); - - /** - * @brief Sets reminder id. - * - * @param reminderId Indicates reminder id. - */ - void SetReminderId(int32_t reminderId); - - void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); - - /** - * @brief Sets the ringing or vibration duration for this reminder, in seconds. - * - * @param ringDurationInSeconds Indicates the duration. The default is 1 second. - * @return Current reminder self. - */ - ReminderRequest& SetRingDuration(const uint64_t ringDurationInSeconds); - - /** - * @brief Sets slot type. - * - * @param slotType Indicates slot type. - * @return Current reminder self. - */ - ReminderRequest& SetSlotType(const NotificationConstant::SlotType &slotType); - ReminderRequest& SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType); - ReminderRequest& SetSnoozeContent(const std::string &snoozeContent); - - /** - * @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. - * @return ReminderRequest& Current reminder self. - */ - ReminderRequest& SetSnoozeTimes(const uint8_t snoozeTimes); - - ReminderRequest& SetSnoozeTimesDynamic(const uint8_t snooziTimes); - - /** - * @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. - * @return ReminderRequest& Current reminder self. - */ - ReminderRequest& SetTimeInterval(const uint64_t timeIntervalInSeconds); - - /** - * @brief Sets title. - * - * @param title Indicates title. - * @return Current reminder self. - */ - ReminderRequest& SetTitle(const std::string &title); - - /** - * @brief Sets trigger time. - * - * @param triggerTimeInMilli Indicates trigger time in milli. - */ - void SetTriggerTimeInMilli(uint64_t triggerTimeInMilli); /** * @brief Sets want agent information. @@ -804,55 +895,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. * @@ -993,7 +1035,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_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 ac81e8e25..1926a8efa 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 000000000..543b664eb --- /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/frameworks/ans/src/reminder_store.cpp b/services/ans/src/reminder_store.cpp similarity index 53% rename from frameworks/ans/src/reminder_store.cpp rename to services/ans/src/reminder_store.cpp index 565bcd382..05bc6d0ea 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,23 +260,32 @@ 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) { - int createDir = mkdir(REMINDER_DB_DIR.c_str(), S_IRWXU); - if (createDir != 0) { - ANSR_LOGE("Failed to create directory %{private}s", REMINDER_DB_DIR.c_str()); - return STATE_FAIL; - } - } - - ReminderTable::InitDbColumns(); + //if (access(REMINDER_DB_DIR.c_str(), F_OK) != 0) { + // int createDir = mkdir(REMINDER_DB_DIR.c_str(), S_IRWXU); + // if (createDir != 0) { + // ANSR_LOGE("Failed to create directory %{private}s", REMINDER_DB_DIR.c_str()); + // return STATE_FAIL; + // } + //} + 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); + int32_t ret = baseStrategy_->Delete(rdbStore_, condition); + if (ret != STATE_OK) { 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); - 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 000000000..9995696c0 --- /dev/null +++ b/services/ans/src/reminder_store_strategy.cpp @@ -0,0 +1,454 @@ +/* + * 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->InitCreatorBundleName(strValue); + int32_t value; + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CREATOR_UID, value); + reminder->InitCreatorUid(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->InitBundleName(strValue); + + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::USER_ID, value); + reminder->InitUserId(value); + ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::UID, value); + reminder->InitUid(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 -- Gitee From 4481084b21e882071710f0739dfe784c4ef1537f Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Tue, 25 Jun 2024 11:22:48 +0800 Subject: [PATCH 2/3] reminder refactor Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 450 +++++++------- frameworks/ans/src/reminder_request_alarm.cpp | 1 - .../test/unittest/reminder_request_test.cpp | 56 +- interfaces/inner_api/reminder_request.h | 555 ++++++++++-------- interfaces/inner_api/reminder_request_alarm.h | 1 - .../inner_api/reminder_request_calendar.h | 1 + ...advanced_notification_reminder_service.cpp | 4 +- services/ans/src/reminder_data_manager.cpp | 6 +- services/ans/src/reminder_store_strategy.cpp | 10 +- .../unittest/reminder_data_manager_test.cpp | 42 +- .../reminderrequest_fuzzer.cpp | 4 +- 11 files changed, 597 insertions(+), 533 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 97a86004b..e929d14d3 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -50,12 +50,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 +73,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) @@ -166,26 +156,51 @@ int32_t ReminderRequest::GetReminderId() const return reminderId_; } +void ReminderRequest::SetReminderId(int32_t reminderId) +{ + reminderId_ = reminderId; +} + std::string ReminderRequest::GetBundleName() const { return bundleName_; } +void ReminderRequest::SetBundleName(const std::string& bundleName) +{ + bundleName_ = bundleName; +} + int32_t ReminderRequest::GetUserId() const { return userId_; } +void ReminderRequest::SetUserId(const int32_t userId) +{ + userId_ = userId; +} + int32_t ReminderRequest::GetUid() const { return uid_; } +void ReminderRequest::SetUid(const int32_t uid) +{ + uid_ = uid; +} + bool ReminderRequest::IsSystemApp() const { return isSystemApp_; } +void ReminderRequest::SetSystemApp(const bool isSystem) +{ + isSystemApp_ = isSystem; +} + ReminderRequest::ReminderType ReminderRequest::GetReminderType() const { return reminderType_; @@ -196,73 +211,87 @@ uint64_t ReminderRequest::GetReminderTimeInMilli() const return reminderTimeInMilli_; } +void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) +{ + reminderTimeInMilli_ = reminderTimeInMilli; +} + uint64_t ReminderRequest::GetTriggerTimeInMilli() const { return triggerTimeInMilli_; } +void ReminderRequest::SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli) +{ + triggerTimeInMilli_ = triggerTimeInMilli; +} + uint64_t ReminderRequest::GetTimeInterval() const { return timeIntervalInMilli_ / MILLI_SECONDS; } +void ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) +{ + 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); + } +} + uint8_t ReminderRequest::GetSnoozeTimes() const { return snoozeTimes_; } +void ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) +{ + snoozeTimes_ = snoozeTimes; + SetSnoozeTimesDynamic(snoozeTimes); +} + uint8_t ReminderRequest::GetSnoozeTimesDynamic() const { return snoozeTimesDynamic_; } +void ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) +{ + snoozeTimesDynamic_ = snooziTimes; +} + uint16_t ReminderRequest::GetRingDuration() const { return ringDurationInMilli_ / MILLI_SECONDS; } +void ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) +{ + uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS; + ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION); +} + bool ReminderRequest::IsExpired() const { return isExpired_; } +void ReminderRequest::SetExpired(const bool isExpired) +{ + isExpired_ = isExpired; +} + uint8_t ReminderRequest::GetState() const { return state_; } -std::string ReminderRequest::SerializeButtonInfo() const +void ReminderRequest::SetState(const uint8_t state) { - 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; + state_ = state; } std::string ReminderRequest::GetCustomButtonUri() const @@ -270,82 +299,79 @@ std::string ReminderRequest::GetCustomButtonUri() const return customButtonUri_; } +void ReminderRequest::SetCustomButtonUri(const std::string& uri) +{ + customButtonUri_ = uri; +} + NotificationConstant::SlotType ReminderRequest::GetSlotType() const { return slotType_; } +void ReminderRequest::SetSlotType(const NotificationConstant::SlotType slotType) +{ + slotType_ = slotType; +} + NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const { return snoozeSlotType_; } +void ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType) +{ + snoozeSlotType_ = snoozeSlotType; +} + int32_t ReminderRequest::GetNotificationId() const { return notificationId_; } +void ReminderRequest::SetNotificationId(const int32_t notificationId) +{ + notificationId_ = notificationId; +} + std::string ReminderRequest::GetTitle() const { return title_; } +void ReminderRequest::SetTitle(const std::string& title) +{ + title_ = title; +} + std::string ReminderRequest::GetContent() const { return content_; } +void ReminderRequest::SetContent(const std::string& content) +{ + content_ = content; +} + std::string ReminderRequest::GetSnoozeContent() const { return snoozeContent_; } -std::string ReminderRequest::GetExpiredContent() const +void ReminderRequest::SetSnoozeContent(const std::string& snoozeContent) { - return expiredContent_; + snoozeContent_ = snoozeContent; } -std::string ReminderRequest::SerializeWantAgent() const +std::string ReminderRequest::GetExpiredContent() const { - 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(); - } - 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; + return expiredContent_; } -std::string ReminderRequest::SerializeMaxWantAgent() const +void ReminderRequest::SetExpiredContent(const std::string& expiredContent) { - 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; + expiredContent_ = expiredContent; } bool ReminderRequest::IsTapDismissed() const @@ -353,116 +379,131 @@ bool ReminderRequest::IsTapDismissed() const return tapDismissed_; } +void ReminderRequest::SetTapDismissed(bool tapDismissed) +{ + tapDismissed_ = tapDismissed; +} + int64_t ReminderRequest::GetAutoDeletedTime() const { return autoDeletedTime_; } -std::string ReminderRequest::GetGroupId() const +void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime) { - return groupId_; + autoDeletedTime_ = autoDeletedTime; } -std::string ReminderRequest::GetCustomRingUri() const +std::string ReminderRequest::GetGroupId() const { - return customRingUri_; + return groupId_; } -std::string ReminderRequest::GetCreatorBundleName() const +void ReminderRequest::SetGroupId(const std::string& groupId) { - return creatorBundleName_; + groupId_ = groupId; } -int32_t ReminderRequest::GetCreatorUid() const +std::string ReminderRequest::GetCustomRingUri() const { - return creatorUid_; + return customRingUri_; } -uint8_t ReminderRequest::GetRepeatDaysOfWeek() const +void ReminderRequest::SetCustomRingUri(const std::string& uri) { - return repeatDaysOfWeek_; + customRingUri_ = uri; } -void ReminderRequest::SetReminderId(int32_t reminderId) +std::string ReminderRequest::GetCreatorBundleName() const { - reminderId_ = reminderId; + return creatorBundleName_; } -void ReminderRequest::InitBundleName(const std::string& bundleName) +void ReminderRequest::SetCreatorBundleName(const std::string& creatorBundleName) { - bundleName_ = bundleName; + creatorBundleName_ = creatorBundleName; } -void ReminderRequest::InitUserId(const int32_t userId) +int32_t ReminderRequest::GetCreatorUid() const { - userId_ = userId; + return creatorUid_; } -void ReminderRequest::InitUid(const int32_t uid) +void ReminderRequest::SetCreatorUid(const int32_t creatorUid) { - uid_ = uid; + creatorUid_ = creatorUid; } -void ReminderRequest::SetSystemApp(const bool isSystem) +uint8_t ReminderRequest::GetRepeatDaysOfWeek() const { - isSystemApp_ = isSystem; + return repeatDaysOfWeek_; } -void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) +void ReminderRequest::SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek) { - reminderTimeInMilli_ = reminderTimeInMilli; + repeatDaysOfWeek_ = repeatDaysOfWeek; } -void ReminderRequest::SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli) +std::shared_ptr ReminderRequest::GetWantAgentInfo() const { - triggerTimeInMilli_ = triggerTimeInMilli; + return wantAgentInfo_; } -void ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) +void ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo) { - if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { - ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); - timeIntervalInMilli_ = 0; - } - 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; - } - else { - timeIntervalInMilli_ = timeIntervalInMilli; - } + if (wantAgentInfo != nullptr) { + wantAgentInfo_ = wantAgentInfo; } } -void ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) +std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const { - snoozeTimes_ = snoozeTimes; - SetSnoozeTimesDynamic(snoozeTimes); + return maxScreenWantAgentInfo_; } -void ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) +void ReminderRequest::SetMaxScreenWantAgentInfo( + const std::shared_ptr &maxScreenWantAgentInfo) { - snoozeTimesDynamic_ = snooziTimes; + maxScreenWantAgentInfo_ = maxScreenWantAgentInfo; } -void ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) +sptr ReminderRequest::GetNotificationRequest() const { - uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS; - ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION); + return notificationRequest_; } -void ReminderRequest::SetExpired(const bool isExpired) +std::string ReminderRequest::SerializeButtonInfo() const { - isExpired_ = isExpired; -} + 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; + } -void ReminderRequest::SetState(const uint8_t state) -{ - state_ = state; + 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; } void ReminderRequest::DeserializeButtonInfo(const std::string& buttonInfo) @@ -500,44 +541,26 @@ void ReminderRequest::DeserializeButtonInfo(const std::string& buttonInfo) } } -void ReminderRequest::SetCustomButtonUri(const std::string& uri) -{ - customButtonUri_ = uri; -} - -void ReminderRequest::SetSlotType(const NotificationConstant::SlotType slotType) -{ - slotType_ = slotType; -} - -void ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType) -{ - snoozeSlotType_ = snoozeSlotType; -} - -void ReminderRequest::SetNotificationId(const int32_t notificationId) -{ - notificationId_ = notificationId; -} - -void ReminderRequest::SetTitle(const std::string& title) -{ - title_ = title; -} - -void ReminderRequest::SetContent(const std::string& content) -{ - content_ = content; -} - -void ReminderRequest::SetSnoozeContent(const std::string& snoozeContent) -{ - snoozeContent_ = snoozeContent; -} - -void ReminderRequest::SetExpiredContent(const std::string& expiredContent) +std::string ReminderRequest::SerializeWantAgent() const { - expiredContent_ = expiredContent; + 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(); + } + 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::DeserializeWantAgent(const std::string& wantInfo) @@ -562,6 +585,27 @@ void ReminderRequest::DeserializeWantAgent(const std::string& wantInfo) SetWantAgentInfo(wai); } +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::DeserializeMaxWantAgent(const std::string& maxWantInfo) { if (nlohmann::json::accept(maxWantInfo)) { @@ -581,40 +625,6 @@ void ReminderRequest::DeserializeMaxWantAgent(const std::string& maxWantInfo) SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); } -void ReminderRequest::SetTapDismissed(bool tapDismissed) -{ - tapDismissed_ = tapDismissed; -} - -void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime) -{ - autoDeletedTime_ = autoDeletedTime; -} - -void ReminderRequest::SetGroupId(const std::string& groupId) -{ - groupId_ = groupId; -} - -void ReminderRequest::SetCustomRingUri(const std::string& uri) -{ - customRingUri_ = uri; -} - -void ReminderRequest::InitCreatorBundleName(const std::string& creatorBundleName) -{ - creatorBundleName_ = creatorBundleName; -} - -void ReminderRequest::InitCreatorUid(const int32_t creatorUid) -{ - creatorUid_ = creatorUid; -} - -void ReminderRequest::SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek) -{ - repeatDaysOfWeek_ = repeatDaysOfWeek; -} @@ -1104,21 +1114,6 @@ void ReminderRequest::RecoverWantAgentByJson(const std::string& wantAgentInfo, c } } -ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( - const std::shared_ptr &maxScreenWantAgentInfo) -{ - maxScreenWantAgentInfo_ = maxScreenWantAgentInfo; - return *this; -} - -ReminderRequest& ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo) -{ - if (wantAgentInfo != nullptr) { - wantAgentInfo_ = wantAgentInfo; - } - return *this; -} - bool ReminderRequest::ShouldShowImmediately() const { uint64_t nowInstantMilli = GetNowInstantMilli(); @@ -1137,21 +1132,6 @@ std::map R return actionButtonMap_; } -std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const -{ - return maxScreenWantAgentInfo_; -} - -sptr ReminderRequest::GetNotificationRequest() const -{ - return notificationRequest_; -} - -std::shared_ptr ReminderRequest::GetWantAgentInfo() const -{ - return wantAgentInfo_; -} - bool ReminderRequest::UpdateNextReminder() { return false; diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/ans/src/reminder_request_alarm.cpp index a59d6b804..8a4bb61cf 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) diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index b1fd3e023..89efc3d9a 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 5c21bb834..25d78b15f 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -203,11 +203,16 @@ public: HM }; - struct ButtonWantAgent { + struct WantAgentBase { std::string pkgName = ""; std::string abilityName = ""; }; + struct WantAgentInfo : public WantAgentBase { + std::string uri = ""; + AAFwk::WantParams parameters; + }; + struct ButtonDataShareUpdate { std::string uri = ""; std::string equalTo = ""; @@ -235,7 +240,7 @@ public: /** * The ability that is redirected to when the button is clicked. */ - std::shared_ptr wantAgent; + std::shared_ptr wantAgent; /** * The ability that is updata App rdb. @@ -243,21 +248,6 @@ public: std::shared_ptr dataShareUpdate; }; - /** - * @brief Want agent information. Indicates the package and the ability to switch to. - */ - struct WantAgentInfo { - std::string pkgName = ""; - std::string abilityName = ""; - std::string uri = ""; - AAFwk::WantParams parameters; - }; - - struct MaxScreenAgentInfo { - std::string pkgName = ""; - std::string abilityName = ""; - }; - public: /** * @brief This constructor should only be used in background proxy service process @@ -278,377 +268,501 @@ public: public: /** - * @brief Obtains reminder id. + * @brief Obtains the reminder id. + * + * @return Returns the reminder id. */ int32_t GetReminderId() const; /** - * @brief Obtains bundle name + * @brief Sets the reminder id. + * + * @param reminderId Indicates the reminder id. + */ + void SetReminderId(int32_t reminderId); + + /** + * @brief Obtains the reminder bundle name of the notification owner. + * + * @return Returns the reminder bundle name of the notification owner. */ std::string GetBundleName() const; /** - * @brief Obtains user id + * @brief Sets the reminder bundle name of the notification owner. + * + * @param bundleName Indicates the bundle name which the reminder belong to. + */ + void SetBundleName(const std::string& bundleName); + + /** + * @brief Obtains the user id. + * + * @return Returns the user id. */ int32_t GetUserId() const; /** - * @brief Obtains uid + * @brief Sets reminder userId when publish reminder success. + * + * 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. + */ + void SetUserId(const int32_t userId); + + /** + * @brief Obtains the uid. + * + * @return Returns the uid. */ int32_t GetUid() const; /** - * @brief Check whether the application is a system application. + * @brief Sets reminder uid when publish reminder success. + * + * 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. + */ + void SetUid(const int32_t uid); + + /** + * @brief Check the reminder creator is a system application. + * + * @return Returns true if this reminder creator is a system application; returns false otherwise. */ bool IsSystemApp() const; /** - * @brief Obtains reminder type. + * @brief Set the reminder creator is a system app. + * + * @param isSystem is a system app. + */ + void SetSystemApp(const bool isSystem); + + /** + * @brief Obtains the reminder type. + * + * @return Returns the reminder type. */ ReminderType GetReminderType() const; /** - * @brief Obtains reminder time in milli. + * @brief Obtains the reminder time in milli. + * + * @return Returns the reminder time in milli. */ uint64_t GetReminderTimeInMilli() const; /** - * @brief Obtains trigger time in milli. + * @brief Set the reminder time in milli. + * + * @param reminderTimeInMilli Indicates the reminder time in milli. + */ + void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); + + /** + * @brief Obtains the trigger time in milli. + * + * @return Returns the trigger time in milli. */ uint64_t GetTriggerTimeInMilli() const; /** - * @brief Obtains the Time Interval in seconds. + * @brief Sets the trigger time in milli.. + * + * @param triggerTimeInMilli Indicates the trigger time in milli. */ - uint64_t GetTimeInterval() const; + void SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli); /** - * @brief Obtains the snooze times. + * @brief Obtains the time interval in seconds. + * + * @return Returns the time interval in seconds. */ - uint8_t GetSnoozeTimes() const; + uint64_t GetTimeInterval() const; /** - * @brief Obtains the snooze times dynamic. + * @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. */ - uint8_t GetSnoozeTimesDynamic() const; + void SetTimeInterval(const uint64_t timeIntervalInSeconds); /** - * @brief Obtains the ringing or vibration duration configured for this reminder. + * @brief Obtains the snooze times. + * + * @return Returns the snooze times. */ - uint16_t GetRingDuration() const; + uint8_t GetSnoozeTimes() const; /** - * @brief Check the reminder is expired or not. + * @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. */ - bool IsExpired() const; + void SetSnoozeTimes(const uint8_t snoozeTimes); /** - * @brief Obtains the reminder state. + * @brief Obtains the snooze times dynamic. + * + * @return Returns the snooze times dynamic. */ - uint8_t GetState() const; + uint8_t GetSnoozeTimesDynamic() const; /** - * @brief Obtains the reminder button info as string to rdb. + * @brief Set the number of snooze times dynamic. + * + * @param snooziTimes Indicates the number of snooze times dynamic. */ - std::string SerializeButtonInfo() const; + void SetSnoozeTimesDynamic(const uint8_t snooziTimes); /** - * @brief Gets custom button uri. + * @brief Obtains the ringing or vibration duration configured for this reminder. + * + * @return Returns the ringing or vibration duration configured for this reminder. */ - std::string GetCustomButtonUri() const; + uint16_t GetRingDuration() const; /** - * @brief Obtains slot type. + * @brief Sets the ringing or vibration duration for this reminder, in seconds. + * + * @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 Returns true if the reminder is expired; returns false otherwise. */ - NotificationConstant::SlotType GetSnoozeSlotType() const; + bool IsExpired() const; /** - * @brief Obtains notification id. + * @brief Sets reminder is expired or not. + * + * @param isExpired Indicates the reminder is expired or not. */ - int32_t GetNotificationId() const; + void SetExpired(const bool isExpired); /** - * @brief Obtains title. + * @brief Obtains the reminder state. + * + * @return Returns the reminder state. */ - std::string GetTitle() const; + uint8_t GetState() const; /** - * @brief Obtains the configured content. + * @brief Sets reminder state. + * + * @param state Indicates the reminder state. */ - std::string GetContent() const; + void SetState(const uint8_t state); /** - * @brief Obtains the configured snooze content. + * @brief Obtains the custom button uri. + * + * @return Returns the custom button uri. */ - std::string GetSnoozeContent() const; + std::string GetCustomButtonUri() const; /** - * @brief Obtains the configured expired content. + * @brief Sets the custom button uri. + * + * @param uri Indicates the custom button uri. */ - std::string GetExpiredContent() const; + void SetCustomButtonUri(const std::string& uri); /** - * @brief Obtains the reminder want agent info as string to rdb. + * @brief Obtains the notification slot type. + * + * @return Returns the notification slot type. */ - std::string SerializeWantAgent() const; + NotificationConstant::SlotType GetSlotType() const; /** - * @brief Obtains the reminder max want agent info as string to rdb. + * @brief Sets the notification slot type. + * + * @param slotType Indicates the notification slot type. */ - std::string SerializeMaxWantAgent() const; + void SetSlotType(const NotificationConstant::SlotType slotType); /** - * @brief Gets tapDismissed. + * @brief Obtains the notification snoozeSlot type. + * + * @return Returns the notification snoozeSlot type. */ - bool IsTapDismissed() const; + NotificationConstant::SlotType GetSnoozeSlotType() const; /** - * @brief Gets autoDeletedTime. + * @brief Sets the notification snoozeSlot type. + * + * @param snoozeSlotType Indicates the notification snoozeSlot type. */ - int64_t GetAutoDeletedTime() const; + void SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType); /** - * @brief Obtains group id. + * @brief Obtains the notification id. + * + * @return Returns the notification id. */ - std::string GetGroupId() const; + int32_t GetNotificationId() const; /** - * @brief Gets custom ring uri. + * @brief Sets the notification id. + * + * @param notificationId Indicates the notification id. */ - std::string GetCustomRingUri() const; + void SetNotificationId(int32_t notificationId); /** - * @brief Obtains creator bundle name. + * @brief Obtains the reminder title. + * + * @return Returns the reminder title. */ - std::string GetCreatorBundleName() const; + std::string GetTitle() const; /** - * @brief Obtains creator uid. + * @brief Sets the reminder title. + * + * @param title Indicates the reminder title. */ - int32_t GetCreatorUid() const; + void SetTitle(const std::string& title); /** - * @brief Obtains repeat days of week. + * @brief Obtains the configured content. + * + * @return Returns the configured content. */ - uint8_t GetRepeatDaysOfWeek() const; + std::string GetContent() const; -public: /** - * @brief Sets reminder id. + * @brief Sets the reminder content. * - * @param reminderId Indicates reminder id. + * @param content Indicates the content text. */ - void SetReminderId(int32_t reminderId); + void SetContent(const std::string& content); /** - * @brief Inites reminder bundle name when publish reminder success. - * - * @param bundleName Indicates the bundle name which the reminder belong to + * @brief Obtains the configured snooze content. + * + * @return Returns the configured snooze content. */ - void InitBundleName(const std::string& bundleName); + std::string GetSnoozeContent() const; /** - * @brief Inits reminder userId when publish reminder success. - * - * 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. + * @brief Sets the reminder snooze content. + * + * @param snoozeContent Indicates the reminder snooze content. */ - void InitUserId(const int32_t userId); + void SetSnoozeContent(const std::string& snoozeContent); /** - * @brief Inites reminder uid when publish reminder success. - * - * 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. + * @brief Obtains the configured expired content. + * + * @return Returns the configured expired content. */ - void InitUid(const int32_t uid); + std::string GetExpiredContent() const; /** - * @brief Set the app system. + * @brief Sets the reminder expired content. + * + * @param expiredContent Indicates the reminder expired content. */ - void SetSystemApp(const bool isSystem); + void SetExpiredContent(const std::string& expiredContent); /** - * @brief Set reminder time in milli. + * @brief Checks whether the reminder will be automatically dismissed after being tapped. + * + * @return Returns true if the reminder will be automatically dismissed; returns false otherwise. */ - void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); + bool IsTapDismissed() const; /** - * @brief Sets trigger time. + * @brief Sets whether to automatically dismiss a reminder after being tapped. * - * @param triggerTimeInMilli Indicates trigger time in milli. + * @param isDismissed Specifies whether a reminder will be automatically dismissed after being tapped. */ - void SetTriggerTimeInMilli(const uint64_t triggerTimeInMilli); + void SetTapDismissed(const bool tapDismissed); /** - * @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. + * @brief Obtains the period during which a reminder is deleted. + * + * @return Returns the period in milliseconds. */ - void SetTimeInterval(const uint64_t timeIntervalInSeconds); + int64_t GetAutoDeletedTime() 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. + * @brief Sets the time to delete a reminder. * - * 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. + * @param autoDeletedTime Indicates the time in milliseconds. + * The default value is 0, indicating that the reminder will not be automatically deleted. */ - void SetSnoozeTimes(const uint8_t snoozeTimes); + void SetAutoDeletedTime(const int64_t autoDeletedTime); /** - * @brief Set the number of snooze times dynamic + * @brief Obtains the reminder group id. + * + * @return Returns the reminder group id. */ - void SetSnoozeTimesDynamic(const uint8_t snooziTimes); + std::string GetGroupId() const; /** - * @brief Sets the ringing or vibration duration for this reminder, in seconds. + * @brief Sets the group id. * - * @param ringDurationInSeconds Indicates the duration. The default is 1 second. + * @param groupId Indicates the group id. */ - void SetRingDuration(const uint64_t ringDurationInSeconds); + void SetGroupId(const std::string& groupId); /** - * @brief Sets reminder is expired or not. + * @brief Obtains the custom ring uri. + * + * @return Returns the custom ring uri. + */ + std::string GetCustomRingUri() const; + + /** + * @brief Sets the custom ring uri. * - * @param isExpired Indicates the reminder is expired or not. + * @param uri Indicates the custom ring uri. */ - void SetExpired(const bool isExpired); + void SetCustomRingUri(const std::string &uri); /** - * @brief Sets reminder state. + * @brief Obtains the reminder bundle name of the reminder creator. + * + * @return Returns the reminder bundle name of the reminder creator. */ - void SetState(const uint8_t state); + std::string GetCreatorBundleName() const; /** - * @brief Sets reminder button info from rdb(string). + * @brief Sets the reminder bundle name of the reminder creator. + * + * @param creatorBundleName Indicates the reminder bundle name of the reminder creator. */ - void DeserializeButtonInfo(const std::string& buttonInfo); + void SetCreatorBundleName(const std::string& creatorBundleName); /** - * @brief Sets custom button uri. - * - * @param uri Indicates uri. + * @brief Obtains the reminder uid of the reminder creator. + * + * @return Returns the reminder uid of the reminder creator. */ - void SetCustomButtonUri(const std::string& uri); + int32_t GetCreatorUid() const; /** - * @brief Sets slot type. + * @brief Sets the reminder uid of the reminder creator. * - * @param slotType Indicates slot type. + * @param uid Indicates the reminder uid of the reminder creator. */ - void SetSlotType(const NotificationConstant::SlotType slotType); + void SetCreatorUid(const int32_t creatorUid); /** - * @brief Sets snooze slot type. + * @brief Obtains the repeat days of week. + * + * @return Returns the repeat days of week. */ - void SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType); + uint8_t GetRepeatDaysOfWeek() const; /** - * @brief Sets notification id. - * - * @param notificationId Indicates notification id. + * @brief Sets the repeat days of week. + * + * @param repeatDaysOfWeek Indicates the repeat days of week. */ - void SetNotificationId(int32_t notificationId); + void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek); +public: /** - * @brief Sets title. + * @brief Obtains the want agent information. * - * @param title Indicates title. + * @return Returns the want agent information. */ - void SetTitle(const std::string& title); + std::shared_ptr GetWantAgentInfo() const; /** - * @brief Sets reminder content. + * @brief Sets the want agent information. * - * @param content Indicates content text. + * @param wantAgentInfo Indicates the want agent information. */ - void SetContent(const std::string& content); + void SetWantAgentInfo(const std::shared_ptr &wantAgentInfo); /** - * @brief Sets reminder snooze content. + * @brief Obtains the max want agent information. + * + * @return Returns the max want agent information. */ - void SetSnoozeContent(const std::string& snoozeContent); + std::shared_ptr GetMaxScreenWantAgentInfo() const; /** - * @brief Sets expired content. + * @brief Sets the max want agent information. * - * @param expiredContent Indicates expired content. + * @param maxScreenWantAgentInfo Indicates the max want agent information. */ - void SetExpiredContent(const std::string& expiredContent); + void SetMaxScreenWantAgentInfo(const std::shared_ptr &maxScreenWantAgentInfo); /** - * @brief Sets reminder want agent info from rdb(string). + * @brief Obtains notification request. + * + * @return notification request instance. */ - void DeserializeWantAgent(const std::string& wantInfo); + sptr GetNotificationRequest() const; +public: /** - * @brief Sets reminder max want agent info from rdb(string). + * @brief Obtains the reminder button info as string to rdb. + * + * @return Returns the reminder bundle name of the notification owner */ - void DeserializeMaxWantAgent(const std::string& maxWantInfo); + std::string SerializeButtonInfo() const; /** - * @brief Sets tapDismissed. - * - * @param tapDismissed Indicates tapDismissed. + * @brief Sets reminder button info from rdb(string). */ - void SetTapDismissed(const bool tapDismissed); + void DeserializeButtonInfo(const std::string& buttonInfo); /** - * @brief Sets autoDeletedTime. - * - * @param autoDeletedTime Indicates autoDeletedTime. + * @brief Obtains the reminder want agent info as string to rdb. + * + * @return Returns the reminder bundle name of the notification owner */ - void SetAutoDeletedTime(const int64_t autoDeletedTime); + std::string SerializeWantAgent() const; /** - * @brief Sets group id. - * - * @param notificationId Indicates group id. + * @brief Sets reminder want agent info from rdb(string). */ - void SetGroupId(const std::string& groupId); + void DeserializeWantAgent(const std::string& wantInfo); /** - * @brief Inites reminder creator bundle name when publish reminder success. - * - * @param creatorBundleName Indicates the creator bundle name which the reminder belong to. + * @brief Obtains the reminder max want agent info as string to rdb. + * + * @return Returns the reminder bundle name of the notification owner */ - void InitCreatorBundleName(const std::string& creatorBundleName); + std::string SerializeMaxWantAgent() const; /** - * @brief Inites reminder creator uid when publish reminder success. - * - * @param uid Indicates the creator uid which the reminder belong to. + * @brief Sets reminder max want agent info from rdb(string). */ - void InitCreatorUid(const int32_t creatorUid); + void DeserializeMaxWantAgent(const std::string& maxWantInfo); + - /** - * @brief Sets repeat days of week. - */ - void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek); @@ -694,22 +808,6 @@ public: */ std::map GetActionButtons() const; - std::shared_ptr GetMaxScreenWantAgentInfo() const; - - /** - * @brief Obtains notification request. - * - * @return notification request instance. - */ - sptr GetNotificationRequest() const; - - /** - * @brief Obtains want agent information. - * - * @return want agent information. - */ - std::shared_ptr GetWantAgentInfo() const; - /** * @brief Inits reminder id when publish reminder success. * Assign a unique reminder id for each reminder. @@ -835,17 +933,6 @@ public: const std::string &resource, const std::shared_ptr &buttonWantAgent = nullptr, const std::shared_ptr &buttonDataShareUpdate = nullptr); - ReminderRequest& SetMaxScreenWantAgentInfo(const std::shared_ptr &maxScreenWantAgentInfo); - - - /** - * @brief Sets want agent information. - * - * @param wantAgentInfo Indicates want agent information. - * @return Current reminder self. - */ - ReminderRequest& SetWantAgentInfo(const std::shared_ptr &wantAgentInfo); - bool ShouldShowImmediately() const; /** @@ -895,13 +982,6 @@ public: std::string GetWantAgentStr(); std::string GetMaxWantAgentStr(); - /** - * @brief Sets custom ring uri. - * - * @param uri Indicates uri. - */ - void SetCustomRingUri(const std::string &uri); - /** * @brief Update notification attributes. * @@ -939,19 +1019,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. */ diff --git a/interfaces/inner_api/reminder_request_alarm.h b/interfaces/inner_api/reminder_request_alarm.h index d82f093a3..29db4f089 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 f6f2add73..01e947aa7 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/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index ad6cbc098..829e0990e 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 29606043e..48c9e6997 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -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", diff --git a/services/ans/src/reminder_store_strategy.cpp b/services/ans/src/reminder_store_strategy.cpp index 9995696c0..f4b4c1e5a 100644 --- a/services/ans/src/reminder_store_strategy.cpp +++ b/services/ans/src/reminder_store_strategy.cpp @@ -122,10 +122,10 @@ void ReminderBaseStrategy::Recover(sptr& reminder, const std::s ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CUSTOM_RING_URI, strValue); reminder->SetCustomRingUri(strValue); ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CREATOR_BUNDLE_NAME, strValue); - reminder->InitCreatorBundleName(strValue); + reminder->SetCreatorBundleName(strValue); int32_t value; ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::CREATOR_UID, value); - reminder->InitCreatorUid(value); + reminder->SetCreatorUid(value); } void ReminderBaseStrategy::RecoverBase(sptr& reminder, const std::shared_ptr& resultSet) @@ -136,12 +136,12 @@ void ReminderBaseStrategy::RecoverBase(sptr& reminder, const st std::string strValue; ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::PACKAGE_NAME, strValue); - reminder->InitBundleName(strValue); + reminder->SetBundleName(strValue); ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::USER_ID, value); - reminder->InitUserId(value); + reminder->SetUserId(value); ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::UID, value); - reminder->InitUid(value); + reminder->SetUid(value); ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::SYSTEM_APP, strValue); reminder->SetSystemApp(strValue == "true"); diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index fecb9b789..acc3aa706 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 1b5cd73e9..176a8cce4 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); -- Gitee From 951d26380f7e6c8244d8503afe0ba8f151fdb185 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 1 Jul 2024 15:42:03 +0800 Subject: [PATCH 3/3] update reminder Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 2 - interfaces/inner_api/reminder_request.h | 102 ++++++++++--------- services/ans/src/reminder_data_manager.cpp | 36 +++---- services/ans/src/reminder_store.cpp | 14 +-- services/ans/src/reminder_store_strategy.cpp | 51 ++++++---- 5 files changed, 115 insertions(+), 90 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index e929d14d3..6c3ee3c6a 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" diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 25d78b15f..73a980ae6 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -203,16 +203,11 @@ public: HM }; - struct WantAgentBase { + struct ButtonWantAgent { std::string pkgName = ""; std::string abilityName = ""; }; - struct WantAgentInfo : public WantAgentBase { - std::string uri = ""; - AAFwk::WantParams parameters; - }; - struct ButtonDataShareUpdate { std::string uri = ""; std::string equalTo = ""; @@ -240,7 +235,7 @@ public: /** * The ability that is redirected to when the button is clicked. */ - std::shared_ptr wantAgent; + std::shared_ptr wantAgent; /** * The ability that is updata App rdb. @@ -248,6 +243,21 @@ public: std::shared_ptr dataShareUpdate; }; + /** + * @brief Want agent information. Indicates the package and the ability to switch to. + */ + struct WantAgentInfo { + std::string pkgName = ""; + std::string abilityName = ""; + std::string uri = ""; + AAFwk::WantParams parameters; + }; + + struct MaxScreenAgentInfo { + std::string pkgName = ""; + std::string abilityName = ""; + }; + public: /** * @brief This constructor should only be used in background proxy service process @@ -269,7 +279,7 @@ public: public: /** * @brief Obtains the reminder id. - * + * * @return Returns the reminder id. */ int32_t GetReminderId() const; @@ -283,7 +293,7 @@ public: /** * @brief Obtains the reminder bundle name of the notification owner. - * + * * @return Returns the reminder bundle name of the notification owner. */ std::string GetBundleName() const; @@ -297,7 +307,7 @@ public: /** * @brief Obtains the user id. - * + * * @return Returns the user id. */ int32_t GetUserId() const; @@ -315,7 +325,7 @@ public: /** * @brief Obtains the uid. - * + * * @return Returns the uid. */ int32_t GetUid() const; @@ -332,42 +342,42 @@ public: /** * @brief Check the reminder creator is a system application. - * + * * @return Returns true if this reminder creator is a system application; returns false otherwise. */ bool IsSystemApp() const; /** * @brief Set the reminder creator is a system app. - * + * * @param isSystem is a system app. */ void SetSystemApp(const bool isSystem); /** * @brief Obtains the reminder type. - * + * * @return Returns the reminder type. */ ReminderType GetReminderType() const; /** * @brief Obtains the reminder time in milli. - * + * * @return Returns the reminder time in milli. */ uint64_t GetReminderTimeInMilli() const; /** * @brief Set the reminder time in milli. - * + * * @param reminderTimeInMilli Indicates the reminder time in milli. */ void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); /** * @brief Obtains the trigger time in milli. - * + * * @return Returns the trigger time in milli. */ uint64_t GetTriggerTimeInMilli() const; @@ -381,7 +391,7 @@ public: /** * @brief Obtains the time interval in seconds. - * + * * @return Returns the time interval in seconds. */ uint64_t GetTimeInterval() const; @@ -401,7 +411,7 @@ public: /** * @brief Obtains the snooze times. - * + * * @return Returns the snooze times. */ uint8_t GetSnoozeTimes() const; @@ -424,21 +434,21 @@ public: /** * @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 Returns the ringing or vibration duration configured for this reminder. */ uint16_t GetRingDuration() const; @@ -452,7 +462,7 @@ public: /** * @brief Check the reminder is expired or not. - * + * * @return Returns true if the reminder is expired; returns false otherwise. */ bool IsExpired() const; @@ -466,21 +476,21 @@ public: /** * @brief Obtains the reminder state. - * + * * @return Returns the reminder state. */ uint8_t GetState() const; /** * @brief Sets reminder state. - * + * * @param state Indicates the reminder state. */ void SetState(const uint8_t state); /** * @brief Obtains the custom button uri. - * + * * @return Returns the custom button uri. */ std::string GetCustomButtonUri() const; @@ -494,7 +504,7 @@ public: /** * @brief Obtains the notification slot type. - * + * * @return Returns the notification slot type. */ NotificationConstant::SlotType GetSlotType() const; @@ -508,21 +518,21 @@ public: /** * @brief Obtains the notification snoozeSlot type. - * + * * @return Returns the notification snoozeSlot type. */ NotificationConstant::SlotType GetSnoozeSlotType() const; /** * @brief Sets the notification snoozeSlot type. - * + * * @param snoozeSlotType Indicates the notification snoozeSlot type. */ void SetSnoozeSlotType(const NotificationConstant::SlotType snoozeSlotType); /** * @brief Obtains the notification id. - * + * * @return Returns the notification id. */ int32_t GetNotificationId() const; @@ -536,7 +546,7 @@ public: /** * @brief Obtains the reminder title. - * + * * @return Returns the reminder title. */ std::string GetTitle() const; @@ -550,7 +560,7 @@ public: /** * @brief Obtains the configured content. - * + * * @return Returns the configured content. */ std::string GetContent() const; @@ -564,21 +574,21 @@ public: /** * @brief Obtains the configured snooze content. - * + * * @return Returns the configured snooze content. */ std::string GetSnoozeContent() const; /** * @brief Sets the reminder snooze content. - * + * * @param snoozeContent Indicates the reminder snooze content. */ void SetSnoozeContent(const std::string& snoozeContent); /** * @brief Obtains the configured expired content. - * + * * @return Returns the configured expired content. */ std::string GetExpiredContent() const; @@ -592,7 +602,7 @@ public: /** * @brief Checks whether the reminder will be automatically dismissed after being tapped. - * + * * @return Returns true if the reminder will be automatically dismissed; returns false otherwise. */ bool IsTapDismissed() const; @@ -606,7 +616,7 @@ public: /** * @brief Obtains the period during which a reminder is deleted. - * + * * @return Returns the period in milliseconds. */ int64_t GetAutoDeletedTime() const; @@ -621,7 +631,7 @@ public: /** * @brief Obtains the reminder group id. - * + * * @return Returns the reminder group id. */ std::string GetGroupId() const; @@ -635,7 +645,7 @@ public: /** * @brief Obtains the custom ring uri. - * + * * @return Returns the custom ring uri. */ std::string GetCustomRingUri() const; @@ -649,7 +659,7 @@ public: /** * @brief Obtains the reminder bundle name of the reminder creator. - * + * * @return Returns the reminder bundle name of the reminder creator. */ std::string GetCreatorBundleName() const; @@ -663,7 +673,7 @@ public: /** * @brief Obtains the reminder uid of the reminder creator. - * + * * @return Returns the reminder uid of the reminder creator. */ int32_t GetCreatorUid() const; @@ -677,14 +687,14 @@ public: /** * @brief Obtains the repeat days of week. - * + * * @return Returns the repeat days of week. */ uint8_t GetRepeatDaysOfWeek() const; /** * @brief Sets the repeat days of week. - * + * * @param repeatDaysOfWeek Indicates the repeat days of week. */ void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek); @@ -728,7 +738,7 @@ public: public: /** * @brief Obtains the reminder button info as string to rdb. - * + * * @return Returns the reminder bundle name of the notification owner */ std::string SerializeButtonInfo() const; @@ -740,7 +750,7 @@ public: /** * @brief Obtains the reminder want agent info as string to rdb. - * + * * @return Returns the reminder bundle name of the notification owner */ std::string SerializeWantAgent() const; @@ -752,7 +762,7 @@ public: /** * @brief Obtains the reminder max want agent info as string to rdb. - * + * * @return Returns the reminder bundle name of the notification owner */ std::string SerializeMaxWantAgent() const; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 48c9e6997..2b0d44afd 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( @@ -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/services/ans/src/reminder_store.cpp b/services/ans/src/reminder_store.cpp index 05bc6d0ea..66c988431 100644 --- a/services/ans/src/reminder_store.cpp +++ b/services/ans/src/reminder_store.cpp @@ -263,13 +263,13 @@ void ReminderStore::ReminderStoreDataCallBack::AddRdbColum(NativeRdb::RdbStore& int32_t ReminderStore::Init() { ANSR_LOGD("Reminder store init."); - //if (access(REMINDER_DB_DIR.c_str(), F_OK) != 0) { - // int createDir = mkdir(REMINDER_DB_DIR.c_str(), S_IRWXU); - // if (createDir != 0) { - // ANSR_LOGE("Failed to create directory %{private}s", REMINDER_DB_DIR.c_str()); - // return STATE_FAIL; - // } - //} + if (access(REMINDER_DB_DIR.c_str(), F_OK) != 0) { + int createDir = mkdir(REMINDER_DB_DIR.c_str(), S_IRWXU); + if (createDir != 0) { + ANSR_LOGE("Failed to create directory %{private}s", REMINDER_DB_DIR.c_str()); + return STATE_FAIL; + } + } ReminderBaseTable::InitDbColumns(); ReminderTimerTable::InitDbColumns(); diff --git a/services/ans/src/reminder_store_strategy.cpp b/services/ans/src/reminder_store_strategy.cpp index f4b4c1e5a..3cc8a0b3e 100644 --- a/services/ans/src/reminder_store_strategy.cpp +++ b/services/ans/src/reminder_store_strategy.cpp @@ -42,7 +42,8 @@ std::shared_ptr ReminderStrategy::Select(std::shared_ptr rdbStore, const std::string& tableName, const NativeRdb::ValuesBucket& values) +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); @@ -77,14 +78,16 @@ inline int32_t ReminderStrategy::Delete(std::shared_ptr rdb return ReminderStore::STATE_OK; } -int32_t ReminderBaseStrategy::Insert(std::shared_ptr rdbStore, const sptr& reminder) +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) +int32_t ReminderBaseStrategy::Update(std::shared_ptr rdbStore, + const sptr& reminder) { NativeRdb::ValuesBucket values; GenValuesBucket(reminder, values); @@ -102,7 +105,8 @@ std::string ReminderBaseStrategy::GetTableName() const return ReminderBaseTable::TABLE_NAME; } -void ReminderBaseStrategy::Recover(sptr& reminder, const std::shared_ptr& resultSet) +void ReminderBaseStrategy::Recover(sptr& reminder, + const std::shared_ptr& resultSet) { RecoverBase(reminder, resultSet); reminder->InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent @@ -128,7 +132,8 @@ void ReminderBaseStrategy::Recover(sptr& reminder, const std::s reminder->SetCreatorUid(value); } -void ReminderBaseStrategy::RecoverBase(sptr& reminder, const std::shared_ptr& resultSet) +void ReminderBaseStrategy::RecoverBase(sptr& reminder, + const std::shared_ptr& resultSet) { int32_t value; ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::REMINDER_ID, value); @@ -228,19 +233,23 @@ void ReminderBaseStrategy::GenValuesBucket(const sptr& reminder values.PutInt(ReminderBaseTable::CREATOR_UID, reminder->GetCreatorUid()); } -std::shared_ptr ReminderAlarmStrategy::Select(std::shared_ptr rdbStore, const int32_t reminderId) +std::shared_ptr ReminderAlarmStrategy::Select(std::shared_ptr rdbStore, + const int32_t reminderId) { - return ReminderStrategy::Select(rdbStore, ReminderAlarmTable::TABLE_NAME, ReminderAlarmTable::SELECT_COLUMNS, reminderId); + return ReminderStrategy::Select(rdbStore, ReminderAlarmTable::TABLE_NAME, + ReminderAlarmTable::SELECT_COLUMNS, reminderId); } -int32_t ReminderAlarmStrategy::Insert(std::shared_ptr rdbStore, const sptr& reminder) +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) +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()); @@ -292,19 +301,23 @@ void ReminderAlarmStrategy::GenValuesBucket(const sptr& reminde values.PutInt(ReminderAlarmTable::REPEAT_DAYS_OF_WEEK, alarm->GetRepeatDaysOfWeek()); } -std::shared_ptr ReminderCalendarStrategy::Select(std::shared_ptr rdbStore, const int32_t reminderId) +std::shared_ptr ReminderCalendarStrategy::Select(std::shared_ptr rdbStore, + const int32_t reminderId) { - return ReminderStrategy::Select(rdbStore, ReminderCalendarTable::TABLE_NAME, ReminderCalendarTable::SELECT_COLUMNS, reminderId); + return ReminderStrategy::Select(rdbStore, ReminderCalendarTable::TABLE_NAME, + ReminderCalendarTable::SELECT_COLUMNS, reminderId); } -int32_t ReminderCalendarStrategy::Insert(std::shared_ptr rdbStore, const sptr& reminder) +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) +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()); @@ -392,19 +405,23 @@ void ReminderCalendarStrategy::GenValuesBucket(const sptr& remi values.PutString(ReminderCalendarTable::EXCLUDE_DATES, calendar->SerializationExcludeDates()); } -std::shared_ptr ReminderTimerStrategy::Select(std::shared_ptr rdbStore, const int32_t reminderId) +std::shared_ptr ReminderTimerStrategy::Select(std::shared_ptr rdbStore, + const int32_t reminderId) { - return ReminderStrategy::Select(rdbStore, ReminderTimerTable::TABLE_NAME, ReminderTimerTable::SELECT_COLUMNS, reminderId); + return ReminderStrategy::Select(rdbStore, ReminderTimerTable::TABLE_NAME, + ReminderTimerTable::SELECT_COLUMNS, reminderId); } -int32_t ReminderTimerStrategy::Insert(std::shared_ptr rdbStore, const sptr& reminder) +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) +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()); -- Gitee