aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-09-05 17:27:41 -0500
committerTao Bao2017-09-08 14:22:43 -0500
commitf05e2bcff297a5735e75e50ba42fc9c7098a579e (patch)
tree47f3aa2b641e12f035183eea60a15d3d60a9a16c /wear_ui.cpp
parent8c753f62538b2008e726c66def9bf47aeed7afe1 (diff)
downloadplatform-bootable-recovery-f05e2bcff297a5735e75e50ba42fc9c7098a579e.tar.gz
platform-bootable-recovery-f05e2bcff297a5735e75e50ba42fc9c7098a579e.tar.xz
platform-bootable-recovery-f05e2bcff297a5735e75e50ba42fc9c7098a579e.zip
wear_ui: Remove Print()/ShowFile()/PutChar().
They're mostly identical to the ones in ScreenRecoveryUI, except for the (legacy) use of 'text_top_'. Because wear_ui.cpp misses the change in [1] that uses an alternate screen for viewing recovery logs. Also clean up the included headers. [1] commit c049163234003ef463bca018920622bc8269c69b ('Add an alternate screen for viewing recovery logs.'). Test: Build a wearable target recovery; `View recovery logs`. Change-Id: Ic9208c42a11c037469f5b073ef7d9b721c14d1f3
Diffstat (limited to 'wear_ui.cpp')
-rw-r--r--wear_ui.cpp114
1 files changed, 1 insertions, 113 deletions
diff --git a/wear_ui.cpp b/wear_ui.cpp
index 670050a0..1e8e7ba0 100644
--- a/wear_ui.cpp
+++ b/wear_ui.cpp
@@ -16,29 +16,16 @@
16 16
17#include "wear_ui.h" 17#include "wear_ui.h"
18 18
19#include <errno.h>
20#include <fcntl.h>
21#include <pthread.h> 19#include <pthread.h>
22#include <stdarg.h> 20#include <stdio.h> // TODO: Remove after killing the call to sprintf().
23#include <stdlib.h>
24#include <string.h> 21#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 22
31#include <string> 23#include <string>
32#include <vector>
33 24
34#include <android-base/properties.h> 25#include <android-base/properties.h>
35#include <android-base/stringprintf.h>
36#include <android-base/strings.h> 26#include <android-base/strings.h>
37#include <minui/minui.h> 27#include <minui/minui.h>
38 28
39#include "common.h"
40#include "device.h"
41
42WearRecoveryUI::WearRecoveryUI() 29WearRecoveryUI::WearRecoveryUI()
43 : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE), 30 : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE),
44 kMenuUnusableRows(RECOVERY_UI_MENU_UNUSABLE_ROWS) { 31 kMenuUnusableRows(RECOVERY_UI_MENU_UNUSABLE_ROWS) {
@@ -166,34 +153,6 @@ void WearRecoveryUI::update_progress_locked() {
166void WearRecoveryUI::SetStage(int current, int max) { 153void WearRecoveryUI::SetStage(int current, int max) {
167} 154}
168 155
169void WearRecoveryUI::Print(const char* fmt, ...) {
170 char buf[256];
171 va_list ap;
172 va_start(ap, fmt);
173 vsnprintf(buf, 256, fmt, ap);
174 va_end(ap);
175
176 fputs(buf, stdout);
177
178 // This can get called before ui_init(), so be careful.
179 pthread_mutex_lock(&updateMutex);
180 if (text_rows_ > 0 && text_cols_ > 0) {
181 char* ptr;
182 for (ptr = buf; *ptr != '\0'; ++ptr) {
183 if (*ptr == '\n' || text_col_ >= text_cols_) {
184 text_[text_row_][text_col_] = '\0';
185 text_col_ = 0;
186 text_row_ = (text_row_ + 1) % text_rows_;
187 if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
188 }
189 if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
190 }
191 text_[text_row_][text_col_] = '\0';
192 update_screen_locked();
193 }
194 pthread_mutex_unlock(&updateMutex);
195}
196
197void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* items, 156void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* items,
198 int initial_selection) { 157 int initial_selection) {
199 pthread_mutex_lock(&updateMutex); 158 pthread_mutex_lock(&updateMutex);
@@ -241,74 +200,3 @@ int WearRecoveryUI::SelectMenu(int sel) {
241 pthread_mutex_unlock(&updateMutex); 200 pthread_mutex_unlock(&updateMutex);
242 return sel; 201 return sel;
243} 202}
244
245void WearRecoveryUI::ShowFile(FILE* fp) {
246 std::vector<off_t> offsets;
247 offsets.push_back(ftello(fp));
248 ClearText();
249
250 struct stat sb;
251 fstat(fileno(fp), &sb);
252
253 bool show_prompt = false;
254 while (true) {
255 if (show_prompt) {
256 Print("--(%d%% of %d bytes)--",
257 static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
258 static_cast<int>(sb.st_size));
259 Redraw();
260 while (show_prompt) {
261 show_prompt = false;
262 int key = WaitKey();
263 if (key == KEY_POWER || key == KEY_ENTER) {
264 return;
265 } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
266 if (offsets.size() <= 1) {
267 show_prompt = true;
268 } else {
269 offsets.pop_back();
270 fseek(fp, offsets.back(), SEEK_SET);
271 }
272 } else {
273 if (feof(fp)) {
274 return;
275 }
276 offsets.push_back(ftello(fp));
277 }
278 }
279 ClearText();
280 }
281
282 int ch = getc(fp);
283 if (ch == EOF) {
284 text_row_ = text_top_ = text_rows_ - 2;
285 show_prompt = true;
286 } else {
287 PutChar(ch);
288 if (text_col_ == 0 && text_row_ >= text_rows_ - 2) {
289 text_top_ = text_row_;
290 show_prompt = true;
291 }
292 }
293 }
294}
295
296void WearRecoveryUI::PutChar(char ch) {
297 pthread_mutex_lock(&updateMutex);
298 if (ch != '\n') text_[text_row_][text_col_++] = ch;
299 if (ch == '\n' || text_col_ >= text_cols_) {
300 text_col_ = 0;
301 ++text_row_;
302 }
303 pthread_mutex_unlock(&updateMutex);
304}
305
306void WearRecoveryUI::ShowFile(const char* filename) {
307 FILE* fp = fopen_path(filename, "re");
308 if (fp == nullptr) {
309 Print(" Unable to open %s: %s\n", filename, strerror(errno));
310 return;
311 }
312 ShowFile(fp);
313 fclose(fp);
314}