release-request-7bfcab52-d1c0-4256-9d6b-5b5092bc78ca-for-git_oc-mr1-release-4133428 snap-temp-L95800000077479875

Change-Id: Icd576b05deb207c83c312ad2b51437bd92264348
diff --git a/Android.mk b/Android.mk
index 344d5ad..95c8823 100644
--- a/Android.mk
+++ b/Android.mk
@@ -95,6 +95,24 @@
 LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
 LOCAL_CFLAGS += -Wno-unused-parameter -Werror
 
+ifneq ($(TARGET_RECOVERY_UI_MARGIN_HEIGHT),)
+LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_HEIGHT=$(TARGET_RECOVERY_UI_MARGIN_HEIGHT)
+else
+LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_HEIGHT=0
+endif
+
+ifneq ($(TARGET_RECOVERY_UI_MARGIN_WIDTH),)
+LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_WIDTH=$(TARGET_RECOVERY_UI_MARGIN_WIDTH)
+else
+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/screen_ui.cpp b/screen_ui.cpp
index 61ef591..c41bb22 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -43,8 +43,6 @@
 #include "screen_ui.h"
 #include "ui.h"
 
-#define TEXT_INDENT     4
-
 // Return the current time as a double (including fractions of a second).
 static double now() {
     struct timeval tv;
@@ -53,7 +51,10 @@
 }
 
 ScreenRecoveryUI::ScreenRecoveryUI()
-    : currentIcon(NONE),
+    : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH),
+      kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT),
+      density_(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f),
+      currentIcon(NONE),
       progressBarType(EMPTY),
       progressScopeStart(0),
       progressScopeSize(0),
@@ -282,65 +283,66 @@
     NULL
 };
 
-// Redraw everything on the screen.  Does not flip pages.
-// Should only be called with updateMutex locked.
+// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
+// locked.
 void ScreenRecoveryUI::draw_screen_locked() {
-    if (!show_text) {
-        draw_background_locked();
-        draw_foreground_locked();
-    } else {
-        gr_color(0, 0, 0, 255);
-        gr_clear();
+  if (!show_text) {
+    draw_background_locked();
+    draw_foreground_locked();
+    return;
+  }
 
-        int y = 0;
-        if (show_menu) {
-            std::string recovery_fingerprint =
-                    android::base::GetProperty("ro.bootimage.build.fingerprint", "");
+  gr_color(0, 0, 0, 255);
+  gr_clear();
 
-            SetColor(INFO);
-            DrawTextLine(TEXT_INDENT, &y, "Android Recovery", true);
-            for (auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
-                DrawTextLine(TEXT_INDENT, &y, chunk.c_str(), false);
-            }
-            DrawTextLines(TEXT_INDENT, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
+  static constexpr int TEXT_INDENT = 4;
+  int x = TEXT_INDENT + kMarginWidth;
+  int y = kMarginHeight;
+  if (show_menu) {
+    std::string recovery_fingerprint =
+        android::base::GetProperty("ro.bootimage.build.fingerprint", "");
 
-            SetColor(HEADER);
-            DrawTextLines(TEXT_INDENT, &y, menu_headers_);
-
-            SetColor(MENU);
-            DrawHorizontalRule(&y);
-            y += 4;
-            for (int i = 0; i < menu_items; ++i) {
-                if (i == menu_sel) {
-                    // Draw the highlight bar.
-                    SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
-                    DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4);
-                    // Bold white text for the selected item.
-                    SetColor(MENU_SEL_FG);
-                    DrawTextLine(TEXT_INDENT, &y, menu_[i], true);
-                    SetColor(MENU);
-                } else {
-                    DrawTextLine(TEXT_INDENT, &y, menu_[i], false);
-                }
-            }
-            DrawHorizontalRule(&y);
-        }
-
-        // 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.
-        SetColor(LOG);
-        int row = (text_top_ + text_rows_ - 1) % text_rows_;
-        size_t count = 0;
-        for (int ty = gr_fb_height() - char_height_ - log_bottom_offset_;
-             ty >= y && count < text_rows_;
-             ty -= char_height_, ++count) {
-            int temp_y = ty;
-            DrawTextLine(0, &temp_y, text_[row], false);
-            --row;
-            if (row < 0) row = text_rows_ - 1;
-        }
+    SetColor(INFO);
+    DrawTextLine(x, &y, "Android Recovery", true);
+    for (const auto& chunk : android::base::Split(recovery_fingerprint, ":")) {
+      DrawTextLine(x, &y, chunk.c_str(), false);
     }
+    DrawTextLines(x, &y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP);
+
+    SetColor(HEADER);
+    DrawTextLines(x, &y, menu_headers_);
+
+    SetColor(MENU);
+    DrawHorizontalRule(&y);
+    y += 4;
+    for (int i = 0; i < menu_items; ++i) {
+      if (i == menu_sel) {
+        // Draw the highlight bar.
+        SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG);
+        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);
+        SetColor(MENU);
+      } else {
+        DrawTextLine(x, &y, menu_[i], false);
+      }
+    }
+    DrawHorizontalRule(&y);
+  }
+
+  // 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.
+  SetColor(LOG);
+  int row = (text_top_ + text_rows_ - 1) % text_rows_;
+  size_t count = 0;
+  for (int ty = gr_fb_height() - kMarginHeight - char_height_;
+       ty >= y && count < text_rows_; ty -= char_height_, ++count) {
+    int temp_y = ty;
+    DrawTextLine(x, &temp_y, text_[row], false);
+    --row;
+    if (row < 0) row = text_rows_ - 1;
+  }
 }
 
 // Redraw everything on the screen and flip the screen (make it visible).
@@ -450,15 +452,14 @@
 }
 
 bool ScreenRecoveryUI::InitTextParams() {
-    if (gr_init() < 0) {
-      return false;
-    }
+  if (gr_init() < 0) {
+    return false;
+  }
 
-    gr_font_size(gr_sys_font(), &char_width_, &char_height_);
-    text_rows_ = gr_fb_height() / char_height_;
-    text_cols_ = gr_fb_width() / char_width_;
-    log_bottom_offset_ = 0;
-    return true;
+  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_;
+  return true;
 }
 
 bool ScreenRecoveryUI::Init(const std::string& locale) {
@@ -467,8 +468,6 @@
     return false;
   }
 
-  density_ = static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f;
-
   // Are we portrait or landscape?
   layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT;
   // Are we the large variant of our base layout?
diff --git a/screen_ui.h b/screen_ui.h
index bd99254..2500575 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -72,10 +72,16 @@
     void SetColor(UIElement e);
 
   protected:
-    Icon currentIcon;
+    // 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.
-    float density_;
+    const float density_;
+
+    Icon currentIcon;
+
     // The layout to use.
     int layout_;
 
@@ -107,7 +113,6 @@
     // Log text overlay, displayed when a magic key is pressed.
     char** text_;
     size_t text_col_, text_row_, text_top_;
-    int log_bottom_offset_;
 
     bool show_text;
     bool show_text_ever;   // has show_text ever been true?
@@ -136,6 +141,7 @@
 
     int char_width_;
     int char_height_;
+
     pthread_mutex_t updateMutex;
 
     virtual bool InitTextParams();
diff --git a/tests/Android.mk b/tests/Android.mk
index 262f4ff..346873d 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -92,6 +92,10 @@
 LOCAL_CFLAGS += -DPRODUCT_SUPPORTS_VERITY=1
 endif
 
+ifeq ($(BOARD_AVB_ENABLE),true)
+LOCAL_CFLAGS += -DBOARD_AVB_ENABLE=1
+endif
+
 LOCAL_MODULE := recovery_component_test
 LOCAL_COMPATIBILITY_SUITE := device-tests
 LOCAL_C_INCLUDES := bootable/recovery
diff --git a/tests/component/update_verifier_test.cpp b/tests/component/update_verifier_test.cpp
index 73b4478..5fc7ef6 100644
--- a/tests/component/update_verifier_test.cpp
+++ b/tests/component/update_verifier_test.cpp
@@ -24,7 +24,7 @@
 class UpdateVerifierTest : public ::testing::Test {
  protected:
   void SetUp() override {
-#ifdef PRODUCT_SUPPORTS_VERITY
+#if defined(PRODUCT_SUPPORTS_VERITY) || defined(BOARD_AVB_ENABLE)
     verity_supported = true;
 #else
     verity_supported = false;
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/update_verifier/Android.mk b/update_verifier/Android.mk
index 37d9bfe..33c5fe9 100644
--- a/update_verifier/Android.mk
+++ b/update_verifier/Android.mk
@@ -39,6 +39,10 @@
 LOCAL_CFLAGS += -DPRODUCT_SUPPORTS_VERITY=1
 endif
 
+ifeq ($(BOARD_AVB_ENABLE),true)
+LOCAL_CFLAGS += -DBOARD_AVB_ENABLE=1
+endif
+
 include $(BUILD_STATIC_LIBRARY)
 
 # update_verifier (executable)
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp
index fdbcfde..d3a5185 100644
--- a/update_verifier/update_verifier.cpp
+++ b/update_verifier/update_verifier.cpp
@@ -99,12 +99,21 @@
     std::string content;
     if (!android::base::ReadFileToString(path, &content)) {
       PLOG(WARNING) << "Failed to read " << path;
-    } else if (android::base::Trim(content) == partition) {
-      dm_block_device = DEV_PATH + std::string(namelist[n]->d_name);
-      while (n--) {
-        free(namelist[n]);
+    } else {
+      std::string dm_block_name = android::base::Trim(content);
+#ifdef BOARD_AVB_ENABLE
+      // AVB is using 'vroot' for the root block device but we're expecting 'system'.
+      if (dm_block_name == "vroot") {
+        dm_block_name = "system";
       }
-      break;
+#endif
+      if (dm_block_name == partition) {
+        dm_block_device = DEV_PATH + std::string(namelist[n]->d_name);
+        while (n--) {
+          free(namelist[n]);
+        }
+        break;
+      }
     }
     free(namelist[n]);
   }
@@ -229,7 +238,7 @@
   if (is_successful == BoolResult::FALSE) {
     // The current slot has not booted successfully.
 
-#ifdef PRODUCT_SUPPORTS_VERITY
+#if defined(PRODUCT_SUPPORTS_VERITY) || defined(BOARD_AVB_ENABLE)
     std::string verity_mode = android::base::GetProperty("ro.boot.veritymode", "");
     if (verity_mode.empty()) {
       LOG(ERROR) << "Failed to get dm-verity mode.";
diff --git a/vr_ui.cpp b/vr_ui.cpp
index b2c65e3..8b8261e 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 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);
+  gr_text(gr_sys_font(), x + kStereoOffset, *y, line, bold);
+  gr_text(gr_sys_font(), x - kStereoOffset + mid_divide, *y, line, bold);
   *y += char_height_ + 4;
 }
diff --git a/vr_ui.h b/vr_ui.h
index 85c5708..31ca4a6 100644
--- a/vr_ui.h
+++ b/vr_ui.h
@@ -26,12 +26,10 @@
   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;
+    const int kStereoOffset;
 
     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;
 };