mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 12:51:22 +04:00
Desktop: fix crash on autolock after restart in locked state (#3643)
* Desktop: fix crash on autolock after restart in locked state * Desktop: switch to clock model to fix condition race in desktop lock.
This commit is contained in:
@@ -61,11 +61,11 @@ static void desktop_clock_update(Desktop* desktop) {
|
|||||||
furi_hal_rtc_get_datetime(&curr_dt);
|
furi_hal_rtc_get_datetime(&curr_dt);
|
||||||
bool time_format_12 = locale_get_time_format() == LocaleTimeFormat12h;
|
bool time_format_12 = locale_get_time_format() == LocaleTimeFormat12h;
|
||||||
|
|
||||||
if(desktop->time_hour != curr_dt.hour || desktop->time_minute != curr_dt.minute ||
|
if(desktop->clock.hour != curr_dt.hour || desktop->clock.minute != curr_dt.minute ||
|
||||||
desktop->time_format_12 != time_format_12) {
|
desktop->clock.format_12 != time_format_12) {
|
||||||
desktop->time_format_12 = time_format_12;
|
desktop->clock.format_12 = time_format_12;
|
||||||
desktop->time_hour = curr_dt.hour;
|
desktop->clock.hour = curr_dt.hour;
|
||||||
desktop->time_minute = curr_dt.minute;
|
desktop->clock.minute = curr_dt.minute;
|
||||||
view_port_update(desktop->clock_viewport);
|
view_port_update(desktop->clock_viewport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,8 +92,8 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) {
|
|||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
|
||||||
uint8_t hour = desktop->time_hour;
|
uint8_t hour = desktop->clock.hour;
|
||||||
if(desktop->time_format_12) {
|
if(desktop->clock.format_12) {
|
||||||
if(hour > 12) {
|
if(hour > 12) {
|
||||||
hour -= 12;
|
hour -= 12;
|
||||||
}
|
}
|
||||||
@@ -103,11 +103,11 @@ static void desktop_clock_draw_callback(Canvas* canvas, void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
snprintf(buffer, sizeof(buffer), "%02u:%02u", hour, desktop->time_minute);
|
snprintf(buffer, sizeof(buffer), "%02u:%02u", hour, desktop->clock.minute);
|
||||||
|
|
||||||
view_port_set_width(
|
view_port_set_width(
|
||||||
desktop->clock_viewport,
|
desktop->clock_viewport,
|
||||||
canvas_string_width(canvas, buffer) - 1 + (desktop->time_minute % 10 == 1));
|
canvas_string_width(canvas, buffer) - 1 + (desktop->clock.minute % 10 == 1));
|
||||||
|
|
||||||
canvas_draw_str_aligned(canvas, 0, 8, AlignLeft, AlignBottom, buffer);
|
canvas_draw_str_aligned(canvas, 0, 8, AlignLeft, AlignBottom, buffer);
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
|||||||
desktop_auto_lock_arm(desktop);
|
desktop_auto_lock_arm(desktop);
|
||||||
return true;
|
return true;
|
||||||
case DesktopGlobalAutoLock:
|
case DesktopGlobalAutoLock:
|
||||||
if(!loader_is_locked(desktop->loader)) {
|
if(!loader_is_locked(desktop->loader) && !desktop->locked) {
|
||||||
desktop_lock(desktop);
|
desktop_lock(desktop);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -215,6 +215,8 @@ static void desktop_clock_timer_callback(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void desktop_lock(Desktop* desktop) {
|
void desktop_lock(Desktop* desktop) {
|
||||||
|
furi_assert(!desktop->locked);
|
||||||
|
|
||||||
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
||||||
|
|
||||||
if(desktop->settings.pin_code.length) {
|
if(desktop->settings.pin_code.length) {
|
||||||
@@ -230,9 +232,13 @@ void desktop_lock(Desktop* desktop) {
|
|||||||
|
|
||||||
DesktopStatus status = {.locked = true};
|
DesktopStatus status = {.locked = true};
|
||||||
furi_pubsub_publish(desktop->status_pubsub, &status);
|
furi_pubsub_publish(desktop->status_pubsub, &status);
|
||||||
|
|
||||||
|
desktop->locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void desktop_unlock(Desktop* desktop) {
|
void desktop_unlock(Desktop* desktop) {
|
||||||
|
furi_assert(desktop->locked);
|
||||||
|
|
||||||
view_port_enabled_set(desktop->lock_icon_viewport, false);
|
view_port_enabled_set(desktop->lock_icon_viewport, false);
|
||||||
Gui* gui = furi_record_open(RECORD_GUI);
|
Gui* gui = furi_record_open(RECORD_GUI);
|
||||||
gui_set_lockdown(gui, false);
|
gui_set_lockdown(gui, false);
|
||||||
@@ -251,6 +257,8 @@ void desktop_unlock(Desktop* desktop) {
|
|||||||
|
|
||||||
DesktopStatus status = {.locked = false};
|
DesktopStatus status = {.locked = false};
|
||||||
furi_pubsub_publish(desktop->status_pubsub, &status);
|
furi_pubsub_publish(desktop->status_pubsub, &status);
|
||||||
|
|
||||||
|
desktop->locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void desktop_set_dummy_mode_state(Desktop* desktop, bool enabled) {
|
void desktop_set_dummy_mode_state(Desktop* desktop, bool enabled) {
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ typedef enum {
|
|||||||
DesktopViewIdTotal,
|
DesktopViewIdTotal,
|
||||||
} DesktopViewId;
|
} DesktopViewId;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t hour;
|
||||||
|
uint8_t minute;
|
||||||
|
bool format_12; // 1 - 12 hour, 0 - 24H
|
||||||
|
} DesktopClock;
|
||||||
|
|
||||||
struct Desktop {
|
struct Desktop {
|
||||||
// Scene
|
// Scene
|
||||||
FuriThread* scene_thread;
|
FuriThread* scene_thread;
|
||||||
@@ -75,11 +81,10 @@ struct Desktop {
|
|||||||
|
|
||||||
FuriPubSub* status_pubsub;
|
FuriPubSub* status_pubsub;
|
||||||
|
|
||||||
uint8_t time_hour;
|
DesktopClock clock;
|
||||||
uint8_t time_minute;
|
|
||||||
bool time_format_12 : 1; // 1 - 12 hour, 0 - 24H
|
|
||||||
|
|
||||||
bool in_transition : 1;
|
bool in_transition : 1;
|
||||||
|
bool locked : 1;
|
||||||
|
|
||||||
FuriSemaphore* animation_semaphore;
|
FuriSemaphore* animation_semaphore;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user