diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 15484ecafad55a1399e10469fb66b34e43881b44..530c570fdbf33ad878e35ff36ee65a645f8423a9 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -247,13 +247,13 @@ public: private: ErrCode CheckSlotForCreateSlot(const sptr &bundleOption, - const sptr &slot, NotificationPreferencesInfo &preferencesInfo) const; + const sptr &slot, std::shared_ptr preferencesInfo) const; ErrCode CheckSlotForRemoveSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, NotificationPreferencesInfo &preferencesInfo) const; + const NotificationConstant::SlotType &slotType, std::shared_ptr preferencesInfo) const; ErrCode CheckSlotForUpdateSlot(const sptr &bundleOption, - const sptr &slot, NotificationPreferencesInfo &preferencesInfo) const; + const sptr &slot, std::shared_ptr preferencesInfo) const; template - ErrCode SetBundleProperty(NotificationPreferencesInfo &preferencesInfo, + ErrCode SetBundleProperty(std::shared_ptr preferencesInfo, const sptr &bundleOption, const BundleType &type, const T &value); template ErrCode SaveBundleProperty(NotificationPreferencesInfo::BundleInfo &bundleInfo, @@ -265,7 +265,7 @@ private: bool CheckApiCompatibility(const sptr &bundleOption) const; private: - NotificationPreferencesInfo preferencesInfo_ {}; + std::shared_ptr preferencesInfo_ = std::make_shared(); std::unique_ptr preferncesDB_ = nullptr; DECLARE_DELAYED_REF_SINGLETON(NotificationPreferences); }; diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index afc0460436e63677a5a33c2c40dd7b21ad1ffb4a..04e5329e61918e32c32ab70c67bb92d3c8700692 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -112,7 +112,7 @@ public: * @param info Indicates notification info. * @return Return true on success, false on failure. */ - bool ParseFromDisturbeDB(NotificationPreferencesInfo &info); + bool ParseFromDisturbeDB(std::shared_ptr info); /** * @brief Delete all data from disturbe DB. @@ -191,15 +191,15 @@ private: std::string GenerateBundleKey(const std::string &bundleKey, const std::string &type = "") const; void ParseBundleFromDistureDB( - NotificationPreferencesInfo &info, const std::unordered_map &entries); + std::shared_ptr info, const std::unordered_map &entries); void ParseSlotFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &bundleKey, const std::pair &entry); void ParseBundlePropertyFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &bundleKey, const std::pair &entry); - void ParseDoNotDisturbType(NotificationPreferencesInfo &info); - void ParseDoNotDisturbBeginDate(NotificationPreferencesInfo &info); - void ParseDoNotDisturbEndDate(NotificationPreferencesInfo &info); - void ParseEnableAllNotification(NotificationPreferencesInfo &info); + void ParseDoNotDisturbType(std::shared_ptr info); + void ParseDoNotDisturbBeginDate(std::shared_ptr info); + void ParseDoNotDisturbEndDate(std::shared_ptr info); + void ParseEnableAllNotification(std::shared_ptr info); void ParseBundleName(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleImportance(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleShowBadge(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; @@ -224,10 +224,10 @@ private: void ParseSlotEnabled(sptr &slot, const std::string &value) const; std::string GenerateBundleLablel(const NotificationPreferencesInfo::BundleInfo &bundleInfo) const; - void GetDoNotDisturbType(NotificationPreferencesInfo &info, int32_t userId); - void GetDoNotDisturbBeginDate(NotificationPreferencesInfo &info, int32_t userId); - void GetDoNotDisturbEndDate(NotificationPreferencesInfo &info, int32_t userId); - void GetEnableAllNotification(NotificationPreferencesInfo &info, int32_t userId); + void GetDoNotDisturbType(std::shared_ptr info, int32_t userId); + void GetDoNotDisturbBeginDate(std::shared_ptr info, int32_t userId); + void GetDoNotDisturbEndDate(std::shared_ptr info, int32_t userId); + void GetEnableAllNotification(std::shared_ptr info, int32_t userId); static const std::map &, std::string &)>> diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 76d4bc62f3c184b668474c4bf02d817ecb6ae3ee..6b55e225b36c3efd7f84b5180f8892e60a5103af 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -49,7 +49,7 @@ ErrCode NotificationPreferences::AddNotificationSlots( if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || slots.empty()) { return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + std::shared_ptr preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; for (auto slot : slots) { result = CheckSlotForCreateSlot(bundleOption, slot, preferencesInfo); @@ -76,9 +76,9 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptr preferencesInfo = preferencesInfo_; NotificationPreferencesInfo::BundleInfo bundleInfo; - preferencesInfo.SetBundleInfo(bundleInfo); + preferencesInfo->SetBundleInfo(bundleInfo); ErrCode result = ERR_OK; if (preferncesDB_->PutBundlePropertyToDisturbeDB(bundleInfo)) { preferencesInfo_ = preferencesInfo; @@ -97,7 +97,7 @@ ErrCode NotificationPreferences::RemoveNotificationSlot( if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + std::shared_ptr preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; result = CheckSlotForRemoveSlot(bundleOption, slotType, preferencesInfo); if (result == ERR_OK && (!preferncesDB_->RemoveSlotFromDisturbeDB(GenerateBundleKey(bundleOption), slotType))) { @@ -116,12 +116,12 @@ ErrCode NotificationPreferences::RemoveNotificationAllSlots(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + std::shared_ptr preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; NotificationPreferencesInfo::BundleInfo bundleInfo; - if (preferencesInfo.GetBundleInfo(bundleOption, bundleInfo)) { + if (preferencesInfo->GetBundleInfo(bundleOption, bundleInfo)) { bundleInfo.RemoveAllSlots(); - preferencesInfo.SetBundleInfo(bundleInfo); + preferencesInfo->SetBundleInfo(bundleInfo); if (!preferncesDB_->RemoveAllSlotsFromDisturbeDB(GenerateBundleKey(bundleOption))) { result = ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } @@ -142,11 +142,11 @@ ErrCode NotificationPreferences::RemoveNotificationForBundle(const sptr preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; - if (preferencesInfo.IsExsitBundleInfo(bundleOption)) { - preferencesInfo.RemoveBundleInfo(bundleOption); + if (preferencesInfo->IsExsitBundleInfo(bundleOption)) { + preferencesInfo->RemoveBundleInfo(bundleOption); if (!preferncesDB_->RemoveBundleFromDisturbeDB(GenerateBundleKey(bundleOption))) { result = ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } @@ -169,7 +169,7 @@ ErrCode NotificationPreferences::UpdateNotificationSlots( return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; +std::shared_ptr preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; for (auto slotIter : slots) { result = CheckSlotForUpdateSlot(bundleOption, slotIter, preferencesInfo); @@ -200,7 +200,7 @@ ErrCode NotificationPreferences::GetNotificationSlot(const sptrGetBundleInfo(bundleOption, bundleInfo)) { if (!bundleInfo.GetSlot(type, slot)) { result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; } @@ -220,7 +220,7 @@ ErrCode NotificationPreferences::GetNotificationAllSlots( ErrCode result = ERR_OK; NotificationPreferencesInfo::BundleInfo bundleInfo; - if (preferencesInfo_.GetBundleInfo(bundleOption, bundleInfo)) { + if (preferencesInfo_->GetBundleInfo(bundleOption, bundleInfo)) { bundleInfo.GetAllSlots(slots); } else { ANS_LOGW("Notification bundle does not exsit."); @@ -239,7 +239,7 @@ ErrCode NotificationPreferences::GetNotificationSlotsNumForBundle( ErrCode result = ERR_OK; NotificationPreferencesInfo::BundleInfo bundleInfo; - if (preferencesInfo_.GetBundleInfo(bundleOption, bundleInfo)) { + if (preferencesInfo_->GetBundleInfo(bundleOption, bundleInfo)) { num = static_cast(bundleInfo.GetAllSlotsSize()); } else { result = ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST; @@ -261,7 +261,7 @@ ErrCode NotificationPreferences::SetShowBadge(const sptr preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SHOW_BADGE_TYPE, enable); if (result == ERR_OK) { preferencesInfo_ = preferencesInfo; @@ -284,7 +284,7 @@ ErrCode NotificationPreferences::SetImportance( if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + std::shared_ptr preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_IMPORTANCE_TYPE, importance); if (result == ERR_OK) { preferencesInfo_ = preferencesInfo; @@ -307,7 +307,7 @@ ErrCode NotificationPreferences::SetTotalBadgeNums( if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + std::shared_ptr preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE, num); if (result == ERR_OK) { preferencesInfo_ = preferencesInfo; @@ -332,7 +332,7 @@ ErrCode NotificationPreferences::SetNotificationsEnabledForBundle( return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + std::shared_ptr preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_ENABLE_NOTIFICATION_TYPE, enabled); if (result == ERR_OK) { @@ -348,7 +348,7 @@ ErrCode NotificationPreferences::GetNotificationsEnabled(const int32_t &userId, } ErrCode result = ERR_OK; - if (!preferencesInfo_.GetEnabledAllNotification(userId, enabled)) { + if (!preferencesInfo_->GetEnabledAllNotification(userId, enabled)) { result = ERR_ANS_INVALID_PARAM; } return result; @@ -360,8 +360,8 @@ ErrCode NotificationPreferences::SetNotificationsEnabled(const int32_t &userId, return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; - preferencesInfo.SetEnabledAllNotification(userId, enabled); + std::shared_ptr preferencesInfo = preferencesInfo_; + preferencesInfo->SetEnabledAllNotification(userId, enabled); ErrCode result = ERR_OK; if (!preferncesDB_->PutNotificationsEnabled(userId, enabled)) { result = ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; @@ -387,7 +387,7 @@ ErrCode NotificationPreferences::SetHasPoppedDialog(const sptr preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_POPPED_DIALOG_TYPE, hasPopped); if (result == ERR_OK) { @@ -404,8 +404,8 @@ ErrCode NotificationPreferences::GetDoNotDisturbDate(const int32_t &userId, } ErrCode result = ERR_OK; - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; - if (!preferencesInfo.GetDoNotDisturbDate(userId, date)) { + std::shared_ptr preferencesInfo = preferencesInfo_; + if (!preferencesInfo->GetDoNotDisturbDate(userId, date)) { result = ERR_ANS_INVALID_PARAM; } return result; @@ -419,8 +419,8 @@ ErrCode NotificationPreferences::SetDoNotDisturbDate(const int32_t &userId, return ERR_ANS_INVALID_PARAM; } - NotificationPreferencesInfo preferencesInfo = preferencesInfo_; - preferencesInfo.SetDoNotDisturbDate(userId, date); + std::shared_ptr preferencesInfo = preferencesInfo_; + preferencesInfo->SetDoNotDisturbDate(userId, date); ErrCode result = ERR_OK; if (!preferncesDB_->PutDoNotDisturbDate(userId, date)) { @@ -441,13 +441,13 @@ ErrCode NotificationPreferences::ClearNotificationInRestoreFactorySettings() } if (result == ERR_OK) { - preferencesInfo_ = NotificationPreferencesInfo(); + preferencesInfo_ = std::make_shared(); } return result; } ErrCode NotificationPreferences::CheckSlotForCreateSlot(const sptr &bundleOption, - const sptr &slot, NotificationPreferencesInfo &preferencesInfo) const + const sptr &slot, std::shared_ptr preferencesInfo) const { if (slot == nullptr) { ANS_LOGE("Notification slot is nullptr."); @@ -455,26 +455,26 @@ ErrCode NotificationPreferences::CheckSlotForCreateSlot(const sptrGetBundleInfo(bundleOption, bundleInfo)) { bundleInfo.SetBundleName(bundleOption->GetBundleName()); bundleInfo.SetBundleUid(bundleOption->GetUid()); bundleInfo.SetEnableNotification(CheckApiCompatibility(bundleOption)); } bundleInfo.SetSlot(slot); - preferencesInfo.SetBundleInfo(bundleInfo); + preferencesInfo->SetBundleInfo(bundleInfo); return ERR_OK; } ErrCode NotificationPreferences::CheckSlotForRemoveSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, NotificationPreferencesInfo &preferencesInfo) const + const NotificationConstant::SlotType &slotType, std::shared_ptr preferencesInfo) const { ErrCode result = ERR_OK; NotificationPreferencesInfo::BundleInfo bundleInfo; - if (preferencesInfo.GetBundleInfo(bundleOption, bundleInfo)) { + if (preferencesInfo->GetBundleInfo(bundleOption, bundleInfo)) { if (bundleInfo.IsExsitSlot(slotType)) { bundleInfo.RemoveSlot(slotType); - preferencesInfo.SetBundleInfo(bundleInfo); + preferencesInfo->SetBundleInfo(bundleInfo); } else { ANS_LOGE("Notification slot type does not exsited."); result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; @@ -487,7 +487,7 @@ ErrCode NotificationPreferences::CheckSlotForRemoveSlot(const sptr &bundleOption, - const sptr &slot, NotificationPreferencesInfo &preferencesInfo) const + const sptr &slot, std::shared_ptr preferencesInfo) const { if (slot == nullptr) { ANS_LOGE("Notification slot is nullptr."); @@ -496,12 +496,12 @@ ErrCode NotificationPreferences::CheckSlotForUpdateSlot(const sptrGetBundleInfo(bundleOption, bundleInfo)) { if (bundleInfo.IsExsitSlot(slot->GetType())) { bundleInfo.SetBundleName(bundleOption->GetBundleName()); bundleInfo.SetBundleUid(bundleOption->GetUid()); bundleInfo.SetSlot(slot); - preferencesInfo.SetBundleInfo(bundleInfo); + preferencesInfo->SetBundleInfo(bundleInfo); } else { ANS_LOGE("Notification slot type does not exist."); result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST; @@ -515,19 +515,19 @@ ErrCode NotificationPreferences::CheckSlotForUpdateSlot(const sptr -ErrCode NotificationPreferences::SetBundleProperty(NotificationPreferencesInfo &preferencesInfo, +ErrCode NotificationPreferences::SetBundleProperty(std::shared_ptr preferencesInfo, const sptr &bundleOption, const BundleType &type, const T &value) { ErrCode result = ERR_OK; NotificationPreferencesInfo::BundleInfo bundleInfo; - if (!preferencesInfo_.GetBundleInfo(bundleOption, bundleInfo)) { + if (!preferencesInfo_->GetBundleInfo(bundleOption, bundleInfo)) { bundleInfo.SetBundleName(bundleOption->GetBundleName()); bundleInfo.SetBundleUid(bundleOption->GetUid()); bundleInfo.SetEnableNotification(CheckApiCompatibility(bundleOption)); } result = SaveBundleProperty(bundleInfo, bundleOption, type, value); - preferencesInfo.SetBundleInfo(bundleInfo); + preferencesInfo->SetBundleInfo(bundleInfo); return result; } @@ -570,7 +570,7 @@ ErrCode NotificationPreferences::GetBundleProperty( { ErrCode result = ERR_OK; NotificationPreferencesInfo::BundleInfo bundleInfo; - if (preferencesInfo_.GetBundleInfo(bundleOption, bundleInfo)) { + if (preferencesInfo_->GetBundleInfo(bundleOption, bundleInfo)) { switch (type) { case BundleType::BUNDLE_IMPORTANCE_TYPE: value = bundleInfo.GetImportance(); @@ -654,8 +654,8 @@ void NotificationPreferences::RemoveSettings(int32_t userId) { ANS_LOGD("%{public}s", __FUNCTION__); - preferencesInfo_.RemoveNotificationEnable(userId); - preferencesInfo_.RemoveDoNotDisturbDate(userId); + preferencesInfo_->RemoveNotificationEnable(userId); + preferencesInfo_->RemoveDoNotDisturbDate(userId); if (preferncesDB_ != nullptr) { preferncesDB_->RemoveNotificationEnable(userId); @@ -681,4 +681,4 @@ void NotificationPreferences::RemoveAnsBundleDbInfo(const sptr info) { ANS_LOGD("%{public}s", __FUNCTION__); ParseDoNotDisturbType(info); @@ -831,7 +831,7 @@ void NotificationPreferencesDatabase::GenerateSlotEntry(const std::string &bundl } void NotificationPreferencesDatabase::ParseBundleFromDistureDB( - NotificationPreferencesInfo &info, const std::unordered_map &values) + std::shared_ptr info, const std::unordered_map &values) { if (!CheckRdbStore()) { ANS_LOGE("RdbStore is nullptr."); @@ -852,7 +852,7 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( } } - info.SetBundleInfoFromDb(bunldeInfo, bundleKey); + info->SetBundleInfoFromDb(bunldeInfo, bundleKey); } } @@ -1028,7 +1028,7 @@ std::string NotificationPreferencesDatabase::SubUniqueIdentifyFromString( return slotType; } -void NotificationPreferencesDatabase::ParseDoNotDisturbType(NotificationPreferencesInfo &info) +void NotificationPreferencesDatabase::ParseDoNotDisturbType(std::shared_ptr info) { std::vector activeUserId; OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeUserId); @@ -1038,7 +1038,7 @@ void NotificationPreferencesDatabase::ParseDoNotDisturbType(NotificationPreferen } } -void NotificationPreferencesDatabase::ParseDoNotDisturbBeginDate(NotificationPreferencesInfo &info) +void NotificationPreferencesDatabase::ParseDoNotDisturbBeginDate(std::shared_ptr info) { std::vector activeUserId; OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeUserId); @@ -1048,7 +1048,7 @@ void NotificationPreferencesDatabase::ParseDoNotDisturbBeginDate(NotificationPre } } -void NotificationPreferencesDatabase::ParseDoNotDisturbEndDate(NotificationPreferencesInfo &info) +void NotificationPreferencesDatabase::ParseDoNotDisturbEndDate(std::shared_ptr info) { std::vector activeUserId; OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeUserId); @@ -1058,7 +1058,7 @@ void NotificationPreferencesDatabase::ParseDoNotDisturbEndDate(NotificationPrefe } } -void NotificationPreferencesDatabase::ParseEnableAllNotification(NotificationPreferencesInfo &info) +void NotificationPreferencesDatabase::ParseEnableAllNotification(std::shared_ptr info) { std::vector activeUserId; OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeUserId); @@ -1210,7 +1210,7 @@ std::string NotificationPreferencesDatabase::GenerateBundleLablel( return bundleInfo.GetBundleName().append(std::to_string(bundleInfo.GetBundleUid())); } -void NotificationPreferencesDatabase::GetDoNotDisturbType(NotificationPreferencesInfo &info, int32_t userId) +void NotificationPreferencesDatabase::GetDoNotDisturbType(std::shared_ptr info, int32_t userId) { std::string key = std::string().append(KEY_DO_NOT_DISTURB_TYPE).append(KEY_UNDER_LINE).append(std::to_string(userId)); @@ -1218,7 +1218,7 @@ void NotificationPreferencesDatabase::GetDoNotDisturbType(NotificationPreference key, [&](const int32_t &status, std::string &value) { sptr disturbDate = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); - info.GetDoNotDisturbDate(userId, disturbDate); + info->GetDoNotDisturbDate(userId, disturbDate); if (status == NativeRdb::E_EMPTY_VALUES_BUCKET) { PutDoNotDisturbDate(userId, disturbDate); } else if (status == NativeRdb::E_OK) { @@ -1231,11 +1231,11 @@ void NotificationPreferencesDatabase::GetDoNotDisturbType(NotificationPreference } else { ANS_LOGW("Parse disturbe mode failed, use default value."); } - info.SetDoNotDisturbDate(userId, disturbDate); + info->SetDoNotDisturbDate(userId, disturbDate); }); } -void NotificationPreferencesDatabase::GetDoNotDisturbBeginDate(NotificationPreferencesInfo &info, int32_t userId) +void NotificationPreferencesDatabase::GetDoNotDisturbBeginDate(std::shared_ptr info, int32_t userId) { std::string key = std::string().append(KEY_DO_NOT_DISTURB_BEGIN_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); @@ -1243,7 +1243,7 @@ void NotificationPreferencesDatabase::GetDoNotDisturbBeginDate(NotificationPrefe key, [&](const int32_t &status, std::string &value) { sptr disturbDate = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); - info.GetDoNotDisturbDate(userId, disturbDate); + info->GetDoNotDisturbDate(userId, disturbDate); if (status == NativeRdb::E_EMPTY_VALUES_BUCKET) { PutDoNotDisturbDate(userId, disturbDate); } else if (status == NativeRdb::E_OK) { @@ -1255,11 +1255,11 @@ void NotificationPreferencesDatabase::GetDoNotDisturbBeginDate(NotificationPrefe } else { ANS_LOGW("Parse disturbe start time failed, use default value."); } - info.SetDoNotDisturbDate(userId, disturbDate); + info->SetDoNotDisturbDate(userId, disturbDate); }); } -void NotificationPreferencesDatabase::GetDoNotDisturbEndDate(NotificationPreferencesInfo &info, int32_t userId) +void NotificationPreferencesDatabase::GetDoNotDisturbEndDate(std::shared_ptr info, int32_t userId) { std::string key = std::string().append(KEY_DO_NOT_DISTURB_END_DATE).append(KEY_UNDER_LINE).append(std::to_string(userId)); @@ -1267,7 +1267,7 @@ void NotificationPreferencesDatabase::GetDoNotDisturbEndDate(NotificationPrefere key, [&](const int32_t &status, std::string &value) { sptr disturbDate = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); - info.GetDoNotDisturbDate(userId, disturbDate); + info->GetDoNotDisturbDate(userId, disturbDate); if (status == NativeRdb::E_EMPTY_VALUES_BUCKET) { PutDoNotDisturbDate(userId, disturbDate); } else if (status == NativeRdb::E_OK) { @@ -1279,11 +1279,11 @@ void NotificationPreferencesDatabase::GetDoNotDisturbEndDate(NotificationPrefere } else { ANS_LOGW("Parse disturbe end time failed, use default value."); } - info.SetDoNotDisturbDate(userId, disturbDate); + info->SetDoNotDisturbDate(userId, disturbDate); }); } -void NotificationPreferencesDatabase::GetEnableAllNotification(NotificationPreferencesInfo &info, int32_t userId) +void NotificationPreferencesDatabase::GetEnableAllNotification(std::shared_ptr info, int32_t userId) { std::string key = std::string().append(KEY_ENABLE_ALL_NOTIFICATION).append(KEY_UNDER_LINE).append(std::to_string(userId)); @@ -1291,14 +1291,14 @@ void NotificationPreferencesDatabase::GetEnableAllNotification(NotificationPrefe key, [&](const int32_t &status, std::string &value) { if (status == NativeRdb::E_EMPTY_VALUES_BUCKET) { bool enable = true; - if (!info.GetEnabledAllNotification(userId, enable)) { - info.SetEnabledAllNotification(userId, enable); + if (!info->GetEnabledAllNotification(userId, enable)) { + info->SetEnabledAllNotification(userId, enable); ANS_LOGW("Enable setting not found, default true."); } PutNotificationsEnabled(userId, enable); } else if (status == NativeRdb::E_OK) { if (!value.empty()) { - info.SetEnabledAllNotification(userId, static_cast(StringToInt(value))); + info->SetEnabledAllNotification(userId, static_cast(StringToInt(value))); } } else { ANS_LOGW("Parse enable all notification failed, use default value."); diff --git a/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp b/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp index 73126ebcd409cc86c1d2ae357391a64462294c23..566178f06c31adeca0b5f96425d2805de5c444d9 100755 --- a/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp +++ b/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp @@ -366,7 +366,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0200 // set CheckRdbStore is false MockInit(false); // test ParseFromDisturbeDB function - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); EXPECT_EQ(preferncesDB_->ParseFromDisturbeDB(info), false); } @@ -382,7 +382,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0210 // set result == NativeRdb::E_ERROR MockQueryDataBeginWithKey(false); // test ParseFromDisturbeDB function - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); EXPECT_EQ(preferncesDB_->ParseFromDisturbeDB(info), false); } @@ -728,7 +728,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0430 { // set CheckRdbStore is false MockInit(false); - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); std::unordered_map values; ASSERT_NE(nullptr, preferncesDB_); preferncesDB_->ParseBundleFromDistureDB(info, values); @@ -780,7 +780,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0470 // set status is NativeRdb::E_ERROR MockQueryData(true); // test GetDoNotDisturbType function - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); int32_t userId = 1; ASSERT_NE(nullptr, preferncesDB_); preferncesDB_->GetDoNotDisturbType(info, userId); @@ -798,7 +798,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0480 // set status is NativeRdb::E_ERROR MockQueryData(true); // test GetDoNotDisturbBeginDate function - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); int32_t userId = 1; ASSERT_NE(nullptr, preferncesDB_); preferncesDB_->GetDoNotDisturbBeginDate(info, userId); @@ -816,7 +816,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0490 // set status is NativeRdb::E_ERROR MockQueryData(true); // test GetDoNotDisturbEndDate function - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); int32_t userId = 1; ASSERT_NE(nullptr, preferncesDB_); preferncesDB_->GetDoNotDisturbEndDate(info, userId); @@ -834,7 +834,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0500 // set status is NativeRdb::E_ERROR MockQueryData(true); // test GetEnableAllNotification function - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); int32_t userId = 1; ASSERT_NE(nullptr, preferncesDB_); preferncesDB_->GetEnableAllNotification(info, userId); diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index a85425dc0c20ab335a4fc527ffe32f8804cb3c60..28bfb14e40d9cae8b4f6f3b83a1c6769cddf8b92 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -35,7 +35,7 @@ public: void TearDown(); void TestAddNotificationSlot(); - void TestAddNotificationSlot(NotificationPreferencesInfo &info); + void TestAddNotificationSlot(std::shared_ptr info); static sptr bundleOption_; static sptr noExsitbundleOption_; @@ -67,10 +67,11 @@ void NotificationPreferencesTest::TestAddNotificationSlot() NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots); } -void NotificationPreferencesTest::TestAddNotificationSlot(NotificationPreferencesInfo &info) +void NotificationPreferencesTest::TestAddNotificationSlot(std::shared_ptr + notificationPreferencesInfo) { sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); - NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info); + NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, notificationPreferencesInfo); } /** @@ -1132,7 +1133,7 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00300, Fu */ HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, nullptr, info), (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST); @@ -1146,7 +1147,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; +std::shared_ptr info = std::make_shared(); sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info), (int)ERR_OK); @@ -1161,7 +1162,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); TestAddNotificationSlot(info); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_OK); @@ -1175,7 +1176,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); @@ -1189,7 +1190,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); TestAddNotificationSlot(info); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, info), @@ -1205,7 +1206,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | S HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | SmallTest | Level1) { sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, nullptr, info), (int)ERR_ANS_INVALID_PARAM); } @@ -1219,7 +1220,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); @@ -1234,7 +1235,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00300, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); TestAddNotificationSlot(info); sptr slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), @@ -1249,7 +1250,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00300, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00400, Function | SmallTest | Level1) { - NotificationPreferencesInfo info; + std::shared_ptr info = std::make_shared(); TestAddNotificationSlot(info); sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info),