on xenial help sign in
Don't show greeter when screen turns off during a call, even if proximity sensor isn't active. Fixes: 1347001

Approved by: Michał Sawicz, Albert Astals Cid

commit7f545d033abd2b7529a6858fbba2fe90d99a18fb authorMichael Terry <michael.terry@canonical.com> dateMon 8 Sep 2014, 14:13 (12 years ago) parent811b84988673fb
9 files changed+76−37
plugins/Powerd/Powerd.cpp+16−2 plugins/Powerd/Powerd.h+8−1 plugins/Powerd/Powerd.qmltypes+3−3 qml/Panel/Indicators/IndicatorsLight.qml+4−7 qml/Shell.qml+5−12 tests/mocks/Powerd/Powerd.cpp+15−1 tests/mocks/Powerd/Powerd.h+8−1 tests/mocks/Powerd/Powerd.qmltypes+3−3 tests/qmltests/tst_Shell.qml+14−7
plugins/Powerd/Powerd.cpp+16−2
@@ -39,7 +39,8 @@ void dimTimeoutChanged(GSettings *settings, const gchar *key, QDBusInterface *un
3939
4040Powerd::Powerd(QObject* parent)
4141 : QObject(parent),
42− unityScreen(nullptr)
42+ unityScreen(nullptr),
43+ cachedStatus(Status::On)
4344{
4445 unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
4546 "/com/canonical/Unity/Screen",
@@ -51,7 +52,7 @@ Powerd::Powerd(QObject* parent)
5152 "com.canonical.Unity.Screen",
5253 "DisplayPowerStateChange",
5354 this,
54− SIGNAL(displayPowerStateChange(int, int)));
55+ SLOT(handleDisplayPowerStateChange(int, int)));
5556
5657 systemSettings = g_settings_new("com.ubuntu.touch.system");
5758 g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), unityScreen);
@@ -67,3 +68,16 @@ Powerd::~Powerd()
6768 g_signal_handlers_disconnect_by_data(systemSettings, unityScreen);
6869 g_object_unref(systemSettings);
6970}
71+
72+Powerd::Status Powerd::status() const
73+{
74+ return cachedStatus;
75+}
76+
77+void Powerd::handleDisplayPowerStateChange(int status, int reason)
78+{
79+ if (cachedStatus != (Status)status) {
80+ cachedStatus = (Status)status;
81+ Q_EMIT statusChanged((DisplayStateChangeReason)reason);
82+ }
83+}
plugins/Powerd/Powerd.h+8−1
@@ -29,6 +29,7 @@ class Powerd: public QObject
2929 Q_OBJECT
3030 Q_ENUMS(Status)
3131 Q_ENUMS(DisplayStateChangeReason)
32+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
3233
3334public:
3435 enum DisplayStateChangeReason {
@@ -46,12 +47,18 @@ public:
4647 explicit Powerd(QObject *parent = 0);
4748 ~Powerd();
4849
50+ Status status() const;
51+
4952Q_SIGNALS:
50− void displayPowerStateChange(int status, int reason);
53+ void statusChanged(DisplayStateChangeReason reason);
54+
55+private Q_SLOTS:
56+ void handleDisplayPowerStateChange(int status, int reason);
5157
5258private:
5359 QDBusInterface *unityScreen;
5460 GSettings *systemSettings;
61+ Status cachedStatus;
5562};
5663
5764#endif
plugins/Powerd/Powerd.qmltypes+3−3
@@ -30,10 +30,10 @@ Module {
3030 "On": 1
3131 }
3232 }
33+ Property { name: "status"; type: "Status"; isReadonly: true }
3334 Signal {
34− name: "displayPowerStateChange"
35− Parameter { name: "status"; type: "int" }
36− Parameter { name: "reason"; type: "int" }
35+ name: "statusChanged"
36+ Parameter { name: "reason"; type: "DisplayStateChangeReason" }
3737 }
3838 }
3939}
qml/Panel/Indicators/IndicatorsLight.qml+4−7
@@ -27,12 +27,9 @@ QtObject {
2727 Component.onDestruction: Lights.state = Lights.Off
2828
2929 // QtObject does not have children
30− property var _connections: Connections {
31− id: powerConnection
32−
33− target: Powerd
34− onDisplayPowerStateChange: {
35− Lights.state = (status === Powerd.Off) ? Lights.On : Lights.Off
36− }
30+ property var _binding: Binding {
31+ target: Lights
32+ property: "state"
33+ value: (Powerd.status === Powerd.Off) ? Lights.On : Lights.Off
3734 }
3835}
qml/Shell.qml+5−12
@@ -22,6 +22,7 @@ import Ubuntu.Components 0.1
2222import Ubuntu.Components.Popups 1.0
2323import Ubuntu.Gestures 0.1
2424import Ubuntu.SystemImage 0.1
25+import Ubuntu.Telephony 0.1 as Telephony
2526import Unity.Connectivity 0.1
2627import Unity.Launcher 0.1
2728import Utils 0.1
@@ -457,18 +458,9 @@ Item {
457458 id: powerConnection
458459 target: Powerd
459460
460− onDisplayPowerStateChange: {
461− // We ignore any display-off signals when the proximity sensor
462− // is active. This usually indicates something like a phone call.
463− if (status == Powerd.Off && reason != Powerd.Proximity && !edgeDemo.running) {
464− greeter.showNow();
465− }
466−
467− // No reason to chew demo CPU when user isn't watching
468− if (status == Powerd.Off) {
469− edgeDemo.paused = true;
470− } else if (status == Powerd.On) {
471− edgeDemo.paused = false;
461+ onStatusChanged: {
462+ if (Powerd.status === Powerd.Off && !callManager.hasCalls && !edgeDemo.running) {
463+ greeter.showNow()
472464 }
473465 }
474466 }
@@ -637,6 +629,7 @@ Item {
637629 EdgeDemo {
638630 id: edgeDemo
639631 z: alphaDisclaimerLabel.z + 10
632+ paused: Powerd.status === Powerd.Off // Saves power
640633 greeter: greeter
641634 launcher: launcher
642635 indicators: panel.indicators
tests/mocks/Powerd/Powerd.cpp+15−1
@@ -19,6 +19,20 @@
1919#include "Powerd.h"
2020
2121Powerd::Powerd(QObject* parent)
22− : QObject(parent)
22+ : QObject(parent),
23+ m_status(Powerd::Status::On)
2324{
2425}
26+
27+void Powerd::setStatus(Powerd::Status status)
28+{
29+ if (m_status != status) {
30+ m_status = status;
31+ Q_EMIT statusChanged(DisplayStateChangeReason::Unknown);
32+ }
33+}
34+
35+Powerd::Status Powerd::status() const
36+{
37+ return m_status;
38+}
tests/mocks/Powerd/Powerd.h+8−1
@@ -26,6 +26,7 @@ class Powerd: public QObject
2626 Q_OBJECT
2727 Q_ENUMS(Status)
2828 Q_ENUMS(DisplayStateChangeReason)
29+ Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) // write only exists for tests
2930
3031public:
3132 enum DisplayStateChangeReason {
@@ -42,8 +43,14 @@ public:
4243
4344 explicit Powerd(QObject *parent = 0);
4445
46+ Status status() const;
47+ void setStatus(Status status);
48+
4549Q_SIGNALS:
46− void displayPowerStateChange(int status, int reason);
50+ void statusChanged(DisplayStateChangeReason reason);
51+
52+private:
53+ Status m_status;
4754};
4855
4956#endif
tests/mocks/Powerd/Powerd.qmltypes+3−3
@@ -30,10 +30,10 @@ Module {
3030 "On": 1
3131 }
3232 }
33+ Property { name: "status"; type: "Status" }
3334 Signal {
34− name: "displayPowerStateChange"
35− Parameter { name: "status"; type: "int" }
36− Parameter { name: "reason"; type: "int" }
35+ name: "statusChanged"
36+ Parameter { name: "reason"; type: "DisplayStateChangeReason" }
3737 }
3838 }
3939}
tests/qmltests/tst_Shell.qml+14−7
@@ -21,6 +21,7 @@ import QtQuick 2.0
2121import QtTest 1.0
2222import GSettings 1.0
2323import LightDM 0.1 as LightDM
24+import Ubuntu.Telephony 0.1 as Telephony
2425import Unity.Application 0.1
2526import Unity.Connectivity 0.1
2627import Unity.Test 0.1 as UT
@@ -74,6 +75,11 @@ Item {
7475 signalName: "unlockingAllModems"
7576 }
7677
78+ Telephony.CallEntry {
79+ id: phoneCall
80+ phoneNumber: "+447812221111"
81+ }
82+
7783 UT.UnityTestCase {
7884 name: "Shell"
7985 when: windowShown
@@ -146,21 +152,22 @@ Item {
146152 verify(mainApp);
147153 tryCompare(mainApp, "state", ApplicationInfoInterface.Running);
148154
149− // Try to suspend while proximity is engaged...
150− Powerd.displayPowerStateChange(Powerd.Off, Powerd.Proximity);
155+ // Suspend while call is active...
156+ callManager.foregroundCall = phoneCall;
157+ Powerd.status = Powerd.Off;
151158 tryCompare(greeter, "showProgress", 0);
152159
153− // Now really suspend
154− print("suspending")
155− Powerd.displayPowerStateChange(Powerd.Off, 0);
156− print("done suspending")
160+ // Now try again after ending call
161+ callManager.foregroundCall = null;
162+ Powerd.status = Powerd.On;
163+ Powerd.status = Powerd.Off;
157164 tryCompare(greeter, "showProgress", 1);
158165
159166 tryCompare(ApplicationManager, "suspended", true);
160167 compare(mainApp.state, ApplicationInfoInterface.Suspended);
161168
162169 // And wake up
163− Powerd.displayPowerStateChange(Powerd.On, 0);
170+ Powerd.status = Powerd.On;
164171 tryCompare(greeter, "showProgress", 1);
165172
166173 // Swipe away greeter to focus app