Skip to content

fix: resolve hotspot status transition issue#496

Open
caixr23 wants to merge 1 commit intolinuxdeepin:masterfrom
caixr23:bug-345413
Open

fix: resolve hotspot status transition issue#496
caixr23 wants to merge 1 commit intolinuxdeepin:masterfrom
caixr23:bug-345413

Conversation

@caixr23
Copy link
Contributor

@caixr23 caixr23 commented Feb 5, 2026

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

Summary by Sourcery

Bug Fixes:

  • Ensure wireless devices in hotspot (AP) mode report as Disconnected instead of Connecting during Prepare/Config states while keeping regular wireless connections unchanged.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts device status mapping for wireless devices in hotspot (AP) mode so that during Prepare/Config phases they report Disconnected instead of Connecting, fixing UI status jumps while preserving existing behavior for other cases.

Sequence diagram for device status resolution with hotspot AP handling

sequenceDiagram
    participant UI
    participant NetManagerThreadPrivate
    participant NetworkDeviceBase
    participant NetworkManager
    participant NetworkInterface
    participant ActiveConnection
    participant Connection
    participant ConnectionSettings
    participant WirelessSetting

    UI->>NetManagerThreadPrivate: deviceStatus(device)
    NetManagerThreadPrivate->>NetworkDeviceBase: status()
    NetworkDeviceBase-->>NetManagerThreadPrivate: DeviceStatus_Prepare_or_Config

    alt device is wireless
        NetManagerThreadPrivate->>NetworkDeviceBase: deviceType()
        NetworkDeviceBase-->>NetManagerThreadPrivate: DeviceType_Wireless
        NetManagerThreadPrivate->>NetworkDeviceBase: path()
        NetworkDeviceBase-->>NetManagerThreadPrivate: device_path
        NetManagerThreadPrivate->>NetworkManager: findNetworkInterface(device_path)
        NetworkManager-->>NetManagerThreadPrivate: NetworkInterface

        alt interface found
            NetManagerThreadPrivate->>NetworkInterface: activeConnection()
            NetworkInterface-->>NetManagerThreadPrivate: ActiveConnection
            alt activeConnection and connection exist
                NetManagerThreadPrivate->>ActiveConnection: connection()
                ActiveConnection-->>NetManagerThreadPrivate: Connection
                NetManagerThreadPrivate->>Connection: settings()
                Connection-->>NetManagerThreadPrivate: ConnectionSettings
                NetManagerThreadPrivate->>ConnectionSettings: setting(Wireless)
                ConnectionSettings-->>NetManagerThreadPrivate: WirelessSetting
                NetManagerThreadPrivate->>WirelessSetting: mode()
                WirelessSetting-->>NetManagerThreadPrivate: Mode

                alt Mode is Ap
                    NetManagerThreadPrivate-->>UI: DS_Disconnected
                else Mode is not Ap
                    NetManagerThreadPrivate-->>UI: DS_Connecting
                end
            else no active connection or connection
                NetManagerThreadPrivate-->>UI: DS_Connecting
            end
        else interface not found
            NetManagerThreadPrivate-->>UI: DS_Connecting
        end
    else device is not wireless
        NetManagerThreadPrivate-->>UI: DS_Connecting
    end
Loading

Class diagram for updated device status mapping logic

classDiagram
    class NetManagerThreadPrivate {
        +deviceStatus(device NetworkDeviceBase) NetType_NetDeviceStatus
    }

    class NetworkDeviceBase {
        +status() DeviceStatus
        +deviceType() DeviceType
        +path() string
    }

    class NetworkManager {
        +findNetworkInterface(path string) NetworkInterface_ptr
    }

    class NetworkInterface {
        +activeConnection() ActiveConnection_ptr
    }

    class ActiveConnection {
        +connection() Connection_ptr
    }

    class Connection {
        +settings() ConnectionSettings_ptr
    }

    class ConnectionSettings {
        +setting(type Setting) SettingBase_ptr
    }

    class WirelessSetting {
        +mode() WirelessMode
    }

    class DeviceStatus {
        <<enumeration>>
        Prepare
        Config
        Disconnected
        Needauth
        IpConfig
    }

    class NetType_NetDeviceStatus {
        <<enumeration>>
        DS_Disconnected
        DS_Connecting
        DS_Authenticating
    }

    class DeviceType {
        <<enumeration>>
        Wireless
        Wired
        Other
    }

    class Setting {
        <<enumeration>>
        Wireless
        OtherSetting
    }

    class WirelessMode {
        <<enumeration>>
        Ap
        Station
        OtherMode
    }

    NetManagerThreadPrivate --> NetworkDeviceBase : uses
    NetManagerThreadPrivate --> NetworkManager : uses
    NetworkManager --> NetworkInterface : returns
    NetworkInterface --> ActiveConnection : returns
    ActiveConnection --> Connection : returns
    Connection --> ConnectionSettings : returns
    ConnectionSettings --> WirelessSetting : returns
    NetManagerThreadPrivate --> NetType_NetDeviceStatus : returns
    NetworkDeviceBase --> DeviceStatus : returns
    NetworkDeviceBase --> DeviceType : returns
    ConnectionSettings --> Setting : parameter
    WirelessSetting --> WirelessMode : returns
Loading

File-Level Changes

Change Details Files
Add special-case handling for wireless devices in AP (hotspot) mode during Prepare/Config to report Disconnected status instead of Connecting.
  • Wrap the Prepare/Config status handling in a scoped block to allow early returns based on device type and connection settings.
  • For wireless devices, look up the corresponding network interface from NetworkManager using the device path.
  • If the wireless device has an active connection with wireless settings in AP mode, return DS_Disconnected instead of DS_Connecting during Prepare/Config.
  • Fall back to returning DS_Connecting when the device is not wireless, has no active connection, has non-wireless settings, or is not in AP mode.
net-view/operation/private/netmanagerthreadprivate.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The AP-mode special case logic inside the Prepare/Config branch is becoming quite nested; consider extracting it into a small helper (e.g., isWirelessApMode(device)) to improve readability and reuse if needed elsewhere.
  • You currently only apply the AP-mode check for Wireless devices; if there are other device types that can enter AP mode, it may be worth centralizing the mode check on the connection rather than the device type to avoid future inconsistencies.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The AP-mode special case logic inside the `Prepare/Config` branch is becoming quite nested; consider extracting it into a small helper (e.g., `isWirelessApMode(device)`) to improve readability and reuse if needed elsewhere.
- You currently only apply the AP-mode check for `Wireless` devices; if there are other device types that can enter AP mode, it may be worth centralizing the mode check on the connection rather than the device type to avoid future inconsistencies.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@caixr23 caixr23 force-pushed the bug-345413 branch 2 times, most recently from f45c614 to a1350b6 Compare February 5, 2026 08:23
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
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要是为了解决无线网卡处于 AP (Access Point) 模式时,UI 错误显示"正在连接"状态的问题。通过增加 isWirelessApMode 函数并在 deviceStatus 中调用它,实现了逻辑判断。

以下是对这段代码的详细审查和改进建议:

1. 语法与逻辑审查

  • 基本逻辑正确:代码通过层层检查(设备类型 -> NM接口 -> 活动连接 -> 连接设置 -> 无线模式)来判断是否处于 AP 模式,逻辑链条清晰,防御性编程做得较好(多处空指针检查)。
  • 类型转换:使用了 staticCast 而非 dynamicCast,正如注释所言,在已经确认设备类型的情况下,staticCast 性能更好,这是合理的优化。
  • 函数设计isWirelessApMode 被声明为 static,因为它不依赖于类的实例成员变量,仅根据输入参数和全局/静态状态(NetworkManager)进行判断,设计合理。

2. 代码质量与可读性

  • 优点
    • 变量命名清晰(如 activeConn, wSettings)。
    • 注释解释了关键步骤和意图,特别是关于 staticCast 的理由和 UI 行为的解释。
  • 改进建议
    • 空指针检查冗余:在 isWirelessApMode 中,activeConn->connection() 的返回值在下一行立即被调用,如果 activeConn 存在但 connection() 返回空,!activeConn->connection() 检查已经拦截。但考虑到代码的健壮性,保留双重检查(!activeConn || !activeConn->connection())是值得的,没有问题。
    • 魔法值DeviceStatus::PrepareDeviceStatus::Config 是枚举值,但代码逻辑中暗示这两个状态在 AP 模式下需要特殊处理。如果后续增加其他状态也需要类似处理,建议考虑是否需要重构状态判断逻辑。

3. 代码性能

  • 潜在的性能开销
    • deviceStatus 函数在 UI 刷新或状态变更时可能会被频繁调用。
    • isWirelessApMode 内部调用了 NetworkManager::findNetworkInterface,这通常涉及 DBus 调用(取决于 NetworkManager-Qt 的实现),可能会有一定的 IPC (进程间通信) 开销。
    • 改进建议:如果 deviceStatus 调用频率极高,且 AP 模式切换并不频繁,可以考虑在 NetworkDeviceBase 或相关上下文中缓存 AP 模式状态,或者仅在设备状态发生变更(如 Prepare/Config)时才进行查询。不过,考虑到 PrepareConfig 本身就是瞬时状态,目前的实现作为初期方案是可以接受的。

4. 代码安全

  • 空指针解引用风险
    • 代码中已经对 devactiveConnsettings 进行了非空检查,风险较低。
    • 注意点settings->setting(Setting::Wireless) 返回的是 Setting::Ptr。如果连接配置中没有无线设置(理论上对于无线设备不应该发生,但配置文件可能损坏),staticCast 后的 wSettings 可能是无效的(虽然 staticCast 本身不检查空,但 Ptr 通常会重载 operator bool)。
    • 代码中 if (wSettings && ...) 已经正确处理了 wSettings 为空的情况,安全性良好。
  • 线程安全
    • NetworkManager 的操作通常涉及异步事件循环。虽然 findNetworkInterface 可能是同步调用,但需确保 deviceStatus 的调用线程与 NetworkManager 的处理线程兼容(通常是在主线程或 NetworkManager 的专用线程)。如果 deviceStatus 在非 UI 线程被调用,需确认 NetworkManager-Qt 的线程安全性。

5. 具体改进代码示例

针对性能和代码结构的微调建议:

bool NetManagerThreadPrivate::isWirelessApMode(NetworkDeviceBase *device)
{
    // 1. 快速路径:如果不是无线设备,直接返回
    if (!device || device->deviceType() != dde::network::DeviceType::Wireless) {
        return false;
    }

    // 2. 查找 NetworkManager 的接口对象
    // 注意:这里可能有 DBus 调用开销
    auto dev = NetworkManager::findNetworkInterface(device->path());
    if (!dev) {
        return false;
    }

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

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

    // 5. 检查无线设置的模式是否为 AP
    // 使用 staticCast 因为前面已经确认了设备类型,性能优于 dynamicCast
    auto wSettings = settings->setting(Setting::Wireless).staticCast<NetworkManager::WirelessSetting>();
    
    // 确保 wSettings 有效,并且模式匹配
    return wSettings && wSettings->mode() == NetworkManager::WirelessSetting::Ap;
}

总结

这段代码整体质量不错,逻辑清晰,安全性考虑周全。主要关注点在于 NetworkManager::findNetworkInterface 可能带来的性能开销。如果在实际运行中发现 UI 刷新卡顿,建议针对 isWirelessApMode 的结果进行缓存优化。目前的实现作为功能修复是合格的。

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Feb 5, 2026

TAG Bot

New tag: 2.0.81
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #497

@caixr23 caixr23 requested a review from mhduiy February 6, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants