diff --git a/CMakeLists.txt b/CMakeLists.txt index 903028dc..8832348e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,7 +184,6 @@ if (NOT DISABLE_DSS_SNIPE) "${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.Accounts1.User.xml userinterface" "${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.ImageEffect1.xml imageeffect1interface" "${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.Logined.xml loginedinterface" - "${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.PowerManager1.xml powermanager1interface" "${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.SystemPower1.xml systempower1interface" "${CMAKE_SOURCE_DIR}/xml/snipe/com.deepin.wm.xml wminterface" "${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.Authenticate1.Session2.xml session2interface" diff --git a/src/dde-lock/lockworker.cpp b/src/dde-lock/lockworker.cpp index 7ce5e463..b6925a91 100644 --- a/src/dde-lock/lockworker.cpp +++ b/src/dde-lock/lockworker.cpp @@ -559,7 +559,7 @@ void LockWorker::doPowerAction(const SessionBaseModel::PowerAction action) if (delayTime < 0) { delayTime = 500; } - if (m_powerManagerInter->CanHibernate()){ + if (canHibernate()){ WarningContent::instance()->tryGrabKeyboard(); QTimer::singleShot(delayTime, this, [=] { // 待机休眠前设置Locked为true,避免刚唤醒时locked状态不对 diff --git a/src/global_util/dbusconstant.h b/src/global_util/dbusconstant.h index 2a23588c..6dc1912e 100644 --- a/src/global_util/dbusconstant.h +++ b/src/global_util/dbusconstant.h @@ -15,8 +15,6 @@ namespace DSS_DBUS { const QString accountsUserPath = "/com/deepin/daemon/Accounts/User%1"; const QString accountsUserInterface = "com.deepin.daemon.Accounts.User"; const QString loginedPath = "/com/deepin/daemon/Logined"; - const QString powerManagerService = "com.deepin.daemon.PowerManager"; - const QString powerManagerPath = "/com/deepin/daemon/PowerManager"; const QString powerService = "com.deepin.system.Power"; const QString powerPath = "/com/deepin/system/Power"; const QString sessionPowerService = "com.deepin.daemon.Power"; @@ -62,8 +60,6 @@ namespace DSS_DBUS { const QString accountsUserPath = "/org/deepin/dde/Accounts1/User%1"; const QString accountsUserInterface = "org.deepin.dde.Accounts1.User"; const QString loginedPath = "/org/deepin/dde/Logined"; - const QString powerManagerService = "org.deepin.dde.PowerManager1"; - const QString powerManagerPath = "/org/deepin/dde/PowerManager1"; const QString powerService = "org.deepin.dde.Power1"; const QString powerPath = "/org/deepin/dde/Power1"; const QString sessionPowerService = "org.deepin.dde.Power1"; diff --git a/src/session-widgets/authinterface.cpp b/src/session-widgets/authinterface.cpp index 5d9deeee..72a530be 100644 --- a/src/session-widgets/authinterface.cpp +++ b/src/session-widgets/authinterface.cpp @@ -21,11 +21,11 @@ AuthInterface::AuthInterface(SessionBaseModel *const model, QObject *parent) , m_accountsInter(new AccountsInter(DSS_DBUS::accountsService, DSS_DBUS::accountsPath, QDBusConnection::systemBus(), this)) , m_loginedInter(new LoginedInter(DSS_DBUS::accountsService, DSS_DBUS::loginedPath, QDBusConnection::systemBus(), this)) , m_login1Inter(new DBusLogin1Manager("org.freedesktop.login1", "/org/freedesktop/login1", QDBusConnection::systemBus(), this)) - , m_powerManagerInter(new PowerManagerInter(DSS_DBUS::powerManagerService, DSS_DBUS::powerManagerPath, QDBusConnection::systemBus(), this)) , m_dbusInter(new DBusObjectInter("org.freedesktop.DBus", "/org/freedesktop/DBus", QDBusConnection::systemBus(), this)) , m_lastLogoutUid(0) , m_currentUserUid(0) , m_loginUserList(0) + , m_isVM(detectVirtualMachine()) { #ifndef ENABLE_DSS_SNIPE // 需要先初始化m_gsettings @@ -241,15 +241,11 @@ void AuthInterface::checkPowerInfo() // 替换接口org.freedesktop.login1 为com.deepin.sessionManager,原接口的是否支持待机和休眠的信息不准确 QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); #ifndef ENABLE_DSS_SNIPE - bool can_sleep = env.contains(POWER_CAN_SLEEP) ? QVariant(env.value(POWER_CAN_SLEEP)).toBool() - : getGSettings("Power","sleep").toBool() && m_powerManagerInter->CanSuspend(); - bool can_hibernate = env.contains(POWER_CAN_HIBERNATE) ? QVariant(env.value(POWER_CAN_HIBERNATE)).toBool() - : getGSettings("Power","hibernate").toBool() && m_powerManagerInter->CanHibernate(); + bool can_sleep = getGSettings("Power","sleep").toBool() && canSuspend(); + bool can_hibernate = getGSettings("Power","hibernate").toBool() && canHibernate(); #else - bool can_sleep = env.contains(POWER_CAN_SLEEP) ? QVariant(env.value(POWER_CAN_SLEEP)).toBool() - : getDconfigValue("sleep", true).toBool() && m_powerManagerInter->CanSuspend(); - bool can_hibernate = env.contains(POWER_CAN_HIBERNATE) ? QVariant(env.value(POWER_CAN_HIBERNATE)).toBool() - : getDconfigValue("hibernate", true).toBool() && m_powerManagerInter->CanHibernate(); + bool can_sleep = getDconfigValue("sleep", true).toBool() && canSuspend(); + bool can_hibernate = getDconfigValue("hibernate", true).toBool() && canHibernate(); #endif m_model->setCanSleep(can_sleep); @@ -261,3 +257,44 @@ bool AuthInterface::checkIsADDomain() //只有加入AD域后,才会生成此文件 return QFile::exists("/etc/krb5.keytab"); } + +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"; +} + +bool AuthInterface::canHibernate() +{ + if (QString(getenv("POWER_CAN_HIBERNATE")) == "0" || m_isVM) + return false; + + QString canHibernate = m_login1Inter->CanHibernate(); + return canHibernate == "yes"; +} + +bool AuthInterface::detectVirtualMachine() +{ + QProcess process; + process.start("/usr/bin/systemd-detect-virt", QStringList()); + // 添加超时限制,例如 3000ms + 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(); +} \ No newline at end of file diff --git a/src/session-widgets/authinterface.h b/src/session-widgets/authinterface.h index 53e68a88..f9472bf6 100644 --- a/src/session-widgets/authinterface.h +++ b/src/session-widgets/authinterface.h @@ -14,14 +14,12 @@ #include #include #include -#include #include #include #else #include "authenticate1interface.h" #include "accounts1interface.h" #include "loginedinterface.h" -#include "powermanager1interface.h" #include "dbusinterface.h" #include "selfinterface.h" #include @@ -34,7 +32,6 @@ using AccountsInter = com::deepin::daemon::Accounts; using LoginedInter = com::deepin::daemon::Logined; using Login1SessionSelf = org::freedesktop::login1::Session; -using PowerManagerInter = com::deepin::daemon::PowerManager; using DBusObjectInter = org::freedesktop::DBus; using com::deepin::daemon::Authenticate; @@ -42,7 +39,6 @@ using com::deepin::daemon::Authenticate; using AccountsInter = org::deepin::dde::Accounts1; using LoginedInter = org::deepin::dde::Logined; using Login1SessionSelf = org::freedesktop::login1::Session; -using PowerManagerInter = org::deepin::dde::PowerManager1; using DBusObjectInter = org::freedesktop::DBus; using Authenticate = org::deepin::dde::Authenticate1; @@ -96,13 +92,16 @@ class AuthInterface : public QObject { failback); } + bool canSuspend(); + bool canHibernate(); + bool detectVirtualMachine(); + protected: SessionBaseModel* m_model; AccountsInter * m_accountsInter; LoginedInter* m_loginedInter; DBusLogin1Manager* m_login1Inter; Login1SessionSelf* m_login1SessionSelf = nullptr; - PowerManagerInter* m_powerManagerInter; DBusObjectInter* m_dbusInter; #ifndef ENABLE_DSS_SNIPE QGSettings* m_gsettings = nullptr; @@ -112,6 +111,7 @@ class AuthInterface : public QObject { uint m_lastLogoutUid; uint m_currentUserUid; std::list m_loginUserList; + bool m_isVM; }; } // namespace Auth diff --git a/xml/snipe/org.deepin.dde.PowerManager1.xml b/xml/snipe/org.deepin.dde.PowerManager1.xml deleted file mode 100644 index 3a7632e0..00000000 --- a/xml/snipe/org.deepin.dde.PowerManager1.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - -