on xenial help sign in
Indicate charging state only if device supports multi color led (#287)

Prior to this change, the Meizu Pro 5 and MX4 (turbo and arale) would flash their single-color home button LED for notifications and charging. This was annoying. To fix this, create a new property in DeviceConfigParser, `supportsMultiColorLed`, and use that property to determine whether the device LED should turn on to indicate the charge state of the device. Fixes https://github.com/ubports/ubuntu-touch/issues/1336

commitdb503ee44892936ca2c5f1e40f34433763ba59ca authorWillem-Jan de Hoog <wdehoog@exalondelft.nl> dateTue 31 Mar 2020, 15:10 (7 years ago) parent184b9d6
9 files changed+79−4
plugins/Utils/deviceconfigparser.cpp+18 plugins/Utils/deviceconfigparser.h+3 qml/DeviceConfiguration.qml+11 qml/OrientedShell.qml+1 qml/Panel/Indicators/IndicatorsLight.qml+24−3 qml/Panel/Panel.qml+2 qml/Shell.qml+2 tests/plugins/Utils/DeviceConfigParserTest.cpp+3 tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml+15−1
plugins/Utils/deviceconfigparser.cpp+18
@@ -116,6 +116,24 @@ QString DeviceConfigParser::category() const
116116 return value;
117117}
118118
119+bool DeviceConfigParser::supportsMultiColorLed() const
120+{
121+ return readBoolFromConfig("SupportsMultiColorLed", true);
122+}
123+
124+bool DeviceConfigParser::readBoolFromConfig(const QString &key, bool defaultValue) const
125+{
126+ m_config->beginGroup(m_name);
127+
128+ bool ret = defaultValue;
129+ if (m_config->contains(key)) {
130+ ret = m_config->value(key).toBool();
131+ }
132+
133+ m_config->endGroup();
134+ return ret;
135+}
136+
119137QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
120138{
121139 m_config->beginGroup(m_name);
plugins/Utils/deviceconfigparser.h+3
@@ -33,6 +33,7 @@ class DeviceConfigParser: public QObject
3333 Q_PROPERTY(Qt::ScreenOrientation portraitOrientation READ portraitOrientation NOTIFY changed)
3434 Q_PROPERTY(Qt::ScreenOrientation invertedPortraitOrientation READ invertedPortraitOrientation NOTIFY changed)
3535 Q_PROPERTY(QString category READ category NOTIFY changed)
36+ Q_PROPERTY(bool supportsMultiColorLed READ supportsMultiColorLed NOTIFY changed)
3637
3738public:
3839 DeviceConfigParser(QObject *parent = nullptr);
@@ -47,6 +48,7 @@ public:
4748 Qt::ScreenOrientation portraitOrientation() const;
4849 Qt::ScreenOrientation invertedPortraitOrientation() const;
4950 QString category() const;
51+ bool supportsMultiColorLed() const;
5052
5153Q_SIGNALS:
5254 void changed();
@@ -58,6 +60,7 @@ private:
5860 QStringList readOrientationsFromConfig(const QString &key) const;
5961 QString readOrientationFromConfig(const QString &key) const;
6062 Qt::ScreenOrientation stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const;
63+ bool readBoolFromConfig(const QString &key, bool defaultValue) const;
6164};
6265
6366#endif
qml/DeviceConfiguration.qml+11
@@ -35,6 +35,8 @@ QtObject {
3535
3636 readonly property alias category: priv.category
3737
38+ readonly property alias supportsMultiColorLed: priv.supportsMultiColorLed
39+
3840 readonly property var deviceConfigParser: DeviceConfigParser {
3941 name: root.name
4042 }
@@ -52,6 +54,7 @@ QtObject {
5254 property int portraitOrientation: deviceConfigParser.portraitOrientation
5355 property int invertedPortraitOrientation: deviceConfigParser.invertedPortraitOrientation
5456 property string category: deviceConfigParser.category
57+ property bool supportsMultiColorLed: deviceConfigParser.supportsMultiColorLed
5558
5659 states: [
5760 State {
@@ -96,6 +99,7 @@ QtObject {
9699 invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
97100 portraitOrientation: Qt.PortraitOrientation
98101 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
102+ supportsMultiColorLed: false
99103 category: "phone"
100104 }
101105 },
@@ -143,6 +147,13 @@ QtObject {
143147 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
144148 category: "desktop"
145149 }
150+ },
151+ State {
152+ name: "turbo"
153+ PropertyChanges {
154+ target: priv
155+ supportsMultiColorLed: false
156+ }
146157 }
147158 ]
148159 }
qml/OrientedShell.qml+1
@@ -275,6 +275,7 @@ Item {
275275 hasMouse: pointerInputDevices > 0
276276 hasKeyboard: keyboardsModel.count > 0
277277 hasTouchscreen: touchScreensModel.count > 0
278+ supportsMultiColorLed: deviceConfiguration.supportsMultiColorLed
278279
279280 // Since we dont have proper multiscreen support yet
280281 // hardcode screen count to only show osk on this screen
qml/Panel/Indicators/IndicatorsLight.qml+24−3
@@ -25,9 +25,13 @@ import QMenuModel 0.1 as QMenuModel
2525import Unity.Indicators 0.1 as Indicators
2626import Wizard 0.1
2727
28+import "../../.."
29+
2830QtObject {
2931 id: root
3032
33+ property bool supportsMultiColorLed: true
34+
3135 property string indicatorState: "INDICATOR_OFF"
3236
3337 property color color: "darkgreen"
@@ -41,6 +45,10 @@ QtObject {
4145 property string batteryIconName: Status.batteryIcon
4246 property string displayStatus: Powerd.status
4347
48+ onSupportsMultiColorLedChanged: {
49+ updateLightState("onSupportsMultiColorLedChanged")
50+ }
51+
4452 onDisplayStatusChanged: {
4553 updateLightState("onDisplayStatusChanged")
4654 }
@@ -50,9 +58,14 @@ QtObject {
5058 }
5159
5260 function updateLightState(msg) {
53− console.log("updateLightState: " + msg + ", hasMessages: " + hasMessages + ", icon: "
54− + batteryIconName + ", displayStatus: " + displayStatus + ", deviceState: "
55− + deviceState + ", batteryLevel: " + batteryLevel)
61+ console.log("updateLightState: " + msg
62+ + ", indicatorState: " + indicatorState
63+ + ", supportsMultiColorLed: " + supportsMultiColorLed
64+ + ", hasMessages: " + hasMessages
65+ + ", icon: " + batteryIconName
66+ + ", displayStatus: " + displayStatus
67+ + ", deviceState: " + deviceState
68+ + ", batteryLevel: " + batteryLevel)
5669
5770 //
5871 // priorities:
@@ -99,6 +112,13 @@ QtObject {
99112 return
100113 }
101114
115+ // if device does not support a multi color led set led off
116+ if(!supportsMultiColorLed) {
117+console.log("no support for Multicolor LED. " + indicatorState)
118+ indicatorState = "INDICATOR_OFF"
119+ return
120+ }
121+
102122 var isCharging = batteryIconName.indexOf("charging") >= 0
103123 || deviceState == "charging"
104124 || deviceState == "fully-charged"
@@ -193,6 +213,7 @@ QtObject {
193213 }
194214 }
195215
216+ Component.onCompleted: Lights.state = Lights.Off
196217 Component.onDestruction: Lights.state = Lights.Off
197218
198219 property var _colorBinding: Binding {
qml/Panel/Panel.qml+2
@@ -47,6 +47,7 @@ Item {
4747 property real panelAreaShowProgress: 1.0
4848 property bool greeterShown: false
4949 property bool hasKeyboard: false
50+ property bool supportsMultiColorLed: true
5051
5152 // Whether our expanded menus should take up the full width of the panel
5253 property bool partialWidth: width >= units.gu(60)
@@ -472,6 +473,7 @@ Item {
472473
473474 IndicatorsLight {
474475 id: indicatorLights
476+ supportsMultiColorLed: root.supportsMultiColorLed
475477 }
476478
477479 states: [
qml/Shell.qml+2
@@ -69,6 +69,7 @@ StyledItem {
6969 property bool hasMouse: false
7070 property bool hasKeyboard: false
7171 property bool hasTouchscreen: false
72+ property bool supportsMultiColorLed: true
7273
7374 // to be read from outside
7475 readonly property int mainAppWindowOrientationAngle: stage.mainAppWindowOrientationAngle
@@ -553,6 +554,7 @@ StyledItem {
553554 || greeter.hasLockedApp
554555 greeterShown: greeter && greeter.shown
555556 hasKeyboard: shell.hasKeyboard
557+ supportsMultiColorLed: shell.supportsMultiColorLed
556558 }
557559
558560 Launcher {
tests/plugins/Utils/DeviceConfigParserTest.cpp+3
@@ -43,6 +43,7 @@ private Q_SLOTS:
4343 QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
4444 QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
4545 QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
46+ QCOMPARE(p.supportsMultiColorLed(), true);
4647 }
4748
4849 void testCustomFile() {
@@ -52,6 +53,7 @@ private Q_SLOTS:
5253
5354 s.setValue("SupportedOrientations", QStringList() << "Portrait" << "Landscape" << "InvertedLandscape");
5455 s.setValue("PrimaryOrientation", "InvertedLandscape");
56+ s.setValue("SupportsMultiColorLed", false);
5557 s.sync();
5658
5759 qputenv("XDG_CONFIG_HOME", dir.path().toUtf8());
@@ -64,6 +66,7 @@ private Q_SLOTS:
6466 QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
6567 QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
6668 QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
69+ QCOMPARE(p.supportsMultiColorLed(), false);
6770 }
6871
6972};
tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml+15−1
@@ -155,7 +155,6 @@ Item {
155155 ActionData.data = noNewMessage;
156156 loader.sourceComponent = undefined;
157157 loader.sourceComponent = light;
158− Powerd.setStatus(Powerd.On, Powerd.Unknown);
159158 }
160159
161160 function test_LightsStatus_data() {
@@ -253,12 +252,27 @@ Item {
253252 expectedLightsOnMillisec: 1000,
254253 expectedLightsOffMillisec: 0,
255254 powerd: Powerd.Off, actionData: batteryLevelDBusSignals["100"], wizardStatus: batteryIconNames.charging },
255+
256+ //
257+ // Support for Multicolor LED
258+ //
259+ { tag: "Powerd.Off with New Message & no support for multicolor led",
260+ expectedLightsState: Lights.On,
261+ powerd: Powerd.Off, actionData: newMessage, supportsMultiColorLed: false },
262+ { tag: "Powerd.Off while charging & support for multicolor led",
263+ expectedLightsState: Lights.On,
264+ powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, supportsMultiColorLed: true },
265+ { tag: "Powerd.Off while charging & no support for multicolor led",
266+ expectedLightsState: Lights.Off,
267+ powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, supportsMultiColorLed: false },
256268 ]
257269 }
258270
259271 function test_LightsStatus(data) {
260272 console.log("----------------------------------------------------------------")
261273
274+ if (data.hasOwnProperty("supportsMultiColorLed"))
275+ loader.item.supportsMultiColorLed = data.supportsMultiColorLed
262276 if (data.hasOwnProperty("powerd"))
263277 Powerd.setStatus(data.powerd, Powerd.Unknown)
264278 if (data.hasOwnProperty("actionData"))