~aleteoryx/muditaos

7ffd1c15a6d9f14424c51ab18e81835319fc557a — Lukasz Mastalerz 2 years ago a4138a8
[CP-2032] Unplugging the cable during file upload leaves partially sent file

Files not completely sent will be deleted after the USB cable is removed from
device to not leave any partially sent file
M harmony_changelog.md => harmony_changelog.md +1 -0
@@ 31,6 31,7 @@
* Added extended information to log filename
* Added Harmony version information in about section
* Added system shutdown if there is no user activity for 180 seconds on the language selection screen
* Files not fully transferred via Center will be now removed when USB cable is unplugged

### Changed / Improved


M module-services/service-desktop/ServiceDesktop.cpp => module-services/service-desktop/ServiceDesktop.cpp +9 -0
@@ 10,6 10,7 @@
#include <system/messages/TetheringStateRequest.hpp>
#include <Timers/TimerFactory.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
#include <service-desktop/endpoints/include/endpoints/filesystem/FileOperations.hpp>

ServiceDesktop::ServiceDesktop(const std::filesystem::path &mtpRootPath)
    : sys::Service(service::name::service_desktop, "", sdesktop::serviceStackSize),


@@ 203,12 204,15 @@ auto ServiceDesktop::usbWorkerDeinit() -> sys::ReturnCodes
    if (!initialized) {
        return sys::ReturnCodes::Success;
    }

    LOG_DEBUG("Deinitializing USB worker");
    settings->deinit();
    desktopWorker->closeWorker();
    desktopWorker.reset();
    initialized     = false;
    isUsbConfigured = false;
    // It must be run after the worker is closed.
    cleanFileSystemEndpointUndeliveredTransfers();
    return sys::ReturnCodes::Success;
}



@@ 374,3 378,8 @@ auto ServiceDesktop::getOnboardingState() const -> sdesktop::endpoints::Onboardi
    return static_cast<sdesktop::endpoints::OnboardingState>(utils::getNumericValue<int>(
        settings->getValue(settings::SystemProperties::onboardingDone, settings::SettingsScope::Global)));
}

void ServiceDesktop::cleanFileSystemEndpointUndeliveredTransfers()
{
    FileOperations::instance().cleanUpUndeliveredTransfers();
}

M module-services/service-desktop/endpoints/filesystem/FileOperations.cpp => module-services/service-desktop/endpoints/filesystem/FileOperations.cpp +15 -2
@@ 67,7 67,7 @@ void FileOperations::cancelTimedOutWriteTransfer()

    fileCtxEntry->second.reset();

    LOG_DEBUG("Canceling timed out rxID %u", static_cast<unsigned>(timedOutXfer));
    LOG_DEBUG("Canceling timed out txID %u", static_cast<unsigned>(timedOutXfer));
    writeTransfers.erase(timedOutXfer);
}



@@ 175,7 175,6 @@ auto FileOperations::createTransmitIDForFile(const std::filesystem::path &file,

    createFileWriteContextFor(file, size, Crc32, txID);
    fileData = std::make_unique<std::vector<uint8_t>>(SingleChunkSize, 0);

    return txID;
}



@@ 226,3 225,17 @@ auto FileOperations::sendDataForTransmitID(transfer_id txID, std::uint32_t chunk

    return returnCode;
}

auto FileOperations::cleanUpUndeliveredTransfers() -> void
{
    if (writeTransfers.empty()) {
        return;
    }

    LOG_INFO("Clean up after undelivered transfers");
    for (auto &wt : writeTransfers) {
        wt.second->removeFile();
        wt.second.reset();
        writeTransfers.erase(wt.first);
    }
}

M module-services/service-desktop/endpoints/include/endpoints/filesystem/FileOperations.hpp => module-services/service-desktop/endpoints/include/endpoints/filesystem/FileOperations.hpp +3 -1
@@ 5,6 5,7 @@

#include "FileContext.hpp"

#include <log/log.hpp>
#include <filesystem>
#include <vector>
#include <map>


@@ 26,7 27,6 @@ class FileOperations
    std::atomic<transfer_id> runningRxId{0};
    std::atomic<transfer_id> runningTxId{0};
    std::unique_ptr<std::vector<std::uint8_t>> fileData{};

    auto createFileReadContextFor(const std::filesystem::path &file, std::size_t fileSize, transfer_id xfrId) -> void;

    auto createFileWriteContextFor(const std::filesystem::path &file,


@@ 71,4 71,6 @@ class FileOperations
        -> transfer_id;

    auto sendDataForTransmitID(transfer_id, std::uint32_t chunkNo, const std::string &data) -> sys::ReturnCodes;

    auto cleanUpUndeliveredTransfers() -> void;
};

M module-services/service-desktop/include/service-desktop/ServiceDesktop.hpp => module-services/service-desktop/include/service-desktop/ServiceDesktop.hpp +2 -0
@@ 120,6 120,8 @@ class ServiceDesktop : public sys::Service

    void checkChargingCondition();

    void cleanFileSystemEndpointUndeliveredTransfers();

    template <typename T>
    auto connectHandler() -> bool
    {

M pure_changelog.md => pure_changelog.md +1 -0
@@ 8,6 8,7 @@
* Added extended information to crashdump filename
* Added extended information to log filename
* Added GUI screens informing about failed MMI/USSD request
* Files not fully transferred via Center will be now removed when USB cable is unplugged

### Changed / Improved