From a92344c5f5310755628682a39cea06f945667f8b Mon Sep 17 00:00:00 2001 From: zhai-peizhe Date: Sat, 13 Sep 2025 15:04:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=91=E5=90=AC=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=88=A0=E9=99=A4=E5=90=8E=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0store=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhai-peizhe Change-Id: Icc33db8994becd9149c33f193ad8d0ea41feae36 --- .../service/data_share/common/db_delegate.cpp | 29 +++++++++++++++++++ .../service/data_share/common/db_delegate.h | 1 + .../data_share/data_share_service_impl.cpp | 24 +++++++++++++++ .../data_share/data_share_service_impl.h | 1 + 4 files changed, 55 insertions(+) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index 7753dbb0c..b6eb963ea 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -80,6 +80,35 @@ std::shared_ptr DBDelegate::Create(DistributedData::StoreMetaData &m return nullptr; } +bool DBDelegate::Delete(DistributedData::StoreMetaData &metaData) +{ + // check deactivating. + if (Account::GetInstance()->IsDeactivating(atoi(metaData.user.c_str()))) { + ZLOGW("user %{public}s is deactivating, storeName: %{public}s", metaData.user.c_str(), + StringUtils::GeneralAnonymous(metaData.GetStoreAlias()).c_str()); + return false; + } + + // delete function. + auto eraseFunc = [&metaData](auto &, std::map> &stores) -> bool { + auto it = stores.find(metaData.storeId); + if (it != stores.end()) { + stores.erase(it); + return true; + } + return false; + }; + + bool result = false; + if (metaData.isEncrypt) { + result = storesEncrypt_.Compute(metaData.tokenId, eraseFunc); + } else { + result = stores_.Compute(metaData.tokenId, eraseFunc); + } + + return result; +} + void DBDelegate::SetExecutorPool(std::shared_ptr executor) { executor_ = std::move(executor); diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index 804a67633..822cca830 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -37,6 +37,7 @@ public: using Filter = std::function; static std::shared_ptr Create(DistributedData::StoreMetaData &metaData, const std::string &extUri = "", const std::string &backup = ""); + static bool Delete(DistributedData::StoreMetaData &metaData); virtual bool Init(const DistributedData::StoreMetaData &meta, int version, bool registerFunction, const std::string &extUri, const std::string &backup) = 0; static void Close(const Filter &filter); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index d1b45596b..1251d80a6 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -611,6 +611,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) SubscribeConcurrentTask(); SubscribeTimeChanged(); SubscribeChange(); + SubscribeListen(); auto task = [](const std::string &bundleName, int32_t userId, const std::string &storeName) { return BundleMgrProxy::GetInstance()->IsConfigSilentProxy(bundleName, userId, storeName); }; @@ -619,6 +620,29 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) return E_OK; } +void DataShareServiceImpl::SubscribeListen() +{ + MetaDataManager::GetInstance().Subscribe( + StoreMetaData::GetPrefix({}), [this](const std::string &key, const std::string &value, int32_t flag) -> auto { + if (flag != MetaDataManager::DELETE) { + return false; + } + if (value.empty()) { + return false; + } + StoreMetaData meta; + if (!(StoreMetaData::Unmarshall(value, meta))) { + ZLOGE("SubscribeListen Unmarshall failed!"); + return false; + } + if (!(DBDelegate::Delete(meta))) { + ZLOGE("SubscribeListen DBDelegate Delete failed!"); + return false; + } + return true; + }, true); +} + void DataShareServiceImpl::SubscribeCommonEvent() { sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index c86cf2fa2..075158565 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -128,6 +128,7 @@ private: }; void RegisterDataShareServiceInfo(); void RegisterHandler(); + void SubscribeListen(); bool SubscribeTimeChanged(); bool NotifyChange(const std::string &uri, int32_t userId); bool GetCallerBundleName(std::string &bundleName); -- Gitee