Merge lp:~unity-api-team/indicator-network/disconnect-wifi-when-hotspot-active into lp:indicator-network/15.10

Proposed by Pete Woods
Status: Merged
Approved by: Pete Woods
Approved revision: 520
Merged at revision: 515
Proposed branch: lp:~unity-api-team/indicator-network/disconnect-wifi-when-hotspot-active
Merge into: lp:indicator-network/15.10
Prerequisite: lp:~unity-api-team/indicator-network/hotspot-button
Diff against target: 312 lines (+75/-49)
6 files modified
src/indicator/nmofono/hotspot-manager.cpp (+36/-48)
src/indicator/nmofono/hotspot-manager.h (+8/-0)
src/indicator/nmofono/manager-impl.cpp (+9/-1)
src/indicator/nmofono/wifi/wifi-link-impl.cpp (+18/-0)
src/indicator/nmofono/wifi/wifi-link-impl.h (+2/-0)
src/indicator/nmofono/wifi/wifi-link.h (+2/-0)
To merge this branch: bzr merge lp:~unity-api-team/indicator-network/disconnect-wifi-when-hotspot-active
Reviewer Review Type Date Requested Status
Antti Kaijanmäki (community) Approve
Review via email: mp+268209@code.launchpad.net

Commit message

Disconnect from access points when starting hotspot

Description of the change

Disconnect from access points when starting hotspot

To post a comment you must log in.
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator/nmofono/hotspot-manager.cpp'
2--- src/indicator/nmofono/hotspot-manager.cpp 2015-08-17 11:05:23 +0000
3+++ src/indicator/nmofono/hotspot-manager.cpp 2015-08-17 11:05:23 +0000
4@@ -67,7 +67,6 @@
5 // Get new settings
6 QVariantDictMap new_settings = createConnectionSettings(m_ssid,
7 m_password,
8- m_device_path,
9 m_mode, false);
10 auto updating = m_hotspot->Update(new_settings);
11 updating.waitForFinished();
12@@ -202,18 +201,16 @@
13 QStringList arguments;
14 arguments << "urfkill.hybris.wlan";
15
16- QProcess *getprop = new QProcess();
17- getprop->start(program, arguments);
18+ QProcess getprop;
19+ getprop.start(program, arguments);
20
21- if (!getprop->waitForFinished())
22+ if (!getprop.waitForFinished())
23 {
24- qCritical() << "getprop process failed:" << getprop->errorString();
25- delete getprop;
26+ qCritical() << "getprop process failed:" << getprop.errorString();
27 return false;
28 }
29
30- int index = getprop->readAllStandardOutput().indexOf("1");
31- delete getprop;
32+ int index = getprop.readAllStandardOutput().indexOf("1");
33
34 // A non-negative integer means getprop returned 1
35 return index >= 0;
36@@ -231,7 +228,7 @@
37 return true;
38 }
39
40- if (isHybrisWlan())
41+ if (m_isHybrisWlan)
42 {
43 QDBusInterface wpasIface(wpa_supplicant_service,
44 wpa_supplicant_path,
45@@ -305,9 +302,8 @@
46 */
47 QVariantDictMap createConnectionSettings(
48 const QByteArray &ssid, const QString &password,
49- const QDBusObjectPath &devicePath, QString mode, bool autoConnect = true)
50+ QString mode, bool autoConnect = true)
51 {
52- Q_UNUSED(devicePath);
53 QVariantDictMap connection;
54
55 QString s_ssid = QString::fromLatin1(ssid);
56@@ -386,7 +382,7 @@
57 void addConnection()
58 {
59 QVariantDictMap connection = createConnectionSettings(m_ssid, m_password,
60- m_device_path, m_mode);
61+ m_mode);
62
63 auto add_connection_reply = m_settings->AddConnection(connection);
64 add_connection_reply.waitForFinished();
65@@ -440,39 +436,6 @@
66 }
67
68 /**
69- * Returns a QDBusObjectPath of a wireless device. For now
70- * it returns the first device.
71- */
72- void getWirelessDevice ()
73- {
74- // find the first wlan adapter for now
75- auto reply1 = m_manager->GetDevices();
76- reply1.waitForFinished();
77-
78- if(!reply1.isValid()) {
79- qCritical() << "Could not get network device: "
80- << reply1.error().message();
81- m_device_path = QDBusObjectPath();
82- return;
83- }
84- auto devices = reply1.value();
85-
86- QDBusObjectPath dev;
87- for (const auto &d : devices) {
88- OrgFreedesktopNetworkManagerDeviceInterface iface(NM_DBUS_SERVICE, d.path(), m_manager->connection());
89- auto type_v = iface.deviceType();
90-
91- if (type_v == NM_DEVICE_TYPE_WIFI)
92- {
93- m_device_path = d;
94- return;
95- }
96- }
97- qCritical() << "Wireless device not found, hotspot functionality is inoperative.";
98- m_device_path = dev;
99- }
100-
101- /**
102 * Helper to check if the hotspot on a given QDBusObjectPath is active
103 * or not. It checks if the Connection.Active [1] for the given
104 * path is in NetworkManager's ActiveConnections property [2].
105@@ -530,6 +493,22 @@
106 m_password = QString::fromStdString(result);
107 }
108
109+ void setDisconnectWifi(bool disconnect)
110+ {
111+ if (!m_isHybrisWlan)
112+ {
113+ return;
114+ }
115+
116+ if (m_disconnectWifi == disconnect)
117+ {
118+ return;
119+ }
120+
121+ m_disconnectWifi = disconnect;
122+ Q_EMIT p.disconnectWifiChanged(m_disconnectWifi);
123+ }
124+
125 public Q_SLOTS:
126 void onNewConnection(const QDBusObjectPath& path)
127 {
128@@ -653,11 +632,12 @@
129 QString m_password;
130 QByteArray m_ssid = "Ubuntu";
131
132- QDBusObjectPath m_device_path;
133-
134 QPowerd::UPtr m_powerd;
135 QPowerd::RequestSPtr m_wakelock;
136
137+ bool m_isHybrisWlan = false;
138+ bool m_disconnectWifi = false;
139+
140 /**
141 * NetworkManager dbus interface proxy we will use to query
142 * against NetworkManager. See
143@@ -680,6 +660,8 @@
144 HotspotManager::HotspotManager(const QDBusConnection& connection, QObject *parent) :
145 QObject(parent), d(new Priv(*this))
146 {
147+ d->m_isHybrisWlan = d->isHybrisWlan();
148+
149 d->m_manager = make_unique<OrgFreedesktopNetworkManagerInterface>(
150 NM_DBUS_SERVICE, NM_DBUS_PATH, connection);
151 d->m_settings = make_unique<OrgFreedesktopNetworkManagerSettingsInterface>(
152@@ -688,7 +670,6 @@
153 d->m_powerd = make_unique<QPowerd>(connection);
154
155 d->generatePassword();
156- d->getWirelessDevice();
157
158 // Stored is false if hotspot path is empty.
159 d->getHotspot();
160@@ -729,6 +710,8 @@
161 return;
162 }
163
164+ d->setDisconnectWifi(value);
165+
166 // We are enabling a hotspot
167 if (value)
168 {
169@@ -840,3 +823,8 @@
170 Q_EMIT modeChanged(value);
171 }
172 }
173+
174+bool HotspotManager::disconnectWifi() const
175+{
176+ return d->m_disconnectWifi;
177+}
178
179=== modified file 'src/indicator/nmofono/hotspot-manager.h'
180--- src/indicator/nmofono/hotspot-manager.h 2015-08-05 09:18:11 +0000
181+++ src/indicator/nmofono/hotspot-manager.h 2015-08-17 11:05:23 +0000
182@@ -114,6 +114,10 @@
183 READ stored
184 NOTIFY storedChanged)
185
186+ Q_PROPERTY( bool disconnectWifi
187+ READ disconnectWifi
188+ NOTIFY disconnectWifiChanged)
189+
190 public:
191 typedef std::shared_ptr<HotspotManager> SPtr;
192
193@@ -131,6 +135,8 @@
194
195 QString mode() const;
196
197+ bool disconnectWifi() const;
198+
199 Q_SIGNALS:
200 void enabledChanged(bool enabled);
201
202@@ -142,6 +148,8 @@
203
204 void modeChanged(const QString& mode);
205
206+ void disconnectWifiChanged(bool disconnect);
207+
208 /*
209 * The mapping of code to string is taken from
210 * http://bazaar.launchpad.net/~vcs-imports/
211
212=== modified file 'src/indicator/nmofono/manager-impl.cpp'
213--- src/indicator/nmofono/manager-impl.cpp 2015-08-17 11:05:23 +0000
214+++ src/indicator/nmofono/manager-impl.cpp 2015-08-17 11:05:23 +0000
215@@ -38,6 +38,7 @@
216
217 #include <QMap>
218 #include <QList>
219+#include <QRegularExpression>
220 #include <NetworkManager.h>
221 #include <QDebug>
222 #include <algorithm>
223@@ -47,6 +48,8 @@
224
225 namespace nmofono {
226
227+static const QRegularExpression ACCESS_POINT_EXPRESSION("^ap\\d+$");
228+
229 class ManagerImpl::Private : public QObject
230 {
231 Q_OBJECT
232@@ -417,13 +420,18 @@
233 d->m_killSwitch);
234
235 // We're not interested in showing access points
236- if (tmp->mode() != wifi::WifiLink::Mode::ap)
237+ if (!ACCESS_POINT_EXPRESSION.match(tmp->name()).hasMatch())
238 {
239 // Wire up enabling / disabling AP visibility to the hotspot enabled state
240 tmp->setHideAccessPoints(d->m_hotspotManager->enabled());
241 QObject::connect(d->m_hotspotManager.get(), &HotspotManager::enabledChanged,
242 tmp.get(), &wifi::WifiLink::setHideAccessPoints);
243
244+ // Disconnect wifi if we're on hybris
245+ tmp->setDisconnectWifi(d->m_hotspotManager->disconnectWifi());
246+ QObject::connect(d->m_hotspotManager.get(), &HotspotManager::disconnectWifiChanged,
247+ tmp.get(), &wifi::WifiLink::setDisconnectWifi);
248+
249 link = tmp;
250 }
251 }
252
253=== modified file 'src/indicator/nmofono/wifi/wifi-link-impl.cpp'
254--- src/indicator/nmofono/wifi/wifi-link-impl.cpp 2015-08-17 11:05:23 +0000
255+++ src/indicator/nmofono/wifi/wifi-link-impl.cpp 2015-08-17 11:05:23 +0000
256@@ -79,6 +79,7 @@
257 unique_ptr<QMetaObject::Connection> m_signalStrengthConnection;
258 bool m_connecting = false;
259 bool m_hideAccessPoints = false;
260+ bool m_disconnectWifi = false;
261
262 void setStatus(Status status)
263 {
264@@ -546,6 +547,23 @@
265 d->strengthUpdated();
266 }
267
268+void
269+WifiLinkImpl::setDisconnectWifi(bool disconnect)
270+{
271+ if (disconnect == d->m_disconnectWifi)
272+ {
273+ return;
274+ }
275+
276+ d->m_dev->setAutoconnect(!disconnect);
277+ if (disconnect && d->m_activeConnection)
278+ {
279+ // Disconnect from the current network
280+ d->m_nm->DeactivateConnection(
281+ QDBusObjectPath(d->m_activeConnection->path()));
282+ }
283+}
284+
285 }
286 }
287
288
289=== modified file 'src/indicator/nmofono/wifi/wifi-link-impl.h'
290--- src/indicator/nmofono/wifi/wifi-link-impl.h 2015-08-17 11:05:23 +0000
291+++ src/indicator/nmofono/wifi/wifi-link-impl.h 2015-08-17 11:05:23 +0000
292@@ -58,6 +58,8 @@
293
294 void setHideAccessPoints(bool) override;
295
296+ void setDisconnectWifi(bool) override;
297+
298 Mode mode() const override;
299
300 Signal signal() const override;
301
302=== modified file 'src/indicator/nmofono/wifi/wifi-link.h'
303--- src/indicator/nmofono/wifi/wifi-link.h 2015-08-17 11:05:23 +0000
304+++ src/indicator/nmofono/wifi/wifi-link.h 2015-08-17 11:05:23 +0000
305@@ -83,6 +83,8 @@
306 public Q_SLOTS:
307 virtual void setHideAccessPoints(bool) = 0;
308
309+ virtual void setDisconnectWifi(bool) = 0;
310+
311 Q_SIGNALS:
312 void accessPointsUpdated(const QSet<AccessPoint::Ptr>&);
313

Subscribers

People subscribed via source and target branches