From 82dbd1bbbe150080d7aabbc181ec6941397f6ea6 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Wed, 18 Jun 2025 11:17:26 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BA=91=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E7=AB=AF=E5=88=B0=E7=AB=AF=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../framework/cloud/schema_meta.cpp | 2 + .../framework/include/cloud/schema_meta.h | 1 + .../framework/include/store/general_store.h | 1 + .../service/cloud/cloud_service_impl.cpp | 63 +++++++++++++++++++ .../service/cloud/cloud_service_impl.h | 1 + .../service/cloud/sync_manager.cpp | 1 + .../service/kvdb/kvdb_general_store.cpp | 1 + .../service/rdb/rdb_general_store.cpp | 1 + 8 files changed, 71 insertions(+) diff --git a/services/distributeddataservice/framework/cloud/schema_meta.cpp b/services/distributeddataservice/framework/cloud/schema_meta.cpp index 7844058ae..273fc6b48 100644 --- a/services/distributeddataservice/framework/cloud/schema_meta.cpp +++ b/services/distributeddataservice/framework/cloud/schema_meta.cpp @@ -23,6 +23,7 @@ bool SchemaMeta::Marshal(Serializable::json &node) const SetValue(node[GET_NAME(version)], version); SetValue(node[GET_NAME(bundleName)], bundleName); SetValue(node[GET_NAME(databases)], databases); + SetValue(node[GET_NAME(e2eeEnable)], e2eeEnable); return true; } @@ -35,6 +36,7 @@ bool SchemaMeta::Unmarshal(const Serializable::json &node) GetValue(node, GET_NAME(bundleName), bundleName); GetValue(node, GET_NAME(databases), databases); GetValue(node, GET_NAME(dbSchema), databases); + GetValue(node, GET_NAME(e2eeEnable), e2eeEnable); return true; } diff --git a/services/distributeddataservice/framework/include/cloud/schema_meta.h b/services/distributeddataservice/framework/include/cloud/schema_meta.h index 33dc0cb41..889392199 100644 --- a/services/distributeddataservice/framework/include/cloud/schema_meta.h +++ b/services/distributeddataservice/framework/include/cloud/schema_meta.h @@ -88,6 +88,7 @@ public: int32_t version = 0; std::string bundleName; std::vector databases; + bool e2eeEnable = false; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 7f1d83b3d..0b56018c5 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -114,6 +114,7 @@ public: int32_t maxNumber = 30; int32_t maxSize = 1024 * 512 * 3; // 1.5M int32_t maxRetryConflictTimes = 3; // default max retry 3 times when version conflict + bool isSupportEncrypt = false; }; enum class DistributedTableMode : int { diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index fdfbd83bc..73c291590 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -923,6 +923,47 @@ bool CloudServiceImpl::UpdateSchema(int32_t user, CloudSyncScene scene) return true; } +/** +* Will be called when 'cloudDriver' OnAppUpdate/OnAppInstall to get newest 'e2eeEnable'. +*/ +int32_t CloudServiceImpl::UpdateSchemaFromServer(int32_t user) +{ + auto [status, cloudInfo] = GetCloudInfo(user); + if (status != SUCCESS) { + ZLOGW("get cloudinfo failed, user:%{public}d, status:%{public}d", user, status); + return status; + } + auto keys = cloudInfo.GetSchemaKey(); + for (const auto &[bundle, key] : keys) { + HapInfo hapInfo{ .user = user, .instIndex = 0, .bundleName = bundle }; + auto appInfoOpt = cloudInfo.GetAppInfo(bundle); + if (appInfoOpt.has_value()) { + const CloudInfo::AppInfo &appInfo = appInfoOpt.value(); + hapInfo.instIndex = appInfo.instanceId; + } + + SchemaMeta schemaMeta; + std::tie(status, schemaMeta) = GetAppSchemaFromServer(user, bundle); + if (status == NOT_SUPPORT) { + ZLOGW("app not support, del cloudInfo! user:%{public}d, bundleName:%{public}s", user, bundle.c_str()); + MetaDataManager::GetInstance().DelMeta(cloudInfo.GetKey(), true); + return status; + } + if (status != SUCCESS) { + continue; + } + SchemaMeta oldMeta; + if (MetaDataManager::GetInstance().LoadMeta(key, oldMeta, true) && + oldMeta.e2eeEnable != schemaMeta.e2eeEnable) { + ZLOGI("Update e2eeEnable: %{public}d->%{public}d, user:%{public}d, bundleName:%{public}s", + oldMeta.e2eeEnable, schemaMeta.e2eeEnable, user, bundle.c_str()); + oldMeta.e2eeEnable = schemaMeta.e2eeEnable; + MetaDataManager::GetInstance().SaveMeta(key, oldMeta, true); + } + } + return SUCCESS; +} + std::pair CloudServiceImpl::GetAppSchemaFromServer(int32_t user, const std::string &bundleName) { SchemaMeta schemaMeta; @@ -1080,6 +1121,17 @@ int32_t CloudServiceImpl::CloudStatic::OnAppUninstall(const std::string &bundleN int32_t CloudServiceImpl::CloudStatic::OnAppInstall(const std::string &bundleName, int32_t user, int32_t index) { ZLOGI("bundleName:%{public}s,user:%{public}d,instanceId:%{public}d", bundleName.c_str(), user, index); + CheckerManager::StoreInfo info; + info.uid = IPCSkeleton::GetCallingUid(); + info.tokenId = IPCSkeleton::GetCallingTokenID(); + info.bundleName = bundleName; + if (CheckerManager::GetInstance().IsValid(info)) { + // cloudDriver install, update schema(for update 'e2eeEnable') + ZLOGI("cloud driver install, bundleName:%{public}s, user:%{public}d, instanceId:%{public}d", + bundleName.c_str(), user, index); + Execute([this, user]() { UpdateSchemaFromServer(user); }); + return SUCCESS; + } auto ret = UpdateCloudInfoFromServer(user); if (ret == E_OK) { StoreInfo info{.bundleName = bundleName, .instanceId = index, .user = user}; @@ -1091,6 +1143,17 @@ int32_t CloudServiceImpl::CloudStatic::OnAppInstall(const std::string &bundleNam int32_t CloudServiceImpl::CloudStatic::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) { ZLOGI("bundleName:%{public}s,user:%{public}d,instanceId:%{public}d", bundleName.c_str(), user, index); + CheckerManager::StoreInfo info; + info.uid = IPCSkeleton::GetCallingUid(); + info.tokenId = IPCSkeleton::GetCallingTokenID(); + info.bundleName = bundleName; + if (CheckerManager::GetInstance().IsValid(info)) { + // cloudDriver updated, update schema(for update 'e2eeEnable') + ZLOGI("cloud driver updated, bundleName:%{public}s, user:%{public}d, instanceId:%{public}d", + bundleName.c_str(), user, index); + Execute([this, user]() { UpdateSchemaFromServer(user); }); + return SUCCESS; + } HapInfo hapInfo{ .user = user, .instIndex = index, .bundleName = bundleName }; Execute([this, hapInfo]() { UpdateSchemaFromHap(hapInfo); }); return SUCCESS; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 271627229..1903cdea1 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -202,6 +202,7 @@ private: static std::pair GetSchemaFromHap(const HapInfo &hapInfo); static int32_t UpdateSchemaFromHap(const HapInfo &hapInfo); + static int32_t UpdateSchemaFromServer(int32_t user); static void UpdateClearWaterMark( const HapInfo &hapInfo, const SchemaMeta &newSchemaMeta, const SchemaMeta &schemaMeta); QueryLastResults AssembleLastResults(const std::vector &databases, diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index db4e6099c..f0d77767c 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -662,6 +662,7 @@ std::pair SyncManager::GetStore(const StoreMetaData & if (MetaDataManager::GetInstance().LoadMeta(info.GetKey(), info, true)) { config.maxNumber = info.maxNumber; config.maxSize = info.maxSize; + config.isSupportEncrypt = schemaMeta.e2eeEnable; } store->Bind(dbMeta, bindInfos, config); } diff --git a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp index b2fab36ce..ebb198a64 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp @@ -257,6 +257,7 @@ int32_t KVDBGeneralStore::Bind( dbConfig.maxUploadCount = config.maxNumber; dbConfig.maxUploadSize = config.maxSize; dbConfig.maxRetryConflictTimes = config.maxRetryConflictTimes; + dbConfig.isSupportEncrypt = config.isSupportEncrypt; std::shared_lock lock(rwMutex_); if (delegate_ == nullptr) { return GeneralError::E_ALREADY_CLOSED; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 33c2d657d..4cfddd278 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -263,6 +263,7 @@ int32_t RdbGeneralStore::Bind(const Database &database, const std::map lock(rwMutex_); if (delegate_ == nullptr) { -- Gitee From e64d419a75ef6a8ef8f79accde8bffd7f79a8a8e Mon Sep 17 00:00:00 2001 From: Hollokin Date: Wed, 18 Jun 2025 15:58:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?TDD=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../service/cloud/cloud_service_impl.cpp | 75 +++++++------- .../service/cloud/cloud_service_impl.h | 6 +- .../service/cloud/sync_manager.cpp | 5 +- .../service/test/cloud_data_test.cpp | 1 + .../service/test/cloud_service_impl_test.cpp | 99 +++++++++++++++++++ 5 files changed, 148 insertions(+), 38 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 73c291590..bb70a274e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -74,6 +74,7 @@ static constexpr const char *FT_USER_UNLOCK = "USER_UNLOCK"; static constexpr const char *FT_NETWORK_RECOVERY = "NETWORK_RECOVERY"; static constexpr const char *FT_SERVICE_INIT = "SERVICE_INIT"; static constexpr const char *FT_SYNC_TASK = "SYNC_TASK"; +static constexpr const char *FT_ENCRYPT_CHANGED = "ENCRYPT_CHANGED"; static constexpr const char *CLOUD_SCHEMA = "arkdata/cloud/cloud_schema.json"; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; const CloudServiceImpl::SaveStrategy CloudServiceImpl::STRATEGY_SAVERS[Strategy::STRATEGY_BUTT] = { @@ -924,7 +925,7 @@ bool CloudServiceImpl::UpdateSchema(int32_t user, CloudSyncScene scene) } /** -* Will be called when 'cloudDriver' OnAppUpdate/OnAppInstall to get newest 'e2eeEnable'. +* Will be called when 'cloudDriver' OnAppUpdate/OnAppInstall to get the newest 'e2eeEnable'. */ int32_t CloudServiceImpl::UpdateSchemaFromServer(int32_t user) { @@ -933,17 +934,14 @@ int32_t CloudServiceImpl::UpdateSchemaFromServer(int32_t user) ZLOGW("get cloudinfo failed, user:%{public}d, status:%{public}d", user, status); return status; } + return UpdateSchemaFromServer(cloudInfo, user); +} + +int32_t CloudServiceImpl::UpdateSchemaFromServer(const CloudInfo &cloudInfo, int32_t user) +{ auto keys = cloudInfo.GetSchemaKey(); for (const auto &[bundle, key] : keys) { - HapInfo hapInfo{ .user = user, .instIndex = 0, .bundleName = bundle }; - auto appInfoOpt = cloudInfo.GetAppInfo(bundle); - if (appInfoOpt.has_value()) { - const CloudInfo::AppInfo &appInfo = appInfoOpt.value(); - hapInfo.instIndex = appInfo.instanceId; - } - - SchemaMeta schemaMeta; - std::tie(status, schemaMeta) = GetAppSchemaFromServer(user, bundle); + auto [status, schemaMeta] = GetAppSchemaFromServer(user, bundle); if (status == NOT_SUPPORT) { ZLOGW("app not support, del cloudInfo! user:%{public}d, bundleName:%{public}s", user, bundle.c_str()); MetaDataManager::GetInstance().DelMeta(cloudInfo.GetKey(), true); @@ -952,18 +950,28 @@ int32_t CloudServiceImpl::UpdateSchemaFromServer(int32_t user) if (status != SUCCESS) { continue; } - SchemaMeta oldMeta; - if (MetaDataManager::GetInstance().LoadMeta(key, oldMeta, true) && - oldMeta.e2eeEnable != schemaMeta.e2eeEnable) { - ZLOGI("Update e2eeEnable: %{public}d->%{public}d, user:%{public}d, bundleName:%{public}s", - oldMeta.e2eeEnable, schemaMeta.e2eeEnable, user, bundle.c_str()); - oldMeta.e2eeEnable = schemaMeta.e2eeEnable; - MetaDataManager::GetInstance().SaveMeta(key, oldMeta, true); - } + UpdateE2eeEnable(key, schemaMeta.e2eeEnable, bundle); } return SUCCESS; } +void CloudServiceImpl::UpdateE2eeEnable(const std::string &schemaKey, bool newE2eeEnable, + const std::string &bundleName) +{ + SchemaMeta oldMeta; + if (!MetaDataManager::GetInstance().LoadMeta(schemaKey, oldMeta, true)) { + return; + } + if (oldMeta.e2eeEnable == newE2eeEnable) { + return; + } + ZLOGI("Update e2eeEnable: %{public}d->%{public}d", oldMeta.e2eeEnable, newE2eeEnable); + oldMeta.e2eeEnable = newE2eeEnable; + Report(FT_ENCRYPT_CHANGED, Fault::CSFAPP_SCHEMA, bundleName, + "oldE2eeEnable=" + std::to_string(oldMeta.e2eeEnable) + ",newE2eeEnable" + std::to_string(newE2eeEnable)); + MetaDataManager::GetInstance().SaveMeta(schemaKey, oldMeta, true); +} + std::pair CloudServiceImpl::GetAppSchemaFromServer(int32_t user, const std::string &bundleName) { SchemaMeta schemaMeta; @@ -1121,15 +1129,7 @@ int32_t CloudServiceImpl::CloudStatic::OnAppUninstall(const std::string &bundleN int32_t CloudServiceImpl::CloudStatic::OnAppInstall(const std::string &bundleName, int32_t user, int32_t index) { ZLOGI("bundleName:%{public}s,user:%{public}d,instanceId:%{public}d", bundleName.c_str(), user, index); - CheckerManager::StoreInfo info; - info.uid = IPCSkeleton::GetCallingUid(); - info.tokenId = IPCSkeleton::GetCallingTokenID(); - info.bundleName = bundleName; - if (CheckerManager::GetInstance().IsValid(info)) { - // cloudDriver install, update schema(for update 'e2eeEnable') - ZLOGI("cloud driver install, bundleName:%{public}s, user:%{public}d, instanceId:%{public}d", - bundleName.c_str(), user, index); - Execute([this, user]() { UpdateSchemaFromServer(user); }); + if (CloudDriverCheck(bundleName, user)) { return SUCCESS; } auto ret = UpdateCloudInfoFromServer(user); @@ -1143,20 +1143,27 @@ int32_t CloudServiceImpl::CloudStatic::OnAppInstall(const std::string &bundleNam int32_t CloudServiceImpl::CloudStatic::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) { ZLOGI("bundleName:%{public}s,user:%{public}d,instanceId:%{public}d", bundleName.c_str(), user, index); + if (CloudDriverCheck(bundleName, user)) { + return SUCCESS; + } + HapInfo hapInfo{ .user = user, .instIndex = index, .bundleName = bundleName }; + Execute([this, hapInfo]() { UpdateSchemaFromHap(hapInfo); }); + return SUCCESS; +} + +bool CloudServiceImpl::CloudStatic::CloudDriverCheck(const std::string &bundleName, int32_t user) +{ CheckerManager::StoreInfo info; info.uid = IPCSkeleton::GetCallingUid(); info.tokenId = IPCSkeleton::GetCallingTokenID(); info.bundleName = bundleName; if (CheckerManager::GetInstance().IsValid(info)) { - // cloudDriver updated, update schema(for update 'e2eeEnable') - ZLOGI("cloud driver updated, bundleName:%{public}s, user:%{public}d, instanceId:%{public}d", - bundleName.c_str(), user, index); + // cloudDriver install, update schema(for update 'e2eeEnable') + ZLOGI("cloud driver check valid, bundleName:%{public}s, user:%{public}d", bundleName.c_str(), user); Execute([this, user]() { UpdateSchemaFromServer(user); }); - return SUCCESS; + return true; } - HapInfo hapInfo{ .user = user, .instIndex = index, .bundleName = bundleName }; - Execute([this, hapInfo]() { UpdateSchemaFromHap(hapInfo); }); - return SUCCESS; + return false; } int32_t CloudServiceImpl::UpdateSchemaFromHap(const HapInfo &hapInfo) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 1903cdea1..4410519c1 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -88,6 +88,8 @@ private: int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index) override; int32_t OnAppInstall(const std::string &bundleName, int32_t user, int32_t index) override; int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index) override; + private: + bool CloudDriverCheck(const std::string &bundleName, int32_t user); }; class Factory { public: @@ -197,12 +199,14 @@ private: using SaveStrategy = int32_t (*)(const std::vector &values, const HapInfo &hapInfo); static const SaveStrategy STRATEGY_SAVERS[Strategy::STRATEGY_BUTT]; static int32_t SaveNetworkStrategy(const std::vector &values, const HapInfo &hapInfo); - void Report(const std::string &faultType, DistributedDataDfx::Fault errCode, const std::string &bundleName, + static void Report(const std::string &faultType, DistributedDataDfx::Fault errCode, const std::string &bundleName, const std::string &appendix); static std::pair GetSchemaFromHap(const HapInfo &hapInfo); static int32_t UpdateSchemaFromHap(const HapInfo &hapInfo); static int32_t UpdateSchemaFromServer(int32_t user); + static int32_t UpdateSchemaFromServer(const CloudInfo &cloudInfo, int32_t user); + static void UpdateE2eeEnable(const std::string &schemaKey, bool newE2eeEnable, const std::string &bundleName); static void UpdateClearWaterMark( const HapInfo &hapInfo, const SchemaMeta &newSchemaMeta, const SchemaMeta &schemaMeta); QueryLastResults AssembleLastResults(const std::vector &databases, diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index f0d77767c..26debbacb 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -660,9 +660,8 @@ std::pair SyncManager::GetStore(const StoreMetaData & } GeneralStore::CloudConfig config; if (MetaDataManager::GetInstance().LoadMeta(info.GetKey(), info, true)) { - config.maxNumber = info.maxNumber; - config.maxSize = info.maxSize; - config.isSupportEncrypt = schemaMeta.e2eeEnable; + config = { .maxNumber = info.maxNumber, .maxSize = info.maxSize, + .isSupportEncrypt = schemaMeta.e2eeEnable }; } store->Bind(dbMeta, bindInfos, config); } diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index c9a6e00fa..3012d81d8 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -243,6 +243,7 @@ void CloudDataTest::InitSchemaMeta() schemaMeta_.databases.emplace_back(database); database.alias = TEST_CLOUD_DATABASE_ALIAS_2; schemaMeta_.databases.emplace_back(database); + schemaMeta_.e2eeEnable = false; } void CloudDataTest::InitCloudInfo() diff --git a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp index 08aea3fe6..1c67d47fc 100644 --- a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp @@ -326,6 +326,105 @@ HWTEST_F(CloudServiceImplTest, DoSubscribe, TestSize.Level0) EXPECT_TRUE(status); } +/** + * @tc.name: OnAppInstallTest + * @tc.desc: Test the OnAppInstallTest + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, OnAppInstallTest, TestSize.Level0) +{ + ZLOGI("CloudServiceImplTest OnAppInstallTest start"); + ASSERT_NE(cloudServiceImpl_, nullptr); + ASSERT_NE(cloudServiceImpl_->factory_.staticActs_, nullptr); + int32_t user = 0; + int32_t index = 0; + auto status = cloudServiceImpl_->factory_.staticActs_->OnAppInstall(TEST_CLOUD_BUNDLE, user, index); + EXPECT_EQ(status, GeneralError::E_ERROR); +} + +/** + * @tc.name: OnAppUpdateTest + * @tc.desc: Test the OnAppUpdateTest + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, OnAppUpdateTest, TestSize.Level0) +{ + ZLOGI("CloudServiceImplTest OnAppUpdateTest start"); + ASSERT_NE(cloudServiceImpl_, nullptr); + ASSERT_NE(cloudServiceImpl_->factory_.staticActs_, nullptr); + int32_t user = 0; + int32_t index = 0; + auto status = cloudServiceImpl_->factory_.staticActs_->OnAppUpdate(TEST_CLOUD_BUNDLE, user, index); + EXPECT_EQ(status, CloudData::CloudService::SUCCESS); +} + +/** + * @tc.name: CloudDriverCheckTest + * @tc.desc: Test the CloudDriverCheck + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, CloudDriverCheckTest, TestSize.Level0) +{ + ZLOGI("CloudServiceImplTest CloudDriverCheckTest start"); + ASSERT_NE(cloudServiceImpl_, nullptr); + ASSERT_NE(cloudServiceImpl_->factory_.staticActs_, nullptr); + int32_t user = 0; + auto result = cloudServiceImpl_->factory_.staticActs_->CloudDriverCheck(TEST_CLOUD_BUNDLE, user); + EXPECT_EQ(result, false); +} + +/** + * @tc.name: UpdateSchemaFromServerTest_001 + * @tc.desc: Test UpdateSchemaFromServer functions + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, UpdateSchemaFromServerTest_001, TestSize.Level0) +{ + ZLOGI("CloudServiceImplTest UpdateSchemaFromServerTest_001 start"); + CloudServer cloudServer; + CloudServer::RegisterCloudInstance(&cloudServer); + int user = 100; + auto status = cloudServiceImpl_->UpdateSchemaFromServer(user); + EXPECT_EQ(status, CloudData::CloudService::ERROR); + CloudServer::instance_ = nullptr; +} + +/** + * @tc.name: UpdateSchemaFromServerTest_002 + * @tc.desc: Test UpdateSchemaFromServer functions. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, UpdateSchemaFromServerTest_002, TestSize.Level0) +{ + ZLOGI("CloudServiceImplTest UpdateSchemaFromServerTest_002 start"); + CloudServer cloudServer; + CloudServer::RegisterCloudInstance(&cloudServer); + int user = 0; + CloudInfo cloudInfo; + cloudInfo.user = user; + auto status = cloudServiceImpl_->UpdateSchemaFromServer(cloudInfo, user); + EXPECT_EQ(status, CloudData::CloudService::SUCCESS); + CloudServer::instance_ = nullptr; +} + +/** + * @tc.name: UpdateE2eeEnableTest + * @tc.desc: Test UpdateE2eeEnable functions. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, UpdateE2eeEnableTest, TestSize.Level0) +{ + ZLOGI("CloudServiceImplTest UpdateE2eeEnableTest start"); + std::string schemaKey = "schemaKey"; + EXPECT_NO_FATAL_FAILURE(cloudServiceImpl_->UpdateE2eeEnable(schemaKey, true, TEST_CLOUD_BUNDLE)); +} + /** * @tc.name: Share001 * @tc.desc: Test the Share with invalid parameters -- Gitee From 155041d6a0cda403673f80a79ce0f7343ea5f2c9 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Thu, 19 Jun 2025 15:22:23 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=A1=A5=E5=85=85TDD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../service/test/cloud_data_test.cpp | 78 +++++++++++++++++-- .../service/test/cloud_service_impl_test.cpp | 5 ++ 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 3012d81d8..68e6bbf49 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -1059,7 +1059,7 @@ HWTEST_F(CloudDataTest, SetCloudStrategy001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync001, TestSize.Level1) +HWTEST_F(CloudDataTest, CloudSync001, TestSize.Level0) { int32_t syncMode = DistributedData::GeneralStore::NEARBY_BEGIN; uint32_t seqNum = 10; @@ -1074,7 +1074,7 @@ HWTEST_F(CloudDataTest, CloudSync001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync002, TestSize.Level1) +HWTEST_F(CloudDataTest, CloudSync002, TestSize.Level0) { int32_t syncMode = DistributedData::GeneralStore::NEARBY_PULL_PUSH; uint32_t seqNum = 10; @@ -1089,7 +1089,7 @@ HWTEST_F(CloudDataTest, CloudSync002, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level1) +HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level0) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_BEGIN; uint32_t seqNum = 10; @@ -1103,7 +1103,7 @@ HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level1) +HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level0) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_TIME_FIRST; uint32_t seqNum = 10; @@ -1117,7 +1117,7 @@ HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level1) +HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level0) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_NATIVE_FIRST; uint32_t seqNum = 10; @@ -1131,7 +1131,7 @@ HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync006, TestSize.Level1) +HWTEST_F(CloudDataTest, CloudSync006, TestSize.Level0) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_CLOUD_FIRST; uint32_t seqNum = 10; @@ -1145,7 +1145,7 @@ HWTEST_F(CloudDataTest, CloudSync006, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync007, TestSize.Level1) +HWTEST_F(CloudDataTest, CloudSync007, TestSize.Level0) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_END; uint32_t seqNum = 10; @@ -1159,7 +1159,7 @@ HWTEST_F(CloudDataTest, CloudSync007, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, InitNotifier001, TestSize.Level1) +HWTEST_F(CloudDataTest, InitNotifier001, TestSize.Level0) { sptr notifier = nullptr; auto ret = cloudServiceImpl_->InitNotifier(notifier); @@ -2158,6 +2158,68 @@ HWTEST_F(CloudDataTest, GetCloudInfo, TestSize.Level1) EXPECT_EQ(ret.first, CloudData::SUCCESS); } +/** +* @tc.name: UpdateSchemaFromServer_001 +* @tc.desc: Test get UpdateSchemaFromServer +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, UpdateSchemaFromServer_001, TestSize.Level1) +{ + auto status = cloudServiceImpl_->UpdateSchemaFromServer(cloudInfo_.user); + EXPECT_EQ(status, CloudData::SUCCESS); +} + +/** + * @tc.name: OnAppInstallTest + * @tc.desc: Test the OnAppInstallTest + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, OnAppInstallTest, TestSize.Level1) +{ + ZLOGI("CloudServiceImplTest OnAppInstallTest start"); + ASSERT_NE(cloudServiceImpl_, nullptr); + ASSERT_NE(cloudServiceImpl_->factory_.staticActs_, nullptr); + int32_t index = 0; + auto status = cloudServiceImpl_->factory_.staticActs_->OnAppInstall(TEST_CLOUD_BUNDLE, cloudInfo_.user, index); + EXPECT_EQ(status, GeneralError::E_OK); +} + +/** + * @tc.name: OnAppUpdateTest + * @tc.desc: Test the OnAppUpdateTest + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(CloudServiceImplTest, OnAppUpdateTest, TestSize.Level1) +{ + ZLOGI("CloudServiceImplTest OnAppUpdateTest start"); + ASSERT_NE(cloudServiceImpl_, nullptr); + ASSERT_NE(cloudServiceImpl_->factory_.staticActs_, nullptr); + int32_t index = 0; + auto status = cloudServiceImpl_->factory_.staticActs_->OnAppUpdate(TEST_CLOUD_BUNDLE, cloudInfo_.user, index); + EXPECT_EQ(status, CloudData::CloudService::SUCCESS); +} + +/** +* @tc.name: UpdateE2eeEnableTest +* @tc.desc: Test the UpdateE2eeEnable +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(CloudDataTest, UpdateE2eeEnableTest, TestSize.Level1) +{ + SchemaMeta schemaMeta; + std::string schemaKey = CloudInfo::GetSchemaKey(cloudInfo_.user, TEST_CLOUD_BUNDLE, 0); + ASSERT_TRUE(MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true)); + EXPECT_EQ(schemaMeta.e2eeEnable, schemaMeta_.e2eeEnable); + + ASSERT_NE(cloudServiceImpl_, nullptr); + EXPECT_NO_FATAL_FAILURE(cloudServiceImpl_->UpdateE2eeEnable(schemaKey, false, TEST_CLOUD_BUNDLE)); + EXPECT_NO_FATAL_FAILURE(cloudServiceImpl_->UpdateE2eeEnable(schemaKey, true, TEST_CLOUD_BUNDLE)); +} + /** * @tc.name: SubTask * @tc.desc: Test the subtask execution logic diff --git a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp index 1c67d47fc..96c993a88 100644 --- a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp @@ -407,6 +407,11 @@ HWTEST_F(CloudServiceImplTest, UpdateSchemaFromServerTest_002, TestSize.Level0) int user = 0; CloudInfo cloudInfo; cloudInfo.user = user; + DistributedData::CloudInfo::AppInfo appInfo; + appInfo.bundleName = TEST_CLOUD_BUNDLE; + appInfo.appId = TEST_CLOUD_APPID; + appInfo.cloudSwitch = true; + cloudInfo.apps = {{ TEST_CLOUD_BUNDLE, appInfo }}; auto status = cloudServiceImpl_->UpdateSchemaFromServer(cloudInfo, user); EXPECT_EQ(status, CloudData::CloudService::SUCCESS); CloudServer::instance_ = nullptr; -- Gitee From 9e83e7bb94de949837b9b03644ec2b1296146c24 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Thu, 19 Jun 2025 17:29:13 +0800 Subject: [PATCH 4/5] cloud driver update Signed-off-by: Hollokin --- .../framework/cloud/cloud_server.cpp | 5 +++++ .../framework/include/cloud/cloud_server.h | 1 + .../service/cloud/cloud_service_impl.cpp | 14 +++++++------- .../service/test/cloud_data_test.cpp | 16 ++++++++-------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_server.cpp b/services/distributeddataservice/framework/cloud/cloud_server.cpp index 2841cf0b2..5d718ee74 100644 --- a/services/distributeddataservice/framework/cloud/cloud_server.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_server.cpp @@ -87,4 +87,9 @@ bool CloudServer::IsSupportCloud(int32_t userId) { return false; } + +bool CloudServer::CloudDriverUpdated(const std::string &bundleName) +{ + return false; +} } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/cloud/cloud_server.h b/services/distributeddataservice/framework/include/cloud/cloud_server.h index 9cb060c81..0d87d0261 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_server.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_server.h @@ -43,6 +43,7 @@ public: virtual void ReleaseUserInfo(int32_t userId); virtual void Bind(std::shared_ptr executor); virtual bool IsSupportCloud(int32_t userId); + virtual bool CloudDriverUpdated(const std::string &bundleName); private: static CloudServer *instance_; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index bb70a274e..593986a3d 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -967,8 +967,8 @@ void CloudServiceImpl::UpdateE2eeEnable(const std::string &schemaKey, bool newE2 } ZLOGI("Update e2eeEnable: %{public}d->%{public}d", oldMeta.e2eeEnable, newE2eeEnable); oldMeta.e2eeEnable = newE2eeEnable; - Report(FT_ENCRYPT_CHANGED, Fault::CSFAPP_SCHEMA, bundleName, - "oldE2eeEnable=" + std::to_string(oldMeta.e2eeEnable) + ",newE2eeEnable" + std::to_string(newE2eeEnable)); + Report(FT_ENCRYPT_CHANGED, Fault::CSF_APP_SCHEMA, bundleName, + "oldE2eeEnable=" + std::to_string(oldMeta.e2eeEnable) + ",newE2eeEnable=" + std::to_string(newE2eeEnable)); MetaDataManager::GetInstance().SaveMeta(schemaKey, oldMeta, true); } @@ -1153,11 +1153,11 @@ int32_t CloudServiceImpl::CloudStatic::OnAppUpdate(const std::string &bundleName bool CloudServiceImpl::CloudStatic::CloudDriverCheck(const std::string &bundleName, int32_t user) { - CheckerManager::StoreInfo info; - info.uid = IPCSkeleton::GetCallingUid(); - info.tokenId = IPCSkeleton::GetCallingTokenID(); - info.bundleName = bundleName; - if (CheckerManager::GetInstance().IsValid(info)) { + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + return false; + } + if (instance->CloudDriverUpdated(bundleName)) { // cloudDriver install, update schema(for update 'e2eeEnable') ZLOGI("cloud driver check valid, bundleName:%{public}s, user:%{public}d", bundleName.c_str(), user); Execute([this, user]() { UpdateSchemaFromServer(user); }); diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 68e6bbf49..ce7e8d8c8 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -1089,7 +1089,7 @@ HWTEST_F(CloudDataTest, CloudSync002, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level0) +HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level1) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_BEGIN; uint32_t seqNum = 10; @@ -1103,7 +1103,7 @@ HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level0) +HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level1) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_TIME_FIRST; uint32_t seqNum = 10; @@ -1117,7 +1117,7 @@ HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level0) +HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level1) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_NATIVE_FIRST; uint32_t seqNum = 10; @@ -1131,7 +1131,7 @@ HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level0) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudDataTest, CloudSync006, TestSize.Level0) +HWTEST_F(CloudDataTest, CloudSync006, TestSize.Level1) { int32_t syncMode = DistributedData::GeneralStore::CLOUD_CLOUD_FIRST; uint32_t seqNum = 10; @@ -2176,9 +2176,9 @@ HWTEST_F(CloudDataTest, UpdateSchemaFromServer_001, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudServiceImplTest, OnAppInstallTest, TestSize.Level1) +HWTEST_F(CloudDataTest, OnAppInstallTest, TestSize.Level1) { - ZLOGI("CloudServiceImplTest OnAppInstallTest start"); + ZLOGI("CloudDataTest OnAppInstallTest start"); ASSERT_NE(cloudServiceImpl_, nullptr); ASSERT_NE(cloudServiceImpl_->factory_.staticActs_, nullptr); int32_t index = 0; @@ -2192,9 +2192,9 @@ HWTEST_F(CloudServiceImplTest, OnAppInstallTest, TestSize.Level1) * @tc.type: FUNC * @tc.require: */ -HWTEST_F(CloudServiceImplTest, OnAppUpdateTest, TestSize.Level1) +HWTEST_F(CloudDataTest, OnAppUpdateTest, TestSize.Level1) { - ZLOGI("CloudServiceImplTest OnAppUpdateTest start"); + ZLOGI("CloudDataTest OnAppUpdateTest start"); ASSERT_NE(cloudServiceImpl_, nullptr); ASSERT_NE(cloudServiceImpl_->factory_.staticActs_, nullptr); int32_t index = 0; -- Gitee From b7bbee927a3f856bb5e2a0b0b9258382ec7e71a1 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Sat, 21 Jun 2025 11:36:16 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=B6=85=E5=A4=A7=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../service/cloud/cloud_service_impl.cpp | 2 +- .../distributeddataservice/service/cloud/sync_manager.cpp | 6 +++--- .../service/test/cloud_service_impl_test.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 593986a3d..4404b855a 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -931,7 +931,7 @@ int32_t CloudServiceImpl::UpdateSchemaFromServer(int32_t user) { auto [status, cloudInfo] = GetCloudInfo(user); if (status != SUCCESS) { - ZLOGW("get cloudinfo failed, user:%{public}d, status:%{public}d", user, status); + ZLOGW("get cloud info failed, user:%{public}d, status:%{public}d", user, status); return status; } return UpdateSchemaFromServer(cloudInfo, user); diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 26debbacb..035002582 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -623,7 +623,6 @@ std::pair SyncManager::GetStore(const StoreMetaData & return { E_USER_UNLOCK, nullptr }; } if (CloudServer::GetInstance() == nullptr) { - ZLOGD("not support cloud sync"); return { E_NOT_SUPPORT, nullptr }; } auto [status, store] = AutoCache::GetInstance().GetDBStore(meta, {}); @@ -660,8 +659,9 @@ std::pair SyncManager::GetStore(const StoreMetaData & } GeneralStore::CloudConfig config; if (MetaDataManager::GetInstance().LoadMeta(info.GetKey(), info, true)) { - config = { .maxNumber = info.maxNumber, .maxSize = info.maxSize, - .isSupportEncrypt = schemaMeta.e2eeEnable }; + config.maxNumber = info.maxNumber; + config.maxSize = info.maxSize; + config.isSupportEncrypt = schemaMeta.e2eeEnable; } store->Bind(dbMeta, bindInfos, config); } diff --git a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp index 96c993a88..253832a64 100644 --- a/services/distributeddataservice/service/test/cloud_service_impl_test.cpp +++ b/services/distributeddataservice/service/test/cloud_service_impl_test.cpp @@ -389,7 +389,7 @@ HWTEST_F(CloudServiceImplTest, UpdateSchemaFromServerTest_001, TestSize.Level0) CloudServer::RegisterCloudInstance(&cloudServer); int user = 100; auto status = cloudServiceImpl_->UpdateSchemaFromServer(user); - EXPECT_EQ(status, CloudData::CloudService::ERROR); + EXPECT_EQ(status, E_ERROR); CloudServer::instance_ = nullptr; } -- Gitee