on xenial help sign in
Instead of looking at proximity sensor to determine if we are in a call, use callManager
commitccf5695d9ba97d3fc586c0399f1df60260ca83b8 authorMichael Terry <michael.terry@canonical.com> dateWed 23 Jul 2014, 17:18 (12 years ago) parent9ac7165
7 files changed+79−23
plugins/Powerd/Powerd.cpp+16−2 plugins/Powerd/Powerd.h+8−1 qml/Panel/Indicators/IndicatorsLight.qml+2−2 qml/Shell.qml+17−8 tests/mocks/Powerd/Powerd.cpp+15−1 tests/mocks/Powerd/Powerd.h+8−1 tests/qmltests/tst_Shell.qml+13−8
plugins/Powerd/Powerd.cpp+16−2
@@ -27,7 +27,8 @@ void autoBrightnessChanged(GSettings *settings, const gchar *key, QDBusInterface
2727
2828Powerd::Powerd(QObject* parent)
2929 : QObject(parent),
30− unityScreen(NULL)
30+ unityScreen(NULL),
31+ cachedStatus(Status::On)
3132{
3233 unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
3334 "/com/canonical/Unity/Screen",
@@ -39,7 +40,7 @@ Powerd::Powerd(QObject* parent)
3940 "com.canonical.Unity.Screen",
4041 "DisplayPowerStateChange",
4142 this,
42− SIGNAL(displayPowerStateChange(int, int)));
43+ SLOT(handleDisplayPowerStateChange(int, int)));
4344
4445 systemSettings = g_settings_new("com.ubuntu.touch.system");
4546 g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), unityScreen);
@@ -51,3 +52,16 @@ Powerd::~Powerd()
5152 g_signal_handlers_disconnect_by_data(systemSettings, unityScreen);
5253 g_object_unref(systemSettings);
5354}
55+
56+Powerd::Status Powerd::status() const
57+{
58+ return cachedStatus;
59+}
60+
61+void Powerd::handleDisplayPowerStateChange(int status, int reason)
62+{
63+ if (cachedStatus != (Status)status) {
64+ cachedStatus = (Status)status;
65+ Q_EMIT statusChanged((DisplayStateChangeReason)reason);
66+ }
67+}
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
qml/Panel/Indicators/IndicatorsLight.qml+2−2
@@ -31,8 +31,8 @@ QtObject {
3131 id: powerConnection
3232
3333 target: Powerd
34− onDisplayPowerStateChange: {
35− Lights.state = (status === Powerd.Off) ? Lights.On : Lights.Off
34+ onStatusChanged: {
35+ Lights.state = (Powerd.status === Powerd.Off) ? Lights.On : Lights.Off
3636 }
3737 }
3838}
qml/Shell.qml+17−8
@@ -21,6 +21,7 @@ import Unity.Application 0.1
2121import Ubuntu.Components 0.1
2222import Ubuntu.Components.Popups 0.1
2323import Ubuntu.Gestures 0.1
24+import Ubuntu.Telephony 0.1 as Telephony
2425import Unity.Launcher 0.1
2526import LightDM 0.1 as LightDM
2627import Powerd 0.1
@@ -638,21 +639,29 @@ FocusScope {
638639 || panel.indicators.shown
639640 }
640641
642+ function showGreeterIfScreenIsOff() {
643+ if (Powerd.status === Powerd.Off && !callManager.hasCalls && !edgeDemo.running) {
644+ greeter.showNow()
645+ }
646+ }
647+
648+ Connections {
649+ id: callConnection
650+ target: callManager
651+ onHasCallsChanged: showGreeterIfScreenIsOff()
652+ }
653+
641654 Connections {
642655 id: powerConnection
643656 target: Powerd
644657
645− onDisplayPowerStateChange: {
646− // We ignore any display-off signals when the proximity sensor
647− // is active. This usually indicates something like a phone call.
648− if (status == Powerd.Off && reason != Powerd.Proximity && !edgeDemo.running) {
649− greeter.showNow();
650− }
658+ onStatusChanged: {
659+ showGreeterIfScreenIsOff()
651660
652661 // No reason to chew demo CPU when user isn't watching
653− if (status == Powerd.Off) {
662+ if (Powerd.status === Powerd.Off) {
654663 edgeDemo.paused = true;
655− } else if (status == Powerd.On) {
664+ } else if (Powerd.status === Powerd.On) {
656665 edgeDemo.paused = false;
657666 }
658667 }
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/qmltests/tst_Shell.qml+13−8
@@ -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.Test 0.1 as UT
2627import Powerd 0.1
@@ -56,6 +57,11 @@ Item {
5657 signalName: "sessionStarted"
5758 }
5859
60+ Telephony.CallEntry {
61+ id: phoneCall
62+ phoneNumber: "+447812221111"
63+ }
64+
5965 UT.UnityTestCase {
6066 name: "Shell"
6167 when: windowShown
@@ -202,21 +208,20 @@ Item {
202208 verify(mainApp);
203209 tryCompare(mainApp, "state", ApplicationInfo.Running);
204210
205− // Try to suspend while proximity is engaged...
206− Powerd.displayPowerStateChange(Powerd.Off, Powerd.Proximity);
211+ // Suspend while call is active...
212+ callManager.foregroundCall = phoneCall;
213+ Powerd.status = Powerd.Off;
207214 tryCompare(greeter, "showProgress", 0);
208215
209− // Now really suspend
210− print("suspending")
211− Powerd.displayPowerStateChange(Powerd.Off, 0);
212− print("done suspending")
216+ // Now end call, triggering a greeter show
217+ callManager.foregroundCall = null;
213218 tryCompare(greeter, "showProgress", 1);
214219
215220 tryCompare(ApplicationManager, "suspended", true);
216221 compare(mainApp.state, ApplicationInfo.Suspended);
217222
218223 // And wake up
219− Powerd.displayPowerStateChange(Powerd.On, 0);
224+ Powerd.status = Powerd.On;
220225 tryCompare(greeter, "showProgress", 1);
221226
222227 // Swipe away greeter to focus app
@@ -497,7 +502,7 @@ Item {
497502 if (data.greeter) {
498503 // Swipe the greeter in
499504 var greeter = findChild(shell, "greeter");
500− Powerd.displayPowerStateChange(Powerd.Off, 0);
505+ LightDM.Greeter.showGreeter();
501506 tryCompare(greeter, "showProgress", 1);
502507 }
503508