feat(power): migrate power services - #146
Conversation
There was a problem hiding this comment.
Sorry @mhduiy, your pull request is larger than the review limit of 150000 diff characters
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideRefactors 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 changesequenceDiagram
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"])
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
TAG Bot TAG: 1.0.40 |
0b1c11f to
c767c0a
Compare
|
已处理自动评审中的有效项:
D-Bus 策略保持旧 |
641e775 to
f9cea3a
Compare
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 pr auto review★ 总体评分:42分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 修复安全漏洞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); });
} |
|
@mhduiy: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
|
TAG Bot New tag: 1.0.40 |
|
TAG Bot New tag: 1.0.41 |
Log: Migrate Power1 ownership while preserving behavior across both display backends.
Influence: X11 and Wayland share compatible Power APIs.
feat(power): 迁移电源服务
Log: 迁移 Power1 所有权并保持两种显示后端的兼容行为。
PMS: TASK-394241
Influence: X11 与 Wayland 共用兼容的电源接口。
Validation:
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:
Bug Fixes:
Enhancements:
Build:
Deployment:
Tests: