fix up back button and menu toggling

This commit is contained in:
Koushik K. Dutta 2010-02-19 14:17:22 -08:00
parent 841b2bf352
commit a3c2f735d7
4 changed files with 30 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -8,4 +8,10 @@ void
toggle_script_asserts();
void
show_choose_zip_menu();
show_choose_zip_menu();
int
get_allow_toggle_display();
int
ui_get_show_menu();

View File

@ -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;
}

4
ui.c
View File

@ -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;
}