Skip to content

feat(power): migrate power services - #146

Open
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:x11power
Open

feat(power): migrate power services#146
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:x11power

Conversation

@mhduiy

@mhduiy mhduiy commented Aug 17, 2026

Copy link
Copy Markdown
Contributor
  1. Unify session Power scheduling across X11 and Wayland backends.
  2. Add the system Power1 plugin with battery and power-mode APIs.
  3. Preserve legacy idle, screen, brightness, short-idle, and scheduled-shutdown behavior.
  4. Harden DPMS state writes and use systemd D-Bus for running-service checks.
  5. Reuse AmbientBrightness1 sensor state instead of claiming the light sensor twice.
  6. Move Power D-Bus, DConfig, Polkit, and activation assets into dde-services.
  7. Require deepin-power-control for system hardware control.

Log: Migrate Power1 ownership while preserving behavior across both display backends.
Influence: X11 and Wayland share compatible Power APIs.

feat(power): 迁移电源服务

  1. 统一 X11 与 Wayland 的会话电源调度后端。
  2. 新增包含电池与电源模式接口的系统 Power1 插件。
  3. 保持旧版空闲、屏幕、亮度、短空闲及定时关机行为。
  4. 加固 DPMS 状态写入,并通过 systemd D-Bus 查询运行中的服务。
  5. 复用 AmbientBrightness1 的传感器状态,避免重复占用光感传感器。
  6. 将电源 D-Bus、DConfig、Polkit 与激活文件迁移至 dde-services。
  7. 为系统硬件控制添加 deepin-power-control 依赖。

Log: 迁移 Power1 所有权并保持两种显示后端的兼容行为。
PMS: TASK-394241
Influence: X11 与 Wayland 共用兼容的电源接口。

Validation:

  • Built plugin-power-session and plugin-power-system.
  • Loaded and unloaded X11, Wayland, and system Power plugins.
  • Verified migrated Power artifacts do not overlap paired daemon packaging.

Summary by Sourcery

Migrate session and system power services into dde-services while maintaining compatible power APIs and behavior across X11 and Wayland.

New Features:

  • Expose a system Power1 service with battery objects, power-mode controls, short-idle state, and warning-level configuration APIs.
  • Provide shared session power scheduling for X11 and Wayland, including idle, display, suspend, brightness, and wake handling.
  • Support dynamic battery-device discovery and aggregated battery telemetry.

Bug Fixes:

  • Preserve and harden legacy scheduled shutdown, low-power warnings, DPMS, lid, and brightness behavior across display backends.
  • Avoid duplicate ambient-light sensor ownership and improve persistence/configuration synchronization.

Enhancements:

  • Add X11 idle and DPMS integrations alongside the existing Wayland implementations.
  • Use authorized power-control queuing, systemd service checks, session/inhibitor checks, and legacy configuration migration.

Build:

  • Build and install the session and system power plugins with X11 dependencies and migrated D-Bus, DConfig, and policy assets.

Deployment:

  • Move Power1 service ownership and activation assets into dde-services and require deepin-power-control for hardware power-mode control.

Tests:

  • Validate building, loading, and unloading the session and system power plugins across X11 and Wayland, including packaging-overlap checks.

@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, your pull request is larger than the review limit of 150000 diff characters

@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 Aug 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors the power management stack so X11 and Wayland share a unified Power1 D‑Bus API, introduces a system‑level power plugin using deepin‑power‑control for hardware control, enhances low‑power and brightness behavior (including ambient light and short‑idle), and exposes richer battery/power‑mode information over D‑Bus and configuration.

Sequence diagram for short idle activation and system power mode change

sequenceDiagram
    participant IdleWatcher as IdleWatcherX11
    participant PSP as PowerSavePlan
    participant PM as PowerManager
    participant SDP as SessionDBusProxy
    participant SPM as SystemPowerManager
    participant DPC as deepin-power-control

    IdleWatcher->>PSP: idled()
    PSP->>PSP: setShortIdle(true)
    PSP->>PM: setShortIdleState(true)
    PM->>SDP: setShortIdleState(true)
    SDP->>SPM: SetShortIdleState(true)
    SPM->>SPM: applyMode("powersave")
    SPM->>DPC: start("/usr/sbin/deepin-power-control", ["set", mappedDspcMode])
    SPM->>DPC: start("/usr/sbin/deepin-power-control", ["idle", "wifi", "on"])
Loading

File-Level Changes

Change Details Files
Unify session power manager, idle/screen handling, and DConfig persistence across X11 and Wayland, adding short‑idle logic, ambient‑light support, and more robust suspend/wakeup behavior.
  • Refactors PowerManager to use helper persist/resetConfig methods, track loading/applying config keys, and register as a full D‑Bus adaptor (ExportAdaptors).
  • Adds X11 implementations for IdleWatcher and ScreenController, wires them into PowerManager::createIdleWatcher/createScreenController, and exposes UseWayland/short‑idle/idle state setters.
  • Introduces short‑idle delays and policy (LinePowerShortIdleDelay/BatteryShortIdleDelay plus DConfig keys and app/service allow/deny lists) with logic to decide when short idle is allowed and to forward state to the system daemon.
  • Improves suspend/wake flow: audio suspend via pipewire/pactl, better screensaver state capture and restore, DPMS handling, session‑activity checks, and inhibitor/multi‑session awareness for suspend/hibernate/shutdown.
  • Adds ambient‑light integration via SensorProxy (claim/release light, map lux to brightness, lid/session gating) and optional brightness adjustment on screen blackening.
  • Cleans up battery/lid handling (maps presence/percentage/state consistently, tracks time‑to‑empty changes, high‑performance support flag, and lid presence).
  • Reworks scheduled‑shutdown config handling to go through persist(), to recompute next shutdown time only when relevant keys change, and to handle large timer intervals safely.
src/plugin-qt/power/session/powermanager.cpp
src/plugin-qt/power/session/powermanager.h
src/plugin-qt/power/session/idle/idlewatcher.h
src/plugin-qt/power/session/idle/idlewatcher_x11.cpp
src/plugin-qt/power/session/screen/screencontroller.h
src/plugin-qt/power/session/screen/screencontroller_x11.cpp
src/plugin-qt/power/session/lidswitchhandler.cpp
src/plugin-qt/power/session/sleepinhibitor.cpp
src/plugin-qt/power/session/plugin-power-session.cpp
Extend the session power‑save plan to handle short‑idle, power‑saving brightness management, and better X11/Wayland parity for screensaver and brightness behavior.
  • Extends PowerSavePlan::Update/Reset to accept short‑idle delays and optional reset‑from‑now semantics and to reschedule tasks based on current idle time.
  • Adds short‑idle transitions that coordinate with PowerManager and the system daemon, including kernel idle state toggling on X11.
  • Refines idle‑off handling to respect power‑button actions, configurable delays when screen is black, and PS_* prepare/resume states while resetting DPMS and brightness.
  • Implements power‑saving brightness logic that stores per‑output brightness, applies drop/restore based on PowerSavingModeBrightnessDropPercent, and synchronizes shared brightness data via DConfig and system Power1.
  • Improves screen‑black behavior to optionally dim brightness before DPMS off, stop the screensaver, and lock screen depending on configuration and backend (X11 vs Wayland).
src/plugin-qt/power/session/powersaveplan.cpp
src/plugin-qt/power/session/powersaveplan.h
Introduce a system‑level Power1 implementation with multi‑battery support, power‑mode orchestration via deepin‑power‑control, and DConfig‑driven power‑saving behavior.
  • Implements SystemPowerManager as a D‑Bus service with QDBusContext, a richer property set (mode, TlpMode, ShortIdleState, mapping config, power‑saving flags), and automatic PropertiesChanged broadcasting.
  • Adds a BatteryDevice class representing each /sys/class/power_supply battery as a separate D‑Bus object with properties for energy, rate, time‑to‑empty/full, capacity, and status plus change notifications.
  • Reworks BatteryManager to manage a list of BatteryDevice instances, aggregate their state (percentage/status/TTE/TTF/capacity), and emit high‑level updates and onBattery changes based on both mains and battery data.
  • Introduces a queued deepin‑power‑control runner (QProcess + queue) and mapping from logical modes (balance/powersave/performance/lowBattery) to actual DSPC configs, applied on mode changes and short‑idle transitions.
  • Redesigns power‑saving mode flags (enabled/auto/auto‑when‑battery‑low, auto‑battery‑percent, brightness drop, short idle) to persist via DConfig with a background reader, migration from legacy JSON, and central updatePowerMode logic that keeps Mode/PowerSavingMode* in sync.
  • Adds initialization logic to start in performance mode until a display session appears, then switch to configured mode, and exposes battery list, refresh methods, and display‑update signals over D‑Bus.
src/plugin-qt/power/system/powermanager.cpp
src/plugin-qt/power/system/powermanager.h
src/plugin-qt/power/system/batterymanager.cpp
src/plugin-qt/power/system/batterymanager.h
src/plugin-qt/power/system/batterydevice.cpp
src/plugin-qt/power/system/batterydevice.h
src/plugin-qt/power/system/plugin-power-system.cpp
src/plugin-qt/power/system/systemdbusproxy.cpp
src/plugin-qt/power/system/systemdbusproxy.h
Expose low‑power warn‑level configuration as a D‑Bus adaptor and tighten its interaction with session power state and DConfig.
  • Converts LowPowerManager into QDBusAbstractAdaptor on the session PowerManager, defines WarnLevelConfig D‑Bus interface and properties (time thresholds, percentage/action thresholds) with change signals.
  • Adds setters that emit both Qt and D‑Bus property change notifications, recompute warn levels, and optionally reset invalid configurations via a validation timer.
  • Refines warn‑level computation to account for time‑to‑empty, on‑battery state, and 0% firmware glitches, and emits warnLevelChanged back into PowerManager for UI and scheduled‑shutdown coordination.
  • Adds Reset() to restore default warn‑level config keys through DConfig and a helper notifyPropertyChanged() to broadcast individual property changes.
src/plugin-qt/power/session/lowpowermanager.cpp
src/plugin-qt/power/session/lowpowermanager.h
Extend the session D‑Bus proxy to cover more system‑daemon APIs (brightness, short‑idle, sensor, login1) used by the new power logic.
  • Adds methods and signals for brightness (Get/Set/SetAndSave/Refresh and BrightnessChanged) by listening to org.freedesktop.DBus.Properties on the Display1 interface.
  • Exposes short‑idle, idle, and screen‑state setters that call into the daemon, plus RefreshBatteries/RefreshMains on the system Power1 service.
  • Connects to SensorProxy PropertiesChanged and provides accessors for ambient light (HasAmbientLight, LightLevelUnit, LightLevel) along with claimLight/releaseLight wrappers.
  • Adds helpers to query login1 inhibitors and sessions (Inhibitors/ListSessions) and to request shutdown/hibernate via the ShutdownFront interface as well as systemd direct methods.
  • Adjusts the display interface lifetime/parenting and wires in display properties change handling.
src/plugin-qt/power/session/sessiondbusproxy.cpp
src/plugin-qt/power/session/sessiondbusproxy.h
Update power constants, build system, and packaging/install assets to ship the unified Power1 session/system plugins with proper D‑Bus and Polkit configuration.
  • Extends powerconstants.h with new DConfig keys (short idle, screen saver/ambient light, wakeup delays, brightness saving, mapping config) and D‑Bus service/interface names (idle, X11 idle, SensorProxy, DisplayManager).
  • Enables building the system power plugin, links X11/XScreenSaver/DPMS for session, and adjusts install paths to use ${CMAKE_INSTALL_DATADIR} instead of *_FULL variants.
  • Installs new DConfig JSON for org.deepin.dde.daemon.power, the system‑bus D‑Bus service and policy files for org.deepin.dde.Power1, and a Polkit policy file for privileged operations.
  • Removes the obsolete systemd unit install for org.deepin.dde.Power1.service (systemd) in favor of D‑Bus activation and Polkit.
src/plugin-qt/power/powerconstants.h
src/plugin-qt/power/CMakeLists.txt
src/plugin-qt/power/session/CMakeLists.txt
src/plugin-qt/power/system/CMakeLists.txt
src/plugin-qt/power/misc/org.deepin.dde.daemon.power.json
src/plugin-qt/power/system/misc/dbus/org.deepin.dde.Power1.service
src/plugin-qt/power/system/misc/dbus/org.deepin.dde.Power1.conf
src/plugin-qt/power/system/misc/org.deepin.dde.power.policy
debian/control

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

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 1.0.40
EXISTED: no
DISTRIBUTION: unstable

@mhduiy
mhduiy force-pushed the x11power branch 2 times, most recently from 0b1c11f to c767c0a Compare August 17, 2026 10:21
@mhduiy

mhduiy commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

已处理自动评审中的有效项:

  • 旧 JSON 配置现在只迁移实际存在的字段,不再用缺失字段覆盖现有 DConfig 值。
  • ApplicationManager 与 systemd 的短空闲同步查询均限制为 1 秒;该检查只在进入短空闲时执行。
  • 读取 X11 活动窗口 /proc/<pid>/cmdline 前校验进程归属当前会话用户。
  • screenBlackFinishscheduleTask() 加入 m_timersHandleIdleOff() 调用 interruptTasks() 会停止并删除该延迟定时器;此处不存在评审描述的不可取消闭包。

D-Bus 策略保持旧 dde-daemon Power1 的兼容权限:只有 root 可拥有服务,DCC 会话客户端可调用电源模式/电池接口。当前系统 Power1 接口不提供评审所述的 RequestSuspend/RequestShutdown;挂起与关机仍走已有的 session/login1/ShutdownFront 授权路径。将系统 Power1 限制为仅 root 会破坏现有 DCC 调用。

@mhduiy
mhduiy force-pushed the x11power branch 5 times, most recently from 641e775 to f9cea3a Compare August 18, 2026 03:06
1. Unify session Power scheduling across X11 and Wayland backends.
2. Add the system Power1 plugin with battery and power-mode APIs.
3. Preserve legacy idle, screen, brightness, short-idle, and shutdown behavior.
4. Harden legacy configuration migration and X11 process validation.
5. Move Power D-Bus, DConfig, Polkit, and activation assets into dde-services.
6. Require deepin-power-control for system hardware control.

Log: Migrate Power1 ownership while preserving behavior across display backends.
Influence: X11 and Wayland share compatible Power APIs.

feat(power): 迁移电源服务

1. 统一 X11 与 Wayland 的会话电源调度。
2. 新增包含电池与电源模式接口的系统 Power1 插件。
3. 保持旧版空闲、屏幕、亮度、短空闲及关机行为。
4. 加固旧配置迁移和 X11 进程校验。
5. 将电源 D-Bus、DConfig、Polkit 与激活文件迁移至 dde-services。
6. 为系统硬件控制添加 deepin-power-control 依赖。

Log: 迁移 Power1 所有权并保持两种显示后端的兼容行为。
PMS: TASK-394241
Influence: X11 与 Wayland 共用兼容的电源接口。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:42分

■ 【总体评价】

代码成功实现了X11后端支持和系统级电源管理迁移,但存在多个逻辑绕过安全漏洞
逻辑正确但因D-Bus属性伪造和X11属性伪造导致的中低危安全漏洞扣58分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✕

代码整体结构清晰,状态机转换和生命周期管理基本正确,如X11资源在析构函数中释放,DConfig迁移有防丢失验证。但在LowPowerManager::configValid()中,仅校验m_percentageAction < 10,未限制下界(如负数),可能导致异常阈值被接受;PowerManager::isCustomDay()中对QByteArray中字符转为quint8的逻辑虽能工作,但依赖隐式类型转换,可读性较差。
潜在问题:configValid校验不严谨可能接受非法负数阈值;类型转换隐式依赖字节序和符号位
建议:在configValid中增加m_percentageAction >= 0 && m_percentageAction < 10的完整范围校验;在isCustomDay中使用显式的static_cast<unsigned char>并添加注释说明字节值含义

  • 2.代码质量(一般)✕

代码使用了现代C++特性,但存在命名不一致的问题,如D-Bus导出槽函数使用PascalCase(ResetRefresh),而内部私有函数混用camelCase;存在大量硬编码字符串,如shouldPreventIdle中直接使用"org.deepin.ScreenSaver"而非复用PowerDBus::kScreensaver常量;setAudioSuspended中硬编码了脚本路径;部分复杂逻辑(如canEnterShortIdle)缺少注释。
潜在问题:硬编码字符串增加维护成本且易出错;复杂的安全检查逻辑缺少注释导致难以审计
建议:统一使用PowerDBusPowerDConfig命名空间中的常量替换硬编码字符串;为canEnterShortIdleshouldPreventIdle等涉及安全决策的函数添加详细注释说明设计意图和假设

  • 3.代码性能(存在性能问题)✕

在空闲事件处理路径上存在多处主线程阻塞风险。canEnterShortIdle()在每次进入短空闲时同步调用两个D-Bus方法(GetManagedObjectsListUnitsByPatterns),各设置1秒超时,可能导致主线程阻塞2秒;shouldPreventIdle()在每次IdleOn事件时都执行XOpenDisplayXCloseDisplay,X11连接建立开销较大;setAudioSuspended()同步执行多个pactl进程并等待其完成。
潜在问题:主线程阻塞可能导致UI卡顿或响应延迟;频繁的X11连接断开增加系统调用开销
建议:将canEnterShortIdle中的D-Bus调用改为异步方式(如使用QDBusPendingCallWatcher);在shouldPreventIdle中缓存或复用X11 Display连接;将setAudioSuspended中的进程调用移至工作线程或使用后台守护进程

  • 4.代码安全(存在 3 个安全漏洞)✕

漏洞对比统计:新增漏洞 3 个,减少漏洞 0 个,持平 0 个
代码在处理外部输入(D-Bus属性、systemd服务名、X11窗口属性)时缺乏严格的信任边界校验,导致攻击者可以通过伪造这些输入来绕过电源管理的安全策略或发起拒绝服务攻击。

  • 安全漏洞1(中危):[逻辑绕过] 在 [PowerManager::canEnterShortIdle] 中,[通过D-Bus获取org.desktopspec.ApplicationManager1.Application接口的DesktopSourcePath属性,并检查其文件名是否包含deepin/dde/uos字符串。由于该属性由应用自身通过D-Bus提供,恶意应用可伪造该属性(例如将桌面文件命名为fake-deepin-app.desktop),从而绕过第三方应用检查,使系统错误地进入短空闲状态。输入源:D-Bus属性。触发方式:运行伪造了D-Bus属性的恶意应用。危害:绕过安全检查,可能导致未保存数据丢失或异常进入低功耗模式] ——非常重要

  • 安全漏洞2(中危):[逻辑绕过] 在 [PowerManager::canEnterShortIdle] 中,[检查systemd服务是否为第三方服务时,仅通过服务名的前缀(如dde-deepin-uos-等)进行判断。恶意服务只需将其命名为deepin-malware.service即可绕过此检查,使系统错误地认为当前仅运行系统服务,从而允许进入短空闲状态。输入源:systemd服务名。触发方式:安装并启动恶意命名的systemd服务。危害:绕过安全检查,可能导致未保存数据丢失或异常进入低功耗模式] ——非常重要

  • 安全漏洞3(低危):[拒绝服务] 在 [PowerManager::shouldPreventIdle] 中,[通过X11获取当前活动窗口的_NET_WM_PID属性以判断是否为全屏防息屏应用。X11客户端可任意设置该属性,恶意窗口可伪造合法全屏应用的PID,欺骗电源管理器认为当前处于全屏状态,从而持续阻止系统进入空闲、黑屏或休眠。输入源:X11窗口属性。触发方式:运行伪造了_NET_WM_PID的恶意X11窗口。危害:拒绝服务,导致屏幕无法关闭或系统无法休眠,加速电池消耗] ——非常重要

  • 建议:对于漏洞1,应从受信任的本地文件系统路径(如/usr/share/applications)读取并验证.desktop文件的真实路径,而非信任D-Bus上报的属性;对于漏洞2,应将允许的服务列表改为白名单机制,仅允许已知安全的系统服务,而非使用易被伪造的前缀匹配;对于漏洞3,应结合/proc/<pid>/exe符号链接解析出真实的可执行文件路径进行比对,而非信任X11窗口属性中的PID

■ 【改进建议代码示例】

// 修复安全漏洞1:不信任 D-Bus 提供的 DesktopSourcePath,而是通过已知的系统应用白名单严格匹配
// 关联文件:src/plugin-qt/power/session/powermanager.cpp
bool PowerManager::canEnterShortIdle() const
{
    if (m_useWayland)
        return true;

    QDBusInterface applications(QStringLiteral("org.desktopspec.ApplicationManager1"),
                                QStringLiteral("/org/desktopspec/ApplicationManager1"),
                                QStringLiteral("org.desktopspec.DBus.ObjectManager"),
                                QDBusConnection::sessionBus());
    applications.setTimeout(1000);

    const QDBusReply<ObjectMap> managed = applications.call(QStringLiteral("GetManagedObjects"));
    if (!managed.isValid()) {
        qWarning(logPowerSession) << "Failed to list launched applications:"
                                  << managed.error().message();
        return false;
    }

    for (const ObjectInterfaceMap &interfaces : managed.value()) {
        const QVariantMap properties = interfaces.value(
            QStringLiteral("org.desktopspec.ApplicationManager1.Application"));
        if (properties.isEmpty()
            || qdbus_cast<QList<QDBusObjectPath>>(
                   properties.value(QStringLiteral("Instances"))).isEmpty())
            continue;

        const QString desktop = QFileInfo(
            properties.value(QStringLiteral("DesktopSourcePath")).toString()).fileName();

        if (m_shortIdleBlacklistApplications.contains(desktop)) {
            qInfo(logPowerSession) << "Short idle blocked by blacklisted application:" << desktop;
            return false;
        }

        // 修复:仅允许严格存在于系统白名单中的应用,移除不安全的关键词包含检查
        if (!m_systemApplications.contains(desktop)) {
            qInfo(logPowerSession) << "Short idle blocked by non-whitelisted application:" << desktop;
            return false;
        }
    }

    // ... (systemd 服务检查同理,应改为严格白名单机制)
    return true;
}

// 修复安全漏洞3:通过 /proc/<pid>/exe 验证真实的可执行文件路径
// 关联文件:src/plugin-qt/power/session/powermanager.cpp
#include <unistd.h>

bool PowerManager::shouldPreventIdle() const
{
    if (m_useWayland || m_fullscreenWorkaroundApplications.isEmpty())
        return false;
    Display *display = XOpenDisplay(nullptr);
    if (!display)
        return false;
    // ... (获取 active 和 fullscreen 状态的逻辑保持不变) ...

    unsigned long pid = 0;
    if (fullscreen && property(active, pidAtom, XA_CARDINAL, 1, &data, &count) && data && count)
        pid = *reinterpret_cast<unsigned long *>(data);
    if (data) XFree(data);
    XCloseDisplay(display);
    
    // 增加 PID 范围校验防止构造异常路径
    if (!pid || pid > static_cast<unsigned long>(sysconf(_SC_PID_MAX)))
        return false;

    if (QFileInfo(QStringLiteral("/proc/%1").arg(pid)).ownerId() != ::geteuid())
        return false;

    // 修复:读取 /proc/<pid>/exe 的真实路径,避免信任 X11 窗口属性
    QString exePath = QFile::symLinkTarget(QStringLiteral("/proc/%1/exe").arg(pid));
    if (exePath.isEmpty())
        return false;

    return std::any_of(m_fullscreenWorkaroundApplications.cbegin(),
                       m_fullscreenWorkaroundApplications.cend(),
                       [&exePath](const QString &app) { return exePath.contains(app); });
}

@deepin-ci-robot

Copy link
Copy Markdown

@mhduiy: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
github-pr-review-ci a39a041 link true /test github-pr-review-ci

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.40
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #154

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.41
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #155

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