Skip to content

Conversation

@fly602
Copy link
Contributor

@fly602 fly602 commented Oct 31, 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. 验证锁屏电源管理功能没有回归问题

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. 验证锁屏电源管理功能没有回归问题
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @fly602, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602

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

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

我来对这个代码变更进行审查。这个变更主要是移除了PowerManager相关的DBus接口,改用login1接口来处理电源管理功能。

  1. 代码逻辑和架构改进:
  • 优点:
    • 简化了电源管理接口,统一使用标准的login1接口,减少了依赖
    • 添加了虚拟机检测功能,避免在虚拟机环境中进行休眠等操作
    • 电源状态检查更加直接和可靠,直接读取/sys/power/mem_sleep文件
  1. 代码质量改进:
  • 建议:
    • 在detectVirtualMachine()函数中,建议增加对systemd-detect-virt命令存在性的检查
    • canSuspend()和canHibernate()函数中的环境变量检查可以考虑使用qgetenv()替代getenv(),这样更符合Qt的编程风格
  1. 性能优化:
  • 建议:
    • detectVirtualMachine()结果被存储在m_isVM中,这是好的做法,避免了重复检测
    • 可以考虑在AuthInterface构造函数中缓存canSuspend和canHibernate的结果,避免频繁的DBus调用
  1. 安全性改进:
  • 优点:
    • 增加了对虚拟机环境的检测,避免在不合适的环境中进行电源操作
    • 直接检查系统文件(/sys/power/mem_sleep)比依赖DBus接口更可靠
  1. 具体建议的代码修改:
bool AuthInterface::detectVirtualMachine() {
    // 检查命令是否存在
    if (!QFile::exists("/usr/bin/systemd-detect-virt")) {
        qWarning() << "systemd-detect-virt command not found";
        return false;
    }
    
    QProcess process;
    process.start("/usr/bin/systemd-detect-virt", QStringList());
    if (!process.waitForFinished(1000)) { // 设置超时时间
        qWarning() << "Failed to detect virtual machine, timeout or error:" << process.errorString();
        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();
}

bool AuthInterface::canSuspend()
{
    if (qgetenv("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";
}

bool AuthInterface::canHibernate()
{
    if (qgetenv("POWER_CAN_SLEEP") == "0" || m_isVM)
        return false;
    
    QString canHibernate = m_login1Inter->CanHibernate();
    return canHibernate == "yes";
}
  1. 其他建议:
  • 考虑添加错误处理机制,当DBus调用失败时提供适当的回退方案
  • 可以添加日志记录,方便调试和问题追踪
  • 建议为新增的函数添加详细的文档注释

总的来说,这次变更是一个好的改进,简化了代码结构,提高了可靠性,但还可以在错误处理和性能优化方面做一些改进。

@fly602 fly602 closed this Nov 4, 2025
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