From c1d45026cf1128f2c4f6f8e8c3ceae3fb9b92d66 Mon Sep 17 00:00:00 2001 From: Roman Kubiak Date: Wed, 14 Oct 2020 20:46:14 +0200 Subject: [PATCH] [EGD-3506]: review fixes --- .../data/LockPhoneData.hpp | 13 ++-- .../application-desktop/windows/Update.cpp | 33 +++++----- .../application-desktop/windows/Update.hpp | 17 ++--- .../service-desktop/ServiceDesktop.cpp | 15 +++-- .../endpoints/update/UpdatePureOS.cpp | 62 +++++++++---------- .../endpoints/update/UpdatePureOS.hpp | 2 +- .../messages/DesktopMessages.hpp | 16 ++--- 7 files changed, 81 insertions(+), 77 deletions(-) diff --git a/module-apps/application-desktop/data/LockPhoneData.hpp b/module-apps/application-desktop/data/LockPhoneData.hpp index 55b0816546ffa84c18a8265ca451acc0234e3c27..24127928a4d4f04bba8f12961a47a2a27dcf84df 100644 --- a/module-apps/application-desktop/data/LockPhoneData.hpp +++ b/module-apps/application-desktop/data/LockPhoneData.hpp @@ -48,7 +48,7 @@ namespace gui }; }; - class UpdateSwitchData : public gui::SwitchData + class UpdateSwitchData : public gui::SwitchData { public: UpdateSwitchData(sdesktop::UpdateOsMessage *messageToCopyFrom) : updateOsMessage(*messageToCopyFrom) @@ -58,12 +58,13 @@ namespace gui return updateOsMessage; } - const sdesktop::UpdateOsMessage &getUpdateOsMessage() - { - return updateOsMessage; - } + const sdesktop::UpdateOsMessage &getUpdateOsMessage() + { + return updateOsMessage; + } + private: - sdesktop::UpdateOsMessage updateOsMessage; + sdesktop::UpdateOsMessage updateOsMessage; }; } // namespace gui diff --git a/module-apps/application-desktop/windows/Update.cpp b/module-apps/application-desktop/windows/Update.cpp index cc8e4c916068629064593baaa4eada1263875c01..9ceab00acb8605db64be98c273328e6893c94868 100644 --- a/module-apps/application-desktop/windows/Update.cpp +++ b/module-apps/application-desktop/windows/Update.cpp @@ -50,7 +50,7 @@ namespace gui titleLabel->setFilled(false); titleLabel->setBorderColor(gui::ColorFullBlack); titleLabel->setFont(style::header::font::title); - titleLabel->setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_NO_EDGES); + titleLabel->setEdges(RectangleEdge::None); titleLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); titleLabel->setText(utils::localize.get("app_desktop_update")); @@ -59,7 +59,7 @@ namespace gui updateVersionInfo->setFilled(false); updateVersionInfo->setBorderColor(gui::ColorFullBlack); updateVersionInfo->setFont(style::window::font::smallbold); - updateVersionInfo->setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_NO_EDGES); + updateVersionInfo->setEdges(RectangleEdge::None); updateVersionInfo->setAlignment( gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Top)); updateVersionInfo->setText(utils::localize.get("app_desktop_update")); @@ -69,7 +69,7 @@ namespace gui updateDetails->setFilled(false); updateDetails->setBorderColor(gui::ColorFullBlack); updateDetails->setFont(style::window::font::verysmall); - updateDetails->setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_NO_EDGES); + updateDetails->setEdges(RectangleEdge::None); updateDetails->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Top)); updateDetails->setText(utils::localize.get("app_desktop_update")); @@ -78,7 +78,7 @@ namespace gui currentVersionInfo->setFilled(false); currentVersionInfo->setBorderColor(gui::ColorFullBlack); currentVersionInfo->setFont(style::window::font::small); - currentVersionInfo->setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_NO_EDGES); + currentVersionInfo->setEdges(RectangleEdge::None); currentVersionInfo->setAlignment( gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Top)); currentVersionInfo->setText(utils::localize.get("app_desktop_update_current")); @@ -103,7 +103,8 @@ namespace gui percentLabel->setFilled(false); percentLabel->setBorderColor(gui::ColorNoColor); percentLabel->setFont(style::window::font::largelight); - percentLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom)); + percentLabel->setAlignment( + gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom)); percentLabel->setVisible(false); uint32_t pinLabelX = 46; @@ -116,7 +117,7 @@ namespace gui label->setPenFocusWidth(2); label->setRadius(5); label->setFont(style::window::font::medium); - label->setEdges(RectangleEdgeFlags::GUI_RECT_ALL_EDGES); + label->setEdges(RectangleEdge::All); label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); selectionLabels.push_back(label); pinLabelX += 193; @@ -133,15 +134,15 @@ namespace gui // callbacks for getting focus selectionLabels[0]->focusChangedCallback = [=](gui::Item &item) { - if (item.focus) - this->state = State::Return; - return true; + if (item.focus) + this->state = State::Return; + return true; }; selectionLabels[1]->focusChangedCallback = [=](gui::Item &item) { - if (item.focus) - this->state = State::UpdateNow; - return true; + if (item.focus) + this->state = State::UpdateNow; + return true; }; } void UpdateWindow::destroyInterface() @@ -153,7 +154,8 @@ namespace gui { if (data == nullptr) { LOG_ERROR("Received null pointer"); - } else { + } + else { gui::UpdateSwitchData *item = dynamic_cast(data); if (item != nullptr) { std::stringstream currentVersion; @@ -223,7 +225,7 @@ namespace gui percentLabel->setVisible(true); percentLabel->setText(utils::localize.get("app_desktop_update_start")); auto msgToSend = std::make_shared(updateFile.c_str(), 0); - sys::Bus::SendUnicast (msgToSend, service::name::service_desktop, application); + sys::Bus::SendUnicast(msgToSend, service::name::service_desktop, application); return true; } @@ -253,7 +255,8 @@ namespace gui ssi << " %"; percentLabel->setText(ssi.str()); infoLabel->setText(item->getUpdateOsMessage().updateStats.messageText); - } else if (item->getUpdateOsMessage().updateStats.messageText != "") { + } + else if (item->getUpdateOsMessage().updateStats.messageText != "") { percentLabel->setText(item->getUpdateOsMessage().updateStats.messageText); } diff --git a/module-apps/application-desktop/windows/Update.hpp b/module-apps/application-desktop/windows/Update.hpp index df455cf09a49c9d9fe23033ad3e4663b70be6818..9ba7131493310bcdd5e9f0148ec4231531aae049 100644 --- a/module-apps/application-desktop/windows/Update.hpp +++ b/module-apps/application-desktop/windows/Update.hpp @@ -18,18 +18,19 @@ namespace gui Return, }; - gui::Label *titleLabel = nullptr; - gui::Label *infoLabel = nullptr; - gui::Label *detailLabel = nullptr; - gui::Label *percentLabel = nullptr; + gui::Label *titleLabel = nullptr; + gui::Label *infoLabel = nullptr; + gui::Label *detailLabel = nullptr; + gui::Label *percentLabel = nullptr; - gui::Label *currentVersionInfo = nullptr; - gui::Label *updateVersionInfo = nullptr; - gui::Label *updateDetails = nullptr; + gui::Label *currentVersionInfo = nullptr; + gui::Label *updateVersionInfo = nullptr; + gui::Label *updateDetails = nullptr; std::vector selectionLabels; - State state = State::Return; + State state = State::Return; int progressPercent = 0; + public: UpdateWindow(app::Application *app); void onBeforeShow(ShowMode mode, SwitchData *data) override; diff --git a/module-services/service-desktop/ServiceDesktop.cpp b/module-services/service-desktop/ServiceDesktop.cpp index ac6db0373d8a4985ec0162f9e7ba1703ec8865d2..08ec5226cb43cf40249378e9de9133e50f63e686 100644 --- a/module-services/service-desktop/ServiceDesktop.cpp +++ b/module-services/service-desktop/ServiceDesktop.cpp @@ -54,15 +54,14 @@ sys::ReturnCodes ServiceDesktop::InitHandler() }); connect(sdesktop::UpdateOsMessage(), [&](sys::DataMessage *msg, sys::ResponseMessage *resp) { - sdesktop::UpdateOsMessage *updateOsMsg = dynamic_cast(msg); + sdesktop::UpdateOsMessage *updateOsMsg = dynamic_cast(msg); if (updateOsMsg != nullptr && updateOsMsg->messageType == updateos::UpdateMessageType::UpdateCheckForUpdateOnce) { fs::path file = UpdatePureOS::checkForUpdate(); - if (file.has_filename()) { - /* send info to applicationDesktop that there is an update waiting */ - + if (file.has_filename()) { + /* send info to applicationDesktop that there is an update waiting */ auto msgToSend = std::make_shared(updateos::UpdateMessageType::UpdateFoundOnBoot, file); msgToSend->updateStats.versioInformation = UpdatePureOS::getVersionInfoFromFile(file); @@ -75,10 +74,10 @@ sys::ReturnCodes ServiceDesktop::InitHandler() updateOsMsg->updateStats.updateFile.c_str(), updateOsMsg->updateStats.uuid); - if (updateOS->setUpdateFile(updateOsMsg->updateStats.updateFile) == updateos::UpdateError::NoError) - updateOS->runUpdate(updateOsMsg->rebootDelay); - } - return std::make_shared(); + if (updateOS->setUpdateFile(updateOsMsg->updateStats.updateFile) == updateos::UpdateError::NoError) + updateOS->runUpdate(); + } + return std::make_shared(); }); vfs.updateTimestamp(); diff --git a/module-services/service-desktop/endpoints/update/UpdatePureOS.cpp b/module-services/service-desktop/endpoints/update/UpdatePureOS.cpp index 70a1800d700b55849ad3efc6f04e48181a5a7bb3..9df38fa130b0a1454ee002d2d17658946ca11dac 100644 --- a/module-services/service-desktop/endpoints/update/UpdatePureOS.cpp +++ b/module-services/service-desktop/endpoints/update/UpdatePureOS.cpp @@ -51,7 +51,7 @@ updateos::UpdateError UpdatePureOS::setUpdateFile(fs::path updateFileToUse) return updateos::UpdateError::NoError; } -updateos::UpdateError UpdatePureOS::runUpdate(const int resetDelay) +updateos::UpdateError UpdatePureOS::runUpdate() { informDebug("Prepraring temp dir"); @@ -101,15 +101,13 @@ updateos::UpdateError UpdatePureOS::runUpdate(const int resetDelay) informError("Can't prepare root dir for reset"); } - if ( (err = cleanupAfterUpdate()) == updateos::UpdateError::NoError) { - if (resetDelay == -1) - return err; - - if (resetDelay >= 0) { // no resetDelay implementation for now - sys::SystemManager::Reboot(owner); - } + if ((err = cleanupAfterUpdate()) != updateos::UpdateError::NoError) { + informError("runUpdate cleanupAfterUpdate failed, resetting anyway"); } + // reboot always + sys::SystemManager::Reboot(owner); + return err; } @@ -223,10 +221,10 @@ void UpdatePureOS::getChecksumInfo(const std::string &infoLine, std::string &fil if (fileCRC32Long != nullptr) { *fileCRC32Long = strtoull(fileCRC32Str.c_str(), nullptr, purefs::buffer::crc_radix); informDebug("getChecksumInfo filePath: %s fileCRC32Str: %s fileCRC32Long: %lu fileCRC32Hex: %lX", - filePath.c_str(), - fileCRC32Str.c_str(), - *fileCRC32Long, - *fileCRC32Long); + filePath.c_str(), + fileCRC32Str.c_str(), + *fileCRC32Long, + *fileCRC32Long); } } } @@ -250,8 +248,8 @@ updateos::UpdateError UpdatePureOS::prepareRoot() if (ret != 0) { informError("prepareRoot ff_deltree on %s caused an error %s", - purefs::dir::os_previous.c_str(), - vfs.lastErrnoToStr().c_str()); + purefs::dir::os_previous.c_str(), + vfs.lastErrnoToStr().c_str()); } if (vfs.isDir(purefs::dir::os_previous.c_str())) { @@ -264,9 +262,9 @@ updateos::UpdateError UpdatePureOS::prepareRoot() if (ret != 0) { informError("prepareRoot can't rename %s -> %s error %s", - purefs::dir::os_current.c_str(), - purefs::dir::os_previous.c_str(), - vfs.lastErrnoToStr().c_str()); + purefs::dir::os_current.c_str(), + purefs::dir::os_previous.c_str(), + vfs.lastErrnoToStr().c_str()); return updateos::UpdateError::CantRenameCurrentToPrevious; } @@ -276,9 +274,9 @@ updateos::UpdateError UpdatePureOS::prepareRoot() if (ret != 0) { informError("prepareRoot can't rename %s -> %s error %s", - updateTempDirectory.c_str(), - purefs::dir::os_current.c_str(), - vfs.lastErrnoToStr().c_str()); + updateTempDirectory.c_str(), + purefs::dir::os_current.c_str(), + vfs.lastErrnoToStr().c_str()); return updateos::UpdateError::CantRenameTempToCurrent; } @@ -326,10 +324,10 @@ bool UpdatePureOS::unpackFileToTemp(mtar_header_t &h, unsigned long *crc32) std::unique_ptr readBuf(new unsigned char[purefs::buffer::tar_buf]); const fs::path fullPath = getUpdateTmpChild(h.name); - uint32_t blocksToRead = (h.size / purefs::buffer::tar_buf) + 1; - uint32_t sizeToRead = purefs::buffer::tar_buf; - fileExtracted = h.name; - fileExtractedSize = h.size; + uint32_t blocksToRead = (h.size / purefs::buffer::tar_buf) + 1; + uint32_t sizeToRead = purefs::buffer::tar_buf; + fileExtracted = h.name; + fileExtractedSize = h.size; informUpdate("Unpack %s", fullPath.filename().c_str()); @@ -448,8 +446,8 @@ updateos::UpdateError UpdatePureOS::prepareTempDirForUpdate() informDebug("prepareTempDirForUpdate trying to create %s as tempDir", updateTempDirectory.c_str()); if (vfs.mkdir(updateTempDirectory.c_str()) != 0) { informError("prepareTempDirForUpdate failed to create: %s error: %s", - updateTempDirectory.c_str(), - vfs.lastErrnoToStr().c_str()); + updateTempDirectory.c_str(), + vfs.lastErrnoToStr().c_str()); return updateos::UpdateError::CantCreateUniqueTmpDir; } @@ -563,7 +561,8 @@ bool UpdatePureOS::isUpgradeToCurrent(const std::string &versionToCompare) const fs::path UpdatePureOS::checkForUpdate() { - std::vector fileList = vfs.listdir(purefs::dir::os_updates.c_str(), updateos::extension::update, true); + std::vector fileList = + vfs.listdir(purefs::dir::os_updates.c_str(), updateos::extension::update, true); for (auto &file : fileList) { json11::Json versionInfo = UpdatePureOS::getVersionInfoFromFile(purefs::dir::os_updates / file.fileName); @@ -571,7 +570,8 @@ const fs::path UpdatePureOS::checkForUpdate() continue; if (versionInfo[purefs::json::os_version][purefs::json::version_string].is_string()) { - if (UpdatePureOS::isUpgradeToCurrent(versionInfo[purefs::json::os_version][purefs::json::version_string].string_value())) { + if (UpdatePureOS::isUpgradeToCurrent( + versionInfo[purefs::json::os_version][purefs::json::version_string].string_value())) { return purefs::dir::os_updates / file.fileName; } } @@ -590,7 +590,7 @@ void UpdatePureOS::informError(const char *format, ...) va_list argptr; std::unique_ptr readBuf(new char[purefs::buffer::tar_buf]); va_start(argptr, format); - vsnprintf (readBuf.get(), purefs::buffer::tar_buf, format, argptr); + vsnprintf(readBuf.get(), purefs::buffer::tar_buf, format, argptr); va_end(argptr); LOG_ERROR("UPDATE_ERRROR %s", readBuf.get()); @@ -606,7 +606,7 @@ void UpdatePureOS::informDebug(const char *format, ...) va_list argptr; std::unique_ptr readBuf(new char[purefs::buffer::tar_buf]); va_start(argptr, format); - vsnprintf (readBuf.get(), purefs::buffer::tar_buf, format, argptr); + vsnprintf(readBuf.get(), purefs::buffer::tar_buf, format, argptr); va_end(argptr); LOG_DEBUG("UPDATE_DEBUG %s", readBuf.get()); @@ -617,7 +617,7 @@ void UpdatePureOS::informUpdate(const char *format, ...) va_list argptr; std::unique_ptr readBuf(new char[purefs::buffer::tar_buf]); va_start(argptr, format); - vsnprintf (readBuf.get(), purefs::buffer::tar_buf, format, argptr); + vsnprintf(readBuf.get(), purefs::buffer::tar_buf, format, argptr); va_end(argptr); LOG_INFO("UPDATE_INFO %s", readBuf.get()); diff --git a/module-services/service-desktop/endpoints/update/UpdatePureOS.hpp b/module-services/service-desktop/endpoints/update/UpdatePureOS.hpp index 0f65d5115148146cfbd399bfb7c91d7bbd8d3326..85e7a4789b70163805fd6b05864e40198437196a 100644 --- a/module-services/service-desktop/endpoints/update/UpdatePureOS.hpp +++ b/module-services/service-desktop/endpoints/update/UpdatePureOS.hpp @@ -106,7 +106,7 @@ class UpdatePureOS : public updateos::UpdateStats public: UpdatePureOS(ServiceDesktop *ownerService); - updateos::UpdateError runUpdate(const int resetDelay); + updateos::UpdateError runUpdate(); updateos::UpdateError prepareTempDirForUpdate(); updateos::UpdateError unpackUpdate(); updateos::UpdateError verifyChecksums(); diff --git a/module-services/service-desktop/messages/DesktopMessages.hpp b/module-services/service-desktop/messages/DesktopMessages.hpp index a10e59ed06d07523d0993a0b512c2d884c6897e5..d44598593a6381a08a9fdf09bce9c10fbcc0ddd3 100644 --- a/module-services/service-desktop/messages/DesktopMessages.hpp +++ b/module-services/service-desktop/messages/DesktopMessages.hpp @@ -9,15 +9,16 @@ namespace sdesktop { class UpdateOsMessage : public sys::DataMessage { - public: + public: UpdateOsMessage(const std::string updateFilePath, const uint32_t requestUUID) - : sys::DataMessage(MessageType::UpdateOS) - { - updateStats.updateFile = updateFilePath; - updateStats.uuid = requestUUID; - }; + : sys::DataMessage(MessageType::UpdateOS) + { + updateStats.updateFile = updateFilePath; + updateStats.uuid = requestUUID; + }; - UpdateOsMessage() : sys::DataMessage(MessageType::UpdateOS) {} + UpdateOsMessage() : sys::DataMessage(MessageType::UpdateOS) + {} UpdateOsMessage(const updateos::UpdateMessageType updateMessageType) : sys::DataMessage(MessageType::UpdateOS), messageType(updateMessageType) @@ -33,7 +34,6 @@ namespace sdesktop updateos::UpdateStats updateStats = {}; updateos::UpdateMessageType messageType = updateos::UpdateMessageType::UpdateNow; - int rebootDelay = 0; }; class BackupMessage : public sys::DataMessage