Skip to content

Latest commit

 

History

History
788 lines (667 loc) · 25.2 KB

qconnectionagent.cpp

File metadata and controls

788 lines (667 loc) · 25.2 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd
** Contact: lorn.potter@gmail.com
**
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/
#include "qconnectionagent.h"
Apr 7, 2014
Apr 7, 2014
18
#include "connectiond_adaptor.h"
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "wakeupwatcher.h"
#include <connman-qt5/useragent.h>
#include <connman-qt5/networkmanager.h>
#include <connman-qt5/networktechnology.h>
#include <connman-qt5/networkservice.h>
#include <connman-qt5/sessionagent.h>
#include <QtDBus/QDBusConnection>
#include <QObject>
#include <QSettings>
#define CONND_SERVICE "com.jolla.Connectiond"
#define CONND_PATH "/Connectiond"
#define CONND_SESSION_PATH = "/ConnectionSession"
QConnectionAgent::QConnectionAgent(QObject *parent) :
QObject(parent),
ua(0),
netman(NetworkManagerFactory::createInstance()),
currentNetworkState(QString()),
isEthernet(false),
connmanAvailable(false),
tetheringWifiTech(0),
tetheringEnabled(false),
flightModeSuppression(false),
May 8, 2014
May 8, 2014
46
scanTimeoutInterval(1),
Jul 7, 2015
Jul 7, 2015
47
48
delayedTethering(false),
valid(true)
49
50
51
{
qDebug() << Q_FUNC_INFO;
Jul 7, 2015
Jul 7, 2015
52
new ConnAdaptor(this);
53
54
55
56
QDBusConnection dbus = QDBusConnection::sessionBus();
if (!dbus.registerService(CONND_SERVICE)) {
qDebug() << "XXXXXXXXXXX could not register service XXXXXXXXXXXXXXXXXX";
Jul 7, 2015
Jul 7, 2015
57
valid = false;
58
59
60
61
}
if (!dbus.registerObject(CONND_PATH, this)) {
qDebug() << "XXXXXXXXXXX could not register object XXXXXXXXXXXXXXXXXX";
Jul 7, 2015
Jul 7, 2015
62
valid = false;
Apr 15, 2014
Apr 15, 2014
65
connect(this,SIGNAL(configurationNeeded(QString)),this,SLOT(openConnectionDialog(QString)));
Jul 7, 2015
Jul 7, 2015
67
connect(netman,SIGNAL(availabilityChanged(bool)),this,SLOT(connmanAvailabilityChanged(bool)));
68
69
70
connect(netman,SIGNAL(servicesListChanged(QStringList)),this,SLOT(servicesListChanged(QStringList)));
connect(netman,SIGNAL(stateChanged(QString)),this,SLOT(networkStateChanged(QString)));
connect(netman,SIGNAL(offlineModeChanged(bool)),this,SLOT(offlineModeChanged(bool)));
Apr 15, 2014
Apr 15, 2014
71
72
connect(netman,SIGNAL(servicesChanged()),this,SLOT(servicesChanged()));
connect(netman,SIGNAL(technologiesChanged()),this,SLOT(techChanged()));
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
QFile connmanConf("/etc/connman/main.conf");
if (connmanConf.open(QIODevice::ReadOnly | QIODevice::Text)) {
while (!connmanConf.atEnd()) {
QString line = connmanConf.readLine();
if (line.startsWith("DefaultAutoConnectTechnologies")) {
QString token = line.section(" = ",1,1).simplified();
techPreferenceList = token.split(",");
break;
}
}
connmanConf.close();
}
if (techPreferenceList.isEmpty())
//ethernet,bluetooth,cellular,wifi is default
techPreferenceList << "bluetooth" << "wifi" << "cellular" << "ethernet";
mceWatch = new WakeupWatcher(this);
connect(mceWatch,SIGNAL(displayStateChanged(QString)),this,SLOT(displayStateChanged(QString)));
connmanAvailable = QDBusConnection::systemBus().interface()->isServiceRegistered("net.connman");
scanTimer = new QTimer(this);
connect(scanTimer,SIGNAL(timeout()),this,SLOT(scanTimeout()));
scanTimer->setSingleShot(true);
Jul 7, 2015
Jul 7, 2015
98
if (connmanAvailable && valid)
99
100
101
102
103
104
105
setup();
}
QConnectionAgent::~QConnectionAgent()
{
}
Jul 7, 2015
Jul 7, 2015
106
bool QConnectionAgent::isValid() const
Jul 7, 2015
Jul 7, 2015
108
return valid;
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
}
// from useragent
void QConnectionAgent::onUserInputRequested(const QString &servicePath, const QVariantMap &fields)
{
qDebug() << servicePath;
// gets called when a connman service gets called to connect and needs more configurations.
Q_EMIT userInputRequested(servicePath, fields);
}
// from useragent
void QConnectionAgent::onUserInputCanceled()
{
qDebug() ;
Q_EMIT userInputCanceled();
}
// from useragent
void QConnectionAgent::onErrorReported(const QString &servicePath, const QString &error)
{
Jun 24, 2014
Jun 24, 2014
129
130
131
132
// Suppress errors when switching to offline mode
if (error == "connect-failed" && servicePath.contains("cellular") && netman->offlineMode())
return;
Aug 25, 2014
Aug 25, 2014
133
if (!tetheringWifiTech) return;
Jun 24, 2014
Jun 24, 2014
134
135
136
137
// Suppress errors when switching to tethering mode
if ((delayedTethering || tetheringWifiTech->tethering()) && servicePath.contains(QStringLiteral("wifi")))
return;
138
139
140
141
142
143
144
145
146
qDebug() << "<<<<<<<<<<<<<<<<<<<<" << servicePath << error;
Q_EMIT errorReported(servicePath, error);
}
// from useragent
void QConnectionAgent::onConnectionRequest()
{
sendConnectReply("Suppress", 15);
qDebug() << flightModeSuppression;
Jul 9, 2014
Jul 9, 2014
147
bool okToRequest = true;
Oct 1, 2014
Oct 1, 2014
148
149
150
Q_FOREACH (Service elem, orderedServicesList) {
qDebug() << "checking" << elem.service->name() << elem.service->autoConnect();
if (elem.service->autoConnect()) {
Jul 9, 2014
Jul 9, 2014
151
152
153
154
155
okToRequest = false;
break;
}
}
if (!flightModeSuppression && okToRequest) {
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Q_EMIT connectionRequest();
}
}
void QConnectionAgent::sendConnectReply(const QString &in0, int in1)
{
ua->sendConnectReply(in0, in1);
}
void QConnectionAgent::sendUserReply(const QVariantMap &input)
{
qDebug() << Q_FUNC_INFO;
ua->sendUserReply(input);
}
void QConnectionAgent::servicesListChanged(const QStringList &list)
{
Oct 1, 2014
Oct 1, 2014
173
174
175
176
177
bool changed = false;
Q_FOREACH(const QString &path, list) {
if (orderedServicesList.indexOf(path) == -1) {
//added
178
qDebug() << Q_FUNC_INFO << "added" << path;
Oct 1, 2014
Oct 1, 2014
179
180
changed = true;
break;
181
182
183
}
}
Oct 1, 2014
Oct 1, 2014
184
185
186
187
188
189
190
191
if (!changed)
Q_FOREACH (Service elem, orderedServicesList) {
if (list.indexOf(elem.path) == -1) {
//removed
qDebug() << Q_FUNC_INFO << "removed" << elem.path;
changed = true;
break;
}
Oct 1, 2014
Oct 1, 2014
193
194
195
if (changed)
updateServices();
196
197
198
199
200
201
202
203
}
void QConnectionAgent::serviceErrorChanged(const QString &error)
{
qDebug() << error;
if (error == "Operation aborted")
return;
NetworkService *service = static_cast<NetworkService *>(sender());
Apr 19, 2014
Apr 19, 2014
204
205
206
207
208
209
210
211
if (error == "connect-failed"
&& (service->type() == "cellular") && netman->offlineMode()) {
return;
}
if (error == "In progress" || error.contains("Method")) // catch dbus errors and discard
return;
212
213
214
215
216
217
Q_EMIT errorReported(service->path(),error);
}
void QConnectionAgent::serviceStateChanged(const QString &state)
{
NetworkService *service = static_cast<NetworkService *>(sender());
May 29, 2014
May 29, 2014
218
219
if (!service)
return;
220
221
222
qDebug() << state << service->name() << service->strength();
qDebug() << "currentNetworkState" << currentNetworkState;
Jun 27, 2014
Jun 27, 2014
223
224
225
226
227
228
if (state == "ready" && service->type() == "wifi"
&& !delayedTethering
&& netman->defaultRoute()->type() == "cellular") {
netman->defaultRoute()->requestDisconnect();
}
May 29, 2014
May 29, 2014
229
230
if (!service->favorite() || !netman->getTechnology(service->type())
|| !netman->getTechnology(service->type())->powered()) {
231
232
233
234
235
236
qDebug() << "not fav or not powered";
return;
}
if (state == "disconnect") {
ua->sendConnectReply("Clear");
}
Apr 30, 2014
Apr 30, 2014
237
238
239
240
if (state == "failure") {
if (delayedTethering && service->type() == "cellular" && tetheringWifiTech->tethering()) {
Q_EMIT tetheringFinished(false);
}
241
242
// serviceInProgress.clear();
// // service->requestDisconnect();
Apr 30, 2014
Apr 30, 2014
243
}
Apr 30, 2014
Apr 30, 2014
245
246
247
if (delayedTethering && service->type() == "wifi" && state == "association") {
service->requestDisconnect();
}
Jun 27, 2014
Jun 27, 2014
248
249
250
251
if (state == "online") {
Q_EMIT connectionState(state, service->type());
Apr 30, 2014
Apr 30, 2014
252
253
254
255
256
257
258
259
260
if (service->type() == "wifi" && delayedTethering) {
netman->getTechnology(service->type())->setTethering(true);
}
if (service->type() == "cellular" && delayedTethering) {
if (!tetheringWifiTech->tethering()) {
tetheringWifiTech->setTethering(true);
}
}
}
261
262
//auto migrate
if (state == "idle") {
Apr 30, 2014
Apr 30, 2014
263
264
265
266
if (service->type() == "wifi" && delayedTethering) {
netman->getTechnology(service->type())->setTethering(true);
}
} else {
Oct 1, 2014
Oct 1, 2014
267
updateServices();
268
269
270
271
272
273
274
275
276
277
}
currentNetworkState = state;
QSettings confFile;
confFile.beginGroup("Connectionagent");
confFile.setValue("connected",currentNetworkState);
}
// from plugin/qml
void QConnectionAgent::connectToType(const QString &type)
{
Apr 17, 2014
Apr 17, 2014
278
279
if (!netman)
return;
Apr 17, 2014
Apr 17, 2014
281
if (netman->technologyPathForType(type).isEmpty()) {
282
283
284
285
Q_EMIT errorReported("","Type not valid");
return;
}
Oct 10, 2014
Oct 10, 2014
286
// Connman is using "cellular" and "wifi" as part of the service path
Aug 28, 2014
Aug 28, 2014
287
288
289
290
291
292
293
294
295
QString convType;
if (type.contains("mobile")) {
convType="cellular";
} else if (type.contains("wlan")) {
convType="wifi";
} else {
convType=type;
}
Oct 10, 2014
Oct 10, 2014
296
bool found = false;
Oct 1, 2014
Oct 1, 2014
297
Q_FOREACH (Service elem, orderedServicesList) {
Oct 10, 2014
Oct 10, 2014
298
if (elem.path.contains(convType)) {
Oct 1, 2014
Oct 1, 2014
299
300
if (!isStateOnline(elem.service->state())) {
if (elem.service->autoConnect()) {
Jun 9, 2014
Jun 9, 2014
301
qDebug() << "<<<<<<<<<<< requestConnect() >>>>>>>>>>>>";
Oct 1, 2014
Oct 1, 2014
302
elem.service->requestConnect();
Aug 28, 2014
Aug 28, 2014
303
return;
Oct 10, 2014
Oct 10, 2014
304
305
306
} else if (!elem.path.contains("cellular")) {
// ignore cellular that are not on autoconnect
found = true;
Apr 17, 2014
Apr 17, 2014
308
309
} else {
return;
310
311
312
}
}
}
Apr 17, 2014
Apr 17, 2014
313
Oct 10, 2014
Oct 10, 2014
314
315
316
317
318
319
// Can't connect to the service of a type that doesn't exist
if (!found)
return;
// Substitute "wifi" with "wlan" for lipstick
if (type.contains("wifi"))
Aug 28, 2014
Aug 28, 2014
320
321
322
convType="wlan";
Q_EMIT configurationNeeded(convType);
323
324
325
326
327
328
329
}
void QConnectionAgent::onScanFinished()
{
qDebug() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
}
Oct 1, 2014
Oct 1, 2014
330
void QConnectionAgent::updateServices()
331
332
{
qDebug() << Q_FUNC_INFO;
Oct 1, 2014
Oct 1, 2014
333
ServiceList oldServices = orderedServicesList;
334
335
336
337
338
339
340
341
342
343
orderedServicesList.clear();
Q_FOREACH (const QString &tech,techPreferenceList) {
QVector<NetworkService*> services = netman->getServices(tech);
Q_FOREACH (NetworkService *serv, services) {
const QString servicePath = serv->path();
qDebug() << "known service:" << serv->name() << serv->strength();
Oct 1, 2014
Oct 1, 2014
344
345
346
347
Service elem;
elem.path = servicePath;
elem.service = serv;
orderedServicesList << elem;
348
349
350
if (!oldServices.contains(servicePath)) {
//new!
Apr 15, 2014
Apr 15, 2014
351
qDebug() <<"new service"<< servicePath;
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
QObject::connect(serv, SIGNAL(stateChanged(QString)),
this,SLOT(serviceStateChanged(QString)), Qt::UniqueConnection);
QObject::connect(serv, SIGNAL(connectRequestFailed(QString)),
this,SLOT(serviceErrorChanged(QString)), Qt::UniqueConnection);
QObject::connect(serv, SIGNAL(errorChanged(QString)),
this,SLOT(servicesError(QString)), Qt::UniqueConnection);
QObject::connect(serv, SIGNAL(autoConnectChanged(bool)),
this,SLOT(serviceAutoconnectChanged(bool)), Qt::UniqueConnection);
}
}
}
}
void QConnectionAgent::servicesError(const QString &errorMessage)
{
if (errorMessage.isEmpty())
return;
NetworkService *serv = static_cast<NetworkService *>(sender());
qDebug() << serv->name() << errorMessage;
Q_EMIT onErrorReported(serv->path(), errorMessage);
}
void QConnectionAgent::networkStateChanged(const QString &state)
{
qDebug() << state;
QSettings confFile;
confFile.beginGroup("Connectionagent");
if (state != "online")
confFile.setValue("connected","offline");
else
confFile.setValue("connected","online");
if ((state == "online" && netman->defaultRoute()->type() == "cellular")
|| (state == "idle")) {
Apr 30, 2014
Apr 30, 2014
390
391
392
393
if (tetheringWifiTech && tetheringWifiTech->powered()
&& !tetheringWifiTech->tethering())
tetheringWifiTech->scan();
394
395
396
397
// on gprs, scan wifi every scanTimeoutInterval minutes
if (scanTimeoutInterval != 0)
scanTimer->start(scanTimeoutInterval * 60 * 1000);
}
Apr 30, 2014
Apr 30, 2014
398
399
400
401
402
403
404
405
406
407
408
409
if (delayedTethering && state == "online") {
if (tetheringWifiTech->tethering()) {
if (netman->defaultRoute()->type() == "cellular") {
delayedTethering = false;
Q_EMIT tetheringFinished(true);
}
} else {
tetheringWifiTech->setTethering(true);
}
}
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
}
void QConnectionAgent::connmanAvailabilityChanged(bool b)
{
qDebug() << Q_FUNC_INFO;
connmanAvailable = b;
if (b) {
setup();
currentNetworkState = netman->state();
} else {
currentNetworkState = "error";
}
}
void QConnectionAgent::setup()
{
qDebug() << Q_FUNC_INFO
<< connmanAvailable;
if (connmanAvailable) {
qDebug() << Q_FUNC_INFO
<< netman->state();
Jul 7, 2015
Jul 7, 2015
432
delete ua;
433
434
435
436
437
438
439
440
441
442
443
444
445
ua = new UserAgent(this);
connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
this,SLOT(onUserInputRequested(QString,QVariantMap)));
connect(ua,SIGNAL(connectionRequest()),this,SLOT(onConnectionRequest()));
connect(ua,SIGNAL(errorReported(QString, QString)),this,SLOT(onErrorReported(QString, QString)));
connect(ua,SIGNAL(userInputCanceled()),this,SLOT(onUserInputCanceled()));
connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
this,SLOT(onUserInputRequested(QString,QVariantMap)), Qt::UniqueConnection);
connect(ua,SIGNAL(browserRequested(QString,QString)),
this,SLOT(browserRequest(QString,QString)), Qt::UniqueConnection);
Oct 1, 2014
Oct 1, 2014
446
updateServices();
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
offlineModeChanged(netman->offlineMode());
QSettings confFile;
confFile.beginGroup("Connectionagent");
scanTimeoutInterval = confFile.value("scanTimerInterval", "1").toUInt(); //in minutes
if (isStateOnline(netman->state())) {
qDebug() << "default route type:" << netman->defaultRoute()->type();
if (netman->defaultRoute()->type() == "ethernet")
isEthernet = true;
if (netman->defaultRoute()->type() == "cellular" && scanTimeoutInterval != 0)
scanTimer->start(scanTimeoutInterval * 60 * 1000);
}
qDebug() << "config file says" << confFile.value("connected", "online").toString();
}
}
Apr 15, 2014
Apr 15, 2014
465
void QConnectionAgent::technologyPowerChanged(bool powered)
466
467
{
NetworkTechnology *tech = static_cast<NetworkTechnology *>(sender());
Jun 12, 2014
Jun 12, 2014
468
469
if (tech->type() != "wifi")
return;
Sep 29, 2014
Sep 29, 2014
470
471
472
473
if (tetheringWifiTech)
qDebug() << tetheringWifiTech->name() << powered;
else
qDebug() << "tetheringWifiTech is null";
Apr 30, 2014
Apr 30, 2014
474
Jun 12, 2014
Jun 12, 2014
475
476
477
if (netman && powered && delayedTethering) {
// wifi tech might not be ready, so delay this
QTimer::singleShot(1000,this,SLOT(setWifiTetheringEnabled()));
Apr 30, 2014
Apr 30, 2014
478
}
479
480
481
482
}
void QConnectionAgent::techChanged()
{
Apr 30, 2014
Apr 30, 2014
483
484
if (!netman)
return;
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
if (netman->getTechnologies().isEmpty()) {
knownTechnologies.clear();
}
if (!netman->getTechnology("wifi")) {
tetheringWifiTech = 0;
return;
}
if (tetheringWifiTech) {
tetheringEnabled = tetheringWifiTech->tethering();
}
Q_FOREACH(NetworkTechnology *technology,netman->getTechnologies()) {
if (!knownTechnologies.contains(technology->path())) {
knownTechnologies << technology->path();
if (technology->type() == "wifi") {
tetheringWifiTech = technology;
connect(tetheringWifiTech,SIGNAL(poweredChanged(bool)),this,SLOT(technologyPowerChanged(bool)));
Apr 15, 2014
Apr 15, 2014
502
connect(tetheringWifiTech,SIGNAL(scanFinished()),this,SLOT(onScanFinished()));
Apr 30, 2014
Apr 30, 2014
503
504
connect(tetheringWifiTech, SIGNAL(tetheringChanged(bool)),
this,SLOT(techTetheringChanged(bool)), Qt::UniqueConnection);
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
}
} else {
knownTechnologies.removeOne(technology->path());
}
}
}
void QConnectionAgent::browserRequest(const QString &servicePath, const QString &url)
{
Q_UNUSED(servicePath)
qDebug() << servicePath;
qDebug() << url;
Q_EMIT requestBrowser(url);
}
bool QConnectionAgent::isStateOnline(const QString &state)
{
if (state == "online" || state == "ready")
return true;
return false;
}
Apr 30, 2014
Apr 30, 2014
528
void QConnectionAgent::techTetheringChanged(bool on)
Apr 15, 2014
Apr 15, 2014
529
{
Apr 30, 2014
Apr 30, 2014
530
531
532
533
534
535
536
537
538
539
540
qDebug() << on;
tetheringEnabled = on;
NetworkTechnology *technology = static_cast<NetworkTechnology *>(sender());
if (on && delayedTethering && technology) {
QVector <NetworkService *> services = netman->getServices("cellular");
if (services.isEmpty())
return;
NetworkService* cellService = services.at(0);
if (cellService) {
if (cellService->state() == "idle"|| cellService->state() == "failure") {
Jun 9, 2014
Jun 9, 2014
541
qDebug() << "<<<<<<<<<<< requestConnect() >>>>>>>>>>>>";
Apr 30, 2014
Apr 30, 2014
542
543
544
545
546
547
548
549
550
cellService->requestConnect();
} else if (cellService->connected()) {
delayedTethering = false;
Q_EMIT tetheringFinished(true);
}
} else {
stopTethering();
}
}
Apr 15, 2014
Apr 15, 2014
551
552
}
553
554
555
556
557
558
559
560
561
562
void QConnectionAgent::offlineModeChanged(bool b)
{
flightModeSuppression = b;
if (b) {
QTimer::singleShot(5 * 1000 * 60,this,SLOT(flightModeDialogSuppressionTimeout())); //5 minutes
}
}
void QConnectionAgent::flightModeDialogSuppressionTimeout()
{
Jul 7, 2015
Jul 7, 2015
563
flightModeSuppression = false;
564
565
566
567
568
569
}
void QConnectionAgent::displayStateChanged(const QString &state)
{
if (state == "on") {
NetworkTechnology *wifiTech = netman->getTechnology("wifi");
Apr 30, 2014
Apr 30, 2014
570
if (wifiTech && wifiTech->powered() && !wifiTech->connected() && !wifiTech->tethering()) {
571
572
573
574
575
576
577
578
wifiTech->scan();
}
}
}
void QConnectionAgent::serviceAutoconnectChanged(bool on)
{
NetworkService *service = qobject_cast<NetworkService *>(sender());
Apr 15, 2014
Apr 15, 2014
579
580
if (!service)
return;
581
qDebug() << service->path() << "AutoConnect is" << on;
Apr 15, 2014
Apr 15, 2014
582
583
if (!on) {
Apr 15, 2014
Apr 15, 2014
584
585
if (service->state() != "idle")
service->requestDisconnect();
586
587
588
}
}
Apr 15, 2014
Apr 15, 2014
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
bool QConnectionAgent::isBestService(NetworkService *service)
{
qDebug() << Q_FUNC_INFO
<< service->path()
<< tetheringEnabled
<< netman->defaultRoute()->path().contains(service->path())
<< (netman->defaultRoute()->state() != "online");
if (tetheringEnabled) return false;
if (netman->offlineMode() && service->type() == "cellular") return false;
if (netman->defaultRoute()->type() == "wifi" && service->type() == "cellular") return false;
if (netman->defaultRoute()->path().contains(service->path())) return false;
return true;
}
605
606
void QConnectionAgent::scanTimeout()
{
Apr 30, 2014
Apr 30, 2014
607
if (!tetheringWifiTech || tetheringWifiTech->tethering())
Jul 7, 2015
Jul 7, 2015
608
return;
Apr 30, 2014
Apr 30, 2014
609
610
if (tetheringWifiTech->powered() && !tetheringWifiTech->connected() && netman->defaultRoute()->type() != "wifi" ) {
611
612
613
614
615
616
617
tetheringWifiTech->scan();
qDebug() << "start scanner" << scanTimeoutInterval;
if (scanTimeoutInterval != 0) {
scanTimer->start(scanTimeoutInterval * 60 * 1000);
}
}
}
Apr 15, 2014
Apr 15, 2014
618
619
620
621
622
623
void QConnectionAgent::servicesChanged()
{
qDebug();
disconnect(netman,SIGNAL(servicesChanged()),this,SLOT(servicesChanged()));
Oct 1, 2014
Oct 1, 2014
624
updateServices();
Apr 15, 2014
Apr 15, 2014
625
626
627
628
629
630
}
QString QConnectionAgent::findBestConnectableService()
{
for (int i = 0; i < orderedServicesList.count(); i++) {
Oct 1, 2014
Oct 1, 2014
631
QString path = orderedServicesList.at(i).path;
Apr 15, 2014
Apr 15, 2014
632
Oct 1, 2014
Oct 1, 2014
633
NetworkService *service = orderedServicesList.at(i).service;
Apr 15, 2014
Apr 15, 2014
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
if (!service)
continue;
qDebug() << "looking at"
<< service->name()
<< service->autoConnect();
bool online = isStateOnline(netman->defaultRoute()->state());
qDebug() << "state is"<< online << netman->defaultRoute()->path();
if (!service->autoConnect()) {
continue;
}
qDebug() <<Q_FUNC_INFO<< "continued"
<< online
<< (netman->defaultRoute()->path() == service->path())
<< netman->defaultRoute()->strength()
<< service->strength();
if ((netman->defaultRoute()->type() == "wifi" && service->type() == "wifi")
&& netman->defaultRoute()->strength() > service->strength())
return QString(); //better quality already connected
if (netman->defaultRoute()->type() == "wifi" && service->type() != "wifi")
return QString(); // prefer connected wifi
if (isBestService(service)
Aug 22, 2014
Aug 22, 2014
662
&& service->favorite()) {
Apr 15, 2014
Apr 15, 2014
663
664
665
666
667
668
669
670
671
qDebug() << path;
return path;
}
}
return QString();
}
void QConnectionAgent::removeAllTypes(const QString &type)
{
Oct 1, 2014
Oct 1, 2014
672
673
Q_FOREACH (Service elem, orderedServicesList) {
if (elem.path.contains(type))
Oct 1, 2014
Oct 1, 2014
674
orderedServicesList.remove(elem.path);
Apr 15, 2014
Apr 15, 2014
675
676
}
}
Apr 15, 2014
Apr 15, 2014
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
void QConnectionAgent::openConnectionDialog(const QString &type)
{
// open Connection Selector
QDBusInterface *connSelectorInterface = new QDBusInterface(QStringLiteral("com.jolla.lipstick.ConnectionSelector"),
QStringLiteral("/"),
QStringLiteral("com.jolla.lipstick.ConnectionSelectorIf"),
QDBusConnection::sessionBus(),
this);
connSelectorInterface->connection().connect(QStringLiteral("com.jolla.lipstick.ConnectionSelector"),
QStringLiteral("/"),
QStringLiteral("com.jolla.lipstick.ConnectionSelectorIf"),
QStringLiteral("connectionSelectorClosed"),
this,
SLOT(connectionSelectorClosed(bool)));
QList<QVariant> args;
args.append(type);
QDBusMessage reply = connSelectorInterface->callWithArgumentList(QDBus::NoBlock,
QStringLiteral("openConnection"), args);
}
Apr 30, 2014
Apr 30, 2014
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
void QConnectionAgent::startTethering(const QString &type)
{
if (!netman | (type != "wifi")) { //we only support wifi for now
Q_EMIT tetheringFinished(false);
return;
}
NetworkTechnology *tetherTech = netman->getTechnology(type);
if (!tetherTech) {
Q_EMIT tetheringFinished(false);
return;
}
QVector <NetworkService *> services = netman->getServices("cellular");
if (services.isEmpty()) {
Q_EMIT tetheringFinished(false);
return;
}
NetworkService *cellService = services.at(0);
if (!cellService || netman->offlineMode()) {
Q_EMIT tetheringFinished(false);
return;
}
QSettings confFile;
confFile.beginGroup("Connectionagent");
bool cellConnected = cellService->connected();
bool cellAutoconnect = cellService->autoConnect();
// save cellular connection state
confFile.setValue("tetheringCellularConnected",cellConnected);
confFile.setValue("tetheringCellularAutoconnect",cellAutoconnect);
bool techPowered = tetherTech->powered();
// save wifi powered state
confFile.setValue("tetheringTechPowered",techPowered);
confFile.setValue("tetheringType",type);
delayedTethering = true;
Aug 25, 2014
Aug 25, 2014
741
742
tetheringWifiTech = tetherTech;
Apr 30, 2014
Apr 30, 2014
743
744
745
746
747
748
749
if (!techPowered) {
tetherTech->setPowered(true);
} else {
tetherTech->setTethering(true);
}
}
Jul 11, 2014
Jul 11, 2014
750
void QConnectionAgent::stopTethering(bool keepPowered)
Apr 30, 2014
Apr 30, 2014
751
752
753
754
755
756
757
758
759
760
761
762
{
delayedTethering = false;
QSettings confFile;
confFile.beginGroup("Connectionagent");
NetworkTechnology *tetherTech = netman->getTechnology(confFile.value("tetheringType","wifi").toString());
if (tetherTech && tetherTech->tethering()) {
tetherTech->setTethering(false);
}
bool b = confFile.value("tetheringCellularConnected").toBool();
bool ab = confFile.value("tetheringCellularAutoconnect").toBool();
Oct 1, 2014
Oct 1, 2014
763
764
765
Q_FOREACH (Service elem, orderedServicesList) {
if (elem.path.contains("cellular")) {
if (isStateOnline(elem.service->state())) {
Apr 30, 2014
Apr 30, 2014
766
767
qDebug() << "disconnect mobile data";
if (!b)
Oct 1, 2014
Oct 1, 2014
768
elem.service->requestDisconnect();
Apr 30, 2014
Apr 30, 2014
769
if (!ab)
Oct 1, 2014
Oct 1, 2014
770
elem.service->setAutoConnect(false);
Apr 30, 2014
Apr 30, 2014
771
772
773
774
775
}
}
}
b = confFile.value("tetheringTechPowered").toBool();
Jul 11, 2014
Jul 11, 2014
776
if (!b && tetherTech && !keepPowered) {
Apr 30, 2014
Apr 30, 2014
777
778
779
780
tetherTech->setPowered(false);
}
Q_EMIT tetheringFinished(false);
}
Jun 12, 2014
Jun 12, 2014
781
782
783
784
785
786
787
788
void QConnectionAgent::setWifiTetheringEnabled()
{
if (tetheringWifiTech) {
qDebug() << "set tethering";
tetheringWifiTech->setTethering(delayedTethering);
}
}