diff --git a/Android.mk b/Android.mk
index bbb2046..3eed7a6 100644
--- a/Android.mk
+++ b/Android.mk
@@ -59,7 +59,8 @@
     libvintf_recovery \
     libcrypto_utils \
     libcrypto \
-    libbase
+    libbase \
+    libziparchive \
 
 include $(BUILD_STATIC_LIBRARY)
 
@@ -107,6 +108,12 @@
 LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_WIDTH=0
 endif
 
+ifneq ($(TARGET_RECOVERY_UI_VR_STEREO_OFFSET),)
+LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=$(TARGET_RECOVERY_UI_VR_STEREO_OFFSET)
+else
+LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=0
+endif
+
 LOCAL_C_INCLUDES += \
     system/vold \
 
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..09754c6
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,3 @@
+enh+aosp-gerrit@google.com
+tbao@google.com
+xunchang@google.com
diff --git a/install.cpp b/install.cpp
index a1f2e4f..7ba8f01 100644
--- a/install.cpp
+++ b/install.cpp
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #include <algorithm>
+#include <atomic>
 #include <chrono>
 #include <condition_variable>
 #include <functional>
@@ -65,18 +66,14 @@
 static std::condition_variable finish_log_temperature;
 
 // This function parses and returns the build.version.incremental
-static int parse_build_number(const std::string& str) {
+static std::string parse_build_number(const std::string& str) {
     size_t pos = str.find('=');
     if (pos != std::string::npos) {
-        std::string num_string = android::base::Trim(str.substr(pos+1));
-        int build_number;
-        if (android::base::ParseInt(num_string.c_str(), &build_number, 0)) {
-            return build_number;
-        }
+        return android::base::Trim(str.substr(pos+1));
     }
 
     LOG(ERROR) << "Failed to parse build number in " << str;
-    return -1;
+    return "";
 }
 
 bool read_metadata_from_package(ZipArchiveHandle zip, std::string* metadata) {
@@ -113,14 +110,14 @@
   for (const std::string& line : lines) {
     std::string str = android::base::Trim(line);
     if (android::base::StartsWith(str, "pre-build-incremental")) {
-      int source_build = parse_build_number(str);
-      if (source_build != -1) {
-        log_buffer->push_back(android::base::StringPrintf("source_build: %d", source_build));
+      std::string source_build = parse_build_number(str);
+      if (!source_build.empty()) {
+        log_buffer->push_back("source_build: " + source_build);
       }
     } else if (android::base::StartsWith(str, "post-build-incremental")) {
-      int target_build = parse_build_number(str);
-      if (target_build != -1) {
-        log_buffer->push_back(android::base::StringPrintf("target_build: %d", target_build));
+      std::string target_build = parse_build_number(str);
+      if (!target_build.empty()) {
+        log_buffer->push_back("target_build: " + target_build);
       }
     }
   }
@@ -294,11 +291,12 @@
 }
 #endif  // !AB_OTA_UPDATER
 
-static void log_max_temperature(int* max_temperature) {
+static void log_max_temperature(int* max_temperature, const std::atomic<bool>& logger_finished) {
   CHECK(max_temperature != nullptr);
   std::mutex mtx;
   std::unique_lock<std::mutex> lck(mtx);
-  while (finish_log_temperature.wait_for(lck, 20s) == std::cv_status::timeout) {
+  while (!logger_finished.load() &&
+         finish_log_temperature.wait_for(lck, 20s) == std::cv_status::timeout) {
     *max_temperature = std::max(*max_temperature, GetMaxValueFromThermalZone());
   }
 }
@@ -403,7 +401,8 @@
   }
   close(pipefd[1]);
 
-  std::thread temperature_logger(log_max_temperature, max_temperature);
+  std::atomic<bool> logger_finished(false);
+  std::thread temperature_logger(log_max_temperature, max_temperature, std::ref(logger_finished));
 
   *wipe_cache = false;
   bool retry_update = false;
@@ -467,6 +466,7 @@
   int status;
   waitpid(pid, &status, 0);
 
+  logger_finished.store(true);
   finish_log_temperature.notify_one();
   temperature_logger.join();
 
diff --git a/screen_ui.cpp b/screen_ui.cpp
index ff51b53..d9574d8 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -45,9 +45,9 @@
 
 // Return the current time as a double (including fractions of a second).
 static double now() {
-    struct timeval tv;
-    gettimeofday(&tv, nullptr);
-    return tv.tv_sec + tv.tv_usec / 1000000.0;
+  struct timeval tv;
+  gettimeofday(&tv, nullptr);
+  return tv.tv_sec + tv.tv_usec / 1000000.0;
 }
 
 ScreenRecoveryUI::ScreenRecoveryUI()
@@ -82,25 +82,30 @@
       max_stage(-1),
       updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
 
-GRSurface* ScreenRecoveryUI::GetCurrentFrame() {
-    if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
-        return intro_done ? loopFrames[current_frame] : introFrames[current_frame];
-    }
-    return error_icon;
+GRSurface* ScreenRecoveryUI::GetCurrentFrame() const {
+  if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
+    return intro_done ? loopFrames[current_frame] : introFrames[current_frame];
+  }
+  return error_icon;
 }
 
-GRSurface* ScreenRecoveryUI::GetCurrentText() {
-    switch (currentIcon) {
-        case ERASING: return erasing_text;
-        case ERROR: return error_text;
-        case INSTALLING_UPDATE: return installing_text;
-        case NO_COMMAND: return no_command_text;
-        case NONE: abort();
-    }
+GRSurface* ScreenRecoveryUI::GetCurrentText() const {
+  switch (currentIcon) {
+    case ERASING:
+      return erasing_text;
+    case ERROR:
+      return error_text;
+    case INSTALLING_UPDATE:
+      return installing_text;
+    case NO_COMMAND:
+      return no_command_text;
+    case NONE:
+      abort();
+  }
 }
 
 int ScreenRecoveryUI::PixelsFromDp(int dp) const {
-    return dp * density_;
+  return dp * density_;
 }
 
 // Here's the intended layout:
@@ -127,17 +132,16 @@
   { 52, 112, },  // LANDSCAPE_LARGE
 };
 
-int ScreenRecoveryUI::GetAnimationBaseline() {
-    return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) -
-            gr_get_height(loopFrames[0]);
+int ScreenRecoveryUI::GetAnimationBaseline() const {
+  return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) - gr_get_height(loopFrames[0]);
 }
 
-int ScreenRecoveryUI::GetTextBaseline() {
-    return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) -
-            gr_get_height(installing_text);
+int ScreenRecoveryUI::GetTextBaseline() const {
+  return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) -
+         gr_get_height(installing_text);
 }
 
-int ScreenRecoveryUI::GetProgressBaseline() {
+int ScreenRecoveryUI::GetProgressBaseline() const {
   int elements_sum = gr_get_height(loopFrames[0]) + PixelsFromDp(kLayouts[layout_][ICON]) +
                      gr_get_height(installing_text) + PixelsFromDp(kLayouts[layout_][TEXT]) +
                      gr_get_height(progressBarFill);
@@ -148,34 +152,33 @@
 // Clear the screen and draw the currently selected background icon (if any).
 // Should only be called with updateMutex locked.
 void ScreenRecoveryUI::draw_background_locked() {
-    pagesIdentical = false;
-    gr_color(0, 0, 0, 255);
-    gr_clear();
+  pagesIdentical = false;
+  gr_color(0, 0, 0, 255);
+  gr_clear();
 
-    if (currentIcon != NONE) {
-        if (max_stage != -1) {
-            int stage_height = gr_get_height(stageMarkerEmpty);
-            int stage_width = gr_get_width(stageMarkerEmpty);
-            int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
-            int y = gr_fb_height() - stage_height;
-            for (int i = 0; i < max_stage; ++i) {
-                GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
-                gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
-                x += stage_width;
-            }
-        }
-
-        GRSurface* text_surface = GetCurrentText();
-        int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
-        int text_y = GetTextBaseline();
-        gr_color(255, 255, 255, 255);
-        gr_texticon(text_x, text_y, text_surface);
+  if (currentIcon != NONE) {
+    if (max_stage != -1) {
+      int stage_height = gr_get_height(stageMarkerEmpty);
+      int stage_width = gr_get_width(stageMarkerEmpty);
+      int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
+      int y = gr_fb_height() - stage_height;
+      for (int i = 0; i < max_stage; ++i) {
+        GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
+        gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
+        x += stage_width;
+      }
     }
+
+    GRSurface* text_surface = GetCurrentText();
+    int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
+    int text_y = GetTextBaseline();
+    gr_color(255, 255, 255, 255);
+    gr_texticon(text_x, text_y, text_surface);
+  }
 }
 
-// Draws the animation and progress bar (if any) on the screen.
-// Does not flip pages.
-// Should only be called with updateMutex locked.
+// Draws the animation and progress bar (if any) on the screen. Does not flip pages. Should only be
+// called with updateMutex locked.
 void ScreenRecoveryUI::draw_foreground_locked() {
   if (currentIcon != NONE) {
     GRSurface* frame = GetCurrentFrame();
@@ -223,67 +226,67 @@
   }
 }
 
-void ScreenRecoveryUI::SetColor(UIElement e) {
-    switch (e) {
-        case INFO:
-            gr_color(249, 194, 0, 255);
-            break;
-        case HEADER:
-            gr_color(247, 0, 6, 255);
-            break;
-        case MENU:
-        case MENU_SEL_BG:
-            gr_color(0, 106, 157, 255);
-            break;
-        case MENU_SEL_BG_ACTIVE:
-            gr_color(0, 156, 100, 255);
-            break;
-        case MENU_SEL_FG:
-            gr_color(255, 255, 255, 255);
-            break;
-        case LOG:
-            gr_color(196, 196, 196, 255);
-            break;
-        case TEXT_FILL:
-            gr_color(0, 0, 0, 160);
-            break;
-        default:
-            gr_color(255, 255, 255, 255);
-            break;
-    }
+void ScreenRecoveryUI::SetColor(UIElement e) const {
+  switch (e) {
+    case INFO:
+      gr_color(249, 194, 0, 255);
+      break;
+    case HEADER:
+      gr_color(247, 0, 6, 255);
+      break;
+    case MENU:
+    case MENU_SEL_BG:
+      gr_color(0, 106, 157, 255);
+      break;
+    case MENU_SEL_BG_ACTIVE:
+      gr_color(0, 156, 100, 255);
+      break;
+    case MENU_SEL_FG:
+      gr_color(255, 255, 255, 255);
+      break;
+    case LOG:
+      gr_color(196, 196, 196, 255);
+      break;
+    case TEXT_FILL:
+      gr_color(0, 0, 0, 160);
+      break;
+    default:
+      gr_color(255, 255, 255, 255);
+      break;
+  }
 }
 
-void ScreenRecoveryUI::DrawHorizontalRule(int* y) {
-    SetColor(MENU);
-    *y += 4;
-    gr_fill(0, *y, gr_fb_width(), *y + 2);
-    *y += 4;
+int ScreenRecoveryUI::DrawHorizontalRule(int y) const {
+  gr_fill(0, y + 4, gr_fb_width(), y + 6);
+  return 8;
 }
 
 void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
-    gr_fill(x, y, x + width, y + height);
+  gr_fill(x, y, x + width, y + height);
 }
 
-void ScreenRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const {
-    gr_text(gr_sys_font(), x, *y, line, bold);
-    *y += char_height_ + 4;
+int ScreenRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
+  gr_text(gr_sys_font(), x, y, line, bold);
+  return char_height_ + 4;
 }
 
-void ScreenRecoveryUI::DrawTextLines(int x, int* y, const char* const* lines) const {
-    for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
-        DrawTextLine(x, y, lines[i], false);
-    }
+int ScreenRecoveryUI::DrawTextLines(int x, int y, const char* const* lines) const {
+  int offset = 0;
+  for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) {
+    offset += DrawTextLine(x, y + offset, lines[i], false);
+  }
+  return offset;
 }
 
 static const char* REGULAR_HELP[] = {
-    "Use volume up/down and power.",
-    NULL
+  "Use volume up/down and power.",
+  NULL
 };
 
 static const char* LONG_PRESS_HELP[] = {
-    "Any button cycles highlight.",
-    "Long-press activates.",
-    NULL
+  "Any button cycles highlight.",
+  "Long-press activates.",
+  NULL
 };
 
 // Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
@@ -294,6 +297,7 @@
     draw_foreground_locked();
     return;
   }
+
   gr_color(0, 0, 0, 255);
   gr_clear();
 
@@ -305,18 +309,17 @@
         android::base::GetProperty("ro.bootimage.build.fingerprint", "");
 
     SetColor(INFO);
-    DrawTextLine(x, &y, "Android Recovery", true);
+    y += DrawTextLine(x, y, "Android Recovery", true);
     for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
-      DrawTextLine(x, &y, chunk.c_str(), false);
+      y += DrawTextLine(x, y, chunk.c_str(), false);
     }
-    DrawTextLines(x, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
+    y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
 
     SetColor(HEADER);
-    DrawTextLines(x, &y, menu_headers_);
+    y += DrawTextLines(x, y, menu_headers_);
 
     SetColor(MENU);
-    DrawHorizontalRule(&y);
-    y += 4;
+    y += DrawHorizontalRule(y) + 4;
     for (int i = 0; i < menu_items; ++i) {
       if (i == menu_sel) {
         // Draw the highlight bar.
@@ -324,13 +327,13 @@
         DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
         // Bold white text for the selected item.
         SetColor(MENU_SEL_FG);
-        DrawTextLine(x, &y, menu_[i], true);
+        y += DrawTextLine(x, y, menu_[i], true);
         SetColor(MENU);
       } else {
-        DrawTextLine(x, &y, menu_[i], false);
+        y += DrawTextLine(x, y, menu_[i], false);
       }
     }
-    DrawHorizontalRule(&y);
+    y += DrawHorizontalRule(y);
   }
 
   // Display from the bottom up, until we hit the top of the screen, the bottom of the menu, or
@@ -338,10 +341,9 @@
   SetColor(LOG);
   int row = (text_top_ + text_rows_ - 1) % text_rows_;
   size_t count = 0;
-  for (int ty = gr_fb_height() - kMarginHeight - char_height_ - log_bottom_offset_;
-       ty >= y && count < text_rows_; ty -= char_height_, ++count) {
-    int temp_y = ty;
-    DrawTextLine(x, &temp_y, text_[row], false);
+  for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
+       ty -= char_height_, ++count) {
+    DrawTextLine(x, ty, text_[row], false);
     --row;
     if (row < 0) row = text_rows_ - 1;
   }
@@ -350,81 +352,81 @@
 // Redraw everything on the screen and flip the screen (make it visible).
 // Should only be called with updateMutex locked.
 void ScreenRecoveryUI::update_screen_locked() {
-    draw_screen_locked();
-    gr_flip();
+  draw_screen_locked();
+  gr_flip();
 }
 
 // Updates only the progress bar, if possible, otherwise redraws the screen.
 // Should only be called with updateMutex locked.
 void ScreenRecoveryUI::update_progress_locked() {
-    if (show_text || !pagesIdentical) {
-        draw_screen_locked();    // Must redraw the whole screen
-        pagesIdentical = true;
-    } else {
-        draw_foreground_locked();  // Draw only the progress bar and overlays
-    }
-    gr_flip();
+  if (show_text || !pagesIdentical) {
+    draw_screen_locked();  // Must redraw the whole screen
+    pagesIdentical = true;
+  } else {
+    draw_foreground_locked();  // Draw only the progress bar and overlays
+  }
+  gr_flip();
 }
 
 // Keeps the progress bar updated, even when the process is otherwise busy.
 void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) {
-    reinterpret_cast<ScreenRecoveryUI*>(data)->ProgressThreadLoop();
-    return nullptr;
+  reinterpret_cast<ScreenRecoveryUI*>(data)->ProgressThreadLoop();
+  return nullptr;
 }
 
 void ScreenRecoveryUI::ProgressThreadLoop() {
-    double interval = 1.0 / animation_fps;
-    while (true) {
-        double start = now();
-        pthread_mutex_lock(&updateMutex);
+  double interval = 1.0 / animation_fps;
+  while (true) {
+    double start = now();
+    pthread_mutex_lock(&updateMutex);
 
-        bool redraw = false;
+    bool redraw = false;
 
-        // update the installation animation, if active
-        // skip this if we have a text overlay (too expensive to update)
-        if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) {
-            if (!intro_done) {
-                if (current_frame == intro_frames - 1) {
-                    intro_done = true;
-                    current_frame = 0;
-                } else {
-                    ++current_frame;
-                }
-            } else {
-                current_frame = (current_frame + 1) % loop_frames;
-            }
-
-            redraw = true;
+    // update the installation animation, if active
+    // skip this if we have a text overlay (too expensive to update)
+    if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) {
+      if (!intro_done) {
+        if (current_frame == intro_frames - 1) {
+          intro_done = true;
+          current_frame = 0;
+        } else {
+          ++current_frame;
         }
+      } else {
+        current_frame = (current_frame + 1) % loop_frames;
+      }
 
-        // move the progress bar forward on timed intervals, if configured
-        int duration = progressScopeDuration;
-        if (progressBarType == DETERMINATE && duration > 0) {
-            double elapsed = now() - progressScopeTime;
-            float p = 1.0 * elapsed / duration;
-            if (p > 1.0) p = 1.0;
-            if (p > progress) {
-                progress = p;
-                redraw = true;
-            }
-        }
-
-        if (redraw) update_progress_locked();
-
-        pthread_mutex_unlock(&updateMutex);
-        double end = now();
-        // minimum of 20ms delay between frames
-        double delay = interval - (end-start);
-        if (delay < 0.02) delay = 0.02;
-        usleep(static_cast<useconds_t>(delay * 1000000));
+      redraw = true;
     }
+
+    // move the progress bar forward on timed intervals, if configured
+    int duration = progressScopeDuration;
+    if (progressBarType == DETERMINATE && duration > 0) {
+      double elapsed = now() - progressScopeTime;
+      float p = 1.0 * elapsed / duration;
+      if (p > 1.0) p = 1.0;
+      if (p > progress) {
+        progress = p;
+        redraw = true;
+      }
+    }
+
+    if (redraw) update_progress_locked();
+
+    pthread_mutex_unlock(&updateMutex);
+    double end = now();
+    // minimum of 20ms delay between frames
+    double delay = interval - (end - start);
+    if (delay < 0.02) delay = 0.02;
+    usleep(static_cast<useconds_t>(delay * 1000000));
+  }
 }
 
 void ScreenRecoveryUI::LoadBitmap(const char* filename, GRSurface** surface) {
-    int result = res_create_display_surface(filename, surface);
-    if (result < 0) {
-        LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
-    }
+  int result = res_create_display_surface(filename, surface);
+  if (result < 0) {
+    LOG(ERROR) << "couldn't load bitmap " << filename << " (error " << result << ")";
+  }
 }
 
 void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, GRSurface** surface) {
@@ -435,22 +437,22 @@
 }
 
 static char** Alloc2d(size_t rows, size_t cols) {
-    char** result = new char*[rows];
-    for (size_t i = 0; i < rows; ++i) {
-        result[i] = new char[cols];
-        memset(result[i], 0, cols);
-    }
-    return result;
+  char** result = new char*[rows];
+  for (size_t i = 0; i < rows; ++i) {
+    result[i] = new char[cols];
+    memset(result[i], 0, cols);
+  }
+  return result;
 }
 
 // Choose the right background string to display during update.
 void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
-    if (security_update) {
-        LoadLocalizedBitmap("installing_security_text", &installing_text);
-    } else {
-        LoadLocalizedBitmap("installing_text", &installing_text);
-    }
-    Redraw();
+  if (security_update) {
+    LoadLocalizedBitmap("installing_security_text", &installing_text);
+  } else {
+    LoadLocalizedBitmap("installing_text", &installing_text);
+  }
+  Redraw();
 }
 
 bool ScreenRecoveryUI::InitTextParams() {
@@ -461,7 +463,6 @@
   gr_font_size(gr_sys_font(), &char_width_, &char_height_);
   text_rows_ = (gr_fb_height() - kMarginHeight * 2) / char_height_;
   text_cols_ = (gr_fb_width() - kMarginWidth * 2) / char_width_;
-  log_bottom_offset_ = 0;
   return true;
 }
 
@@ -507,309 +508,309 @@
 }
 
 void ScreenRecoveryUI::LoadAnimation() {
-    std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir);
-    dirent* de;
-    std::vector<std::string> intro_frame_names;
-    std::vector<std::string> loop_frame_names;
+  std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/res/images"), closedir);
+  dirent* de;
+  std::vector<std::string> intro_frame_names;
+  std::vector<std::string> loop_frame_names;
 
-    while ((de = readdir(dir.get())) != nullptr) {
-        int value, num_chars;
-        if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) {
-            intro_frame_names.emplace_back(de->d_name, num_chars);
-        } else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) {
-            loop_frame_names.emplace_back(de->d_name, num_chars);
-        }
+  while ((de = readdir(dir.get())) != nullptr) {
+    int value, num_chars;
+    if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) {
+      intro_frame_names.emplace_back(de->d_name, num_chars);
+    } else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) {
+      loop_frame_names.emplace_back(de->d_name, num_chars);
     }
+  }
 
-    intro_frames = intro_frame_names.size();
-    loop_frames = loop_frame_names.size();
+  intro_frames = intro_frame_names.size();
+  loop_frames = loop_frame_names.size();
 
-    // It's okay to not have an intro.
-    if (intro_frames == 0) intro_done = true;
-    // But you must have an animation.
-    if (loop_frames == 0) abort();
+  // It's okay to not have an intro.
+  if (intro_frames == 0) intro_done = true;
+  // But you must have an animation.
+  if (loop_frames == 0) abort();
 
-    std::sort(intro_frame_names.begin(), intro_frame_names.end());
-    std::sort(loop_frame_names.begin(), loop_frame_names.end());
+  std::sort(intro_frame_names.begin(), intro_frame_names.end());
+  std::sort(loop_frame_names.begin(), loop_frame_names.end());
 
-    introFrames = new GRSurface*[intro_frames];
-    for (size_t i = 0; i < intro_frames; i++) {
-        LoadBitmap(intro_frame_names.at(i).c_str(), &introFrames[i]);
-    }
+  introFrames = new GRSurface*[intro_frames];
+  for (size_t i = 0; i < intro_frames; i++) {
+    LoadBitmap(intro_frame_names.at(i).c_str(), &introFrames[i]);
+  }
 
-    loopFrames = new GRSurface*[loop_frames];
-    for (size_t i = 0; i < loop_frames; i++) {
-        LoadBitmap(loop_frame_names.at(i).c_str(), &loopFrames[i]);
-    }
+  loopFrames = new GRSurface*[loop_frames];
+  for (size_t i = 0; i < loop_frames; i++) {
+    LoadBitmap(loop_frame_names.at(i).c_str(), &loopFrames[i]);
+  }
 }
 
 void ScreenRecoveryUI::SetBackground(Icon icon) {
-    pthread_mutex_lock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
 
-    currentIcon = icon;
-    update_screen_locked();
+  currentIcon = icon;
+  update_screen_locked();
 
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::SetProgressType(ProgressType type) {
-    pthread_mutex_lock(&updateMutex);
-    if (progressBarType != type) {
-        progressBarType = type;
-    }
-    progressScopeStart = 0;
-    progressScopeSize = 0;
-    progress = 0;
-    update_progress_locked();
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  if (progressBarType != type) {
+    progressBarType = type;
+  }
+  progressScopeStart = 0;
+  progressScopeSize = 0;
+  progress = 0;
+  update_progress_locked();
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
-    pthread_mutex_lock(&updateMutex);
-    progressBarType = DETERMINATE;
-    progressScopeStart += progressScopeSize;
-    progressScopeSize = portion;
-    progressScopeTime = now();
-    progressScopeDuration = seconds;
-    progress = 0;
-    update_progress_locked();
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  progressBarType = DETERMINATE;
+  progressScopeStart += progressScopeSize;
+  progressScopeSize = portion;
+  progressScopeTime = now();
+  progressScopeDuration = seconds;
+  progress = 0;
+  update_progress_locked();
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::SetProgress(float fraction) {
-    pthread_mutex_lock(&updateMutex);
-    if (fraction < 0.0) fraction = 0.0;
-    if (fraction > 1.0) fraction = 1.0;
-    if (progressBarType == DETERMINATE && fraction > progress) {
-        // Skip updates that aren't visibly different.
-        int width = gr_get_width(progressBarEmpty);
-        float scale = width * progressScopeSize;
-        if ((int) (progress * scale) != (int) (fraction * scale)) {
-            progress = fraction;
-            update_progress_locked();
-        }
+  pthread_mutex_lock(&updateMutex);
+  if (fraction < 0.0) fraction = 0.0;
+  if (fraction > 1.0) fraction = 1.0;
+  if (progressBarType == DETERMINATE && fraction > progress) {
+    // Skip updates that aren't visibly different.
+    int width = gr_get_width(progressBarEmpty);
+    float scale = width * progressScopeSize;
+    if ((int)(progress * scale) != (int)(fraction * scale)) {
+      progress = fraction;
+      update_progress_locked();
     }
-    pthread_mutex_unlock(&updateMutex);
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::SetStage(int current, int max) {
-    pthread_mutex_lock(&updateMutex);
-    stage = current;
-    max_stage = max;
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  stage = current;
+  max_stage = max;
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
-    std::string str;
-    android::base::StringAppendV(&str, fmt, ap);
+  std::string str;
+  android::base::StringAppendV(&str, fmt, ap);
 
-    if (copy_to_stdout) {
-        fputs(str.c_str(), stdout);
-    }
+  if (copy_to_stdout) {
+    fputs(str.c_str(), stdout);
+  }
 
-    pthread_mutex_lock(&updateMutex);
-    if (text_rows_ > 0 && text_cols_ > 0) {
-        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 (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
-            }
-            if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
-        }
+  pthread_mutex_lock(&updateMutex);
+  if (text_rows_ > 0 && text_cols_ > 0) {
+    for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
+      if (*ptr == '\n' || text_col_ >= text_cols_) {
         text_[text_row_][text_col_] = '\0';
-        update_screen_locked();
+        text_col_ = 0;
+        text_row_ = (text_row_ + 1) % text_rows_;
+        if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
+      }
+      if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
     }
-    pthread_mutex_unlock(&updateMutex);
+    text_[text_row_][text_col_] = '\0';
+    update_screen_locked();
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::Print(const char* fmt, ...) {
-    va_list ap;
-    va_start(ap, fmt);
-    PrintV(fmt, true, ap);
-    va_end(ap);
+  va_list ap;
+  va_start(ap, fmt);
+  PrintV(fmt, true, ap);
+  va_end(ap);
 }
 
 void ScreenRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
-    va_list ap;
-    va_start(ap, fmt);
-    PrintV(fmt, false, ap);
-    va_end(ap);
+  va_list ap;
+  va_start(ap, fmt);
+  PrintV(fmt, false, ap);
+  va_end(ap);
 }
 
 void ScreenRecoveryUI::PutChar(char ch) {
-    pthread_mutex_lock(&updateMutex);
-    if (ch != '\n') text_[text_row_][text_col_++] = ch;
-    if (ch == '\n' || text_col_ >= text_cols_) {
-        text_col_ = 0;
-        ++text_row_;
+  pthread_mutex_lock(&updateMutex);
+  if (ch != '\n') text_[text_row_][text_col_++] = ch;
+  if (ch == '\n' || text_col_ >= text_cols_) {
+    text_col_ = 0;
+    ++text_row_;
 
-        if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
-    }
-    pthread_mutex_unlock(&updateMutex);
+    if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::ClearText() {
-    pthread_mutex_lock(&updateMutex);
-    text_col_ = 0;
-    text_row_ = 0;
-    text_top_ = 1;
-    for (size_t i = 0; i < text_rows_; ++i) {
-        memset(text_[i], 0, text_cols_ + 1);
-    }
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  text_col_ = 0;
+  text_row_ = 0;
+  text_top_ = 1;
+  for (size_t i = 0; i < text_rows_; ++i) {
+    memset(text_[i], 0, text_cols_ + 1);
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::ShowFile(FILE* fp) {
-    std::vector<off_t> offsets;
-    offsets.push_back(ftello(fp));
-    ClearText();
+  std::vector<off_t> offsets;
+  offsets.push_back(ftello(fp));
+  ClearText();
 
-    struct stat sb;
-    fstat(fileno(fp), &sb);
+  struct stat sb;
+  fstat(fileno(fp), &sb);
 
-    bool show_prompt = false;
-    while (true) {
-        if (show_prompt) {
-            PrintOnScreenOnly("--(%d%% of %d bytes)--",
-                  static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
-                  static_cast<int>(sb.st_size));
-            Redraw();
-            while (show_prompt) {
-                show_prompt = false;
-                int key = WaitKey();
-                if (key == KEY_POWER || key == KEY_ENTER) {
-                    return;
-                } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
-                    if (offsets.size() <= 1) {
-                        show_prompt = true;
-                    } else {
-                        offsets.pop_back();
-                        fseek(fp, offsets.back(), SEEK_SET);
-                    }
-                } else {
-                    if (feof(fp)) {
-                        return;
-                    }
-                    offsets.push_back(ftello(fp));
-                }
-            }
-            ClearText();
-        }
-
-        int ch = getc(fp);
-        if (ch == EOF) {
-            while (text_row_ < text_rows_ - 1) PutChar('\n');
+  bool show_prompt = false;
+  while (true) {
+    if (show_prompt) {
+      PrintOnScreenOnly("--(%d%% of %d bytes)--",
+                        static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
+                        static_cast<int>(sb.st_size));
+      Redraw();
+      while (show_prompt) {
+        show_prompt = false;
+        int key = WaitKey();
+        if (key == KEY_POWER || key == KEY_ENTER) {
+          return;
+        } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
+          if (offsets.size() <= 1) {
             show_prompt = true;
+          } else {
+            offsets.pop_back();
+            fseek(fp, offsets.back(), SEEK_SET);
+          }
         } else {
-            PutChar(ch);
-            if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
-                show_prompt = true;
-            }
+          if (feof(fp)) {
+            return;
+          }
+          offsets.push_back(ftello(fp));
         }
+      }
+      ClearText();
     }
+
+    int ch = getc(fp);
+    if (ch == EOF) {
+      while (text_row_ < text_rows_ - 1) PutChar('\n');
+      show_prompt = true;
+    } else {
+      PutChar(ch);
+      if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
+        show_prompt = true;
+      }
+    }
+  }
 }
 
 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));
-        return;
-    }
+  FILE* fp = fopen_path(filename, "re");
+  if (fp == nullptr) {
+    Print("  Unable to open %s: %s\n", filename, strerror(errno));
+    return;
+  }
 
-    char** old_text = text_;
-    size_t old_text_col = text_col_;
-    size_t old_text_row = text_row_;
-    size_t old_text_top = text_top_;
+  char** old_text = text_;
+  size_t old_text_col = text_col_;
+  size_t old_text_row = text_row_;
+  size_t old_text_top = text_top_;
 
-    // Swap in the alternate screen and clear it.
-    text_ = file_viewer_text_;
-    ClearText();
+  // Swap in the alternate screen and clear it.
+  text_ = file_viewer_text_;
+  ClearText();
 
-    ShowFile(fp);
-    fclose(fp);
+  ShowFile(fp);
+  fclose(fp);
 
-    text_ = old_text;
-    text_col_ = old_text_col;
-    text_row_ = old_text_row;
-    text_top_ = old_text_top;
+  text_ = old_text;
+  text_col_ = old_text_col;
+  text_row_ = old_text_row;
+  text_top_ = old_text_top;
 }
 
-void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
+void ScreenRecoveryUI::StartMenu(const char* const* headers, const char* const* items,
                                  int initial_selection) {
-    pthread_mutex_lock(&updateMutex);
-    if (text_rows_ > 0 && text_cols_ > 0) {
-        menu_headers_ = headers;
-        size_t i = 0;
-        for (; i < text_rows_ && items[i] != nullptr; ++i) {
-            strncpy(menu_[i], items[i], text_cols_ - 1);
-            menu_[i][text_cols_ - 1] = '\0';
-        }
-        menu_items = i;
-        show_menu = true;
-        menu_sel = initial_selection;
-        update_screen_locked();
+  pthread_mutex_lock(&updateMutex);
+  if (text_rows_ > 0 && text_cols_ > 0) {
+    menu_headers_ = headers;
+    size_t i = 0;
+    for (; i < text_rows_ && items[i] != nullptr; ++i) {
+      strncpy(menu_[i], items[i], text_cols_ - 1);
+      menu_[i][text_cols_ - 1] = '\0';
     }
-    pthread_mutex_unlock(&updateMutex);
+    menu_items = i;
+    show_menu = true;
+    menu_sel = initial_selection;
+    update_screen_locked();
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 int ScreenRecoveryUI::SelectMenu(int sel) {
-    pthread_mutex_lock(&updateMutex);
-    if (show_menu) {
-        int old_sel = menu_sel;
-        menu_sel = sel;
+  pthread_mutex_lock(&updateMutex);
+  if (show_menu) {
+    int old_sel = menu_sel;
+    menu_sel = sel;
 
-        // Wrap at top and bottom.
-        if (menu_sel < 0) menu_sel = menu_items - 1;
-        if (menu_sel >= menu_items) menu_sel = 0;
+    // Wrap at top and bottom.
+    if (menu_sel < 0) menu_sel = menu_items - 1;
+    if (menu_sel >= menu_items) menu_sel = 0;
 
-        sel = menu_sel;
-        if (menu_sel != old_sel) update_screen_locked();
-    }
-    pthread_mutex_unlock(&updateMutex);
-    return sel;
+    sel = menu_sel;
+    if (menu_sel != old_sel) update_screen_locked();
+  }
+  pthread_mutex_unlock(&updateMutex);
+  return sel;
 }
 
 void ScreenRecoveryUI::EndMenu() {
-    pthread_mutex_lock(&updateMutex);
-    if (show_menu && text_rows_ > 0 && text_cols_ > 0) {
-        show_menu = false;
-        update_screen_locked();
-    }
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  if (show_menu && text_rows_ > 0 && text_cols_ > 0) {
+    show_menu = false;
+    update_screen_locked();
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 bool ScreenRecoveryUI::IsTextVisible() {
-    pthread_mutex_lock(&updateMutex);
-    int visible = show_text;
-    pthread_mutex_unlock(&updateMutex);
-    return visible;
+  pthread_mutex_lock(&updateMutex);
+  int visible = show_text;
+  pthread_mutex_unlock(&updateMutex);
+  return visible;
 }
 
 bool ScreenRecoveryUI::WasTextEverVisible() {
-    pthread_mutex_lock(&updateMutex);
-    int ever_visible = show_text_ever;
-    pthread_mutex_unlock(&updateMutex);
-    return ever_visible;
+  pthread_mutex_lock(&updateMutex);
+  int ever_visible = show_text_ever;
+  pthread_mutex_unlock(&updateMutex);
+  return ever_visible;
 }
 
 void ScreenRecoveryUI::ShowText(bool visible) {
-    pthread_mutex_lock(&updateMutex);
-    show_text = visible;
-    if (show_text) show_text_ever = true;
-    update_screen_locked();
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  show_text = visible;
+  if (show_text) show_text_ever = true;
+  update_screen_locked();
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::Redraw() {
-    pthread_mutex_lock(&updateMutex);
-    update_screen_locked();
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  update_screen_locked();
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void ScreenRecoveryUI::KeyLongPress(int) {
-    // Redraw so that if we're in the menu, the highlight
-    // will change color to indicate a successful long press.
-    Redraw();
+  // Redraw so that if we're in the menu, the highlight
+  // will change color to indicate a successful long press.
+  Redraw();
 }
diff --git a/screen_ui.h b/screen_ui.h
index e961c1c..8402fac 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -30,153 +30,163 @@
 // Implementation of RecoveryUI appropriate for devices with a screen
 // (shows an icon + a progress bar, text logging, menu, etc.)
 class ScreenRecoveryUI : public RecoveryUI {
-  public:
-    ScreenRecoveryUI();
+ public:
+  ScreenRecoveryUI();
 
-    bool Init(const std::string& locale) override;
+  bool Init(const std::string& locale) override;
 
-    // overall recovery state ("background image")
-    void SetBackground(Icon icon);
-    void SetSystemUpdateText(bool security_update);
+  // overall recovery state ("background image")
+  void SetBackground(Icon icon) override;
+  void SetSystemUpdateText(bool security_update) override;
 
-    // progress indicator
-    void SetProgressType(ProgressType type) override;
-    void ShowProgress(float portion, float seconds) override;
-    void SetProgress(float fraction) override;
+  // progress indicator
+  void SetProgressType(ProgressType type) override;
+  void ShowProgress(float portion, float seconds) override;
+  void SetProgress(float fraction) override;
 
-    void SetStage(int current, int max) override;
+  void SetStage(int current, int max) override;
 
-    // text log
-    void ShowText(bool visible) override;
-    bool IsTextVisible() override;
-    bool WasTextEverVisible() override;
+  // text log
+  void ShowText(bool visible) override;
+  bool IsTextVisible() override;
+  bool WasTextEverVisible() override;
 
-    // printing messages
-    void Print(const char* fmt, ...) __printflike(2, 3);
-    void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3);
-    void ShowFile(const char* filename);
+  // 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;
 
-    // menu display
-    void StartMenu(const char* const * headers, const char* const * items,
-                   int initial_selection);
-    int SelectMenu(int sel);
-    void EndMenu();
+  // menu display
+  void StartMenu(const char* const* headers, const char* const* items,
+                 int initial_selection) override;
+  int SelectMenu(int sel) override;
+  void EndMenu() override;
 
-    void KeyLongPress(int);
+  void KeyLongPress(int) override;
 
-    void Redraw();
+  void Redraw();
 
-    enum UIElement {
-        HEADER, MENU, MENU_SEL_BG, MENU_SEL_BG_ACTIVE, MENU_SEL_FG, LOG, TEXT_FILL, INFO
-    };
-    void SetColor(UIElement e);
+  enum UIElement {
+    HEADER,
+    MENU,
+    MENU_SEL_BG,
+    MENU_SEL_BG_ACTIVE,
+    MENU_SEL_FG,
+    LOG,
+    TEXT_FILL,
+    INFO
+  };
+  void SetColor(UIElement e) const;
 
-  protected:
-    // The margin that we don't want to use for showing texts (e.g. round screen, or screen with
-    // rounded corners).
-    const int kMarginWidth;
-    const int kMarginHeight;
+ protected:
+  // The margin that we don't want to use for showing texts (e.g. round screen, or screen with
+  // rounded corners).
+  const int kMarginWidth;
+  const int kMarginHeight;
 
-    // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
-    const float density_;
+  // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
+  const float density_;
 
-    Icon currentIcon;
+  Icon currentIcon;
 
-    // The layout to use.
-    int layout_;
+  // The layout to use.
+  int layout_;
 
-    GRSurface* error_icon;
+  GRSurface* error_icon;
 
-    GRSurface* erasing_text;
-    GRSurface* error_text;
-    GRSurface* installing_text;
-    GRSurface* no_command_text;
+  GRSurface* erasing_text;
+  GRSurface* error_text;
+  GRSurface* installing_text;
+  GRSurface* no_command_text;
 
-    GRSurface** introFrames;
-    GRSurface** loopFrames;
+  GRSurface** introFrames;
+  GRSurface** loopFrames;
 
-    GRSurface* progressBarEmpty;
-    GRSurface* progressBarFill;
-    GRSurface* stageMarkerEmpty;
-    GRSurface* stageMarkerFill;
+  GRSurface* progressBarEmpty;
+  GRSurface* progressBarFill;
+  GRSurface* stageMarkerEmpty;
+  GRSurface* stageMarkerFill;
 
-    ProgressType progressBarType;
+  ProgressType progressBarType;
 
-    float progressScopeStart, progressScopeSize, progress;
-    double progressScopeTime, progressScopeDuration;
+  float progressScopeStart, progressScopeSize, progress;
+  double progressScopeTime, progressScopeDuration;
 
-    // true when both graphics pages are the same (except for the progress bar).
-    bool pagesIdentical;
+  // true when both graphics pages are the same (except for the progress bar).
+  bool pagesIdentical;
 
-    size_t text_cols_, text_rows_;
+  size_t text_cols_, text_rows_;
 
-    // Log text overlay, displayed when a magic key is pressed.
-    char** text_;
-    size_t text_col_, text_row_, text_top_;
-    int log_bottom_offset_;
+  // Log text overlay, displayed when a magic key is pressed.
+  char** text_;
+  size_t text_col_, text_row_, text_top_;
 
-    bool show_text;
-    bool show_text_ever;   // has show_text ever been true?
+  bool show_text;
+  bool show_text_ever;  // has show_text ever been true?
 
-    char** menu_;
-    const char* const* menu_headers_;
-    bool show_menu;
-    int menu_items, menu_sel;
+  char** menu_;
+  const char* const* menu_headers_;
+  bool show_menu;
+  int menu_items, menu_sel;
 
-    // An alternate text screen, swapped with 'text_' when we're viewing a log file.
-    char** file_viewer_text_;
+  // An alternate text screen, swapped with 'text_' when we're viewing a log file.
+  char** file_viewer_text_;
 
-    pthread_t progress_thread_;
+  pthread_t progress_thread_;
 
-    // Number of intro frames and loop frames in the animation.
-    size_t intro_frames;
-    size_t loop_frames;
+  // Number of intro frames and loop frames in the animation.
+  size_t intro_frames;
+  size_t loop_frames;
 
-    size_t current_frame;
-    bool intro_done;
+  size_t current_frame;
+  bool intro_done;
 
-    // Number of frames per sec (default: 30) for both parts of the animation.
-    int animation_fps;
+  // Number of frames per sec (default: 30) for both parts of the animation.
+  int animation_fps;
 
-    int stage, max_stage;
+  int stage, max_stage;
 
-    int char_width_;
-    int char_height_;
+  int char_width_;
+  int char_height_;
 
-    pthread_mutex_t updateMutex;
+  pthread_mutex_t updateMutex;
 
-    virtual bool InitTextParams();
+  virtual bool InitTextParams();
 
-    virtual void draw_background_locked();
-    virtual void draw_foreground_locked();
-    virtual void draw_screen_locked();
-    virtual void update_screen_locked();
-    virtual void update_progress_locked();
+  virtual void draw_background_locked();
+  virtual void draw_foreground_locked();
+  virtual void draw_screen_locked();
+  virtual void update_screen_locked();
+  virtual void update_progress_locked();
 
-    GRSurface* GetCurrentFrame();
-    GRSurface* GetCurrentText();
+  GRSurface* GetCurrentFrame() const;
+  GRSurface* GetCurrentText() const;
 
-    static void* ProgressThreadStartRoutine(void* data);
-    void ProgressThreadLoop();
+  static void* ProgressThreadStartRoutine(void* data);
+  void ProgressThreadLoop();
 
-    virtual void ShowFile(FILE*);
-    virtual void PrintV(const char*, bool, va_list);
-    void PutChar(char);
-    void ClearText();
+  virtual void ShowFile(FILE*);
+  virtual void PrintV(const char*, bool, va_list);
+  void PutChar(char);
+  void ClearText();
 
-    void LoadAnimation();
-    void LoadBitmap(const char* filename, GRSurface** surface);
-    void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
+  void LoadAnimation();
+  void LoadBitmap(const char* filename, GRSurface** surface);
+  void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
 
-    int PixelsFromDp(int dp) const;
-    virtual int GetAnimationBaseline();
-    virtual int GetProgressBaseline();
-    virtual int GetTextBaseline();
+  int PixelsFromDp(int dp) const;
+  virtual int GetAnimationBaseline() const;
+  virtual int GetProgressBaseline() const;
+  virtual int GetTextBaseline() const;
 
-    virtual void DrawHorizontalRule(int* y);
-    virtual void DrawHighlightBar(int x, int y, int width, int height) const;
-    virtual void DrawTextLine(int x, int* y, const char* line, bool bold) const;
-    void DrawTextLines(int x, int* y, const char* const* lines) const;
+  // Draws a highlight bar at (x, y) - (x + width, y + height).
+  virtual void DrawHighlightBar(int x, int y, int width, int height) const;
+  // Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
+  virtual int DrawHorizontalRule(int y) const;
+  // Draws a line of text. Returns the offset it should be moving along Y-axis.
+  virtual int DrawTextLine(int x, int y, const char* line, bool bold) const;
+  // Draws multiple text lines. Returns the offset it should be moving along Y-axis.
+  int DrawTextLines(int x, int y, const char* const* lines) const;
 };
 
 #endif  // RECOVERY_UI_H
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 35e87fd..0298a76 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -224,102 +224,6 @@
     expect("", script6.c_str(), kNoCause);
 }
 
-TEST_F(UpdaterTest, package_extract_dir) {
-  // package_extract_dir expects 2 arguments.
-  expect(nullptr, "package_extract_dir()", kArgsParsingFailure);
-  expect(nullptr, "package_extract_dir(\"arg1\")", kArgsParsingFailure);
-  expect(nullptr, "package_extract_dir(\"arg1\", \"arg2\", \"arg3\")", kArgsParsingFailure);
-
-  std::string zip_path = from_testdata_base("ziptest_valid.zip");
-  ZipArchiveHandle handle;
-  ASSERT_EQ(0, OpenArchive(zip_path.c_str(), &handle));
-
-  // Need to set up the ziphandle.
-  UpdaterInfo updater_info;
-  updater_info.package_zip = handle;
-
-  // Extract "b/c.txt" and "b/d.txt" with package_extract_dir("b", "<dir>").
-  TemporaryDir td;
-  std::string temp_dir(td.path);
-  std::string script("package_extract_dir(\"b\", \"" + temp_dir + "\")");
-  expect("t", script.c_str(), kNoCause, &updater_info);
-
-  // Verify.
-  std::string data;
-  std::string file_c = temp_dir + "/c.txt";
-  ASSERT_TRUE(android::base::ReadFileToString(file_c, &data));
-  ASSERT_EQ(kCTxtContents, data);
-
-  std::string file_d = temp_dir + "/d.txt";
-  ASSERT_TRUE(android::base::ReadFileToString(file_d, &data));
-  ASSERT_EQ(kDTxtContents, data);
-
-  // Modify the contents in order to retry. It's expected to be overwritten.
-  ASSERT_TRUE(android::base::WriteStringToFile("random", file_c));
-  ASSERT_TRUE(android::base::WriteStringToFile("random", file_d));
-
-  // Extract again and verify.
-  expect("t", script.c_str(), kNoCause, &updater_info);
-
-  ASSERT_TRUE(android::base::ReadFileToString(file_c, &data));
-  ASSERT_EQ(kCTxtContents, data);
-  ASSERT_TRUE(android::base::ReadFileToString(file_d, &data));
-  ASSERT_EQ(kDTxtContents, data);
-
-  // Clean up the temp files under td.
-  ASSERT_EQ(0, unlink(file_c.c_str()));
-  ASSERT_EQ(0, unlink(file_d.c_str()));
-
-  // Extracting "b/" (with slash) should give the same result.
-  script = "package_extract_dir(\"b/\", \"" + temp_dir + "\")";
-  expect("t", script.c_str(), kNoCause, &updater_info);
-
-  ASSERT_TRUE(android::base::ReadFileToString(file_c, &data));
-  ASSERT_EQ(kCTxtContents, data);
-  ASSERT_TRUE(android::base::ReadFileToString(file_d, &data));
-  ASSERT_EQ(kDTxtContents, data);
-
-  ASSERT_EQ(0, unlink(file_c.c_str()));
-  ASSERT_EQ(0, unlink(file_d.c_str()));
-
-  // Extracting "" is allowed. The entries will carry the path name.
-  script = "package_extract_dir(\"\", \"" + temp_dir + "\")";
-  expect("t", script.c_str(), kNoCause, &updater_info);
-
-  std::string file_a = temp_dir + "/a.txt";
-  ASSERT_TRUE(android::base::ReadFileToString(file_a, &data));
-  ASSERT_EQ(kATxtContents, data);
-  std::string file_b = temp_dir + "/b.txt";
-  ASSERT_TRUE(android::base::ReadFileToString(file_b, &data));
-  ASSERT_EQ(kBTxtContents, data);
-  std::string file_b_c = temp_dir + "/b/c.txt";
-  ASSERT_TRUE(android::base::ReadFileToString(file_b_c, &data));
-  ASSERT_EQ(kCTxtContents, data);
-  std::string file_b_d = temp_dir + "/b/d.txt";
-  ASSERT_TRUE(android::base::ReadFileToString(file_b_d, &data));
-  ASSERT_EQ(kDTxtContents, data);
-
-  ASSERT_EQ(0, unlink(file_a.c_str()));
-  ASSERT_EQ(0, unlink(file_b.c_str()));
-  ASSERT_EQ(0, unlink(file_b_c.c_str()));
-  ASSERT_EQ(0, unlink(file_b_d.c_str()));
-  ASSERT_EQ(0, rmdir((temp_dir + "/b").c_str()));
-
-  // Extracting non-existent entry should still give "t".
-  script = "package_extract_dir(\"doesntexist\", \"" + temp_dir + "\")";
-  expect("t", script.c_str(), kNoCause, &updater_info);
-
-  // Only relative zip_path is allowed.
-  script = "package_extract_dir(\"/b\", \"" + temp_dir + "\")";
-  expect("", script.c_str(), kNoCause, &updater_info);
-
-  // Only absolute dest_path is allowed.
-  script = "package_extract_dir(\"b\", \"path\")";
-  expect("", script.c_str(), kNoCause, &updater_info);
-
-  CloseArchive(handle);
-}
-
 // TODO: Test extracting to block device.
 TEST_F(UpdaterTest, package_extract_file) {
   // package_extract_file expects 1 or 2 arguments.
diff --git a/ui.cpp b/ui.cpp
index cad7449..30b42a1 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -71,23 +71,23 @@
 }
 
 void RecoveryUI::OnKeyDetected(int key_code) {
-    if (key_code == KEY_POWER) {
-        has_power_key = true;
-    } else if (key_code == KEY_DOWN || key_code == KEY_VOLUMEDOWN) {
-        has_down_key = true;
-    } else if (key_code == KEY_UP || key_code == KEY_VOLUMEUP) {
-        has_up_key = true;
-    }
+  if (key_code == KEY_POWER) {
+    has_power_key = true;
+  } else if (key_code == KEY_DOWN || key_code == KEY_VOLUMEDOWN) {
+    has_down_key = true;
+  } else if (key_code == KEY_UP || key_code == KEY_VOLUMEUP) {
+    has_up_key = true;
+  }
 }
 
 // Reads input events, handles special hot keys, and adds to the key queue.
 static void* InputThreadLoop(void*) {
-    while (true) {
-        if (!ev_wait(-1)) {
-            ev_dispatch();
-        }
+  while (true) {
+    if (!ev_wait(-1)) {
+      ev_dispatch();
     }
-    return nullptr;
+  }
+  return nullptr;
 }
 
 bool RecoveryUI::InitScreensaver() {
@@ -141,39 +141,39 @@
 }
 
 int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) {
-    struct input_event ev;
-    if (ev_get_input(fd, epevents, &ev) == -1) {
-        return -1;
-    }
+  struct input_event ev;
+  if (ev_get_input(fd, epevents, &ev) == -1) {
+    return -1;
+  }
 
-    if (ev.type == EV_SYN) {
-        return 0;
-    } else if (ev.type == EV_REL) {
-        if (ev.code == REL_Y) {
-            // accumulate the up or down motion reported by
-            // the trackball.  When it exceeds a threshold
-            // (positive or negative), fake an up/down
-            // key event.
-            rel_sum += ev.value;
-            if (rel_sum > 3) {
-                ProcessKey(KEY_DOWN, 1);   // press down key
-                ProcessKey(KEY_DOWN, 0);   // and release it
-                rel_sum = 0;
-            } else if (rel_sum < -3) {
-                ProcessKey(KEY_UP, 1);     // press up key
-                ProcessKey(KEY_UP, 0);     // and release it
-                rel_sum = 0;
-            }
-        }
-    } else {
-        rel_sum = 0;
-    }
-
-    if (ev.type == EV_KEY && ev.code <= KEY_MAX) {
-        ProcessKey(ev.code, ev.value);
-    }
-
+  if (ev.type == EV_SYN) {
     return 0;
+  } else if (ev.type == EV_REL) {
+    if (ev.code == REL_Y) {
+      // accumulate the up or down motion reported by
+      // the trackball.  When it exceeds a threshold
+      // (positive or negative), fake an up/down
+      // key event.
+      rel_sum += ev.value;
+      if (rel_sum > 3) {
+        ProcessKey(KEY_DOWN, 1);  // press down key
+        ProcessKey(KEY_DOWN, 0);  // and release it
+        rel_sum = 0;
+      } else if (rel_sum < -3) {
+        ProcessKey(KEY_UP, 1);  // press up key
+        ProcessKey(KEY_UP, 0);  // and release it
+        rel_sum = 0;
+      }
+    }
+  } else {
+    rel_sum = 0;
+  }
+
+  if (ev.type == EV_KEY && ev.code <= KEY_MAX) {
+    ProcessKey(ev.code, ev.value);
+  }
+
+  return 0;
 }
 
 // Process a key-up or -down event.  A key is "registered" when it is
@@ -189,82 +189,84 @@
 //
 // updown == 1 for key down events; 0 for key up events
 void RecoveryUI::ProcessKey(int key_code, int updown) {
-    bool register_key = false;
-    bool long_press = false;
-    bool reboot_enabled;
+  bool register_key = false;
+  bool long_press = false;
+  bool reboot_enabled;
 
-    pthread_mutex_lock(&key_queue_mutex);
-    key_pressed[key_code] = updown;
-    if (updown) {
-        ++key_down_count;
-        key_last_down = key_code;
-        key_long_press = false;
-        key_timer_t* info = new key_timer_t;
-        info->ui = this;
-        info->key_code = key_code;
-        info->count = key_down_count;
-        pthread_t thread;
-        pthread_create(&thread, nullptr, &RecoveryUI::time_key_helper, info);
-        pthread_detach(thread);
-    } else {
-        if (key_last_down == key_code) {
-            long_press = key_long_press;
-            register_key = true;
-        }
-        key_last_down = -1;
+  pthread_mutex_lock(&key_queue_mutex);
+  key_pressed[key_code] = updown;
+  if (updown) {
+    ++key_down_count;
+    key_last_down = key_code;
+    key_long_press = false;
+    key_timer_t* info = new key_timer_t;
+    info->ui = this;
+    info->key_code = key_code;
+    info->count = key_down_count;
+    pthread_t thread;
+    pthread_create(&thread, nullptr, &RecoveryUI::time_key_helper, info);
+    pthread_detach(thread);
+  } else {
+    if (key_last_down == key_code) {
+      long_press = key_long_press;
+      register_key = true;
     }
-    reboot_enabled = enable_reboot;
-    pthread_mutex_unlock(&key_queue_mutex);
+    key_last_down = -1;
+  }
+  reboot_enabled = enable_reboot;
+  pthread_mutex_unlock(&key_queue_mutex);
 
-    if (register_key) {
-        switch (CheckKey(key_code, long_press)) {
-          case RecoveryUI::IGNORE:
-            break;
+  if (register_key) {
+    switch (CheckKey(key_code, long_press)) {
+      case RecoveryUI::IGNORE:
+        break;
 
-          case RecoveryUI::TOGGLE:
-            ShowText(!IsTextVisible());
-            break;
+      case RecoveryUI::TOGGLE:
+        ShowText(!IsTextVisible());
+        break;
 
-          case RecoveryUI::REBOOT:
-            if (reboot_enabled) {
-                reboot("reboot,");
-                while (true) { pause(); }
-            }
-            break;
-
-          case RecoveryUI::ENQUEUE:
-            EnqueueKey(key_code);
-            break;
+      case RecoveryUI::REBOOT:
+        if (reboot_enabled) {
+          reboot("reboot,");
+          while (true) {
+            pause();
+          }
         }
+        break;
+
+      case RecoveryUI::ENQUEUE:
+        EnqueueKey(key_code);
+        break;
     }
+  }
 }
 
 void* RecoveryUI::time_key_helper(void* cookie) {
-    key_timer_t* info = static_cast<key_timer_t*>(cookie);
-    info->ui->time_key(info->key_code, info->count);
-    delete info;
-    return nullptr;
+  key_timer_t* info = static_cast<key_timer_t*>(cookie);
+  info->ui->time_key(info->key_code, info->count);
+  delete info;
+  return nullptr;
 }
 
 void RecoveryUI::time_key(int key_code, int count) {
-    usleep(750000);  // 750 ms == "long"
-    bool long_press = false;
-    pthread_mutex_lock(&key_queue_mutex);
-    if (key_last_down == key_code && key_down_count == count) {
-        long_press = key_long_press = true;
-    }
-    pthread_mutex_unlock(&key_queue_mutex);
-    if (long_press) KeyLongPress(key_code);
+  usleep(750000);  // 750 ms == "long"
+  bool long_press = false;
+  pthread_mutex_lock(&key_queue_mutex);
+  if (key_last_down == key_code && key_down_count == count) {
+    long_press = key_long_press = true;
+  }
+  pthread_mutex_unlock(&key_queue_mutex);
+  if (long_press) KeyLongPress(key_code);
 }
 
 void RecoveryUI::EnqueueKey(int key_code) {
-    pthread_mutex_lock(&key_queue_mutex);
-    const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
-    if (key_queue_len < queue_max) {
-        key_queue[key_queue_len++] = key_code;
-        pthread_cond_signal(&key_queue_cond);
-    }
-    pthread_mutex_unlock(&key_queue_mutex);
+  pthread_mutex_lock(&key_queue_mutex);
+  const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
+  if (key_queue_len < queue_max) {
+    key_queue[key_queue_len++] = key_code;
+    pthread_cond_signal(&key_queue_cond);
+  }
+  pthread_mutex_unlock(&key_queue_mutex);
 }
 
 int RecoveryUI::WaitKey() {
@@ -330,98 +332,96 @@
 }
 
 bool RecoveryUI::IsUsbConnected() {
-    int fd = open("/sys/class/android_usb/android0/state", O_RDONLY);
-    if (fd < 0) {
-        printf("failed to open /sys/class/android_usb/android0/state: %s\n",
-               strerror(errno));
-        return 0;
-    }
+  int fd = open("/sys/class/android_usb/android0/state", O_RDONLY);
+  if (fd < 0) {
+    printf("failed to open /sys/class/android_usb/android0/state: %s\n", strerror(errno));
+    return 0;
+  }
 
-    char buf;
-    // USB is connected if android_usb state is CONNECTED or CONFIGURED.
-    int connected = (TEMP_FAILURE_RETRY(read(fd, &buf, 1)) == 1) && (buf == 'C');
-    if (close(fd) < 0) {
-        printf("failed to close /sys/class/android_usb/android0/state: %s\n",
-               strerror(errno));
-    }
-    return connected;
+  char buf;
+  // USB is connected if android_usb state is CONNECTED or CONFIGURED.
+  int connected = (TEMP_FAILURE_RETRY(read(fd, &buf, 1)) == 1) && (buf == 'C');
+  if (close(fd) < 0) {
+    printf("failed to close /sys/class/android_usb/android0/state: %s\n", strerror(errno));
+  }
+  return connected;
 }
 
 bool RecoveryUI::IsKeyPressed(int key) {
-    pthread_mutex_lock(&key_queue_mutex);
-    int pressed = key_pressed[key];
-    pthread_mutex_unlock(&key_queue_mutex);
-    return pressed;
+  pthread_mutex_lock(&key_queue_mutex);
+  int pressed = key_pressed[key];
+  pthread_mutex_unlock(&key_queue_mutex);
+  return pressed;
 }
 
 bool RecoveryUI::IsLongPress() {
-    pthread_mutex_lock(&key_queue_mutex);
-    bool result = key_long_press;
-    pthread_mutex_unlock(&key_queue_mutex);
-    return result;
+  pthread_mutex_lock(&key_queue_mutex);
+  bool result = key_long_press;
+  pthread_mutex_unlock(&key_queue_mutex);
+  return result;
 }
 
 bool RecoveryUI::HasThreeButtons() {
-    return has_power_key && has_up_key && has_down_key;
+  return has_power_key && has_up_key && has_down_key;
 }
 
 void RecoveryUI::FlushKeys() {
-    pthread_mutex_lock(&key_queue_mutex);
-    key_queue_len = 0;
-    pthread_mutex_unlock(&key_queue_mutex);
+  pthread_mutex_lock(&key_queue_mutex);
+  key_queue_len = 0;
+  pthread_mutex_unlock(&key_queue_mutex);
 }
 
 RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
+  pthread_mutex_lock(&key_queue_mutex);
+  key_long_press = false;
+  pthread_mutex_unlock(&key_queue_mutex);
+
+  // If we have power and volume up keys, that chord is the signal to toggle the text display.
+  if (HasThreeButtons()) {
+    if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) {
+      return TOGGLE;
+    }
+  } else {
+    // Otherwise long press of any button toggles to the text display,
+    // and there's no way to toggle back (but that's pretty useless anyway).
+    if (is_long_press && !IsTextVisible()) {
+      return TOGGLE;
+    }
+
+    // Also, for button-limited devices, a long press is translated to KEY_ENTER.
+    if (is_long_press && IsTextVisible()) {
+      EnqueueKey(KEY_ENTER);
+      return IGNORE;
+    }
+  }
+
+  // Press power seven times in a row to reboot.
+  if (key == KEY_POWER) {
     pthread_mutex_lock(&key_queue_mutex);
-    key_long_press = false;
+    bool reboot_enabled = enable_reboot;
     pthread_mutex_unlock(&key_queue_mutex);
 
-    // If we have power and volume up keys, that chord is the signal to toggle the text display.
-    if (HasThreeButtons()) {
-        if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) {
-            return TOGGLE;
-        }
-    } else {
-        // Otherwise long press of any button toggles to the text display,
-        // and there's no way to toggle back (but that's pretty useless anyway).
-        if (is_long_press && !IsTextVisible()) {
-            return TOGGLE;
-        }
-
-        // Also, for button-limited devices, a long press is translated to KEY_ENTER.
-        if (is_long_press && IsTextVisible()) {
-            EnqueueKey(KEY_ENTER);
-            return IGNORE;
-        }
+    if (reboot_enabled) {
+      ++consecutive_power_keys;
+      if (consecutive_power_keys >= 7) {
+        return REBOOT;
+      }
     }
+  } else {
+    consecutive_power_keys = 0;
+  }
 
-    // Press power seven times in a row to reboot.
-    if (key == KEY_POWER) {
-        pthread_mutex_lock(&key_queue_mutex);
-        bool reboot_enabled = enable_reboot;
-        pthread_mutex_unlock(&key_queue_mutex);
-
-        if (reboot_enabled) {
-            ++consecutive_power_keys;
-            if (consecutive_power_keys >= 7) {
-                return REBOOT;
-            }
-        }
-    } else {
-        consecutive_power_keys = 0;
-    }
-
-    last_key = key;
-    return (IsTextVisible() || screensaver_state_ == ScreensaverState::OFF) ? ENQUEUE : IGNORE;
+  last_key = key;
+  return (IsTextVisible() || screensaver_state_ == ScreensaverState::OFF) ? ENQUEUE : IGNORE;
 }
 
 void RecoveryUI::KeyLongPress(int) {
 }
 
 void RecoveryUI::SetEnableReboot(bool enabled) {
-    pthread_mutex_lock(&key_queue_mutex);
-    enable_reboot = enabled;
-    pthread_mutex_unlock(&key_queue_mutex);
+  pthread_mutex_lock(&key_queue_mutex);
+  enable_reboot = enabled;
+  pthread_mutex_unlock(&key_queue_mutex);
 }
 
 void RecoveryUI::SetLocale(const std::string& new_locale) {
diff --git a/ui.h b/ui.h
index 823eb65..7eb04ae 100644
--- a/ui.h
+++ b/ui.h
@@ -25,163 +25,155 @@
 
 // Abstract class for controlling the user interface during recovery.
 class RecoveryUI {
-  public:
-    RecoveryUI();
+ public:
+  RecoveryUI();
 
-    virtual ~RecoveryUI() { }
+  virtual ~RecoveryUI() {}
 
-    // Initialize the object; called before anything else. UI texts will be
-    // initialized according to the given locale. Returns true on success.
-    virtual bool Init(const std::string& locale);
+  // Initializes the object; called before anything else. UI texts will be initialized according to
+  // the given locale. Returns true on success.
+  virtual bool Init(const std::string& locale);
 
-    // Show a stage indicator.  Call immediately after Init().
-    virtual void SetStage(int current, int max) = 0;
+  // Shows a stage indicator. Called immediately after Init().
+  virtual void SetStage(int current, int max) = 0;
 
-    // Set the overall recovery state ("background image").
-    enum Icon { NONE, INSTALLING_UPDATE, ERASING, NO_COMMAND, ERROR };
-    virtual void SetBackground(Icon icon) = 0;
-    virtual void SetSystemUpdateText(bool security_update) = 0;
+  // Sets the overall recovery state ("background image").
+  enum Icon { NONE, INSTALLING_UPDATE, ERASING, NO_COMMAND, ERROR };
+  virtual void SetBackground(Icon icon) = 0;
+  virtual void SetSystemUpdateText(bool security_update) = 0;
 
-    // --- progress indicator ---
-    enum ProgressType { EMPTY, INDETERMINATE, DETERMINATE };
-    virtual void SetProgressType(ProgressType determinate) = 0;
+  // --- progress indicator ---
+  enum ProgressType { EMPTY, INDETERMINATE, DETERMINATE };
+  virtual void SetProgressType(ProgressType determinate) = 0;
 
-    // Show a progress bar and define the scope of the next operation:
-    //   portion - fraction of the progress bar the next operation will use
-    //   seconds - expected time interval (progress bar moves at this minimum rate)
-    virtual void ShowProgress(float portion, float seconds) = 0;
+  // Shows a progress bar and define the scope of the next operation:
+  //   portion - fraction of the progress bar the next operation will use
+  //   seconds - expected time interval (progress bar moves at this minimum rate)
+  virtual void ShowProgress(float portion, float seconds) = 0;
 
-    // Set progress bar position (0.0 - 1.0 within the scope defined
-    // by the last call to ShowProgress).
-    virtual void SetProgress(float fraction) = 0;
+  // Sets progress bar position (0.0 - 1.0 within the scope defined by the last call to
+  // ShowProgress).
+  virtual void SetProgress(float fraction) = 0;
 
-    // --- text log ---
+  // --- text log ---
 
-    virtual void ShowText(bool visible) = 0;
+  virtual void ShowText(bool visible) = 0;
 
-    virtual bool IsTextVisible() = 0;
+  virtual bool IsTextVisible() = 0;
 
-    virtual bool WasTextEverVisible() = 0;
+  virtual bool WasTextEverVisible() = 0;
 
-    // Write 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;
-    virtual void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3) = 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;
+  virtual void PrintOnScreenOnly(const char* fmt, ...) __printflike(2, 3) = 0;
 
-    virtual void ShowFile(const char* filename) = 0;
+  virtual void ShowFile(const char* filename) = 0;
 
-    // --- key handling ---
+  // --- key handling ---
 
-    // Wait for a key and return it.  May return -1 after timeout.
-    virtual int WaitKey();
+  // Waits for a key and return it. May return -1 after timeout.
+  virtual int WaitKey();
 
-    virtual bool IsKeyPressed(int key);
-    virtual bool IsLongPress();
+  virtual bool IsKeyPressed(int key);
+  virtual bool IsLongPress();
 
-    // Returns true if you have the volume up/down and power trio typical
-    // of phones and tablets, false otherwise.
-    virtual bool HasThreeButtons();
+  // Returns true if you have the volume up/down and power trio typical of phones and tablets, false
+  // otherwise.
+  virtual bool HasThreeButtons();
 
-    // Erase any queued-up keys.
-    virtual void FlushKeys();
+  // Erases any queued-up keys.
+  virtual void FlushKeys();
 
-    // Called on each key press, even while operations are in progress.
-    // Return value indicates whether an immediate operation should be
-    // triggered (toggling the display, rebooting the device), or if
-    // the key should be enqueued for use by the main thread.
-    enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE };
-    virtual KeyAction CheckKey(int key, bool is_long_press);
+  // Called on each key press, even while operations are in progress. Return value indicates whether
+  // an immediate operation should be triggered (toggling the display, rebooting the device), or if
+  // the key should be enqueued for use by the main thread.
+  enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE };
+  virtual KeyAction CheckKey(int key, bool is_long_press);
 
-    // Called when a key is held down long enough to have been a
-    // long-press (but before the key is released).  This means that
-    // if the key is eventually registered (released without any other
-    // keys being pressed in the meantime), CheckKey will be called with
-    // 'is_long_press' true.
-    virtual void KeyLongPress(int key);
+  // Called when a key is held down long enough to have been a long-press (but before the key is
+  // released). This means that if the key is eventually registered (released without any other keys
+  // being pressed in the meantime), CheckKey will be called with 'is_long_press' true.
+  virtual void KeyLongPress(int key);
 
-    // Normally in recovery there's a key sequence that triggers
-    // immediate reboot of the device, regardless of what recovery is
-    // doing (with the default CheckKey implementation, it's pressing
-    // the power button 7 times in row).  Call this to enable or
-    // disable that feature.  It is enabled by default.
-    virtual void SetEnableReboot(bool enabled);
+  // Normally in recovery there's a key sequence that triggers immediate reboot of the device,
+  // regardless of what recovery is doing (with the default CheckKey implementation, it's pressing
+  // the power button 7 times in row). Call this to enable or disable that feature. It is enabled by
+  // default.
+  virtual void SetEnableReboot(bool enabled);
 
-    // --- menu display ---
+  // --- menu display ---
 
-    // Display some header text followed by a menu of items, which appears
-    // at the top of the screen (in place of any scrolling ui_print()
-    // output, if necessary).
-    virtual void StartMenu(const char* const * headers, const char* const * items,
-                           int initial_selection) = 0;
+  // Display some header text followed by a menu of items, which appears at the top of the screen
+  // (in place of any scrolling ui_print() output, if necessary).
+  virtual void StartMenu(const char* const* headers, const char* const* items,
+                         int initial_selection) = 0;
 
-    // Set the menu highlight to the given index, wrapping if necessary.
-    // Returns the actual item selected.
-    virtual int SelectMenu(int sel) = 0;
+  // Sets the menu highlight to the given index, wrapping if necessary. Returns the actual item
+  // selected.
+  virtual int SelectMenu(int sel) = 0;
 
-    // End menu mode, resetting the text overlay so that ui_print()
-    // statements will be displayed.
-    virtual void EndMenu() = 0;
+  // Ends menu mode, resetting the text overlay so that ui_print() statements will be displayed.
+  virtual void EndMenu() = 0;
 
-  protected:
-    void EnqueueKey(int key_code);
+ protected:
+  void EnqueueKey(int key_code);
 
-    // The locale that's used to show the rendered texts.
-    std::string locale_;
-    bool rtl_locale_;
+  // The locale that's used to show the rendered texts.
+  std::string locale_;
+  bool rtl_locale_;
 
-    // The normal and dimmed brightness percentages (default: 50 and 25, which means 50% and 25%
-    // of the max_brightness). Because the absolute values may vary across devices. These two
-    // values can be configured via subclassing. Setting brightness_normal_ to 0 to disable
-    // screensaver.
-    unsigned int brightness_normal_;
-    unsigned int brightness_dimmed_;
+  // The normal and dimmed brightness percentages (default: 50 and 25, which means 50% and 25% of
+  // the max_brightness). Because the absolute values may vary across devices. These two values can
+  // be configured via subclassing. Setting brightness_normal_ to 0 to disable screensaver.
+  unsigned int brightness_normal_;
+  unsigned int brightness_dimmed_;
 
-  private:
-    // Key event input queue
-    pthread_mutex_t key_queue_mutex;
-    pthread_cond_t key_queue_cond;
-    int key_queue[256], key_queue_len;
-    char key_pressed[KEY_MAX + 1];     // under key_queue_mutex
-    int key_last_down;                 // under key_queue_mutex
-    bool key_long_press;               // under key_queue_mutex
-    int key_down_count;                // under key_queue_mutex
-    bool enable_reboot;                // under key_queue_mutex
-    int rel_sum;
+ private:
+  // Key event input queue
+  pthread_mutex_t key_queue_mutex;
+  pthread_cond_t key_queue_cond;
+  int key_queue[256], key_queue_len;
+  char key_pressed[KEY_MAX + 1];  // under key_queue_mutex
+  int key_last_down;              // under key_queue_mutex
+  bool key_long_press;            // under key_queue_mutex
+  int key_down_count;             // under key_queue_mutex
+  bool enable_reboot;             // under key_queue_mutex
+  int rel_sum;
 
-    int consecutive_power_keys;
-    int last_key;
+  int consecutive_power_keys;
+  int last_key;
 
-    bool has_power_key;
-    bool has_up_key;
-    bool has_down_key;
+  bool has_power_key;
+  bool has_up_key;
+  bool has_down_key;
 
-    struct key_timer_t {
-        RecoveryUI* ui;
-        int key_code;
-        int count;
-    };
+  struct key_timer_t {
+    RecoveryUI* ui;
+    int key_code;
+    int count;
+  };
 
-    pthread_t input_thread_;
+  pthread_t input_thread_;
 
-    void OnKeyDetected(int key_code);
-    int OnInputEvent(int fd, uint32_t epevents);
-    void ProcessKey(int key_code, int updown);
+  void OnKeyDetected(int key_code);
+  int OnInputEvent(int fd, uint32_t epevents);
+  void ProcessKey(int key_code, int updown);
 
-    bool IsUsbConnected();
+  bool IsUsbConnected();
 
-    static void* time_key_helper(void* cookie);
-    void time_key(int key_code, int count);
+  static void* time_key_helper(void* cookie);
+  void time_key(int key_code, int count);
 
-    void SetLocale(const std::string&);
+  void SetLocale(const std::string&);
 
-    enum class ScreensaverState { DISABLED, NORMAL, DIMMED, OFF };
-    ScreensaverState screensaver_state_;
-    // The following two contain the absolute values computed from brightness_normal_ and
-    // brightness_dimmed_ respectively.
-    unsigned int brightness_normal_value_;
-    unsigned int brightness_dimmed_value_;
-    bool InitScreensaver();
+  enum class ScreensaverState { DISABLED, NORMAL, DIMMED, OFF };
+  ScreensaverState screensaver_state_;
+  // The following two contain the absolute values computed from brightness_normal_ and
+  // brightness_dimmed_ respectively.
+  unsigned int brightness_normal_value_;
+  unsigned int brightness_dimmed_value_;
+  bool InitScreensaver();
 };
 
 #endif  // RECOVERY_UI_H
diff --git a/vr_ui.cpp b/vr_ui.cpp
index b2c65e3..1251672 100644
--- a/vr_ui.cpp
+++ b/vr_ui.cpp
@@ -18,39 +18,18 @@
 
 #include <minui/minui.h>
 
-VrRecoveryUI::VrRecoveryUI() :
-  x_offset(400),
-  y_offset(400),
-  stereo_offset(100) {
-}
+VrRecoveryUI::VrRecoveryUI() : kStereoOffset(RECOVERY_UI_VR_STEREO_OFFSET) {}
 
 bool VrRecoveryUI::InitTextParams() {
-  if (gr_init() < 0) {
-    return false;
-  }
-
-  gr_font_size(gr_sys_font(), &char_width_, &char_height_);
+  if (!ScreenRecoveryUI::InitTextParams()) return false;
   int mid_divide = gr_fb_width() / 2;
-  text_rows_ = (gr_fb_height() - 2 * y_offset) / char_height_;
-  text_cols_ = (mid_divide - x_offset - stereo_offset) / char_width_;
-  log_bottom_offset_ = gr_fb_height() - 2 * y_offset;
+  text_cols_ = (mid_divide - kMarginWidth - kStereoOffset) / char_width_;
   return true;
 }
 
-void VrRecoveryUI::DrawHorizontalRule(int* y) {
-  SetColor(MENU);
-  *y += 4;
-  gr_fill(0, *y + y_offset, gr_fb_width(), *y + y_offset + 2);
-  *y += 4;
-}
-
-void VrRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
-  gr_fill(x, y + y_offset, x + width, y + y_offset + height);
-}
-
-void VrRecoveryUI::DrawTextLine(int x, int* y, const char* line, bool bold) const {
+int VrRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
   int mid_divide = gr_fb_width() / 2;
-  gr_text(gr_sys_font(), x + x_offset + stereo_offset, *y + y_offset, line, bold);
-  gr_text(gr_sys_font(), x + x_offset - stereo_offset + mid_divide, *y + y_offset, line, bold);
-  *y += char_height_ + 4;
+  gr_text(gr_sys_font(), x + kStereoOffset, y, line, bold);
+  gr_text(gr_sys_font(), x - kStereoOffset + mid_divide, y, line, bold);
+  return char_height_ + 4;
 }
diff --git a/vr_ui.h b/vr_ui.h
index 85c5708..d996c14 100644
--- a/vr_ui.h
+++ b/vr_ui.h
@@ -20,19 +20,17 @@
 #include "screen_ui.h"
 
 class VrRecoveryUI : public ScreenRecoveryUI {
-  public:
-    VrRecoveryUI();
+ public:
+  VrRecoveryUI();
 
-  protected:
-    // Pixel offsets to move drawing functions to visible range.
-    // Can vary per device depending on screen size and lens distortion.
-    int x_offset, y_offset, stereo_offset;
+ protected:
+  // Pixel offsets to move drawing functions to visible range.
+  // Can vary per device depending on screen size and lens distortion.
+  const int kStereoOffset;
 
-    bool InitTextParams() override;
+  bool InitTextParams() override;
 
-    void DrawHorizontalRule(int* y) override;
-    void DrawHighlightBar(int x, int y, int width, int height) const override;
-    void DrawTextLine(int x, int* y, const char* line, bool bold) const override;
+  int DrawTextLine(int x, int y, const char* line, bool bold) const override;
 };
 
 #endif  // RECOVERY_VR_UI_H
diff --git a/wear_ui.cpp b/wear_ui.cpp
index 6c02865..18c30d3 100644
--- a/wear_ui.cpp
+++ b/wear_ui.cpp
@@ -45,167 +45,158 @@
 
 // Return the current time as a double (including fractions of a second).
 static double now() {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    return tv.tv_sec + tv.tv_usec / 1000000.0;
+  struct timeval tv;
+  gettimeofday(&tv, NULL);
+  return tv.tv_sec + tv.tv_usec / 1000000.0;
 }
 
-WearRecoveryUI::WearRecoveryUI() :
-    progress_bar_y(259),
-    outer_height(0),
-    outer_width(0),
-    menu_unusable_rows(0) {
-    intro_frames = 22;
-    loop_frames = 60;
-    animation_fps = 30;
+WearRecoveryUI::WearRecoveryUI()
+    : progress_bar_y(259), outer_height(0), outer_width(0), menu_unusable_rows(0) {
+  intro_frames = 22;
+  loop_frames = 60;
+  animation_fps = 30;
 
-    for (size_t i = 0; i < 5; i++)
-        backgroundIcon[i] = NULL;
+  for (size_t i = 0; i < 5; i++) backgroundIcon[i] = NULL;
 
-    self = this;
+  self = this;
 }
 
-int WearRecoveryUI::GetProgressBaseline() {
-    return progress_bar_y;
+int WearRecoveryUI::GetProgressBaseline() const {
+  return progress_bar_y;
 }
 
 // Draw background frame on the screen.  Does not flip pages.
 // Should only be called with updateMutex locked.
 // TODO merge drawing routines with screen_ui
-void WearRecoveryUI::draw_background_locked()
-{
-    pagesIdentical = false;
-    gr_color(0, 0, 0, 255);
-    gr_fill(0, 0, gr_fb_width(), gr_fb_height());
+void WearRecoveryUI::draw_background_locked() {
+  pagesIdentical = false;
+  gr_color(0, 0, 0, 255);
+  gr_fill(0, 0, gr_fb_width(), gr_fb_height());
 
-    if (currentIcon != NONE) {
-        GRSurface* surface;
-        if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
-            if (!intro_done) {
-                surface = introFrames[current_frame];
-            } else {
-                surface = loopFrames[current_frame];
-            }
-        }
-        else {
-            surface = backgroundIcon[currentIcon];
-        }
-
-        int width = gr_get_width(surface);
-        int height = gr_get_height(surface);
-
-        int x = (gr_fb_width() - width) / 2;
-        int y = (gr_fb_height() - height) / 2;
-
-        gr_blit(surface, 0, 0, width, height, x, y);
+  if (currentIcon != NONE) {
+    GRSurface* surface;
+    if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
+      if (!intro_done) {
+        surface = introFrames[current_frame];
+      } else {
+        surface = loopFrames[current_frame];
+      }
+    } else {
+      surface = backgroundIcon[currentIcon];
     }
+
+    int width = gr_get_width(surface);
+    int height = gr_get_height(surface);
+
+    int x = (gr_fb_width() - width) / 2;
+    int y = (gr_fb_height() - height) / 2;
+
+    gr_blit(surface, 0, 0, width, height, x, y);
+  }
 }
 
-static const char* HEADERS[] = {
-    "Swipe up/down to move.",
-    "Swipe left/right to select.",
-    "",
-    NULL
+static const char* SWIPE_HELP[] = {
+  "Swipe up/down to move.",
+  "Swipe left/right to select.",
+  "",
+  NULL
 };
 
 // TODO merge drawing routines with screen_ui
-void WearRecoveryUI::draw_screen_locked()
-{
-    char cur_selection_str[50];
+void WearRecoveryUI::draw_screen_locked() {
+  char cur_selection_str[50];
 
-    draw_background_locked();
-    if (!show_text) {
-        draw_foreground_locked();
-    } else {
-        SetColor(TEXT_FILL);
-        gr_fill(0, 0, gr_fb_width(), gr_fb_height());
+  draw_background_locked();
+  if (!show_text) {
+    draw_foreground_locked();
+  } else {
+    SetColor(TEXT_FILL);
+    gr_fill(0, 0, gr_fb_width(), gr_fb_height());
 
-        int y = outer_height;
-        int x = outer_width;
-        if (show_menu) {
-            std::string recovery_fingerprint =
-                    android::base::GetProperty("ro.bootimage.build.fingerprint", "");
-            SetColor(HEADER);
-            DrawTextLine(x + 4, &y, "Android Recovery", true);
-            for (auto& chunk: android::base::Split(recovery_fingerprint, ":")) {
-                DrawTextLine(x +4, &y, chunk.c_str(), false);
-            }
+    int y = outer_height;
+    int x = outer_width;
+    if (show_menu) {
+      std::string recovery_fingerprint =
+          android::base::GetProperty("ro.bootimage.build.fingerprint", "");
+      SetColor(HEADER);
+      y += DrawTextLine(x + 4, y, "Android Recovery", true);
+      for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
+        y += DrawTextLine(x + 4, y, chunk.c_str(), false);
+      }
 
-            // This is actually the help strings.
-            DrawTextLines(x + 4, &y, HEADERS);
-            SetColor(HEADER);
-            DrawTextLines(x + 4, &y, menu_headers_);
+      // This is actually the help strings.
+      y += DrawTextLines(x + 4, y, SWIPE_HELP);
+      SetColor(HEADER);
+      y += DrawTextLines(x + 4, y, menu_headers_);
 
-            // Show the current menu item number in relation to total number if
-            // items don't fit on the screen.
-            if (menu_items > menu_end - menu_start) {
-                sprintf(cur_selection_str, "Current item: %d/%d", menu_sel + 1, menu_items);
-                gr_text(gr_sys_font(), x+4, y, cur_selection_str, 1);
-                y += char_height_+4;
-            }
+      // Show the current menu item number in relation to total number if
+      // items don't fit on the screen.
+      if (menu_items > menu_end - menu_start) {
+        sprintf(cur_selection_str, "Current item: %d/%d", menu_sel + 1, menu_items);
+        gr_text(gr_sys_font(), x + 4, y, cur_selection_str, 1);
+        y += char_height_ + 4;
+      }
 
-            // Menu begins here
-            SetColor(MENU);
+      // Menu begins here
+      SetColor(MENU);
 
-            for (int i = menu_start; i < menu_end; ++i) {
-
-                if (i == menu_sel) {
-                    // draw the highlight bar
-                    SetColor(MENU_SEL_BG);
-                    gr_fill(x, y-2, gr_fb_width()-x, y+char_height_+2);
-                    // white text of selected item
-                    SetColor(MENU_SEL_FG);
-                    if (menu_[i][0]) {
-                        gr_text(gr_sys_font(), x + 4, y, menu_[i], 1);
-                    }
-                    SetColor(MENU);
-                } else if (menu_[i][0]) {
-                    gr_text(gr_sys_font(), x + 4, y, menu_[i], 0);
-                }
-                y += char_height_+4;
-            }
-            SetColor(MENU);
-            y += 4;
-            gr_fill(0, y, gr_fb_width(), y+2);
-            y += 4;
+      for (int i = menu_start; i < menu_end; ++i) {
+        if (i == menu_sel) {
+          // draw the highlight bar
+          SetColor(MENU_SEL_BG);
+          gr_fill(x, y - 2, gr_fb_width() - x, y + char_height_ + 2);
+          // white text of selected item
+          SetColor(MENU_SEL_FG);
+          if (menu_[i][0]) {
+            gr_text(gr_sys_font(), x + 4, y, menu_[i], 1);
+          }
+          SetColor(MENU);
+        } else if (menu_[i][0]) {
+          gr_text(gr_sys_font(), x + 4, y, menu_[i], 0);
         }
-
-        SetColor(LOG);
-
-        // display from the bottom up, until we hit the top of the
-        // screen, the bottom of the menu, or we've displayed the
-        // entire text buffer.
-        int ty;
-        int row = (text_top_ + text_rows_ - 1) % text_rows_;
-        size_t count = 0;
-        for (int ty = gr_fb_height() - char_height_ - outer_height;
-             ty > y + 2 && count < text_rows_;
-             ty -= char_height_, ++count) {
-            gr_text(gr_sys_font(), x+4, ty, text_[row], 0);
-            --row;
-            if (row < 0) row = text_rows_ - 1;
-        }
+        y += char_height_ + 4;
+      }
+      SetColor(MENU);
+      y += 4;
+      gr_fill(0, y, gr_fb_width(), y + 2);
+      y += 4;
     }
+
+    SetColor(LOG);
+
+    // display from the bottom up, until we hit the top of the
+    // screen, the bottom of the menu, or we've displayed the
+    // entire text buffer.
+    int ty;
+    int row = (text_top_ + text_rows_ - 1) % text_rows_;
+    size_t count = 0;
+    for (int ty = gr_fb_height() - char_height_ - outer_height; ty > y + 2 && count < text_rows_;
+         ty -= char_height_, ++count) {
+      gr_text(gr_sys_font(), x + 4, ty, text_[row], 0);
+      --row;
+      if (row < 0) row = text_rows_ - 1;
+    }
+  }
 }
 
 // TODO merge drawing routines with screen_ui
 void WearRecoveryUI::update_progress_locked() {
-    draw_screen_locked();
-    gr_flip();
+  draw_screen_locked();
+  gr_flip();
 }
 
 bool WearRecoveryUI::InitTextParams() {
-    if (!ScreenRecoveryUI::InitTextParams()) {
-        return false;
-    }
+  if (!ScreenRecoveryUI::InitTextParams()) {
+    return false;
+  }
 
-    text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_;
+  text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_;
 
-    if (text_rows_ > kMaxRows) text_rows_ = kMaxRows;
-    if (text_cols_ > kMaxCols) text_cols_ = kMaxCols;
+  if (text_rows_ > kMaxRows) text_rows_ = kMaxRows;
+  if (text_cols_ > kMaxCols) text_cols_ = kMaxCols;
 
-    visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_;
-    return true;
+  visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_;
+  return true;
 }
 
 bool WearRecoveryUI::Init(const std::string& locale) {
@@ -222,7 +213,8 @@
   return true;
 }
 
-void WearRecoveryUI::SetStage(int current, int max) {}
+void WearRecoveryUI::SetStage(int current, int max) {
+}
 
 void WearRecoveryUI::Print(const char* fmt, ...) {
   char buf[256];
@@ -252,165 +244,153 @@
   pthread_mutex_unlock(&updateMutex);
 }
 
-void WearRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
+void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* items,
                                int initial_selection) {
-    pthread_mutex_lock(&updateMutex);
-    if (text_rows_ > 0 && text_cols_ > 0) {
-        menu_headers_ = headers;
-        size_t i = 0;
-        // "i < text_rows_" is removed from the loop termination condition,
-        // which is different from the one in ScreenRecoveryUI::StartMenu().
-        // Because WearRecoveryUI supports scrollable menu, it's fine to have
-        // more entries than text_rows_. The menu may be truncated otherwise.
-        // Bug: 23752519
-        for (; items[i] != nullptr; i++) {
-            strncpy(menu_[i], items[i], text_cols_ - 1);
-            menu_[i][text_cols_ - 1] = '\0';
-        }
-        menu_items = i;
-        show_menu = true;
-        menu_sel = initial_selection;
-        menu_start = 0;
-        menu_end = visible_text_rows - 1 - menu_unusable_rows;
-        if (menu_items <= menu_end)
-          menu_end = menu_items;
-        update_screen_locked();
+  pthread_mutex_lock(&updateMutex);
+  if (text_rows_ > 0 && text_cols_ > 0) {
+    menu_headers_ = headers;
+    size_t i = 0;
+    // "i < text_rows_" is removed from the loop termination condition,
+    // which is different from the one in ScreenRecoveryUI::StartMenu().
+    // Because WearRecoveryUI supports scrollable menu, it's fine to have
+    // more entries than text_rows_. The menu may be truncated otherwise.
+    // Bug: 23752519
+    for (; items[i] != nullptr; i++) {
+      strncpy(menu_[i], items[i], text_cols_ - 1);
+      menu_[i][text_cols_ - 1] = '\0';
     }
-    pthread_mutex_unlock(&updateMutex);
+    menu_items = i;
+    show_menu = true;
+    menu_sel = initial_selection;
+    menu_start = 0;
+    menu_end = visible_text_rows - 1 - menu_unusable_rows;
+    if (menu_items <= menu_end) menu_end = menu_items;
+    update_screen_locked();
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 int WearRecoveryUI::SelectMenu(int sel) {
-    int old_sel;
-    pthread_mutex_lock(&updateMutex);
-    if (show_menu) {
-        old_sel = menu_sel;
-        menu_sel = sel;
-        if (menu_sel < 0) menu_sel = 0;
-        if (menu_sel >= menu_items) menu_sel = menu_items-1;
-        if (menu_sel < menu_start) {
-          menu_start--;
-          menu_end--;
-        } else if (menu_sel >= menu_end && menu_sel < menu_items) {
-          menu_end++;
-          menu_start++;
-        }
-        sel = menu_sel;
-        if (menu_sel != old_sel) update_screen_locked();
+  int old_sel;
+  pthread_mutex_lock(&updateMutex);
+  if (show_menu) {
+    old_sel = menu_sel;
+    menu_sel = sel;
+    if (menu_sel < 0) menu_sel = 0;
+    if (menu_sel >= menu_items) menu_sel = menu_items - 1;
+    if (menu_sel < menu_start) {
+      menu_start--;
+      menu_end--;
+    } else if (menu_sel >= menu_end && menu_sel < menu_items) {
+      menu_end++;
+      menu_start++;
     }
-    pthread_mutex_unlock(&updateMutex);
-    return sel;
+    sel = menu_sel;
+    if (menu_sel != old_sel) update_screen_locked();
+  }
+  pthread_mutex_unlock(&updateMutex);
+  return sel;
 }
 
 void WearRecoveryUI::ShowFile(FILE* fp) {
-    std::vector<off_t> offsets;
-    offsets.push_back(ftello(fp));
-    ClearText();
+  std::vector<off_t> offsets;
+  offsets.push_back(ftello(fp));
+  ClearText();
 
-    struct stat sb;
-    fstat(fileno(fp), &sb);
+  struct stat sb;
+  fstat(fileno(fp), &sb);
 
-    bool show_prompt = false;
-    while (true) {
-        if (show_prompt) {
-            Print("--(%d%% of %d bytes)--",
-                  static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
-                  static_cast<int>(sb.st_size));
-            Redraw();
-            while (show_prompt) {
-                show_prompt = false;
-                int key = WaitKey();
-                if (key == KEY_POWER || key == KEY_ENTER) {
-                    return;
-                } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
-                    if (offsets.size() <= 1) {
-                        show_prompt = true;
-                    } else {
-                        offsets.pop_back();
-                        fseek(fp, offsets.back(), SEEK_SET);
-                    }
-                } else {
-                    if (feof(fp)) {
-                        return;
-                    }
-                    offsets.push_back(ftello(fp));
-                }
-            }
-            ClearText();
-        }
-
-        int ch = getc(fp);
-        if (ch == EOF) {
-            text_row_ = text_top_ = text_rows_ - 2;
+  bool show_prompt = false;
+  while (true) {
+    if (show_prompt) {
+      Print("--(%d%% of %d bytes)--",
+            static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
+            static_cast<int>(sb.st_size));
+      Redraw();
+      while (show_prompt) {
+        show_prompt = false;
+        int key = WaitKey();
+        if (key == KEY_POWER || key == KEY_ENTER) {
+          return;
+        } else if (key == KEY_UP || key == KEY_VOLUMEUP) {
+          if (offsets.size() <= 1) {
             show_prompt = true;
+          } else {
+            offsets.pop_back();
+            fseek(fp, offsets.back(), SEEK_SET);
+          }
         } else {
-            PutChar(ch);
-            if (text_col_ == 0 && text_row_ >= text_rows_ - 2) {
-                text_top_ = text_row_;
-                show_prompt = true;
-            }
+          if (feof(fp)) {
+            return;
+          }
+          offsets.push_back(ftello(fp));
         }
+      }
+      ClearText();
     }
+
+    int ch = getc(fp);
+    if (ch == EOF) {
+      text_row_ = text_top_ = text_rows_ - 2;
+      show_prompt = true;
+    } else {
+      PutChar(ch);
+      if (text_col_ == 0 && text_row_ >= text_rows_ - 2) {
+        text_top_ = text_row_;
+        show_prompt = true;
+      }
+    }
+  }
 }
 
 void WearRecoveryUI::PutChar(char ch) {
-    pthread_mutex_lock(&updateMutex);
-    if (ch != '\n') text_[text_row_][text_col_++] = ch;
-    if (ch == '\n' || text_col_ >= text_cols_) {
-        text_col_ = 0;
-        ++text_row_;
-    }
-    pthread_mutex_unlock(&updateMutex);
+  pthread_mutex_lock(&updateMutex);
+  if (ch != '\n') text_[text_row_][text_col_++] = ch;
+  if (ch == '\n' || text_col_ >= text_cols_) {
+    text_col_ = 0;
+    ++text_row_;
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
 
 void WearRecoveryUI::ShowFile(const char* filename) {
-    FILE* fp = fopen_path(filename, "re");
-    if (fp == nullptr) {
-        Print("  Unable to open %s: %s\n", filename, strerror(errno));
-        return;
-    }
-    ShowFile(fp);
-    fclose(fp);
-}
-
-void WearRecoveryUI::ClearText() {
-    pthread_mutex_lock(&updateMutex);
-    text_col_ = 0;
-    text_row_ = 0;
-    text_top_ = 1;
-    for (size_t i = 0; i < text_rows_; ++i) {
-        memset(text_[i], 0, text_cols_ + 1);
-    }
-    pthread_mutex_unlock(&updateMutex);
+  FILE* fp = fopen_path(filename, "re");
+  if (fp == nullptr) {
+    Print("  Unable to open %s: %s\n", filename, strerror(errno));
+    return;
+  }
+  ShowFile(fp);
+  fclose(fp);
 }
 
 void WearRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
-    va_list ap;
-    va_start(ap, fmt);
-    PrintV(fmt, false, ap);
-    va_end(ap);
+  va_list ap;
+  va_start(ap, fmt);
+  PrintV(fmt, false, ap);
+  va_end(ap);
 }
 
 void WearRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
-    std::string str;
-    android::base::StringAppendV(&str, fmt, ap);
+  std::string str;
+  android::base::StringAppendV(&str, fmt, ap);
 
-    if (copy_to_stdout) {
-        fputs(str.c_str(), stdout);
-    }
+  if (copy_to_stdout) {
+    fputs(str.c_str(), stdout);
+  }
 
-    pthread_mutex_lock(&updateMutex);
-    if (text_rows_ > 0 && text_cols_ > 0) {
-        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 (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
-            }
-            if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
-        }
+  pthread_mutex_lock(&updateMutex);
+  if (text_rows_ > 0 && text_cols_ > 0) {
+    for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
+      if (*ptr == '\n' || text_col_ >= text_cols_) {
         text_[text_row_][text_col_] = '\0';
-        update_screen_locked();
+        text_col_ = 0;
+        text_row_ = (text_row_ + 1) % text_rows_;
+        if (text_row_ == text_top_) text_top_ = (text_top_ + 1) % text_rows_;
+      }
+      if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
     }
-    pthread_mutex_unlock(&updateMutex);
+    text_[text_row_][text_col_] = '\0';
+    update_screen_locked();
+  }
+  pthread_mutex_unlock(&updateMutex);
 }
diff --git a/wear_ui.h b/wear_ui.h
index 4cd852f..a814118 100644
--- a/wear_ui.h
+++ b/wear_ui.h
@@ -22,64 +22,61 @@
 #include <string>
 
 class WearRecoveryUI : public ScreenRecoveryUI {
-  public:
-    WearRecoveryUI();
+ public:
+  WearRecoveryUI();
 
-    bool Init(const std::string& locale) override;
+  bool Init(const std::string& locale) override;
 
-    void SetStage(int current, int max) override;
+  void SetStage(int current, int max) override;
 
-    // printing messages
-    void Print(const char* fmt, ...) override;
-    void PrintOnScreenOnly(const char* fmt, ...) override __printflike(2, 3);
-    void ShowFile(const char* filename) override;
-    void ShowFile(FILE* fp) override;
+  // printing messages
+  void Print(const char* fmt, ...) override;
+  void PrintOnScreenOnly(const char* fmt, ...) override __printflike(2, 3);
+  void ShowFile(const char* filename) override;
+  void ShowFile(FILE* fp) override;
 
-    // menu display
-    void StartMenu(const char* const * headers, const char* const * items,
-                   int initial_selection) override;
-    int SelectMenu(int sel) override;
+  // menu display
+  void StartMenu(const char* const* headers, const char* const* items,
+                 int initial_selection) override;
+  int SelectMenu(int sel) override;
 
-  protected:
-    // progress bar vertical position, it's centered horizontally
-    int progress_bar_y;
+ protected:
+  // progress bar vertical position, it's centered horizontally
+  int progress_bar_y;
 
-    // outer of window
-    int outer_height, outer_width;
+  // outer of window
+  int outer_height, outer_width;
 
-    // Unusable rows when displaying the recovery menu, including the lines
-    // for headers (Android Recovery, build id and etc) and the bottom lines
-    // that may otherwise go out of the screen.
-    int menu_unusable_rows;
+  // Unusable rows when displaying the recovery menu, including the lines for headers (Android
+  // Recovery, build id and etc) and the bottom lines that may otherwise go out of the screen.
+  int menu_unusable_rows;
 
-    int GetProgressBaseline() override;
+  int GetProgressBaseline() const override;
 
-    bool InitTextParams() override;
+  bool InitTextParams() override;
 
-    void update_progress_locked() override;
+  void update_progress_locked() override;
 
-    void PrintV(const char*, bool, va_list) override;
+  void PrintV(const char*, bool, va_list) override;
 
-  private:
-    GRSurface* backgroundIcon[5];
+ private:
+  GRSurface* backgroundIcon[5];
 
-    static const int kMaxCols = 96;
-    static const int kMaxRows = 96;
+  static const int kMaxCols = 96;
+  static const int kMaxRows = 96;
 
-    // Number of text rows seen on screen
-    int visible_text_rows;
+  // Number of text rows seen on screen
+  int visible_text_rows;
 
-    const char* const* menu_headers_;
-    int menu_start, menu_end;
+  const char* const* menu_headers_;
+  int menu_start, menu_end;
 
-    pthread_t progress_t;
+  pthread_t progress_t;
 
-    void draw_background_locked() override;
-    void draw_screen_locked() override;
-    void draw_progress_locked();
+  void draw_background_locked() override;
+  void draw_screen_locked() override;
 
-    void PutChar(char);
-    void ClearText();
+  void PutChar(char);
 };
 
 #endif  // RECOVERY_WEAR_UI_H
