From 21d12a41e84d2b80814926ed295d7a72d1b25983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=AE?= Date: Mon, 31 Oct 2022 16:16:23 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:=20#I5YM1V=20Description:=20=E5=A4=9A?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=93=8D=E4=BD=9CkvStore=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=20Sig:=20SIG=5FApplicationFramework=20Featur?= =?UTF-8?q?e=20or=20Bugfix:=20Bugfix=20Binary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨亮 Change-Id: Ief0aca77e0ddd00b6deaa9e8a1d790814bdb5341 --- .../notification_preferences_database.h | 1 - .../src/notification_preferences_database.cpp | 25 ++----------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index e2123a89e..b1a6c68a9 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 b8b64fcbb..c79e65527 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 -- Gitee