aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-09-08 16:44:40 -0500
committerGerrit Code Review2017-09-08 16:44:40 -0500
commitfa4f0140637ea2d2c24e9d8739ab3a573fbd22fe (patch)
treeaffbbff85143cc4548b8664896d99d95e49db1f6 /wear_ui.cpp
parentf51bb0f2d6626a8907bf6f94d856b935a0b750b1 (diff)
parentf05e2bcff297a5735e75e50ba42fc9c7098a579e (diff)
downloadplatform-bootable-recovery-fa4f0140637ea2d2c24e9d8739ab3a573fbd22fe.tar.gz
platform-bootable-recovery-fa4f0140637ea2d2c24e9d8739ab3a573fbd22fe.tar.xz
platform-bootable-recovery-fa4f0140637ea2d2c24e9d8739ab3a573fbd22fe.zip
Merge "wear_ui: Remove Print()/ShowFile()/PutChar()."
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 edc39cfb..1859b131 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);
@@ -240,74 +199,3 @@ int WearRecoveryUI::SelectMenu(int sel) {
240 pthread_mutex_unlock(&updateMutex); 199 pthread_mutex_unlock(&updateMutex);
241 return sel; 200 return sel;
242} 201}
243
244void WearRecoveryUI::ShowFile(FILE* fp) {
245 std::vector<off_t> offsets;
246 offsets.push_back(ftello(fp));
247 ClearText();
248
249 struct stat sb;
250 fstat(fileno(fp), &sb);
251
252 bool show_prompt = false;
253 while (true) {
254 if (show_prompt) {
255 Print("--(%d%% of %d bytes)--",
256 static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
257 static_cast<int>(sb.st_size));
258 Redraw();
259 while (show_prompt) {
260 show_prompt = false;
261 int key = WaitKey();
262 if (key == KEY_POWER || key == KEY_ENTER) {
263 return;
264 } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
265 if (offsets.size() <= 1) {
266 show_prompt = true;
267 } else {
268 offsets.pop_back();
269 fseek(fp, offsets.back(), SEEK_SET);
270 }
271 } else {
272 if (feof(fp)) {
273 return;
274 }
275 offsets.push_back(ftello(fp));
276 }
277 }
278 ClearText();
279 }
280
281 int ch = getc(fp);
282 if (ch == EOF) {
283 text_row_ = text_top_ = text_rows_ - 2;
284 show_prompt = true;
285 } else {
286 PutChar(ch);
287 if (text_col_ == 0 && text_row_ >= text_rows_ - 2) {
288 text_top_ = text_row_;
289 show_prompt = true;
290 }
291 }
292 }
293}
294
295void WearRecoveryUI::PutChar(char ch) {
296 pthread_mutex_lock(&updateMutex);
297 if (ch != '\n') text_[text_row_][text_col_++] = ch;
298 if (ch == '\n' || text_col_ >= text_cols_) {
299 text_col_ = 0;
300 ++text_row_;
301 }
302 pthread_mutex_unlock(&updateMutex);
303}
304
305void WearRecoveryUI::ShowFile(const char* filename) {
306 FILE* fp = fopen_path(filename, "re");
307 if (fp == nullptr) {
308 Print(" Unable to open %s: %s\n", filename, strerror(errno));
309 return;
310 }
311 ShowFile(fp);
312 fclose(fp);
313}