Skip to content

fix: Fix airplane mode tips display logic#493

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
ut003640:master
Feb 4, 2026
Merged

fix: Fix airplane mode tips display logic#493
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
ut003640:master

Conversation

@ut003640
Copy link
Contributor

@ut003640 ut003640 commented Feb 4, 2026

Fix the logic for displaying airplane mode tips by adding wireless support check. Only show the tips when airplane mode is enabled AND wireless is supported.

Log: Fixed airplane mode tips display condition
PMS: BUG-349721

fix: 修复飞行模式提示显示逻辑

修复飞行模式提示的显示逻辑,增加无线支持检查。仅在飞行模式启用且支持无线功能时显示提示。

Log: 修复飞行模式提示显示条件
PMS: BUG-349721

Summary by Sourcery

Ensure airplane mode tips are only shown when airplane mode is enabled and wireless networking is supported.

Bug Fixes:

  • Correct airplane mode tips visibility to depend on both airplane mode state and presence of wireless-capable devices.

Enhancements:

  • Track wireless support state in the network manager thread and propagate it to the UI layer for conditional item visibility.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 4, 2026

Reviewer's Guide

Adds tracking of whether any wireless devices are present and uses this state to only display the airplane mode tips when airplane mode is enabled and wireless is supported, wiring the new flag through the NetManager thread and private manager classes.

Sequence diagram for updating airplane mode tips visibility based on wireless support

sequenceDiagram
    participant NetManager as NetManager
    participant NetManagerPrivate as NetManagerPrivate
    participant ManagerThread as NetManagerThreadPrivate
    participant NetworkController as NetworkController
    participant Device as NetworkDeviceBase

    Note over ManagerThread,NetworkController: Wireless support tracking
    ManagerThread->>NetworkController: devices()
    NetworkController-->>ManagerThread: QList<NetworkDeviceBase*>
    loop ForEachDevice
        ManagerThread->>Device: deviceType()
        alt Device is wireless
            ManagerThread-->ManagerThread: supportWireless = true
            ManagerThread->>ManagerThread: break
        end
    end
    alt supportWireless state changed
        ManagerThread-->>NetManagerPrivate: supportWirelessChanged(supportWireless)
        NetManagerPrivate->>NetManagerPrivate: onSupportWirelessChanged(supportWireless)
        NetManagerPrivate-->NetManagerPrivate: m_supportWireless = supportWireless
    end

    Note over NetManager,NetManagerPrivate: Airplane mode tips visibility
    NetManager->>NetManagerPrivate: updateAirplaneMode(enabled)
    NetManagerPrivate->>NetManagerPrivate: m_airplaneMode = enabled
    NetManagerPrivate-->>NetManager: airplaneModeChanged(m_airplaneMode)
    NetManagerPrivate->>NetManagerPrivate: updateItemVisible(NetAirplaneModeTipsItem, enabled && m_supportWireless)
Loading

Updated class diagram for NetManagerThreadPrivate and NetManagerPrivate wireless support tracking

classDiagram
    class NetManagerThreadPrivate {
        +NetManagerThreadPrivate()
        +void onDeviceAdded(QList<NetworkDeviceBase*> devices)
        +void onDeviceRemoved(QList<NetworkDeviceBase*> devices)
        +void onConnectivityChanged()
        +NetworkManager::WirelessSecuritySetting::KeyMgmt getKeyMgmtByAp(NetworkManager::AccessPoint* ap)
        +void updateSupportWireless()
        +static NetType::NetDeviceStatus toNetDeviceStatus(ConnectionStatus status)
        +static NetType::NetConnectionStatus toNetConnectionStatus(ConnectionStatus status)
        +static NetType::NetDeviceStatus deviceStatus(NetworkDeviceBase* device)
        +void toControlCenter()
        +void netCheckAvailableChanged(const bool& netCheckAvailable)
        +void supportWirelessChanged(bool supportWireless)
        -QString m_showPageCmd
        -QTimer* m_showPageTimer
        -QString m_newVPNuuid
        -bool m_supportWireless
    }

    class NetManagerPrivate {
        +NetManagerPrivate(NetManager* manager)
        +~NetManagerPrivate()
        +void updateAirplaneMode(bool enabled)
        +void onItemDestroyed(QObject* obj)
        +void onSupportWirelessChanged(bool supportWireless)
        +void setDeviceEnabled(const QString& id, bool enabled)
        +void clearPasswordRequest(const QString& id)
        +void retranslateUi()
        -bool m_airplaneMode
        -bool m_autoAddConnection
        -NetManagerThreadPrivate* m_managerThread
        -void* m_passwordRequestData
        -int m_deviceCount[DeviceItemCount]
        -bool m_supportWireless
        -NetManager* q_ptr
    }

    class NetManager {
        +void airplaneModeChanged(bool airplaneMode)
    }

    NetManagerPrivate --> NetManagerThreadPrivate : uses
    NetManagerThreadPrivate --> NetManagerPrivate : supportWirelessChanged(bool)
    NetManagerPrivate --> NetManager : airplaneModeChanged(bool)
Loading

File-Level Changes

Change Details Files
Track whether the system supports wireless devices in the manager thread and emit changes.
  • Add m_supportWireless boolean member to NetManagerThreadPrivate and initialize it in the constructor.
  • Implement updateSupportWireless() to scan NetworkController devices for a wireless device and update/emit supportWirelessChanged when the value changes.
  • Invoke updateSupportWireless() whenever devices are added or removed so the wireless support state stays current.
net-view/operation/private/netmanagerthreadprivate.cpp
net-view/operation/private/netmanagerthreadprivate.h
Propagate wireless support state to the UI layer and gate airplane mode tips visibility on it.
  • Add m_supportWireless member to NetManagerPrivate and initialize it in the constructor.
  • Connect NetManagerThreadPrivate::supportWirelessChanged to NetManagerPrivate::onSupportWirelessChanged to keep the flag in sync.
  • Implement onSupportWirelessChanged(bool) to update the internal m_supportWireless flag.
  • Change updateAirplaneMode to only show NetAirplaneModeTipsItem when airplane mode is enabled and m_supportWireless is true.
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

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 found 2 issues, and left some high level feedback:

  • When wireless support changes while airplane mode is already enabled, the visibility of NetAirplaneModeTipsItem will not update because it’s only toggled in updateAirplaneMode; consider updating the item visibility in onSupportWirelessChanged (e.g., reusing m_airplaneMode there) to keep the UI in sync.
  • You only recalculate m_supportWireless in onDeviceAdded/onDeviceRemoved; if the initial device list is available at startup, consider calling updateSupportWireless() once after the initial device enumeration to ensure the tip state is correct from the beginning.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When wireless support changes while airplane mode is already enabled, the visibility of `NetAirplaneModeTipsItem` will not update because it’s only toggled in `updateAirplaneMode`; consider updating the item visibility in `onSupportWirelessChanged` (e.g., reusing `m_airplaneMode` there) to keep the UI in sync.
- You only recalculate `m_supportWireless` in `onDeviceAdded`/`onDeviceRemoved`; if the initial device list is available at startup, consider calling `updateSupportWireless()` once after the initial device enumeration to ensure the tip state is correct from the beginning.

## Individual Comments

### Comment 1
<location> `net-view/operation/private/netmanagerthreadprivate.cpp:1945` </location>
<code_context>
         }
     }
     updateDSLEnabledable();
+    updateSupportWireless();
 }

</code_context>

<issue_to_address>
**issue:** Wireless support state is only refreshed on add/remove, so the initial value may be wrong until the first device event.

If the system boots with existing wireless devices but no add/remove events occur, `m_supportWireless` and the UI will stay `false` indefinitely. To avoid this, initialize the value by calling `updateSupportWireless()` once during startup, after the thread and `NetworkController` are ready, so the initial state matches the actual hardware.
</issue_to_address>

### Comment 2
<location> `net-view/operation/netmanager.cpp:882-884` </location>
<code_context>
     m_dataMap.remove(obj->objectName());
 }

+void NetManagerPrivate::onSupportWirelessChanged(bool supportWireless)
+{
+    m_supportWireless = supportWireless;
+}
+
</code_context>

<issue_to_address>
**issue:** Wireless support changes don’t update airplane-mode UI when airplane mode is already enabled.

`updateAirplaneMode` ties `NetAirplaneModeTipsItem` visibility to `enabled && m_supportWireless`, but `onSupportWirelessChanged` only updates `m_supportWireless`. If wireless support changes while airplane mode is already enabled, the tips item visibility won’t update until airplane mode is toggled again. Consider having `onSupportWirelessChanged` refresh the relevant item visibility when `m_airplaneMode` is true.
</issue_to_address>

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.

}
}
updateDSLEnabledable();
updateSupportWireless();
Copy link

Choose a reason for hiding this comment

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

issue: Wireless support state is only refreshed on add/remove, so the initial value may be wrong until the first device event.

If the system boots with existing wireless devices but no add/remove events occur, m_supportWireless and the UI will stay false indefinitely. To avoid this, initialize the value by calling updateSupportWireless() once during startup, after the thread and NetworkController are ready, so the initial state matches the actual hardware.

Comment on lines +882 to +884
void NetManagerPrivate::onSupportWirelessChanged(bool supportWireless)
{
m_supportWireless = supportWireless;
Copy link

Choose a reason for hiding this comment

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

issue: Wireless support changes don’t update airplane-mode UI when airplane mode is already enabled.

updateAirplaneMode ties NetAirplaneModeTipsItem visibility to enabled && m_supportWireless, but onSupportWirelessChanged only updates m_supportWireless. If wireless support changes while airplane mode is already enabled, the tips item visibility won’t update until airplane mode is toggled again. Consider having onSupportWirelessChanged refresh the relevant item visibility when m_airplaneMode is true.


if (m_supportWireless != supportWireless) {
m_supportWireless = supportWireless;
emit supportWirelessChanged(m_supportWireless);
Copy link
Contributor

Choose a reason for hiding this comment

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

发信号统一用Q_EMIT

Fix the logic for displaying airplane mode tips by adding wireless support check. Only show the tips when airplane mode is enabled AND wireless is supported.

Log: Fixed airplane mode tips display condition
PMS: BUG-349721

fix: 修复飞行模式提示显示逻辑

修复飞行模式提示的显示逻辑,增加无线支持检查。仅在飞行模式启用且支持无线功能时显示提示。

Log: 修复飞行模式提示显示条件
PMS: BUG-349721
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, ut003640

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

@deepin-ci-robot
Copy link

deepin pr auto review

这份代码的改动主要实现了检测系统是否支持无线网络功能,并根据此状态控制"飞行模式提示项"的显示逻辑。整体来看,代码逻辑清晰,能够实现预期功能。以下是对语法逻辑、代码质量、代码性能和代码安全方面的详细审查及改进意见:

1. 语法逻辑

  • 初始化一致性

    • NetManagerPrivate 的构造函数中,m_supportWireless 被初始化为 false
    • NetManagerThreadPrivate 的构造函数中,m_supportWireless 也被初始化为 false
    • 问题NetManagerPrivate 初始化为 false 后,依赖于 NetManagerThreadPrivate 后续的信号 supportWirelessChanged 来更新它。如果初始状态就是支持无线(即系统启动时就有无线网卡),虽然 onDeviceAdded 会触发 updateSupportWireless,但在极短的初始化间隙,逻辑上可能存在不一致。
    • 建议:目前的逻辑在信号触发后是正确的,但为了严谨,可以在 NetManagerPrivate 初始化时,主动调用一次检查逻辑,或者确保 NetManagerThreadPrivate 在构造完成后立即同步一次状态(如果设备列表已存在)。不过鉴于 onDeviceAdded 的机制,目前的逻辑在大多数情况下是安全的。
  • 信号连接

    • connect(m_managerThread, &NetManagerThreadPrivate::supportWirelessChanged, this, &NetManagerPrivate::onSupportWirelessChanged, Qt::QueuedConnection);
    • 评价:使用了 Qt::QueuedConnection 是正确的,因为涉及到跨线程通信(NetManagerThreadPrivate 运行在独立线程中)。

2. 代码质量

  • 函数职责

    • updateSupportWireless() 函数封装得很好,职责单一,仅负责检测并发出信号。
    • onSupportWirelessChanged() 槽函数也很简洁,仅负责更新成员变量。
  • 命名规范

    • 变量名 m_supportWireless、函数名 updateSupportWireless 和信号名 supportWirelessChanged 均符合 Qt/C++ 的命名规范,语义清晰。
  • 代码复用性

    • updateSupportWireless 中遍历设备列表的逻辑是通用的。如果未来需要检测其他类型的设备(如蓝牙),可以考虑将设备类型作为参数传入,或者使用模板/lambda。但在当前需求下,直接实现是最优解。

3. 代码性能

  • 设备遍历
    • updateSupportWireless 中,使用了基于范围的 for 循环遍历 NetworkController::instance()->devices()
    • 分析:每次设备增删(onDeviceAdded, onDeviceRemoved)都会触发一次全量遍历。
    • 影响:设备数量通常较少(个位数或十几个),且 onDeviceAdded/onDeviceRemoved 不是高频操作,因此性能开销可以忽略不计。
    • 优化建议:无需优化,当前实现足够高效。

4. 代码安全

  • 线程安全

    • m_supportWirelessNetManagerThreadPrivate 中被写入,并通过信号传递给 NetManagerPrivate
    • 由于使用了 Qt::QueuedConnection,信号参数的拷贝是安全的,且槽函数在接收者线程执行,避免了多线程同时读写同一变量的竞争条件。这一点做得很好。
  • 空指针检查

    • NetworkController::instance()->devices() 返回的列表中的指针通常由框架管理,假设框架保证了指针的有效性。在 onDeviceAdded 中对 device 的检查已经在上层逻辑处理过(虽然 diff 未完全展示上下文,但通常这是安全的)。
    • 建议:在 updateSupportWireless 中,虽然 device->deviceType() 访问通常是安全的,但为了防御性编程,可以添加非空检查(如果 devices() 列表可能包含空指针):
      for (dde::network::NetworkDeviceBase *device : devices) {
          if (!device) continue; // 防御性检查
          if (device->deviceType() == dde::network::DeviceType::Wireless) {
              supportWireless = true;
              break;
          }
      }

5. 综合改进建议

  1. 防御性编程:如上所述,在遍历设备时增加空指针检查。
  2. 逻辑优化updateSupportWireless 函数中的 continue 语句可以改为直接判断,使逻辑更紧凑(虽然 continue 也很清晰)。
    // 修改后的 updateSupportWireless
    void NetManagerThreadPrivate::updateSupportWireless()
    {
        bool supportWireless = false;
        const auto devices = NetworkController::instance()->devices();
        for (const auto &device : devices) {
            if (device && device->deviceType() == dde::network::DeviceType::Wireless) {
                supportWireless = true;
                break;
            }
        }
    
        if (m_supportWireless != supportWireless) {
            m_supportWireless = supportWireless;
            Q_EMIT supportWirelessChanged(m_supportWireless);
        }
    }
  3. 逻辑一致性:确认 NetManagerPrivate 初始化时,是否需要立即从 NetManagerThreadPrivate 获取一次初始状态,防止 UI 初始化时短暂显示错误状态(例如,如果系统默认有无线网卡,初始化时 m_supportWirelessfalse,可能导致飞行模式提示项短暂不显示)。如果 onDeviceAdded 在 UI 构造前触发,则无此问题。

总结

代码改动逻辑正确,线程安全处理得当,性能影响极小。主要建议是增加空指针检查以提高鲁棒性,并确认初始化时的状态同步时序。整体质量较高。

@ut003640
Copy link
Contributor Author

ut003640 commented Feb 4, 2026

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Feb 4, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 0c73dd1 into linuxdeepin:master Feb 4, 2026
16 of 18 checks passed
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.

3 participants