[FL-2152] New PIN lock (#989)
* [Fl-2152] New PIN Lock, part 1 * Fix errors & leaks, renaming * Add support to f6 * Fix error, remove duplicate code * Fix drawing corners of Lock Popup * FuriHal: insomnia if usb connected * Applications: cleanup timers use Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -3,5 +3,7 @@ ADD_SCENE(desktop, lock_menu, LockMenu)
|
||||
ADD_SCENE(desktop, debug, Debug)
|
||||
ADD_SCENE(desktop, first_start, FirstStart)
|
||||
ADD_SCENE(desktop, hw_mismatch, HwMismatch)
|
||||
ADD_SCENE(desktop, pinsetup, PinSetup)
|
||||
ADD_SCENE(desktop, fault, Fault)
|
||||
ADD_SCENE(desktop, locked, Locked)
|
||||
ADD_SCENE(desktop, pin_input, PinInput)
|
||||
ADD_SCENE(desktop, pin_timeout, PinTimeout)
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <dolphin/helpers/dolphin_deed.h>
|
||||
|
||||
#include "../desktop_i.h"
|
||||
#include "../views/desktop_debug.h"
|
||||
#include "../views/desktop_view_debug.h"
|
||||
#include "desktop_scene.h"
|
||||
|
||||
void desktop_scene_debug_callback(DesktopEvent event, void* context) {
|
||||
@@ -17,7 +17,7 @@ void desktop_scene_debug_on_enter(void* context) {
|
||||
desktop_debug_get_dolphin_data(desktop->debug_view);
|
||||
|
||||
desktop_debug_set_callback(desktop->debug_view, desktop_scene_debug_callback, desktop);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewDebug);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdDebug);
|
||||
}
|
||||
|
||||
bool desktop_scene_debug_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@@ -25,7 +25,7 @@ void desktop_scene_fault_on_enter(void* context) {
|
||||
char* message = (char*)furi_hal_rtc_get_fault_data();
|
||||
popup_set_text(popup, message, 60, 37 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter);
|
||||
popup_set_callback(popup, desktop_scene_fault_callback);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewHwMismatch);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdHwMismatch);
|
||||
}
|
||||
|
||||
bool desktop_scene_fault_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include <storage/storage.h>
|
||||
|
||||
#include "../desktop_i.h"
|
||||
#include "../views/desktop_first_start.h"
|
||||
#include "../views/desktop_view_first_start.h"
|
||||
#include "../views/desktop_events.h"
|
||||
|
||||
void desktop_scene_first_start_callback(DesktopEvent event, void* context) {
|
||||
@@ -17,7 +17,7 @@ void desktop_scene_first_start_on_enter(void* context) {
|
||||
desktop_first_start_set_callback(
|
||||
first_start_view, desktop_scene_first_start_callback, desktop);
|
||||
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewFirstStart);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdFirstStart);
|
||||
}
|
||||
|
||||
bool desktop_scene_first_start_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include <gui/scene_manager.h>
|
||||
#include <furi_hal_version.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include "desktop_scene.h"
|
||||
#include "../desktop_i.h"
|
||||
@@ -31,7 +31,7 @@ void desktop_scene_hw_mismatch_on_enter(void* context) {
|
||||
popup, "!!!! HW Mismatch !!!!", 60, 14 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter);
|
||||
popup_set_text(popup, text_buffer, 60, 37 + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter);
|
||||
popup_set_callback(popup, desktop_scene_hw_mismatch_callback);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewHwMismatch);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdHwMismatch);
|
||||
}
|
||||
|
||||
bool desktop_scene_hw_mismatch_on_event(void* context, SceneManagerEvent event) {
|
||||
|
@@ -1,7 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
DesktopMainSceneStateUnlocked,
|
||||
DesktopMainSceneStateLockedWithPin,
|
||||
DesktopMainSceneStateLockedNoPin,
|
||||
} DesktopMainSceneState;
|
||||
#define SCENE_LOCKED_FIRST_ENTER 0
|
||||
#define SCENE_LOCKED_REPEAT_ENTER 1
|
||||
|
@@ -1,8 +1,13 @@
|
||||
#include <gui/scene_manager.h>
|
||||
#include <applications.h>
|
||||
#include <furi_hal.h>
|
||||
#include <toolbox/saved_struct.h>
|
||||
#include <stdbool.h>
|
||||
#include <loader/loader.h>
|
||||
|
||||
#include "../desktop_i.h"
|
||||
#include "../views/desktop_lock_menu.h"
|
||||
#include "../desktop_settings/desktop_settings.h"
|
||||
#include "../views/desktop_view_lock_menu.h"
|
||||
#include "desktop_scene_i.h"
|
||||
#include "desktop_scene.h"
|
||||
|
||||
@@ -15,36 +20,50 @@ void desktop_scene_lock_menu_on_enter(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
|
||||
LOAD_DESKTOP_SETTINGS(&desktop->settings);
|
||||
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
|
||||
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
|
||||
desktop_lock_menu_pin_set(desktop->lock_menu, desktop->settings.pincode.length > 0);
|
||||
desktop_lock_menu_pin_set(desktop->lock_menu, desktop->settings.pin_code.length > 0);
|
||||
desktop_lock_menu_set_idx(desktop->lock_menu, 0);
|
||||
|
||||
uint8_t idx = scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLockMenu);
|
||||
desktop_lock_menu_set_idx(desktop->lock_menu, idx);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewLockMenu);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu);
|
||||
}
|
||||
|
||||
bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.type == SceneManagerEventTypeTick) {
|
||||
bool check_pin_changed =
|
||||
scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLockMenu);
|
||||
if(check_pin_changed) {
|
||||
LOAD_DESKTOP_SETTINGS(&desktop->settings);
|
||||
if(desktop->settings.pin_code.length > 0) {
|
||||
desktop_lock_menu_pin_set(desktop->lock_menu, 1);
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
|
||||
}
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case DesktopLockMenuEventLock:
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopSceneMain, DesktopMainSceneStateLockedNoPin);
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopSceneLocked, SCENE_LOCKED_FIRST_ENTER);
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopLockMenuEventPinLock:
|
||||
if(desktop->settings.pincode.length > 0) {
|
||||
if(desktop->settings.pin_code.length > 0) {
|
||||
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopSceneMain, DesktopMainSceneStateLockedWithPin);
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
||||
desktop->scene_manager, DesktopSceneLocked, SCENE_LOCKED_FIRST_ENTER);
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
|
||||
} else {
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 1);
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopScenePinSetup);
|
||||
Loader* loader = furi_record_open("loader");
|
||||
LoaderStatus status =
|
||||
loader_start(loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
|
||||
furi_check(status == LoaderStatusOk);
|
||||
furi_record_close("loader");
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
|
109
applications/desktop/scenes/desktop_scene_locked.c
Normal file
109
applications/desktop/scenes/desktop_scene_locked.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/view_stack.h>
|
||||
#include <stdint.h>
|
||||
#include <portmacro.h>
|
||||
|
||||
#include "../desktop.h"
|
||||
#include "../desktop_i.h"
|
||||
#include "../desktop_helpers.h"
|
||||
#include "../animations/animation_manager.h"
|
||||
#include "../views/desktop_events.h"
|
||||
#include "../views/desktop_view_pin_input.h"
|
||||
#include "../views/desktop_view_locked.h"
|
||||
#include "desktop_scene.h"
|
||||
#include "desktop_scene_i.h"
|
||||
|
||||
#define WRONG_PIN_HEADER_TIMEOUT 3000
|
||||
#define INPUT_PIN_VIEW_TIMEOUT 15000
|
||||
|
||||
static void desktop_scene_locked_callback(DesktopEvent event, void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
|
||||
}
|
||||
|
||||
static void desktop_scene_locked_new_idle_animation_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
view_dispatcher_send_custom_event(
|
||||
desktop->view_dispatcher, DesktopAnimationEventNewIdleAnimation);
|
||||
}
|
||||
|
||||
void desktop_scene_locked_on_enter(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
|
||||
// callbacks for 1-st layer
|
||||
animation_manager_set_new_idle_callback(
|
||||
desktop->animation_manager, desktop_scene_locked_new_idle_animation_callback);
|
||||
animation_manager_set_check_callback(desktop->animation_manager, NULL);
|
||||
animation_manager_set_interact_callback(desktop->animation_manager, NULL);
|
||||
|
||||
// callbacks for 2-nd layer
|
||||
desktop_view_locked_set_callback(desktop->locked_view, desktop_scene_locked_callback, desktop);
|
||||
|
||||
bool switch_to_timeout_scene = false;
|
||||
uint32_t state = scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLocked);
|
||||
if(state == SCENE_LOCKED_FIRST_ENTER) {
|
||||
bool pin_locked = furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock);
|
||||
desktop_helpers_lock_system(desktop, pin_locked);
|
||||
if(pin_locked) {
|
||||
LOAD_DESKTOP_SETTINGS(&desktop->settings);
|
||||
desktop_view_locked_lock(desktop->locked_view, true);
|
||||
uint32_t pin_fails = furi_hal_rtc_get_pin_fails();
|
||||
uint32_t pin_timeout = desktop_helpers_get_pin_fail_timeout(pin_fails);
|
||||
if(pin_timeout) {
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopScenePinTimeout, pin_timeout);
|
||||
switch_to_timeout_scene = true;
|
||||
} else {
|
||||
desktop_view_locked_close_doors(desktop->locked_view);
|
||||
}
|
||||
} else {
|
||||
desktop_view_locked_lock(desktop->locked_view, false);
|
||||
desktop_view_locked_close_doors(desktop->locked_view);
|
||||
}
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopSceneLocked, SCENE_LOCKED_REPEAT_ENTER);
|
||||
}
|
||||
|
||||
if(switch_to_timeout_scene) {
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopScenePinTimeout);
|
||||
} else {
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLocked);
|
||||
}
|
||||
}
|
||||
|
||||
bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case DesktopLockedEventUnlocked:
|
||||
furi_hal_rtc_set_pin_fails(0);
|
||||
desktop_helpers_unlock_system(desktop);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
desktop->scene_manager, DesktopSceneMain);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopLockedEventUpdate:
|
||||
desktop_view_locked_update(desktop->locked_view);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopLockedEventShowPinInput:
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopScenePinInput);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopAnimationEventNewIdleAnimation:
|
||||
animation_manager_new_idle_process(desktop->animation_manager);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void desktop_scene_locked_on_exit(void* context) {
|
||||
}
|
@@ -4,15 +4,14 @@
|
||||
#include <assets_icons.h>
|
||||
#include <loader/loader.h>
|
||||
|
||||
#include "desktop/desktop_i.h"
|
||||
#include "desktop/views/desktop_main.h"
|
||||
#include "../desktop_i.h"
|
||||
#include "../views/desktop_events.h"
|
||||
#include "../views/desktop_view_main.h"
|
||||
#include "desktop_scene.h"
|
||||
#include "desktop_scene_i.h"
|
||||
|
||||
#define TAG "DesktopSrv"
|
||||
|
||||
#define MAIN_VIEW_DEFAULT (0UL)
|
||||
|
||||
static void desktop_scene_main_app_started_callback(const void* message, void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
@@ -31,19 +30,22 @@ static void desktop_scene_main_app_started_callback(const void* message, void* c
|
||||
static void desktop_scene_main_new_idle_animation_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopMainEventNewIdleAnimation);
|
||||
view_dispatcher_send_custom_event(
|
||||
desktop->view_dispatcher, DesktopAnimationEventNewIdleAnimation);
|
||||
}
|
||||
|
||||
static void desktop_scene_main_check_animation_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopMainEventCheckAnimation);
|
||||
view_dispatcher_send_custom_event(
|
||||
desktop->view_dispatcher, DesktopAnimationEventCheckAnimation);
|
||||
}
|
||||
|
||||
static void desktop_scene_main_interact_animation_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopMainEventInteractAnimation);
|
||||
view_dispatcher_send_custom_event(
|
||||
desktop->view_dispatcher, DesktopAnimationEventInteractAnimation);
|
||||
}
|
||||
|
||||
static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* flipper_app) {
|
||||
@@ -80,7 +82,6 @@ void desktop_scene_main_on_enter(void* context) {
|
||||
desktop->animation_manager, desktop_scene_main_check_animation_callback);
|
||||
animation_manager_set_interact_callback(
|
||||
desktop->animation_manager, desktop_scene_main_interact_animation_callback);
|
||||
desktop_locked_set_callback(desktop->locked_view, desktop_scene_main_callback, desktop);
|
||||
|
||||
furi_assert(osSemaphoreGetCount(desktop->unload_animation_semaphore) == 0);
|
||||
Loader* loader = furi_record_open("loader");
|
||||
@@ -90,24 +91,7 @@ void desktop_scene_main_on_enter(void* context) {
|
||||
|
||||
desktop_main_set_callback(main_view, desktop_scene_main_callback, desktop);
|
||||
|
||||
DesktopMainSceneState state =
|
||||
scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneMain);
|
||||
if(state == DesktopMainSceneStateLockedNoPin) {
|
||||
desktop_locked_lock(desktop->locked_view);
|
||||
view_port_enabled_set(desktop->lock_viewport, true);
|
||||
} else if(state == DesktopMainSceneStateLockedWithPin) {
|
||||
LOAD_DESKTOP_SETTINGS(&desktop->settings);
|
||||
furi_assert(desktop->settings.pincode.length > 0);
|
||||
desktop_locked_lock_pincode(desktop->locked_view, desktop->settings.pincode);
|
||||
view_port_enabled_set(desktop->lock_viewport, true);
|
||||
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
||||
furi_hal_usb_disable();
|
||||
} else {
|
||||
furi_assert(state == DesktopMainSceneStateUnlocked);
|
||||
view_port_enabled_set(desktop->lock_viewport, false);
|
||||
}
|
||||
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewMain);
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdMain);
|
||||
}
|
||||
|
||||
bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
@@ -154,15 +138,15 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case DesktopMainEventCheckAnimation:
|
||||
case DesktopAnimationEventCheckAnimation:
|
||||
animation_manager_check_blocking_process(desktop->animation_manager);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopMainEventNewIdleAnimation:
|
||||
case DesktopAnimationEventNewIdleAnimation:
|
||||
animation_manager_new_idle_process(desktop->animation_manager);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopMainEventInteractAnimation:
|
||||
case DesktopAnimationEventInteractAnimation:
|
||||
animation_manager_interact_process(desktop->animation_manager);
|
||||
consumed = true;
|
||||
break;
|
||||
@@ -175,16 +159,8 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
|
||||
animation_manager_load_and_continue_animation(desktop->animation_manager);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopMainEventUnlocked:
|
||||
consumed = true;
|
||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
||||
furi_hal_usb_enable();
|
||||
view_port_enabled_set(desktop->lock_viewport, false);
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopSceneMain, DesktopMainSceneStateUnlocked);
|
||||
break;
|
||||
case DesktopMainEventUpdate:
|
||||
desktop_locked_update(desktop->locked_view);
|
||||
case DesktopLockedEventUpdate:
|
||||
desktop_view_locked_update(desktop->locked_view);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
@@ -213,5 +189,4 @@ void desktop_scene_main_on_exit(void* context) {
|
||||
animation_manager_set_check_callback(desktop->animation_manager, NULL);
|
||||
animation_manager_set_interact_callback(desktop->animation_manager, NULL);
|
||||
animation_manager_set_context(desktop->animation_manager, desktop);
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneMain, MAIN_VIEW_DEFAULT);
|
||||
}
|
||||
|
162
applications/desktop/scenes/desktop_scene_pin_input.c
Normal file
162
applications/desktop/scenes/desktop_scene_pin_input.c
Normal file
@@ -0,0 +1,162 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <gui/view_stack.h>
|
||||
#include <stdint.h>
|
||||
#include <portmacro.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#include "../desktop.h"
|
||||
#include "../desktop_i.h"
|
||||
#include "../animations/animation_manager.h"
|
||||
#include "../views/desktop_events.h"
|
||||
#include "../views/desktop_view_pin_input.h"
|
||||
#include "../desktop_helpers.h"
|
||||
#include "desktop_scene.h"
|
||||
#include "desktop_scene_i.h"
|
||||
|
||||
#define WRONG_PIN_HEADER_TIMEOUT 3000
|
||||
#define INPUT_PIN_VIEW_TIMEOUT 15000
|
||||
|
||||
typedef struct {
|
||||
TimerHandle_t timer;
|
||||
} DesktopScenePinInputState;
|
||||
|
||||
static void desktop_scene_locked_light_red(bool value) {
|
||||
NotificationApp* app = furi_record_open("notification");
|
||||
if(value) {
|
||||
notification_message(app, &sequence_set_only_red_255);
|
||||
} else {
|
||||
notification_message(app, &sequence_reset_red);
|
||||
}
|
||||
furi_record_close("notification");
|
||||
}
|
||||
|
||||
static void
|
||||
desktop_scene_pin_input_set_timer(Desktop* desktop, bool enable, TickType_t new_period) {
|
||||
furi_assert(desktop);
|
||||
|
||||
DesktopScenePinInputState* state = (DesktopScenePinInputState*)scene_manager_get_scene_state(
|
||||
desktop->scene_manager, DesktopScenePinInput);
|
||||
furi_assert(state);
|
||||
if(enable) {
|
||||
xTimerChangePeriod(state->timer, new_period, portMAX_DELAY);
|
||||
} else {
|
||||
xTimerStop(state->timer, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
static void desktop_scene_pin_input_back_callback(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopPinInputEventBack);
|
||||
}
|
||||
|
||||
static void desktop_scene_pin_input_done_callback(const PinCode* pin_code, void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
if(pins_are_equal(&desktop->settings.pin_code, pin_code)) {
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopPinInputEventUnlocked);
|
||||
} else {
|
||||
view_dispatcher_send_custom_event(
|
||||
desktop->view_dispatcher, DesktopPinInputEventUnlockFailed);
|
||||
}
|
||||
}
|
||||
|
||||
static void desktop_scene_pin_input_timer_callback(TimerHandle_t timer) {
|
||||
Desktop* desktop = pvTimerGetTimerID(timer);
|
||||
|
||||
view_dispatcher_send_custom_event(
|
||||
desktop->view_dispatcher, DesktopPinInputEventResetWrongPinLabel);
|
||||
}
|
||||
|
||||
void desktop_scene_pin_input_on_enter(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
|
||||
desktop_view_pin_input_set_context(desktop->pin_input_view, desktop);
|
||||
desktop_view_pin_input_set_back_callback(
|
||||
desktop->pin_input_view, desktop_scene_pin_input_back_callback);
|
||||
desktop_view_pin_input_set_timeout_callback(
|
||||
desktop->pin_input_view, desktop_scene_pin_input_back_callback);
|
||||
desktop_view_pin_input_set_done_callback(
|
||||
desktop->pin_input_view, desktop_scene_pin_input_done_callback);
|
||||
|
||||
DesktopScenePinInputState* state = furi_alloc(sizeof(DesktopScenePinInputState));
|
||||
state->timer =
|
||||
xTimerCreate(NULL, 10000, pdFALSE, desktop, desktop_scene_pin_input_timer_callback);
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopScenePinInput, (uint32_t)state);
|
||||
|
||||
desktop_view_pin_input_hide_pin(desktop->pin_input_view, true);
|
||||
desktop_view_pin_input_set_label_button(desktop->pin_input_view, "OK");
|
||||
desktop_view_pin_input_set_label_secondary(desktop->pin_input_view, 44, 25, "Enter PIN:");
|
||||
desktop_view_pin_input_set_pin_position(desktop->pin_input_view, 64, 37);
|
||||
desktop_view_pin_input_reset_pin(desktop->pin_input_view);
|
||||
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdPinInput);
|
||||
}
|
||||
|
||||
bool desktop_scene_pin_input_on_event(void* context, SceneManagerEvent event) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
bool consumed = false;
|
||||
uint32_t pin_fails = 0;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case DesktopPinInputEventUnlockFailed:
|
||||
pin_fails = furi_hal_rtc_get_pin_fails();
|
||||
pin_fails++;
|
||||
furi_hal_rtc_set_pin_fails(pin_fails);
|
||||
uint32_t pin_timeout = desktop_helpers_get_pin_fail_timeout(pin_fails);
|
||||
if(pin_timeout > 0) {
|
||||
desktop_helpers_emit_error_notification();
|
||||
scene_manager_set_scene_state(
|
||||
desktop->scene_manager, DesktopScenePinTimeout, pin_timeout);
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopScenePinTimeout);
|
||||
} else {
|
||||
desktop_scene_locked_light_red(true);
|
||||
desktop_view_pin_input_set_label_primary(desktop->pin_input_view, 0, 0, NULL);
|
||||
desktop_view_pin_input_set_label_secondary(
|
||||
desktop->pin_input_view, 25, 25, "Wrong PIN try again:");
|
||||
desktop_scene_pin_input_set_timer(desktop, true, WRONG_PIN_HEADER_TIMEOUT);
|
||||
desktop_view_pin_input_reset_pin(desktop->pin_input_view);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopPinInputEventResetWrongPinLabel:
|
||||
desktop_scene_locked_light_red(false);
|
||||
desktop_view_pin_input_set_label_primary(desktop->pin_input_view, 0, 0, NULL);
|
||||
desktop_view_pin_input_set_label_secondary(
|
||||
desktop->pin_input_view, 44, 25, "Enter PIN:");
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopPinInputEventUnlocked:
|
||||
desktop_view_locked_unlock(desktop->locked_view);
|
||||
furi_hal_rtc_set_pin_fails(0);
|
||||
desktop_helpers_unlock_system(desktop);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
desktop->scene_manager, DesktopSceneMain);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopPinInputEventBack:
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
desktop->scene_manager, DesktopSceneLocked);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void desktop_scene_pin_input_on_exit(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
desktop_scene_locked_light_red(false);
|
||||
|
||||
DesktopScenePinInputState* state = (DesktopScenePinInputState*)scene_manager_get_scene_state(
|
||||
desktop->scene_manager, DesktopScenePinInput);
|
||||
xTimerStop(state->timer, portMAX_DELAY);
|
||||
while(xTimerIsTimerActive(state->timer)) {
|
||||
delay(1);
|
||||
}
|
||||
xTimerDelete(state->timer, portMAX_DELAY);
|
||||
free(state);
|
||||
}
|
46
applications/desktop/scenes/desktop_scene_pin_timeout.c
Normal file
46
applications/desktop/scenes/desktop_scene_pin_timeout.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <furi.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <portmacro.h>
|
||||
#include <timer.h>
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
#include "../desktop_i.h"
|
||||
#include "../views/desktop_view_pin_timeout.h"
|
||||
#include "desktop_scene.h"
|
||||
#include "desktop_scene_i.h"
|
||||
|
||||
static void desktop_scene_pin_timeout_callback(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopPinTimeoutExit);
|
||||
}
|
||||
|
||||
void desktop_scene_pin_timeout_on_enter(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
|
||||
uint32_t timeout =
|
||||
scene_manager_get_scene_state(desktop->scene_manager, DesktopScenePinTimeout);
|
||||
desktop_view_pin_timeout_start(desktop->pin_timeout_view, timeout);
|
||||
desktop_view_pin_timeout_set_callback(
|
||||
desktop->pin_timeout_view, desktop_scene_pin_timeout_callback, desktop);
|
||||
|
||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdPinTimeout);
|
||||
}
|
||||
|
||||
bool desktop_scene_pin_timeout_on_event(void* context, SceneManagerEvent event) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case DesktopPinTimeoutExit:
|
||||
scene_manager_previous_scene(desktop->scene_manager);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void desktop_scene_pin_timeout_on_exit(void* context) {
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
#include "../desktop_i.h"
|
||||
|
||||
#define SCENE_EXIT_EVENT (0U)
|
||||
|
||||
void desktop_scene_ok_callback(void* context) {
|
||||
Desktop* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_EXIT_EVENT);
|
||||
}
|
||||
|
||||
void desktop_scene_pinsetup_on_enter(void* context) {
|
||||
Desktop* app = context;
|
||||
CodeInput* code_input = app->code_input;
|
||||
|
||||
code_input_set_result_callback(
|
||||
code_input,
|
||||
desktop_scene_ok_callback,
|
||||
NULL,
|
||||
app,
|
||||
app->settings.pincode.data,
|
||||
&app->settings.pincode.length,
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, DesktopViewPinSetup);
|
||||
}
|
||||
|
||||
bool desktop_scene_pinsetup_on_event(void* context, SceneManagerEvent event) {
|
||||
Desktop* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SCENE_EXIT_EVENT:
|
||||
scene_manager_previous_scene(app->scene_manager);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void desktop_scene_pinsetup_on_exit(void* context) {
|
||||
Desktop* app = context;
|
||||
SAVE_DESKTOP_SETTINGS(&app->settings);
|
||||
code_input_set_result_callback(app->code_input, NULL, NULL, NULL, NULL, NULL, 0);
|
||||
code_input_set_header_text(app->code_input, "");
|
||||
}
|
Reference in New Issue
Block a user