From db1606d9274bee2329d562beacc8f26678e1e98f Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 21 Dec 2023 20:18:59 +0800 Subject: [PATCH 1/3] fix ut bug Signed-off-by: gaojiaqi --- services/ans/include/reminder_data_manager.h | 2 +- services/ans/src/reminder_data_manager.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 8b0a553c5..00911fea9 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -42,7 +42,7 @@ public: { Init(false); }; - ~ReminderDataManager() {}; + ~ReminderDataManager(); ReminderDataManager(ReminderDataManager &other) = delete; ReminderDataManager& operator = (const ReminderDataManager &other) = delete; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 2422b9d86..11957db47 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -70,6 +70,8 @@ std::mutex ReminderDataManager::SHOW_MUTEX; std::mutex ReminderDataManager::ALERT_MUTEX; std::mutex ReminderDataManager::TIMER_MUTEX; +ReminderDataManager::~ReminderDataManager() = default; + ErrCode ReminderDataManager::PublishReminder(const sptr &reminder, const sptr &bundleOption) { -- Gitee From c8f0fe7a308e9cce61abd2c7d792b59137342f62 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 25 Dec 2023 16:16:07 +0800 Subject: [PATCH 2/3] fix bug Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 17 +++++++++++++++++ frameworks/ans/src/reminder_store.cpp | 7 ++++++- frameworks/ans/src/reminder_table.cpp | 4 +++- interfaces/inner_api/reminder_request.h | 15 +++++++++++++++ interfaces/inner_api/reminder_table.h | 5 +++++ .../ans/src/advanced_notification_service.cpp | 1 + services/ans/src/reminder_data_manager.cpp | 9 ++------- 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index d4700a173..39e3d264d 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -116,6 +116,7 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->repeatDaysOfWeek_ = other.repeatDaysOfWeek_; this->groupId_ = other.groupId_; this->customRingUri_ = other.customRingUri_; + this->creatorBundleName_ = other.creatorBundleName_; } ReminderRequest::ReminderRequest(int32_t reminderId) @@ -201,6 +202,11 @@ void ReminderRequest::SetExpired(bool isExpired) isExpired_ = isExpired; } +void ReminderRequest::InitCreatorBundleName(const std::string &creatorBundleName) +{ + creatorBundleName_ = creatorBundleName; +} + void ReminderRequest::InitReminderId() { std::lock_guard lock(std::mutex); @@ -600,6 +606,9 @@ void ReminderRequest::RecoverFromDb(const std::shared_ptr // customRingUri ReminderStore::GetStringVal(resultSet, ReminderTable::CUSTOM_RING_URI, customRingUri_); + + // creatorBundleName + ReminderStore::GetStringVal(resultSet, ReminderTable::CREATOR_BUNDLE_NAME, creatorBundleName_); } void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) @@ -824,6 +833,11 @@ std::map R return actionButtonMap_; } +std::string ReminderRequest::GetCreatorBundleName() const +{ + return creatorBundleName_; +} + std::string ReminderRequest::GetContent() const { return content_; @@ -1110,6 +1124,7 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const 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_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); // write bool WRITE_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); @@ -1206,6 +1221,7 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) 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_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); READ_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); READ_BOOL_RETURN_FALSE_LOG(parcel, isSystemApp_, "isSystemApp"); @@ -1803,6 +1819,7 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutInt(ReminderTable::REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); values.PutString(ReminderTable::GROUP_ID, reminder->GetGroupId()); values.PutString(ReminderTable::CUSTOM_RING_URI, reminder->GetCustomRingUri()); + values.PutString(ReminderTable::CREATOR_BUNDLE_NAME, reminder->GetCreatorBundleName()); AppendWantAgentValuesBucket(reminder, values); diff --git a/frameworks/ans/src/reminder_store.cpp b/frameworks/ans/src/reminder_store.cpp index d7a919354..f7a04e122 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/frameworks/ans/src/reminder_store.cpp @@ -32,7 +32,8 @@ namespace Notification { namespace { 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 REMINDER_RDB_VERSION_V3 = 3; +const uint32_t REMINDER_RDB_VERSION = 4; const int32_t STATE_FAIL = -1; std::string g_sqlColumns; } @@ -60,9 +61,13 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade( AddRdbColum(store, "groupId", "TEXT"); AddRdbColum(store, "custom_ring_uri", "TEXT"); AddRdbColum(store, "snooze_slot_id", "INT"); + AddRdbColum(store, "creator_bundle_name", "TEXT"); } else if (oldVersion == REMINDER_RDB_VERSION_V2) { AddRdbColum(store, "custom_ring_uri", "TEXT"); AddRdbColum(store, "snooze_slot_id", "INT"); + AddRdbColum(store, "creator_bundle_name", "TEXT"); + } else if (oldVersion == REMINDER_RDB_VERSION_V3) { + AddRdbColum(store, "creator_bundle_name", "TEXT"); } } store.SetVersion(newVersion); diff --git a/frameworks/ans/src/reminder_table.cpp b/frameworks/ans/src/reminder_table.cpp index 72b8240e9..77846d0db 100644 --- a/frameworks/ans/src/reminder_table.cpp +++ b/frameworks/ans/src/reminder_table.cpp @@ -53,6 +53,7 @@ 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"; +const std::string ReminderTable::CREATOR_BUNDLE_NAME = "creator_bundle_name"; // Reminder Table Calendar Columns. const std::string ReminderTable::REPEAT_DAYS = "repeat_days"; @@ -116,7 +117,8 @@ void ReminderTable::InitBasicColumns() AddColumn(AUTO_DELETED_TIME, "BIGINT"); AddColumn(REPEAT_DAYS_OF_WEEK, "INT"); AddColumn(GROUP_ID, "TEXT"); - AddColumn(CUSTOM_RING_URI, "TEXT", false); + AddColumn(CUSTOM_RING_URI, "TEXT"); + AddColumn(CREATOR_BUNDLE_NAME, "TEXT", false); } void ReminderTable::InitCalendarColumns() diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index a167472de..f84fbb5da 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -311,6 +311,13 @@ public: */ std::map GetActionButtons() const; + /** + * @brief Obtains creator bundle name + * + * @return creator bundle name + */ + std::string GetCreatorBundleName() const; + /** * @brief Obtains the configured content. * @@ -441,6 +448,13 @@ public: */ std::shared_ptr GetWantAgentInfo() const; + /** + * @brief Inites reminder creator bundle name when publish reminder success. + * + * @param creatorBundleName Indicates the creator bundle name which the reminder belong to + */ + void InitCreatorBundleName(const std::string &creatorBundleName); + /** * @brief Inits reminder id when publish reminder success. * Assign a unique reminder id for each reminder. @@ -1038,6 +1052,7 @@ private: int64_t autoDeletedTime_ {0}; std::string customButtonUri_ {}; std::string customRingUri_ {}; + std::string creatorBundleName_ {}; // 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 0a82370fb..8273c3774 100644 --- a/interfaces/inner_api/reminder_table.h +++ b/interfaces/inner_api/reminder_table.h @@ -202,6 +202,11 @@ public: */ static const std::string CUSTOM_RING_URI; + /* + * reminder creator bundle name + */ + static const std::string CREATOR_BUNDLE_NAME; + // Reminder Table Calendar Columns. static const std::string REPEAT_DAYS; static const std::string REPEAT_MONTHS; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 6b8f4b1b4..effd5462f 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2572,6 +2572,7 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi sptr notificationRequest = reminder->GetNotificationRequest(); std::string bundle = GetClientBundleName(); + reminder->InitCreatorBundleName(bundle); if (reminder->GetWantAgentInfo() == nullptr || reminder->GetMaxScreenWantAgentInfo() == nullptr) { ANSR_LOGE("wantagent info is nullptr"); return ERR_ANS_INVALID_PARAM; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 11957db47..6210f5c08 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -466,12 +466,7 @@ sptr ReminderDataManager::FindReminderRequestLocked( if (reminder == nullptr) { return nullptr; } - sptr notificationRequest = reminder->GetNotificationRequest(); - if (notificationRequest == nullptr) { - ANSR_LOGW("Not find the reminder due to notification request is null"); - return nullptr; - } - if (notificationRequest->GetCreatorBundleName() != pkgName) { + if (reminder->GetCreatorBundleName() != pkgName) { ANSR_LOGW("Not find the reminder due to package name not match"); return nullptr; } @@ -988,7 +983,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co return; } if (!IsAllowedNotify(reminder)) { - ANSR_LOGD("Not allow to notify."); + ANSR_LOGE("Not allow to notify."); reminder->OnShow(false, isSysTimeChanged, false); store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); return; -- Gitee From eb51fca4855cea22f1aecf5411b5a67ecc67d3cb Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 25 Dec 2023 16:24:34 +0800 Subject: [PATCH 3/3] add ut test Signed-off-by: gaojiaqi --- .../test/unittest/reminder_request_test.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index c7b5427c5..d40222b5f 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1905,5 +1905,33 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00300, Function | SmallTe // then EXPECT_EQ(ret->GetSlotType(), NotificationConstant::SlotType::SOCIAL_COMMUNICATION); } + +/** + * @tc.name: InitCreatorBundleName_00001 + * @tc.desc: Test InitCreatorBundleName with normal parameters. + * @tc.type: FUNC + * @tc.require: issue#I8R55M + */ +HWTEST_F(ReminderRequestTest, InitCreatorBundleName_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string bundleName = "com.example.myapplication"; + rrc->InitCreatorBundleName(bundleName); + EXPECT_EQ(rrc->GetCreatorBundleName(), bundleName); +} + +/** + * @tc.name: InitCreatorBundleName_00002 + * @tc.desc: Test InitCreatorBundleName with special parameters. + * @tc.type: FUNC + * @tc.require: issue#I8R55M + */ +HWTEST_F(ReminderRequestTest, InitCreatorBundleName_00002, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string bundleName = "com.example.myapplication.~!@#$%^&*()"; + rrc->InitCreatorBundleName(bundleName); + EXPECT_EQ(rrc->GetCreatorBundleName(), bundleName); +} } } -- Gitee