添加编译选项

Signed-off-by: yangli <yangli228@huawei.com>
This commit is contained in:
yangli 2024-10-28 21:21:17 +08:00
parent acfa09b706
commit d6ebd88ae6
9 changed files with 116 additions and 7 deletions

View File

@ -29,6 +29,7 @@ image_framework_path = "//foundation/multimedia/image_framework"
clouddisk_database_path = "${services_path}/clouddisk_database"
declare_args() {
support_same_account = true
if (defined(global_parts_info) &&
defined(global_parts_info.powermgr_battery_manager)) {
cloudsync_service_power = true
@ -56,4 +57,9 @@ declare_args() {
} else {
cloudsync_service_hicollie_enable = false
}
if (!defined(global_parts_info) || !defined(
global_parts_info.distributedhardware_distributed_hardware_adapter)) {
support_same_account = false
}
}

View File

@ -104,6 +104,10 @@ ohos_shared_library("libdistributedfiledaemon") {
defines = [ "LOG_TAG=\"distributedfile_daemon\"" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
part_name = "dfs_service"
subsystem_name = "filemanagement"
kernel_permission_path = "./encaps.json"

View File

@ -41,7 +41,9 @@ using namespace std;
const int32_t DFS_QOS_TYPE_MIN_BW = 90 * 1024 * 1024;
const int32_t DFS_QOS_TYPE_MAX_LATENCY = 10000;
const int32_t DFS_QOS_TYPE_MIN_LATENCY = 2000;
#ifdef SUPPORT_SAME_ACCOUNT
const uint32_t MAX_ONLINE_DEVICE_SIZE = 10000;
#endif
SoftbusAgent::SoftbusAgent(weak_ptr<MountPoint> mountPoint) : NetworkAgentTemplate(mountPoint)
{
auto spt = mountPoint.lock();
@ -58,6 +60,7 @@ SoftbusAgent::SoftbusAgent(weak_ptr<MountPoint> mountPoint) : NetworkAgentTempla
bool SoftbusAgent::IsSameAccount(const std::string &networkId)
{
#ifdef SUPPORT_SAME_ACCOUNT
std::vector<DistributedHardware::DmDeviceInfo> deviceList;
DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(IDaemon::SERVICE_NAME, "", deviceList);
if (deviceList.size() == 0 || deviceList.size() > MAX_ONLINE_DEVICE_SIZE) {
@ -70,6 +73,9 @@ bool SoftbusAgent::IsSameAccount(const std::string &networkId)
}
}
return false;
#else
return true;
#endif
}
int32_t SoftbusAgent::JudgeNetworkTypeIsWifi(const DeviceInfo &info)
@ -159,6 +165,10 @@ int32_t SoftbusAgent::OpenSession(const DeviceInfo &info, const uint8_t &linkTyp
{
LOGI("Start to OpenSession, cid:%{public}s, linkType:%{public}d",
Utils::GetAnonyString(info.GetCid()).c_str(), linkType);
if (!IsSameAccount(info.GetCid())) {
LOGI("The source and sink device is not same account, not support.");
return FileManagement::E_INVAL_ARG;
}
ISocketListener sessionListener = {
.OnBind = SoftbusSessionDispatcher::OnSessionOpened,
.OnShutdown = SoftbusSessionDispatcher::OnSessionClosed,
@ -181,10 +191,6 @@ int32_t SoftbusAgent::OpenSession(const DeviceInfo &info, const uint8_t &linkTyp
int32_t socketId = Socket(clientInfo);
if (socketId < FileManagement::E_OK) {
LOGE("Create OpenSoftbusChannel Socket error");
RADAR_REPORT(RadarReporter::DFX_SET_DFS, RadarReporter::DFX_BUILD__LINK, RadarReporter::DFX_FAILED,
RadarReporter::BIZ_STATE, RadarReporter::DFX_END, RadarReporter::ERROR_CODE,
RadarReporter::CREAT_SOCKET_ERROR, RadarReporter::PACKAGE_NAME,
RadarReporter::dSoftBus + to_string(socketId));
return FileManagement::E_CONTEXT;
}
int32_t ret = Bind(socketId, qos, sizeof(qos) / sizeof(qos[0]), &sessionListener);
@ -211,6 +217,10 @@ void SoftbusAgent::OpenApSession(const DeviceInfo &info, const uint8_t &linkType
{
LOGI("Start to OpenApSession, cid:%{public}s, linkType:%{public}d",
Utils::GetAnonyString(info.GetCid()).c_str(), linkType);
if (!IsSameAccount(info.GetCid())) {
LOGI("The source and sink device is not same account, not support.");
return;
}
if (JudgeNetworkTypeIsWifi(info)) {
LOGI("networktype is not wifi");
return;

View File

@ -37,7 +37,9 @@ const int32_t DFS_QOS_TYPE_MIN_BW = 90 * 1024 * 1024;
const int32_t DFS_QOS_TYPE_MAX_LATENCY = 10000;
const int32_t DFS_QOS_TYPE_MIN_LATENCY = 2000;
const int32_t INVALID_SESSION_ID = -1;
#ifdef SUPPORT_SAME_ACCOUNT
const uint32_t MAX_ONLINE_DEVICE_SIZE = 10000;
#endif
constexpr size_t MAX_SIZE = 500;
std::mutex SoftBusHandler::clientSessNameMapMutex_;
std::map<int32_t, std::string> SoftBusHandler::clientSessNameMap_;
@ -47,6 +49,16 @@ std::mutex SoftBusHandler::networkIdMapMutex_;
std::map<int32_t, std::string> SoftBusHandler::networkIdMap_;
void SoftBusHandler::OnSinkSessionOpened(int32_t sessionId, PeerSocketInfo info)
{
if (!SoftBusHandler::IsSameAccount(info.networkId)) {
std::lock_guard<std::mutex> lock(serverIdMapMutex_);
auto it = serverIdMap_.find(info.name);
if (it != serverIdMap_.end()) {
Shutdown(it->second);
serverIdMap_.erase(it);
LOGI("RemoveSessionServer success.");
}
Shutdown(sessionId);
}
AllConnectManager::GetInstance().PublishServiceState(info.networkId,
ServiceCollaborationManagerBussinessStatus::SCM_CONNECTED);
{
@ -59,6 +71,7 @@ void SoftBusHandler::OnSinkSessionOpened(int32_t sessionId, PeerSocketInfo info)
bool SoftBusHandler::IsSameAccount(const std::string &networkId)
{
#ifdef SUPPORT_SAME_ACCOUNT
std::vector<DistributedHardware::DmDeviceInfo> deviceList;
DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(SERVICE_NAME, "", deviceList);
if (deviceList.size() == 0 || deviceList.size() > MAX_ONLINE_DEVICE_SIZE) {
@ -71,6 +84,9 @@ bool SoftBusHandler::IsSameAccount(const std::string &networkId)
}
}
return false;
#else
return true;
#endif
}
std::string SoftBusHandler::GetSessionName(int32_t sessionId)
@ -167,6 +183,10 @@ int32_t SoftBusHandler::OpenSession(const std::string &mySessionName, const std:
return FileManagement::ERR_BAD_VALUE;
}
LOGI("OpenSession Enter peerDevId: %{public}s", Utils::GetAnonyString(peerDevId).c_str());
if (!IsSameAccount(peerDevId)) {
LOGI("The source and sink device is not same account, not support.");
return E_OPEN_SESSION;
}
QosTV qos[] = {
{.qos = QOS_TYPE_MIN_BW, .value = DFS_QOS_TYPE_MIN_BW},
{.qos = QOS_TYPE_MAX_LATENCY, .value = DFS_QOS_TYPE_MAX_LATENCY},

View File

@ -81,6 +81,11 @@ weak_ptr<SoftbusAgent> SoftbusSessionDispatcher::GetAgent(int32_t sessionId, std
void SoftbusSessionDispatcher::OnSessionOpened(int32_t sessionId, PeerSocketInfo info)
{
LOGI("OnSessionOpened Enter sessionId = %{public}d", sessionId);
if (!SoftbusAgent::IsSameAccount(info.networkId)) {
LOGI("The source and sink device is not same account, not support.");
Shutdown(sessionId);
return;
}
std::string peerSessionName(info.name);
std::string peerDevId = info.networkId;
{

View File

@ -73,6 +73,11 @@ std::vector<std::string> SoftBusSessionListener::GetFileName(const std::vector<s
void SoftBusSessionListener::OnSessionOpened(int32_t sessionId, PeerSocketInfo info)
{
LOGI("OnSessionOpened sessionId = %{public}d", sessionId);
if (!SoftBusHandler::IsSameAccount(info.networkId)) {
LOGI("The source and sink device is not same account, not support.");
Shutdown(sessionId);
return;
}
std::string sessionName = info.name;
SoftBusSessionPool::SessionInfo sessionInfo;
auto ret = SoftBusSessionPool::GetInstance().GetSessionInfo(sessionName, sessionInfo);

View File

@ -155,6 +155,10 @@ ohos_unittest("device_manager_agent_sup_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("device_manager_agent_test") {
@ -244,6 +248,10 @@ ohos_unittest("device_manager_agent_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("os_account_observer_test") {
@ -328,6 +336,9 @@ ohos_unittest("os_account_observer_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("devsl_dispatcher_test") {
@ -411,6 +422,10 @@ ohos_unittest("devsl_dispatcher_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("kernel_talker_test") {
@ -494,6 +509,10 @@ ohos_unittest("kernel_talker_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("network_agent_template_test") {
@ -572,6 +591,10 @@ ohos_unittest("network_agent_template_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("session_pool_test") {
@ -654,6 +677,10 @@ ohos_unittest("session_pool_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_agent_test") {
@ -740,6 +767,10 @@ ohos_unittest("softbus_agent_test") {
"private=public",
"protected=public",
]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_file_receive_listener_test") {
@ -790,6 +821,10 @@ ohos_unittest("softbus_file_receive_listener_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_file_send_listener_test") {
@ -840,6 +875,10 @@ ohos_unittest("softbus_file_send_listener_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_session_dispatcher_test") {
@ -923,6 +962,10 @@ ohos_unittest("softbus_session_dispatcher_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_session_test") {
@ -1006,6 +1049,10 @@ ohos_unittest("softbus_session_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_handler_asset_test") {
@ -1065,6 +1112,10 @@ ohos_unittest("softbus_handler_asset_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_handler_test") {
@ -1116,6 +1167,10 @@ ohos_unittest("softbus_handler_test") {
]
defines = [ "private=public" ]
if (support_same_account) {
defines += [ "SUPPORT_SAME_ACCOUNT" ]
}
}
ohos_unittest("softbus_session_pool_test") {

View File

@ -131,6 +131,7 @@ HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_IsSameAccount_0100, TestSize.Level1)
std::shared_ptr<SoftbusAgent> agent = std::make_shared<SoftbusAgent>(wmp);
bool flag = agent->IsSameAccount(NETWORKID_ONE);
EXPECT_EQ(flag, true);
#ifdef SUPPORT_SAME_ACCOUNT
flag = agent->IsSameAccount(NETWORKID_TWO);
EXPECT_EQ(flag, false);
flag = agent->IsSameAccount(NETWORKID_THREE);
@ -138,6 +139,7 @@ HWTEST_F(SoftbusAgentTest, SoftbusAgentTest_IsSameAccount_0100, TestSize.Level1)
g_mockGetTrustedDeviceList = false;
flag = agent->IsSameAccount(NETWORKID_ONE);
EXPECT_EQ(flag, false);
#endif
g_mockGetTrustedDeviceList = true;
GTEST_LOG_(INFO) << "SoftbusAgentTest_IsSameAccount_0100 end";
}

View File

@ -302,6 +302,7 @@ HWTEST_F(SoftbusHandlerTest, SoftbusHandlerTest_IsSameAccount_0100, TestSize.Lev
SoftBusHandler handler;
bool flag = handler.IsSameAccount(TEST_NETWORKID);
EXPECT_EQ(flag, true);
#ifdef SUPPORT_SAME_ACCOUNT
flag = handler.IsSameAccount(TEST_NETWORKID_TWO);
EXPECT_EQ(flag, false);
flag = handler.IsSameAccount(TEST_NETWORKID_THREE);
@ -309,6 +310,7 @@ HWTEST_F(SoftbusHandlerTest, SoftbusHandlerTest_IsSameAccount_0100, TestSize.Lev
g_mockGetTrustedDeviceList = false;
flag = handler.IsSameAccount(TEST_NETWORKID);
EXPECT_EQ(flag, false);
#endif
g_mockGetTrustedDeviceList = true;
GTEST_LOG_(INFO) << "SoftbusHandlerTest_IsSameAccount_0100 end";
}
@ -355,14 +357,14 @@ HWTEST_F(SoftbusHandlerTest, SoftbusHandlerTest_OnSinkSessionOpened_0100, TestSi
EXPECT_EQ(handler.GetSessionName(sessionId1), sessionName1);
EXPECT_EQ(handler.GetSessionName(sessionId2), sessionName2);
EXPECT_EQ(handler.GetSessionName(sessionId3), sessionName3);
#ifdef SUPPORT_SAME_ACCOUNT
auto iter = handler.serverIdMap_.find(sessionName2);
if (iter != handler.serverIdMap_.end()) {
handler.serverIdMap_.clear();
if (iter == handler.serverIdMap_.end()) {
EXPECT_TRUE(true);
} else {
EXPECT_TRUE(false);
}
#endif
handler.clientSessNameMap_.erase(sessionId1);
handler.clientSessNameMap_.erase(sessionId2);
handler.clientSessNameMap_.erase(sessionId3);