From e18a182c1857ad616dc0fe227b00b5089083372f Mon Sep 17 00:00:00 2001 From: fuleyi Date: Thu, 15 Oct 2026 19:23:06 +0800 Subject: [PATCH] fix: restore the power mode from the active session only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Gate the recovery on the active login1 session, so a background session no longer writes the global power mode when the system resumes. 2. Run the recovery from the wakeup handler and from ActiveChanged(true); the active check inside makes the order of those signals irrelevant. 3. Keep the write idempotent: skip it when the target mode already matches, and re-check activity after reading the power properties. Log: Stop background sessions from writing the global power mode Influence: 1. Log in as user A, switch to user B and hibernate; after resume switch back to A and confirm no password dialog is left on the lock screen. 2. Confirm the background session issues no SetTlpMode on wakeup (the user journal shows no attempt). 3. In the active session, wake up with a configured mode different from the applied one and confirm the mode is restored exactly once. 4. With low battery and powersave as the target, confirm the low battery mode is written once and not written again afterwards. fix: 仅由活动会话恢复电源模式 1. 恢复前判断当前会话是否为活动会话,后台会话在系统唤醒时不再写入 全局电源模式。 2. 唤醒处理与 ActiveChanged(true) 都会调用恢复;内部的 active 判断 使这两个信号的先后顺序不影响结果。 3. 写入保持幂等:目标模式与当前一致时跳过;读取电源属性后再次校验 会话活动状态。 Log: 避免后台会话写入全局电源模式 Influence: 1. 用户A登录后切到用户B休眠,唤醒后切回A,确认锁屏不再残留密码 认证弹窗。 2. 确认后台会话唤醒时不调用 SetTlpMode(用户日志无相关尝试)。 3. 活动会话唤醒且配置模式与已应用模式不同时,确认模式只被恢复一次。 4. 低电量且目标为节能模式时,确认 lowBattery 写入一次且不重复写入。 PMS: BUG-379055 --- src/dde-session/impl/sessionmanager.cpp | 31 +++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/dde-session/impl/sessionmanager.cpp b/src/dde-session/impl/sessionmanager.cpp index e873e98..cd69dfe 100644 --- a/src/dde-session/impl/sessionmanager.cpp +++ b/src/dde-session/impl/sessionmanager.cpp @@ -130,7 +130,7 @@ void SessionManager::initConnections() connect(m_login1ManagerInter, &org::freedesktop::login1::Manager::PrepareForSleep, [=](bool sleep) { qDebug() << "system is preparing for sleep: " << sleep; if (!sleep) { - // 唤醒后恢复之前的电源模式 + // 唤醒后恢复之前的电源模式;只有活动会话才会真正写入 recoverySystemPowerMode(); } }); @@ -138,7 +138,8 @@ void SessionManager::initConnections() connect(m_login1SessionInter, &org::freedesktop::login1::Session::ActiveChanged, [=](bool active) { qDebug() << "session active status changed to:" << active; if (active) { - // 变活跃 + // 变为活动会话:恢复唤醒时未能处理的电源模式 + recoverySystemPowerMode(); } else { // 变不活跃 bool isPreparingForSleep = m_login1ManagerInter->preparingForSleep(); @@ -866,6 +867,10 @@ void SessionManager::setTlpMode(const QString &mode) void SessionManager::recoverySystemPowerMode() { + // 电源模式是系统级的,只有活动会话可以恢复,否则会与活动会话冲突 + if (!m_login1SessionInter->active()) + return; + qInfo() << "recoverySystemPowerMode"; QDBusInterface inter("org.deepin.dde.Power1", "/org/deepin/dde/Power1", "org.freedesktop.DBus.Properties", QDBusConnection::systemBus()); @@ -900,21 +905,23 @@ void SessionManager::recoverySystemPowerMode() QDBusMessage batteryMsg = inter.call("Get", "org.deepin.dde.Power1", "HasBattery"); if (batteryMsg.type() == QDBusMessage::ReplyMessage) { bool hasBattery = batteryMsg.arguments().value(0).value().variant().toBool(); - if (!hasBattery) { - setTlpMode(mode); - return; - } - - QDBusMessage capacityMsg = inter.call("Get", "org.deepin.dde.Power1", "BatteryCapacity"); - if (capacityMsg.type() == QDBusMessage::ReplyMessage) { - double batteryCapacity = capacityMsg.arguments().value(0).value().variant().toDouble(); - if (batteryCapacity <= 20.0) { - mode = LowBattery; + if (hasBattery) { + QDBusMessage capacityMsg = inter.call("Get", "org.deepin.dde.Power1", "BatteryCapacity"); + if (capacityMsg.type() == QDBusMessage::ReplyMessage) { + double batteryCapacity = capacityMsg.arguments().value(0).value().variant().toDouble(); + if (batteryCapacity <= 20.0) { + mode = LowBattery; + } } } } } + if (mode == tlpMode) + return; + // 读取属性期间会话可能已变为非活动,等下次激活时再恢复 + if (!m_login1SessionInter->active()) + return; setTlpMode(mode); }