From 8f1003f6bbc6d5801b3d7bc2dce7aeeedfa69f2d Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sat, 13 Jan 2024 14:08:37 -0500 Subject: [PATCH] Code that works until the last step, then crashes the binary --- src/functions.h | 43 ++++++++++++++++++++++++- src/homeWidget/mainwindow.cpp | 21 ++++++++++++ src/homeWidget/mainwindow.h | 2 ++ src/localLibrary/locallibrarywidget.cpp | 4 +-- src/widgets/dialogs/generaldialog.cpp | 28 +++++++++++++++- 5 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/functions.h b/src/functions.h index 17818a8..cdc7da8 100644 --- a/src/functions.h +++ b/src/functions.h @@ -97,6 +97,7 @@ namespace global { inline bool encfsDialog; inline bool vncDialog; inline bool wifiPassphraseDialog; + inline bool telemetryMessageDialog; inline QString keyboardText; inline QString keypadText; inline bool embed = true; @@ -232,6 +233,14 @@ 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; @@ -582,7 +591,7 @@ namespace { proc->deleteLater(); } } - void getUID() { + QString getUID() { QString prog ("dd"); QStringList args; args << "if=/dev/mmcblk0" << "bs=512" << "skip=1" << "count=1" << "status=none"; @@ -594,6 +603,8 @@ namespace { deviceUID = deviceUID.left(256); proc->deleteLater(); + + return deviceUID; } void getKernelVersion() { QString prog ("uname"); @@ -1221,6 +1232,36 @@ 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 c56a1ad..7566af5 100644 --- a/src/homeWidget/mainwindow.cpp +++ b/src/homeWidget/mainwindow.cpp @@ -1099,6 +1099,27 @@ void MainWindow::openTelemetryDialog() { global::telemetry::telemetryDialog = true; generalDialogWindow = new generalDialog(this); + QObject::connect(generalDialogWindow, &generalDialog::destroyed, this, &MainWindow::openTelemetryMessageDialog); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); QApplication::processEvents(); } + +void MainWindow::openTelemetryMessageDialog() { + if(global::keyboard::telemetryMessageDialog == true) { + log("Showing telemetry message dialog", className); + global::keyboard::keyboardDialog = true; + global::keyboard::keyboardText = ""; + generalDialogWindow = new generalDialog(this); + QObject::connect(generalDialogWindow, &generalDialog::destroyed, 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"); +} diff --git a/src/homeWidget/mainwindow.h b/src/homeWidget/mainwindow.h index 676fcbb..4e2c2f8 100644 --- a/src/homeWidget/mainwindow.h +++ b/src/homeWidget/mainwindow.h @@ -104,6 +104,8 @@ private slots: void launchOnlineLibrary(); void on_audioBtn_clicked(); void openTelemetryDialog(); + void openTelemetryMessageDialog(); + void sendDeviceInformationSlot(); private: Ui::MainWindow * ui; diff --git a/src/localLibrary/locallibrarywidget.cpp b/src/localLibrary/locallibrarywidget.cpp index 8c24c07..efec498 100644 --- a/src/localLibrary/locallibrarywidget.cpp +++ b/src/localLibrary/locallibrarywidget.cpp @@ -177,10 +177,10 @@ void localLibraryWidget::setupDatabase() { // Determine maximum page number booksNumber = databaseJsonArrayList.size(); if(folderFeatureEnabled == false) { - pagesNumber = std::ceil((double)booksNumber / buttonsNumber); + pagesNumber = std::ceil((double)booksNumber / buttonsNumber); } else { - calculateMaximumPagesNumberForFolders(); + calculateMaximumPagesNumberForFolders(); } if(databaseJsonArrayList.isEmpty()) { log("Database is empty", className); diff --git a/src/widgets/dialogs/generaldialog.cpp b/src/widgets/dialogs/generaldialog.cpp index 7990310..8eaf83b 100644 --- a/src/widgets/dialogs/generaldialog.cpp +++ b/src/widgets/dialogs/generaldialog.cpp @@ -309,6 +309,12 @@ void generalDialog::on_cancelBtn_clicked() log("User declined telemetry request", className); writeFile("/mnt/onboard/.adds/inkbox/.config/24-telemetry/asked", "true"); } + else if(global::keyboard::telemetryMessageDialog == true) { + global::keyboard::telemetryMessageDialog = false; + global::keyboard::keyboardText = ""; + global::telemetry::collectedData::message = ""; + log("No message to be sent along with collected data", className); + } generalDialog::close(); } } @@ -550,6 +556,20 @@ void generalDialog::on_okBtn_clicked() showToast("Please type in the required argument"); } } + else if(global::keyboard::telemetryMessageDialog == true) { + if(!global::keyboard::keyboardText.isEmpty()) { + global::telemetry::collectedData::message = global::keyboard::keyboardText; + 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 { + global::toast::delay = 3000; + showToast("Please type in the required argument"); + } + } else { global::keyboard::keyboardDialog = false; generalDialog::close(); @@ -580,7 +600,7 @@ void generalDialog::on_okBtn_clicked() } else if(global::telemetry::telemetryDialog == true) { global::telemetry::telemetryDialog = false; - + global::keyboard::telemetryMessageDialog = true; generalDialog::close(); } } @@ -677,6 +697,12 @@ void generalDialog::setupKeyboardDialog() { ui->okBtn->setText("OK"); ui->cancelBtn->setText("Cancel"); } + else if(global::keyboard::telemetryMessageDialog == true) { + ui->headerLabel->setWordWrap(true); + ui->headerLabel->setText("If you'd like, feel free to send us a random message along with the collected data"); + ui->okBtn->setText("Continue"); + ui->cancelBtn->setText("No, thanks"); + } else { ui->headerLabel->setText("Enter a string"); ui->okBtn->setText("OK");