mirror of
https://gitee.com/openharmony/deviceprofile_device_info_manager
synced 2024-11-27 01:31:01 +00:00
commit
2e037aed91
@ -42,7 +42,6 @@ ohos_shared_library("distributed_device_profile_common") {
|
||||
"src/interfaces/sync_completed_callback_stub.cpp",
|
||||
"src/interfaces/sync_options.cpp",
|
||||
"src/interfaces/trust_device_profile.cpp",
|
||||
"src/utils/dp_detect_utils.cpp",
|
||||
"src/utils/ipc_utils.cpp",
|
||||
"src/utils/profile_utils.cpp",
|
||||
]
|
||||
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_DP_DETECT_VERSION
|
||||
#define OHOS_DP_DETECT_VERSION
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
#include "session.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedDeviceProfile {
|
||||
class DPDetectVersion {
|
||||
public:
|
||||
static int32_t DetectRemoteDPVersion(const std::string& peerDevId);
|
||||
};
|
||||
} // namespace DeviceProfile
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DEVICE_PROFILE_DP_DETECT_VERSION_H
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 <securec.h>
|
||||
#include "dp_detect_utils.h"
|
||||
|
||||
#include "distributed_device_profile_constants.h"
|
||||
#include "distributed_device_profile_log.h"
|
||||
#include "distributed_device_profile_errors.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedDeviceProfile {
|
||||
namespace {
|
||||
const std::string TAG = "DPDetectUtils";
|
||||
}
|
||||
std::mutex operationMtx_;
|
||||
const char *sessName = "com.huawei.profile-session";
|
||||
const char *pkgName = "com.huawei.profile";
|
||||
|
||||
static int32_t OnSessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void OnSessionClosed(int32_t sessionId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ISessionListener sessListener_ {.OnSessionOpened = OnSessionOpened,
|
||||
.OnSessionClosed = OnSessionClosed};
|
||||
|
||||
int32_t DPDetectVersion::DetectRemoteDPVersion(const std::string& peerDevId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(operationMtx_);
|
||||
if (peerDevId.empty()) {
|
||||
HILOGE("input peerDevId is empty");
|
||||
return DP_INVALID_PARAMS;
|
||||
}
|
||||
int32_t ret = CreateSessionServer(pkgName, sessName, &sessListener_);
|
||||
if (ret != DP_SUCCESS) {
|
||||
HILOGE("create session adapter failed");
|
||||
return DP_CREATE_SESSION_FAILED;
|
||||
}
|
||||
int dataType = TYPE_BYTES;
|
||||
SessionAttribute attribute = { 0 };
|
||||
attribute.dataType = dataType;
|
||||
attribute.linkTypeNum = LINK_TYPE_MAX;
|
||||
LinkType linkTypeList[LINK_TYPE_MAX] = {
|
||||
LINK_TYPE_WIFI_P2P,
|
||||
LINK_TYPE_WIFI_WLAN_5G,
|
||||
LINK_TYPE_WIFI_WLAN_2G,
|
||||
LINK_TYPE_BR,
|
||||
};
|
||||
ret = memcpy_s(attribute.linkType, sizeof(attribute.linkType), linkTypeList, sizeof(linkTypeList));
|
||||
if (ret != EOK) {
|
||||
HILOGE("data copy failed.");
|
||||
return DP_NO_MEMORY;
|
||||
}
|
||||
int32_t sessionId = OpenSession(sessName, sessName, peerDevId.c_str(), "0", &attribute);
|
||||
if (sessionId < 0) {
|
||||
HILOGE("open softbus session failed for sessionId:%{pubilc}d", sessionId);
|
||||
return DP_SESSION_ERROR;
|
||||
}
|
||||
CloseSession(sessionId);
|
||||
RemoveSessionServer(pkgName, sessName);
|
||||
return DP_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
@ -25,7 +25,6 @@
|
||||
#include "distributed_device_profile_log.h"
|
||||
#include "profile_utils.h"
|
||||
#include "profile_cache.h"
|
||||
#include "dp_detect_utils.h"
|
||||
#include "device_profile_manager.h"
|
||||
#include "permission_manager.h"
|
||||
|
||||
|
@ -119,16 +119,6 @@ ohos_unittest("PermissionManagerTest") {
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("DPDetectUtilsTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/dp_detect_utils_test.cpp" ]
|
||||
configs = device_profile_configs
|
||||
deps = device_profile_deps
|
||||
external_deps = device_profile_external_deps
|
||||
part_name = "device_info_manager"
|
||||
subsystem_name = "deviceprofile"
|
||||
}
|
||||
|
||||
ohos_unittest("IpcUtilsTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "unittest/ipc_utils_test.cpp" ]
|
||||
@ -193,7 +183,6 @@ group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":ClientRdbTest",
|
||||
":DPDetectUtilsTest",
|
||||
":DPSubscribeInfoTest",
|
||||
":IpcUtilsTest",
|
||||
":PermissionManagerTest",
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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 <gtest/gtest.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include "dp_detect_utils.h"
|
||||
#include "distributed_device_profile_constants.h"
|
||||
#include "distributed_device_profile_log.h"
|
||||
#include "distributed_device_profile_errors.h"
|
||||
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedDeviceProfile;
|
||||
using namespace std;
|
||||
namespace {
|
||||
const std::string TAG = "DPDetectUtilsTest";
|
||||
}
|
||||
class DPDetectUtilsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void DPDetectUtilsTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DPDetectUtilsTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DPDetectUtilsTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DPDetectUtilsTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: DetectRemoteDPVersion_001
|
||||
* @tc.desc: Normal testCase of DPDetectUtilsTest for CRUD
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DPDetectUtilsTest, DetectRemoteDPVersion_001, TestSize.Level1)
|
||||
{
|
||||
int32_t ret = DPDetectVersion::DetectRemoteDPVersion("12345");
|
||||
EXPECT_EQ(ret, DP_CREATE_SESSION_FAILED);
|
||||
std::string peerDevId;
|
||||
ret = DPDetectVersion::DetectRemoteDPVersion(peerDevId);
|
||||
EXPECT_EQ(ret, DP_INVALID_PARAMS);
|
||||
}
|
Loading…
Reference in New Issue
Block a user