diff --git a/frameworks/innerkitsimpl/rdb/include/irdb_service.h b/frameworks/innerkitsimpl/rdb/include/irdb_service.h index 399be4fe03d853de62428b612a9353130f167fc6..e6b94541166a1a0e330042c76ee168b6ce0eafa8 100644 --- a/frameworks/innerkitsimpl/rdb/include/irdb_service.h +++ b/frameworks/innerkitsimpl/rdb/include/irdb_service.h @@ -27,7 +27,6 @@ class IRdbService : public RdbService, public IRemoteBroker { public: enum { RDB_SERVICE_CMD_OBTAIN_TABLE, - RDB_SERVICE_CMD_GET_DEVICES, RDB_SERVICE_CMD_INIT_NOTIFIER, RDB_SERVICE_CMD_SET_DIST_TABLE, RDB_SERVICE_CMD_SYNC, @@ -39,8 +38,6 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbService"); - virtual std::vector GetConnectDevices() = 0; - virtual int32_t InitNotifier(const RdbSyncerParam& param, const sptr notifier) = 0; protected: diff --git a/frameworks/innerkitsimpl/rdb/include/rdb_manager.h b/frameworks/innerkitsimpl/rdb/include/rdb_manager.h index fe1d95307d90d03b329c0606c63507733bd943db..ad02e41e67f683f0472d1812b0375e768bf9f262 100644 --- a/frameworks/innerkitsimpl/rdb/include/rdb_manager.h +++ b/frameworks/innerkitsimpl/rdb/include/rdb_manager.h @@ -26,8 +26,6 @@ namespace OHOS::DistributedRdb { class RdbManager { public: - static std::vector GetConnectDevices(); - static std::shared_ptr GetRdbService(const RdbSyncerParam& param); }; } diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_manager.cpp b/frameworks/innerkitsimpl/rdb/src/rdb_manager.cpp index 7a438892cd1f4b715f428601f2a53e74d612f67c..bf0fdb2128226cb62c3e955358b9976179da017b 100644 --- a/frameworks/innerkitsimpl/rdb/src/rdb_manager.cpp +++ b/frameworks/innerkitsimpl/rdb/src/rdb_manager.cpp @@ -17,11 +17,6 @@ #include "rdb_manager_impl.h" namespace OHOS::DistributedRdb { -std::vector RdbManager::GetConnectDevices() -{ - return RdbManagerImpl::GetInstance().GetConnectDevices(); -} - std::shared_ptr RdbManager::GetRdbService(const RdbSyncerParam& param) { return RdbManagerImpl::GetInstance().GetRdbService(param); diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.cpp b/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.cpp index b0c55b370e5d103568be8b3a60941fe3ce653c6f..1be079979c3e7fc3eb3a14035fab5f9ad6ab4d00 100644 --- a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.cpp +++ b/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.cpp @@ -78,18 +78,6 @@ RdbManagerImpl& RdbManagerImpl::GetInstance() return manager; } -std::vector RdbManagerImpl::GetConnectDevices() -{ - std::lock_guard lock(mutex_); - auto service = GetRdbService(); - if (service == nullptr) { - ZLOGE("get service failed"); - return std::vector(); - } - - return ((RdbServiceProxy *)service.GetRefPtr())->GetConnectDevices(); -} - sptr RdbManagerImpl::GetRdbService() { if (distributedDataMgr_ == nullptr) { diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.h b/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.h index 95ea174c5db1b1caeec357a04b2512a3f14b7165..5285e1a96eb9aad396529a246b3ce3c9974c47c1 100644 --- a/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.h +++ b/frameworks/innerkitsimpl/rdb/src/rdb_manager_impl.h @@ -40,8 +40,6 @@ public: static RdbManagerImpl &GetInstance(); - std::vector GetConnectDevices(); - std::shared_ptr GetRdbService(const RdbSyncerParam& param); void OnRemoteDied(); diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.cpp b/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.cpp index 3f1e9ec240521f0060bb5e34e0ab08d597f75c2e..89988293224e8c83d1d832e1f70b60e650cb81a4 100644 --- a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.cpp +++ b/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.cpp @@ -231,31 +231,6 @@ int32_t RdbServiceProxy::DoAsync(const RdbSyncerParam& param, const SyncOption & return RDB_OK; } -std::vector RdbServiceProxy::GetConnectDevices() -{ - MessageParcel data; - if (!data.WriteInterfaceToken(IRdbService::GetDescriptor())) { - ZLOGE("write descriptor failed"); - return {}; - } - - MessageParcel reply; - MessageOption option; - if (Remote()->SendRequest(RDB_SERVICE_CMD_GET_DEVICES, data, reply, option) != 0) { - ZLOGE("send request failed"); - return {}; - } - - std::vector devices; - if (!reply.ReadStringVector(&devices)) { - ZLOGE("read devices failed"); - return {}; - } - - ZLOGI("success"); - return devices; -} - int32_t RdbServiceProxy::SetDistributedTables(const RdbSyncerParam& param, const std::vector &tables) { MessageParcel data; diff --git a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.h b/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.h index 29dab88f95b4d6e1addd630189b1c7058d473980..468fb5a135241ddca42037a49e334447000a5278 100644 --- a/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.h +++ b/frameworks/innerkitsimpl/rdb/src/rdb_service_proxy.h @@ -33,8 +33,6 @@ public: std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; - std::vector GetConnectDevices() override; - int32_t InitNotifier(const RdbSyncerParam& param); int32_t InitNotifier(const RdbSyncerParam& param, const sptr notifier) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index eb74d2077b05e844705fe153ca8eec89a45807e8..034f5d61358d8b1ac9636d28378d2850692b31c3 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -125,20 +125,6 @@ std::string RdbServiceImpl::ObtainDistributedTableName(const std::string &device return DistributedDB::RelationalStoreManager::GetDistributedTableName(uuid, table); } -std::vector RdbServiceImpl::GetConnectDevices() -{ - auto deviceInfos = AppDistributedKv::CommunicationProvider::GetInstance().GetRemoteNodesBasicInfo(); - std::vector devices; - for (const auto& deviceInfo : deviceInfos) { - devices.push_back(deviceInfo.deviceId); - } - ZLOGI("size=%{public}u", static_cast(devices.size())); - for (const auto& device: devices) { - ZLOGI("%{public}.6s", device.c_str()); - } - return devices; -} - int32_t RdbServiceImpl::InitNotifier(const RdbSyncerParam& param, const sptr notifier) { if (!CheckAccess(param)) { @@ -262,7 +248,7 @@ int32_t RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, const SyncOption &op if (syncer == nullptr) { return RDB_ERROR; } - return syncer->DoSync(option, predicates, result); + return syncer->DoSync(option, const_cast(predicates), result); } void RdbServiceImpl::OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResult &result) @@ -282,9 +268,10 @@ int32_t RdbServiceImpl::DoAsync(const RdbSyncerParam ¶m, uint32_t seqNum, co if (syncer == nullptr) { return RDB_ERROR; } - return syncer->DoAsync(option, predicates, [this, pid, seqNum] (const SyncResult& result) { - OnAsyncComplete(pid, seqNum, result); - }); + return syncer->DoAsync(option, const_cast(predicates), + [this, pid, seqNum] (const SyncResult& result) { + OnAsyncComplete(pid, seqNum, result); + }); } std::string RdbServiceImpl::TransferStringToHex(const std::string &origStr) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 31a96de64acd2b22a384d75bdb257977de25f4ba..1014ae33035b1b86db1c61a6965b8f4bfd0668d7 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -36,8 +36,6 @@ public: /* IPC interface */ std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; - std::vector GetConnectDevices() override; - int32_t InitNotifier(const RdbSyncerParam& param, const sptr notifier) override; int32_t SetDistributedTables(const RdbSyncerParam& param, const std::vector& tables) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 797d532f890aeed9e4abb6428dc48ba611d00918..1de876eea2a766e101fa9c865485c31c5b2101c9 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -40,16 +40,6 @@ int32_t RdbServiceStub::OnRemoteObtainDistributedTableName(MessageParcel &data, return RDB_OK; } -int32_t RdbServiceStub::OnRemoteGetConnectDevices(MessageParcel& data, MessageParcel& reply) -{ - std::vector devices = GetConnectDevices(); - if (!reply.WriteStringVector(devices)) { - ZLOGE("write devices failed"); - } - - return RDB_OK; -} - int32_t RdbServiceStub::OnRemoteInitNotifier(MessageParcel &data, MessageParcel &reply) { int32_t error = RDB_ERROR; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.h b/services/distributeddataservice/service/rdb/rdb_service_stub.h index c520bc4904b8cc1c18a3a39dd745e4364baef20e..a6c1e6217d587ddc70b2f985632f0ba7f4864fff 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.h +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.h @@ -48,8 +48,6 @@ private: int32_t OnRemoteObtainDistributedTableName(MessageParcel& data, MessageParcel& reply); - int32_t OnRemoteGetConnectDevices(MessageParcel& data, MessageParcel& reply); - int32_t OnRemoteInitNotifier(MessageParcel&data, MessageParcel& reply); int32_t OnRemoteSetDistributedTables(MessageParcel &data, MessageParcel &reply); @@ -65,7 +63,6 @@ private: using RequestHandle = int (RdbServiceStub::*)(MessageParcel &, MessageParcel &); static constexpr RequestHandle HANDLERS[RDB_SERVICE_CMD_MAX] = { [RDB_SERVICE_CMD_OBTAIN_TABLE] = &RdbServiceStub::OnRemoteObtainDistributedTableName, - [RDB_SERVICE_CMD_GET_DEVICES] = &RdbServiceStub::OnRemoteGetConnectDevices, [RDB_SERVICE_CMD_INIT_NOTIFIER] = &RdbServiceStub::OnRemoteInitNotifier, [RDB_SERVICE_CMD_SET_DIST_TABLE] = &RdbServiceStub::OnRemoteSetDistributedTables, [RDB_SERVICE_CMD_SYNC] = &RdbServiceStub::OnRemoteDoSync, diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 1c48d44cbb0e958f6f28011d849a6970c8e501ed..a1813e3b245f372eff1ea903b568e5e8e0b2a434 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -23,6 +23,7 @@ #include "kvstore_utils.h" #include "kvstore_meta_manager.h" +using OHOS::DistributedKv::KvStoreUtils; using OHOS::DistributedKv::AccountDelegate; using OHOS::DistributedKv::KvStoreMetaManager; using OHOS::AppDistributedKv::CommunicationProvider; @@ -177,16 +178,32 @@ int32_t RdbSyncer::SetDistributedTables(const std::vector &tables) return RDB_OK; } +std::vector RdbSyncer::GetConnectDevices() +{ + auto deviceInfos = AppDistributedKv::CommunicationProvider::GetInstance().GetRemoteNodesBasicInfo(); + std::vector devices; + for (const auto& deviceInfo : deviceInfos) { + devices.push_back(deviceInfo.deviceId); + } + ZLOGI("size=%{public}u", static_cast(devices.size())); + for (const auto& device: devices) { + ZLOGI("%{public}s", KvStoreUtils::ToBeAnonymous(device).c_str()); + } + return devices; +} + std::vector RdbSyncer::NetworkIdToUUID(const std::vector &networkIds) { std::vector uuids; for (const auto& networkId : networkIds) { auto uuid = CommunicationProvider::GetInstance().GetUuidByNodeId(networkId); if (uuid.empty()) { - ZLOGE("%{public}.6s failed", networkId.c_str()); + ZLOGE("%{public}s failed", KvStoreUtils::ToBeAnonymous(networkId).c_str()); continue; } uuids.push_back(uuid); + ZLOGI("%{public}s <--> %{public}s", KvStoreUtils::ToBeAnonymous(networkId).c_str(), + KvStoreUtils::ToBeAnonymous(uuid).c_str()); } return uuids; } @@ -261,9 +278,6 @@ DistributedDB::Query RdbSyncer::MakeQuery(const RdbPredicates &predicates) { ZLOGI("table=%{public}s", predicates.table_.c_str()); auto query = DistributedDB::Query::Select(predicates.table_); - for (const auto& device : predicates.devices_) { - ZLOGI("device=%{public}.6s", device.c_str()); - } for (const auto& operation : predicates.operations_) { if (operation.operator_ >= 0 && operation.operator_ < OPERATOR_MAX) { HANDLES[operation.operator_](operation, query); @@ -281,7 +295,13 @@ int32_t RdbSyncer::DoSync(const SyncOption &option, const RdbPredicates &predica return RDB_ERROR; } - auto devices = NetworkIdToUUID(predicates.devices_); + std::vector devices; + if (predicates.devices_.empty()) { + devices = NetworkIdToUUID(GetConnectDevices()); + } else { + devices = NetworkIdToUUID(predicates.devices_); + } + ZLOGI("delegate sync"); return delegate->Sync(devices, static_cast(option.mode), MakeQuery(predicates), [&result] (const auto& syncStatus) { @@ -296,7 +316,14 @@ int32_t RdbSyncer::DoAsync(const SyncOption &option, const RdbPredicates &predic ZLOGE("delegate is nullptr"); return RDB_ERROR; } - auto devices = NetworkIdToUUID(predicates.devices_); + + std::vector devices; + if (predicates.devices_.empty()) { + devices = NetworkIdToUUID(GetConnectDevices()); + } else { + devices = NetworkIdToUUID(predicates.devices_); + } + ZLOGI("delegate sync"); return delegate->Sync(devices, static_cast(option.mode), MakeQuery(predicates), [callback] (const auto& syncStatus) { diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.h b/services/distributeddataservice/service/rdb/rdb_syncer.h index b31adfb86ba1794754de3530242f7680eeeecde3..23039ed1a4015129546a0eb3acc14cdf2c9018f0 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -71,6 +71,7 @@ private: pid_t uid_ {}; uint32_t timerId_ {}; + static std::vector GetConnectDevices(); static std::vector NetworkIdToUUID(const std::vector& networkIds); static void HandleSyncStatus(const std::map>& SyncStatus,