Skip to content

Commit cae4aa0

Browse files
deepin-ci-robotfly602
authored andcommitted
sync: from linuxdeepin/dde-session-shell
Synchronize source files from linuxdeepin/dde-session-shell. Source-pull-request: linuxdeepin/dde-session-shell#50
1 parent 84252d4 commit cae4aa0

File tree

6 files changed

+52
-35
lines changed

6 files changed

+52
-35
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ if (NOT DISABLE_DSS_SNIPE)
184184
"${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.Accounts1.User.xml userinterface"
185185
"${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.ImageEffect1.xml imageeffect1interface"
186186
"${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.Logined.xml loginedinterface"
187-
"${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.PowerManager1.xml powermanager1interface"
188187
"${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.SystemPower1.xml systempower1interface"
189188
"${CMAKE_SOURCE_DIR}/xml/snipe/com.deepin.wm.xml wminterface"
190189
"${CMAKE_SOURCE_DIR}/xml/snipe/org.deepin.dde.Authenticate1.Session2.xml session2interface"

src/dde-lock/lockworker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void LockWorker::doPowerAction(const SessionBaseModel::PowerAction action)
559559
if (delayTime < 0) {
560560
delayTime = 500;
561561
}
562-
if (m_powerManagerInter->CanHibernate()){
562+
if (canHibernate()){
563563
WarningContent::instance()->tryGrabKeyboard();
564564
QTimer::singleShot(delayTime, this, [=] {
565565
// 待机休眠前设置Locked为true,避免刚唤醒时locked状态不对

src/global_util/dbusconstant.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ namespace DSS_DBUS {
1515
const QString accountsUserPath = "/com/deepin/daemon/Accounts/User%1";
1616
const QString accountsUserInterface = "com.deepin.daemon.Accounts.User";
1717
const QString loginedPath = "/com/deepin/daemon/Logined";
18-
const QString powerManagerService = "com.deepin.daemon.PowerManager";
19-
const QString powerManagerPath = "/com/deepin/daemon/PowerManager";
2018
const QString powerService = "com.deepin.system.Power";
2119
const QString powerPath = "/com/deepin/system/Power";
2220
const QString sessionPowerService = "com.deepin.daemon.Power";
@@ -62,8 +60,6 @@ namespace DSS_DBUS {
6260
const QString accountsUserPath = "/org/deepin/dde/Accounts1/User%1";
6361
const QString accountsUserInterface = "org.deepin.dde.Accounts1.User";
6462
const QString loginedPath = "/org/deepin/dde/Logined";
65-
const QString powerManagerService = "org.deepin.dde.PowerManager1";
66-
const QString powerManagerPath = "/org/deepin/dde/PowerManager1";
6763
const QString powerService = "org.deepin.dde.Power1";
6864
const QString powerPath = "/org/deepin/dde/Power1";
6965
const QString sessionPowerService = "org.deepin.dde.Power1";

src/session-widgets/authinterface.cpp

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ AuthInterface::AuthInterface(SessionBaseModel *const model, QObject *parent)
2121
, m_accountsInter(new AccountsInter(DSS_DBUS::accountsService, DSS_DBUS::accountsPath, QDBusConnection::systemBus(), this))
2222
, m_loginedInter(new LoginedInter(DSS_DBUS::accountsService, DSS_DBUS::loginedPath, QDBusConnection::systemBus(), this))
2323
, m_login1Inter(new DBusLogin1Manager("org.freedesktop.login1", "/org/freedesktop/login1", QDBusConnection::systemBus(), this))
24-
, m_powerManagerInter(new PowerManagerInter(DSS_DBUS::powerManagerService, DSS_DBUS::powerManagerPath, QDBusConnection::systemBus(), this))
2524
, m_dbusInter(new DBusObjectInter("org.freedesktop.DBus", "/org/freedesktop/DBus", QDBusConnection::systemBus(), this))
2625
, m_lastLogoutUid(0)
2726
, m_currentUserUid(0)
2827
, m_loginUserList(0)
28+
, m_isVM(detectVirtualMachine())
2929
{
3030
#ifndef ENABLE_DSS_SNIPE
3131
// 需要先初始化m_gsettings
@@ -241,15 +241,11 @@ void AuthInterface::checkPowerInfo()
241241
// 替换接口org.freedesktop.login1 为com.deepin.sessionManager,原接口的是否支持待机和休眠的信息不准确
242242
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
243243
#ifndef ENABLE_DSS_SNIPE
244-
bool can_sleep = env.contains(POWER_CAN_SLEEP) ? QVariant(env.value(POWER_CAN_SLEEP)).toBool()
245-
: getGSettings("Power","sleep").toBool() && m_powerManagerInter->CanSuspend();
246-
bool can_hibernate = env.contains(POWER_CAN_HIBERNATE) ? QVariant(env.value(POWER_CAN_HIBERNATE)).toBool()
247-
: getGSettings("Power","hibernate").toBool() && m_powerManagerInter->CanHibernate();
244+
bool can_sleep = getGSettings("Power","sleep").toBool() && canSuspend();
245+
bool can_hibernate = getGSettings("Power","hibernate").toBool() && canHibernate();
248246
#else
249-
bool can_sleep = env.contains(POWER_CAN_SLEEP) ? QVariant(env.value(POWER_CAN_SLEEP)).toBool()
250-
: getDconfigValue("sleep", true).toBool() && m_powerManagerInter->CanSuspend();
251-
bool can_hibernate = env.contains(POWER_CAN_HIBERNATE) ? QVariant(env.value(POWER_CAN_HIBERNATE)).toBool()
252-
: getDconfigValue("hibernate", true).toBool() && m_powerManagerInter->CanHibernate();
247+
bool can_sleep = getDconfigValue("sleep", true).toBool() && canSuspend();
248+
bool can_hibernate = getDconfigValue("hibernate", true).toBool() && canHibernate();
253249
#endif
254250

255251
m_model->setCanSleep(can_sleep);
@@ -261,3 +257,44 @@ bool AuthInterface::checkIsADDomain()
261257
//只有加入AD域后,才会生成此文件
262258
return QFile::exists("/etc/krb5.keytab");
263259
}
260+
261+
bool AuthInterface::canSuspend()
262+
{
263+
if (QString(getenv("POWER_CAN_SLEEP")) == "0" || m_isVM)
264+
return false;
265+
266+
// 检查内存休眠支持文件是否存在
267+
if (!QFile::exists("/sys/power/mem_sleep"))
268+
return false;
269+
270+
QString canSuspend = m_login1Inter->CanSuspend();
271+
return canSuspend == "yes";
272+
}
273+
274+
bool AuthInterface::canHibernate()
275+
{
276+
if (QString(getenv("POWER_CAN_HIBERNATE")) == "0" || m_isVM)
277+
return false;
278+
279+
QString canHibernate = m_login1Inter->CanHibernate();
280+
return canHibernate == "yes";
281+
}
282+
283+
bool AuthInterface::detectVirtualMachine()
284+
{
285+
QProcess process;
286+
process.start("/usr/bin/systemd-detect-virt", QStringList());
287+
// 添加超时限制,例如 3000ms
288+
if (!process.waitForFinished(3000)) {
289+
qWarning() << "Timeout detecting virtual machine";
290+
return false;
291+
}
292+
293+
if (process.exitCode() != 0) {
294+
qWarning() << "Failed to detect virtual machine, error:" << process.errorString();
295+
return false;
296+
}
297+
298+
QString name = QString::fromUtf8(process.readAllStandardOutput()).trimmed();
299+
return name != "none" && !name.isEmpty();
300+
}

src/session-widgets/authinterface.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
#include <com_deepin_daemon_logined.h>
1515
#include <com_deepin_daemon_authenticate.h>
1616
#include <org_freedesktop_login1_session_self.h>
17-
#include <com_deepin_daemon_powermanager.h>
1817
#include <org_freedesktop_dbus.h>
1918
#include <QGSettings>
2019
#else
2120
#include "authenticate1interface.h"
2221
#include "accounts1interface.h"
2322
#include "loginedinterface.h"
24-
#include "powermanager1interface.h"
2523
#include "dbusinterface.h"
2624
#include "selfinterface.h"
2725
#include <DConfig>
@@ -34,15 +32,13 @@
3432
using AccountsInter = com::deepin::daemon::Accounts;
3533
using LoginedInter = com::deepin::daemon::Logined;
3634
using Login1SessionSelf = org::freedesktop::login1::Session;
37-
using PowerManagerInter = com::deepin::daemon::PowerManager;
3835
using DBusObjectInter = org::freedesktop::DBus;
3936

4037
using com::deepin::daemon::Authenticate;
4138
#else
4239
using AccountsInter = org::deepin::dde::Accounts1;
4340
using LoginedInter = org::deepin::dde::Logined;
4441
using Login1SessionSelf = org::freedesktop::login1::Session;
45-
using PowerManagerInter = org::deepin::dde::PowerManager1;
4642
using DBusObjectInter = org::freedesktop::DBus;
4743

4844
using Authenticate = org::deepin::dde::Authenticate1;
@@ -96,13 +92,16 @@ class AuthInterface : public QObject {
9692
failback);
9793
}
9894

95+
bool canSuspend();
96+
bool canHibernate();
97+
bool detectVirtualMachine();
98+
9999
protected:
100100
SessionBaseModel* m_model;
101101
AccountsInter * m_accountsInter;
102102
LoginedInter* m_loginedInter;
103103
DBusLogin1Manager* m_login1Inter;
104104
Login1SessionSelf* m_login1SessionSelf = nullptr;
105-
PowerManagerInter* m_powerManagerInter;
106105
DBusObjectInter* m_dbusInter;
107106
#ifndef ENABLE_DSS_SNIPE
108107
QGSettings* m_gsettings = nullptr;
@@ -112,6 +111,7 @@ class AuthInterface : public QObject {
112111
uint m_lastLogoutUid;
113112
uint m_currentUserUid;
114113
std::list<uint> m_loginUserList;
114+
bool m_isVM;
115115
};
116116
} // namespace Auth
117117

xml/snipe/org.deepin.dde.PowerManager1.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)