From 4429ea7804c9f314ec9c0e555462c664a1840caf Mon Sep 17 00:00:00 2001 From: hunili Date: Wed, 24 Jan 2024 10:04:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9C=80=E6=96=B0dp=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20issue:=20https://gitee.com/openharmony/deviceprofil?= =?UTF-8?q?e=5Fdevice=5Finfo=5Fmanager/issues/I8YDI7=20Signed-off-by:=20hu?= =?UTF-8?q?nili=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../innerkits/common/include/dms_constant.h | 7 +- services/dtbschedmgr/BUILD.gn | 1 + .../include/dtbschedmgr_device_info_storage.h | 18 ++--- .../src/adapter/dnetwork_adapter.cpp | 1 - .../dtbschedmgr/src/dms_version_manager.cpp | 12 ++- .../src/dtbschedmgr_device_info_storage.cpp | 76 +++---------------- .../dtbschedmgr_device_info_storage_test.cpp | 14 ---- 7 files changed, 29 insertions(+), 100 deletions(-) diff --git a/interfaces/innerkits/common/include/dms_constant.h b/interfaces/innerkits/common/include/dms_constant.h index cb668d85..d4379e18 100644 --- a/interfaces/innerkits/common/include/dms_constant.h +++ b/interfaces/innerkits/common/include/dms_constant.h @@ -20,7 +20,12 @@ namespace OHOS { namespace DistributedSchedule { namespace Constants { constexpr const char* DMS_NAME = "dmsfwk"; -constexpr const char* DMS_VERSION = "4.0.0"; +constexpr const char* DMS_VERSION = "4.1.0"; +constexpr const char* DMS_SERVICE_ID = "dmsfwk_svr_id"; +constexpr const char* DMS_CHAR_ID = "dmsInfo"; +constexpr const char* PACKAGE_NAMES = "packageNames"; +constexpr const char* VERSIONS = "versions"; +constexpr const char* DMS_SERVICE_TYPE = "appInfo"; } // Constants } // DistributedSchedule } // OHOS diff --git a/services/dtbschedmgr/BUILD.gn b/services/dtbschedmgr/BUILD.gn index d37d4e5d..d9f18b65 100644 --- a/services/dtbschedmgr/BUILD.gn +++ b/services/dtbschedmgr/BUILD.gn @@ -28,6 +28,7 @@ config("distributed_sched_config") { "${communication_path}/dsoftbus/dsoftbus_enhance/interfaces/kits/broadcast", "${communication_path}/dsoftbus/interfaces/kits/common", "${dms_path}/interfaces/kits/napi/include", + "${dms_path}/interfaces/innerkits/common/include", "include/distributedWant", "//third_party/cJSON", ] diff --git a/services/dtbschedmgr/include/dtbschedmgr_device_info_storage.h b/services/dtbschedmgr/include/dtbschedmgr_device_info_storage.h index 34ca80ff..5dc8b9da 100644 --- a/services/dtbschedmgr/include/dtbschedmgr_device_info_storage.h +++ b/services/dtbschedmgr/include/dtbschedmgr_device_info_storage.h @@ -25,7 +25,6 @@ #include "event_handler.h" #include "iremote_object.h" #include "single_instance.h" -#include "sync_completed_callback_stub.h" namespace OHOS { namespace DistributedSchedule { @@ -63,6 +62,13 @@ public: */ std::string GetUuidByNetworkId(const std::string& networkId); + /** + * get udid by networkId + * + * @param networkId + */ + std::string GetUdidByNetworkId(const std::string& networkId); + /** * get networkId by uuid * @@ -84,13 +90,6 @@ public: */ void UpdateDeviceInfoStorage(const std::vector& dmDeviceInfoList); - /** - * Sync dms version info to remote - * - * @param remoteNetworkId - */ - int32_t SyncDmsVersionInfoToRemote(const std::string& remoteNetworkId); - private: bool InitNetworkIdManager(std::shared_ptr dnetworkAdapter); bool ConnectSoftbus(); @@ -108,9 +107,6 @@ private: std::mutex uuidNetworkIdLock_; std::shared_ptr initHandler_; std::shared_ptr networkIdMgrHandler_; - class SyncCallback : public OHOS::DistributedDeviceProfile::SyncCompletedCallbackStub { - void OnSyncCompleted(const std::map &syncResults); - }; }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/src/adapter/dnetwork_adapter.cpp b/services/dtbschedmgr/src/adapter/dnetwork_adapter.cpp index 714ba89b..7c06f6e1 100644 --- a/services/dtbschedmgr/src/adapter/dnetwork_adapter.cpp +++ b/services/dtbschedmgr/src/adapter/dnetwork_adapter.cpp @@ -78,7 +78,6 @@ void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo& HILOGE("OnNodeOnline post task failed"); return; } - DtbschedmgrDeviceInfoStorage::GetInstance().SyncDmsVersionInfoToRemote(networkId); } void DnetworkAdapter::DmsDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo& deviceInfo) diff --git a/services/dtbschedmgr/src/dms_version_manager.cpp b/services/dtbschedmgr/src/dms_version_manager.cpp index d0742e68..4c96ad13 100644 --- a/services/dtbschedmgr/src/dms_version_manager.cpp +++ b/services/dtbschedmgr/src/dms_version_manager.cpp @@ -16,6 +16,7 @@ #include "dms_version_manager.h" #include "distributed_device_profile_client.h" +#include "dms_constant.h" #include "dtbschedmgr_device_info_storage.h" #include "dtbschedmgr_log.h" #include "nlohmann/json.hpp" @@ -23,14 +24,11 @@ namespace OHOS { namespace DistributedSchedule { + +using namespace Constants; + namespace { const std::string TAG = "DmsVersionManager"; -const std::string DMS_SERVICE_ID = "dmsfwk_svr_id"; -const std::string DMS_CHAR_ID = "dmsInfo"; -const std::string DMS_SERVICE_TYPE = "appInfo"; -const std::string PACKAGE_NAMES = "packageNames"; -const std::string VERSIONS = "versions"; -const std::string DMS_NAME = "dmsfwk"; const int32_t DMS_VERSION_LENGTH = 3; const int32_t DMS_MAJOR_VERSION_INDEX = 0; const int32_t DMS_MINOR_VERSION_INDEX = 1; @@ -81,7 +79,7 @@ int32_t DmsVersionManager::GetAppInfoFromDP(const std::string& deviceId, std::st { DistributedDeviceProfile::CharacteristicProfile profile; std::string udid = ""; - udid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUuidByNetworkId(deviceId); + udid = DtbschedmgrDeviceInfoStorage::GetInstance().GetUdidByNetworkId(deviceId); int32_t result = DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance().GetCharacteristicProfile( udid, DMS_SERVICE_ID, DMS_CHAR_ID, profile); if (result != ERR_OK) { diff --git a/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp b/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp index 4c5dcd8e..8f3f121e 100644 --- a/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp +++ b/services/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp @@ -19,13 +19,11 @@ #include #include "distributed_device_node_listener.h" -#include "distributed_device_profile_client.h" #include "distributed_sched_service.h" #include "dtbschedmgr_log.h" #include "ipc_object_proxy.h" #include "ipc_skeleton.h" #include "iservice_registry.h" -#include "cJSON.h" #include "system_ability_definition.h" using namespace std; @@ -33,18 +31,11 @@ namespace OHOS { namespace DistributedSchedule { using namespace std::chrono_literals; using namespace DistributedHardware; -using namespace DistributedDeviceProfile; namespace { constexpr int32_t RETRY_TIMES = 30; constexpr int32_t CONNECT_SOFTBUS_RETRY_TIMES = 60; const std::string TAG = "DtbschedmgrDeviceInfoStorage"; -const std::string DMS_SERVICE_ID = "dmsfwk_svr_id"; -const std::string DMS_CHAR_ID = "dmsInfo"; -const std::string DMS_VERSION = "4.1.0"; -const std::string DMS_NAMES = "dmsfwk"; -constexpr const char *PACKAGE_NAMES = "packageNames"; -constexpr const char *VERSIONS = "versions"; } IMPLEMENT_SINGLE_INSTANCE(DtbschedmgrDeviceInfoStorage); @@ -198,52 +189,6 @@ void DtbschedmgrDeviceInfoStorage::UpdateDeviceInfoStorage( } } -int32_t DtbschedmgrDeviceInfoStorage::SyncDmsVersionInfoToRemote(const std::string& remoteNetworkId) -{ - std::string localUdid = ""; - GetLocalUdid(localUdid); - if (localUdid.empty()) { - HILOGE("getlocaludid failed, localUdid is empty"); - } - DistributedDeviceProfile::ServiceProfile serviceProfile; - serviceProfile.SetDeviceId(localUdid); - serviceProfile.SetServiceName(DMS_SERVICE_ID); - serviceProfile.SetServiceType(DMS_SERVICE_ID); - DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance().PutServiceProfile(serviceProfile); - - DistributedDeviceProfile::CharacteristicProfile characteristicProfile; - characteristicProfile.SetDeviceId(localUdid); - characteristicProfile.SetServiceName(DMS_SERVICE_ID); - characteristicProfile.SetCharacteristicKey(DMS_CHAR_ID); - cJSON *jObject = cJSON_CreateObject(); - if (jObject == nullptr) { - HILOGE("Failed to create cJSON object."); - return ERR_NULL_OBJECT; - } - cJSON_AddStringToObject(jObject, PACKAGE_NAMES, DMS_NAMES.c_str()); - cJSON_AddStringToObject(jObject, VERSIONS, DMS_VERSION.c_str()); - char *jsonData = cJSON_PrintUnformatted(jObject); - if (jsonData == nullptr) { - HILOGE("Failed to create JSON data."); - cJSON_Delete(jObject); - return ERR_NULL_OBJECT; - } - std::string dmsInfo(jsonData); - cJSON_Delete(jObject); - cJSON_free(jsonData); - characteristicProfile.SetCharacteristicValue(dmsInfo); - DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance(). - PutCharacteristicProfile(characteristicProfile); - - SyncOptions syncOptions; - syncOptions.AddDevice(remoteNetworkId); - syncOptions.SetSyncMode(SyncMode::PUSH_PULL); - sptr syncCallback = new(std::nothrow) SyncCallback; - int32_t syncRes = DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOptions, syncCallback); - HILOGI("SyncDeviceProfile result: %{public}d", syncRes); - return syncRes; -} - bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceId(std::string& networkId) { return GetLocalDeviceFromDnet(networkId); @@ -326,6 +271,16 @@ std::string DtbschedmgrDeviceInfoStorage::GetUuidByNetworkId(const std::string& return uuid; } +std::string DtbschedmgrDeviceInfoStorage::GetUdidByNetworkId(const std::string& networkId) +{ + if (networkId.empty()) { + HILOGW("GetUdidByNetworkId networkId empty!"); + return ""; + } + std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(networkId); + return udid; +} + std::string DtbschedmgrDeviceInfoStorage::GetNetworkIdByUuid(const std::string& uuid) { if (uuid.empty()) { @@ -401,17 +356,6 @@ void DtbschedmgrDeviceInfoStorage::OnDeviceInfoChanged(const std::string& device HILOGI("OnDeviceInfoChanged called"); } -void DtbschedmgrDeviceInfoStorage::SyncCallback::OnSyncCompleted(const std::map &syncResults) -{ - for (const auto &item : syncResults) { - std::string networkId = item.first; - int32_t syncResult = item.second; - HILOGI("networkId: %{public}s, SyncStatus: %{public}d", - DnetworkAdapter::AnonymizeNetworkId(networkId).c_str(), syncResult); - } -} - void DnetServiceDeathRecipient::OnRemoteDied(const wptr& remote) { HILOGI("OnRemoteDied dnetwork service died"); diff --git a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp index cfc64196..433f3b59 100644 --- a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp +++ b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp @@ -416,19 +416,5 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetLocalDeviceUdidTest_001, TestSize. EXPECT_EQ(!udid.empty(), true); DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetLocalDeviceUdidTest_001 end" << std::endl; } - -/** - * @tc.name: SyncDmsVersionInfoToRemoteTest_001 - * @tc.desc: test SyncDmsVersionInfoToRemote - * @tc.type: FUNC - */ -HWTEST_F(DtbschedmgrDeviceInfoStorageTest, SyncDmsVersionInfoToRemoteTest_001, TestSize.Level3) -{ - DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest SyncDmsVersionInfoToRemoteTest_001 start" << std::endl; - std::string remoteNetworkId = "test"; - int32_t result = DtbschedmgrDeviceInfoStorage::GetInstance().SyncDmsVersionInfoToRemote(remoteNetworkId); - EXPECT_TRUE(result != DistributedDeviceProfile::DP_SUCCESS); - DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest SyncDmsVersionInfoToRemoteTest_001 end" << std::endl; -} } // namespace DistributedSchedule } // namespace OHOS