From 1a39a3b8a3c060fa17e1b65b4f64031dbbd1fe81 Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Wed, 25 Sep 2024 17:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E7=BA=BF=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../include/distributed_hardware_errno.h | 1 + .../distributed_hardware_manager_factory.h | 5 +- .../include/resourcemanager/db_adapter.h | 2 +- .../local_capability_info_manager.h | 2 + .../resourcemanager/meta_info_manager.h | 3 +- .../src/accessmanager/access_manager.cpp | 60 ++++++++++--------- .../distributed_hardware_manager_factory.cpp | 30 +++++++--- .../src/resourcemanager/db_adapter.cpp | 13 ++-- .../local_capability_info_manager.cpp | 27 +++++++++ .../src/resourcemanager/meta_info_manager.cpp | 25 +++++++- .../accessmanager/access_manager_test.cpp | 11 +++- .../src/resource_manager_test.cpp | 8 +-- utils/include/dh_utils_tool.h | 2 + utils/src/dh_utils_tool.cpp | 19 ++++++ 14 files changed, 152 insertions(+), 56 deletions(-) diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index d10282cb..a2894d5d 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -31,6 +31,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_TYPE_NOT_EXIST = -10003; constexpr int32_t ERR_DH_FWK_JSON_PARSE_FAILED = -10004; constexpr int32_t ERR_DH_FWK_POINTER_IS_NULL = -10005; + constexpr int32_t ERR_DH_FWK_INVALID_OSTYPE = -10006; /* VersionManager errno, range: [-10200, -10299] */ constexpr int32_t ERR_DH_FWK_VERSION_DEVICE_ID_NOT_EXIST = -10200; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index f34c06b9..91c8df2c 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -32,11 +32,12 @@ public: bool InitLocalDevInfo(); bool IsInit(); int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, - uint16_t deviceType); + uint16_t deviceType, int32_t osType); int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType); int32_t GetComponentVersion(std::unordered_map &versionMap); - void ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid); + void ClearRemoteDeviceMetaInfoData(const std::string &peerudid, const std::string &peeruuid); + void ClearRemoteDeviceLocalInfoData(const std::string &peeruuid); int Dump(const std::vector &argsStr, std::string &result); void UnInit(); diff --git a/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h b/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h index 60e56ed2..9f3c7e68 100644 --- a/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h +++ b/services/distributedhardwarefwkservice/include/resourcemanager/db_adapter.h @@ -54,7 +54,7 @@ public: int32_t RemoveDataByKey(const std::string &key); std::vector GetEntriesByKeys(const std::vector &keys); bool SyncDataByNetworkId(const std::string &networkId); - bool ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid); + bool ClearDataByPrefix(const std::string &prefix); private: int32_t RegisterChangeListener(); diff --git a/services/distributedhardwarefwkservice/include/resourcemanager/local_capability_info_manager.h b/services/distributedhardwarefwkservice/include/resourcemanager/local_capability_info_manager.h index 4dfd4e7b..e7b48f6b 100644 --- a/services/distributedhardwarefwkservice/include/resourcemanager/local_capability_info_manager.h +++ b/services/distributedhardwarefwkservice/include/resourcemanager/local_capability_info_manager.h @@ -57,6 +57,8 @@ public: int32_t GetDataByDHType(const DHType dhType, CapabilityInfoMap &capabilityMap); /* Queries batch records in the database based on the prefix of the key. */ int32_t GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap); + int32_t RemoveLocalInfoInMemByUuid(const std::string &peeruuid); + int32_t ClearRemoteDeviceLocalInfoData(const std::string &peeruuid); private: mutable std::mutex capInfoMgrMutex_; diff --git a/services/distributedhardwarefwkservice/include/resourcemanager/meta_info_manager.h b/services/distributedhardwarefwkservice/include/resourcemanager/meta_info_manager.h index 9b81cf4a..3fa19cb8 100644 --- a/services/distributedhardwarefwkservice/include/resourcemanager/meta_info_manager.h +++ b/services/distributedhardwarefwkservice/include/resourcemanager/meta_info_manager.h @@ -45,13 +45,14 @@ public: int32_t SyncRemoteMetaInfos(); int32_t GetDataByKeyPrefix(const std::string &keyPrefix, MetaCapInfoMap &metaCapMap); int32_t RemoveMetaInfoByKey(const std::string &key); + int32_t RemoveMetaInfoInMemByUdid(const std::string &peerudid); int32_t GetMetaCapInfo(const std::string &udidHash, const std::string &dhId, std::shared_ptr &metaCapPtr); void GetMetaCapInfosByUdidHash(const std::string &udidHash, std::vector> &metaCapInfos); int32_t GetMetaDataByDHType(const DHType dhType, MetaCapInfoMap &metaInfoMap); int32_t SyncDataByNetworkId(const std::string &networkId); - int32_t ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid); + int32_t ClearRemoteDeviceMetaInfoData(const std::string &peerudid, const std::string &peeruuid); /* Database data changes callback */ virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification) override; /* Cloud data changes callback */ diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 3b2db283..561b0cd9 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -36,6 +36,7 @@ namespace DistributedHardware { constexpr int32_t DH_RETRY_INIT_DM_COUNT = 6; constexpr int32_t DH_RETRY_INIT_DM_INTERVAL_US = 1000 * 500; + AccessManager::~AccessManager() { UnInit(); @@ -123,8 +124,29 @@ void AccessManager::OnRemoteDied() void AccessManager::OnDeviceOnline(const DmDeviceInfo &deviceInfo) { - (void)deviceInfo; - return; + std::lock_guard lock(accessMutex_); + DHLOGI("AccessManager online, networkId: %{public}s, deviceName: %{public}s, deviceTypeId: %{public}d", + GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str(), + deviceInfo.deviceTypeId); + + auto networkId = std::string(deviceInfo.networkId); + if (!IsIdLengthValid(networkId)) { + return; + } + auto uuid = GetUUIDByDm(networkId); + if (!IsIdLengthValid(uuid)) { + return; + } + auto udid = GetUDIDByDm(networkId); + if (!IsIdLengthValid(udid)) { + return; + } + int32_t osType = GetDeviceSystemType(deviceInfo.extraData); + auto ret = DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, udid, + deviceInfo.deviceTypeId, osType); + DHLOGI("AccessManager online result: %{public}d, networkId: %{public}s, uuid: %{public}s, udid: %{public}s," + "osType = %{public}d", ret, GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), + GetAnonyString(udid).c_str(), osType); } void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) @@ -155,28 +177,8 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) { - std::lock_guard lock(accessMutex_); - DHLOGI("AccessManager online, networkId: %{public}s, deviceName: %{public}s, deviceTypeId: %{public}d", - GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str(), - deviceInfo.deviceTypeId); - - auto networkId = std::string(deviceInfo.networkId); - if (!IsIdLengthValid(networkId)) { - return; - } - auto uuid = GetUUIDByDm(networkId); - if (!IsIdLengthValid(uuid)) { - return; - } - auto udid = GetUDIDByDm(networkId); - if (!IsIdLengthValid(udid)) { - return; - } - auto ret = - DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, udid, - deviceInfo.deviceTypeId); - DHLOGI("AccessManager online result: %{public}d, networkId: %{public}s, uuid: %{public}s, udid: %{public}s", - ret, GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); + (void)deviceInfo; + return; } void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) @@ -197,7 +199,7 @@ void AccessManager::OnDeviceTrustChange(const std::string &peerudid, const std:: DHLOGE("Peer is not same account"); return; } - DistributedHardwareManagerFactory::GetInstance().ClearDataWhenPeerLogout(peerudid, peeruuid); + DistributedHardwareManagerFactory::GetInstance().ClearRemoteDeviceMetaInfoData(peerudid, peeruuid); } void AccessManager::CheckTrustedDeviceOnline() @@ -212,10 +214,12 @@ void AccessManager::CheckTrustedDeviceOnline() const auto networkId = std::string(deviceInfo.networkId); const auto uuid = GetUUIDByDm(networkId); const auto udid = GetUDIDByDm(networkId); - DHLOGI("Send trusted device online, networkId = %{public}s, uuid = %{public}s, udid = %{public}s", - GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); + int32_t osType = GetDeviceSystemType(deviceInfo.extraData); + DHLOGI("Send trusted device online, networkId = %{public}s, uuid = %{public}s, udid = %{public}s," + "osType = %{public}d", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), + GetAnonyString(udid).c_str(), osType); DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, udid, - deviceInfo.deviceTypeId); + deviceInfo.deviceTypeId, osType); } } diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index f68d3f63..61761b36 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -38,10 +38,14 @@ #include "distributed_hardware_log.h" #include "distributed_hardware_manager.h" #include "device_param_mgr.h" +#include "local_capability_info_manager.h" #include "meta_info_manager.h" namespace OHOS { namespace DistributedHardware { +namespace { + constexpr int32_t DOUBLE_FRAME_DEVICE_TYPE = -1; +} #undef DH_LOG_TAG #define DH_LOG_TAG "DistributedHardwareManagerFactory" @@ -135,11 +139,11 @@ void DistributedHardwareManagerFactory::CheckExitSAOrNot() const auto uuid = GetUUIDByDm(networkId); const auto udid = GetUDIDByDm(networkId); DHLOGI("Send trusted device online, networkId = %{public}s, uuid = %{public}s", - GetAnonyString(networkId).c_str(), - GetAnonyString(uuid).c_str()); + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); uint16_t deviceType = deviceInfo.deviceTypeId; - std::thread([this, networkId, uuid, udid, deviceType]() { - this->SendOnLineEvent(networkId, uuid, udid, deviceType); + int32_t osType = GetDeviceSystemType(deviceInfo.extraData); + std::thread([this, networkId, uuid, udid, deviceType, osType]() { + this->SendOnLineEvent(networkId, uuid, udid, deviceType, osType); }).detach(); } } @@ -150,7 +154,7 @@ bool DistributedHardwareManagerFactory::IsInit() } int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &networkId, const std::string &uuid, - const std::string &udid, uint16_t deviceType) + const std::string &udid, uint16_t deviceType, int32_t osType) { if (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(udid)) { return ERR_DH_FWK_PARA_INVALID; @@ -182,6 +186,13 @@ int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &ne DHLOGI("e2e device, need initiative sync data."); MetaInfoManager::GetInstance()->SyncDataByNetworkId(networkId); } + + if (osType == DOUBLE_FRAME_DEVICE_TYPE) { + DHLOGE("double frame device, networkId = %{public}s, uuid = %{public}s, udid = %{public}s, need clear data.", + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); + ClearRemoteDeviceMetaInfoData(udid, uuid); + ClearRemoteDeviceLocalInfoData(uuid); + } auto onlineResult = DistributedHardwareManager::GetInstance().SendOnLineEvent(networkId, uuid, udid, deviceType); if (onlineResult != DH_FWK_SUCCESS) { DHLOGE("online failed, errCode = %{public}d", onlineResult); @@ -237,10 +248,15 @@ bool DistributedHardwareManagerFactory::GetUnInitFlag() return flagUnInit_.load(); } -void DistributedHardwareManagerFactory::ClearDataWhenPeerLogout(const std::string &peerudid, +void DistributedHardwareManagerFactory::ClearRemoteDeviceMetaInfoData(const std::string &peerudid, const std::string &peeruuid) { - MetaInfoManager::GetInstance()->ClearDataWhenPeerLogout(peerudid, peeruuid); + MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid); +} + +void DistributedHardwareManagerFactory::ClearRemoteDeviceLocalInfoData(const std::string &peeruuid) +{ + LocalCapabilityInfoManager::GetInstance()->ClearRemoteDeviceLocalInfoData(peeruuid); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index 79a0228c..8760ecd5 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -565,16 +565,16 @@ bool DBAdapter::SyncDataByNetworkId(const std::string &networkId) return true; } -bool DBAdapter::ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid) +bool DBAdapter::ClearDataByPrefix(const std::string &prefix) { - DHLOGI("Clear cloudData start."); + DHLOGI("Clear data by prefix: %{public}s.", GetAnonyString(prefix).c_str()); std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is nullptr!"); return false; } - std::string udIdHash = Sha256(peerudid); - DistributedKv::Key allEntryKeyPrefix(udIdHash); + std::string keyPrefix = Sha256(prefix); + DistributedKv::Key allEntryKeyPrefix(keyPrefix); std::vector peerEntries; DistributedKv::Status status = kvStoragePtr_->GetEntries(allEntryKeyPrefix, peerEntries); if (status != DistributedKv::Status::SUCCESS || peerEntries.size() == 0) { @@ -590,11 +590,6 @@ bool DBAdapter::ClearDataWhenPeerLogout(const std::string &peerudid, const std:: DHLOGE("DeleteBatch failed, error: %{public}d", status); return false; } - - if (kvStoragePtr_->RemoveDeviceData(peeruuid) != DistributedKv::Status::SUCCESS) { - DHLOGE("RemoveDeviceData failed, peeruuid=%{public}s", GetAnonyString(peeruuid).c_str()); - return false; - } return true; } } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp index 0d7d01dd..a13809c5 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp @@ -259,5 +259,32 @@ int32_t LocalCapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPre } return DH_FWK_SUCCESS; } + +int32_t LocalCapabilityInfoManager::RemoveLocalInfoInMemByUuid(const std::string &peeruuid) +{ + DHLOGI("remove device localinfo in memory, peerudid: %{public}s", GetAnonyString(peeruuid).c_str()); + std::string deviceId = Sha256(peeruuid); + for (auto iter = globalCapInfoMap_.begin(); iter != globalCapInfoMap_.end();) { + if (!IsCapKeyMatchDeviceId(iter->first, deviceId)) { + DHLOGI("not find deviceId: %{public}s", GetAnonyString(deviceId).c_str()); + iter++; + continue; + } + globalCapInfoMap_.erase(iter++); + } + return DH_FWK_SUCCESS; +} + +int32_t LocalCapabilityInfoManager::ClearRemoteDeviceLocalInfoData(const std::string &peeruuid) +{ + std::lock_guard lock(capInfoMgrMutex_); + if (dbAdapterPtr_ == nullptr) { + DHLOGE("dbAdapterPtr is null"); + return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL; + } + dbAdapterPtr_->ClearDataByPrefix(peeruuid); + RemoveLocalInfoInMemByUuid(peeruuid); + return DH_FWK_SUCCESS; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index c6134e81..72847a16 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -337,13 +337,34 @@ int32_t MetaInfoManager::SyncDataByNetworkId(const std::string &networkId) return DH_FWK_SUCCESS; } -int32_t MetaInfoManager::ClearDataWhenPeerLogout(const std::string &peerudid, const std::string &peeruuid) +int32_t MetaInfoManager::RemoveMetaInfoInMemByUdid(const std::string &peerudid) +{ + DHLOGI("remove device metainfo in memory, peerudid: %{public}s", GetAnonyString(peerudid).c_str()); + std::lock_guard lock(metaInfoMgrMutex_); + std::string udIdHash = Sha256(peerudid); + for (auto iter = globalMetaInfoMap_.begin(); iter != globalMetaInfoMap_.end();) { + if (!IsCapKeyMatchDeviceId(iter->first, udIdHash)) { + DHLOGI("not find udIdHash: %{public}s", GetAnonyString(udIdHash).c_str()); + iter++; + continue; + } + globalMetaInfoMap_.erase(iter++); + } + return DH_FWK_SUCCESS; +} + +int32_t MetaInfoManager::ClearRemoteDeviceMetaInfoData(const std::string &peerudid, const std::string &peeruuid) { if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL; } - dbAdapterPtr_->ClearDataWhenPeerLogout(peerudid, peeruuid); + dbAdapterPtr_->ClearDataByPrefix(peerudid); + if (dbAdapterPtr_->RemoveDeviceData(peeruuid) != DH_FWK_SUCCESS) { + DHLOGE("Remove Device Data failed, peeruuid: %{public}s", GetAnonyString(peeruuid).c_str()); + return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; + } + RemoveMetaInfoInMemByUdid(peerudid); return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp index 57917eb6..eace93ad 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp @@ -31,6 +31,7 @@ enum class Status : uint32_t { }; constexpr uint16_t TEST_DEV_TYPE_PAD = 0x11; +constexpr int32_t INVALID_OSTYPE = 10; const std::string TEST_NETWORKID = "111111"; const std::string TEST_UUID = "222222"; const std::string TEST_UDID = "333333"; @@ -63,14 +64,20 @@ void AccessManagerTest::TearDownTestCase() {} */ HWTEST_F(AccessManagerTest, SendOnLineEvent_001, TestSize.Level1) { + int32_t ostype = -1; DHContext::GetInstance().AddOnlineDevice(TEST_UDID, TEST_UUID, TEST_NETWORKID); auto ret = DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(TEST_NETWORKID, TEST_UUID, TEST_UDID, - TEST_DEV_TYPE_PAD); + TEST_DEV_TYPE_PAD, ostype); EXPECT_EQ(ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_ONLINE, ret); DHContext::GetInstance().devIdEntrySet_.clear(); ret = DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(TEST_NETWORKID, TEST_UUID, TEST_UDID, - TEST_DEV_TYPE_PAD); + TEST_DEV_TYPE_PAD, ostype); + EXPECT_EQ(DH_FWK_SUCCESS, ret); + + DHContext::GetInstance().devIdEntrySet_.clear(); + ret = DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(TEST_NETWORKID, TEST_UUID, TEST_UDID, + TEST_DEV_TYPE_PAD, INVALID_OSTYPE); EXPECT_EQ(DH_FWK_SUCCESS, ret); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp index 1a3b8566..211d48b4 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp @@ -1220,16 +1220,16 @@ HWTEST_F(ResourceManagerTest, SyncDataByNetworkId_001, TestSize.Level0) EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); } -HWTEST_F(ResourceManagerTest, ClearDataWhenPeerLogout_001, TestSize.Level0) +HWTEST_F(ResourceManagerTest, ClearRemoteDeviceMetaInfoData_001, TestSize.Level0) { MetaInfoManager::GetInstance()->Init(); std::string peerudid = "peerudid_test"; std::string peeruuid = "peeruuid_test"; - auto ret = MetaInfoManager::GetInstance()->ClearDataWhenPeerLogout(peerudid, peeruuid); - EXPECT_EQ(DH_FWK_SUCCESS, ret); + auto ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid); + EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL, ret); MetaInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; - ret = MetaInfoManager::GetInstance()->ClearDataWhenPeerLogout(peerudid, peeruuid); + ret = MetaInfoManager::GetInstance()->ClearRemoteDeviceMetaInfoData(peerudid, peeruuid); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); } } // namespace DistributedHardware diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index ddb7a497..9fd96f06 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -77,6 +77,8 @@ bool IsArrayLengthValid(const std::vector &array); bool IsKeySizeValid(const std::string &key); bool IsHashSizeValid(const std::string &hashValue); + +int32_t GetDeviceSystemType(const std::string &extraData); } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 455e031f..8d7b19aa 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -45,6 +45,7 @@ namespace { constexpr unsigned char MASK = 0x0F; constexpr int32_t DOUBLE_TIMES = 2; constexpr int32_t COMPRESS_SLICE_SIZE = 1024; + const std::string PARAM_KEY_OS_TYPE = "OS_TYPE"; } int64_t GetCurrentTime() @@ -344,5 +345,23 @@ bool IsHashSizeValid(const std::string &inputHashValue) } return true; } + +int32_t GetDeviceSystemType(const std::string &extraData) +{ + cJSON *jsonObj = cJSON_Parse(extraData.c_str()); + if (jsonObj == NULL) { + DHLOGE("jsonStr parse failed"); + return ERR_DH_FWK_INVALID_OSTYPE; + } + cJSON *paramKey = cJSON_GetObjectItem(jsonObj, PARAM_KEY_OS_TYPE.c_str()); + if (paramKey == NULL || !cJSON_IsNumber(paramKey)) { + DHLOGE("paramKey is null or paramKey is invaild type!"); + cJSON_Delete(jsonObj); + return ERR_DH_FWK_INVALID_OSTYPE; + } + int32_t osType = paramKey->valueint; + cJSON_Delete(jsonObj); + return osType; +} } // namespace DistributedHardware } // namespace OHOS