diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index e2123a89ed9cc8fc0ac812cf8b1a46942f402a98..b1a6c68a96a04f7e2dd69330186885996038a66e 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -168,7 +168,6 @@ public: private: void TryTwice(const std::function &func) const; DistributedKv::Status GetKvStore(); - void CloseKvStore(); bool CheckKvStore(); bool CheckBundle(const std::string &bundleName, const int32_t &bundleUid); diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index b8b64fcbbd171989f328daf847f558032f6cfdef..c79e655279d3b5f26b2afb3607a24efa9df2ecbd 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -287,7 +287,7 @@ NotificationPreferencesDatabase::NotificationPreferencesDatabase() NotificationPreferencesDatabase::~NotificationPreferencesDatabase() { - CloseKvStore(); + dataManager_.CloseKvStore(appId_, kvStorePtr_); } void NotificationPreferencesDatabase::TryTwice(const std::function &func) const @@ -318,12 +318,6 @@ DistributedKv::Status NotificationPreferencesDatabase::GetKvStore() return status; } -void NotificationPreferencesDatabase::CloseKvStore() -{ - ANS_LOGI("Close kvStore success."); - dataManager_.CloseKvStore(appId_, kvStorePtr_); -} - bool NotificationPreferencesDatabase::CheckKvStore() { if (kvStorePtr_ != nullptr) { @@ -361,7 +355,6 @@ bool NotificationPreferencesDatabase::PutSlotsToDisturbeDB( return false; } DistributedKv::Status status = kvStorePtr_->PutBatch(entries); - CloseKvStore(); return (status == DistributedKv::Status::SUCCESS); } @@ -394,7 +387,6 @@ bool NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( break; } }); - CloseKvStore(); return result; } @@ -500,7 +492,6 @@ bool NotificationPreferencesDatabase::PutNotificationsEnabled(const int32_t &use DistributedKv::Key enableKey(typeKey); DistributedKv::Value enableValue(std::to_string(enabled)); DistributedKv::Status status = kvStorePtr_->Put(enableKey, enableValue); - CloseKvStore(); if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Store enable notification failed. %{public}d", status); return false; @@ -564,7 +555,6 @@ bool NotificationPreferencesDatabase::PutDoNotDisturbDate( }; DistributedKv::Status status = kvStorePtr_->PutBatch(entries); - CloseKvStore(); if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Store DoNotDisturbDate failed. %{public}d", status); return false; @@ -693,7 +683,6 @@ bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreference return false; } ParseBundleFromDistureDB(info, entries); - CloseKvStore(); return true; } @@ -723,7 +712,6 @@ bool NotificationPreferencesDatabase::RemoveBundleFromDisturbeDB(const std::stri if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Get Bundle Info failed."); - CloseKvStore(); return false; } @@ -735,7 +723,6 @@ bool NotificationPreferencesDatabase::RemoveBundleFromDisturbeDB(const std::stri DistributedKv::Key bundleDBKey(KEY_BUNDLE_LABEL + KEY_BUNDLE_NAME + KEY_UNDER_LINE + bundleKey); keys.push_back(bundleDBKey); status = kvStorePtr_->DeleteBatch(keys); - CloseKvStore(); if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("delete bundle Info failed."); return false; @@ -764,7 +751,6 @@ bool NotificationPreferencesDatabase::RemoveSlotFromDisturbeDB( status = kvStorePtr_->GetEntries(DistributedKv::Key(GenerateSlotKey(bundleKey, slotType) + KEY_UNDER_LINE), slotentries); if (status != DistributedKv::Status::SUCCESS) { - CloseKvStore(); return false; } std::vector keys; @@ -773,7 +759,6 @@ bool NotificationPreferencesDatabase::RemoveSlotFromDisturbeDB( } status = kvStorePtr_->DeleteBatch(keys); - CloseKvStore(); if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("delete bundle Info failed."); return false; @@ -800,7 +785,6 @@ bool NotificationPreferencesDatabase::RemoveAllSlotsFromDisturbeDB(const std::st std::vector slotsEntries; status = kvStorePtr_->GetEntries(DistributedKv::Key(GenerateSlotKey(bundleKey) + KEY_UNDER_LINE), slotsEntries); if (status != DistributedKv::Status::SUCCESS) { - CloseKvStore(); return false; } std::vector keys; @@ -809,7 +793,6 @@ bool NotificationPreferencesDatabase::RemoveAllSlotsFromDisturbeDB(const std::st } status = kvStorePtr_->DeleteBatch(keys); - CloseKvStore(); ANS_LOGD("%{public}s remove all slots status %{public}d", __FUNCTION__, status); return (status == DistributedKv::Status::SUCCESS); } @@ -855,7 +838,6 @@ DistributedKv::Status NotificationPreferencesDatabase::PutBundlePropertyToDistur return DistributedKv::Status::ERROR; } DistributedKv::Status status = kvStorePtr_->Put(key, value); - CloseKvStore(); return status; } @@ -1437,7 +1419,6 @@ bool NotificationPreferencesDatabase::RemoveNotificationEnable(const int32_t use std::string(KEY_ENABLE_ALL_NOTIFICATION).append(KEY_UNDER_LINE).append(std::to_string(userId)); DistributedKv::Key enableKey(key); DistributedKv::Status status = kvStorePtr_->Delete(enableKey); - CloseKvStore(); if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("delete bundle Info failed."); return false; @@ -1469,7 +1450,6 @@ bool NotificationPreferencesDatabase::RemoveDoNotDisturbDate(const int32_t userI }; DistributedKv::Status status = kvStorePtr_->DeleteBatch(keys); - CloseKvStore(); if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("delete DoNotDisturb date failed."); return false; @@ -1489,7 +1469,6 @@ bool NotificationPreferencesDatabase::RemoveAnsBundleDbInfo(std::string bundleNa std::string key = KEY_BUNDLE_LABEL + bundleName + std::to_string(uid); DistributedKv::Key enableKey(key); DistributedKv::Status status = kvStorePtr_->Delete(enableKey); - CloseKvStore(); if (status != DistributedKv::Status::SUCCESS) { ANS_LOGE("Delete ans bundle db info failed, bundle[%{public}s:%{public}d]", bundleName.c_str(), uid); return false; @@ -1499,4 +1478,4 @@ bool NotificationPreferencesDatabase::RemoveAnsBundleDbInfo(std::string bundleNa return true; } } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS