Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame^] | 17 | #include "ui.h" |
| 18 | |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <linux/input.h> |
| 22 | #include <pthread.h> |
| 23 | #include <stdarg.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <sys/time.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <time.h> |
| 31 | #include <unistd.h> |
| 32 | |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame^] | 33 | #include <string> |
| 34 | |
Elliott Hughes | cb22040 | 2016-09-23 15:30:55 -0700 | [diff] [blame] | 35 | #include <android-base/properties.h> |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 36 | #include <cutils/android_reboot.h> |
| 37 | |
| 38 | #include "common.h" |
Doug Zongker | 9e805d6 | 2013-09-04 13:44:38 -0700 | [diff] [blame] | 39 | #include "roots.h" |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 40 | #include "device.h" |
| 41 | #include "minui/minui.h" |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 42 | |
| 43 | #define UI_WAIT_KEY_TIMEOUT_SEC 120 |
| 44 | |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 45 | RecoveryUI::RecoveryUI() |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame^] | 46 | : locale_(""), |
| 47 | rtl_locale_(false), |
| 48 | key_queue_len(0), |
| 49 | key_last_down(-1), |
| 50 | key_long_press(false), |
| 51 | key_down_count(0), |
| 52 | enable_reboot(true), |
| 53 | consecutive_power_keys(0), |
| 54 | last_key(-1), |
| 55 | has_power_key(false), |
| 56 | has_up_key(false), |
| 57 | has_down_key(false) { |
| 58 | pthread_mutex_init(&key_queue_mutex, nullptr); |
| 59 | pthread_cond_init(&key_queue_cond, nullptr); |
| 60 | memset(key_pressed, 0, sizeof(key_pressed)); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 63 | void RecoveryUI::OnKeyDetected(int key_code) { |
| 64 | if (key_code == KEY_POWER) { |
| 65 | has_power_key = true; |
| 66 | } else if (key_code == KEY_DOWN || key_code == KEY_VOLUMEDOWN) { |
| 67 | has_down_key = true; |
| 68 | } else if (key_code == KEY_UP || key_code == KEY_VOLUMEUP) { |
| 69 | has_up_key = true; |
| 70 | } |
| 71 | } |
| 72 | |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 73 | int RecoveryUI::InputCallback(int fd, uint32_t epevents, void* data) { |
| 74 | return reinterpret_cast<RecoveryUI*>(data)->OnInputEvent(fd, epevents); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 77 | // Reads input events, handles special hot keys, and adds to the key queue. |
| 78 | static void* InputThreadLoop(void*) { |
| 79 | while (true) { |
| 80 | if (!ev_wait(-1)) { |
| 81 | ev_dispatch(); |
| 82 | } |
| 83 | } |
| 84 | return nullptr; |
| 85 | } |
| 86 | |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame^] | 87 | bool RecoveryUI::Init(const std::string& locale) { |
| 88 | // Set up the locale info. |
| 89 | SetLocale(locale); |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 90 | |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame^] | 91 | ev_init(InputCallback, this); |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 92 | |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame^] | 93 | ev_iterate_available_keys(std::bind(&RecoveryUI::OnKeyDetected, this, std::placeholders::_1)); |
| 94 | |
| 95 | pthread_create(&input_thread_, nullptr, InputThreadLoop, nullptr); |
| 96 | return true; |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) { |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 100 | struct input_event ev; |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 101 | if (ev_get_input(fd, epevents, &ev) == -1) { |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 102 | return -1; |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 103 | } |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 104 | |
| 105 | if (ev.type == EV_SYN) { |
| 106 | return 0; |
| 107 | } else if (ev.type == EV_REL) { |
| 108 | if (ev.code == REL_Y) { |
| 109 | // accumulate the up or down motion reported by |
| 110 | // the trackball. When it exceeds a threshold |
| 111 | // (positive or negative), fake an up/down |
| 112 | // key event. |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 113 | rel_sum += ev.value; |
| 114 | if (rel_sum > 3) { |
| 115 | ProcessKey(KEY_DOWN, 1); // press down key |
| 116 | ProcessKey(KEY_DOWN, 0); // and release it |
| 117 | rel_sum = 0; |
| 118 | } else if (rel_sum < -3) { |
| 119 | ProcessKey(KEY_UP, 1); // press up key |
| 120 | ProcessKey(KEY_UP, 0); // and release it |
| 121 | rel_sum = 0; |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | } else { |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 125 | rel_sum = 0; |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 128 | if (ev.type == EV_KEY && ev.code <= KEY_MAX) { |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 129 | ProcessKey(ev.code, ev.value); |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 130 | } |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | // Process a key-up or -down event. A key is "registered" when it is |
| 136 | // pressed and then released, with no other keypresses or releases in |
| 137 | // between. Registered keys are passed to CheckKey() to see if it |
| 138 | // should trigger a visibility toggle, an immediate reboot, or be |
| 139 | // queued to be processed next time the foreground thread wants a key |
| 140 | // (eg, for the menu). |
| 141 | // |
| 142 | // We also keep track of which keys are currently down so that |
| 143 | // CheckKey can call IsKeyPressed to see what other keys are held when |
| 144 | // a key is registered. |
| 145 | // |
| 146 | // updown == 1 for key down events; 0 for key up events |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 147 | void RecoveryUI::ProcessKey(int key_code, int updown) { |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 148 | bool register_key = false; |
Doug Zongker | bb01d0c | 2012-12-17 10:52:58 -0800 | [diff] [blame] | 149 | bool long_press = false; |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 150 | bool reboot_enabled; |
Doug Zongker | bb01d0c | 2012-12-17 10:52:58 -0800 | [diff] [blame] | 151 | |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 152 | pthread_mutex_lock(&key_queue_mutex); |
| 153 | key_pressed[key_code] = updown; |
| 154 | if (updown) { |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 155 | ++key_down_count; |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 156 | key_last_down = key_code; |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 157 | key_long_press = false; |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 158 | key_timer_t* info = new key_timer_t; |
| 159 | info->ui = this; |
| 160 | info->key_code = key_code; |
| 161 | info->count = key_down_count; |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 162 | pthread_t thread; |
| 163 | pthread_create(&thread, nullptr, &RecoveryUI::time_key_helper, info); |
| 164 | pthread_detach(thread); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 165 | } else { |
Doug Zongker | bb01d0c | 2012-12-17 10:52:58 -0800 | [diff] [blame] | 166 | if (key_last_down == key_code) { |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 167 | long_press = key_long_press; |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 168 | register_key = true; |
Doug Zongker | bb01d0c | 2012-12-17 10:52:58 -0800 | [diff] [blame] | 169 | } |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 170 | key_last_down = -1; |
| 171 | } |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 172 | reboot_enabled = enable_reboot; |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 173 | pthread_mutex_unlock(&key_queue_mutex); |
| 174 | |
| 175 | if (register_key) { |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 176 | switch (CheckKey(key_code, long_press)) { |
Doug Zongker | 48b5b07 | 2012-01-18 13:46:26 -0800 | [diff] [blame] | 177 | case RecoveryUI::IGNORE: |
| 178 | break; |
| 179 | |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 180 | case RecoveryUI::TOGGLE: |
| 181 | ShowText(!IsTextVisible()); |
| 182 | break; |
| 183 | |
| 184 | case RecoveryUI::REBOOT: |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 185 | if (reboot_enabled) { |
Elliott Hughes | cb22040 | 2016-09-23 15:30:55 -0700 | [diff] [blame] | 186 | android::base::SetProperty(ANDROID_RB_PROPERTY, "reboot,"); |
Tao Bao | 7523863 | 2015-05-27 14:46:17 -0700 | [diff] [blame] | 187 | while (true) { pause(); } |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 188 | } |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 189 | break; |
| 190 | |
| 191 | case RecoveryUI::ENQUEUE: |
Doug Zongker | bb01d0c | 2012-12-17 10:52:58 -0800 | [diff] [blame] | 192 | EnqueueKey(key_code); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 193 | break; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 198 | void* RecoveryUI::time_key_helper(void* cookie) { |
| 199 | key_timer_t* info = (key_timer_t*) cookie; |
| 200 | info->ui->time_key(info->key_code, info->count); |
| 201 | delete info; |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 202 | return nullptr; |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void RecoveryUI::time_key(int key_code, int count) { |
| 206 | usleep(750000); // 750 ms == "long" |
| 207 | bool long_press = false; |
| 208 | pthread_mutex_lock(&key_queue_mutex); |
| 209 | if (key_last_down == key_code && key_down_count == count) { |
| 210 | long_press = key_long_press = true; |
| 211 | } |
| 212 | pthread_mutex_unlock(&key_queue_mutex); |
| 213 | if (long_press) KeyLongPress(key_code); |
| 214 | } |
| 215 | |
Doug Zongker | bb01d0c | 2012-12-17 10:52:58 -0800 | [diff] [blame] | 216 | void RecoveryUI::EnqueueKey(int key_code) { |
| 217 | pthread_mutex_lock(&key_queue_mutex); |
| 218 | const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]); |
| 219 | if (key_queue_len < queue_max) { |
| 220 | key_queue[key_queue_len++] = key_code; |
| 221 | pthread_cond_signal(&key_queue_cond); |
| 222 | } |
| 223 | pthread_mutex_unlock(&key_queue_mutex); |
| 224 | } |
| 225 | |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 226 | int RecoveryUI::WaitKey() { |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 227 | pthread_mutex_lock(&key_queue_mutex); |
| 228 | |
| 229 | // Time out after UI_WAIT_KEY_TIMEOUT_SEC, unless a USB cable is |
| 230 | // plugged in. |
| 231 | do { |
| 232 | struct timeval now; |
| 233 | struct timespec timeout; |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 234 | gettimeofday(&now, nullptr); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 235 | timeout.tv_sec = now.tv_sec; |
| 236 | timeout.tv_nsec = now.tv_usec * 1000; |
| 237 | timeout.tv_sec += UI_WAIT_KEY_TIMEOUT_SEC; |
| 238 | |
| 239 | int rc = 0; |
| 240 | while (key_queue_len == 0 && rc != ETIMEDOUT) { |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 241 | rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex, &timeout); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 242 | } |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 243 | } while (IsUsbConnected() && key_queue_len == 0); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 244 | |
| 245 | int key = -1; |
| 246 | if (key_queue_len > 0) { |
| 247 | key = key_queue[0]; |
| 248 | memcpy(&key_queue[0], &key_queue[1], sizeof(int) * --key_queue_len); |
| 249 | } |
| 250 | pthread_mutex_unlock(&key_queue_mutex); |
| 251 | return key; |
| 252 | } |
| 253 | |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 254 | bool RecoveryUI::IsUsbConnected() { |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 255 | int fd = open("/sys/class/android_usb/android0/state", O_RDONLY); |
| 256 | if (fd < 0) { |
| 257 | printf("failed to open /sys/class/android_usb/android0/state: %s\n", |
| 258 | strerror(errno)); |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | char buf; |
Elliott Hughes | 985022a | 2015-04-13 13:04:32 -0700 | [diff] [blame] | 263 | // USB is connected if android_usb state is CONNECTED or CONFIGURED. |
Elliott Hughes | 7bad7c4 | 2015-04-28 17:24:24 -0700 | [diff] [blame] | 264 | int connected = (TEMP_FAILURE_RETRY(read(fd, &buf, 1)) == 1) && (buf == 'C'); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 265 | if (close(fd) < 0) { |
| 266 | printf("failed to close /sys/class/android_usb/android0/state: %s\n", |
| 267 | strerror(errno)); |
| 268 | } |
| 269 | return connected; |
| 270 | } |
| 271 | |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 272 | bool RecoveryUI::IsKeyPressed(int key) { |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 273 | pthread_mutex_lock(&key_queue_mutex); |
| 274 | int pressed = key_pressed[key]; |
| 275 | pthread_mutex_unlock(&key_queue_mutex); |
| 276 | return pressed; |
| 277 | } |
| 278 | |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 279 | bool RecoveryUI::IsLongPress() { |
| 280 | pthread_mutex_lock(&key_queue_mutex); |
| 281 | bool result = key_long_press; |
| 282 | pthread_mutex_unlock(&key_queue_mutex); |
| 283 | return result; |
| 284 | } |
| 285 | |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 286 | bool RecoveryUI::HasThreeButtons() { |
| 287 | return has_power_key && has_up_key && has_down_key; |
| 288 | } |
| 289 | |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 290 | void RecoveryUI::FlushKeys() { |
| 291 | pthread_mutex_lock(&key_queue_mutex); |
| 292 | key_queue_len = 0; |
| 293 | pthread_mutex_unlock(&key_queue_mutex); |
| 294 | } |
| 295 | |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 296 | RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) { |
| 297 | pthread_mutex_lock(&key_queue_mutex); |
| 298 | key_long_press = false; |
| 299 | pthread_mutex_unlock(&key_queue_mutex); |
| 300 | |
| 301 | // If we have power and volume up keys, that chord is the signal to toggle the text display. |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 302 | if (HasThreeButtons()) { |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 303 | if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) { |
| 304 | return TOGGLE; |
| 305 | } |
| 306 | } else { |
| 307 | // Otherwise long press of any button toggles to the text display, |
| 308 | // and there's no way to toggle back (but that's pretty useless anyway). |
| 309 | if (is_long_press && !IsTextVisible()) { |
| 310 | return TOGGLE; |
| 311 | } |
| 312 | |
| 313 | // Also, for button-limited devices, a long press is translated to KEY_ENTER. |
| 314 | if (is_long_press && IsTextVisible()) { |
| 315 | EnqueueKey(KEY_ENTER); |
| 316 | return IGNORE; |
| 317 | } |
Doug Zongker | 9e805d6 | 2013-09-04 13:44:38 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 320 | // Press power seven times in a row to reboot. |
Doug Zongker | 9e805d6 | 2013-09-04 13:44:38 -0700 | [diff] [blame] | 321 | if (key == KEY_POWER) { |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 322 | pthread_mutex_lock(&key_queue_mutex); |
| 323 | bool reboot_enabled = enable_reboot; |
| 324 | pthread_mutex_unlock(&key_queue_mutex); |
| 325 | |
| 326 | if (reboot_enabled) { |
| 327 | ++consecutive_power_keys; |
| 328 | if (consecutive_power_keys >= 7) { |
| 329 | return REBOOT; |
| 330 | } |
Doug Zongker | 9e805d6 | 2013-09-04 13:44:38 -0700 | [diff] [blame] | 331 | } |
| 332 | } else { |
| 333 | consecutive_power_keys = 0; |
| 334 | } |
| 335 | |
Doug Zongker | 9e805d6 | 2013-09-04 13:44:38 -0700 | [diff] [blame] | 336 | last_key = key; |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 337 | return IsTextVisible() ? ENQUEUE : IGNORE; |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 338 | } |
Doug Zongker | bb01d0c | 2012-12-17 10:52:58 -0800 | [diff] [blame] | 339 | |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 340 | void RecoveryUI::KeyLongPress(int) { |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 341 | } |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 342 | |
| 343 | void RecoveryUI::SetEnableReboot(bool enabled) { |
| 344 | pthread_mutex_lock(&key_queue_mutex); |
| 345 | enable_reboot = enabled; |
| 346 | pthread_mutex_unlock(&key_queue_mutex); |
| 347 | } |
Tao Bao | 736d59c | 2017-01-03 10:15:33 -0800 | [diff] [blame^] | 348 | |
| 349 | void RecoveryUI::SetLocale(const std::string& new_locale) { |
| 350 | this->locale_ = new_locale; |
| 351 | this->rtl_locale_ = false; |
| 352 | |
| 353 | if (!new_locale.empty()) { |
| 354 | size_t underscore = new_locale.find('_'); |
| 355 | // lang has the language prefix prior to '_', or full string if '_' doesn't exist. |
| 356 | std::string lang = new_locale.substr(0, underscore); |
| 357 | |
| 358 | // A bit cheesy: keep an explicit list of supported RTL languages. |
| 359 | if (lang == "ar" || // Arabic |
| 360 | lang == "fa" || // Persian (Farsi) |
| 361 | lang == "he" || // Hebrew (new language code) |
| 362 | lang == "iw" || // Hebrew (old language code) |
| 363 | lang == "ur") { // Urdu |
| 364 | rtl_locale_ = true; |
| 365 | } |
| 366 | } |
| 367 | } |