From 7143c852012bb5d51fd25f25c1c5fddd816d0d92 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sat, 13 Jan 2024 21:18:28 -0500 Subject: [PATCH] Working telemetry class --- inkbox.pro | 2 ++ src/functions.h | 49 +++++---------------------- src/homeWidget/mainwindow.cpp | 14 ++++---- src/homeWidget/mainwindow.h | 4 ++- src/widgets/dialogs/generaldialog.cpp | 6 ++-- src/widgets/dialogs/generaldialog.h | 1 + 6 files changed, 23 insertions(+), 53 deletions(-) diff --git a/inkbox.pro b/inkbox.pro index 154b229..e5ed15d 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -28,6 +28,7 @@ SOURCES += \ src/audio/audiothread.cpp \ src/splash/alert.cpp \ src/apps/apps.cpp \ + src/telemetry/telemetry.cpp \ src/widgets/dialogs/audio/audiodialog.cpp \ src/widgets/dialogs/audio/audiofile.cpp \ src/widgets/dialogs/audio/audiofilequeue.cpp \ @@ -77,6 +78,7 @@ HEADERS += \ src/apps/todo.h \ src/splash/alert.h \ src/apps/apps.h \ + src/telemetry/telemetry.h \ src/widgets/dialogs/audio/audiodialog.h \ src/widgets/dialogs/audio/audiofile.h \ src/widgets/dialogs/audio/audiofilequeue.h \ diff --git a/src/functions.h b/src/functions.h index cdc7da8..531dc30 100644 --- a/src/functions.h +++ b/src/functions.h @@ -233,14 +233,6 @@ namespace global { namespace telemetry { inline bool enabled = false; inline bool telemetryDialog = false; - namespace collectedData { - inline QString message; - inline QString deviceUID; - inline QString systemVersion; - inline QString device; - inline bool deviceRooted; - inline bool developerKeyInstalled; - } } inline QString systemInfoText; inline bool forbidOpenSearchDialog; @@ -1179,21 +1171,26 @@ namespace { } } } - int testPing() { + int testPing(QString ipAddress = "1.1.1.1") { // For some reason, implementing a non-blocking version of this functions triggers a "terminate called without an active exception" error with a platform plugin compiled with a newer GCC 11 toolchain. The problem has been solved by transplanting this function into the related area which uses it. + QString function = __func__; log(function + ": pinging IP address " + ipAddress, "functions"); QProcess *pingProcess = new QProcess(); QString pingProg = "ping"; QStringList pingArgs; - pingArgs << "-c" << "1" << "1.1.1.1"; + pingArgs << "-c" << "1" << ipAddress; pingProcess->start(pingProg, pingArgs); pingProcess->waitForFinished(); int exitCode = pingProcess->exitCode(); pingProcess->deleteLater(); if(exitCode == 0) { + log("Ping successful", "functions"); global::wifi::isConnected = true; } else { - global::wifi::isConnected = false; + log("Ping unsuccessful", "functions"); + if(ipAddress == "1.1.1.1") { + global::wifi::isConnected = false; + } } return exitCode; } @@ -1232,36 +1229,6 @@ namespace { fhandler << str.toStdString(); fhandler.close(); } - QJsonObject collectDeviceInformation() { - global::telemetry::collectedData::deviceUID = getUID(); - global::telemetry::collectedData::systemVersion = readFile("/opt/version").trimmed(); - global::telemetry::collectedData::device = global::deviceID.trimmed(); - if(checkconfig("/external_root/opt/root/rooted")) { - global::telemetry::collectedData::deviceRooted = "true"; - } - else { - global::telemetry::collectedData::deviceRooted = "false"; - } - if(checkconfig("/external_root/opt/developer/valid-key")) { - global::telemetry::collectedData::developerKeyInstalled = "true"; - } - else { - global::telemetry::collectedData::developerKeyInstalled = "false"; - } - - QJsonObject data; - data.insert("UID", global::telemetry::collectedData::deviceUID); - data.insert("SystemVersion", global::telemetry::collectedData::systemVersion); - data.insert("DeviceModel", global::telemetry::collectedData::device); - data.insert("DeviceRooted", global::telemetry::collectedData::deviceRooted); - data.insert("DeveloperKeyInstalled", global::telemetry::collectedData::developerKeyInstalled); - data.insert("Message", global::telemetry::collectedData::message); - - return(data); - } - bool sendDeviceInformation(QJsonObject data) { - qDebug() << data; - } } #endif // FUNCTIONS_H diff --git a/src/homeWidget/mainwindow.cpp b/src/homeWidget/mainwindow.cpp index 7566af5..2467cdc 100644 --- a/src/homeWidget/mainwindow.cpp +++ b/src/homeWidget/mainwindow.cpp @@ -436,7 +436,7 @@ MainWindow::MainWindow(QWidget *parent) // Telemetry if(checkconfig(".config/24-telemetry/enabled") == false && checkconfig(".config/24-telemetry/asked") == false) { - if(testPing() == 0) { + if(testPing("23.163.0.39") == 0) { QTimer::singleShot(1000, this, SLOT(openTelemetryDialog())); } } @@ -1110,16 +1110,14 @@ void MainWindow::openTelemetryMessageDialog() { global::keyboard::keyboardDialog = true; global::keyboard::keyboardText = ""; generalDialogWindow = new generalDialog(this); - QObject::connect(generalDialogWindow, &generalDialog::destroyed, this, &MainWindow::sendDeviceInformationSlot); + QObject::connect(generalDialogWindow, &generalDialog::telemetryMessage, this, &MainWindow::sendDeviceInformationSlot); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); QApplication::processEvents(); } } -void MainWindow::sendDeviceInformationSlot() { - QJsonObject data = collectDeviceInformation(); - qDebug() << data; - sendDeviceInformation(data); - writeFile("/mnt/onboard/.adds/inkbox/.config/24-telemetry/asked", "true"); - writeFile("/mnt/onboard/.adds/inkbox/.config/24-telemetry/enabled", "true"); +void MainWindow::sendDeviceInformationSlot(QString message) { + telemetryInstance = new telemetry(this); + QObject::connect(telemetryInstance, &telemetry::showToast, this, &MainWindow::showToast); + telemetryInstance->message = message; } diff --git a/src/homeWidget/mainwindow.h b/src/homeWidget/mainwindow.h index 4e2c2f8..6261fb1 100644 --- a/src/homeWidget/mainwindow.h +++ b/src/homeWidget/mainwindow.h @@ -20,6 +20,7 @@ #include "librarywidget.h" #include "locallibrarywidget.h" #include "homepagewidget.h" +#include "telemetry.h" using namespace std; @@ -105,7 +106,7 @@ private slots: void on_audioBtn_clicked(); void openTelemetryDialog(); void openTelemetryMessageDialog(); - void sendDeviceInformationSlot(); + void sendDeviceInformationSlot(QString message); private: Ui::MainWindow * ui; @@ -126,6 +127,7 @@ private: libraryWidget * libraryWidgetWindow; localLibraryWidget * localLibraryWidgetWindow; homePageWidget * homePageWidgetWindow; + telemetry * telemetryInstance; }; #endif // MAINWINDOW_H diff --git a/src/widgets/dialogs/generaldialog.cpp b/src/widgets/dialogs/generaldialog.cpp index 8eaf83b..e3a9299 100644 --- a/src/widgets/dialogs/generaldialog.cpp +++ b/src/widgets/dialogs/generaldialog.cpp @@ -311,8 +311,8 @@ void generalDialog::on_cancelBtn_clicked() } else if(global::keyboard::telemetryMessageDialog == true) { global::keyboard::telemetryMessageDialog = false; + emit telemetryMessage(global::keyboard::keyboardText); global::keyboard::keyboardText = ""; - global::telemetry::collectedData::message = ""; log("No message to be sent along with collected data", className); } generalDialog::close(); @@ -558,11 +558,11 @@ void generalDialog::on_okBtn_clicked() } else if(global::keyboard::telemetryMessageDialog == true) { if(!global::keyboard::keyboardText.isEmpty()) { - global::telemetry::collectedData::message = global::keyboard::keyboardText; + emit telemetryMessage(global::keyboard::keyboardText); + log("Message to be sent along with collected data is: " + global::keyboard::keyboardText, className); global::keyboard::keyboardText = ""; global::keyboard::telemetryMessageDialog = false; global::keyboard::keyboardDialog = false; - log("Message to be sent along with collected data is: " + global::telemetry::collectedData::message, className); this->close(); } else { diff --git a/src/widgets/dialogs/generaldialog.h b/src/widgets/dialogs/generaldialog.h index 500602e..d2614aa 100644 --- a/src/widgets/dialogs/generaldialog.h +++ b/src/widgets/dialogs/generaldialog.h @@ -94,6 +94,7 @@ signals: void disableStorageEncryption(); void syncOnlineLibrary(); void noSyncOnlineLibrary(); + void telemetryMessage(QString message); }; #endif // GENERALDIALOG_H