Merge lp:~unity-api-team/indicator-network/connectivity-service-mobile-data-management into lp:indicator-network
- connectivity-service-mobile-data-management
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Pete Woods |
Approved revision: | 586 |
Merged at revision: | 598 |
Proposed branch: | lp:~unity-api-team/indicator-network/connectivity-service-mobile-data-management |
Merge into: | lp:indicator-network |
Diff against target: |
2816 lines (+2373/-3) 34 files modified
CMakeLists.txt (+2/-0) data/com.ubuntu.connectivity1.Modem.xml (+9/-0) data/com.ubuntu.connectivity1.Private.xml (+8/-0) data/com.ubuntu.connectivity1.Sim.xml (+16/-0) scripts/CMakeLists.txt (+5/-0) scripts/disable-mobile-data.sh (+8/-0) scripts/enable-mobile-data.sh (+8/-0) scripts/get-mobile-data-enabled.sh (+6/-0) scripts/get-modems.sh (+6/-0) scripts/get-sim-for-mobile-data.sh (+7/-0) scripts/get-sims.sh (+6/-0) scripts/monitor-private-properties.sh (+7/-0) scripts/set-sim-for-mobile-data.sh (+9/-0) src/indicator/CMakeLists.txt (+22/-0) src/indicator/connectivity-service/connectivity-service.cpp (+175/-0) src/indicator/connectivity-service/connectivity-service.h (+17/-0) src/indicator/connectivity-service/dbus-modem.cpp (+98/-0) src/indicator/connectivity-service/dbus-modem.h (+83/-0) src/indicator/connectivity-service/dbus-sim.cpp (+148/-0) src/indicator/connectivity-service/dbus-sim.h (+103/-0) src/indicator/nmofono/connectivity-service-settings.cpp (+148/-0) src/indicator/nmofono/connectivity-service-settings.h (+67/-0) src/indicator/nmofono/manager-impl.cpp (+210/-1) src/indicator/nmofono/manager-impl.h (+12/-0) src/indicator/nmofono/manager.h (+26/-0) src/indicator/nmofono/wwan/modem.cpp (+63/-2) src/indicator/nmofono/wwan/modem.h (+10/-0) src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp (+252/-0) src/indicator/nmofono/wwan/qofono-sim-wrapper.h (+77/-0) src/indicator/nmofono/wwan/sim-manager.cpp (+261/-0) src/indicator/nmofono/wwan/sim-manager.h (+57/-0) src/indicator/nmofono/wwan/sim.cpp (+309/-0) src/indicator/nmofono/wwan/sim.h (+125/-0) src/qdbus-stubs/dbus-types.h (+13/-0) |
To merge this branch: | bzr merge lp:~unity-api-team/indicator-network/connectivity-service-mobile-data-management |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
Indicator Applet Developers | Pending | ||
Review via email: mp+293081@code.launchpad.net |
Commit message
New Connectivity Service Private API for managing mobile data and SIM cards.
Description of the change
New Connectivity Service Private API for managing mobile data and SIM cards.
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:582
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:583
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:585
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:586
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2016-02-15 09:31:38 +0000 |
3 | +++ CMakeLists.txt 2016-05-16 07:44:17 +0000 |
4 | @@ -139,3 +139,5 @@ |
5 | ) |
6 | |
7 | endif() |
8 | + |
9 | +add_subdirectory(scripts) |
10 | |
11 | === added file 'data/com.ubuntu.connectivity1.Modem.xml' |
12 | --- data/com.ubuntu.connectivity1.Modem.xml 1970-01-01 00:00:00 +0000 |
13 | +++ data/com.ubuntu.connectivity1.Modem.xml 2016-05-16 07:44:17 +0000 |
14 | @@ -0,0 +1,9 @@ |
15 | +<?xml version="1.0" encoding="UTF-8" ?> |
16 | + |
17 | +<node> |
18 | + <interface name="com.ubuntu.connectivity1.Modem"> |
19 | + <property name="Index" type="i" access="read" /> |
20 | + <property name="Serial" type="s" access="read" /> |
21 | + <property name="Sim" type="o" access="read" /> |
22 | + </interface> |
23 | +</node> |
24 | |
25 | === modified file 'data/com.ubuntu.connectivity1.Private.xml' |
26 | --- data/com.ubuntu.connectivity1.Private.xml 2015-12-04 13:18:04 +0000 |
27 | +++ data/com.ubuntu.connectivity1.Private.xml 2016-05-16 07:44:17 +0000 |
28 | @@ -52,6 +52,14 @@ |
29 | |
30 | <property name="VpnConnections" type="ao" access="read"/> |
31 | |
32 | + <property name="MobileDataEnabled" type="b" access="readwrite"/> |
33 | + |
34 | + <property name="SimForMobileData" type="o" access="readwrite"/> |
35 | + |
36 | + <property name="Modems" type="ao" access="read"/> |
37 | + |
38 | + <property name="Sims" type="ao" access="read"/> |
39 | + |
40 | <signal name="ReportError"> |
41 | <arg type="i" direction="out" name="reason"/> |
42 | </signal> |
43 | |
44 | === added file 'data/com.ubuntu.connectivity1.Sim.xml' |
45 | --- data/com.ubuntu.connectivity1.Sim.xml 1970-01-01 00:00:00 +0000 |
46 | +++ data/com.ubuntu.connectivity1.Sim.xml 2016-05-16 07:44:17 +0000 |
47 | @@ -0,0 +1,16 @@ |
48 | +<?xml version="1.0" encoding="UTF-8" ?> |
49 | + |
50 | +<node> |
51 | + <interface name="com.ubuntu.connectivity1.Sim"> |
52 | + <property name="Imsi" type="s" access="read" /> |
53 | + <property name="PrimaryPhoneNumber" type="s" access="read" /> |
54 | + <property name="Locked" type="b" access="read" /> |
55 | + <property name="Present" type="b" access="read" /> |
56 | + <property name="Mcc" type="s" access="read" /> |
57 | + <property name="Mnc" type="s" access="read" /> |
58 | + <property name="PreferredLanguages" type="as" access="read" /> |
59 | + <property name="DataRoamingEnabled" type="b" access="readwrite" /> |
60 | + |
61 | + <method name="Unlock" /> |
62 | + </interface> |
63 | +</node> |
64 | |
65 | === added directory 'scripts' |
66 | === added file 'scripts/CMakeLists.txt' |
67 | --- scripts/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
68 | +++ scripts/CMakeLists.txt 2016-05-16 07:44:17 +0000 |
69 | @@ -0,0 +1,5 @@ |
70 | + |
71 | +file(GLOB_RECURSE SCRIPT_FILES |
72 | + ${CMAKE_CURRENT_SOURCE_DIR}/*.sh |
73 | +) |
74 | +add_custom_target(scriptfiles SOURCES ${SCRIPT_FILES}) |
75 | |
76 | === added file 'scripts/disable-mobile-data.sh' |
77 | --- scripts/disable-mobile-data.sh 1970-01-01 00:00:00 +0000 |
78 | +++ scripts/disable-mobile-data.sh 2016-05-16 07:44:17 +0000 |
79 | @@ -0,0 +1,8 @@ |
80 | +dbus-send --session --print-reply \ |
81 | + --dest=com.ubuntu.connectivity1 \ |
82 | + /com/ubuntu/connectivity1/Private \ |
83 | + org.freedesktop.DBus.Properties.Set \ |
84 | + string:com.ubuntu.connectivity1.Private \ |
85 | + string:MobileDataEnabled \ |
86 | + variant:boolean:false |
87 | +sh get-mobile-data-enabled.sh |
88 | |
89 | === added file 'scripts/enable-mobile-data.sh' |
90 | --- scripts/enable-mobile-data.sh 1970-01-01 00:00:00 +0000 |
91 | +++ scripts/enable-mobile-data.sh 2016-05-16 07:44:17 +0000 |
92 | @@ -0,0 +1,8 @@ |
93 | +dbus-send --session --print-reply \ |
94 | + --dest=com.ubuntu.connectivity1 \ |
95 | + /com/ubuntu/connectivity1/Private \ |
96 | + org.freedesktop.DBus.Properties.Set \ |
97 | + string:com.ubuntu.connectivity1.Private \ |
98 | + string:MobileDataEnabled \ |
99 | + variant:boolean:true |
100 | +sh get-mobile-data-enabled.sh |
101 | |
102 | === added file 'scripts/get-mobile-data-enabled.sh' |
103 | --- scripts/get-mobile-data-enabled.sh 1970-01-01 00:00:00 +0000 |
104 | +++ scripts/get-mobile-data-enabled.sh 2016-05-16 07:44:17 +0000 |
105 | @@ -0,0 +1,6 @@ |
106 | +dbus-send --session --print-reply \ |
107 | + --dest=com.ubuntu.connectivity1 \ |
108 | + /com/ubuntu/connectivity1/Private \ |
109 | + org.freedesktop.DBus.Properties.Get \ |
110 | + string:com.ubuntu.connectivity1.Private \ |
111 | + string:MobileDataEnabled |
112 | |
113 | === added file 'scripts/get-modems.sh' |
114 | --- scripts/get-modems.sh 1970-01-01 00:00:00 +0000 |
115 | +++ scripts/get-modems.sh 2016-05-16 07:44:17 +0000 |
116 | @@ -0,0 +1,6 @@ |
117 | +dbus-send --session --print-reply \ |
118 | + --dest=com.ubuntu.connectivity1 \ |
119 | + /com/ubuntu/connectivity1/Private \ |
120 | + org.freedesktop.DBus.Properties.Get \ |
121 | + string:com.ubuntu.connectivity1.Private \ |
122 | + string:Modems |
123 | |
124 | === added file 'scripts/get-sim-for-mobile-data.sh' |
125 | --- scripts/get-sim-for-mobile-data.sh 1970-01-01 00:00:00 +0000 |
126 | +++ scripts/get-sim-for-mobile-data.sh 2016-05-16 07:44:17 +0000 |
127 | @@ -0,0 +1,7 @@ |
128 | +#!/bin/sh |
129 | +dbus-send --session --print-reply \ |
130 | + --dest=com.ubuntu.connectivity1 \ |
131 | + /com/ubuntu/connectivity1/Private \ |
132 | + org.freedesktop.DBus.Properties.Get \ |
133 | + string:com.ubuntu.connectivity1.Private \ |
134 | + string:SimForMobileData |
135 | |
136 | === added file 'scripts/get-sims.sh' |
137 | --- scripts/get-sims.sh 1970-01-01 00:00:00 +0000 |
138 | +++ scripts/get-sims.sh 2016-05-16 07:44:17 +0000 |
139 | @@ -0,0 +1,6 @@ |
140 | +dbus-send --session --print-reply \ |
141 | + --dest=com.ubuntu.connectivity1 \ |
142 | + /com/ubuntu/connectivity1/Private \ |
143 | + org.freedesktop.DBus.Properties.Get \ |
144 | + string:com.ubuntu.connectivity1.Private \ |
145 | + string:Sims |
146 | |
147 | === added file 'scripts/monitor-private-properties.sh' |
148 | --- scripts/monitor-private-properties.sh 1970-01-01 00:00:00 +0000 |
149 | +++ scripts/monitor-private-properties.sh 2016-05-16 07:44:17 +0000 |
150 | @@ -0,0 +1,7 @@ |
151 | +dbus-monitor --session \ |
152 | + "type=signal, |
153 | + sender='com.ubuntu.connectivity1', |
154 | + path=/com/ubuntu/connectivity1/Private, |
155 | + interface=org.freedesktop.DBus.Properties, |
156 | + member=PropertiesChanged" |
157 | + |
158 | |
159 | === added file 'scripts/set-sim-for-mobile-data.sh' |
160 | --- scripts/set-sim-for-mobile-data.sh 1970-01-01 00:00:00 +0000 |
161 | +++ scripts/set-sim-for-mobile-data.sh 2016-05-16 07:44:17 +0000 |
162 | @@ -0,0 +1,9 @@ |
163 | +#!/bin/sh |
164 | +dbus-send --session --print-reply \ |
165 | + --dest=com.ubuntu.connectivity1 \ |
166 | + /com/ubuntu/connectivity1/Private \ |
167 | + org.freedesktop.DBus.Properties.Set \ |
168 | + string:com.ubuntu.connectivity1.Private \ |
169 | + string:SimForMobileData \ |
170 | + variant:objpath:$1 |
171 | +/bin/sh ./get-sim-for-mobile-data.sh |
172 | |
173 | === modified file 'src/indicator/CMakeLists.txt' |
174 | --- src/indicator/CMakeLists.txt 2016-02-15 09:31:38 +0000 |
175 | +++ src/indicator/CMakeLists.txt 2016-05-16 07:44:17 +0000 |
176 | @@ -20,6 +20,7 @@ |
177 | set(NETWORK_SERVICE_SOURCES |
178 | ${NETWORK_SERVICE_HEADERS} |
179 | |
180 | + nmofono/connectivity-service-settings.cpp |
181 | nmofono/hotspot-manager.cpp |
182 | nmofono/kill-switch.cpp |
183 | nmofono/manager.cpp |
184 | @@ -32,6 +33,9 @@ |
185 | nmofono/wifi/grouped-access-point.cpp |
186 | nmofono/wifi/wifi-link-impl.cpp |
187 | nmofono/wwan/modem.cpp |
188 | + nmofono/wwan/sim.cpp |
189 | + nmofono/wwan/sim-manager.cpp |
190 | + nmofono/wwan/qofono-sim-wrapper.cpp |
191 | nmofono/vpn/openvpn-connection.cpp |
192 | nmofono/vpn/pptp-connection.cpp |
193 | nmofono/vpn/vpn-connection.cpp |
194 | @@ -53,6 +57,8 @@ |
195 | connectivity-service/dbus-openvpn-connection.cpp |
196 | connectivity-service/dbus-pptp-connection.cpp |
197 | connectivity-service/dbus-vpn-connection.cpp |
198 | + connectivity-service/dbus-modem.cpp |
199 | + connectivity-service/dbus-sim.cpp |
200 | |
201 | menuitems/access-point-item.cpp |
202 | menuitems/switch-item.cpp |
203 | @@ -73,6 +79,22 @@ |
204 | |
205 | qt5_add_dbus_adaptor( |
206 | NETWORK_SERVICE_SOURCES |
207 | + "${DATA_DIR}/com.ubuntu.connectivity1.Modem.xml" |
208 | + connectivity-service/dbus-modem.h |
209 | + connectivity_service::DBusModem |
210 | + ModemAdaptor |
211 | +) |
212 | + |
213 | +qt5_add_dbus_adaptor( |
214 | + NETWORK_SERVICE_SOURCES |
215 | + "${DATA_DIR}/com.ubuntu.connectivity1.Sim.xml" |
216 | + connectivity-service/dbus-sim.h |
217 | + connectivity_service::DBusSim |
218 | + SimAdaptor |
219 | +) |
220 | + |
221 | +qt5_add_dbus_adaptor( |
222 | + NETWORK_SERVICE_SOURCES |
223 | "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml" |
224 | connectivity-service/connectivity-service.h |
225 | connectivity_service::PrivateService |
226 | |
227 | === modified file 'src/indicator/connectivity-service/connectivity-service.cpp' |
228 | --- src/indicator/connectivity-service/connectivity-service.cpp 2016-01-14 11:40:59 +0000 |
229 | +++ src/indicator/connectivity-service/connectivity-service.cpp 2016-05-16 07:44:17 +0000 |
230 | @@ -19,6 +19,8 @@ |
231 | */ |
232 | |
233 | #include <connectivity-service/connectivity-service.h> |
234 | +#include <connectivity-service/dbus-modem.h> |
235 | +#include <connectivity-service/dbus-sim.h> |
236 | #include <connectivity-service/dbus-vpn-connection.h> |
237 | #include <connectivity-service/dbus-openvpn-connection.h> |
238 | #include <connectivity-service/dbus-pptp-connection.h> |
239 | @@ -48,6 +50,9 @@ |
240 | |
241 | QMap<QDBusObjectPath, DBusVpnConnection::SPtr> m_vpnConnections; |
242 | |
243 | + QMap<QString, DBusModem::SPtr> m_modems; |
244 | + QMap<QString, DBusSim::SPtr> m_sims; |
245 | + |
246 | shared_ptr<PrivateService> m_privateService; |
247 | |
248 | QStringList m_limitations; |
249 | @@ -166,6 +171,102 @@ |
250 | }); |
251 | } |
252 | |
253 | + void mobileDataEnabledUpdated(bool value) |
254 | + { |
255 | + Q_UNUSED(value) |
256 | + notifyPrivateProperties({ |
257 | + "MobileDataEnabled" |
258 | + }); |
259 | + } |
260 | + |
261 | + void simForMobileDataUpdated() |
262 | + { |
263 | + notifyPrivateProperties({ |
264 | + "SimForMobileData" |
265 | + }); |
266 | + } |
267 | + |
268 | + void updateSims() |
269 | + { |
270 | + auto current_imsis = m_sims.keys().toSet(); |
271 | + QMap<QString, nmofono::wwan::Sim::Ptr> sims; |
272 | + for (auto i : m_manager->sims()) |
273 | + { |
274 | + sims[i->imsi()] = i; |
275 | + } |
276 | + auto toAdd(sims.keys().toSet()); |
277 | + toAdd.subtract(current_imsis); |
278 | + |
279 | + auto toRemove(current_imsis); |
280 | + toRemove.subtract(sims.keys().toSet()); |
281 | + |
282 | + for (auto imsi : toRemove) |
283 | + { |
284 | + m_sims.remove(imsi); |
285 | + } |
286 | + |
287 | + for (auto imsi : toAdd) |
288 | + { |
289 | + DBusSim::SPtr dbussim = make_shared<DBusSim>(sims[imsi], m_connection); |
290 | + m_sims[imsi] = dbussim; |
291 | + } |
292 | + |
293 | + notifyPrivateProperties({ |
294 | + "Sims" |
295 | + }); |
296 | + } |
297 | + |
298 | + void updateModems() |
299 | + { |
300 | + auto current_serials = m_modems.keys().toSet(); |
301 | + QMap<QString, nmofono::wwan::Modem::Ptr> modems; |
302 | + for (auto i : m_manager->modems()) |
303 | + { |
304 | + modems[i->serial()] = i; |
305 | + } |
306 | + auto toAdd(modems.keys().toSet()); |
307 | + toAdd.subtract(current_serials); |
308 | + |
309 | + auto toRemove(current_serials); |
310 | + toRemove.subtract(modems.keys().toSet()); |
311 | + |
312 | + for (auto serial : toRemove) |
313 | + { |
314 | + m_modems.remove(serial); |
315 | + } |
316 | + |
317 | + for (auto serial : toAdd) |
318 | + { |
319 | + wwan::Modem::Ptr m = modems[serial]; |
320 | + |
321 | + DBusModem::SPtr dbusmodem = make_shared<DBusModem>(m, m_connection); |
322 | + m_modems[serial] = dbusmodem; |
323 | + updateModemSimPath(dbusmodem, m->sim()); |
324 | + connect(m.get(), &wwan::Modem::simUpdated, this, &Private::modemSimUpdated); |
325 | + } |
326 | + notifyPrivateProperties({ |
327 | + "Modems" |
328 | + }); |
329 | + } |
330 | + |
331 | + void modemSimUpdated() |
332 | + { |
333 | + auto modem_raw = qobject_cast<wwan::Modem*>(sender()); |
334 | + updateModemSimPath(m_modems[modem_raw->serial()], modem_raw->sim()); |
335 | + } |
336 | + |
337 | + void updateModemSimPath(DBusModem::SPtr modem, wwan::Sim::Ptr sim) |
338 | + { |
339 | + if (!sim) |
340 | + { |
341 | + modem->setSim(QDBusObjectPath("/")); |
342 | + } |
343 | + else |
344 | + { |
345 | + modem->setSim(m_sims[sim->imsi()]->path()); |
346 | + } |
347 | + } |
348 | + |
349 | void updateNetworkingStatus() |
350 | { |
351 | QStringList changed; |
352 | @@ -293,10 +394,17 @@ |
353 | connect(d->m_manager.get(), &Manager::hotspotAuthChanged, d.get(), &Private::hotspotAuthUpdated); |
354 | connect(d->m_manager.get(), &Manager::hotspotStoredChanged, d.get(), &Private::hotspotStoredUpdated); |
355 | |
356 | + connect(d->m_manager.get(), &Manager::mobileDataEnabledChanged, d.get(), &Private::mobileDataEnabledUpdated); |
357 | + connect(d->m_manager.get(), &Manager::simsChanged, d.get(), &Private::updateSims); |
358 | + connect(d->m_manager.get(), &Manager::modemsChanged, d.get(), &Private::updateModems); |
359 | + connect(d->m_manager.get(), &Manager::simForMobileDataChanged, d.get(), &Private::simForMobileDataUpdated); |
360 | + |
361 | connect(d->m_manager.get(), &Manager::reportError, d->m_privateService.get(), &PrivateService::ReportError); |
362 | |
363 | connect(d->m_vpnManager.get(), &vpn::VpnManager::connectionsChanged, d.get(), &Private::updateVpnList); |
364 | |
365 | + d->updateSims(); |
366 | + d->updateModems(); |
367 | d->updateNetworkingStatus(); |
368 | d->updateVpnList(); |
369 | |
370 | @@ -508,6 +616,73 @@ |
371 | return paths; |
372 | } |
373 | |
374 | +bool PrivateService::mobileDataEnabled() const |
375 | +{ |
376 | + return p.d->m_manager->mobileDataEnabled(); |
377 | +} |
378 | + |
379 | +void PrivateService::setMobileDataEnabled(bool enabled) |
380 | +{ |
381 | + p.d->m_manager->setMobileDataEnabled(enabled); |
382 | +} |
383 | + |
384 | +QDBusObjectPath PrivateService::simForMobileData() const |
385 | +{ |
386 | + wwan::Sim::Ptr sim = p.d->m_manager->simForMobileData(); |
387 | + if (!sim) |
388 | + { |
389 | + return QDBusObjectPath("/"); |
390 | + } |
391 | + |
392 | + Q_ASSERT(p.d->m_sims.contains(sim->imsi())); |
393 | + return p.d->m_sims[sim->imsi()]->path(); |
394 | +} |
395 | + |
396 | +void PrivateService::setSimForMobileData(const QDBusObjectPath &path) |
397 | +{ |
398 | + if (path.path() == "/") |
399 | + { |
400 | + p.d->m_manager->setSimForMobileData(wwan::Sim::Ptr()); |
401 | + return; |
402 | + } |
403 | + |
404 | + bool found = false; |
405 | + for (DBusSim::SPtr dbussim: p.d->m_sims) |
406 | + { |
407 | + if (dbussim->path() == path) |
408 | + { |
409 | + found = true; |
410 | + p.d->m_manager->setSimForMobileData(dbussim->sim()); |
411 | + } |
412 | + } |
413 | + |
414 | + if (!found) |
415 | + { |
416 | + sendErrorReply(QDBusError::UnknownObject); |
417 | + } |
418 | +} |
419 | + |
420 | +QList<QDBusObjectPath> PrivateService::modems() const |
421 | +{ |
422 | + auto list = QList<QDBusObjectPath>(); |
423 | + for (DBusModem::SPtr modem : p.d->m_modems) |
424 | + { |
425 | + list << modem->path(); |
426 | + } |
427 | + return list; |
428 | +} |
429 | + |
430 | +QList<QDBusObjectPath> PrivateService::sims() const |
431 | +{ |
432 | + QList<QDBusObjectPath> paths; |
433 | + |
434 | + for (auto dbussim : p.d->m_sims) |
435 | + { |
436 | + paths.append(dbussim->path()); |
437 | + } |
438 | + return paths; |
439 | +} |
440 | + |
441 | } |
442 | |
443 | #include "connectivity-service.moc" |
444 | |
445 | === modified file 'src/indicator/connectivity-service/connectivity-service.h' |
446 | --- src/indicator/connectivity-service/connectivity-service.h 2015-12-04 13:18:04 +0000 |
447 | +++ src/indicator/connectivity-service/connectivity-service.h 2016-05-16 07:44:17 +0000 |
448 | @@ -109,6 +109,18 @@ |
449 | Q_PROPERTY(QList<QDBusObjectPath> VpnConnections READ vpnConnections) |
450 | QList<QDBusObjectPath> vpnConnections() const; |
451 | |
452 | + Q_PROPERTY(bool MobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled) |
453 | + bool mobileDataEnabled() const; |
454 | + |
455 | + Q_PROPERTY(QDBusObjectPath SimForMobileData READ simForMobileData WRITE setSimForMobileData) |
456 | + QDBusObjectPath simForMobileData() const; |
457 | + |
458 | + Q_PROPERTY(QList<QDBusObjectPath> Modems READ modems) |
459 | + QList<QDBusObjectPath> modems() const; |
460 | + |
461 | + Q_PROPERTY(QList<QDBusObjectPath> Sims READ sims) |
462 | + QList<QDBusObjectPath> sims() const; |
463 | + |
464 | protected Q_SLOTS: |
465 | void UnlockAllModems(); |
466 | |
467 | @@ -132,6 +144,11 @@ |
468 | |
469 | void RemoveVpnConnection(const QDBusObjectPath &path); |
470 | |
471 | + void setMobileDataEnabled(bool enabled); |
472 | + |
473 | + void setSimForMobileData(const QDBusObjectPath &path); |
474 | + |
475 | + |
476 | Q_SIGNALS: |
477 | void ReportError(int reason); |
478 | |
479 | |
480 | === added file 'src/indicator/connectivity-service/dbus-modem.cpp' |
481 | --- src/indicator/connectivity-service/dbus-modem.cpp 1970-01-01 00:00:00 +0000 |
482 | +++ src/indicator/connectivity-service/dbus-modem.cpp 2016-05-16 07:44:17 +0000 |
483 | @@ -0,0 +1,98 @@ |
484 | +/* |
485 | + * Copyright (C) 2016 Canonical, Ltd. |
486 | + * |
487 | + * This program is free software: you can redistribute it and/or modify it |
488 | + * under the terms of the GNU General Public License version 3, as published |
489 | + * by the Free Software Foundation. |
490 | + * |
491 | + * This program is distributed in the hope that it will be useful, but |
492 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
493 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
494 | + * PURPOSE. See the GNU General Public License for more details. |
495 | + * |
496 | + * You should have received a copy of the GNU General Public License along |
497 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
498 | + * |
499 | + * Authors: |
500 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
501 | + */ |
502 | + |
503 | +#include <connectivity-service/dbus-modem.h> |
504 | +#include <ModemAdaptor.h> |
505 | +#include <dbus-types.h> |
506 | +#include <util/dbus-utils.h> |
507 | + |
508 | +using namespace std; |
509 | +using namespace nmofono::wwan; |
510 | + |
511 | +namespace connectivity_service |
512 | +{ |
513 | + |
514 | +DBusModem::DBusModem(Modem::Ptr modem, |
515 | + const QDBusConnection& connection) : |
516 | + m_modem(modem), |
517 | + m_connection(connection) |
518 | +{ |
519 | + m_path.setPath(DBusTypes::modemPath(m_modem->serial())); |
520 | + |
521 | + new ModemAdaptor(this); |
522 | + |
523 | + registerDBusObject(); |
524 | +} |
525 | + |
526 | +DBusModem::~DBusModem() |
527 | +{ |
528 | +} |
529 | + |
530 | +void DBusModem::registerDBusObject() |
531 | +{ |
532 | + if (!m_connection.registerObject(m_path.path(), this)) |
533 | + { |
534 | + qWarning() << "Unable to register Modem object" << m_path.path(); |
535 | + } |
536 | +} |
537 | + |
538 | +void DBusModem::notifyProperties(const QStringList& propertyNames) |
539 | +{ |
540 | + DBusUtils::notifyPropertyChanged( |
541 | + m_connection, |
542 | + *this, |
543 | + m_path.path(), |
544 | + ModemAdaptor::staticMetaObject.classInfo(ModemAdaptor::staticMetaObject.indexOfClassInfo("D-Bus Interface")).value(), |
545 | + propertyNames |
546 | + ); |
547 | +} |
548 | + |
549 | +QDBusObjectPath DBusModem::sim() const |
550 | +{ |
551 | + return m_simpath; |
552 | +} |
553 | + |
554 | +void DBusModem::setSim(QDBusObjectPath path) |
555 | +{ |
556 | + if (m_simpath == path) |
557 | + { |
558 | + return; |
559 | + } |
560 | + m_simpath = path; |
561 | + notifyProperties({"Sim"}); |
562 | +} |
563 | + |
564 | +int DBusModem::index() const |
565 | +{ |
566 | + return m_modem->index(); |
567 | +} |
568 | + |
569 | + |
570 | +QString DBusModem::serial() const |
571 | +{ |
572 | + return m_modem->serial(); |
573 | +} |
574 | + |
575 | +QDBusObjectPath |
576 | +DBusModem::path() const |
577 | +{ |
578 | + return m_path; |
579 | +} |
580 | + |
581 | +} |
582 | |
583 | === added file 'src/indicator/connectivity-service/dbus-modem.h' |
584 | --- src/indicator/connectivity-service/dbus-modem.h 1970-01-01 00:00:00 +0000 |
585 | +++ src/indicator/connectivity-service/dbus-modem.h 2016-05-16 07:44:17 +0000 |
586 | @@ -0,0 +1,83 @@ |
587 | +/* |
588 | + * Copyright (C) 2016 Canonical, Ltd. |
589 | + * |
590 | + * This program is free software: you can redistribute it and/or modify it |
591 | + * under the terms of the GNU General Public License version 3, as published |
592 | + * by the Free Software Foundation. |
593 | + * |
594 | + * This program is distributed in the hope that it will be useful, but |
595 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
596 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
597 | + * PURPOSE. See the GNU General Public License for more details. |
598 | + * |
599 | + * You should have received a copy of the GNU General Public License along |
600 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
601 | + * |
602 | + * Authors: |
603 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
604 | + */ |
605 | + |
606 | +#pragma once |
607 | + |
608 | +#include <nmofono/wwan/modem.h> |
609 | + |
610 | +#include <QDBusConnection> |
611 | +#include <QDBusContext> |
612 | +#include <QDBusObjectPath> |
613 | +#include <QObject> |
614 | +#include <QString> |
615 | + |
616 | +#include <unity/util/DefinesPtrs.h> |
617 | + |
618 | +class ModemAdaptor; |
619 | + |
620 | +namespace connectivity_service |
621 | +{ |
622 | + |
623 | +class DBusModem: public QObject, protected QDBusContext |
624 | +{ |
625 | + Q_OBJECT |
626 | + Q_DISABLE_COPY(DBusModem) |
627 | + |
628 | + friend ModemAdaptor; |
629 | + |
630 | +public: |
631 | + UNITY_DEFINES_PTRS(DBusModem); |
632 | + |
633 | + DBusModem(nmofono::wwan::Modem::Ptr modem, const QDBusConnection& connection); |
634 | + |
635 | + virtual ~DBusModem(); |
636 | + |
637 | + Q_PROPERTY(int Index READ index) |
638 | + int index() const; |
639 | + |
640 | + Q_PROPERTY(QString Serial READ serial) |
641 | + QString serial() const; |
642 | + |
643 | + Q_PROPERTY(QDBusObjectPath Sim READ sim) |
644 | + QDBusObjectPath sim() const; |
645 | + |
646 | + void setSim(QDBusObjectPath path); |
647 | + |
648 | + QDBusObjectPath path() const; |
649 | + |
650 | +Q_SIGNALS: |
651 | + |
652 | +protected Q_SLOTS: |
653 | + |
654 | +private: |
655 | + void notifyProperties(const QStringList& propertyNames); |
656 | + |
657 | +protected: |
658 | + void registerDBusObject(); |
659 | + |
660 | + nmofono::wwan::Modem::Ptr m_modem; |
661 | + |
662 | + QDBusConnection m_connection; |
663 | + |
664 | + QDBusObjectPath m_path; |
665 | + QDBusObjectPath m_simpath; |
666 | + |
667 | +}; |
668 | + |
669 | +} |
670 | |
671 | === added file 'src/indicator/connectivity-service/dbus-sim.cpp' |
672 | --- src/indicator/connectivity-service/dbus-sim.cpp 1970-01-01 00:00:00 +0000 |
673 | +++ src/indicator/connectivity-service/dbus-sim.cpp 2016-05-16 07:44:17 +0000 |
674 | @@ -0,0 +1,148 @@ |
675 | +/* |
676 | + * Copyright (C) 2016 Canonical, Ltd. |
677 | + * |
678 | + * This program is free software: you can redistribute it and/or modify it |
679 | + * under the terms of the GNU General Public License version 3, as published |
680 | + * by the Free Software Foundation. |
681 | + * |
682 | + * This program is distributed in the hope that it will be useful, but |
683 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
684 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
685 | + * PURPOSE. See the GNU General Public License for more details. |
686 | + * |
687 | + * You should have received a copy of the GNU General Public License along |
688 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
689 | + * |
690 | + * Authors: |
691 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
692 | + */ |
693 | + |
694 | +#include <connectivity-service/dbus-sim.h> |
695 | +#include <SimAdaptor.h> |
696 | +#include <dbus-types.h> |
697 | +#include <util/dbus-utils.h> |
698 | + |
699 | +#include <QDebug> |
700 | + |
701 | +using namespace std; |
702 | +using namespace nmofono::wwan; |
703 | + |
704 | +namespace connectivity_service |
705 | +{ |
706 | + |
707 | +DBusSim::DBusSim(Sim::Ptr sim, |
708 | + const QDBusConnection& connection) : |
709 | + m_sim(sim), |
710 | + m_connection(connection) |
711 | +{ |
712 | + m_path.setPath(DBusTypes::simPath(m_sim->imsi())); |
713 | + |
714 | + new SimAdaptor(this); |
715 | + |
716 | + registerDBusObject(); |
717 | + |
718 | + connect(sim.get(), &Sim::lockedChanged, this, &DBusSim::lockedChanged); |
719 | + connect(sim.get(), &Sim::presentChanged, this, &DBusSim::presentChanged); |
720 | + connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &DBusSim::dataRoamingEnabledChanged); |
721 | +} |
722 | + |
723 | +DBusSim::~DBusSim() |
724 | +{ |
725 | +} |
726 | + |
727 | +QDBusObjectPath DBusSim::path() const |
728 | +{ |
729 | + return m_path; |
730 | +} |
731 | + |
732 | +void DBusSim::registerDBusObject() |
733 | +{ |
734 | + if (!m_connection.registerObject(m_path.path(), this)) |
735 | + { |
736 | + qWarning() << "Unable to register SIM object" << m_path.path(); |
737 | + } |
738 | +} |
739 | + |
740 | +void DBusSim::notifyProperties(const QStringList& propertyNames) |
741 | +{ |
742 | + DBusUtils::notifyPropertyChanged( |
743 | + m_connection, |
744 | + *this, |
745 | + m_path.path(), |
746 | + SimAdaptor::staticMetaObject.classInfo(SimAdaptor::staticMetaObject.indexOfClassInfo("D-Bus Interface")).value(), |
747 | + propertyNames |
748 | + ); |
749 | +} |
750 | + |
751 | +QString DBusSim::imsi() const |
752 | +{ |
753 | + return m_sim->imsi(); |
754 | +} |
755 | + |
756 | +QString DBusSim::primaryPhoneNumber() const |
757 | +{ |
758 | + return m_sim->primaryPhoneNumber(); |
759 | +} |
760 | + |
761 | +bool DBusSim::locked() const |
762 | +{ |
763 | + return m_sim->locked(); |
764 | +} |
765 | + |
766 | +bool DBusSim::present() const |
767 | +{ |
768 | + return m_sim->present(); |
769 | +} |
770 | + |
771 | +QString DBusSim::mcc() const |
772 | +{ |
773 | + return m_sim->mcc(); |
774 | +} |
775 | + |
776 | +QString DBusSim::mnc() const |
777 | +{ |
778 | + return m_sim->mnc(); |
779 | +} |
780 | + |
781 | +QStringList DBusSim::preferredLanguages() const |
782 | +{ |
783 | + return m_sim->preferredLanguages(); |
784 | +} |
785 | + |
786 | +bool DBusSim::dataRoamingEnabled() const |
787 | +{ |
788 | + return m_sim->dataRoamingEnabled(); |
789 | +} |
790 | + |
791 | +void DBusSim::setDataRoamingEnabled(bool value) const |
792 | +{ |
793 | + m_sim->setDataRoamingEnabled(value); |
794 | +} |
795 | + |
796 | +void DBusSim::Unlock() |
797 | +{ |
798 | + m_sim->unlock(); |
799 | +} |
800 | + |
801 | +void DBusSim::lockedChanged() |
802 | +{ |
803 | + notifyProperties({"Locked"}); |
804 | +} |
805 | + |
806 | +void DBusSim::presentChanged() |
807 | +{ |
808 | + notifyProperties({"Present"}); |
809 | +} |
810 | + |
811 | +void DBusSim::dataRoamingEnabledChanged() |
812 | +{ |
813 | + notifyProperties({"DataRoamingEnabled"}); |
814 | +} |
815 | + |
816 | +nmofono::wwan::Sim::Ptr DBusSim::sim() const |
817 | +{ |
818 | + return m_sim; |
819 | +} |
820 | + |
821 | + |
822 | +} |
823 | |
824 | === added file 'src/indicator/connectivity-service/dbus-sim.h' |
825 | --- src/indicator/connectivity-service/dbus-sim.h 1970-01-01 00:00:00 +0000 |
826 | +++ src/indicator/connectivity-service/dbus-sim.h 2016-05-16 07:44:17 +0000 |
827 | @@ -0,0 +1,103 @@ |
828 | +/* |
829 | + * Copyright (C) 2016 Canonical, Ltd. |
830 | + * |
831 | + * This program is free software: you can redistribute it and/or modify it |
832 | + * under the terms of the GNU General Public License version 3, as published |
833 | + * by the Free Software Foundation. |
834 | + * |
835 | + * This program is distributed in the hope that it will be useful, but |
836 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
837 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
838 | + * PURPOSE. See the GNU General Public License for more details. |
839 | + * |
840 | + * You should have received a copy of the GNU General Public License along |
841 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
842 | + * |
843 | + * Authors: |
844 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
845 | + */ |
846 | + |
847 | +#pragma once |
848 | + |
849 | +#include <nmofono/wwan/sim.h> |
850 | + |
851 | +#include <QDBusConnection> |
852 | +#include <QDBusContext> |
853 | +#include <QDBusObjectPath> |
854 | +#include <QObject> |
855 | +#include <QString> |
856 | + |
857 | +#include <unity/util/DefinesPtrs.h> |
858 | + |
859 | +class SimAdaptor; |
860 | + |
861 | +namespace connectivity_service |
862 | +{ |
863 | + |
864 | +class DBusSim: public QObject, protected QDBusContext |
865 | +{ |
866 | + Q_OBJECT |
867 | + Q_DISABLE_COPY(DBusSim) |
868 | + |
869 | + friend SimAdaptor; |
870 | + |
871 | +public: |
872 | + UNITY_DEFINES_PTRS(DBusSim); |
873 | + |
874 | + DBusSim(nmofono::wwan::Sim::Ptr sim, const QDBusConnection& connection); |
875 | + |
876 | + virtual ~DBusSim(); |
877 | + |
878 | + Q_PROPERTY(QString Imsi READ imsi) |
879 | + QString imsi() const; |
880 | + |
881 | + Q_PROPERTY(QString PrimaryPhoneNumber READ primaryPhoneNumber) |
882 | + QString primaryPhoneNumber() const; |
883 | + |
884 | + Q_PROPERTY(bool Locked READ locked) |
885 | + bool locked() const; |
886 | + |
887 | + Q_PROPERTY(bool Present READ present) |
888 | + bool present() const; |
889 | + |
890 | + Q_PROPERTY(QString Mcc READ mcc) |
891 | + QString mcc() const; |
892 | + |
893 | + Q_PROPERTY(QString Mnc READ mnc) |
894 | + QString mnc() const; |
895 | + |
896 | + Q_PROPERTY(QStringList PreferredLanguages READ preferredLanguages) |
897 | + QStringList preferredLanguages() const; |
898 | + |
899 | + Q_PROPERTY(bool DataRoamingEnabled READ dataRoamingEnabled WRITE setDataRoamingEnabled) |
900 | + bool dataRoamingEnabled() const; |
901 | + void setDataRoamingEnabled(bool value) const; |
902 | + |
903 | + QDBusObjectPath path() const; |
904 | + |
905 | + nmofono::wwan::Sim::Ptr sim() const; |
906 | + |
907 | +Q_SIGNALS: |
908 | + |
909 | +protected Q_SLOTS: |
910 | + |
911 | + void Unlock(); |
912 | + |
913 | + void lockedChanged(); |
914 | + void presentChanged(); |
915 | + void dataRoamingEnabledChanged(); |
916 | + |
917 | +private: |
918 | + void notifyProperties(const QStringList& propertyNames); |
919 | + |
920 | +protected: |
921 | + void registerDBusObject(); |
922 | + |
923 | + nmofono::wwan::Sim::Ptr m_sim; |
924 | + |
925 | + QDBusConnection m_connection; |
926 | + |
927 | + QDBusObjectPath m_path; |
928 | +}; |
929 | + |
930 | +} |
931 | |
932 | === added file 'src/indicator/nmofono/connectivity-service-settings.cpp' |
933 | --- src/indicator/nmofono/connectivity-service-settings.cpp 1970-01-01 00:00:00 +0000 |
934 | +++ src/indicator/nmofono/connectivity-service-settings.cpp 2016-05-16 07:44:17 +0000 |
935 | @@ -0,0 +1,148 @@ |
936 | +/* |
937 | + * Copyright (C) 2016 Canonical, Ltd. |
938 | + * |
939 | + * This program is free software: you can redistribute it and/or modify it |
940 | + * under the terms of the GNU General Public License version 3, as published |
941 | + * by the Free Software Foundation. |
942 | + * |
943 | + * This program is distributed in the hope that it will be useful, but |
944 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
945 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
946 | + * PURPOSE. See the GNU General Public License for more details. |
947 | + * |
948 | + * You should have received a copy of the GNU General Public License along |
949 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
950 | + * |
951 | + * Authors: |
952 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
953 | + */ |
954 | + |
955 | +#include <nmofono/connectivity-service-settings.h> |
956 | + |
957 | +using namespace nmofono; |
958 | + |
959 | +class ConnectivityServiceSettings::Private : public QObject |
960 | +{ |
961 | + Q_OBJECT |
962 | +public: |
963 | + |
964 | + ConnectivityServiceSettings &p; |
965 | + QSettings *m_settings; |
966 | + |
967 | + Private(ConnectivityServiceSettings &parent) |
968 | + : p(parent) |
969 | + { |
970 | + m_settings = new QSettings(QSettings::IniFormat, |
971 | + QSettings::UserScope, |
972 | + "Ubuntu", |
973 | + "connectivityservice", |
974 | + this); |
975 | + } |
976 | + |
977 | + virtual ~Private() |
978 | + { |
979 | + |
980 | + } |
981 | + |
982 | +public Q_SLOTS: |
983 | + |
984 | +Q_SIGNALS: |
985 | + |
986 | +}; |
987 | + |
988 | +ConnectivityServiceSettings::ConnectivityServiceSettings(QObject *parent) |
989 | + : QObject(parent), |
990 | + d{new Private(*this)} |
991 | +{ |
992 | + |
993 | +} |
994 | + |
995 | +ConnectivityServiceSettings::~ConnectivityServiceSettings() |
996 | +{ |
997 | + |
998 | +} |
999 | + |
1000 | +QVariant ConnectivityServiceSettings::mobileDataEnabled() |
1001 | +{ |
1002 | + return d->m_settings->value("MobileDataEnabled"); |
1003 | +} |
1004 | +void ConnectivityServiceSettings::setMobileDataEnabled(bool value) |
1005 | +{ |
1006 | + d->m_settings->setValue("MobileDataEnabled", value); |
1007 | + d->m_settings->sync(); |
1008 | +} |
1009 | + |
1010 | +QVariant ConnectivityServiceSettings::simForMobileData() |
1011 | +{ |
1012 | + return d->m_settings->value("SimForMobileData"); |
1013 | +} |
1014 | +void ConnectivityServiceSettings::setSimForMobileData(const QString &imsi) |
1015 | +{ |
1016 | + d->m_settings->setValue("SimForMobileData", imsi); |
1017 | + d->m_settings->sync(); |
1018 | +} |
1019 | + |
1020 | +QStringList ConnectivityServiceSettings::knownSims() |
1021 | +{ |
1022 | + QVariant ret; |
1023 | + ret = d->m_settings->value("KnownSims"); |
1024 | + if (ret.isNull()) |
1025 | + { |
1026 | + /* This is the first time we are running on a system. |
1027 | + */ |
1028 | + setKnownSims(QStringList()); |
1029 | + return QStringList(); |
1030 | + } |
1031 | + |
1032 | + return ret.toStringList(); |
1033 | +} |
1034 | + |
1035 | +void ConnectivityServiceSettings::setKnownSims(const QStringList &list) |
1036 | +{ |
1037 | + d->m_settings->setValue("KnownSims", QVariant(list)); |
1038 | + d->m_settings->sync(); |
1039 | +} |
1040 | + |
1041 | +wwan::Sim::Ptr ConnectivityServiceSettings::createSimFromSettings(const QString &imsi) |
1042 | +{ |
1043 | + d->m_settings->beginGroup(QString("Sims/%1/").arg(imsi)); |
1044 | + QVariant primaryPhoneNumber_var = d->m_settings->value("PrimaryPhoneNumber"); |
1045 | + QVariant mcc_var = d->m_settings->value("Mcc"); |
1046 | + QVariant mnc_var = d->m_settings->value("Mnc"); |
1047 | + QVariant preferredLanguages_var = d->m_settings->value("PreferredLanguages"); |
1048 | + QVariant dataRoamingEnabled_var = d->m_settings->value("DataRoamingEnabled"); |
1049 | + d->m_settings->endGroup(); |
1050 | + |
1051 | + if (imsi.isNull() || |
1052 | + primaryPhoneNumber_var.isNull() || |
1053 | + mcc_var.isNull() || |
1054 | + mnc_var.isNull() || |
1055 | + preferredLanguages_var.isNull() || |
1056 | + dataRoamingEnabled_var.isNull()) |
1057 | + { |
1058 | + qWarning() << "Corrupt settings for SIM: " << imsi; |
1059 | + d->m_settings->remove(QString("Sims/%1/").arg(imsi)); |
1060 | + return wwan::Sim::Ptr(); |
1061 | + } |
1062 | + |
1063 | + return wwan::Sim::Ptr(new wwan::Sim(imsi, |
1064 | + primaryPhoneNumber_var.toString(), |
1065 | + mcc_var.toString(), |
1066 | + mnc_var.toString(), |
1067 | + preferredLanguages_var.toStringList(), |
1068 | + dataRoamingEnabled_var.toBool())); |
1069 | +} |
1070 | + |
1071 | +void ConnectivityServiceSettings::saveSimToSettings(wwan::Sim::Ptr sim) |
1072 | +{ |
1073 | + d->m_settings->beginGroup(QString("Sims/%1/").arg(sim->imsi())); |
1074 | + d->m_settings->setValue("PrimaryPhoneNumber", QVariant(sim->primaryPhoneNumber())); |
1075 | + d->m_settings->setValue("Mcc", sim->mcc()); |
1076 | + d->m_settings->setValue("Mnc", sim->mnc()); |
1077 | + d->m_settings->setValue("PreferredLanguages", QVariant(sim->preferredLanguages())); |
1078 | + d->m_settings->setValue("DataRoamingEnabled", sim->dataRoamingEnabled()); |
1079 | + d->m_settings->endGroup(); |
1080 | + d->m_settings->sync(); |
1081 | +} |
1082 | + |
1083 | +#include "connectivity-service-settings.moc" |
1084 | |
1085 | === added file 'src/indicator/nmofono/connectivity-service-settings.h' |
1086 | --- src/indicator/nmofono/connectivity-service-settings.h 1970-01-01 00:00:00 +0000 |
1087 | +++ src/indicator/nmofono/connectivity-service-settings.h 2016-05-16 07:44:17 +0000 |
1088 | @@ -0,0 +1,67 @@ |
1089 | +/* |
1090 | + * Copyright (C) 2016 Canonical, Ltd. |
1091 | + * |
1092 | + * This program is free software: you can redistribute it and/or modify it |
1093 | + * under the terms of the GNU General Public License version 3, as published |
1094 | + * by the Free Software Foundation. |
1095 | + * |
1096 | + * This program is distributed in the hope that it will be useful, but |
1097 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
1098 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1099 | + * PURPOSE. See the GNU General Public License for more details. |
1100 | + * |
1101 | + * You should have received a copy of the GNU General Public License along |
1102 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
1103 | + * |
1104 | + * Authors: |
1105 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
1106 | + */ |
1107 | + |
1108 | +#pragma once |
1109 | + |
1110 | +#include <QObject> |
1111 | +#include <QSettings> |
1112 | +#include <QString> |
1113 | + |
1114 | +#include <nmofono/wwan/sim.h> |
1115 | + |
1116 | +#include <memory> |
1117 | + |
1118 | + |
1119 | +namespace nmofono |
1120 | +{ |
1121 | + |
1122 | +class ConnectivityServiceSettings : public QObject |
1123 | +{ |
1124 | + Q_OBJECT |
1125 | + |
1126 | + class Private; |
1127 | + std::shared_ptr<Private> d; |
1128 | + |
1129 | +public: |
1130 | + |
1131 | + typedef std::shared_ptr<ConnectivityServiceSettings> Ptr; |
1132 | + typedef std::weak_ptr<ConnectivityServiceSettings> WeakPtr; |
1133 | + |
1134 | + ConnectivityServiceSettings(QObject *parent = 0); |
1135 | + virtual ~ConnectivityServiceSettings(); |
1136 | + |
1137 | + QVariant mobileDataEnabled(); |
1138 | + void setMobileDataEnabled(bool value); |
1139 | + |
1140 | + QVariant simForMobileData(); |
1141 | + void setSimForMobileData(const QString &imsi); |
1142 | + |
1143 | + QStringList knownSims(); |
1144 | + void setKnownSims(const QStringList &list); |
1145 | + |
1146 | + wwan::Sim::Ptr createSimFromSettings(const QString &imsi); |
1147 | + void saveSimToSettings(wwan::Sim::Ptr sim); |
1148 | + |
1149 | +public Q_SLOTS: |
1150 | + |
1151 | +Q_SIGNALS: |
1152 | + |
1153 | +}; |
1154 | + |
1155 | +} |
1156 | |
1157 | === modified file 'src/indicator/nmofono/manager-impl.cpp' |
1158 | --- src/indicator/nmofono/manager-impl.cpp 2016-04-06 09:30:45 +0000 |
1159 | +++ src/indicator/nmofono/manager-impl.cpp 2016-05-16 07:44:17 +0000 |
1160 | @@ -19,7 +19,9 @@ |
1161 | */ |
1162 | |
1163 | #include <nmofono/manager-impl.h> |
1164 | +#include <nmofono/connectivity-service-settings.h> |
1165 | #include <nmofono/wifi/wifi-link-impl.h> |
1166 | +#include <nmofono/wwan/sim-manager.h> |
1167 | #include <NetworkManagerActiveConnectionInterface.h> |
1168 | #include <NetworkManagerDeviceInterface.h> |
1169 | #include <NetworkManagerInterface.h> |
1170 | @@ -30,6 +32,7 @@ |
1171 | #include <qofono-qt5/qofonomanager.h> |
1172 | #include <qofono-qt5/qofonomodem.h> |
1173 | #undef slots |
1174 | +#include <ofono/dbus.h> |
1175 | |
1176 | #include <notify-cpp/notification-manager.h> |
1177 | #include <notify-cpp/snapdecision/sim-unlock.h> |
1178 | @@ -39,6 +42,7 @@ |
1179 | #include <QMap> |
1180 | #include <QList> |
1181 | #include <QRegularExpression> |
1182 | +#include <QSettings> |
1183 | #include <NetworkManager.h> |
1184 | #include <QDebug> |
1185 | #include <algorithm> |
1186 | @@ -76,9 +80,110 @@ |
1187 | |
1188 | HotspotManager::SPtr m_hotspotManager; |
1189 | |
1190 | + bool m_mobileDataEnabled = false; |
1191 | + bool m_mobileDataEnabledPending = false; |
1192 | + |
1193 | + wwan::Sim::Ptr m_simForMobileData; |
1194 | + bool m_simForMobileDataPending = false; |
1195 | + |
1196 | + QList<wwan::Modem::Ptr> m_modems; |
1197 | + QList<wwan::Sim::Ptr> m_sims; |
1198 | + |
1199 | + wwan::SimManager::Ptr m_simManager; |
1200 | + |
1201 | + ConnectivityServiceSettings::Ptr m_settings; |
1202 | + |
1203 | Private(Manager& parent) : |
1204 | p(parent) |
1205 | { |
1206 | + m_settings = std::make_shared<ConnectivityServiceSettings>(); |
1207 | + |
1208 | + m_simManager = make_shared<wwan::SimManager>(m_settings); |
1209 | + m_sims = m_simManager->knownSims(); |
1210 | + connect(m_simManager.get(), &wwan::SimManager::simAdded, this, &Private::simAdded); |
1211 | + |
1212 | + QVariant ret = m_settings->mobileDataEnabled(); |
1213 | + if (ret.isNull()) |
1214 | + { |
1215 | + /* This is the first time we are running on a system. |
1216 | + * |
1217 | + * We need to figure out the status of mobile data from looking |
1218 | + * at the individual modems. |
1219 | + */ |
1220 | + m_mobileDataEnabledPending = true; |
1221 | + m_settings->setMobileDataEnabled(false); |
1222 | + } |
1223 | + else |
1224 | + { |
1225 | + m_mobileDataEnabled = ret.toBool(); |
1226 | + } |
1227 | + |
1228 | + ret = m_settings->simForMobileData(); |
1229 | + if (ret.isNull()) |
1230 | + { |
1231 | + /* This is the first time we are running on a system. |
1232 | + * |
1233 | + * We need to figure out the SIM used for mobile data |
1234 | + * from the individual modems. |
1235 | + */ |
1236 | + m_simForMobileDataPending = true; |
1237 | + m_settings->setSimForMobileData(QString()); |
1238 | + } |
1239 | + else |
1240 | + { |
1241 | + QString imsi = ret.toString(); |
1242 | + wwan::Sim::Ptr sim; |
1243 | + for(auto i = m_sims.begin(); i != m_sims.end(); i++) |
1244 | + { |
1245 | + if ((*i)->imsi() == imsi) { |
1246 | + sim = *i; |
1247 | + break; |
1248 | + } |
1249 | + } |
1250 | + m_simForMobileData = sim; |
1251 | + } |
1252 | + |
1253 | + } |
1254 | + |
1255 | + void matchModemsAndSims() |
1256 | + { |
1257 | + for (wwan::Modem::Ptr modem: m_modems) |
1258 | + { |
1259 | + bool match = false; |
1260 | + for(wwan::Sim::Ptr sim : m_sims) |
1261 | + { |
1262 | + if (sim->ofonoPath() == modem->ofonoPath()) |
1263 | + { |
1264 | + match = true; |
1265 | + modem->setSim(sim); |
1266 | + break; |
1267 | + } |
1268 | + } |
1269 | + if (!match) |
1270 | + { |
1271 | + modem->setSim(wwan::Sim::Ptr()); |
1272 | + } |
1273 | + } |
1274 | + } |
1275 | + |
1276 | + void simAdded(wwan::Sim::Ptr sim) |
1277 | + { |
1278 | + m_sims.append(sim); |
1279 | + matchModemsAndSims(); |
1280 | + Q_EMIT p.simsChanged(); |
1281 | + } |
1282 | + |
1283 | + void modemReady() |
1284 | + { |
1285 | + wwan::Modem *modem_raw = qobject_cast<wwan::Modem*>(sender()); |
1286 | + if (!modem_raw) |
1287 | + { |
1288 | + Q_ASSERT(0); |
1289 | + return; |
1290 | + } |
1291 | + m_modems.append(m_ofonoLinks[modem_raw->name()]); |
1292 | + matchModemsAndSims(); |
1293 | + Q_EMIT p.modemsChanged(); |
1294 | } |
1295 | |
1296 | void setUnstoppableOperationHappening(bool happening) |
1297 | @@ -192,6 +297,8 @@ |
1298 | m_pendingUnlocks.removeOne(modem); |
1299 | disconnect(modem.get(), &wwan::Modem::readyToUnlock, this, &Private::modemReadyToUnlock); |
1300 | } |
1301 | + m_modems.removeAll(modem); |
1302 | + Q_EMIT p.modemsChanged(); |
1303 | } |
1304 | |
1305 | for (const auto& path : toAdd) |
1306 | @@ -202,6 +309,7 @@ |
1307 | auto modem = make_shared<wwan::Modem>(modemInterface); |
1308 | m_ofonoLinks[path] = modem; |
1309 | connect(modem.get(), &wwan::Modem::readyToUnlock, this, &Private::modemReadyToUnlock); |
1310 | + connect(modem.get(), &wwan::Modem::ready, this, &Private::modemReady); |
1311 | } |
1312 | |
1313 | Q_EMIT p.linksUpdated(); |
1314 | @@ -209,6 +317,67 @@ |
1315 | |
1316 | updateModemAvailable(); |
1317 | } |
1318 | + |
1319 | + void setMobileDataEnabled(bool value) { |
1320 | + if (m_mobileDataEnabled == value) |
1321 | + { |
1322 | + return; |
1323 | + } |
1324 | + |
1325 | + m_settings->setMobileDataEnabled(value); |
1326 | + m_mobileDataEnabled = value; |
1327 | + Q_EMIT p.mobileDataEnabledChanged(value); |
1328 | + |
1329 | + if (m_mobileDataEnabled) |
1330 | + { |
1331 | + for (wwan::Modem::Ptr modem : m_modems) |
1332 | + { |
1333 | + if (modem->sim() && modem->sim() == m_simForMobileData) |
1334 | + { |
1335 | + modem->sim()->setMobileDataEnabled(true); |
1336 | + } |
1337 | + } |
1338 | + } |
1339 | + else |
1340 | + { |
1341 | + for (wwan::Modem::Ptr modem : m_modems) |
1342 | + { |
1343 | + if (modem->sim()) { |
1344 | + modem->sim()->setMobileDataEnabled(false); |
1345 | + } |
1346 | + } |
1347 | + } |
1348 | + } |
1349 | + |
1350 | + void setSimForMobileData(wwan::Sim::Ptr sim) { |
1351 | + if (m_simForMobileData == sim) |
1352 | + { |
1353 | + return; |
1354 | + } |
1355 | + |
1356 | + if (m_simForMobileData) |
1357 | + { |
1358 | + m_simForMobileData->setMobileDataEnabled(false); |
1359 | + } |
1360 | + |
1361 | + if (!sim) |
1362 | + { |
1363 | + m_settings->setSimForMobileData(""); |
1364 | + } |
1365 | + else |
1366 | + { |
1367 | + m_settings->setSimForMobileData(sim->imsi()); |
1368 | + } |
1369 | + |
1370 | + |
1371 | + m_simForMobileData = sim; |
1372 | + if (m_simForMobileData) |
1373 | + { |
1374 | + m_simForMobileData->setMobileDataEnabled(p.mobileDataEnabled()); |
1375 | + } |
1376 | + |
1377 | + Q_EMIT p.simForMobileDataChanged(); |
1378 | + } |
1379 | }; |
1380 | |
1381 | void |
1382 | @@ -506,7 +675,8 @@ |
1383 | bool |
1384 | ManagerImpl::roaming() const |
1385 | { |
1386 | - for (auto modem : d->m_ofonoLinks) { |
1387 | + for (auto modem : d->m_ofonoLinks) |
1388 | + { |
1389 | if (modem->modemStatus() == wwan::Modem::ModemStatus::roaming) { |
1390 | return true; |
1391 | } |
1392 | @@ -522,7 +692,9 @@ |
1393 | if (!d->m_ofonoLinks.values().contains(modem) |
1394 | || d->m_unlockDialog->modem() == modem |
1395 | || count(d->m_pendingUnlocks.begin(), d->m_pendingUnlocks.end(), modem) != 0) |
1396 | + { |
1397 | return; |
1398 | + } |
1399 | |
1400 | if (d->m_unlockDialog->state() == SimUnlockDialog::State::ready |
1401 | && (d->m_pendingUnlocks.size() == 0)) |
1402 | @@ -652,6 +824,43 @@ |
1403 | d->m_hotspotManager->setAuth(auth); |
1404 | } |
1405 | |
1406 | +bool |
1407 | +ManagerImpl::mobileDataEnabled() const |
1408 | +{ |
1409 | + return d->m_mobileDataEnabled; |
1410 | +} |
1411 | + |
1412 | +void |
1413 | +ManagerImpl::setMobileDataEnabled(bool value) |
1414 | +{ |
1415 | + d->setMobileDataEnabled(value); |
1416 | +} |
1417 | + |
1418 | +wwan::Sim::Ptr |
1419 | +ManagerImpl::simForMobileData() const |
1420 | +{ |
1421 | + return d->m_simForMobileData; |
1422 | +} |
1423 | + |
1424 | +void |
1425 | +ManagerImpl::setSimForMobileData(wwan::Sim::Ptr sim) |
1426 | +{ |
1427 | + d->setSimForMobileData(sim); |
1428 | +} |
1429 | + |
1430 | +QList<wwan::Modem::Ptr> |
1431 | +ManagerImpl::modems() const |
1432 | +{ |
1433 | + return d->m_modems; |
1434 | +} |
1435 | + |
1436 | +QList<wwan::Sim::Ptr> |
1437 | +ManagerImpl::sims() const |
1438 | +{ |
1439 | + return d->m_sims; |
1440 | +} |
1441 | + |
1442 | + |
1443 | } |
1444 | |
1445 | #include "manager-impl.moc" |
1446 | |
1447 | === modified file 'src/indicator/nmofono/manager-impl.h' |
1448 | --- src/indicator/nmofono/manager-impl.h 2015-10-06 10:19:30 +0000 |
1449 | +++ src/indicator/nmofono/manager-impl.h 2016-05-16 07:44:17 +0000 |
1450 | @@ -91,6 +91,14 @@ |
1451 | |
1452 | QString hotspotAuth() const override; |
1453 | |
1454 | + bool mobileDataEnabled() const override; |
1455 | + |
1456 | + wwan::Sim::Ptr simForMobileData() const override; |
1457 | + |
1458 | + QList<wwan::Modem::Ptr> modems() const override; |
1459 | + |
1460 | + QList<wwan::Sim::Ptr> sims() const override; |
1461 | + |
1462 | void setHotspotEnabled(bool) override; |
1463 | |
1464 | void setHotspotSsid(const QByteArray&) override; |
1465 | @@ -101,6 +109,10 @@ |
1466 | |
1467 | void setHotspotAuth(const QString&) override; |
1468 | |
1469 | + void setMobileDataEnabled(bool) override; |
1470 | + |
1471 | + void setSimForMobileData(wwan::Sim::Ptr) override; |
1472 | + |
1473 | private Q_SLOTS: |
1474 | void device_added(const QDBusObjectPath &path); |
1475 | void device_removed(const QDBusObjectPath &path); |
1476 | |
1477 | === modified file 'src/indicator/nmofono/manager.h' |
1478 | --- src/indicator/nmofono/manager.h 2015-09-15 12:35:22 +0000 |
1479 | +++ src/indicator/nmofono/manager.h 2016-05-16 07:44:17 +0000 |
1480 | @@ -23,6 +23,7 @@ |
1481 | #include <nmofono/link.h> |
1482 | #include <nmofono/wifi/wifi-link.h> |
1483 | #include <nmofono/wwan/modem.h> |
1484 | +#include <nmofono/wwan/sim.h> |
1485 | |
1486 | #include <memory> |
1487 | #include <QSet> |
1488 | @@ -143,6 +144,19 @@ |
1489 | Q_PROPERTY(QString hotspotAuth READ hotspotAuth WRITE setHotspotAuth NOTIFY hotspotAuthChanged) |
1490 | virtual QString hotspotAuth() const = 0; |
1491 | |
1492 | + Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledChanged) |
1493 | + virtual bool mobileDataEnabled() const = 0; |
1494 | + |
1495 | + Q_PROPERTY(wwan::Sim::Ptr simForMobileData READ simForMobileData WRITE setSimForMobileData NOTIFY simForMobileDataChanged) |
1496 | + virtual wwan::Sim::Ptr simForMobileData() const = 0; |
1497 | + |
1498 | + Q_PROPERTY(QList<wwan::Modem::Ptr> modems READ modems NOTIFY modemsChanged) |
1499 | + virtual QList<wwan::Modem::Ptr> modems() const = 0; |
1500 | + |
1501 | + Q_PROPERTY(QList<wwan::Sim::Ptr> sims READ sims NOTIFY simsChanged) |
1502 | + virtual QList<wwan::Sim::Ptr> sims() const = 0; |
1503 | + |
1504 | + |
1505 | Q_SIGNALS: |
1506 | void flightModeUpdated(bool); |
1507 | |
1508 | @@ -174,6 +188,14 @@ |
1509 | |
1510 | void unstoppableOperationHappeningUpdated(bool); |
1511 | |
1512 | + void mobileDataEnabledChanged(bool); |
1513 | + |
1514 | + void simForMobileDataChanged(); |
1515 | + |
1516 | + void modemsChanged(); |
1517 | + |
1518 | + void simsChanged(); |
1519 | + |
1520 | public Q_SLOTS: |
1521 | virtual void setWifiEnabled(bool) = 0; |
1522 | |
1523 | @@ -189,6 +211,10 @@ |
1524 | |
1525 | virtual void setHotspotAuth(const QString&) = 0; |
1526 | |
1527 | + virtual void setMobileDataEnabled(bool) = 0; |
1528 | + |
1529 | + virtual void setSimForMobileData(wwan::Sim::Ptr) = 0; |
1530 | + |
1531 | protected: |
1532 | /** |
1533 | * @brief The default constructor is protected. |
1534 | |
1535 | === modified file 'src/indicator/nmofono/wwan/modem.cpp' |
1536 | --- src/indicator/nmofono/wwan/modem.cpp 2015-08-05 15:14:28 +0000 |
1537 | +++ src/indicator/nmofono/wwan/modem.cpp 2016-05-16 07:44:17 +0000 |
1538 | @@ -96,6 +96,10 @@ |
1539 | bool m_requiredPinSet = false; |
1540 | bool m_retriesSet = false; |
1541 | |
1542 | + QString m_serial; |
1543 | + bool m_serialSet = false; |
1544 | + bool m_readyFired = false; |
1545 | + |
1546 | QString m_operatorName; |
1547 | Modem::ModemStatus m_status; |
1548 | int8_t m_strength; |
1549 | @@ -108,6 +112,8 @@ |
1550 | |
1551 | QSet<QString> m_interfaces; |
1552 | |
1553 | + Sim::Ptr m_sim; |
1554 | + |
1555 | shared_ptr<QOfonoConnectionManager> m_connectionManager; |
1556 | shared_ptr<QOfonoNetworkRegistration> m_networkRegistration; |
1557 | shared_ptr<QOfonoSimManager> m_simManager; |
1558 | @@ -125,6 +131,9 @@ |
1559 | connect(m_ofonoModem.get(), &QOfonoModem::interfacesChanged, this, &Private::interfacesChanged); |
1560 | interfacesChanged(m_ofonoModem->interfaces()); |
1561 | |
1562 | + connect(m_ofonoModem.get(), &QOfonoModem::serialChanged, this, &Private::serialChanged); |
1563 | + serialChanged(m_ofonoModem->serial()); |
1564 | + |
1565 | /// @todo hook up with system-settings to allow changing the identifier. |
1566 | /// for now just provide the defaults |
1567 | auto path = m_ofonoModem->modemPath(); |
1568 | @@ -154,6 +163,28 @@ |
1569 | m_shouldTriggerUnlock = false; |
1570 | Q_EMIT p.readyToUnlock(p.name()); |
1571 | } |
1572 | + |
1573 | + if (m_serialSet && !m_readyFired) |
1574 | + { |
1575 | + m_readyFired = true; |
1576 | + Q_EMIT p.ready(); |
1577 | + } |
1578 | + } |
1579 | + |
1580 | + void serialChanged(const QString &value) { |
1581 | + if (m_serial == value) |
1582 | + { |
1583 | + return; |
1584 | + } |
1585 | + if (m_serialSet) |
1586 | + { |
1587 | + qWarning() << "Unexpected update on SERIAL: " << m_serial << ", " << value; |
1588 | + } |
1589 | + |
1590 | + m_serial = value; |
1591 | + m_serialSet = true; |
1592 | + |
1593 | + update(); |
1594 | } |
1595 | |
1596 | void connectionManagerChanged(shared_ptr<QOfonoConnectionManager> conmgr) |
1597 | @@ -662,6 +693,12 @@ |
1598 | QString |
1599 | Modem::name() const |
1600 | { |
1601 | + return ofonoPath(); |
1602 | +} |
1603 | + |
1604 | +QString |
1605 | +Modem::ofonoPath() const |
1606 | +{ |
1607 | return d->m_ofonoModem->modemPath(); |
1608 | } |
1609 | |
1610 | @@ -725,8 +762,32 @@ |
1611 | { |
1612 | d->m_shouldTriggerUnlock = true; |
1613 | } |
1614 | -} |
1615 | - |
1616 | + |
1617 | +Sim::Ptr Modem::sim() const |
1618 | +{ |
1619 | + return d->m_sim; |
1620 | +} |
1621 | + |
1622 | +void |
1623 | +Modem::setSim(Sim::Ptr sim) |
1624 | +{ |
1625 | + if (d->m_sim == sim) |
1626 | + { |
1627 | + return; |
1628 | + } |
1629 | + d->m_sim = sim; |
1630 | + Q_EMIT simUpdated(); |
1631 | +} |
1632 | + |
1633 | +QString |
1634 | +Modem::serial() const |
1635 | +{ |
1636 | + return d->m_serial; |
1637 | +} |
1638 | + |
1639 | + |
1640 | + |
1641 | +} |
1642 | } |
1643 | |
1644 | #include "modem.moc" |
1645 | |
1646 | === modified file 'src/indicator/nmofono/wwan/modem.h' |
1647 | --- src/indicator/nmofono/wwan/modem.h 2015-08-05 15:14:28 +0000 |
1648 | +++ src/indicator/nmofono/wwan/modem.h 2016-05-16 07:44:17 +0000 |
1649 | @@ -21,6 +21,8 @@ |
1650 | |
1651 | #include <nmofono/wwan/wwan-link.h> |
1652 | |
1653 | +#include <nmofono/wwan/sim.h> |
1654 | + |
1655 | #include <map> |
1656 | #include <memory> |
1657 | |
1658 | @@ -127,8 +129,12 @@ |
1659 | const QString &simIdentifier() const; |
1660 | |
1661 | int index() const; |
1662 | + Sim::Ptr sim() const; |
1663 | + void setSim(Sim::Ptr sim); |
1664 | + QString serial() const; |
1665 | |
1666 | QString name() const override; |
1667 | + QString ofonoPath() const; |
1668 | |
1669 | WwanType wwanType() const override; |
1670 | |
1671 | @@ -176,6 +182,10 @@ |
1672 | void resetPinFailed(const QString& error); |
1673 | |
1674 | bool readyToUnlock(const QString& name); |
1675 | + |
1676 | + void simUpdated(); |
1677 | + |
1678 | + void ready(); |
1679 | }; |
1680 | |
1681 | } |
1682 | |
1683 | === added file 'src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp' |
1684 | --- src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp 1970-01-01 00:00:00 +0000 |
1685 | +++ src/indicator/nmofono/wwan/qofono-sim-wrapper.cpp 2016-05-16 07:44:17 +0000 |
1686 | @@ -0,0 +1,252 @@ |
1687 | +/* |
1688 | + * Copyright (C) 2016 Canonical, Ltd. |
1689 | + * |
1690 | + * This program is free software: you can redistribute it and/or modify it |
1691 | + * under the terms of the GNU General Public License version 3, as published |
1692 | + * by the Free Software Foundation. |
1693 | + * |
1694 | + * This program is distributed in the hope that it will be useful, but |
1695 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
1696 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1697 | + * PURPOSE. See the GNU General Public License for more details. |
1698 | + * |
1699 | + * You should have received a copy of the GNU General Public License along |
1700 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
1701 | + * |
1702 | + * Authors: |
1703 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
1704 | + */ |
1705 | + |
1706 | +#include <nmofono/wwan/qofono-sim-wrapper.h> |
1707 | + |
1708 | +#include <ofono/dbus.h> |
1709 | + |
1710 | +using namespace std; |
1711 | + |
1712 | +namespace nmofono |
1713 | +{ |
1714 | +namespace wwan |
1715 | +{ |
1716 | +namespace |
1717 | +{ |
1718 | + |
1719 | +} |
1720 | + |
1721 | +class QOfonoSimWrapper::Private : public QObject, public std::enable_shared_from_this<Private> |
1722 | +{ |
1723 | + Q_OBJECT |
1724 | + |
1725 | +public: |
1726 | + |
1727 | + QOfonoSimWrapper& p; |
1728 | + shared_ptr<QOfonoSimManager> m_simManager; |
1729 | + |
1730 | + QString m_imsi; |
1731 | + QStringList m_phoneNumbers; |
1732 | + QString m_mcc; |
1733 | + QString m_mnc; |
1734 | + QStringList m_preferredLanguages; |
1735 | + |
1736 | + bool m_present = false; |
1737 | + |
1738 | + bool m_imsiSet = false; |
1739 | + bool m_phoneNumbersSet = false; |
1740 | + bool m_mccSet = false; |
1741 | + bool m_mncSet = false; |
1742 | + bool m_preferredLanguagesSet = false; |
1743 | + |
1744 | + |
1745 | + Private(QOfonoSimWrapper& parent, shared_ptr<QOfonoSimManager> simmgr) |
1746 | + : p(parent), m_simManager{simmgr} |
1747 | + { |
1748 | + connect(simmgr.get(), &QOfonoSimManager::presenceChanged, this, &Private::presentChanged); |
1749 | + connect(simmgr.get(), &QOfonoSimManager::subscriberIdentityChanged, this, &Private::imsiChanged); |
1750 | + connect(simmgr.get(), &QOfonoSimManager::mobileCountryCodeChanged, this, &Private::mccChanged); |
1751 | + connect(simmgr.get(), &QOfonoSimManager::mobileNetworkCodeChanged, this, &Private::mncChanged); |
1752 | + connect(simmgr.get(), &QOfonoSimManager::subscriberNumbersChanged, this, &Private::phoneNumbersChanged); |
1753 | + connect(simmgr.get(), &QOfonoSimManager::preferredLanguagesChanged, this, &Private::preferredLanguagesChanged); |
1754 | + } |
1755 | + |
1756 | +public Q_SLOTS: |
1757 | + |
1758 | + void presentChanged(bool value) |
1759 | + { |
1760 | + if (m_present == value) |
1761 | + { |
1762 | + return; |
1763 | + } |
1764 | + m_present = value; |
1765 | + if (!m_present) |
1766 | + { |
1767 | + m_imsiSet = false; |
1768 | + m_phoneNumbersSet = false; |
1769 | + m_mccSet = false; |
1770 | + m_mncSet = false; |
1771 | + m_preferredLanguagesSet = false; |
1772 | + Q_EMIT p.readyChanged(false); |
1773 | + } |
1774 | + Q_EMIT p.presentChanged(value); |
1775 | + } |
1776 | + |
1777 | + void imsiChanged(const QString &value) |
1778 | + { |
1779 | + if (value.isEmpty()) |
1780 | + { |
1781 | + return; |
1782 | + } |
1783 | + |
1784 | + if (m_imsiSet) |
1785 | + { |
1786 | + qWarning() << "Unexpected update on IMSI: " << m_imsi << ", " << value; |
1787 | + } |
1788 | + |
1789 | + m_imsi = value; |
1790 | + m_imsiSet = true; |
1791 | + if (p.ready()) |
1792 | + { |
1793 | + Q_EMIT p.readyChanged(true); |
1794 | + } |
1795 | + } |
1796 | + |
1797 | + void mccChanged(const QString &value) |
1798 | + { |
1799 | + if (value.isEmpty()) |
1800 | + { |
1801 | + return; |
1802 | + } |
1803 | + |
1804 | + if (m_mccSet) |
1805 | + { |
1806 | + qWarning() << "Unexpected update on MCC: " << m_mcc << ", " << value; |
1807 | + } |
1808 | + |
1809 | + |
1810 | + m_mcc = value; |
1811 | + m_mccSet = true; |
1812 | + if (p.ready()) |
1813 | + { |
1814 | + Q_EMIT p.readyChanged(true); |
1815 | + } |
1816 | + } |
1817 | + |
1818 | + void mncChanged(const QString &value) |
1819 | + { |
1820 | + if (value.isEmpty()) |
1821 | + { |
1822 | + return; |
1823 | + } |
1824 | + |
1825 | + if (m_mncSet) |
1826 | + { |
1827 | + qWarning() << "Unexpected update on MNC: " << m_mnc << ", " << value; |
1828 | + } |
1829 | + |
1830 | + m_mnc = value; |
1831 | + m_mncSet = true; |
1832 | + if (p.ready()) |
1833 | + { |
1834 | + Q_EMIT p.readyChanged(true); |
1835 | + } |
1836 | + } |
1837 | + |
1838 | + void phoneNumbersChanged(const QStringList &value) |
1839 | + { |
1840 | + if (value.isEmpty()) |
1841 | + { |
1842 | + return; |
1843 | + } |
1844 | + |
1845 | + if (m_phoneNumbersSet) |
1846 | + { |
1847 | + qWarning() << "Unexpected update on Phone Numbers: " << m_phoneNumbers << ", " << value; |
1848 | + } |
1849 | + |
1850 | + |
1851 | + m_phoneNumbers = value; |
1852 | + m_phoneNumbersSet = true; |
1853 | + if (p.ready()) |
1854 | + { |
1855 | + Q_EMIT p.readyChanged(true); |
1856 | + } |
1857 | + } |
1858 | + |
1859 | + void preferredLanguagesChanged(const QStringList &value) |
1860 | + { |
1861 | + if (value.isEmpty()) |
1862 | + { |
1863 | + return; |
1864 | + } |
1865 | + |
1866 | + if (m_preferredLanguagesSet) |
1867 | + { |
1868 | + qWarning() << "Unexpected update on Preferred Languages: " << m_preferredLanguages << ", " << value; |
1869 | + } |
1870 | + |
1871 | + |
1872 | + m_preferredLanguages = value; |
1873 | + m_preferredLanguagesSet = true; |
1874 | + if (p.ready()) |
1875 | + { |
1876 | + Q_EMIT p.readyChanged(true); |
1877 | + } |
1878 | + } |
1879 | +}; |
1880 | + |
1881 | + |
1882 | + |
1883 | +QOfonoSimWrapper::QOfonoSimWrapper(std::shared_ptr<QOfonoSimManager> simmgr) |
1884 | + : d{new Private(*this, simmgr)} |
1885 | +{ |
1886 | +} |
1887 | + |
1888 | +QOfonoSimWrapper::~QOfonoSimWrapper() |
1889 | +{} |
1890 | + |
1891 | +QString QOfonoSimWrapper::imsi() const |
1892 | +{ |
1893 | + return d->m_imsi; |
1894 | +} |
1895 | + |
1896 | +bool QOfonoSimWrapper::present() const |
1897 | +{ |
1898 | + return d->m_present; |
1899 | +} |
1900 | + |
1901 | +QString QOfonoSimWrapper::mcc() const |
1902 | +{ |
1903 | + return d->m_mcc; |
1904 | +} |
1905 | + |
1906 | +QString QOfonoSimWrapper::mnc() const |
1907 | +{ |
1908 | + return d->m_mnc; |
1909 | +} |
1910 | + |
1911 | +QStringList QOfonoSimWrapper::phoneNumbers() const |
1912 | +{ |
1913 | + return d->m_phoneNumbers; |
1914 | +} |
1915 | + |
1916 | +QStringList QOfonoSimWrapper::preferredLanguages() const |
1917 | +{ |
1918 | + return d->m_preferredLanguages; |
1919 | +} |
1920 | + |
1921 | +bool QOfonoSimWrapper::ready() const { |
1922 | + return d->m_imsiSet && |
1923 | + d->m_phoneNumbersSet && |
1924 | + d->m_mccSet && |
1925 | + d->m_mncSet && |
1926 | + d->m_preferredLanguagesSet; |
1927 | +} |
1928 | + |
1929 | +std::shared_ptr<QOfonoSimManager> QOfonoSimWrapper::ofonoSimManager() const |
1930 | +{ |
1931 | + return d->m_simManager; |
1932 | +} |
1933 | + |
1934 | + |
1935 | +} |
1936 | +} |
1937 | + |
1938 | +#include "qofono-sim-wrapper.moc" |
1939 | |
1940 | === added file 'src/indicator/nmofono/wwan/qofono-sim-wrapper.h' |
1941 | --- src/indicator/nmofono/wwan/qofono-sim-wrapper.h 1970-01-01 00:00:00 +0000 |
1942 | +++ src/indicator/nmofono/wwan/qofono-sim-wrapper.h 2016-05-16 07:44:17 +0000 |
1943 | @@ -0,0 +1,77 @@ |
1944 | +/* |
1945 | + * Copyright (C) 2016 Canonical, Ltd. |
1946 | + * |
1947 | + * This program is free software: you can redistribute it and/or modify it |
1948 | + * under the terms of the GNU General Public License version 3, as published |
1949 | + * by the Free Software Foundation. |
1950 | + * |
1951 | + * This program is distributed in the hope that it will be useful, but |
1952 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
1953 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1954 | + * PURPOSE. See the GNU General Public License for more details. |
1955 | + * |
1956 | + * You should have received a copy of the GNU General Public License along |
1957 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
1958 | + * |
1959 | + * Authors: |
1960 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
1961 | + */ |
1962 | + |
1963 | +#pragma once |
1964 | + |
1965 | +#include <QObject> |
1966 | +#include <QSettings> |
1967 | + |
1968 | +#include <memory> |
1969 | + |
1970 | +#define slots |
1971 | +#include <qofono-qt5/qofonomodem.h> |
1972 | +#include <qofono-qt5/qofonosimmanager.h> |
1973 | +#undef slots |
1974 | + |
1975 | +class QOfonoModem; |
1976 | + |
1977 | +namespace nmofono |
1978 | +{ |
1979 | +class ManagerImpl; |
1980 | + |
1981 | +namespace wwan |
1982 | +{ |
1983 | + |
1984 | +class QOfonoSimWrapper : public QObject |
1985 | +{ |
1986 | + Q_OBJECT |
1987 | + |
1988 | + class Private; |
1989 | + std::shared_ptr<Private> d; |
1990 | + |
1991 | +public: |
1992 | + |
1993 | + typedef std::shared_ptr<QOfonoSimWrapper> Ptr; |
1994 | + typedef std::weak_ptr<QOfonoSimWrapper> WeakPtr; |
1995 | + |
1996 | + QOfonoSimWrapper() = delete; |
1997 | + |
1998 | + |
1999 | + QOfonoSimWrapper(std::shared_ptr<QOfonoSimManager> simmgr); |
2000 | + ~QOfonoSimWrapper(); |
2001 | + |
2002 | + QString imsi() const; |
2003 | + bool present() const; |
2004 | + QString mcc() const; |
2005 | + QString mnc() const; |
2006 | + QStringList phoneNumbers() const; |
2007 | + QStringList preferredLanguages() const; |
2008 | + bool ready() const; |
2009 | + |
2010 | + std::shared_ptr<QOfonoSimManager> ofonoSimManager() const; |
2011 | + |
2012 | + |
2013 | +Q_SIGNALS: |
2014 | + |
2015 | + void presentChanged(bool value); |
2016 | + void readyChanged(bool value); |
2017 | +}; |
2018 | + |
2019 | +} |
2020 | +} |
2021 | |
2022 | === added file 'src/indicator/nmofono/wwan/sim-manager.cpp' |
2023 | --- src/indicator/nmofono/wwan/sim-manager.cpp 1970-01-01 00:00:00 +0000 |
2024 | +++ src/indicator/nmofono/wwan/sim-manager.cpp 2016-05-16 07:44:17 +0000 |
2025 | @@ -0,0 +1,261 @@ |
2026 | +/* |
2027 | + * Copyright (C) 2016 Canonical, Ltd. |
2028 | + * |
2029 | + * This program is free software: you can redistribute it and/or modify it |
2030 | + * under the terms of the GNU General Public License version 3, as published |
2031 | + * by the Free Software Foundation. |
2032 | + * |
2033 | + * This program is distributed in the hope that it will be useful, but |
2034 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
2035 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2036 | + * PURPOSE. See the GNU General Public License for more details. |
2037 | + * |
2038 | + * You should have received a copy of the GNU General Public License along |
2039 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
2040 | + * |
2041 | + * Authors: |
2042 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
2043 | + */ |
2044 | + |
2045 | +#include <nmofono/wwan/sim-manager.h> |
2046 | + |
2047 | +#include <nmofono/wwan/qofono-sim-wrapper.h> |
2048 | + |
2049 | +#define slots |
2050 | +#include <qofono-qt5/qofonomanager.h> |
2051 | +#include <qofono-qt5/qofonomodem.h> |
2052 | +#include <qofono-qt5/qofonosimmanager.h> |
2053 | +#undef slots |
2054 | +#include <ofono/dbus.h> |
2055 | + |
2056 | +using namespace std; |
2057 | + |
2058 | +namespace nmofono |
2059 | +{ |
2060 | +namespace wwan |
2061 | +{ |
2062 | +namespace |
2063 | +{ |
2064 | + |
2065 | +} |
2066 | + |
2067 | +class SimManager::Private : public QObject, public std::enable_shared_from_this<Private> |
2068 | +{ |
2069 | + Q_OBJECT |
2070 | + |
2071 | +public: |
2072 | + |
2073 | + SimManager& p; |
2074 | + |
2075 | + QMap<QString, Sim::Ptr> m_knownSims; |
2076 | + |
2077 | + shared_ptr<QOfonoManager> m_ofono; |
2078 | + QMap<QString, shared_ptr<QOfonoModem>> m_ofonoModems; |
2079 | + QMap<QString, QOfonoSimWrapper::Ptr> m_wrappers; |
2080 | + |
2081 | + ConnectivityServiceSettings::Ptr m_settings; |
2082 | + |
2083 | + Private(SimManager& parent, ConnectivityServiceSettings::Ptr settings) |
2084 | + : p(parent), |
2085 | + m_settings(settings) |
2086 | + { |
2087 | + QStringList imsis = m_settings->knownSims(); |
2088 | + for(auto imsi : imsis) { |
2089 | + auto sim = m_settings->createSimFromSettings(imsi); |
2090 | + connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &Private::simDataRoamingEnabledChanged); |
2091 | + if (!sim) |
2092 | + { |
2093 | + continue; |
2094 | + } |
2095 | + m_knownSims[sim->imsi()] = sim; |
2096 | + } |
2097 | + |
2098 | + m_ofono = make_shared<QOfonoManager>(); |
2099 | + connect(m_ofono.get(), &QOfonoManager::modemsChanged, this, &Private::modemsChanged); |
2100 | + modemsChanged(m_ofono->modems()); |
2101 | + } |
2102 | + |
2103 | +public Q_SLOTS: |
2104 | + |
2105 | + void modemsChanged(const QStringList& value) |
2106 | + { |
2107 | + QSet<QString> modemPaths(value.toSet()); |
2108 | + QSet<QString> currentModemPaths(m_ofonoModems.keys().toSet()); |
2109 | + |
2110 | + auto toRemove = currentModemPaths; |
2111 | + toRemove.subtract(modemPaths); |
2112 | + |
2113 | + auto toAdd = modemPaths; |
2114 | + toAdd.subtract(currentModemPaths); |
2115 | + |
2116 | + for (const auto& path : toRemove) |
2117 | + { |
2118 | + if (!m_ofonoModems.contains(path)) |
2119 | + { |
2120 | + qWarning() << __PRETTY_FUNCTION__ << ": trying to remove unknown modem: " << path; |
2121 | + continue; |
2122 | + } |
2123 | + auto modem = m_ofonoModems.take(path); |
2124 | + if (m_wrappers.contains(path)) |
2125 | + { |
2126 | + auto wrapper = m_wrappers[path]; |
2127 | + if (m_knownSims.contains(wrapper->imsi())) |
2128 | + { |
2129 | + auto sim = m_knownSims[wrapper->imsi()]; |
2130 | + sim->setOfonoSimManager(std::shared_ptr<QOfonoSimManager>()); |
2131 | + } |
2132 | + m_wrappers.remove(path); |
2133 | + } |
2134 | + } |
2135 | + |
2136 | + for (const auto& path : toAdd) |
2137 | + { |
2138 | + auto modem = make_shared<QOfonoModem>(); |
2139 | + modem->setModemPath(path); |
2140 | + |
2141 | + if (m_ofonoModems.contains(path)) |
2142 | + { |
2143 | + qWarning() << __PRETTY_FUNCTION__ << ": trying to add already existing modem: " << path; |
2144 | + continue; |
2145 | + } |
2146 | + m_ofonoModems[path] = modem; |
2147 | + |
2148 | + connect(modem.get(), &QOfonoModem::interfacesChanged, this, &Private::modemInterfacesChanged); |
2149 | + modem->interfacesChanged(modem->interfaces()); |
2150 | + } |
2151 | + } |
2152 | + |
2153 | + void modemInterfacesChanged() { |
2154 | + QOfonoModem *modem = qobject_cast<QOfonoModem*>(sender()); |
2155 | + if (!modem) |
2156 | + { |
2157 | + Q_ASSERT(0); |
2158 | + return; |
2159 | + } |
2160 | + |
2161 | + QSet<QString> interfaces(modem->interfaces().toSet()); |
2162 | + if (interfaces.contains(OFONO_SIM_MANAGER_INTERFACE)) |
2163 | + { |
2164 | + if (!m_wrappers.contains(modem->modemPath())) |
2165 | + { |
2166 | + auto simmgr = make_shared<QOfonoSimManager>(); |
2167 | + simmgr->setModemPath(modem->modemPath()); |
2168 | + |
2169 | + auto wrapper = make_shared<wwan::QOfonoSimWrapper>(simmgr); |
2170 | + |
2171 | + connect(wrapper.get(), &wwan::QOfonoSimWrapper::presentChanged, this, &Private::ofonoSimPresentChanged); |
2172 | + connect(wrapper.get(), &wwan::QOfonoSimWrapper::readyChanged, this, &Private::ofonoSimReady); |
2173 | + |
2174 | + m_wrappers[modem->modemPath()] = wrapper; |
2175 | + } |
2176 | + |
2177 | + } else { |
2178 | + if (m_wrappers.contains(modem->modemPath())) |
2179 | + { |
2180 | + auto wrapper = m_wrappers[modem->modemPath()]; |
2181 | + if (m_knownSims.contains(wrapper->imsi())) |
2182 | + { |
2183 | + auto sim = m_knownSims[wrapper->imsi()]; |
2184 | + sim->setOfonoSimManager(std::shared_ptr<QOfonoSimManager>()); |
2185 | + } |
2186 | + m_wrappers.remove(modem->modemPath()); |
2187 | + } |
2188 | + } |
2189 | + } |
2190 | + |
2191 | + void ofonoSimPresentChanged(bool present) |
2192 | + { |
2193 | + auto wrapper = qobject_cast<QOfonoSimWrapper*>(sender()); |
2194 | + if (!wrapper) |
2195 | + { |
2196 | + Q_ASSERT(0); |
2197 | + return; |
2198 | + } |
2199 | + |
2200 | + if (!present) |
2201 | + { |
2202 | + if (m_knownSims.contains(wrapper->imsi())) |
2203 | + { |
2204 | + auto sim = m_knownSims[wrapper->imsi()]; |
2205 | + sim->setOfonoSimManager(std::shared_ptr<QOfonoSimManager>()); |
2206 | + } |
2207 | + } |
2208 | + } |
2209 | + |
2210 | + void ofonoSimReady(bool value) |
2211 | + { |
2212 | + if (!value) |
2213 | + { |
2214 | + // handled in present changed |
2215 | + return; |
2216 | + } |
2217 | + |
2218 | + auto wrapper = qobject_cast<wwan::QOfonoSimWrapper*>(sender()); |
2219 | + if (!wrapper) |
2220 | + { |
2221 | + Q_ASSERT(0); |
2222 | + return; |
2223 | + } |
2224 | + |
2225 | + bool found = false; |
2226 | + for (auto i : m_knownSims.values()) |
2227 | + { |
2228 | + if (wrapper->imsi() == i->imsi()) |
2229 | + { |
2230 | + found = true; |
2231 | + i->setOfonoSimManager(wrapper->ofonoSimManager()); |
2232 | + break; |
2233 | + } |
2234 | + } |
2235 | + if (!found) |
2236 | + { |
2237 | + auto sim = Sim::fromQOfonoSimWrapper(wrapper); |
2238 | + connect(sim.get(), &Sim::dataRoamingEnabledChanged, this, &Private::simDataRoamingEnabledChanged); |
2239 | + m_settings->saveSimToSettings(sim); |
2240 | + m_knownSims[sim->imsi()] = sim; |
2241 | + m_settings->setKnownSims(m_knownSims.keys()); |
2242 | + Q_EMIT p.simAdded(sim); |
2243 | + } |
2244 | + } |
2245 | + |
2246 | + void simDataRoamingEnabledChanged(bool value) |
2247 | + { |
2248 | + Q_UNUSED(value) |
2249 | + |
2250 | + auto sim_raw = qobject_cast<Sim*>(sender()); |
2251 | + if (!sim_raw) |
2252 | + { |
2253 | + Q_ASSERT(0); |
2254 | + return; |
2255 | + } |
2256 | + auto sim = m_knownSims[sim_raw->imsi()]; |
2257 | + if (!sim) |
2258 | + { |
2259 | + Q_ASSERT(0); |
2260 | + return; |
2261 | + } |
2262 | + m_settings->saveSimToSettings(sim); |
2263 | + } |
2264 | + |
2265 | +}; |
2266 | + |
2267 | + |
2268 | + |
2269 | +SimManager::SimManager(ConnectivityServiceSettings::Ptr settings) |
2270 | + : d{new Private(*this, settings)} |
2271 | +{ |
2272 | +} |
2273 | + |
2274 | +SimManager::~SimManager() |
2275 | +{} |
2276 | + |
2277 | +QList<Sim::Ptr> |
2278 | +SimManager::knownSims() const |
2279 | +{ |
2280 | + return d->m_knownSims.values(); |
2281 | +} |
2282 | + |
2283 | +} |
2284 | +} |
2285 | + |
2286 | +#include "sim-manager.moc" |
2287 | |
2288 | === added file 'src/indicator/nmofono/wwan/sim-manager.h' |
2289 | --- src/indicator/nmofono/wwan/sim-manager.h 1970-01-01 00:00:00 +0000 |
2290 | +++ src/indicator/nmofono/wwan/sim-manager.h 2016-05-16 07:44:17 +0000 |
2291 | @@ -0,0 +1,57 @@ |
2292 | +/* |
2293 | + * Copyright (C) 2016 Canonical, Ltd. |
2294 | + * |
2295 | + * This program is free software: you can redistribute it and/or modify it |
2296 | + * under the terms of the GNU General Public License version 3, as published |
2297 | + * by the Free Software Foundation. |
2298 | + * |
2299 | + * This program is distributed in the hope that it will be useful, but |
2300 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
2301 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2302 | + * PURPOSE. See the GNU General Public License for more details. |
2303 | + * |
2304 | + * You should have received a copy of the GNU General Public License along |
2305 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
2306 | + * |
2307 | + * Authors: |
2308 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
2309 | + */ |
2310 | + |
2311 | +#pragma once |
2312 | + |
2313 | +#include <QObject> |
2314 | +#include <QSettings> |
2315 | + |
2316 | +#include <memory> |
2317 | + |
2318 | +#include "sim.h" |
2319 | +#include <nmofono/connectivity-service-settings.h> |
2320 | + |
2321 | +namespace nmofono |
2322 | +{ |
2323 | +namespace wwan |
2324 | +{ |
2325 | + |
2326 | +class SimManager : public QObject |
2327 | +{ |
2328 | + Q_OBJECT |
2329 | + |
2330 | + class Private; |
2331 | + std::shared_ptr<Private> d; |
2332 | + |
2333 | +public: |
2334 | + |
2335 | + typedef std::shared_ptr<SimManager> Ptr; |
2336 | + typedef std::weak_ptr<SimManager> WeakPtr; |
2337 | + |
2338 | + SimManager(ConnectivityServiceSettings::Ptr settings); |
2339 | + ~SimManager(); |
2340 | + |
2341 | + QList<Sim::Ptr> knownSims() const; |
2342 | + |
2343 | +Q_SIGNALS: |
2344 | + void simAdded(Sim::Ptr sim); |
2345 | +}; |
2346 | + |
2347 | +} |
2348 | +} |
2349 | |
2350 | === added file 'src/indicator/nmofono/wwan/sim.cpp' |
2351 | --- src/indicator/nmofono/wwan/sim.cpp 1970-01-01 00:00:00 +0000 |
2352 | +++ src/indicator/nmofono/wwan/sim.cpp 2016-05-16 07:44:17 +0000 |
2353 | @@ -0,0 +1,309 @@ |
2354 | +/* |
2355 | + * Copyright (C) 2016 Canonical, Ltd. |
2356 | + * |
2357 | + * This program is free software: you can redistribute it and/or modify it |
2358 | + * under the terms of the GNU General Public License version 3, as published |
2359 | + * by the Free Software Foundation. |
2360 | + * |
2361 | + * This program is distributed in the hope that it will be useful, but |
2362 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
2363 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2364 | + * PURPOSE. See the GNU General Public License for more details. |
2365 | + * |
2366 | + * You should have received a copy of the GNU General Public License along |
2367 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
2368 | + * |
2369 | + * Authors: |
2370 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
2371 | + */ |
2372 | + |
2373 | +#include <nmofono/wwan/sim.h> |
2374 | + |
2375 | +#include <ofono/dbus.h> |
2376 | + |
2377 | +#define slots |
2378 | +#include <qofono-qt5/qofonoconnectionmanager.h> |
2379 | +#undef slots |
2380 | + |
2381 | +using namespace std; |
2382 | + |
2383 | +namespace nmofono |
2384 | +{ |
2385 | +namespace wwan |
2386 | +{ |
2387 | +namespace |
2388 | +{ |
2389 | + |
2390 | +} |
2391 | + |
2392 | +Sim::Ptr Sim::fromQOfonoSimWrapper(const QOfonoSimWrapper *wrapper) |
2393 | +{ |
2394 | + auto sim = Sim::Ptr(new Sim(wrapper->imsi(), |
2395 | + wrapper->phoneNumbers().first(), // default to the first number |
2396 | + wrapper->mcc(), |
2397 | + wrapper->mnc(), |
2398 | + wrapper->preferredLanguages(), |
2399 | + false)); |
2400 | + sim->setOfonoSimManager(wrapper->ofonoSimManager()); |
2401 | + return sim; |
2402 | +} |
2403 | + |
2404 | +class Sim::Private : public QObject, public std::enable_shared_from_this<Private> |
2405 | +{ |
2406 | + Q_OBJECT |
2407 | + |
2408 | +public: |
2409 | + |
2410 | + Sim& p; |
2411 | + |
2412 | + int m_index = -1; |
2413 | + |
2414 | + QString m_simIdentifier; |
2415 | + |
2416 | + shared_ptr<QOfonoSimManager> m_simManager; |
2417 | + shared_ptr<QOfonoConnectionManager> m_connManager; |
2418 | + |
2419 | + QSet<QString> m_interfaces; |
2420 | + |
2421 | + QString m_imsi; |
2422 | + QString m_primaryPhoneNumber; |
2423 | + QString m_mcc; |
2424 | + QString m_mnc; |
2425 | + QStringList m_preferredLanguages; |
2426 | + bool m_dataRoamingEnabled; |
2427 | + bool m_mobileDataEnabled = false; |
2428 | + |
2429 | + bool m_locked = false; |
2430 | + |
2431 | + Private(Sim &parent) |
2432 | + : p(parent) |
2433 | + { |
2434 | + } |
2435 | + |
2436 | + Private(Sim& parent, shared_ptr<QOfonoSimManager> simmgr) |
2437 | + : p(parent) |
2438 | + { |
2439 | + simManagerChanged(simmgr); |
2440 | + |
2441 | + |
2442 | + /// @todo hook up with system-settings to allow changing the identifier. |
2443 | + if (m_simIdentifier.isEmpty()) |
2444 | + { |
2445 | + setSimIdentifier(m_primaryPhoneNumber); |
2446 | + } |
2447 | + } |
2448 | + |
2449 | +public Q_SLOTS: |
2450 | + |
2451 | + |
2452 | + void simManagerChanged(shared_ptr<QOfonoSimManager> simmgr) |
2453 | + { |
2454 | + if (m_simManager == simmgr) |
2455 | + { |
2456 | + return; |
2457 | + } |
2458 | + |
2459 | + m_simManager = simmgr; |
2460 | + update(); |
2461 | + |
2462 | + Q_EMIT p.presentChanged(m_simManager.get() != nullptr); |
2463 | + } |
2464 | + |
2465 | + void connManagerChanged(shared_ptr<QOfonoConnectionManager> connmgr) |
2466 | + { |
2467 | + if (m_connManager == connmgr) |
2468 | + { |
2469 | + return; |
2470 | + } |
2471 | + |
2472 | + m_connManager = connmgr; |
2473 | + if (m_connManager) |
2474 | + { |
2475 | + connect(m_connManager.get(), |
2476 | + &QOfonoConnectionManager::poweredChanged, this, |
2477 | + &Private::update); |
2478 | + connect(m_connManager.get(), |
2479 | + &QOfonoConnectionManager::roamingAllowedChanged, this, |
2480 | + &Private::update); |
2481 | + |
2482 | + m_connManager->setPowered(m_mobileDataEnabled); |
2483 | + m_connManager->setRoamingAllowed(m_dataRoamingEnabled); |
2484 | + } |
2485 | + |
2486 | + update(); |
2487 | + } |
2488 | + |
2489 | + void update() |
2490 | + { |
2491 | + if (m_connManager) |
2492 | + { |
2493 | + bool powered = m_connManager->powered(); |
2494 | + bool roamingAllowed = m_connManager->roamingAllowed(); |
2495 | + |
2496 | + /* |
2497 | + * Connectivity Service is the policy manager for the system. |
2498 | + * If ofono has different settings force them back to stored values. |
2499 | + */ |
2500 | + if (m_mobileDataEnabled != powered) |
2501 | + { |
2502 | + m_connManager->setPowered(m_mobileDataEnabled); |
2503 | + } |
2504 | + if (m_dataRoamingEnabled != roamingAllowed) |
2505 | + { |
2506 | + m_connManager->setRoamingAllowed(m_dataRoamingEnabled); |
2507 | + } |
2508 | + } |
2509 | + else |
2510 | + { |
2511 | + /* empty */ |
2512 | + } |
2513 | + } |
2514 | + |
2515 | + void setSimIdentifier(const QString& simIdentifier) |
2516 | + { |
2517 | + if (m_simIdentifier == simIdentifier) |
2518 | + { |
2519 | + return; |
2520 | + } |
2521 | + |
2522 | + m_simIdentifier = simIdentifier; |
2523 | + Q_EMIT p.simIdentifierUpdated(m_simIdentifier); |
2524 | + } |
2525 | + |
2526 | + void setOfono(std::shared_ptr<QOfonoSimManager> simmgr) |
2527 | + { |
2528 | + simManagerChanged(simmgr); |
2529 | + if (simmgr) |
2530 | + { |
2531 | + m_connManager = std::make_shared<QOfonoConnectionManager>(this); |
2532 | + m_connManager->setModemPath(simmgr->modemPath()); |
2533 | + connManagerChanged(m_connManager); |
2534 | + } |
2535 | + else |
2536 | + { |
2537 | + m_connManager = std::shared_ptr<QOfonoConnectionManager>(); |
2538 | + connManagerChanged(m_connManager); |
2539 | + } |
2540 | + } |
2541 | + |
2542 | + |
2543 | +}; |
2544 | + |
2545 | +Sim::Sim(const QString &imsi, |
2546 | + const QString &primaryPhoneNumber, |
2547 | + const QString &mcc, |
2548 | + const QString &mnc, |
2549 | + const QStringList &preferredLanguages, |
2550 | + bool dataRoamingEnabled) |
2551 | + : d{new Private(*this)} |
2552 | +{ |
2553 | + d->m_imsi = imsi; |
2554 | + d->m_primaryPhoneNumber = primaryPhoneNumber; |
2555 | + d->m_mcc = mcc; |
2556 | + d->m_mnc = mnc; |
2557 | + d->m_preferredLanguages = preferredLanguages; |
2558 | + d->m_dataRoamingEnabled = dataRoamingEnabled; |
2559 | +} |
2560 | + |
2561 | +Sim::~Sim() |
2562 | +{} |
2563 | + |
2564 | +const QString& |
2565 | +Sim::simIdentifier() const |
2566 | +{ |
2567 | + return d->m_simIdentifier; |
2568 | +} |
2569 | + |
2570 | +QString Sim::imsi() const |
2571 | +{ |
2572 | + return d->m_imsi; |
2573 | +} |
2574 | + |
2575 | +QString Sim::primaryPhoneNumber() const |
2576 | +{ |
2577 | + return d->m_primaryPhoneNumber; |
2578 | +} |
2579 | + |
2580 | +bool Sim::locked() const |
2581 | +{ |
2582 | + return d->m_locked; |
2583 | +} |
2584 | + |
2585 | +bool Sim::present() const |
2586 | +{ |
2587 | + return d->m_simManager.get() != nullptr; |
2588 | +} |
2589 | + |
2590 | +QString Sim::mcc() const |
2591 | +{ |
2592 | + return d->m_mcc; |
2593 | +} |
2594 | + |
2595 | +QString Sim::mnc() const |
2596 | +{ |
2597 | + return d->m_mnc; |
2598 | +} |
2599 | + |
2600 | +QList<QString> Sim::preferredLanguages() const |
2601 | +{ |
2602 | + return d->m_preferredLanguages; |
2603 | +} |
2604 | + |
2605 | +bool Sim::dataRoamingEnabled() const |
2606 | +{ |
2607 | + return d->m_dataRoamingEnabled; |
2608 | +} |
2609 | + |
2610 | +void Sim::setDataRoamingEnabled(bool value) |
2611 | +{ |
2612 | + if (d->m_dataRoamingEnabled == value) |
2613 | + { |
2614 | + return; |
2615 | + } |
2616 | + d->m_dataRoamingEnabled = value; |
2617 | + Q_EMIT dataRoamingEnabledChanged(value); |
2618 | +} |
2619 | + |
2620 | +bool Sim::mobileDataEnabled() const |
2621 | +{ |
2622 | + return d->m_mobileDataEnabled; |
2623 | +} |
2624 | + |
2625 | +void Sim::setMobileDataEnabled(bool value) |
2626 | +{ |
2627 | + if (d->m_mobileDataEnabled == value) |
2628 | + { |
2629 | + return; |
2630 | + } |
2631 | + d->m_mobileDataEnabled = value; |
2632 | + if (d->m_connManager) |
2633 | + { |
2634 | + d->m_connManager->setPowered(d->m_mobileDataEnabled); |
2635 | + } |
2636 | + Q_EMIT mobileDataEnabledChanged(value); |
2637 | +} |
2638 | + |
2639 | +void Sim::unlock() |
2640 | +{ |
2641 | + |
2642 | +} |
2643 | + |
2644 | +QString Sim::ofonoPath() const |
2645 | +{ |
2646 | + if (d->m_simManager) |
2647 | + { |
2648 | + return d->m_simManager->objectPath(); |
2649 | + } |
2650 | + return QString(); |
2651 | +} |
2652 | + |
2653 | +void Sim::setOfonoSimManager(std::shared_ptr<QOfonoSimManager> simmgr) |
2654 | +{ |
2655 | + d->setOfono(simmgr); |
2656 | +} |
2657 | + |
2658 | + |
2659 | +} |
2660 | +} |
2661 | + |
2662 | +#include "sim.moc" |
2663 | |
2664 | === added file 'src/indicator/nmofono/wwan/sim.h' |
2665 | --- src/indicator/nmofono/wwan/sim.h 1970-01-01 00:00:00 +0000 |
2666 | +++ src/indicator/nmofono/wwan/sim.h 2016-05-16 07:44:17 +0000 |
2667 | @@ -0,0 +1,125 @@ |
2668 | +/* |
2669 | + * Copyright (C) 2016 Canonical, Ltd. |
2670 | + * |
2671 | + * This program is free software: you can redistribute it and/or modify it |
2672 | + * under the terms of the GNU General Public License version 3, as published |
2673 | + * by the Free Software Foundation. |
2674 | + * |
2675 | + * This program is distributed in the hope that it will be useful, but |
2676 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
2677 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2678 | + * PURPOSE. See the GNU General Public License for more details. |
2679 | + * |
2680 | + * You should have received a copy of the GNU General Public License along |
2681 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
2682 | + * |
2683 | + * Authors: |
2684 | + * Antti Kaijanmäki <antti.kaijanmaki@canonical.com> |
2685 | + */ |
2686 | + |
2687 | +#pragma once |
2688 | + |
2689 | +#include <QObject> |
2690 | +#include <QSettings> |
2691 | + |
2692 | +#include <memory> |
2693 | + |
2694 | +#define slots |
2695 | +#include <qofono-qt5/qofonomodem.h> |
2696 | +#include <qofono-qt5/qofonosimmanager.h> |
2697 | +#undef slots |
2698 | + |
2699 | +#include <nmofono/wwan/qofono-sim-wrapper.h> |
2700 | + |
2701 | +class QOfonoModem; |
2702 | + |
2703 | +namespace nmofono |
2704 | +{ |
2705 | +class ManagerImpl; |
2706 | +class ConnectivityServiceSettings; |
2707 | + |
2708 | +namespace wwan |
2709 | +{ |
2710 | + |
2711 | +class Sim : public QObject |
2712 | +{ |
2713 | + Q_OBJECT |
2714 | + |
2715 | + class Private; |
2716 | + std::shared_ptr<Private> d; |
2717 | + |
2718 | + friend class nmofono::ConnectivityServiceSettings; |
2719 | + |
2720 | +public: |
2721 | + |
2722 | + typedef std::shared_ptr<Sim> Ptr; |
2723 | + typedef std::weak_ptr<Sim> WeakPtr; |
2724 | + |
2725 | + Sim() = delete; |
2726 | + |
2727 | + static Sim::Ptr fromQOfonoSimWrapper(const QOfonoSimWrapper *wrapper); |
2728 | + |
2729 | +private: |
2730 | + Sim(const QString &imsi, |
2731 | + const QString &primaryPhoneNumber, |
2732 | + const QString &mcc, |
2733 | + const QString &mnc, |
2734 | + const QStringList &preferredLanguages, |
2735 | + bool dataRoamingEnabled); |
2736 | + |
2737 | +public: |
2738 | + ~Sim(); |
2739 | + void setOfonoSimManager(std::shared_ptr<QOfonoSimManager> simmgr); |
2740 | + |
2741 | + Q_PROPERTY(QString simIdentifier READ simIdentifier NOTIFY simIdentifierUpdated) |
2742 | + const QString &simIdentifier() const; |
2743 | + |
2744 | + Q_PROPERTY(QString imsi READ imsi CONSTANT) |
2745 | + QString imsi() const; |
2746 | + |
2747 | + Q_PROPERTY(QString primaryPhoneNumber READ primaryPhoneNumber CONSTANT) |
2748 | + QString primaryPhoneNumber() const; |
2749 | + |
2750 | + Q_PROPERTY(bool locked READ locked NOTIFY lockedChanged) |
2751 | + bool locked() const; |
2752 | + |
2753 | + Q_PROPERTY(bool present READ present NOTIFY presentChanged) |
2754 | + bool present() const; |
2755 | + |
2756 | + Q_PROPERTY(QString mcc READ mcc CONSTANT) |
2757 | + QString mcc() const; |
2758 | + |
2759 | + Q_PROPERTY(QString mnc READ mnc CONSTANT) |
2760 | + QString mnc() const; |
2761 | + |
2762 | + Q_PROPERTY(QList<QString> preferredLanguages READ preferredLanguages CONSTANT) |
2763 | + QList<QString> preferredLanguages() const; |
2764 | + |
2765 | + Q_PROPERTY(bool dataRoamingEnabled READ dataRoamingEnabled WRITE setDataRoamingEnabled NOTIFY dataRoamingEnabledChanged) |
2766 | + bool dataRoamingEnabled() const; |
2767 | + void setDataRoamingEnabled(bool value); |
2768 | + |
2769 | + Q_PROPERTY(bool mobileDataEnabled READ mobileDataEnabled WRITE setMobileDataEnabled NOTIFY mobileDataEnabledChanged) |
2770 | + bool mobileDataEnabled() const; |
2771 | + void setMobileDataEnabled(bool value); |
2772 | + |
2773 | + QString ofonoPath() const; |
2774 | + |
2775 | +public Q_SLOTS: |
2776 | + void unlock(); |
2777 | + |
2778 | +Q_SIGNALS: |
2779 | + |
2780 | + void simIdentifierUpdated(const QString &); |
2781 | + |
2782 | + void lockedChanged(bool value); |
2783 | + |
2784 | + void presentChanged(bool value); |
2785 | + |
2786 | + void dataRoamingEnabledChanged(bool value); |
2787 | + |
2788 | + void mobileDataEnabledChanged(bool value); |
2789 | +}; |
2790 | + |
2791 | +} |
2792 | +} |
2793 | |
2794 | === modified file 'src/qdbus-stubs/dbus-types.h' |
2795 | --- src/qdbus-stubs/dbus-types.h 2015-11-20 13:14:50 +0000 |
2796 | +++ src/qdbus-stubs/dbus-types.h 2016-05-16 07:44:17 +0000 |
2797 | @@ -47,6 +47,19 @@ |
2798 | return path.arg(counter++); |
2799 | } |
2800 | |
2801 | + inline QString modemPath(const QString &serial) |
2802 | + { |
2803 | + static QString path{"/com/ubuntu/connectivity1/modem/%1"}; |
2804 | + return path.arg(serial); |
2805 | + } |
2806 | + |
2807 | + inline QString simPath(const QString &imsi) |
2808 | + { |
2809 | + static QString path{"/com/ubuntu/connectivity1/sim/%1"}; |
2810 | + return path.arg(imsi); |
2811 | + } |
2812 | + |
2813 | + |
2814 | static constexpr char const* WPASUPPLICANT_DBUS_NAME = "fi.w1.wpa_supplicant1"; |
2815 | |
2816 | static constexpr char const* WPASUPPLICANT_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"; |
FAILED: Continuous integration, rev:581 jenkins. qa.ubuntu. com/job/ indicator- network- ci/413/ jenkins. qa.ubuntu. com/job/ indicator- network- wily-amd64- ci/65/console jenkins. qa.ubuntu. com/job/ indicator- network- wily-armhf- ci/65/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/indicator- network- ci/413/ rebuild
http://