~aleteoryx/muditaos

e541f0d70dc6583023326a95a9fcb9fe2da6ddd8 — Wojtek Rzepecki 4 years ago 5324fcc
[EGD-7089] Fix torch color change when locked

Fix of torch behavior while phone is locked
M module-apps/apps-common/locks/CMakeLists.txt => module-apps/apps-common/locks/CMakeLists.txt +2 -0
@@ 11,6 11,7 @@ target_sources(apps-common
		handlers/SimLockHandler.cpp
		handlers/SimLockSubject.cpp
		handlers/LockPolicyHandler.cpp
		input/PhoneLockedKeysWhitelist.cpp
		widgets/Lock.cpp
		widgets/LockBoxConstantSize.cpp
		widgets/LockBoxAlternatingSize.cpp


@@ 28,6 29,7 @@ target_sources(apps-common
		handlers/LockPolicyHandler.hpp
		handlers/SimLockHandler.hpp
		handlers/SimLockSubject.hpp
		input/PhoneLockedKeysWhitelist.hpp
		widgets/LockHash.hpp
		widgets/Lock.hpp
		widgets/LockBox.hpp

A module-apps/apps-common/locks/input/PhoneLockedKeysWhitelist.cpp => module-apps/apps-common/locks/input/PhoneLockedKeysWhitelist.cpp +25 -0
@@ 0,0 1,25 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PhoneLockedKeysWhitelist.hpp"
#include <array>

namespace locks::PhoneLockedKeysWhitelist
{
    namespace
    {
        using namespace gui;
        constexpr std::array list = {
            KeyCode::KEY_TORCH, KeyCode::KEY_VOLDN, KeyCode::HEADSET_VOLDN, KeyCode::KEY_VOLUP, KeyCode::HEADSET_VOLUP};
    } // anonymous namespace

    [[nodiscard]] bool isOnWhitelist(const gui::InputEvent &inputEvent)
    {
        for (const auto &key : list) {
            if (inputEvent.is(key)) {
                return true;
            }
        }
        return false;
    }
} // namespace locks::PhoneLockedKeysWhitelist

A module-apps/apps-common/locks/input/PhoneLockedKeysWhitelist.hpp => module-apps/apps-common/locks/input/PhoneLockedKeysWhitelist.hpp +11 -0
@@ 0,0 1,11 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <InputEvent.hpp>

namespace locks::PhoneLockedKeysWhitelist
{
    [[nodiscard]] bool isOnWhitelist(const gui::InputEvent &inputEvent);
} // namespace locks::PhoneLockedKeysWhitelist

M module-apps/apps-common/popups/WindowWithTimer.cpp => module-apps/apps-common/popups/WindowWithTimer.cpp +4 -1
@@ 15,7 15,7 @@ namespace gui
    WindowWithTimer::WindowWithTimer(app::Application *app,
                                     const std::string &name,
                                     const std::chrono::milliseconds timeout)
        : AppWindow{app, name}
        : AppWindow{app, name}, timeout{timeout}
    {
        popupTimer    = app::GuiTimerFactory::createSingleShotTimer(application, this, popup::timerName, timeout);
        timerCallback = [this](Item &, sys::Timer &timer) {


@@ 27,6 27,9 @@ namespace gui

    void WindowWithTimer::resetTimer()
    {
        if (!popupTimer.isValid()) {
            popupTimer = app::GuiTimerFactory::createSingleShotTimer(application, this, popup::timerName, timeout);
        }
        popupTimer.stop();
        popupTimer.start();
    }

M module-apps/apps-common/popups/WindowWithTimer.hpp => module-apps/apps-common/popups/WindowWithTimer.hpp +1 -0
@@ 13,6 13,7 @@ namespace gui
    {
      private:
        sys::TimerHandle popupTimer;
        const std::chrono::milliseconds timeout;

      public:
        explicit WindowWithTimer(app::Application *app,

M module-apps/apps-common/popups/lock-popups/PhoneLockInputWindow.cpp => module-apps/apps-common/popups/lock-popups/PhoneLockInputWindow.cpp +5 -1
@@ 3,6 3,7 @@

#include "PhoneLockInputWindow.hpp"

#include <locks/input/PhoneLockedKeysWhitelist.hpp>
#include <service-appmgr/Controller.hpp>
#include <locks/data/LockData.hpp>
#include <locks/widgets/PhoneLockBox.hpp>


@@ 127,6 128,9 @@ namespace gui
        }

        // check if any of the lower inheritance onInput methods catch the event
        return AppWindow::onInput(inputEvent);
        if (locks::PhoneLockedKeysWhitelist::isOnWhitelist(inputEvent)) {
            return AppWindow::onInput(inputEvent);
        }
        return true;
    }
} /* namespace gui */

M module-apps/apps-common/popups/lock-popups/PhoneLockedInfoWindow.cpp => module-apps/apps-common/popups/lock-popups/PhoneLockedInfoWindow.cpp +6 -0
@@ 3,6 3,7 @@

#include "PhoneLockedInfoWindow.hpp"

#include <locks/input/PhoneLockedKeysWhitelist.hpp>
#include <service-appmgr/Controller.hpp>
#include <application-desktop/data/DesktopStyle.hpp>



@@ 41,6 42,11 @@ void PhoneLockedInfoWindow::onBeforeShow([[maybe_unused]] ShowMode mode, SwitchD

bool PhoneLockedInfoWindow::onInput(const InputEvent &inputEvent)
{
    // check if any of the lower inheritance onInput methods catch the event
    if (locks::PhoneLockedKeysWhitelist::isOnWhitelist(inputEvent)) {
        return AppWindow::onInput(inputEvent);
    }

    // Right key = go back
    if (inputEvent.isShortRelease(KeyCode::KEY_RF)) {
        detachTimerIfExists();

M module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.cpp => module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.cpp +8 -4
@@ 4,6 4,7 @@
#include "PhoneLockedWindow.hpp"
#include "PhoneLockedInfoData.hpp"

#include <locks/input/PhoneLockedKeysWhitelist.hpp>
#include <application-desktop/data/DesktopStyle.hpp>
#include <module-services/service-appmgr/service-appmgr/Controller.hpp>
#include <time/time_conversion_factory.hpp>


@@ 79,14 80,17 @@ namespace gui
        if (inputEvent.is(KeyCode::KEY_RF)) {

            application->switchWindow(gui::popup::window::power_off_window);
            return true;
        }
        // check if any of the lower inheritance onInput methods catch the event
        return AppWindow::onInput(inputEvent);
        return true;
    }

    bool PhoneLockedWindow::onInput(const InputEvent &inputEvent)
    {
        // check if any of the lower inheritance onInput methods catch the event
        if (locks::PhoneLockedKeysWhitelist::isOnWhitelist(inputEvent)) {
            return AppWindow::onInput(inputEvent);
        }

        if (inputEvent.isLongRelease()) {
            return processLongReleaseEvent(inputEvent);
        }


@@ 97,7 101,7 @@ namespace gui
                                      std::make_unique<PhoneLockedInfoData>(requiredStage));
            return true;
        }
        return AppWindow::onInput(inputEvent);
        return true;
    }

    bool PhoneLockedWindow::updateTime()