From 0e577ee424acf7a5e6600560d702ab3c8020a29f Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Mon, 7 May 2018 11:21:10 -0700 Subject: recovery: Add ability to set title lines Add the ability to change the contents of the title lines, displayed at the top of the screen. Once set, the same lines are displayed for all menus until changed again. Test: Recovery works Bug: 78793464 Change-Id: I7ef5594b0d76dbbd2e01ad7508863af1270b2a2a --- recovery.cpp | 5 +++++ screen_ui.cpp | 12 +++++++----- screen_ui.h | 3 +++ stub_ui.h | 2 ++ ui.h | 2 ++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 21f633011..56b2567d1 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1063,6 +1063,11 @@ Device::BuiltinAction start_recovery(Device* device, const std::vectorSetStage(st_cur, st_max); } + std::vector title_lines = + android::base::Split(android::base::GetProperty("ro.bootimage.build.fingerprint", ""), ":"); + title_lines.insert(std::begin(title_lines), "Android Recovery"); + ui->SetTitle(title_lines); + device->StartRecovery(); printf("Command:"); diff --git a/screen_ui.cpp b/screen_ui.cpp index fd7a1bea5..f1b38781a 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -496,6 +496,10 @@ int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, return offset; } +void ScreenRecoveryUI::SetTitle(const std::vector& lines) { + title_lines_ = lines; +} + // Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex // locked. void ScreenRecoveryUI::draw_screen_locked() { @@ -529,11 +533,9 @@ void ScreenRecoveryUI::draw_menu_and_text_buffer_locked( int x = kMarginWidth + kMenuIndent; SetColor(INFO); - y += DrawTextLine(x, y, "Android Recovery", true); - std::string recovery_fingerprint = - android::base::GetProperty("ro.bootimage.build.fingerprint", ""); - for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) { - y += DrawTextLine(x, y, chunk, false); + + for (size_t i = 0; i < title_lines_.size(); i++) { + y += DrawTextLine(x, y, title_lines_[i], i == 0); } y += DrawTextLines(x, y, help_message); diff --git a/screen_ui.h b/screen_ui.h index 2d6b621d5..c90a2cd17 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -141,6 +141,7 @@ class ScreenRecoveryUI : public RecoveryUI { size_t ShowMenu(const std::vector& headers, const std::vector& items, size_t initial_selection, bool menu_only, const std::function& key_handler) override; + void SetTitle(const std::vector& lines) override; void KeyLongPress(int) override; @@ -266,6 +267,8 @@ class ScreenRecoveryUI : public RecoveryUI { bool show_text; bool show_text_ever; // has show_text ever been true? + std::vector title_lines_; + bool scrollable_menu_; std::unique_ptr menu_; diff --git a/stub_ui.h b/stub_ui.h index 67c338e99..a3cf12b05 100644 --- a/stub_ui.h +++ b/stub_ui.h @@ -67,6 +67,8 @@ class StubRecoveryUI : public RecoveryUI { const std::function& /* key_handler */) override { return initial_selection; } + + void SetTitle(const std::vector& /* lines */) override {} }; #endif // RECOVERY_STUB_UI_H diff --git a/ui.h b/ui.h index 39284268d..a74b14f85 100644 --- a/ui.h +++ b/ui.h @@ -134,6 +134,8 @@ class RecoveryUI { // --- menu display --- + virtual void SetTitle(const std::vector& lines) = 0; + // Displays a menu with the given 'headers' and 'items'. The supplied 'key_handler' callback, // which is typically bound to Device::HandleMenuKey(), should return the expected action for the // given key code and menu visibility (e.g. to move the cursor or to select an item). Caller sets -- cgit v1.2.3