From acaffaa3d4bac633a91cb767bceca3c109e5d864 Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 21 Apr 2025 18:07:04 +0800 Subject: [PATCH 1/6] update Signed-off-by: yangliu --- .../src/device_manager_adapter.cpp | 31 +++++++++++++++++++ .../communicator/device_manager_adapter.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index b9b0078f6..074bae762 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -176,6 +176,7 @@ void DeviceManagerAdapter::Online(const DmDeviceInfo &info) KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType, static_cast(dvInfo.authForm), dvInfo.osType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_ONLINE); + SaveHosDevInfo(dvInfo, DeviceChangeType::DEVICE_ONLINE); syncTask_.Insert(dvInfo.uuid, dvInfo.uuid); auto observers = GetObservers(); ResetLocalDeviceInfo(); @@ -245,6 +246,7 @@ void DeviceManagerAdapter::Offline(const DmDeviceInfo &info) KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType, static_cast(dvInfo.authForm), dvInfo.osType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_OFFLINE); + SaveHosDevInfo(dvInfo, DeviceChangeType::DEVICE_OFFLINE); auto task = [this, dvInfo]() { observers_.ForEachCopies([&dvInfo](const auto &key, auto &value) { if (value != nullptr) { @@ -409,6 +411,9 @@ bool DeviceManagerAdapter::IsOHOSType(const std::string &id) int32_t DeviceManagerAdapter::GetAuthType(const std::string &id) { DeviceInfo dvInfo; + if (hosDeviceInfos_.Get(id, dvInfo)) { + return static_cast(dvInfo.authForm); + } if (!deviceInfos_.Get(id, dvInfo)) { InitDeviceInfo(); deviceInfos_.Get(id, dvInfo); @@ -642,4 +647,30 @@ void DeviceManagerAdapter::ResetLocalDeviceInfo() deviceInfos_.Set(local.udid, local); deviceInfos_.Set(local.networkId, local); } + +void DeviceManagerAdapter::SaveHosDevInfo(const DeviceInfo &dvInfo, const DeviceChangeType &type) +{ + if (dvInfo.networkId == DeviceManagerAdapter::cloudDmInfo.networkId || + dvInfo.osType == OH_OS_TYPE) { + return; + } + switch (type) { + case DeviceChangeType::DEVICE_ONLINE: { + hosDeviceInfos_.Set(dvInfo.networkId, dvInfo); + hosDeviceInfos_.Set(dvInfo.uuid, dvInfo); + hosDeviceInfos_.Set(dvInfo.udid, dvInfo); + break; + } + case DeviceChangeType::DEVICE_OFFLINE: { + hosDeviceInfos_.Delete(dvInfo.networkId); + hosDeviceInfos_.Delete(dvInfo.uuid); + hosDeviceInfos_.Delete(dvInfo.udid); + break; + } + default: { + ZLOGW("unknown type."); + break; + } + } +} } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h index a50783ae1..cacdeef59 100644 --- a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h +++ b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h @@ -91,6 +91,7 @@ private: void OnChanged(const DmDeviceInfo &info); std::vector GetObservers(); void ResetLocalDeviceInfo(); + void SaveHosDevInfo(const DeviceInfo &dvInfo, const DeviceChangeType &type); static inline uint64_t GetTimeStamp() { return std::chrono::duration_cast( @@ -103,6 +104,7 @@ private: const DmDeviceInfo cloudDmInfo; ConcurrentMap observers_ {}; LRUBucket deviceInfos_ {64}; + LRUBucket hosDeviceInfos_ {64}; static constexpr size_t TIME_TASK_CAPACITY = 50; static constexpr int32_t SYNC_TIMEOUT = 60 * 1000; // ms static constexpr int32_t OH_OS_TYPE = 10; -- Gitee From 60086f97a41f9c0b1a81208835d8fc59686306b3 Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 21 Apr 2025 19:28:42 +0800 Subject: [PATCH 2/6] update Signed-off-by: yangliu --- .../adapter/include/communicator/device_manager_adapter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h index cacdeef59..18b7b76cc 100644 --- a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h +++ b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h @@ -91,7 +91,7 @@ private: void OnChanged(const DmDeviceInfo &info); std::vector GetObservers(); void ResetLocalDeviceInfo(); - void SaveHosDevInfo(const DeviceInfo &dvInfo, const DeviceChangeType &type); + void SaveHosDevInfo(const DeviceInfo &dvInfo, const AppDistributedKv::DeviceChangeType &type); static inline uint64_t GetTimeStamp() { return std::chrono::duration_cast( -- Gitee From cc4e4f161e4a0252d203683efcf2085ec8b3cf51 Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 21 Apr 2025 19:55:05 +0800 Subject: [PATCH 3/6] update Signed-off-by: yangliu --- .../adapter/communicator/src/device_manager_adapter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 074bae762..2aba86879 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -265,8 +265,9 @@ void DeviceManagerAdapter::OnChanged(const DmDeviceInfo &info) ZLOGE("get device info fail"); return; } - ZLOGI("[OnChanged] uuid:%{public}s, name:%{public}s, type:%{public}d", - KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType); + ZLOGI("[OnChanged] uuid:%{public}s, name:%{public}s, type:%{public}d, authForm:%{public}d", + KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType, + static_cast(dvInfo.authForm)); } void DeviceManagerAdapter::OnReady(const DmDeviceInfo &info) -- Gitee From a1a848a2c6d1a08f8c3b7a18483a81d06aa5f550 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 22 Apr 2025 15:29:08 +0800 Subject: [PATCH 4/6] update Signed-off-by: yangliu --- .../src/device_manager_adapter.cpp | 51 ++++++------------- .../communicator/device_manager_adapter.h | 3 +- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 2aba86879..81d9ce9fd 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -246,7 +246,6 @@ void DeviceManagerAdapter::Offline(const DmDeviceInfo &info) KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType, static_cast(dvInfo.authForm), dvInfo.osType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_OFFLINE); - SaveHosDevInfo(dvInfo, DeviceChangeType::DEVICE_OFFLINE); auto task = [this, dvInfo]() { observers_.ForEachCopies([&dvInfo](const auto &key, auto &value) { if (value != nullptr) { @@ -265,9 +264,9 @@ void DeviceManagerAdapter::OnChanged(const DmDeviceInfo &info) ZLOGE("get device info fail"); return; } - ZLOGI("[OnChanged] uuid:%{public}s, name:%{public}s, type:%{public}d, authForm:%{public}d", + ZLOGI("[OnChanged] uuid:%{public}s, name:%{public}s, type:%{public}d, authForm:%{public}d osType:%{public}d", KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType, - static_cast(dvInfo.authForm)); + static_cast(dvInfo.authForm), dvInfo.osType); } void DeviceManagerAdapter::OnReady(const DmDeviceInfo &info) @@ -278,8 +277,9 @@ void DeviceManagerAdapter::OnReady(const DmDeviceInfo &info) return; } readyDevices_.InsertOrAssign(dvInfo.uuid, std::make_pair(DeviceState::DEVICE_ONREADY, dvInfo)); - ZLOGI("[OnReady] uuid:%{public}s, name:%{public}s, type:%{public}d", - KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType); + ZLOGI("[OnReady] uuid:%{public}s, name:%{public}s, type:%{public}d, authForm:%{public}d, osType:%{public}d", + KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType, + static_cast(dvInfo.authForm), dvInfo.osType); auto task = [this, dvInfo]() { observers_.ForEachCopies([&dvInfo](const auto &key, auto &value) { if (value != nullptr) { @@ -329,6 +329,11 @@ void DeviceManagerAdapter::SaveDeviceInfo(const DeviceInfo &dvInfo, const Device deviceInfos_.Set(dvInfo.uuid, dvInfo); deviceInfos_.Set(dvInfo.udid, dvInfo); readyDevices_.InsertOrAssign(dvInfo.uuid, std::make_pair(DeviceState::DEVICE_ONLINE, dvInfo)); + if (dvInfo.osType != OH_OS_TYPE) { + otherDeviceInfos_.Set(dvInfo.networkId, dvInfo); + otherDeviceInfos_.Set(dvInfo.uuid, dvInfo); + otherDeviceInfos_.Set(dvInfo.udid, dvInfo); + } break; } case DeviceChangeType::DEVICE_OFFLINE: { @@ -336,6 +341,11 @@ void DeviceManagerAdapter::SaveDeviceInfo(const DeviceInfo &dvInfo, const Device deviceInfos_.Delete(dvInfo.uuid); deviceInfos_.Delete(dvInfo.udid); readyDevices_.Erase(dvInfo.uuid); + if (dvInfo.osType != OH_OS_TYPE) { + otherDeviceInfos_.Delete(dvInfo.networkId, dvInfo); + otherDeviceInfos_.Delete(dvInfo.uuid, dvInfo); + otherDeviceInfos_.Delete(dvInfo.udid, dvInfo); + } break; } default: { @@ -412,10 +422,7 @@ bool DeviceManagerAdapter::IsOHOSType(const std::string &id) int32_t DeviceManagerAdapter::GetAuthType(const std::string &id) { DeviceInfo dvInfo; - if (hosDeviceInfos_.Get(id, dvInfo)) { - return static_cast(dvInfo.authForm); - } - if (!deviceInfos_.Get(id, dvInfo)) { + if (!otherDeviceInfos_.Get(id, dvInfo) && !deviceInfos_.Get(id, dvInfo)) { InitDeviceInfo(); deviceInfos_.Get(id, dvInfo); } @@ -648,30 +655,4 @@ void DeviceManagerAdapter::ResetLocalDeviceInfo() deviceInfos_.Set(local.udid, local); deviceInfos_.Set(local.networkId, local); } - -void DeviceManagerAdapter::SaveHosDevInfo(const DeviceInfo &dvInfo, const DeviceChangeType &type) -{ - if (dvInfo.networkId == DeviceManagerAdapter::cloudDmInfo.networkId || - dvInfo.osType == OH_OS_TYPE) { - return; - } - switch (type) { - case DeviceChangeType::DEVICE_ONLINE: { - hosDeviceInfos_.Set(dvInfo.networkId, dvInfo); - hosDeviceInfos_.Set(dvInfo.uuid, dvInfo); - hosDeviceInfos_.Set(dvInfo.udid, dvInfo); - break; - } - case DeviceChangeType::DEVICE_OFFLINE: { - hosDeviceInfos_.Delete(dvInfo.networkId); - hosDeviceInfos_.Delete(dvInfo.uuid); - hosDeviceInfos_.Delete(dvInfo.udid); - break; - } - default: { - ZLOGW("unknown type."); - break; - } - } -} } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h index 18b7b76cc..53135966b 100644 --- a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h +++ b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h @@ -91,7 +91,6 @@ private: void OnChanged(const DmDeviceInfo &info); std::vector GetObservers(); void ResetLocalDeviceInfo(); - void SaveHosDevInfo(const DeviceInfo &dvInfo, const AppDistributedKv::DeviceChangeType &type); static inline uint64_t GetTimeStamp() { return std::chrono::duration_cast( @@ -104,7 +103,7 @@ private: const DmDeviceInfo cloudDmInfo; ConcurrentMap observers_ {}; LRUBucket deviceInfos_ {64}; - LRUBucket hosDeviceInfos_ {64}; + LRUBucket otherDeviceInfos_ {64}; static constexpr size_t TIME_TASK_CAPACITY = 50; static constexpr int32_t SYNC_TIMEOUT = 60 * 1000; // ms static constexpr int32_t OH_OS_TYPE = 10; -- Gitee From 717b8fe6bef08028e5fd2d466c2ff7d7d5add150 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 22 Apr 2025 15:29:42 +0800 Subject: [PATCH 5/6] update Signed-off-by: yangliu --- .../adapter/communicator/src/device_manager_adapter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 81d9ce9fd..175685d82 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -176,7 +176,6 @@ void DeviceManagerAdapter::Online(const DmDeviceInfo &info) KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType, static_cast(dvInfo.authForm), dvInfo.osType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_ONLINE); - SaveHosDevInfo(dvInfo, DeviceChangeType::DEVICE_ONLINE); syncTask_.Insert(dvInfo.uuid, dvInfo.uuid); auto observers = GetObservers(); ResetLocalDeviceInfo(); -- Gitee From d08d7ee3b2473e7c1238dcfe589a81e0f0df2c5a Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 22 Apr 2025 15:49:26 +0800 Subject: [PATCH 6/6] update Signed-off-by: yangliu --- .../adapter/communicator/src/device_manager_adapter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 175685d82..817824732 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -341,9 +341,9 @@ void DeviceManagerAdapter::SaveDeviceInfo(const DeviceInfo &dvInfo, const Device deviceInfos_.Delete(dvInfo.udid); readyDevices_.Erase(dvInfo.uuid); if (dvInfo.osType != OH_OS_TYPE) { - otherDeviceInfos_.Delete(dvInfo.networkId, dvInfo); - otherDeviceInfos_.Delete(dvInfo.uuid, dvInfo); - otherDeviceInfos_.Delete(dvInfo.udid, dvInfo); + otherDeviceInfos_.Delete(dvInfo.networkId); + otherDeviceInfos_.Delete(dvInfo.uuid); + otherDeviceInfos_.Delete(dvInfo.udid); } break; } -- Gitee