mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
Don't use semaphores for lock state tracking
This commit is contained in:
@@ -417,7 +417,7 @@ void desktop_unlock(Desktop* desktop) {
|
||||
|
||||
view_port_enabled_set(desktop->lock_icon_viewport, false);
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
gui_remove_lockdown(gui);
|
||||
gui_set_lockdown(gui, false);
|
||||
furi_record_close(RECORD_GUI);
|
||||
desktop_view_locked_unlock(desktop->locked_view);
|
||||
scene_manager_search_and_switch_to_previous_scene(desktop->scene_manager, DesktopSceneMain);
|
||||
|
||||
@@ -45,7 +45,7 @@ void desktop_scene_locked_on_enter(void* context) {
|
||||
if(state == DesktopSceneLockedStateFirstEnter) {
|
||||
view_port_enabled_set(desktop->lock_icon_viewport, true);
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
gui_set_lockdown(gui);
|
||||
gui_set_lockdown(gui, true);
|
||||
furi_record_close(RECORD_GUI);
|
||||
|
||||
if(desktop_pin_code_is_set()) {
|
||||
|
||||
@@ -484,33 +484,32 @@ size_t gui_get_framebuffer_size(const Gui* gui) {
|
||||
return canvas_get_buffer_size(gui->canvas);
|
||||
}
|
||||
|
||||
void gui_set_lockdown(Gui* gui) {
|
||||
void gui_set_lockdown(Gui* gui, bool lockdown) {
|
||||
furi_check(gui);
|
||||
|
||||
gui_lock(gui);
|
||||
FURI_LOG_D(TAG, "Releasing lockdown semaphore");
|
||||
furi_semaphore_release(gui->unlock);
|
||||
gui->lockdown = lockdown;
|
||||
gui_unlock(gui);
|
||||
|
||||
// Request redraw
|
||||
gui_update(gui);
|
||||
}
|
||||
|
||||
void gui_remove_lockdown(Gui* gui) {
|
||||
void gui_set_lockdown_inhibit(Gui* gui, bool inhibit) {
|
||||
furi_check(gui);
|
||||
FURI_LOG_D(TAG, "Acquiring lockdown semaphore");
|
||||
|
||||
gui_lock(gui);
|
||||
if(furi_semaphore_acquire(gui->unlock, 1000) != FuriStatusOk) {
|
||||
furi_crash("Could not acquire lockdown semaphore");
|
||||
}
|
||||
gui->lockdown_inhibit = inhibit;
|
||||
gui_unlock(gui);
|
||||
|
||||
// Request redraw
|
||||
gui_update(gui);
|
||||
}
|
||||
|
||||
bool gui_is_lockdown(const Gui* gui) {
|
||||
furi_check(gui);
|
||||
|
||||
return furi_semaphore_get_count(gui->unlock) == 0;
|
||||
return gui->lockdown && !gui->lockdown_inhibit;
|
||||
}
|
||||
|
||||
Canvas* gui_direct_draw_acquire(Gui* gui) {
|
||||
@@ -547,8 +546,6 @@ Gui* gui_alloc(void) {
|
||||
gui->thread_id = furi_thread_get_current_id();
|
||||
// Allocate mutex
|
||||
gui->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
// Semaphore for the lockdown state
|
||||
gui->unlock = furi_semaphore_alloc(2, 1);
|
||||
|
||||
// Layers
|
||||
for(size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
|
||||
@@ -106,14 +106,19 @@ size_t gui_get_framebuffer_size(const Gui* gui);
|
||||
* This feature prevents services from showing sensitive information when flipper is locked.
|
||||
*
|
||||
* @param gui Gui instance
|
||||
* @param lockdown true to enable lockdown mode
|
||||
*/
|
||||
void gui_set_lockdown(Gui* gui);
|
||||
void gui_set_lockdown(Gui* gui, bool lockdown);
|
||||
|
||||
/** Disable lockdown mode
|
||||
*
|
||||
/** Inhibit lockdown mode
|
||||
*
|
||||
* Lockdown mode can be inhibited by calling this function with inhibit set to true.
|
||||
* This is used to show information even when flipper is locked.
|
||||
*
|
||||
* @param gui Gui instance
|
||||
* @param inhibit true to inhibit lockdown mode
|
||||
*/
|
||||
void gui_remove_lockdown(Gui* gui);
|
||||
void gui_set_lockdown_inhibit(Gui* gui, bool inhibit);
|
||||
|
||||
/** Check if Gui is in lockdown mode
|
||||
*
|
||||
|
||||
@@ -48,9 +48,10 @@ struct Gui {
|
||||
// Thread and lock
|
||||
FuriThreadId thread_id;
|
||||
FuriMutex* mutex;
|
||||
FuriSemaphore* unlock;
|
||||
|
||||
// Layers and Canvas
|
||||
bool lockdown;
|
||||
bool lockdown_inhibit;
|
||||
bool direct_draw;
|
||||
ViewPortArray_t layers[GuiLayerMAX];
|
||||
Canvas* canvas;
|
||||
|
||||
@@ -112,7 +112,7 @@ int32_t clock_settings_alarm(void* p) {
|
||||
|
||||
// Register view port in GUI
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
gui_remove_lockdown(gui);
|
||||
gui_set_lockdown_inhibit(gui, true);
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
@@ -139,7 +139,7 @@ int32_t clock_settings_alarm(void* p) {
|
||||
model.is_snooze = true;
|
||||
model.alarm_start = model.snooze_until; // For correct timeout behavior
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_set_lockdown(gui);
|
||||
gui_set_lockdown_inhibit(gui, false);
|
||||
} else {
|
||||
running = false;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ int32_t clock_settings_alarm(void* p) {
|
||||
if(datetime_datetime_to_timestamp(&model.now) >=
|
||||
datetime_datetime_to_timestamp(&model.snooze_until)) {
|
||||
view_port_enabled_set(view_port, true);
|
||||
gui_remove_lockdown(gui);
|
||||
gui_set_lockdown_inhibit(gui, true);
|
||||
|
||||
model.is_snooze = false;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ int32_t clock_settings_alarm(void* p) {
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_set_lockdown(gui);
|
||||
gui_set_lockdown_inhibit(gui, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
view_port_free(view_port);
|
||||
furi_message_queue_free(event_queue);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
entry,status,name,type,params
|
||||
Version,+,79.2,,
|
||||
Version,+,80.0,,
|
||||
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
|
||||
@@ -1957,9 +1957,9 @@ Function,+,gui_direct_draw_release,void,Gui*
|
||||
Function,+,gui_get_framebuffer_size,size_t,const Gui*
|
||||
Function,+,gui_is_lockdown,_Bool,const Gui*
|
||||
Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*"
|
||||
Function,+,gui_remove_lockdown,void,Gui*
|
||||
Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_set_lockdown,void,Gui*
|
||||
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
||||
Function,+,gui_set_lockdown_inhibit,void,"Gui*, _Bool"
|
||||
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
||||
Function,-,hci_send_req,int,"hci_request*, uint8_t"
|
||||
@@ -2940,9 +2940,9 @@ Function,+,pipe_install_as_stdio,void,PipeSide*
|
||||
Function,+,pipe_receive,size_t,"PipeSide*, void*, size_t, FuriWait"
|
||||
Function,+,pipe_role,PipeRole,PipeSide*
|
||||
Function,+,pipe_send,size_t,"PipeSide*, const void*, size_t, FuriWait"
|
||||
Function,+,pipe_set_broken_callback,void,"PipeSide*, PipeSideBrokenCallback, FuriEventLoopEvent"
|
||||
Function,+,pipe_set_callback_context,void,"PipeSide*, void*"
|
||||
Function,+,pipe_set_data_arrived_callback,void,"PipeSide*, PipeSideDataArrivedCallback, FuriEventLoopEvent"
|
||||
Function,+,pipe_set_broken_callback,void,"PipeSide*, PipeSideBrokenCallback, FuriEventLoopEvent"
|
||||
Function,+,pipe_set_space_freed_callback,void,"PipeSide*, PipeSideSpaceFreedCallback, FuriEventLoopEvent"
|
||||
Function,+,pipe_spaces_available,size_t,PipeSide*
|
||||
Function,+,pipe_state,PipeState,PipeSide*
|
||||
|
||||
|
Reference in New Issue
Block a user