mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-02-06 20:33:00 -05:00
Secure all endpoints by returning 403(Forbidden) when USB is connected. Request screen passcode to enable secured endpoints.
93 lines
4.4 KiB
C++
93 lines
4.4 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "application-settings-new/ApplicationSettings.hpp"
|
|
#include "application-settings-new/data/ChangePasscodeData.hpp"
|
|
#include "module-apps/application-desktop/windows/Names.hpp"
|
|
#include "module-apps/application-desktop/data/LockPhoneData.hpp"
|
|
#include "OptionSetting.hpp"
|
|
#include "SecurityMainWindow.hpp"
|
|
|
|
namespace gui
|
|
{
|
|
SecurityMainWindow::SecurityMainWindow(app::Application *app, app::settingsInterface::SecuritySettings *settings)
|
|
: BaseSettingsWindow(app, window::name::security), lockScreenPasscodeIsOn(app->isLockScreenPasscodeOn()),
|
|
securitySettings(settings)
|
|
{}
|
|
|
|
auto SecurityMainWindow::buildOptionsList() -> std::list<Option>
|
|
{
|
|
std::list<Option> optionList;
|
|
|
|
optionList.emplace_back(std::make_unique<option::OptionSettings>(
|
|
utils::translateI18("app_settings_security_lock_screen_passcode"),
|
|
[=](Item &item) {
|
|
lockScreenPasscodeIsOn = !lockScreenPasscodeIsOn;
|
|
LOG_INFO("switching to %s page", window::name::change_passcode);
|
|
auto data = lockScreenPasscodeIsOn
|
|
? std::make_unique<ChangePasscodeData>(ChangePasscodeAction::OnlyProvideNewPasscode)
|
|
: std::make_unique<ChangePasscodeData>(ChangePasscodeAction::OnlyCheckCurrentPasscode);
|
|
application->switchWindow(window::name::change_passcode, std::move(data));
|
|
return true;
|
|
},
|
|
[=](Item &item) {
|
|
if (item.focus) {
|
|
this->setBottomBarText(utils::localize.get(style::strings::common::Switch),
|
|
BottomBar::Side::CENTER);
|
|
}
|
|
else {
|
|
this->setBottomBarText(utils::localize.get(style::strings::common::select),
|
|
BottomBar::Side::CENTER);
|
|
}
|
|
return true;
|
|
},
|
|
nullptr,
|
|
lockScreenPasscodeIsOn ? option::SettingRightItem::On : option::SettingRightItem::Off));
|
|
|
|
optionList.emplace_back(std::make_unique<option::OptionSettings>(
|
|
utils::translateI18("app_settings_security_usb_passcode"),
|
|
[=](Item &item) {
|
|
auto lock = std::make_unique<gui::PinLock>(
|
|
Store::GSM::SIM::NONE, PinLock::LockState::PasscodeRequired, PinLock::LockType::Screen);
|
|
lock->onActivatedCallback = [this](PinLock::LockType type, const std::vector<unsigned int> &data) {
|
|
securitySettings->setUSBSecurity(!securitySettings->isUSBSecured());
|
|
application->returnToPreviousWindow();
|
|
};
|
|
application->switchWindow(app::window::name::desktop_pin_lock,
|
|
gui::ShowMode::GUI_SHOW_INIT,
|
|
std::make_unique<gui::LockPhoneData>(std::move(lock)));
|
|
return true;
|
|
},
|
|
[=](Item &item) {
|
|
if (item.focus) {
|
|
this->setBottomBarText(utils::localize.get(style::strings::common::Switch),
|
|
BottomBar::Side::CENTER);
|
|
}
|
|
else {
|
|
this->setBottomBarText(utils::localize.get(style::strings::common::select),
|
|
BottomBar::Side::CENTER);
|
|
}
|
|
return true;
|
|
},
|
|
nullptr,
|
|
securitySettings->isUSBSecured() ? option::SettingRightItem::On : option::SettingRightItem::Off));
|
|
|
|
if (lockScreenPasscodeIsOn) {
|
|
optionList.emplace_back(std::make_unique<option::OptionSettings>(
|
|
utils::translateI18("app_settings_security_change_passcode"),
|
|
[=](Item &item) {
|
|
LOG_INFO("switching to %s page", window::name::change_passcode);
|
|
application->switchWindow(
|
|
window::name::change_passcode,
|
|
std::make_unique<ChangePasscodeData>(ChangePasscodeAction::ChangeCurrentPasscode));
|
|
return true;
|
|
},
|
|
nullptr,
|
|
nullptr,
|
|
option::SettingRightItem::ArrowWhite));
|
|
}
|
|
|
|
return optionList;
|
|
}
|
|
} // namespace gui
|