diff --git a/default_recovery_ui.c b/default_recovery_ui.c index 991f376..2c39a78 100644 --- a/default_recovery_ui.c +++ b/default_recovery_ui.c @@ -18,6 +18,7 @@ #include "recovery_ui.h" #include "common.h" +#include "extendedcommands.h" char* MENU_HEADERS[] = { "Android system recovery utility", "", @@ -36,7 +37,8 @@ int device_toggle_display(volatile char* key_pressed, int key_code) { int alt = key_pressed[KEY_LEFTALT] || key_pressed[KEY_RIGHTALT]; if (alt && key_code == KEY_L) return 1; - return key_code == KEY_HOME || key_code == KEY_MENU || key_code == KEY_POWER || key_code == KEY_END; + // allow toggling of the display if the correct key is pressed, and the display toggle is allowed or the display is currently off + return get_allow_toggle_display() && (key_code == KEY_HOME || key_code == KEY_MENU || key_code == KEY_POWER || key_code == KEY_END); } int device_reboot_now(volatile char* key_pressed, int key_code) { @@ -57,9 +59,12 @@ int device_handle_key(int key_code, int visible) { case KEY_ENTER: case BTN_MOUSE: return SELECT_ITEM; - case KEY_BACKSPACE: + + case KEY_POWER: case KEY_END: - return GO_BACK; + case KEY_BACKSPACE: + if (!get_allow_toggle_display()) + return GO_BACK; } } diff --git a/extendedcommands.h b/extendedcommands.h index a4d4992..2729de2 100644 --- a/extendedcommands.h +++ b/extendedcommands.h @@ -8,4 +8,10 @@ void toggle_script_asserts(); void -show_choose_zip_menu(); \ No newline at end of file +show_choose_zip_menu(); + +int +get_allow_toggle_display(); + +int +ui_get_show_menu(); \ No newline at end of file diff --git a/recovery.c b/recovery.c index 7a12e10..e398393 100644 --- a/recovery.c +++ b/recovery.c @@ -49,6 +49,8 @@ static const struct option OPTIONS[] = { { NULL, 0, NULL, 0 }, }; +static int allow_display_toggle = 1; + static const char *COMMAND_FILE = "CACHE:recovery/command"; static const char *INTENT_FILE = "CACHE:recovery/intent"; static const char *LOG_FILE = "CACHE:recovery/log"; @@ -313,7 +315,7 @@ get_menu_selection(char** headers, char** items, int menu_only) { int selected = 0; int chosen_item = -1; - while (chosen_item < 0) { + while (chosen_item < 0 && chosen_item != GO_BACK) { int key = ui_wait_key(); int visible = ui_text_visible(); @@ -335,7 +337,8 @@ get_menu_selection(char** headers, char** items, int menu_only) { case NO_ACTION: break; case GO_BACK: - return GO_BACK; + chosen_item = GO_BACK; + break; } } else if (!menu_only) { chosen_item = action; @@ -394,7 +397,9 @@ prompt_and_wait() finish_recovery(NULL); ui_reset_progress(); + allow_display_toggle = 1; int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0); + allow_display_toggle = 0; // device-specific code may take some action here. It may // return one of the core actions handled in the switch @@ -530,3 +535,7 @@ main(int argc, char **argv) reboot(RB_AUTOBOOT); return EXIT_SUCCESS; } + +int get_allow_toggle_display() { + return allow_display_toggle; +} \ No newline at end of file diff --git a/ui.c b/ui.c index 51df1fa..70ddc33 100644 --- a/ui.c +++ b/ui.c @@ -538,3 +538,7 @@ void ui_clear_key_queue() { key_queue_len = 0; pthread_mutex_unlock(&key_queue_mutex); } + +void ui_get_show_menu() { + return show_menu; +}