Skip to content

Latest commit

 

History

History
535 lines (470 loc) · 21.9 KB

developermodesettings.cpp

File metadata and controls

535 lines (470 loc) · 21.9 KB
 
Nov 15, 2019
Nov 15, 2019
2
3
* Copyright (c) 2013 – 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
4
* Contact: Thomas Perl <thomas.perl@jollamobile.com>
Apr 28, 2018
Apr 28, 2018
5
* Contact: Raine Makelainen <raine.makelainen@jolla.com>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#include "developermodesettings.h"
Apr 25, 2018
Apr 25, 2018
36
#include "logging_p.h"
37
38
39
40
#include <QFile>
#include <QDir>
#include <QDBusReply>
Feb 5, 2018
Feb 5, 2018
41
#include <QNetworkInterface>
Apr 28, 2018
Apr 28, 2018
42
#include <transaction.h>
Mar 12, 2018
Mar 12, 2018
43
Dec 10, 2015
Dec 10, 2015
44
45
#include <getdef.h>
#include <pwd.h>
46
47
48
49
50
51
52
53
/* Symbolic constants */
#define PROGRESS_INDETERMINATE (-1)
/* Interfaces for IP addresses */
#define USB_NETWORK_FALLBACK_INTERFACE "usb0"
#define USB_NETWORK_FALLBACK_IP "192.168.2.15"
#define WLAN_NETWORK_INTERFACE "wlan0"
May 21, 2014
May 21, 2014
54
#define WLAN_NETWORK_FALLBACK_INTERFACE "tether"
Oct 3, 2013
Oct 3, 2013
56
57
/* A file that is provided by the developer mode package */
#define DEVELOPER_MODE_PROVIDED_FILE "/usr/bin/devel-su"
Jun 21, 2018
Jun 21, 2018
58
#define DEVELOPER_MODE_PACKAGE "jolla-developer-mode"
Nov 15, 2019
Nov 15, 2019
59
#define DEVELOPER_MODE_PACKAGE_PRELOAD_DIR "/var/lib/jolla-developer-mode/preloaded/"
Oct 3, 2013
Oct 3, 2013
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* D-Bus service */
#define USB_MODED_SERVICE "com.meego.usb_moded"
#define USB_MODED_PATH "/com/meego/usb_moded"
#define USB_MODED_INTERFACE "com.meego.usb_moded"
/* D-Bus method names */
#define USB_MODED_GET_NET_CONFIG "get_net_config"
#define USB_MODED_SET_NET_CONFIG "net_config"
/* USB Mode Daemon network configuration properties */
#define USB_MODED_CONFIG_IP "ip"
#define USB_MODED_CONFIG_INTERFACE "interface"
Apr 28, 2018
Apr 28, 2018
74
static QMap<QString,QString> enumerate_network_interfaces()
75
76
77
{
QMap<QString,QString> result;
Jun 21, 2018
Jun 21, 2018
78
79
for (const QNetworkInterface &intf : QNetworkInterface::allInterfaces()) {
for (const QNetworkAddressEntry &entry : intf.addressEntries()) {
80
81
82
83
84
85
86
87
88
if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol) {
result[intf.name()] = entry.ip().toString();
}
}
}
return result;
}
Nov 15, 2019
Nov 15, 2019
89
90
91
92
93
94
95
96
97
98
99
static QString get_cached_package(const QString &version)
{
QDir dir(DEVELOPER_MODE_PACKAGE_PRELOAD_DIR);
QStringList filters;
filters << QStringLiteral("%1-%2.*.rpm").arg(DEVELOPER_MODE_PACKAGE).arg(version);
auto preloaded = dir.entryList(filters, QDir::Files, QDir::Name);
if (preloaded.empty())
return QString();
return dir.absoluteFilePath(preloaded.last());
}
100
101
DeveloperModeSettings::DeveloperModeSettings(QObject *parent)
: QObject(parent)
Jun 21, 2018
Jun 21, 2018
102
, m_usbModeDaemon(USB_MODED_SERVICE, USB_MODED_PATH, USB_MODED_INTERFACE, QDBusConnection::systemBus())
103
104
105
, m_wlanIpAddress("-")
, m_usbInterface(USB_NETWORK_FALLBACK_INTERFACE)
, m_usbIpAddress(USB_NETWORK_FALLBACK_IP)
Dec 10, 2015
Dec 10, 2015
106
, m_username("nemo")
Feb 5, 2018
Feb 5, 2018
107
, m_developerModeEnabled(QFile::exists(DEVELOPER_MODE_PROVIDED_FILE))
Jun 21, 2018
Jun 21, 2018
108
109
, m_workStatus(Idle)
, m_workProgress(PROGRESS_INDETERMINATE)
Apr 28, 2018
Apr 28, 2018
110
111
, m_transactionRole(PackageKit::Transaction::RoleUnknown)
, m_transactionStatus(PackageKit::Transaction::StatusUnknown)
Jun 21, 2018
Jun 21, 2018
112
, m_refreshedForInstall(false)
Nov 15, 2019
Nov 15, 2019
113
114
, m_localInstallFailed(false)
, m_localDeveloperModePackagePath(get_cached_package(QStringLiteral("*"))) // Initialized to possibly incompatible package
Dec 10, 2015
Dec 10, 2015
116
117
118
119
120
int uid = getdef_num("UID_MIN", -1);
struct passwd *pwd;
if ((pwd = getpwuid(uid)) != NULL) {
m_username = QString(pwd->pw_name);
} else {
Apr 25, 2018
Apr 25, 2018
121
qCWarning(lcDeveloperModeLog) << "Failed to return username using getpwuid()";
Dec 10, 2015
Dec 10, 2015
122
123
}
Nov 15, 2019
Nov 15, 2019
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Resolve and update local package path
if (!m_localDeveloperModePackagePath.isEmpty()) {
PackageKit::Transaction *resolvePackage = PackageKit::Daemon::resolve(DEVELOPER_MODE_PACKAGE"-preload", PackageKit::Transaction::FilterInstalled);
connect(resolvePackage, &PackageKit::Transaction::errorCode, this, &DeveloperModeSettings::reportTransactionErrorCode);
connect(resolvePackage, &PackageKit::Transaction::package,
this, [this](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary) {
Q_UNUSED(summary)
Q_ASSERT(info == PackageKit::Transaction::InfoInstalled);
const QString version = PackageKit::Transaction::packageVersion(packageID);
m_localDeveloperModePackagePath = get_cached_package(version);
if (m_localDeveloperModePackagePath.isEmpty()) {
emit repositoryAccessRequiredChanged();
}
qCDebug(lcDeveloperModeLog) << "Preload package version: " << version << ", local package path: " << m_localDeveloperModePackagePath;
});
}
141
142
143
144
145
146
147
148
149
150
refresh();
// TODO: Watch WLAN / USB IP addresses for changes
// TODO: Watch package manager for changes to developer mode
}
DeveloperModeSettings::~DeveloperModeSettings()
{
}
Apr 28, 2018
Apr 28, 2018
151
QString DeveloperModeSettings::wlanIpAddress() const
152
153
154
155
{
return m_wlanIpAddress;
}
Apr 28, 2018
Apr 28, 2018
156
QString DeveloperModeSettings::usbIpAddress() const
157
158
159
160
{
return m_usbIpAddress;
}
Apr 28, 2018
Apr 28, 2018
161
QString DeveloperModeSettings::username() const
Dec 10, 2015
Dec 10, 2015
162
163
164
165
{
return m_username;
}
Apr 28, 2018
Apr 28, 2018
166
bool DeveloperModeSettings::developerModeEnabled() const
167
168
169
170
{
return m_developerModeEnabled;
}
Jun 21, 2018
Jun 21, 2018
171
enum DeveloperModeSettings::Status DeveloperModeSettings::workStatus() const
Jun 21, 2018
Jun 21, 2018
173
return m_workStatus;
174
175
}
Jun 21, 2018
Jun 21, 2018
176
int DeveloperModeSettings::workProgress() const
Jun 21, 2018
Jun 21, 2018
178
return m_workProgress;
179
180
}
Nov 15, 2019
Nov 15, 2019
181
182
183
184
185
186
bool DeveloperModeSettings::repositoryAccessRequired() const
{
// Aka local-install-of-developer-mode-package-is-not-possible
return m_localInstallFailed || m_localDeveloperModePackagePath.isEmpty();
}
Apr 28, 2018
Apr 28, 2018
187
void DeveloperModeSettings::setDeveloperMode(bool enabled)
Apr 28, 2018
Apr 28, 2018
189
if (m_developerModeEnabled != enabled) {
Jun 21, 2018
Jun 21, 2018
190
191
192
193
194
195
if (m_workStatus != Idle) {
qCWarning(lcDeveloperModeLog) << "DeveloperMode state change requested during activity, ignored.";
return;
}
m_refreshedForInstall = false;
196
if (enabled) {
Jun 21, 2018
Jun 21, 2018
197
resolveAndExecute(InstallCommand);
198
} else {
Jun 21, 2018
Jun 21, 2018
199
resolveAndExecute(RemoveCommand);
200
201
202
203
}
}
}
Apr 28, 2018
Apr 28, 2018
204
void DeveloperModeSettings::setUsbIpAddress(const QString &usbIpAddress)
205
206
{
if (m_usbIpAddress != usbIpAddress) {
Jun 21, 2018
Jun 21, 2018
207
usbModedSetConfig(USB_MODED_CONFIG_IP, usbIpAddress);
208
209
210
211
212
m_usbIpAddress = usbIpAddress;
emit usbIpAddressChanged();
}
}
Apr 28, 2018
Apr 28, 2018
213
void DeveloperModeSettings::refresh()
214
215
{
/* Retrieve network configuration from usb_moded */
Jun 21, 2018
Jun 21, 2018
216
217
218
m_usbInterface = usbModedGetConfig(USB_MODED_CONFIG_INTERFACE, USB_NETWORK_FALLBACK_INTERFACE);
QString usbIp = usbModedGetConfig(USB_MODED_CONFIG_IP, USB_NETWORK_FALLBACK_IP);
219
if (usbIp != m_usbIpAddress) {
Oct 28, 2013
Oct 28, 2013
220
m_usbIpAddress = usbIp;
221
222
223
224
225
226
227
emit usbIpAddressChanged();
}
/* Retrieve network configuration from interfaces */
QMap<QString,QString> entries = enumerate_network_interfaces();
if (entries.contains(m_usbInterface)) {
Oct 28, 2013
Oct 28, 2013
228
QString ip = entries[m_usbInterface];
229
230
231
232
233
234
235
236
237
if (m_usbIpAddress != ip) {
m_usbIpAddress = ip;
emit usbIpAddressChanged();
}
}
if (entries.contains(WLAN_NETWORK_INTERFACE)) {
QString ip = entries[WLAN_NETWORK_INTERFACE];
if (m_wlanIpAddress != ip) {
May 21, 2014
May 21, 2014
238
239
240
241
242
243
244
245
246
m_wlanIpAddress = ip;
emit wlanIpAddressChanged();
}
} else if (entries.contains(WLAN_NETWORK_FALLBACK_INTERFACE)) {
// If the WLAN network interface does not have an IP address,
// but there is a "tether" interface that does have an IP, assume
// it is the WLAN interface in tethering mode, and use its IP.
QString ip = entries[WLAN_NETWORK_FALLBACK_INTERFACE];
if (m_wlanIpAddress != ip) {
247
248
249
250
251
m_wlanIpAddress = ip;
emit wlanIpAddressChanged();
}
}
Jun 21, 2018
Jun 21, 2018
252
253
for (const QString &device : entries.keys()) {
qCDebug(lcDeveloperModeLog) << "Device:" << device << "IP:" << entries[device];
254
255
256
}
}
Jun 21, 2018
Jun 21, 2018
257
void DeveloperModeSettings::refreshPackageCacheAndInstall()
Feb 5, 2018
Feb 5, 2018
258
{
Jun 21, 2018
Jun 21, 2018
259
m_refreshedForInstall = true;
Feb 5, 2018
Feb 5, 2018
260
Apr 28, 2018
Apr 28, 2018
261
262
// Soft refresh, do not clear & reload valid cache.
PackageKit::Transaction *refreshCache = PackageKit::Daemon::refreshCache(false);
Jun 21, 2018
Jun 21, 2018
263
264
265
connect(refreshCache, &PackageKit::Transaction::errorCode, this, &DeveloperModeSettings::reportTransactionErrorCode);
connect(refreshCache, &PackageKit::Transaction::finished,
this, [this](PackageKit::Transaction::Exit status, uint runtime) {
Apr 28, 2018
Apr 28, 2018
266
qCDebug(lcDeveloperModeLog) << "Package cache updated:" << status << runtime;
Jun 21, 2018
Jun 21, 2018
267
resolveAndExecute(InstallCommand); // trying again regardless of success, some repositories might be updated
Apr 28, 2018
Apr 28, 2018
268
});
Feb 5, 2018
Feb 5, 2018
269
270
}
Jun 21, 2018
Jun 21, 2018
271
void DeveloperModeSettings::resolveAndExecute(Command command)
Feb 5, 2018
Feb 5, 2018
272
{
Jun 21, 2018
Jun 21, 2018
273
setWorkStatus(Preparing);
Nov 15, 2019
Nov 15, 2019
274
m_workProgress = 0;
Jun 21, 2018
Jun 21, 2018
275
276
m_developerModePackageId.clear(); // might differ between installed/available
Nov 15, 2019
Nov 15, 2019
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
if (command == InstallCommand && !m_localInstallFailed && !m_localDeveloperModePackagePath.isEmpty()) {
// Resolve which version of developer mode package is expected
PackageKit::Transaction *resolvePackage = PackageKit::Daemon::resolve(DEVELOPER_MODE_PACKAGE"-preload", PackageKit::Transaction::FilterInstalled);
connect(resolvePackage, &PackageKit::Transaction::errorCode, this, &DeveloperModeSettings::reportTransactionErrorCode);
connect(resolvePackage, &PackageKit::Transaction::package,
this, [this](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary) {
Q_UNUSED(summary)
Q_ASSERT(info == PackageKit::Transaction::InfoInstalled);
const QString version = PackageKit::Transaction::packageVersion(packageID);
m_localDeveloperModePackagePath = get_cached_package(version);
emit repositoryAccessRequiredChanged();
qCDebug(lcDeveloperModeLog) << "Preload package version: " << version << ", local package path: " << m_localDeveloperModePackagePath;
});
connect(resolvePackage, &PackageKit::Transaction::finished,
this, [this](PackageKit::Transaction::Exit status, uint runtime) {
Q_UNUSED(runtime)
if (status != PackageKit::Transaction::ExitSuccess || m_localDeveloperModePackagePath.isEmpty()) {
qCDebug(lcDeveloperModeLog) << "Preloaded package not found, must use remote package";
// No cached package => install from repos
resolveAndExecute(InstallCommand);
} else {
PackageKit::Transaction *tx = PackageKit::Daemon::installFiles(QStringList() << m_localDeveloperModePackagePath);
connectCommandSignals(tx);
connect(tx, &PackageKit::Transaction::finished,
this, [this](PackageKit::Transaction::Exit status, uint runtime) {
if (status == PackageKit::Transaction::ExitSuccess) {
qCDebug(lcDeveloperModeLog) << "Developer mode installation from local package transaction done:" << status << runtime;
resetState();
} else if (status == PackageKit::Transaction::ExitFailed) {
qCWarning(lcDeveloperModeLog) << "Developer mode installation from local package failed, trying from repos";
m_localInstallFailed = true;
emit repositoryAccessRequiredChanged();
resolveAndExecute(InstallCommand); // TODO: If repo access is not available this can not bail out
} // else ExitUnknown (ignored)
});
}
});
Jun 21, 2018
Jun 21, 2018
315
Nov 15, 2019
Nov 15, 2019
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
} else {
PackageKit::Transaction::Filters filters;
if (command == RemoveCommand) {
filters = PackageKit::Transaction::FilterInstalled;
} else {
filters = PackageKit::Transaction::FilterNewest;
}
PackageKit::Transaction *resolvePackage = PackageKit::Daemon::resolve(DEVELOPER_MODE_PACKAGE, filters);
connect(resolvePackage, &PackageKit::Transaction::errorCode, this, &DeveloperModeSettings::reportTransactionErrorCode);
connect(resolvePackage, &PackageKit::Transaction::package,
this, [this](PackageKit::Transaction::Info info, const QString &packageId, const QString &summary) {
qCDebug(lcDeveloperModeLog) << "Package transaction:" << info << packageId << "summary:" << summary;
m_developerModePackageId = packageId;
});
connect(resolvePackage, &PackageKit::Transaction::finished,
this, [this, command](PackageKit::Transaction::Exit status, uint runtime) {
Q_UNUSED(runtime)
if (status != PackageKit::Transaction::ExitSuccess || m_developerModePackageId.isEmpty()) {
if (command == InstallCommand) {
if (m_refreshedForInstall) {
qCWarning(lcDeveloperModeLog) << "Failed to install developer mode, package didn't resolve.";
resetState();
} else {
refreshPackageCacheAndInstall(); // try once if it helps
}
} else if (command == RemoveCommand) {
qCWarning(lcDeveloperModeLog) << "Removing developer mode but package didn't resolve into anything. Shouldn't happen.";
resetState();
}
Jun 21, 2018
Jun 21, 2018
348
Nov 15, 2019
Nov 15, 2019
349
350
351
} else if (command == InstallCommand) {
PackageKit::Transaction *tx = PackageKit::Daemon::installPackage(m_developerModePackageId);
connectCommandSignals(tx);
Jun 21, 2018
Jun 21, 2018
352
353
if (m_refreshedForInstall) {
Nov 15, 2019
Nov 15, 2019
354
355
356
357
358
connect(tx, &PackageKit::Transaction::finished,
this, [this](PackageKit::Transaction::Exit status, uint runtime) {
qCDebug(lcDeveloperModeLog) << "Developer mode installation transaction done (with refresh):" << status << runtime;
resetState();
});
Jun 21, 2018
Jun 21, 2018
359
} else {
Nov 15, 2019
Nov 15, 2019
360
361
362
363
364
365
366
367
368
369
connect(tx, &PackageKit::Transaction::finished,
this, [this](PackageKit::Transaction::Exit status, uint runtime) {
if (status == PackageKit::Transaction::ExitSuccess) {
qCDebug(lcDeveloperModeLog) << "Developer mode installation transaction done:" << status << runtime;
resetState();
} else {
qCDebug(lcDeveloperModeLog) << "Developer mode installation failed, trying again after refresh";
refreshPackageCacheAndInstall();
}
});
Jun 21, 2018
Jun 21, 2018
370
371
}
} else {
Nov 15, 2019
Nov 15, 2019
372
373
PackageKit::Transaction *tx = PackageKit::Daemon::removePackage(m_developerModePackageId, true, true);
connectCommandSignals(tx);
Jun 21, 2018
Jun 21, 2018
374
375
connect(tx, &PackageKit::Transaction::finished,
this, [this](PackageKit::Transaction::Exit status, uint runtime) {
Nov 15, 2019
Nov 15, 2019
376
377
qCDebug(lcDeveloperModeLog) << "Developer mode removal transaction done:" << status << runtime;
resetState();
Jun 21, 2018
Jun 21, 2018
378
379
});
}
Nov 15, 2019
Nov 15, 2019
380
381
});
}
Feb 5, 2018
Feb 5, 2018
382
383
}
Apr 28, 2018
Apr 28, 2018
384
void DeveloperModeSettings::connectCommandSignals(PackageKit::Transaction *transaction)
Mar 12, 2018
Mar 12, 2018
385
{
Jun 21, 2018
Jun 21, 2018
386
connect(transaction, &PackageKit::Transaction::errorCode, this, &DeveloperModeSettings::reportTransactionErrorCode);
Apr 28, 2018
Apr 28, 2018
387
388
389
connect(transaction, &PackageKit::Transaction::percentageChanged, this, [this, transaction]() {
updateState(transaction->percentage(), m_transactionStatus, m_transactionRole);
});
Mar 12, 2018
Mar 12, 2018
390
Apr 28, 2018
Apr 28, 2018
391
connect(transaction, &PackageKit::Transaction::statusChanged, this, [this, transaction]() {
Jun 21, 2018
Jun 21, 2018
392
updateState(m_workProgress, transaction->status(), m_transactionRole);
Apr 28, 2018
Apr 28, 2018
393
});
Feb 5, 2018
Feb 5, 2018
394
Apr 28, 2018
Apr 28, 2018
395
connect(transaction, &PackageKit::Transaction::roleChanged, this, [this, transaction]() {
Jun 21, 2018
Jun 21, 2018
396
updateState(m_workProgress, m_transactionStatus, transaction->role());
Feb 5, 2018
Feb 5, 2018
397
398
399
});
}
Apr 28, 2018
Apr 28, 2018
400
void DeveloperModeSettings::updateState(int percentage, PackageKit::Transaction::Status status, PackageKit::Transaction::Role role)
Mar 12, 2018
Mar 12, 2018
402
// Expected changes from PackageKit when installing packages:
Nov 15, 2019
Nov 15, 2019
403
// 1. Change to 'install packages' role or 'install files' if installing from local package file
Jun 21, 2018
Jun 21, 2018
404
// 2. Status changes:
Mar 12, 2018
Mar 12, 2018
405
406
407
408
409
// setup -> refresh cache -> query -> resolve deps -> install (refer to as 'Preparing' status)
// -> download ('DownloadingPackages' status)
// -> install ('InstallingPackages' status)
// -> finished
//
Nov 15, 2019
Nov 15, 2019
410
411
// If installing from local package fails, it starts over!
//
Mar 12, 2018
Mar 12, 2018
412
// Expected changes from PackageKit when removing packages:
Jun 21, 2018
Jun 21, 2018
413
414
// 1. Change to 'remove packages' role
// 2. Status changes:
Mar 12, 2018
Mar 12, 2018
415
416
417
418
419
420
// setup -> remove -> resolve deps (refer to as 'Preparing' status)
// -> remove ('RemovingPackages' status)
// -> finished
//
// Notice the 'install' and 'remove' packagekit status changes occur twice.
Jun 21, 2018
Jun 21, 2018
421
422
int progress = m_workProgress;
DeveloperModeSettings::Status workStatus = m_workStatus;
Mar 12, 2018
Mar 12, 2018
423
Apr 28, 2018
Apr 28, 2018
424
425
m_transactionRole = role;
m_transactionStatus = status;
Mar 12, 2018
Mar 12, 2018
426
Nov 15, 2019
Nov 15, 2019
427
428
429
430
431
432
// Do not update progress when finished or role is unknown.
if (m_transactionStatus == PackageKit::Transaction::StatusFinished
|| m_transactionRole == PackageKit::Transaction::RoleUnknown) {
return;
}
Apr 28, 2018
Apr 28, 2018
433
if (percentage >= 0 && percentage <= 100) {
Mar 12, 2018
Mar 12, 2018
434
435
int rangeStart = 0;
int rangeEnd = 0;
Nov 15, 2019
Nov 15, 2019
436
437
if (m_transactionRole == PackageKit::Transaction::RoleInstallPackages
|| m_transactionRole == PackageKit::Transaction::RoleInstallFiles) {
Mar 12, 2018
Mar 12, 2018
438
switch (m_transactionStatus) {
Apr 28, 2018
Apr 28, 2018
439
case PackageKit::Transaction::StatusRefreshCache: // 0-10 %
Mar 12, 2018
Mar 12, 2018
440
441
442
rangeStart = 0;
rangeEnd = 10;
break;
Apr 28, 2018
Apr 28, 2018
443
444
case PackageKit::Transaction::StatusQuery: // fall through; packagekit progress changes 0-100 over query->resolve stages
case PackageKit::Transaction::StatusDepResolve: // 10-20 %
Mar 12, 2018
Mar 12, 2018
445
446
447
rangeStart = 10;
rangeEnd = 20;
break;
Apr 28, 2018
Apr 28, 2018
448
case PackageKit::Transaction::StatusDownload: // 20-60 %
Nov 15, 2019
Nov 15, 2019
449
450
451
452
// Skip downloading when installing from local file
if (m_transactionRole != PackageKit::Transaction::RoleInstallFiles) {
workStatus = DownloadingPackages;
}
Mar 12, 2018
Mar 12, 2018
453
454
455
rangeStart = 20;
rangeEnd = 60;
break;
Apr 28, 2018
Apr 28, 2018
456
case PackageKit::Transaction::StatusInstall: // 60-100 %
Jun 21, 2018
Jun 21, 2018
457
workStatus = InstallingPackages;
Apr 28, 2018
Apr 28, 2018
458
459
rangeStart = 60;
rangeEnd = 100;
Mar 12, 2018
Mar 12, 2018
460
461
462
break;
default:
break;
Mar 12, 2018
Mar 12, 2018
463
}
Apr 28, 2018
Apr 28, 2018
464
465
466
} else if (m_transactionRole == PackageKit::Transaction::RoleRemovePackages) {
if (m_transactionStatus == PackageKit::Transaction::StatusSetup) {
// Let the setup to be bound between 0-20 %
Mar 12, 2018
Mar 12, 2018
467
468
469
rangeStart = 0;
rangeEnd = 20;
} else { // 20-100 %
Jun 21, 2018
Jun 21, 2018
470
workStatus = RemovingPackages;
Mar 12, 2018
Mar 12, 2018
471
472
rangeStart = 20;
rangeEnd = 100;
Mar 12, 2018
Mar 12, 2018
473
474
}
}
Mar 12, 2018
Mar 12, 2018
475
if (rangeEnd > 0 && rangeEnd > rangeStart) {
Apr 28, 2018
Apr 28, 2018
476
progress = rangeStart + ((rangeEnd - rangeStart) * (percentage / 100.0));
Mar 12, 2018
Mar 12, 2018
477
}
Mar 12, 2018
Mar 12, 2018
479
Jun 21, 2018
Jun 21, 2018
480
progress = qBound(0, qMax(progress, m_workProgress), 100); // Ensure the emitted progress value never decreases.
Mar 12, 2018
Mar 12, 2018
481
Jun 21, 2018
Jun 21, 2018
482
483
484
485
486
setWorkStatus(workStatus);
if (m_workProgress != progress) {
m_workProgress = progress;
emit workProgressChanged();
Mar 12, 2018
Mar 12, 2018
487
}
488
489
}
Jun 21, 2018
Jun 21, 2018
490
void DeveloperModeSettings::resetState()
Feb 5, 2018
Feb 5, 2018
491
{
Jun 21, 2018
Jun 21, 2018
492
493
494
495
496
bool enabled = QFile::exists(DEVELOPER_MODE_PROVIDED_FILE);
if (m_developerModeEnabled != enabled) {
m_developerModeEnabled = enabled;
emit developerModeEnabledChanged();
}
Feb 5, 2018
Feb 5, 2018
497
Jun 21, 2018
Jun 21, 2018
498
setWorkStatus(Idle);
Feb 5, 2018
Feb 5, 2018
499
Jun 21, 2018
Jun 21, 2018
500
501
502
503
504
if (m_workProgress != PROGRESS_INDETERMINATE) {
m_workProgress = PROGRESS_INDETERMINATE;
emit workProgressChanged();
}
}
Feb 5, 2018
Feb 5, 2018
505
Jun 21, 2018
Jun 21, 2018
506
507
508
509
510
void DeveloperModeSettings::setWorkStatus(DeveloperModeSettings::Status status)
{
if (m_workStatus != status) {
m_workStatus = status;
emit workStatusChanged();
Jun 21, 2018
Jun 21, 2018
512
513
514
515
516
}
void DeveloperModeSettings::reportTransactionErrorCode(PackageKit::Transaction::Error code, const QString &details)
{
qCWarning(lcDeveloperModeLog) << "Transaction error:" << code << details;
Jun 21, 2018
Jun 21, 2018
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
QString DeveloperModeSettings::usbModedGetConfig(const QString &key, const QString &fallback)
{
QString value = fallback;
QDBusMessage msg = m_usbModeDaemon.call(USB_MODED_GET_NET_CONFIG, key);
QList<QVariant> result = msg.arguments();
if (result[0].toString() == key && result.size() == 2) {
value = result[1].toString();
}
return value;
}
void DeveloperModeSettings::usbModedSetConfig(const QString &key, const QString &value)
{
m_usbModeDaemon.call(USB_MODED_SET_NET_CONFIG, key, value);
}