From 538cf8c9ddeb09c2aaac04d0d7fbcda35177f4ba Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Thu, 3 Feb 2022 11:41:23 +0100 Subject: [PATCH] Extend telemetry to include OS Imager is being run on --- debian/changelog | 6 +++++- downloadstatstelemetry.cpp | 32 +++++++++++++++++++++++++++++--- downloadstatstelemetry.h | 2 +- imagewriter.cpp | 4 +++- imagewriter.h | 2 +- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 3395e21..11b26db 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,8 +16,12 @@ rpi-imager (1.7.0) unstable; urgency=medium * Allow nested subitems entries * Add word-wrapping to OS list (contributed by mzanetti) * Update icons + * Telemetry: phone back home when image from repository is written: + - name of image written, parent category. + - about the computer running Imager: OS, version, architecture, + locale, Imager version, Pi revision. - -- Floris Bos Mon, 31 Jan 2022 13:33:47 +0100 + -- Floris Bos Wed, 02 Feb 2022 19:47:17 +0100 rpi-imager (1.6.2) unstable; urgency=medium diff --git a/downloadstatstelemetry.cpp b/downloadstatstelemetry.cpp index ebe8029..85a1c16 100644 --- a/downloadstatstelemetry.cpp +++ b/downloadstatstelemetry.cpp @@ -3,18 +3,44 @@ #include #include #include +#include +#include +#include +#include /* * SPDX-License-Identifier: Apache-2.0 * Copyright (C) 2020 Raspberry Pi (Trading) Limited */ -DownloadStatsTelemetry::DownloadStatsTelemetry(const QByteArray &url, const QByteArray &parentcategory, const QByteArray &osname, QObject *parent) +DownloadStatsTelemetry::DownloadStatsTelemetry(const QByteArray &url, const QByteArray &parentcategory, const QByteArray &osname, bool embedded, const QString &imagerLang, QObject *parent) : QThread(parent), _url(TELEMETRY_URL) { + QLocale locale; _postfields = "url="+QUrl::toPercentEncoding(url) +"&os="+QUrl::toPercentEncoding(parentcategory) - +"&image="+QUrl::toPercentEncoding(osname); + +"&image="+QUrl::toPercentEncoding(osname) + +"&imagerVersion=" IMAGER_VERSION_STR + +"&imagerOsType="+(embedded ? "embedded" : QUrl::toPercentEncoding(QSysInfo::productType())) + +"&imagerOsVersion="+QUrl::toPercentEncoding(QSysInfo::productVersion()) + +"&imagerOsArch="+QUrl::toPercentEncoding(QSysInfo::currentCpuArchitecture()) + +"&imagerLocale="+QUrl::toPercentEncoding(embedded ? imagerLang : locale.name()); +#ifdef Q_OS_LINUX + QFile f("/proc/cpuinfo"); + f.open(f.ReadOnly); + QByteArray cpuinfo = f.readAll(); + f.close(); + + if (cpuinfo.contains("Raspberry Pi")) { + QRegularExpression rx("Revision[ \t]*: ([0-9a-f]+)"); + QRegularExpressionMatch m = rx.match(cpuinfo); + if (m.hasMatch()) + { + _postfields += "&imagerPiRevision="+QUrl::toPercentEncoding(m.captured(1)); + } + } +#endif + _useragent = "Mozilla/5.0 rpi-imager/" IMAGER_VERSION_STR; } @@ -39,7 +65,7 @@ void DownloadStatsTelemetry::run() CURLcode ret = curl_easy_perform(_c); curl_easy_cleanup(_c); - qDebug() << "Telemetry done. cURL status code =" << ret; + qDebug() << "Telemetry done. cURL status code =" << ret << "info sent =" << _postfields; } /* /dev/null write handler */ diff --git a/downloadstatstelemetry.h b/downloadstatstelemetry.h index 57bd4b6..d5e1c5a 100644 --- a/downloadstatstelemetry.h +++ b/downloadstatstelemetry.h @@ -14,7 +14,7 @@ class DownloadStatsTelemetry : public QThread { Q_OBJECT public: - explicit DownloadStatsTelemetry(const QByteArray &url, const QByteArray &parentcategory, const QByteArray &osname, QObject *parent = nullptr); + explicit DownloadStatsTelemetry(const QByteArray &url, const QByteArray &parentcategory, const QByteArray &osname, bool embedded, const QString &imagerLang, QObject *parent = nullptr); protected: CURL *_c; diff --git a/imagewriter.cpp b/imagewriter.cpp index ac365f7..fa0f3a1 100644 --- a/imagewriter.cpp +++ b/imagewriter.cpp @@ -170,6 +170,7 @@ ImageWriter::ImageWriter(QObject *parent) if (langcode == currentlangcode) { _currentLang = langname; + _currentLangcode = currentlangcode; } } //_currentKeyboard = "us"; @@ -278,7 +279,7 @@ void ImageWriter::startWrite() _thread = new DownloadExtractThread(urlstr, _dst.toLatin1(), _expectedHash, this); if (_repo.toString() == OSLIST_URL) { - DownloadStatsTelemetry *tele = new DownloadStatsTelemetry(urlstr, _parentCategory.toLatin1(), _osName.toLatin1(), this); + DownloadStatsTelemetry *tele = new DownloadStatsTelemetry(urlstr, _parentCategory.toLatin1(), _osName.toLatin1(), _embeddedMode, _currentLangcode, this); connect(tele, SIGNAL(finished()), tele, SLOT(deleteLater())); tele->start(); } @@ -1136,6 +1137,7 @@ void ImageWriter::changeLanguage(const QString &newLanguageName) { replaceTranslator(trans); _currentLang = newLanguageName; + _currentLangcode = langcode; } else { diff --git a/imagewriter.h b/imagewriter.h index e2c16f3..e24ef44 100644 --- a/imagewriter.h +++ b/imagewriter.h @@ -156,7 +156,7 @@ protected slots: protected: QUrl _src, _repo; - QString _dst, _cacheFileName, _parentCategory, _osName, _currentLang, _currentKeyboard; + QString _dst, _cacheFileName, _parentCategory, _osName, _currentLang, _currentLangcode, _currentKeyboard; QByteArray _expectedHash, _cachedFileHash, _cmdline, _config, _firstrun, _cloudinit, _cloudinitNetwork, _initFormat; quint64 _downloadLen, _extrLen, _devLen, _dlnow, _verifynow; DriveListModel _drivelist;