diff options
author | Alessandro Astone <ales.astone@gmail.com> | 2019-04-01 11:11:33 +0200 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-04-11 00:20:32 +0200 |
commit | 20c8d41aceba80ef9d98fe08236d1b3d05e0569e (patch) | |
tree | a1b4582d62dec92f552c6b4c5860e24386048c57 | |
parent | a674419675e5f5b9c7359698f90dfc3d316cda44 (diff) | |
download | android_bootable_recovery-20c8d41aceba80ef9d98fe08236d1b3d05e0569e.tar.gz android_bootable_recovery-20c8d41aceba80ef9d98fe08236d1b3d05e0569e.tar.bz2 android_bootable_recovery-20c8d41aceba80ef9d98fe08236d1b3d05e0569e.zip |
recovery: show text during install
* The text array will be handled by always writing to the
last row, and will be moved up on a new line.
* Update the screen at each print.
* N.B. This does not show text on OTA updates,
but rather only on updates launched from the menu.
Change-Id: Ia62c361da17c5e24af508c29a04f045e81306e1c
-rw-r--r-- | recovery.cpp | 4 | ||||
-rw-r--r-- | screen_ui.cpp | 43 | ||||
-rw-r--r-- | screen_ui.h | 6 | ||||
-rw-r--r-- | stub_ui.h | 1 | ||||
-rw-r--r-- | ui.h | 2 |
5 files changed, 49 insertions, 7 deletions
diff --git a/recovery.cpp b/recovery.cpp index 2bb60521..b9598583 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1240,12 +1240,14 @@ static int apply_from_storage(Device* device, VolumeInfo& vi, bool* wipe_cache) VolumeManager::Instance()->volumeUnmount(vi.mId, true); + ui->UpdateScreenOnPrint(true); status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, TEMPORARY_INSTALL_FILE, false, 0 /*retry_count*/, true /*verify*/); if (status == INSTALL_UNVERIFIED && ask_to_continue_unverified_install(device)) { status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, TEMPORARY_INSTALL_FILE, false, 0 /*retry_count*/, false /*verify*/); } + ui->UpdateScreenOnPrint(false); finish_sdcard_fuse(token); return status; @@ -1290,10 +1292,12 @@ refresh: true /*refreshable*/); if (item == Device::kRefresh) { sideload_wait(false); + ui->UpdateScreenOnPrint(true); status = sideload_install(wipe_cache, TEMPORARY_INSTALL_FILE, true); if (status == INSTALL_UNVERIFIED && ask_to_continue_unverified_install(device)) { status = sideload_install(wipe_cache, TEMPORARY_INSTALL_FILE, false); } + ui->UpdateScreenOnPrint(false); } else { sideload_wait(true); status = INSTALL_NONE; diff --git a/screen_ui.cpp b/screen_ui.cpp index d83c293b..d763343b 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -137,6 +137,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() text_row_(0), show_text(false), show_text_ever(false), + previous_row_ended(false), + update_screen_on_print(false), menu_is_main_(true), menu_type_(MT_NONE), menu_headers_(nullptr), @@ -879,7 +881,8 @@ bool ScreenRecoveryUI::Init(const std::string& locale) { text_ = Alloc2d(text_rows_, text_cols_ + 1); file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1); - text_col_ = text_row_ = 0; + text_row_ = text_rows_ - 1; // Printed text grows bottom up + text_col_ = 0; // Set up the locale info. SetLocale(locale); @@ -1025,6 +1028,18 @@ void ScreenRecoveryUI::SetStage(int current, int max) { pthread_mutex_unlock(&updateMutex); } +void ScreenRecoveryUI::NewLine() { + // Shift the rows array up + char* p = text_[0]; + for (size_t i = 0; i < text_rows_ - 1; i++) { + text_[i] = text_[i + 1]; + } + text_[text_rows_ - 1] = p; + memset(text_[text_rows_ - 1], 0, text_cols_ + 1); + + text_col_ = 0; +} + void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) { std::string str; android::base::StringAppendV(&str, fmt, ap); @@ -1035,15 +1050,29 @@ void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) pthread_mutex_lock(&updateMutex); if (text_rows_ > 0 && text_cols_ > 0) { + if (previous_row_ended) { + NewLine(); + } + previous_row_ended = false; + + size_t row = text_rows_ - 1; for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) { - if (*ptr == '\n' || text_col_ >= text_cols_) { - text_[text_row_][text_col_] = '\0'; - text_col_ = 0; - text_row_ = (text_row_ + 1) % text_rows_; + if (*ptr == '\n' && *(ptr + 1) == '\0') { + // Scroll on the next print + text_[row][text_col_] = '\0'; + previous_row_ended = true; + } else if ((*ptr == '\n' && *(ptr + 1) != '\0') || text_col_ >= text_cols_) { + // We need to keep printing, scroll now + text_[row][text_col_] = '\0'; + NewLine(); } - if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr; + if (*ptr != '\n') text_[row][text_col_++] = *ptr; + } + text_[row][text_col_] = '\0'; + + if (show_text && update_screen_on_print) { + update_screen_locked(); } - text_[text_row_][text_col_] = '\0'; } pthread_mutex_unlock(&updateMutex); } diff --git a/screen_ui.h b/screen_ui.h index 53632ccb..442baf0a 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -93,6 +93,9 @@ class ScreenRecoveryUI : public RecoveryUI { void ShowText(bool visible) override; bool IsTextVisible() override; bool WasTextEverVisible() override; + void UpdateScreenOnPrint(bool update) override { + update_screen_on_print = update; + } // printing messages void Print(const char* fmt, ...) override __printflike(2, 3); @@ -162,6 +165,7 @@ class ScreenRecoveryUI : public RecoveryUI { virtual int ShowFile(FILE*); virtual void PrintV(const char*, bool, va_list); + void NewLine(); void PutChar(char); void ClearText(); @@ -238,6 +242,8 @@ class ScreenRecoveryUI : public RecoveryUI { bool show_text; bool show_text_ever; // has show_text ever been true? + bool previous_row_ended; + bool update_screen_on_print; std::vector<std::string> menu_; bool menu_is_main_; @@ -43,6 +43,7 @@ class StubRecoveryUI : public RecoveryUI { bool WasTextEverVisible() override { return false; } + void UpdateScreenOnPrint(bool /* update */) override{}; // printing messages void Print(const char* fmt, ...) override { @@ -157,6 +157,8 @@ class RecoveryUI { virtual bool WasTextEverVisible() = 0; + virtual void UpdateScreenOnPrint(bool update) = 0; + // Writes a message to the on-screen log (shown if the user has toggled on the text display). // Print() will also dump the message to stdout / log file, while PrintOnScreenOnly() not. virtual void Print(const char* fmt, ...) __printflike(2, 3) = 0; |