~aleteoryx/muditaos

42ca53a732487f7dabf5e06ee4c03f73c329882b — Maciej-Mudita 3 years ago a24fa17
[MOS-686] Fix the accessibility of user files by MTP

User files accessible via MTP only if phone is unlocked
M module-bsp/board/linux/usb_cdc/usb_cdc.cpp => module-bsp/board/linux/usb_cdc/usb_cdc.cpp +6 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "bsp/usb/usb.hpp"


@@ 160,6 160,11 @@ namespace bsp
        LOG_INFO("usbSuspend");
    }

    void usbStartMTP()
    {
        LOG_INFO("mtpStart");
    }

    int usbInit(const bsp::usbInitParams &initParams)
    {


M module-bsp/bsp/usb/usb.hpp => module-bsp/bsp/usb/usb.hpp +1 -0
@@ 47,5 47,6 @@ namespace bsp
    void usbReinit(const std::string& rootPath);
    void usbSuspend();
    void usbHandleDataReceived();
    void usbStartMTP();

} // namespace bsp

M module-services/service-desktop/ServiceDesktop.cpp => module-services/service-desktop/ServiceDesktop.cpp +7 -4
@@ 201,10 201,11 @@ auto ServiceDesktop::usbWorkerInit() -> sys::ReturnCodes
                                                    serialNumber,
                                                    purefs::dir::getUserDiskPath() / "music");

    initialized =
        desktopWorker->init({{sdesktop::RECEIVE_QUEUE_BUFFER_NAME, sizeof(std::string *), sdesktop::cdc_queue_len},
                             {sdesktop::SEND_QUEUE_BUFFER_NAME, sizeof(std::string *), sdesktop::cdc_queue_object_size},
                             {sdesktop::IRQ_QUEUE_BUFFER_NAME, 1, sdesktop::irq_queue_object_size}});
    initialized = desktopWorker->init(
        {{sdesktop::RECEIVE_QUEUE_BUFFER_NAME, sizeof(std::string *), sdesktop::cdcReceiveQueueLength},
         {sdesktop::SEND_QUEUE_BUFFER_NAME, sizeof(std::string *), sdesktop::cdcSendQueueLength},
         {sdesktop::IRQ_QUEUE_BUFFER_NAME, sdesktop::irqQueueSize, sdesktop::irqQueueLength},
         {sdesktop::SIGNALLING_QUEUE_BUFFER_NAME, sizeof(WorkerDesktop::Signal), sdesktop::signallingQueueLength}});

    if (!initialized) {
        LOG_ERROR("!!! service-desktop usbWorkerInit failed to initialize worker, service-desktop won't work");


@@ 264,6 265,7 @@ auto ServiceDesktop::handle(locks::UnlockedPhone * /*msg*/) -> std::shared_ptr<s
        bus.sendUnicast(std::make_shared<sys::TetheringStateRequest>(sys::phone_modes::Tethering::On),
                        service::name::system_manager);
        isPlugEventUnhandled = false;
        desktopWorker->notify(WorkerDesktop::Signal::startMTP);
    }

    return sys::MessageNone{};


@@ 369,6 371,7 @@ auto ServiceDesktop::handle(sdesktop::usb::USBConfigured *msg) -> std::shared_pt
            bus.sendUnicast(std::make_shared<sys::TetheringStateRequest>(sys::phone_modes::Tethering::On),
                            service::name::system_manager);
            isPlugEventUnhandled = false;
            desktopWorker->notify(WorkerDesktop::Signal::startMTP);
        }
    }


M module-services/service-desktop/WorkerDesktop.cpp => module-services/service-desktop/WorkerDesktop.cpp +32 -0
@@ 112,6 112,13 @@ void WorkerDesktop::reset()
    }
}

void WorkerDesktop::notify(Signal command)
{
    if (auto queue = getQueueByName(sdesktop::SIGNALLING_QUEUE_BUFFER_NAME); !queue->Overwrite(&command)) {
        LOG_ERROR("Unable to overwrite the command in the commands queue.");
    }
}

bool WorkerDesktop::handleMessage(std::uint32_t queueID)
{
    bool result       = false;


@@ 130,6 137,9 @@ bool WorkerDesktop::handleMessage(std::uint32_t queueID)
    else if (qname == sdesktop::IRQ_QUEUE_BUFFER_NAME) {
        result = handleIrqQueueMessage(queue);
    }
    else if (qname == sdesktop::SIGNALLING_QUEUE_BUFFER_NAME) {
        result = handleSignallingQueueMessage(queue);
    }
    else {
        LOG_INFO("handeMessage got message on an unhandled queue");
    }


@@ 240,6 250,28 @@ bool WorkerDesktop::handleIrqQueueMessage(std::shared_ptr<sys::WorkerQueue> &que
    return true;
}

bool WorkerDesktop::handleSignallingQueueMessage(std::shared_ptr<sys::WorkerQueue> &queue)
{
    if (!initialized) {
        return false;
    }
    sys::WorkerCommand command;
    if (!queue->Dequeue(&command, 0)) {
        LOG_ERROR("handleMessage failed to receive from \"%s\"", sdesktop::SIGNALLING_QUEUE_BUFFER_NAME);
        return false;
    }

    switch (static_cast<Signal>(command.command)) {
    case Signal::startMTP:
        bsp::usbStartMTP();
        break;
    default:
        LOG_ERROR("Command not valid.");
        return false;
    }
    return true;
}

void WorkerDesktop::suspendUsb()
{
    bsp::usbSuspend();

M module-services/service-desktop/WorkerDesktop.hpp => module-services/service-desktop/WorkerDesktop.hpp +7 -0
@@ 19,6 19,11 @@
class WorkerDesktop : public sys::Worker
{
  public:
    enum class Signal
    {
        startMTP
    };

    WorkerDesktop(sys::Service *ownerServicePtr,
                  std::function<void()> messageProcessedCallback,
                  const sdesktop::USBSecurityModel &securityModel,


@@ 30,6 35,7 @@ class WorkerDesktop : public sys::Worker
    bool reinit(const std::filesystem::path &path);

    bool handleMessage(std::uint32_t queueID) override final;
    void notify(Signal command);

    xQueueHandle getReceiveQueue()
    {


@@ 44,6 50,7 @@ class WorkerDesktop : public sys::Worker
    bool handleSendQueueMessage(std::shared_ptr<sys::WorkerQueue> &queue);
    bool handleServiceQueueMessage(std::shared_ptr<sys::WorkerQueue> &queue);
    bool handleIrqQueueMessage(std::shared_ptr<sys::WorkerQueue> &queue);
    bool handleSignallingQueueMessage(std::shared_ptr<sys::WorkerQueue> &queue);

    std::atomic<bool> initialized = false;


M module-services/service-desktop/include/service-desktop/ServiceDesktop.hpp => module-services/service-desktop/include/service-desktop/ServiceDesktop.hpp +6 -3
@@ 28,14 28,17 @@ namespace sdesktop
{
    inline constexpr auto service_stack             = 8192;
    inline constexpr auto worker_stack              = 8704;
    inline constexpr auto cdc_queue_len             = 1024;
    inline constexpr auto cdc_queue_object_size     = 1024;
    inline constexpr auto irq_queue_object_size     = sizeof(bsp::USBDeviceStatus);
    inline constexpr auto cdcReceiveQueueLength        = 1024;
    inline constexpr auto cdcSendQueueLength           = 1024;
    inline constexpr auto signallingQueueLength        = 4;
    inline constexpr auto irqQueueLength               = 4;
    inline constexpr auto irqQueueSize                 = sizeof(bsp::USBDeviceStatus);
    constexpr auto connectionActiveTimerName        = "connectionActiveTimer";
    constexpr auto connectionActiveTimerDelayMs     = std::chrono::milliseconds{1000 * 20};
    inline constexpr auto RECEIVE_QUEUE_BUFFER_NAME = "receiveQueueBuffer";
    inline constexpr auto SEND_QUEUE_BUFFER_NAME    = "sendQueueBuffer";
    inline constexpr auto IRQ_QUEUE_BUFFER_NAME     = "irqQueueBuffer";
    inline constexpr auto SIGNALLING_QUEUE_BUFFER_NAME = "signallingQueueBuffer";
    inline constexpr auto DeviceUniqueIdLength      = 32;
    inline constexpr auto DeviceUniqueIdName        = "sd_device_unique_id";
    constexpr auto pathFactoryDataSerial            = "factory_data/serial";

M pure_changelog.md => pure_changelog.md +1 -0
@@ 8,6 8,7 @@
* Separated system volume from Bluetooth device volume for A2DP

### Fixed
* Fixed the accessibility of user files by MTP
* Fixed SIM card pop-ups not showing
* Fixed lost bytes in logs
* Fixed passcode lock time discrepancy between lock screen and 'Wrong password' popup

M third-party/usb_stack => third-party/usb_stack +1 -1
@@ 1,1 1,1 @@
Subproject commit 1712d16bacb5a07c2e0a56ee7952e279d290fb47
Subproject commit f8081cb29540aa96f228de7a82d3b5ef3170f121