boot loops & null dereference error fixed

namechanger application was updated thanks to ESurge and application now works without issues :D
This commit is contained in:
jbohack
2023-01-06 23:51:29 -05:00
parent 76c8489797
commit 73164d6c32
2 changed files with 162 additions and 141 deletions

View File

@@ -26,9 +26,10 @@ static void desktop_loader_callback(const void* message, void* context) {
Desktop* desktop = context; Desktop* desktop = context;
const LoaderEvent* event = message; const LoaderEvent* event = message;
if(event->type == LoaderEventTypeApplicationStarted) { if (event->type == LoaderEventTypeApplicationStarted) {
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalBeforeAppStarted); 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); 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); furi_assert(context);
Desktop* desktop = (Desktop*)context; Desktop* desktop = (Desktop*)context;
switch(event) { switch (event) {
case DesktopGlobalBeforeAppStarted: case DesktopGlobalBeforeAppStarted:
animation_manager_unload_and_stall_animation(desktop->animation_manager); animation_manager_unload_and_stall_animation(desktop->animation_manager);
desktop_auto_lock_inhibit(desktop); 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); 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)) {
if(desktop->settings.pin_code.length > 0) { if (desktop->settings.pin_code.length > 0) {
desktop_pin_lock(&desktop->settings); desktop_pin_lock(&desktop->settings);
desktop_lock(desktop); desktop_lock(desktop);
} else { }
else {
desktop_lock(desktop); desktop_lock(desktop);
} }
} }
@@ -92,7 +94,7 @@ static void desktop_input_event_callback(const void* value, void* context) {
furi_assert(context); furi_assert(context);
const InputEvent* event = value; const InputEvent* event = value;
Desktop* desktop = context; Desktop* desktop = context;
if(event->type == InputTypePress) { if (event->type == InputTypePress) {
desktop_start_auto_lock_timer(desktop); 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) { 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_subscription = furi_pubsub_subscribe(
desktop->input_events_pubsub, desktop_input_event_callback, desktop); desktop->input_events_pubsub, desktop_input_event_callback, desktop);
desktop_start_auto_lock_timer(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) { static void desktop_auto_lock_inhibit(Desktop* desktop) {
desktop_stop_auto_lock_timer(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); furi_pubsub_unsubscribe(desktop->input_events_pubsub, desktop->input_events_subscription);
desktop->input_events_subscription = NULL; 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); desktop_main_set_sfw_mode_state(desktop->main_view, enabled);
animation_manager_set_sfw_mode_state(desktop->animation_manager, enabled); animation_manager_set_sfw_mode_state(desktop->animation_manager, enabled);
desktop->settings.sfw_mode = enabled; desktop->settings.sfw_mode = enabled;
DESKTOP_SETTINGS_SAVE(&desktop->settings);
} }
Desktop* desktop_alloc() { Desktop* desktop_alloc() {
@@ -247,8 +248,8 @@ Desktop* desktop_alloc() {
// Special case: autostart application is already running // Special case: autostart application is already running
desktop->loader = furi_record_open(RECORD_LOADER); desktop->loader = furi_record_open(RECORD_LOADER);
if(loader_is_locked(desktop->loader) && if (loader_is_locked(desktop->loader) &&
animation_manager_is_animation_loaded(desktop->animation_manager)) { animation_manager_is_animation_loaded(desktop->animation_manager)) {
animation_manager_unload_and_stall_animation(desktop->animation_manager); animation_manager_unload_and_stall_animation(desktop->animation_manager);
} }
@@ -271,7 +272,7 @@ void desktop_free(Desktop* desktop) {
furi_pubsub_unsubscribe( furi_pubsub_unsubscribe(
loader_get_pubsub(desktop->loader), desktop->app_start_stop_subscription); 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); furi_pubsub_unsubscribe(desktop->input_events_pubsub, desktop->input_events_subscription);
desktop->input_events_subscription = NULL; 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) { int32_t desktop_srv(void* p) {
UNUSED(p); UNUSED(p);
Desktop* desktop = desktop_alloc();
bool loaded = DESKTOP_SETTINGS_LOAD(&desktop->settings); if (furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal)
if(!loaded) { {
memset(&desktop->settings, 0, sizeof(desktop->settings)); FURI_LOG_W("Desktop", "Desktop load skipped. Device is in special startup mode.");
DESKTOP_SETTINGS_SAVE(&desktop->settings);
} }
else
{
Desktop* desktop = desktop_alloc();
view_port_enabled_set(desktop->sfw_mode_icon_viewport, desktop->settings.sfw_mode); bool loaded = DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_main_set_sfw_mode_state(desktop->main_view, desktop->settings.sfw_mode); if (!loaded) {
animation_manager_set_sfw_mode_state( memset(&desktop->settings, 0, sizeof(desktop->settings));
desktop->animation_manager, desktop->settings.sfw_mode); DESKTOP_SETTINGS_SAVE(&desktop->settings);
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);
} }
} else {
desktop_lock(desktop);
}
if(desktop_check_file_flag(SLIDESHOW_FS_PATH)) { view_port_enabled_set(desktop->sfw_mode_icon_viewport, desktop->settings.sfw_mode);
scene_manager_next_scene(desktop->scene_manager, DesktopSceneSlideshow); 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, DesktopSceneMain);
scene_manager_next_scene(desktop->scene_manager, DesktopSceneHwMismatch);
}
if(furi_hal_rtc_get_fault_data()) { desktop_pin_lock_init(&desktop->settings);
scene_manager_next_scene(desktop->scene_manager, DesktopSceneFault);
}
view_dispatcher_run(desktop->view_dispatcher); if (!desktop_pin_lock_is_locked()) {
desktop_free(desktop); 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; return 0;
} }

View File

@@ -4,157 +4,168 @@
#include <flipper_format/flipper_format.h> #include <flipper_format/flipper_format.h>
void namechanger_on_system_start() { void namechanger_on_system_start() {
Storage* storage = furi_record_open(RECORD_STORAGE); if (furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal)
FlipperFormat* file = flipper_format_file_alloc(storage); {
FURI_LOG_W(TAG, "NameChangerSRV load skipped. Device is in special startup mode.");
FuriString* NAMEHEADER; }
NAMEHEADER = furi_string_alloc_set("Flipper Name File"); else
{
FuriString* filepath; Storage* storage = furi_record_open(RECORD_STORAGE);
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
FlipperFormat* file = flipper_format_file_alloc(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 { do {
// Open file for write if (!flipper_format_file_open_existing(file, furi_string_get_cstr(filepath))) {
if(!flipper_format_file_open_always(file, furi_string_get_cstr(filepath))) {
break; break;
} }
// Write header // header
if(!flipper_format_write_header_cstr(file, furi_string_get_cstr(NAMEHEADER), 1)) { uint32_t version;
if (!flipper_format_read_header(file, data, &version)) {
break; break;
} }
// Write comments if (furi_string_cmp_str(data, furi_string_get_cstr(NAMEHEADER)) != 0) {
if(!flipper_format_write_comment_cstr(
file, "Changing the value below will change your FlipperZero device name.")) {
break; break;
} }
if(!flipper_format_write_comment_cstr( if (version != 1) {
file,
"Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) {
break; break;
} }
if(!flipper_format_write_comment_cstr( // get Name
file, "It can contain other characters but use at your own risk.")) { if (!flipper_format_read_string(file, "Name", data)) {
break; break;
} }
//Write name result = true;
if(!flipper_format_write_string_cstr(file, "Name", furi_hal_version_get_name_ptr())) { } while (false);
break;
}
res = true;
} while(false);
flipper_format_free(file); flipper_format_free(file);
if(!res) { if (!result) {
FURI_LOG_E(TAG, "Save failed."); //file not good - write new one
}
} else {
if(!furi_string_size(data)) {
//Empty file - get default name and write to file.
FlipperFormat* file = flipper_format_file_alloc(storage); FlipperFormat* file = flipper_format_file_alloc(storage);
bool res = false; bool res = false;
do { do {
// Open file for write // 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; break;
} }
// Write header // 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; break;
} }
// Write comments // Write comments
if(!flipper_format_write_comment_cstr( if (!flipper_format_write_comment_cstr(
file, file,
"Changing the value below will change your FlipperZero device name.")) { "Changing the value below will change your FlipperZero device name.")) {
break; break;
} }
if(!flipper_format_write_comment_cstr( if (!flipper_format_write_comment_cstr(
file, file,
"Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) { "Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) {
break; break;
} }
if(!flipper_format_write_comment_cstr( if (!flipper_format_write_comment_cstr(
file, "It cannot contain any other characters.")) { file, "It can contain other characters but use at your own risk.")) {
break; break;
} }
//Write name //Write name
if(!flipper_format_write_string_cstr( if (!flipper_format_write_string_cstr(file, "Name", furi_hal_version_get_name_ptr())) {
file, "Name", furi_hal_version_get_name_ptr())) {
break; break;
} }
res = true; res = true;
} while(false); } while (false);
flipper_format_free(file); flipper_format_free(file);
if(!res) { if (!res) {
FURI_LOG_E(TAG, "Save failed."); 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);
}