Doug Zongker | 211aebc | 2011-10-28 15:13:10 -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 | |
| 17 | #include <errno.h> |
| 18 | #include <fcntl.h> |
| 19 | #include <linux/input.h> |
| 20 | #include <pthread.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <sys/time.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <time.h> |
| 29 | #include <unistd.h> |
| 30 | |
| 31 | #include "common.h" |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 32 | #include "device.h" |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 33 | #include "minui/minui.h" |
| 34 | #include "screen_ui.h" |
| 35 | #include "ui.h" |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 36 | |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 37 | static int char_width; |
| 38 | static int char_height; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 39 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 40 | // There's only (at most) one of these objects, and global callbacks |
| 41 | // (for pthread_create, and the input event system) need to find it, |
| 42 | // so use a global variable. |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 43 | static ScreenRecoveryUI* self = nullptr; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 44 | |
| 45 | // Return the current time as a double (including fractions of a second). |
| 46 | static double now() { |
| 47 | struct timeval tv; |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 48 | gettimeofday(&tv, nullptr); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 49 | return tv.tv_sec + tv.tv_usec / 1000000.0; |
| 50 | } |
| 51 | |
| 52 | ScreenRecoveryUI::ScreenRecoveryUI() : |
| 53 | currentIcon(NONE), |
| 54 | installingFrame(0), |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 55 | locale(nullptr), |
Doug Zongker | 5fa8c23 | 2012-09-18 12:37:02 -0700 | [diff] [blame] | 56 | rtl_locale(false), |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 57 | progressBarType(EMPTY), |
| 58 | progressScopeStart(0), |
| 59 | progressScopeSize(0), |
| 60 | progress(0), |
| 61 | pagesIdentical(false), |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 62 | text(nullptr), |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 63 | text_cols(0), |
| 64 | text_rows(0), |
| 65 | text_col(0), |
| 66 | text_row(0), |
| 67 | text_top(0), |
| 68 | show_text(false), |
| 69 | show_text_ever(false), |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 70 | menu(nullptr), |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 71 | show_menu(false), |
| 72 | menu_top(0), |
| 73 | menu_items(0), |
| 74 | menu_sel(0), |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 75 | animation_fps(20), |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 76 | installing_frames(-1), |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 77 | stage(-1), |
| 78 | max_stage(-1) { |
yetta_wu | 5b468fc | 2013-06-25 15:03:11 +0800 | [diff] [blame] | 79 | |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 80 | for (int i = 0; i < 5; i++) { |
| 81 | backgroundIcon[i] = nullptr; |
| 82 | } |
| 83 | pthread_mutex_init(&updateMutex, nullptr); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 84 | self = this; |
| 85 | } |
| 86 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 87 | // Clear the screen and draw the currently selected background icon (if any). |
| 88 | // Should only be called with updateMutex locked. |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 89 | void ScreenRecoveryUI::draw_background_locked(Icon icon) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 90 | pagesIdentical = false; |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 91 | gr_color(0, 0, 0, 255); |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 92 | gr_clear(); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 93 | |
| 94 | if (icon) { |
| 95 | gr_surface surface = backgroundIcon[icon]; |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 96 | if (icon == INSTALLING_UPDATE || icon == ERASING) { |
| 97 | surface = installation[installingFrame]; |
| 98 | } |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 99 | gr_surface text_surface = backgroundText[icon]; |
| 100 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 101 | int iconWidth = gr_get_width(surface); |
| 102 | int iconHeight = gr_get_height(surface); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 103 | int textWidth = gr_get_width(text_surface); |
| 104 | int textHeight = gr_get_height(text_surface); |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 105 | int stageHeight = gr_get_height(stageMarkerEmpty); |
| 106 | |
| 107 | int sh = (max_stage >= 0) ? stageHeight : 0; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 108 | |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 109 | iconX = (gr_fb_width() - iconWidth) / 2; |
| 110 | iconY = (gr_fb_height() - (iconHeight+textHeight+40+sh)) / 2; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 111 | |
| 112 | int textX = (gr_fb_width() - textWidth) / 2; |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 113 | int textY = ((gr_fb_height() - (iconHeight+textHeight+40+sh)) / 2) + iconHeight + 40; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 114 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 115 | gr_blit(surface, 0, 0, iconWidth, iconHeight, iconX, iconY); |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 116 | if (stageHeight > 0) { |
| 117 | int sw = gr_get_width(stageMarkerEmpty); |
| 118 | int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2; |
| 119 | int y = iconY + iconHeight + 20; |
| 120 | for (int i = 0; i < max_stage; ++i) { |
| 121 | gr_blit((i < stage) ? stageMarkerFill : stageMarkerEmpty, |
| 122 | 0, 0, sw, stageHeight, x, y); |
| 123 | x += sw; |
| 124 | } |
| 125 | } |
| 126 | |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 127 | gr_color(255, 255, 255, 255); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 128 | gr_texticon(textX, textY, text_surface); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | // Draw the progress bar (if any) on the screen. Does not flip pages. |
| 133 | // Should only be called with updateMutex locked. |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 134 | void ScreenRecoveryUI::draw_progress_locked() { |
Doug Zongker | 69f4b67 | 2012-04-26 14:37:53 -0700 | [diff] [blame] | 135 | if (currentIcon == ERROR) return; |
| 136 | |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 137 | if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) { |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 138 | gr_surface icon = installation[installingFrame]; |
| 139 | gr_blit(icon, 0, 0, gr_get_width(icon), gr_get_height(icon), iconX, iconY); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | if (progressBarType != EMPTY) { |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 143 | int iconHeight = gr_get_height(backgroundIcon[INSTALLING_UPDATE]); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 144 | int width = gr_get_width(progressBarEmpty); |
| 145 | int height = gr_get_height(progressBarEmpty); |
| 146 | |
| 147 | int dx = (gr_fb_width() - width)/2; |
| 148 | int dy = (3*gr_fb_height() + iconHeight - 2*height)/4; |
| 149 | |
| 150 | // Erase behind the progress bar (in case this was a progress-only update) |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 151 | gr_color(0, 0, 0, 255); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 152 | gr_fill(dx, dy, width, height); |
| 153 | |
| 154 | if (progressBarType == DETERMINATE) { |
| 155 | float p = progressScopeStart + progress * progressScopeSize; |
| 156 | int pos = (int) (p * width); |
| 157 | |
Doug Zongker | 5fa8c23 | 2012-09-18 12:37:02 -0700 | [diff] [blame] | 158 | if (rtl_locale) { |
| 159 | // Fill the progress bar from right to left. |
| 160 | if (pos > 0) { |
| 161 | gr_blit(progressBarFill, width-pos, 0, pos, height, dx+width-pos, dy); |
| 162 | } |
| 163 | if (pos < width-1) { |
| 164 | gr_blit(progressBarEmpty, 0, 0, width-pos, height, dx, dy); |
| 165 | } |
| 166 | } else { |
| 167 | // Fill the progress bar from left to right. |
| 168 | if (pos > 0) { |
| 169 | gr_blit(progressBarFill, 0, 0, pos, height, dx, dy); |
| 170 | } |
| 171 | if (pos < width-1) { |
| 172 | gr_blit(progressBarEmpty, pos, 0, width-pos, height, dx+pos, dy); |
| 173 | } |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 179 | void ScreenRecoveryUI::SetColor(UIElement e) { |
| 180 | switch (e) { |
| 181 | case HEADER: |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 182 | gr_color(247, 0, 6, 255); |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 183 | break; |
| 184 | case MENU: |
| 185 | case MENU_SEL_BG: |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 186 | gr_color(0, 106, 157, 255); |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 187 | break; |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 188 | case MENU_SEL_BG_ACTIVE: |
| 189 | gr_color(0, 156, 100, 255); |
| 190 | break; |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 191 | case MENU_SEL_FG: |
| 192 | gr_color(255, 255, 255, 255); |
| 193 | break; |
| 194 | case LOG: |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 195 | gr_color(249, 194, 0, 255); |
| 196 | break; |
| 197 | case TEXT_FILL: |
| 198 | gr_color(0, 0, 0, 160); |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 199 | break; |
| 200 | default: |
| 201 | gr_color(255, 255, 255, 255); |
| 202 | break; |
| 203 | } |
| 204 | } |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 205 | |
| 206 | // Redraw everything on the screen. Does not flip pages. |
| 207 | // Should only be called with updateMutex locked. |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 208 | void ScreenRecoveryUI::draw_screen_locked() { |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 209 | if (!show_text) { |
| 210 | draw_background_locked(currentIcon); |
| 211 | draw_progress_locked(); |
| 212 | } else { |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 213 | gr_color(0, 0, 0, 255); |
Doug Zongker | 39cf417 | 2014-03-06 16:16:05 -0800 | [diff] [blame] | 214 | gr_clear(); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 215 | |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 216 | int y = 0; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 217 | int i = 0; |
| 218 | if (show_menu) { |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 219 | SetColor(HEADER); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 220 | |
| 221 | for (; i < menu_top + menu_items; ++i) { |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 222 | if (i == menu_top) SetColor(MENU); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 223 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 224 | if (i == menu_top + menu_sel) { |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 225 | // draw the highlight bar |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 226 | SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG); |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 227 | gr_fill(0, y-2, gr_fb_width(), y+char_height+2); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 228 | // white text of selected item |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 229 | SetColor(MENU_SEL_FG); |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 230 | if (menu[i][0]) gr_text(4, y, menu[i], 1); |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 231 | SetColor(MENU); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 232 | } else { |
Doug Zongker | 5b5f6c2 | 2014-06-03 10:50:13 -0700 | [diff] [blame] | 233 | if (menu[i][0]) gr_text(4, y, menu[i], i < menu_top); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 234 | } |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 235 | y += char_height+4; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 236 | } |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 237 | SetColor(MENU); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 238 | y += 4; |
| 239 | gr_fill(0, y, gr_fb_width(), y+2); |
| 240 | y += 4; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 241 | ++i; |
| 242 | } |
| 243 | |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 244 | SetColor(LOG); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 245 | |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 246 | // display from the bottom up, until we hit the top of the |
| 247 | // screen, the bottom of the menu, or we've displayed the |
| 248 | // entire text buffer. |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 249 | int row = (text_top+text_rows-1) % text_rows; |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 250 | size_t count = 0; |
| 251 | for (int ty = gr_fb_height() - char_height; |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 252 | ty > y+2 && count < text_rows; |
| 253 | ty -= char_height, ++count) { |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 254 | gr_text(0, ty, text[row], 0); |
Doug Zongker | 6fd59ac | 2013-03-06 15:01:11 -0800 | [diff] [blame] | 255 | --row; |
| 256 | if (row < 0) row = text_rows-1; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | // Redraw everything on the screen and flip the screen (make it visible). |
| 262 | // Should only be called with updateMutex locked. |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 263 | void ScreenRecoveryUI::update_screen_locked() { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 264 | draw_screen_locked(); |
| 265 | gr_flip(); |
| 266 | } |
| 267 | |
| 268 | // Updates only the progress bar, if possible, otherwise redraws the screen. |
| 269 | // Should only be called with updateMutex locked. |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 270 | void ScreenRecoveryUI::update_progress_locked() { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 271 | if (show_text || !pagesIdentical) { |
| 272 | draw_screen_locked(); // Must redraw the whole screen |
| 273 | pagesIdentical = true; |
| 274 | } else { |
| 275 | draw_progress_locked(); // Draw only the progress bar and overlays |
| 276 | } |
| 277 | gr_flip(); |
| 278 | } |
| 279 | |
| 280 | // Keeps the progress bar updated, even when the process is otherwise busy. |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 281 | void* ScreenRecoveryUI::progress_thread(void *cookie) { |
| 282 | self->progress_loop(); |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 283 | return nullptr; |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void ScreenRecoveryUI::progress_loop() { |
| 287 | double interval = 1.0 / animation_fps; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 288 | for (;;) { |
| 289 | double start = now(); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 290 | pthread_mutex_lock(&updateMutex); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 291 | |
| 292 | int redraw = 0; |
| 293 | |
| 294 | // update the installation animation, if active |
| 295 | // skip this if we have a text overlay (too expensive to update) |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 296 | if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && |
| 297 | installing_frames > 0 && !show_text) { |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 298 | installingFrame = (installingFrame + 1) % installing_frames; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 299 | redraw = 1; |
| 300 | } |
| 301 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 302 | // move the progress bar forward on timed intervals, if configured |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 303 | int duration = progressScopeDuration; |
| 304 | if (progressBarType == DETERMINATE && duration > 0) { |
| 305 | double elapsed = now() - progressScopeTime; |
Doug Zongker | 69f4b67 | 2012-04-26 14:37:53 -0700 | [diff] [blame] | 306 | float p = 1.0 * elapsed / duration; |
| 307 | if (p > 1.0) p = 1.0; |
| 308 | if (p > progress) { |
| 309 | progress = p; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 310 | redraw = 1; |
| 311 | } |
| 312 | } |
| 313 | |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 314 | if (redraw) update_progress_locked(); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 315 | |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 316 | pthread_mutex_unlock(&updateMutex); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 317 | double end = now(); |
| 318 | // minimum of 20ms delay between frames |
| 319 | double delay = interval - (end-start); |
| 320 | if (delay < 0.02) delay = 0.02; |
| 321 | usleep((long)(delay * 1000000)); |
| 322 | } |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void ScreenRecoveryUI::LoadBitmap(const char* filename, gr_surface* surface) { |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 326 | int result = res_create_display_surface(filename, surface); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 327 | if (result < 0) { |
| 328 | LOGE("missing bitmap %s\n(Code %d)\n", filename, result); |
| 329 | } |
| 330 | } |
| 331 | |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 332 | void ScreenRecoveryUI::LoadBitmapArray(const char* filename, int* frames, gr_surface** surface) { |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 333 | int result = res_create_multi_display_surface(filename, frames, surface); |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 334 | if (result < 0) { |
| 335 | LOGE("missing bitmap %s\n(Code %d)\n", filename, result); |
| 336 | } |
| 337 | } |
| 338 | |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 339 | void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, gr_surface* surface) { |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 340 | int result = res_create_localized_alpha_surface(filename, locale, surface); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 341 | if (result < 0) { |
| 342 | LOGE("missing bitmap %s\n(Code %d)\n", filename, result); |
| 343 | } |
| 344 | } |
| 345 | |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 346 | static char** Alloc2d(size_t rows, size_t cols) { |
| 347 | char** result = new char*[rows]; |
| 348 | for (size_t i = 0; i < rows; ++i) { |
| 349 | result[i] = new char[cols]; |
| 350 | memset(result[i], 0, cols); |
| 351 | } |
| 352 | return result; |
| 353 | } |
| 354 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 355 | void ScreenRecoveryUI::Init() { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 356 | gr_init(); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 357 | |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 358 | gr_font_size(&char_width, &char_height); |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 359 | text_rows = gr_fb_height() / char_height; |
| 360 | text_cols = gr_fb_width() / char_width; |
| 361 | |
| 362 | text = Alloc2d(text_rows, text_cols + 1); |
| 363 | menu = Alloc2d(text_rows, text_cols + 1); |
Doug Zongker | 55a36ac | 2013-03-04 15:49:02 -0800 | [diff] [blame] | 364 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 365 | text_col = text_row = 0; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 366 | text_top = 1; |
| 367 | |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 368 | backgroundIcon[NONE] = nullptr; |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 369 | LoadBitmapArray("icon_installing", &installing_frames, &installation); |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 370 | backgroundIcon[INSTALLING_UPDATE] = installing_frames ? installation[0] : nullptr; |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 371 | backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE]; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 372 | LoadBitmap("icon_error", &backgroundIcon[ERROR]); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 373 | backgroundIcon[NO_COMMAND] = backgroundIcon[ERROR]; |
| 374 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 375 | LoadBitmap("progress_empty", &progressBarEmpty); |
| 376 | LoadBitmap("progress_fill", &progressBarFill); |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 377 | LoadBitmap("stage_empty", &stageMarkerEmpty); |
| 378 | LoadBitmap("stage_fill", &stageMarkerFill); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 379 | |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 380 | LoadLocalizedBitmap("installing_text", &backgroundText[INSTALLING_UPDATE]); |
| 381 | LoadLocalizedBitmap("erasing_text", &backgroundText[ERASING]); |
| 382 | LoadLocalizedBitmap("no_command_text", &backgroundText[NO_COMMAND]); |
| 383 | LoadLocalizedBitmap("error_text", &backgroundText[ERROR]); |
| 384 | |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 385 | pthread_create(&progress_t, nullptr, progress_thread, nullptr); |
Doug Zongker | 32a0a47 | 2011-11-01 11:00:20 -0700 | [diff] [blame] | 386 | |
| 387 | RecoveryUI::Init(); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 390 | void ScreenRecoveryUI::SetLocale(const char* new_locale) { |
| 391 | if (new_locale) { |
| 392 | this->locale = new_locale; |
Doug Zongker | 5fa8c23 | 2012-09-18 12:37:02 -0700 | [diff] [blame] | 393 | char* lang = strdup(locale); |
| 394 | for (char* p = lang; *p; ++p) { |
| 395 | if (*p == '_') { |
| 396 | *p = '\0'; |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // A bit cheesy: keep an explicit list of supported languages |
| 402 | // that are RTL. |
| 403 | if (strcmp(lang, "ar") == 0 || // Arabic |
| 404 | strcmp(lang, "fa") == 0 || // Persian (Farsi) |
| 405 | strcmp(lang, "he") == 0 || // Hebrew (new language code) |
Doug Zongker | b66cb69 | 2012-09-18 14:52:18 -0700 | [diff] [blame] | 406 | strcmp(lang, "iw") == 0 || // Hebrew (old language code) |
| 407 | strcmp(lang, "ur") == 0) { // Urdu |
Doug Zongker | 5fa8c23 | 2012-09-18 12:37:02 -0700 | [diff] [blame] | 408 | rtl_locale = true; |
| 409 | } |
| 410 | free(lang); |
Doug Zongker | a418aa7 | 2014-03-17 12:10:02 -0700 | [diff] [blame] | 411 | } else { |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 412 | new_locale = nullptr; |
Doug Zongker | 5fa8c23 | 2012-09-18 12:37:02 -0700 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 416 | void ScreenRecoveryUI::SetBackground(Icon icon) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 417 | pthread_mutex_lock(&updateMutex); |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 418 | |
Doug Zongker | 52eeea4f | 2012-09-04 14:28:25 -0700 | [diff] [blame] | 419 | currentIcon = icon; |
| 420 | update_screen_locked(); |
| 421 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 422 | pthread_mutex_unlock(&updateMutex); |
| 423 | } |
| 424 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 425 | void ScreenRecoveryUI::SetProgressType(ProgressType type) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 426 | pthread_mutex_lock(&updateMutex); |
| 427 | if (progressBarType != type) { |
| 428 | progressBarType = type; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 429 | } |
Doug Zongker | 69f4b67 | 2012-04-26 14:37:53 -0700 | [diff] [blame] | 430 | progressScopeStart = 0; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 431 | progressScopeSize = 0; |
Doug Zongker | 69f4b67 | 2012-04-26 14:37:53 -0700 | [diff] [blame] | 432 | progress = 0; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 433 | update_progress_locked(); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 434 | pthread_mutex_unlock(&updateMutex); |
| 435 | } |
| 436 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 437 | void ScreenRecoveryUI::ShowProgress(float portion, float seconds) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 438 | pthread_mutex_lock(&updateMutex); |
| 439 | progressBarType = DETERMINATE; |
| 440 | progressScopeStart += progressScopeSize; |
| 441 | progressScopeSize = portion; |
| 442 | progressScopeTime = now(); |
| 443 | progressScopeDuration = seconds; |
| 444 | progress = 0; |
| 445 | update_progress_locked(); |
| 446 | pthread_mutex_unlock(&updateMutex); |
| 447 | } |
| 448 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 449 | void ScreenRecoveryUI::SetProgress(float fraction) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 450 | pthread_mutex_lock(&updateMutex); |
| 451 | if (fraction < 0.0) fraction = 0.0; |
| 452 | if (fraction > 1.0) fraction = 1.0; |
| 453 | if (progressBarType == DETERMINATE && fraction > progress) { |
| 454 | // Skip updates that aren't visibly different. |
Doug Zongker | eac881c | 2014-03-07 09:21:25 -0800 | [diff] [blame] | 455 | int width = gr_get_width(progressBarEmpty); |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 456 | float scale = width * progressScopeSize; |
| 457 | if ((int) (progress * scale) != (int) (fraction * scale)) { |
| 458 | progress = fraction; |
| 459 | update_progress_locked(); |
| 460 | } |
| 461 | } |
| 462 | pthread_mutex_unlock(&updateMutex); |
| 463 | } |
| 464 | |
Doug Zongker | c87bab1 | 2013-11-25 13:53:25 -0800 | [diff] [blame] | 465 | void ScreenRecoveryUI::SetStage(int current, int max) { |
| 466 | pthread_mutex_lock(&updateMutex); |
| 467 | stage = current; |
| 468 | max_stage = max; |
| 469 | pthread_mutex_unlock(&updateMutex); |
| 470 | } |
| 471 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 472 | void ScreenRecoveryUI::Print(const char *fmt, ...) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 473 | char buf[256]; |
| 474 | va_list ap; |
| 475 | va_start(ap, fmt); |
| 476 | vsnprintf(buf, 256, fmt, ap); |
| 477 | va_end(ap); |
| 478 | |
| 479 | fputs(buf, stdout); |
| 480 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 481 | pthread_mutex_lock(&updateMutex); |
| 482 | if (text_rows > 0 && text_cols > 0) { |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 483 | for (const char* ptr = buf; *ptr != '\0'; ++ptr) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 484 | if (*ptr == '\n' || text_col >= text_cols) { |
| 485 | text[text_row][text_col] = '\0'; |
| 486 | text_col = 0; |
| 487 | text_row = (text_row + 1) % text_rows; |
| 488 | if (text_row == text_top) text_top = (text_top + 1) % text_rows; |
| 489 | } |
| 490 | if (*ptr != '\n') text[text_row][text_col++] = *ptr; |
| 491 | } |
| 492 | text[text_row][text_col] = '\0'; |
| 493 | update_screen_locked(); |
| 494 | } |
| 495 | pthread_mutex_unlock(&updateMutex); |
| 496 | } |
| 497 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 498 | // TODO: replace this with something not line-based so we can wrap correctly without getting |
| 499 | // confused about what line we're on. |
| 500 | void ScreenRecoveryUI::print_no_update(const char* s) { |
| 501 | pthread_mutex_lock(&updateMutex); |
| 502 | if (text_rows > 0 && text_cols > 0) { |
| 503 | for (const char* ptr = s; *ptr != '\0'; ++ptr) { |
| 504 | if (*ptr == '\n' || text_col >= text_cols) { |
| 505 | text[text_row][text_col] = '\0'; |
| 506 | text_col = 0; |
| 507 | text_row = (text_row + 1) % text_rows; |
| 508 | if (text_row == text_top) text_top = (text_top + 1) % text_rows; |
| 509 | } |
| 510 | if (*ptr != '\n') text[text_row][text_col++] = *ptr; |
| 511 | } |
| 512 | text[text_row][text_col] = '\0'; |
| 513 | } |
| 514 | pthread_mutex_unlock(&updateMutex); |
| 515 | } |
| 516 | |
| 517 | void ScreenRecoveryUI::ShowFile(const char* filename) { |
| 518 | FILE* fp = fopen_path(filename, "re"); |
| 519 | if (fp == nullptr) { |
| 520 | Print(" Unable to open %s: %s\n", filename, strerror(errno)); |
| 521 | return; |
| 522 | } |
| 523 | |
| 524 | char line[1024]; |
| 525 | int ct = 0; |
| 526 | int key = 0; |
| 527 | while (fgets(line, sizeof(line), fp) != nullptr) { |
| 528 | print_no_update(line); |
| 529 | ct++; |
| 530 | if (ct % text_rows == 0) { |
| 531 | Redraw(); |
| 532 | |
| 533 | // give the user time to glance at the entries |
| 534 | key = WaitKey(); |
| 535 | |
| 536 | if (key == KEY_POWER) { |
| 537 | break; |
| 538 | } else if (key == KEY_VOLUMEUP) { |
| 539 | // Go back by seeking to the beginning and dumping ct - n |
| 540 | // lines. It's ugly, but this way we don't need to store |
| 541 | // the previous offsets. The files we're dumping here aren't |
| 542 | // expected to be very large. |
| 543 | ct -= 2 * text_rows; |
| 544 | if (ct < 0) { |
| 545 | ct = 0; |
| 546 | } |
| 547 | fseek(fp, 0, SEEK_SET); |
| 548 | for (int i = 0; i < ct; i++) { |
| 549 | fgets(line, sizeof(line), fp); |
| 550 | } |
| 551 | Print("^^^^^^^^^^\n"); |
| 552 | } else { |
| 553 | // Next page. |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | // If the user didn't abort, then give the user time to glance at |
| 559 | // the end of the log, sorry, no rewind here |
| 560 | if (key != KEY_POWER) { |
| 561 | Print("\n--END-- (press any key)\n"); |
| 562 | WaitKey(); |
| 563 | } |
| 564 | fclose(fp); |
| 565 | } |
| 566 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 567 | void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items, |
| 568 | int initial_selection) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 569 | pthread_mutex_lock(&updateMutex); |
| 570 | if (text_rows > 0 && text_cols > 0) { |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 571 | size_t i; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 572 | for (i = 0; i < text_rows; ++i) { |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 573 | if (headers[i] == nullptr) break; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 574 | strncpy(menu[i], headers[i], text_cols-1); |
| 575 | menu[i][text_cols-1] = '\0'; |
| 576 | } |
| 577 | menu_top = i; |
| 578 | for (; i < text_rows; ++i) { |
Elliott Hughes | aa0d6af | 2015-04-08 12:42:50 -0700 | [diff] [blame] | 579 | if (items[i-menu_top] == nullptr) break; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 580 | strncpy(menu[i], items[i-menu_top], text_cols-1); |
| 581 | menu[i][text_cols-1] = '\0'; |
| 582 | } |
| 583 | menu_items = i - menu_top; |
| 584 | show_menu = 1; |
| 585 | menu_sel = initial_selection; |
| 586 | update_screen_locked(); |
| 587 | } |
| 588 | pthread_mutex_unlock(&updateMutex); |
| 589 | } |
| 590 | |
| 591 | int ScreenRecoveryUI::SelectMenu(int sel) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 592 | pthread_mutex_lock(&updateMutex); |
| 593 | if (show_menu > 0) { |
Elliott Hughes | 01a4d08 | 2015-03-24 15:21:48 -0700 | [diff] [blame] | 594 | int old_sel = menu_sel; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 595 | menu_sel = sel; |
Elliott Hughes | fc06f87 | 2015-03-23 13:45:31 -0700 | [diff] [blame] | 596 | |
| 597 | // Wrap at top and bottom. |
| 598 | if (menu_sel < 0) menu_sel = menu_items - 1; |
| 599 | if (menu_sel >= menu_items) menu_sel = 0; |
| 600 | |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 601 | sel = menu_sel; |
| 602 | if (menu_sel != old_sel) update_screen_locked(); |
| 603 | } |
| 604 | pthread_mutex_unlock(&updateMutex); |
| 605 | return sel; |
| 606 | } |
| 607 | |
| 608 | void ScreenRecoveryUI::EndMenu() { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 609 | pthread_mutex_lock(&updateMutex); |
| 610 | if (show_menu > 0 && text_rows > 0 && text_cols > 0) { |
| 611 | show_menu = 0; |
| 612 | update_screen_locked(); |
| 613 | } |
| 614 | pthread_mutex_unlock(&updateMutex); |
| 615 | } |
| 616 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 617 | bool ScreenRecoveryUI::IsTextVisible() { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 618 | pthread_mutex_lock(&updateMutex); |
| 619 | int visible = show_text; |
| 620 | pthread_mutex_unlock(&updateMutex); |
| 621 | return visible; |
| 622 | } |
| 623 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 624 | bool ScreenRecoveryUI::WasTextEverVisible() { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 625 | pthread_mutex_lock(&updateMutex); |
| 626 | int ever_visible = show_text_ever; |
| 627 | pthread_mutex_unlock(&updateMutex); |
| 628 | return ever_visible; |
| 629 | } |
| 630 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 631 | void ScreenRecoveryUI::ShowText(bool visible) { |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 632 | pthread_mutex_lock(&updateMutex); |
| 633 | show_text = visible; |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 634 | if (show_text) show_text_ever = true; |
Doug Zongker | 211aebc | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 635 | update_screen_locked(); |
| 636 | pthread_mutex_unlock(&updateMutex); |
| 637 | } |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 638 | |
Elliott Hughes | 8de5207 | 2015-04-08 20:06:50 -0700 | [diff] [blame] | 639 | void ScreenRecoveryUI::Redraw() { |
Doug Zongker | c0441d1 | 2013-07-31 11:28:24 -0700 | [diff] [blame] | 640 | pthread_mutex_lock(&updateMutex); |
| 641 | update_screen_locked(); |
| 642 | pthread_mutex_unlock(&updateMutex); |
| 643 | } |
Elliott Hughes | 642aaa7 | 2015-04-10 12:47:46 -0700 | [diff] [blame] | 644 | |
| 645 | void ScreenRecoveryUI::KeyLongPress(int) { |
| 646 | // Redraw so that if we're in the menu, the highlight |
| 647 | // will change color to indicate a successful long press. |
| 648 | Redraw(); |
| 649 | } |