diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 8904f2caa6fe637ecf598389e3b3dcf9cfc080d6..493f8dee0a3a3f8ebeb7b9fcc8f8208a778e8f98 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -110,6 +110,7 @@ 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"; +const std::string ReminderRequest::CUSTOM_RING_URI = "custom_ring_uri"; std::string ReminderRequest::sqlOfAddColumns = ""; std::vector ReminderRequest::columns; @@ -148,6 +149,7 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->customButtonUri_ = other.customButtonUri_; this->repeatDaysOfWeek_ = other.repeatDaysOfWeek_; this->groupId_ = other.groupId_; + this->customRingUri_ = other.customRingUri_; } ReminderRequest::ReminderRequest(int32_t reminderId) @@ -608,6 +610,9 @@ void ReminderRequest::RecoverFromDb(const std::shared_ptr // groupId ReminderStore::GetStringVal(resultSet, GROUP_ID, groupId_); + + // customRingUri + ReminderStore::GetStringVal(resultSet, CUSTOM_RING_URI, customRingUri_); } void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) @@ -977,6 +982,16 @@ 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_; @@ -1054,6 +1069,7 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); WRITE_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); // write bool WRITE_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); @@ -1136,6 +1152,7 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); READ_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); + READ_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); READ_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); READ_BOOL_RETURN_FALSE_LOG(parcel, isSystemApp_, "isSystemApp"); @@ -1723,6 +1740,7 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); values.PutInt(REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); values.PutString(GROUP_ID, reminder->GetGroupId()); + values.PutString(CUSTOM_RING_URI, reminder->GetCustomRingUri()); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; @@ -1779,6 +1797,7 @@ void ReminderRequest::InitDbColumns() AddColumn(AUTO_DELETED_TIME, "BIGINT", false); AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); AddColumn(GROUP_ID, "TEXT", false); + AddColumn(CUSTOM_RING_URI, "TEXT", false); } void ReminderRequest::AddColumn( diff --git a/frameworks/ans/src/reminder_store.cpp b/frameworks/ans/src/reminder_store.cpp index 93b0486a5bb9e88aa00f324c3c5bba54d280b2aa..a3c888d5e6c8c159ffec64f9e8a4b3aabd54c07b 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/frameworks/ans/src/reminder_store.cpp @@ -29,7 +29,9 @@ namespace OHOS { namespace Notification { namespace { -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,18 @@ 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!"); + } + } else if (oldVersion == REMINDER_RDB_VERSION_V2) { + if (!AddRdbColum(store, "custom_ring_uri", "TEXT")) { + ANSR_LOGW("Add custom_ring_uri colum failed!"); + } + } } store.SetVersion(newVersion); return NativeRdb::E_OK; @@ -449,5 +462,21 @@ 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 (!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/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index ccfc39a2143d5f4cc4750698710a66ff9c5e2547..ee774a7ae3dfddc95d8a7d2f43780132d3535f44 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* CUSTOM_RING_URI = "customRingUri"; 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 c8b977c1cad663bec9248795f5f594328fd803d1..2aa6e3a9d39348bf59c29fae8ca17bcd0a911b95 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -765,6 +765,10 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi // group id napi_create_string_utf8(env, reminder.GetGroupId().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, GROUP_ID, value); + + // custom ring uri + napi_create_string_utf8(env, reminder.GetCustomRingUri().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, CUSTOM_RING_URI, 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..3227c5f3fe57c3c8b9aa025ab8830cb66a2ffae0 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -535,6 +535,11 @@ napi_value ReminderCommon::GenReminder( reminder->SetGroupId(std::string(str)); } + // custom ring uri + if (GetStringUtf8(env, value, ReminderAgentNapi::CUSTOM_RING_URI, str, NotificationNapi::STR_MAX_SIZE)) { + reminder->SetCustomRingUri(std::string(str)); + } + return NotificationNapi::Common::NapiGetNull(env); } diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index a174bfa934878017e0fb711d563ce9a0a8d4a842..ed4f00f6081060466e1c10727d0ed593f459dfa5 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -769,6 +769,20 @@ public: */ std::string GetCustomButtonUri() const; + /** + * @brief Gets custom ring uri. + * + * @return custom ring uri. + */ + std::string GetCustomRingUri() const; + + /** + * @brief Sets custom ring uri. + * + * @param uri Indicates uri. + */ + void SetCustomRingUri(const std::string &uri); + /** * @brief Update notification attributes. * @@ -886,6 +900,7 @@ public: static const std::string AUTO_DELETED_TIME; static const std::string REPEAT_DAYS_OF_WEEK; static const std::string GROUP_ID; + static const std::string CUSTOM_RING_URI; static std::string sqlOfAddColumns; static std::vector columns; @@ -1004,6 +1019,7 @@ private: bool tapDismissed_ {true}; int64_t autoDeletedTime_ {0}; std::string customButtonUri_ {}; + std::string customRingUri_ {}; // Indicates the reminder has been shown in the past time. // When the reminder has been created but not showed, it is equals to 0. diff --git a/interfaces/inner_api/reminder_store.h b/interfaces/inner_api/reminder_store.h index 58be32314d79848436df6ff8bdb37063ac6bb84b..107ed6a5209a636b55c97f0e6468ff8b5f5363cf 100644 --- a/interfaces/inner_api/reminder_store.h +++ b/interfaces/inner_api/reminder_store.h @@ -73,7 +73,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 0c08c0462ad41416bc382769b1f06fca67a4acc0..0f326eef3012762ec14b0a934b7288df610937fb 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -274,6 +274,14 @@ private: */ void GenDstBundleName(std::string &dstBundleName, const std::string &uri) const; + /** + * @brief get custom ring uri. + * + * @param reminder Indicates the reminder. + * @return Returns the uri of ring tone. + */ + std::string GetCustomRingUri(const sptr &reminder); + /** * @brief Cancels all the reminders of the target bundle or user. * diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index b91ea9b2d20e0832917f24a05a2fb88974669853..ab5febf22a93e6361a30a29bb580ddd0a212f217 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1410,6 +1410,13 @@ void ReminderDataManager::PlaySoundAndVibrationLocked(const sptr &reminder) { + if (reminder == nullptr) { + return ""; + } + return reminder->GetCustomRingUri(); +} + void ReminderDataManager::PlaySoundAndVibration(const sptr &reminder) { if (reminder == nullptr) { @@ -1428,7 +1435,9 @@ void ReminderDataManager::PlaySoundAndVibration(const sptr &rem return; } } - Uri soundUri = DEFAULT_REMINDER_SOUND; + std::string ringUri = GetCustomRingUri(reminder); + Uri reminderSound(ringUri); + Uri soundUri = ringUri.empty() ? DEFAULT_REMINDER_SOUND : reminderSound; std::string uri = soundUri.GetSchemeSpecificPart(); ANSR_LOGD("uri:%{public}s", uri.c_str()); soundPlayer_->SetSource(uri); diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index bdaf6253d51023c9e28a1944087bfb01e58521dc..e22cd54c13d7e0dd3d6fe34692f93703339ad394 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/ans/test/unittest/reminder_data_manager_test.cpp @@ -442,6 +442,21 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_017, Level1) EXPECT_TRUE(reminder2->isExpired_); } +/** + * @tc.name: ReminderDataManagerTest_018 + * @tc.desc: Reminder data manager test + * @tc.type: FUNC + * @tc.require: issueI8E7Z1 + */ +HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_018, Level1) +{ + sptr reminder = new ReminderRequestTimer(10); + std::string ringUri = "123"; + reminder->SetCustomRingUri(ringUri); + std::string getRingUri = manager->GetCustomRingUri(reminder); + EXPECT_EQ(ringUri, getRingUri); +} + /** * @tc.name: ReminderEventManagerTest_001 * @tc.desc: Reminder data manager test