Add a new key_pressed_mutex
The following variables in recovery ui were protected by key_queue_mutex. But the purpose of key_queue_mutex is to protect the key_queue, which will be changed after we already have a key code. So getting the key pressed should be orthogonal to the key queue. And adding a mutex will help to avoid deadlocks in b/135078366. Variables include: char key_pressed[KEY_MAX + 1]; int key_last_down; bool key_long_press; int key_down_count; bool enable_reboot; Bug: 135078366 Test: boot into recovery and press keys Change-Id: Ie2cfcf1f2fec49b53f8fac97aa9a2c60f15b84f9
This commit is contained in:
parent
e1701454b2
commit
b8a959b00f
2 changed files with 16 additions and 12 deletions
|
@ -230,18 +230,22 @@ class RecoveryUI {
|
|||
|
||||
bool InitScreensaver();
|
||||
void SetScreensaverState(ScreensaverState state);
|
||||
|
||||
// Key event input queue
|
||||
std::mutex key_queue_mutex;
|
||||
std::condition_variable key_queue_cond;
|
||||
bool key_interrupted_;
|
||||
int key_queue[256], key_queue_len;
|
||||
char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
|
||||
int key_last_down; // under key_queue_mutex
|
||||
bool key_long_press; // under key_queue_mutex
|
||||
int key_down_count; // under key_queue_mutex
|
||||
bool enable_reboot; // under key_queue_mutex
|
||||
int rel_sum;
|
||||
|
||||
// key press events
|
||||
std::mutex key_press_mutex;
|
||||
char key_pressed[KEY_MAX + 1];
|
||||
int key_last_down;
|
||||
bool key_long_press;
|
||||
int key_down_count;
|
||||
bool enable_reboot;
|
||||
|
||||
int rel_sum;
|
||||
int consecutive_power_keys;
|
||||
int last_key;
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@ void RecoveryUI::ProcessKey(int key_code, int updown) {
|
|||
bool long_press = false;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(key_queue_mutex);
|
||||
std::lock_guard<std::mutex> lg(key_press_mutex);
|
||||
key_pressed[key_code] = updown;
|
||||
if (updown) {
|
||||
++key_down_count;
|
||||
|
@ -393,7 +393,7 @@ void RecoveryUI::TimeKey(int key_code, int count) {
|
|||
std::this_thread::sleep_for(750ms); // 750 ms == "long"
|
||||
bool long_press = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(key_queue_mutex);
|
||||
std::lock_guard<std::mutex> lg(key_press_mutex);
|
||||
if (key_last_down == key_code && key_down_count == count) {
|
||||
long_press = key_long_press = true;
|
||||
}
|
||||
|
@ -518,13 +518,13 @@ bool RecoveryUI::IsUsbConnected() {
|
|||
}
|
||||
|
||||
bool RecoveryUI::IsKeyPressed(int key) {
|
||||
std::lock_guard<std::mutex> lg(key_queue_mutex);
|
||||
std::lock_guard<std::mutex> lg(key_press_mutex);
|
||||
int pressed = key_pressed[key];
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool RecoveryUI::IsLongPress() {
|
||||
std::lock_guard<std::mutex> lg(key_queue_mutex);
|
||||
std::lock_guard<std::mutex> lg(key_press_mutex);
|
||||
bool result = key_long_press;
|
||||
return result;
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ void RecoveryUI::FlushKeys() {
|
|||
|
||||
RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(key_queue_mutex);
|
||||
std::lock_guard<std::mutex> lg(key_press_mutex);
|
||||
key_long_press = false;
|
||||
}
|
||||
|
||||
|
@ -592,6 +592,6 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
|
|||
void RecoveryUI::KeyLongPress(int) {}
|
||||
|
||||
void RecoveryUI::SetEnableReboot(bool enabled) {
|
||||
std::lock_guard<std::mutex> lg(key_queue_mutex);
|
||||
std::lock_guard<std::mutex> lg(key_press_mutex);
|
||||
enable_reboot = enabled;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue