Skip to content

fix(network): implement primaryConnectionType tracking in NetManager - #628

Closed
mhduiy wants to merge 1 commit into
masterfrom
agent/pms-bug-bot/b72b318f585d
Closed

mhduiy wants to merge 1 commit into
masterfrom
agent/pms-bug-bot/b72b318f585d

Conversation

@mhduiy

@mhduiy mhduiy commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The NetManager class in dde-network-core never implemented primary connection type tracking. The primaryConnectionType() getter was a stub returning Unknown, the updatePrimaryConnectionType() function body was fully commented out, and the m_primaryConnectionType member variable was also commented out. When both wired and wireless connections are active, updateNetworkIcon() calls primaryConnectionType(), gets Unknown, and falls back to selecting the wireless icon by default.

Key evidence: netmanager.cpp:84-86 (stub getter), netmanager.cpp:1046-1053 (commented-out function body), netstatus.cpp:798-803 (icon fallback logic).

Fix

Uncomment and enable the existing primary connection type tracking infrastructure — 4 changes across 2 files, all within NetManager/NetManagerPrivate classes, no signature or interface changes:

  1. Uncomment m_primaryConnectionType member variable in netmanager_p.h
  2. Uncomment constructor initialization m_primaryConnectionType(Wired) in netmanager.cpp
  3. Change primaryConnectionType() to return d->m_primaryConnectionType instead of hardcoded Unknown
  4. Uncomment updatePrimaryConnectionType() function body to store the value and emit primaryConnectionTypeChanged signal

The data pipeline from NetworkManagerQt → NetManagerThreadPrivate → NetManagerPrivate::onDataChanged → updatePrimaryConnectionType was already wired; only the storage and signal emission were missing.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target code was introduced in the initial commit (2024-10-24, "feat: Implement control center network plugin") in commented-out state — this is not a regression of any previous bug fix, simply enabling unfinished functionality.
  • All 6 callers of primaryConnectionType() in netstatus.cpp (lines 550, 553, 621, 629, 798, 987, 1051) currently receive Unknown and will now receive the actual connection type. The primaryConnectionTypeChanged signal is already connected to updateNetworkIcon and updateNetworkTips in netstatus.cpp:73-74.

Business Impact Scope

  • Taskbar network icon: When both wired and wireless are connected, the icon will now correctly show the wired icon instead of defaulting to wireless.
  • Network status IP display: IP display logic that depends on connection type will now function correctly.
  • Network tips: Connection-type-dependent tip display will now reflect the actual primary connection type.

Verification Suggestion

Test with both wired and wireless simultaneously connected — verify the taskbar network icon shows wired. Then test wired-only and wireless-only scenarios to confirm no regression.


根因分析

dde-network-core 中 NetManager 类的主连接类型追踪功能从未实现。primaryConnectionType() getter 为桩函数返回 Unknown,updatePrimaryConnectionType() 函数体被完全注释掉,m_primaryConnectionType 成员变量也被注释。当有线和无线同时连接时,updateNetworkIcon() 调用 primaryConnectionType() 得到 Unknown,fallback 默认选择无线图标。

关键证据:netmanager.cpp:84-86(桩 getter)、netmanager.cpp:1046-1053(注释掉的函数体)、netstatus.cpp:798-803(图标 fallback 逻辑)。

修复方案

取消注释并启用已有的主连接类型追踪基础设施——4 处改动跨 2 个文件,均在 NetManager/NetManagerPrivate 类内,不改签名/接口:

  1. 取消注释 netmanager_p.h 中的 m_primaryConnectionType 成员变量
  2. 取消注释 netmanager.cpp 构造函数中的 m_primaryConnectionType(Wired) 初始化
  3. primaryConnectionType() 返回 d->m_primaryConnectionType 而非硬编码 Unknown
  4. 取消注释 updatePrimaryConnectionType() 函数体,存储值并发送 primaryConnectionTypeChanged 信号

从 NetworkManagerQt → NetManagerThreadPrivate → NetManagerPrivate::onDataChanged → updatePrimaryConnectionType 的数据管道已接通,仅缺少存储和信号发送。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标代码由初始提交(2024-10-24, "feat: Implement control center network plugin")引入即为注释状态——这不是对任何历史 bug 修复的回退,而是启用未完成的功能。
  • netstatus.cpp 中 primaryConnectionType() 的全部 6 个调用点(行 550、553、621、629、798、987、1051)当前收到 Unknown,修复后将收到实际连接类型。primaryConnectionTypeChanged 信号已在 netstatus.cpp:73-74 连接到 updateNetworkIcon 和 updateNetworkTips。

业务影响范围

  • 任务栏网络图标:有线+无线同时连接时,图标将正确显示有线图标而非默认无线。
  • 网络状态 IP 显示:依赖连接类型的 IP 显示逻辑将正常工作。
  • 网络提示:依赖连接类型的提示显示将反映实际主连接类型。

验证建议

测试有线+无线同时连接场景——验证任务栏网络图标显示有线图标。然后测试仅有线和仅无线场景,确认无回归。

PMS: BUG-375223

Summary by Sourcery

Bug Fixes:

  • Enable primary network connection tracking so connection-type-dependent icons, IP displays, and tips use the actual active connection.

1. Uncomment m_primaryConnectionType member variable in NetManagerPrivate
2. Initialize m_primaryConnectionType to Wired in constructor
3. Return actual value from primaryConnectionType() instead of hardcoded Unknown
4. Implement updatePrimaryConnectionType() to store value and emit change signal

Log: Fix network icon showing wireless instead of wired when both are connected

fix(network): 实现 NetManager 主连接类型追踪功能

1. 取消注释 NetManagerPrivate 中的 m_primaryConnectionType 成员变量
2. 构造函数中初始化 m_primaryConnectionType 为 Wired
3. primaryConnectionType() 返回实际值而非硬编码 Unknown
4. 实现 updatePrimaryConnectionType() 存储值并发送变更信号

Log: 修复有线和无线同时连接时任务栏网络图标显示为无线图标的问题
PMS: BUG-375223

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @mhduiy, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 hours and 24 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

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

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR completes the existing primary connection type data path by restoring private-state storage, Wired initialization, getter access, and change-signal emission. Consumers such as network icon, IP display, and tips can now react to the actual primary connection, especially when wired and wireless links are simultaneously active.

Sequence diagram for primary connection type updates

sequenceDiagram
    participant NetworkManagerQt
    participant NetManagerThreadPrivate
    participant NetManagerPrivate
    participant NetManager
    participant NetStatus

    NetworkManagerQt->>NetManagerThreadPrivate: primary connection type data changes
    NetManagerThreadPrivate->>NetManagerPrivate: onDataChanged
    NetManagerPrivate->>NetManagerPrivate: updatePrimaryConnectionType(type)
    NetManagerPrivate->>NetManager: primaryConnectionTypeChanged(type)
    NetManager->>NetStatus: updateNetworkIcon()
    NetManager->>NetStatus: updateNetworkTips()
    NetStatus->>NetManager: primaryConnectionType()
Loading

File-Level Changes

Change Details Files
Enable primary connection type state, initialization, and change notifications.
  • Store the primary connection type in the private manager state.
  • Initialize the state to Wired.
  • Return the stored type from the public getter.
  • Update the state only when changed and emit primaryConnectionTypeChanged.
net-view/operation/netmanager.cpp
net-view/operation/private/netmanager_p.h

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。本次提交修复了 NetManager 主连接类型追踪功能未实现的问题,通过取消注释已有代码基础设施,启用了 primaryConnectionType 属性的存储、更新和信号通知机制。改动范围小、逻辑清晰、与 commit 目的完全一致。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰。所有取消注释的代码均为有效的 C++ 代码,遵循 Qt d-pointer 模式。primaryConnectionType() getter 正确返回 d->m_primaryConnectionType;构造函数正确初始化 m_primaryConnectionType(Wired) 作为默认值;updatePrimaryConnectionType() 正确使用 Q_Q 宏获取公共类指针并发送 primaryConnectionTypeChanged 信号。数据管道完整:NetworkManager → NetManagerThreadPrivate → onDataChanged → updatePrimaryConnectionType → primaryConnectionTypeChanged 信号 → NetStatus。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码结构清晰,注释完整。改动仅 4 处跨 2 个文件,全部在 NetManager/NetManagerPrivate 类内,不改签名/接口。代码模式与同类函数 updateAirplaneMode(netmanager.cpp:1035-1044)完全一致,保持了一致性。无重复代码,无残留调试代码。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。updatePrimaryConnectionType() 使用条件判断(m_primaryConnectionType != type)避免不必要的信号发射,仅在实际变化时才触发 UI 更新。ConnectionType 为枚举类型,按值传递高效。整体复杂度 O(1),无性能瓶颈。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 安全合规。本次改动不涉及用户输入处理、外部数据交互、文件操作或网络通信。type 参数来源于 NetworkManager 内部数据管道(onDataChanged → value.toInt()),不涉及外部不可信数据。无命令注入、SQL 注入、路径遍历等安全风险。无硬编码密钥或敏感信息。


💡 改进建议代码示例

// 本次改动无需修复代码示例,所有变更均为取消注释已有代码
// netmanager_p.h - 取消注释成员变量
NetManager::ConnectionType m_primaryConnectionType;

// netmanager.cpp - getter 返回实际值
NetManager::ConnectionType NetManager::primaryConnectionType() const
{
    return d->m_primaryConnectionType;
}

// netmanager.cpp - 构造函数初始化
, m_primaryConnectionType(NetManager::ConnectionType::Wired)

// netmanager.cpp - 更新函数体
void NetManagerPrivate::updatePrimaryConnectionType(NetManager::ConnectionType type)
{
    if (m_primaryConnectionType != type) {
        m_primaryConnectionType = type;
        Q_Q(NetManager);
        Q_EMIT q->primaryConnectionTypeChanged(m_primaryConnectionType);
    }
}

本报告由 AI 代码审查工具自动生成

@mhduiy

mhduiy commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

#626 在这里跟踪修复,此PR关闭

@mhduiy mhduiy closed this Sep 14, 2026
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