[FL-2163] CLI: Separate session from CLI service (#1130)
* CLI: session refactoring * Added forgotten define * Desktop lock state save * Dolphin: use proper type for value returned by dolphin_state_xp_to_levelup Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <toolbox/saved_struct.h>
|
||||
|
||||
#define DESKTOP_SETTINGS_VER (2)
|
||||
#define DESKTOP_SETTINGS_VER (3)
|
||||
#define DESKTOP_SETTINGS_PATH "/int/desktop.settings"
|
||||
#define DESKTOP_SETTINGS_MAGIC (0x17)
|
||||
#define PIN_MAX_LENGTH 12
|
||||
@@ -39,5 +39,6 @@ typedef struct {
|
||||
typedef struct {
|
||||
uint16_t favorite;
|
||||
PinCode pin_code;
|
||||
uint8_t is_locked;
|
||||
uint32_t auto_lock_delay_ms;
|
||||
} DesktopSettings;
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "../helpers/pin_lock.h"
|
||||
#include "../desktop_i.h"
|
||||
#include <cli/cli_vcp.h>
|
||||
|
||||
static const NotificationSequence sequence_pin_fail = {
|
||||
&message_display_on,
|
||||
@@ -61,26 +62,50 @@ uint32_t desktop_pin_lock_get_fail_timeout() {
|
||||
return pin_timeout;
|
||||
}
|
||||
|
||||
void desktop_pin_lock() {
|
||||
void desktop_pin_lock(DesktopSettings* settings) {
|
||||
furi_assert(settings);
|
||||
|
||||
furi_hal_rtc_set_pin_fails(0);
|
||||
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
||||
furi_hal_usb_disable();
|
||||
Cli* cli = furi_record_open("cli");
|
||||
cli_session_close(cli);
|
||||
furi_record_close("cli");
|
||||
settings->is_locked = 1;
|
||||
SAVE_DESKTOP_SETTINGS(settings);
|
||||
}
|
||||
|
||||
void desktop_pin_unlock() {
|
||||
void desktop_pin_unlock(DesktopSettings* settings) {
|
||||
furi_assert(settings);
|
||||
|
||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
||||
furi_hal_usb_enable();
|
||||
Cli* cli = furi_record_open("cli");
|
||||
cli_session_open(cli, &cli_vcp);
|
||||
furi_record_close("cli");
|
||||
settings->is_locked = 0;
|
||||
SAVE_DESKTOP_SETTINGS(settings);
|
||||
}
|
||||
|
||||
void desktop_pin_lock_init(DesktopSettings* settings) {
|
||||
furi_assert(settings);
|
||||
|
||||
if(settings->pin_code.length > 0) {
|
||||
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
||||
furi_hal_usb_disable();
|
||||
if(settings->is_locked == 1) {
|
||||
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
||||
} else {
|
||||
if(desktop_pin_lock_is_locked()) {
|
||||
settings->is_locked = 1;
|
||||
SAVE_DESKTOP_SETTINGS(settings);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
furi_hal_rtc_set_pin_fails(0);
|
||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
||||
furi_hal_usb_enable();
|
||||
}
|
||||
|
||||
if(desktop_pin_lock_is_locked()) {
|
||||
furi_hal_usb_disable();
|
||||
}
|
||||
}
|
||||
|
||||
bool desktop_pin_lock_verify(const PinCode* pin_set, const PinCode* pin_entered) {
|
||||
|
@@ -8,9 +8,9 @@ void desktop_pin_lock_error_notify();
|
||||
|
||||
uint32_t desktop_pin_lock_get_fail_timeout();
|
||||
|
||||
void desktop_pin_lock();
|
||||
void desktop_pin_lock(DesktopSettings* settings);
|
||||
|
||||
void desktop_pin_unlock();
|
||||
void desktop_pin_unlock(DesktopSettings* settings);
|
||||
|
||||
bool desktop_pin_lock_is_locked();
|
||||
|
||||
|
@@ -54,7 +54,7 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
break;
|
||||
case DesktopLockMenuEventPinLock:
|
||||
if(desktop->settings.pin_code.length > 0) {
|
||||
desktop_pin_lock();
|
||||
desktop_pin_lock(&desktop->settings);
|
||||
desktop_lock(desktop);
|
||||
} else {
|
||||
LoaderStatus status =
|
||||
|
@@ -126,7 +126,7 @@ bool desktop_scene_pin_input_on_event(void* context, SceneManagerEvent event) {
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopPinInputEventUnlocked:
|
||||
desktop_pin_unlock();
|
||||
desktop_pin_unlock(&desktop->settings);
|
||||
desktop_unlock(desktop);
|
||||
consumed = true;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user