Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions net-view/operation/private/netmanagerthreadprivate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "netmanagerthreadprivate.h"
Expand Down Expand Up @@ -3042,6 +3042,40 @@ NetType::NetConnectionStatus NetManagerThreadPrivate::toNetConnectionStatus(Conn
return NetType::NetConnectionStatus::CS_UnConnected;
}

bool NetManagerThreadPrivate::isWirelessApMode(NetworkDeviceBase *device)
{
// 增加空指针保护,防止 deviceType() 崩溃
if (!device || device->deviceType() != dde::network::DeviceType::Wireless) {
return false;
}

// 查找 NetworkManager 的接口对象
auto dev = NetworkManager::findNetworkInterface(device->path());
if (!dev) {
return false;
}

// 获取当前活动连接
auto activeConn = dev->activeConnection();
if (!activeConn || !activeConn->connection()) {
return false;
}

// 获取连接设置
auto settings = activeConn->connection()->settings();
if (!settings) {
return false;
}

// 检查无线设置的模式是否为 AP
// 使用 staticCast 因为前面已经确认了设备类型,性能优于 dynamicCast
// 显式获取 WirelessSetting 指针,提高可读性
auto wSettings = settings->setting(Setting::Wireless).staticCast<NetworkManager::WirelessSetting>();

// 检查 wSettings 是否有效以及模式是否匹配
return wSettings && wSettings->mode() == NetworkManager::WirelessSetting::Ap;
}

NetType::NetDeviceStatus NetManagerThreadPrivate::deviceStatus(NetworkDeviceBase *device)
{
// 如果当前网卡是有线网卡,且没有插入网线,那么就返回未插入网线
Expand Down Expand Up @@ -3080,7 +3114,9 @@ NetType::NetDeviceStatus NetManagerThreadPrivate::deviceStatus(NetworkDeviceBase
return NetType::NetDeviceStatus::DS_Disconnected;
case DeviceStatus::Prepare:
case DeviceStatus::Config:
return NetType::NetDeviceStatus::DS_Connecting;
// 当设备处于 AP 模式时,虽然底层状态可能是 Prepare 或 Config,
// 但为了避免 UI 显示"正在连接"(用户并未连接外部网络),返回 Disconnected 状态。
return isWirelessApMode(device) ? NetType::NetDeviceStatus::DS_Disconnected : NetType::NetDeviceStatus::DS_Connecting;
case DeviceStatus::Needauth:
return NetType::NetDeviceStatus::DS_Authenticating;
case DeviceStatus::IpConfig:
Expand Down
5 changes: 3 additions & 2 deletions net-view/operation/private/netmanagerthreadprivate.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef NETMANAGERTHREADPRIVATE_H
Expand Down Expand Up @@ -246,7 +246,7 @@ protected Q_SLOTS:
bool handle8021xAccessPoint(AccessPoints *ap, bool hidden);
void onPrepareForSleep(bool state);

protected:
private:
void addDevice(NetDeviceItemPrivate *deviceItem, NetworkDeviceBase *dev);

void getNetCheckAvailableFromDBus();
Expand All @@ -262,6 +262,7 @@ protected Q_SLOTS:

static NetType::NetDeviceStatus toNetDeviceStatus(ConnectionStatus status);
static NetType::NetConnectionStatus toNetConnectionStatus(ConnectionStatus status);
static bool isWirelessApMode(NetworkDeviceBase *device);
static NetType::NetDeviceStatus deviceStatus(NetworkDeviceBase *device);

private:
Expand Down