Skip to content

Conversation

@fly602
Copy link
Contributor

@fly602 fly602 commented Nov 4, 2025

  1. Removed PowerManager D-Bus interface dependency from the authentication system
  2. Replaced PowerManager calls with direct login1 D-Bus interface calls for power management
  3. Added local power capability detection methods (canSuspend/ canHibernate) that check system files and login1 interface
  4. Implemented virtual machine detection to disable power features in VM environments
  5. Removed all PowerManager related XML definitions, adaptors, and constants
  6. Simplified power info checking logic by removing environment variable fallbacks

This change eliminates the dependency on the deprecated PowerManager service and uses the standard login1 interface directly, making the code more maintainable and reducing external dependencies.

Influence:

  1. Test suspend/hibernate functionality on physical machines
  2. Verify power options are disabled in virtual machine environments
  3. Test power actions with different system configurations
  4. Ensure power state detection works correctly with login1 interface
  5. Verify no regression in lock screen power management features

重构:移除 PowerManager 接口依赖

  1. 从认证系统中移除了 PowerManager D-Bus 接口依赖
  2. 将 PowerManager 调用替换为直接的 login1 D-Bus 接口调用进行电源管理
  3. 添加了本地电源能力检测方法(canSuspend/canHibernate),检查系统文件和 login1 接口
  4. 实现了虚拟机检测功能,在虚拟环境中禁用电源功能
  5. 移除了所有与 PowerManager 相关的 XML 定义、适配器和常量
  6. 通过移除环境变量回退简化了电源信息检查逻辑

此更改消除了对已弃用的 PowerManager 服务的依赖,直接使用标准的 login1 接
口,使代码更易于维护并减少外部依赖。

影响:

  1. 在物理机上测试挂起/休眠功能
  2. 验证虚拟环境中电源选项被禁用
  3. 使用不同系统配置测试电源操作
  4. 确保通过 login1 接口的电源状态检测正常工作
  5. 验证锁屏电源管理功能没有回归问题

deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Nov 4, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#50
@fly602 fly602 requested a review from yixinshark November 4, 2025 06:00
return canHibernate == "yes";
}

bool AuthInterface::detectVirtualMachine() {
Copy link
Contributor

Choose a reason for hiding this comment

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

大括号换行

deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Nov 4, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#50
deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Nov 4, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#50
deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Nov 4, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#50
1. Removed PowerManager D-Bus interface dependency from the
authentication system
2. Replaced PowerManager calls with direct login1 D-Bus interface calls
for power management
3. Added local power capability detection methods (canSuspend/
canHibernate) that check system files and login1 interface
4. Implemented virtual machine detection to disable power features in
VM environments
5. Removed all PowerManager related XML definitions, adaptors, and
constants
6. Simplified power info checking logic by removing environment variable
fallbacks

This change eliminates the dependency on the deprecated PowerManager
service and uses the standard login1 interface directly, making the code
more maintainable and reducing external dependencies.

Influence:
1. Test suspend/hibernate functionality on physical machines
2. Verify power options are disabled in virtual machine environments
3. Test power actions with different system configurations
4. Ensure power state detection works correctly with login1 interface
5. Verify no regression in lock screen power management features

重构:移除 PowerManager 接口依赖

1. 从认证系统中移除了 PowerManager D-Bus 接口依赖
2. 将 PowerManager 调用替换为直接的 login1 D-Bus 接口调用进行电源管理
3. 添加了本地电源能力检测方法(canSuspend/canHibernate),检查系统文件和
login1 接口
4. 实现了虚拟机检测功能,在虚拟环境中禁用电源功能
5. 移除了所有与 PowerManager 相关的 XML 定义、适配器和常量
6. 通过移除环境变量回退简化了电源信息检查逻辑

此更改消除了对已弃用的 PowerManager 服务的依赖,直接使用标准的 login1 接
口,使代码更易于维护并减少外部依赖。

影响:
1. 在物理机上测试挂起/休眠功能
2. 验证虚拟环境中电源选项被禁用
3. 使用不同系统配置测试电源操作
4. 确保通过 login1 接口的电源状态检测正常工作
5. 验证锁屏电源管理功能没有回归问题
deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Nov 4, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#50
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码变更进行审查:

  1. 主要变更内容:
  • 移除了PowerManager1相关的DBus接口定义和使用
  • 将电源管理功能转移到使用login1接口
  • 增加了虚拟机检测功能
  • 优化了休眠和待机状态的检测逻辑
  1. 代码质量改进建议:

a) 虚拟机检测部分:

bool AuthInterface::detectVirtualMachine()
{
    QProcess process;
    process.start("/usr/bin/systemd-detect-virt", QStringList());
    if (!process.waitForFinished(3000)) {
        qWarning() << "Timeout detecting virtual machine";
        return false;
    }
    
    if (process.exitCode() != 0) {
        qWarning() << "Failed to detect virtual machine, error:" << process.errorString();
        return false;
    }
    
    QString name = QString::fromUtf8(process.readAllStandardOutput()).trimmed();
    return name != "none" && !name.isEmpty();
}

建议改进:

  • 添加进程启动失败的检查
  • 考虑将超时时间作为配置项
  • 添加对systemd-detect-virt命令存在性的检查

b) 电源状态检测部分:

bool AuthInterface::canSuspend()
{
    if (QString(getenv("POWER_CAN_SLEEP")) == "0" || m_isVM)
        return false; 

    if (!QFile::exists("/sys/power/mem_sleep"))
        return false;
    
    QString canSuspend = m_login1Inter->CanSuspend();
    return canSuspend == "yes";
}

建议改进:

  • 添加对DBus接口调用失败的处理
  • 考虑添加对/sys/power/state文件的检查
  • 建议使用更严格的字符串比较(如QString::compare)
  1. 性能优化建议:
  • 虚拟机检测结果应该缓存,避免重复检测
  • 电源状态检测可以考虑缓存结果,并监听相关信号更新
  • 文件存在性检查可以使用QFileInfo代替QFile
  1. 安全性建议:
  • 检查环境变量时应该考虑大小写
  • 对systemd-detect-virt的输出进行更严格的验证
  • 添加对DBus接口调用的权限检查
  1. 其他建议:
  • 建议添加更多的错误日志
  • 考虑添加单元测试
  • 建议将超时时间等常量定义为宏或配置项
  • 可以考虑使用QProcess::execute替代start/waitForFinished组合
  1. 代码结构建议:
  • 将虚拟机检测和电源状态检测相关的代码抽取为单独的工具类
  • 考虑使用策略模式处理不同场景下的电源管理
  • 建议添加更多的注释说明检测逻辑

这些变更总体上是好的,移除了不必要的依赖,简化了代码结构,但在错误处理和健壮性方面还有改进空间。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, yixinshark

The full list of commands accepted by this bot can be found here.

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

@fly602 fly602 merged commit 1fabba7 into linuxdeepin:master Nov 4, 2025
14 of 15 checks passed
fly602 pushed a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Nov 4, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#50
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