From 619b162d67e0dd4e5e99c78e67dd8729aa37320b Mon Sep 17 00:00:00 2001 From: Jin Qian Date: Fri, 21 Apr 2017 14:36:12 -0700 Subject: recovery: replace make_ext4 with e2fsprogs Execute mke2fs to create empty ext4 filesystem. Execute e2fsdroid to add files to filesystem. Test: enter recovery mode and wipe data Bug: 35219933 Change-Id: I10a9f4c1f4754ad864b2df45b1f879180ab33876 Merged-In: I10a9f4c1f4754ad864b2df45b1f879180ab33876 --- Android.mk | 8 ++++--- roots.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++------ updater/install.cpp | 27 +++++++++++++++++++++-- 3 files changed, 86 insertions(+), 11 deletions(-) diff --git a/Android.mk b/Android.mk index 5f3a8a45d..cfd55a79a 100644 --- a/Android.mk +++ b/Android.mk @@ -83,9 +83,11 @@ LOCAL_MODULE := recovery LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_REQUIRED_MODULES := e2fsdroid_static mke2fs_static mke2fs.conf + ifeq ($(TARGET_USERIMAGES_USE_F2FS),true) ifeq ($(HOST_OS),linux) -LOCAL_REQUIRED_MODULES := mkfs.f2fs +LOCAL_REQUIRED_MODULES += mkfs.f2fs endif endif @@ -112,6 +114,7 @@ LOCAL_STATIC_LIBRARIES := \ libverifier \ libbatterymonitor \ libbootloader_message \ + libfs_mgr \ libext4_utils \ libsparse \ libziparchive \ @@ -122,7 +125,6 @@ LOCAL_STATIC_LIBRARIES := \ libfusesideload \ libminui \ libpng \ - libfs_mgr \ libcrypto_utils \ libcrypto \ libvintf_recovery \ @@ -151,7 +153,7 @@ else endif ifeq ($(BOARD_CACHEIMAGE_PARTITION_SIZE),) -LOCAL_REQUIRED_MODULES := recovery-persist recovery-refresh +LOCAL_REQUIRED_MODULES += recovery-persist recovery-refresh endif include $(BUILD_EXECUTABLE) diff --git a/roots.cpp b/roots.cpp index 9b4270256..e98dfd448 100644 --- a/roots.cpp +++ b/roots.cpp @@ -27,7 +27,8 @@ #include #include -#include +#include +#include #include #include @@ -215,11 +216,60 @@ int format_volume(const char* volume, const char* directory) { } int result; if (strcmp(v->fs_type, "ext4") == 0) { - if (v->erase_blk_size != 0 && v->logical_blk_size != 0) { - result = make_ext4fs_directory_align(v->blk_device, length, volume, sehandle, - directory, v->erase_blk_size, v->logical_blk_size); - } else { - result = make_ext4fs_directory(v->blk_device, length, volume, sehandle, directory); + static constexpr int block_size = 4096; + int raid_stride = v->logical_blk_size / block_size; + int raid_stripe_width = v->erase_blk_size / block_size; + + // stride should be the max of 8kb and logical block size + if (v->logical_blk_size != 0 && v->logical_blk_size < 8192) { + raid_stride = 8192 / block_size; + } + + const char* mke2fs_argv[] = { "/sbin/mke2fs_static", + "-F", + "-t", + "ext4", + "-b", + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr }; + + int i = 5; + std::string block_size_str = std::to_string(block_size); + mke2fs_argv[i++] = block_size_str.c_str(); + + std::string ext_args; + if (v->erase_blk_size != 0 && v->logical_blk_size != 0) { + ext_args = android::base::StringPrintf("stride=%d,stripe-width=%d", raid_stride, + raid_stripe_width); + mke2fs_argv[i++] = "-E"; + mke2fs_argv[i++] = ext_args.c_str(); + } + + mke2fs_argv[i++] = v->blk_device; + + std::string size_str = std::to_string(length / block_size); + if (length != 0) { + mke2fs_argv[i++] = size_str.c_str(); + } + + result = exec_cmd(mke2fs_argv[0], const_cast(mke2fs_argv)); + if (result == 0 && directory != nullptr) { + const char* e2fsdroid_argv[] = { "/sbin/e2fsdroid_static", + "-e", + "-S", + "/file_contexts", + "-f", + directory, + "-a", + volume, + v->blk_device, + nullptr }; + + result = exec_cmd(e2fsdroid_argv[0], const_cast(e2fsdroid_argv)); } } else { /* Has to be f2fs because we checked earlier. */ if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) { diff --git a/updater/install.cpp b/updater/install.cpp index ff79edce0..c9a3a0799 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -302,9 +302,32 @@ Value* FormatFn(const char* name, State* state, const std::vector(mke2fs_argv)); + if (status != 0) { + LOG(WARNING) << name << ": mke2fs failed (" << status << ") on " << location + << ", falling back to make_ext4fs"; + status = make_ext4fs(location.c_str(), size, mount_point.c_str(), sehandle); + if (status != 0) { + LOG(ERROR) << name << ": make_ext4fs failed (" << status << ") on " << location; + return StringValue(""); + } + return StringValue(location); + } + + const char* e2fsdroid_argv[] = { "/sbin/e2fsdroid_static", "-e", "-S", + "/file_contexts", "-a", mount_point.c_str(), + location.c_str(), nullptr }; + status = exec_cmd(e2fsdroid_argv[0], const_cast(e2fsdroid_argv)); if (status != 0) { - LOG(ERROR) << name << ": make_ext4fs failed (" << status << ") on " << location; + LOG(ERROR) << name << ": e2fsdroid failed (" << status << ") on " << location; return StringValue(""); } return StringValue(location); -- cgit v1.2.3 From edc6b52f006eda2cd23c2de654968be347b3f2a5 Mon Sep 17 00:00:00 2001 From: Luke Song Date: Mon, 12 Jun 2017 16:08:33 -0700 Subject: Introduce VR recovery ui A version of screen ui with specific adjustments for vr device compatibility. Cherry picked from commit a44dba7f4e7296077f65fd571232e8a61aed9418 Bug: 37779982 Test: "adb reboot recovery" to view Change-Id: If6b0f26c1b587f8d0176060685b5efb6c67593b1 --- Android.mk | 12 ++++++++++++ screen_ui.cpp | 18 +++++++++++------- screen_ui.h | 6 ++++-- vr_device.cpp | 23 +++++++++++++++++++++++ vr_ui.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vr_ui.h | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 vr_device.cpp create mode 100644 vr_ui.cpp create mode 100644 vr_ui.h diff --git a/Android.mk b/Android.mk index cfd55a79a..bbb204660 100644 --- a/Android.mk +++ b/Android.mk @@ -76,6 +76,7 @@ LOCAL_SRC_FILES := \ rotate_logs.cpp \ screen_ui.cpp \ ui.cpp \ + vr_ui.cpp \ wear_ui.cpp \ wear_touch.cpp \ @@ -196,6 +197,17 @@ LOCAL_STATIC_LIBRARIES := \ LOCAL_CFLAGS := -Werror include $(BUILD_STATIC_LIBRARY) +# vr headset default device +# =============================== +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := vr_device.cpp + +# should match TARGET_RECOVERY_UI_LIB set in BoardConfig.mk +LOCAL_MODULE := librecovery_ui_vr + +include $(BUILD_STATIC_LIBRARY) + include \ $(LOCAL_PATH)/applypatch/Android.mk \ $(LOCAL_PATH)/boot_control/Android.mk \ diff --git a/screen_ui.cpp b/screen_ui.cpp index 7334b713e..ff51b53e1 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -260,6 +260,10 @@ void ScreenRecoveryUI::DrawHorizontalRule(int* y) { *y += 4; } +void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const { + 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; @@ -290,7 +294,6 @@ void ScreenRecoveryUI::draw_screen_locked() { draw_foreground_locked(); return; } - gr_color(0, 0, 0, 255); gr_clear(); @@ -318,15 +321,14 @@ void ScreenRecoveryUI::draw_screen_locked() { if (i == menu_sel) { // Draw the highlight bar. SetColor(IsLongPress() ? MENU_SEL_BG_ACTIVE : MENU_SEL_BG); - gr_fill(0, y - 2, gr_fb_width(), y + char_height_ + 2); + DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4); // Bold white text for the selected item. SetColor(MENU_SEL_FG); - gr_text(gr_sys_font(), 4, y, menu_[i], true); + DrawTextLine(x, &y, menu_[i], true); SetColor(MENU); } else { - gr_text(gr_sys_font(), 4, y, menu_[i], false); + DrawTextLine(x, &y, menu_[i], false); } - y += char_height_ + 4; } DrawHorizontalRule(&y); } @@ -336,9 +338,10 @@ void ScreenRecoveryUI::draw_screen_locked() { SetColor(LOG); int row = (text_top_ + text_rows_ - 1) % text_rows_; size_t count = 0; - for (int ty = gr_fb_height() - kMarginHeight - char_height_; + for (int ty = gr_fb_height() - kMarginHeight - char_height_ - log_bottom_offset_; ty >= y && count < text_rows_; ty -= char_height_, ++count) { - gr_text(gr_sys_font(), 0, ty, text_[row], false); + int temp_y = ty; + DrawTextLine(x, &temp_y, text_[row], false); --row; if (row < 0) row = text_rows_ - 1; } @@ -458,6 +461,7 @@ bool ScreenRecoveryUI::InitTextParams() { 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; } diff --git a/screen_ui.h b/screen_ui.h index 58032d80b..e961c1c93 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -113,6 +113,7 @@ 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? @@ -172,8 +173,9 @@ class ScreenRecoveryUI : public RecoveryUI { virtual int GetProgressBaseline(); virtual int GetTextBaseline(); - void DrawHorizontalRule(int* y); - void DrawTextLine(int x, int* y, const char* line, bool bold) 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; }; diff --git a/vr_device.cpp b/vr_device.cpp new file mode 100644 index 000000000..61e15cbb6 --- /dev/null +++ b/vr_device.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device.h" +#include "vr_ui.h" + +Device* make_device() { + return new Device(new VrRecoveryUI); +} + diff --git a/vr_ui.cpp b/vr_ui.cpp new file mode 100644 index 000000000..b2c65e3af --- /dev/null +++ b/vr_ui.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "vr_ui.h" + +#include + +VrRecoveryUI::VrRecoveryUI() : + x_offset(400), + y_offset(400), + stereo_offset(100) { +} + +bool VrRecoveryUI::InitTextParams() { + if (gr_init() < 0) { + return false; + } + + gr_font_size(gr_sys_font(), &char_width_, &char_height_); + 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; + 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); + *y += char_height_ + 4; +} diff --git a/vr_ui.h b/vr_ui.h new file mode 100644 index 000000000..85c570815 --- /dev/null +++ b/vr_ui.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RECOVERY_VR_UI_H +#define RECOVERY_VR_UI_H + +#include "screen_ui.h" + +class VrRecoveryUI : public ScreenRecoveryUI { + 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; + + 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; +}; + +#endif // RECOVERY_VR_UI_H -- cgit v1.2.3 From 14ebc1e5ae6968424eb242f3b0330f82e475a1e4 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Wed, 5 Jul 2017 12:04:07 -0700 Subject: Fix a rare failure for imgdiff when random data equals gzip header In a rare case, a random chunk will pass both the gzip header check and the inflation process; but fail the uncompressed length check in the footer. This leads to a imgdiff failure. So, we should treat this chunk as 'normal' instead of 'inflated' while generating the patch. Bug: 63334984 Test: imgdiff generates patch successfully on previous failing images. Change-Id: Ice84f22d3653bce9756bda91e70528c0d2f264a0 --- applypatch/imgdiff.cpp | 25 ++++++++++++++----------- tests/component/imgdiff_test.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/applypatch/imgdiff.cpp b/applypatch/imgdiff.cpp index 41d73ab98..fc240644f 100644 --- a/applypatch/imgdiff.cpp +++ b/applypatch/imgdiff.cpp @@ -693,6 +693,20 @@ static bool ReadImage(const char* filename, std::vector* chunks, continue; } + // The footer contains the size of the uncompressed data. Double-check to make sure that it + // matches the size of the data we got when we actually did the decompression. + size_t footer_index = pos + raw_data_len + GZIP_FOOTER_LEN - 4; + if (sz - footer_index < 4) { + printf("Warning: invalid footer position; treating as a nomal chunk\n"); + continue; + } + size_t footer_size = get_unaligned(img->data() + footer_index); + if (footer_size != uncompressed_len) { + printf("Warning: footer size %zu != decompressed size %zu; treating as a nomal chunk\n", + footer_size, uncompressed_len); + continue; + } + ImageChunk body(CHUNK_DEFLATE, pos, img, raw_data_len); uncompressed_data.resize(uncompressed_len); body.SetUncompressedData(std::move(uncompressed_data)); @@ -704,17 +718,6 @@ static bool ReadImage(const char* filename, std::vector* chunks, chunks->emplace_back(CHUNK_NORMAL, pos, img, GZIP_FOOTER_LEN); pos += GZIP_FOOTER_LEN; - - // The footer (that we just skipped over) contains the size of - // the uncompressed data. Double-check to make sure that it - // matches the size of the data we got when we actually did - // the decompression. - size_t footer_size = get_unaligned(img->data() + pos - 4); - if (footer_size != body.DataLengthForPatch()) { - printf("Error: footer size %zu != decompressed size %zu\n", footer_size, - body.GetRawDataLength()); - return false; - } } else { // Use a normal chunk to take all the contents until the next gzip chunk (or EOF); we expect // the number of chunks to be small (5 for typical boot and recovery images). diff --git a/tests/component/imgdiff_test.cpp b/tests/component/imgdiff_test.cpp index 6f5960bbd..bf25aebb0 100644 --- a/tests/component/imgdiff_test.cpp +++ b/tests/component/imgdiff_test.cpp @@ -328,6 +328,39 @@ TEST(ImgdiffTest, image_mode_simple) { verify_patched_image(src, patch, tgt); } +TEST(ImgdiffTest, image_mode_bad_gzip) { + // Modify the uncompressed length in the gzip footer. + const std::vector src_data = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', '\x1f', '\x8b', '\x08', '\x00', '\xc4', '\x1e', + '\x53', '\x58', '\x00', '\x03', '\xab', '\xa8', '\xac', + '\x02', '\x00', '\x67', '\xba', '\x8e', '\xeb', '\x03', + '\xff', '\xff', '\xff' }; + const std::string src(src_data.cbegin(), src_data.cend()); + TemporaryFile src_file; + ASSERT_TRUE(android::base::WriteStringToFile(src, src_file.path)); + + // Modify the uncompressed length in the gzip footer. + const std::vector tgt_data = { + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'x', 'y', 'z', '\x1f', '\x8b', + '\x08', '\x00', '\x62', '\x1f', '\x53', '\x58', '\x00', '\x03', '\xab', '\xa8', '\xa8', '\xac', + '\xac', '\xaa', '\x02', '\x00', '\x96', '\x30', '\x06', '\xb7', '\x06', '\xff', '\xff', '\xff' + }; + const std::string tgt(tgt_data.cbegin(), tgt_data.cend()); + TemporaryFile tgt_file; + ASSERT_TRUE(android::base::WriteStringToFile(tgt, tgt_file.path)); + + TemporaryFile patch_file; + std::vector args = { + "imgdiff", src_file.path, tgt_file.path, patch_file.path, + }; + ASSERT_EQ(0, imgdiff(args.size(), args.data())); + + // Verify. + std::string patch; + ASSERT_TRUE(android::base::ReadFileToString(patch_file.path, &patch)); + verify_patched_image(src, patch, tgt); +} + TEST(ImgdiffTest, image_mode_different_num_chunks) { // src: "abcdefgh" + gzipped "xyz" (echo -n "xyz" | gzip -f | hd) + gzipped "test". const std::vector src_data = { -- cgit v1.2.3 From c392888df752479ffaeee2fa9e624d71ce2a4618 Mon Sep 17 00:00:00 2001 From: Luke Song Date: Fri, 23 Jun 2017 14:33:46 -0700 Subject: Restructure vr_ui Get rid of pixel offset variables, and use makefile variables in BoardConfigs. Cherry picked from commit 81a8e4cab2a20fd1b1a4716563d4d2586bd1e1de Bug: 37779982 Test: Verified vr ui has same behavior. Change-Id: Ifbf44e27d7101aedbe3c0e6db4b8181d56efadfd --- Android.mk | 6 ++++++ screen_ui.cpp | 3 +-- screen_ui.h | 1 - vr_ui.cpp | 31 +++++-------------------------- vr_ui.h | 4 +--- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/Android.mk b/Android.mk index bbb204660..95c8823e3 100644 --- a/Android.mk +++ b/Android.mk @@ -107,6 +107,12 @@ 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 ff51b53e1..a7d9c9f4b 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -338,7 +338,7 @@ void ScreenRecoveryUI::draw_screen_locked() { 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_; + 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); @@ -461,7 +461,6 @@ bool ScreenRecoveryUI::InitTextParams() { 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; } diff --git a/screen_ui.h b/screen_ui.h index e961c1c93..2500575ca 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -113,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? diff --git a/vr_ui.cpp b/vr_ui.cpp index b2c65e3af..8b8261e35 100644 --- a/vr_ui.cpp +++ b/vr_ui.cpp @@ -18,39 +18,18 @@ #include -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 85c570815..31ca4a61d 100644 --- a/vr_ui.h +++ b/vr_ui.h @@ -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; }; -- cgit v1.2.3