mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-19 04:24:05 -04:00
Fix of the issue that Meditation app would prevent phone from locking on every screen, though it should do so only on timer screen.
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "LockPolicyHandler.hpp"
|
|
#include <log/log.hpp>
|
|
#include <ApplicationCommon.hpp>
|
|
#include <gsl/assert>
|
|
#include <AppWindow.hpp>
|
|
|
|
using namespace locks;
|
|
|
|
AutoLockPolicy LockPolicyAccessInterface::get() const noexcept
|
|
{
|
|
return autoLockingPolicy;
|
|
}
|
|
|
|
void LockPolicyAccessInterface::set(AutoLockPolicy policy) noexcept
|
|
{
|
|
if (autoLockingPolicy != AutoLockPolicy::PreventPermanently) {
|
|
autoLockingPolicy = policy;
|
|
}
|
|
else {
|
|
LOG_ERROR("AutoLocking is prevented permanently");
|
|
}
|
|
}
|
|
|
|
bool LockPolicyHandlerInterface::preventsAutoLocking()
|
|
{
|
|
if (const auto policy = get(); policy == AutoLockPolicy::DetermineByWindow) {
|
|
return preventsAutoLockByWindow();
|
|
}
|
|
else if (policy == AutoLockPolicy::DetermineByAppState) {
|
|
return preventsAutoLockByState() || preventsAutoLockByWindow();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
LockPolicyHandler::LockPolicyHandler(app::ApplicationCommon *owner,
|
|
std::function<bool()> preventsAutoLockByStateCallback) noexcept
|
|
: owner{owner}, preventsAutoLockByStateCallback(std::move(preventsAutoLockByStateCallback))
|
|
{
|
|
Expects(owner != nullptr);
|
|
}
|
|
|
|
void LockPolicyHandler::setPreventsAutoLockByStateCallback(
|
|
std::function<bool()> _preventsAutoLockByStateCallback) noexcept
|
|
{
|
|
preventsAutoLockByStateCallback = std::move(_preventsAutoLockByStateCallback);
|
|
}
|
|
|
|
bool LockPolicyHandler::preventsAutoLockByWindow()
|
|
{
|
|
return owner->getCurrentWindow()->preventsAutoLocking();
|
|
}
|
|
|
|
bool LockPolicyHandler::preventsAutoLockByState() const
|
|
{
|
|
Expects(preventsAutoLockByStateCallback != nullptr);
|
|
return preventsAutoLockByStateCallback();
|
|
}
|