diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 773c451a259ff88ec9b0de860907f8a81d9391a2..f66e845f7033fe502e535549a145a12d04d941b5 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -115,6 +115,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) @@ -596,6 +597,9 @@ void ReminderRequest::RecoverFromDb(const std::shared_ptr // groupId ReminderStore::GetStringVal(resultSet, ReminderTable::GROUP_ID, groupId_); + + // customRingUri + ReminderStore::GetStringVal(resultSet, ReminderTable::CUSTOM_RING_URI, customRingUri_); } void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) @@ -981,6 +985,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_; @@ -1095,6 +1109,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"); @@ -1190,6 +1205,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"); @@ -1790,6 +1806,7 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(ReminderTable::EXPIRED_CONTENT, reminder->GetExpiredContent()); values.PutInt(ReminderTable::REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); values.PutString(ReminderTable::GROUP_ID, reminder->GetGroupId()); + values.PutString(ReminderTable::CUSTOM_RING_URI, reminder->GetCustomRingUri()); AppendWantAgentValuesBucket(reminder, values); diff --git a/frameworks/ans/src/reminder_table.cpp b/frameworks/ans/src/reminder_table.cpp index 1a42c27899564e9f8fc37034928e289327eedc83..759220fdca4ab67a528f22a79a15fde6a7140ef8 100644 --- a/frameworks/ans/src/reminder_table.cpp +++ b/frameworks/ans/src/reminder_table.cpp @@ -52,6 +52,7 @@ 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"; +const std::string ReminderTable::CUSTOM_RING_URI = "custom_ring_uri"; // Reminder Table Calendar Columns. const std::string ReminderTable::REPEAT_DAYS = "repeat_days"; @@ -115,6 +116,7 @@ void ReminderTable::InitBasicColumns() AddColumn(AUTO_DELETED_TIME, "BIGINT"); AddColumn(REPEAT_DAYS_OF_WEEK, "INT"); AddColumn(GROUP_ID, "TEXT"); + AddColumn(CUSTOM_RING_URI, "TEXT", false); } void ReminderTable::InitCalendarColumns() diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index c0c9ef6a5905346bf81d9b6c2c5a51f4f3373214..eb5971666983cb9115d29da327b25a8e64bd32d2 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 char* SNOOZE_SLOT_TYPE = "snoozeSlotType"; const int INDEX_KEY = 0; const int INDEX_TYPE = 1; diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 86d2d4d72f00d89000b918abf8954927a3fb582c..b8f83116639203c3368881a21258730b1e3b4951 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -771,6 +771,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 fa2ce981388c9807aa119bdeb10969e29ecd7325..94fd3aae277844f7af167f8a4eeb8eb6b050c245 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -546,6 +546,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 b96f031e71a032ad6ce808e7b1a4423d4fd68529..a167472de23b56841f3d047077ec54eb426de425 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -774,6 +774,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. * @@ -892,6 +906,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; @@ -1022,6 +1037,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_table.h b/interfaces/inner_api/reminder_table.h index 8ac8c7b91add643c51a69938c76ce10b74af526c..520537ba19b25d4c4485d3eabc5a675878797ed3 100644 --- a/interfaces/inner_api/reminder_table.h +++ b/interfaces/inner_api/reminder_table.h @@ -197,6 +197,11 @@ public: */ static const std::string GROUP_ID; + /* + * reminder ring uri + */ + static const std::string CUSTOM_RING_URI; + // Reminder Table Calendar Columns. static const std::string REPEAT_DAYS; static const std::string REPEAT_MONTHS; diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 0c57a32429c472728c4d313679fabb20fc1aab37..ba3790ebcb57b87608234010f7db5dff3712f5d4 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 7ba84953188d91285d0f9975d6bf89ab0e9e4684..b321471eef52bdc7c01f7fcd1bc572532614337c 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1414,6 +1414,13 @@ void ReminderDataManager::PlaySoundAndVibrationLocked(const sptr &reminder) { + if (reminder == nullptr) { + return ""; + } + return reminder->GetCustomRingUri(); +} + void ReminderDataManager::PlaySoundAndVibration(const sptr &reminder) { if (reminder == nullptr) { @@ -1432,7 +1439,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