diff options
author | Doug Zongker <dougz@android.com> | 2014-03-12 02:42:56 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-12 02:42:56 +0000 |
commit | aa6b8026ed5ae32f10b948edd26e3f489ba20751 (patch) | |
tree | 4bafa1a1b4266e561fb670a7d9277cf5394106f1 | |
parent | c15b7865badc3ac406a7ce978baa65151a50bb55 (diff) | |
parent | 5950899369b712f66aa56c857c66ed1b6741f0e0 (diff) | |
download | bootable_recovery-aa6b8026ed5ae32f10b948edd26e3f489ba20751.zip bootable_recovery-aa6b8026ed5ae32f10b948edd26e3f489ba20751.tar.gz bootable_recovery-aa6b8026ed5ae32f10b948edd26e3f489ba20751.tar.bz2 |
am 59508993: Merge "allow CheckKey to request mounting /system"
* commit '5950899369b712f66aa56c857c66ed1b6741f0e0':
allow CheckKey to request mounting /system
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | ui.cpp | 48 | ||||
-rw-r--r-- | ui.h | 6 |
3 files changed, 52 insertions, 3 deletions
@@ -89,6 +89,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := verifier_test LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_MODULE_TAGS := tests +LOCAL_CFLAGS += -DNO_RECOVERY_MOUNT LOCAL_SRC_FILES := \ verifier_test.cpp \ asn1_decoder.cpp \ @@ -31,6 +31,7 @@ #include <cutils/android_reboot.h> #include "common.h" +#include "roots.h" #include "device.h" #include "minui/minui.h" #include "screen_ui.h" @@ -47,7 +48,10 @@ RecoveryUI::RecoveryUI() : key_queue_len(0), key_last_down(-1), key_long_press(false), - key_down_count(0) { + key_down_count(0), + consecutive_power_keys(0), + consecutive_alternate_keys(0), + last_key(-1) { pthread_mutex_init(&key_queue_mutex, NULL); pthread_cond_init(&key_queue_cond, NULL); self = this; @@ -152,6 +156,13 @@ void RecoveryUI::process_key(int key_code, int updown) { case RecoveryUI::ENQUEUE: EnqueueKey(key_code); break; + + case RecoveryUI::MOUNT_SYSTEM: +#ifndef NO_RECOVERY_MOUNT + ensure_path_mounted("/system"); + Print("Mounted /system."); +#endif + break; } } } @@ -258,8 +269,41 @@ void RecoveryUI::FlushKeys() { pthread_mutex_unlock(&key_queue_mutex); } +// The default CheckKey implementation assumes the device has power, +// volume up, and volume down keys. +// +// - Hold power and press vol-up to toggle display. +// - Press power seven times in a row to reboot. +// - Alternate vol-up and vol-down seven times to mount /system. RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) { - return RecoveryUI::ENQUEUE; + if (IsKeyPressed(KEY_POWER) && key == KEY_VOLUMEUP) { + return TOGGLE; + } + + if (key == KEY_POWER) { + ++consecutive_power_keys; + if (consecutive_power_keys >= 7) { + return REBOOT; + } + } else { + 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; + + return ENQUEUE; } void RecoveryUI::NextCheckKeyIsLong(bool is_long_press) { @@ -79,7 +79,7 @@ class RecoveryUI { // Return value indicates whether an immediate operation should be // triggered (toggling the display, rebooting the device), or if // the key should be enqueued for use by the main thread. - enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE }; + enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE, MOUNT_SYSTEM }; virtual KeyAction CheckKey(int key); // Called immediately before each call to CheckKey(), tell you if @@ -123,6 +123,10 @@ private: int key_down_count; // under key_queue_mutex int rel_sum; + int consecutive_power_keys; + int consecutive_alternate_keys; + int last_key; + typedef struct { RecoveryUI* ui; int key_code; |