summaryrefslogtreecommitdiff
blob: cb6e27b7a97718b3b485e0c56446cec6f630341a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
From d21102cc6c7a4db204a29f376ce5eb316ef57a6e Mon Sep 17 00:00:00 2001
From: Kai Uwe Broulik <kde@privat.broulik.de>
Date: Fri, 19 Jun 2020 19:51:06 +0200
Subject: [PATCH] Watch DBus service right away to discard pending inhibitions
 reliably

PowerDevil delays applying a power management inhibition by 5 seconds to avoid brief inhibitions
to e.g. wake up the screen and similar.
However, when an inhibition was posted and the process then quit, we would then still
enforce the inhibition as it wasn't explicitly revoked.
Fix this by always watching the inhibition sender and remove it from pending when the
service goes away.

BUG: 423131
FIXED-IN: 5.18.6
---
 daemon/powerdevilpolicyagent.cpp | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/daemon/powerdevilpolicyagent.cpp b/daemon/powerdevilpolicyagent.cpp
index a7d92dfd..2c2b1152 100644
--- a/daemon/powerdevilpolicyagent.cpp
+++ b/daemon/powerdevilpolicyagent.cpp
@@ -513,6 +513,11 @@ uint PolicyAgent::addInhibitionWithExplicitDBusService(uint types, const QString
 
     const int cookie = m_lastCookie; // when the Timer below fires, m_lastCookie might be different already
 
+    if (!m_busWatcher.isNull() && !service.isEmpty()) {
+        m_cookieToBusService.insert(cookie, service);
+        m_busWatcher.data()->addWatchedService(service);
+    }
+
     m_pendingInhibitions.append(cookie);
 
     qCDebug(POWERDEVIL) << "Scheduling inhibition from" << service << appName << "with cookie"
@@ -532,11 +537,6 @@ uint PolicyAgent::addInhibitionWithExplicitDBusService(uint types, const QString
 
         m_cookieToAppName.insert(cookie, qMakePair<QString, QString>(appName, reason));
 
-        if (!m_busWatcher.isNull() && !service.isEmpty()) {
-            m_cookieToBusService.insert(cookie, service);
-            m_busWatcher.data()->addWatchedService(service);
-        }
-
         addInhibitionTypeHelper(cookie, static_cast< PolicyAgent::RequiredPolicies >(types));
 
         Q_EMIT InhibitionsChanged({ {qMakePair(appName, reason)} }, {});
@@ -596,22 +596,20 @@ void PolicyAgent::ReleaseInhibition(uint cookie)
 {
     qCDebug(POWERDEVIL) << "Releasing inhibition with cookie " << cookie;
 
-    if (m_pendingInhibitions.contains(cookie)) {
+    QString service = m_cookieToBusService.take(cookie);
+    if (!m_busWatcher.isNull() && !service.isEmpty() && !m_cookieToBusService.key(service)) {
+        // no cookies from service left
+        m_busWatcher.data()->removeWatchedService(service);
+    }
+
+    if (m_pendingInhibitions.removeOne(cookie)) {
         qCDebug(POWERDEVIL) << "It was only scheduled for inhibition but not enforced yet, just discarding it";
-        m_pendingInhibitions.removeOne(cookie);
         return;
     }
 
     Q_EMIT InhibitionsChanged(QList<InhibitionInfo>(), { {m_cookieToAppName.value(cookie).first} });
     m_cookieToAppName.remove(cookie);
 
-
-    QString service = m_cookieToBusService.take(cookie);
-    if (!m_busWatcher.isNull() && !service.isEmpty() && !m_cookieToBusService.key(service)) {
-        // no cookies from service left
-        m_busWatcher.data()->removeWatchedService(service);
-    }
-
     // Look through all of the inhibition types
     bool notify = false;
     if (m_typesToCookie[ChangeProfile].contains(cookie)) {
-- 
GitLab