From 9e805d6ca0101f6bfc458e5c1e9b48fecb495a72 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 4 Sep 2013 13:44:38 -0700 Subject: allow CheckKey to request mounting /system Also provide a default implementation of CheckKey that's reasonable for many devices (those that have power and volume keys). Change-Id: Icf6c7746ebd866152d402059dbd27fd16bd51ff8 --- ui.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index cece02d31..5043ee528 100644 --- a/ui.cpp +++ b/ui.cpp @@ -31,6 +31,7 @@ #include #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) { -- cgit v1.2.3 From e7265df3523d27c9f59829c858de256cf063da26 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Tue, 10 Sep 2013 16:53:12 -0700 Subject: recovery: ui changes for ev_*() switch to epoll Convert callback events parameter to unsigned int. Change-Id: Ife0e983f307c07bf4aca807d70574aeb20c460cd --- ui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index 5043ee528..08c291ddc 100644 --- a/ui.cpp +++ b/ui.cpp @@ -63,12 +63,12 @@ void RecoveryUI::Init() { } -int RecoveryUI::input_callback(int fd, short revents, void* data) +int RecoveryUI::input_callback(int fd, unsigned int epevents, void* data) { struct input_event ev; int ret; - ret = ev_get_input(fd, revents, &ev); + ret = ev_get_input(fd, epevents, &ev); if (ret) return -1; -- cgit v1.2.3 From a5ef19fabd10428ccff2055455ef1a55dfdc5fa0 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Tue, 17 Sep 2013 13:39:10 -0700 Subject: recovery: fix epoll events type to uint32_t Change-Id: I5db9987102201c18821acb45d1f824e9865a1451 --- ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index 08c291ddc..67a2500bb 100644 --- a/ui.cpp +++ b/ui.cpp @@ -63,7 +63,7 @@ void RecoveryUI::Init() { } -int RecoveryUI::input_callback(int fd, unsigned int epevents, void* data) +int RecoveryUI::input_callback(int fd, uint32_t epevents, void* data) { struct input_event ev; int ret; -- cgit v1.2.3 From 4db31d20c92d093e1bdc9499aeeddc1adc19b209 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 4 Sep 2013 13:44:38 -0700 Subject: allow CheckKey to request mounting /system Also provide a default implementation of CheckKey that's reasonable for many devices (those that have power and volume keys). Change-Id: Icf6c7746ebd866152d402059dbd27fd16bd51ff8 --- ui.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index cece02d31..5043ee528 100644 --- a/ui.cpp +++ b/ui.cpp @@ -31,6 +31,7 @@ #include #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) { -- cgit v1.2.3 From 02abde50851f66196c74d215150014f1378cb853 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Tue, 1 Apr 2014 09:45:24 -0700 Subject: remove DefaultDevice's UI subclass RecoveryUI (which is the superclass of ScreenRecoveryUI), provides a basic CheckKey method that is useful for devices that have KEY_POWER, KEY_VOLUMEUP, and KEY_VOLUMEDOWN. Stop overriding it with a less featureful method; with this no recovery UI customization is needed for most handheld devices (phones, tablets, etc.). Change-Id: I7d57cfaaef79afea8af4fc3dbc570afc61aeb5bc --- ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index 67a2500bb..091012f29 100644 --- a/ui.cpp +++ b/ui.cpp @@ -276,7 +276,7 @@ void RecoveryUI::FlushKeys() { // - 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) { - if (IsKeyPressed(KEY_POWER) && key == KEY_VOLUMEUP) { + if ((IsKeyPressed(KEY_POWER) && key == KEY_VOLUMEUP) || key == KEY_HOME) { return TOGGLE; } -- cgit v1.2.3 From c704e06ce596bd0a6de66b10b108aee95535468a Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Fri, 23 May 2014 08:40:35 -0700 Subject: disable async reboot during package installation The default recovery UI will reboot the device when the power key is pressed 7 times in a row, regardless of what recovery is doing. Disable this feature during package installation, to minimize the chance of corrupting the device due to a mid-install reboot. (Debug packages can explicitly request that the feature be reenabled.) Change-Id: I20f3ec240ecd344615d452005ff26d8dd7775acf --- ui.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index 091012f29..98442539b 100644 --- a/ui.cpp +++ b/ui.cpp @@ -49,6 +49,7 @@ RecoveryUI::RecoveryUI() : key_last_down(-1), key_long_press(false), key_down_count(0), + enable_reboot(true), consecutive_power_keys(0), consecutive_alternate_keys(0), last_key(-1) { @@ -116,6 +117,7 @@ int RecoveryUI::input_callback(int fd, uint32_t epevents, void* data) void RecoveryUI::process_key(int key_code, int updown) { bool register_key = false; bool long_press = false; + bool reboot_enabled; pthread_mutex_lock(&key_queue_mutex); key_pressed[key_code] = updown; @@ -137,6 +139,7 @@ void RecoveryUI::process_key(int key_code, int updown) { } key_last_down = -1; } + reboot_enabled = enable_reboot; pthread_mutex_unlock(&key_queue_mutex); if (register_key) { @@ -150,7 +153,9 @@ void RecoveryUI::process_key(int key_code, int updown) { break; case RecoveryUI::REBOOT: - android_reboot(ANDROID_RB_RESTART, 0, 0); + if (reboot_enabled) { + android_reboot(ANDROID_RB_RESTART, 0, 0); + } break; case RecoveryUI::ENQUEUE: @@ -281,9 +286,15 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) { } if (key == KEY_POWER) { - ++consecutive_power_keys; - if (consecutive_power_keys >= 7) { - return REBOOT; + pthread_mutex_lock(&key_queue_mutex); + bool reboot_enabled = enable_reboot; + pthread_mutex_unlock(&key_queue_mutex); + + if (reboot_enabled) { + ++consecutive_power_keys; + if (consecutive_power_keys >= 7) { + return REBOOT; + } } } else { consecutive_power_keys = 0; @@ -311,3 +322,9 @@ void RecoveryUI::NextCheckKeyIsLong(bool is_long_press) { void RecoveryUI::KeyLongPress(int key) { } + +void RecoveryUI::SetEnableReboot(bool enabled) { + pthread_mutex_lock(&key_queue_mutex); + enable_reboot = enabled; + pthread_mutex_unlock(&key_queue_mutex); +} -- cgit v1.2.3 From 187d626e6108298b436f22657a8e14658c15d910 Mon Sep 17 00:00:00 2001 From: Mihai Serban Date: Fri, 6 Jun 2014 15:23:20 +0300 Subject: recovery: initialize keys press tracking status Checks for keys pressed return random results because of an uninitialized data structure. Change-Id: Ic8b3d453d62347921aa893403079b374c16a092e Signed-off-by: Mihai Serban --- ui.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index 5043ee528..a7c8bea48 100644 --- a/ui.cpp +++ b/ui.cpp @@ -55,6 +55,7 @@ RecoveryUI::RecoveryUI() : pthread_mutex_init(&key_queue_mutex, NULL); pthread_cond_init(&key_queue_cond, NULL); self = this; + memset(key_pressed, 0, sizeof(key_pressed)); } void RecoveryUI::Init() { -- cgit v1.2.3