From e5c61ff581beabf07d448cc0eebc3ec7b9ece6ab Mon Sep 17 00:00:00 2001 From: caixiangrong Date: Thu, 5 Feb 2026 16:01:14 +0800 Subject: [PATCH] fix: resolve hotspot status transition issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When opening a hotspot, the device status was incorrectly showing as "Connecting" instead of "Disconnected" during the Prepare and Config phases. This caused visual status jump issues in the UI. The fix adds special handling for wireless devices in hotspot mode (AP mode). When a wireless device is in AP mode during Prepare/Config status, it now returns DS_Disconnected status instead of DS_Connecting to properly reflect the hotspot state. Log: Fixed incorrect status display when opening hotspot Influence: 1. Test opening hotspot and verify status shows as Disconnected during setup 2. Verify normal wireless connections still show Connecting status correctly 3. Check status transitions for both hotspot and regular wireless connections 4. Test hotspot functionality end-to-end to ensure no regression fix: 修复热点状态跳变问题 当打开热点时,设备状态在准备和配置阶段错误地显示为"正在连接"而非"已断 开"。这导致了UI中的视觉状态跳变问题。 修复方案为热点模式(AP模式)下的无线设备添加特殊处理。当无线设备在准备/ 配置状态处于AP模式时,现在返回"已断开"状态而非"正在连接"状态,以正确反映 热点状态。 Log: 修复打开热点时状态显示不正确的问题 Influence: 1. 测试打开热点功能,验证设置过程中状态正确显示为已断开 2. 验证普通无线连接仍能正确显示正在连接状态 3. 检查热点和普通无线连接的状态转换 4. 端到端测试热点功能确保无回归问题 Fixes: #345413 --- .../private/netmanagerthreadprivate.cpp | 38 ++++++++++++++++++- .../private/netmanagerthreadprivate.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/net-view/operation/private/netmanagerthreadprivate.cpp b/net-view/operation/private/netmanagerthreadprivate.cpp index f9aa83cb..4a7ea590 100644 --- a/net-view/operation/private/netmanagerthreadprivate.cpp +++ b/net-view/operation/private/netmanagerthreadprivate.cpp @@ -3042,6 +3042,40 @@ NetType::NetConnectionStatus NetManagerThreadPrivate::toNetConnectionStatus(Conn return NetType::NetConnectionStatus::CS_UnConnected; } +bool NetManagerThreadPrivate::isWirelessApMode(NetworkDeviceBase *device) +{ + if (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 + auto wSettings = settings->setting(Setting::Wireless).staticCast(); + if (wSettings && wSettings->mode() == NetworkManager::WirelessSetting::Ap) { + return true; + } + + return false; +} + NetType::NetDeviceStatus NetManagerThreadPrivate::deviceStatus(NetworkDeviceBase *device) { // 如果当前网卡是有线网卡,且没有插入网线,那么就返回未插入网线 @@ -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: diff --git a/net-view/operation/private/netmanagerthreadprivate.h b/net-view/operation/private/netmanagerthreadprivate.h index 2bd803e4..0bc461fa 100644 --- a/net-view/operation/private/netmanagerthreadprivate.h +++ b/net-view/operation/private/netmanagerthreadprivate.h @@ -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: