From 1d156b988244660739c56803c87576f0403569ac Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 2 May 2018 12:43:18 -0700 Subject: screen_ui: Drop the dependency on common.h. Remove the use of fopen_path() in screen_ui.cpp, as this is the only place that requires the dependency on common.h. The mounting work should be done by the caller. Also change the parameter in RecoveryUI::ShowFile() from const char* to const std::string&. Test: mmma -j bootable/recovery Test: Build and boot into recovery image on angler. Choose 'View recovery logs'. Change-Id: I8e63f14a8e2b12b856e5a92476e4226cd6ea39fb --- recovery.cpp | 2 +- screen_ui.cpp | 12 +++++------- screen_ui.h | 2 +- stub_ui.h | 5 ++++- ui.h | 4 +++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 7e539ce3d..dc2cc085f 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -820,7 +820,7 @@ static void choose_recovery_file(Device* device) { std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2)); if (entries[chosen_item] == "Back") break; - ui->ShowFile(entries[chosen_item].c_str()); + ui->ShowFile(entries[chosen_item]); } } diff --git a/screen_ui.cpp b/screen_ui.cpp index aaeb18c7f..00ed45d3e 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -42,7 +42,6 @@ #include #include -#include "common.h" #include "device.h" #include "ui.h" @@ -951,10 +950,10 @@ void ScreenRecoveryUI::ShowFile(FILE* fp) { } } -void ScreenRecoveryUI::ShowFile(const char* filename) { - FILE* fp = fopen_path(filename, "re"); - if (fp == nullptr) { - Print(" Unable to open %s: %s\n", filename, strerror(errno)); +void ScreenRecoveryUI::ShowFile(const std::string& filename) { + std::unique_ptr fp(fopen(filename.c_str(), "re"), fclose); + if (!fp) { + Print(" Unable to open %s: %s\n", filename.c_str(), strerror(errno)); return; } @@ -966,8 +965,7 @@ void ScreenRecoveryUI::ShowFile(const char* filename) { text_ = file_viewer_text_; ClearText(); - ShowFile(fp); - fclose(fp); + ShowFile(fp.get()); text_ = old_text; text_col_ = old_text_col; diff --git a/screen_ui.h b/screen_ui.h index 837d346a2..986959c69 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -133,7 +133,7 @@ class ScreenRecoveryUI : public RecoveryUI { // printing messages void Print(const char* fmt, ...) override __printflike(2, 3); void PrintOnScreenOnly(const char* fmt, ...) override __printflike(2, 3); - void ShowFile(const char* filename) override; + void ShowFile(const std::string& filename) override; // menu display int ShowMenu(const char* const* headers, const char* const* items, int initial_selection, diff --git a/stub_ui.h b/stub_ui.h index 3c36fcfb1..362aab443 100644 --- a/stub_ui.h +++ b/stub_ui.h @@ -17,6 +17,9 @@ #ifndef RECOVERY_STUB_UI_H #define RECOVERY_STUB_UI_H +#include +#include + #include "ui.h" // Stub implementation of RecoveryUI for devices without screen. @@ -51,7 +54,7 @@ class StubRecoveryUI : public RecoveryUI { va_end(ap); } void PrintOnScreenOnly(const char* /* fmt */, ...) override {} - void ShowFile(const char* /* filename */) override {} + void ShowFile(const std::string& /* filename */) override {} // menu display int ShowMenu(const char* const* /* headers */, const char* const* /* items */, diff --git a/ui.h b/ui.h index 636c2ff70..c4689923a 100644 --- a/ui.h +++ b/ui.h @@ -88,7 +88,9 @@ class RecoveryUI { virtual void Print(const char* fmt, ...) __printflike(2, 3) = 0; virtual void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3) = 0; - virtual void ShowFile(const char* filename) = 0; + // Shows the contents of the given file. Caller ensures the patition that contains the file has + // been mounted. + virtual void ShowFile(const std::string& filename) = 0; // --- key handling --- -- cgit v1.2.3