blob: a366bb3efa62a20cf18675a6f18fd44755d2c71b [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
Tao Bao736d59c2017-01-03 10:15:33 -080032#include <string>
Elliott Hughes95fc63e2015-04-10 19:12:01 -070033#include <vector>
34
Tianjie Xuc21edd42016-08-05 18:00:04 -070035#include <android-base/logging.h>
Elliott Hughescb220402016-09-23 15:30:55 -070036#include <android-base/properties.h>
Elliott Hughes4b166f02015-12-04 15:30:20 -080037#include <android-base/stringprintf.h>
Tao Baocb5524c2017-09-08 21:25:32 -070038#include <android-base/strings.h>
Tao Baob6918c72015-05-19 17:02:16 -070039
Doug Zongker211aebc2011-10-28 15:13:10 -070040#include "common.h"
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070041#include "device.h"
Doug Zongker32a0a472011-11-01 11:00:20 -070042#include "minui/minui.h"
43#include "screen_ui.h"
44#include "ui.h"
Doug Zongker211aebc2011-10-28 15:13:10 -070045
Doug Zongker211aebc2011-10-28 15:13:10 -070046// Return the current time as a double (including fractions of a second).
47static double now() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070048 struct timeval tv;
49 gettimeofday(&tv, nullptr);
50 return tv.tv_sec + tv.tv_usec / 1000000.0;
Doug Zongker211aebc2011-10-28 15:13:10 -070051}
52
Tao Bao736d59c2017-01-03 10:15:33 -080053ScreenRecoveryUI::ScreenRecoveryUI()
Tao Bao4521b702017-06-20 18:11:21 -070054 : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH),
55 kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT),
Tao Bao0470cee2017-08-02 17:11:04 -070056 kAnimationFps(RECOVERY_UI_ANIMATION_FPS),
Tao Bao75779652017-09-10 11:28:32 -070057 kDensity(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f),
Tao Bao171b4c42017-06-19 23:10:44 -070058 currentIcon(NONE),
Tao Bao736d59c2017-01-03 10:15:33 -080059 progressBarType(EMPTY),
60 progressScopeStart(0),
61 progressScopeSize(0),
62 progress(0),
63 pagesIdentical(false),
64 text_cols_(0),
65 text_rows_(0),
66 text_(nullptr),
67 text_col_(0),
68 text_row_(0),
Tao Bao736d59c2017-01-03 10:15:33 -080069 show_text(false),
70 show_text_ever(false),
Tao Baoe15d7a52017-09-07 13:38:51 -070071 menu_headers_(nullptr),
Tao Bao736d59c2017-01-03 10:15:33 -080072 show_menu(false),
73 menu_items(0),
74 menu_sel(0),
75 file_viewer_text_(nullptr),
76 intro_frames(0),
77 loop_frames(0),
78 current_frame(0),
79 intro_done(false),
Tao Bao736d59c2017-01-03 10:15:33 -080080 stage(-1),
81 max_stage(-1),
82 updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
Doug Zongker211aebc2011-10-28 15:13:10 -070083
Tao Bao99b2d772017-06-23 22:47:03 -070084GRSurface* ScreenRecoveryUI::GetCurrentFrame() const {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070085 if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
86 return intro_done ? loopFrames[current_frame] : introFrames[current_frame];
87 }
88 return error_icon;
Elliott Hughes498cda62016-04-14 16:49:04 -070089}
90
Tao Bao99b2d772017-06-23 22:47:03 -070091GRSurface* ScreenRecoveryUI::GetCurrentText() const {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070092 switch (currentIcon) {
93 case ERASING:
94 return erasing_text;
95 case ERROR:
96 return error_text;
97 case INSTALLING_UPDATE:
98 return installing_text;
99 case NO_COMMAND:
100 return no_command_text;
101 case NONE:
102 abort();
103 }
Elliott Hughes498cda62016-04-14 16:49:04 -0700104}
105
Mikhail Lappob49767c2017-03-23 21:44:26 +0100106int ScreenRecoveryUI::PixelsFromDp(int dp) const {
Tao Bao75779652017-09-10 11:28:32 -0700107 return dp * kDensity;
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700108}
109
110// Here's the intended layout:
111
Elliott Hughes6d089a92016-07-08 17:23:41 -0700112// | portrait large landscape large
113// ---------+-------------------------------------------------
Tao Bao3250f722017-06-29 14:32:05 -0700114// gap |
Elliott Hughes6d089a92016-07-08 17:23:41 -0700115// icon | (200dp)
116// gap | 68dp 68dp 56dp 112dp
117// text | (14sp)
118// gap | 32dp 32dp 26dp 52dp
119// progress | (2dp)
Tao Bao3250f722017-06-29 14:32:05 -0700120// gap |
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700121
Tao Bao3250f722017-06-29 14:32:05 -0700122// Note that "baseline" is actually the *top* of each icon (because that's how our drawing routines
123// work), so that's the more useful measurement for calling code. We use even top and bottom gaps.
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700124
Elliott Hughes6d089a92016-07-08 17:23:41 -0700125enum Layout { PORTRAIT = 0, PORTRAIT_LARGE = 1, LANDSCAPE = 2, LANDSCAPE_LARGE = 3, LAYOUT_MAX };
Tao Bao3250f722017-06-29 14:32:05 -0700126enum Dimension { TEXT = 0, ICON = 1, DIMENSION_MAX };
Elliott Hughes6d089a92016-07-08 17:23:41 -0700127static constexpr int kLayouts[LAYOUT_MAX][DIMENSION_MAX] = {
Tao Bao3250f722017-06-29 14:32:05 -0700128 { 32, 68, }, // PORTRAIT
129 { 32, 68, }, // PORTRAIT_LARGE
130 { 26, 56, }, // LANDSCAPE
131 { 52, 112, }, // LANDSCAPE_LARGE
Elliott Hughes6d089a92016-07-08 17:23:41 -0700132};
133
Tao Bao99b2d772017-06-23 22:47:03 -0700134int ScreenRecoveryUI::GetAnimationBaseline() const {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700135 return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) - gr_get_height(loopFrames[0]);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700136}
137
Tao Bao99b2d772017-06-23 22:47:03 -0700138int ScreenRecoveryUI::GetTextBaseline() const {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700139 return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) -
140 gr_get_height(installing_text);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700141}
142
Tao Bao99b2d772017-06-23 22:47:03 -0700143int ScreenRecoveryUI::GetProgressBaseline() const {
Tao Bao3250f722017-06-29 14:32:05 -0700144 int elements_sum = gr_get_height(loopFrames[0]) + PixelsFromDp(kLayouts[layout_][ICON]) +
145 gr_get_height(installing_text) + PixelsFromDp(kLayouts[layout_][TEXT]) +
146 gr_get_height(progressBarFill);
147 int bottom_gap = (gr_fb_height() - elements_sum) / 2;
148 return gr_fb_height() - bottom_gap - gr_get_height(progressBarFill);
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700149}
150
Doug Zongker211aebc2011-10-28 15:13:10 -0700151// Clear the screen and draw the currently selected background icon (if any).
152// Should only be called with updateMutex locked.
Elliott Hughes498cda62016-04-14 16:49:04 -0700153void ScreenRecoveryUI::draw_background_locked() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700154 pagesIdentical = false;
155 gr_color(0, 0, 0, 255);
156 gr_clear();
Doug Zongker211aebc2011-10-28 15:13:10 -0700157
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700158 if (currentIcon != NONE) {
159 if (max_stage != -1) {
160 int stage_height = gr_get_height(stageMarkerEmpty);
161 int stage_width = gr_get_width(stageMarkerEmpty);
162 int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
163 int y = gr_fb_height() - stage_height;
164 for (int i = 0; i < max_stage; ++i) {
165 GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
166 gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
167 x += stage_width;
168 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700169 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700170
171 GRSurface* text_surface = GetCurrentText();
172 int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
173 int text_y = GetTextBaseline();
174 gr_color(255, 255, 255, 255);
175 gr_texticon(text_x, text_y, text_surface);
176 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700177}
178
Tao Baoea78d862017-06-28 14:52:17 -0700179// Draws the animation and progress bar (if any) on the screen. Does not flip pages. Should only be
180// called with updateMutex locked.
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700181void ScreenRecoveryUI::draw_foreground_locked() {
Tao Bao736d59c2017-01-03 10:15:33 -0800182 if (currentIcon != NONE) {
183 GRSurface* frame = GetCurrentFrame();
184 int frame_width = gr_get_width(frame);
185 int frame_height = gr_get_height(frame);
186 int frame_x = (gr_fb_width() - frame_width) / 2;
187 int frame_y = GetAnimationBaseline();
188 gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
189 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700190
Tao Bao736d59c2017-01-03 10:15:33 -0800191 if (progressBarType != EMPTY) {
192 int width = gr_get_width(progressBarEmpty);
193 int height = gr_get_height(progressBarEmpty);
Doug Zongker211aebc2011-10-28 15:13:10 -0700194
Tao Bao736d59c2017-01-03 10:15:33 -0800195 int progress_x = (gr_fb_width() - width) / 2;
196 int progress_y = GetProgressBaseline();
Doug Zongker211aebc2011-10-28 15:13:10 -0700197
Tao Bao736d59c2017-01-03 10:15:33 -0800198 // Erase behind the progress bar (in case this was a progress-only update)
199 gr_color(0, 0, 0, 255);
200 gr_fill(progress_x, progress_y, width, height);
Doug Zongker211aebc2011-10-28 15:13:10 -0700201
Tao Bao736d59c2017-01-03 10:15:33 -0800202 if (progressBarType == DETERMINATE) {
203 float p = progressScopeStart + progress * progressScopeSize;
204 int pos = static_cast<int>(p * width);
Doug Zongker211aebc2011-10-28 15:13:10 -0700205
Tao Bao736d59c2017-01-03 10:15:33 -0800206 if (rtl_locale_) {
207 // Fill the progress bar from right to left.
208 if (pos > 0) {
209 gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
210 progress_y);
Doug Zongker211aebc2011-10-28 15:13:10 -0700211 }
Tao Bao736d59c2017-01-03 10:15:33 -0800212 if (pos < width - 1) {
213 gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
214 }
215 } else {
216 // Fill the progress bar from left to right.
217 if (pos > 0) {
218 gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
219 }
220 if (pos < width - 1) {
221 gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
222 }
223 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700224 }
Tao Bao736d59c2017-01-03 10:15:33 -0800225 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700226}
227
Tao Bao99b2d772017-06-23 22:47:03 -0700228void ScreenRecoveryUI::SetColor(UIElement e) const {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700229 switch (e) {
230 case INFO:
231 gr_color(249, 194, 0, 255);
232 break;
233 case HEADER:
234 gr_color(247, 0, 6, 255);
235 break;
236 case MENU:
237 case MENU_SEL_BG:
238 gr_color(0, 106, 157, 255);
239 break;
240 case MENU_SEL_BG_ACTIVE:
241 gr_color(0, 156, 100, 255);
242 break;
243 case MENU_SEL_FG:
244 gr_color(255, 255, 255, 255);
245 break;
246 case LOG:
247 gr_color(196, 196, 196, 255);
248 break;
249 case TEXT_FILL:
250 gr_color(0, 0, 0, 160);
251 break;
252 default:
253 gr_color(255, 255, 255, 255);
254 break;
255 }
Doug Zongkerc0441d12013-07-31 11:28:24 -0700256}
Doug Zongker211aebc2011-10-28 15:13:10 -0700257
Tao Baoea78d862017-06-28 14:52:17 -0700258int ScreenRecoveryUI::DrawHorizontalRule(int y) const {
259 gr_fill(0, y + 4, gr_fb_width(), y + 6);
260 return 8;
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700261}
262
Luke Songe2bd8762017-06-12 16:08:33 -0700263void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700264 gr_fill(x, y, x + width, y + height);
Luke Songe2bd8762017-06-12 16:08:33 -0700265}
266
Tao Baoea78d862017-06-28 14:52:17 -0700267int ScreenRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
268 gr_text(gr_sys_font(), x, y, line, bold);
269 return char_height_ + 4;
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700270}
271
Tao Baoea78d862017-06-28 14:52:17 -0700272int ScreenRecoveryUI::DrawTextLines(int x, int y, const char* const* lines) const {
273 int offset = 0;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700274 for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
Tao Baoea78d862017-06-28 14:52:17 -0700275 offset += DrawTextLine(x, y + offset, lines[i], false);
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700276 }
Tao Baoea78d862017-06-28 14:52:17 -0700277 return offset;
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700278}
279
Tao Bao2bbc6d62017-08-13 23:48:55 -0700280int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, const char* const* lines) const {
281 int offset = 0;
282 for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
283 // The line will be wrapped if it exceeds text_cols_.
284 std::string line(lines[i]);
285 size_t next_start = 0;
286 while (next_start < line.size()) {
287 std::string sub = line.substr(next_start, text_cols_ + 1);
288 if (sub.size() <= text_cols_) {
289 next_start += sub.size();
290 } else {
291 // Line too long and must be wrapped to text_cols_ columns.
292 size_t last_space = sub.find_last_of(" \t\n");
293 if (last_space == std::string::npos) {
294 // No space found, just draw as much as we can
295 sub.resize(text_cols_);
296 next_start += text_cols_;
297 } else {
298 sub.resize(last_space);
299 next_start += last_space + 1;
300 }
301 }
302 offset += DrawTextLine(x, y + offset, sub.c_str(), false);
303 }
304 }
305 return offset;
306}
307
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700308static const char* REGULAR_HELP[] = {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700309 "Use volume up/down and power.",
310 NULL
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700311};
312
313static const char* LONG_PRESS_HELP[] = {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700314 "Any button cycles highlight.",
315 "Long-press activates.",
316 NULL
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700317};
318
Tao Bao171b4c42017-06-19 23:10:44 -0700319// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
320// locked.
Elliott Hughes8de52072015-04-08 20:06:50 -0700321void ScreenRecoveryUI::draw_screen_locked() {
Tao Bao171b4c42017-06-19 23:10:44 -0700322 if (!show_text) {
323 draw_background_locked();
324 draw_foreground_locked();
325 return;
326 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700327
Tao Bao171b4c42017-06-19 23:10:44 -0700328 gr_color(0, 0, 0, 255);
329 gr_clear();
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700330
Tao Bao4521b702017-06-20 18:11:21 -0700331 int y = kMarginHeight;
Tao Bao171b4c42017-06-19 23:10:44 -0700332 if (show_menu) {
Tao Baoca6ce2c2017-07-13 11:15:27 -0700333 static constexpr int kMenuIndent = 4;
334 int x = kMarginWidth + kMenuIndent;
Elliott Hughes8fd86d72015-04-13 14:36:02 -0700335
Tao Bao171b4c42017-06-19 23:10:44 -0700336 SetColor(INFO);
Tao Baoea78d862017-06-28 14:52:17 -0700337 y += DrawTextLine(x, y, "Android Recovery", true);
Tao Baoca6ce2c2017-07-13 11:15:27 -0700338 std::string recovery_fingerprint =
339 android::base::GetProperty("ro.bootimage.build.fingerprint", "");
Tao Bao171b4c42017-06-19 23:10:44 -0700340 for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
Tao Baoea78d862017-06-28 14:52:17 -0700341 y += DrawTextLine(x, y, chunk.c_str(), false);
Doug Zongker211aebc2011-10-28 15:13:10 -0700342 }
Tao Baoea78d862017-06-28 14:52:17 -0700343 y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
Tao Bao171b4c42017-06-19 23:10:44 -0700344
345 SetColor(HEADER);
Tao Bao13aa4a92017-08-16 13:25:55 -0700346 // Ignore kMenuIndent, which is not taken into account by text_cols_.
347 y += DrawWrappedTextLines(kMarginWidth, y, menu_headers_);
Tao Bao171b4c42017-06-19 23:10:44 -0700348
349 SetColor(MENU);
Tao Baoea78d862017-06-28 14:52:17 -0700350 y += DrawHorizontalRule(y) + 4;
Tao Bao171b4c42017-06-19 23:10:44 -0700351 for (int i = 0; i < menu_items; ++i) {
352 if (i == menu_sel) {
353 // Draw the highlight bar.
354 SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
355 DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
356 // Bold white text for the selected item.
357 SetColor(MENU_SEL_FG);
Tao Baoe15d7a52017-09-07 13:38:51 -0700358 y += DrawTextLine(x, y, menu_[i].c_str(), true);
Tao Bao171b4c42017-06-19 23:10:44 -0700359 SetColor(MENU);
360 } else {
Tao Baoe15d7a52017-09-07 13:38:51 -0700361 y += DrawTextLine(x, y, menu_[i].c_str(), false);
Tao Bao171b4c42017-06-19 23:10:44 -0700362 }
363 }
Tao Baoea78d862017-06-28 14:52:17 -0700364 y += DrawHorizontalRule(y);
Tao Bao171b4c42017-06-19 23:10:44 -0700365 }
366
367 // Display from the bottom up, until we hit the top of the screen, the bottom of the menu, or
368 // we've displayed the entire text buffer.
369 SetColor(LOG);
Tao Baocb5524c2017-09-08 21:25:32 -0700370 int row = text_row_;
Tao Bao171b4c42017-06-19 23:10:44 -0700371 size_t count = 0;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700372 for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
373 ty -= char_height_, ++count) {
Tao Baoca6ce2c2017-07-13 11:15:27 -0700374 DrawTextLine(kMarginWidth, ty, text_[row], false);
Tao Bao171b4c42017-06-19 23:10:44 -0700375 --row;
376 if (row < 0) row = text_rows_ - 1;
377 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700378}
379
380// Redraw everything on the screen and flip the screen (make it visible).
381// Should only be called with updateMutex locked.
Elliott Hughes8de52072015-04-08 20:06:50 -0700382void ScreenRecoveryUI::update_screen_locked() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700383 draw_screen_locked();
384 gr_flip();
Doug Zongker211aebc2011-10-28 15:13:10 -0700385}
386
387// Updates only the progress bar, if possible, otherwise redraws the screen.
388// Should only be called with updateMutex locked.
Elliott Hughes8de52072015-04-08 20:06:50 -0700389void ScreenRecoveryUI::update_progress_locked() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700390 if (show_text || !pagesIdentical) {
391 draw_screen_locked(); // Must redraw the whole screen
392 pagesIdentical = true;
393 } else {
394 draw_foreground_locked(); // Draw only the progress bar and overlays
395 }
396 gr_flip();
Doug Zongker211aebc2011-10-28 15:13:10 -0700397}
398
399// Keeps the progress bar updated, even when the process is otherwise busy.
Elliott Hughes985022a2015-04-13 13:04:32 -0700400void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700401 reinterpret_cast<ScreenRecoveryUI*>(data)->ProgressThreadLoop();
402 return nullptr;
Doug Zongker32a0a472011-11-01 11:00:20 -0700403}
404
Elliott Hughes985022a2015-04-13 13:04:32 -0700405void ScreenRecoveryUI::ProgressThreadLoop() {
Tao Bao0470cee2017-08-02 17:11:04 -0700406 double interval = 1.0 / kAnimationFps;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700407 while (true) {
408 double start = now();
409 pthread_mutex_lock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700410
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700411 bool redraw = false;
Doug Zongker211aebc2011-10-28 15:13:10 -0700412
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700413 // update the installation animation, if active
414 // skip this if we have a text overlay (too expensive to update)
415 if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) {
416 if (!intro_done) {
417 if (current_frame == intro_frames - 1) {
418 intro_done = true;
419 current_frame = 0;
420 } else {
421 ++current_frame;
Doug Zongker211aebc2011-10-28 15:13:10 -0700422 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700423 } else {
424 current_frame = (current_frame + 1) % loop_frames;
425 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700426
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700427 redraw = true;
Doug Zongker211aebc2011-10-28 15:13:10 -0700428 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700429
430 // move the progress bar forward on timed intervals, if configured
431 int duration = progressScopeDuration;
432 if (progressBarType == DETERMINATE && duration > 0) {
433 double elapsed = now() - progressScopeTime;
434 float p = 1.0 * elapsed / duration;
435 if (p > 1.0) p = 1.0;
436 if (p > progress) {
437 progress = p;
438 redraw = true;
439 }
440 }
441
442 if (redraw) update_progress_locked();
443
444 pthread_mutex_unlock(&updateMutex);
445 double end = now();
446 // minimum of 20ms delay between frames
447 double delay = interval - (end - start);
448 if (delay < 0.02) delay = 0.02;
449 usleep(static_cast<useconds_t>(delay * 1000000));
450 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700451}
452
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700453void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700454 int result = res_create_display_surface(filename, surface);
455 if (result < 0) {
456 LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
457 }
Doug Zongkereac881c2014-03-07 09:21:25 -0800458}
459
Elliott Hughes0a5cb0c2015-04-15 10:58:56 -0700460void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) {
Tao Bao736d59c2017-01-03 10:15:33 -0800461 int result = res_create_localized_alpha_surface(filename, locale_.c_str(), surface);
462 if (result < 0) {
463 LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
464 }
Doug Zongker02ec6b82012-08-22 17:26:40 -0700465}
466
Elliott Hughesaa0d6af2015-04-08 12:42:50 -0700467static char** Alloc2d(size_t rows, size_t cols) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700468 char** result = new char*[rows];
469 for (size_t i = 0; i < rows; ++i) {
470 result[i] = new char[cols];
471 memset(result[i], 0, cols);
472 }
473 return result;
Elliott Hughesaa0d6af2015-04-08 12:42:50 -0700474}
475
Tianjie Xu35926c42016-04-28 18:06:26 -0700476// Choose the right background string to display during update.
477void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700478 if (security_update) {
479 LoadLocalizedBitmap("installing_security_text", &installing_text);
480 } else {
481 LoadLocalizedBitmap("installing_text", &installing_text);
482 }
483 Redraw();
Tianjie Xu35926c42016-04-28 18:06:26 -0700484}
485
Sen Jiangd5304492016-12-09 16:20:49 -0800486bool ScreenRecoveryUI::InitTextParams() {
Tao Bao171b4c42017-06-19 23:10:44 -0700487 if (gr_init() < 0) {
488 return false;
489 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700490
Tao Bao171b4c42017-06-19 23:10:44 -0700491 gr_font_size(gr_sys_font(), &char_width_, &char_height_);
Tao Bao4521b702017-06-20 18:11:21 -0700492 text_rows_ = (gr_fb_height() - kMarginHeight * 2) / char_height_;
493 text_cols_ = (gr_fb_width() - kMarginWidth * 2) / char_width_;
Tao Bao171b4c42017-06-19 23:10:44 -0700494 return true;
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -0700495}
496
Tao Bao736d59c2017-01-03 10:15:33 -0800497bool ScreenRecoveryUI::Init(const std::string& locale) {
498 RecoveryUI::Init(locale);
499 if (!InitTextParams()) {
500 return false;
501 }
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -0700502
Tao Bao736d59c2017-01-03 10:15:33 -0800503 // Are we portrait or landscape?
504 layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT;
505 // Are we the large variant of our base layout?
506 if (gr_fb_height() > PixelsFromDp(800)) ++layout_;
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700507
Tao Bao736d59c2017-01-03 10:15:33 -0800508 text_ = Alloc2d(text_rows_, text_cols_ + 1);
509 file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);
Doug Zongker55a36ac2013-03-04 15:49:02 -0800510
Tao Bao736d59c2017-01-03 10:15:33 -0800511 text_col_ = text_row_ = 0;
Doug Zongker211aebc2011-10-28 15:13:10 -0700512
Tao Bao736d59c2017-01-03 10:15:33 -0800513 LoadBitmap("icon_error", &error_icon);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700514
Tao Bao736d59c2017-01-03 10:15:33 -0800515 LoadBitmap("progress_empty", &progressBarEmpty);
516 LoadBitmap("progress_fill", &progressBarFill);
Elliott Hughes498cda62016-04-14 16:49:04 -0700517
Tao Bao736d59c2017-01-03 10:15:33 -0800518 LoadBitmap("stage_empty", &stageMarkerEmpty);
519 LoadBitmap("stage_fill", &stageMarkerFill);
Doug Zongker211aebc2011-10-28 15:13:10 -0700520
Tao Bao736d59c2017-01-03 10:15:33 -0800521 // Background text for "installing_update" could be "installing update"
522 // or "installing security update". It will be set after UI init according
523 // to commands in BCB.
524 installing_text = nullptr;
525 LoadLocalizedBitmap("erasing_text", &erasing_text);
526 LoadLocalizedBitmap("no_command_text", &no_command_text);
527 LoadLocalizedBitmap("error_text", &error_text);
Elliott Hughes498cda62016-04-14 16:49:04 -0700528
Tao Bao736d59c2017-01-03 10:15:33 -0800529 LoadAnimation();
Doug Zongker02ec6b82012-08-22 17:26:40 -0700530
Tao Bao736d59c2017-01-03 10:15:33 -0800531 pthread_create(&progress_thread_, nullptr, ProgressThreadStartRoutine, this);
Sen Jiangd5304492016-12-09 16:20:49 -0800532
Tao Bao736d59c2017-01-03 10:15:33 -0800533 return true;
Doug Zongker211aebc2011-10-28 15:13:10 -0700534}
535
Elliott Hughes498cda62016-04-14 16:49:04 -0700536void ScreenRecoveryUI::LoadAnimation() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700537 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir);
538 dirent* de;
539 std::vector<std::string> intro_frame_names;
540 std::vector<std::string> loop_frame_names;
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -0700541
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700542 while ((de = readdir(dir.get())) != nullptr) {
543 int value, num_chars;
544 if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) {
545 intro_frame_names.emplace_back(de->d_name, num_chars);
546 } else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) {
547 loop_frame_names.emplace_back(de->d_name, num_chars);
Elliott Hughes498cda62016-04-14 16:49:04 -0700548 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700549 }
Elliott Hughes498cda62016-04-14 16:49:04 -0700550
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700551 intro_frames = intro_frame_names.size();
552 loop_frames = loop_frame_names.size();
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -0700553
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700554 // It's okay to not have an intro.
555 if (intro_frames == 0) intro_done = true;
556 // But you must have an animation.
557 if (loop_frames == 0) abort();
Elliott Hughes498cda62016-04-14 16:49:04 -0700558
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700559 std::sort(intro_frame_names.begin(), intro_frame_names.end());
560 std::sort(loop_frame_names.begin(), loop_frame_names.end());
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -0700561
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700562 introFrames = new GRSurface*[intro_frames];
563 for (size_t i = 0; i < intro_frames; i++) {
564 LoadBitmap(intro_frame_names.at(i).c_str(), &introFrames[i]);
565 }
Elliott Hughes498cda62016-04-14 16:49:04 -0700566
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700567 loopFrames = new GRSurface*[loop_frames];
568 for (size_t i = 0; i < loop_frames; i++) {
569 LoadBitmap(loop_frame_names.at(i).c_str(), &loopFrames[i]);
570 }
Elliott Hughes498cda62016-04-14 16:49:04 -0700571}
572
Elliott Hughes8de52072015-04-08 20:06:50 -0700573void ScreenRecoveryUI::SetBackground(Icon icon) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700574 pthread_mutex_lock(&updateMutex);
Doug Zongker02ec6b82012-08-22 17:26:40 -0700575
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700576 currentIcon = icon;
577 update_screen_locked();
Doug Zongker52eeea4f2012-09-04 14:28:25 -0700578
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700579 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700580}
581
Elliott Hughes8de52072015-04-08 20:06:50 -0700582void ScreenRecoveryUI::SetProgressType(ProgressType type) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700583 pthread_mutex_lock(&updateMutex);
584 if (progressBarType != type) {
585 progressBarType = type;
586 }
587 progressScopeStart = 0;
588 progressScopeSize = 0;
589 progress = 0;
590 update_progress_locked();
591 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700592}
593
Elliott Hughes8de52072015-04-08 20:06:50 -0700594void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700595 pthread_mutex_lock(&updateMutex);
596 progressBarType = DETERMINATE;
597 progressScopeStart += progressScopeSize;
598 progressScopeSize = portion;
599 progressScopeTime = now();
600 progressScopeDuration = seconds;
601 progress = 0;
602 update_progress_locked();
603 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700604}
605
Elliott Hughes8de52072015-04-08 20:06:50 -0700606void ScreenRecoveryUI::SetProgress(float fraction) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700607 pthread_mutex_lock(&updateMutex);
608 if (fraction < 0.0) fraction = 0.0;
609 if (fraction > 1.0) fraction = 1.0;
610 if (progressBarType == DETERMINATE && fraction > progress) {
611 // Skip updates that aren't visibly different.
612 int width = gr_get_width(progressBarEmpty);
613 float scale = width * progressScopeSize;
614 if ((int)(progress * scale) != (int)(fraction * scale)) {
615 progress = fraction;
616 update_progress_locked();
Doug Zongker211aebc2011-10-28 15:13:10 -0700617 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700618 }
619 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700620}
621
Doug Zongkerc87bab12013-11-25 13:53:25 -0800622void ScreenRecoveryUI::SetStage(int current, int max) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700623 pthread_mutex_lock(&updateMutex);
624 stage = current;
625 max_stage = max;
626 pthread_mutex_unlock(&updateMutex);
Doug Zongkerc87bab12013-11-25 13:53:25 -0800627}
628
Tao Baob6918c72015-05-19 17:02:16 -0700629void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700630 std::string str;
631 android::base::StringAppendV(&str, fmt, ap);
Doug Zongker211aebc2011-10-28 15:13:10 -0700632
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700633 if (copy_to_stdout) {
634 fputs(str.c_str(), stdout);
635 }
Doug Zongker211aebc2011-10-28 15:13:10 -0700636
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700637 pthread_mutex_lock(&updateMutex);
638 if (text_rows_ > 0 && text_cols_ > 0) {
639 for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
640 if (*ptr == '\n' || text_col_ >= text_cols_) {
Elliott Hughesc0491632015-05-06 12:40:05 -0700641 text_[text_row_][text_col_] = '\0';
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700642 text_col_ = 0;
643 text_row_ = (text_row_ + 1) % text_rows_;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700644 }
645 if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
Doug Zongker211aebc2011-10-28 15:13:10 -0700646 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700647 text_[text_row_][text_col_] = '\0';
648 update_screen_locked();
649 }
650 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700651}
652
Tao Baob6918c72015-05-19 17:02:16 -0700653void ScreenRecoveryUI::Print(const char* fmt, ...) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700654 va_list ap;
655 va_start(ap, fmt);
656 PrintV(fmt, true, ap);
657 va_end(ap);
Tao Baob6918c72015-05-19 17:02:16 -0700658}
659
660void ScreenRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700661 va_list ap;
662 va_start(ap, fmt);
663 PrintV(fmt, false, ap);
664 va_end(ap);
Tao Baob6918c72015-05-19 17:02:16 -0700665}
666
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700667void ScreenRecoveryUI::PutChar(char ch) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700668 pthread_mutex_lock(&updateMutex);
669 if (ch != '\n') text_[text_row_][text_col_++] = ch;
670 if (ch == '\n' || text_col_ >= text_cols_) {
671 text_col_ = 0;
672 ++text_row_;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700673 }
674 pthread_mutex_unlock(&updateMutex);
Elliott Hughes8de52072015-04-08 20:06:50 -0700675}
676
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700677void ScreenRecoveryUI::ClearText() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700678 pthread_mutex_lock(&updateMutex);
679 text_col_ = 0;
680 text_row_ = 0;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700681 for (size_t i = 0; i < text_rows_; ++i) {
682 memset(text_[i], 0, text_cols_ + 1);
683 }
684 pthread_mutex_unlock(&updateMutex);
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700685}
686
687void ScreenRecoveryUI::ShowFile(FILE* fp) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700688 std::vector<off_t> offsets;
689 offsets.push_back(ftello(fp));
690 ClearText();
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700691
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700692 struct stat sb;
693 fstat(fileno(fp), &sb);
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700694
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700695 bool show_prompt = false;
696 while (true) {
697 if (show_prompt) {
698 PrintOnScreenOnly("--(%d%% of %d bytes)--",
699 static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
700 static_cast<int>(sb.st_size));
701 Redraw();
702 while (show_prompt) {
703 show_prompt = false;
704 int key = WaitKey();
705 if (key == KEY_POWER || key == KEY_ENTER) {
706 return;
707 } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
708 if (offsets.size() <= 1) {
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700709 show_prompt = true;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700710 } else {
711 offsets.pop_back();
712 fseek(fp, offsets.back(), SEEK_SET);
713 }
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700714 } else {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700715 if (feof(fp)) {
716 return;
717 }
718 offsets.push_back(ftello(fp));
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700719 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700720 }
721 ClearText();
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700722 }
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700723
724 int ch = getc(fp);
725 if (ch == EOF) {
726 while (text_row_ < text_rows_ - 1) PutChar('\n');
727 show_prompt = true;
728 } else {
729 PutChar(ch);
730 if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
731 show_prompt = true;
732 }
733 }
734 }
Elliott Hughes95fc63e2015-04-10 19:12:01 -0700735}
736
Elliott Hughes8de52072015-04-08 20:06:50 -0700737void ScreenRecoveryUI::ShowFile(const char* filename) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700738 FILE* fp = fopen_path(filename, "re");
739 if (fp == nullptr) {
740 Print(" Unable to open %s: %s\n", filename, strerror(errno));
741 return;
742 }
Elliott Hughesc0491632015-05-06 12:40:05 -0700743
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700744 char** old_text = text_;
745 size_t old_text_col = text_col_;
746 size_t old_text_row = text_row_;
Elliott Hughesc0491632015-05-06 12:40:05 -0700747
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700748 // Swap in the alternate screen and clear it.
749 text_ = file_viewer_text_;
750 ClearText();
Elliott Hughesc0491632015-05-06 12:40:05 -0700751
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700752 ShowFile(fp);
753 fclose(fp);
Elliott Hughesc0491632015-05-06 12:40:05 -0700754
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700755 text_ = old_text;
756 text_col_ = old_text_col;
757 text_row_ = old_text_row;
Elliott Hughes8de52072015-04-08 20:06:50 -0700758}
759
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700760void ScreenRecoveryUI::StartMenu(const char* const* headers, const char* const* items,
Doug Zongker211aebc2011-10-28 15:13:10 -0700761 int initial_selection) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700762 pthread_mutex_lock(&updateMutex);
763 if (text_rows_ > 0 && text_cols_ > 0) {
764 menu_headers_ = headers;
Tao Baoe15d7a52017-09-07 13:38:51 -0700765 menu_.clear();
766 for (size_t i = 0; i < text_rows_ && items[i] != nullptr; ++i) {
767 menu_.emplace_back(std::string(items[i], strnlen(items[i], text_cols_ - 1)));
Doug Zongker211aebc2011-10-28 15:13:10 -0700768 }
Tao Baoe15d7a52017-09-07 13:38:51 -0700769 menu_items = static_cast<int>(menu_.size());
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700770 show_menu = true;
771 menu_sel = initial_selection;
772 update_screen_locked();
773 }
774 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700775}
776
777int ScreenRecoveryUI::SelectMenu(int sel) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700778 pthread_mutex_lock(&updateMutex);
779 if (show_menu) {
780 int old_sel = menu_sel;
781 menu_sel = sel;
Elliott Hughesfc06f872015-03-23 13:45:31 -0700782
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700783 // Wrap at top and bottom.
784 if (menu_sel < 0) menu_sel = menu_items - 1;
785 if (menu_sel >= menu_items) menu_sel = 0;
Elliott Hughesfc06f872015-03-23 13:45:31 -0700786
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700787 sel = menu_sel;
788 if (menu_sel != old_sel) update_screen_locked();
789 }
790 pthread_mutex_unlock(&updateMutex);
791 return sel;
Doug Zongker211aebc2011-10-28 15:13:10 -0700792}
793
794void ScreenRecoveryUI::EndMenu() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700795 pthread_mutex_lock(&updateMutex);
796 if (show_menu && text_rows_ > 0 && text_cols_ > 0) {
797 show_menu = false;
798 update_screen_locked();
799 }
800 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700801}
802
Elliott Hughes8de52072015-04-08 20:06:50 -0700803bool ScreenRecoveryUI::IsTextVisible() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700804 pthread_mutex_lock(&updateMutex);
805 int visible = show_text;
806 pthread_mutex_unlock(&updateMutex);
807 return visible;
Doug Zongker211aebc2011-10-28 15:13:10 -0700808}
809
Elliott Hughes8de52072015-04-08 20:06:50 -0700810bool ScreenRecoveryUI::WasTextEverVisible() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700811 pthread_mutex_lock(&updateMutex);
812 int ever_visible = show_text_ever;
813 pthread_mutex_unlock(&updateMutex);
814 return ever_visible;
Doug Zongker211aebc2011-10-28 15:13:10 -0700815}
816
Elliott Hughes8de52072015-04-08 20:06:50 -0700817void ScreenRecoveryUI::ShowText(bool visible) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700818 pthread_mutex_lock(&updateMutex);
819 show_text = visible;
820 if (show_text) show_text_ever = true;
821 update_screen_locked();
822 pthread_mutex_unlock(&updateMutex);
Doug Zongker211aebc2011-10-28 15:13:10 -0700823}
Doug Zongkerc0441d12013-07-31 11:28:24 -0700824
Elliott Hughes8de52072015-04-08 20:06:50 -0700825void ScreenRecoveryUI::Redraw() {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700826 pthread_mutex_lock(&updateMutex);
827 update_screen_locked();
828 pthread_mutex_unlock(&updateMutex);
Doug Zongkerc0441d12013-07-31 11:28:24 -0700829}
Elliott Hughes642aaa72015-04-10 12:47:46 -0700830
831void ScreenRecoveryUI::KeyLongPress(int) {
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700832 // Redraw so that if we're in the menu, the highlight
833 // will change color to indicate a successful long press.
834 Redraw();
Elliott Hughes642aaa72015-04-10 12:47:46 -0700835}