Loading recovery.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -1506,11 +1506,10 @@ int main(int argc, char **argv) { Device* device = make_device(); ui = device->GetUI(); if (!ui->Init()) { if (!ui->Init(locale)) { printf("Failed to initialize UI, use stub UI instead."); ui = new StubRecoveryUI(); } ui->SetLocale(locale.c_str()); // Set background string to "installing security update" for security update, // otherwise set it to "installing system update". ui->SetSystemUpdateText(security_update); Loading screen_ui.cpp +103 −131 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include <time.h> #include <unistd.h> #include <string> #include <vector> #include <android-base/logging.h> Loading @@ -51,9 +52,8 @@ static double now() { return tv.tv_sec + tv.tv_usec / 1000000.0; } ScreenRecoveryUI::ScreenRecoveryUI() : currentIcon(NONE), locale(nullptr), ScreenRecoveryUI::ScreenRecoveryUI() : currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), progressScopeSize(0), Loading @@ -79,9 +79,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() : animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), updateMutex(PTHREAD_MUTEX_INITIALIZER), rtl_locale(false) { } updateMutex(PTHREAD_MUTEX_INITIALIZER) {} GRSurface* ScreenRecoveryUI::GetCurrentFrame() { if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) { Loading Loading @@ -197,13 +195,13 @@ void ScreenRecoveryUI::draw_foreground_locked() { if (progressBarType == DETERMINATE) { float p = progressScopeStart + progress * progressScopeSize; int pos = (int) (p * width); int pos = static_cast<int>(p * width); if (rtl_locale) { if (rtl_locale_) { // Fill the progress bar from right to left. if (pos > 0) { gr_blit(progressBarFill, width-pos, 0, pos, height, progress_x+width-pos, progress_y); gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos, progress_y); } if (pos < width - 1) { gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y); Loading @@ -214,8 +212,7 @@ void ScreenRecoveryUI::draw_foreground_locked() { gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y); } if (pos < width - 1) { gr_blit(progressBarEmpty, pos, 0, width-pos, height, progress_x+pos, progress_y); gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y); } } } Loading Loading @@ -423,7 +420,7 @@ void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) { } void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) { int result = res_create_localized_alpha_surface(filename, locale, surface); int result = res_create_localized_alpha_surface(filename, locale_.c_str(), surface); if (result < 0) { LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")"; } Loading Loading @@ -459,8 +456,8 @@ bool ScreenRecoveryUI::InitTextParams() { return true; } bool ScreenRecoveryUI::Init() { RecoveryUI::Init(); bool ScreenRecoveryUI::Init(const std::string& locale) { RecoveryUI::Init(locale); if (!InitTextParams()) { return false; } Loading Loading @@ -539,31 +536,6 @@ void ScreenRecoveryUI::LoadAnimation() { } } void ScreenRecoveryUI::SetLocale(const char* new_locale) { this->locale = new_locale; this->rtl_locale = false; if (locale) { char* lang = strdup(locale); for (char* p = lang; *p; ++p) { if (*p == '_') { *p = '\0'; break; } } // A bit cheesy: keep an explicit list of supported RTL languages. if (strcmp(lang, "ar") == 0 || // Arabic strcmp(lang, "fa") == 0 || // Persian (Farsi) strcmp(lang, "he") == 0 || // Hebrew (new language code) strcmp(lang, "iw") == 0 || // Hebrew (old language code) strcmp(lang, "ur") == 0) { // Urdu rtl_locale = true; } free(lang); } } void ScreenRecoveryUI::SetBackground(Icon icon) { pthread_mutex_lock(&updateMutex); Loading screen_ui.h +3 −5 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include <pthread.h> #include <stdio.h> #include <string> #include "ui.h" #include "minui/minui.h" Loading @@ -29,8 +31,7 @@ class ScreenRecoveryUI : public RecoveryUI { public: ScreenRecoveryUI(); bool Init() override; void SetLocale(const char* locale); bool Init(const std::string& locale) override; // overall recovery state ("background image") void SetBackground(Icon icon); Loading Loading @@ -71,8 +72,6 @@ class ScreenRecoveryUI : public RecoveryUI { protected: Icon currentIcon; const char* locale; // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. float density_; // The layout to use. Loading Loading @@ -135,7 +134,6 @@ class ScreenRecoveryUI : public RecoveryUI { int char_width_; int char_height_; pthread_mutex_t updateMutex; bool rtl_locale; virtual bool InitTextParams(); Loading stub_ui.h +0 −2 Original line number Diff line number Diff line Loading @@ -24,8 +24,6 @@ class StubRecoveryUI : public RecoveryUI { public: StubRecoveryUI() = default; void SetLocale(const char* locale) override {} void SetBackground(Icon icon) override {} void SetSystemUpdateText(bool security_update) override {} Loading tests/component/verifier_test.cpp +38 −32 Original line number Diff line number Diff line Loading @@ -40,38 +40,44 @@ RecoveryUI* ui = NULL; class MockUI : public RecoveryUI { bool Init() { return true; } void SetStage(int, int) { } void SetLocale(const char*) { } void SetBackground(Icon /*icon*/) { } void SetSystemUpdateText(bool /*security_update*/) { } void SetProgressType(ProgressType /*determinate*/) { } void ShowProgress(float /*portion*/, float /*seconds*/) { } void SetProgress(float /*fraction*/) { } void ShowText(bool /*visible*/) { } bool IsTextVisible() { return false; } bool WasTextEverVisible() { return false; } void Print(const char* fmt, ...) { bool Init(const std::string&) override { return true; } void SetStage(int, int) override {} void SetBackground(Icon /*icon*/) override {} void SetSystemUpdateText(bool /*security_update*/) override {} void SetProgressType(ProgressType /*determinate*/) override {} void ShowProgress(float /*portion*/, float /*seconds*/) override {} void SetProgress(float /*fraction*/) override {} void ShowText(bool /*visible*/) override {} bool IsTextVisible() override { return false; } bool WasTextEverVisible() override { return false; } void Print(const char* fmt, ...) override { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); } void PrintOnScreenOnly(const char* fmt, ...) { void PrintOnScreenOnly(const char* fmt, ...) override { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); } void ShowFile(const char*) { } void ShowFile(const char*) override {} void StartMenu(const char* const* /*headers*/, const char* const* /*items*/, int /*initial_selection*/) { } int SelectMenu(int /*sel*/) { return 0; } void EndMenu() { } void StartMenu(const char* const* /*headers*/, const char* const* /*items*/, int /*initial_selection*/) override {} int SelectMenu(int /*sel*/) override { return 0; } void EndMenu() override {} }; void Loading Loading
recovery.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -1506,11 +1506,10 @@ int main(int argc, char **argv) { Device* device = make_device(); ui = device->GetUI(); if (!ui->Init()) { if (!ui->Init(locale)) { printf("Failed to initialize UI, use stub UI instead."); ui = new StubRecoveryUI(); } ui->SetLocale(locale.c_str()); // Set background string to "installing security update" for security update, // otherwise set it to "installing system update". ui->SetSystemUpdateText(security_update); Loading
screen_ui.cpp +103 −131 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include <time.h> #include <unistd.h> #include <string> #include <vector> #include <android-base/logging.h> Loading @@ -51,9 +52,8 @@ static double now() { return tv.tv_sec + tv.tv_usec / 1000000.0; } ScreenRecoveryUI::ScreenRecoveryUI() : currentIcon(NONE), locale(nullptr), ScreenRecoveryUI::ScreenRecoveryUI() : currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), progressScopeSize(0), Loading @@ -79,9 +79,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() : animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), updateMutex(PTHREAD_MUTEX_INITIALIZER), rtl_locale(false) { } updateMutex(PTHREAD_MUTEX_INITIALIZER) {} GRSurface* ScreenRecoveryUI::GetCurrentFrame() { if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) { Loading Loading @@ -197,13 +195,13 @@ void ScreenRecoveryUI::draw_foreground_locked() { if (progressBarType == DETERMINATE) { float p = progressScopeStart + progress * progressScopeSize; int pos = (int) (p * width); int pos = static_cast<int>(p * width); if (rtl_locale) { if (rtl_locale_) { // Fill the progress bar from right to left. if (pos > 0) { gr_blit(progressBarFill, width-pos, 0, pos, height, progress_x+width-pos, progress_y); gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos, progress_y); } if (pos < width - 1) { gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y); Loading @@ -214,8 +212,7 @@ void ScreenRecoveryUI::draw_foreground_locked() { gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y); } if (pos < width - 1) { gr_blit(progressBarEmpty, pos, 0, width-pos, height, progress_x+pos, progress_y); gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y); } } } Loading Loading @@ -423,7 +420,7 @@ void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) { } void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) { int result = res_create_localized_alpha_surface(filename, locale, surface); int result = res_create_localized_alpha_surface(filename, locale_.c_str(), surface); if (result < 0) { LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")"; } Loading Loading @@ -459,8 +456,8 @@ bool ScreenRecoveryUI::InitTextParams() { return true; } bool ScreenRecoveryUI::Init() { RecoveryUI::Init(); bool ScreenRecoveryUI::Init(const std::string& locale) { RecoveryUI::Init(locale); if (!InitTextParams()) { return false; } Loading Loading @@ -539,31 +536,6 @@ void ScreenRecoveryUI::LoadAnimation() { } } void ScreenRecoveryUI::SetLocale(const char* new_locale) { this->locale = new_locale; this->rtl_locale = false; if (locale) { char* lang = strdup(locale); for (char* p = lang; *p; ++p) { if (*p == '_') { *p = '\0'; break; } } // A bit cheesy: keep an explicit list of supported RTL languages. if (strcmp(lang, "ar") == 0 || // Arabic strcmp(lang, "fa") == 0 || // Persian (Farsi) strcmp(lang, "he") == 0 || // Hebrew (new language code) strcmp(lang, "iw") == 0 || // Hebrew (old language code) strcmp(lang, "ur") == 0) { // Urdu rtl_locale = true; } free(lang); } } void ScreenRecoveryUI::SetBackground(Icon icon) { pthread_mutex_lock(&updateMutex); Loading
screen_ui.h +3 −5 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include <pthread.h> #include <stdio.h> #include <string> #include "ui.h" #include "minui/minui.h" Loading @@ -29,8 +31,7 @@ class ScreenRecoveryUI : public RecoveryUI { public: ScreenRecoveryUI(); bool Init() override; void SetLocale(const char* locale); bool Init(const std::string& locale) override; // overall recovery state ("background image") void SetBackground(Icon icon); Loading Loading @@ -71,8 +72,6 @@ class ScreenRecoveryUI : public RecoveryUI { protected: Icon currentIcon; const char* locale; // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. float density_; // The layout to use. Loading Loading @@ -135,7 +134,6 @@ class ScreenRecoveryUI : public RecoveryUI { int char_width_; int char_height_; pthread_mutex_t updateMutex; bool rtl_locale; virtual bool InitTextParams(); Loading
stub_ui.h +0 −2 Original line number Diff line number Diff line Loading @@ -24,8 +24,6 @@ class StubRecoveryUI : public RecoveryUI { public: StubRecoveryUI() = default; void SetLocale(const char* locale) override {} void SetBackground(Icon icon) override {} void SetSystemUpdateText(bool security_update) override {} Loading
tests/component/verifier_test.cpp +38 −32 Original line number Diff line number Diff line Loading @@ -40,38 +40,44 @@ RecoveryUI* ui = NULL; class MockUI : public RecoveryUI { bool Init() { return true; } void SetStage(int, int) { } void SetLocale(const char*) { } void SetBackground(Icon /*icon*/) { } void SetSystemUpdateText(bool /*security_update*/) { } void SetProgressType(ProgressType /*determinate*/) { } void ShowProgress(float /*portion*/, float /*seconds*/) { } void SetProgress(float /*fraction*/) { } void ShowText(bool /*visible*/) { } bool IsTextVisible() { return false; } bool WasTextEverVisible() { return false; } void Print(const char* fmt, ...) { bool Init(const std::string&) override { return true; } void SetStage(int, int) override {} void SetBackground(Icon /*icon*/) override {} void SetSystemUpdateText(bool /*security_update*/) override {} void SetProgressType(ProgressType /*determinate*/) override {} void ShowProgress(float /*portion*/, float /*seconds*/) override {} void SetProgress(float /*fraction*/) override {} void ShowText(bool /*visible*/) override {} bool IsTextVisible() override { return false; } bool WasTextEverVisible() override { return false; } void Print(const char* fmt, ...) override { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); } void PrintOnScreenOnly(const char* fmt, ...) { void PrintOnScreenOnly(const char* fmt, ...) override { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); } void ShowFile(const char*) { } void ShowFile(const char*) override {} void StartMenu(const char* const* /*headers*/, const char* const* /*items*/, int /*initial_selection*/) { } int SelectMenu(int /*sel*/) { return 0; } void EndMenu() { } void StartMenu(const char* const* /*headers*/, const char* const* /*items*/, int /*initial_selection*/) override {} int SelectMenu(int /*sel*/) override { return 0; } void EndMenu() override {} }; void Loading