From d5068ee86d070fdc073a8e05db77e4fc3eb85d20 Mon Sep 17 00:00:00 2001 From: XKK Date: Mon, 10 Jul 2023 14:49:41 +0800 Subject: [PATCH] =?UTF-8?q?preferences=E5=B9=B6=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- services/ans/src/notification_preferences.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 0c9ef2fbc..501deab94 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -49,6 +49,7 @@ ErrCode NotificationPreferences::AddNotificationSlots( if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || slots.empty()) { return ERR_ANS_INVALID_PARAM; } + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; for (auto slot : slots) { @@ -76,6 +77,7 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptr lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; NotificationPreferencesInfo::BundleInfo bundleInfo; preferencesInfo.SetBundleInfo(bundleInfo); @@ -97,6 +99,7 @@ ErrCode NotificationPreferences::RemoveNotificationSlot( if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; result = CheckSlotForRemoveSlot(bundleOption, slotType, preferencesInfo); @@ -116,6 +119,7 @@ ErrCode NotificationPreferences::RemoveNotificationAllSlots(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; NotificationPreferencesInfo::BundleInfo bundleInfo; @@ -141,7 +145,7 @@ ErrCode NotificationPreferences::RemoveNotificationForBundle(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; @@ -168,7 +172,7 @@ ErrCode NotificationPreferences::UpdateNotificationSlots( if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || slots.empty()) { return ERR_ANS_INVALID_PARAM; } - + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; for (auto slotIter : slots) { @@ -260,7 +264,7 @@ ErrCode NotificationPreferences::SetShowBadge(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SHOW_BADGE_TYPE, enable); if (result == ERR_OK) { @@ -284,6 +288,7 @@ ErrCode NotificationPreferences::SetImportance( if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_IMPORTANCE_TYPE, importance); if (result == ERR_OK) { @@ -307,6 +312,7 @@ ErrCode NotificationPreferences::SetTotalBadgeNums( if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE, num); if (result == ERR_OK) { @@ -360,7 +366,7 @@ ErrCode NotificationPreferences::SetNotificationsEnabled(const int32_t &userId, if (userId <= SUBSCRIBE_USER_INIT) { return ERR_ANS_INVALID_PARAM; } - + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; preferencesInfo.SetEnabledAllNotification(userId, enabled); ErrCode result = ERR_OK; @@ -387,7 +393,7 @@ ErrCode NotificationPreferences::SetHasPoppedDialog(const sptr lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = ERR_OK; result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_POPPED_DIALOG_TYPE, hasPopped); @@ -405,6 +411,7 @@ ErrCode NotificationPreferences::GetDoNotDisturbDate(const int32_t &userId, } ErrCode result = ERR_OK; + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; if (!preferencesInfo.GetDoNotDisturbDate(userId, date)) { result = ERR_ANS_INVALID_PARAM; @@ -419,7 +426,7 @@ ErrCode NotificationPreferences::SetDoNotDisturbDate(const int32_t &userId, if (userId <= SUBSCRIBE_USER_INIT) { return ERR_ANS_INVALID_PARAM; } - + std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; preferencesInfo.SetDoNotDisturbDate(userId, date); -- Gitee