diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 73c3b944784897f0042c2ad3bfd25298564673b2..fb7e08c593a6f7ec59ccf808b46e69ae86520563 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -105,6 +105,7 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/reminder_request_calendar.cpp", "${frameworks_module_ans_path}/src/reminder_request_timer.cpp", "${frameworks_module_ans_path}/src/reminder_store.cpp", + "${frameworks_module_ans_path}/src/reminder_table.cpp", ] public_configs = [ ":ans_innerkits_public_config" ] diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/ans/src/reminder_helper.cpp index 33c84c1a14e4ffaffc97c9b7b4830f35936f9308..6b09c8a314e7af59c004c30ace41d1492637779e 100644 --- a/frameworks/ans/src/reminder_helper.cpp +++ b/frameworks/ans/src/reminder_helper.cpp @@ -58,5 +58,6 @@ ErrCode ReminderHelper::RemoveNotificationSlot(const NotificationConstant::SlotT ANSR_LOGI("RemoveNotificationSlot start"); return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); } + } } \ No newline at end of file diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 8904f2caa6fe637ecf598389e3b3dcf9cfc080d6..90daa5bbd5b2f448c1a458540b668ac27343c233 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -15,6 +15,7 @@ #include "reminder_request.h" +#include "reminder_table.h" #include "ans_const_define.h" #include "ans_log_wrapper.h" #include "bundle_mgr_interface.h" @@ -76,41 +77,6 @@ const uint8_t ReminderRequest::SUNDAY = 7; const uint8_t ReminderRequest::HOURS_PER_DAY = 24; const uint16_t ReminderRequest::SECONDS_PER_HOUR = 3600; -// For database recovery. -const std::string ReminderRequest::REMINDER_ID = "reminder_id"; -const std::string ReminderRequest::PKG_NAME = "package_name"; -const std::string ReminderRequest::USER_ID = "user_id"; -const std::string ReminderRequest::UID = "uid"; -const std::string ReminderRequest::SYS_APP = "system_app"; -const std::string ReminderRequest::APP_LABEL = "app_label"; -const std::string ReminderRequest::REMINDER_TYPE = "reminder_type"; -const std::string ReminderRequest::REMINDER_TIME = "reminder_time"; -const std::string ReminderRequest::TRIGGER_TIME = "trigger_time"; -const std::string ReminderRequest::RTC_TRIGGER_TIME = "rtc_trigger_time"; -const std::string ReminderRequest::TIME_INTERVAL = "time_interval"; -const std::string ReminderRequest::SNOOZE_TIMES = "snooze_times"; -const std::string ReminderRequest::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; -const std::string ReminderRequest::RING_DURATION = "ring_duration"; -const std::string ReminderRequest::IS_EXPIRED = "is_expired"; -const std::string ReminderRequest::IS_ACTIVE = "is_active"; -const std::string ReminderRequest::STATE = "state"; -const std::string ReminderRequest::ZONE_ID = "zone_id"; -const std::string ReminderRequest::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; -const std::string ReminderRequest::ACTION_BUTTON_INFO = "button_info"; -const std::string ReminderRequest::CUSTOM_BUTTON_URI = "custom_button_uri"; -const std::string ReminderRequest::SLOT_ID = "slot_id"; -const std::string ReminderRequest::NOTIFICATION_ID = "notification_id"; -const std::string ReminderRequest::TITLE = "title"; -const std::string ReminderRequest::CONTENT = "content"; -const std::string ReminderRequest::SNOOZE_CONTENT = "snooze_content"; -const std::string ReminderRequest::EXPIRED_CONTENT = "expired_content"; -const std::string ReminderRequest::AGENT = "agent"; -const std::string ReminderRequest::MAX_SCREEN_AGENT = "maxScreen_agent"; -const std::string ReminderRequest::TAP_DISMISSED = "tapDismissed"; -const std::string ReminderRequest::AUTO_DELETED_TIME = "autoDeletedTime"; -const std::string ReminderRequest::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; -const std::string ReminderRequest::GROUP_ID = "groupId"; - std::string ReminderRequest::sqlOfAddColumns = ""; std::vector ReminderRequest::columns; @@ -338,8 +304,8 @@ bool ReminderRequest::HandleTimeZoneChange( if (isExpired_) { return false; } - ANSR_LOGD("Handle timezone change, oldZoneTriggerTime:%{public}" PRIu64 "\ - , newZoneTriggerTime:%{public}" PRIu64 "", oldZoneTriggerTime, newZoneTriggerTime); + ANSR_LOGD("Handle timezone change, old:%{public}" PRIu64 ", new:%{public}" PRIu64 "", + oldZoneTriggerTime, newZoneTriggerTime); if (oldZoneTriggerTime == newZoneTriggerTime) { return false; } @@ -495,119 +461,157 @@ int64_t ReminderRequest::RecoverInt64FromDb(const std::shared_ptr &resultSet) +void ReminderRequest::RecoverBasicFromDb(const std::shared_ptr& resultSet) { - if (resultSet == nullptr) { - ANSR_LOGE("ResultSet is null"); - return; - } - // reminderId - ReminderStore::GetInt32Val(resultSet, REMINDER_ID, reminderId_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::REMINDER_ID, reminderId_); // userId - ReminderStore::GetInt32Val(resultSet, USER_ID, userId_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::USER_ID, userId_); // bundleName - ReminderStore::GetStringVal(resultSet, PKG_NAME, bundleName_); + ReminderStore::GetStringVal(resultSet, ReminderTable::PKG_NAME, bundleName_); // uid - ReminderStore::GetInt32Val(resultSet, UID, uid_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::UID, uid_); // isSystemApp std::string isSysApp; - ReminderStore::GetStringVal(resultSet, SYS_APP, isSysApp); + ReminderStore::GetStringVal(resultSet, ReminderTable::SYS_APP, isSysApp); isSystemApp_ = isSysApp == "true" ? true : false; // reminderType int32_t reminderType; - ReminderStore::GetInt32Val(resultSet, REMINDER_TYPE, reminderType); + ReminderStore::GetInt32Val(resultSet, ReminderTable::REMINDER_TYPE, reminderType); reminderType_ = ReminderType(reminderType); // reminderTime reminderTimeInMilli_ = - static_cast(RecoverInt64FromDb(resultSet, REMINDER_TIME, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REMINDER_TIME, + DbRecoveryType::LONG)); // triggerTime triggerTimeInMilli_ = - static_cast(RecoverInt64FromDb(resultSet, TRIGGER_TIME, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::TRIGGER_TIME, + DbRecoveryType::LONG)); // timeInterval uint64_t timeIntervalInSecond = - static_cast(RecoverInt64FromDb(resultSet, TIME_INTERVAL, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::TIME_INTERVAL, + DbRecoveryType::LONG)); SetTimeInterval(timeIntervalInSecond); // snoozeTimes - snoozeTimes_ = static_cast(RecoverInt64FromDb(resultSet, SNOOZE_TIMES, DbRecoveryType::INT)); + snoozeTimes_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::SNOOZE_TIMES, + DbRecoveryType::INT)); // dynamicSnoozeTimes snoozeTimesDynamic_ = - static_cast(RecoverInt64FromDb(resultSet, DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::DYNAMIC_SNOOZE_TIMES, + DbRecoveryType::INT)); // ringDuration uint64_t ringDurationInSecond = - static_cast(RecoverInt64FromDb(resultSet, RING_DURATION, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::RING_DURATION, + DbRecoveryType::LONG)); SetRingDuration(ringDurationInSecond); // isExpired std::string isExpired; - ReminderStore::GetStringVal(resultSet, IS_EXPIRED, isExpired); + ReminderStore::GetStringVal(resultSet, ReminderTable::IS_EXPIRED, + isExpired); isExpired_ = isExpired == "true" ? true : false; // state - state_ = static_cast(RecoverInt64FromDb(resultSet, STATE, DbRecoveryType::INT)); + state_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::STATE, + DbRecoveryType::INT)); // repeatDaysOfWeek_ - repeatDaysOfWeek_ = static_cast(RecoverInt64FromDb(resultSet, REPEAT_DAYS_OF_WEEK, DbRecoveryType::INT)); - + repeatDaysOfWeek_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_DAYS_OF_WEEK, + DbRecoveryType::INT)); + // action buttons RecoverActionButton(resultSet); // slotType int32_t slotType; - ReminderStore::GetInt32Val(resultSet, SLOT_ID, slotType); + ReminderStore::GetInt32Val(resultSet, ReminderTable::SLOT_ID, slotType); slotType_ = NotificationConstant::SlotType(slotType); // notification id - ReminderStore::GetInt32Val(resultSet, NOTIFICATION_ID, notificationId_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::NOTIFICATION_ID, notificationId_); // title - ReminderStore::GetStringVal(resultSet, TITLE, title_); + ReminderStore::GetStringVal(resultSet, ReminderTable::TITLE, title_); // content - ReminderStore::GetStringVal(resultSet, CONTENT, content_); + ReminderStore::GetStringVal(resultSet, ReminderTable::CONTENT, content_); // snoozeContent - ReminderStore::GetStringVal(resultSet, SNOOZE_CONTENT, snoozeContent_); + ReminderStore::GetStringVal(resultSet, ReminderTable::SNOOZE_CONTENT, snoozeContent_); // expiredContent - ReminderStore::GetStringVal(resultSet, EXPIRED_CONTENT, expiredContent_); + ReminderStore::GetStringVal(resultSet, ReminderTable::EXPIRED_CONTENT, expiredContent_); InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent +} + +void ReminderRequest::RecoverFromDb(const std::shared_ptr &resultSet) +{ + if (resultSet == nullptr) { + ANSR_LOGE("ResultSet is null"); + return; + } + + RecoverBasicFromDb(resultSet); // wantAgent std::string wantAgent; - ReminderStore::GetStringVal(resultSet, AGENT, wantAgent); + ReminderStore::GetStringVal(resultSet, ReminderTable::AGENT, wantAgent); RecoverWantAgent(wantAgent, 0); // maxScreenWantAgent std::string maxScreenWantAgent; - ReminderStore::GetStringVal(resultSet, MAX_SCREEN_AGENT, maxScreenWantAgent); + ReminderStore::GetStringVal(resultSet, ReminderTable::MAX_SCREEN_AGENT, maxScreenWantAgent); RecoverWantAgent(maxScreenWantAgent, 1); // tapDismissed std::string tapDismissed; - ReminderStore::GetStringVal(resultSet, TAP_DISMISSED, tapDismissed); + ReminderStore::GetStringVal(resultSet, ReminderTable::TAP_DISMISSED, tapDismissed); tapDismissed_ = tapDismissed == "true" ? true : false; // autoDeletedTime autoDeletedTime_ = - static_cast(RecoverInt64FromDb(resultSet, AUTO_DELETED_TIME, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::AUTO_DELETED_TIME, + DbRecoveryType::LONG)); // customButtonUri - ReminderStore::GetStringVal(resultSet, CUSTOM_BUTTON_URI, customButtonUri_); + ReminderStore::GetStringVal(resultSet, ReminderTable::CUSTOM_BUTTON_URI, customButtonUri_); // groupId - ReminderStore::GetStringVal(resultSet, GROUP_ID, groupId_); + ReminderStore::GetStringVal(resultSet, ReminderTable::GROUP_ID, groupId_); +} + +void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) +{ + nlohmann::json root = nlohmann::json::parse(jsonString); + std::string type = root.at("type").get(); + std::string title = root.at("title").get(); + std::string resource = root.at("resource").get(); + auto buttonWantAgent = std::make_shared(); + if (!root["wantAgent"].empty()) { + nlohmann::json wantAgent = root["wantAgent"]; + buttonWantAgent->pkgName = wantAgent.at("pkgName").get(); + buttonWantAgent->abilityName = wantAgent.at("abilityName").get(); + } + auto buttonDataShareUpdate = std::make_shared(); + if (!root["dataShareUpdate"].empty()) { + nlohmann::json dataShareUpdate = root["dataShareUpdate"]; + buttonDataShareUpdate->uri = dataShareUpdate.at("uri").get(); + buttonDataShareUpdate->equalTo = dataShareUpdate.at("equalTo").get(); + buttonDataShareUpdate->valuesBucket = dataShareUpdate.at("valuesBucket").get(); + } + SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)), + resource, buttonWantAgent, buttonDataShareUpdate); } void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) @@ -617,7 +621,7 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptr multiButton = StringSplit(actionButtonInfo, SEP_BUTTON_MULTI); for (auto button : multiButton) { std::vector singleButton = StringSplit(button, SEP_BUTTON_SINGLE); @@ -627,25 +631,7 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptr(); - std::string title = root.at("title").get(); - std::string resource = root.at("resource").get(); - auto buttonWantAgent = std::make_shared(); - if (!root["wantAgent"].empty()) { - nlohmann::json wantAgent = root["wantAgent"]; - buttonWantAgent->pkgName = wantAgent.at("pkgName").get(); - buttonWantAgent->abilityName = wantAgent.at("abilityName").get(); - } - auto buttonDataShareUpdate = std::make_shared(); - if (!root["dataShareUpdate"].empty()) { - nlohmann::json dataShareUpdate = root["dataShareUpdate"]; - buttonDataShareUpdate->uri = dataShareUpdate.at("uri").get(); - buttonDataShareUpdate->equalTo = dataShareUpdate.at("equalTo").get(); - buttonDataShareUpdate->valuesBucket = dataShareUpdate.at("valuesBucket").get(); - } - SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)), - resource, buttonWantAgent, buttonDataShareUpdate); + RecoverActionButtonJsonMode(jsonString); continue; } // old method Soon to be deleted @@ -1041,6 +1027,39 @@ void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std } } +bool ReminderRequest::MarshallingActionButton(Parcel& parcel) const +{ + // write map + uint64_t actionButtonMapSize = static_cast(actionButtonMap_.size()); + WRITE_UINT64_RETURN_FALSE_LOG(parcel, actionButtonMapSize, "actionButtonMapSize"); + for (auto button : actionButtonMap_) { + uint8_t buttonType = static_cast(button.first); + WRITE_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.title, "buttonTitle"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.resource, "buttonResource"); + + if (button.second.wantAgent == nullptr) { + ANSR_LOGE("button wantAgent is null"); + return false; + } + + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->pkgName, "wantAgent's pkgName"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->abilityName, "wantAgent's abilityName"); + + if (button.second.dataShareUpdate == nullptr) { + ANSR_LOGE("button dataShareUpdate is null"); + return false; + } + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->uri, + "dataShareUpdate's uri"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->equalTo, + "dataShareUpdate's equalTo"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->valuesBucket, + "dataShareUpdate's valuesBucket"); + } + return true; +} + bool ReminderRequest::Marshalling(Parcel &parcel) const { // write string @@ -1082,30 +1101,8 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const int32_t slotType = static_cast(slotType_); WRITE_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); - // write map - uint64_t actionButtonMapSize = static_cast(actionButtonMap_.size()); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, actionButtonMapSize, "actionButtonMapSize"); - for (auto button : actionButtonMap_) { - uint8_t buttonType = static_cast(button.first); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.title, "buttonTitle"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.resource, "buttonResource"); - - if (button.second.wantAgent == nullptr) { - ANSR_LOGE("button wantAgent is null"); - return false; - } - - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->pkgName, "wantAgent's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->abilityName, "wantAgent's abilityName"); - - if (button.second.dataShareUpdate == nullptr) { - ANSR_LOGE("button dataShareUpdate is null"); - return false; - } - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->uri, "dataShareUpdate's uri"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->equalTo, "dataShareUpdate's equalTo"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->valuesBucket, "dataShareUpdate's valuesBucket"); + if (!MarshallingActionButton(parcel)) { + return false; } return true; } @@ -1124,6 +1121,38 @@ ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) return objptr; } +bool ReminderRequest::ReadActionButtonFromParcel(Parcel& parcel) +{ + uint64_t buttonMapSize = 0; + READ_UINT64_RETURN_FALSE_LOG(parcel, buttonMapSize, "actionButtonMapSize"); + buttonMapSize = (buttonMapSize < MAX_ACTION_BUTTON_NUM) ? buttonMapSize : MAX_ACTION_BUTTON_NUM; + for (uint64_t i = 0; i < buttonMapSize; i++) { + uint8_t buttonType = static_cast(ActionButtonType::INVALID); + READ_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); + ActionButtonType type = static_cast(buttonType); + std::string title = parcel.ReadString(); + std::string resource = parcel.ReadString(); + std::string pkgName = parcel.ReadString(); + std::string abilityName = parcel.ReadString(); + std::string uri = parcel.ReadString(); + std::string equalTo = parcel.ReadString(); + std::string valuesBucket = parcel.ReadString(); + ActionButtonInfo info; + info.type = type; + info.title = title; + info.resource = resource; + info.wantAgent = std::make_shared(); + info.wantAgent->pkgName = pkgName; + info.wantAgent->abilityName = abilityName; + info.dataShareUpdate = std::make_shared(); + info.dataShareUpdate->uri = uri; + info.dataShareUpdate->equalTo = equalTo; + info.dataShareUpdate->valuesBucket = valuesBucket; + actionButtonMap_.insert(std::pair(type, info)); + } + return true; +} + bool ReminderRequest::ReadFromParcel(Parcel &parcel) { READ_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); @@ -1168,33 +1197,10 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); slotType_ = static_cast(slotType); - uint64_t buttonMapSize = 0; - READ_UINT64_RETURN_FALSE_LOG(parcel, buttonMapSize, "actionButtonMapSize"); - buttonMapSize = (buttonMapSize < MAX_ACTION_BUTTON_NUM) ? buttonMapSize : MAX_ACTION_BUTTON_NUM; - for (uint64_t i = 0; i < buttonMapSize; i++) { - uint8_t buttonType = static_cast(ActionButtonType::INVALID); - READ_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); - ActionButtonType type = static_cast(buttonType); - std::string title = parcel.ReadString(); - std::string resource = parcel.ReadString(); - std::string pkgName = parcel.ReadString(); - std::string abilityName = parcel.ReadString(); - std::string uri = parcel.ReadString(); - std::string equalTo = parcel.ReadString(); - std::string valuesBucket = parcel.ReadString(); - ActionButtonInfo info; - info.type = type; - info.title = title; - info.resource = resource; - info.wantAgent = std::make_shared(); - info.wantAgent->pkgName = pkgName; - info.wantAgent->abilityName = abilityName; - info.dataShareUpdate = std::make_shared(); - info.dataShareUpdate->uri = uri; - info.dataShareUpdate->equalTo = equalTo; - info.dataShareUpdate->valuesBucket = valuesBucket; - actionButtonMap_.insert(std::pair(type, info)); + if (!ReadActionButtonFromParcel(parcel)) { + return false; } + if (!InitNotificationRequest()) { return false; } @@ -1690,106 +1696,67 @@ int32_t ReminderRequest::GetUserId(const int32_t &uid) return userId; } -void ReminderRequest::AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values) +void ReminderRequest::AppendWantAgentValuesBucket(const sptr& reminder, + NativeRdb::ValuesBucket& values) { - values.PutInt(REMINDER_ID, reminder->GetReminderId()); - values.PutString(PKG_NAME, bundleOption->GetBundleName()); - values.PutInt(USER_ID, reminder->GetUserId()); - values.PutInt(UID, reminder->GetUid()); - values.PutString(SYS_APP, reminder->IsSystemApp() ? "true" : "false"); - values.PutString(APP_LABEL, ""); // no use, compatible with old version. - values.PutInt(REMINDER_TYPE, static_cast(reminder->GetReminderType())); - values.PutLong(REMINDER_TIME, reminder->GetReminderTimeInMilli()); - values.PutLong(TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); - values.PutLong( - RTC_TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); // no use, compatible with old version. - values.PutLong(TIME_INTERVAL, reminder->GetTimeInterval()); - values.PutInt(SNOOZE_TIMES, reminder->GetSnoozeTimes()); - values.PutInt(DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic()); - values.PutLong(RING_DURATION, reminder->GetRingDuration()); - values.PutString(IS_EXPIRED, reminder->IsExpired() ? "true" : "false"); - values.PutString(IS_ACTIVE, ""); // no use, compatible with old version. - values.PutInt(STATE, reminder->GetState()); - values.PutString(ZONE_ID, ""); // no use, compatible with old version. - values.PutString(HAS_SCHEDULED_TIMEOUT, ""); // no use, compatible with old version. - values.PutString(ACTION_BUTTON_INFO, reminder->GetButtonInfo()); - values.PutString(CUSTOM_BUTTON_URI, reminder->GetCustomButtonUri()); - values.PutInt(SLOT_ID, reminder->GetSlotType()); - values.PutInt(NOTIFICATION_ID, reminder->GetNotificationId()); - values.PutString(TITLE, reminder->GetTitle()); - values.PutString(CONTENT, reminder->GetContent()); - values.PutString(SNOOZE_CONTENT, reminder->GetSnoozeContent()); - values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); - values.PutInt(REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); - values.PutString(GROUP_ID, reminder->GetGroupId()); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; - values.PutString(AGENT, info); + values.PutString(ReminderTable::AGENT, info); } else { std::string info = wantAgentInfo->pkgName + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->uri; - values.PutString(AGENT, info); + values.PutString(ReminderTable::AGENT, info); } + auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); if (maxScreenWantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; - values.PutString(MAX_SCREEN_AGENT, info); + values.PutString(ReminderTable::MAX_SCREEN_AGENT, info); } else { - values.PutString(MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + values.PutString(ReminderTable::MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); } - values.PutString(TAP_DISMISSED, reminder->IsTapDismissed() ? "true" : "false"); - values.PutLong(AUTO_DELETED_TIME, reminder->GetAutoDeletedTime()); -} - -void ReminderRequest::InitDbColumns() -{ - AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", false); - AddColumn(PKG_NAME, "TEXT NOT NULL", false); - AddColumn(USER_ID, "INT NOT NULL", false); - AddColumn(UID, "INT NOT NULL", false); - AddColumn(SYS_APP, "TEXT NOT NULL", false); - AddColumn(APP_LABEL, "TEXT", false); - AddColumn(REMINDER_TYPE, "INT NOT NULL", false); - AddColumn(REMINDER_TIME, "BIGINT NOT NULL", false); - AddColumn(TRIGGER_TIME, "BIGINT NOT NULL", false); - AddColumn(RTC_TRIGGER_TIME, "BIGINT NOT NULL", false); - AddColumn(TIME_INTERVAL, "BIGINT NOT NULL", false); - AddColumn(SNOOZE_TIMES, "INT NOT NULL", false); - AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL", false); - AddColumn(RING_DURATION, "BIGINT NOT NULL", false); - AddColumn(IS_EXPIRED, "TEXT NOT NULL", false); - AddColumn(IS_ACTIVE, "TEXT NOT NULL", false); - AddColumn(STATE, "INT NOT NULL", false); - AddColumn(ZONE_ID, "TEXT", false); - AddColumn(HAS_SCHEDULED_TIMEOUT, "TEXT", false); - AddColumn(ACTION_BUTTON_INFO, "TEXT", false); - AddColumn(CUSTOM_BUTTON_URI, "TEXT", false); - AddColumn(SLOT_ID, "INT", false); - AddColumn(NOTIFICATION_ID, "INT NOT NULL", false); - AddColumn(TITLE, "TEXT", false); - AddColumn(CONTENT, "TEXT", false); - AddColumn(SNOOZE_CONTENT, "TEXT", false); - AddColumn(EXPIRED_CONTENT, "TEXT", false); - AddColumn(AGENT, "TEXT", false); - AddColumn(MAX_SCREEN_AGENT, "TEXT", false); - AddColumn(TAP_DISMISSED, "TEXT", false); - AddColumn(AUTO_DELETED_TIME, "BIGINT", false); - AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); - AddColumn(GROUP_ID, "TEXT", false); -} - -void ReminderRequest::AddColumn( - const std::string &name, const std::string &type, const bool &isEnd) -{ - columns.push_back(name); - if (!isEnd) { - sqlOfAddColumns += name + " " + type + ", "; - } else { - sqlOfAddColumns += name + " " + type; - } +} + +void ReminderRequest::AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + values.PutInt(ReminderTable::REMINDER_ID, reminder->GetReminderId()); + values.PutString(ReminderTable::PKG_NAME, bundleOption->GetBundleName()); + values.PutInt(ReminderTable::USER_ID, reminder->GetUserId()); + values.PutInt(ReminderTable::UID, reminder->GetUid()); + values.PutString(ReminderTable::SYS_APP, reminder->IsSystemApp() ? "true" : "false"); + values.PutString(ReminderTable::APP_LABEL, ""); // no use, compatible with old version. + values.PutInt(ReminderTable::REMINDER_TYPE, static_cast(reminder->GetReminderType())); + values.PutLong(ReminderTable::REMINDER_TIME, reminder->GetReminderTimeInMilli()); + values.PutLong(ReminderTable::TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); + values.PutLong( + ReminderTable::RTC_TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); // no use, compatible with old version. + values.PutLong(ReminderTable::TIME_INTERVAL, reminder->GetTimeInterval()); + values.PutInt(ReminderTable::SNOOZE_TIMES, reminder->GetSnoozeTimes()); + values.PutInt(ReminderTable::DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic()); + values.PutLong(ReminderTable::RING_DURATION, reminder->GetRingDuration()); + values.PutString(ReminderTable::IS_EXPIRED, reminder->IsExpired() ? "true" : "false"); + values.PutString(ReminderTable::IS_ACTIVE, ""); // no use, compatible with old version. + values.PutInt(ReminderTable::STATE, reminder->GetState()); + values.PutString(ReminderTable::ZONE_ID, ""); // no use, compatible with old version. + values.PutString(ReminderTable::HAS_SCHEDULED_TIMEOUT, ""); // no use, compatible with old version. + values.PutString(ReminderTable::ACTION_BUTTON_INFO, reminder->GetButtonInfo()); + values.PutString(ReminderTable::CUSTOM_BUTTON_URI, reminder->GetCustomButtonUri()); + values.PutInt(ReminderTable::SLOT_ID, reminder->GetSlotType()); + values.PutInt(ReminderTable::NOTIFICATION_ID, reminder->GetNotificationId()); + values.PutString(ReminderTable::TITLE, reminder->GetTitle()); + values.PutString(ReminderTable::CONTENT, reminder->GetContent()); + values.PutString(ReminderTable::SNOOZE_CONTENT, reminder->GetSnoozeContent()); + values.PutString(ReminderTable::EXPIRED_CONTENT, reminder->GetExpiredContent()); + values.PutInt(ReminderTable::REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); + values.PutString(ReminderTable::GROUP_ID, reminder->GetGroupId()); + + AppendWantAgentValuesBucket(reminder, values); + + values.PutString(ReminderTable::TAP_DISMISSED, reminder->IsTapDismissed() ? "true" : "false"); + values.PutLong(ReminderTable::AUTO_DELETED_TIME, reminder->GetAutoDeletedTime()); } int64_t ReminderRequest::GetNextDaysOfWeek(const time_t now, const time_t target) const @@ -1904,5 +1871,6 @@ void ReminderRequest::OnLanguageChange(const std::shared_ptr daysOfWeek) : ReminderRequest(ReminderRequest::ReminderType::ALARM) { @@ -203,11 +200,13 @@ void ReminderRequestAlarm::RecoverFromDb(const std::shared_ptr(RecoverInt64FromDb(resultSet, ALARM_HOUR, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::ALARM_HOUR, + DbRecoveryType::INT)); // minute minute_ = - static_cast(RecoverInt64FromDb(resultSet, ALARM_MINUTE, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::ALARM_MINUTE, + DbRecoveryType::INT)); } void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder, @@ -220,14 +219,9 @@ void ReminderRequestAlarm::AppendValuesBucket(const sptr &remin hour = alarm->GetHour(); minute = alarm->GetMinute(); } - values.PutInt(ALARM_HOUR, hour); - values.PutInt(ALARM_MINUTE, minute); + values.PutInt(ReminderTable::ALARM_HOUR, hour); + values.PutInt(ReminderTable::ALARM_MINUTE, minute); } -void ReminderRequestAlarm::InitDbColumns() -{ - ReminderRequest::AddColumn(ALARM_HOUR, "INT", false); - ReminderRequest::AddColumn(ALARM_MINUTE, "INT", true); -} } } \ 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 4f6a3bbba78e9ad250db22637b37a142d4d6b851..6aedbd1cb7938b8e84aa66063479c05d56eb4045 100644 --- a/frameworks/ans/src/reminder_request_calendar.cpp +++ b/frameworks/ans/src/reminder_request_calendar.cpp @@ -15,6 +15,7 @@ #include "reminder_request_calendar.h" +#include "reminder_table.h" #include "ans_log_wrapper.h" namespace OHOS { @@ -25,18 +26,6 @@ const uint8_t ReminderRequestCalendar::JANUARY = 1; const uint8_t ReminderRequestCalendar::DECEMBER = 12; const uint8_t ReminderRequestCalendar::DEFAULT_SNOOZE_TIMES = 3; -// For database recovery. -const std::string ReminderRequestCalendar::REPEAT_DAYS = "repeat_days"; -const std::string ReminderRequestCalendar::REPEAT_MONTHS = "repeat_months"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_YEAR = "first_designate_year"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_MONTH = "first_designate_month"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_DAY = "first_designate_day"; -const std::string ReminderRequestCalendar::CALENDAR_YEAR = "calendar_year"; -const std::string ReminderRequestCalendar::CALENDAR_MONTH = "calendar_month"; -const std::string ReminderRequestCalendar::CALENDAR_DAY = "calendar_day"; -const std::string ReminderRequestCalendar::CALENDAR_HOUR = "calendar_hour"; -const std::string ReminderRequestCalendar::CALENDAR_MINUTE = "calendar_minute"; - const uint8_t ReminderRequestCalendar::DAY_ARRAY[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const uint8_t ReminderRequestCalendar::FEBRUARY = 2; const uint8_t ReminderRequestCalendar::LEAP_MONTH = 29; @@ -466,38 +455,48 @@ void ReminderRequestCalendar::RecoverFromDb(const std::shared_ptr(RecoverInt64FromDb(resultSet, REPEAT_DAYS, DbRecoveryType::INT)); + repeatDay_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_DAYS, + DbRecoveryType::INT)); // repeatMonth repeatMonth_ = - static_cast(RecoverInt64FromDb(resultSet, REPEAT_MONTHS, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_MONTHS, + DbRecoveryType::INT)); // firstDesignateYear firstDesignateYear_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_YEAR, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_YEAR, + DbRecoveryType::INT)); // firstDesignateMonth firstDesignateMonth_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_MONTH, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_MONTH, + DbRecoveryType::INT)); // firstDesignateDay firstDesignateDay_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_DAY, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_DAY, + DbRecoveryType::INT)); // year - year_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_YEAR, DbRecoveryType::INT)); + year_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_YEAR, + DbRecoveryType::INT)); // month - month_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_MONTH, DbRecoveryType::INT)); + month_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MONTH, + DbRecoveryType::INT)); // day - day_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_DAY, DbRecoveryType::INT)); + day_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_DAY, + DbRecoveryType::INT)); // hour - hour_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_HOUR, DbRecoveryType::INT)); + hour_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_HOUR, + DbRecoveryType::INT)); // minute - minute_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_MINUTE, DbRecoveryType::INT)); + minute_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MINUTE, + DbRecoveryType::INT)); } void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, @@ -528,30 +527,17 @@ void ReminderRequestCalendar::AppendValuesBucket(const sptr &re minute = calendar->GetMinute(); } } - values.PutInt(REPEAT_DAYS, repeatDay); - values.PutInt(REPEAT_MONTHS, repeatMonth); - values.PutInt(FIRST_DESIGNATE_YEAR, firstDesignateYear); - values.PutInt(FIRST_DESIGNATE_MONTH, firstDesignateMonth); - values.PutInt(FIRST_DESIGNATE_DAY, firstDesignateDay); - values.PutInt(CALENDAR_YEAR, year); - values.PutInt(CALENDAR_MONTH, month); - values.PutInt(CALENDAR_DAY, day); - values.PutInt(CALENDAR_HOUR, hour); - values.PutInt(CALENDAR_MINUTE, minute); + values.PutInt(ReminderTable::REPEAT_DAYS, repeatDay); + values.PutInt(ReminderTable::REPEAT_MONTHS, repeatMonth); + values.PutInt(ReminderTable::FIRST_DESIGNATE_YEAR, firstDesignateYear); + values.PutInt(ReminderTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth); + values.PutInt(ReminderTable::FIRST_DESIGNATE_DAY, firstDesignateDay); + values.PutInt(ReminderTable::CALENDAR_YEAR, year); + values.PutInt(ReminderTable::CALENDAR_MONTH, month); + values.PutInt(ReminderTable::CALENDAR_DAY, day); + values.PutInt(ReminderTable::CALENDAR_HOUR, hour); + values.PutInt(ReminderTable::CALENDAR_MINUTE, minute); } -void ReminderRequestCalendar::InitDbColumns() -{ - ReminderRequest::AddColumn(REPEAT_DAYS, "INT", false); - ReminderRequest::AddColumn(REPEAT_MONTHS, "INT", false); - ReminderRequest::AddColumn(FIRST_DESIGNATE_YEAR, "INT", false); - ReminderRequest::AddColumn(FIRST_DESIGNATE_MONTH, "INT", false); - ReminderRequest::AddColumn(FIRST_DESIGNATE_DAY, "INT", false); - ReminderRequest::AddColumn(CALENDAR_YEAR, "INT", false); - ReminderRequest::AddColumn(CALENDAR_MONTH, "INT", false); - ReminderRequest::AddColumn(CALENDAR_DAY, "INT", false); - ReminderRequest::AddColumn(CALENDAR_HOUR, "INT", false); - ReminderRequest::AddColumn(CALENDAR_MINUTE, "INT", false); -} } } diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/ans/src/reminder_request_timer.cpp index e8827184ab4b1aee762ea35036fb39c978814ac5..67bbe1362d3704d48ea842a6fb5d7528b6070463 100644 --- a/frameworks/ans/src/reminder_request_timer.cpp +++ b/frameworks/ans/src/reminder_request_timer.cpp @@ -94,6 +94,7 @@ void ReminderRequestTimer::UpdateTimeInfo(const std::string &description) if (IsExpired()) { return; } + ANSR_LOGD("%{public}s, update countdown time trigger time", description.c_str()); time_t now; (void)time(&now); // unit is seconds. @@ -147,5 +148,6 @@ bool ReminderRequestTimer::ReadFromParcel(Parcel &parcel) } return false; } + } } diff --git a/frameworks/ans/src/reminder_store.cpp b/frameworks/ans/src/reminder_store.cpp index 93b0486a5bb9e88aa00f324c3c5bba54d280b2aa..e015731f3448f971ee9084c9e4d26e088432d612 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/frameworks/ans/src/reminder_store.cpp @@ -22,6 +22,7 @@ #include "ability_context.h" #include "ans_log_wrapper.h" +#include "reminder_table.h" #include "reminder_request_alarm.h" #include "reminder_request_calendar.h" #include "reminder_request_timer.h" @@ -31,7 +32,6 @@ namespace Notification { namespace { const uint32_t REMINDER_RDB_VERSION = 2; const int32_t STATE_FAIL = -1; -std::vector columns; std::string g_sqlColumns; } @@ -44,7 +44,7 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore & { ANSR_LOGD("Create table."); std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" - + ReminderRequest::sqlOfAddColumns + ")"; + + ReminderTable::sqlOfAddColumns + ")"; ANSR_LOGD("CreateTable:%{public}s", CREATE_REMINDER_TABLE.c_str()); return store.ExecuteSql(CREATE_REMINDER_TABLE); } @@ -73,12 +73,10 @@ int32_t ReminderStore::Init() } } - ReminderRequest::InitDbColumns(); - ReminderRequestCalendar::InitDbColumns(); - ReminderRequestAlarm::InitDbColumns(); - columns.insert(columns.begin(), - ReminderRequest::columns.begin(), ReminderRequest::columns.end()); - for (std::vector::const_iterator it = columns.begin(); it != columns.end(); ++it) { + ReminderTable::InitDbColumns(); + for (std::vector::const_iterator it = ReminderTable::columns.begin(); + it != ReminderTable::columns.end(); + ++it) { g_sqlColumns += *it + ","; } g_sqlColumns = g_sqlColumns.substr(0, g_sqlColumns.size() - 1); @@ -103,12 +101,12 @@ int32_t ReminderStore::InitData() ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - std::string deleteCondition = ReminderRequest::IS_EXPIRED + " is true"; + std::string deleteCondition = ReminderTable::IS_EXPIRED + " is true"; ReminderStore::Delete(deleteCondition); int32_t statusChangedRows = STATE_FAIL; NativeRdb::ValuesBucket statusValues; - statusValues.PutInt(ReminderRequest::STATE, ReminderRequest::REMINDER_STATUS_INACTIVE); + statusValues.PutInt(ReminderTable::STATE, ReminderRequest::REMINDER_STATUS_INACTIVE); int32_t statusResult = rdbStore_->Update(statusChangedRows, REMINDER_DB_TABLE, statusValues); ANSR_LOGD("Change status to inactive, changed rows: %{public}d.", statusChangedRows); if (statusResult != NativeRdb::E_OK) { @@ -118,8 +116,8 @@ int32_t ReminderStore::InitData() int32_t activeChangedRows = STATE_FAIL; NativeRdb::ValuesBucket activeValues; - activeValues.PutString(ReminderRequest::IS_ACTIVE, "false"); - std::string activeUpdateCondition = ReminderRequest::IS_ACTIVE + " is true"; + activeValues.PutString(ReminderTable::IS_ACTIVE, "false"); + std::string activeUpdateCondition = ReminderTable::IS_ACTIVE + " is true"; std::vector activeWhereArgs; int32_t activeResult = rdbStore_->Update( activeChangedRows, REMINDER_DB_TABLE, activeValues, activeUpdateCondition, activeWhereArgs); @@ -131,8 +129,8 @@ int32_t ReminderStore::InitData() int32_t scheduledChangedRows = STATE_FAIL; NativeRdb::ValuesBucket scheduledValues; - scheduledValues.PutString(ReminderRequest::HAS_SCHEDULED_TIMEOUT, "false"); - std::string scheduledUpdateCondition = ReminderRequest::HAS_SCHEDULED_TIMEOUT + " is true"; + scheduledValues.PutString(ReminderTable::HAS_SCHEDULED_TIMEOUT, "false"); + std::string scheduledUpdateCondition = ReminderTable::HAS_SCHEDULED_TIMEOUT + " is true"; std::vector scheduledWhereArgs; int32_t scheduledResult = rdbStore_->Update( scheduledChangedRows, REMINDER_DB_TABLE, scheduledValues, scheduledUpdateCondition, scheduledWhereArgs); @@ -146,21 +144,21 @@ int32_t ReminderStore::InitData() int32_t ReminderStore::Delete(int32_t reminderId) { - std::string deleteCondition = ReminderRequest::REMINDER_ID + std::string deleteCondition = ReminderTable ::REMINDER_ID + " = " + std::to_string(reminderId); return ReminderStore::Delete(deleteCondition); } int32_t ReminderStore::DeleteUser(int32_t userId) { - std::string deleteCondition = ReminderRequest::USER_ID + " = " + std::to_string(userId); + std::string deleteCondition = ReminderTable::USER_ID + " = " + std::to_string(userId); return ReminderStore::Delete(deleteCondition); } int32_t ReminderStore::Delete(const std::string &pkg, int32_t userId) { - std::string deleteCondition = ReminderRequest::PKG_NAME + " = \"" + pkg + "\" and " - + ReminderRequest::USER_ID + " = " + std::to_string(userId); + std::string deleteCondition = ReminderTable::PKG_NAME + " = \"" + pkg + "\" and " + + ReminderTable::USER_ID + " = " + std::to_string(userId); return ReminderStore::Delete(deleteCondition); } @@ -236,7 +234,7 @@ int64_t ReminderStore::Update( int32_t changedRows = STATE_FAIL; NativeRdb::ValuesBucket values; ReminderStore::GenerateData(reminder, bundleOption, values); - std::string updateCondition = ReminderRequest::REMINDER_ID + std::string updateCondition = ReminderTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); std::vector whereArgs; int32_t result = rdbStore_->Update(changedRows, REMINDER_DB_TABLE, values, updateCondition, whereArgs); @@ -253,7 +251,7 @@ int64_t ReminderStore::Update( bool ReminderStore::IsReminderExist(const sptr &reminder) { NativeRdb::AbsRdbPredicates absRdbPredicates(REMINDER_DB_TABLE); - absRdbPredicates.EqualTo(ReminderRequest::REMINDER_ID, std::to_string(reminder->GetReminderId())); + absRdbPredicates.EqualTo(ReminderTable::REMINDER_ID, std::to_string(reminder->GetReminderId())); auto queryResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (queryResultSet == nullptr) { ANSR_LOGE("QueryResultSet is null."); @@ -284,9 +282,9 @@ int32_t ReminderStore::GetMaxId() ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - std::string queryCondition = "select " + ReminderRequest::REMINDER_ID + std::string queryCondition = "select " + ReminderTable::REMINDER_ID + " from " + REMINDER_DB_TABLE + " order by " - + ReminderRequest::REMINDER_ID + " desc"; + + ReminderTable::REMINDER_ID + " desc"; auto queryResultSet = ReminderStore::Query(queryCondition); if (queryResultSet == nullptr) { ANSR_LOGE("QueryResultSet is null."); @@ -310,12 +308,11 @@ int32_t ReminderStore::GetMaxId() std::vector> ReminderStore::GetAllValidReminders() { - std::string queryCondition = "select " + g_sqlColumns + " from " + REMINDER_DB_TABLE + " where " - + ReminderRequest::IS_EXPIRED + " is false order by " - + ReminderRequest::TRIGGER_TIME + " asc"; - ANSR_LOGD("Get all reminders"); - ANSR_LOGD("ReminderStore GetAllValidReminders queryCondition =%{public}s", queryCondition.c_str()); - return GetReminders(queryCondition); + std::string sql = "select " + g_sqlColumns + " from " + REMINDER_DB_TABLE + " where " + + ReminderTable::IS_EXPIRED + " = 'false' order by " + + ReminderTable::TRIGGER_TIME + " asc"; + ANSR_LOGD("GetAllValidReminders sql =%{public}s", sql.c_str()); + return GetReminders(sql); } std::vector> ReminderStore::GetReminders(const std::string &queryCondition) @@ -347,8 +344,8 @@ sptr ReminderStore::BuildReminder(const std::shared_ptr reminder = nullptr; switch (reminderType) { @@ -385,7 +382,7 @@ bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptr queryResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (queryResultSet == nullptr) { @@ -398,9 +395,9 @@ bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptrGoToNextRow(); std::string pkgName; - GetStringVal(queryResultSet, ReminderRequest::PKG_NAME, pkgName); + GetStringVal(queryResultSet, ReminderTable ::PKG_NAME, pkgName); int32_t uid; - GetInt32Val(queryResultSet, ReminderRequest::UID, uid); + GetInt32Val(queryResultSet, ReminderTable::UID, uid); bundleOption->SetBundleName(pkgName); bundleOption->SetUid(uid); return true; @@ -449,5 +446,6 @@ void ReminderStore::GenerateData(const sptr &reminder, ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); } + } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/src/reminder_table.cpp b/frameworks/ans/src/reminder_table.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2989683c59bf0fc48ec2cc79f4e6ba3eaeade01f --- /dev/null +++ b/frameworks/ans/src/reminder_table.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2023 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_table.h" + +namespace OHOS { +namespace Notification { +// Reminder Table Basic Columns. +const std::string ReminderTable::REMINDER_ID = "reminder_id"; +const std::string ReminderTable::PKG_NAME = "package_name"; +const std::string ReminderTable::USER_ID = "user_id"; +const std::string ReminderTable::UID = "uid"; +const std::string ReminderTable::SYS_APP = "system_app"; +const std::string ReminderTable::APP_LABEL = "app_label"; +const std::string ReminderTable::REMINDER_TYPE = "reminder_type"; +const std::string ReminderTable::REMINDER_TIME = "reminder_time"; +const std::string ReminderTable::TRIGGER_TIME = "trigger_time"; +const std::string ReminderTable::RTC_TRIGGER_TIME = "rtc_trigger_time"; +const std::string ReminderTable::TIME_INTERVAL = "time_interval"; +const std::string ReminderTable::SNOOZE_TIMES = "snooze_times"; +const std::string ReminderTable::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; +const std::string ReminderTable::RING_DURATION = "ring_duration"; +const std::string ReminderTable::IS_EXPIRED = "is_expired"; +const std::string ReminderTable::IS_ACTIVE = "is_active"; +const std::string ReminderTable::STATE = "state"; +const std::string ReminderTable::ZONE_ID = "zone_id"; +const std::string ReminderTable::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; +const std::string ReminderTable::ACTION_BUTTON_INFO = "button_info"; +const std::string ReminderTable::CUSTOM_BUTTON_URI = "custom_button_uri"; +const std::string ReminderTable::SLOT_ID = "slot_id"; +const std::string ReminderTable::NOTIFICATION_ID = "notification_id"; +const std::string ReminderTable::TITLE = "title"; +const std::string ReminderTable::CONTENT = "content"; +const std::string ReminderTable::SNOOZE_CONTENT = "snooze_content"; +const std::string ReminderTable::EXPIRED_CONTENT = "expired_content"; +const std::string ReminderTable::AGENT = "agent"; +const std::string ReminderTable::MAX_SCREEN_AGENT = "maxScreen_agent"; +const std::string ReminderTable::TAP_DISMISSED = "tapDismissed"; +const std::string ReminderTable::AUTO_DELETED_TIME = "autoDeletedTime"; +const std::string ReminderTable::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; +const std::string ReminderTable::GROUP_ID = "groupId"; + +// Reminder Table Calendar Columns. +const std::string ReminderTable::REPEAT_DAYS = "repeat_days"; +const std::string ReminderTable::REPEAT_MONTHS = "repeat_months"; +const std::string ReminderTable::FIRST_DESIGNATE_YEAR = "first_designate_year"; +const std::string ReminderTable::FIRST_DESIGNATE_MONTH = "first_designate_month"; +const std::string ReminderTable::FIRST_DESIGNATE_DAY = "first_designate_day"; +const std::string ReminderTable::CALENDAR_YEAR = "calendar_year"; +const std::string ReminderTable::CALENDAR_MONTH = "calendar_month"; +const std::string ReminderTable::CALENDAR_DAY = "calendar_day"; +const std::string ReminderTable::CALENDAR_HOUR = "calendar_hour"; +const std::string ReminderTable::CALENDAR_MINUTE = "calendar_minute"; + +// Reminder Table Alarm Columns. +const std::string ReminderTable::ALARM_HOUR = "alarm_hour"; +const std::string ReminderTable::ALARM_MINUTE = "alarm_minute"; + +std::string ReminderTable::sqlOfAddColumns = ""; +std::vector ReminderTable::columns; + +void ReminderTable::InitDbColumns() +{ + InitBasicColumns(); + InitCalendarColumns(); + InitAlarmColumns(); +} + +void ReminderTable::InitBasicColumns() +{ + AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY"); + AddColumn(PKG_NAME, "TEXT NOT NULL"); + AddColumn(USER_ID, "INT NOT NULL"); + AddColumn(UID, "INT NOT NULL"); + AddColumn(SYS_APP, "TEXT NOT NULL"); + AddColumn(APP_LABEL, "TEXT"); + AddColumn(REMINDER_TYPE, "INT NOT NULL"); + AddColumn(REMINDER_TIME, "BIGINT NOT NULL"); + AddColumn(TRIGGER_TIME, "BIGINT NOT NULL"); + AddColumn(RTC_TRIGGER_TIME, "BIGINT NOT NULL"); + AddColumn(TIME_INTERVAL, "BIGINT NOT NULL"); + AddColumn(SNOOZE_TIMES, "INT NOT NULL"); + AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL"); + AddColumn(RING_DURATION, "BIGINT NOT NULL"); + AddColumn(IS_EXPIRED, "TEXT NOT NULL"); + AddColumn(IS_ACTIVE, "TEXT NOT NULL"); + AddColumn(STATE, "INT NOT NULL"); + AddColumn(ZONE_ID, "TEXT"); + AddColumn(HAS_SCHEDULED_TIMEOUT, "TEXT"); + AddColumn(ACTION_BUTTON_INFO, "TEXT"); + AddColumn(CUSTOM_BUTTON_URI, "TEXT"); + AddColumn(SLOT_ID, "INT"); + AddColumn(NOTIFICATION_ID, "INT NOT NULL"); + AddColumn(TITLE, "TEXT"); + AddColumn(CONTENT, "TEXT"); + AddColumn(SNOOZE_CONTENT, "TEXT"); + AddColumn(EXPIRED_CONTENT, "TEXT"); + AddColumn(AGENT, "TEXT"); + AddColumn(MAX_SCREEN_AGENT, "TEXT"); + AddColumn(TAP_DISMISSED, "TEXT"); + AddColumn(AUTO_DELETED_TIME, "BIGINT"); + AddColumn(REPEAT_DAYS_OF_WEEK, "INT"); + AddColumn(GROUP_ID, "TEXT"); +} + +void ReminderTable::InitCalendarColumns() +{ + AddColumn(REPEAT_DAYS, "INT"); + AddColumn(REPEAT_MONTHS, "INT"); + AddColumn(FIRST_DESIGNATE_YEAR, "INT"); + AddColumn(FIRST_DESIGNATE_MONTH, "INT"); + AddColumn(FIRST_DESIGNATE_DAY, "INT"); + AddColumn(CALENDAR_YEAR, "INT"); + AddColumn(CALENDAR_MONTH, "INT"); + AddColumn(CALENDAR_DAY, "INT"); + AddColumn(CALENDAR_HOUR, "INT"); + AddColumn(CALENDAR_MINUTE, "INT"); +} + +void ReminderTable::InitAlarmColumns() +{ + AddColumn(ALARM_HOUR, "INT"); + AddColumn(ALARM_MINUTE, "INT", true); +} + +void ReminderTable ::AddColumn( + const std::string& name, const std::string& type, bool isEnd) +{ + columns.push_back(name); + if (!isEnd) { + sqlOfAddColumns += name + " " + type + ", "; + } else { + sqlOfAddColumns += name + " " + type; + } +} + +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 4458d9bf54f216d0fbfb903004b5bf69105972fa..a11941c4cbd2dfb0bb9b001844983222287f0c2f 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -18,6 +18,7 @@ #define private public #define protected public #include "reminder_request.h" +#include "reminder_table.h" #undef private #undef protected @@ -1329,14 +1330,11 @@ HWTEST_F(ReminderRequestTest, CreateWantAgent_00002, Function | SmallTest | Leve */ HWTEST_F(ReminderRequestTest, AddColumn_00002, Function | SmallTest | Level1) { - auto rrc = std::make_shared(); - rrc->InitDbColumns(); std::string name = "this is name"; std::string type = "this is type"; - rrc->AddColumn(name, type, true); - rrc->AddColumn(name, type, false); - int32_t result = rrc->GetReminderId(); - EXPECT_EQ(result, -1); + ReminderTable::AddColumn(name, type, true); + ReminderTable::AddColumn(name, type, false); + EXPECT_EQ(ReminderTable::columns.size(), 2); } /** diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index a174bfa934878017e0fb711d563ce9a0a8d4a842..d2a58f544a374124eb04ac3ece53e147bcb6c496 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -577,8 +577,6 @@ public: * @param resultSet Indicates the resultSet with pointer to the row of record data. */ virtual void RecoverFromDb(const std::shared_ptr &resultSet); - void RecoverActionButton(const std::shared_ptr &resultSet); - void RecoverWantAgent(const std::string &wantAgentInfo, const uint8_t &type); /** * @brief Sets action button. @@ -901,6 +899,7 @@ protected: { return INVALID_LONG_LONG_VALUE; } + int64_t RecoverInt64FromDb(const std::shared_ptr &resultSet, const std::string &columnName, const DbRecoveryType &columnType); @@ -980,6 +979,17 @@ private: */ void UpdateNotificationStateForSnooze(); + static void AppendWantAgentValuesBucket(const sptr& reminder, + NativeRdb::ValuesBucket& values); + + bool MarshallingActionButton(Parcel& parcel) const; + bool ReadActionButtonFromParcel(Parcel& parcel); + + void RecoverBasicFromDb(const std::shared_ptr& resultSet); + void RecoverActionButtonJsonMode(const std::string& jsonString); + void RecoverActionButton(const std::shared_ptr& resultSet); + void RecoverWantAgent(const std::string& wantAgentInfo, const uint8_t& type); + static const uint32_t MIN_TIME_INTERVAL_IN_MILLI; static const std::string SEP_BUTTON_SINGLE; static const std::string SEP_BUTTON_MULTI; diff --git a/interfaces/inner_api/reminder_request_alarm.h b/interfaces/inner_api/reminder_request_alarm.h index a70a57a96c82e5057d9ffebbe349a33597679ee6..1eea3c0f6031a7b362933061cab5e0de48da2ec3 100644 --- a/interfaces/inner_api/reminder_request_alarm.h +++ b/interfaces/inner_api/reminder_request_alarm.h @@ -128,10 +128,6 @@ private: uint8_t hour_ = {0}; uint8_t minute_ = {0}; - - // For database recovery. - static const std::string ALARM_HOUR; - static const std::string ALARM_MINUTE; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/reminder_request_calendar.h b/interfaces/inner_api/reminder_request_calendar.h index 72b2cb6209ea1f31fa3fc200ae677eecf7ec8fb7..88e5c410838e2ed0e44c64bad85056bd4ceeaf81 100644 --- a/interfaces/inner_api/reminder_request_calendar.h +++ b/interfaces/inner_api/reminder_request_calendar.h @@ -208,18 +208,6 @@ private: uint16_t repeatMonth_ {0}; uint32_t repeatDay_ {0}; - // For database recovery. - static const std::string REPEAT_DAYS; - static const std::string REPEAT_MONTHS; - static const std::string FIRST_DESIGNATE_YEAR; - static const std::string FIRST_DESIGNATE_MONTH; - static const std::string FIRST_DESIGNATE_DAY; - static const std::string CALENDAR_YEAR; - static const std::string CALENDAR_MONTH; - static const std::string CALENDAR_DAY; - static const std::string CALENDAR_HOUR; - static const std::string CALENDAR_MINUTE; - static const uint8_t DAY_ARRAY[12]; static const uint8_t FEBRUARY; static const uint8_t LEAP_MONTH; diff --git a/interfaces/inner_api/reminder_table.h b/interfaces/inner_api/reminder_table.h new file mode 100644 index 0000000000000000000000000000000000000000..d82c78bc71829439a3df76e5f90073a6b6912eb5 --- /dev/null +++ b/interfaces/inner_api/reminder_table.h @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2023 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_INTERFACES_INNER_API_REMINDER_TABLE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H + +#include +#include + +namespace OHOS { +namespace Notification { +class ReminderTable { +public: + static void InitDbColumns(); + + // Reminder Table Basic Columns. + + /* + * reminder id + */ + static const std::string REMINDER_ID; + + /* + * package name + */ + static const std::string PKG_NAME; + + /* + * user id + */ + static const std::string USER_ID; + + /* + * uid + */ + static const std::string UID; + + /* + * systerm app flag + */ + static const std::string SYS_APP; + + /* + * app label + */ + static const std::string APP_LABEL; + + /* + * reminder type: Timer/Calendar/Alarm + */ + static const std::string REMINDER_TYPE; + + /* + * reminder time + */ + static const std::string REMINDER_TIME; + + /* + * trigger time + */ + static const std::string TRIGGER_TIME; + + /* + * RTC trigger time + */ + static const std::string RTC_TRIGGER_TIME; + + /* + * time interval + */ + static const std::string TIME_INTERVAL; + + /* + * snooze times + */ + static const std::string SNOOZE_TIMES; + + /* + * dynamic snooze times + */ + static const std::string DYNAMIC_SNOOZE_TIMES; + + /* + * ring duration + */ + static const std::string RING_DURATION; + + /* + * expired flag + */ + static const std::string IS_EXPIRED; + + /* + * active flag + */ + static const std::string IS_ACTIVE; + + /* + * reminder state + */ + static const std::string STATE; + + /* + * zone id + */ + static const std::string ZONE_ID; + + /* + * scheduled timeout flag + */ + static const std::string HAS_SCHEDULED_TIMEOUT; + + /* + * action button information + */ + static const std::string ACTION_BUTTON_INFO; + + /* + * custom button uri + */ + static const std::string CUSTOM_BUTTON_URI; + + /* + * slot type + */ + static const std::string SLOT_ID; + + /* + * notification id + */ + static const std::string NOTIFICATION_ID; + + /* + * notification title + */ + static const std::string TITLE; + + /* + * notification content + */ + static const std::string CONTENT; + + /* + * notification snooze content + */ + static const std::string SNOOZE_CONTENT; + + /* + * notification expired content + */ + static const std::string EXPIRED_CONTENT; + + /* + * agent information + */ + static const std::string AGENT; + + /* + * max screen agent information + */ + static const std::string MAX_SCREEN_AGENT; + + /* + * tap dismissed flag + */ + static const std::string TAP_DISMISSED; + + /* + * auto deleted time + */ + static const std::string AUTO_DELETED_TIME; + + /* + * repeat days of week + */ + static const std::string REPEAT_DAYS_OF_WEEK; + + /* + * reminder group id + */ + static const std::string GROUP_ID; + + // Reminder Table Calendar Columns. + static const std::string REPEAT_DAYS; + static const std::string REPEAT_MONTHS; + static const std::string FIRST_DESIGNATE_YEAR; + static const std::string FIRST_DESIGNATE_MONTH; + static const std::string FIRST_DESIGNATE_DAY; + static const std::string CALENDAR_YEAR; + static const std::string CALENDAR_MONTH; + static const std::string CALENDAR_DAY; + static const std::string CALENDAR_HOUR; + static const std::string CALENDAR_MINUTE; + + // Reminder Table Alarm Columns. + static const std::string ALARM_HOUR; + static const std::string ALARM_MINUTE; + + static std::string sqlOfAddColumns; + static std::vector columns; + +private: + static void InitBasicColumns(); + static void InitCalendarColumns(); + static void InitAlarmColumns(); + static void AddColumn(const std::string& name, const std::string& type, bool isEnd = false); +}; +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H \ No newline at end of file