diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 6d8bc24a37bace6921552b0fada8c2e96d8b9dc2..6c34fa13006f6c977373a1d40d447fdee6e23e88 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -99,6 +99,7 @@ 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::SNOOZE_SLOT_ID = "snooze_slot_id"; const std::string ReminderRequest::NOTIFICATION_ID = "notification_id"; const std::string ReminderRequest::TITLE = "title"; const std::string ReminderRequest::CONTENT = "content"; @@ -139,6 +140,7 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) 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_; @@ -568,6 +570,11 @@ void ReminderRequest::RecoverFromDb(const std::shared_ptr resultSet->GetInt(ReminderStore::GetColumnIndex(SLOT_ID), slotType); slotType_ = NotificationConstant::SlotType(slotType); + // snoozeSlotType + int32_t snoozeSlotType; + resultSet->GetInt(ReminderStore::GetColumnIndex(SNOOZE_SLOT_ID), snoozeSlotType); + snoozeSlotType_ = NotificationConstant::SlotType(snoozeSlotType); + // notification id resultSet->GetInt(ReminderStore::GetColumnIndex(NOTIFICATION_ID), notificationId_); @@ -746,6 +753,12 @@ ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotTy return *this; } +ReminderRequest& ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType) +{ + snoozeSlotType_ = snoozeSlotType; + return *this; +} + ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent) { snoozeContent_ = snoozeContent; @@ -885,6 +898,11 @@ NotificationConstant::SlotType ReminderRequest::GetSlotType() const return slotType_; } +NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const +{ + return snoozeSlotType_; +} + std::string ReminderRequest::GetSnoozeContent() const { return snoozeContent_; @@ -1005,7 +1023,11 @@ void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std switch (type) { case UpdateNotificationType::COMMON: { ANSR_LOGI("UpdateNotification common information"); - UpdateNotificationCommon(); + if (extra == "snooze") { + UpdateNotificationCommon(true); + } else { + UpdateNotificationCommon(false); + } break; } case UpdateNotificationType::REMOVAL_WANT_AGENT: { @@ -1042,6 +1064,35 @@ void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std bool ReminderRequest::Marshalling(Parcel &parcel) const { // write string + if(!WriteStringMarshalling(parcel)){ + return false; + } + + // write bool + if(!WriteBoolMarshalling(parcel)){ + return false; + } + + // write int + if(!WriteIntMarshalling(parcel)){ + return false; + } + + // write enum + if(!WriteEnumMarshalling(parcel)){ + return false; + } + + // write map + if(!WritemMapMarshalling(parcel)){ + return false; + } + + return true; +} + +bool ReminderRequest::WriteStringMarshalling(Parcel &parcel) const +{ if (!parcel.WriteString(content_)) { ANSR_LOGE("Failed to write content"); return false; @@ -1082,8 +1133,11 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write customButtonUri"); return false; } + return true; +} - // write bool +bool ReminderRequest::WriteBoolMarshalling(Parcel &parcel) const +{ if (!parcel.WriteBool(isExpired_)) { ANSR_LOGE("Failed to write isExpired"); return false; @@ -1096,8 +1150,11 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write tapDismissed"); return false; } + return true; +} - // write int +bool ReminderRequest::WriteIntMarshalling(Parcel &parcel) const +{ if (!parcel.WriteInt64(autoDeletedTime_)) { ANSR_LOGE("Failed to write autoDeletedTime"); return false; @@ -1146,8 +1203,11 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write repeatDaysOfWeek"); return false; } + return true; +} - // write enum +bool ReminderRequest::WriteEnumMarshalling(Parcel &parcel) const +{ if (!parcel.WriteUint8(static_cast(reminderType_))) { ANSR_LOGE("Failed to write reminder type"); return false; @@ -1156,8 +1216,15 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write slot type"); return false; } + if (!parcel.WriteInt32(static_cast(snoozeSlotType_))) { + ANSR_LOGE("Failed to write snoozeSlotType type"); + return false; + } + return true; +} - // write map +bool ReminderRequest::WritemMapMarshalling(Parcel &parcel) const +{ if (!parcel.WriteUint64(static_cast(actionButtonMap_.size()))) { ANSR_LOGE("Failed to write action button size"); return false; @@ -1224,6 +1291,38 @@ ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) bool ReminderRequest::ReadFromParcel(Parcel &parcel) { // read string + if(!ReadStringFromParcel(parcel)){ + return false; + } + + // read bool + if(!ReadBoolFromParcel(parcel)){ + return false; + } + + // read int + if(!ReadIntFromParcel(parcel)){ + return false; + } + + // read enum + if(!ReadEnumFromParcel(parcel)){ + return false; + } + + // read map + if(!ReadMapFromParcel(parcel)){ + return false; + } + + if (!InitNotificationRequest()) { + return false; + } + return true; +} + +bool ReminderRequest::ReadStringFromParcel(Parcel &parcel) +{ if (!parcel.ReadString(content_)) { ANSR_LOGE("Failed to read content"); return false; @@ -1264,8 +1363,11 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read customButtonUri"); return false; } + return true; +} - // read bool +bool ReminderRequest::ReadBoolFromParcel(Parcel &parcel) +{ if (!parcel.ReadBool(isExpired_)) { ANSR_LOGE("Failed to read isExpired"); return false; @@ -1278,8 +1380,11 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read tapDismissed"); return false; } + return true; +} - // read int +bool ReminderRequest::ReadIntFromParcel(Parcel &parcel) +{ if (!parcel.ReadInt64(autoDeletedTime_)) { ANSR_LOGE("Failed to read autoDeletedTime"); return false; @@ -1331,8 +1436,11 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read repeatDaysOfWeek"); return false; } + return true; +} - // read enum +bool ReminderRequest::ReadEnumFromParcel(Parcel &parcel) +{ uint8_t reminderType = static_cast(ReminderType::INVALID); if (!parcel.ReadUint8(reminderType)) { ANSR_LOGE("Failed to read reminderType"); @@ -1347,7 +1455,17 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) } slotType_ = static_cast(slotType); - // read map + int32_t snoozeSlotType = static_cast(NotificationConstant::SlotType::OTHER); + if (!parcel.ReadInt32(snoozeSlotType)) { + ANSR_LOGE("Failed to read snoozeSlotType"); + return false; + } + snoozeSlotType_ = static_cast(snoozeSlotType); + return true; +} + +bool ReminderRequest::ReadMapFromParcel(Parcel &parcel) +{ uint64_t buttonMapSize = 0; if (!parcel.ReadUint64(buttonMapSize)) { ANSR_LOGE("Failed to read buttonMapSize"); @@ -1382,9 +1500,6 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) info.dataShareUpdate->valuesBucket = valuesBucket; actionButtonMap_.insert(std::pair(type, info)); } - if (!InitNotificationRequest()) { - return false; - } return true; } @@ -1722,14 +1837,22 @@ bool ReminderRequest::UpdateNextReminder(const bool &force) return result; } -void ReminderRequest::UpdateNotificationCommon() +void ReminderRequest::UpdateNotificationCommon(bool isSnooze) { time_t now; (void)time(&now); // unit is seconds. notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now)); notificationRequest_->SetLabel(NOTIFICATION_LABEL); notificationRequest_->SetShowDeliveryTime(true); - notificationRequest_->SetSlotType(slotType_); + if (isSnooze) { + if (snoozeSlotType_ == NotificationConstant::SlotType::OTHER){ + notificationRequest_->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); + } else { + notificationRequest_->SetSlotType(snoozeSlotType_); + } + } else { + notificationRequest_->SetSlotType(slotType_); + } notificationRequest_->SetTapDismissed(tapDismissed_); notificationRequest_->SetAutoDeletedTime(autoDeletedTime_); auto notificationNormalContent = std::make_shared(); @@ -1903,6 +2026,7 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(ACTION_BUTTON_INFO, reminder->GetButtonInfo()); values.PutString(CUSTOM_BUTTON_URI, reminder->GetCustomButtonUri()); values.PutInt(SLOT_ID, reminder->GetSlotType()); + values.PutInt(SNOOZE_SLOT_ID, reminder->GetSnoozeSlotType()); values.PutInt(NOTIFICATION_ID, reminder->GetNotificationId()); values.PutString(TITLE, reminder->GetTitle()); values.PutString(CONTENT, reminder->GetContent()); @@ -1955,6 +2079,7 @@ void ReminderRequest::InitDbColumns() AddColumn(ACTION_BUTTON_INFO, "TEXT", false); AddColumn(CUSTOM_BUTTON_URI, "TEXT", false); AddColumn(SLOT_ID, "INT", false); + AddColumn(SNOOZE_SLOT_ID, "INT", false); AddColumn(NOTIFICATION_ID, "INT NOT NULL", false); AddColumn(TITLE, "TEXT", false); AddColumn(CONTENT, "TEXT", false); diff --git a/frameworks/ans/src/reminder_store.cpp b/frameworks/ans/src/reminder_store.cpp index ca636cebee4e48de2c31626dca590fcf00adf500..21b1cf25c5cfe53bfb6ec00bdfe3d782d4a2354f 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/frameworks/ans/src/reminder_store.cpp @@ -32,7 +32,9 @@ namespace { const std::string REMINDER_DB_DIR = "/data/service/el1/public/notification/"; const std::string REMINDER_DB_NAME = "notification.db"; const std::string REMINDER_DB_TABLE = "reminder"; -const uint32_t REMINDER_RDB_VERSION = 2; +const int32_t REMINDER_RDB_VERSION_V1 = 1; +const int32_t REMINDER_RDB_VERSION_V2 = 2; +const uint32_t REMINDER_RDB_VERSION = 3; const int32_t STATE_FAIL = -1; std::vector columns; std::string g_sqlColumns; @@ -54,7 +56,24 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade( { ANSR_LOGI("OnUpgrade oldVersion is %{public}d, newVersion is %{public}d", oldVersion, newVersion); if (oldVersion < newVersion && newVersion == REMINDER_RDB_VERSION) { - store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD groupId TEXT DEFAULT '';"); + if (oldVersion == REMINDER_RDB_VERSION_V1) { + if (!AddRdbColum(store, "groupId", "TEXT")) { + ANSR_LOGW("Add groupId colum failed!"); + } + if (!AddRdbColum(store, "custom_ring_uri", "TEXT")) { + ANSR_LOGW("Add custom_ring_uri colum failed!"); + } + if (!AddRdbColum(store, "snooze_slot_id", "INT")) { + ANSR_LOGW("Add snooze_slot_id colum failed!"); + } + } else if (oldVersion == REMINDER_RDB_VERSION_V2) { + if (!AddRdbColum(store, "custom_ring_uri", "TEXT")) { + ANSR_LOGW("Add custom_ring_uri colum failed!"); + } + if (!AddRdbColum(store, "snooze_slot_id", "INT")) { + ANSR_LOGW("Add snooze_slot_id colum failed!"); + } + } } store.SetVersion(newVersion); return NativeRdb::E_OK; @@ -439,5 +458,25 @@ void ReminderStore::GenerateData(const sptr &reminder, ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); } + +bool ReminderStore::AddRdbColum(NativeRdb::RdbStore &store, const std::string &columName, const std::string &type) +{ + std::string sqlStr = ""; + bool isSucess = false; + if (type == "TEXT") { + sqlStr = "ALTER TABLE " + REMINDER_DB_TABLE + " ADD " + columName + " " + type + " DEFAULT '';"; + isSucess = true; + } + if (type == "INT") { + sqlStr = "ALTER TABLE " + REMINDER_DB_TABLE + " ADD " + columName + " " + type + " DEFAULT -1;"; + isSucess = true; + } + if (!isSucess) { + return false; + } + ANSR_LOGD("AddRdbColum sqlStr =%{public}s", sqlStr.c_str()); + store.ExecuteSql(sqlStr); + return isSucess; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp b/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp index af05dd80ee29f744556a08528ff1b89c60e46dba..9bfa63aace72687918fd4c27059968e12d155fd1 100644 --- a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp @@ -498,7 +498,7 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00100, Function | S int32_t notificationId_ = 0; reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); reminderRequest->reminderType_ = ReminderRequest::ReminderType::TIMER; - reminderRequest->UpdateNotificationCommon(); + reminderRequest->UpdateNotificationCommon(false); } /** @@ -515,7 +515,7 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00200, Function | S int32_t notificationId_ = 0; reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); reminderRequest->reminderType_ = ReminderRequest::ReminderType::ALARM; - reminderRequest->UpdateNotificationCommon(); + reminderRequest->UpdateNotificationCommon(false); } /** @@ -532,7 +532,7 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00300, Function | S int32_t notificationId_ = 0; reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); reminderRequest->reminderType_ = ReminderRequest::ReminderType::INVALID; - reminderRequest->UpdateNotificationCommon(); + reminderRequest->UpdateNotificationCommon(false); } /** diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp index 8f36447f1dbde8c8daceaaf2e2f9c1e5dc0afedc..a3160f8c862a6299571ad11dc87dfd594dab6515 100644 --- a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp @@ -738,6 +738,10 @@ HWTEST_F(ReminderRequestCalendarTest, UpdateNextReminder_00003, Function | Small bool isSet1 = true; calendar->SetMonth(month, isSet1); + std::vector daysOfWeek; + daysOfWeek.push_back(1); + calendar->SetRepeatDaysOfWeek(isSet, daysOfWeek); + auto rrc = std::make_shared(); rrc->SetSnoozeTimesDynamic(0); EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 0); @@ -781,6 +785,12 @@ HWTEST_F(ReminderRequestCalendarTest, UpdateNextReminder_00004, Function | Small bool result7 = calendar->IsRepeatMonth(month); EXPECT_EQ(result7, false); + std::vector daysOfWeek; + daysOfWeek.push_back(1); + calendar->SetRepeatDaysOfWeek(isSet, daysOfWeek); + bool result2 = calendar->IsRepeatDaysOfWeek(1); + EXPECT_EQ(result2, false); + auto reminderRequest = std::make_shared(); reminderRequest->SetSnoozeTimes(1); EXPECT_EQ(reminderRequest->GetSnoozeTimes(), 1) << "Get snoozeTimes not 1"; @@ -820,6 +830,10 @@ HWTEST_F(ReminderRequestCalendarTest, UpdateNextReminder_00005, Function | Small bool result1 = calendar->IsRepeatMonth(month); EXPECT_EQ(result1, false); + std::vector daysOfWeek; + daysOfWeek.push_back(1); + calendar->SetRepeatDaysOfWeek(isSet1, daysOfWeek); + auto rrc = std::make_shared(); rrc->SetSnoozeTimes(1); EXPECT_EQ(rrc->GetSnoozeTimes(), 1) << "Get snoozeTimes not 1"; @@ -835,6 +849,61 @@ HWTEST_F(ReminderRequestCalendarTest, UpdateNextReminder_00005, Function | Small EXPECT_EQ(result3, false); } +/** + * @tc.name: UpdateNextReminder_00006 + * @tc.desc: Test UpdateNextReminder parameters. + * @tc.type: FUNC + * @tc.require: I8CZ6P + */ +HWTEST_F(ReminderRequestCalendarTest, UpdateNextReminder_00006, Function | SmallTest | Level1) +{ + struct tm nowTime; + auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); + EXPECT_NE(nullptr, calendar); + + uint8_t day = 2; + bool isSet = false; + bool isSet1 = true; + calendar->SetDay(day, isSet); + bool result = calendar->IsRepeatDay(day); + EXPECT_EQ(result, false); + + uint8_t month = 2; + calendar->SetMonth(month, isSet); + bool result1 = calendar->IsRepeatMonth(month); + EXPECT_EQ(result1, false); + + std::vector daysOfWeek; + daysOfWeek.push_back(1); + daysOfWeek.push_back(3); + daysOfWeek.push_back(4); + daysOfWeek.push_back(5); + daysOfWeek.push_back(6); + calendar->SetRepeatDaysOfWeek(isSet1, daysOfWeek); + + bool result2 = calendar->IsRepeatDaysOfWeek(1); + EXPECT_EQ(result2, true); + + bool result3 = calendar->IsRepeatReminder(); + EXPECT_EQ(result3, true); + + auto rrc = std::make_shared(); + rrc->SetSnoozeTimes(1); + EXPECT_EQ(rrc->GetSnoozeTimes(), 1) << "Get snoozeTimes not 1"; + EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 1) << "Get snoozeTimesDynamic not 1"; + + uint32_t minTimeIntervalInSecond = 5 * 60; + rrc->SetTimeInterval(1); + EXPECT_EQ(rrc->GetTimeInterval(), minTimeIntervalInSecond); + + bool result4 = calendar->UpdateNextReminder(); + EXPECT_EQ(result4, true); + + uint16_t ret2 = calendar->GetRepeatDaysOfWeek(); + uint16_t ret3 = 61; + EXPECT_EQ(ret2, ret3); +} + /** * @tc.name: SetRepeatMonths_00001 * @tc.desc: Test SetRepeatMonths parameters. diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 2dc0605fa3d1263a7511f9361f163074c10d7538..0d727ff3c39c14c934888a6c6f49cba9b42878f1 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1826,5 +1826,72 @@ HWTEST_F(ReminderRequestTest, InitBundleName_00002, Function | SmallTest | Level rrc->InitBundleName(bundleName); EXPECT_EQ(rrc->GetBundleName(), bundleName); } + +/** + * @tc.name: UpdateNotificationCommon_00100 + * @tc.desc: Test UpdateNotificationCommon when snooze is true. + * @tc.type: FUNC + * @tc.require: issueII8F9EZ + */ +HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00100, Function | SmallTest | Level1) +{ + // given + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->InitNotificationRequest(), true); + sptr ret = rrc->GetNotificationRequest(); + rrc->snoozeSlotType_ = NotificationConstant::SlotType::OTHER; + bool isSnooze = true; + + // when + rrc->UpdateNotificationCommon(isSnooze); + + // then + EXPECT_EQ(ret->getSlotType(), NotificationConstant::SlotType::CONTENT_INFORMATION); +} + +/** + * @tc.name: UpdateNotificationCommon_00200 + * @tc.desc: Test UpdateNotificationCommon when snooze is true. + * @tc.type: FUNC + * @tc.require: issueII8F9EZ + */ +HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00200, Function | SmallTest | Level1) +{ + // given + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->InitNotificationRequest(), true); + sptr ret = rrc->GetNotificationRequest(); + rrc->snoozeSlotType_ = NotificationConstant::SlotType::SERVICE_REMINDER; + bool isSnooze = true; + + // when + rrc->UpdateNotificationCommon(isSnooze); + + // then + EXPECT_EQ(ret->getSlotType(), NotificationConstant::SlotType::SERVICE_REMINDER); +} + +/** + * @tc.name: UpdateNotificationCommon_00300 + * @tc.desc: Test UpdateNotificationCommon when snooze is false. + * @tc.type: FUNC + * @tc.require: issueII8F9EZ + */ +HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00300, Function | SmallTest | Level1) +{ + // given + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->InitNotificationRequest(), true); + sptr ret = rrc->GetNotificationRequest(); + rrc->snoozeSlotType_ = NotificationConstant::SlotType::SERVICE_REMINDER; + rrc->slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + bool isSnooze = false; + + // when + rrc->UpdateNotificationCommon(isSnooze); + + // then + EXPECT_EQ(ret->getSlotType(), NotificationConstant::SlotType::SOCIAL_COMMUNICATION); +} } } diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index ccfc39a2143d5f4cc4750698710a66ff9c5e2547..c0c9ef6a5905346bf81d9b6c2c5a51f4f3373214 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -72,6 +72,7 @@ const char* BUTTON_DATA_SHARE_UPDATE_VALUE = "value"; const char* TAPDISMISSED = "tapDismissed"; const char* AUTODELETEDTIME = "autoDeletedTime"; const char* GROUP_ID = "groupId"; +const char* SNOOZE_SLOT_TYPE = "snoozeSlotType"; const int INDEX_KEY = 0; const int INDEX_TYPE = 1; const int INDEX_VALUE = 2; diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index d2fb6ea6d3a4d729831ec1c4e38c5a7fae871477..78140a3e83e8dd7ef20613710378618d82c71022 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -760,6 +760,12 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi napi_create_int32(env, static_cast(jsSlotType), &value); napi_set_named_property(env, result, SLOT_TYPE, value); + // snoozeSlotType + NotificationNapi::SlotType jsSnoozeSlotType; + NotificationNapi::Common::SlotTypeCToJS(reminder.GetSnoozeSlotType(), jsSnoozeSlotType); + napi_create_int32(env, static_cast(jsSnoozeSlotType), &value); + napi_set_named_property(env, result, SNOOZE_SLOT_TYPE, value); + // wantAgent ParseWantAgent(env, reminder, result); diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 0351e0c74244913fb64250ee853f530afd72e143..fa2ce981388c9807aa119bdeb10969e29ecd7325 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -503,6 +503,17 @@ napi_value ReminderCommon::GenReminder( reminder->SetSlotType(actureType); } + // snoozeSlotType + int32_t snoozeSlotType = 0; + if (GetInt32(env, value, ReminderAgentNapi::SNOOZE_SLOT_TYPE, snoozeSlotType, false)) { + enum NotificationConstant::SlotType actureSnoozeType = NotificationConstant::SlotType::OTHER; + if (!NotificationNapi::Common::SlotTypeJSToC(NotificationNapi::SlotType(snoozeSlotType), actureSnoozeType)) { + ANSR_LOGW("snooze slot type not support."); + return nullptr; + } + reminder->SetSnoozeSlotType(actureSnoozeType); + } + // tapDismissed bool tapDismissed = false; if (GetBool(env, value, ReminderAgentNapi::TAPDISMISSED, tapDismissed)) { diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 3d6e6c8af489909f155ea1fe4fc53172480643ba..bcdd3291be898057e41c2dc3c364b02f71cabbfa 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -280,6 +280,13 @@ public: */ NotificationConstant::SlotType GetSlotType() const; + /** + * @brief Obtains snoozeSlot type. + * + * @return snoozeSlot type. + */ + NotificationConstant::SlotType GetSnoozeSlotType() const; + std::string GetSnoozeContent() const; uint8_t GetSnoozeTimes() const; uint8_t GetSnoozeTimesDynamic() const; @@ -559,7 +566,7 @@ public: * @return Current reminder self. */ ReminderRequest& SetSlotType(const NotificationConstant::SlotType &slotType); - + ReminderRequest& SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType); ReminderRequest& SetSnoozeContent(const std::string &snoozeContent); /** @@ -777,6 +784,7 @@ public: static const std::string ACTION_BUTTON_INFO; static const std::string CUSTOM_BUTTON_URI; static const std::string SLOT_ID; + static const std::string SNOOZE_SLOT_ID; static const std::string NOTIFICATION_ID; static const std::string TITLE; static const std::string CONTENT; @@ -852,7 +860,7 @@ private: void UpdateActionButtons(const bool &setSnooze); bool UpdateNextReminder(const bool &force); void UpdateNotificationContent(const bool &setSnooze); - void UpdateNotificationCommon(); + void UpdateNotificationCommon(bool isSnooze); /** * @brief Determine whether it is repeated every week. @@ -882,6 +890,76 @@ private: */ void UpdateNotificationStateForSnooze(); + /** + * @brief Marshal a NotificationRequest string into a Parcel. + * + * @param parcel the string into the parcel + */ + bool WriteStringMarshalling(Parcel &parcel) const; + + /** + * @brief Marshal a NotificationRequest bool into a Parcel. + * + * @param parcel the bool into the parcel + */ + bool WriteBoolMarshalling(Parcel &parcel) const; + + /** + * @brief Marshal a NotificationRequest int into a Parcel. + * + * @param parcel the int into the parcel + */ + bool WriteIntMarshalling(Parcel &parcel) const; + + /** + * @brief Marshal a NotificationRequest enum into a Parcel. + * + * @param parcel the enum into the parcel + */ + bool WriteEnumMarshalling(Parcel &parcel) const; + + /** + * @brief Marshal a NotificationRequest map into a Parcel. + * + * @param parcel the map into the parcel + */ + bool WritemMapMarshalling(Parcel &parcel) const; + + /** + * @brief Read a NotificationRequest string from a Parcel. + * + * @param parcel the string from the parcel + */ + bool ReadStringFromParcel(Parcel &parcel); + + /** + * @brief Read a NotificationRequest bool from a Parcel. + * + * @param parcel the bool from the parcel + */ + bool ReadBoolFromParcel(Parcel &parcel); + + /** + * @brief Read a NotificationRequest int from a Parcel. + * + * @param parcel the int from the parcel + */ + bool ReadIntFromParcel(Parcel &parcel); + + /** + * @brief Read a NotificationRequest enum from a Parcel. + * + * @param parcel the enum from the parcel + */ + bool ReadEnumFromParcel(Parcel &parcel); + + /** + * @brief Read a NotificationRequest map from a Parcel. + * + * @param parcel the map from the parcel + */ + bool ReadMapFromParcel(Parcel &parcel); + static const uint32_t MIN_TIME_INTERVAL_IN_MILLI; static const std::string SEP_BUTTON_SINGLE; static const std::string SEP_BUTTON_MULTI; @@ -915,6 +993,7 @@ private: uint64_t timeIntervalInMilli_ {0}; ReminderType reminderType_ {ReminderType::INVALID}; NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; + NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; sptr notificationRequest_ = nullptr; std::shared_ptr wantAgentInfo_ = nullptr; std::shared_ptr maxScreenWantAgentInfo_ = nullptr; diff --git a/interfaces/inner_api/reminder_store.h b/interfaces/inner_api/reminder_store.h index 8bb3c166f445ac9c63cab16e380cf232dcec4c6d..fc977fddb40fbf0856cd3cea0feca485e26b5ef6 100644 --- a/interfaces/inner_api/reminder_store.h +++ b/interfaces/inner_api/reminder_store.h @@ -68,7 +68,8 @@ private: int64_t Insert(const sptr &reminder, const sptr &bundleOption); std::shared_ptr Query(const std::string &queryCondition) const; int64_t Update(const sptr &reminder, const sptr &bundleOption); - + static bool AddRdbColum(NativeRdb::RdbStore &rdbStore, const std::string &columName, + const std::string &type); class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { public: int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 5fae70f7cc650833a951f1cabda01de7c697cdcf..b06b54a105229ae1824ca9a8bec404672f4579b0 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -518,7 +518,7 @@ private: void UpdateAndSaveReminderLocked( const sptr &reminder, const sptr &bundleOption); - void UpdateNotification(const sptr &reminder); + void UpdateNotification(const sptr &reminder, bool isSnooze); static bool cmp(sptr &reminderRequest, sptr &other); diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 54026ad0747e077edb094cd8b48eb4c4e6ceaecc..9b50bba9bc071d825a3a8b14046d6bcfeff7c53a 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -777,7 +777,7 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde return; } ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); - UpdateNotification(reminder); + UpdateNotification(reminder, false); if (advancedNotificationService_ == nullptr) { ANSR_LOGE("Ans instance is null."); return; @@ -979,7 +979,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co bool toPlaySound = isNeedToPlaySound && ShouldAlert(reminder) ? true : false; reminder->OnShow(toPlaySound, isSysTimeChanged, true); AddToShowedReminders(reminder); - UpdateNotification(reminder); // this should be called after OnShow + UpdateNotification(reminder, false); // this should be called after OnShow if (alertingReminderId_ != -1) { TerminateAlerting(alertingReminder_, "PlaySoundAndVibration"); @@ -1007,7 +1007,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } } -void ReminderDataManager::UpdateNotification(const sptr &reminder) +void ReminderDataManager::UpdateNotification(const sptr &reminder, bool isSnooze) { int32_t reminderId = reminder->GetReminderId(); sptr bundleOption = FindNotificationBundleOption(reminderId); @@ -1015,7 +1015,11 @@ void ReminderDataManager::UpdateNotification(const sptr &remind ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); return; } - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, ""); + if (isSnooze) { + reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, "snooze"); + } else { + reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, ""); + } reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::REMOVAL_WANT_AGENT, ""); reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::WANT_AGENT, ""); reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::MAX_SCREEN_WANT_AGENT, ""); @@ -1060,7 +1064,7 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) return; } ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); - UpdateNotification(reminder); + UpdateNotification(reminder, true); if (advancedNotificationService_ == nullptr) { ANSR_LOGE("Ans instance is null"); return;