blob: cfaecd922656afdf606c61d299547abdff456402 [file] [log] [blame]
Doug Zongker211aebc2011-10-28 15:13:10 -07001/*
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
Elliott Hughes498cda62016-04-14 16:49:04 -070017#include <dirent.h>
Doug Zongker211aebc2011-10-28 15:13:10 -070018#include <errno.h>
19#include <fcntl.h>
20#include <linux/input.h>
21#include <pthread.h>
22#include <stdarg.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/stat.h>
27#include <sys/time.h>
28#include <sys/types.h>
29#include <time.h>
30#include <unistd.h>
31
Elliott Hughes95fc63e2015-04-10 19:12:01 -070032#include <vector>
33
Tianjie Xu74778142016-08-05 18:00:04 -070034#include <android-base/logging.h>
Elliott Hughes4b166f02015-12-04 15:30:20 -080035#include <android-base/strings.h>
36#include <android-base/stringprintf.h>
Tao Baob6918c72015-05-19 17:02:16 -070037#include <cutils/properties.h>
38
Doug Zongker211aebc2011-10-28 15:13:10 -070039#include "common.h"
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070040#include "device.h"
Doug Zongker32a0a472011-11-01 11:00:20 -070041#include "minui/minui.h"
42#include "screen_ui.h"
43#include "ui.h"
Doug Zongker211aebc2011-10-28 15:13:10 -070044
Prashant Malani7a491222016-03-11 10:00:55 -080045#define TEXT_INDENT 4
Doug Zongker211aebc2011-10-28 15:13:10 -070046
Doug Zongker211aebc2011-10-28 15:13:10 -070047// Return the current time as a double (including fractions of a second).
48static double now() {
49 struct timeval tv;
Elliott Hughesaa0d6af2015-04-08 12:42:50 -070050 gettimeofday(&tv, nullptr);
Doug Zongker211aebc2011-10-28 15:13:10 -070051 return tv.tv_sec + tv.tv_usec / 1000000.0;
52}
53
54ScreenRecoveryUI::ScreenRecoveryUI() :
Prashant Malanif7f9e502016-03-10 03:40:20 +000055 currentIcon(NONE),
Elliott Hughesaa0d6af2015-04-08 12:42:50 -070056 locale(nullptr),
Elliott Hughes498cda62016-04-14 16:49:04 -070057 intro_done(false),
58 current_frame(0),
Doug Zongker211aebc2011-10-28 15:13:10 -070059 progressBarType(EMPTY),
60 progressScopeStart(0),
61 progressScopeSize(0),
62 progress(0),
63 pagesIdentical(false),
Elliott Hughesc0491632015-05-06 12:40:05 -070064 text_cols_(0),
65 text_rows_(0),
66 text_(nullptr),
67 text_col_(0),
68 text_row_(0),
69 text_top_(0),
Doug Zongker211aebc2011-10-28 15:13:10 -070070 show_text(false),
71 show_text_ever(false),
Elliott Hughesc0491632015-05-06 12:40:05 -070072 menu_(nullptr),
Doug Zongker211aebc2011-10-28 15:13:10 -070073 show_menu(false),
Doug Zongker211aebc2011-10-28 15:13:10 -070074 menu_items(0),
75 menu_sel(0),
Elliott Hughesc0491632015-05-06 12:40:05 -070076 file_viewer_text_(nullptr),
Elliott Hughes498cda62016-04-14 16:49:04 -070077 intro_frames(0),
78 loop_frames(0),
79 animation_fps(30), // TODO: there's currently no way to infer this.
Doug Zongkerc87bab12013-11-25 13:53:25 -080080 stage(-1),
Prashant Malani0ba21cf2016-03-10 14:51:25 -080081 max_stage(-1),
Elliott Hughesfaf36e02016-04-20 17:22:16 -070082 updateMutex(PTHREAD_MUTEX_INITIALIZER),
Prashant Malani0ba21cf2016-03-10 14:51:25 -080083 rtl_locale(false) {
Doug Zongker211aebc2011-10-28 15:13:10 -070084}
85
Elliott Hughes498cda62016-04-14 16:49:04 -070086GRSurface* ScreenRecoveryUI::GetCurrentFrame() {
87 if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
88 return intro_done ? loopFrames[current_frame] : introFrames[current_frame];
89 }
90 return error_icon;
91}
92
93GRSurface* ScreenRecoveryUI::GetCurrentText() {
94 switch (currentIcon) {
95 case ERASING: return erasing_text;
96 case ERROR: return error_text;
97 case INSTALLING_UPDATE: return installing_text;
98 case NO_COMMAND: return no_command_text;
99 case NONE: abort();
100 }
101}
102
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700103int ScreenRecoveryUI::PixelsFromDp(int dp) {
104 return dp * density_;
105}
106
107// Here's the intended layout:
108
Elliott Hughes6d089a92016-07-08 17:23:41 -0700109// | portrait large landscape large
110// ---------+-------------------------------------------------
111// gap | 220dp 366dp 142dp 284dp
112// icon | (200dp)
113// gap | 68dp 68dp 56dp 112dp
114// text | (14sp)
115// gap | 32dp 32dp 26dp 52dp
116// progress | (2dp)
117// gap | 194dp 340dp 131dp 262dp
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700118
119// Note that "baseline" is actually the *top* of each icon (because that's how our drawing
Elliott Hughesa3691042016-04-27 17:40:11 -0700120// routines work), so that's the more useful measurement for calling code.
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700121
Elliott Hughes6d089a92016-07-08 17:23:41 -0700122enum Layout { PORTRAIT = 0, PORTRAIT_LARGE = 1, LANDSCAPE = 2, LANDSCAPE_LARGE = 3, LAYOUT_MAX };
123enum Dimension { PROGRESS = 0, TEXT = 1, ICON = 2, DIMENSION_MAX };
124static constexpr int kLayouts[LAYOUT_MAX][DIMENSION_MAX] = {
125 { 194, 32, 68, }, // PORTRAIT
126 { 340, 32, 68, }, // PORTRAIT_LARGE
127 { 131, 26, 56, }, // LANDSCAPE
128 { 262, 52, 112, }, // LANDSCAPE_LARGE
129};
130
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700131int ScreenRecoveryUI::GetAnimationBaseline() {
Elliott Hughes6d089a92016-07-08 17:23:41 -0700132 return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) -
133 gr_get_height(loopFrames[0]);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700134}
135
136int ScreenRecoveryUI::GetTextBaseline() {
Elliott Hughes6d089a92016-07-08 17:23:41 -0700137 return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) -
138 gr_get_height(installing_text);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700139}
140
141int ScreenRecoveryUI::GetProgressBaseline() {
Elliott Hughes6d089a92016-07-08 17:23:41 -0700142 return gr_fb_height() - PixelsFromDp(kLayouts[layout_][PROGRESS]) -
143 gr_get_height(progressBarFill);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700144}
145
Doug Zongker211aebc2011-10-28 15:13:10 -0700146// Clear the screen and draw the currently selected background icon (if any).
147// Should only be called with updateMutex locked.
Elliott Hughes498cda62016-04-14 16:49:04 -0700148void ScreenRecoveryUI::draw_background_locked() {
Doug Zongker211aebc2011-10-28 15:13:10 -0700149 pagesIdentical = false;
Doug Zongker5b5f6c22014-06-03 10:50:13 -0700150 gr_color(0, 0, 0, 255);
Doug Zongker39cf4172014-03-06 16:16:05 -0800151 gr_clear();
Doug Zongker211aebc2011-10-28 15:13:10 -0700152
Elliott Hughes498cda62016-04-14 16:49:04 -0700153 if (currentIcon != NONE) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700154 if (max_stage != -1) {
155 int stage_height = gr_get_height(stageMarkerEmpty);
156 int stage_width = gr_get_width(stageMarkerEmpty);
Doug Zongkerc87bab12013-11-25 13:53:25 -0800157 int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700158 int y = gr_fb_height() - stage_height;
Doug Zongkerc87bab12013-11-25 13:53:25 -0800159 for (int i = 0; i < max_stage; ++i) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700160 GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
161 gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
162 x += stage_width;
Doug Zongkerc87bab12013-11-25 13:53:25 -0800163 }
164 }
165
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700166 GRSurface* text_surface = GetCurrentText();
167 int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
168 int text_y = GetTextBaseline();
Doug Zongker5b5f6c22014-06-03 10:50:13 -0700169 gr_color(255, 255, 255, 255);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700170 gr_texticon(text_x, text_y, text_surface);
Doug Zongker211aebc2011-10-28 15:13:10 -0700171 }
172}
173
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700174// Draws the animation and progress bar (if any) on the screen.
175// Does not flip pages.
Doug Zongker211aebc2011-10-28 15:13:10 -0700176// Should only be called with updateMutex locked.
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700177void ScreenRecoveryUI::draw_foreground_locked() {
178 if (currentIcon != NONE) {
Elliott Hughes498cda62016-04-14 16:49:04 -0700179 GRSurface* frame = GetCurrentFrame();
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700180 int frame_width = gr_get_width(frame);
181 int frame_height = gr_get_height(frame);
182 int frame_x = (gr_fb_width() - frame_width) / 2;
183 int frame_y = GetAnimationBaseline();
184 gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
Doug Zongker211aebc2011-10-28 15:13:10 -0700185 }
186
187 if (progressBarType != EMPTY) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700188 int width = gr_get_width(progressBarEmpty);
189 int height = gr_get_height(progressBarEmpty);
190
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700191 int progress_x = (gr_fb_width() - width)/2;
192 int progress_y = GetProgressBaseline();
Doug Zongker211aebc2011-10-28 15:13:10 -0700193
194 // Erase behind the progress bar (in case this was a progress-only update)
Doug Zongker5b5f6c22014-06-03 10:50:13 -0700195 gr_color(0, 0, 0, 255);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700196 gr_fill(progress_x, progress_y, width, height);
Doug Zongker211aebc2011-10-28 15:13:10 -0700197
198 if (progressBarType == DETERMINATE) {
199 float p = progressScopeStart + progress * progressScopeSize;
200 int pos = (int) (p * width);
201
Doug Zongker5fa8c232012-09-18 12:37:02 -0700202 if (rtl_locale) {
203 // Fill the progress bar from right to left.
204 if (pos > 0) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700205 gr_blit(progressBarFill, width-pos, 0, pos, height,
206 progress_x+width-pos, progress_y);
Doug Zongker5fa8c232012-09-18 12:37:02 -0700207 }
208 if (pos < width-1) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700209 gr_blit(progressBarEmpty, 0, 0, width-pos, height, progress_x, progress_y);
Doug Zongker5fa8c232012-09-18 12:37:02 -0700210 }
211 } else {
212 // Fill the progress bar from left to right.
213 if (pos > 0) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700214 gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
Doug Zongker5fa8c232012-09-18 12:37:02 -0700215 }
216 if (pos < width-1) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700217 gr_blit(progressBarEmpty, pos, 0, width-pos, height,
218 progress_x+pos, progress_y);
Doug Zongker5fa8c232012-09-18 12:37:02 -0700219 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700220 }
221 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700222 }
223}
224
Doug Zongkerc0441d12013-07-31 11:28:24 -0700225void ScreenRecoveryUI::SetColor(UIElement e) {
226 switch (e) {
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700227 case INFO:
228 gr_color(249, 194, 0, 255);
229 break;
Doug Zongkerc0441d12013-07-31 11:28:24 -0700230 case HEADER:
Doug Zongker5b5f6c22014-06-03 10:50:13 -0700231 gr_color(247, 0, 6, 255);
Doug Zongkerc0441d12013-07-31 11:28:24 -0700232 break;
233 case MENU:
234 case MENU_SEL_BG:
Doug Zongker5b5f6c22014-06-03 10:50:13 -0700235 gr_color(0, 106, 157, 255);
Doug Zongkerc0441d12013-07-31 11:28:24 -0700236 break;
Elliott Hughes642aaa72015-04-10 12:47:46 -0700237 case MENU_SEL_BG_ACTIVE:
238 gr_color(0, 156, 100, 255);
239 break;
Doug Zongkerc0441d12013-07-31 11:28:24 -0700240 case MENU_SEL_FG:
241 gr_color(255, 255, 255, 255);
242 break;
243 case LOG:
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700244 gr_color(196, 196, 196, 255);
Doug Zongker5b5f6c22014-06-03 10:50:13 -0700245 break;
246 case TEXT_FILL:
247 gr_color(0, 0, 0, 160);
Doug Zongkerc0441d12013-07-31 11:28:24 -0700248 break;
249 default:
250 gr_color(255, 255, 255, 255);
251 break;
252 }
253}
Doug Zongker211aebc2011-10-28 15:13:10 -0700254
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700255void ScreenRecoveryUI::DrawHorizontalRule(int* y) {
256 SetColor(MENU);
257 *y += 4;
258 gr_fill(0, *y, gr_fb_width(), *y + 2);
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700259 *y += 4;
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700260}
261
Prashant Malani7a491222016-03-11 10:00:55 -0800262void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) {
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700263 gr_text(gr_sys_font(), x, *y, line, bold);
Prashant Malani7a491222016-03-11 10:00:55 -0800264 *y += char_height_ + 4;
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700265}
266
Prashant Malani7a491222016-03-11 10:00:55 -0800267void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) {
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700268 for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
Prashant Malani7a491222016-03-11 10:00:55 -0800269 DrawTextLine(x, y, lines[i], false);
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700270 }
271}
272
273static const char* REGULAR_HELP[] = {
274 "Use volume up/down and power.",
275 NULL
276};
277
278static const char* LONG_PRESS_HELP[] = {
279 "Any button cycles highlight.",
280 "Long-press activates.",
281 NULL
282};
283
Doug Zongker211aebc2011-10-28 15:13:10 -0700284// Redraw everything on the screen. Does not flip pages.
285// Should only be called with updateMutex locked.
Elliott Hughes8de52072015-04-08 20:06:50 -0700286void ScreenRecoveryUI::draw_screen_locked() {
Doug Zongker39cf4172014-03-06 16:16:05 -0800287 if (!show_text) {
Elliott Hughes498cda62016-04-14 16:49:04 -0700288 draw_background_locked();
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700289 draw_foreground_locked();
Doug Zongker39cf4172014-03-06 16:16:05 -0800290 } else {
Doug Zongker5b5f6c22014-06-03 10:50:13 -0700291 gr_color(0, 0, 0, 255);
Doug Zongker39cf4172014-03-06 16:16:05 -0800292 gr_clear();
Doug Zongker211aebc2011-10-28 15:13:10 -0700293
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800294 int y = 0;
Doug Zongker211aebc2011-10-28 15:13:10 -0700295 if (show_menu) {
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700296 char recovery_fingerprint[PROPERTY_VALUE_MAX];
297 property_get("ro.bootimage.build.fingerprint", recovery_fingerprint, "");
298
299 SetColor(INFO);
Prashant Malani7a491222016-03-11 10:00:55 -0800300 DrawTextLine(TEXT_INDENT, &y, "Android Recovery", true);
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700301 for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
Prashant Malani7a491222016-03-11 10:00:55 -0800302 DrawTextLine(TEXT_INDENT, &y, chunk.c_str(), false);
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700303 }
Elliott Hughes498cda62016-04-14 16:49:04 -0700304 DrawTextLines(TEXT_INDENT, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700305
Doug Zongkerc0441d12013-07-31 11:28:24 -0700306 SetColor(HEADER);
Prashant Malani7a491222016-03-11 10:00:55 -0800307 DrawTextLines(TEXT_INDENT, &y, menu_headers_);
Doug Zongker211aebc2011-10-28 15:13:10 -0700308
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700309 SetColor(MENU);
310 DrawHorizontalRule(&y);
311 y += 4;
312 for (int i = 0; i < menu_items; ++i) {
313 if (i == menu_sel) {
314 // Draw the highlight bar.
Elliott Hughes642aaa72015-04-10 12:47:46 -0700315 SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
Prashant Malani7a491222016-03-11 10:00:55 -0800316 gr_fill(0, y - 2, gr_fb_width(), y + char_height_ + 2);
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700317 // Bold white text for the selected item.
Doug Zongkerc0441d12013-07-31 11:28:24 -0700318 SetColor(MENU_SEL_FG);
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700319 gr_text(gr_sys_font(), 4, y, menu_[i], true);
Doug Zongkerc0441d12013-07-31 11:28:24 -0700320 SetColor(MENU);
Doug Zongker211aebc2011-10-28 15:13:10 -0700321 } else {
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700322 gr_text(gr_sys_font(), 4, y, menu_[i], false);
Doug Zongker211aebc2011-10-28 15:13:10 -0700323 }
Prashant Malani7a491222016-03-11 10:00:55 -0800324 y += char_height_ + 4;
Doug Zongker211aebc2011-10-28 15:13:10 -0700325 }
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700326 DrawHorizontalRule(&y);
Doug Zongker211aebc2011-10-28 15:13:10 -0700327 }
328
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800329 // display from the bottom up, until we hit the top of the
330 // screen, the bottom of the menu, or we've displayed the
331 // entire text buffer.
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700332 SetColor(LOG);
Elliott Hughesc0491632015-05-06 12:40:05 -0700333 int row = (text_top_ + text_rows_ - 1) % text_rows_;
Elliott Hughesaa0d6af2015-04-08 12:42:50 -0700334 size_t count = 0;
Prashant Malani7a491222016-03-11 10:00:55 -0800335 for (int ty = gr_fb_height() - char_height_;
Elliott Hughesc0491632015-05-06 12:40:05 -0700336 ty >= y && count < text_rows_;
Prashant Malani7a491222016-03-11 10:00:55 -0800337 ty -= char_height_, ++count) {
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700338 gr_text(gr_sys_font(), 0, ty, text_[row], false);
Doug Zongker6fd59ac2013-03-06 15:01:11 -0800339 --row;
Elliott Hughesc0491632015-05-06 12:40:05 -0700340 if (row < 0) row = text_rows_ - 1;
Doug Zongker211aebc2011-10-28 15:13:10 -0700341 }
342 }
343}
344
345// Redraw everything on the screen and flip the screen (make it visible).
346// Should only be called with updateMutex locked.
Elliott Hughes8de52072015-04-08 20:06:50 -0700347void ScreenRecoveryUI::update_screen_locked() {
Doug Zongker211aebc2011-10-28 15:13:10 -0700348 draw_screen_locked();
349 gr_flip();
350}
351
352// Updates only the progress bar, if possible, otherwise redraws the screen.
353// Should only be called with updateMutex locked.
Elliott Hughes8de52072015-04-08 20:06:50 -0700354void ScreenRecoveryUI::update_progress_locked() {
Doug Zongker211aebc2011-10-28 15:13:10 -0700355 if (show_text || !pagesIdentical) {
356 draw_screen_locked(); // Must redraw the whole screen
357 pagesIdentical = true;
358 } else {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700359 draw_foreground_locked(); // Draw only the progress bar and overlays
Doug Zongker211aebc2011-10-28 15:13:10 -0700360 }
361 gr_flip();
362}
363
364// Keeps the progress bar updated, even when the process is otherwise busy.
Elliott Hughes985022a2015-04-13 13:04:32 -0700365void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) {
366 reinterpret_cast<ScreenRecoveryUI*>(data)->ProgressThreadLoop();
Elliott Hughesaa0d6af2015-04-08 12:42:50 -0700367 return nullptr;
Doug Zongker32a0a472011-11-01 11:00:20 -0700368}
369
Elliott Hughes985022a2015-04-13 13:04:32 -0700370void ScreenRecoveryUI::ProgressThreadLoop() {
Doug Zongker32a0a472011-11-01 11:00:20 -0700371 double interval = 1.0 / animation_fps;
Elliott Hughes985022a2015-04-13 13:04:32 -0700372 while (true) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700373 double start = now();
Doug Zongker32a0a472011-11-01 11:00:20 -0700374 pthread_mutex_lock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700375
Elliott Hughes498cda62016-04-14 16:49:04 -0700376 bool redraw = false;
Doug Zongker211aebc2011-10-28 15:13:10 -0700377
378 // update the installation animation, if active
379 // skip this if we have a text overlay (too expensive to update)
Elliott Hughes498cda62016-04-14 16:49:04 -0700380 if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) {
381 if (!intro_done) {
382 if (current_frame == intro_frames - 1) {
383 intro_done = true;
384 current_frame = 0;
385 } else {
386 ++current_frame;
387 }
388 } else {
389 current_frame = (current_frame + 1) % loop_frames;
390 }
391
392 redraw = true;
Doug Zongker211aebc2011-10-28 15:13:10 -0700393 }
394
Doug Zongker211aebc2011-10-28 15:13:10 -0700395 // move the progress bar forward on timed intervals, if configured
Doug Zongker32a0a472011-11-01 11:00:20 -0700396 int duration = progressScopeDuration;
397 if (progressBarType == DETERMINATE && duration > 0) {
398 double elapsed = now() - progressScopeTime;
Doug Zongker69f4b672012-04-26 14:37:53 -0700399 float p = 1.0 * elapsed / duration;
400 if (p > 1.0) p = 1.0;
401 if (p > progress) {
402 progress = p;
Elliott Hughes498cda62016-04-14 16:49:04 -0700403 redraw = true;
Doug Zongker211aebc2011-10-28 15:13:10 -0700404 }
405 }
406
Doug Zongker32a0a472011-11-01 11:00:20 -0700407 if (redraw) update_progress_locked();
Doug Zongker211aebc2011-10-28 15:13:10 -0700408
Doug Zongker32a0a472011-11-01 11:00:20 -0700409 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700410 double end = now();
411 // minimum of 20ms delay between frames
412 double delay = interval - (end-start);
413 if (delay < 0.02) delay = 0.02;
Chih-Hung Hsieh54a27472016-04-18 11:30:55 -0700414 usleep(static_cast<useconds_t>(delay * 1000000));
Doug Zongker211aebc2011-10-28 15:13:10 -0700415 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700416}
417
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700418void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700419 int result = res_create_display_surface(filename, surface);
Doug Zongker211aebc2011-10-28 15:13:10 -0700420 if (result < 0) {
Tianjie Xu74778142016-08-05 18:00:04 -0700421 LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
Doug Zongkereac881c2014-03-07 09:21:25 -0800422 }
423}
424
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700425void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) {
Doug Zongkera418aa72014-03-17 12:10:02 -0700426 int result = res_create_localized_alpha_surface(filename, locale, surface);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700427 if (result < 0) {
Tianjie Xu74778142016-08-05 18:00:04 -0700428 LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
Doug Zongker02ec6b82012-08-22 17:26:40 -0700429 }
430}
431
Elliott Hughesaa0d6af2015-04-08 12:42:50 -0700432static char** Alloc2d(size_t rows, size_t cols) {
433 char** result = new char*[rows];
434 for (size_t i = 0; i < rows; ++i) {
435 result[i] = new char[cols];
436 memset(result[i], 0, cols);
437 }
438 return result;
439}
440
Tianjie Xu35926c42016-04-28 18:06:26 -0700441// Choose the right background string to display during update.
442void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
443 if (security_update) {
444 LoadLocalizedBitmap("installing_security_text", &installing_text);
445 } else {
446 LoadLocalizedBitmap("installing_text", &installing_text);
447 }
448 Redraw();
449}
450
Elliott Hughes8de52072015-04-08 20:06:50 -0700451void ScreenRecoveryUI::Init() {
Doug Zongker211aebc2011-10-28 15:13:10 -0700452 gr_init();
Doug Zongker211aebc2011-10-28 15:13:10 -0700453
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700454 density_ = static_cast<float>(property_get_int32("ro.sf.lcd_density", 160)) / 160.f;
Elliott Hughes6d089a92016-07-08 17:23:41 -0700455
456 // Are we portrait or landscape?
457 layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT;
458 // Are we the large variant of our base layout?
459 if (gr_fb_height() > PixelsFromDp(800)) ++layout_;
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700460
Damien Bargiacchi35fff612016-08-11 15:57:03 -0700461 gr_font_size(gr_sys_font(), &char_width_, &char_height_);
Prashant Malani7a491222016-03-11 10:00:55 -0800462 text_rows_ = gr_fb_height() / char_height_;
463 text_cols_ = gr_fb_width() / char_width_;
Elliott Hughesaa0d6af2015-04-08 12:42:50 -0700464
Elliott Hughesc0491632015-05-06 12:40:05 -0700465 text_ = Alloc2d(text_rows_, text_cols_ + 1);
466 file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);
467 menu_ = Alloc2d(text_rows_, text_cols_ + 1);
Doug Zongker55a36ac2013-03-04 15:49:02 -0800468
Elliott Hughesc0491632015-05-06 12:40:05 -0700469 text_col_ = text_row_ = 0;
470 text_top_ = 1;
Doug Zongker211aebc2011-10-28 15:13:10 -0700471
Elliott Hughes498cda62016-04-14 16:49:04 -0700472 LoadBitmap("icon_error", &error_icon);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700473
Doug Zongker211aebc2011-10-28 15:13:10 -0700474 LoadBitmap("progress_empty", &progressBarEmpty);
475 LoadBitmap("progress_fill", &progressBarFill);
Elliott Hughes498cda62016-04-14 16:49:04 -0700476
Doug Zongkerc87bab12013-11-25 13:53:25 -0800477 LoadBitmap("stage_empty", &stageMarkerEmpty);
478 LoadBitmap("stage_fill", &stageMarkerFill);
Doug Zongker211aebc2011-10-28 15:13:10 -0700479
Tianjie Xu35926c42016-04-28 18:06:26 -0700480 // Background text for "installing_update" could be "installing update"
481 // or "installing security update". It will be set after UI init according
482 // to commands in BCB.
483 installing_text = nullptr;
Elliott Hughes498cda62016-04-14 16:49:04 -0700484 LoadLocalizedBitmap("erasing_text", &erasing_text);
485 LoadLocalizedBitmap("no_command_text", &no_command_text);
486 LoadLocalizedBitmap("error_text", &error_text);
487
488 LoadAnimation();
Doug Zongker02ec6b82012-08-22 17:26:40 -0700489
Elliott Hughes985022a2015-04-13 13:04:32 -0700490 pthread_create(&progress_thread_, nullptr, ProgressThreadStartRoutine, this);
Doug Zongker32a0a472011-11-01 11:00:20 -0700491
492 RecoveryUI::Init();
Doug Zongker211aebc2011-10-28 15:13:10 -0700493}
494
Elliott Hughes498cda62016-04-14 16:49:04 -0700495void ScreenRecoveryUI::LoadAnimation() {
496 // How many frames of intro and loop do we have?
497 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir);
498 dirent* de;
499 while ((de = readdir(dir.get())) != nullptr) {
500 int value;
501 if (sscanf(de->d_name, "intro%d", &value) == 1 && intro_frames < (value + 1)) {
502 intro_frames = value + 1;
503 } else if (sscanf(de->d_name, "loop%d", &value) == 1 && loop_frames < (value + 1)) {
504 loop_frames = value + 1;
505 }
506 }
507
508 // It's okay to not have an intro.
509 if (intro_frames == 0) intro_done = true;
510 // But you must have an animation.
511 if (loop_frames == 0) abort();
512
513 introFrames = new GRSurface*[intro_frames];
514 for (int i = 0; i < intro_frames; ++i) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700515 // TODO: remember the names above, so we don't have to hard-code the number of 0s.
516 LoadBitmap(android::base::StringPrintf("intro%05d", i).c_str(), &introFrames[i]);
Elliott Hughes498cda62016-04-14 16:49:04 -0700517 }
518
519 loopFrames = new GRSurface*[loop_frames];
520 for (int i = 0; i < loop_frames; ++i) {
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700521 LoadBitmap(android::base::StringPrintf("loop%05d", i).c_str(), &loopFrames[i]);
Elliott Hughes498cda62016-04-14 16:49:04 -0700522 }
523}
524
Doug Zongkera418aa72014-03-17 12:10:02 -0700525void ScreenRecoveryUI::SetLocale(const char* new_locale) {
Elliott Hughes498cda62016-04-14 16:49:04 -0700526 this->locale = new_locale;
527 this->rtl_locale = false;
528
529 if (locale) {
Doug Zongker5fa8c232012-09-18 12:37:02 -0700530 char* lang = strdup(locale);
531 for (char* p = lang; *p; ++p) {
532 if (*p == '_') {
533 *p = '\0';
534 break;
535 }
536 }
537
Elliott Hughes498cda62016-04-14 16:49:04 -0700538 // A bit cheesy: keep an explicit list of supported RTL languages.
Doug Zongker5fa8c232012-09-18 12:37:02 -0700539 if (strcmp(lang, "ar") == 0 || // Arabic
540 strcmp(lang, "fa") == 0 || // Persian (Farsi)
541 strcmp(lang, "he") == 0 || // Hebrew (new language code)
Doug Zongkerb66cb692012-09-18 14:52:18 -0700542 strcmp(lang, "iw") == 0 || // Hebrew (old language code)
543 strcmp(lang, "ur") == 0) { // Urdu
Doug Zongker5fa8c232012-09-18 12:37:02 -0700544 rtl_locale = true;
545 }
546 free(lang);
547 }
548}
549
Elliott Hughes8de52072015-04-08 20:06:50 -0700550void ScreenRecoveryUI::SetBackground(Icon icon) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700551 pthread_mutex_lock(&updateMutex);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700552
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700553 currentIcon = icon;
554 update_screen_locked();
555
Doug Zongker211aebc2011-10-28 15:13:10 -0700556 pthread_mutex_unlock(&updateMutex);
557}
558
Elliott Hughes8de52072015-04-08 20:06:50 -0700559void ScreenRecoveryUI::SetProgressType(ProgressType type) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700560 pthread_mutex_lock(&updateMutex);
561 if (progressBarType != type) {
562 progressBarType = type;
Doug Zongker211aebc2011-10-28 15:13:10 -0700563 }
Doug Zongker69f4b672012-04-26 14:37:53 -0700564 progressScopeStart = 0;
Doug Zongker239ac6a2013-08-20 16:03:25 -0700565 progressScopeSize = 0;
Doug Zongker69f4b672012-04-26 14:37:53 -0700566 progress = 0;
Doug Zongker239ac6a2013-08-20 16:03:25 -0700567 update_progress_locked();
Doug Zongker211aebc2011-10-28 15:13:10 -0700568 pthread_mutex_unlock(&updateMutex);
569}
570
Elliott Hughes8de52072015-04-08 20:06:50 -0700571void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700572 pthread_mutex_lock(&updateMutex);
573 progressBarType = DETERMINATE;
574 progressScopeStart += progressScopeSize;
575 progressScopeSize = portion;
576 progressScopeTime = now();
577 progressScopeDuration = seconds;
578 progress = 0;
579 update_progress_locked();
580 pthread_mutex_unlock(&updateMutex);
581}
582
Elliott Hughes8de52072015-04-08 20:06:50 -0700583void ScreenRecoveryUI::SetProgress(float fraction) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700584 pthread_mutex_lock(&updateMutex);
585 if (fraction < 0.0) fraction = 0.0;
586 if (fraction > 1.0) fraction = 1.0;
587 if (progressBarType == DETERMINATE && fraction > progress) {
588 // Skip updates that aren't visibly different.
Doug Zongkereac881c2014-03-07 09:21:25 -0800589 int width = gr_get_width(progressBarEmpty);
Doug Zongker211aebc2011-10-28 15:13:10 -0700590 float scale = width * progressScopeSize;
591 if ((int) (progress * scale) != (int) (fraction * scale)) {
592 progress = fraction;
593 update_progress_locked();
594 }
595 }
596 pthread_mutex_unlock(&updateMutex);
597}
598
Doug Zongkerc87bab12013-11-25 13:53:25 -0800599void ScreenRecoveryUI::SetStage(int current, int max) {
600 pthread_mutex_lock(&updateMutex);
601 stage = current;
602 max_stage = max;
603 pthread_mutex_unlock(&updateMutex);
604}
605
Tao Baob6918c72015-05-19 17:02:16 -0700606void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
607 std::string str;
608 android::base::StringAppendV(&str, fmt, ap);
Doug Zongker211aebc2011-10-28 15:13:10 -0700609
Tao Baob6918c72015-05-19 17:02:16 -0700610 if (copy_to_stdout) {
611 fputs(str.c_str(), stdout);
612 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700613
Doug Zongker211aebc2011-10-28 15:13:10 -0700614 pthread_mutex_lock(&updateMutex);
Elliott Hughesc0491632015-05-06 12:40:05 -0700615 if (text_rows_ > 0 && text_cols_ > 0) {
Tao Baob6918c72015-05-19 17:02:16 -0700616 for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
Elliott Hughesc0491632015-05-06 12:40:05 -0700617 if (*ptr == '\n' || text_col_ >= text_cols_) {
618 text_[text_row_][text_col_] = '\0';
619 text_col_ = 0;
620 text_row_ = (text_row_ + 1) % text_rows_;
621 if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
Doug Zongker211aebc2011-10-28 15:13:10 -0700622 }
Elliott Hughesc0491632015-05-06 12:40:05 -0700623 if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
Doug Zongker211aebc2011-10-28 15:13:10 -0700624 }
Elliott Hughesc0491632015-05-06 12:40:05 -0700625 text_[text_row_][text_col_] = '\0';
Doug Zongker211aebc2011-10-28 15:13:10 -0700626 update_screen_locked();
627 }
628 pthread_mutex_unlock(&updateMutex);
629}
630
Tao Baob6918c72015-05-19 17:02:16 -0700631void ScreenRecoveryUI::Print(const char* fmt, ...) {
632 va_list ap;
633 va_start(ap, fmt);
634 PrintV(fmt, true, ap);
635 va_end(ap);
636}
637
638void ScreenRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
639 va_list ap;
640 va_start(ap, fmt);
641 PrintV(fmt, false, ap);
642 va_end(ap);
643}
644
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700645void ScreenRecoveryUI::PutChar(char ch) {
Elliott Hughes8de52072015-04-08 20:06:50 -0700646 pthread_mutex_lock(&updateMutex);
Elliott Hughesc0491632015-05-06 12:40:05 -0700647 if (ch != '\n') text_[text_row_][text_col_++] = ch;
648 if (ch == '\n' || text_col_ >= text_cols_) {
649 text_col_ = 0;
650 ++text_row_;
651
652 if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
Elliott Hughes8de52072015-04-08 20:06:50 -0700653 }
654 pthread_mutex_unlock(&updateMutex);
655}
656
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700657void ScreenRecoveryUI::ClearText() {
658 pthread_mutex_lock(&updateMutex);
Elliott Hughesc0491632015-05-06 12:40:05 -0700659 text_col_ = 0;
660 text_row_ = 0;
661 text_top_ = 1;
662 for (size_t i = 0; i < text_rows_; ++i) {
663 memset(text_[i], 0, text_cols_ + 1);
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700664 }
665 pthread_mutex_unlock(&updateMutex);
666}
667
668void ScreenRecoveryUI::ShowFile(FILE* fp) {
Chih-Hung Hsieh54a27472016-04-18 11:30:55 -0700669 std::vector<off_t> offsets;
670 offsets.push_back(ftello(fp));
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700671 ClearText();
672
673 struct stat sb;
674 fstat(fileno(fp), &sb);
675
676 bool show_prompt = false;
677 while (true) {
678 if (show_prompt) {
Tao Bao9a7fd802015-09-10 13:33:58 -0700679 PrintOnScreenOnly("--(%d%% of %d bytes)--",
Chih-Hung Hsieh54a27472016-04-18 11:30:55 -0700680 static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700681 static_cast<int>(sb.st_size));
682 Redraw();
683 while (show_prompt) {
684 show_prompt = false;
685 int key = WaitKey();
Elliott Hughes300ed082015-04-13 10:47:59 -0700686 if (key == KEY_POWER || key == KEY_ENTER) {
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700687 return;
688 } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
689 if (offsets.size() <= 1) {
690 show_prompt = true;
691 } else {
692 offsets.pop_back();
693 fseek(fp, offsets.back(), SEEK_SET);
694 }
695 } else {
696 if (feof(fp)) {
697 return;
698 }
Chih-Hung Hsieh54a27472016-04-18 11:30:55 -0700699 offsets.push_back(ftello(fp));
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700700 }
701 }
702 ClearText();
703 }
704
705 int ch = getc(fp);
706 if (ch == EOF) {
Elliott Hughesc0491632015-05-06 12:40:05 -0700707 while (text_row_ < text_rows_ - 1) PutChar('\n');
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700708 show_prompt = true;
709 } else {
710 PutChar(ch);
Elliott Hughesc0491632015-05-06 12:40:05 -0700711 if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700712 show_prompt = true;
713 }
714 }
715 }
716}
717
Elliott Hughes8de52072015-04-08 20:06:50 -0700718void ScreenRecoveryUI::ShowFile(const char* filename) {
719 FILE* fp = fopen_path(filename, "re");
720 if (fp == nullptr) {
721 Print(" Unable to open %s: %s\n", filename, strerror(errno));
722 return;
723 }
Elliott Hughesc0491632015-05-06 12:40:05 -0700724
725 char** old_text = text_;
726 size_t old_text_col = text_col_;
727 size_t old_text_row = text_row_;
728 size_t old_text_top = text_top_;
729
730 // Swap in the alternate screen and clear it.
731 text_ = file_viewer_text_;
732 ClearText();
733
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700734 ShowFile(fp);
Elliott Hughes8de52072015-04-08 20:06:50 -0700735 fclose(fp);
Elliott Hughesc0491632015-05-06 12:40:05 -0700736
737 text_ = old_text;
738 text_col_ = old_text_col;
739 text_row_ = old_text_row;
740 text_top_ = old_text_top;
Elliott Hughes8de52072015-04-08 20:06:50 -0700741}
742
Doug Zongker211aebc2011-10-28 15:13:10 -0700743void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
744 int initial_selection) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700745 pthread_mutex_lock(&updateMutex);
Elliott Hughesc0491632015-05-06 12:40:05 -0700746 if (text_rows_ > 0 && text_cols_ > 0) {
747 menu_headers_ = headers;
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700748 size_t i = 0;
Elliott Hughesc0491632015-05-06 12:40:05 -0700749 for (; i < text_rows_ && items[i] != nullptr; ++i) {
750 strncpy(menu_[i], items[i], text_cols_ - 1);
751 menu_[i][text_cols_ - 1] = '\0';
Doug Zongker211aebc2011-10-28 15:13:10 -0700752 }
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700753 menu_items = i;
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700754 show_menu = true;
Doug Zongker211aebc2011-10-28 15:13:10 -0700755 menu_sel = initial_selection;
756 update_screen_locked();
757 }
758 pthread_mutex_unlock(&updateMutex);
759}
760
761int ScreenRecoveryUI::SelectMenu(int sel) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700762 pthread_mutex_lock(&updateMutex);
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700763 if (show_menu) {
Elliott Hughes01a4d082015-03-24 15:21:48 -0700764 int old_sel = menu_sel;
Doug Zongker211aebc2011-10-28 15:13:10 -0700765 menu_sel = sel;
Elliott Hughesfc06f872015-03-23 13:45:31 -0700766
767 // Wrap at top and bottom.
768 if (menu_sel < 0) menu_sel = menu_items - 1;
769 if (menu_sel >= menu_items) menu_sel = 0;
770
Doug Zongker211aebc2011-10-28 15:13:10 -0700771 sel = menu_sel;
772 if (menu_sel != old_sel) update_screen_locked();
773 }
774 pthread_mutex_unlock(&updateMutex);
775 return sel;
776}
777
778void ScreenRecoveryUI::EndMenu() {
Doug Zongker211aebc2011-10-28 15:13:10 -0700779 pthread_mutex_lock(&updateMutex);
Elliott Hughesc0491632015-05-06 12:40:05 -0700780 if (show_menu && text_rows_ > 0 && text_cols_ > 0) {
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700781 show_menu = false;
Doug Zongker211aebc2011-10-28 15:13:10 -0700782 update_screen_locked();
783 }
784 pthread_mutex_unlock(&updateMutex);
785}
786
Elliott Hughes8de52072015-04-08 20:06:50 -0700787bool ScreenRecoveryUI::IsTextVisible() {
Doug Zongker211aebc2011-10-28 15:13:10 -0700788 pthread_mutex_lock(&updateMutex);
789 int visible = show_text;
790 pthread_mutex_unlock(&updateMutex);
791 return visible;
792}
793
Elliott Hughes8de52072015-04-08 20:06:50 -0700794bool ScreenRecoveryUI::WasTextEverVisible() {
Doug Zongker211aebc2011-10-28 15:13:10 -0700795 pthread_mutex_lock(&updateMutex);
796 int ever_visible = show_text_ever;
797 pthread_mutex_unlock(&updateMutex);
798 return ever_visible;
799}
800
Elliott Hughes8de52072015-04-08 20:06:50 -0700801void ScreenRecoveryUI::ShowText(bool visible) {
Doug Zongker211aebc2011-10-28 15:13:10 -0700802 pthread_mutex_lock(&updateMutex);
803 show_text = visible;
Elliott Hughes8de52072015-04-08 20:06:50 -0700804 if (show_text) show_text_ever = true;
Doug Zongker211aebc2011-10-28 15:13:10 -0700805 update_screen_locked();
806 pthread_mutex_unlock(&updateMutex);
807}
Doug Zongkerc0441d12013-07-31 11:28:24 -0700808
Elliott Hughes8de52072015-04-08 20:06:50 -0700809void ScreenRecoveryUI::Redraw() {
Doug Zongkerc0441d12013-07-31 11:28:24 -0700810 pthread_mutex_lock(&updateMutex);
811 update_screen_locked();
812 pthread_mutex_unlock(&updateMutex);
813}
Elliott Hughes642aaa72015-04-10 12:47:46 -0700814
815void ScreenRecoveryUI::KeyLongPress(int) {
816 // Redraw so that if we're in the menu, the highlight
817 // will change color to indicate a successful long press.
818 Redraw();
819}