From d4edf710b4dc233f3d049541ffc20600e8e7aded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Tue, 10 Dec 2024 10:00:15 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../src/device_manager_service_impl.cpp | 53 ---- .../src/device_manager_service_impl_lite.cpp | 39 --- .../src/discovery/dm_discovery_filter.cpp | 235 --------------- .../src/discovery/dm_discovery_manager.cpp | 285 ------------------ .../src/publish/dm_publish_manager.cpp | 135 --------- 5 files changed, 747 deletions(-) delete mode 100644 services/implementation/src/discovery/dm_discovery_filter.cpp delete mode 100644 services/implementation/src/discovery/dm_discovery_manager.cpp delete mode 100644 services/implementation/src/publish/dm_publish_manager.cpp diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index ef62fddad..66a8b686b 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -57,12 +57,6 @@ int32_t DeviceManagerServiceImpl::Initialize(const std::shared_ptr(); } - if (discoveryMgr_ == nullptr) { - discoveryMgr_ = std::make_shared(softbusConnector_, listener, hiChainConnector_); - } - if (publishMgr_ == nullptr) { - publishMgr_ = std::make_shared(softbusConnector_, listener); - } if (hiChainAuthConnector_ == nullptr) { hiChainAuthConnector_ = std::make_shared(); } @@ -109,53 +103,6 @@ void DeviceManagerServiceImpl::Release() dpInitedCallback_ = nullptr; } -int32_t DeviceManagerServiceImpl::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, - const std::string &extra) -{ - if (pkgName.empty()) { - LOGE("StartDeviceDiscovery failed, pkgName is empty"); - return ERR_DM_INPUT_PARA_INVALID; - } - return discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); -} - -int32_t DeviceManagerServiceImpl::StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId, - const std::string &filterOptions) -{ - if (pkgName.empty()) { - LOGE("StartDeviceDiscovery failed, pkgName is empty"); - return ERR_DM_INPUT_PARA_INVALID; - } - return discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeId, filterOptions); -} - -int32_t DeviceManagerServiceImpl::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) -{ - if (pkgName.empty()) { - LOGE("StopDeviceDiscovery failed, pkgName is empty"); - return ERR_DM_INPUT_PARA_INVALID; - } - return discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); -} - -int32_t DeviceManagerServiceImpl::PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo) -{ - if (pkgName.empty()) { - LOGE("PublishDeviceDiscovery failed, pkgName is empty"); - return ERR_DM_INPUT_PARA_INVALID; - } - return publishMgr_->PublishDeviceDiscovery(pkgName, publishInfo); -} - -int32_t DeviceManagerServiceImpl::UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId) -{ - if (pkgName.empty()) { - LOGE("UnPublishDeviceDiscovery failed, pkgName is empty"); - return ERR_DM_INPUT_PARA_INVALID; - } - return publishMgr_->UnPublishDeviceDiscovery(pkgName, publishId); -} - int32_t DeviceManagerServiceImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel) { diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index d08c6c5d8..a36d2b4e4 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -71,45 +71,6 @@ void DeviceManagerServiceImpl::Release() mineHiChainConnector_ = nullptr; } -int32_t DeviceManagerServiceImpl::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, - const std::string &extra) -{ - (void)pkgName; - (void)subscribeInfo; - (void)extra; - return DM_OK; -} - -int32_t DeviceManagerServiceImpl::StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId, - const std::string &filterOptions) -{ - (void)pkgName; - (void)subscribeId; - (void)filterOptions; - return DM_OK; -} - -int32_t DeviceManagerServiceImpl::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) -{ - (void)pkgName; - (void)subscribeId; - return DM_OK; -} - -int32_t DeviceManagerServiceImpl::PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo) -{ - (void)pkgName; - (void)publishInfo; - return DM_OK; -} - -int32_t DeviceManagerServiceImpl::UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId) -{ - (void)pkgName; - (void)publishId; - return DM_OK; -} - int32_t DeviceManagerServiceImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel) { diff --git a/services/implementation/src/discovery/dm_discovery_filter.cpp b/services/implementation/src/discovery/dm_discovery_filter.cpp deleted file mode 100644 index 7eb5ae7dd..000000000 --- a/services/implementation/src/discovery/dm_discovery_filter.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -#include "dm_discovery_filter.h" - -#include "dm_anonymous.h" -#include "dm_constants.h" -#include "dm_device_info.h" -#include "dm_log.h" -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DistributedHardware { -const std::string FILTERS_KEY = "filters"; -const std::string FILTER_OP_KEY = "filter_op"; -const std::string FILTERS_TYPE_OR = "OR"; -const std::string FILTERS_TYPE_AND = "AND"; - -enum DmDiscoveryDeviceFilter { - DM_INVALID_DEVICE = 0, - DM_VALID_DEVICE = 1, - DM_ALL_DEVICE = 2 -}; - -int32_t DmDeviceFilterOption::ParseFilterJson(const std::string &str) -{ - nlohmann::json jsonObject = nlohmann::json::parse(str, nullptr, false); - if (jsonObject.is_discarded()) { - LOGE("FilterOptions parse error."); - return ERR_DM_INPUT_PARA_INVALID; - } - if (!jsonObject.contains(FILTERS_KEY) || !jsonObject[FILTERS_KEY].is_array() || jsonObject[FILTERS_KEY].empty()) { - LOGE("Filters invalid."); - return ERR_DM_INPUT_PARA_INVALID; - } - if (jsonObject.contains(FILTER_OP_KEY) && !jsonObject[FILTER_OP_KEY].is_string()) { - LOGE("Filters_op invalid."); - return ERR_DM_INPUT_PARA_INVALID; - } - if (!jsonObject.contains(FILTER_OP_KEY)) { - filterOp_ = FILTERS_TYPE_OR; // filterOp optional, "OR" default - } else { - jsonObject[FILTER_OP_KEY].get_to(filterOp_); - } - - for (const auto &object : jsonObject[FILTERS_KEY]) { - if (!object.contains("type") || !object["type"].is_string()) { - LOGE("Filters type invalid"); - return ERR_DM_INPUT_PARA_INVALID; - } - if (!object.contains("value") || !object["value"].is_number_integer()) { - LOGE("Filters value invalid"); - return ERR_DM_INPUT_PARA_INVALID; - } - DmDeviceFilters deviceFilters; - deviceFilters.type = object["type"]; - deviceFilters.value = object["value"]; - filters_.push_back(deviceFilters); - } - return DM_OK; -} - -void DmDeviceFilterOption::ParseFilterOptionJson(const std::string &str) -{ - nlohmann::json object = nlohmann::json::parse(str, nullptr, false); - if (object.is_discarded()) { - LOGE("FilterOptions parse error."); - return; - } - filterOp_ = FILTERS_TYPE_AND; - DmDeviceFilters deviceFilters; - if (!object.contains("credible") || !object["credible"].is_number_integer()) { - LOGE("Filters credible type invalid"); - } else { - deviceFilters.type = "credible"; - deviceFilters.value = object["credible"]; - filters_.push_back(deviceFilters); - } - - if (!object.contains("range") || !object["range"].is_number_integer()) { - LOGE("Filters range type invalid"); - } else { - deviceFilters.type = "range"; - deviceFilters.value = object["range"]; - filters_.push_back(deviceFilters); - } - - if (!object.contains("isTrusted") || !object["isTrusted"].is_number_integer()) { - LOGE("Filters isTrusted type invalid"); - } else { - deviceFilters.type = "isTrusted"; - deviceFilters.value = object["isTrusted"]; - filters_.push_back(deviceFilters); - } - - if (!object.contains("authForm") || !object["authForm"].is_number_integer()) { - LOGE("Filters authForm type invalid"); - } else { - deviceFilters.type = "authForm"; - deviceFilters.value = object["authForm"]; - filters_.push_back(deviceFilters); - } - - if (!object.contains("deviceType") || !object["deviceType"].is_number_integer()) { - LOGE("Filters deviceType type invalid"); - } else { - deviceFilters.type = "deviceType"; - deviceFilters.value = object["deviceType"]; - filters_.push_back(deviceFilters); - } -} - -int32_t DmDeviceFilterOption::TransformToFilter(const std::string &filterOptions) -{ - if (filterOptions.empty()) { - LOGI("DmDeviceFilterOption::filterOptions empty"); - filterOp_ = FILTERS_TYPE_OR; - DmDeviceFilters deviceFilters; - deviceFilters.type = "credible"; - deviceFilters.value = DM_INVALID_DEVICE; - filters_.push_back(deviceFilters); - return DM_OK; - } - return ParseFilterJson(filterOptions); -} - -void DmDeviceFilterOption::TransformFilterOption(const std::string &filterOptions) -{ - if (filterOptions.empty()) { - LOGI("DmDeviceFilterOption::filterOptions empty"); - filterOp_ = FILTERS_TYPE_OR; - DmDeviceFilters deviceFilters; - deviceFilters.type = "credible"; - deviceFilters.value = DM_INVALID_DEVICE; - filters_.push_back(deviceFilters); - return; - } - ParseFilterOptionJson(filterOptions); -} - -bool DmDiscoveryFilter::FilterByDeviceState(int32_t value, bool isActive) -{ - if (value == DM_INVALID_DEVICE) { - return !isActive; - } - if (value == DM_VALID_DEVICE) { - return isActive; - } - return (value == DM_ALL_DEVICE); -} - -bool DmDiscoveryFilter::FilterByRange(int32_t value, int32_t range) -{ - return ((range > 0) && (range <= value)); -} - -bool DmDiscoveryFilter::FilterByAuthForm(int32_t value, int32_t authForm) -{ - return (value == authForm); -} - -bool DmDiscoveryFilter::FilterByDeviceType(int32_t value, int32_t deviceType) -{ - return (value == deviceType); -} - -bool DmDiscoveryFilter::FilterByType(const DmDeviceFilters &filters, const DmDeviceFilterPara &filterPara) -{ - LOGI("DmDiscoveryFilter::FilterByType: type: %{public}s, value: %{public}d", filters.type.c_str(), filters.value); - if (filters.type == "credible") { - return FilterByDeviceState(filters.value, filterPara.isOnline); - } - if (filters.type == "range") { - return FilterByRange(filters.value, filterPara.range); - } - if (filters.type == "isTrusted") { - return FilterByDeviceState(filters.value, filterPara.isTrusted); - } - if (filters.type == "authForm") { - return FilterByAuthForm(filters.value, filterPara.authForm); - } - if (filters.type == "deviceType") { - return FilterByDeviceType(filters.value, filterPara.deviceType); - } - return false; -} - -bool DmDiscoveryFilter::FilterOr(const std::vector &filters, const DmDeviceFilterPara &filterPara) -{ - for (auto &iter : filters) { - if (FilterByType(iter, filterPara) == true) { - return true; - } - } - return false; -} - -bool DmDiscoveryFilter::FilterAnd(const std::vector &filters, const DmDeviceFilterPara &filterPara) -{ - for (auto &iter : filters) { - if (FilterByType(iter, filterPara) == false) { - return false; - } - } - return true; -} - -bool DmDiscoveryFilter::IsValidDevice(const std::string &filterOp, const std::vector &filters, - const DmDeviceFilterPara &filterPara) -{ - LOGI("DmDiscoveryFilter::IsValidDevice: filterOp: %{public}s, isOnline: %{public}d, range: %{public}d, isTrusted:" - "%{public}d, authForm: %{public}d, deviceType: %{public}d", filterOp.c_str(), filterPara.isOnline, - filterPara.range, filterPara.isTrusted, filterPara.authForm, filterPara.deviceType); - if (filterOp == FILTERS_TYPE_OR) { - return FilterOr(filters, filterPara); - } - if (filterOp == FILTERS_TYPE_AND) { - return FilterAnd(filters, filterPara); - } - return false; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/implementation/src/discovery/dm_discovery_manager.cpp b/services/implementation/src/discovery/dm_discovery_manager.cpp deleted file mode 100644 index a872d4f02..000000000 --- a/services/implementation/src/discovery/dm_discovery_manager.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -#include "dm_discovery_manager.h" -#include "dm_discovery_filter.h" -#include "dm_anonymous.h" -#include "dm_constants.h" -#include "dm_log.h" -#include "dm_radar_helper.h" -#include "parameter.h" - -namespace OHOS { -namespace DistributedHardware { -constexpr const char* DISCOVERY_TIMEOUT_TASK = "deviceManagerTimer:discovery"; -const int32_t DISCOVERY_TIMEOUT = 120; - -DmDiscoveryManager::DmDiscoveryManager(std::shared_ptr softbusConnector, - std::shared_ptr listener, - std::shared_ptr hiChainConnector) - : softbusConnector_(softbusConnector), listener_(listener), hiChainConnector_(hiChainConnector) -{ - LOGI("DmDiscoveryManager constructor"); -} - -DmDiscoveryManager::~DmDiscoveryManager() -{ - LOGI("DmDiscoveryManager destructor"); -} - -void DmDiscoveryManager::CfgDiscoveryTimer() -{ - if (timer_ == nullptr) { - timer_ = std::make_shared(); - } - timer_->StartTimer(std::string(DISCOVERY_TIMEOUT_TASK), DISCOVERY_TIMEOUT, - [this] (std::string name) { - DmDiscoveryManager::HandleDiscoveryTimeout(name); - }); -} - -int32_t DmDiscoveryManager::CheckDiscoveryQueue(const std::string &pkgName) -{ - uint16_t subscribeId = 0; - std::string frontPkgName = ""; - { - std::lock_guard autoLock(locks_); - if (discoveryQueue_.empty()) { - return DM_OK; - } - - frontPkgName = discoveryQueue_.front(); - if (pkgName == frontPkgName) { - LOGE("DmDiscoveryManager::StartDeviceDiscovery repeated, pkgName:%{public}s", pkgName.c_str()); - return ERR_DM_DISCOVERY_REPEATED; - } - - LOGI("DmDiscoveryManager::StartDeviceDiscovery stop preview discovery first, the preview pkgName is %{public}s", - discoveryQueue_.front().c_str()); - subscribeId = discoveryContextMap_[frontPkgName].subscribeId; - } - StopDeviceDiscovery(frontPkgName, subscribeId); - return DM_OK; -} - -int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, - const std::string &extra) -{ - DmDeviceFilterOption dmFilter; - if (dmFilter.TransformToFilter(extra) != DM_OK) { - return ERR_DM_INPUT_PARA_INVALID; - } - - if (CheckDiscoveryQueue(pkgName) != DM_OK) { - return ERR_DM_DISCOVERY_REPEATED; - } - { - std::lock_guard autoLock(locks_); - discoveryQueue_.push(pkgName); - DmDiscoveryContext context = {pkgName, extra, subscribeInfo.subscribeId, dmFilter.filterOp_, dmFilter.filters_}; - discoveryContextMap_.emplace(pkgName, context); - } - softbusConnector_->RegisterSoftbusDiscoveryCallback(pkgName, - std::shared_ptr(shared_from_this())); - CfgDiscoveryTimer(); - return softbusConnector_->StartDiscovery(subscribeInfo); -} - -int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId, - const std::string &filterOptions) -{ - DmDeviceFilterOption dmFilter; - dmFilter.TransformFilterOption(filterOptions); - if (CheckDiscoveryQueue(pkgName) != DM_OK) { - return ERR_DM_DISCOVERY_REPEATED; - } - { - std::lock_guard autoLock(locks_); - discoveryQueue_.push(pkgName); - DmDiscoveryContext context = {pkgName, filterOptions, subscribeId, dmFilter.filterOp_, dmFilter.filters_}; - discoveryContextMap_.emplace(pkgName, context); - } - softbusConnector_->RegisterSoftbusDiscoveryCallback(pkgName, - std::shared_ptr(shared_from_this())); - CfgDiscoveryTimer(); - return softbusConnector_->StartDiscovery(subscribeId); -} - -int32_t DmDiscoveryManager::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) -{ - if (pkgName.empty()) { - LOGE("Invalid parameter, pkgName is empty."); - return ERR_DM_INPUT_PARA_INVALID; - } - { - std::lock_guard autoLock(locks_); - if (!discoveryQueue_.empty()) { - discoveryQueue_.pop(); - } - if (!discoveryContextMap_.empty()) { - discoveryContextMap_.erase(pkgName); - if (timer_ != nullptr) { - timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK)); - } - } - } - softbusConnector_->UnRegisterSoftbusDiscoveryCallback(pkgName); - return softbusConnector_->StopDiscovery(subscribeId); -} - -void DmDiscoveryManager::OnDeviceFound(const std::string &pkgName, DmDeviceInfo &info, bool isOnline) -{ - LOGI("DmDiscoveryManager::OnDeviceFound deviceId = %{public}s", GetAnonyString(info.deviceId).c_str()); - DmDiscoveryContext discoveryContext; - { - std::lock_guard autoLock(locks_); - auto iter = discoveryContextMap_.find(pkgName); - if (iter == discoveryContextMap_.end()) { - LOGE("subscribeId not found by pkgName %{public}s", GetAnonyString(pkgName).c_str()); - return; - } - discoveryContext = iter->second; - } - DmDiscoveryFilter filter; - DmDeviceFilterPara filterPara; - filterPara.isOnline = isOnline; - filterPara.range = info.range; - filterPara.deviceType = info.deviceTypeId; - char localDeviceId[DEVICE_UUID_LENGTH]; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - info.authForm = DmAuthForm::INVALID_TYPE; - GetAuthForm(localDeviceId, info.deviceId, filterPara.isTrusted, info.authForm); - filterPara.authForm = info.authForm; - return; -} - -int32_t DmDiscoveryManager::GetAuthForm(const std::string &localDeviceId, const std::string &deviceId, - bool &isTrusted, DmAuthForm &authForm) -{ - LOGI("Get localDeviceId: %{public}s auth form.", GetAnonyString(localDeviceId).c_str()); - isTrusted = false; - if (localDeviceId.empty() || deviceId.empty()) { - LOGE("Invalid parameter."); - return ERR_DM_INPUT_PARA_INVALID; - } - if (hiChainConnector_ == nullptr || softbusConnector_ == nullptr) { - LOGE("hiChainConnector_ or softbusConnector_ is nullpter."); - return ERR_DM_POINT_NULL; - } - - std::vector trustDeviceUdidList = hiChainConnector_->GetTrustedDevices(localDeviceId); - if (trustDeviceUdidList.empty()) { - LOGI("Trusted devices is empty."); - return DM_OK; - } - std::string udidHash; - for (auto udid : trustDeviceUdidList) { - udidHash = softbusConnector_->GetDeviceUdidHashByUdid(udid); - if (udidHash == deviceId) { - isTrusted = true; - authForm = hiChainConnector_->GetGroupType(udid); - LOGI("deviceId: %{public}s is trusted!", GetAnonyString(deviceId).c_str()); - } - } - - return DM_OK; -} - -void DmDiscoveryManager::OnDeviceFound(const std::string &pkgName, - DmDeviceBasicInfo &info, const int32_t range, bool isOnline) -{ - LOGI("DmDiscoveryManager::OnDeviceFound deviceId = %{public}s,isOnline %{public}d", - GetAnonyString(info.deviceId).c_str(), isOnline); - DmDiscoveryContext discoveryContext; - { - std::lock_guard autoLock(locks_); - auto iter = discoveryContextMap_.find(pkgName); - if (iter == discoveryContextMap_.end()) { - LOGE("subscribeId not found by pkgName %{public}s", GetAnonyString(pkgName).c_str()); - return; - } - discoveryContext = iter->second; - } - DmDiscoveryFilter filter; - DmDeviceFilterPara filterPara; - filterPara.isOnline = isOnline; - filterPara.range = range; - filterPara.deviceType = info.deviceTypeId; - char localDeviceId[DEVICE_UUID_LENGTH]; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - DmAuthForm authForm = DmAuthForm::INVALID_TYPE; - GetAuthForm(localDeviceId, info.deviceId, filterPara.isTrusted, authForm); - filterPara.authForm = authForm; - return; -} - -void DmDiscoveryManager::OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason) -{ - LOGI("DmDiscoveryManager::OnDiscoveryFailed subscribeId = %{public}d reason = %{public}d", subscribeId, - failedReason); - if (pkgName.empty()) { - LOGE("Invalid parameter, pkgName is empty."); - return; - } - { - std::lock_guard autoLock(locks_); - if (!discoveryQueue_.empty()) { - discoveryQueue_.pop(); - } - if (!discoveryContextMap_.empty()) { - discoveryContextMap_.erase(pkgName); - if (timer_ != nullptr) { - timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK)); - } - } - } - softbusConnector_->StopDiscovery(subscribeId); -} - -void DmDiscoveryManager::OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId) -{ - LOGI("DmDiscoveryManager::OnDiscoverySuccess subscribeId = %{public}d", subscribeId); - { - std::lock_guard autoLock(locks_); - discoveryContextMap_[pkgName].subscribeId = (uint32_t)subscribeId; - } -} - -void DmDiscoveryManager::HandleDiscoveryTimeout(std::string name) -{ - (void)name; - LOGI("DmDiscoveryManager::HandleDiscoveryTimeout"); - uint16_t subscribeId = 0; - std::string pkgName = ""; - { - std::lock_guard autoLock(locks_); - if (discoveryQueue_.empty()) { - LOGE("HandleDiscoveryTimeout: discovery queue is empty."); - return; - } - - pkgName = discoveryQueue_.front(); - auto iter = discoveryContextMap_.find(pkgName); - if (iter == discoveryContextMap_.end()) { - LOGE("HandleDiscoveryTimeout: subscribeId not found by pkgName %{public}s", - GetAnonyString(pkgName).c_str()); - return; - } - subscribeId = discoveryContextMap_[pkgName].subscribeId; - } - StopDeviceDiscovery(pkgName, subscribeId); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/implementation/src/publish/dm_publish_manager.cpp b/services/implementation/src/publish/dm_publish_manager.cpp deleted file mode 100644 index b09398161..000000000 --- a/services/implementation/src/publish/dm_publish_manager.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -#include "dm_publish_manager.h" -#include "dm_anonymous.h" -#include "dm_constants.h" -#include "dm_log.h" - -namespace OHOS { -namespace DistributedHardware { -constexpr const char* PUBLISH_DISCOVERY_TIMEOUT_TASK = "deviceManagerTimer:publish"; -const int32_t PUBLISH_DISCOVERY_TIMEOUT = 120; - -DmPublishManager::DmPublishManager(std::shared_ptr softbusConnector, - std::shared_ptr listener) - : softbusConnector_(softbusConnector), listener_(listener) -{ - LOGI("DmPublishManager constructor"); -} - -DmPublishManager::~DmPublishManager() -{ - LOGI("DmPublishManager destructor"); -} - -void DmPublishManager::CfgPublishTimer() -{ - if (timer_ == nullptr) { - timer_ = std::make_shared(); - } - timer_->StartTimer(std::string(PUBLISH_DISCOVERY_TIMEOUT_TASK), PUBLISH_DISCOVERY_TIMEOUT, - [this] (std::string name) { - DmPublishManager::HandlePublishTimeout(name); - }); -} - -int32_t DmPublishManager::CheckPublishQueue(const std::string &pkgName) -{ - if (publishQueue_.empty()) { - return DM_OK; - } - - if (pkgName == publishQueue_.front()) { - LOGE("DmPublishManager::pkgName : %{public}s PublishDeviceDiscovery repeated", pkgName.c_str()); - return ERR_DM_PUBLISH_REPEATED; - } else { - LOGI("DmPublishManager::UnPublishDeviceDiscovery the preview pkgName : %{public}s", - publishQueue_.front().c_str()); - UnPublishDeviceDiscovery(publishQueue_.front(), - publishContextMap_[publishQueue_.front()].publishInfo.publishId); - return DM_OK; - } -} - -int32_t DmPublishManager::PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo) -{ - int32_t ret = CheckPublishQueue(pkgName); - if (ret != DM_OK) { - return ret; - } - std::lock_guard autoLock(locks_); - publishQueue_.push(pkgName); - DmPublishContext context = {pkgName, publishInfo}; - publishContextMap_.emplace(pkgName, context); - softbusConnector_->RegisterSoftbusPublishCallback(pkgName, - std::shared_ptr(shared_from_this())); - CfgPublishTimer(); - return softbusConnector_->PublishDiscovery(publishInfo); -} - -int32_t DmPublishManager::UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId) -{ - if (pkgName.empty()) { - LOGE("Invalid parameter, pkgName is empty."); - return ERR_DM_INPUT_PARA_INVALID; - } - std::lock_guard autoLock(locks_); - if (!publishQueue_.empty()) { - publishQueue_.pop(); - } - if (!publishContextMap_.empty()) { - publishContextMap_.erase(pkgName); - softbusConnector_->UnRegisterSoftbusPublishCallback(pkgName); - if (timer_ != nullptr) { - timer_->DeleteTimer(std::string(PUBLISH_DISCOVERY_TIMEOUT_TASK)); - } - } - return softbusConnector_->UnPublishDiscovery(publishId); -} - -void DmPublishManager::OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) -{ - if (pkgName.empty()) { - LOGE("Invalid parameter, pkgName is empty."); - return; - } - LOGI("DmPublishManager::OnPublishResult, publishId = %{public}d, publishResult = %{public}d", publishId, - publishResult); - if (publishResult != 0) { - UnPublishDeviceDiscovery(pkgName, publishId); - } - listener_->OnPublishResult(pkgName, publishId, publishResult); -} - -void DmPublishManager::HandlePublishTimeout(std::string name) -{ - (void)name; - LOGI("DmPublishManager::HandlePublishDiscoveryTimeout"); - if (publishQueue_.empty()) { - LOGE("HandlePublishDiscoveryTimeout: Publish discovery queue is empty."); - return; - } - - std::string pkgName = publishQueue_.front(); - auto iter = publishContextMap_.find(pkgName); - if (iter == publishContextMap_.end()) { - LOGE("HandleDiscoveryTimeout:pkgName %{public}s fail to publish", GetAnonyString(pkgName).c_str()); - return; - } - UnPublishDeviceDiscovery(pkgName, iter->second.publishInfo.publishId); -} -} // namespace DistributedHardware -} // namespace OHOS -- Gitee From 3adc24dc5d47df929628012200aa42158fe22935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Tue, 10 Dec 2024 14:41:45 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/implementation/BUILD.gn | 5 --- .../include/device_manager_service_impl.h | 16 -------- .../src/device_manager_service_impl.cpp | 2 - .../include/idevice_manager_service_impl.h | 37 ------------------- test/unittest/BUILD.gn | 1 - 5 files changed, 61 deletions(-) diff --git a/services/implementation/BUILD.gn b/services/implementation/BUILD.gn index 737475f96..8599d59e5 100644 --- a/services/implementation/BUILD.gn +++ b/services/implementation/BUILD.gn @@ -114,8 +114,6 @@ if (defined(ohos_lite)) { "include/ability", "include/credential", "include/devicestate", - "include/discovery", - "include/publish", "include/dependency/commonevent", "include/dependency/deviceprofile", "include/dependency/multipleuser", @@ -176,9 +174,6 @@ if (defined(ohos_lite)) { "src/dependency/softbus/softbus_session.cpp", "src/device_manager_service_impl.cpp", "src/devicestate/dm_device_state_manager.cpp", - "src/discovery/dm_discovery_filter.cpp", - "src/discovery/dm_discovery_manager.cpp", - "src/publish/dm_publish_manager.cpp", ] public_configs = [ ":devicemanagerserviceimpl_config" ] diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 12c09caa2..d13962533 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -26,8 +26,6 @@ #include "dm_credential_manager.h" #include "dm_device_info.h" #include "dm_device_state_manager.h" -#include "dm_discovery_manager.h" -#include "dm_publish_manager.h" #include "dp_inited_callback.h" #include "idevice_manager_service_impl.h" #include "dm_single_instance.h" @@ -45,18 +43,6 @@ public: void Release(); - int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, - const std::string &extra); - - int32_t StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId, - const std::string &filterOptions); - - int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId); - - int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo); - - int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId); - int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); @@ -160,8 +146,6 @@ private: private: std::shared_ptr authMgr_; std::shared_ptr deviceStateMgr_; - std::shared_ptr discoveryMgr_; - std::shared_ptr publishMgr_; std::shared_ptr softbusConnector_; std::shared_ptr abilityMgr_; std::shared_ptr hiChainConnector_; diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 66a8b686b..a8a0381c1 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -94,8 +94,6 @@ void DeviceManagerServiceImpl::Release() hiChainConnector_->UnRegisterHiChainCallback(); authMgr_ = nullptr; deviceStateMgr_ = nullptr; - discoveryMgr_ = nullptr; - publishMgr_ = nullptr; softbusConnector_ = nullptr; abilityMgr_ = nullptr; hiChainConnector_ = nullptr; diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index bfa0f92be..164527d25 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -46,43 +46,6 @@ public: */ virtual void Release() = 0; - /** - * @tc.name: IDeviceManagerServiceImpl::StartDeviceDiscovery - * @tc.desc: Start Device Discovery of the device manager service impl - * @tc.type: FUNC - */ - virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, - const std::string &extra) = 0; - - /** - * @tc.name: IDeviceManagerServiceImpl::StartDeviceDiscovery - * @tc.desc: Start Device Discovery of the device manager service impl - * @tc.type: FUNC - */ - virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId, - const std::string &filterOptions) = 0; - - /** - * @tc.name: IDeviceManagerServiceImpl::StopDeviceDiscovery - * @tc.desc: Stop Device Discovery of the device manager service impl - * @tc.type: FUNC - */ - virtual int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) = 0; - - /** - * @tc.name: IDeviceManagerServiceImpl::PublishDeviceDiscovery - * @tc.desc: Publish Device Discovery of the device manager service impl - * @tc.type: FUNC - */ - virtual int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo) = 0; - - /** - * @tc.name: IDeviceManagerServiceImpl::UnPublishDeviceDiscovery - * @tc.desc: UnPublish Device Discovery of the device manager service impl - * @tc.type: FUNC - */ - virtual int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId) = 0; - /** * @tc.name: IDeviceManagerServiceImpl::UnAuthenticateDevice * @tc.desc: UnAuthenticate Device of the device manager service impl diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 176b10184..6f10bdaa2 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -1518,7 +1518,6 @@ ohos_unittest("UTTest_dm_publish_manager") { "${services_path}/src/softbus/softbus_listener.cpp", "${servicesimpl_path}/src/dependency/softbus/softbus_connector.cpp", "${servicesimpl_path}/src/dependency/softbus/softbus_session.cpp", - "${servicesimpl_path}/src/publish/dm_publish_manager.cpp", "${softbuscache_parh}/src/dm_softbus_cache.cpp", ] -- Gitee From 3af6896bb634070e1a09f689e615e27212592c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Tue, 10 Dec 2024 17:50:54 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../dependency/softbus/softbus_connector.h | 48 --- .../softbus/softbus_discovery_callback.h | 37 -- .../softbus/softbus_publish_callback.h | 27 -- .../include/discovery/dm_discovery_filter.h | 63 ---- .../include/discovery/dm_discovery_manager.h | 118 ------- .../include/publish/dm_publish_manager.h | 82 ----- .../dependency/softbus/softbus_connector.cpp | 318 ------------------ test/commonfuzztest/BUILD.gn | 1 - ...uthenticate_device_service_impl_fuzzer.cpp | 6 - .../dmdiscoverymanager_fuzzer/BUILD.gn | 71 ---- .../dmdiscoverymanager_fuzzer/corpus/init | 13 - .../dm_discovery_manager_fuzzer.cpp | 67 ---- .../dm_discovery_manager_fuzzer.h | 21 -- .../dmdiscoverymanager_fuzzer/project.xml | 25 -- .../UTTest_device_manager_service_impl.cpp | 163 --------- 15 files changed, 1060 deletions(-) delete mode 100644 services/implementation/include/dependency/softbus/softbus_discovery_callback.h delete mode 100644 services/implementation/include/dependency/softbus/softbus_publish_callback.h delete mode 100644 services/implementation/include/discovery/dm_discovery_filter.h delete mode 100644 services/implementation/include/discovery/dm_discovery_manager.h delete mode 100644 services/implementation/include/publish/dm_publish_manager.h delete mode 100644 test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn delete mode 100644 test/commonfuzztest/dmdiscoverymanager_fuzzer/corpus/init delete mode 100644 test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.cpp delete mode 100644 test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.h delete mode 100644 test/commonfuzztest/dmdiscoverymanager_fuzzer/project.xml diff --git a/services/implementation/include/dependency/softbus/softbus_connector.h b/services/implementation/include/dependency/softbus/softbus_connector.h index 49b417ce1..75ea054f4 100644 --- a/services/implementation/include/dependency/softbus/softbus_connector.h +++ b/services/implementation/include/dependency/softbus/softbus_connector.h @@ -38,34 +38,6 @@ namespace OHOS { namespace DistributedHardware { class SoftbusConnector { public: - /** - * @tc.name: SoftbusConnector::OnSoftbusPublishResult - * @tc.desc: OnSoftbusPublishResult of the SoftbusConnector - * @tc.type: FUNC - */ - static void OnSoftbusPublishResult(int32_t publishId, PublishResult result); - - /** - * @tc.name: SoftbusConnector::OnSoftbusDeviceFound - * @tc.desc: OnSoftbus DeviceFound of the SoftbusConnector - * @tc.type: FUNC - */ - static void OnSoftbusDeviceFound(const DeviceInfo *device); - - /** - * @tc.name: SoftbusConnector::OnSoftbusDeviceDiscovery - * @tc.desc: OnSoftbus DeviceDiscovery of the SoftbusConnector - * @tc.type: FUNC - */ - static void OnSoftbusDeviceDiscovery(const DeviceInfo *device); - - /** - * @tc.name: SoftbusConnector::OnSoftbusDiscoveryResult - * @tc.desc: OnSoftbus Discovery Result of the SoftbusConnector - * @tc.type: FUNC - */ - static void OnSoftbusDiscoveryResult(int subscribeId, RefreshResult result); - /** * @tc.name: SoftbusConnector::OnSoftbusJoinLNNResult * @tc.desc: OnSoftbus JoinLNN Result of the SoftbusConnector @@ -117,19 +89,8 @@ public: public: SoftbusConnector(); ~SoftbusConnector(); - int32_t RegisterSoftbusDiscoveryCallback(const std::string &pkgName, - const std::shared_ptr callback); - int32_t UnRegisterSoftbusDiscoveryCallback(const std::string &pkgName); - int32_t RegisterSoftbusPublishCallback(const std::string &pkgName, - const std::shared_ptr callback); - int32_t UnRegisterSoftbusPublishCallback(const std::string &pkgName); int32_t RegisterSoftbusStateCallback(const std::shared_ptr callback); int32_t UnRegisterSoftbusStateCallback(); - int32_t PublishDiscovery(const DmPublishInfo &dmPublishInfo); - int32_t UnPublishDiscovery(int32_t publishId); - int32_t StartDiscovery(const DmSubscribeInfo &dmSubscribeInfo); - int32_t StartDiscovery(const uint16_t subscribeId); - int32_t StopDiscovery(uint16_t subscribeId); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::shared_ptr GetSoftbusSession(); #endif @@ -165,21 +126,12 @@ private: }; static std::string remoteUdidHash_; static PulishStatus publishStatus; - static IRefreshCallback softbusDiscoveryCallback_; - static IRefreshCallback softbusDiscoveryByIdCallback_; - static IPublishCb softbusPublishCallback_; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::shared_ptr softbusSession_; #endif - static std::map> discoveryDeviceInfoMap_; - static std::map> discoveryCallbackMap_; - static std::map> publishCallbackMap_; std::shared_ptr deviceStateManagerCallback_; - static std::queue discoveryDeviceIdQueue_; static std::unordered_map deviceUdidMap_; static std::vector processInfoVec_; - static std::mutex discoveryCallbackMutex_; - static std::mutex discoveryDeviceInfoMutex_; static std::mutex deviceUdidLocks_; static std::mutex processInfoVecMutex_; }; diff --git a/services/implementation/include/dependency/softbus/softbus_discovery_callback.h b/services/implementation/include/dependency/softbus/softbus_discovery_callback.h deleted file mode 100644 index 6457d1a49..000000000 --- a/services/implementation/include/dependency/softbus/softbus_discovery_callback.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2022 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_DM_SOFTBUS_DISCOVERY_CALLBACK_H -#define OHOS_DM_SOFTBUS_DISCOVERY_CALLBACK_H - -namespace OHOS { -namespace DistributedHardware { -class ISoftbusDiscoveryCallback { -public: - virtual void OnDeviceFound(const std::string &pkgName, DmDeviceInfo &info, bool isOnline) = 0; - virtual void OnDeviceFound(const std::string &pkgName, DmDeviceBasicInfo &info, - const int32_t range, bool isOnline) - { - (void)pkgName; - (void)info; - (void)range; - (void)isOnline; - }; - virtual void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId) = 0; - virtual void OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_SOFTBUS_DISCOVERY_CALLBACK_H diff --git a/services/implementation/include/dependency/softbus/softbus_publish_callback.h b/services/implementation/include/dependency/softbus/softbus_publish_callback.h deleted file mode 100644 index 6ca3454ba..000000000 --- a/services/implementation/include/dependency/softbus/softbus_publish_callback.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2022 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_DM_SOFTBUS_PUBLISH_CALLBACK_H -#define OHOS_DM_SOFTBUS_PUBLISH_CALLBACK_H - -namespace OHOS { -namespace DistributedHardware { -class ISoftbusPublishCallback { -public: - virtual void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_SOFTBUS_PUBLISH_CALLBACK_H diff --git a/services/implementation/include/discovery/dm_discovery_filter.h b/services/implementation/include/discovery/dm_discovery_filter.h deleted file mode 100644 index b183ad407..000000000 --- a/services/implementation/include/discovery/dm_discovery_filter.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2022 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_DM_DISCOVERY_FILTER_H -#define OHOS_DM_DISCOVERY_FILTER_H - -#include -#include - -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DistributedHardware { -struct DmDeviceFilters { - std::string type; - int32_t value; -}; - -struct DmDeviceFilterOption { - std::string filterOp_; - std::vector filters_; - int32_t ParseFilterJson(const std::string &str); - void ParseFilterOptionJson(const std::string &str); - int32_t TransformToFilter(const std::string &filterOptions); - void TransformFilterOption(const std::string &filterOptions); -}; - -struct DmDeviceFilterPara { - bool isOnline; - int32_t range; - bool isTrusted; - int32_t authForm; - int32_t deviceType; -}; - -class DmDiscoveryFilter { -public: - bool IsValidDevice(const std::string &filterOp, const std::vector &filters, - const DmDeviceFilterPara &filterPara); -private: - bool FilterByDeviceState(int32_t value, bool isActive); - bool FilterByRange(int32_t value, int32_t range); - bool FilterByAuthForm(int32_t value, int32_t authForm); - bool FilterByDeviceType(int32_t value, int32_t deviceType); - bool FilterByType(const DmDeviceFilters &filters, const DmDeviceFilterPara &filterPara); - bool FilterOr(const std::vector &filters, const DmDeviceFilterPara &filterPara); - bool FilterAnd(const std::vector &filters, const DmDeviceFilterPara &filterPara); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_DISCOVERY_FILTER_H diff --git a/services/implementation/include/discovery/dm_discovery_manager.h b/services/implementation/include/discovery/dm_discovery_manager.h deleted file mode 100644 index 521869ec5..000000000 --- a/services/implementation/include/discovery/dm_discovery_manager.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2022 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_DM_DISCOVERY_MANAGER_H -#define OHOS_DM_DISCOVERY_MANAGER_H - -#include - -#include "dm_discovery_filter.h" -#include "idevice_manager_service_listener.h" -#include "dm_timer.h" -#include "hichain_connector.h" -#include "softbus_connector.h" -namespace OHOS { -namespace DistributedHardware { -typedef struct DmDiscoveryContext { - std::string pkgName; - std::string extra; - uint16_t subscribeId; - std::string filterOp; - std::vector filters; -} DmDiscoveryContext; - -class DmDiscoveryManager final : public ISoftbusDiscoveryCallback, - public std::enable_shared_from_this { -public: - DmDiscoveryManager(std::shared_ptr softbusConnector, - std::shared_ptr listener, - std::shared_ptr hiChainConnector); - ~DmDiscoveryManager(); - - /** - * @tc.name: DmDiscoveryManager::StartDeviceDiscovery - * @tc.desc: Start Device Discovery of the Dm Discovery Manager - * @tc.type: FUNC - */ - int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, - const std::string &extra); - - /** - * @tc.name: DmDiscoveryManager::StartDeviceDiscovery - * @tc.desc: Start Device Discovery of the Dm Discovery Manager - * @tc.type: FUNC - */ - int32_t StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId, - const std::string &filterOptions); - - /** - * @tc.name: DmDiscoveryManager::StopDeviceDiscovery - * @tc.desc: Stop Device Discovery of the Dm Discovery Manager - * @tc.type: FUNC - */ - int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId); - - /** - * @tc.name: DmDiscoveryManager::OnDeviceFound - * @tc.desc: OnDevice Found of the Dm Discovery Manager - * @tc.type: FUNC - */ - void OnDeviceFound(const std::string &pkgName, DmDeviceInfo &info, bool isOnline); - - /** - * @tc.name: DmDiscoveryManager::OnDeviceFound - * @tc.desc: OnDevice Found of the Dm Discovery Manager - * @tc.type: FUNC - */ - void OnDeviceFound(const std::string &pkgName, DmDeviceBasicInfo &info, const int32_t range, bool isOnline); - - /** - * @tc.name: DmDiscoveryManager::OnDiscoverySuccess - * @tc.desc: OnDiscovery Success of the Dm Discovery Manager - * @tc.type: FUNC - */ - void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId); - - /** - * @tc.name: DmDiscoveryManager::OnDiscoveryFailed - * @tc.desc: OnDiscovery Failed of the Dm Discovery Manager - * @tc.type: FUNC - */ - void OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason); - - /** - * @tc.name: DmDiscoveryManager::HandleDiscoveryTimeout - * @tc.desc: Handle Discovery Timeout of the Dm Discovery Manager - * @tc.type: FUNC - */ - void HandleDiscoveryTimeout(std::string name); -private: - void CfgDiscoveryTimer(); - int32_t CheckDiscoveryQueue(const std::string &pkgName); - int32_t GetAuthForm(const std::string &localDeviceId, const std::string &deviceId, - bool &isTrusted, DmAuthForm &authForm); - -private: - std::shared_ptr softbusConnector_; - std::shared_ptr listener_; - std::shared_ptr hiChainConnector_; - std::queue discoveryQueue_; - std::map discoveryContextMap_; - std::shared_ptr timer_; - std::mutex locks_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_DISCOVERY_MANAGER_H diff --git a/services/implementation/include/publish/dm_publish_manager.h b/services/implementation/include/publish/dm_publish_manager.h deleted file mode 100644 index 878031b6c..000000000 --- a/services/implementation/include/publish/dm_publish_manager.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2022 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_DM_PUBLISH_MANAGER_H -#define OHOS_DM_PUBLISH_MANAGER_H - -#include - -#include "dm_publish_info.h" -#include "device_manager_service_listener.h" -#include "dm_timer.h" -#include "softbus_connector.h" -#include "softbus_publish_callback.h" - -namespace OHOS { -namespace DistributedHardware { -typedef struct DmPublishContext { - std::string pkgName; - DmPublishInfo publishInfo; -} DmPublishContext; - -class DmPublishManager final : public ISoftbusPublishCallback, - public std::enable_shared_from_this { -public: - DmPublishManager(std::shared_ptr softbusConnector, - std::shared_ptr listener); - ~DmPublishManager(); - - /** - * @tc.name: DmPublishManager::PublishDeviceDiscovery - * @tc.desc: Publish Device Discovery of the Dm Publish Manager - * @tc.type: FUNC - */ - int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo); - - /** - * @tc.name: DmPublishManager::UnPublishDeviceDiscovery - * @tc.desc: UnPublish Device Discovery of the Dm Discovery Manager - * @tc.type: FUNC - */ - int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId); - - /** - * @tc.name: DmPublishManager::OnPublishResult - * @tc.desc: OnPublish Result of the Dm Discovery Manager - * @tc.type: FUNC - */ - void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult); - - /** - * @tc.name: DmPublishManager::HandlePublishDiscoveryTimeout - * @tc.desc: Handle Publish Timeout of the Dm OnPublish Manager - * @tc.type: FUNC - */ - void HandlePublishTimeout(std::string name); -private: - void CfgPublishTimer(); - int32_t CheckPublishQueue(const std::string &pkgName); - -private: - std::shared_ptr softbusConnector_; - std::shared_ptr listener_; - std::queue publishQueue_; - std::map publishContextMap_; - std::shared_ptr timer_; - std::mutex locks_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DM_PUBLISH_MANAGER_H diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index 560959b0d..28db41ccd 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -44,30 +44,12 @@ constexpr const char* ETH_PORT = "ETH_PORT"; std::string SoftbusConnector::remoteUdidHash_ = ""; SoftbusConnector::PulishStatus SoftbusConnector::publishStatus = SoftbusConnector::STATUS_UNKNOWN; -std::map> SoftbusConnector::discoveryDeviceInfoMap_ = {}; -std::map> SoftbusConnector::discoveryCallbackMap_ = {}; -std::map> SoftbusConnector::publishCallbackMap_ = {}; std::queue SoftbusConnector::discoveryDeviceIdQueue_ = {}; std::unordered_map SoftbusConnector::deviceUdidMap_ = {}; std::vector SoftbusConnector::processInfoVec_ = {}; -std::mutex SoftbusConnector::discoveryCallbackMutex_; -std::mutex SoftbusConnector::discoveryDeviceInfoMutex_; std::mutex SoftbusConnector::deviceUdidLocks_; std::mutex SoftbusConnector::processInfoVecMutex_; -IPublishCb SoftbusConnector::softbusPublishCallback_ = { - .OnPublishResult = SoftbusConnector::OnSoftbusPublishResult, -}; -IRefreshCallback SoftbusConnector::softbusDiscoveryCallback_ = { - .OnDeviceFound = SoftbusConnector::OnSoftbusDeviceFound, - .OnDiscoverResult = SoftbusConnector::OnSoftbusDiscoveryResult, -}; - -IRefreshCallback SoftbusConnector::softbusDiscoveryByIdCallback_ = { - .OnDeviceFound = SoftbusConnector::OnSoftbusDeviceDiscovery, - .OnDiscoverResult = SoftbusConnector::OnSoftbusDiscoveryResult, -}; - SoftbusConnector::SoftbusConnector() { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -93,169 +75,6 @@ int32_t SoftbusConnector::UnRegisterSoftbusStateCallback() return DM_OK; } -int32_t SoftbusConnector::RegisterSoftbusDiscoveryCallback(const std::string &pkgName, - const std::shared_ptr callback) -{ - std::lock_guard lock(discoveryCallbackMutex_); - discoveryCallbackMap_.emplace(pkgName, callback); - return DM_OK; -} - -int32_t SoftbusConnector::UnRegisterSoftbusDiscoveryCallback(const std::string &pkgName) -{ - std::lock_guard lock(discoveryCallbackMutex_); - discoveryCallbackMap_.erase(pkgName); - return DM_OK; -} - -int32_t SoftbusConnector::RegisterSoftbusPublishCallback(const std::string &pkgName, - const std::shared_ptr callback) -{ - std::mutex registerCallback; - std::lock_guard lock(registerCallback); - publishCallbackMap_.emplace(pkgName, callback); - return DM_OK; -} - -int32_t SoftbusConnector::UnRegisterSoftbusPublishCallback(const std::string &pkgName) -{ - std::mutex unRegisterCallback; - std::lock_guard lock(unRegisterCallback); - publishCallbackMap_.erase(pkgName); - return DM_OK; -} - -int32_t SoftbusConnector::PublishDiscovery(const DmPublishInfo &dmPublishInfo) -{ - PublishInfo publishInfo; - if (memset_s(&publishInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)) != EOK) { - LOGE("PublishDiscovery memset_s failed."); - return ERR_DM_FAILED; - } - publishInfo.publishId = dmPublishInfo.publishId; - publishInfo.mode = static_cast(dmPublishInfo.mode); - publishInfo.medium = ExchangeMedium::AUTO; - publishInfo.freq = static_cast(dmPublishInfo.freq); - publishInfo.capability = DM_CAPABILITY_OSD; - publishInfo.ranging = dmPublishInfo.ranging; - LOGI("start, publishId: %{public}d, mode: 0x%{public}x, ranging: %{public}d.", publishInfo.publishId, - publishInfo.mode, publishInfo.ranging); - int32_t ret = ::PublishLNN(DM_PKG_NAME, &publishInfo, &softbusPublishCallback_); - if (ret != DM_OK) { - LOGE("[SOFTBUS]PublishLNN failed, ret %{public}d.", ret); - return ret; - } - return ret; -} - -int32_t SoftbusConnector::UnPublishDiscovery(int32_t publishId) -{ - LOGI("UnPublishDiscovery begin, publishId: %{public}d.", publishId); - int32_t ret = ::StopPublishLNN(DM_PKG_NAME, publishId); - if (ret != DM_OK) { - LOGE("[SOFTBUS]StopPublishLNN failed with ret: %{public}d.", ret); - return ret; - } - return ret; -} - -int32_t SoftbusConnector::StartDiscovery(const DmSubscribeInfo &dmSubscribeInfo) -{ - SubscribeInfo subscribeInfo; - if (memset_s(&subscribeInfo, sizeof(SubscribeInfo), 0, sizeof(SubscribeInfo)) != EOK) { - LOGE("StartDiscovery memset_s failed."); - return ERR_DM_FAILED; - } - subscribeInfo.subscribeId = dmSubscribeInfo.subscribeId; - subscribeInfo.mode = static_cast(dmSubscribeInfo.mode); - subscribeInfo.medium = static_cast(dmSubscribeInfo.medium); - subscribeInfo.freq = static_cast(dmSubscribeInfo.freq); - subscribeInfo.isSameAccount = dmSubscribeInfo.isSameAccount; - subscribeInfo.isWakeRemote = dmSubscribeInfo.isWakeRemote; - subscribeInfo.capability = dmSubscribeInfo.capability; - LOGI("StartDiscovery begin, subscribeId: %{public}d, mode: 0x%{public}x, medium: %{public}d.", - subscribeInfo.subscribeId, subscribeInfo.mode, subscribeInfo.medium); - int32_t ret = ::RefreshLNN(DM_PKG_NAME, &subscribeInfo, &softbusDiscoveryCallback_); - struct RadarInfo info = { - .funcName = "StartDiscovery", - .toCallPkg = SOFTBUSNAME, - .stageRes = (ret == DM_OK) ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .bizState = (ret == DM_OK) ? - static_cast(BizState::BIZ_STATE_START) : static_cast(BizState::BIZ_STATE_END), - .commServ = static_cast(CommServ::USE_SOFTBUS), - .errCode = ret, - }; - if (!DmRadarHelper::GetInstance().ReportDiscoverRegCallback(info)) { - LOGE("ReportDiscoverRegCallback failed"); - } - if (ret != DM_OK) { - LOGE("[SOFTBUS]RefreshLNN failed, ret: %{public}d.", ret); - return ret; - } - return ret; -} - -int32_t SoftbusConnector::StartDiscovery(const uint16_t subscribeId) -{ - SubscribeInfo subscribeInfo; - if (memset_s(&subscribeInfo, sizeof(SubscribeInfo), 0, sizeof(SubscribeInfo)) != EOK) { - LOGE("StartDiscovery memset_s failed."); - return ERR_DM_FAILED; - } - subscribeInfo.subscribeId = subscribeId; - subscribeInfo.mode = static_cast(DmDiscoverMode::DM_DISCOVER_MODE_ACTIVE); - subscribeInfo.medium = static_cast(DmExchangeMedium::DM_AUTO); - subscribeInfo.freq = static_cast(DmExchangeFreq::DM_SUPER_HIGH); - subscribeInfo.isSameAccount = false; - subscribeInfo.isWakeRemote = false; - subscribeInfo.capability = DM_CAPABILITY_OSD; - LOGI("StartDiscovery by subscribeId begin, subscribeId: %{public}d, mode: 0x%{public}x, medium: %{public}d.", - subscribeId, subscribeInfo.mode, subscribeInfo.medium); - int32_t ret = ::RefreshLNN(DM_PKG_NAME, &subscribeInfo, &softbusDiscoveryByIdCallback_); - struct RadarInfo info = { - .funcName = "StartDiscovery", - .toCallPkg = SOFTBUSNAME, - .stageRes = (ret == DM_OK) ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .bizState = (ret == DM_OK) ? - static_cast(BizState::BIZ_STATE_START) : static_cast(BizState::BIZ_STATE_END), - .commServ = static_cast(CommServ::USE_SOFTBUS), - .errCode = ret, - }; - if (!DmRadarHelper::GetInstance().ReportDiscoverRegCallback(info)) { - LOGE("ReportDiscoverRegCallback failed"); - } - if (ret != DM_OK) { - LOGE("[SOFTBUS]RefreshLNN failed, ret: %{public}d.", ret); - return ret; - } - return ret; -} - -int32_t SoftbusConnector::StopDiscovery(uint16_t subscribeId) -{ - LOGI("StopDiscovery begin, subscribeId: %{public}d.", (int32_t)subscribeId); - int32_t ret = ::StopRefreshLNN(DM_PKG_NAME, subscribeId); - struct RadarInfo info = { - .funcName = "StopDiscovery", - .hostName = SOFTBUSNAME, - .stageRes = (ret == DM_OK) ? - static_cast(StageRes::STAGE_CANCEL) : static_cast(StageRes::STAGE_FAIL), - .bizState = (ret == DM_OK) ? - static_cast(BizState::BIZ_STATE_CANCEL) : static_cast(BizState::BIZ_STATE_END), - .errCode = ret, - }; - if (!DmRadarHelper::GetInstance().ReportDiscoverUserRes(info)) { - LOGE("ReportDiscoverUserRes failed"); - } - if (ret != DM_OK) { - LOGE("[SOFTBUS]StopRefreshLNN failed, ret: %{public}d.", ret); - return ret; - } - return ret; -} - void SoftbusConnector::JoinLnn(const std::string &deviceId) { std::string connectAddr; @@ -415,16 +234,6 @@ void SoftbusConnector::ConvertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo, dmDeviceBasicInfo.deviceTypeId = deviceInfo.devType; } -void SoftbusConnector::OnSoftbusPublishResult(int32_t publishId, PublishResult result) -{ - LOGI("Callback In, publishId: %{public}d, result: %{public}d.", publishId, result); - std::mutex publishResult; - std::lock_guard lock(publishResult); - for (auto &iter : publishCallbackMap_) { - iter.second->OnPublishResult(iter.first, publishId, result); - } -} - void SoftbusConnector::OnSoftbusJoinLNNResult(ConnectionAddr *addr, const char *networkId, int32_t result) { (void)addr; @@ -432,133 +241,6 @@ void SoftbusConnector::OnSoftbusJoinLNNResult(ConnectionAddr *addr, const char * LOGD("[SOFTBUS]OnSoftbusJoinLNNResult, result: %{public}d.", result); } -void SoftbusConnector::OnSoftbusDeviceFound(const DeviceInfo *device) -{ - if (device == nullptr) { - LOGE("[SOFTBUS]device is null."); - return; - } - std::string deviceId = device->devId; - LOGI("[SOFTBUS]notify found device: %{public}s found, range: %{public}d, isOnline: %{public}d.", - GetAnonyString(deviceId).c_str(), device->range, device->isOnline); - if (!device->isOnline) { - std::shared_ptr infoPtr = std::make_shared(); - DeviceInfo *srcInfo = infoPtr.get(); - int32_t ret = memcpy_s(srcInfo, sizeof(DeviceInfo), device, sizeof(DeviceInfo)); - if (ret != DM_OK) { - LOGE("save discovery device info failed, ret: %{public}d.", ret); - return; - } - { - std::lock_guard lock(discoveryDeviceInfoMutex_); - if (discoveryDeviceInfoMap_.find(deviceId) == discoveryDeviceInfoMap_.end()) { - discoveryDeviceIdQueue_.emplace(deviceId); - } - discoveryDeviceInfoMap_[deviceId] = infoPtr; - - // Remove the earliest element when reached the max size - if (discoveryDeviceIdQueue_.size() == SOFTBUS_DISCOVER_DEVICE_INFO_MAX_SIZE) { - discoveryDeviceInfoMap_.erase(discoveryDeviceIdQueue_.front()); - discoveryDeviceIdQueue_.pop(); - } - } - } - - DmDeviceInfo dmDeviceInfo; - ConvertDeviceInfoToDmDevice(*device, dmDeviceInfo); - std::lock_guard lock(discoveryCallbackMutex_); - struct RadarInfo info = { - .funcName = "OnSoftbusDeviceFound", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .peerNetId = "", - .peerUdid = device->devId, - }; - if (!DmRadarHelper::GetInstance().ReportDiscoverResCallback(info)) { - LOGE("ReportDiscoverResCallback failed"); - } - for (auto &iter : discoveryCallbackMap_) { - iter.second->OnDeviceFound(iter.first, dmDeviceInfo, device->isOnline); - } -} - -void SoftbusConnector::OnSoftbusDeviceDiscovery(const DeviceInfo *device) -{ - if (device == nullptr) { - LOGE("[SOFTBUS]device is null."); - return; - } - std::string deviceId = device->devId; - LOGI("[SOFTBUS]notify discover device: %{public}s found, range: %{public}d, isOnline: %{public}d.", - GetAnonyString(deviceId).c_str(), device->range, device->isOnline); - if (!device->isOnline) { - std::shared_ptr infoPtr = std::make_shared(); - DeviceInfo *srcInfo = infoPtr.get(); - int32_t ret = memcpy_s(srcInfo, sizeof(DeviceInfo), device, sizeof(DeviceInfo)); - if (ret != DM_OK) { - LOGE("save discovery device info failed, ret: %{public}d.", ret); - return; - } - { - std::lock_guard lock(discoveryDeviceInfoMutex_); - if (discoveryDeviceInfoMap_.find(deviceId) == discoveryDeviceInfoMap_.end()) { - discoveryDeviceIdQueue_.emplace(deviceId); - } - discoveryDeviceInfoMap_[deviceId] = infoPtr; - - // Remove the earliest element when reached the max size - if (discoveryDeviceIdQueue_.size() == SOFTBUS_DISCOVER_DEVICE_INFO_MAX_SIZE) { - discoveryDeviceInfoMap_.erase(discoveryDeviceIdQueue_.front()); - discoveryDeviceIdQueue_.pop(); - } - } - } - - DmDeviceBasicInfo dmDeviceBasicInfo; - ConvertDeviceInfoToDmDevice(*device, dmDeviceBasicInfo); - std::lock_guard lock(discoveryCallbackMutex_); - struct RadarInfo info = { - .funcName = "OnSoftbusDeviceDiscovery", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .peerNetId = "", - .peerUdid = device->devId, - - }; - if (!DmRadarHelper::GetInstance().ReportDiscoverResCallback(info)) { - LOGE("ReportDiscoverResCallback failed"); - } - for (auto &iter : discoveryCallbackMap_) { - iter.second->OnDeviceFound(iter.first, dmDeviceBasicInfo, device->range, device->isOnline); - } -} - -void SoftbusConnector::OnSoftbusDiscoveryResult(int subscribeId, RefreshResult result) -{ - uint16_t originId = static_cast((static_cast(subscribeId)) & SOFTBUS_SUBSCRIBE_ID_MASK); - std::lock_guard lock(discoveryCallbackMutex_); - if (result == REFRESH_LNN_SUCCESS) { - LOGI("[SOFTBUS]start to discovery device successfully with subscribeId: %{public}d, result: %{public}d.", - subscribeId, result); - for (auto &iter : discoveryCallbackMap_) { - iter.second->OnDiscoverySuccess(iter.first, originId); - } - } else { - LOGE("[SOFTBUS]fail to discovery device with subscribeId: %{public}d, result: %{public}d.", subscribeId, - result); - for (auto iter = discoveryCallbackMap_.begin(); iter != discoveryCallbackMap_.end();) { - iter->second->OnDiscoveryFailed(iter->first, originId, result); - iter = discoveryCallbackMap_.erase(iter); - } - struct RadarInfo info = { - .funcName = "OnSoftbusDiscoveryResult", - .stageRes = static_cast(StageRes::STAGE_FAIL), - .errCode = result, - }; - if (!DmRadarHelper::GetInstance().ReportDiscoverResCallback(info)) { - LOGE("ReportDiscoverResCallback failed"); - } - } -} - std::string SoftbusConnector::GetDeviceUdidByUdidHash(const std::string &udidHash) { std::lock_guard lock(deviceUdidLocks_); diff --git a/test/commonfuzztest/BUILD.gn b/test/commonfuzztest/BUILD.gn index 83cb6a5e3..4430b898c 100644 --- a/test/commonfuzztest/BUILD.gn +++ b/test/commonfuzztest/BUILD.gn @@ -21,7 +21,6 @@ group("fuzztest") { "dmauthmanager_fuzzer:fuzztest", "dmcommoneventmanager_fuzzer:fuzztest", "dmcredentialimpl_fuzzer:fuzztest", - "dmdiscoverymanager_fuzzer:fuzztest", "generateencrypteduuid_fuzzer:fuzztest", "getdeviceinfo_fuzzer:fuzztest", "hichainconnector_fuzzer:fuzztest", diff --git a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/authenticate_device_service_impl_fuzzer.cpp b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/authenticate_device_service_impl_fuzzer.cpp index 32b0d79f9..46d4c31e1 100644 --- a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/authenticate_device_service_impl_fuzzer.cpp +++ b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/authenticate_device_service_impl_fuzzer.cpp @@ -133,12 +133,6 @@ void AuthenticateDeviceServiceImplFuzzTest(const uint8_t* data, size_t size) deviceManagerServiceImpl->Initialize(listener); deviceManagerServiceImpl->RegisterUiStateCallback(str); deviceManagerServiceImpl->RegisterCredentialCallback(str); - deviceManagerServiceImpl->StartDeviceDiscovery(str, subscribeInfo, str); - deviceManagerServiceImpl->StopDeviceDiscovery(str, subscribeInfo.subscribeId); - deviceManagerServiceImpl->StartDeviceDiscovery(str, g_subscribeId, str); - deviceManagerServiceImpl->StopDeviceDiscovery(str, g_subscribeId); - deviceManagerServiceImpl->PublishDeviceDiscovery(str, publishInfo); - deviceManagerServiceImpl->UnPublishDeviceDiscovery(str, publishInfo.publishId); deviceManagerServiceImpl->UnAuthenticateDevice(str, str, bindLevel); deviceManagerServiceImpl->UnBindDevice(str, str, bindLevel); deviceManagerServiceImpl->SetUserOperation(str, g_action, str); diff --git a/test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn b/test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn deleted file mode 100644 index 20d05de72..000000000 --- a/test/commonfuzztest/dmdiscoverymanager_fuzzer/BUILD.gn +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2022-2024 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/test.gni") -import("//foundation/distributedhardware/device_manager/device_manager.gni") - -##############################fuzztest########################################## -ohos_fuzztest("DmDiscoveryManagerFuzzTest") { - module_out_path = fuzz_test_output_path - fuzz_config_file = - "${devicemanager_path}/test/commonfuzztest/dmdiscoverymanager_fuzzer" - - include_dirs = [ - "${utils_path}/include", - "${common_path}/include", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${utils_path}/include/ipc/standard", - "${servicesimpl_path}/include", - "${servicesimpl_path}/include/discovery", - ] - - cflags = [ - "-g", - "-O0", - "-Dprivate=public", - "-Dprotected=public", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "dm_discovery_manager_fuzzer.cpp" ] - - deps = [ - "${services_path}:devicemanagerservice", - "${servicesimpl_path}:devicemanagerserviceimpl", - "${utils_path}:devicemanagerutils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DmDiscoveryManagerFuzzTest\"", - "LOG_DOMAIN=0xD004110", - ] - - external_deps = [ - "device_auth:deviceauth_sdk", - "ffrt:libffrt", - "safwk:system_ability_fwk", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - - deps = [ ":DmDiscoveryManagerFuzzTest" ] -} -############################################################################### diff --git a/test/commonfuzztest/dmdiscoverymanager_fuzzer/corpus/init b/test/commonfuzztest/dmdiscoverymanager_fuzzer/corpus/init deleted file mode 100644 index 1b910144f..000000000 --- a/test/commonfuzztest/dmdiscoverymanager_fuzzer/corpus/init +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2022 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. -FUZZ \ No newline at end of file diff --git a/test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.cpp b/test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.cpp deleted file mode 100644 index be89e5097..000000000 --- a/test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -#include "dm_discovery_manager.h" -#include "dm_device_info.h" -#include "dm_publish_info.h" -#include "dm_subscribe_info.h" -#include "dm_constants.h" -#include "dm_anonymous.h" -#include "device_manager_service_listener.h" -#include "ipc_server_listener.h" -#include "softbus_bus_center.h" -#include "softbus_connector.h" -#include "dm_discovery_manager_fuzzer.h" - -namespace OHOS { -namespace DistributedHardware { - -void DmDiscoveryManagerFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(uint16_t))) { - return; - } - - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - std::shared_ptr dmDiscoveryManager = - std::make_shared(softbusConnector, listener, hiChainConnector); - std::string pkgName(reinterpret_cast(data), size); - DmSubscribeInfo subscribeInfo; - std::string extra(reinterpret_cast(data), size); - uint16_t subscribeId = *(reinterpret_cast(data)); - DmDeviceInfo info; - DmDeviceBasicInfo basicInfo; - bool isOnline = true; - int32_t range = 1; - - dmDiscoveryManager->StartDeviceDiscovery(pkgName, subscribeInfo, extra); - dmDiscoveryManager->StartDeviceDiscovery(pkgName, subscribeId, extra); - dmDiscoveryManager->StopDeviceDiscovery(pkgName, subscribeId); - dmDiscoveryManager->OnDeviceFound(pkgName, info, isOnline); - dmDiscoveryManager->OnDeviceFound(pkgName, basicInfo, range, isOnline); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::DmDiscoveryManagerFuzzTest(data, size); - - return 0; -} diff --git a/test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.h b/test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.h deleted file mode 100644 index dc6ffe250..000000000 --- a/test/commonfuzztest/dmdiscoverymanager_fuzzer/dm_discovery_manager_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 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 DM_DISCOVERY_MANAGER_FUZZER_H -#define DM_DISCOVERY_MANAGER_FUZZER_H - -#define FUZZ_PROJECT_NAME "dmdiscoverymanager_fuzzer" - -#endif // DM_DISCOVERY_MANAGER_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/dmdiscoverymanager_fuzzer/project.xml b/test/commonfuzztest/dmdiscoverymanager_fuzzer/project.xml deleted file mode 100644 index 27c26d11b..000000000 --- a/test/commonfuzztest/dmdiscoverymanager_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - \ No newline at end of file diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index cf632b2c4..ce6f35fca 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -158,8 +158,6 @@ HWTEST_F(DeviceManagerServiceImplTest, Initialize_003, testing::ext::TestSize.Le deviceManagerServiceImpl_->softbusConnector_ = nullptr; deviceManagerServiceImpl_->hiChainConnector_ = nullptr; deviceManagerServiceImpl_->mineHiChainConnector_ = nullptr; - deviceManagerServiceImpl_->discoveryMgr_ = nullptr; - deviceManagerServiceImpl_->publishMgr_ = nullptr; deviceManagerServiceImpl_->hiChainAuthConnector_ = nullptr; deviceManagerServiceImpl_->deviceStateMgr_ = nullptr; deviceManagerServiceImpl_->authMgr_ = nullptr; @@ -938,167 +936,6 @@ HWTEST_F(DeviceManagerServiceImplTest, HandleDeviceStatusChange_004, testing::ex EXPECT_NE(deviceManagerServiceImpl_->deviceStateMgr_, nullptr); } -/** - * @tc.name: StartDeviceDiscovery_001 - * @tc.desc: return SOFTBUS_IPC_ERR - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0) -{ - const std::string pkgName = "com.ohos.test"; - uint16_t subscribeId = 0; - std::string filterOptions; - int32_t ret = deviceManagerServiceImpl_->StartDeviceDiscovery(pkgName, subscribeId, filterOptions); - EXPECT_TRUE(CheckSoftbusRes(ret)); -} - -/** - * @tc.name: StartDeviceDiscovery_002 - * @tc.desc: return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, StartDeviceDiscovery_002, testing::ext::TestSize.Level0) -{ - const std::string pkgName; - uint16_t subscribeId = 0; - std::string filterOptions; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->StartDeviceDiscovery(pkgName, subscribeId, filterOptions); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: StartDeviceDiscovery_003 - * @tc.desc: return SOFTBUS_INVALID_PARAM - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, StartDeviceDiscovery_003, testing::ext::TestSize.Level0) -{ - const std::string pkgName = "com.ohos.test"; - DmSubscribeInfo subscribeInfo; - std::string extra; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); - EXPECT_TRUE(CheckSoftbusRes(ret)); -} - -/** - * @tc.name: StartDeviceDiscovery_004 - * @tc.desc: return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, StartDeviceDiscovery_004, testing::ext::TestSize.Level0) -{ - const std::string pkgName; - DmSubscribeInfo subscribeInfo; - std::string extra; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: StopDeviceDiscovery_001 - * @tc.desc: return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0) -{ - std::string pkgName; - uint16_t subscribeId = 1; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->StopDeviceDiscovery(pkgName, subscribeId); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: StopDeviceDiscovery_002 - * @tc.desc: return SOFTBUS_IPC_ERR - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, StopDeviceDiscovery_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.test"; - uint16_t subscribeId = 1; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->StopDeviceDiscovery(pkgName, subscribeId); - EXPECT_TRUE(CheckSoftbusRes(ret)); -} - -/** - * @tc.name: PublishDeviceDiscovery_001 - * @tc.desc: return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, PublishDeviceDiscovery_001, testing::ext::TestSize.Level0) -{ - std::string pkgName; - DmPublishInfo publishInfo; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->PublishDeviceDiscovery(pkgName, publishInfo); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: PublishDeviceDiscovery_002 - * @tc.desc: return SOFTBUS_INVALID_PARAM - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, PublishDeviceDiscovery_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.test"; - DmPublishInfo publishInfo; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->PublishDeviceDiscovery(pkgName, publishInfo); - EXPECT_TRUE(CheckSoftbusRes(ret)); -} - -/** - * @tc.name: UnPublishDeviceDiscovery_001 - * @tc.desc: return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, UnPublishDeviceDiscovery_001, testing::ext::TestSize.Level0) -{ - std::string pkgName; - int32_t publishId = 1; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->UnPublishDeviceDiscovery(pkgName, publishId); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: UnPublishDeviceDiscovery_002 - * @tc.desc: return SOFTBUS_IPC_ERR - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, UnPublishDeviceDiscovery_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.test"; - int32_t publishId = 1; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - int32_t ret = deviceManagerServiceImpl_->UnPublishDeviceDiscovery(pkgName, publishId); - EXPECT_TRUE(CheckSoftbusRes(ret)); -} - /** * @tc.name: GetUdidHashByNetWorkId_001 * @tc.desc: return ERR_DM_POINT_NULL -- Gitee From 1820b6d3933ea81ea0f5d346eb2acb5cbc77bb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 11 Dec 2024 11:31:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A0=E9=99=A4ut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../UTTest_dm_discovery_manager.cpp | 571 ------------------ .../UTTest_dm_discovery_manager.h | 40 -- test/unittest/BUILD.gn | 25 - 3 files changed, 636 deletions(-) delete mode 100644 test/commonunittest/UTTest_dm_discovery_manager.cpp delete mode 100644 test/commonunittest/UTTest_dm_discovery_manager.h diff --git a/test/commonunittest/UTTest_dm_discovery_manager.cpp b/test/commonunittest/UTTest_dm_discovery_manager.cpp deleted file mode 100644 index 0026854a0..000000000 --- a/test/commonunittest/UTTest_dm_discovery_manager.cpp +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright (c) 2022-2024 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. - */ - -#include "UTTest_dm_discovery_manager.h" - -#include -#include -#include - -#include "dm_log.h" -#include "dm_constants.h" -#include "dm_anonymous.h" -#include "ipc_server_listener.h" -#include "device_manager_service_listener.h" -#include "softbus_bus_center.h" -#include "device_manager_service_listener.h" -#include "softbus_error_code.h" - -namespace OHOS { -namespace DistributedHardware { -void DmDiscoveryManagerTest::SetUp() -{ -} - -void DmDiscoveryManagerTest::TearDown() -{ -} - -void DmDiscoveryManagerTest::SetUpTestCase() -{ -} - -void DmDiscoveryManagerTest::TearDownTestCase() -{ -} - -namespace { -std::shared_ptr softbusConnector_ = std::make_shared(); -std::shared_ptr listener_ = std::make_shared(); -std::shared_ptr hiChainConnector_ = std::make_shared(); -std::shared_ptr discoveryMgr_ = - std::make_shared(softbusConnector_, listener_, hiChainConnector_); - -bool CheckSoftbusRes(int32_t ret) -{ - return ret == SOFTBUS_INVALID_PARAM || ret == SOFTBUS_NETWORK_NOT_INIT || ret == SOFTBUS_NETWORK_LOOPER_ERR || - ret == SOFTBUS_IPC_ERR; -} - -/** - * @tc.name: DmDiscoveryManager_001 - * @tc.desc: Test whether the DmDiscoveryManager function can generate a new pointer - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr Test = - std::make_shared(softbusConnector_, listener_, hiChainConnector_); - ASSERT_NE(Test, nullptr); -} - -/** - * @tc.name: DmDiscoveryManager_002 - * @tc.desc: Test whether the DmDiscoveryManager function can delete a new pointer - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_002, testing::ext::TestSize.Level0) -{ - std::shared_ptr Test = - std::make_shared(softbusConnector_, listener_, hiChainConnector_); - Test.reset(); - EXPECT_EQ(Test, nullptr); -} - -/** - * @tc.name:StartDeviceDiscovery_001 - * @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery once, - * extra is not empty and return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - DmSubscribeInfo subscribeInfo; - subscribeInfo.subscribeId = 1; - const std::string extra = "com.ohos.test"; - int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); - discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); -} - -/** - * @tc.name:StartDeviceDiscovery_002 - * @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery once, - * extra is empty and return ERR_DM_DISCOVERY_REPEATED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - DmSubscribeInfo subscribeInfo; - subscribeInfo.subscribeId = 1; - std::string extra; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - discoveryMgr_->discoveryQueue_.push(pkgName); - int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); - EXPECT_EQ(ret, ERR_DM_DISCOVERY_REPEATED); - discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); -} - -/** - * @tc.name:StartDeviceDiscovery_003 - * @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery once, - * extra is empty, discoveryQueue_ is empty, and return SOFTBUS_INVALID_PARAM - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_003, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - std::string extra; - DmSubscribeInfo subscribeInfo; - subscribeInfo.subscribeId = 1; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); - ASSERT_TRUE(CheckSoftbusRes(ret)); - discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); -} - -/** - * @tc.name:StartDeviceDiscovery_004 - * @tc.desc: pkgame changed, call StartDeviceDiscovery once, - * discoveryQueue is not empty and return ERR_DM_DISCOVERY_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_004, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - uint16_t subscribeId = 1; - std::string filterOptions; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - discoveryMgr_->discoveryQueue_.push(pkgName); - int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeId, filterOptions); - ASSERT_EQ(ret, ERR_DM_DISCOVERY_REPEATED); - discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); -} - -/** - * @tc.name:StartDeviceDiscovery_005 - * @tc.desc: pkgame changed, call StartDeviceDiscovery once, - * discoveryQueue is empty and return SOFTBUS_IPC_ERR - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_005, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - uint16_t subscribeId = 1; - std::string filterOptions; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeId, filterOptions); - ASSERT_TRUE(CheckSoftbusRes(ret)); - discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); -} - -/** - * @tc.name: StopDeviceDiscovery_001 - * @tc.desc: return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0) -{ - std::string pkgName; - uint16_t subscribeId = 1; - int32_t ret = discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: StopDeviceDiscovery_002 - * @tc.desc: return SOFTBUS_IPC_ERR - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, StopDeviceDiscovery_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - uint16_t subscribeId = 1; - int32_t ret = discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); - EXPECT_TRUE(CheckSoftbusRes(ret)); -} - -/** - * @tc.name: OnDeviceFound_001 - * @tc.desc: The OnDeviceFound function does the correct case and assigns pkgName - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_001, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - std::string filterOptions = R"( - { - "filter_op": "OR", - "filters": - [ - { - "type" : "credible", - "value" : 0 - } - ] - } - )"; - DmDeviceFilterOption dmFilter; - dmFilter.TransformToFilter(filterOptions); - uint16_t aaa = 11; - DmDiscoveryContext context { pkgName, filterOptions, aaa, dmFilter.filterOp_, dmFilter.filters_ }; - discoveryMgr_->discoveryContextMap_[pkgName] = context; - sleep(1); - DmDeviceInfo info; - info.deviceId[0] = '\0'; - info.deviceName[0] = '\0'; - bool isOnline = false; - discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); -} - -/** - * @tc.name: OnDeviceFound_002 - * @tc.desc: set pkgName not null and discoveryContextMap_ null and return - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - std::string filterOptions = R"( - { - "filter_op": "AND", - "filters": - [ - { - "type" : "credible", - "value" : 2 - } - ] - } - )"; - DmDeviceFilterOption dmFilter; - dmFilter.TransformToFilter(filterOptions); - uint16_t aaa = 11; - DmDiscoveryContext context { pkgName, filterOptions, aaa, dmFilter.filterOp_, dmFilter.filters_ }; - discoveryMgr_->discoveryContextMap_[pkgName] = context; - DmDeviceInfo info; - bool isOnline = false; - discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); - int ret = discoveryMgr_->discoveryContextMap_.count(pkgName); - EXPECT_EQ(ret, 1); -} - -/** - * @tc.name: OnDeviceFound_003 - * @tc.desc: set pkgName not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_003, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - DmDeviceInfo info; - bool isOnline = true; - discoveryMgr_->discoveryContextMap_.clear(); - discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); -} - -/** - * @tc.name: OnDeviceFound_004 - * @tc.desc: set pkgName not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_004, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - DmDeviceInfo info; - bool isOnline = true; - DmDiscoveryContext context; - discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); - discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); -} - -/** - * @tc.name: OnDeviceFound_005 - * @tc.desc: set pkgName not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_005, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - DmDeviceBasicInfo info; - int32_t range = 0; - bool isOnline = true; - discoveryMgr_->discoveryContextMap_.clear(); - discoveryMgr_->OnDeviceFound(pkgName, info, range, isOnline); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); -} - -/** - * @tc.name: OnDeviceFound_006 - * @tc.desc: set pkgName not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_006, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - DmDeviceBasicInfo info; - int32_t range = 0; - bool isOnline = true; - DmDiscoveryContext context; - discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); - discoveryMgr_->OnDeviceFound(pkgName, info, range, isOnline); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); -} - -/** - * @tc.name: GetAuthForm_001 - * @tc.desc: set localDeviceId null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_001, testing::ext::TestSize.Level0) -{ - std::string localDeviceId; - std::string deviceId; - bool isTrusted = true; - DmAuthForm authForm; - int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: GetAuthForm_002 - * @tc.desc: set localDeviceId not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_002, testing::ext::TestSize.Level0) -{ - std::string localDeviceId = "125462"; - std::string deviceId; - bool isTrusted = true; - DmAuthForm authForm; - int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -/** - * @tc.name: GetAuthForm_003 - * @tc.desc: set localDeviceId not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_003, testing::ext::TestSize.Level0) -{ - std::string localDeviceId = "125462"; - std::string deviceId = "236541"; - bool isTrusted = true; - DmAuthForm authForm; - discoveryMgr_->hiChainConnector_ = nullptr; - int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); - EXPECT_EQ(ret, ERR_DM_POINT_NULL); -} - -/** - * @tc.name: GetAuthForm_004 - * @tc.desc: set localDeviceId not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_004, testing::ext::TestSize.Level0) -{ - std::string localDeviceId = "125462"; - std::string deviceId = "236541"; - bool isTrusted = true; - DmAuthForm authForm; - discoveryMgr_->softbusConnector_ = nullptr; - int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); - EXPECT_EQ(ret, ERR_DM_POINT_NULL); -} - -/** - * @tc.name: GetAuthForm_005 - * @tc.desc: set localDeviceId not null - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_005, testing::ext::TestSize.Level0) -{ - std::string localDeviceId = "125462"; - std::string deviceId = "236541"; - bool isTrusted = true; - DmAuthForm authForm; - discoveryMgr_->softbusConnector_ = std::make_shared(); - discoveryMgr_->hiChainConnector_ = std::make_shared(); - int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnDiscoveryFailed_001 - * @tc.desc: The OnDeviceFound function takes the wrong case and emptying pkgName - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_001, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - int32_t subscribeId = 1; - int32_t failedReason = 3; - discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); -} - -/** - * @tc.name: OnDiscoveryFailed_002 - * @tc.desc: The OnDeviceFound function takes the wrong case and emptying pkgName - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_002, testing::ext::TestSize.Level0) -{ - std::string pkgName; - int32_t subscribeId = 1; - int32_t failedReason = 3; - discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); - int ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName); - EXPECT_EQ(ret1, 0); -} - -/** - * @tc.name: OnDiscoveryFailed_003 - * @tc.desc: The OnDeviceFound function takes the wrong case and emptying pkgName - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_003, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - int32_t subscribeId = 1; - int32_t failedReason = 3; - discoveryMgr_->discoveryQueue_.push(pkgName); - DmDiscoveryContext context; - discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); - discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); -} - -/** - * @tc.name: OnDiscoverySuccess_001 - * @tc.desc: The OnDeviceFound function takes the wrong case and return pkgName - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_001, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld"; - int32_t subscribeId = 1; - discoveryMgr_->OnDiscoverySuccess(pkgName, subscribeId); - EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); -} - -/** - * @tc.name: OnDiscoverySuccess_002 - * @tc.desc: set pkgName null and return discoveryContextMap_ null and return pkgName(null) - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_002, testing::ext::TestSize.Level0) -{ - std::string pkgName; - int32_t subscribeId = 1; - discoveryMgr_->OnDiscoverySuccess(pkgName, subscribeId); - int ret = discoveryMgr_->discoveryContextMap_.count(pkgName); - EXPECT_EQ(ret, 1); -} - -HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_001, testing::ext::TestSize.Level0) -{ - std::string pkgName; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - discoveryMgr_->HandleDiscoveryTimeout(pkgName); - EXPECT_EQ(discoveryMgr_->discoveryQueue_.empty(), true); -} - -HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld_new"; - discoveryMgr_->discoveryQueue_.push(pkgName); - discoveryMgr_->HandleDiscoveryTimeout(pkgName); - EXPECT_EQ(discoveryMgr_->discoveryQueue_.empty(), false); -} - -HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_003, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.helloworld_new"; - discoveryMgr_->discoveryQueue_.push(pkgName); - DmDiscoveryContext context; - discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); - discoveryMgr_->HandleDiscoveryTimeout(pkgName); - EXPECT_EQ(discoveryMgr_->discoveryQueue_.empty(), false); -} - -HWTEST_F(DmDiscoveryManagerTest, CheckDiscoveryQueue_001, testing::ext::TestSize.Level0) -{ - std::string pkgName; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - int32_t ret = discoveryMgr_->CheckDiscoveryQueue(pkgName); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DmDiscoveryManagerTest, CheckDiscoveryQueue_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "ohos_test"; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - discoveryMgr_->discoveryQueue_.push(pkgName); - int32_t ret = discoveryMgr_->CheckDiscoveryQueue(pkgName); - EXPECT_EQ(ret, ERR_DM_DISCOVERY_REPEATED); -} - -HWTEST_F(DmDiscoveryManagerTest, CheckDiscoveryQueue_003, testing::ext::TestSize.Level0) -{ - std::string pkgName = "pkgName"; - std::queue emptyQueue; - discoveryMgr_->discoveryQueue_ = emptyQueue; - std::string frontPkgName = "ohos_test"; - discoveryMgr_->discoveryQueue_.push(frontPkgName); - int32_t ret = discoveryMgr_->CheckDiscoveryQueue(pkgName); - EXPECT_EQ(ret, DM_OK); -} -} // namespace -} // namespace DistributedHardware -} // namespace OHOS diff --git a/test/commonunittest/UTTest_dm_discovery_manager.h b/test/commonunittest/UTTest_dm_discovery_manager.h deleted file mode 100644 index dc6df8567..000000000 --- a/test/commonunittest/UTTest_dm_discovery_manager.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2022-2024 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_UTTEST_DM_DISCOVERY_MANAGER_H -#define OHOS_UTTEST_DM_DISCOVERY_MANAGER_H - -#include -#include -#include - -#include "device_manager_service_listener.h" -#include "dm_discovery_manager.h" -#include "ipc_notify_device_found_req.h" -#include "ipc_notify_discover_result_req.h" -#include "softbus_connector.h" - -namespace OHOS { -namespace DistributedHardware { -class DmDiscoveryManagerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_UTTEST_DM_DISCOVERY_MANAGER_H diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 6f10bdaa2..208480475 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -45,7 +45,6 @@ group("unittest") { ":UTTest_dm_deviceprofile_connector_second", ":UTTest_dm_dfx", ":UTTest_dm_discovery_filter", - ":UTTest_dm_discovery_manager", ":UTTest_dm_distributed_hardware_load", ":UTTest_dm_import_auth_code", ":UTTest_dm_pin_holder", @@ -1356,30 +1355,6 @@ ohos_unittest("UTTest_dm_deviceprofile_connector_second") { ############################# -## UnitTest UTTest_dm_discovery_manager {{{ -ohos_unittest("UTTest_dm_discovery_manager") { - module_out_path = module_out_path - - include_dirs = [ "${devicemanager_path}/test/commonunittest" ] - - sources = [ - "${devicemanager_path}/test/commonunittest/UTTest_dm_discovery_manager.cpp", - ] - - deps = [ ":device_manager_test_common" ] - - external_deps = [ - "device_auth:deviceauth_sdk", - "device_info_manager:distributed_device_profile_common", - "device_info_manager:distributed_device_profile_sdk", - "ffrt:libffrt", - "googletest:gmock", - "hitrace:hitrace_meter", - ] -} - -## UnitTest UTTest_dm_discovery_manager }}} - ## UnitTest UTTest_dm_distributed_hardware_load {{{ ohos_unittest("UTTest_dm_distributed_hardware_load") { module_out_path = module_out_path -- Gitee From a3a452bc974128028cb12d1aa60a4083f0aec90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 11 Dec 2024 20:38:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../dependency/softbus/softbus_connector.h | 4 +-- .../dependency/softbus/softbus_connector.cpp | 3 +- .../softbus_connector_publish_fuzzer.cpp | 13 -------- .../softbus_connector_static_fuzzer.cpp | 2 -- .../UTTest_softbus_connector.cpp | 31 ------------------- .../UTTest_device_manager_service_impl.h | 1 + 6 files changed, 5 insertions(+), 49 deletions(-) diff --git a/services/implementation/include/dependency/softbus/softbus_connector.h b/services/implementation/include/dependency/softbus/softbus_connector.h index 75ea054f4..04b8c7d12 100644 --- a/services/implementation/include/dependency/softbus/softbus_connector.h +++ b/services/implementation/include/dependency/softbus/softbus_connector.h @@ -27,8 +27,6 @@ #include "dm_device_info.h" #include "dm_publish_info.h" #include "dm_subscribe_info.h" -#include "softbus_discovery_callback.h" -#include "softbus_publish_callback.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "softbus_session.h" #endif @@ -129,9 +127,11 @@ private: #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::shared_ptr softbusSession_; #endif + static std::map> discoveryDeviceInfoMap_; std::shared_ptr deviceStateManagerCallback_; static std::unordered_map deviceUdidMap_; static std::vector processInfoVec_; + static std::mutex discoveryDeviceInfoMutex_; static std::mutex deviceUdidLocks_; static std::mutex processInfoVecMutex_; }; diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index 28db41ccd..3df77bb73 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -44,9 +44,10 @@ constexpr const char* ETH_PORT = "ETH_PORT"; std::string SoftbusConnector::remoteUdidHash_ = ""; SoftbusConnector::PulishStatus SoftbusConnector::publishStatus = SoftbusConnector::STATUS_UNKNOWN; -std::queue SoftbusConnector::discoveryDeviceIdQueue_ = {}; +std::map> SoftbusConnector::discoveryDeviceInfoMap_ = {}; std::unordered_map SoftbusConnector::deviceUdidMap_ = {}; std::vector SoftbusConnector::processInfoVec_ = {}; +std::mutex SoftbusConnector::discoveryDeviceInfoMutex_; std::mutex SoftbusConnector::deviceUdidLocks_; std::mutex SoftbusConnector::processInfoVecMutex_; diff --git a/test/softbusfuzztest/softbusconnectorpublish_fuzzer/softbus_connector_publish_fuzzer.cpp b/test/softbusfuzztest/softbusconnectorpublish_fuzzer/softbus_connector_publish_fuzzer.cpp index 482272b2a..d3bfb3b74 100644 --- a/test/softbusfuzztest/softbusconnectorpublish_fuzzer/softbus_connector_publish_fuzzer.cpp +++ b/test/softbusfuzztest/softbusconnectorpublish_fuzzer/softbus_connector_publish_fuzzer.cpp @@ -19,8 +19,6 @@ #include "dm_device_info.h" #include "dm_publish_info.h" #include "dm_subscribe_info.h" -#include "softbus_discovery_callback.h" -#include "softbus_publish_callback.h" #include "softbus_session.h" #include "softbus_connector_publish_fuzzer.h" @@ -33,19 +31,8 @@ void SoftBusConnectorPublishFuzzTest(const uint8_t* data, size_t size) } std::string deviceId(reinterpret_cast(data), size); - int32_t publishId = *(reinterpret_cast(data)); - uint16_t subscribeId = *(reinterpret_cast(data)); std::shared_ptr softbusConnector = std::make_shared(); - DmPublishInfo dmPublishInfo; - dmPublishInfo.publishId = publishId; - DmSubscribeInfo subscribeInfo; - subscribeInfo.subscribeId = subscribeId; - softbusConnector->PublishDiscovery(dmPublishInfo); - softbusConnector->UnPublishDiscovery(publishId); - softbusConnector->StartDiscovery(subscribeInfo); - softbusConnector->StopDiscovery(subscribeId); - softbusConnector->StartDiscovery(subscribeId); softbusConnector->HaveDeviceInMap(deviceId); } } diff --git a/test/softbusfuzztest/softbusconnectorstatic_fuzzer/softbus_connector_static_fuzzer.cpp b/test/softbusfuzztest/softbusconnectorstatic_fuzzer/softbus_connector_static_fuzzer.cpp index 04c8e9e52..4293ebdb3 100644 --- a/test/softbusfuzztest/softbusconnectorstatic_fuzzer/softbus_connector_static_fuzzer.cpp +++ b/test/softbusfuzztest/softbusconnectorstatic_fuzzer/softbus_connector_static_fuzzer.cpp @@ -18,8 +18,6 @@ #include "dm_device_info.h" #include "dm_publish_info.h" #include "dm_subscribe_info.h" -#include "softbus_discovery_callback.h" -#include "softbus_publish_callback.h" #include "softbus_session.h" #include "softbus_connector_static_fuzzer.h" diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 57dbcc5e2..25ea83200 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -314,37 +314,6 @@ HWTEST_F(SoftbusConnectorTest, GetSoftbusSession_001, testing::ext::TestSize.Lev EXPECT_NE(softSession, nullptr); } -/** - * @tc.name: GetSoftbusSession_001 - * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_001, testing::ext::TestSize.Level0) -{ - std::string deviceId = "12345678"; - SoftbusConnector::discoveryDeviceInfoMap_[deviceId]; - std::shared_ptr softbusConnector = std::make_shared(); - bool ret = softbusConnector->HaveDeviceInMap(deviceId); - EXPECT_EQ(ret, true); - SoftbusConnector::discoveryDeviceInfoMap_.clear(); -} - -/** - * @tc.name: GetSoftbusSession_001 - * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_002, testing::ext::TestSize.Level0) -{ - std::string deviceId = "12345678"; - std::shared_ptr softbusConnector = std::make_shared(); - bool ret = softbusConnector->HaveDeviceInMap(deviceId); - EXPECT_EQ(ret, false); - SoftbusConnector::discoveryDeviceInfoMap_.clear(); -} - /** * @tc.name: GetConnectAddrByType_001 * @tc.desc: set deviceInfo'pointer null, go to first branch, and return nullptr diff --git a/test/unittest/UTTest_device_manager_service_impl.h b/test/unittest/UTTest_device_manager_service_impl.h index e41900940..afb383400 100644 --- a/test/unittest/UTTest_device_manager_service_impl.h +++ b/test/unittest/UTTest_device_manager_service_impl.h @@ -23,6 +23,7 @@ #include #include "device_manager_service_impl.h" +#include "device_manager_service_listener.h" #include "deviceprofile_connector_mock.h" #include "softbus_connector_mock.h" #include "dm_device_state_manager_mock.h" -- Gitee