From c258f8d499c865c2bb7b2cdc6137c7b5ab2c7bde Mon Sep 17 00:00:00 2001 From: bigteer Date: Tue, 19 Aug 2025 14:55:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=8C=87=E5=AE=9AdeviceId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/device_manager_adapter.cpp | 25 ++++ .../unittest/device_manager_adapter_test.cpp | 45 ++++++ .../communicator/device_manager_adapter.h | 2 + .../app/src/kvstore_data_service.cpp | 2 +- .../device_sync_app_manager.cpp | 12 +- .../device_sync_app/device_sync_app_manager.h | 3 +- .../include/metadata/store_meta_data.h | 1 + .../include/metadata/store_meta_data_local.h | 12 ++ .../framework/metadata/store_meta_data.cpp | 5 + .../metadata/store_meta_data_local.cpp | 15 ++ .../test/device_sync_app_manager_test.cpp | 41 ++++- .../service/rdb/rdb_general_store.cpp | 2 +- .../service/rdb/rdb_query.cpp | 4 +- .../service/rdb/rdb_query.h | 2 +- .../service/rdb/rdb_service_impl.cpp | 141 ++++++++++++++---- .../service/rdb/rdb_service_impl.h | 4 +- .../service/test/rdb_service_impl_test.cpp | 13 +- 17 files changed, 276 insertions(+), 53 deletions(-) mode change 100755 => 100644 services/distributeddataservice/framework/include/metadata/store_meta_data_local.h mode change 100755 => 100644 services/distributeddataservice/framework/metadata/store_meta_data_local.cpp diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index ea4915cf9..5ad57fb78 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -573,6 +573,19 @@ std::vector DeviceManagerAdapter::ToUUID(const std::vector DeviceManagerAdapter::ToUDID(const std::vector &devices) +{ + std::vector udids; + for (auto &device : devices) { + auto udid = DeviceManagerAdapter::GetInstance().ToUDID(device); + if (udid.empty()) { + continue; + } + udids.push_back(std::move(udid)); + } + return udids; +} + std::vector DeviceManagerAdapter::ToUUID(std::vector devices) { std::vector uuids; @@ -585,6 +598,18 @@ std::vector DeviceManagerAdapter::ToUUID(std::vector de return uuids; } +std::vector DeviceManagerAdapter::ToUDID(std::vector devices) +{ + std::vector udids; + for (auto &device : devices) { + if (device.udid.empty()) { + continue; + } + udids.push_back(std::move(device.udid)); + } + return udids; +} + std::string DeviceManagerAdapter::ToNetworkID(const std::string &id) { return GetDeviceInfoFromCache(id).networkId; diff --git a/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp b/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp index f08d3153b..855f2a5d4 100644 --- a/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp +++ b/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp @@ -311,6 +311,29 @@ HWTEST_F(DeviceManagerAdapterTest, DeviceIdsToUUID, TestSize.Level0) } } +/** +* @tc.name: DeviceIdToUDID +* @tc.desc: transfer deviceIds to udid +* @tc.type: FUNC +* @tc.require: +* @tc.author: zd + */ +HWTEST_F(DeviceManagerAdapterTest, DeviceIdsToUDID, TestSize.Level0) +{ + std::vector devices; + devices.emplace_back(EMPTY_DEVICE_ID); + devices.emplace_back(INVALID_DEVICE_ID); + auto dvInfo = DeviceManagerAdapter::GetInstance().GetLocalDevice(); + devices.emplace_back(dvInfo.uuid); + devices.emplace_back(dvInfo.udid); + devices.emplace_back(dvInfo.networkId); + auto udids = DeviceManagerAdapter::GetInstance().ToUDID(devices); + EXPECT_EQ(udids.size(), LOCAL_DEVICE_ID_NUM); + for (const auto &udid : udids) { + EXPECT_EQ(udid, dvInfo.udid); + } +} + /** * @tc.name: DeviceIdToUUID * @tc.desc: transfer deviceIds to uuid @@ -333,6 +356,28 @@ HWTEST_F(DeviceManagerAdapterTest, DeviceIdToUUID, TestSize.Level0) EXPECT_EQ(uuids[1], dvInfo.uuid); } +/** +* @tc.name: DeviceInfosToUUID +* @tc.desc: transfer deviceIds to udid +* @tc.type: FUNC +* @tc.require: +* @tc.author: zd + */ +HWTEST_F(DeviceManagerAdapterTest, DeviceInfosToUUID, TestSize.Level0) +{ + std::vector devices; + DeviceInfo dvInfo; + devices.emplace_back(dvInfo); + dvInfo.udid = INVALID_DEVICE_ID; + devices.emplace_back(dvInfo); + dvInfo = DeviceManagerAdapter::GetInstance().GetLocalDevice(); + devices.emplace_back(dvInfo); + auto udids = DeviceManagerAdapter::GetInstance().ToUDID(devices); + EXPECT_EQ(udids.size(), LOCAL_UUID_NUM); + EXPECT_EQ(udids[0], INVALID_DEVICE_ID); + EXPECT_EQ(udids[1], dvInfo.udid); +} + /** * @tc.name: DeviceIdToNetworkId * @tc.desc: transfer deviceId to networkId, the deviceId is invalid diff --git a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h index 575a2f393..9a9bc67b9 100644 --- a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h +++ b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h @@ -67,7 +67,9 @@ public: std::string ToUUID(const std::string &id); std::string ToUDID(const std::string &id); static std::vector ToUUID(const std::vector &devices); + static std::vector ToUDID(const std::vector &devices); static std::vector ToUUID(std::vector devices); + static std::vector ToUDID(std::vector devices); std::string ToNetworkID(const std::string &id); void NotifyReadyEvent(const std::string &uuid); int32_t GetAuthType(const std::string& id); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 51af0c61e..f7a34cad0 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -909,7 +909,7 @@ void KvStoreDataService::AccountEventChanged(const AccountEventInfo &eventInfo) g_kvStoreAccountEventStatus = 1; // delete all kvstore meta belong to this user std::vector metaData; - MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({""}), metaData, true); + MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({}), metaData, true); for (const auto &meta : metaData) { if (meta.user != eventInfo.userId) { continue; diff --git a/services/distributeddataservice/framework/device_sync_app/device_sync_app_manager.cpp b/services/distributeddataservice/framework/device_sync_app/device_sync_app_manager.cpp index e20ee46ef..b7a2e671a 100644 --- a/services/distributeddataservice/framework/device_sync_app/device_sync_app_manager.cpp +++ b/services/distributeddataservice/framework/device_sync_app/device_sync_app_manager.cpp @@ -33,7 +33,7 @@ void DeviceSyncAppManager::Initialize(const std::vector &lists) } } -bool DeviceSyncAppManager::Check(const WhiteList &whiteList) +bool DeviceSyncAppManager::CheckVersion(const WhiteList &whiteList) { for (const auto &info : whiteLists_) { if (info.appId == whiteList.appId && (info.bundleName == whiteList.bundleName) && @@ -43,5 +43,13 @@ bool DeviceSyncAppManager::Check(const WhiteList &whiteList) } return false; } - +bool DeviceSyncAppManager::CheckBundleName(const std::string &bundleName, const std::string &appId) +{ + for (const auto &info : whiteLists_) { + if (info.appId == appId && (info.bundleName == bundleName)) { + return true; + } + } + return false; +} } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/device_sync_app/device_sync_app_manager.h b/services/distributeddataservice/framework/include/device_sync_app/device_sync_app_manager.h index 664883bce..d3116e318 100644 --- a/services/distributeddataservice/framework/include/device_sync_app/device_sync_app_manager.h +++ b/services/distributeddataservice/framework/include/device_sync_app/device_sync_app_manager.h @@ -29,7 +29,8 @@ public: }; API_EXPORT static DeviceSyncAppManager &GetInstance(); API_EXPORT void Initialize(const std::vector &lists); - API_EXPORT bool Check(const WhiteList &whiteList); + API_EXPORT bool CheckVersion(const WhiteList &whiteList); + API_EXPORT bool CheckBundleName(const std::string &bundleName, const std::string &appId); private: DeviceSyncAppManager(); diff --git a/services/distributeddataservice/framework/include/metadata/store_meta_data.h b/services/distributeddataservice/framework/include/metadata/store_meta_data.h index 201fccc01..a72bbd19a 100644 --- a/services/distributeddataservice/framework/include/metadata/store_meta_data.h +++ b/services/distributeddataservice/framework/include/metadata/store_meta_data.h @@ -91,6 +91,7 @@ struct API_EXPORT StoreMetaData : public Serializable { API_EXPORT virtual std::string GetStrategyKey() const; API_EXPORT virtual std::string GetBackupSecretKey() const; API_EXPORT virtual std::string GetAutoLaunchKey() const; + API_EXPORT virtual std::string GetAutoSyncDeviceKey() const; API_EXPORT virtual std::string GetDebugInfoKey() const; API_EXPORT virtual std::string GetDebugInfoKeyWithoutPath() const; API_EXPORT virtual std::string GetDfxInfoKey() const; diff --git a/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h b/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h old mode 100755 new mode 100644 index 717b495f9..c3242140b --- a/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h +++ b/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h @@ -81,5 +81,17 @@ struct API_EXPORT StoreDfxInfo final : public Serializable { private: static constexpr const char *KEY_PREFIX = "StoreDfxInfo"; }; + +struct API_EXPORT AutoSyncDevicesInfo final : public Serializable { + std::vector udids {}; + API_EXPORT AutoSyncDevicesInfo() = default; + API_EXPORT ~AutoSyncDevicesInfo() = default; + API_EXPORT static std::string GetKey(const std::initializer_list &fields); + bool Marshal(Serializable::json &node) const override; + bool Unmarshal(const Serializable::json &node) override; + +private: + static constexpr const char *KEY_PREFIX = "AutoSyncDevice"; +}; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_LOCAL_H diff --git a/services/distributeddataservice/framework/metadata/store_meta_data.cpp b/services/distributeddataservice/framework/metadata/store_meta_data.cpp index 3dba8c533..6255d384e 100644 --- a/services/distributeddataservice/framework/metadata/store_meta_data.cpp +++ b/services/distributeddataservice/framework/metadata/store_meta_data.cpp @@ -196,6 +196,11 @@ std::string StoreMetaData::GetAutoLaunchKey() const return AutoLaunchMetaData::GetPrefix({ deviceId, user, "default", bundleName, storeId }); } +std::string StoreMetaData::GetAutoSyncDeviceKey() const +{ + return AutoSyncDevicesInfo::GetKey({ deviceId, user, "default", bundleName, storeId, dataDir }); +} + std::string StoreMetaData::GetDebugInfoKey() const { return StoreDebugInfo::GetPrefix( diff --git a/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp b/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp old mode 100755 new mode 100644 index 19aea85c5..8fa74a287 --- a/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp +++ b/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp @@ -155,5 +155,20 @@ bool StoreDfxInfo::Unmarshal(const json &node) GetValue(node, GET_NAME(lastOpenTime), lastOpenTime); return true; } +std::string AutoSyncDevicesInfo::GetKey(const std::initializer_list &fields) +{ + return Constant::Join(AutoSyncDevicesInfo::KEY_PREFIX, Constant::KEY_SEPARATOR, fields); +} +bool AutoSyncDevicesInfo::Marshal(json &node) const +{ + SetValue(node[GET_NAME(udids)], udids); + return true; +} + +bool AutoSyncDevicesInfo::Unmarshal(const json &node) +{ + GetValue(node, GET_NAME(udids), udids); + return true; +} } // namespace DistributedData } // namespace OHOS diff --git a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp index 6ae441b9f..a4f375f60 100644 --- a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp +++ b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp @@ -44,7 +44,7 @@ public: HWTEST_F(DeviceSyncAppManagerTest, Check001, TestSize.Level1) { DeviceSyncAppManager::WhiteList whiteList = {"appId1", "bundleName1", 1}; - bool result = DeviceSyncAppManager::GetInstance().Check(whiteList); + bool result = DeviceSyncAppManager::GetInstance().CheckVersion(whiteList); EXPECT_TRUE(result); } @@ -56,7 +56,7 @@ HWTEST_F(DeviceSyncAppManagerTest, Check001, TestSize.Level1) HWTEST_F(DeviceSyncAppManagerTest, Check002, TestSize.Level1) { DeviceSyncAppManager::WhiteList testList = {"appId2", "bundleName1", 1}; - bool result = DeviceSyncAppManager::GetInstance().Check(testList); + bool result = DeviceSyncAppManager::GetInstance().CheckVersion(testList); EXPECT_FALSE(result); } @@ -68,7 +68,7 @@ HWTEST_F(DeviceSyncAppManagerTest, Check002, TestSize.Level1) HWTEST_F(DeviceSyncAppManagerTest, Check003, TestSize.Level1) { DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName2", 1}; - bool result = DeviceSyncAppManager::GetInstance().Check(testList); + bool result = DeviceSyncAppManager::GetInstance().CheckVersion(testList); EXPECT_FALSE(result); } @@ -80,7 +80,7 @@ HWTEST_F(DeviceSyncAppManagerTest, Check003, TestSize.Level1) HWTEST_F(DeviceSyncAppManagerTest, Check004, TestSize.Level1) { DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName1", 2}; - bool result = DeviceSyncAppManager::GetInstance().Check(testList); + bool result = DeviceSyncAppManager::GetInstance().CheckVersion(testList); EXPECT_FALSE(result); } @@ -92,7 +92,38 @@ HWTEST_F(DeviceSyncAppManagerTest, Check004, TestSize.Level1) HWTEST_F(DeviceSyncAppManagerTest, Check005, TestSize.Level1) { DeviceSyncAppManager::WhiteList whiteList = {"appId4", "bundleName4", 4}; - bool result = DeviceSyncAppManager::GetInstance().Check(whiteList); + bool result = DeviceSyncAppManager::GetInstance().CheckVersion(whiteList); EXPECT_FALSE(result); } + +/** +* @tc.name: Check006 +* @tc.desc: Checks that the given WhiteList object does not exist in whiteLists_ list. +* @tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check006, TestSize.Level1) +{ + bool result = DeviceSyncAppManager::GetInstance().CheckBundleName("bundleName4", "appId4"); + EXPECT_FALSE(result); +} +/** +* @tc.name: Check007 +* @tc.desc: Check that the given bundleName object does not match. +* @tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check007, TestSize.Level1) +{ + bool result = DeviceSyncAppManager::GetInstance().CheckBundleName("bundleName2", "appId1"); + EXPECT_FALSE(result); +} +/** +* @tc.name: Check008 +* @tc.desc: Checks that the given WhiteList object exists in whiteLists_ list. +* @tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check008, TestSize.Level1) +{ + bool result = DeviceSyncAppManager::GetInstance().CheckBundleName("bundleName1", "appId1"); + EXPECT_TRUE(result); +} } // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index d6b43d5be..cd4745a7d 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -961,7 +961,7 @@ int32_t RdbGeneralStore::SetDistributedTables(const std::vector &ta } auto [exist, database] = GetDistributedSchema(observer_.meta_); if (exist && type == DistributedTableType::DISTRIBUTED_DEVICE) { - auto force = DeviceSyncAppManager::GetInstance().Check( + auto force = DeviceSyncAppManager::GetInstance().CheckVersion( {observer_.meta_.appId, observer_.meta_.bundleName, database.version}); delegate_->SetDistributedSchema(GetGaussDistributedSchema(database), force); } diff --git a/services/distributeddataservice/service/rdb/rdb_query.cpp b/services/distributeddataservice/service/rdb/rdb_query.cpp index 994a98a45..ec716bbcc 100644 --- a/services/distributeddataservice/service/rdb/rdb_query.cpp +++ b/services/distributeddataservice/service/rdb/rdb_query.cpp @@ -70,9 +70,9 @@ void RdbQuery::MakeQuery(const PredicatesMemo &predicates) tables_ = predicates.tables_; } -void RdbQuery::MakeQuery(const std::string &table) +void RdbQuery::MakeDeviceQuery(const std::vector &tables) { - query_ = DistributedDB::Query::Select(table); + query_ = DistributedDB::Query::Select().FromTable(tables); } void RdbQuery::MakeCloudQuery(const PredicatesMemo& predicates) diff --git a/services/distributeddataservice/service/rdb/rdb_query.h b/services/distributeddataservice/service/rdb/rdb_query.h index 94d9460f2..cf80b032a 100644 --- a/services/distributeddataservice/service/rdb/rdb_query.h +++ b/services/distributeddataservice/service/rdb/rdb_query.h @@ -41,7 +41,7 @@ public: bool IsRemoteQuery(); bool IsPriority(); void MakeQuery(const PredicatesMemo &predicates); - void MakeQuery(const std::string &table); + void MakeDeviceQuery(const std::vector &tables); void MakeRemoteQuery(const std::string &devices, const std::string &sql, DistributedData::Values &&args); void MakeCloudQuery(const PredicatesMemo &predicates); diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 43c0c7cfb..2a4ec5713 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -28,6 +28,7 @@ #include "cloud/schema_meta.h" #include "communicator/device_manager_adapter.h" #include "device_matrix.h" +#include "device_sync_app/device_sync_app_manager.h" #include "directory/directory_manager.h" #include "dump/dump_manager.h" #include "eventcenter/event_center.h" @@ -60,7 +61,6 @@ using OHOS::DistributedData::Anonymous; using OHOS::DistributedData::CheckerManager; using OHOS::DistributedData::MetaDataManager; using OHOS::DistributedData::StoreMetaData; -using OHOS::DistributedData::AccountDelegate; using namespace OHOS::DistributedData; using namespace OHOS::Security::AccessToken; using DistributedDB::RelationalStoreManager; @@ -71,6 +71,7 @@ using system_clock = std::chrono::system_clock; constexpr uint32_t ITERATE_TIMES = 10000; constexpr uint32_t ALLOW_ONLINE_AUTO_SYNC = 8; +constexpr uint32_t ALLOW_AUTO_SYNC_DEVICE = 10; constexpr int32_t VALID_PARAM_LENGTH = 2; const size_t KEY_COUNT = 2; namespace OHOS::DistributedRdb { @@ -291,8 +292,9 @@ void RdbServiceImpl::UpdateMeta(const StoreMetaData &meta, const StoreMetaData & syncMeta.isEncrypt, meta.isEncrypt, syncMeta.area, meta.area); MetaDataManager::GetInstance().SaveMeta(meta.GetKeyWithoutPath(), localMeta); } + bool isAutoSync = DeviceSyncAppManager::GetInstance().CheckBundleName(meta.bundleName, meta.appId); Database dataBase; - if (RdbSchemaConfig::GetDistributedSchema(localMeta, dataBase) && !dataBase.name.empty() && + if (isAutoSync && RdbSchemaConfig::GetDistributedSchema(localMeta, dataBase) && !dataBase.name.empty() && !dataBase.bundleName.empty()) { MetaDataManager::GetInstance().SaveMeta(dataBase.GetKey(), dataBase, true); store->SetConfig({false, GeneralStore::DistributedTableMode::COLLABORATION}); @@ -466,10 +468,48 @@ int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, return DoSync(param, option, predicates, async); } +void RdbServiceImpl::SaveAutoSyncDeviceId(const StoreMetaData &meta, const PredicatesMemo &predicates) +{ + DistributedData::AutoSyncDevicesInfo deviceInfos; + std::vector devices = DmAdapter::ToUDID(predicates.devices_); + if (devices.empty()) { + ZLOGE("There is no deviceId in predicates"); + return; + } + if(!MetaDataManager::GetInstance().LoadMeta(meta.GetAutoSyncDeviceKey(), deviceInfos, true)){ + deviceInfos.udids = std::move(devices); + MetaDataManager::GetInstance().SaveMeta(meta.GetAutoSyncDeviceKey(), deviceInfos, true); + return; + } + for (auto &device : devices) { + auto iter = std::find(deviceInfos.udids.begin(), deviceInfos.udids.end(), device); + if (iter != deviceInfos.udids.end() && deviceInfos.udids.size() == 1){ + continue; + } + if (iter != deviceInfos.udids.end()) { + std::swap(*iter, deviceInfos.udids.back()); + } else { + deviceInfos.udids.push_back(device); + } + } + if (deviceInfos.udids.size() > ALLOW_AUTO_SYNC_DEVICE) { + auto index = deviceInfos.udids.size() - ALLOW_AUTO_SYNC_DEVICE; + deviceInfos.udids.erase(deviceInfos.udids.begin(), deviceInfos.udids.begin() + index - 1); + } + MetaDataManager::GetInstance().SaveMeta(meta.GetAutoSyncDeviceKey(), deviceInfos, true); +} + int RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, const RdbService::Option &option, const PredicatesMemo &predicates, const AsyncDetail &async) { StoreMetaData meta = GetStoreMetaData(param); + if(meta.instanceId != 0) { + return RDB_ERROR; + } + bool isAutoSync = DeviceSyncAppManager::GetInstance().CheckBundleName(meta.bundleName, meta.appId); + if (isAutoSync) { + SaveAutoSyncDeviceId(meta, predicates); + } auto store = GetStore(meta); if (store == nullptr) { return RDB_ERROR; @@ -1196,9 +1236,22 @@ std::vector RdbServiceImpl::GetReuseDevice(const std::vector &devices, const Database &dataBase, std::vector tables) + const std::vector &devices, const StoreMetaData &storeMetaData, std::vector tables) { - StoreMetaData storeMetaData = GetStoreMetaData(dataBase); + if(storeMetaData.instanceId != 0) { + return RDB_ERROR; + } + std::vector isSyncDevices; + std::vector deviceIds = DmAdapter::ToUDID(DmAdapter::GetInstance().GetRemoteDevices()); + for(auto &device : devices){ + if(std::find(deviceIds.begin(), deviceIds.end(), device) != deviceIds.end()){ + isSyncDevices.push_back(device); + } + } + if (isSyncDevices.empty()) { + ZLOGE("Designated syncdevice not in trustdevicelist.storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); + return RDB_ERROR; + } auto store = GetStore(storeMetaData); if (store == nullptr) { ZLOGE("autosync store null, storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); @@ -1210,44 +1263,60 @@ int RdbServiceImpl::DoAutoSync( } SyncParam syncParam = { 0, 0 }; DetailAsync async; - for (auto &table : tables) { - executors_->Execute([this, table, store, syncParam, async, devices, storeMetaData]() { - RdbQuery rdbQuery; - rdbQuery.MakeQuery(table); - std::vector onDevices = GetReuseDevice(devices, storeMetaData); - if (onDevices.empty()) { - ZLOGE("autosync ondevices null, storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); - return; - } - auto complete = [this, rdbQuery, store, syncParam, async]( - const auto &results) mutable { - auto ret = ProcessResult(results); - store->Sync(ret.first, rdbQuery, async, syncParam); - }; - if (IsNeedMetaSync(storeMetaData, onDevices)) { - MetaDataManager::GetInstance().Sync(onDevices, complete); - return; - } - (void)store->Sync(onDevices, rdbQuery, async, syncParam).first; + executors_->Execute([this, tables, store, syncParam, async, isSyncDevices, storeMetaData]() { + RdbQuery rdbQuery; + rdbQuery.MakeDeviceQuery(tables); + std::vector onDevices = GetReuseDevice(isSyncDevices, storeMetaData); + if (onDevices.empty()) { + ZLOGE("autosync device null, storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); return; - }); - } + } + auto complete = [this, rdbQuery, store, syncParam, async](const auto &results) mutable { + auto ret = ProcessResult(results); + store->Sync(ret.first, rdbQuery, async, syncParam); + }; + if (IsNeedMetaSync(storeMetaData, onDevices)) { + MetaDataManager::GetInstance().Sync(onDevices, complete); + return; + } + (void)store->Sync(onDevices, rdbQuery, async, syncParam).first; + return; + }); return RDB_OK; } int RdbServiceImpl::DoOnlineSync(const std::vector &devices, const Database &dataBase) { + if (devices.empty()) { + return RDB_ERROR; + } std::vector tableNames; for (auto &table : dataBase.tables) { if (!table.deviceSyncFields.empty()) { tableNames.push_back(table.name); } } - return DoAutoSync(devices, dataBase, tableNames); + StoreMetaData storeMetaData = GetStoreMetaData(dataBase); + DistributedData::AutoSyncDevicesInfo deviceInfos; + if(!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetAutoSyncDeviceKey(), deviceInfos, true)){ + return RDB_ERROR; + } + std::vector deviceIds = DmAdapter::ToUDID(devices); + if(deviceIds.empty()){ + return RDB_ERROR; + } + if (deviceInfos.udids.empty() || + std::find(deviceInfos.udids.begin(), deviceInfos.udids.end(), deviceIds[0]) == deviceInfos.udids.end()) { + return RDB_ERROR; + } + return DoAutoSync(devices, storeMetaData, tableNames); } int32_t RdbServiceImpl::OnReady(const std::string &device) { + if(device.empty()){ + return 0; + } int index = ALLOW_ONLINE_AUTO_SYNC; Database dataBase; std::string prefix = dataBase.GetPrefix({}); @@ -1414,13 +1483,19 @@ int RdbServiceImpl::DoDataChangeSync(const StoreInfo &storeInfo, const RdbChange tableNames.push_back(key); } } - if (MetaDataManager::GetInstance().LoadMeta(dataBase.GetKey(), dataBase, true)) { - std::vector devices = DmAdapter::ToUUID(DmAdapter::GetInstance().GetRemoteDevices()); - if ((dataBase.autoSyncType == AutoSyncType::SYNC_ON_CHANGE || - dataBase.autoSyncType == AutoSyncType::SYNC_ON_CHANGE_READY) && - !devices.empty()) { - return DoAutoSync(devices, dataBase, tableNames); - } + if (!MetaDataManager::GetInstance().LoadMeta(dataBase.GetKey(), dataBase, true)) { + return RDB_OK; + } + StoreMetaData storeMetaData = GetStoreMetaData(dataBase); + DistributedData::AutoSyncDevicesInfo deviceInfos; + if (!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetAutoSyncDeviceKey(), deviceInfos, true) || + deviceInfos.udids.empty()) { + ZLOGE("There is no autoSyncDevice, store:%{public}s.", Anonymous::Change(storeInfo.storeName).c_str()); + return RDB_ERROR; + } + if ((dataBase.autoSyncType == AutoSyncType::SYNC_ON_CHANGE || + dataBase.autoSyncType == AutoSyncType::SYNC_ON_CHANGE_READY)) { + return DoAutoSync(deviceInfos.udids, storeMetaData, tableNames); } return RDB_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index b7fe3c03c..fe36b10ee 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -178,12 +178,14 @@ private: const AsyncDetail &async); void DoCompensateSync(const DistributedData::BindEvent& event); + + void SaveAutoSyncDeviceId(const StoreMetaData &meta, const PredicatesMemo &predicates); int DoSync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async); int DoAutoSync( - const std::vector &devices, const Database &dataBase, std::vector tableNames); + const std::vector &devices, const StoreMetaData &storeMetaData, std::vector tables); std::vector GetReuseDevice(const std::vector &devices, const StoreMetaData &metaData); int DoOnlineSync(const std::vector &devices, const Database &dataBase); diff --git a/services/distributeddataservice/service/test/rdb_service_impl_test.cpp b/services/distributeddataservice/service/test/rdb_service_impl_test.cpp index abe248836..2524b7d86 100644 --- a/services/distributeddataservice/service/test/rdb_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/rdb_service_impl_test.cpp @@ -639,10 +639,10 @@ HWTEST_F(RdbServiceImplTest, DoAutoSync001, TestSize.Level0) { RdbServiceImpl service; std::vector devices = {"device1"}; - DistributedData::Database dataBase; + StoreMetaData meta; std::vector tables = {"table1"}; - auto result = service.DoAutoSync(devices, dataBase, tables); + auto result = service.DoAutoSync(devices, meta, tables); EXPECT_EQ(result, RDB_ERROR); } @@ -661,13 +661,14 @@ HWTEST_F(RdbServiceImplTest, DoAutoSync002, TestSize.Level0) metaMapping.devicePath = "path1"; EXPECT_EQ(MetaDataManager::GetInstance().SaveMeta(metaMapping.GetKey(), metaMapping, true), true); RdbServiceImpl service; + StoreMetaData meta; std::vector devices = {"device1"}; DistributedData::Database dataBase; std::vector tables = {"table1"}; - dataBase.bundleName = "bundleName"; - dataBase.name = "storeName"; - dataBase.user = "100"; - auto result = service.DoAutoSync(devices, dataBase, tables); + meta.bundleName = "bundleName"; + meta.storeId= "storeName"; + meta.user = "100"; + auto result = service.DoAutoSync(devices, meta, tables); EXPECT_EQ(result, RDB_ERROR); } -- Gitee From bc80e0b8aba91cc77ad3a85d0e2445727073189e Mon Sep 17 00:00:00 2001 From: zhangdi Date: Tue, 2 Sep 2025 17:29:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8C=87=E5=AE=9Adeviceid=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdi --- conf/config.json | 9 +- .../src/device_manager_adapter.cpp | 25 --- .../unittest/device_manager_adapter_test.cpp | 45 ---- .../communicator/device_manager_adapter.h | 2 - .../schema_helper/get_schema_helper.cpp | 2 +- .../app/src/kvstore_data_service.cpp | 2 +- .../distributeddataservice/framework/BUILD.gn | 3 +- .../include/metadata/special_channel_data.h | 32 +++ .../include/metadata/store_meta_data.h | 1 - .../include/metadata/store_meta_data_local.h | 12 - .../sync_mgr.h} | 83 +++---- .../special_channel_data.cpp} | 90 +++----- .../framework/metadata/store_meta_data.cpp | 5 - .../metadata/store_meta_data_local.cpp | 15 -- .../framework/store/auto_cache.cpp | 6 +- .../framework/sync_mgr/sync_mgr.cpp | 76 +++++++ .../framework/test/BUILD.gn | 6 +- .../test/device_sync_app_manager_test.cpp | 129 ----------- .../framework/test/sync_manager_test.cpp | 142 ++++++++++++ .../framework/utils/anonymous.cpp | 1 + .../framework/utils/time_utils.cpp | 2 +- .../service/bootstrap/include/bootstrap.h | 2 +- .../service/bootstrap/src/bootstrap.cpp | 14 +- .../service/config/BUILD.gn | 2 +- .../service/config/include/config_factory.h | 2 +- ...e_list_config.h => auto_sync_app_config.h} | 66 +++--- .../config/include/model/global_config.h | 4 +- .../service/config/src/config_factory.cpp | 4 +- ...st_config.cpp => auto_sync_app_config.cpp} | 81 +++---- .../config/src/model/global_config.cpp | 6 +- .../service/rdb/rdb_general_store.cpp | 2 +- .../service/rdb/rdb_service_impl.cpp | 206 ++++++++---------- .../service/rdb/rdb_service_impl.h | 11 +- .../service/test/BUILD.gn | 4 +- .../service/test/rdb_service_impl_test.cpp | 3 +- 35 files changed, 536 insertions(+), 559 deletions(-) create mode 100644 services/distributeddataservice/framework/include/metadata/special_channel_data.h rename services/distributeddataservice/framework/include/{device_sync_app/device_sync_app_manager.h => sync_mgr/sync_mgr.h} (56%) rename services/distributeddataservice/framework/{device_sync_app/device_sync_app_manager.cpp => metadata/special_channel_data.cpp} (38%) create mode 100644 services/distributeddataservice/framework/sync_mgr/sync_mgr.cpp delete mode 100644 services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp create mode 100644 services/distributeddataservice/framework/test/sync_manager_test.cpp rename services/distributeddataservice/service/config/include/model/{device_sync_app_white_list_config.h => auto_sync_app_config.h} (57%) rename services/distributeddataservice/service/config/src/model/{device_sync_app_white_list_config.cpp => auto_sync_app_config.cpp} (66%) diff --git a/conf/config.json b/conf/config.json index 69b0995a9..045d6840f 100644 --- a/conf/config.json +++ b/conf/config.json @@ -100,5 +100,12 @@ "schedularInternal" : 1800, "backupInternal" : 36000, "backupNumber" : 20 - } + }, + "autoSyncApps": [ + { + "appId": "", + "bundleName": "", + "version": 3 + } + ] } \ No newline at end of file diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 5ad57fb78..ea4915cf9 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -573,19 +573,6 @@ std::vector DeviceManagerAdapter::ToUUID(const std::vector DeviceManagerAdapter::ToUDID(const std::vector &devices) -{ - std::vector udids; - for (auto &device : devices) { - auto udid = DeviceManagerAdapter::GetInstance().ToUDID(device); - if (udid.empty()) { - continue; - } - udids.push_back(std::move(udid)); - } - return udids; -} - std::vector DeviceManagerAdapter::ToUUID(std::vector devices) { std::vector uuids; @@ -598,18 +585,6 @@ std::vector DeviceManagerAdapter::ToUUID(std::vector de return uuids; } -std::vector DeviceManagerAdapter::ToUDID(std::vector devices) -{ - std::vector udids; - for (auto &device : devices) { - if (device.udid.empty()) { - continue; - } - udids.push_back(std::move(device.udid)); - } - return udids; -} - std::string DeviceManagerAdapter::ToNetworkID(const std::string &id) { return GetDeviceInfoFromCache(id).networkId; diff --git a/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp b/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp index 855f2a5d4..f08d3153b 100644 --- a/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp +++ b/services/distributeddataservice/adapter/communicator/test/unittest/device_manager_adapter_test.cpp @@ -311,29 +311,6 @@ HWTEST_F(DeviceManagerAdapterTest, DeviceIdsToUUID, TestSize.Level0) } } -/** -* @tc.name: DeviceIdToUDID -* @tc.desc: transfer deviceIds to udid -* @tc.type: FUNC -* @tc.require: -* @tc.author: zd - */ -HWTEST_F(DeviceManagerAdapterTest, DeviceIdsToUDID, TestSize.Level0) -{ - std::vector devices; - devices.emplace_back(EMPTY_DEVICE_ID); - devices.emplace_back(INVALID_DEVICE_ID); - auto dvInfo = DeviceManagerAdapter::GetInstance().GetLocalDevice(); - devices.emplace_back(dvInfo.uuid); - devices.emplace_back(dvInfo.udid); - devices.emplace_back(dvInfo.networkId); - auto udids = DeviceManagerAdapter::GetInstance().ToUDID(devices); - EXPECT_EQ(udids.size(), LOCAL_DEVICE_ID_NUM); - for (const auto &udid : udids) { - EXPECT_EQ(udid, dvInfo.udid); - } -} - /** * @tc.name: DeviceIdToUUID * @tc.desc: transfer deviceIds to uuid @@ -356,28 +333,6 @@ HWTEST_F(DeviceManagerAdapterTest, DeviceIdToUUID, TestSize.Level0) EXPECT_EQ(uuids[1], dvInfo.uuid); } -/** -* @tc.name: DeviceInfosToUUID -* @tc.desc: transfer deviceIds to udid -* @tc.type: FUNC -* @tc.require: -* @tc.author: zd - */ -HWTEST_F(DeviceManagerAdapterTest, DeviceInfosToUUID, TestSize.Level0) -{ - std::vector devices; - DeviceInfo dvInfo; - devices.emplace_back(dvInfo); - dvInfo.udid = INVALID_DEVICE_ID; - devices.emplace_back(dvInfo); - dvInfo = DeviceManagerAdapter::GetInstance().GetLocalDevice(); - devices.emplace_back(dvInfo); - auto udids = DeviceManagerAdapter::GetInstance().ToUDID(devices); - EXPECT_EQ(udids.size(), LOCAL_UUID_NUM); - EXPECT_EQ(udids[0], INVALID_DEVICE_ID); - EXPECT_EQ(udids[1], dvInfo.udid); -} - /** * @tc.name: DeviceIdToNetworkId * @tc.desc: transfer deviceId to networkId, the deviceId is invalid diff --git a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h index 9a9bc67b9..575a2f393 100644 --- a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h +++ b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h @@ -67,9 +67,7 @@ public: std::string ToUUID(const std::string &id); std::string ToUDID(const std::string &id); static std::vector ToUUID(const std::vector &devices); - static std::vector ToUDID(const std::vector &devices); static std::vector ToUUID(std::vector devices); - static std::vector ToUDID(std::vector devices); std::string ToNetworkID(const std::string &id); void NotifyReadyEvent(const std::string &uuid); int32_t GetAuthType(const std::string& id); diff --git a/services/distributeddataservice/adapter/schema_helper/get_schema_helper.cpp b/services/distributeddataservice/adapter/schema_helper/get_schema_helper.cpp index 25ce22999..ce4064d70 100644 --- a/services/distributeddataservice/adapter/schema_helper/get_schema_helper.cpp +++ b/services/distributeddataservice/adapter/schema_helper/get_schema_helper.cpp @@ -16,7 +16,7 @@ #define LOG_TAG "SchemaHelper" #include "get_schema_helper.h" -#include "bundle_mgr_interface.h" +#include "bundlemgr/bundle_mgr_interface.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "log_print.h" diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index f7a34cad0..5c18907da 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -387,7 +387,7 @@ void KvStoreDataService::LoadConfigs() Bootstrap::GetInstance().LoadBackup(executors_); Bootstrap::GetInstance().LoadCloud(); Bootstrap::GetInstance().LoadAppIdMappings(); - Bootstrap::GetInstance().LoadDeviceSyncAppWhiteLists(); + Bootstrap::GetInstance().LoadAutoSyncApps(); Bootstrap::GetInstance().LoadSyncTrustedApp(); } diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index c02ccc84c..3f6eea650 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -71,7 +71,6 @@ ohos_shared_library("distributeddatasvcfwk") { "communication/connect_manager.cpp", "crypto/crypto_manager.cpp", "device_manager/device_manager_delegate.cpp", - "device_sync_app/device_sync_app_manager.cpp", "dfx/reporter.cpp", "directory/directory_manager.cpp", "dump/dump_manager.cpp", @@ -90,6 +89,7 @@ ohos_shared_library("distributeddatasvcfwk") { "metadata/meta_data_manager.cpp", "metadata/object_user_meta_data.cpp", "metadata/secret_key_meta_data.cpp", + "metadata/special_channel_data.cpp", "metadata/store_debug_info.cpp", "metadata/store_meta_data.cpp", "metadata/store_meta_data_local.cpp", @@ -103,6 +103,7 @@ ohos_shared_library("distributeddatasvcfwk") { "snapshot/bind_event.cpp", "snapshot/snapshot.cpp", "store/auto_cache.cpp", + "sync_mgr/sync_mgr.cpp", "thread/thread_manager.cpp", "utils/anonymous.cpp", "utils/base64_utils.cpp", diff --git a/services/distributeddataservice/framework/include/metadata/special_channel_data.h b/services/distributeddataservice/framework/include/metadata/special_channel_data.h new file mode 100644 index 000000000..c35290f0b --- /dev/null +++ b/services/distributeddataservice/framework/include/metadata/special_channel_data.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_SPECIAL_CHANNEL_DATA_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_SPECIAL_CHANNEL_DATA_H +#include + +#include "serializable/serializable.h" +namespace OHOS::DistributedData { +struct API_EXPORT SpecialChannelData final : public Serializable { + std::vector devices; + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + API_EXPORT static std::string GetKey(); + +private: + static constexpr const char *KEY_PREFIX = "SpecialChannel"; +}; +} // namespace OHOS::DistributedData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_SPECIAL_CHANNEL_DATA_H diff --git a/services/distributeddataservice/framework/include/metadata/store_meta_data.h b/services/distributeddataservice/framework/include/metadata/store_meta_data.h index a72bbd19a..201fccc01 100644 --- a/services/distributeddataservice/framework/include/metadata/store_meta_data.h +++ b/services/distributeddataservice/framework/include/metadata/store_meta_data.h @@ -91,7 +91,6 @@ struct API_EXPORT StoreMetaData : public Serializable { API_EXPORT virtual std::string GetStrategyKey() const; API_EXPORT virtual std::string GetBackupSecretKey() const; API_EXPORT virtual std::string GetAutoLaunchKey() const; - API_EXPORT virtual std::string GetAutoSyncDeviceKey() const; API_EXPORT virtual std::string GetDebugInfoKey() const; API_EXPORT virtual std::string GetDebugInfoKeyWithoutPath() const; API_EXPORT virtual std::string GetDfxInfoKey() const; diff --git a/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h b/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h index c3242140b..717b495f9 100644 --- a/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h +++ b/services/distributeddataservice/framework/include/metadata/store_meta_data_local.h @@ -81,17 +81,5 @@ struct API_EXPORT StoreDfxInfo final : public Serializable { private: static constexpr const char *KEY_PREFIX = "StoreDfxInfo"; }; - -struct API_EXPORT AutoSyncDevicesInfo final : public Serializable { - std::vector udids {}; - API_EXPORT AutoSyncDevicesInfo() = default; - API_EXPORT ~AutoSyncDevicesInfo() = default; - API_EXPORT static std::string GetKey(const std::initializer_list &fields); - bool Marshal(Serializable::json &node) const override; - bool Unmarshal(const Serializable::json &node) override; - -private: - static constexpr const char *KEY_PREFIX = "AutoSyncDevice"; -}; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_LOCAL_H diff --git a/services/distributeddataservice/framework/include/device_sync_app/device_sync_app_manager.h b/services/distributeddataservice/framework/include/sync_mgr/sync_mgr.h similarity index 56% rename from services/distributeddataservice/framework/include/device_sync_app/device_sync_app_manager.h rename to services/distributeddataservice/framework/include/sync_mgr/sync_mgr.h index d3116e318..5907e8594 100644 --- a/services/distributeddataservice/framework/include/device_sync_app/device_sync_app_manager.h +++ b/services/distributeddataservice/framework/include/sync_mgr/sync_mgr.h @@ -1,40 +1,45 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTEDDATAMGR_DEVICE_SYNC_APP_MANAGER_H -#define DISTRIBUTEDDATAMGR_DEVICE_SYNC_APP_MANAGER_H - -#include -#include -#include "visibility.h" -namespace OHOS::DistributedData { -class DeviceSyncAppManager { -public: - struct WhiteList { - std::string appId; - std::string bundleName; - uint32_t version; - }; - API_EXPORT static DeviceSyncAppManager &GetInstance(); - API_EXPORT void Initialize(const std::vector &lists); - API_EXPORT bool CheckVersion(const WhiteList &whiteList); - API_EXPORT bool CheckBundleName(const std::string &bundleName, const std::string &appId); - -private: - DeviceSyncAppManager(); - std::vector whiteLists_; -}; -} // namespace OHOS::DistributedData +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISTRIBUTEDDATAMGR_DEVICE_SYNC_APP_MANAGER_H +#define DISTRIBUTEDDATAMGR_DEVICE_SYNC_APP_MANAGER_H + +#include +#include +#include +#include "visibility.h" +namespace OHOS::DistributedData { +class SyncManager { +public: + struct AutoSyncInfo { + uint32_t version = 0; + std::string appId; + std::string bundleName; + std::vector storeIds; + }; + API_EXPORT static SyncManager &GetInstance(); + API_EXPORT void Initialize(const std::vector &autoSyncApps); + API_EXPORT void SetAutoSyncAppInfo(const AutoSyncInfo &autoSyncApp); + API_EXPORT bool IsAutoSyncApp(const std::string &bundleName, const std::string &appId); + API_EXPORT bool IsAutoSyncStore(const std::string &bundleName, const std::string &appId, + const std::string &store); + API_EXPORT bool NeedForceReplaceSchema(const AutoSyncInfo &autoSyncApp); + +private: + SyncManager(); + std::map autoSyncApps_; +}; +} // namespace OHOS::DistributedData #endif // DISTRIBUTEDDATAMGR_DEVICE_SYNC_APP_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/framework/device_sync_app/device_sync_app_manager.cpp b/services/distributeddataservice/framework/metadata/special_channel_data.cpp similarity index 38% rename from services/distributeddataservice/framework/device_sync_app/device_sync_app_manager.cpp rename to services/distributeddataservice/framework/metadata/special_channel_data.cpp index b7a2e671a..6c8866008 100644 --- a/services/distributeddataservice/framework/device_sync_app/device_sync_app_manager.cpp +++ b/services/distributeddataservice/framework/metadata/special_channel_data.cpp @@ -1,55 +1,35 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define LOG_TAG "DeviceSyncAppManager" -#include "device_sync_app/device_sync_app_manager.h" - -namespace OHOS::DistributedData { -DeviceSyncAppManager::DeviceSyncAppManager() -{ -} - -DeviceSyncAppManager &DeviceSyncAppManager::GetInstance() -{ - static DeviceSyncAppManager instance; - return instance; -} - -void DeviceSyncAppManager::Initialize(const std::vector &lists) -{ - for (const auto &list : lists) { - whiteLists_.push_back(list); - } -} - -bool DeviceSyncAppManager::CheckVersion(const WhiteList &whiteList) -{ - for (const auto &info : whiteLists_) { - if (info.appId == whiteList.appId && (info.bundleName == whiteList.bundleName) && - (info.version == whiteList.version)) { - return true; - } - } - return false; -} -bool DeviceSyncAppManager::CheckBundleName(const std::string &bundleName, const std::string &appId) -{ - for (const auto &info : whiteLists_) { - if (info.appId == appId && (info.bundleName == bundleName)) { - return true; - } - } - return false; -} -} // namespace OHOS::DistributedData \ No newline at end of file +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "metadata/special_channel_data.h" +#include "utils/constant.h" +namespace OHOS::DistributedData { +bool SpecialChannelData::Marshal(json &node) const +{ + SetValue(node[GET_NAME(devices)], devices); + return true; +} + +bool SpecialChannelData::Unmarshal(const json &node) +{ + GetValue(node, GET_NAME(devices), devices); + return true; +} + +std::string SpecialChannelData::GetKey() +{ + return std::string(KEY_PREFIX) + Constant::KEY_SEPARATOR; +} +} \ No newline at end of file diff --git a/services/distributeddataservice/framework/metadata/store_meta_data.cpp b/services/distributeddataservice/framework/metadata/store_meta_data.cpp index 6255d384e..3dba8c533 100644 --- a/services/distributeddataservice/framework/metadata/store_meta_data.cpp +++ b/services/distributeddataservice/framework/metadata/store_meta_data.cpp @@ -196,11 +196,6 @@ std::string StoreMetaData::GetAutoLaunchKey() const return AutoLaunchMetaData::GetPrefix({ deviceId, user, "default", bundleName, storeId }); } -std::string StoreMetaData::GetAutoSyncDeviceKey() const -{ - return AutoSyncDevicesInfo::GetKey({ deviceId, user, "default", bundleName, storeId, dataDir }); -} - std::string StoreMetaData::GetDebugInfoKey() const { return StoreDebugInfo::GetPrefix( diff --git a/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp b/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp index 8fa74a287..19aea85c5 100644 --- a/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp +++ b/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp @@ -155,20 +155,5 @@ bool StoreDfxInfo::Unmarshal(const json &node) GetValue(node, GET_NAME(lastOpenTime), lastOpenTime); return true; } -std::string AutoSyncDevicesInfo::GetKey(const std::initializer_list &fields) -{ - return Constant::Join(AutoSyncDevicesInfo::KEY_PREFIX, Constant::KEY_SEPARATOR, fields); -} -bool AutoSyncDevicesInfo::Marshal(json &node) const -{ - SetValue(node[GET_NAME(udids)], udids); - return true; -} - -bool AutoSyncDevicesInfo::Unmarshal(const json &node) -{ - GetValue(node, GET_NAME(udids), udids); - return true; -} } // namespace DistributedData } // namespace OHOS diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index 4253619e5..d65c9dee5 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -63,10 +63,10 @@ AutoCache::~AutoCache() std::string AutoCache::GenerateKey(const std::string &path, const std::string &storeId) const { - std::string key = ""; - if (path.empty() || storeId.empty()) { - return key; + if (path.empty()) { + return storeId; } + std::string key = ""; return key.append(path).append(KEY_SEPARATOR).append(storeId); } diff --git a/services/distributeddataservice/framework/sync_mgr/sync_mgr.cpp b/services/distributeddataservice/framework/sync_mgr/sync_mgr.cpp new file mode 100644 index 000000000..9b7d91f0f --- /dev/null +++ b/services/distributeddataservice/framework/sync_mgr/sync_mgr.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "SyncManager" +#include "sync_mgr/sync_mgr.h" + +namespace OHOS::DistributedData { +SyncManager::SyncManager() +{ +} + +SyncManager &SyncManager::GetInstance() +{ + static SyncManager instance; + return instance; +} + +void SyncManager::Initialize(const std::vector &autoSyncApps) +{ + for (const auto &app : autoSyncApps) { + SetAutoSyncAppInfo(app); + } +} + +void SyncManager::SetAutoSyncAppInfo(const AutoSyncInfo &autoSyncApp) +{ + autoSyncApps_[autoSyncApp.bundleName] = autoSyncApp; +} + +bool SyncManager::IsAutoSyncApp(const std::string &bundleName, const std::string &appId) +{ + auto it = autoSyncApps_.find(bundleName); + if (it == autoSyncApps_.end()) { + return false; + } + return it->second.appId == appId; +} + +bool SyncManager::IsAutoSyncStore(const std::string &bundleName, const std::string &appId, const std::string &store) +{ + auto it = autoSyncApps_.find(bundleName); + if (it == autoSyncApps_.end()) { + return false; + } + if (it->second.appId != appId) { + return false; + } + + for (auto &storeId : it->second.storeIds) { + if (storeId == store) { + return true; + } + } + return false; +} + +bool SyncManager::NeedForceReplaceSchema(const AutoSyncInfo &autoSyncApp) +{ + auto it = autoSyncApps_.find(autoSyncApp.bundleName); + if (it == autoSyncApps_.end()) { + return false; + } + return ((it->second.version == autoSyncApp.version) && (it->second.appId == autoSyncApp.appId)); +} +} // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index 37a5bafdd..d0c27991f 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -400,9 +400,9 @@ ohos_unittest("ConnectManagerTest") { external_deps = [ "kv_store:datamgr_common" ] } -ohos_unittest("DeviceSyncAppManagerTest") { +ohos_unittest("SyncManagerTest") { module_out_path = module_output_path - sources = [ "device_sync_app_manager_test.cpp" ] + sources = [ "sync_manager_test.cpp" ] configs = [ ":module_private_config" ] deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] external_deps = [ "kv_store:datamgr_common" ] @@ -423,7 +423,6 @@ group("unittest") { ":ConnectManagerTest", ":ConstantTest", ":CryptoTest", - ":DeviceSyncAppManagerTest", ":EventCenterTest", ":EventTest", ":FeatureTest", @@ -436,6 +435,7 @@ group("unittest") { ":StoreMetaDataLocalTest", ":StoreTest", ":SubscriptionTest", + ":SyncManagerTest", ] } ############################################################################### diff --git a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp deleted file mode 100644 index a4f375f60..000000000 --- a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "device_sync_app/device_sync_app_manager.h" -#include - -using namespace testing::ext; -using namespace OHOS::DistributedData; - -namespace OHOS::Test { -class DeviceSyncAppManagerTest : public testing::Test { -public: - void SetUp() - { - whiteList1 = {"appId1", "bundleName1", 1}; - whiteList2 = {"appId2", "bundleName2", 2}; - whiteList3 = {"appId3", "bundleName3", 3}; - - std::vector lists = {whiteList1, whiteList2, whiteList3}; - DeviceSyncAppManager::GetInstance().Initialize(lists); - } - - DeviceSyncAppManager::WhiteList whiteList1; - DeviceSyncAppManager::WhiteList whiteList2; - DeviceSyncAppManager::WhiteList whiteList3; -}; - -/** -* @tc.name: Check001 -* @tc.desc: Checks that the given WhiteList object exists in whiteLists_ list. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check001, TestSize.Level1) -{ - DeviceSyncAppManager::WhiteList whiteList = {"appId1", "bundleName1", 1}; - bool result = DeviceSyncAppManager::GetInstance().CheckVersion(whiteList); - EXPECT_TRUE(result); -} - -/** -* @tc.name: Check002 -* @tc.desc: Check that the given appId object does not match. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check002, TestSize.Level1) -{ - DeviceSyncAppManager::WhiteList testList = {"appId2", "bundleName1", 1}; - bool result = DeviceSyncAppManager::GetInstance().CheckVersion(testList); - EXPECT_FALSE(result); -} - -/** -* @tc.name: Check003 -* @tc.desc: Check that the given bundleName object does not match. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check003, TestSize.Level1) -{ - DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName2", 1}; - bool result = DeviceSyncAppManager::GetInstance().CheckVersion(testList); - EXPECT_FALSE(result); -} - -/** -* @tc.name: Check004 -* @tc.desc: Check that the given version object does not match. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check004, TestSize.Level1) -{ - DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName1", 2}; - bool result = DeviceSyncAppManager::GetInstance().CheckVersion(testList); - EXPECT_FALSE(result); -} - -/** -* @tc.name: Check005 -* @tc.desc: Checks that the given WhiteList object does not exist in whiteLists_ list. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check005, TestSize.Level1) -{ - DeviceSyncAppManager::WhiteList whiteList = {"appId4", "bundleName4", 4}; - bool result = DeviceSyncAppManager::GetInstance().CheckVersion(whiteList); - EXPECT_FALSE(result); -} - -/** -* @tc.name: Check006 -* @tc.desc: Checks that the given WhiteList object does not exist in whiteLists_ list. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check006, TestSize.Level1) -{ - bool result = DeviceSyncAppManager::GetInstance().CheckBundleName("bundleName4", "appId4"); - EXPECT_FALSE(result); -} -/** -* @tc.name: Check007 -* @tc.desc: Check that the given bundleName object does not match. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check007, TestSize.Level1) -{ - bool result = DeviceSyncAppManager::GetInstance().CheckBundleName("bundleName2", "appId1"); - EXPECT_FALSE(result); -} -/** -* @tc.name: Check008 -* @tc.desc: Checks that the given WhiteList object exists in whiteLists_ list. -* @tc.type: FUNC -*/ -HWTEST_F(DeviceSyncAppManagerTest, Check008, TestSize.Level1) -{ - bool result = DeviceSyncAppManager::GetInstance().CheckBundleName("bundleName1", "appId1"); - EXPECT_TRUE(result); -} -} // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/sync_manager_test.cpp b/services/distributeddataservice/framework/test/sync_manager_test.cpp new file mode 100644 index 000000000..36c1cb181 --- /dev/null +++ b/services/distributeddataservice/framework/test/sync_manager_test.cpp @@ -0,0 +1,142 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#include + +#include "sync_mgr/sync_mgr.h" + +using namespace testing::ext; +using namespace OHOS::DistributedData; + +namespace OHOS::Test { +class SyncManagerTest : public testing::Test { +public: + void SetUp() + { + SyncManager::AutoSyncInfo syncInfo1 = { 1, "appId1", "bundleName1" }; + SyncManager::AutoSyncInfo syncInfo2 = { 2, "appId2", "bundleName2" }; + SyncManager::AutoSyncInfo syncInfo3 = { 3, "appId3", "bundleName3" }; + SyncManager::AutoSyncInfo syncInfo4 = { 3, "appId13", "bundleName13", { "storeId1", "storeId2" } }; + SyncManager::GetInstance().Initialize({ syncInfo1, syncInfo2, syncInfo3, syncInfo4 }); + } +}; + +/** +* @tc.name: NeedForceReplaceSchema001 +* @tc.desc: the app need force replace the sync schema. +* @tc.type: FUNC +*/ +HWTEST_F(SyncManagerTest, NeedForceReplaceSchema001, TestSize.Level1) +{ + SyncManager::AutoSyncInfo autoSyncInfo = { 1, "appId1", "bundleName1" }; + bool result = SyncManager::GetInstance().NeedForceReplaceSchema(autoSyncInfo); + EXPECT_TRUE(result); +} + +/** +* @tc.name: NeedForceReplaceSchema002 +* @tc.desc: the app need not force replace the sync schema. +* @tc.type: FUNC +*/ +HWTEST_F(SyncManagerTest, NeedForceReplaceSchema002, TestSize.Level1) +{ + SyncManager::AutoSyncInfo autoSyncInfo = { 1, "appId2", "bundleName1" }; + bool result = SyncManager::GetInstance().NeedForceReplaceSchema(autoSyncInfo); + EXPECT_FALSE(result); +} + +/** +* @tc.name: NeedForceReplaceSchema003 +* @tc.desc: the app need not force replace the sync schema. +* @tc.type: FUNC +*/ +HWTEST_F(SyncManagerTest, NeedForceReplaceSchema003, TestSize.Level1) +{ + SyncManager::AutoSyncInfo autoSyncInfo = { 1, "appId1", "bundleName2" }; + bool result = SyncManager::GetInstance().NeedForceReplaceSchema(autoSyncInfo); + EXPECT_FALSE(result); +} + +/** +* @tc.name: NeedForceReplaceSchema004 +* @tc.desc: the app need not force replace the sync schema. +* @tc.type: FUNC +*/ +HWTEST_F(SyncManagerTest, NeedForceReplaceSchema004, TestSize.Level1) +{ + SyncManager::AutoSyncInfo autoSyncInfo = { 2, "appId1", "bundleName2" }; + bool result = SyncManager::GetInstance().NeedForceReplaceSchema(autoSyncInfo); + EXPECT_FALSE(result); +} + +/** +* @tc.name: NeedForceReplaceSchema005 +* @tc.desc: the app need not force replace the sync schema. +* @tc.type: FUNC +*/ +HWTEST_F(SyncManagerTest, NeedForceReplaceSchema005, TestSize.Level1) +{ + SyncManager::AutoSyncInfo autoSyncInfo = { 4, "appId4", "bundleName4" }; + bool result = SyncManager::GetInstance().NeedForceReplaceSchema(autoSyncInfo); + EXPECT_FALSE(result); +} + +/** +* @tc.name: IsAutoSyncApp001 +* @tc.desc: the app is auto sync system app. +* @tc.type: FUNC +*/ +HWTEST_F(SyncManagerTest, IsAutoSyncApp001, TestSize.Level1) +{ + // valid bundleName and valid appid + bool autoSync = SyncManager::GetInstance().IsAutoSyncApp("bundleName2", "appId2"); + EXPECT_TRUE(autoSync); + // invalid bundleName and invalid appid + autoSync = SyncManager::GetInstance().IsAutoSyncApp("bundleName4", "appId4"); + EXPECT_FALSE(autoSync); + // valid bundleName and invalid appid + autoSync = SyncManager::GetInstance().IsAutoSyncApp("bundleName1", "appId5"); + EXPECT_FALSE(autoSync); +} + +/** +* @tc.name: IsAutoSyncStore001 +* @tc.desc: the bundleName is equal to the sync system app, but the appId is another app. +* @tc.type: FUNC +*/ +HWTEST_F(SyncManagerTest, IsAutoSyncStore001, TestSize.Level1) +{ + // valid bundleName, valid appid, valid storeId, + bool autoSyncStore = SyncManager::GetInstance().IsAutoSyncStore("bundleName13", "appId13", "storeId1"); + EXPECT_TRUE(autoSyncStore); + // valid bundleName, valid appid, another valid storeId, + autoSyncStore = SyncManager::GetInstance().IsAutoSyncStore("bundleName13", "appId13", "storeId2"); + EXPECT_TRUE(autoSyncStore); + // valid bundleName, valid appid, invalid storeId, + autoSyncStore = SyncManager::GetInstance().IsAutoSyncStore("bundleName13", "appId13", "storeId3"); + EXPECT_FALSE(autoSyncStore); + // invalid bundleName, valid appid, invalid storeId, + autoSyncStore = SyncManager::GetInstance().IsAutoSyncStore("bundleName1", "appId13", "storeId3"); + EXPECT_FALSE(autoSyncStore); + // invalid bundleName, invalid appid, invalid storeId, + autoSyncStore = SyncManager::GetInstance().IsAutoSyncStore("bundleName1", "appId1", "storeId3"); + EXPECT_FALSE(autoSyncStore); + // invalid bundleName, invalid appid, valid storeId, + autoSyncStore = SyncManager::GetInstance().IsAutoSyncStore("bundleName1", "appId1", "storeId1"); + EXPECT_FALSE(autoSyncStore); + // invalid bundleName, valid appid, valid storeId, + autoSyncStore = SyncManager::GetInstance().IsAutoSyncStore("bundleName1", "appId13", "storeId1"); + EXPECT_FALSE(autoSyncStore); +} +} // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/framework/utils/anonymous.cpp b/services/distributeddataservice/framework/utils/anonymous.cpp index 2cf8434a1..de87b5b24 100644 --- a/services/distributeddataservice/framework/utils/anonymous.cpp +++ b/services/distributeddataservice/framework/utils/anonymous.cpp @@ -14,6 +14,7 @@ */ #include "utils/anonymous.h" +#include namespace OHOS { namespace DistributedData { diff --git a/services/distributeddataservice/framework/utils/time_utils.cpp b/services/distributeddataservice/framework/utils/time_utils.cpp index a85d147f4..e133f6f20 100644 --- a/services/distributeddataservice/framework/utils/time_utils.cpp +++ b/services/distributeddataservice/framework/utils/time_utils.cpp @@ -14,7 +14,7 @@ */ #define LOG_TAG "TimeUtils" -#include "time_utils.h" +#include "utils/time_utils.h" #include #include diff --git a/services/distributeddataservice/service/bootstrap/include/bootstrap.h b/services/distributeddataservice/service/bootstrap/include/bootstrap.h index eaf767244..eb94790ba 100644 --- a/services/distributeddataservice/service/bootstrap/include/bootstrap.h +++ b/services/distributeddataservice/service/bootstrap/include/bootstrap.h @@ -33,7 +33,7 @@ public: API_EXPORT void LoadBackup(std::shared_ptr executors); API_EXPORT void LoadAppIdMappings(); API_EXPORT void LoadThread(); - API_EXPORT void LoadDeviceSyncAppWhiteLists(); + API_EXPORT void LoadAutoSyncApps(); API_EXPORT void LoadSyncTrustedApp(); private: static constexpr const char *DEFAULT_LABEL = "distributeddata"; diff --git a/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp b/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp index 106363c18..a241ef80b 100644 --- a/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp +++ b/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp @@ -24,9 +24,9 @@ #include "checker/checker_manager.h" #include "cloud/cloud_config_manager.h" #include "config_factory.h" -#include "device_sync_app/device_sync_app_manager.h" #include "directory/directory_manager.h" #include "log_print.h" +#include "sync_mgr/sync_mgr.h" #include "thread/thread_manager.h" namespace OHOS { namespace DistributedData { @@ -199,17 +199,15 @@ void Bootstrap::LoadThread() ThreadManager::GetInstance().Initialize(config->minThreadNum, config->maxThreadNum, config->ipcThreadNum); } -void Bootstrap::LoadDeviceSyncAppWhiteLists() +void Bootstrap::LoadAutoSyncApps() { - auto *deviceSyncAppWhiteLists = ConfigFactory::GetInstance().GetDeviceSyncAppWhiteListConfig(); - if (deviceSyncAppWhiteLists == nullptr) { + auto *autoSyncApps = ConfigFactory::GetInstance().GetAutoSyncAppConfig(); + if (autoSyncApps == nullptr) { return; } - std::vector infos; - for (const auto &info : deviceSyncAppWhiteLists->whiteLists) { - infos.push_back({ info.appId, info.bundleName, info.version }); + for (auto &autoSyncApp : *autoSyncApps) { + SyncManager::GetInstance().SetAutoSyncAppInfo(autoSyncApp); } - DeviceSyncAppManager::GetInstance().Initialize(infos); } void Bootstrap::LoadSyncTrustedApp() diff --git a/services/distributeddataservice/service/config/BUILD.gn b/services/distributeddataservice/service/config/BUILD.gn index 99550fc4a..3b3684099 100644 --- a/services/distributeddataservice/service/config/BUILD.gn +++ b/services/distributeddataservice/service/config/BUILD.gn @@ -26,12 +26,12 @@ ohos_source_set("distributeddata_config") { "src/config_factory.cpp", "src/model/app_access_check_config.cpp", "src/model/app_id_mapping_config.cpp", + "src/model/auto_sync_app_config.cpp", "src/model/backup_config.cpp", "src/model/checker_config.cpp", "src/model/cloud_config.cpp", "src/model/component_config.cpp", "src/model/datashare_config.cpp", - "src/model/device_sync_app_white_list_config.cpp", "src/model/directory_config.cpp", "src/model/global_config.cpp", "src/model/network_config.cpp", diff --git a/services/distributeddataservice/service/config/include/config_factory.h b/services/distributeddataservice/service/config/include/config_factory.h index 87fcb7e69..448eec27a 100644 --- a/services/distributeddataservice/service/config/include/config_factory.h +++ b/services/distributeddataservice/service/config/include/config_factory.h @@ -34,7 +34,7 @@ public: API_EXPORT std::vector *GetAppIdMappingConfig(); API_EXPORT ThreadConfig *GetThreadConfig(); API_EXPORT DataShareConfig *GetDataShareConfig(); - API_EXPORT DeviceSyncAppWhiteListConfig *GetDeviceSyncAppWhiteListConfig(); + API_EXPORT std::vector *GetAutoSyncAppConfig(); API_EXPORT AppAccessCheckConfig *GetSyncAppsConfig(); private: static constexpr const char *CONF_PATH = "/system/etc/distributeddata/conf"; diff --git a/services/distributeddataservice/service/config/include/model/device_sync_app_white_list_config.h b/services/distributeddataservice/service/config/include/model/auto_sync_app_config.h similarity index 57% rename from services/distributeddataservice/service/config/include/model/device_sync_app_white_list_config.h rename to services/distributeddataservice/service/config/include/model/auto_sync_app_config.h index 03729b9c7..59531c442 100644 --- a/services/distributeddataservice/service/config/include/model/device_sync_app_white_list_config.h +++ b/services/distributeddataservice/service/config/include/model/auto_sync_app_config.h @@ -1,37 +1,29 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_DEVICE_SYNC_APP_WHITE_LIST_CONFIG_H -#define OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_DEVICE_SYNC_APP_WHITE_LIST_CONFIG_H - -#include "serializable/serializable.h" -namespace OHOS { -namespace DistributedData { -class DeviceSyncAppWhiteListConfig final : public Serializable { -public: - struct WhiteList final : public Serializable { - std::string appId; - std::string bundleName; - uint32_t version; - bool Marshal(json &node) const override; - bool Unmarshal(const json &node) override; - }; - bool Marshal(json &node) const override; - bool Unmarshal(const json &node) override; - - std::vector whiteLists; -}; -} // namespace DistributedData -} // namespace OHOS -#endif //OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_DEVICE_SYNC_APP_WHITE_LIST_CONFIG_H +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_AUTO_SYNC_APP_CONFIG_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_AUTO_SYNC_APP_CONFIG_H + +#include "sync_mgr/sync_mgr.h" +#include "serializable/serializable.h" +namespace OHOS { +namespace DistributedData { +struct AutoSyncAppConfig final : public Serializable, public SyncManager::AutoSyncInfo { +public: + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; +}; +} // namespace DistributedData +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_AUTO_SYNC_APP_CONFIG_H diff --git a/services/distributeddataservice/service/config/include/model/global_config.h b/services/distributeddataservice/service/config/include/model/global_config.h index 4d7a9e531..da3c907d4 100644 --- a/services/distributeddataservice/service/config/include/model/global_config.h +++ b/services/distributeddataservice/service/config/include/model/global_config.h @@ -17,6 +17,7 @@ #define OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_GLOBAL_CONFIG_H #include "model/app_access_check_config.h" #include "model/app_id_mapping_config.h" +#include "model/auto_sync_app_config.h" #include "model/backup_config.h" #include "model/checker_config.h" #include "model/cloud_config.h" @@ -25,7 +26,6 @@ #include "model/directory_config.h" #include "model/network_config.h" #include "model/thread_config.h" -#include "model/device_sync_app_white_list_config.h" #include "serializable/serializable.h" namespace OHOS { namespace DistributedData { @@ -44,7 +44,7 @@ public: std::vector *appIdMapping = nullptr; ThreadConfig *thread = nullptr; DataShareConfig *dataShare = nullptr; - DeviceSyncAppWhiteListConfig *deviceSyncAppWhiteList = nullptr; + std::vector *autoSyncApps = nullptr; AppAccessCheckConfig *syncAppList = nullptr; ~GlobalConfig(); bool Marshal(json &node) const override; diff --git a/services/distributeddataservice/service/config/src/config_factory.cpp b/services/distributeddataservice/service/config/src/config_factory.cpp index 0f91cb6aa..9c7c7cdd3 100644 --- a/services/distributeddataservice/service/config/src/config_factory.cpp +++ b/services/distributeddataservice/service/config/src/config_factory.cpp @@ -97,9 +97,9 @@ DataShareConfig *ConfigFactory::GetDataShareConfig() return config_.dataShare; } -DeviceSyncAppWhiteListConfig *ConfigFactory::GetDeviceSyncAppWhiteListConfig() +std::vector *ConfigFactory::GetAutoSyncAppConfig() { - return config_.deviceSyncAppWhiteList; + return config_.autoSyncApps; } AppAccessCheckConfig *ConfigFactory::GetSyncAppsConfig() diff --git a/services/distributeddataservice/service/config/src/model/device_sync_app_white_list_config.cpp b/services/distributeddataservice/service/config/src/model/auto_sync_app_config.cpp similarity index 66% rename from services/distributeddataservice/service/config/src/model/device_sync_app_white_list_config.cpp rename to services/distributeddataservice/service/config/src/model/auto_sync_app_config.cpp index 594d3f2ae..17d627ddb 100644 --- a/services/distributeddataservice/service/config/src/model/device_sync_app_white_list_config.cpp +++ b/services/distributeddataservice/service/config/src/model/auto_sync_app_config.cpp @@ -1,45 +1,36 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "model/device_sync_app_white_list_config.h" -namespace OHOS { -namespace DistributedData { -bool DeviceSyncAppWhiteListConfig::Marshal(Serializable::json &node) const -{ - SetValue(node[GET_NAME(whiteLists)], whiteLists); - return true; -} -bool DeviceSyncAppWhiteListConfig::Unmarshal(const Serializable::json &node) -{ - GetValue(node, GET_NAME(whiteLists), whiteLists); - return true; -} - -bool DeviceSyncAppWhiteListConfig::WhiteList::Marshal(Serializable::json &node) const -{ - SetValue(node[GET_NAME(appId)], appId); - SetValue(node[GET_NAME(bundleName)], bundleName); - SetValue(node[GET_NAME(version)], version); - return true; -} -bool DeviceSyncAppWhiteListConfig::WhiteList::Unmarshal(const Serializable::json &node) -{ - GetValue(node, GET_NAME(appId), appId); - GetValue(node, GET_NAME(bundleName), bundleName); - GetValue(node, GET_NAME(version), version); - return true; -} -} // namespace DistributedData -} // namespace OHOS +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "model/auto_sync_app_config.h" +namespace OHOS { +namespace DistributedData { +bool AutoSyncAppConfig::Marshal(Serializable::json &node) const +{ + SetValue(node[GET_NAME(version)], version); + SetValue(node[GET_NAME(appId)], appId); + SetValue(node[GET_NAME(bundleName)], bundleName); + SetValue(node[GET_NAME(storeIds)], storeIds); + return true; +} +bool AutoSyncAppConfig::Unmarshal(const Serializable::json &node) +{ + GetValue(node, GET_NAME(version), version); + GetValue(node, GET_NAME(appId), appId); + GetValue(node, GET_NAME(bundleName), bundleName); + GetValue(node, GET_NAME(storeIds), storeIds); + return true; +} +} // namespace DistributedData +} // namespace OHOS diff --git a/services/distributeddataservice/service/config/src/model/global_config.cpp b/services/distributeddataservice/service/config/src/model/global_config.cpp index 51b12d61e..09891bc37 100644 --- a/services/distributeddataservice/service/config/src/model/global_config.cpp +++ b/services/distributeddataservice/service/config/src/model/global_config.cpp @@ -31,7 +31,7 @@ bool GlobalConfig::Marshal(json &node) const SetValue(node[GET_NAME(appIdMapping)], appIdMapping); SetValue(node[GET_NAME(thread)], thread); SetValue(node[GET_NAME(dataShare)], dataShare); - SetValue(node[GET_NAME(deviceSyncAppWhiteList)], deviceSyncAppWhiteList); + SetValue(node[GET_NAME(autoSyncApps)], autoSyncApps); SetValue(node[GET_NAME(syncAppList)], syncAppList); return true; } @@ -51,7 +51,7 @@ bool GlobalConfig::Unmarshal(const json &node) GetValue(node, GET_NAME(appIdMapping), appIdMapping); GetValue(node, GET_NAME(thread), thread); GetValue(node, GET_NAME(dataShare), dataShare); - GetValue(node, GET_NAME(deviceSyncAppWhiteList), deviceSyncAppWhiteList); + GetValue(node, GET_NAME(autoSyncApps), autoSyncApps); GetValue(node, GET_NAME(syncAppList), syncAppList); return true; } @@ -67,7 +67,7 @@ GlobalConfig::~GlobalConfig() delete appIdMapping; delete thread; delete dataShare; - delete deviceSyncAppWhiteList; + delete autoSyncApps; delete syncAppList; } } // namespace DistributedData diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index cd4745a7d..b4963d2cd 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -961,7 +961,7 @@ int32_t RdbGeneralStore::SetDistributedTables(const std::vector &ta } auto [exist, database] = GetDistributedSchema(observer_.meta_); if (exist && type == DistributedTableType::DISTRIBUTED_DEVICE) { - auto force = DeviceSyncAppManager::GetInstance().CheckVersion( + auto force = SyncManager::GetInstance().NeedForceReplaceSchema( {observer_.meta_.appId, observer_.meta_.bundleName, database.version}); delegate_->SetDistributedSchema(GetGaussDistributedSchema(database), force); } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 2a4ec5713..ac57ffc24 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -28,7 +28,6 @@ #include "cloud/schema_meta.h" #include "communicator/device_manager_adapter.h" #include "device_matrix.h" -#include "device_sync_app/device_sync_app_manager.h" #include "directory/directory_manager.h" #include "dump/dump_manager.h" #include "eventcenter/event_center.h" @@ -38,6 +37,7 @@ #include "metadata/auto_launch_meta_data.h" #include "metadata/capability_meta_data.h" #include "metadata/meta_data_manager.h" +#include "metadata/special_channel_data.h" #include "metadata/store_debug_info.h" #include "metadata/store_meta_data.h" #include "metadata/store_meta_data_local.h" @@ -50,11 +50,13 @@ #include "rdb_schema_config.h" #include "rdb_watcher.h" #include "store/general_store.h" +#include "sync_mgr/sync_mgr.h" #include "tokenid_kit.h" #include "types_export.h" #include "utils/anonymous.h" #include "utils/constant.h" #include "utils/converter.h" +#include "utils/crypto.h" #include "xcollie.h" using OHOS::DistributedData::AccountDelegate; using OHOS::DistributedData::Anonymous; @@ -104,7 +106,7 @@ RdbServiceImpl::RdbServiceImpl() { ZLOGI("construct"); DistributedDB::RelationalStoreManager::SetAutoLaunchRequestCallback( - [this](const std::string& identifier, DistributedDB::AutoLaunchParam ¶m) { + [this](const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) { return ResolveAutoLaunch(identifier, param); }); RegisterEvent(); @@ -121,7 +123,7 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib return false; } ZLOGI("size=%{public}d", static_cast(entries.size())); - for (const auto& entry : entries) { + for (const auto &entry : entries) { if (entry.storeType != RDB_DEVICE_COLLABORATION) { continue; } @@ -209,7 +211,7 @@ int32_t RdbServiceImpl::OnFeatureExit(pid_t uid, pid_t pid, uint32_t tokenId, co return E_OK; } -bool RdbServiceImpl::IsValidAccess(const std::string& bundleName, const std::string& storeName) +bool RdbServiceImpl::IsValidAccess(const std::string &bundleName, const std::string &storeName) { CheckerManager::StoreInfo storeInfo; storeInfo.uid = IPCSkeleton::GetCallingUid(); @@ -292,12 +294,12 @@ void RdbServiceImpl::UpdateMeta(const StoreMetaData &meta, const StoreMetaData & syncMeta.isEncrypt, meta.isEncrypt, syncMeta.area, meta.area); MetaDataManager::GetInstance().SaveMeta(meta.GetKeyWithoutPath(), localMeta); } - bool isAutoSync = DeviceSyncAppManager::GetInstance().CheckBundleName(meta.bundleName, meta.appId); + bool isAutoSync = SyncManager::GetInstance().IsAutoSyncApp(meta.bundleName, meta.appId); Database dataBase; if (isAutoSync && RdbSchemaConfig::GetDistributedSchema(localMeta, dataBase) && !dataBase.name.empty() && !dataBase.bundleName.empty()) { MetaDataManager::GetInstance().SaveMeta(dataBase.GetKey(), dataBase, true); - store->SetConfig({false, GeneralStore::DistributedTableMode::COLLABORATION}); + store->SetConfig({ false, GeneralStore::DistributedTableMode::COLLABORATION }); } } @@ -319,7 +321,7 @@ int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const bool isCreatedLocal = MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), localMeta, true); if (!isCreatedLocal) { ZLOGE("no meta. bundleName:%{public}s, storeName:%{public}s. GetStore failed", param.bundleName_.c_str(), - Anonymous::Change(param.storeName_).c_str()); + Anonymous::Change(param.storeName_).c_str()); return RDB_ERROR; } auto store = GetStore(meta); @@ -335,9 +337,9 @@ int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const } else if (type == DistributedTableType::DISTRIBUTED_CLOUD) { if (localMeta.asyncDownloadAsset != param.asyncDownloadAsset_ || localMeta.enableCloud != param.enableCloud_) { ZLOGI("update meta, bundleName:%{public}s, storeName:%{public}s, asyncDownloadAsset? [%{public}d -> " - "%{public}d],enableCloud? [%{public}d -> %{public}d]", param.bundleName_.c_str(), - Anonymous::Change(param.storeName_).c_str(), localMeta.asyncDownloadAsset, param.asyncDownloadAsset_, - localMeta.enableCloud, param.enableCloud_); + "%{public}d],enableCloud? [%{public}d -> %{public}d]", + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), localMeta.asyncDownloadAsset, + param.asyncDownloadAsset_, localMeta.enableCloud, param.enableCloud_); localMeta.asyncDownloadAsset = param.asyncDownloadAsset_; localMeta.enableCloud = param.enableCloud_; MetaDataManager::GetInstance().SaveMeta(localMeta.GetKey(), localMeta, true); @@ -379,7 +381,7 @@ std::string RdbServiceImpl::TransferStringToHex(const std::string &origStr) std::string tmp; for (auto item : origStr) { auto currentByte = static_cast(item); - tmp.push_back(hex[currentByte >> 4]); // high 4 bit to one hex. + tmp.push_back(hex[currentByte >> 4]); // high 4 bit to one hex. tmp.push_back(hex[currentByte & 0x0F]); // low 4 bit to one hex. } return tmp; @@ -422,8 +424,8 @@ RdbServiceImpl::DetailAsync RdbServiceImpl::GetCallbacks(uint32_t tokenId, const }; } -std::pair> RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, - const std::string& device, const std::string& sql, const std::vector& selectionArgs) +std::pair> RdbServiceImpl::RemoteQuery(const RdbSyncerParam ¶m, + const std::string &device, const std::string &sql, const std::vector &selectionArgs) { if (!IsValidParam(param) || !IsValidAccess(param.bundleName_, param.storeName_)) { ZLOGE("bundleName:%{public}s, storeName:%{public}s. Permission error", param.bundleName_.c_str(), @@ -439,7 +441,7 @@ std::pair> RdbServiceImpl::R } std::vector devices = { DmAdapter::GetInstance().ToUUID(device) }; if (IsNeedMetaSync(meta, devices) && !MetaDataManager::GetInstance().Sync( - devices, [](auto &results) {}, true)) { + devices, [](auto &results) {}, true)) { ZLOGW("bundleName:%{public}s, storeName:%{public}s. meta sync failed", param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str()); } @@ -453,7 +455,7 @@ std::pair> RdbServiceImpl::R } int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, - const AsyncDetail &async) + const AsyncDetail &async) { if (!IsValidParam(param) || !IsValidAccess(param.bundleName_, param.storeName_)) { ZLOGE("bundleName:%{public}s, storeName:%{public}s. Permission error", param.bundleName_.c_str(), @@ -468,56 +470,56 @@ int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, return DoSync(param, option, predicates, async); } -void RdbServiceImpl::SaveAutoSyncDeviceId(const StoreMetaData &meta, const PredicatesMemo &predicates) +void RdbServiceImpl::SaveAutoSyncDeviceId(const StoreMetaData &meta, const std::vector &devices) { - DistributedData::AutoSyncDevicesInfo deviceInfos; - std::vector devices = DmAdapter::ToUDID(predicates.devices_); + DistributedData::SpecialChannelData specialDevices; if (devices.empty()) { ZLOGE("There is no deviceId in predicates"); return; } - if(!MetaDataManager::GetInstance().LoadMeta(meta.GetAutoSyncDeviceKey(), deviceInfos, true)){ - deviceInfos.udids = std::move(devices); - MetaDataManager::GetInstance().SaveMeta(meta.GetAutoSyncDeviceKey(), deviceInfos, true); - return; - } + + MetaDataManager::GetInstance().LoadMeta(specialDevices.GetKey(), specialDevices, true); + auto &specialUUIDs = specialDevices.devices; for (auto &device : devices) { - auto iter = std::find(deviceInfos.udids.begin(), deviceInfos.udids.end(), device); - if (iter != deviceInfos.udids.end() && deviceInfos.udids.size() == 1){ + auto sha256UUID = Crypto::Sha256(device); + auto iter = std::find(specialUUIDs.begin(), specialUUIDs.end(), sha256UUID); + if (iter != specialUUIDs.end() && specialUUIDs.size() == 1) { continue; } - if (iter != deviceInfos.udids.end()) { - std::swap(*iter, deviceInfos.udids.back()); + if (iter != specialUUIDs.end()) { + std::swap(*iter, specialUUIDs.back()); } else { - deviceInfos.udids.push_back(device); + specialUUIDs.push_back(device); } } - if (deviceInfos.udids.size() > ALLOW_AUTO_SYNC_DEVICE) { - auto index = deviceInfos.udids.size() - ALLOW_AUTO_SYNC_DEVICE; - deviceInfos.udids.erase(deviceInfos.udids.begin(), deviceInfos.udids.begin() + index - 1); + if (specialUUIDs.size() > ALLOW_AUTO_SYNC_DEVICE) { + auto index = specialUUIDs.size() - ALLOW_AUTO_SYNC_DEVICE; + specialUUIDs.erase(specialUUIDs.begin(), specialUUIDs.begin() + index - 1); } - MetaDataManager::GetInstance().SaveMeta(meta.GetAutoSyncDeviceKey(), deviceInfos, true); + MetaDataManager::GetInstance().SaveMeta(specialDevices.GetKey(), specialDevices, true); } int RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, const RdbService::Option &option, const PredicatesMemo &predicates, const AsyncDetail &async) { StoreMetaData meta = GetStoreMetaData(param); - if(meta.instanceId != 0) { + if (meta.instanceId != 0) { return RDB_ERROR; } - bool isAutoSync = DeviceSyncAppManager::GetInstance().CheckBundleName(meta.bundleName, meta.appId); - if (isAutoSync) { - SaveAutoSyncDeviceId(meta, predicates); + + RdbQuery rdbQuery; + rdbQuery.MakeQuery(predicates); + auto devices = rdbQuery.GetDevices().empty() ? DmAdapter::ToUUID(DmAdapter::GetInstance().GetRemoteDevices()) + : DmAdapter::ToUUID(rdbQuery.GetDevices()); + bool isAutoSync = SyncManager::GetInstance().IsAutoSyncApp(meta.bundleName, meta.appId); + if (isAutoSync && !rdbQuery.GetDevices().empty()) { + SaveAutoSyncDeviceId(meta, devices); } auto store = GetStore(meta); if (store == nullptr) { return RDB_ERROR; } - RdbQuery rdbQuery; - rdbQuery.MakeQuery(predicates); - auto devices = rdbQuery.GetDevices().empty() ? DmAdapter::ToUUID(DmAdapter::GetInstance().GetRemoteDevices()) - : DmAdapter::ToUUID(rdbQuery.GetDevices()); + auto pid = IPCSkeleton::GetCallingPid(); SyncParam syncParam = { option.mode, 0, option.isCompensation }; auto tokenId = IPCSkeleton::GetCallingTokenID(); @@ -587,7 +589,7 @@ RdbServiceImpl::SyncResult RdbServiceImpl::ProcessResult(const std::map({ ValueProxy::Convert(std::move(value)) })); } auto memo = predicates.GetDistributedPredicates(); @@ -639,8 +641,8 @@ void RdbServiceImpl::DoCloudSync(const RdbSyncerParam ¶m, const RdbService:: } }; auto highMode = (!predicates.tables_.empty() && option.mode == DistributedData::GeneralStore::CLOUD_CLOUD_FIRST) - ? GeneralStore::ASSETS_SYNC_MODE - : (option.isAutoSync ? GeneralStore::AUTO_SYNC_MODE : GeneralStore::MANUAL_SYNC_MODE); + ? GeneralStore::ASSETS_SYNC_MODE + : (option.isAutoSync ? GeneralStore::AUTO_SYNC_MODE : GeneralStore::MANUAL_SYNC_MODE); auto mixMode = static_cast(GeneralStore::MixMode(option.mode, highMode)); SyncParam syncParam = { mixMode, (option.isAsync ? 0 : static_cast(WAIT_TIME)), option.isCompensation }; syncParam.asyncDownloadAsset = param.asyncDownloadAsset_; @@ -675,8 +677,8 @@ int32_t RdbServiceImpl::Subscribe(const RdbSyncerParam ¶m, const SubscribeOp return true; }); if (isCreate) { - AutoCache::GetInstance().SetObserver(tokenId, GetWatchers(tokenId, param.storeName_), - GetPath(param), RemoveSuffix(param.storeName_)); + AutoCache::GetInstance().SetObserver(tokenId, GetWatchers(tokenId, param.storeName_), GetPath(param), + RemoveSuffix(param.storeName_)); } return RDB_OK; } @@ -704,13 +706,13 @@ int32_t RdbServiceImpl::UnSubscribe(const RdbSyncerParam ¶m, const Subscribe return true; }); if (destroyed) { - AutoCache::GetInstance().SetObserver(tokenId, GetWatchers(tokenId, param.storeName_), - GetPath(param), RemoveSuffix(param.storeName_)); + AutoCache::GetInstance().SetObserver(tokenId, GetWatchers(tokenId, param.storeName_), GetPath(param), + RemoveSuffix(param.storeName_)); } return RDB_OK; } -int32_t RdbServiceImpl::RegisterAutoSyncCallback(const RdbSyncerParam& param, +int32_t RdbServiceImpl::RegisterAutoSyncCallback(const RdbSyncerParam ¶m, std::shared_ptr observer) { pid_t pid = IPCSkeleton::GetCallingPid(); @@ -730,7 +732,7 @@ int32_t RdbServiceImpl::RegisterAutoSyncCallback(const RdbSyncerParam& param, return RDB_OK; } -int32_t RdbServiceImpl::UnregisterAutoSyncCallback(const RdbSyncerParam& param, +int32_t RdbServiceImpl::UnregisterAutoSyncCallback(const RdbSyncerParam ¶m, std::shared_ptr observer) { auto tokenId = IPCSkeleton::GetCallingTokenID(); @@ -830,7 +832,7 @@ std::pair> RdbServiceImpl::Query return { RDB_OK, std::make_shared(cursor) }; } -std::pair> RdbServiceImpl::AllocResource(StoreInfo& storeInfo, +std::pair> RdbServiceImpl::AllocResource(StoreInfo &storeInfo, std::shared_ptr rdbQuery) { std::pair> result; @@ -1039,7 +1041,7 @@ bool RdbServiceImpl::SaveAppIDMeta(const StoreMetaData &meta, const StoreMetaDat return true; } -int32_t RdbServiceImpl::ReportStatistic(const RdbSyncerParam& param, const RdbStatEvent &statEvent) +int32_t RdbServiceImpl::ReportStatistic(const RdbSyncerParam ¶m, const RdbStatEvent &statEvent) { if (!IsValidAccess(param.bundleName_, param.storeName_)) { ZLOGE("bundleName:%{public}s, storeName:%{public}s. Permission error", param.bundleName_.c_str(), @@ -1057,7 +1059,7 @@ void RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) storeInfo.tokenId = IPCSkeleton::GetCallingTokenID(); storeInfo.bundleName = param.bundleName_; storeInfo.storeName = RemoveSuffix(param.storeName_); - auto [instanceId, user]= GetInstIndexAndUser(storeInfo.tokenId, param.bundleName_); + auto [instanceId, user] = GetInstIndexAndUser(storeInfo.tokenId, param.bundleName_); storeInfo.instanceId = instanceId; storeInfo.user = user; storeInfo.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; @@ -1095,7 +1097,7 @@ std::pair RdbServiceImpl::LoadStoreMetaData(const RdbSyncer metaData.customDir = param.customDir_; metaData.dataDir = DirectoryManager::GetInstance().GetStorePath(metaData) + "/" + param.storeName_; auto exist = MetaDataManager::GetInstance().LoadMeta(metaData.GetKey(), metaData, true); - return {exist, metaData}; + return { exist, metaData }; } StoreMetaData RdbServiceImpl::GetStoreMetaData(const RdbSyncerParam ¶m) @@ -1147,7 +1149,7 @@ int32_t RdbServiceImpl::Upgrade(const RdbSyncerParam ¶m, const StoreMetaData Details RdbServiceImpl::HandleGenDetails(const GenDetails &details) { Details dbDetails; - for (const auto& [id, detail] : details) { + for (const auto &[id, detail] : details) { auto &dbDetail = dbDetails[id]; dbDetail.progress = detail.progress; dbDetail.code = detail.code; @@ -1159,7 +1161,7 @@ Details RdbServiceImpl::HandleGenDetails(const GenDetails &details) return dbDetails; } -std::string RdbServiceImpl::RemoveSuffix(const std::string& name) +std::string RdbServiceImpl::RemoveSuffix(const std::string &name) { std::string suffix(".db"); auto pos = name.rfind(suffix); @@ -1235,21 +1237,28 @@ std::vector RdbServiceImpl::GetReuseDevice(const std::vector &devices, const StoreMetaData &storeMetaData, std::vector tables) +int RdbServiceImpl::DoAutoSync(const std::vector &devices, const StoreMetaData &storeMetaData, + const std::vector &tables) { - if(storeMetaData.instanceId != 0) { + if (storeMetaData.instanceId != 0) { + return RDB_ERROR; + } + DistributedData::SpecialChannelData specialDevices; + if (!MetaDataManager::GetInstance().LoadMeta(specialDevices.GetKey(), specialDevices, true) || + specialDevices.devices.empty()) { + ZLOGE("There is no auto sync devices, store:%{public}s.", Anonymous::Change(storeMetaData.storeId).c_str()); return RDB_ERROR; } - std::vector isSyncDevices; - std::vector deviceIds = DmAdapter::ToUDID(DmAdapter::GetInstance().GetRemoteDevices()); - for(auto &device : devices){ - if(std::find(deviceIds.begin(), deviceIds.end(), device) != deviceIds.end()){ - isSyncDevices.push_back(device); + auto &specialUUIDs = specialDevices.devices; + std::vector syncDevices; + for (auto &device : devices) { + auto sha256UUID = Crypto::Sha256(device); + if (std::find(specialUUIDs.begin(), specialUUIDs.end(), device) != specialUUIDs.end()) { + syncDevices.push_back(device); } } - if (isSyncDevices.empty()) { - ZLOGE("Designated syncdevice not in trustdevicelist.storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); + if (syncDevices.empty()) { + ZLOGE("Designated sync device not in cache storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); return RDB_ERROR; } auto store = GetStore(storeMetaData); @@ -1263,15 +1272,15 @@ int RdbServiceImpl::DoAutoSync( } SyncParam syncParam = { 0, 0 }; DetailAsync async; - executors_->Execute([this, tables, store, syncParam, async, isSyncDevices, storeMetaData]() { + executors_->Execute([this, tables, store, syncParam, async, syncDevices, storeMetaData]() { RdbQuery rdbQuery; rdbQuery.MakeDeviceQuery(tables); - std::vector onDevices = GetReuseDevice(isSyncDevices, storeMetaData); + std::vector onDevices = GetReuseDevice(syncDevices, storeMetaData); if (onDevices.empty()) { ZLOGE("autosync device null, storeId:%{public}s", storeMetaData.GetStoreAlias().c_str()); return; } - auto complete = [this, rdbQuery, store, syncParam, async](const auto &results) mutable { + auto complete = [rdbQuery, store, syncParam, async](const auto &results) mutable { auto ret = ProcessResult(results); store->Sync(ret.first, rdbQuery, async, syncParam); }; @@ -1285,11 +1294,8 @@ int RdbServiceImpl::DoAutoSync( return RDB_OK; } -int RdbServiceImpl::DoOnlineSync(const std::vector &devices, const Database &dataBase) +int RdbServiceImpl::DoOnlineSync(const std::string &device, const Database &dataBase) { - if (devices.empty()) { - return RDB_ERROR; - } std::vector tableNames; for (auto &table : dataBase.tables) { if (!table.deviceSyncFields.empty()) { @@ -1297,24 +1303,12 @@ int RdbServiceImpl::DoOnlineSync(const std::vector &devices, const } } StoreMetaData storeMetaData = GetStoreMetaData(dataBase); - DistributedData::AutoSyncDevicesInfo deviceInfos; - if(!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetAutoSyncDeviceKey(), deviceInfos, true)){ - return RDB_ERROR; - } - std::vector deviceIds = DmAdapter::ToUDID(devices); - if(deviceIds.empty()){ - return RDB_ERROR; - } - if (deviceInfos.udids.empty() || - std::find(deviceInfos.udids.begin(), deviceInfos.udids.end(), deviceIds[0]) == deviceInfos.udids.end()) { - return RDB_ERROR; - } - return DoAutoSync(devices, storeMetaData, tableNames); + return DoAutoSync({ device }, storeMetaData, tableNames); } int32_t RdbServiceImpl::OnReady(const std::string &device) { - if(device.empty()){ + if (device.empty()) { return 0; } int index = ALLOW_ONLINE_AUTO_SYNC; @@ -1324,12 +1318,11 @@ int32_t RdbServiceImpl::OnReady(const std::string &device) if (!MetaDataManager::GetInstance().LoadMeta(prefix, dataBases, true)) { return 0; } - for (auto dataBase : dataBases) { + for (auto &dataBase : dataBases) { if ((dataBase.autoSyncType == AutoSyncType::SYNC_ON_READY || dataBase.autoSyncType == AutoSyncType::SYNC_ON_CHANGE_READY) && index > 0) { - std::vector devices = {device}; - if (DoOnlineSync(devices, dataBase) != RDB_OK) { + if (DoOnlineSync(device, dataBase) != RDB_OK) { ZLOGE("store online sync fail, storeId:%{public}s", Anonymous::Change(dataBase.name).c_str()); } index--; @@ -1394,7 +1387,7 @@ int32_t RdbServiceImpl::RdbStatic::CloseStore(const std::string &bundleName, int int32_t RdbServiceImpl::RdbStatic::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) { - std::string prefix = Database::GetPrefix({std::to_string(user), "default", bundleName}); + std::string prefix = Database::GetPrefix({ std::to_string(user), "default", bundleName }); std::vector dataBase; if (MetaDataManager::GetInstance().LoadMeta(prefix, dataBase, true)) { for (const auto &dataBase : dataBase) { @@ -1406,7 +1399,7 @@ int32_t RdbServiceImpl::RdbStatic::OnAppUninstall(const std::string &bundleName, int32_t RdbServiceImpl::RdbStatic::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) { - std::string prefix = Database::GetPrefix({std::to_string(user), "default", bundleName}); + std::string prefix = Database::GetPrefix({ std::to_string(user), "default", bundleName }); std::vector dataBase; if (MetaDataManager::GetInstance().LoadMeta(prefix, dataBase, true)) { for (const auto &database : dataBase) { @@ -1487,21 +1480,15 @@ int RdbServiceImpl::DoDataChangeSync(const StoreInfo &storeInfo, const RdbChange return RDB_OK; } StoreMetaData storeMetaData = GetStoreMetaData(dataBase); - DistributedData::AutoSyncDevicesInfo deviceInfos; - if (!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetAutoSyncDeviceKey(), deviceInfos, true) || - deviceInfos.udids.empty()) { - ZLOGE("There is no autoSyncDevice, store:%{public}s.", Anonymous::Change(storeInfo.storeName).c_str()); - return RDB_ERROR; - } if ((dataBase.autoSyncType == AutoSyncType::SYNC_ON_CHANGE || dataBase.autoSyncType == AutoSyncType::SYNC_ON_CHANGE_READY)) { - return DoAutoSync(deviceInfos.udids, storeMetaData, tableNames); + return DoAutoSync(DmAdapter::ToUUID(DmAdapter::GetInstance().GetRemoteDevices()), storeMetaData, tableNames); } return RDB_OK; } -int32_t RdbServiceImpl::NotifyDataChange( - const RdbSyncerParam ¶m, const RdbChangedData &rdbChangedData, const RdbNotifyConfig &rdbNotifyConfig) +int32_t RdbServiceImpl::NotifyDataChange(const RdbSyncerParam ¶m, const RdbChangedData &rdbChangedData, + const RdbNotifyConfig &rdbNotifyConfig) { XCollie xcollie(__FUNCTION__, XCollie::XCOLLIE_LOG | XCollie::XCOLLIE_RECOVERY); if (!IsValidParam(param) || !IsValidAccess(param.bundleName_, param.storeName_)) { @@ -1525,7 +1512,7 @@ int32_t RdbServiceImpl::NotifyDataChange( } for (const auto &[key, value] : rdbChangedData.tableData) { if (value.isTrackedDataChange) { - DataChangeEvent::TableChangeProperties tableChangeProperties = {value.isTrackedDataChange}; + DataChangeEvent::TableChangeProperties tableChangeProperties = { value.isTrackedDataChange }; eventInfo.tableProperties.insert_or_assign(key, std::move(tableChangeProperties)); } } @@ -1573,7 +1560,7 @@ bool RdbServiceImpl::IsPostImmediately(const int32_t callingPid, const RdbNotify return postImmediately; } -int32_t RdbServiceImpl::SetSearchable(const RdbSyncerParam& param, bool isSearchable) +int32_t RdbServiceImpl::SetSearchable(const RdbSyncerParam ¶m, bool isSearchable) { XCollie xcollie(__FUNCTION__, XCollie::XCOLLIE_LOG | XCollie::XCOLLIE_RECOVERY); if (!IsValidAccess(param.bundleName_, param.storeName_)) { @@ -1678,10 +1665,10 @@ StoreInfo RdbServiceImpl::GetStoreInfo(const RdbSyncerParam ¶m) std::pair RdbServiceImpl::LockCloudContainer(const RdbSyncerParam ¶m) { - std::pair result { RDB_ERROR, 0 }; + std::pair result{ RDB_ERROR, 0 }; if (!IsValidAccess(param.bundleName_, param.storeName_)) { ZLOGE("bundleName:%{public}s, storeName:%{public}s. Permission error", param.bundleName_.c_str(), - Anonymous::Change(param.storeName_).c_str()); + Anonymous::Change(param.storeName_).c_str()); return result; } ZLOGI("start to lock cloud db: bundleName:%{public}s, storeName:%{public}s", param.bundleName_.c_str(), @@ -1703,7 +1690,7 @@ int32_t RdbServiceImpl::UnlockCloudContainer(const RdbSyncerParam ¶m) int32_t result = RDB_ERROR; if (!IsValidAccess(param.bundleName_, param.storeName_)) { ZLOGE("bundleName:%{public}s, storeName:%{public}s. Permission error", param.bundleName_.c_str(), - Anonymous::Change(param.storeName_).c_str()); + Anonymous::Change(param.storeName_).c_str()); return result; } ZLOGI("start to unlock cloud db: bundleName:%{public}s, storeName:%{public}s", param.bundleName_.c_str(), @@ -1767,7 +1754,7 @@ int32_t RdbServiceImpl::SaveDebugInfo(const StoreMetaData &metaData, const RdbSy fileInfo.mode = info.mode_; fileInfo.uid = info.uid_; fileInfo.gid = info.gid_; - debugMeta.fileInfos.insert(std::pair{name, fileInfo}); + debugMeta.fileInfos.insert(std::pair{ name, fileInfo }); } MetaDataManager::GetInstance().SaveMeta(metaData.GetDebugInfoKey(), debugMeta, true); return RDB_OK; @@ -1849,7 +1836,7 @@ int32_t RdbServiceImpl::VerifyPromiseInfo(const RdbSyncerParam ¶m) bool isPromise = std::any_of(localMeta.promiseInfo.permissionNames.begin(), localMeta.promiseInfo.permissionNames.end(), [tokenId](const std::string &permissionName) { return PermitDelegate::VerifyPermission(permissionName, tokenId); - }); + }); if (tokenIdRet == localMeta.promiseInfo.tokenIds.end() && uidRet == localMeta.promiseInfo.uids.end() && !isPromise) { return RDB_ERROR; @@ -1879,8 +1866,7 @@ std::string RdbServiceImpl::GetSubUser(const int32_t subUser) return userId; } -bool RdbServiceImpl::TryUpdateDeviceId(const RdbSyncerParam ¶m, const StoreMetaData &oldMeta, - StoreMetaData &meta) +bool RdbServiceImpl::TryUpdateDeviceId(const RdbSyncerParam ¶m, const StoreMetaData &oldMeta, StoreMetaData &meta) { StoreMetaData syncMeta; if (oldMeta.isNeedUpdateDeviceId && oldMeta.storeType >= StoreMetaData::StoreType::STORE_RELATIONAL_BEGIN && diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index fe36b10ee..0ec8aa657 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "cloud/cloud_event.h" #include "commonevent/data_change_event.h" @@ -28,6 +29,7 @@ #include "feature/static_acts.h" #include "metadata/secret_key_meta_data.h" #include "metadata/store_meta_data.h" +#include "process_communicator_impl.h" #include "rdb_notifier_proxy.h" #include "rdb_query.h" #include "rdb_service_stub.h" @@ -38,7 +40,6 @@ #include "store/general_value.h" #include "store_observer.h" #include "visibility.h" -#include "process_communicator_impl.h" namespace OHOS::DistributedRdb { using namespace OHOS::AppDistributedKv; @@ -179,16 +180,16 @@ private: void DoCompensateSync(const DistributedData::BindEvent& event); - void SaveAutoSyncDeviceId(const StoreMetaData &meta, const PredicatesMemo &predicates); + void SaveAutoSyncDeviceId(const StoreMetaData &meta, const std::vector &devices); int DoSync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async); - int DoAutoSync( - const std::vector &devices, const StoreMetaData &storeMetaData, std::vector tables); + int DoAutoSync(const std::vector &devices, const StoreMetaData &storeMetaData, + const std::vector &tables); std::vector GetReuseDevice(const std::vector &devices, const StoreMetaData &metaData); - int DoOnlineSync(const std::vector &devices, const Database &dataBase); + int DoOnlineSync(const std::string &devices, const Database &dataBase); int DoDataChangeSync(const StoreInfo &storeInfo, const RdbChangedData &rdbChangedData); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 98c13fef7..b4b3e7232 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1325,12 +1325,12 @@ ohos_unittest("DataShareServiceImplMockTest") { "${data_service_path}/service/common/xcollie.cpp", "${data_service_path}/service/config/src/model/app_access_check_config.cpp", "${data_service_path}/service/config/src/model/app_id_mapping_config.cpp", + "${data_service_path}/service/config/src/model/auto_sync_app_config.cpp", "${data_service_path}/service/config/src/model/backup_config.cpp", "${data_service_path}/service/config/src/model/checker_config.cpp", "${data_service_path}/service/config/src/model/cloud_config.cpp", "${data_service_path}/service/config/src/model/component_config.cpp", "${data_service_path}/service/config/src/model/datashare_config.cpp", - "${data_service_path}/service/config/src/model/device_sync_app_white_list_config.cpp", "${data_service_path}/service/config/src/model/directory_config.cpp", "${data_service_path}/service/config/src/model/global_config.cpp", "${data_service_path}/service/config/src/model/network_config.cpp", @@ -2136,12 +2136,12 @@ ohos_unittest("BootStrapMockTest") { "${data_service_path}/service/bootstrap/src/bootstrap.cpp", "${data_service_path}/service/config/src/model/app_access_check_config.cpp", "${data_service_path}/service/config/src/model/app_id_mapping_config.cpp", + "${data_service_path}/service/config/src/model/auto_sync_app_config.cpp", "${data_service_path}/service/config/src/model/backup_config.cpp", "${data_service_path}/service/config/src/model/checker_config.cpp", "${data_service_path}/service/config/src/model/cloud_config.cpp", "${data_service_path}/service/config/src/model/component_config.cpp", "${data_service_path}/service/config/src/model/datashare_config.cpp", - "${data_service_path}/service/config/src/model/device_sync_app_white_list_config.cpp", "${data_service_path}/service/config/src/model/directory_config.cpp", "${data_service_path}/service/config/src/model/global_config.cpp", "${data_service_path}/service/config/src/model/network_config.cpp", diff --git a/services/distributeddataservice/service/test/rdb_service_impl_test.cpp b/services/distributeddataservice/service/test/rdb_service_impl_test.cpp index 2524b7d86..839518c87 100644 --- a/services/distributeddataservice/service/test/rdb_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/rdb_service_impl_test.cpp @@ -682,7 +682,6 @@ HWTEST_F(RdbServiceImplTest, DoAutoSync002, TestSize.Level0) HWTEST_F(RdbServiceImplTest, DoOnlineSync001, TestSize.Level0) { RdbServiceImpl service; - std::vector devices = {"device1"}; DistributedData::Database dataBase; dataBase.name = TEST_STORE; @@ -695,7 +694,7 @@ HWTEST_F(RdbServiceImplTest, DoOnlineSync001, TestSize.Level0) dataBase.tables = {table1, table2}; - auto result = service.DoOnlineSync(devices, dataBase); + auto result = service.DoOnlineSync("device1", dataBase); EXPECT_EQ(result, RDB_ERROR); } -- Gitee