diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index dc109463a23646ff36efa977381f77d7c0694f63..7f1d83b3df1bf1d8df23abbf7c8c6bf0992d0fc1 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -45,7 +45,7 @@ public: CLOUD_BEGIN = 4, CLOUD_TIME_FIRST = CLOUD_BEGIN, CLOUD_NATIVE_FIRST, - CLOUD_ClOUD_FIRST, + CLOUD_CLOUD_FIRST, CLOUD_END, NEARBY_SUBSCRIBE_REMOTE, NEARBY_UNSUBSCRIBE_REMOTE, diff --git a/services/distributeddataservice/service/cloud/BUILD.gn b/services/distributeddataservice/service/cloud/BUILD.gn index b36909c07967979acfa47d36caaf246362aaaa40..3da5401eb4400aaf0388d6de082d134bcbc2e5d4 100755 --- a/services/distributeddataservice/service/cloud/BUILD.gn +++ b/services/distributeddataservice/service/cloud/BUILD.gn @@ -28,6 +28,7 @@ ohos_source_set("distributeddata_cloud") { } sources = [ "cloud_data_translate.cpp", + "cloud_notifier_proxy.cpp", "cloud_service_impl.cpp", "cloud_service_stub.cpp", "cloud_types_util.cpp", diff --git a/services/distributeddataservice/service/cloud/cloud_notifier_proxy.cpp b/services/distributeddataservice/service/cloud/cloud_notifier_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..40d39763e256ef88b3e02e4298fb1dc344d66662 --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_notifier_proxy.cpp @@ -0,0 +1,59 @@ +/* + * 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 "CloudNotifierProxy" + +#include "cloud_notifier_proxy.h" + +#include "cloud_service.h" +#include "itypes_util.h" +#include "log_print.h" +#include "utils/anonymous.h" + +namespace OHOS::CloudData { +using namespace DistributedRdb; +using NotifierCode = RelationalStore::ICloudNotifierInterfaceCode; + +CloudNotifierProxy::CloudNotifierProxy(const sptr &object) + : IRemoteProxy(object) +{} + +CloudNotifierProxy::~CloudNotifierProxy() noexcept {} + +int32_t CloudNotifierProxy::OnComplete(uint32_t seqNum, DistributedRdb::Details &&result) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + ZLOGE("write descriptor failed"); + return CloudService::IPC_PARCEL_ERROR; + } + if (!ITypesUtil::Marshal(data, seqNum, result)) { + return CloudService::IPC_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + auto remote = Remote(); + if (remote == nullptr) { + ZLOGE("get remote failed, seqNum:%{public}u", seqNum); + return CloudService::IPC_ERROR; + } + auto status = remote->SendRequest(static_cast(NotifierCode::CLOUD_NOTIFIER_CMD_SYNC_COMPLETE), + data, reply, option); + if (status != CloudService::SUCCESS) { + ZLOGE("seqNum:%{public}u, send request failed, status:%{public}d", seqNum, status); + } + return status; +} +} // namespace OHOS::CloudData diff --git a/services/distributeddataservice/service/cloud/cloud_notifier_proxy.h b/services/distributeddataservice/service/cloud/cloud_notifier_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..97829ba0ce3f082d1a1e4ccedd5f49b1cbf56465 --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_notifier_proxy.h @@ -0,0 +1,41 @@ +/* + * 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_CLOUD_CLOUD_NOTIFIER_PROXY_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_NOTIFIER_PROXY_H + +#include +#include + +#include "cloud_notifier.h" + +namespace OHOS::CloudData { +class CloudNotifierProxyBroker : public ICloudNotifier, public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.CloudData.ICloudNotifier"); +}; + +class CloudNotifierProxy : public IRemoteProxy { +public: + explicit CloudNotifierProxy(const sptr& object); + virtual ~CloudNotifierProxy() noexcept; + + int32_t OnComplete(uint32_t seqNum, DistributedRdb::Details &&result) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::CloudData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_NOTIFIER_PROXY_H diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index f566532a7a43f64a9e30fe5dc6a2640b213e23e2..dfdc9ecc8b89972539ea816685cbfbb9516d853e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -23,6 +23,7 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "checker/checker_manager.h" +#include "cloud/change_event.h" #include "cloud/cloud_last_sync_info.h" #include "cloud/cloud_mark.h" #include "cloud/cloud_server.h" @@ -48,6 +49,7 @@ #include "sync_manager.h" #include "sync_strategies/network_sync_strategy.h" #include "utils/anonymous.h" +#include "utils/constant.h" #include "values_bucket.h" #include "xcollie.h" @@ -1231,6 +1233,76 @@ bool CloudServiceImpl::ReleaseUserInfo(int32_t user, CloudSyncScene scene) return true; } +int32_t CloudServiceImpl::InitNotifier(sptr notifier) +{ + if (notifier == nullptr) { + ZLOGE("no notifier."); + return INVALID_ARGUMENT; + } + auto notifierProxy = iface_cast(notifier); + uint32_t tokenId = IPCSkeleton::GetCallingTokenID(); + syncAgents_.Compute(tokenId, [notifierProxy](auto, SyncAgent &agent) { + agent = SyncAgent(); + agent.notifier_ = notifierProxy; + return true; + }); + return SUCCESS; +} + +Details CloudServiceImpl::HandleGenDetails(const GenDetails &details) +{ + Details dbDetails; + for (const auto& [id, detail] : details) { + auto &dbDetail = dbDetails[id]; + dbDetail.progress = detail.progress; + dbDetail.code = detail.code; + for (auto &[name, table] : detail.details) { + auto &dbTable = dbDetail.details[name]; + Constant::Copy(&dbTable, &table); + } + } + return dbDetails; +} + +void CloudServiceImpl::OnAsyncComplete(uint32_t tokenId, uint32_t seqNum, Details &&result) +{ + ZLOGI("tokenId=%{public}x, seqnum=%{public}u", tokenId, seqNum); + sptr notifier = nullptr; + syncAgents_.ComputeIfPresent(tokenId, [¬ifier](auto, SyncAgent &syncAgent) { + notifier = syncAgent.notifier_; + return true; + }); + if (notifier != nullptr) { + notifier->OnComplete(seqNum, std::move(result)); + } +} + +int32_t CloudServiceImpl::CloudSync(const std::string &bundleName, const std::string &storeId, + const Option &option, const AsyncDetail &async) +{ + if (option.syncMode < DistributedData::GeneralStore::CLOUD_BEGIN || + option.syncMode >= DistributedData::GeneralStore::CLOUD_END) { + ZLOGE("not support cloud sync, syncMode = %{public}d", option.syncMode); + return INVALID_ARGUMENT; + } + StoreInfo storeInfo; + storeInfo.bundleName = bundleName; + storeInfo.tokenId = IPCSkeleton::GetCallingTokenID(); + storeInfo.user = AccountDelegate::GetInstance()->GetUserByToken(storeInfo.tokenId); + storeInfo.storeName = storeId; + GenAsync asyncCallback = + [this, tokenId = storeInfo.tokenId, seqNum = option.seqNum](const GenDetails &result) mutable { + OnAsyncComplete(tokenId, seqNum, HandleGenDetails(result)); + }; + auto highMode = GeneralStore::MANUAL_SYNC_MODE; + auto mixMode = static_cast(GeneralStore::MixMode(option.syncMode, highMode)); + SyncParam syncParam = { mixMode, 0, false }; + auto info = ChangeEvent::EventInfo(syncParam, false, nullptr, asyncCallback); + auto evt = std::make_unique(std::move(storeInfo), std::move(info)); + EventCenter::GetInstance().PostEvent(std::move(evt)); + return SUCCESS; +} + bool CloudServiceImpl::DoCloudSync(int32_t user, CloudSyncScene scene) { auto [status, cloudInfo] = GetCloudInfo(user); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index d0242197b58ce03ba8dd05b9fb80a30f6b25c254..271627229a7ba6c5ac471add5935c537a87e38c3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -22,6 +22,7 @@ #include "cloud/cloud_event.h" #include "cloud/cloud_extra_data.h" #include "cloud/cloud_info.h" +#include "cloud_notifier_proxy.h" #include "cloud/schema_meta.h" #include "cloud/sharing_center.h" #include "cloud/subscription.h" @@ -33,6 +34,7 @@ #include "values_bucket.h" namespace OHOS::CloudData { +using namespace DistributedRdb; class CloudServiceImpl : public CloudServiceStub { public: using CloudLastSyncInfo = DistributedData::CloudLastSyncInfo; @@ -51,6 +53,9 @@ public: std::pair QueryLastSyncInfo( const std::string &id, const std::string &bundleName, const std::string &storeId) override; int32_t SetGlobalCloudStrategy(Strategy strategy, const std::vector &values) override; + int32_t CloudSync(const std::string &bundleName, const std::string &storeId, const Option &option, + const AsyncDetail &async) override; + int32_t InitNotifier(sptr notifier) override; std::pair> AllocResourceAndShare(const std::string &storeId, const DistributedRdb::PredicatesMemo &predicates, const std::vector &columns, @@ -126,6 +131,11 @@ private: std::string bundleName; }; + struct SyncAgent { + SyncAgent() = default; + sptr notifier_; + }; + static std::map ConvertAction(const std::map &actions); static HapInfo GetHapInfo(uint32_t tokenId); static std::string GetDfxFaultType(CloudSyncScene scene); @@ -152,7 +162,9 @@ private: static std::pair GetCloudInfoFromServer(int32_t userId); static int32_t UpdateCloudInfoFromServer(int32_t user); static std::pair GetAppSchemaFromServer(int32_t user, const std::string &bundleName); + static Details HandleGenDetails(const DistributedData::GenDetails &details); + void OnAsyncComplete(uint32_t tokenId, uint32_t seqNum, Details &&result); std::pair GetSchemaMeta(int32_t userId, const std::string &bundleName, int32_t instanceId); void UpgradeSchemaMeta(int32_t user, const SchemaMeta &schemaMeta); std::map ExecuteStatistics( @@ -203,6 +215,7 @@ private: uint64_t expireTime_ = static_cast( std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) .count()); + ConcurrentMap syncAgents_; static constexpr Handle WORK_CLOUD_INFO_UPDATE = &CloudServiceImpl::UpdateCloudInfo; static constexpr Handle WORK_SCHEMA_UPDATE = &CloudServiceImpl::UpdateSchema; diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index ace668b55e88bc646a91010ff1327d23a697f28a..f1a2fd85f4f115b69cf966026907cc98f0834040 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -36,6 +36,7 @@ const CloudServiceStub::Handler CloudServiceStub::HANDLERS[TRANS_BUTT] = { &CloudServiceStub::OnQueryStatistics, &CloudServiceStub::OnQueryLastSyncInfo, &CloudServiceStub::OnSetGlobalCloudStrategy, + &CloudServiceStub::OnCloudSync, &CloudServiceStub::OnAllocResourceAndShare, &CloudServiceStub::OnShare, &CloudServiceStub::OnUnshare, @@ -46,6 +47,7 @@ const CloudServiceStub::Handler CloudServiceStub::HANDLERS[TRANS_BUTT] = { &CloudServiceStub::OnConfirmInvitation, &CloudServiceStub::OnChangeConfirmation, &CloudServiceStub::OnSetCloudStrategy, + &CloudServiceStub::OnInitNotifier, }; int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) @@ -326,4 +328,29 @@ int32_t CloudServiceStub::OnSetCloudStrategy(MessageParcel &data, MessageParcel auto status = SetCloudStrategy(strategy, values); return ITypesUtil::Marshal(reply, status) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; } + +int32_t CloudServiceStub::OnCloudSync(MessageParcel &data, MessageParcel &reply) +{ + std::string bundleName; + std::string storeId; + Option option; + if (!ITypesUtil::Unmarshal(data, bundleName, storeId, option)) { + ZLOGE("Unmarshal failed, bundleName:%{public}s, storeId:%{public}s, syncMode:%{public}d, seqNum:%{public}u", + bundleName.c_str(), Anonymous::Change(storeId).c_str(), option.syncMode, option.seqNum); + return IPC_STUB_INVALID_DATA_ERR; + } + auto status = CloudSync(bundleName, storeId, option, nullptr); + return ITypesUtil::Marshal(reply, status) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} + +int32_t CloudServiceStub::OnInitNotifier(MessageParcel &data, MessageParcel &reply) +{ + sptr notifier = nullptr; + if (!ITypesUtil::Unmarshal(data, notifier) || notifier == nullptr) { + ZLOGE("Unmarshal failed, notifier is nullptr?[%{public}u]", notifier == nullptr); + return IPC_STUB_INVALID_DATA_ERR; + } + auto status = InitNotifier(notifier); + return ITypesUtil::Marshal(reply, status) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.h b/services/distributeddataservice/service/cloud/cloud_service_stub.h index 5f51fe846ee8bb27c0e04e689e84d22d01f63b6a..ea1d57bd42974a5aee27dfc50ccb9eb42dac9601 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.h +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.h @@ -37,6 +37,7 @@ private: int32_t OnQueryStatistics(MessageParcel &data, MessageParcel &reply); int32_t OnQueryLastSyncInfo(MessageParcel &data, MessageParcel &reply); int32_t OnSetGlobalCloudStrategy(MessageParcel &data, MessageParcel &reply); + int32_t OnCloudSync(MessageParcel &data, MessageParcel &reply); int32_t OnAllocResourceAndShare(MessageParcel &data, MessageParcel &reply); int32_t OnShare(MessageParcel &data, MessageParcel &reply); @@ -49,6 +50,7 @@ private: int32_t OnChangeConfirmation(MessageParcel &data, MessageParcel &reply); int32_t OnSetCloudStrategy(MessageParcel &data, MessageParcel &reply); + int32_t OnInitNotifier(MessageParcel &data, MessageParcel &reply); static const Handler HANDLERS[TRANS_BUTT]; }; } // namespace OHOS::CloudData diff --git a/services/distributeddataservice/service/cloud/cloud_types_util.cpp b/services/distributeddataservice/service/cloud/cloud_types_util.cpp index 116d1b72eeb44a388b33462cfd699aeb6c8cd0bb..cc6aa141e21029c1480576d26e6437a6d31e3c4a 100644 --- a/services/distributeddataservice/service/cloud/cloud_types_util.cpp +++ b/services/distributeddataservice/service/cloud/cloud_types_util.cpp @@ -109,4 +109,16 @@ bool Unmarshalling(CloudSyncInfo &output, MessageParcel &data) { return Unmarshal(data, output.startTime, output.finishTime, output.code, output.syncStatus); } + +template<> +bool Marshalling(const Option &input, MessageParcel &data) +{ + return Marshal(data, input.syncMode, input.seqNum); +} + +template<> +bool Unmarshalling(Option &output, MessageParcel &data) +{ + return Unmarshal(data, output.syncMode, output.seqNum); +} } // namespace OHOS::ITypesUtil \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_types_util.h b/services/distributeddataservice/service/cloud/cloud_types_util.h index 7a53f6938a15cb195dd299992813811ab26295c3..e4c029956f4949532d459be215922d364e2bf525 100644 --- a/services/distributeddataservice/service/cloud/cloud_types_util.h +++ b/services/distributeddataservice/service/cloud/cloud_types_util.h @@ -17,6 +17,7 @@ #define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_TYPES_UTIL_H #include "cloud_types.h" +#include "cloud_service.h" #include "itypes_util.h" #include "values_bucket.h" @@ -32,6 +33,7 @@ using ValuesBucket = OHOS::NativeRdb::ValuesBucket; using StatisticInfo = OHOS::CloudData::StatisticInfo; using Strategy = OHOS::CloudData::Strategy; using CloudSyncInfo = OHOS::CloudData::CloudSyncInfo; +using Option = OHOS::CloudData::CloudService::Option; template<> bool Marshalling(const Participant &input, MessageParcel &data); @@ -68,5 +70,10 @@ template<> bool Marshalling(const CloudSyncInfo &input, MessageParcel &data); template<> bool Unmarshalling(CloudSyncInfo &output, MessageParcel &data); + +template<> +bool Marshalling(const Option &input, MessageParcel &data); +template<> +bool Unmarshalling(Option &output, MessageParcel &data); } // namespace OHOS::ITypesUtil #endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_TYPES_UTIL_H \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index dd7c60f61e9292a3b8aa0fe2c2db345c3ad01a36..9ba84ff176cf6640a61182b161663fb186409951 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -59,7 +59,6 @@ public: bool IsBound(uint32_t user) override; bool IsValid(); int32_t Execute(const std::string &table, const std::string &sql) override; - int32_t SetReference(const std::vector &references); int32_t SetDistributedTables(const std::vector &tables, int32_t type, const std::vector &references) override; int32_t SetTrackerTable(const std::string& tableName, const std::set& trackerColNames, @@ -94,6 +93,7 @@ public: private: RdbGeneralStore(const RdbGeneralStore& rdbGeneralStore); RdbGeneralStore& operator=(const RdbGeneralStore& rdbGeneralStore); + int32_t SetReference(const std::vector &references); using RdbDelegate = DistributedDB::RelationalStoreDelegate; using RdbManager = DistributedDB::RelationalStoreManager; using SyncProcess = DistributedDB::SyncProcess; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index d93120bba52cb25fd27655f65ed65ca50f474b4c..9e15dd01ba63ae067786ab4888b6b476583cade9 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -605,7 +605,7 @@ void RdbServiceImpl::DoCloudSync(const RdbSyncerParam ¶m, const RdbService:: async(HandleGenDetails(details)); } }; - auto highMode = (!predicates.tables_.empty() && option.mode == DistributedData::GeneralStore::CLOUD_ClOUD_FIRST) + 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); auto mixMode = static_cast(GeneralStore::MixMode(option.mode, highMode)); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index e9d0d0a84bfb23523fe8678f0c72907a5725c0f8..b741c1dc2f91b76e0398ac90187bdacac35f5b84 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -68,6 +68,7 @@ ohos_unittest("CloudDataTest") { module_out_path = module_output_path sources = [ "${data_service_path}/service/cloud/cloud_data_translate.cpp", + "${data_service_path}/service/cloud/cloud_notifier_proxy.cpp", "${data_service_path}/service/cloud/cloud_service_impl.cpp", "${data_service_path}/service/cloud/cloud_service_stub.cpp", "${data_service_path}/service/cloud/cloud_types_util.cpp", @@ -120,6 +121,7 @@ ohos_unittest("CloudServiceImplTest") { module_out_path = module_output_path sources = [ "${data_service_path}/service/cloud/cloud_data_translate.cpp", + "${data_service_path}/service/cloud/cloud_notifier_proxy.cpp", "${data_service_path}/service/cloud/cloud_service_impl.cpp", "${data_service_path}/service/cloud/cloud_service_stub.cpp", "${data_service_path}/service/cloud/cloud_types_util.cpp", diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index fde1eea08bd49aed9a86aa3ba3278ec02e1a3562..86440d4ff66791e9438bda30b0824a2838e74d94 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -1045,6 +1045,122 @@ HWTEST_F(CloudDataTest, SetCloudStrategy001, TestSize.Level1) EXPECT_EQ(ret, CloudData::CloudService::SUCCESS); } +/** +* @tc.name: CloudSync001 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, CloudSync001, TestSize.Level1) +{ + int32_t syncMode = DistributedData::GeneralStore::NEARBY_BEGIN; + uint32_t seqNum = 10; + // invalid syncMode + auto ret = cloudServiceImpl_->CloudSync("bundleName", "storeId", { syncMode, seqNum }, nullptr); + EXPECT_EQ(ret, CloudData::CloudService::INVALID_ARGUMENT); +} + +/** +* @tc.name: CloudSync002 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, CloudSync002, TestSize.Level1) +{ + int32_t syncMode = DistributedData::GeneralStore::NEARBY_PULL_PUSH; + uint32_t seqNum = 10; + // invalid syncMode + auto ret = cloudServiceImpl_->CloudSync("bundleName", "storeId", { syncMode, seqNum }, nullptr); + EXPECT_EQ(ret, CloudData::CloudService::INVALID_ARGUMENT); +} + +/** +* @tc.name: CloudSync003 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, CloudSync003, TestSize.Level1) +{ + int32_t syncMode = DistributedData::GeneralStore::CLOUD_BEGIN; + uint32_t seqNum = 10; + auto ret = cloudServiceImpl_->CloudSync("bundleName", "storeId", { syncMode, seqNum }, nullptr); + EXPECT_EQ(ret, CloudData::CloudService::SUCCESS); +} + +/** +* @tc.name: CloudSync004 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, CloudSync004, TestSize.Level1) +{ + int32_t syncMode = DistributedData::GeneralStore::CLOUD_TIME_FIRST; + uint32_t seqNum = 10; + auto ret = cloudServiceImpl_->CloudSync("bundleName", "storeId", { syncMode, seqNum }, nullptr); + EXPECT_EQ(ret, CloudData::CloudService::SUCCESS); +} + +/** +* @tc.name: CloudSync005 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, CloudSync005, TestSize.Level1) +{ + int32_t syncMode = DistributedData::GeneralStore::CLOUD_NATIVE_FIRST; + uint32_t seqNum = 10; + auto ret = cloudServiceImpl_->CloudSync("bundleName", "storeId", { syncMode, seqNum }, nullptr); + EXPECT_EQ(ret, CloudData::CloudService::SUCCESS); +} + +/** +* @tc.name: CloudSync006 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, CloudSync006, TestSize.Level1) +{ + int32_t syncMode = DistributedData::GeneralStore::CLOUD_CLOUD_FIRST; + uint32_t seqNum = 10; + auto ret = cloudServiceImpl_->CloudSync("bundleName", "storeId", { syncMode, seqNum }, nullptr); + EXPECT_EQ(ret, CloudData::CloudService::SUCCESS); +} + +/** +* @tc.name: CloudSync007 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, CloudSync007, TestSize.Level1) +{ + int32_t syncMode = DistributedData::GeneralStore::CLOUD_END; + uint32_t seqNum = 10; + auto ret = cloudServiceImpl_->CloudSync("bundleName", "storeId", { syncMode, seqNum }, nullptr); + EXPECT_EQ(ret, CloudData::CloudService::INVALID_ARGUMENT); +} + +/** +* @tc.name: InitNotifier001 +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, InitNotifier001, TestSize.Level1) +{ + sptr notifier = nullptr; + auto ret = cloudServiceImpl_->InitNotifier(notifier); + EXPECT_EQ(ret, CloudData::CloudService::INVALID_ARGUMENT); + + ret = cloudServiceImpl_->InitNotifier(notifier); + EXPECT_EQ(ret, CloudData::CloudService::INVALID_ARGUMENT); +} + /** * @tc.name: Clean * @tc.desc: @@ -1700,6 +1816,51 @@ HWTEST_F(CloudDataTest, OnSetCloudStrategy, TestSize.Level0) EXPECT_EQ(ret, ERR_NONE); } +/** +* @tc.name: OnCloudSync +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, OnCloudSync, TestSize.Level0) +{ + MessageParcel reply; + MessageParcel data; + data.WriteInterfaceToken(cloudServiceImpl_->GetDescriptor()); + auto ret = cloudServiceImpl_->OnRemoteRequest(CloudData::CloudService::TRANS_CLOUD_SYNC, data, reply); + EXPECT_EQ(ret, IPC_STUB_INVALID_DATA_ERR); + data.WriteInterfaceToken(cloudServiceImpl_->GetDescriptor()); + std::string bundleName = "bundleName"; + std::string storeId = "storeId"; + CloudData::CloudService::Option option; + option.syncMode = 4; + option.seqNum = 1; + ITypesUtil::Marshal(data, bundleName, storeId, option); + ret = cloudServiceImpl_->OnRemoteRequest(CloudData::CloudService::TRANS_CLOUD_SYNC, data, reply); + EXPECT_EQ(ret, ERR_NONE); +} + +/** +* @tc.name: OnInitNotifier +* @tc.desc: +* @tc.type: FUNC +* @tc.require: + */ +HWTEST_F(CloudDataTest, OnInitNotifier, TestSize.Level0) +{ + MessageParcel reply; + MessageParcel data; + data.WriteInterfaceToken(cloudServiceImpl_->GetDescriptor()); + auto ret = cloudServiceImpl_->OnRemoteRequest(CloudData::CloudService::TRANS_INIT_NOTIFIER, data, reply); + EXPECT_EQ(ret, IPC_STUB_INVALID_DATA_ERR); + data.WriteInterfaceToken(cloudServiceImpl_->GetDescriptor()); + std::string bundleName = "bundleName"; + sptr notifier = nullptr; + ITypesUtil::Marshal(data, bundleName, notifier); + ret = cloudServiceImpl_->OnRemoteRequest(CloudData::CloudService::TRANS_INIT_NOTIFIER, data, reply); + EXPECT_EQ(ret, IPC_STUB_INVALID_DATA_ERR); +} + /** * @tc.name: SharingUtil001 * @tc.desc: @@ -2425,7 +2586,7 @@ HWTEST_F(CloudDataTest, GetPriorityLevel001, TestSize.Level1) }); DistributedRdb::RdbServiceImpl rdbServiceImpl; DistributedRdb::RdbSyncerParam param{ .bundleName_ = TEST_CLOUD_BUNDLE, .storeName_ = TEST_CLOUD_STORE }; - DistributedRdb::RdbService::Option option{ .mode = GeneralStore::SyncMode::CLOUD_ClOUD_FIRST, .isAsync = true }; + DistributedRdb::RdbService::Option option{ .mode = GeneralStore::SyncMode::CLOUD_CLOUD_FIRST, .isAsync = true }; DistributedRdb::PredicatesMemo memo; memo.tables_ = { TEST_CLOUD_TABLE }; rdbServiceImpl.DoCloudSync(param, option, memo, nullptr); @@ -2469,7 +2630,7 @@ HWTEST_F(CloudDataTest, GetPriorityLevel003, TestSize.Level1) }); DistributedRdb::RdbServiceImpl rdbServiceImpl; DistributedRdb::RdbSyncerParam param{ .bundleName_ = TEST_CLOUD_BUNDLE, .storeName_ = TEST_CLOUD_STORE }; - DistributedRdb::RdbService::Option option{ .mode = GeneralStore::SyncMode::CLOUD_ClOUD_FIRST, .isAsync = true }; + DistributedRdb::RdbService::Option option{ .mode = GeneralStore::SyncMode::CLOUD_CLOUD_FIRST, .isAsync = true }; DistributedRdb::PredicatesMemo memo; rdbServiceImpl.DoCloudSync(param, option, memo, nullptr); } @@ -2490,7 +2651,7 @@ HWTEST_F(CloudDataTest, GetPriorityLevel004, TestSize.Level1) }); DistributedRdb::RdbServiceImpl rdbServiceImpl; DistributedRdb::RdbSyncerParam param{ .bundleName_ = TEST_CLOUD_BUNDLE, .storeName_ = TEST_CLOUD_STORE }; - DistributedRdb::RdbService::Option option{ .mode = GeneralStore::SyncMode::CLOUD_ClOUD_FIRST, + DistributedRdb::RdbService::Option option{ .mode = GeneralStore::SyncMode::CLOUD_CLOUD_FIRST, .seqNum = 0, .isAsync = true, .isAutoSync = true };