Skip to content

feat: support device idle power saving flag - #218

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
52cyb:master
Nov 19, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
52cyb:master

Conversation

@52cyb

@52cyb 52cyb commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor
  1. Add DeviceIdlePowerSaving property backed by the power DConfig key.
  2. Persist the flag and append --dev-idle when replaying the mode command.
  3. Keep the last DSPC mode so toggling only adds or removes --dev-idle.
  4. Load the flag at startup and apply it once via initializePowerMode.

Log: Add system-side state and CLI support for device idle power saving

Influence:

  1. Toggle DeviceIdlePowerSaving via busctl and verify the property and DConfig value change.
  2. Verify the mode command carries --dev-idle when on and omits it when off.
  3. Restart Power1 and verify the flag is restored and applied only once at startup.
  4. Switch power mode or trigger low battery while enabled and verify --dev-idle is kept.
  5. Confirm the installed deepin-power-control version supports --dev-idle.

feat: 支持设备空闲省电配置

  1. 新增 DeviceIdlePowerSaving 属性,状态持久化到电源 DConfig。
  2. 下发模式命令时根据开关追加或移除 --dev-idle。
  3. 记录最近一次下发的 DSPC 模式,切换开关时原样重放而不重新解析。
  4. 启动时加载该配置,并由 initializePowerMode 统一下发一次。

Log: 为设备空闲省电增加系统侧状态与命令下发支持

Influence:

  1. 通过 busctl 切换 DeviceIdlePowerSaving,确认属性与 DConfig 值同步更新。
  2. 确认开启时命令携带 --dev-idle,关闭时恢复为不带该参数。
  3. 重启 Power1,确认开关状态恢复且仅在启动初始化时下发一次。
  4. 开启后切换性能模式或触发低电量,确认命令仍携带 --dev-idle。
  5. 确认安装的 deepin-power-control 版本支持 --dev-idle。

PMS: TASK-394399

Summary by Sourcery

Add persistent device idle power-saving state and integrate it with power-mode command execution.

New Features:

  • Expose a system power property for configuring device idle power saving and persist its value in power DConfig.
  • Propagate the device idle power-saving setting to power-mode commands through the --dev-idle option.

Enhancements:

  • Restore the setting at startup and reapply the most recently selected power mode when the setting changes without reinterpreting the mode.

Build:

  • Update the package dependency to a deepin-power-control version that supports device idle power saving.

@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose DeviceIdlePowerSaving through the D-Bus interface, including its getter, setter, and change signal.

  • src/plugin-qt/power/misc/org.deepin.dde.daemon.power.json L87-98
  • src/plugin-qt/power/system/powermanager.h L40-147 (4 small edits)

Implementation

Load and persist the device-idle setting, retain the last DSPC mode, and replay it with the appropriate option when the setting changes.

  • src/plugin-qt/power/powerconstants.h L55
  • src/plugin-qt/power/system/powermanager.cpp L865-876, L1103-1120 (+2 small edits)
  • src/plugin-qt/power/system/powermanager.h L163, L203-207

Configuration

Update package dependency metadata for the power-control CLI option used by the new feature.

  • debian/control L53

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

@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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/plugin-qt/power/system/powermanager.cpp" line_range="1109" />
<code_context>
+    if (m_deviceIdlePowerSaving == enabled)
+        return;
+
+    if (!m_loadingConfig && !authorizePowerAction())
+        return;
+
</code_context>
<issue_to_address>
**DConfig writes bypass authorization**

When a local process able to write the public DConfig key changes its value, an unprivileged local process writes the new global, public, readwrite DConfig key; the `valueChanged` handler calls `SetDeviceIdlePowerSaving` outside a D-Bus invocation, so `authorizePowerAction()` accepts it and the daemon enqueues the mode command without Polkit authorization.

Restrict writes to this global key to an authorized path, or require an explicit authorization check before applying externally initiated DConfig changes.
</issue_to_address>

### Comment 2
<location path="src/plugin-qt/power/system/powermanager.cpp" line_range="557" />
<code_context>
         else if (key == QLatin1String(kPowerSavingModeAutoBatteryPercent))
             setPowerSavingModeAutoBatteryPercent(value.toUInt());
+        else if (key == QLatin1String(kDeviceIdlePowerSaving))
+            SetDeviceIdlePowerSaving(value.toBool());
         else if (key == QLatin1String(kShortIdleEnable))
             m_shortIdleEnabled = value.toBool();
</code_context>
<issue_to_address>
**Older config read reverses newer toggle**

When an older DConfig read has been queued for application and a newer bus setter completes before that callback runs, the queued DConfig callback calls `SetDeviceIdlePowerSaving(true)` after a newer bus setter has persisted `false`; the stale callback then persists `true` and queues an enabled mode command, reverting the caller’s latest setting.

Re-read or version-check the DConfig value immediately before applying queued callbacks so stale reads cannot overwrite newer updates.
</issue_to_address>

### Comment 3
<location path="src/plugin-qt/power/system/powermanager.cpp" line_range="876" />
<code_context>
+    if (m_deviceIdlePowerSaving)
+        args << QStringLiteral("--dev-idle");
+
+    enqueuePowerControl(args);
 }

</code_context>
<issue_to_address>
**Enabled setting is never applied**

When the installed power-control binary rejects `--dev-idle` or the command otherwise exits unsuccessfully, `enqueueModeCommand` queues the flag-bearing command, but the process-finished handler only logs a nonzero exit and advances the queue. The property and DConfig value remain enabled even though the power-control mode was not applied, so callers see the setting on without its effect.

Handle a failed flag-bearing command by retrying or surfacing the failure and keeping the reported and persisted setting consistent with the applied state.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@52cyb
52cyb force-pushed the master branch 3 times, most recently from c767e85 to 1e8a51f Compare November 16, 2026 02:40
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为新增"设备空闲省电"功能开关,涉及 DConfig 配置项、Q_PROPERTY 属性、 DConfig 变更监听、授权校验及模式下发重构。代码遵循已有模式(如 SetShortIdleState), 授权检查完善,重构合理(将 applyMode 中的下发逻辑抽取为 enqueueModeCommand 复用), 四维度均无缺陷,无安全漏洞。OCR 因本地代码仓库克隆失败未产出有效结果,不影响审查结论。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

本次变更无需修复,代码已符合规范。以下为已有的良好实践示范(SetDeviceIdlePowerSaving 方法):
void SystemPowerManager::SetDeviceIdlePowerSaving(bool enabled) {
    // 幂等守卫:值未变化时直接返回
    if (m_deviceIdlePowerSaving == enabled)
        return;

    // 授权校验:加载阶段跳过
    if (!m_loadingConfig && !authorizePowerAction())
        return;

    m_deviceIdlePowerSaving = enabled;
    Q_EMIT deviceIdlePowerSavingChanged();
    persist(kDeviceIdlePowerSaving, enabled);

    // 启动加载时模式尚未应用,跳过本次下发
    if (!m_loadingConfig)
        enqueueModeCommand();
}

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

1. Add DeviceIdlePowerSaving property backed by the power DConfig key.
2. Persist the flag and append --dev-idle when replaying the mode command.
3. Keep the last DSPC mode so toggling only adds or removes --dev-idle.
4. Load the flag at startup and apply it once via initializePowerMode.

Log: Add system-side state and CLI support for device idle power saving

Influence:
1. Toggle DeviceIdlePowerSaving via busctl and verify the property and DConfig value change.
2. Verify the mode command carries --dev-idle when on and omits it when off.
3. Restart Power1 and verify the flag is restored and applied only once at startup.
4. Switch power mode or trigger low battery while enabled and verify --dev-idle is kept.
5. Confirm the installed deepin-power-control version supports --dev-idle.

feat: 支持设备空闲省电配置

1. 新增 DeviceIdlePowerSaving 属性,状态持久化到电源 DConfig。
2. 下发模式命令时根据开关追加或移除 --dev-idle。
3. 记录最近一次下发的 DSPC 模式,切换开关时原样重放而不重新解析。
4. 启动时加载该配置,并由 initializePowerMode 统一下发一次。

Influence:
1. 通过 busctl 切换 DeviceIdlePowerSaving,确认属性与 DConfig 值同步更新。
2. 确认开启时命令携带 --dev-idle,关闭时恢复为不带该参数。
3. 重启 Power1,确认开关状态恢复且仅在启动初始化时下发一次。
4. 开启后切换性能模式或触发低电量,确认命令仍携带 --dev-idle。
5. 确认安装的 deepin-power-control 版本支持 --dev-idle。

Log: 为设备空闲省电增加系统侧状态与命令下发支持
PMS: TASK-394399
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 52cyb, robertkill

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

@52cyb

52cyb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit fbab7a9 into linuxdeepin:master Nov 19, 2026
8 of 10 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