fix: support showing lock screen triggered by logind lock signal#197
fix: support showing lock screen triggered by logind lock signal#197yixinshark merged 1 commit intolinuxdeepin:masterfrom
Conversation
- Support showing the lock screen when receiving a lock signal from logind. - Use asynchronous DBus call for RequestLock to prevent blocking the main thread when locking the session, especially when switching TTY. - Introduce a boolean `m_inCallRequestLock` to prevent multiple concurrent lock requests from being sent in a short time. - 支持接收 logind 的 lock 锁定信号后,触发并显示锁屏。 - 使用异步 DBus 调用 [RequestLock](cci:1://file:///home/zyz/works/work/v25/dde-session/src/dde-session/impl/sessionmanager.cpp:418:0-434:1),防止在锁定会话(如切换 TTY 时)阻塞主线程。 - 引入了 `m_inCallRequestLock` 标志位,防止短时间内产生多次并发的锁屏请求。 Log: support showing lock screen triggered by logind lock signal Pms: BUG-314653
Reviewer's GuideThis PR changes session locking to use an asynchronous DBus call for the lock screen and wires the logind lock signal to trigger the lock, with a guard flag to avoid concurrent lock requests that can block the main thread during TTY switches. Updated class diagram for SessionManager asynchronous lock handlingclassDiagram
class SessionManager {
- org_freedesktop_systemd1_Manager* m_systemd1ManagerInter
- org_freedesktop_DBus* m_DBusInter
- QMap~uint,Inhibitor*~ m_inhibitorMap
- bool m_inCallRequestLock
+ SessionManager(QObject* parent)
+ void RequestLock()
+ void RequestHibernate()
+ void RequestLogout()
+ void handleLoginSessionLocked()
+ void handleLoginSessionUnlocked()
}
class QDBusInterface {
+ QDBusInterface(QString service, QString path, QString interface, QDBusConnection connection)
+ QDBusPendingCall asyncCall(QString method)
}
class QDBusPendingCall {
}
class QDBusPendingCallWatcher {
+ QDBusPendingCallWatcher(QDBusPendingCall call, QObject* parent)
+ void finished(QDBusPendingCallWatcher* watcher)
}
class QDBusPendingReply {
+ bool isError()
+ QDBusError error()
}
class QDBusError {
+ QString message()
}
SessionManager --> QDBusInterface : uses
SessionManager --> QDBusPendingCall : uses
SessionManager --> QDBusPendingCallWatcher : creates
SessionManager --> QDBusPendingReply : processes
QDBusPendingReply --> QDBusError : returns
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
m_inCallRequestLockflag is only cleared in the async DBus callback; if the call never finishes or the watcher is never triggered, future lock requests will be suppressed indefinitely—consider adding a timeout or a fallback path to reset the flag. - Currently
m_inCallRequestLockis only used inhandleLoginSessionLocked; if other code paths callRequestLock()directly they can still issue concurrent async calls—consider moving the flag handling intoRequestLock()itself so the concurrency guard applies uniformly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `m_inCallRequestLock` flag is only cleared in the async DBus callback; if the call never finishes or the watcher is never triggered, future lock requests will be suppressed indefinitely—consider adding a timeout or a fallback path to reset the flag.
- Currently `m_inCallRequestLock` is only used in `handleLoginSessionLocked`; if other code paths call `RequestLock()` directly they can still issue concurrent async calls—consider moving the flag handling into `RequestLock()` itself so the concurrency guard applies uniformly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码的修改主要是将 1. 语法逻辑审查
2. 代码质量审查
3. 代码性能审查
4. 代码安全审查
5. 改进后的代码示例以下是改进后的 void SessionManager::RequestLock()
{
QDBusInterface inter("org.deepin.dde.LockFront1", "/org/deepin/dde/LockFront1", "org.deepin.dde.LockFront1", QDBusConnection::sessionBus(), this);
// 使用异步调用方式防止当前线程阻塞
QDBusPendingCall async = inter.asyncCall("Show");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<> reply = *watcher;
if (reply.isError()) {
qWarning() << "failed to lock, async error: " << reply.error().message();
}
// 确保标志位被正确重置
if (m_inCallRequestLock) {
m_inCallRequestLock = false;
}
watcher->deleteLater();
});
}
void SessionManager::handleLoginSessionLocked()
{
qDebug() << "login session locked." << locked();
// 在特殊情况下,比如用 dde-switchtogreeter 命令切换到 greeter, 即切换到其他 tty
// 此时同步的 DBus RequestLock 方法不能立即返回,需要使用异步调用避免阻塞主线程。
// 如果已经锁定,则立即返回
if (locked()) {
qDebug() << "already locked, return";
return;
}
// 防止短时间内多次同时调用 RequestLock
if (m_inCallRequestLock) {
qDebug() << "handleLoginSessionLocked inCall is true, return";
return;
}
m_inCallRequestLock = true;
qDebug() << "handleLoginSessionLocked call RequestLock begin (async)";
RequestLock();
}6. 头文件修改建议在 #include <atomic>
class SessionManager : public QObject
{
// ... 其他代码 ...
private:
std::atomic<bool> m_inCallRequestLock{false};
// ... 其他代码 ...
};总结这段代码的修改方向是正确的,但需要进一步完善以确保内存安全和线程安全。通过使用 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: robertkill, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Support showing the lock screen when receiving a lock signal from logind.
Use asynchronous DBus call for RequestLock to prevent blocking the main thread when locking the session, especially when switching TTY.
Introduce a boolean
m_inCallRequestLockto prevent multiple concurrent lock requests from being sent in a short time.支持接收 logind 的 lock 锁定信号后,触发并显示锁屏。
使用异步 DBus 调用 RequestLock,防止在锁定会话(如切换 TTY 时)阻塞主线程。
引入了
m_inCallRequestLock标志位,防止短时间内产生多次并发的锁屏请求。Log: support showing lock screen triggered by logind lock signal
Pms: BUG-314653
Summary by Sourcery
Handle logind lock signals by asynchronously triggering the lock screen without blocking the session manager main thread.
Bug Fixes: