From 717fc24802c39129323ee2064a9eaf31529e4c1a Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 12 Nov 2024 11:52:41 +0800 Subject: [PATCH 01/24] update Signed-off-by: yangliu --- .../app/src/feature_stub_impl.cpp | 5 +- .../app/src/feature_stub_impl.h | 3 +- .../app/src/kvstore_data_service.cpp | 62 +++---------------- .../app/src/kvstore_data_service.h | 7 +-- .../src/session_manager/upgrade_manager.cpp | 53 ---------------- .../app/src/session_manager/upgrade_manager.h | 5 -- .../framework/feature/feature_system.cpp | 3 +- .../include/feature/feature_system.h | 4 +- .../framework/include/store/general_store.h | 2 +- .../service/kvdb/kvdb_general_store.cpp | 8 ++- .../service/kvdb/kvdb_service_impl.cpp | 17 ++++- .../service/kvdb/kvdb_service_impl.h | 4 +- .../service/object/object_service_impl.cpp | 3 +- .../service/object/object_service_impl.h | 3 +- .../service/rdb/rdb_service_impl.cpp | 3 +- .../service/rdb/rdb_service_impl.h | 3 +- 16 files changed, 56 insertions(+), 129 deletions(-) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index a690ddbe9..8498a6151 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -77,12 +77,13 @@ int32_t FeatureStubImpl::OnAppInstall(const std::string &bundleName, int32_t use return featureImpl_->OnAppInstall(bundleName, user, index); } -int32_t FeatureStubImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) +int32_t FeatureStubImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta, bool isTriple) { if (featureImpl_ == nullptr) { return -1; } - return featureImpl_->ResolveAutoLaunch(identifier, param); + return featureImpl_->ResolveAutoLaunch(identifier, param, meta, isTriple); } int32_t FeatureStubImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.h b/services/distributeddataservice/app/src/feature_stub_impl.h index e9249a76b..8a1c07597 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/services/distributeddataservice/app/src/feature_stub_impl.h @@ -35,7 +35,8 @@ public: int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index); int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index); - int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); + int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta = StoreMetaData(), bool isTriple = false); int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); int32_t Online(const std::string &device); int32_t Offline(const std::string &device); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 562e3892b..27573ff64 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -362,9 +362,11 @@ void KvStoreDataService::StartService() // subscribe account event listener to EventNotificationMgr auto autoLaunch = [this](const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) -> bool { - auto status = ResolveAutoLaunchParamByIdentifier(identifier, param); - features_.ForEachCopies([&identifier, ¶m](const auto &, sptr &value) { - value->ResolveAutoLaunch(identifier, param); + StoreMetaData metaData; + bool isTriple = false; + auto status = ResolveAutoLaunchParamByIdentifier(identifier, param, metaData, isTriple); + features_.ForEachCopies([&identifier, ¶m, &metaData, &isTriple](const auto &, sptr &value) { + value->ResolveAutoLaunch(identifier, param, metaData, isTriple); return false; }); return status; @@ -415,7 +417,7 @@ bool KvStoreDataService::CompareTripleIdentifier(const std::string &accountId, c } bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) + const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool isTriple) { std::vector entries; std::string localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; @@ -436,7 +438,9 @@ bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( const std::string &itemDualIdentifier = DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier("", storeMeta.appId, storeMeta.storeId, true); if (isTripleIdentifierEqual && storeMeta.bundleName != Bootstrap::GetInstance().GetProcessLabel()) { - ResolveAutoLaunchCompatible(storeMeta, identifier, accountId); + isTriple = isTripleIdentifierEqual; + metaDate = storeMeta; + metaDate.account = accountId; } if (identifier == itemDualIdentifier || isTripleIdentifierEqual) { ZLOGI("identifier find"); @@ -486,54 +490,6 @@ DistributedDB::SecurityOption KvStoreDataService::ConvertSecurity(int securityLe } } -void KvStoreDataService::ResolveAutoLaunchCompatible(const StoreMetaData &storeMeta, const std::string &identifier, - const std::string &accountId) -{ - if (storeMeta.storeType > KvStoreType::SINGLE_VERSION) { - ZLOGW("no longer support multi or higher version store type"); - return; - } - ZLOGI("AutoLaunch:peer device is old tuple, begin to open store, storeId: %{public}s", - Anonymous::Change(storeMeta.storeId).c_str()); - // open store and SetEqualIdentifier, then close store after 60s - DistributedDB::KvStoreDelegateManager delegateManager(storeMeta.appId, storeMeta.user); - delegateManager.SetKvStoreConfig({ DirectoryManager::GetInstance().GetStorePath(storeMeta) }); - Options options = { - .createIfMissing = false, - .encrypt = storeMeta.isEncrypt, - .autoSync = storeMeta.isAutoSync, - .securityLevel = storeMeta.securityLevel, - .kvStoreType = static_cast(storeMeta.storeType), - }; - DistributedDB::KvStoreNbDelegate::Option dbOptions; - SecretKeyMeta secretKey; - if (storeMeta.isEncrypt && MetaDataManager::GetInstance().LoadMeta(storeMeta.GetSecretKey(), secretKey)) { - std::vector decryptKey; - CryptoManager::GetInstance().Decrypt(secretKey.sKey, decryptKey); - std::fill(secretKey.sKey.begin(), secretKey.sKey.end(), 0); - secretKey.sKey = std::move(decryptKey); - std::fill(decryptKey.begin(), decryptKey.end(), 0); - } - InitNbDbOption(options, secretKey.sKey, dbOptions); - DistributedDB::KvStoreNbDelegate *store = nullptr; - delegateManager.GetKvStore(storeMeta.storeId, dbOptions, - [&store, &storeMeta, &accountId](int status, DistributedDB::KvStoreNbDelegate *delegate) { - ZLOGI("temporary open db for equal identifier, ret:%{public}d", status); - if (delegate != nullptr) { - KvStoreTuple tuple = { accountId, storeMeta.appId, storeMeta.storeId }; - UpgradeManager::SetCompatibleIdentifyByType(delegate, tuple); - store = delegate; - } - }); - ExecutorPool::Task delayTask([store]() { - ZLOGI("AutoLaunch:close store after 60s while autolaunch finishied"); - DistributedDB::KvStoreDelegateManager delegateManager("", ""); - delegateManager.CloseKvStore(store); - }); - constexpr int CLOSE_STORE_DELAY_TIME = 60; // unit: seconds - executors_->Schedule(std::chrono::seconds(CLOSE_STORE_DELAY_TIME), std::move(delayTask)); -} - Status KvStoreDataService::InitNbDbOption(const Options &options, const std::vector &cipherKey, DistributedDB::KvStoreNbDelegate::Option &dbOption) { diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 53a02afe2..82f822e96 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -165,10 +165,9 @@ private: void OnStoreMetaChanged(const std::vector &key, const std::vector &value, CHANGE_FLAG flag); Status AppExit(pid_t uid, pid_t pid, uint32_t token, const AppId &appId); - - bool ResolveAutoLaunchParamByIdentifier(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); - void ResolveAutoLaunchCompatible(const StoreMetaData &storeMeta, const std::string &identifier, - const std::string &accountId); + + bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( + const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool isTriple); void LoadConfigs(); diff --git a/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp b/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp index 65360d848..4055f30f1 100644 --- a/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp +++ b/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp @@ -87,57 +87,4 @@ bool UpgradeManager::InitLocalCapability() ZLOGI("put capability meta data ret %{public}d", status); return status; } - -void UpgradeManager::GetIdentifierParams(std::vector &devices, - const std::vector &uuids, int32_t authType) -{ - for (const auto &devId : uuids) { - if (DmAdapter::GetInstance().IsOHOSType(devId)) { - continue; - } - if (DmAdapter::GetInstance().GetAuthType(devId) != authType) { - continue; - } - devices.push_back(devId); - } -} - -void UpgradeManager::SetCompatibleIdentifyByType(DistributedDB::KvStoreNbDelegate *storeDelegate, - const KvStoreTuple &tuple) -{ - if (storeDelegate == nullptr) { - ZLOGE("null store delegate"); - return; - } - auto uuids = DmAdapter::ToUUID(DmAdapter::GetInstance().GetRemoteDevices()); - if (uuids.empty()) { - ZLOGI("no remote devs"); - return; - } - - std::vector sameAccountDevs {}; - std::vector defaultAccountDevs {}; - GetIdentifierParams(sameAccountDevs, uuids, IDENTICAL_ACCOUNT); - GetIdentifierParams(defaultAccountDevs, uuids, NO_ACCOUNT); - if (!sameAccountDevs.empty()) { - auto convertedIds = AppIdMappingConfigManager::GetInstance().Convert(tuple.appId, tuple.userId); - auto identifier = - DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier(convertedIds.second, - convertedIds.first, tuple.storeId); - ZLOGI("same account store:%{public}s, user:%{public}s, device:%{public}.10s, appId:%{public}s", - Anonymous::Change(tuple.storeId).c_str(), Anonymous::Change(convertedIds.second).c_str(), - DistributedData::Serializable::Marshall(sameAccountDevs).c_str(), convertedIds.first.c_str()); - storeDelegate->SetEqualIdentifier(identifier, sameAccountDevs); - } - if (!defaultAccountDevs.empty()) { - auto convertedIds = AppIdMappingConfigManager::GetInstance().Convert(tuple.appId, defaultAccountId); - auto identifier = - DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier(convertedIds.second, - convertedIds.first, tuple.storeId); - ZLOGI("no account identifier, store:%{public}s, device:%{public}.10s, appId:%{public}s", - Anonymous::Change(tuple.storeId).c_str(), - DistributedData::Serializable::Marshall(defaultAccountDevs).c_str(), convertedIds.first.c_str()); - storeDelegate->SetEqualIdentifier(identifier, defaultAccountDevs); - } -} } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/app/src/session_manager/upgrade_manager.h b/services/distributeddataservice/app/src/session_manager/upgrade_manager.h index 9348fc02b..411181e38 100644 --- a/services/distributeddataservice/app/src/session_manager/upgrade_manager.h +++ b/services/distributeddataservice/app/src/session_manager/upgrade_manager.h @@ -32,11 +32,6 @@ public: static UpgradeManager &GetInstance(); void Init(std::shared_ptr executors); CapMetaData GetCapability(const std::string &deviceId, bool &status); - static std::string GetIdentifierByType(int32_t groupType, bool &isSuccess); - static void SetCompatibleIdentifyByType( - KvStoreNbDelegate *storeDelegate, const KvStoreTuple &tuple); - static void GetIdentifierParams(std::vector &devices, - const std::vector &uuids, int32_t authType); private: static constexpr int RETRY_INTERVAL = 500; // milliseconds diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index 593a7c63b..eef3e7c00 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -91,7 +91,8 @@ int32_t FeatureSystem::Feature::OnAppInstall(const std::string &bundleName, int3 return E_OK; } -int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) +int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta, bool isTriple) { return E_OK; } diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index ecadb34db..3fdd67328 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -21,6 +21,7 @@ #include "executor_pool.h" #include "static_acts.h" #include "visibility.h" +#include "metadata/store_meta_data.h" namespace DistributedDB { struct AutoLaunchParam; } @@ -50,7 +51,8 @@ public: virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index); virtual int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); virtual int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index); - virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); + virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta = StoreMetaData(), bool isTriple = false); virtual int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); virtual int32_t Online(const std::string &device); virtual int32_t Offline(const std::string &device); diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index ddc987ad1..82de57d48 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -176,7 +176,7 @@ public: virtual std::vector GetWaterVersion(const std::string &deviceId) = 0; - virtual void SetEqualIdentifier(const std::string &appId, const std::string &storeId) {}; + virtual void SetEqualIdentifier(const std::string &appId, const std::string &storeId, std::string account = "") {}; virtual void SetConfig(const StoreConfig &storeConfig) {}; diff --git a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp index ab5ab9a0c..c4d41e9e4 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp @@ -423,7 +423,7 @@ int32_t KVDBGeneralStore::Sync(const Devices &devices, GenQuery &query, DetailAs return ConvertStatus(dbStatus); } -void KVDBGeneralStore::SetEqualIdentifier(const std::string &appId, const std::string &storeId) +void KVDBGeneralStore::SetEqualIdentifier(const std::string &appId, const std::string &storeId, std::string account) { std::shared_lock lock(rwMutex_); if (delegate_ == nullptr) { @@ -434,10 +434,14 @@ void KVDBGeneralStore::SetEqualIdentifier(const std::string &appId, const std::s std::vector sameAccountDevs{}; std::vector defaultAccountDevs{}; auto uuids = DMAdapter::ToUUID(DMAdapter::GetInstance().GetRemoteDevices()); + if (uuids.empty()) { + ZLOGI("no remote device to sync.appId:%{public}s",appId.c_str()); + return; + } GetIdentifierParams(sameAccountDevs, uuids, IDENTICAL_ACCOUNT); GetIdentifierParams(defaultAccountDevs, uuids, NO_ACCOUNT); if (!sameAccountDevs.empty()) { - auto accountId = AccountDelegate::GetInstance()->GetUnencryptedAccountId(); + auto accountId = account.empty() ? AccountDelegate::GetInstance()->GetUnencryptedAccountId() : account; auto convertedIds = AppIdMappingConfigManager::GetInstance().Convert(appId, accountId); auto identifier = KvManager::GetKvStoreIdentifier(convertedIds.second, convertedIds.first, storeId); ZLOGI("same account store:%{public}s, user:%{public}s, device:%{public}.10s, appId:%{public}s", diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 00911ffe6..6bcbb8a35 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -49,6 +49,7 @@ #include "utils/constant.h" #include "utils/converter.h" #include "water_version_manager.h" +#include "app_id_mapping/app_id_mapping_config_manager.h" namespace OHOS::DistributedKv { using namespace OHOS::DistributedData; @@ -753,10 +754,24 @@ int32_t KVDBServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const return SUCCESS; } -int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m) +int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, + StoreMetaData meta, bool isTriple) { ZLOGI("user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), Anonymous::Change(identifier).c_str()); + if (isTriple) { + auto watchers = GetWatchers(meta.tokenId, meta.storeId); + ZLOGI("triple autolaunch.appId:%{public}s storeId:%{public}s tokenid:0x%{public}x size:%{public}zu", + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), meta.tokenId, watchers.size()); + auto store = AutoCache::GetInstance().GetStore(meta, watchers); + if (store == nullptr) { + ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); + return STORE_NOT_OPEN; + } + store->SetEqualIdentifier(meta.appId, meta.stordId, meta.account); + return SUCCESS; + } + std::vector metaData; auto prefix = StoreMetaData::GetPrefix({ DMAdapter::GetInstance().GetLocalDevice().uuid, param.userId }); if (!MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index c2fcef042..463abaf0a 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -39,6 +39,7 @@ public: using DBLaunchParam = DistributedDB::AutoLaunchParam; using Handler = std::function> &)>; using RefCount = DistributedData::RefCount; + using StoreMetaData = OHOS::DistributedData::StoreMetaData; API_EXPORT KVDBServiceImpl(); virtual ~KVDBServiceImpl(); Status GetStoreIds(const AppId &appId, std::vector &storeIds) override; @@ -72,7 +73,8 @@ public: int32_t OnBind(const BindInfo &bindInfo) override; int32_t OnInitialize() override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; - int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m) override; + int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, + StoreMetaData meta = StoreMetaData(), bool isTriple = false) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; Status RemoveDeviceData(const AppId &appId, const StoreId &storeId, const std::string &device) override; diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index 1a3182fcc..2dee7bab6 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -295,7 +295,8 @@ int32_t ObjectServiceImpl::ObjectStatic::OnAppUninstall(const std::string &bundl return result; } -int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) +int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta, bool isTriple) { ZLOGI("start, user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), param.appId.c_str(), DistributedData::Anonymous::Change(param.storeId).c_str(), diff --git a/services/distributeddataservice/service/object/object_service_impl.h b/services/distributeddataservice/service/object/object_service_impl.h index 437d49e9e..841dc90a8 100644 --- a/services/distributeddataservice/service/object/object_service_impl.h +++ b/services/distributeddataservice/service/object/object_service_impl.h @@ -41,7 +41,8 @@ public: int32_t IsBundleNameEqualTokenId( const std::string &bundleName, const std::string &sessionId, const uint32_t &tokenId); void Clear(); - int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; + int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta = StoreMetaData(), bool isTriple = false) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; int32_t OnInitialize() override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index b3903b142..706585d9b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -144,7 +144,8 @@ RdbServiceImpl::RdbServiceImpl() EventCenter::GetInstance().Subscribe(BindEvent::RECOVER_SYNC, compensateSyncProcess); } -int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) +int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta, bool isTriple) { std::string identifierHex = TransferStringToHex(identifier); ZLOGI("%{public}.6s", identifierHex.c_str()); diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index b49d448ef..fc332fe14 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -74,7 +74,8 @@ public: int32_t UnregisterAutoSyncCallback(const RdbSyncerParam& param, std::shared_ptr observer) override; - int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; + int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData meta = StoreMetaData(), bool isTriple) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; From 1e52662f030c855ffe8a7f296dd73d48bdd2ef09 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 12 Nov 2024 12:06:28 +0800 Subject: [PATCH 02/24] update Signed-off-by: yangliu --- .../distributeddataservice/app/src/kvstore_data_service.cpp | 2 +- .../distributeddataservice/app/src/kvstore_data_service.h | 2 +- .../app/test/unittest/kvstore_data_service_test.cpp | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 27573ff64..e2546baf7 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -417,7 +417,7 @@ bool KvStoreDataService::CompareTripleIdentifier(const std::string &accountId, c } bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool isTriple) + const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool &isTriple) { std::vector entries; std::string localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 82f822e96..5ea4c7d46 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -167,7 +167,7 @@ private: Status AppExit(pid_t uid, pid_t pid, uint32_t token, const AppId &appId); bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool isTriple); + const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool &isTriple); void LoadConfigs(); diff --git a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp index 581d6f6a0..ea060a3e7 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp @@ -191,7 +191,9 @@ HWTEST_F(KvStoreDataServiceTest, ResolveAutoLaunchParamByIdentifier001, TestSize KvStoreDataService kvStoreDataServiceTest; std::string identifier = "kvstoredataservicetest"; DistributedDB::AutoLaunchParam param; - auto status = kvStoreDataServiceTest.ResolveAutoLaunchParamByIdentifier(identifier, param); + StoreMetaData meta; + bool isTriple = false; + auto status = kvStoreDataServiceTest.ResolveAutoLaunchParamByIdentifier(identifier, param, meta, false); EXPECT_EQ(status, SUCCESS); } From 60809bebbb27ebb9f86e0e379db8f392333a0c56 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 12 Nov 2024 15:07:33 +0800 Subject: [PATCH 03/24] update Signed-off-by: yangliu --- .../distributeddataservice/app/src/kvstore_data_service.cpp | 3 ++- .../distributeddataservice/service/kvdb/kvdb_general_store.cpp | 2 +- .../distributeddataservice/service/kvdb/kvdb_general_store.h | 2 +- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 2 +- services/distributeddataservice/service/rdb/rdb_service_impl.h | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index e2546baf7..747201d57 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -365,7 +365,8 @@ void KvStoreDataService::StartService() StoreMetaData metaData; bool isTriple = false; auto status = ResolveAutoLaunchParamByIdentifier(identifier, param, metaData, isTriple); - features_.ForEachCopies([&identifier, ¶m, &metaData, &isTriple](const auto &, sptr &value) { + features_.ForEachCopies([&identifier, ¶m, &metaData, &isTriple](const auto &, + sptr &value) { value->ResolveAutoLaunch(identifier, param, metaData, isTriple); return false; }); diff --git a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp index c4d41e9e4..f303b9c97 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp @@ -435,7 +435,7 @@ void KVDBGeneralStore::SetEqualIdentifier(const std::string &appId, const std::s std::vector defaultAccountDevs{}; auto uuids = DMAdapter::ToUUID(DMAdapter::GetInstance().GetRemoteDevices()); if (uuids.empty()) { - ZLOGI("no remote device to sync.appId:%{public}s",appId.c_str()); + ZLOGI("no remote device to sync.appId:%{public}s", appId.c_str()); return; } GetIdentifierParams(sameAccountDevs, uuids, IDENTICAL_ACCOUNT); diff --git a/services/distributeddataservice/service/kvdb/kvdb_general_store.h b/services/distributeddataservice/service/kvdb/kvdb_general_store.h index 8caa063bf..e7bbd1dcb 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_general_store.h +++ b/services/distributeddataservice/service/kvdb/kvdb_general_store.h @@ -73,7 +73,7 @@ public: int32_t MergeMigratedData(const std::string &tableName, VBuckets &&values) override; int32_t CleanTrackerData(const std::string &tableName, int64_t cursor) override; std::vector GetWaterVersion(const std::string &deviceId) override; - void SetEqualIdentifier(const std::string &appId, const std::string &storeId) override; + void SetEqualIdentifier(const std::string &appId, const std::string &storeId, std::string account = "") override; void SetConfig(const StoreConfig &storeConfig) override; void SetExecutor(std::shared_ptr executor) override; static DBPassword GetDBPassword(const StoreMetaData &data); diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 6bcbb8a35..9c3143af8 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -768,7 +768,7 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); return STORE_NOT_OPEN; } - store->SetEqualIdentifier(meta.appId, meta.stordId, meta.account); + store->SetEqualIdentifier(meta.appId, meta.storeId, meta.account); return SUCCESS; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index fc332fe14..6e2e5f432 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -75,7 +75,7 @@ public: std::shared_ptr observer) override; int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta = StoreMetaData(), bool isTriple) override; + StoreMetaData meta = StoreMetaData(), bool isTriple = false) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; From b36487d0881b98216235653e7e6bb304fa8e1798 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 12 Nov 2024 16:13:07 +0800 Subject: [PATCH 04/24] update Signed-off-by: yangliu --- services/distributeddataservice/app/src/kvstore_data_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 5ea4c7d46..42f9b1f45 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -166,7 +166,7 @@ private: Status AppExit(pid_t uid, pid_t pid, uint32_t token, const AppId &appId); - bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( + bool ResolveAutoLaunchParamByIdentifier( const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool &isTriple); void LoadConfigs(); From 1fb6abdaf4c85c1816eb9ceccef7f95e5dfe42f1 Mon Sep 17 00:00:00 2001 From: yangliu Date: Thu, 14 Nov 2024 10:35:10 +0800 Subject: [PATCH 05/24] update Signed-off-by: yangliu --- .../distributeddataservice/app/src/kvstore_data_service.cpp | 6 +++--- .../distributeddataservice/app/src/kvstore_data_service.h | 2 +- .../app/test/unittest/kvstore_data_service_test.cpp | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 747201d57..e79155919 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -418,7 +418,7 @@ bool KvStoreDataService::CompareTripleIdentifier(const std::string &accountId, c } bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool &isTriple) + const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaData, bool &isTriple) { std::vector entries; std::string localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; @@ -440,8 +440,8 @@ bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier("", storeMeta.appId, storeMeta.storeId, true); if (isTripleIdentifierEqual && storeMeta.bundleName != Bootstrap::GetInstance().GetProcessLabel()) { isTriple = isTripleIdentifierEqual; - metaDate = storeMeta; - metaDate.account = accountId; + metaData = storeMeta; + metaData.account = accountId; } if (identifier == itemDualIdentifier || isTripleIdentifierEqual) { ZLOGI("identifier find"); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 42f9b1f45..c034cf288 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -167,7 +167,7 @@ private: Status AppExit(pid_t uid, pid_t pid, uint32_t token, const AppId &appId); bool ResolveAutoLaunchParamByIdentifier( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaDate, bool &isTriple); + const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaData, bool &isTriple); void LoadConfigs(); diff --git a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp index ea060a3e7..e6ff6ad29 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp @@ -192,7 +192,6 @@ HWTEST_F(KvStoreDataServiceTest, ResolveAutoLaunchParamByIdentifier001, TestSize std::string identifier = "kvstoredataservicetest"; DistributedDB::AutoLaunchParam param; StoreMetaData meta; - bool isTriple = false; auto status = kvStoreDataServiceTest.ResolveAutoLaunchParamByIdentifier(identifier, param, meta, false); EXPECT_EQ(status, SUCCESS); } From 4b2eb96d9bb555ce6ee6ef8867426de0b8f40861 Mon Sep 17 00:00:00 2001 From: yangliu Date: Thu, 14 Nov 2024 16:25:03 +0800 Subject: [PATCH 06/24] update Signed-off-by: yangliu --- services/distributeddataservice/service/kvdb/kvdb_service_impl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index 463abaf0a..88e30d68a 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -79,7 +79,6 @@ public: Status RemoveDeviceData(const AppId &appId, const StoreId &storeId, const std::string &device) override; private: - using StoreMetaData = OHOS::DistributedData::StoreMetaData; using StrategyMeta = OHOS::DistributedData::StrategyMeta; using StoreMetaDataLocal = OHOS::DistributedData::StoreMetaDataLocal; using ChangeType = OHOS::DistributedData::DeviceMatrix::ChangeType; From 0c4e82cd89a4ddcc39599aaa7647e2a8e976da7d Mon Sep 17 00:00:00 2001 From: yangliu Date: Thu, 14 Nov 2024 17:00:39 +0800 Subject: [PATCH 07/24] update Signed-off-by: yangliu --- .../app/test/unittest/kvstore_data_service_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp index e6ff6ad29..b6067e29b 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp @@ -192,7 +192,8 @@ HWTEST_F(KvStoreDataServiceTest, ResolveAutoLaunchParamByIdentifier001, TestSize std::string identifier = "kvstoredataservicetest"; DistributedDB::AutoLaunchParam param; StoreMetaData meta; - auto status = kvStoreDataServiceTest.ResolveAutoLaunchParamByIdentifier(identifier, param, meta, false); + bool isTriple = false; + auto status = kvStoreDataServiceTest.ResolveAutoLaunchParamByIdentifier(identifier, param, meta, isTriple); EXPECT_EQ(status, SUCCESS); } From d17fe77b072759f551f5cc88bfa2d3a320ec2889 Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 21:45:21 +0800 Subject: [PATCH 08/24] update Signed-off-by: yangliu --- .../app/src/feature_stub_impl.cpp | 4 +- .../app/src/feature_stub_impl.h | 2 +- .../app/src/kvstore_data_service.cpp | 137 +----------------- .../app/src/kvstore_data_service.h | 6 - .../framework/feature/feature_system.cpp | 2 +- .../include/feature/feature_system.h | 2 +- .../service/kvdb/kvdb_service_impl.cpp | 129 +++++++++++++++-- .../service/kvdb/kvdb_service_impl.h | 9 +- .../service/object/object_service_impl.cpp | 3 +- .../service/object/object_service_impl.h | 2 +- .../service/rdb/rdb_service_impl.cpp | 5 +- .../service/rdb/rdb_service_impl.h | 2 +- 12 files changed, 137 insertions(+), 166 deletions(-) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index 8498a6151..75fcfaa7a 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -78,12 +78,12 @@ int32_t FeatureStubImpl::OnAppInstall(const std::string &bundleName, int32_t use } int32_t FeatureStubImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta, bool isTriple) + bool &isFindIdentifier) { if (featureImpl_ == nullptr) { return -1; } - return featureImpl_->ResolveAutoLaunch(identifier, param, meta, isTriple); + return featureImpl_->ResolveAutoLaunch(identifier, param, isFindIdentifier); } int32_t FeatureStubImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.h b/services/distributeddataservice/app/src/feature_stub_impl.h index 8a1c07597..3f4d97a4f 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/services/distributeddataservice/app/src/feature_stub_impl.h @@ -36,7 +36,7 @@ public: int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index); int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta = StoreMetaData(), bool isTriple = false); + bool &isFindIdentifier); int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); int32_t Online(const std::string &device); int32_t Offline(const std::string &device); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index e79155919..344201cd3 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -363,14 +363,13 @@ void KvStoreDataService::StartService() // subscribe account event listener to EventNotificationMgr auto autoLaunch = [this](const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) -> bool { StoreMetaData metaData; - bool isTriple = false; - auto status = ResolveAutoLaunchParamByIdentifier(identifier, param, metaData, isTriple); - features_.ForEachCopies([&identifier, ¶m, &metaData, &isTriple](const auto &, + bool isFindIdentifier = false; + features_.ForEachCopies([&identifier, ¶m, &isFindIdentifier](const auto &, sptr &value) { - value->ResolveAutoLaunch(identifier, param, metaData, isTriple); + value->ResolveAutoLaunch(identifier, param, isFindIdentifier); return false; }); - return status; + return isFindIdentifier; }; KvStoreDelegateManager::SetAutoLaunchRequestCallback(autoLaunch); ZLOGI("Start distributedata Success, Publish ret: %{public}d", static_cast(ret)); @@ -398,134 +397,6 @@ void KvStoreDataService::OnStoreMetaChanged( ZLOGI("dirty kv store. storeId:%{public}s", Anonymous::Change(metaData.storeId).c_str()); } -bool KvStoreDataService::CompareTripleIdentifier(const std::string &accountId, const std::string &identifier, - const StoreMetaData &storeMeta) -{ - std::vector accountIds { accountId, "ohosAnonymousUid", "default" }; - for (auto &id : accountIds) { - auto convertedIds = - AppIdMappingConfigManager::GetInstance().Convert(storeMeta.appId, storeMeta.user); - const std::string &tempTripleIdentifier = - DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier(id, convertedIds.first, - storeMeta.storeId, false); - if (tempTripleIdentifier == identifier) { - ZLOGI("find triple identifier,storeId:%{public}s,id:%{public}s", - Anonymous::Change(storeMeta.storeId).c_str(), Anonymous::Change(id).c_str()); - return true; - } - } - return false; -} - -bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaData, bool &isTriple) -{ - std::vector entries; - std::string localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ localDeviceId }), entries)) { - ZLOGE("get full meta failed"); - return false; - } - - auto accountId = AccountDelegate::GetInstance()->GetUnencryptedAccountId(); - for (const auto &storeMeta : entries) { - if ((!param.userId.empty() && (param.userId != storeMeta.user)) || (localDeviceId != storeMeta.deviceId) || - ((StoreMetaData::STORE_RELATIONAL_BEGIN <= storeMeta.storeType) && - (StoreMetaData::STORE_RELATIONAL_END >= storeMeta.storeType))) { - // judge local userid and local meta - continue; - } - bool isTripleIdentifierEqual = CompareTripleIdentifier(accountId, identifier, storeMeta); - const std::string &itemDualIdentifier = - DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier("", storeMeta.appId, storeMeta.storeId, true); - if (isTripleIdentifierEqual && storeMeta.bundleName != Bootstrap::GetInstance().GetProcessLabel()) { - isTriple = isTripleIdentifierEqual; - metaData = storeMeta; - metaData.account = accountId; - } - if (identifier == itemDualIdentifier || isTripleIdentifierEqual) { - ZLOGI("identifier find"); - DistributedDB::AutoLaunchOption option; - option.createIfNecessary = false; - option.isEncryptedDb = storeMeta.isEncrypt; - - SecretKeyMeta secretKey; - if (storeMeta.isEncrypt && MetaDataManager::GetInstance().LoadMeta(storeMeta.GetSecretKey(), secretKey)) { - std::vector decryptKey; - CryptoManager::GetInstance().Decrypt(secretKey.sKey, decryptKey); - option.passwd.SetValue(decryptKey.data(), decryptKey.size()); - std::fill(decryptKey.begin(), decryptKey.end(), 0); - } - - if (storeMeta.bundleName == Bootstrap::GetInstance().GetProcessLabel()) { - param.userId = storeMeta.user; - } - option.schema = storeMeta.schema; - option.createDirByStoreIdOnly = true; - option.dataDir = storeMeta.dataDir; - option.secOption = ConvertSecurity(storeMeta.securityLevel); - option.isAutoSync = storeMeta.isAutoSync; - option.syncDualTupleMode = true; // dual tuple flag - param.appId = storeMeta.appId; - param.storeId = storeMeta.storeId; - param.option = option; - return true; - } - } - ZLOGI("not find identifier"); - return false; -} - -DistributedDB::SecurityOption KvStoreDataService::ConvertSecurity(int securityLevel) -{ - if (securityLevel < SecurityLevel::NO_LABEL || securityLevel > SecurityLevel::S4) { - return {DistributedDB::NOT_SET, DistributedDB::ECE}; - } - switch (securityLevel) { - case SecurityLevel::S3: - return {DistributedDB::S3, DistributedDB::SECE}; - case SecurityLevel::S4: - return {DistributedDB::S4, DistributedDB::ECE}; - default: - return {securityLevel, DistributedDB::ECE}; - } -} - -Status KvStoreDataService::InitNbDbOption(const Options &options, const std::vector &cipherKey, - DistributedDB::KvStoreNbDelegate::Option &dbOption) -{ - DistributedDB::CipherPassword password; - auto status = password.SetValue(cipherKey.data(), cipherKey.size()); - if (status != DistributedDB::CipherPassword::ErrorCode::OK) { - ZLOGE("Failed to set the passwd."); - return Status::DB_ERROR; - } - - dbOption.syncDualTupleMode = true; // tuple of (appid+storeid) - dbOption.createIfNecessary = options.createIfMissing; - dbOption.isMemoryDb = (!options.persistent); - dbOption.isEncryptedDb = options.encrypt; - dbOption.isNeedCompressOnSync = options.isNeedCompress; - if (options.encrypt) { - dbOption.cipher = DistributedDB::CipherType::AES_256_GCM; - dbOption.passwd = password; - } - - if (options.kvStoreType == KvStoreType::SINGLE_VERSION) { - dbOption.conflictResolvePolicy = DistributedDB::LAST_WIN; - } else if (options.kvStoreType == KvStoreType::DEVICE_COLLABORATION) { - dbOption.conflictResolvePolicy = DistributedDB::DEVICE_COLLABORATION; - } else { - ZLOGE("kvStoreType is invalid"); - return Status::INVALID_ARGUMENT; - } - - dbOption.schema = options.schema; - dbOption.createDirByStoreIdOnly = true; - dbOption.secOption = ConvertSecurity(options.securityLevel); - return Status::SUCCESS; -} - void KvStoreDataService::OnStop() { ZLOGI("begin."); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index c034cf288..0e78f0b59 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -171,12 +171,6 @@ private: void LoadConfigs(); - bool CompareTripleIdentifier(const std::string &accountId, const std::string &identifier, - const StoreMetaData &storeMeta); - static DistributedDB::SecurityOption ConvertSecurity(int securityLevel); - static Status InitNbDbOption(const Options &options, const std::vector &cipherKey, - DistributedDB::KvStoreNbDelegate::Option &dbOption); - static constexpr int TEN_SEC = 10; ConcurrentMap> clients_; diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index eef3e7c00..435d209c4 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -92,7 +92,7 @@ int32_t FeatureSystem::Feature::OnAppInstall(const std::string &bundleName, int3 } int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta, bool isTriple) + bool &isFindIdentifier) { return E_OK; } diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index 3fdd67328..97a0408da 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -52,7 +52,7 @@ public: virtual int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); virtual int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index); virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta = StoreMetaData(), bool isTriple = false); + bool &isFindIdentifier); virtual int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); virtual int32_t Online(const std::string &device); virtual int32_t Offline(const std::string &device); diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 9c3143af8..af64ab6c1 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -59,6 +59,7 @@ using system_clock = std::chrono::system_clock; using DMAdapter = DistributedData::DeviceManagerAdapter; using DumpManager = OHOS::DistributedData::DumpManager; using CommContext = OHOS::DistributedData::CommunicatorContext; +using SecretKeyMeta = DistributedData::SecretKeyMetaData; static constexpr const char *DEFAULT_USER_ID = "0"; __attribute__((used)) KVDBServiceImpl::Factory KVDBServiceImpl::factory_; KVDBServiceImpl::Factory::Factory() @@ -754,24 +755,109 @@ int32_t KVDBServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const return SUCCESS; } -int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, - StoreMetaData meta, bool isTriple) +bool KVDBServiceImpl::CompareTripleIdentifier(const std::string &accountId, const std::string &identifier, + const StoreMetaData &storeMeta) +{ + std::vector accountIds { accountId, "ohosAnonymousUid", "default" }; + for (auto &id : accountIds) { + auto convertedIds = + AppIdMappingConfigManager::GetInstance().Convert(storeMeta.appId, storeMeta.user); + const std::string &tempTripleIdentifier = + DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier(id, convertedIds.first, + storeMeta.storeId, false); + if (tempTripleIdentifier == identifier) { + ZLOGI("find triple identifier,storeId:%{public}s,id:%{public}s", + Anonymous::Change(storeMeta.storeId).c_str(), Anonymous::Change(id).c_str()); + return true; + } + } + return false; +} + +bool KVDBServiceImpl::IsTripleAutoLaunch( + const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &meta, bool &isFindIdentifier) +{ + std::vector entries; + std::string localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ localDeviceId }), entries)) { + ZLOGE("get full meta failed"); + return false; + } + + auto accountId = AccountDelegate::GetInstance()->GetUnencryptedAccountId(); + for (const auto &storeMeta : entries) { + if ((!param.userId.empty() && (param.userId != storeMeta.user)) || (localDeviceId != storeMeta.deviceId) || + ((StoreMetaData::STORE_RELATIONAL_BEGIN <= storeMeta.storeType) && + (StoreMetaData::STORE_RELATIONAL_END >= storeMeta.storeType))) { + // judge local userid and local meta + continue; + } + bool isTripleIdentifierEqual = CompareTripleIdentifier(accountId, identifier, storeMeta); + const std::string &itemDualIdentifier = + DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier("", storeMeta.appId, storeMeta.storeId, true); + if (isTripleIdentifierEqual && storeMeta.bundleName != Bootstrap::GetInstance().GetProcessLabel()) { + meta = storeMeta; + meta.account = accountId; + } + if (identifier == itemDualIdentifier || isTripleIdentifierEqual) { + ZLOGI("identifier find:%{public}d", isTripleIdentifierEqual); + DistributedDB::AutoLaunchOption option; + option.createIfNecessary = false; + option.isEncryptedDb = storeMeta.isEncrypt; + + SecretKeyMeta secretKey; + if (storeMeta.isEncrypt && MetaDataManager::GetInstance().LoadMeta(storeMeta.GetSecretKey(), secretKey)) { + std::vector decryptKey; + CryptoManager::GetInstance().Decrypt(secretKey.sKey, decryptKey); + option.passwd.SetValue(decryptKey.data(), decryptKey.size()); + std::fill(decryptKey.begin(), decryptKey.end(), 0); + } + + if (storeMeta.bundleName == Bootstrap::GetInstance().GetProcessLabel()) { + param.userId = storeMeta.user; + } + option.schema = storeMeta.schema; + option.createDirByStoreIdOnly = true; + option.dataDir = storeMeta.dataDir; + option.secOption = ConvertSecurity(storeMeta.securityLevel); + option.isAutoSync = storeMeta.isAutoSync; + option.syncDualTupleMode = true; // dual tuple flag + param.appId = storeMeta.appId; + param.storeId = storeMeta.storeId; + param.option = option; + isFindIdentifier = true; + return isTripleIdentifierEqual; + } + } + ZLOGI("not find identifier"); + return false; +} + +int32_t KVDBServiceImpl::DoTripleAutoLaunch(StoreMetaData &meta) +{ + auto watchers = GetWatchers(meta.tokenId, meta.storeId); + ZLOGI("triple autolaunch.appId:%{public}s storeId:%{public}s tokenid:0x%{public}x size:%{public}zu", + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), meta.tokenId, watchers.size()); + auto store = AutoCache::GetInstance().GetStore(meta, watchers); + if (store == nullptr) { + ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); + return STORE_NOT_OPEN; + } + store->SetEqualIdentifier(meta.appId, meta.storeId, meta.account); + return SUCCESS; +} + +int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, bool &isFindIdentifier) { ZLOGI("user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), Anonymous::Change(identifier).c_str()); - if (isTriple) { - auto watchers = GetWatchers(meta.tokenId, meta.storeId); - ZLOGI("triple autolaunch.appId:%{public}s storeId:%{public}s tokenid:0x%{public}x size:%{public}zu", - meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), meta.tokenId, watchers.size()); - auto store = AutoCache::GetInstance().GetStore(meta, watchers); - if (store == nullptr) { - ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); - return STORE_NOT_OPEN; - } - store->SetEqualIdentifier(meta.appId, meta.storeId, meta.account); - return SUCCESS; - } + StoreMetaData meta; + if (IsTripleAutoLaunch(identifier, param, meta, isFindIdentifier)) { + ZLOGI("do triple autolaunch. storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); + return DoTripleAutoLaunch(meta); + } + std::vector metaData; auto prefix = StoreMetaData::GetPrefix({ DMAdapter::GetInstance().GetLocalDevice().uuid, param.userId }); if (!MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { @@ -797,6 +883,21 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun return SUCCESS; } +DistributedDB::SecurityOption KVDBServiceImpl::ConvertSecurity(int securityLevel) +{ + if (securityLevel < SecurityLevel::NO_LABEL || securityLevel > SecurityLevel::S4) { + return {DistributedDB::NOT_SET, DistributedDB::ECE}; + } + switch (securityLevel) { + case SecurityLevel::S3: + return {DistributedDB::S3, DistributedDB::SECE}; + case SecurityLevel::S4: + return {DistributedDB::S4, DistributedDB::ECE}; + default: + return {securityLevel, DistributedDB::ECE}; + } +} + int32_t KVDBServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { (void)code; diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index 88e30d68a..a15f8faee 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -73,8 +73,7 @@ public: int32_t OnBind(const BindInfo &bindInfo) override; int32_t OnInitialize() override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; - int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, - StoreMetaData meta = StoreMetaData(), bool isTriple = false) override; + int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, bool &isFindIdentifier) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; Status RemoveDeviceData(const AppId &appId, const StoreId &storeId, const std::string &device) override; @@ -151,6 +150,12 @@ private: void TryToSync(const StoreMetaData &metaData, bool force = false); bool IsRemoteChange(const StoreMetaData &metaData, const std::string &device); bool IsOHOSType(const std::vector &ids); + bool CompareTripleIdentifier(const std::string &accountId, const std::string &identifier, + const StoreMetaData &storeMeta); + bool IsTripleAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData &meta, bool &isFindIdentifier); + int32_t DoTripleAutoLaunch(StoreMetaData &meta); + DistributedDB::SecurityOption ConvertSecurity(int securityLevel); static Factory factory_; ConcurrentMap syncAgents_; std::shared_ptr executors_; diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index 2dee7bab6..537af24be 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -295,8 +295,7 @@ int32_t ObjectServiceImpl::ObjectStatic::OnAppUninstall(const std::string &bundl return result; } -int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta, bool isTriple) +int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, bool &isFindIdentifier) { ZLOGI("start, user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), param.appId.c_str(), DistributedData::Anonymous::Change(param.storeId).c_str(), diff --git a/services/distributeddataservice/service/object/object_service_impl.h b/services/distributeddataservice/service/object/object_service_impl.h index 841dc90a8..0557f0840 100644 --- a/services/distributeddataservice/service/object/object_service_impl.h +++ b/services/distributeddataservice/service/object/object_service_impl.h @@ -42,7 +42,7 @@ public: const std::string &bundleName, const std::string &sessionId, const uint32_t &tokenId); void Clear(); int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta = StoreMetaData(), bool isTriple = false) override; + bool &isFindIdentifier) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; int32_t OnInitialize() override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 706585d9b..6a7d6e2bd 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -97,7 +97,8 @@ RdbServiceImpl::RdbServiceImpl() ZLOGI("construct"); DistributedDB::RelationalStoreManager::SetAutoLaunchRequestCallback( [this](const std::string& identifier, DistributedDB::AutoLaunchParam ¶m) { - return ResolveAutoLaunch(identifier, param); + bool isFindIdentifier = false; + return ResolveAutoLaunch(identifier, param, isFindIdentifier); }); auto process = [this](const Event &event) { auto &evt = static_cast(event); @@ -145,7 +146,7 @@ RdbServiceImpl::RdbServiceImpl() } int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta, bool isTriple) + bool &isFindIdentifier) { std::string identifierHex = TransferStringToHex(identifier); ZLOGI("%{public}.6s", identifierHex.c_str()); diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 6e2e5f432..0ed285c46 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -75,7 +75,7 @@ public: std::shared_ptr observer) override; int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData meta = StoreMetaData(), bool isTriple = false) override; + bool &isFindIdentifier) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; From 7f9cee3e264046cf3e55788758803c49a6fae259 Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 21:48:58 +0800 Subject: [PATCH 09/24] update Signed-off-by: yangliu --- .../unittest/kvstore_data_service_test.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp index b6067e29b..4e551e917 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp @@ -179,24 +179,6 @@ HWTEST_F(KvStoreDataServiceTest, AppExit001, TestSize.Level1) EXPECT_EQ(status, SUCCESS); } -/** -* @tc.name: ResolveAutoLaunchParamByIdentifier001 -* @tc.desc: -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(KvStoreDataServiceTest, ResolveAutoLaunchParamByIdentifier001, TestSize.Level1) -{ - KvStoreDataService kvStoreDataServiceTest; - std::string identifier = "kvstoredataservicetest"; - DistributedDB::AutoLaunchParam param; - StoreMetaData meta; - bool isTriple = false; - auto status = kvStoreDataServiceTest.ResolveAutoLaunchParamByIdentifier(identifier, param, meta, isTriple); - EXPECT_EQ(status, SUCCESS); -} - /** * @tc.name: ConvertSecurity001 * @tc.desc: From fd64c8ab18126230582e881268957b6b8cd0511f Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 21:52:59 +0800 Subject: [PATCH 10/24] update Signed-off-by: yangliu --- .../distributeddataservice/framework/test/feature_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/test/feature_test.cpp b/services/distributeddataservice/framework/test/feature_test.cpp index 6f733a0de..1e72a062e 100644 --- a/services/distributeddataservice/framework/test/feature_test.cpp +++ b/services/distributeddataservice/framework/test/feature_test.cpp @@ -206,7 +206,8 @@ HWTEST_F(FeatureSystemTest, ResolveAutoLaunchTest, TestSize.Level1) DistributedDB::AutoLaunchParam param; MockFeature mockFeature; - int32_t ret = mockFeature.ResolveAutoLaunch(identifier, param); + bool status = false; + int32_t ret = mockFeature.ResolveAutoLaunch(identifier, param, status); EXPECT_EQ(ret, E_OK); } From 3a83392ed15a17dce7188fa06792e34e281fd9e5 Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 22:01:22 +0800 Subject: [PATCH 11/24] update Signed-off-by: yangliu --- .../unittest/kvstore_data_service_test.cpp | 37 ------------------- .../service/test/kvdb_service_impl_test.cpp | 5 ++- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp index 4e551e917..2d45ffddf 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_data_service_test.cpp @@ -177,41 +177,4 @@ HWTEST_F(KvStoreDataServiceTest, AppExit001, TestSize.Level1) OHOS::DistributedKv::AppId appId = { "ohos.test.kvstoredataservice" }; Status status = kvStoreDataServiceTest.AppExit(uid, pid, token, appId); EXPECT_EQ(status, SUCCESS); -} - -/** -* @tc.name: ConvertSecurity001 -* @tc.desc: -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(KvStoreDataServiceTest, ConvertSecurity001, TestSize.Level1) -{ - KvStoreDataService kvStoreDataServiceTest; - auto object = kvStoreDataServiceTest.ConvertSecurity(0); - ASSERT_NE(&object, nullptr); -} - -/** -* @tc.name: InitNbDbOption001 -* @tc.desc: -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(KvStoreDataServiceTest, InitNbDbOption001, TestSize.Level1) -{ - KvStoreDataService kvStoreDataServiceTest; - DistributedDB::KvStoreNbDelegate::Option dbOption; - Options options = { - .createIfMissing = false, - .encrypt = true, - .autoSync = false, - .securityLevel = 1, - }; - std::vector decryptKey; - DistributedDB::KvStoreNbDelegate::Option dbOptions; - auto status = kvStoreDataServiceTest.InitNbDbOption(options, decryptKey, dbOptions); - EXPECT_EQ(status, SUCCESS); } \ No newline at end of file diff --git a/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp b/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp index cdb512aa7..12b857f62 100644 --- a/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp @@ -598,8 +598,9 @@ HWTEST_F(KvdbServiceImplTest, ResolveAutoLaunch, TestSize.Level0) EXPECT_NE(kvStore, nullptr); EXPECT_EQ(status, Status::SUCCESS); std::string identifier = "identifier"; + bool isFind = false; DistributedKv::KVDBServiceImpl::DBLaunchParam launchParam; - auto result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam); + auto result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam, isFind); EXPECT_EQ(result, Status::STORE_NOT_FOUND); std::shared_ptr executors = std::make_shared(1, 0); Bootstrap::GetInstance().LoadDirectory(); @@ -607,7 +608,7 @@ HWTEST_F(KvdbServiceImplTest, ResolveAutoLaunch, TestSize.Level0) DistributedKv::KvStoreMetaManager::GetInstance().BindExecutor(executors); DistributedKv::KvStoreMetaManager::GetInstance().InitMetaParameter(); DistributedKv::KvStoreMetaManager::GetInstance().InitMetaListener(); - result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam); + result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam, isFind); EXPECT_EQ(result, Status::SUCCESS); } From 636163358a5b197f529ad3bfaee001777841478b Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 22:45:37 +0800 Subject: [PATCH 12/24] update Signed-off-by: yangliu --- .../service/kvdb/kvdb_service_impl.cpp | 25 +++++++++++-------- .../service/kvdb/kvdb_service_impl.h | 1 + .../service/object/object_service_impl.cpp | 3 ++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index f9734b36f..3a19c9625 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -59,7 +59,7 @@ using system_clock = std::chrono::system_clock; using DMAdapter = DistributedData::DeviceManagerAdapter; using DumpManager = OHOS::DistributedData::DumpManager; using CommContext = OHOS::DistributedData::CommunicatorContext; -using SecretKeyMeta = DistributedData::SecretKeyMetaData; +using SecretKeyMeta = DistributedData::SecretKeyMetaData; static constexpr const char *DEFAULT_USER_ID = "0"; __attribute__((used)) KVDBServiceImpl::Factory KVDBServiceImpl::factory_; KVDBServiceImpl::Factory::Factory() @@ -816,15 +816,7 @@ bool KVDBServiceImpl::IsTripleAutoLaunch( if (storeMeta.bundleName == Bootstrap::GetInstance().GetProcessLabel()) { param.userId = storeMeta.user; } - option.schema = storeMeta.schema; - option.createDirByStoreIdOnly = true; - option.dataDir = storeMeta.dataDir; - option.secOption = ConvertSecurity(storeMeta.securityLevel); - option.isAutoSync = storeMeta.isAutoSync; - option.syncDualTupleMode = true; // dual tuple flag - param.appId = storeMeta.appId; - param.storeId = storeMeta.storeId; - param.option = option; + SetAutoLaunchParam(option, param); isFindIdentifier = true; return isTripleIdentifierEqual; } @@ -833,6 +825,19 @@ bool KVDBServiceImpl::IsTripleAutoLaunch( return false; } +void KVDBServiceImpl::SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, DistributedDB::AutoLaunchParam ¶m) +{ + option.schema = storeMeta.schema; + option.createDirByStoreIdOnly = true; + option.dataDir = storeMeta.dataDir; + option.secOption = ConvertSecurity(storeMeta.securityLevel); + option.isAutoSync = storeMeta.isAutoSync; + option.syncDualTupleMode = true; // dual tuple flag + param.appId = storeMeta.appId; + param.storeId = storeMeta.storeId; + param.option = option; +} + int32_t KVDBServiceImpl::DoTripleAutoLaunch(StoreMetaData &meta) { auto watchers = GetWatchers(meta.tokenId, meta.storeId); diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index 6c3e2741d..24036a3bf 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -156,6 +156,7 @@ private: StoreMetaData &meta, bool &isFindIdentifier); int32_t DoTripleAutoLaunch(StoreMetaData &meta); DistributedDB::SecurityOption ConvertSecurity(int securityLevel); + void SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, DistributedDB::AutoLaunchParam ¶m); Status ConvertDbStatusNative(DBStatus status); static Factory factory_; ConcurrentMap syncAgents_; diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index 537af24be..bdf30b583 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -295,7 +295,8 @@ int32_t ObjectServiceImpl::ObjectStatic::OnAppUninstall(const std::string &bundl return result; } -int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, bool &isFindIdentifier) +int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, + bool &isFindIdentifier) { ZLOGI("start, user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), param.appId.c_str(), DistributedData::Anonymous::Change(param.storeId).c_str(), From 0e357ad289b51ea972133a8eda4aae366c2867ab Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 22:46:44 +0800 Subject: [PATCH 13/24] update Signed-off-by: yangliu --- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 3a19c9625..f1dac19dc 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -778,7 +778,7 @@ bool KVDBServiceImpl::IsTripleAutoLaunch( const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &meta, bool &isFindIdentifier) { std::vector entries; - std::string localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + std::string localDeviceId = DMAdapter::GetInstance().GetLocalDevice().uuid; if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ localDeviceId }), entries)) { ZLOGE("get full meta failed"); return false; From 1e1cc7e1392a14f535aa84b110e783ee6f11d2de Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 23:04:24 +0800 Subject: [PATCH 14/24] update Signed-off-by: yangliu --- .../service/kvdb/kvdb_service_impl.cpp | 5 +++-- .../distributeddataservice/service/kvdb/kvdb_service_impl.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index f1dac19dc..9c37c43ca 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -816,7 +816,7 @@ bool KVDBServiceImpl::IsTripleAutoLaunch( if (storeMeta.bundleName == Bootstrap::GetInstance().GetProcessLabel()) { param.userId = storeMeta.user; } - SetAutoLaunchParam(option, param); + SetAutoLaunchParam(option, param, ); isFindIdentifier = true; return isTripleIdentifierEqual; } @@ -825,7 +825,8 @@ bool KVDBServiceImpl::IsTripleAutoLaunch( return false; } -void KVDBServiceImpl::SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, DistributedDB::AutoLaunchParam ¶m) +void KVDBServiceImpl::SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, + DistributedDB::AutoLaunchParam ¶m, StoreMetaData &storeMeta) { option.schema = storeMeta.schema; option.createDirByStoreIdOnly = true; diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index 24036a3bf..30dc0512e 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -156,7 +156,8 @@ private: StoreMetaData &meta, bool &isFindIdentifier); int32_t DoTripleAutoLaunch(StoreMetaData &meta); DistributedDB::SecurityOption ConvertSecurity(int securityLevel); - void SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, DistributedDB::AutoLaunchParam ¶m); + void SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, DistributedDB::AutoLaunchParam ¶m, + StoreMetaData &storeMeta); Status ConvertDbStatusNative(DBStatus status); static Factory factory_; ConcurrentMap syncAgents_; From 1189e9fadb6cee7d99d6d1b60c641a7684bab3ca Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 18 Nov 2024 23:10:38 +0800 Subject: [PATCH 15/24] update Signed-off-by: yangliu --- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 9c37c43ca..d2276fd52 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -816,7 +816,7 @@ bool KVDBServiceImpl::IsTripleAutoLaunch( if (storeMeta.bundleName == Bootstrap::GetInstance().GetProcessLabel()) { param.userId = storeMeta.user; } - SetAutoLaunchParam(option, param, ); + SetAutoLaunchParam(option, param, storeMeta); isFindIdentifier = true; return isTripleIdentifierEqual; } From 18dd07e79b4cfba8ff104bd53bcfe4c70f714516 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 19 Nov 2024 09:08:49 +0800 Subject: [PATCH 16/24] update Signed-off-by: yangliu --- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 2 +- .../distributeddataservice/service/kvdb/kvdb_service_impl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index d2276fd52..ab8076ea6 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -826,7 +826,7 @@ bool KVDBServiceImpl::IsTripleAutoLaunch( } void KVDBServiceImpl::SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, - DistributedDB::AutoLaunchParam ¶m, StoreMetaData &storeMeta) + DistributedDB::AutoLaunchParam ¶m, const StoreMetaData &storeMeta) { option.schema = storeMeta.schema; option.createDirByStoreIdOnly = true; diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index 30dc0512e..f950d2a90 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -157,7 +157,7 @@ private: int32_t DoTripleAutoLaunch(StoreMetaData &meta); DistributedDB::SecurityOption ConvertSecurity(int securityLevel); void SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData &storeMeta); + const StoreMetaData &storeMeta); Status ConvertDbStatusNative(DBStatus status); static Factory factory_; ConcurrentMap syncAgents_; From dcc5d7b8d8cfa7acb03c8dce461da816a3067efe Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 19 Nov 2024 09:11:52 +0800 Subject: [PATCH 17/24] update Signed-off-by: yangliu --- services/distributeddataservice/app/src/kvstore_data_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 344201cd3..93a093d4e 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -362,7 +362,6 @@ void KvStoreDataService::StartService() // subscribe account event listener to EventNotificationMgr auto autoLaunch = [this](const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) -> bool { - StoreMetaData metaData; bool isFindIdentifier = false; features_.ForEachCopies([&identifier, ¶m, &isFindIdentifier](const auto &, sptr &value) { From 921280e9c8c14ffcb78ebabed8467b131815cf00 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 19 Nov 2024 09:29:47 +0800 Subject: [PATCH 18/24] update Signed-off-by: yangliu --- services/distributeddataservice/app/src/kvstore_data_service.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 0e78f0b59..77f221bb3 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -166,9 +166,6 @@ private: Status AppExit(pid_t uid, pid_t pid, uint32_t token, const AppId &appId); - bool ResolveAutoLaunchParamByIdentifier( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &metaData, bool &isTriple); - void LoadConfigs(); static constexpr int TEN_SEC = 10; From 8a11485520b028ed05f7bfe8680f9729c58d58ac Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 19 Nov 2024 22:19:44 +0800 Subject: [PATCH 19/24] update Signed-off-by: yangliu --- .../app/src/feature_stub_impl.cpp | 5 +- .../app/src/feature_stub_impl.h | 3 +- .../app/src/kvstore_data_service.cpp | 8 +- .../framework/feature/feature_system.cpp | 3 +- .../include/feature/feature_system.h | 3 +- .../framework/test/feature_test.cpp | 3 +- .../service/kvdb/kvdb_service_impl.cpp | 122 ++---------------- .../service/kvdb/kvdb_service_impl.h | 9 +- .../service/object/object_service_impl.cpp | 3 +- .../service/object/object_service_impl.h | 3 +- .../service/rdb/rdb_service_impl.cpp | 6 +- .../service/rdb/rdb_service_impl.h | 3 +- .../service/test/kvdb_service_impl_test.cpp | 5 +- 13 files changed, 31 insertions(+), 145 deletions(-) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index 75fcfaa7a..a690ddbe9 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -77,13 +77,12 @@ int32_t FeatureStubImpl::OnAppInstall(const std::string &bundleName, int32_t use return featureImpl_->OnAppInstall(bundleName, user, index); } -int32_t FeatureStubImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier) +int32_t FeatureStubImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) { if (featureImpl_ == nullptr) { return -1; } - return featureImpl_->ResolveAutoLaunch(identifier, param, isFindIdentifier); + return featureImpl_->ResolveAutoLaunch(identifier, param); } int32_t FeatureStubImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.h b/services/distributeddataservice/app/src/feature_stub_impl.h index 3f4d97a4f..e9249a76b 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/services/distributeddataservice/app/src/feature_stub_impl.h @@ -35,8 +35,7 @@ public: int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index); int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index); - int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier); + int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); int32_t Online(const std::string &device); int32_t Offline(const std::string &device); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 93a093d4e..291a4dfcb 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -362,13 +362,11 @@ void KvStoreDataService::StartService() // subscribe account event listener to EventNotificationMgr auto autoLaunch = [this](const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) -> bool { - bool isFindIdentifier = false; - features_.ForEachCopies([&identifier, ¶m, &isFindIdentifier](const auto &, - sptr &value) { - value->ResolveAutoLaunch(identifier, param, isFindIdentifier); + features_.ForEachCopies([&identifier, ¶m](const auto &, sptr &value) { + value->ResolveAutoLaunch(identifier, param); return false; }); - return isFindIdentifier; + return false; }; KvStoreDelegateManager::SetAutoLaunchRequestCallback(autoLaunch); ZLOGI("Start distributedata Success, Publish ret: %{public}d", static_cast(ret)); diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index 435d209c4..593a7c63b 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -91,8 +91,7 @@ int32_t FeatureSystem::Feature::OnAppInstall(const std::string &bundleName, int3 return E_OK; } -int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier) +int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) { return E_OK; } diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index 97a0408da..a7da54d1d 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -51,8 +51,7 @@ public: virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index); virtual int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index); virtual int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index); - virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier); + virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); virtual int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); virtual int32_t Online(const std::string &device); virtual int32_t Offline(const std::string &device); diff --git a/services/distributeddataservice/framework/test/feature_test.cpp b/services/distributeddataservice/framework/test/feature_test.cpp index 1e72a062e..6f733a0de 100644 --- a/services/distributeddataservice/framework/test/feature_test.cpp +++ b/services/distributeddataservice/framework/test/feature_test.cpp @@ -206,8 +206,7 @@ HWTEST_F(FeatureSystemTest, ResolveAutoLaunchTest, TestSize.Level1) DistributedDB::AutoLaunchParam param; MockFeature mockFeature; - bool status = false; - int32_t ret = mockFeature.ResolveAutoLaunch(identifier, param, status); + int32_t ret = mockFeature.ResolveAutoLaunch(identifier, param); EXPECT_EQ(ret, E_OK); } diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index ab8076ea6..00aa80d6e 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -774,136 +774,42 @@ bool KVDBServiceImpl::CompareTripleIdentifier(const std::string &accountId, cons return false; } -bool KVDBServiceImpl::IsTripleAutoLaunch( - const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, StoreMetaData &meta, bool &isFindIdentifier) -{ - std::vector entries; - std::string localDeviceId = DMAdapter::GetInstance().GetLocalDevice().uuid; - if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ localDeviceId }), entries)) { - ZLOGE("get full meta failed"); - return false; - } - - auto accountId = AccountDelegate::GetInstance()->GetUnencryptedAccountId(); - for (const auto &storeMeta : entries) { - if ((!param.userId.empty() && (param.userId != storeMeta.user)) || (localDeviceId != storeMeta.deviceId) || - ((StoreMetaData::STORE_RELATIONAL_BEGIN <= storeMeta.storeType) && - (StoreMetaData::STORE_RELATIONAL_END >= storeMeta.storeType))) { - // judge local userid and local meta - continue; - } - bool isTripleIdentifierEqual = CompareTripleIdentifier(accountId, identifier, storeMeta); - const std::string &itemDualIdentifier = - DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier("", storeMeta.appId, storeMeta.storeId, true); - if (isTripleIdentifierEqual && storeMeta.bundleName != Bootstrap::GetInstance().GetProcessLabel()) { - meta = storeMeta; - meta.account = accountId; - } - if (identifier == itemDualIdentifier || isTripleIdentifierEqual) { - ZLOGI("identifier find:%{public}d", isTripleIdentifierEqual); - DistributedDB::AutoLaunchOption option; - option.createIfNecessary = false; - option.isEncryptedDb = storeMeta.isEncrypt; - - SecretKeyMeta secretKey; - if (storeMeta.isEncrypt && MetaDataManager::GetInstance().LoadMeta(storeMeta.GetSecretKey(), secretKey)) { - std::vector decryptKey; - CryptoManager::GetInstance().Decrypt(secretKey.sKey, decryptKey); - option.passwd.SetValue(decryptKey.data(), decryptKey.size()); - std::fill(decryptKey.begin(), decryptKey.end(), 0); - } - - if (storeMeta.bundleName == Bootstrap::GetInstance().GetProcessLabel()) { - param.userId = storeMeta.user; - } - SetAutoLaunchParam(option, param, storeMeta); - isFindIdentifier = true; - return isTripleIdentifierEqual; - } - } - ZLOGI("not find identifier"); - return false; -} - -void KVDBServiceImpl::SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, - DistributedDB::AutoLaunchParam ¶m, const StoreMetaData &storeMeta) -{ - option.schema = storeMeta.schema; - option.createDirByStoreIdOnly = true; - option.dataDir = storeMeta.dataDir; - option.secOption = ConvertSecurity(storeMeta.securityLevel); - option.isAutoSync = storeMeta.isAutoSync; - option.syncDualTupleMode = true; // dual tuple flag - param.appId = storeMeta.appId; - param.storeId = storeMeta.storeId; - param.option = option; -} - -int32_t KVDBServiceImpl::DoTripleAutoLaunch(StoreMetaData &meta) -{ - auto watchers = GetWatchers(meta.tokenId, meta.storeId); - ZLOGI("triple autolaunch.appId:%{public}s storeId:%{public}s tokenid:0x%{public}x size:%{public}zu", - meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), meta.tokenId, watchers.size()); - auto store = AutoCache::GetInstance().GetStore(meta, watchers); - if (store == nullptr) { - ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); - return STORE_NOT_OPEN; - } - store->SetEqualIdentifier(meta.appId, meta.storeId, meta.account); - return SUCCESS; -} - -int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, bool &isFindIdentifier) +int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m) { ZLOGI("user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), Anonymous::Change(identifier).c_str()); - StoreMetaData meta; - if (IsTripleAutoLaunch(identifier, param, meta, isFindIdentifier)) { - ZLOGI("do triple autolaunch. storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); - return DoTripleAutoLaunch(meta); - } - std::vector metaData; - auto prefix = StoreMetaData::GetPrefix({ DMAdapter::GetInstance().GetLocalDevice().uuid, param.userId }); + auto prefix = StoreMetaData::GetPrefix({ DMAdapter::GetInstance().GetLocalDevice().uuid }); if (!MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { ZLOGE("no store in user:%{public}s", param.userId.c_str()); return STORE_NOT_FOUND; } + auto accountId = AccountDelegate::GetInstance()->GetUnencryptedAccountId(); for (const auto &storeMeta : metaData) { if (storeMeta.storeType < StoreMetaData::StoreType::STORE_KV_BEGIN || - storeMeta.storeType > StoreMetaData::StoreType::STORE_KV_END) { + storeMeta.storeType > StoreMetaData::StoreType::STORE_KV_END || + (!param.userId.empty() && (param.userId != storeMeta.user))) { continue; } auto identifierTag = DBManager::GetKvStoreIdentifier("", storeMeta.appId, storeMeta.storeId, true); - if (identifier != identifierTag) { + bool isTripleIdentifierEqual = CompareTripleIdentifier(accountId, identifier, storeMeta); + if (identifier != identifierTag && !isTripleIdentifierEqual) { continue; } auto watchers = GetWatchers(storeMeta.tokenId, storeMeta.storeId); - AutoCache::GetInstance().GetStore(storeMeta, watchers); - - ZLOGD("user:%{public}s appId:%{public}s storeId:%{public}s", storeMeta.user.c_str(), - storeMeta.bundleName.c_str(), Anonymous::Change(storeMeta.storeId).c_str()); + auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers); + if (isTripleIdentifierEqual && store != nullptr) { + store->SetEqualIdentifier(storeMeta.appId, storeMeta.storeId, accountId); + } + ZLOGI("isTriple:%{public}d,storeId:%{public}s,tokenid:0x%{public}x,size:%{public}zu,user:%{public}s", + isTripleIdentifierEqual, Anonymous::Change(meta.storeId).c_str(), + meta.tokenId, watchers.size(), storeMeta.user.c_str()); } return SUCCESS; } -DistributedDB::SecurityOption KVDBServiceImpl::ConvertSecurity(int securityLevel) -{ - if (securityLevel < SecurityLevel::NO_LABEL || securityLevel > SecurityLevel::S4) { - return {DistributedDB::NOT_SET, DistributedDB::ECE}; - } - switch (securityLevel) { - case SecurityLevel::S3: - return {DistributedDB::S3, DistributedDB::SECE}; - case SecurityLevel::S4: - return {DistributedDB::S4, DistributedDB::ECE}; - default: - return {securityLevel, DistributedDB::ECE}; - } -} - int32_t KVDBServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { (void)code; diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index f950d2a90..a4c86bc37 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -73,7 +73,7 @@ public: int32_t OnBind(const BindInfo &bindInfo) override; int32_t OnInitialize() override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; - int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m, bool &isFindIdentifier) override; + int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; Status RemoveDeviceData(const AppId &appId, const StoreId &storeId, const std::string &device) override; @@ -152,13 +152,6 @@ private: bool IsOHOSType(const std::vector &ids); bool CompareTripleIdentifier(const std::string &accountId, const std::string &identifier, const StoreMetaData &storeMeta); - bool IsTripleAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - StoreMetaData &meta, bool &isFindIdentifier); - int32_t DoTripleAutoLaunch(StoreMetaData &meta); - DistributedDB::SecurityOption ConvertSecurity(int securityLevel); - void SetAutoLaunchParam(DistributedDB::AutoLaunchOption &option, DistributedDB::AutoLaunchParam ¶m, - const StoreMetaData &storeMeta); - Status ConvertDbStatusNative(DBStatus status); static Factory factory_; ConcurrentMap syncAgents_; std::shared_ptr executors_; diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index bdf30b583..1a3182fcc 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -295,8 +295,7 @@ int32_t ObjectServiceImpl::ObjectStatic::OnAppUninstall(const std::string &bundl return result; } -int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier) +int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) { ZLOGI("start, user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), param.appId.c_str(), DistributedData::Anonymous::Change(param.storeId).c_str(), diff --git a/services/distributeddataservice/service/object/object_service_impl.h b/services/distributeddataservice/service/object/object_service_impl.h index 0557f0840..437d49e9e 100644 --- a/services/distributeddataservice/service/object/object_service_impl.h +++ b/services/distributeddataservice/service/object/object_service_impl.h @@ -41,8 +41,7 @@ public: int32_t IsBundleNameEqualTokenId( const std::string &bundleName, const std::string &sessionId, const uint32_t &tokenId); void Clear(); - int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier) override; + int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; int32_t OnInitialize() override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 6a7d6e2bd..b3903b142 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -97,8 +97,7 @@ RdbServiceImpl::RdbServiceImpl() ZLOGI("construct"); DistributedDB::RelationalStoreManager::SetAutoLaunchRequestCallback( [this](const std::string& identifier, DistributedDB::AutoLaunchParam ¶m) { - bool isFindIdentifier = false; - return ResolveAutoLaunch(identifier, param, isFindIdentifier); + return ResolveAutoLaunch(identifier, param); }); auto process = [this](const Event &event) { auto &evt = static_cast(event); @@ -145,8 +144,7 @@ RdbServiceImpl::RdbServiceImpl() EventCenter::GetInstance().Subscribe(BindEvent::RECOVER_SYNC, compensateSyncProcess); } -int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier) +int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) { std::string identifierHex = TransferStringToHex(identifier); ZLOGI("%{public}.6s", identifierHex.c_str()); diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 0ed285c46..b49d448ef 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -74,8 +74,7 @@ public: int32_t UnregisterAutoSyncCallback(const RdbSyncerParam& param, std::shared_ptr observer) override; - int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m, - bool &isFindIdentifier) override; + int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; diff --git a/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp b/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp index 12b857f62..cdb512aa7 100644 --- a/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/kvdb_service_impl_test.cpp @@ -598,9 +598,8 @@ HWTEST_F(KvdbServiceImplTest, ResolveAutoLaunch, TestSize.Level0) EXPECT_NE(kvStore, nullptr); EXPECT_EQ(status, Status::SUCCESS); std::string identifier = "identifier"; - bool isFind = false; DistributedKv::KVDBServiceImpl::DBLaunchParam launchParam; - auto result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam, isFind); + auto result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam); EXPECT_EQ(result, Status::STORE_NOT_FOUND); std::shared_ptr executors = std::make_shared(1, 0); Bootstrap::GetInstance().LoadDirectory(); @@ -608,7 +607,7 @@ HWTEST_F(KvdbServiceImplTest, ResolveAutoLaunch, TestSize.Level0) DistributedKv::KvStoreMetaManager::GetInstance().BindExecutor(executors); DistributedKv::KvStoreMetaManager::GetInstance().InitMetaParameter(); DistributedKv::KvStoreMetaManager::GetInstance().InitMetaListener(); - result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam, isFind); + result = kvdbServiceImpl_->ResolveAutoLaunch(identifier, launchParam); EXPECT_EQ(result, Status::SUCCESS); } From 7ae3f5980a13fd7fa3ef2636fefe92e4be1b3eda Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 19 Nov 2024 22:28:39 +0800 Subject: [PATCH 20/24] update Signed-off-by: yangliu --- .../framework/include/feature/feature_system.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index a7da54d1d..ecadb34db 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -21,7 +21,6 @@ #include "executor_pool.h" #include "static_acts.h" #include "visibility.h" -#include "metadata/store_meta_data.h" namespace DistributedDB { struct AutoLaunchParam; } From 89c711595da99628429795739ad3440f5754945f Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 19 Nov 2024 22:37:40 +0800 Subject: [PATCH 21/24] update Signed-off-by: yangliu --- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 00aa80d6e..7ddd1886c 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -804,8 +804,8 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun store->SetEqualIdentifier(storeMeta.appId, storeMeta.storeId, accountId); } ZLOGI("isTriple:%{public}d,storeId:%{public}s,tokenid:0x%{public}x,size:%{public}zu,user:%{public}s", - isTripleIdentifierEqual, Anonymous::Change(meta.storeId).c_str(), - meta.tokenId, watchers.size(), storeMeta.user.c_str()); + isTripleIdentifierEqual, Anonymous::Change(meta.storeId).c_str(), + meta.tokenId, watchers.size(), storeMeta.user.c_str()); } return SUCCESS; } From 6bccec79171483a0847511c45a3f41ec1d93a2ca Mon Sep 17 00:00:00 2001 From: yangliu Date: Wed, 20 Nov 2024 09:37:53 +0800 Subject: [PATCH 22/24] update Signed-off-by: yangliu --- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 4 ++-- .../distributeddataservice/service/kvdb/kvdb_service_impl.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 7ddd1886c..65ba9d47b 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -804,8 +804,8 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun store->SetEqualIdentifier(storeMeta.appId, storeMeta.storeId, accountId); } ZLOGI("isTriple:%{public}d,storeId:%{public}s,tokenid:0x%{public}x,size:%{public}zu,user:%{public}s", - isTripleIdentifierEqual, Anonymous::Change(meta.storeId).c_str(), - meta.tokenId, watchers.size(), storeMeta.user.c_str()); + isTripleIdentifierEqual, Anonymous::Change(storeMeta.storeId).c_str(), + storeMeta.tokenId, watchers.size(), storeMeta.user.c_str()); } return SUCCESS; } diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index a4c86bc37..dba6babeb 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -150,6 +150,7 @@ private: void TryToSync(const StoreMetaData &metaData, bool force = false); bool IsRemoteChange(const StoreMetaData &metaData, const std::string &device); bool IsOHOSType(const std::vector &ids); + Status ConvertDbStatusNative(DBStatus status); bool CompareTripleIdentifier(const std::string &accountId, const std::string &identifier, const StoreMetaData &storeMeta); static Factory factory_; From 73f9c097597d9baa5963d32b6918820772b6a744 Mon Sep 17 00:00:00 2001 From: yangliu Date: Thu, 21 Nov 2024 19:06:15 +0800 Subject: [PATCH 23/24] update Signed-off-by: yangliu --- .../service/kvdb/kvdb_service_impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 65ba9d47b..894424163 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -782,7 +782,7 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun std::vector metaData; auto prefix = StoreMetaData::GetPrefix({ DMAdapter::GetInstance().GetLocalDevice().uuid }); if (!MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { - ZLOGE("no store in user:%{public}s", param.userId.c_str()); + ZLOGE("no meta data appId:%{public}s", param.appId.c_str()); return STORE_NOT_FOUND; } @@ -803,9 +803,9 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun if (isTripleIdentifierEqual && store != nullptr) { store->SetEqualIdentifier(storeMeta.appId, storeMeta.storeId, accountId); } - ZLOGI("isTriple:%{public}d,storeId:%{public}s,tokenid:0x%{public}x,size:%{public}zu,user:%{public}s", + ZLOGI("isTriple:%{public}d,storeId:%{public}s,size:%{public}zu,user:%{public}s", isTripleIdentifierEqual, Anonymous::Change(storeMeta.storeId).c_str(), - storeMeta.tokenId, watchers.size(), storeMeta.user.c_str()); + watchers.size(), storeMeta.user.c_str()); } return SUCCESS; } From d0e0645485b8627e8f5cdbd094756a93f7bc359a Mon Sep 17 00:00:00 2001 From: yangliu Date: Thu, 21 Nov 2024 19:08:15 +0800 Subject: [PATCH 24/24] update Signed-off-by: yangliu --- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 894424163..2efbeeaf6 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -803,8 +803,8 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun if (isTripleIdentifierEqual && store != nullptr) { store->SetEqualIdentifier(storeMeta.appId, storeMeta.storeId, accountId); } - ZLOGI("isTriple:%{public}d,storeId:%{public}s,size:%{public}zu,user:%{public}s", - isTripleIdentifierEqual, Anonymous::Change(storeMeta.storeId).c_str(), + ZLOGI("isTriple:%{public}d,storeId:%{public}s,appId:%{public}s,size:%{public}zu,user:%{public}s", + isTripleIdentifierEqual, Anonymous::Change(storeMeta.storeId).c_str(), storeMeta.storeId.c_str(), watchers.size(), storeMeta.user.c_str()); } return SUCCESS;