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

Change-Id: Icd576b05deb207c83c312ad2b51437bd92264348
This commit is contained in:
android-build-team Robot
2017-06-25 07:40:54 +00:00
10 changed files with 123 additions and 202 deletions
+18
View File
@@ -95,6 +95,24 @@ endif
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 \
+66 -67
View File
@@ -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 @@ static double now() {
}
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 @@ static const char* LONG_PRESS_HELP[] = {
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 @@ void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
}
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 @@ bool ScreenRecoveryUI::Init(const std::string& locale) {
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?
+9 -3
View File
@@ -72,10 +72,16 @@ class ScreenRecoveryUI : public RecoveryUI {
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 @@ class ScreenRecoveryUI : public RecoveryUI {
// 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 @@ class ScreenRecoveryUI : public RecoveryUI {
int char_width_;
int char_height_;
pthread_mutex_t updateMutex;
virtual bool InitTextParams();
+4
View File
@@ -92,6 +92,10 @@ ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
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
+1 -1
View File
@@ -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;
-96
View File
@@ -224,102 +224,6 @@ TEST_F(UpdaterTest, file_getprop) {
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.
+4
View File
@@ -39,6 +39,10 @@ ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
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)
+15 -6
View File
@@ -99,12 +99,21 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
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";
}
#endif
if (dm_block_name == partition) {
dm_block_device = DEV_PATH + std::string(namelist[n]->d_name);
while (n--) {
free(namelist[n]);
}
break;
}
break;
}
free(namelist[n]);
}
@@ -229,7 +238,7 @@ int update_verifier(int argc, char** argv) {
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.";
+5 -26
View File
@@ -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;
}
+1 -3
View File
@@ -26,12 +26,10 @@ class VrRecoveryUI : public ScreenRecoveryUI {
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;
};