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