Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/dde-lock/lockworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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状态不对
Expand Down
4 changes: 0 additions & 4 deletions src/global_util/dbusconstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
55 changes: 46 additions & 9 deletions src/session-widgets/authinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
10 changes: 5 additions & 5 deletions src/session-widgets/authinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@

#ifndef ENABLE_DSS_SNIPE
#include <com_deepin_daemon_accounts.h>
#include <com_deepin_daemon_logined.h>

Check warning on line 14 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <com_deepin_daemon_logined.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <com_deepin_daemon_authenticate.h>

Check warning on line 15 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <com_deepin_daemon_authenticate.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <org_freedesktop_login1_session_self.h>

Check warning on line 16 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <org_freedesktop_login1_session_self.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <com_deepin_daemon_powermanager.h>
#include <org_freedesktop_dbus.h>

Check warning on line 17 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <org_freedesktop_dbus.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QGSettings>

Check warning on line 18 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#else
#include "authenticate1interface.h"

Check warning on line 20 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "authenticate1interface.h" not found.
#include "accounts1interface.h"

Check warning on line 21 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "accounts1interface.h" not found.
#include "loginedinterface.h"

Check warning on line 22 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "loginedinterface.h" not found.
#include "powermanager1interface.h"
#include "dbusinterface.h"

Check warning on line 23 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dbusinterface.h" not found.
#include "selfinterface.h"

Check warning on line 24 in src/session-widgets/authinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "selfinterface.h" not found.
#include <DConfig>
#endif

Expand All @@ -34,15 +32,13 @@
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;
#else
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;
Expand Down Expand Up @@ -96,13 +92,16 @@
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;
Expand All @@ -112,6 +111,7 @@
uint m_lastLogoutUid;
uint m_currentUserUid;
std::list<uint> m_loginUserList;
bool m_isVM;
};
} // namespace Auth

Expand Down
15 changes: 0 additions & 15 deletions xml/snipe/org.deepin.dde.PowerManager1.xml

This file was deleted.

Loading