From 7f5fdd7b718d1ed12cb8dbedfd406d39f970e520 Mon Sep 17 00:00:00 2001 From: mubaoyu Date: Mon, 13 Nov 2023 20:47:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E9=97=B9=E9=92=9F=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8F=90=E7=A4=BA=E5=A3=B0=E9=9F=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mubaoyu --- frameworks/ans/src/reminder_request.cpp | 19 +++++++++++ frameworks/ans/src/reminder_store.cpp | 33 +++++++++++++++++-- .../napi/include/reminder/reminder_common.h | 1 + frameworks/js/napi/src/reminder/publish.cpp | 4 +++ .../js/napi/src/reminder/reminder_common.cpp | 5 +++ interfaces/inner_api/reminder_request.h | 16 +++++++++ interfaces/inner_api/reminder_store.h | 3 +- services/ans/include/reminder_data_manager.h | 8 +++++ services/ans/src/reminder_data_manager.cpp | 11 ++++++- .../unittest/reminder_data_manager_test.cpp | 15 +++++++++ 10 files changed, 111 insertions(+), 4 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 8904f2caa..493f8dee0 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 93b0486a5..a3c888d5e 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 ccfc39a21..ee774a7ae 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 c8b977c1c..2aa6e3a9d 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 0351e0c74..3227c5f3f 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 a174bfa93..ed4f00f60 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 58be32314..107ed6a52 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 0c08c0462..0f326eef3 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 b91ea9b2d..ab5febf22 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 bdaf6253d..e22cd54c1 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 -- Gitee