From 73164d6c32ab396f6b8b5647d85f272591ab1fb5 Mon Sep 17 00:00:00 2001 From: jbohack Date: Fri, 6 Jan 2023 23:51:29 -0500 Subject: [PATCH] boot loops & null dereference error fixed namechanger application was updated thanks to ESurge and application now works without issues :D --- applications/services/desktop/desktop.c | 98 +++++---- .../services/namechangersrv/namechangersrv.c | 205 +++++++++--------- 2 files changed, 162 insertions(+), 141 deletions(-) diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index 7cf4a2948..357b0e4b7 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -26,9 +26,10 @@ static void desktop_loader_callback(const void* message, void* context) { Desktop* desktop = context; const LoaderEvent* event = message; - if(event->type == LoaderEventTypeApplicationStarted) { + if (event->type == LoaderEventTypeApplicationStarted) { view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalBeforeAppStarted); - } else if(event->type == LoaderEventTypeApplicationStopped) { + } + else if (event->type == LoaderEventTypeApplicationStopped) { view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAfterAppFinished); } } @@ -48,7 +49,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) { furi_assert(context); Desktop* desktop = (Desktop*)context; - switch(event) { + switch (event) { case DesktopGlobalBeforeAppStarted: animation_manager_unload_and_stall_animation(desktop->animation_manager); desktop_auto_lock_inhibit(desktop); @@ -61,11 +62,12 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) { desktop_auto_lock_arm(desktop); return true; case DesktopGlobalAutoLock: - if(!loader_is_locked(desktop->loader)) { - if(desktop->settings.pin_code.length > 0) { + if (!loader_is_locked(desktop->loader)) { + if (desktop->settings.pin_code.length > 0) { desktop_pin_lock(&desktop->settings); desktop_lock(desktop); - } else { + } + else { desktop_lock(desktop); } } @@ -92,7 +94,7 @@ static void desktop_input_event_callback(const void* value, void* context) { furi_assert(context); const InputEvent* event = value; Desktop* desktop = context; - if(event->type == InputTypePress) { + if (event->type == InputTypePress) { desktop_start_auto_lock_timer(desktop); } } @@ -113,7 +115,7 @@ static void desktop_stop_auto_lock_timer(Desktop* desktop) { } static void desktop_auto_lock_arm(Desktop* desktop) { - if(desktop->settings.auto_lock_delay_ms) { + if (desktop->settings.auto_lock_delay_ms) { desktop->input_events_subscription = furi_pubsub_subscribe( desktop->input_events_pubsub, desktop_input_event_callback, desktop); desktop_start_auto_lock_timer(desktop); @@ -122,7 +124,7 @@ static void desktop_auto_lock_arm(Desktop* desktop) { static void desktop_auto_lock_inhibit(Desktop* desktop) { desktop_stop_auto_lock_timer(desktop); - if(desktop->input_events_subscription) { + if (desktop->input_events_subscription) { furi_pubsub_unsubscribe(desktop->input_events_pubsub, desktop->input_events_subscription); desktop->input_events_subscription = NULL; } @@ -151,7 +153,6 @@ void desktop_set_sfw_mode_state(Desktop* desktop, bool enabled) { desktop_main_set_sfw_mode_state(desktop->main_view, enabled); animation_manager_set_sfw_mode_state(desktop->animation_manager, enabled); desktop->settings.sfw_mode = enabled; - DESKTOP_SETTINGS_SAVE(&desktop->settings); } Desktop* desktop_alloc() { @@ -247,8 +248,8 @@ Desktop* desktop_alloc() { // Special case: autostart application is already running desktop->loader = furi_record_open(RECORD_LOADER); - if(loader_is_locked(desktop->loader) && - animation_manager_is_animation_loaded(desktop->animation_manager)) { + if (loader_is_locked(desktop->loader) && + animation_manager_is_animation_loaded(desktop->animation_manager)) { animation_manager_unload_and_stall_animation(desktop->animation_manager); } @@ -271,7 +272,7 @@ void desktop_free(Desktop* desktop) { furi_pubsub_unsubscribe( loader_get_pubsub(desktop->loader), desktop->app_start_stop_subscription); - if(desktop->input_events_subscription) { + if (desktop->input_events_subscription) { furi_pubsub_unsubscribe(desktop->input_events_pubsub, desktop->input_events_subscription); desktop->input_events_subscription = NULL; } @@ -326,45 +327,54 @@ static bool desktop_check_file_flag(const char* flag_path) { int32_t desktop_srv(void* p) { UNUSED(p); - Desktop* desktop = desktop_alloc(); - bool loaded = DESKTOP_SETTINGS_LOAD(&desktop->settings); - if(!loaded) { - memset(&desktop->settings, 0, sizeof(desktop->settings)); - DESKTOP_SETTINGS_SAVE(&desktop->settings); + if (furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) + { + FURI_LOG_W("Desktop", "Desktop load skipped. Device is in special startup mode."); } + else + { + Desktop* desktop = desktop_alloc(); - view_port_enabled_set(desktop->sfw_mode_icon_viewport, desktop->settings.sfw_mode); - desktop_main_set_sfw_mode_state(desktop->main_view, desktop->settings.sfw_mode); - animation_manager_set_sfw_mode_state( - desktop->animation_manager, desktop->settings.sfw_mode); - - scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain); - - desktop_pin_lock_init(&desktop->settings); - - if(!desktop_pin_lock_is_locked()) { - if(!loader_is_locked(desktop->loader)) { - desktop_auto_lock_arm(desktop); + bool loaded = DESKTOP_SETTINGS_LOAD(&desktop->settings); + if (!loaded) { + memset(&desktop->settings, 0, sizeof(desktop->settings)); + DESKTOP_SETTINGS_SAVE(&desktop->settings); } - } else { - desktop_lock(desktop); - } - if(desktop_check_file_flag(SLIDESHOW_FS_PATH)) { - scene_manager_next_scene(desktop->scene_manager, DesktopSceneSlideshow); - } + view_port_enabled_set(desktop->sfw_mode_icon_viewport, desktop->settings.sfw_mode); + desktop_main_set_sfw_mode_state(desktop->main_view, desktop->settings.sfw_mode); + animation_manager_set_sfw_mode_state( + desktop->animation_manager, desktop->settings.sfw_mode); - if(!furi_hal_version_do_i_belong_here()) { - scene_manager_next_scene(desktop->scene_manager, DesktopSceneHwMismatch); - } + scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain); - if(furi_hal_rtc_get_fault_data()) { - scene_manager_next_scene(desktop->scene_manager, DesktopSceneFault); - } + desktop_pin_lock_init(&desktop->settings); - view_dispatcher_run(desktop->view_dispatcher); - desktop_free(desktop); + if (!desktop_pin_lock_is_locked()) { + if (!loader_is_locked(desktop->loader)) { + desktop_auto_lock_arm(desktop); + } + } + else { + desktop_lock(desktop); + } + + if (desktop_check_file_flag(SLIDESHOW_FS_PATH)) { + scene_manager_next_scene(desktop->scene_manager, DesktopSceneSlideshow); + } + + if (!furi_hal_version_do_i_belong_here()) { + scene_manager_next_scene(desktop->scene_manager, DesktopSceneHwMismatch); + } + + if (furi_hal_rtc_get_fault_data()) { + scene_manager_next_scene(desktop->scene_manager, DesktopSceneFault); + } + + view_dispatcher_run(desktop->view_dispatcher); + desktop_free(desktop); + } return 0; } diff --git a/applications/services/namechangersrv/namechangersrv.c b/applications/services/namechangersrv/namechangersrv.c index 933882ce2..3e63c9120 100644 --- a/applications/services/namechangersrv/namechangersrv.c +++ b/applications/services/namechangersrv/namechangersrv.c @@ -4,157 +4,168 @@ #include void namechanger_on_system_start() { - Storage* storage = furi_record_open(RECORD_STORAGE); - FlipperFormat* file = flipper_format_file_alloc(storage); - - FuriString* NAMEHEADER; - NAMEHEADER = furi_string_alloc_set("Flipper Name File"); - - FuriString* filepath; - filepath = furi_string_alloc_set("/ext/dolphin/name.txt"); - - bool result = false; - - FuriString* data; - data = furi_string_alloc(); - - do { - if(!flipper_format_file_open_existing(file, furi_string_get_cstr(filepath))) { - break; - } - - // header - uint32_t version; - - if(!flipper_format_read_header(file, data, &version)) { - break; - } - - if(furi_string_cmp_str(data, furi_string_get_cstr(NAMEHEADER)) != 0) { - break; - } - - if(version != 1) { - break; - } - - // get Name - if(!flipper_format_read_string(file, "Name", data)) { - break; - } - - result = true; - } while(false); - - flipper_format_free(file); - - if(!result) { - //file not good - write new one + if (furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) + { + FURI_LOG_W(TAG, "NameChangerSRV load skipped. Device is in special startup mode."); + } + else + { + Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* file = flipper_format_file_alloc(storage); - bool res = false; + FuriString* NAMEHEADER; + NAMEHEADER = furi_string_alloc_set("Flipper Name File"); + + FuriString* filepath; + filepath = furi_string_alloc_set("/ext/dolphin/name.txt"); + + bool result = false; + + FuriString* data; + data = furi_string_alloc(); do { - // Open file for write - if(!flipper_format_file_open_always(file, furi_string_get_cstr(filepath))) { + if (!flipper_format_file_open_existing(file, furi_string_get_cstr(filepath))) { break; } - // Write header - if(!flipper_format_write_header_cstr(file, furi_string_get_cstr(NAMEHEADER), 1)) { + // header + uint32_t version; + + if (!flipper_format_read_header(file, data, &version)) { break; } - // Write comments - if(!flipper_format_write_comment_cstr( - file, "Changing the value below will change your FlipperZero device name.")) { + if (furi_string_cmp_str(data, furi_string_get_cstr(NAMEHEADER)) != 0) { break; } - if(!flipper_format_write_comment_cstr( - file, - "Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) { + if (version != 1) { break; } - if(!flipper_format_write_comment_cstr( - file, "It can contain other characters but use at your own risk.")) { + // get Name + if (!flipper_format_read_string(file, "Name", data)) { break; } - //Write name - if(!flipper_format_write_string_cstr(file, "Name", furi_hal_version_get_name_ptr())) { - break; - } - - res = true; - } while(false); + result = true; + } while (false); flipper_format_free(file); - if(!res) { - FURI_LOG_E(TAG, "Save failed."); - } - } else { - if(!furi_string_size(data)) { - //Empty file - get default name and write to file. + if (!result) { + //file not good - write new one FlipperFormat* file = flipper_format_file_alloc(storage); bool res = false; do { // Open file for write - if(!flipper_format_file_open_always(file, furi_string_get_cstr(filepath))) { + if (!flipper_format_file_open_always(file, furi_string_get_cstr(filepath))) { break; } // Write header - if(!flipper_format_write_header_cstr(file, furi_string_get_cstr(NAMEHEADER), 1)) { + if (!flipper_format_write_header_cstr(file, furi_string_get_cstr(NAMEHEADER), 1)) { break; } // Write comments - if(!flipper_format_write_comment_cstr( - file, - "Changing the value below will change your FlipperZero device name.")) { + if (!flipper_format_write_comment_cstr( + file, + "Changing the value below will change your FlipperZero device name.")) { break; } - if(!flipper_format_write_comment_cstr( - file, - "Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) { + if (!flipper_format_write_comment_cstr( + file, + "Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) { break; } - if(!flipper_format_write_comment_cstr( - file, "It cannot contain any other characters.")) { + if (!flipper_format_write_comment_cstr( + file, "It can contain other characters but use at your own risk.")) { break; } //Write name - if(!flipper_format_write_string_cstr( - file, "Name", furi_hal_version_get_name_ptr())) { + if (!flipper_format_write_string_cstr(file, "Name", furi_hal_version_get_name_ptr())) { break; } res = true; - } while(false); + } while (false); flipper_format_free(file); - if(!res) { + if (!res) { FURI_LOG_E(TAG, "Save failed."); } - } else { - char newdata[9]; - snprintf(newdata, 9, "%s", furi_string_get_cstr(data)); - //set name from file - furi_hal_version_set_custom_name(newdata); } + else { + if (!furi_string_size(data)) { + //Empty file - get default name and write to file. + FlipperFormat* file = flipper_format_file_alloc(storage); + + bool res = false; + + do { + // Open file for write + if (!flipper_format_file_open_always(file, furi_string_get_cstr(filepath))) { + break; + } + + // Write header + if (!flipper_format_write_header_cstr( + file, furi_string_get_cstr(NAMEHEADER), 1)) { + break; + } + + // Write comments + if (!flipper_format_write_comment_cstr( + file, + "Changing the value below will change your FlipperZero device name.")) { + break; + } + + if (!flipper_format_write_comment_cstr( + file, + "Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) { + break; + } + + if (!flipper_format_write_comment_cstr( + file, "It cannot contain any other characters.")) { + break; + } + + //Write name + if (!flipper_format_write_string_cstr( + file, "Name", furi_hal_version_get_name_ptr())) { + break; + } + + res = true; + } while (false); + + flipper_format_free(file); + + if (!res) { + FURI_LOG_E(TAG, "Save failed."); + } + } + else { + char newdata[9]; + snprintf(newdata, 9, "%s", furi_string_get_cstr(data)); + //set name from file + furi_hal_version_set_custom_name(newdata); + } + } + + furi_string_free(data); + + furi_string_free(filepath); + furi_record_close(RECORD_STORAGE); } - - furi_string_free(data); - - furi_string_free(filepath); - furi_record_close(RECORD_STORAGE); -} \ No newline at end of file +}