Move "Mount /system" to the main menu.

Everyone's adding secret key combinations for this anyway, and it's
very useful when debugging.

Change-Id: Iad549452b872a7af963dd649f283ebcd3ea24234
This commit is contained in:
Elliott Hughes 2015-04-10 10:01:53 -07:00
parent 18eaa0cfe7
commit ec28340cf3
6 changed files with 42 additions and 55 deletions

View file

@ -107,7 +107,6 @@ include $(CLEAR_VARS)
LOCAL_MODULE := verifier_test LOCAL_MODULE := verifier_test
LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_TAGS := tests LOCAL_MODULE_TAGS := tests
LOCAL_CFLAGS += -DNO_RECOVERY_MOUNT
LOCAL_CFLAGS += -Wno-unused-parameter LOCAL_CFLAGS += -Wno-unused-parameter
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
verifier_test.cpp \ verifier_test.cpp \

View file

@ -31,6 +31,7 @@ static const char* ITEMS[] = {
"Apply update from SD card", "Apply update from SD card",
"Wipe data/factory reset", "Wipe data/factory reset",
"Wipe cache partition", "Wipe cache partition",
"Mount /system",
"View recovery logs", "View recovery logs",
"Power off", "Power off",
NULL NULL
@ -44,11 +45,12 @@ Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
case 0: return REBOOT; case 0: return REBOOT;
case 1: return REBOOT_BOOTLOADER; case 1: return REBOOT_BOOTLOADER;
case 2: return APPLY_ADB_SIDELOAD; case 2: return APPLY_ADB_SIDELOAD;
case 3: return APPLY_EXT; case 3: return APPLY_SDCARD;
case 4: return WIPE_DATA; case 4: return WIPE_DATA;
case 5: return WIPE_CACHE; case 5: return WIPE_CACHE;
case 6: return READ_RECOVERY_LASTLOG; case 6: return MOUNT_SYSTEM;
case 7: return SHUTDOWN; case 7: return VIEW_RECOVERY_LOGS;
case 8: return SHUTDOWN;
default: return NO_ACTION; default: return NO_ACTION;
} }
} }

View file

@ -56,10 +56,19 @@ class Device {
// - invoke a specific action (a menu position: any non-negative number) // - invoke a specific action (a menu position: any non-negative number)
virtual int HandleMenuKey(int key, int visible) = 0; virtual int HandleMenuKey(int key, int visible) = 0;
enum BuiltinAction { NO_ACTION, REBOOT, APPLY_EXT, enum BuiltinAction {
APPLY_CACHE, // APPLY_CACHE is deprecated; has no effect NO_ACTION = 0,
APPLY_ADB_SIDELOAD, WIPE_DATA, WIPE_CACHE, REBOOT = 1,
REBOOT_BOOTLOADER, SHUTDOWN, READ_RECOVERY_LASTLOG }; APPLY_SDCARD = 2,
// APPLY_CACHE was 3.
APPLY_ADB_SIDELOAD = 4,
WIPE_DATA = 5,
WIPE_CACHE = 6,
REBOOT_BOOTLOADER = 7,
SHUTDOWN = 8,
VIEW_RECOVERY_LOGS = 9,
MOUNT_SYSTEM = 10,
};
// Return the headers (an array of strings, one per line, // Return the headers (an array of strings, one per line,
// NULL-terminated) for the main menu. Typically these tell users // NULL-terminated) for the main menu. Typically these tell users

View file

@ -840,7 +840,7 @@ prompt_and_wait(Device* device, int status) {
break; break;
case Device::APPLY_ADB_SIDELOAD: case Device::APPLY_ADB_SIDELOAD:
case Device::APPLY_EXT: case Device::APPLY_SDCARD:
{ {
bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD); bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD);
if (adb) { if (adb) {
@ -867,12 +867,14 @@ prompt_and_wait(Device* device, int status) {
} }
break; break;
case Device::APPLY_CACHE: case Device::VIEW_RECOVERY_LOGS:
ui->Print("\nAPPLY_CACHE is deprecated.\n"); choose_recovery_file(device);
break; break;
case Device::READ_RECOVERY_LASTLOG: case Device::MOUNT_SYSTEM:
choose_recovery_file(device); if (ensure_path_mounted("/system") != -1) {
ui->Print("Mounted /system.");
}
break; break;
} }
} }

44
ui.cpp
View file

@ -44,14 +44,13 @@
// so use a global variable. // so use a global variable.
static RecoveryUI* self = NULL; static RecoveryUI* self = NULL;
RecoveryUI::RecoveryUI() : RecoveryUI::RecoveryUI()
key_queue_len(0), : key_queue_len(0),
key_last_down(-1), key_last_down(-1),
key_long_press(false), key_long_press(false),
key_down_count(0), key_down_count(0),
enable_reboot(true), enable_reboot(true),
consecutive_power_keys(0), consecutive_power_keys(0),
consecutive_alternate_keys(0),
last_key(-1) { last_key(-1) {
pthread_mutex_init(&key_queue_mutex, NULL); pthread_mutex_init(&key_queue_mutex, NULL);
pthread_cond_init(&key_queue_cond, NULL); pthread_cond_init(&key_queue_cond, NULL);
@ -65,8 +64,7 @@ void RecoveryUI::Init() {
} }
int RecoveryUI::input_callback(int fd, uint32_t epevents, void* data) int RecoveryUI::input_callback(int fd, uint32_t epevents, void* data) {
{
struct input_event ev; struct input_event ev;
int ret; int ret;
@ -162,13 +160,6 @@ void RecoveryUI::process_key(int key_code, int updown) {
case RecoveryUI::ENQUEUE: case RecoveryUI::ENQUEUE:
EnqueueKey(key_code); EnqueueKey(key_code);
break; break;
case RecoveryUI::MOUNT_SYSTEM:
#ifndef NO_RECOVERY_MOUNT
ensure_path_mounted("/system");
Print("Mounted /system.");
#endif
break;
} }
} }
} }
@ -203,17 +194,16 @@ void RecoveryUI::EnqueueKey(int key_code) {
// Reads input events, handles special hot keys, and adds to the key queue. // Reads input events, handles special hot keys, and adds to the key queue.
void* RecoveryUI::input_thread(void *cookie) void* RecoveryUI::input_thread(void* cookie) {
{ while (true) {
for (;;) { if (!ev_wait(-1)) {
if (!ev_wait(-1))
ev_dispatch(); ev_dispatch();
} }
}
return NULL; return NULL;
} }
int RecoveryUI::WaitKey() int RecoveryUI::WaitKey() {
{
pthread_mutex_lock(&key_queue_mutex); pthread_mutex_lock(&key_queue_mutex);
// Time out after UI_WAIT_KEY_TIMEOUT_SEC, unless a USB cable is // Time out after UI_WAIT_KEY_TIMEOUT_SEC, unless a USB cable is
@ -228,8 +218,7 @@ int RecoveryUI::WaitKey()
int rc = 0; int rc = 0;
while (key_queue_len == 0 && rc != ETIMEDOUT) { while (key_queue_len == 0 && rc != ETIMEDOUT) {
rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex, rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex, &timeout);
&timeout);
} }
} while (usb_connected() && key_queue_len == 0); } while (usb_connected() && key_queue_len == 0);
@ -261,8 +250,7 @@ bool RecoveryUI::usb_connected() {
return connected; return connected;
} }
bool RecoveryUI::IsKeyPressed(int key) bool RecoveryUI::IsKeyPressed(int key) {
{
pthread_mutex_lock(&key_queue_mutex); pthread_mutex_lock(&key_queue_mutex);
int pressed = key_pressed[key]; int pressed = key_pressed[key];
pthread_mutex_unlock(&key_queue_mutex); pthread_mutex_unlock(&key_queue_mutex);
@ -301,18 +289,6 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) {
consecutive_power_keys = 0; consecutive_power_keys = 0;
} }
if ((key == KEY_VOLUMEUP &&
(last_key == KEY_VOLUMEDOWN || last_key == -1)) ||
(key == KEY_VOLUMEDOWN &&
(last_key == KEY_VOLUMEUP || last_key == -1))) {
++consecutive_alternate_keys;
if (consecutive_alternate_keys >= 7) {
consecutive_alternate_keys = 0;
return MOUNT_SYSTEM;
}
} else {
consecutive_alternate_keys = 0;
}
last_key = key; last_key = key;
return ENQUEUE; return ENQUEUE;

3
ui.h
View file

@ -81,7 +81,7 @@ class RecoveryUI {
// Return value indicates whether an immediate operation should be // Return value indicates whether an immediate operation should be
// triggered (toggling the display, rebooting the device), or if // triggered (toggling the display, rebooting the device), or if
// the key should be enqueued for use by the main thread. // the key should be enqueued for use by the main thread.
enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE, MOUNT_SYSTEM }; enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE };
virtual KeyAction CheckKey(int key); virtual KeyAction CheckKey(int key);
// Called immediately before each call to CheckKey(), tell you if // Called immediately before each call to CheckKey(), tell you if
@ -134,7 +134,6 @@ private:
int rel_sum; int rel_sum;
int consecutive_power_keys; int consecutive_power_keys;
int consecutive_alternate_keys;
int last_key; int last_key;
typedef struct { typedef struct {