From ef9dad791e6c2f882c8a365c9b017423ef0c969d Mon Sep 17 00:00:00 2001 From: mubaoyu Date: Mon, 6 Nov 2023 17:58: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 | 29 ++++++++++++++++ frameworks/ans/src/reminder_store.cpp | 33 +++++++++++++++++-- .../napi/include/reminder/reminder_common.h | 1 + frameworks/js/napi/src/reminder/publish.cpp | 13 +++++--- .../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, 126 insertions(+), 8 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 6d8bc24a3..9478d731e 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) @@ -606,6 +608,12 @@ void ReminderRequest::RecoverFromDb(const std::shared_ptr // customButtonUri resultSet->GetString(ReminderStore::GetColumnIndex(CUSTOM_BUTTON_URI), customButtonUri_); + + // groupId + resultSet->GetString(ReminderStore::GetColumnIndex(GROUP_ID), groupId_); + + // customRingUri + resultSet->GetString(ReminderStore::GetColumnIndex(CUSTOM_RING_URI), customRingUri_); } void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) @@ -975,6 +983,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_; @@ -1082,6 +1100,11 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write customButtonUri"); return false; } + if (!parcel.WriteString(customRingUri_)) { + ANSR_LOGE("Failed to write customRingUri"); + return false; + } + // write bool if (!parcel.WriteBool(isExpired_)) { @@ -1264,6 +1287,10 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read customButtonUri"); return false; } + if (!parcel.ReadString(customRingUri_)) { + ANSR_LOGE("Failed to read customRingUri"); + return false; + } // read bool if (!parcel.ReadBool(isExpired_)) { @@ -1910,6 +1937,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"; @@ -1966,6 +1994,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 ca636cebe..b5310b902 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,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; @@ -439,5 +452,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 d2fb6ea6d..e14798941 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -760,6 +760,14 @@ 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); + // 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); @@ -768,11 +776,8 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi // actionButtons ParseActionButtons(env, reminder, result); - return NotificationNapi::Common::NapiGetBoolean(env, true); - // group id - napi_create_string_utf8(env, reminder.GetGroupId().c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, GROUP_ID, value); + return NotificationNapi::Common::NapiGetBoolean(env, true); } void GetValidRemindersInner(napi_env env, const std::vector>& validReminders, napi_value& arr) 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 3d6e6c8af..94326bfbb 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -671,6 +671,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. * @@ -788,6 +802,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; @@ -906,6 +921,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 8bb3c166f..fc977fddb 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 5fae70f7c..81846afe6 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -268,6 +268,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 e2c25de69..e4a0aea2a 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1406,6 +1406,13 @@ void ReminderDataManager::PlaySoundAndVibrationLocked(const sptr &reminder) { + if (reminder == nullptr) { + return ""; + } + return reminder->GetCustomRingUri(); +} + void ReminderDataManager::PlaySoundAndVibration(const sptr &reminder) { if (reminder == nullptr) { @@ -1424,7 +1431,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