~aleteoryx/muditaos

5f9df4cd244467779a48e66fa328380af515e156 — Lefucjusz 3 years ago 553f04c
[MOS-559] Fix unlock when phone started not in Connected mode

Fix of the issue that when phone was started in
mode different than Connected, next mode changed
resulted in bypassing of the lock.
M module-apps/apps-common/ApplicationCommon.cpp => module-apps/apps-common/ApplicationCommon.cpp +34 -8
@@ 28,6 28,8 @@
#include <popups/data/PhoneModeParams.hpp>
#include <popups/data/BluetoothModeParams.hpp>

#include <locks/data/PhoneLockMessages.hpp>

#if DEBUG_INPUT_EVENTS == 1
#define debug_input_events(...) LOG_DEBUG(__VA_ARGS__)
#else


@@ 92,6 94,7 @@ namespace app

        bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications);
        bus.channels.push_back(sys::BusChannel::USBNotifications);
        bus.channels.push_back(sys::BusChannel::PhoneLockChanges);

        longPressTimer = sys::TimerFactory::createPeriodicTimer(this,
                                                                "LongPress",


@@ 112,6 115,16 @@ namespace app
        connect(typeid(sdesktop::usb::USBDisconnected),
                [&](sys::Message *msg) -> sys::MessagePointer { return handleUSBStatusChange(); });

        connect(typeid(locks::UnlockedPhone), [&](sys::Message *msg) {
            phoneIsLocked = false;
            return sys::MessageNone{};
        });

        connect(typeid(locks::LockedPhone), [&](sys::Message *msg) {
            phoneIsLocked = true;
            return sys::MessageNone{};
        });

        addActionReceiver(app::manager::actions::PhoneModeChanged, [this](auto &&params) {
            if (params != nullptr) {
                auto modeParams                  = static_cast<gui::PhoneModeParams *>(params.get());


@@ 544,16 557,29 @@ namespace app

    sys::MessagePointer ApplicationCommon::handleSwitchWindow(sys::Message *msgl)
    {
        auto msg = static_cast<AppSwitchWindowMessage *>(msgl);
        if (not windowsFactory.isRegistered(msg->getWindowName())) {
            LOG_ERROR("No such window: %s", msg->getWindowName().c_str());
        const auto msg        = static_cast<AppSwitchWindowMessage *>(msgl);
        const auto windowName = msg->getWindowName();
        if (not windowsFactory.isRegistered(windowName)) {
            LOG_ERROR("No such window: %s", windowName.c_str());
            return sys::msgHandled();
        }

        // Workaround for corner case when phone started with mode slider in position different than "Connected".
        // This triggers race condition between PhoneLockPopup and PhoneModesPopup. Usually PhoneLockPopup got placed
        // on PhoneModesPopup in windows stack, which resulted in PhoneLockPopup being dropped when phone mode was
        // changed again (see how pushWindow method works), what bypassed the phone lock.
        if (phoneIsLocked && (not windowsStack().isWindowOnStack(gui::popup::window::phone_lock_window)) &&
            (windowName == gui::popup::window::phone_modes_window)) {
            LOG_ERROR(
                "Tried to show PhoneModesPopup on locked phone, but PhoneLockPopup was not at the window stack yet!");
            return sys::msgHandled();
        }

        auto switchData = std::move(msg->getData());
        if (switchData && switchData->ignoreCurrentWindowOnStack) {
            windowsStack().pop();
        }
        auto anotherWindowOnTop = (not isCurrentWindow(msg->getWindowName())) and (not windowsStack().isEmpty());
        auto anotherWindowOnTop = (not isCurrentWindow(windowName)) and (not windowsStack().isEmpty());
        if (anotherWindowOnTop) {
            auto closeReason = gui::Window::CloseReason::WindowSwitch;
            switch (msg->getReason()) {


@@ 569,7 595,7 @@ namespace app
            getCurrentWindow()->onClose(closeReason);
        }

        LOG_DEBUG("Current window: %s vs %s", getCurrentWindow()->getName().c_str(), msg->getWindowName().c_str());
        LOG_DEBUG("Current window: %s vs %s", getCurrentWindow()->getName().c_str(), windowName.c_str());
        const auto &[name, data] = msg->getSwitchData();
        pushWindow(name, data);
        getCurrentWindow()->handleSwitchData(switchData.get());


@@ 843,12 869,12 @@ namespace app
    {
        auto request = windowsPopupQueue->popRequest(getPopupFilter());
        if (request) {
            auto popup = std::string(magic_enum::enum_name(request->getPopupParams().getPopupId()));
            LOG_DEBUG("handling popup: %s", popup.c_str());
            const auto popup = magic_enum::enum_name(request->getPopupParams().getPopupId()).data();
            LOG_DEBUG("handling popup: %s", popup);
            /// request handle actually switches window to popup window
            auto retval = request->handle();
            if (not retval) {
                LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup.c_str());
                LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup);
            }
            return retval;
        }

M module-apps/apps-common/ApplicationCommon.hpp => module-apps/apps-common/ApplicationCommon.hpp +1 -0
@@ 187,6 187,7 @@ namespace app
        std::unique_ptr<WindowsStack> windowsStackImpl;
        std::string default_window;
        State state = State::DEACTIVATED;
        bool phoneIsLocked = true;

        sys::MessagePointer handleSignalStrengthUpdate(sys::Message *msgl);
        sys::MessagePointer handleNetworkAccessTechnologyUpdate(sys::Message *msgl);

M module-apps/apps-common/WindowsStack.cpp => module-apps/apps-common/WindowsStack.cpp +5 -0
@@ 116,6 116,11 @@ namespace app
        return std::find_if(stack.begin(), stack.end(), [&](auto &el) { return el.name == window; });
    }

    bool WindowsStack::isWindowOnStack(const std::string &window)
    {
        return findInStack(window) != stack.end();
    }

    void WindowsStack::dropPendingPopups()
    {
        auto it = stack.rbegin();

M module-apps/apps-common/WindowsStack.hpp => module-apps/apps-common/WindowsStack.hpp +2 -0
@@ 73,6 73,8 @@ namespace app
        void dropPendingPopups();
        void clear();

        bool isWindowOnStack(const std::string &window);

        bool rebuildWindows(app::WindowsFactory &windowsFactory, ApplicationCommon *app);
    };


M module-services/service-cellular/call/CellularCall.cpp => module-services/service-cellular/call/CellularCall.cpp +0 -11
@@ 3,22 3,11 @@

#include "call/CellularCall.hpp"
#include "service-cellular/ServiceCellular.hpp"
#include "service-db/agents/settings/SystemSettings.hpp"

#include <CalllogRecord.hpp>
#include <PhoneNumber.hpp>
#include <Utils.hpp>
#include <log/log.hpp>

#include <cinttypes>
#include <ctime>
#include <memory>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include "CallMachine.hpp"

namespace call