Merge lp:~ken-vandine/ubuntu-system-settings/rtm-add-sim-unlock-1378883 into lp:ubuntu-system-settings/rtm-14.09

Proposed by Ken VanDine
Status: Merged
Approved by: Ken VanDine
Approved revision: 975
Merged at revision: 982
Proposed branch: lp:~ken-vandine/ubuntu-system-settings/rtm-add-sim-unlock-1378883
Merge into: lp:ubuntu-system-settings/rtm-14.09
Diff against target: 326 lines (+187/-10)
7 files modified
plugins/security-privacy/CMakeLists.txt (+2/-0)
plugins/security-privacy/SimPin.qml (+31/-6)
plugins/security-privacy/connectivity.cpp (+49/-0)
plugins/security-privacy/connectivity.h (+35/-0)
plugins/security-privacy/plugin.cpp (+11/-0)
tests/autopilot/ubuntu_system_settings/tests/__init__.py (+38/-3)
tests/autopilot/ubuntu_system_settings/tests/test_security.py (+21/-1)
To merge this branch: bzr merge lp:~ken-vandine/ubuntu-system-settings/rtm-add-sim-unlock-1378883
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Jonas G. Drange (community) Approve
Review via email: mp+248044@code.launchpad.net

Commit message

[security/privacy] add connectivity binding and let user unlock a given SIM

Description of the change

[security/privacy] add connectivity binding and let user unlock a given SIM

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

LGTM

Not sure what's up with CI, but it appears it cannot start the app.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/security-privacy/CMakeLists.txt'
2--- plugins/security-privacy/CMakeLists.txt 2014-10-15 11:50:40 +0000
3+++ plugins/security-privacy/CMakeLists.txt 2015-01-29 19:52:22 +0000
4@@ -33,6 +33,8 @@
5 )
6
7 set(PANEL_SOURCES
8+ connectivity.cpp
9+ connectivity.h
10 plugin.cpp
11 plugin.h
12 securityprivacy.cpp
13
14=== modified file 'plugins/security-privacy/SimPin.qml'
15--- plugins/security-privacy/SimPin.qml 2014-09-11 11:40:24 +0000
16+++ plugins/security-privacy/SimPin.qml 2015-01-29 19:52:22 +0000
17@@ -25,6 +25,7 @@
18 import Ubuntu.Components.ListItems 0.1 as ListItem
19 import Ubuntu.Components.Popups 0.1
20 import SystemSettings 1.0
21+import Ubuntu.SystemSettings.SecurityPrivacy 1.0
22 import MeeGo.QOfono 0.2
23 import "sims.js" as Sims
24
25@@ -300,11 +301,23 @@
26 Repeater {
27 model: sims.length
28 Column {
29+ id: sim
30 anchors {
31 left: parent.left
32 right: parent.right
33 }
34
35+ states: [
36+ State {
37+ name: "locked"
38+ when: sims[index].simMng.pinRequired !== OfonoSimManager.NoPin
39+ },
40+ State {
41+ name: "unlocked"
42+ when: sims[index].simMng.pinRequired === OfonoSimManager.NoPin
43+ }
44+ ]
45+
46 Connections {
47 target: sims[index].simMng
48 onLockedPinsChanged: {
49@@ -329,23 +342,35 @@
50 PopupUtils.open(lockDialogComponent, simPinSwitch);
51 }
52 }
53- showDivider: index < (sims.length - 1) && simPinSwitch.checked
54 }
55
56- ListItem.SingleControl {
57+ ListItem.Standard {
58 id: changeControl
59- visible: sims[index].simMng.lockedPins.length > 0
60+ visible: sim.state === "unlocked"
61+ text: i18n.tr("Unlocked")
62 control: Button {
63 enabled: parent.visible
64 text: i18n.tr("Change PIN…")
65- width: parent.width - units.gu(4)
66 onClicked: {
67 curSim = sims[index].simMng;
68 PopupUtils.open(dialogComponent);
69 }
70 }
71- showDivider: false
72- }
73+ }
74+
75+ ListItem.Standard {
76+ id: lockControl
77+ visible: sim.state === "locked"
78+ text: i18n.tr("Locked")
79+ control: Button {
80+ objectName: "unlock"
81+ enabled: sims[index].simMng.pinRequired !== 'none'
82+ text: i18n.tr("Unlock…")
83+ color: UbuntuColors.green
84+ onClicked: Connectivity.unlockModem(sims[index].path)
85+ }
86+ }
87+
88 ListItem.Divider {
89 visible: index < (sims.length - 1)
90 }
91
92=== added file 'plugins/security-privacy/connectivity.cpp'
93--- plugins/security-privacy/connectivity.cpp 1970-01-01 00:00:00 +0000
94+++ plugins/security-privacy/connectivity.cpp 2015-01-29 19:52:22 +0000
95@@ -0,0 +1,49 @@
96+/*
97+ * Copyright (C) 2015 Canonical, Ltd.
98+ *
99+ * Authors:
100+ * Jonas G. Drange <jonas.drange@canonical.com>
101+ *
102+ * This program is free software: you can redistribute it and/or modify it
103+ * under the terms of the GNU General Public License version 3, as published
104+ * by the Free Software Foundation.
105+ *
106+ * This library is distributed in the hope that it will be useful, but WITHOUT
107+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
108+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
109+ * details.
110+ *
111+ * You should have received a copy of the GNU General Public License
112+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
113+ */
114+
115+#include <QDBusReply>
116+#include <QtDebug>
117+#include <QDBusInterface>
118+#include "connectivity.h"
119+
120+namespace {
121+ const QString conn_service("com.ubuntu.connectivity1");
122+ const QString conn_object("/com/ubuntu/connectivity1/Private");
123+ const QString conn_interface("com.ubuntu.connectivity1.Private");
124+ const QString conn_unlockmodem_method("UnlockModem");
125+}
126+
127+Connectivity::Connectivity(QObject *parent) : QObject(parent)
128+{
129+}
130+
131+void Connectivity::unlockModem(QString path)
132+{
133+ QDBusInterface connectivityIface (
134+ conn_service,
135+ conn_object,
136+ conn_interface,
137+ QDBusConnection::sessionBus(),
138+ this);
139+
140+ auto reply = connectivityIface.call(conn_unlockmodem_method, path);
141+ if (reply.type() == QDBusMessage::ErrorMessage) {
142+ qWarning() << "Failed to unlock modem" << path << reply.errorMessage();
143+ }
144+}
145
146=== added file 'plugins/security-privacy/connectivity.h'
147--- plugins/security-privacy/connectivity.h 1970-01-01 00:00:00 +0000
148+++ plugins/security-privacy/connectivity.h 2015-01-29 19:52:22 +0000
149@@ -0,0 +1,35 @@
150+/*
151+ * Copyright (C) 2015 Canonical, Ltd.
152+ *
153+ * Authors:
154+ * Jonas G. Drange <jonas.drange@canonical.com>
155+ *
156+ * This program is free software: you can redistribute it and/or modify it
157+ * under the terms of the GNU General Public License version 3, as published
158+ * by the Free Software Foundation.
159+ *
160+ * This library is distributed in the hope that it will be useful, but WITHOUT
161+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
162+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
163+ * details.
164+ *
165+ * You should have received a copy of the GNU General Public License
166+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
167+ */
168+
169+#ifndef CELLULAR_CONNECTIVITY_HELPER
170+#define CELLULAR_CONNECTIVITY_HELPER
171+
172+#include <QObject>
173+
174+class Connectivity : public QObject {
175+ Q_OBJECT
176+
177+public:
178+ explicit Connectivity(QObject *parent = nullptr);
179+ ~Connectivity() {};
180+
181+ Q_INVOKABLE void unlockModem(QString path);
182+};
183+
184+#endif
185
186=== modified file 'plugins/security-privacy/plugin.cpp'
187--- plugins/security-privacy/plugin.cpp 2014-07-23 13:14:47 +0000
188+++ plugins/security-privacy/plugin.cpp 2015-01-29 19:52:22 +0000
189@@ -19,12 +19,23 @@
190 #include "plugin.h"
191 #include "securityprivacy.h"
192 #include "trust-store-model.h"
193+#include "connectivity.h"
194
195 #include <QtQml/QtQml>
196
197+static QObject *connectivitySingeltonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
198+{
199+ Q_UNUSED(engine)
200+ Q_UNUSED(scriptEngine)
201+
202+ Connectivity *connectivity = new Connectivity();
203+ return connectivity;
204+}
205+
206 void BackendPlugin::registerTypes(const char *uri)
207 {
208 Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.SecurityPrivacy"));
209+ qmlRegisterSingletonType<Connectivity>(uri, 1, 0, "Connectivity", connectivitySingeltonProvider);
210 qmlRegisterType<SecurityPrivacy>(uri, 1, 0, "UbuntuSecurityPrivacyPanel");
211 qmlRegisterType<TrustStoreModel>(uri, 1, 0, "TrustStoreModel");
212 }
213
214=== modified file 'tests/autopilot/ubuntu_system_settings/tests/__init__.py'
215--- tests/autopilot/ubuntu_system_settings/tests/__init__.py 2015-01-21 14:19:49 +0000
216+++ tests/autopilot/ubuntu_system_settings/tests/__init__.py 2015-01-29 19:52:22 +0000
217@@ -48,8 +48,10 @@
218 NM_SERVICE = 'org.freedesktop.NetworkManager'
219 NM_PATH = '/org/freedesktop/NetworkManager'
220 NM_IFACE = 'org.freedesktop.NetworkManager'
221-NM_IFACE = 'org.freedesktop.NetworkManager'
222 NM_AC_CON_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
223+CON_SERVICE = 'com.ubuntu.connectivity1'
224+CON_PATH = '/com/ubuntu/connectivity1/Private'
225+CON_IFACE = 'com.ubuntu.connectivity1.Private'
226 UPOWER_VERSION = str(UPowerGlib.MAJOR_VERSION)
227 UPOWER_VERSION += '.' + str(UPowerGlib.MINOR_VERSION)
228
229@@ -287,12 +289,13 @@
230 (cls.p_mock, cls.obj_ofono) = cls.spawn_server_template(
231 template, stdout=subprocess.PIPE)
232 cls.dbusmock = dbus.Interface(cls.obj_ofono, dbusmock.MOCK_IFACE)
233+ super(UbuntuSystemSettingsOfonoTestCase, cls).setUpClass()
234
235 @classmethod
236 def tearDownClass(cls):
237+ cls.p_mock.terminate()
238+ cls.p_mock.wait()
239 super(UbuntuSystemSettingsOfonoTestCase, cls).tearDownClass()
240- cls.p_mock.terminate()
241- cls.p_mock.wait()
242
243 def setUp(self, panel=None):
244 self.obj_ofono.Reset()
245@@ -715,6 +718,38 @@
246 super(ResetBaseTestCase, self).tearDown()
247
248
249+class ConnectivityMixin(dbusmock.DBusTestCase):
250+ @classmethod
251+ def setUpClass(cls):
252+ cls.start_session_bus()
253+ cls.connectivity_dbus = cls.get_dbus()
254+ cls.connectivity_server = cls.spawn_server(CON_SERVICE,
255+ CON_PATH,
256+ CON_IFACE,
257+ system_bus=False,
258+ stdout=subprocess.PIPE)
259+
260+ cls.connectivity_mock = dbus.Interface(
261+ cls.connectivity_dbus.get_object(CON_SERVICE,
262+ CON_PATH),
263+ dbusmock.MOCK_IFACE)
264+
265+ cls.connectivity_mock.AddMethod('', 'UnlockModem', 's', '', '')
266+ super(ConnectivityMixin, cls).setUpClass()
267+
268+ def setUp(self):
269+ self.wait_for_bus_object(CON_SERVICE,
270+ CON_PATH,
271+ system_bus=False)
272+ super(ConnectivityMixin, self).setUp()
273+
274+ @classmethod
275+ def tearDownClass(cls):
276+ cls.connectivity_server.terminate()
277+ cls.connectivity_server.wait()
278+ super(ConnectivityMixin, cls).tearDownClass()
279+
280+
281 class SecurityBaseTestCase(UbuntuSystemSettingsOfonoTestCase):
282 """ Base class for security and privacy settings tests"""
283
284
285=== modified file 'tests/autopilot/ubuntu_system_settings/tests/test_security.py'
286--- tests/autopilot/ubuntu_system_settings/tests/test_security.py 2015-01-12 16:22:55 +0000
287+++ tests/autopilot/ubuntu_system_settings/tests/test_security.py 2015-01-29 19:52:22 +0000
288@@ -13,13 +13,14 @@
289
290 from ubuntu_system_settings.tests import (
291 SecurityBaseTestCase,
292+ ConnectivityMixin,
293 SIM_IFACE)
294
295 from ubuntu_system_settings.utils.i18n import ugettext as _
296 from ubuntuuitoolkit import emulators as toolkit_emulators
297
298
299-class SecurityTestCase(SecurityBaseTestCase):
300+class SecurityTestCase(SecurityBaseTestCase, ConnectivityMixin):
301 """ Tests for Security Page """
302
303 def setUp(self):
304@@ -409,3 +410,22 @@
305 self.assertFalse(
306 len(self.modem_0.Get(SIM_IFACE, 'LockedPins')) > 0
307 )
308+
309+ def test_sim_unlock(self):
310+ # lock sim
311+ self.modem_0.Set(SIM_IFACE, 'PinRequired', 'pin')
312+ self.modem_0.EmitSignal(
313+ SIM_IFACE, 'PropertyChanged', 'sv', ['PinRequired', 'pin'])
314+
315+ self._go_to_sim_lock()
316+ unlock = self.system_settings.main_view.select_single(
317+ objectName='unlock')
318+ self.system_settings.main_view.pointing_device.click_object(unlock)
319+
320+ self.assertThat(
321+ lambda: len(self.connectivity_mock.GetMethodCalls('UnlockModem')),
322+ Eventually(Equals(1)))
323+
324+ # make sure the argument for the one call is the modem path
325+ for d, args in self.connectivity_mock.GetMethodCalls('UnlockModem'):
326+ self.assertEqual(str(args[0]), '/ril_0')

Subscribers

People subscribed via source and target branches