Repository navigation
feat: support device idle power saving flag - #218
Conversation
Reviewer's GuideAPIExpose DeviceIdlePowerSaving through the D-Bus interface, including its getter, setter, and change signal.
ImplementationLoad and persist the device-idle setting, retain the last DSPC mode, and replay it with the appropriate option when the setting changes.
ConfigurationUpdate package dependency metadata for the power-control CLI option used by the new feature.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>c767e85 to
1e8a51f
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在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
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Log: Add system-side state and CLI support for device idle power saving
Influence:
feat: 支持设备空闲省电配置
Log: 为设备空闲省电增加系统侧状态与命令下发支持
Influence:
PMS: TASK-394399
Summary by Sourcery
Add persistent device idle power-saving state and integrate it with power-mode command execution.
New Features:
Enhancements:
Build: