From 2330dd8733ce0b207058e3003a3b1efebc022394 Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Wed, 14 Jun 2017 15:30:39 -0700 Subject: Fix "No file_contexts" warning Fixed by Loading the file_contexts specified in libselinux, whereas previously recovery loaded /file_contexts which no longer exists. Bug: 62587423 Test: build and flash recovery on Angler. Warning is gone. Test: Wipe data and cache. Test: sideload OTA Change-Id: I11581c878b860ac5f412e6e8e7acde811f37870f --- recovery.cpp | 9 +++------ updater/updater.cpp | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 122b89d0b..852f1e862 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -53,6 +53,7 @@ #include #include /* private pmsg functions */ #include /* for AID_SYSTEM */ +#include #include #include #include @@ -1481,12 +1482,8 @@ int main(int argc, char **argv) { ui->SetBackground(RecoveryUI::NONE); if (show_text) ui->ShowText(true); - struct selinux_opt seopts[] = { - { SELABEL_OPT_PATH, "/file_contexts" } - }; - - sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); - + sehandle = selinux_android_file_context_handle(); + selinux_android_set_sehandle(sehandle); if (!sehandle) { ui->Print("Warning: No file_contexts\n"); } diff --git a/updater/updater.cpp b/updater/updater.cpp index f5ff6df91..1d8fa8e92 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -139,9 +140,8 @@ int main(int argc, char** argv) { return 6; } - struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } }; - - sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); + sehandle = selinux_android_file_context_handle(); + selinux_android_set_sehandle(sehandle); if (!sehandle) { fprintf(cmd_pipe, "ui_print Warning: No file_contexts\n"); -- cgit v1.2.3 From a44dba7f4e7296077f65fd571232e8a61aed9418 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. Bug: 37779982 Test: "adb reboot recovery" to view Change-Id: If6b0f26c1b587f8d0176060685b5efb6c67593b1 --- Android.mk | 12 ++++++++++++ screen_ui.cpp | 17 +++++++++++------ screen_ui.h | 6 ++++-- vr_device.cpp | 23 +++++++++++++++++++++++ vr_ui.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vr_ui.h | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 144 insertions(+), 8 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 e619db031..5348e365e 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 \ @@ -182,6 +183,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 bb2772dd8..61ef5911f 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -256,6 +256,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; @@ -310,15 +314,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(TEXT_INDENT, &y, menu_[i], true); SetColor(MENU); } else { - gr_text(gr_sys_font(), 4, y, menu_[i], false); + DrawTextLine(TEXT_INDENT, &y, menu_[i], false); } - y += char_height_ + 4; } DrawHorizontalRule(&y); } @@ -329,10 +332,11 @@ 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() - char_height_; + for (int ty = gr_fb_height() - 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(0, &temp_y, text_[row], false); --row; if (row < 0) row = text_rows_ - 1; } @@ -453,6 +457,7 @@ bool ScreenRecoveryUI::InitTextParams() { 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; } diff --git a/screen_ui.h b/screen_ui.h index a2322c36c..bd99254f6 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -107,6 +107,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? @@ -165,8 +166,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 ac31808cd37cfb98755e5821dbb2efb5fe5cb12a 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 --- 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 5348e365e..344d5ad31 100644 --- a/Android.mk +++ b/Android.mk @@ -84,9 +84,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 @@ -101,6 +103,7 @@ LOCAL_STATIC_LIBRARIES := \ libverifier \ libbatterymonitor \ libbootloader_message \ + libfs_mgr \ libext4_utils \ libsparse \ libziparchive \ @@ -111,7 +114,6 @@ LOCAL_STATIC_LIBRARIES := \ libfusesideload \ libminui \ libpng \ - libfs_mgr \ libcrypto_utils \ libcrypto \ libvintf_recovery \ @@ -140,7 +142,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 87f4650874346f1d0238e70b148a31cea5e19a2e Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 19 Jun 2017 23:10:44 -0700 Subject: screen_ui: Allow setting screen margin space. For round screen or screens with rounded corners, we don't want to show texts within the margin which could otherwise be invisible. Move the density computation to ScreenRecoveryUI ctor so that the value can be used earlier. Note that this is similar to the existing stuff in wear UI (outer_width, outer_height). This CL gets ScreenRecoveryUI and WearRecoveryUI one-step closer. Bug: 62732748 Test: Setting and not setting margin_{width,height}_ on angler. Check the recovery texts (recovery menu as well as 'View recovery logs'). Change-Id: Ibf6238c9cc8949a42ed8a410e1c09d55b0b5a151 --- screen_ui.cpp | 138 +++++++++++++++++++++++++++++----------------------------- screen_ui.h | 11 ++++- 2 files changed, 78 insertions(+), 71 deletions(-) diff --git a/screen_ui.cpp b/screen_ui.cpp index 61ef5911f..2dc1cc4c9 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,8 @@ static double now() { } ScreenRecoveryUI::ScreenRecoveryUI() - : currentIcon(NONE), + : density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), + currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), progressScopeSize(0), @@ -79,6 +78,8 @@ ScreenRecoveryUI::ScreenRecoveryUI() animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), + margin_width_(0), + margin_height_(0), updateMutex(PTHREAD_MUTEX_INITIALIZER) {} GRSurface* ScreenRecoveryUI::GetCurrentFrame() { @@ -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(); - - int y = 0; - if (show_menu) { - std::string recovery_fingerprint = - android::base::GetProperty("ro.bootimage.build.fingerprint", ""); - - 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); - - 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); - } + if (!show_text) { + draw_background_locked(); + draw_foreground_locked(); + return; + } - // 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; - } + gr_color(0, 0, 0, 255); + gr_clear(); + + static constexpr int TEXT_INDENT = 4; + int x = TEXT_INDENT + margin_width_; + int y = margin_height_; + if (show_menu) { + std::string recovery_fingerprint = + android::base::GetProperty("ro.bootimage.build.fingerprint", ""); + + 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() - margin_height_ - 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); + --row; + if (row < 0) row = text_rows_ - 1; + } } // Redraw everything on the screen and flip the screen (make it visible). @@ -450,15 +452,15 @@ 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() - margin_height_ * 2) / char_height_; + text_cols_ = (gr_fb_width() - margin_width_ * 2) / char_width_; + log_bottom_offset_ = 0; + return true; } bool ScreenRecoveryUI::Init(const std::string& locale) { @@ -467,8 +469,6 @@ bool ScreenRecoveryUI::Init(const std::string& locale) { return false; } - density_ = static_cast(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 bd99254f6..fd9f471e9 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -72,10 +72,11 @@ class ScreenRecoveryUI : public RecoveryUI { void SetColor(UIElement e); protected: + // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. + const float density_; + Icon currentIcon; - // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. - float density_; // The layout to use. int layout_; @@ -136,6 +137,12 @@ class ScreenRecoveryUI : public RecoveryUI { int char_width_; int char_height_; + + // The margin that we don't want to use for showing texts (e.g. round screen, or screen with + // rounded corners). + int margin_width_; + int margin_height_; + pthread_mutex_t updateMutex; virtual bool InitTextParams(); -- cgit v1.2.3 From a92d8fb45676566a56d7c27d2e8fb644523adc94 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 20 Jun 2017 18:11:21 -0700 Subject: Use Makefile variables to specify margin settings. Instead of defining device-specific UI class, this CL allows using Makefile variables to specify margin values directly. Values explicitly defined via TARGET_RECOVERY_UI_MARGIN_HEIGHT and TARGET_RECOVERY_UI_MARGIN_WIDTH will be used. Otherwise they will default to zero. Bug: 62732748 Test: Specify the height and width and check recovery texts. Change-Id: Icb6f7466c8d407f877b93da38aebfdf7e6b41be7 --- Android.mk | 12 ++++++++++++ screen_ui.cpp | 16 ++++++++-------- screen_ui.h | 10 +++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Android.mk b/Android.mk index 5348e365e..5ce9d335c 100644 --- a/Android.mk +++ b/Android.mk @@ -93,6 +93,18 @@ 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 + LOCAL_C_INCLUDES += \ system/vold \ diff --git a/screen_ui.cpp b/screen_ui.cpp index 2dc1cc4c9..d21a64890 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -51,7 +51,9 @@ static double now() { } ScreenRecoveryUI::ScreenRecoveryUI() - : density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), + : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH), + kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT), + density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), currentIcon(NONE), progressBarType(EMPTY), progressScopeStart(0), @@ -78,8 +80,6 @@ ScreenRecoveryUI::ScreenRecoveryUI() animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), - margin_width_(0), - margin_height_(0), updateMutex(PTHREAD_MUTEX_INITIALIZER) {} GRSurface* ScreenRecoveryUI::GetCurrentFrame() { @@ -296,8 +296,8 @@ void ScreenRecoveryUI::draw_screen_locked() { gr_clear(); static constexpr int TEXT_INDENT = 4; - int x = TEXT_INDENT + margin_width_; - int y = margin_height_; + int x = TEXT_INDENT + kMarginWidth; + int y = kMarginHeight; if (show_menu) { std::string recovery_fingerprint = android::base::GetProperty("ro.bootimage.build.fingerprint", ""); @@ -336,7 +336,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() - margin_height_ - char_height_ - log_bottom_offset_; + 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); @@ -457,8 +457,8 @@ bool ScreenRecoveryUI::InitTextParams() { } gr_font_size(gr_sys_font(), &char_width_, &char_height_); - text_rows_ = (gr_fb_height() - margin_height_ * 2) / char_height_; - text_cols_ = (gr_fb_width() - margin_width_ * 2) / char_width_; + 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 fd9f471e9..e961c1c93 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -72,6 +72,11 @@ class ScreenRecoveryUI : public RecoveryUI { void SetColor(UIElement e); 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_; @@ -138,11 +143,6 @@ class ScreenRecoveryUI : public RecoveryUI { int char_width_; int char_height_; - // The margin that we don't want to use for showing texts (e.g. round screen, or screen with - // rounded corners). - int margin_width_; - int margin_height_; - pthread_mutex_t updateMutex; virtual bool InitTextParams(); -- cgit v1.2.3 From 81a8e4cab2a20fd1b1a4716563d4d2586bd1e1de 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. 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 d21a64890..c41bb22e1 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -336,7 +336,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); @@ -459,7 +459,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 From 7af933b6a6fd687bd17710ef6fda0ad5483e4d6d Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 11 Jul 2017 16:45:04 -0700 Subject: Remove the obsolete reference to /file_contexts. This file no longer exists: - /file_contexts has been split into plat_file_contexts and nonplat_file_contexts since commit b236eb6ca204cefcb926e19bd5682f9dcad4021d (system/sepolicy). - It was named /file_contexts.bin prior to the split. '-S file_contexts' is also no longer required by e2fsdroid, since commit 2fff6fb036cbbb6dedd7da3d208b312a9038a5ce (external/e2fsprogs). It will load the file contexts via libselinux. Test: Trigger the path by performing a data wipe for converting to FBE. Change-Id: I179939da409e5c0415ae0ea0bf5ddb23f9e6331e --- roots.cpp | 4 +--- updater/install.cpp | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/roots.cpp b/roots.cpp index e98dfd448..c4afd5de3 100644 --- a/roots.cpp +++ b/roots.cpp @@ -260,8 +260,6 @@ int format_volume(const char* volume, const char* directory) { if (result == 0 && directory != nullptr) { const char* e2fsdroid_argv[] = { "/sbin/e2fsdroid_static", "-e", - "-S", - "/file_contexts", "-f", directory, "-a", @@ -270,7 +268,7 @@ int format_volume(const char* volume, const char* directory) { 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) { LOG(ERROR) << "format_volume: crypt footer + negative length (" << length diff --git a/updater/install.cpp b/updater/install.cpp index c9a3a0799..bfe91e7f9 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -322,8 +322,7 @@ Value* FormatFn(const char* name, State* state, const std::vector(e2fsdroid_argv)); if (status != 0) { -- cgit v1.2.3 From d774ff247e65426be7482921e3aac7a4323527f8 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 19 Jul 2017 18:51:03 +0900 Subject: Build libminui with BOARD_VNDK_VERSION Use libdrm_platform which is a platform variant of libdrm. Bug: 63741047 Bug: 37342627 Test: BOARD_VNDK_VERSION=current m -j libminui Test: ryu recovery graphics test shows various graphics Change-Id: Ifd2c1432781a96538585cdf818aa728d628a2f5a Merged-In: Ifd2c1432781a96538585cdf818aa728d628a2f5a (cherry picked from commit a48c494f138ddb99320583d00120674be1e3297c) --- minui/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minui/Android.mk b/minui/Android.mk index 4dfc65f8a..6522fcfd2 100644 --- a/minui/Android.mk +++ b/minui/Android.mk @@ -25,7 +25,7 @@ LOCAL_SRC_FILES := \ LOCAL_WHOLE_STATIC_LIBRARIES := \ libadf \ - libdrm \ + libdrm_platform \ libsync_recovery LOCAL_STATIC_LIBRARIES := \ -- cgit v1.2.3 From d9759e8a7ba89d7005d86cf8c8e3e561d04e56a4 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Fri, 21 Jul 2017 21:06:52 +0000 Subject: Fix a case when brotli writer fails to write last few blocks of data receive_new_data may exit too early if the zip processor has sent all the raw data. As a result, the last few 'new' commands will fail even though the brotli decoder has more output in its buffer. Restruct the code so that 'NewThreadInfo' owns the decoder state solely; and receive_brotli_new_data is responsible for the decompression. Also reduce the test data size to 100 blocks to avoid the test timeout. Bug: 63802629 Test: recovery_component_test. on bullhead, apply full updates with and w/o brotli compressed entries, apply an incremental update. Change-Id: Id429b2c2f31951897961525609fa12c3657216b7 (cherry picked from commit 6ed175d5412deeaec9691f85757e45452407b8e3) --- tests/component/updater_test.cpp | 19 ++++- updater/blockimg.cpp | 175 ++++++++++++++++++--------------------- 2 files changed, 96 insertions(+), 98 deletions(-) diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp index 01b86f224..6c341c111 100644 --- a/tests/component/updater_test.cpp +++ b/tests/component/updater_test.cpp @@ -592,10 +592,10 @@ TEST_F(UpdaterTest, brotli_new_data) { ASSERT_EQ(0, zip_writer.StartEntry("new.dat.br", 0)); auto generator = []() { return rand() % 128; }; - // Generate 2048 blocks of random data. + // Generate 100 blocks of random data. std::string brotli_new_data; - brotli_new_data.reserve(4096 * 2048); - generate_n(back_inserter(brotli_new_data), 4096 * 2048, generator); + brotli_new_data.reserve(4096 * 100); + generate_n(back_inserter(brotli_new_data), 4096 * 100, generator); size_t encoded_size = BrotliEncoderMaxCompressedSize(brotli_new_data.size()); std::vector encoded_data(encoded_size); @@ -609,8 +609,19 @@ TEST_F(UpdaterTest, brotli_new_data) { ASSERT_EQ(0, zip_writer.StartEntry("patch_data", 0)); ASSERT_EQ(0, zip_writer.FinishEntry()); + // Write a few small chunks of new data, then a large chunk, and finally a few small chunks. + // This helps us to catch potential short writes. std::vector transfer_list = { - "4", "2048", "0", "0", "new 4,0,512,512,1024", "new 2,1024,2048", + "4", + "100", + "0", + "0", + "new 2,0,1", + "new 2,1,2", + "new 4,2,50,50,97", + "new 2,97,98", + "new 2,98,99", + "new 2,99,100", }; ASSERT_EQ(0, zip_writer.StartEntry("transfer_list", 0)); std::string commands = android::base::Join(transfer_list, '\n'); diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index 2bec487fe..a0b9ad233 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -158,20 +158,22 @@ class RangeSinkWriter { CHECK_NE(tgt.size(), static_cast(0)); }; - virtual ~RangeSinkWriter() {}; - bool Finished() const { return next_range_ == tgt_.size() && current_range_left_ == 0; } - // Return number of bytes consumed; and 0 indicates a writing failure. - virtual size_t Write(const uint8_t* data, size_t size) { + size_t AvailableSpace() const { + return tgt_.blocks() * BLOCKSIZE - bytes_written_; + } + + // Return number of bytes written; and 0 indicates a writing failure. + size_t Write(const uint8_t* data, size_t size) { if (Finished()) { LOG(ERROR) << "range sink write overrun; can't write " << size << " bytes"; return 0; } - size_t consumed = 0; + size_t written = 0; while (size > 0) { // Move to the next range as needed. if (!SeekToOutputRange()) { @@ -191,18 +193,18 @@ class RangeSinkWriter { size -= write_now; current_range_left_ -= write_now; - consumed += write_now; + written += write_now; } - bytes_written_ += consumed; - return consumed; + bytes_written_ += written; + return written; } size_t BytesWritten() const { return bytes_written_; } - protected: + private: // Set up the output cursor, move to next range if needed. bool SeekToOutputRange() { // We haven't finished the current range yet. @@ -241,75 +243,6 @@ class RangeSinkWriter { size_t bytes_written_; }; -class BrotliNewDataWriter : public RangeSinkWriter { - public: - BrotliNewDataWriter(int fd, const RangeSet& tgt, BrotliDecoderState* state) - : RangeSinkWriter(fd, tgt), state_(state) {} - - size_t Write(const uint8_t* data, size_t size) override { - if (Finished()) { - LOG(ERROR) << "Brotli new data write overrun; can't write " << size << " bytes"; - return 0; - } - CHECK(state_ != nullptr); - - size_t consumed = 0; - while (true) { - // Move to the next range as needed. - if (!SeekToOutputRange()) { - break; - } - - size_t available_in = size; - size_t write_now = std::min(32768, current_range_left_); - uint8_t buffer[write_now]; - - size_t available_out = write_now; - uint8_t* next_out = buffer; - - // The brotli decoder will update |data|, |available_in|, |next_out| and |available_out|. - BrotliDecoderResult result = BrotliDecoderDecompressStream( - state_, &available_in, &data, &available_out, &next_out, nullptr); - - // We don't have a way to recover from the decode error; report the failure. - if (result == BROTLI_DECODER_RESULT_ERROR) { - LOG(ERROR) << "Decompression failed with " - << BrotliDecoderErrorString(BrotliDecoderGetErrorCode(state_)); - return 0; - } - - if (write_all(fd_, buffer, write_now - available_out) == -1) { - return 0; - } - - LOG(DEBUG) << "bytes written: " << write_now - available_out << ", bytes consumed " - << size - available_in << ", decoder status " << result; - - // Update the total bytes written to output by the current writer; this is different from the - // consumed input bytes. - bytes_written_ += write_now - available_out; - current_range_left_ -= (write_now - available_out); - consumed += (size - available_in); - - // Update the remaining size. The input data ptr is already updated by brotli decoder - // function. - size = available_in; - - // Continue if we have more output to write, or more input to consume. - if (result == BROTLI_DECODER_RESULT_SUCCESS || - (result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT && size == 0)) { - break; - } - } - - return consumed; - } - - private: - // Pointer to the decoder state. (initialized by PerformBlockImageUpdate) - BrotliDecoderState* state_; -}; - /** * All of the data for all the 'new' transfers is contained in one file in the update package, * concatenated together in the order in which transfers.list will need it. We want to stream it out @@ -354,16 +287,73 @@ static bool receive_new_data(const uint8_t* data, size_t size, void* cookie) { // At this point nti->writer is set, and we own it. The main thread is waiting for it to // disappear from nti. - size_t consumed = nti->writer->Write(data, size); + size_t write_now = std::min(size, nti->writer->AvailableSpace()); + if (nti->writer->Write(data, write_now) != write_now) { + LOG(ERROR) << "Failed to write " << write_now << " bytes."; + return false; + } + + data += write_now; + size -= write_now; + + if (nti->writer->Finished()) { + // We have written all the bytes desired by this writer. + + pthread_mutex_lock(&nti->mu); + nti->writer = nullptr; + pthread_cond_broadcast(&nti->cv); + pthread_mutex_unlock(&nti->mu); + } + } + + return true; +} + +static bool receive_brotli_new_data(const uint8_t* data, size_t size, void* cookie) { + NewThreadInfo* nti = static_cast(cookie); + + while (size > 0 || BrotliDecoderHasMoreOutput(nti->brotli_decoder_state)) { + // Wait for nti->writer to be non-null, indicating some of this data is wanted. + pthread_mutex_lock(&nti->mu); + while (nti->writer == nullptr) { + pthread_cond_wait(&nti->cv, &nti->mu); + } + pthread_mutex_unlock(&nti->mu); + + // At this point nti->writer is set, and we own it. The main thread is waiting for it to + // disappear from nti. + + size_t buffer_size = std::min(32768, nti->writer->AvailableSpace()); + if (buffer_size == 0) { + LOG(ERROR) << "No space left in output range"; + return false; + } + uint8_t buffer[buffer_size]; + size_t available_in = size; + size_t available_out = buffer_size; + uint8_t* next_out = buffer; + + // The brotli decoder will update |data|, |available_in|, |next_out| and |available_out|. + BrotliDecoderResult result = BrotliDecoderDecompressStream( + nti->brotli_decoder_state, &available_in, &data, &available_out, &next_out, nullptr); - // We encounter a fatal error if we fail to consume any input bytes. If this happens, abort the - // extraction. - if (consumed == 0) { - LOG(ERROR) << "Failed to process " << size << " input bytes."; + if (result == BROTLI_DECODER_RESULT_ERROR) { + LOG(ERROR) << "Decompression failed with " + << BrotliDecoderErrorString(BrotliDecoderGetErrorCode(nti->brotli_decoder_state)); return false; } - data += consumed; - size -= consumed; + + LOG(DEBUG) << "bytes to write: " << buffer_size - available_out << ", bytes consumed " + << size - available_in << ", decoder status " << result; + + size_t write_now = buffer_size - available_out; + if (nti->writer->Write(buffer, write_now) != write_now) { + LOG(ERROR) << "Failed to write " << write_now << " bytes."; + return false; + } + + // Update the remaining size. The input data ptr is already updated by brotli decoder function. + size = available_in; if (nti->writer->Finished()) { // We have written all the bytes desired by this writer. @@ -380,8 +370,11 @@ static bool receive_new_data(const uint8_t* data, size_t size, void* cookie) { static void* unzip_new_data(void* cookie) { NewThreadInfo* nti = static_cast(cookie); - ProcessZipEntryContents(nti->za, &nti->entry, receive_new_data, nti); - + if (nti->brotli_compressed) { + ProcessZipEntryContents(nti->za, &nti->entry, receive_brotli_new_data, nti); + } else { + ProcessZipEntryContents(nti->za, &nti->entry, receive_new_data, nti); + } pthread_mutex_lock(&nti->mu); nti->receiver_available = false; if (nti->writer != nullptr) { @@ -1240,12 +1233,7 @@ static int PerformCommandNew(CommandParameters& params) { LOG(INFO) << " writing " << tgt.blocks() << " blocks of new data"; pthread_mutex_lock(¶ms.nti.mu); - if (params.nti.brotli_compressed) { - params.nti.writer = - std::make_unique(params.fd, tgt, params.nti.brotli_decoder_state); - } else { - params.nti.writer = std::make_unique(params.fd, tgt); - } + params.nti.writer = std::make_unique(params.fd, tgt); pthread_cond_broadcast(¶ms.nti.cv); while (params.nti.writer != nullptr) { @@ -1485,7 +1473,6 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, if (params.canwrite) { params.nti.za = za; params.nti.entry = new_entry; - // The entry is compressed by brotli if has a 'br' extension. params.nti.brotli_compressed = android::base::EndsWith(new_data_fn->data, ".br"); if (params.nti.brotli_compressed) { // Initialize brotli decoder state. -- cgit v1.2.3 From 329fe83509d916c2b7465f3a60ebb308add61898 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 21 Jul 2017 12:13:15 -0700 Subject: Avoid crashing recovery with unwritable /cache. When /cache is unwritable, recovery hits a crash loop. Because it passes nullptr to fileno(3) when writing back the locale file. This prevents user from recovering a device - it cannot boot far enough to recovery menu which allows wiping /cache. Bug: 63927337 Test: Corrupt /cache and boot into recovery on bullhead: 1. m -j recoveryimage 2. fastboot erase cache 3. fastboot boot $OUT/recovery.img 4. recovery menu shows up. Change-Id: I1407743f802049eb48add56a36298b665cb86139 (cherry picked from commit ec57903a7ec0bfe3c2f39dd6ee9cfc3de4ed20e6) --- recovery.cpp | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 50115885f..11c12f6f1 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -478,40 +478,38 @@ static void copy_logs() { sync(); } -// clear the recovery command and prepare to boot a (hopefully working) system, +// Clear the recovery command and prepare to boot a (hopefully working) system, // copy our log file to cache as well (for the system to read). This function is // idempotent: call it as many times as you like. static void finish_recovery() { - // Save the locale to cache, so if recovery is next started up - // without a --locale argument (eg, directly from the bootloader) - // it will use the last-known locale. - if (!locale.empty() && has_cache) { - LOG(INFO) << "Saving locale \"" << locale << "\""; - - FILE* fp = fopen_path(LOCALE_FILE, "we"); - if (!android::base::WriteStringToFd(locale, fileno(fp))) { - PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE; - } - check_and_fclose(fp, LOCALE_FILE); + // Save the locale to cache, so if recovery is next started up without a '--locale' argument + // (e.g., directly from the bootloader) it will use the last-known locale. + if (!locale.empty() && has_cache) { + LOG(INFO) << "Saving locale \"" << locale << "\""; + if (ensure_path_mounted(LOCALE_FILE) != 0) { + LOG(ERROR) << "Failed to mount " << LOCALE_FILE; + } else if (!android::base::WriteStringToFile(locale, LOCALE_FILE)) { + PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE; } + } - copy_logs(); + copy_logs(); - // Reset to normal system boot so recovery won't cycle indefinitely. - std::string err; - if (!clear_bootloader_message(&err)) { - LOG(ERROR) << "Failed to clear BCB message: " << err; - } + // Reset to normal system boot so recovery won't cycle indefinitely. + std::string err; + if (!clear_bootloader_message(&err)) { + LOG(ERROR) << "Failed to clear BCB message: " << err; + } - // Remove the command file, so recovery won't repeat indefinitely. - if (has_cache) { - if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) { - LOG(WARNING) << "Can't unlink " << COMMAND_FILE; - } - ensure_path_unmounted(CACHE_ROOT); + // Remove the command file, so recovery won't repeat indefinitely. + if (has_cache) { + if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) { + LOG(WARNING) << "Can't unlink " << COMMAND_FILE; } + ensure_path_unmounted(CACHE_ROOT); + } - sync(); // For good measure. + sync(); // For good measure. } struct saved_log_file { -- cgit v1.2.3 From 5fb9f532f00ffc885c7415c6dc48c4deed20a219 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 21 Jul 2017 15:15:31 -0700 Subject: update_verifier: Handle legacy care_map.txt gracefully. update_verifier should be backward compatible to not reject legacy care_map.txt from old releases, which could otherwise fail to boot into the new release. For example, we've changed the care_map format between N and O. An O update_verifier would fail to work with an N care_map.txt - a) we have switched update_verifier to read from device mapper in O; b) the last few blocks that contain metadata can't be read via device mapper. This could be a result of sideloading an O OTA while the device having a pending N update. Bug: 63544345 Test: As follows on sailfish: 1. Flash the device with this CL; 2. Put a copy of N care_map.txt at /data/ota_package/. Restore the permissions properly ('cache' group); 3. `adb reboot bootloader`; 4. `fastboot set_active ` 5. Device boots up into home screen, with a warning in logcat that says it has skipped legacy care_map.txt. Change-Id: I6acc88c9e655a9245e6531f176fef7953953935f (cherry picked from commit 5a1dee01df3af346729b5791606b72d59b8e9815) --- update_verifier/update_verifier.cpp | 71 ++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp index d3a5185b8..b49011a12 100644 --- a/update_verifier/update_verifier.cpp +++ b/update_verifier/update_verifier.cpp @@ -175,40 +175,53 @@ static bool read_blocks(const std::string& partition, const std::string& range_s return true; } +// Returns true to indicate a passing verification (or the error should be ignored); Otherwise +// returns false on fatal errors, where we should reject the current boot and trigger a fallback. +// Note that update_verifier should be backward compatible to not reject care_map.txt from old +// releases, which could otherwise fail to boot into the new release. For example, we've changed +// the care_map format between N and O. An O update_verifier would fail to work with N +// care_map.txt. This could be a result of sideloading an O OTA while the device having a pending N +// update. bool verify_image(const std::string& care_map_name) { - android::base::unique_fd care_map_fd(TEMP_FAILURE_RETRY(open(care_map_name.c_str(), O_RDONLY))); - // If the device is flashed before the current boot, it may not have care_map.txt - // in /data/ota_package. To allow the device to continue booting in this situation, - // we should print a warning and skip the block verification. - if (care_map_fd.get() == -1) { - PLOG(WARNING) << "Failed to open " << care_map_name; - return true; - } - // Care map file has four lines (two lines if vendor partition is not present): - // First line has the block partition name (system/vendor). - // Second line holds all ranges of blocks to verify. - // The next two lines have the same format but for vendor partition. - std::string file_content; - if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) { - LOG(ERROR) << "Error reading care map contents to string."; - return false; - } + android::base::unique_fd care_map_fd(TEMP_FAILURE_RETRY(open(care_map_name.c_str(), O_RDONLY))); + // If the device is flashed before the current boot, it may not have care_map.txt + // in /data/ota_package. To allow the device to continue booting in this situation, + // we should print a warning and skip the block verification. + if (care_map_fd.get() == -1) { + PLOG(WARNING) << "Failed to open " << care_map_name; + return true; + } + // Care map file has four lines (two lines if vendor partition is not present): + // First line has the block partition name (system/vendor). + // Second line holds all ranges of blocks to verify. + // The next two lines have the same format but for vendor partition. + std::string file_content; + if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) { + LOG(ERROR) << "Error reading care map contents to string."; + return false; + } - std::vector lines; - lines = android::base::Split(android::base::Trim(file_content), "\n"); - if (lines.size() != 2 && lines.size() != 4) { - LOG(ERROR) << "Invalid lines in care_map: found " << lines.size() - << " lines, expecting 2 or 4 lines."; - return false; - } + std::vector lines; + lines = android::base::Split(android::base::Trim(file_content), "\n"); + if (lines.size() != 2 && lines.size() != 4) { + LOG(ERROR) << "Invalid lines in care_map: found " << lines.size() + << " lines, expecting 2 or 4 lines."; + return false; + } - for (size_t i = 0; i < lines.size(); i += 2) { - if (!read_blocks(lines[i], lines[i+1])) { - return false; - } + for (size_t i = 0; i < lines.size(); i += 2) { + // We're seeing an N care_map.txt. Skip the verification since it's not compatible with O + // update_verifier (the last few metadata blocks can't be read via device mapper). + if (android::base::StartsWith(lines[i], "/dev/block/")) { + LOG(WARNING) << "Found legacy care_map.txt; skipped."; + return true; + } + if (!read_blocks(lines[i], lines[i+1])) { + return false; } + } - return true; + return true; } static int reboot_device() { -- cgit v1.2.3 From 5cee24f4f1aa3f53c0b386abb2797c1e0f3088eb Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 24 Jul 2017 09:22:39 -0700 Subject: tests: Add a test to cover legacy care_map.txt handling. This is to cover the code added by commit 5a1dee01df3af346729b5791606b72d59b8e9815, where an O update_verifier should not reject N care_map.txt. Bug: 63544345 Test: recovery_component_test passes on marlin. Change-Id: Ia944e16cba3cc635098b3ffd92842d725b570fec (cherry picked from commit c319613e06f996aed32da3a1c3e93bf9b04ffa95) --- tests/component/update_verifier_test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/component/update_verifier_test.cpp b/tests/component/update_verifier_test.cpp index 5fc7ef63f..b04e1185e 100644 --- a/tests/component/update_verifier_test.cpp +++ b/tests/component/update_verifier_test.cpp @@ -81,3 +81,16 @@ TEST_F(UpdateVerifierTest, verify_image_malformed_care_map) { ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file.path)); ASSERT_FALSE(verify_image(temp_file.path)); } + +TEST_F(UpdateVerifierTest, verify_image_legacy_care_map) { + // This test relies on dm-verity support. + if (!verity_supported) { + GTEST_LOG_(INFO) << "Test skipped on devices without dm-verity support."; + return; + } + + TemporaryFile temp_file; + std::string content = "/dev/block/bootdevice/by-name/system\n2,1,0"; + ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file.path)); + ASSERT_TRUE(verify_image(temp_file.path)); +} -- cgit v1.2.3 From fda6ee7d6117f1ef563a590571af65c185169efe Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 25 Jul 2017 09:52:36 -0700 Subject: recovery: Fix the flickering when turning on text mode. When there's no command specified when booting into debuggable builds (such as using `adb reboot recovery`), we turn on the text mode (i.e. recovery menu) directly. This CL fixes the issue to avoid showing the background image in a flash while turning on the text mode. Bug: 63985334 Test: `fastboot boot $OUT/recovery.img` and it shows the recovery menu directly without the no command image in a flash. Change-Id: Id86bbe346ab76c8defc95e2b423e695a86774b09 (cherry picked from commit 7022f33ec8531c742f8f4701552d687233901495) --- recovery.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 11c12f6f1..8f08c53f4 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -1591,15 +1591,14 @@ int main(int argc, char **argv) { ui->Print("Rebooting automatically.\n"); } } else if (!just_exit) { - status = INSTALL_NONE; // No command specified - ui->SetBackground(RecoveryUI::NO_COMMAND); - - // http://b/17489952 - // If this is an eng or userdebug build, automatically turn on the - // text display if no command is specified. - if (is_ro_debuggable()) { - ui->ShowText(true); - } + // If this is an eng or userdebug build, automatically turn on the text display if no command + // is specified. Note that this should be called before setting the background to avoid + // flickering the background image. + if (is_ro_debuggable()) { + ui->ShowText(true); + } + status = INSTALL_NONE; // No command specified + ui->SetBackground(RecoveryUI::NO_COMMAND); } if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) { -- cgit v1.2.3 From af9f8b4d97af56b5abcb622aaecebce59179bc0b Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 28 Jul 2017 00:05:40 -0700 Subject: ui: Move the support for touch inputs into RecoveryUI. - Added detection for EV_ABS events in minui/events.cpp, if it's allowed; - Added listening and processing touch inputs in ui.cpp; - Fixed an issue in recognizing swipe with multi-touch protocol A; - Changed the logic in RecoveryUI::ProcessKey() to be swipe-aware. It now allows turning on text mode with + . The last change also fixed an issue on devices with protocol A: prior to this CL, user may accidentally toggle the text mode during an OTA. Because it was considered as a single-button device, a long tap that sent BTN_TOUCH event would turn on text mode. Test: Allow detecting touch inputs. Swiping (up, down, enter) works on angler, angelfish, dorado respectively. Bug: 36169090 Bug: 64307776 Change-Id: I4bc882b99114ce4ab414f8bdb8f4f7a525b8a8fd (cherry picked from commit 5f8dd9951d986b65d98d6a9ea38003427e9e46df) --- Android.mk | 12 ++++ minui/events.cpp | 47 +++++++++++---- minui/include/minui/minui.h | 3 +- ui.cpp | 139 ++++++++++++++++++++++++++++++++++++++++++-- ui.h | 24 ++++++++ 5 files changed, 209 insertions(+), 16 deletions(-) diff --git a/Android.mk b/Android.mk index 3eed7a696..967b9dfbe 100644 --- a/Android.mk +++ b/Android.mk @@ -108,6 +108,18 @@ else LOCAL_CFLAGS += -DRECOVERY_UI_MARGIN_WIDTH=0 endif +ifneq ($(TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD),) +LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_LOW_THRESHOLD=$(TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD) +else +LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_LOW_THRESHOLD=50 +endif + +ifneq ($(TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD),) +LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_HIGH_THRESHOLD=$(TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD) +else +LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_HIGH_THRESHOLD=90 +endif + ifneq ($(TARGET_RECOVERY_UI_VR_STEREO_OFFSET),) LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=$(TARGET_RECOVERY_UI_VR_STEREO_OFFSET) else diff --git a/minui/events.cpp b/minui/events.cpp index 0e1fd44a0..24c2a8277 100644 --- a/minui/events.cpp +++ b/minui/events.cpp @@ -53,36 +53,37 @@ static bool test_bit(size_t bit, unsigned long* array) { // NOLINT return (array[bit/BITS_PER_LONG] & (1UL << (bit % BITS_PER_LONG))) != 0; } -int ev_init(ev_callback input_cb) { - bool epollctlfail = false; - +int ev_init(ev_callback input_cb, bool allow_touch_inputs) { g_epoll_fd = epoll_create(MAX_DEVICES + MAX_MISC_FDS); if (g_epoll_fd == -1) { return -1; } + bool epollctlfail = false; DIR* dir = opendir("/dev/input"); - if (dir != NULL) { + if (dir != nullptr) { dirent* de; while ((de = readdir(dir))) { - // Use unsigned long to match ioctl's parameter type. - unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT - - // fprintf(stderr,"/dev/input/%s\n", de->d_name); if (strncmp(de->d_name, "event", 5)) continue; int fd = openat(dirfd(dir), de->d_name, O_RDONLY); if (fd == -1) continue; + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT + // Read the evbits of the input device. if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) { close(fd); continue; } - // We assume that only EV_KEY, EV_REL, and EV_SW event types are ever needed. + // We assume that only EV_KEY, EV_REL, and EV_SW event types are ever needed. EV_ABS is also + // allowed if allow_touch_inputs is set. if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits) && !test_bit(EV_SW, ev_bits)) { - close(fd); - continue; + if (!allow_touch_inputs || !test_bit(EV_ABS, ev_bits)) { + close(fd); + continue; + } } epoll_event ev; @@ -231,3 +232,27 @@ void ev_iterate_available_keys(const std::function& f) { } } } + +void ev_iterate_touch_inputs(const std::function& action) { + for (size_t i = 0; i < ev_dev_count; ++i) { + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)] = {}; // NOLINT + if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) == -1) { + continue; + } + if (!test_bit(EV_ABS, ev_bits)) { + continue; + } + + unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)] = {}; // NOLINT + if (ioctl(ev_fdinfo[i].fd, EVIOCGBIT(EV_ABS, KEY_MAX), key_bits) == -1) { + continue; + } + + for (int key_code = 0; key_code <= KEY_MAX; ++key_code) { + if (test_bit(key_code, key_bits)) { + action(key_code); + } + } + } +} diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h index 78dd4cb98..017ddde75 100644 --- a/minui/include/minui/minui.h +++ b/minui/include/minui/minui.h @@ -74,10 +74,11 @@ struct input_event; using ev_callback = std::function; using ev_set_key_callback = std::function; -int ev_init(ev_callback input_cb); +int ev_init(ev_callback input_cb, bool allow_touch_inputs = false); void ev_exit(); int ev_add_fd(int fd, ev_callback cb); void ev_iterate_available_keys(const std::function& f); +void ev_iterate_touch_inputs(const std::function& action); int ev_sync_key_state(const ev_set_key_callback& set_key_cb); // 'timeout' has the same semantics as poll(2). diff --git a/ui.cpp b/ui.cpp index 30b42a19a..eadcdd433 100644 --- a/ui.cpp +++ b/ui.cpp @@ -54,6 +54,9 @@ RecoveryUI::RecoveryUI() rtl_locale_(false), brightness_normal_(50), brightness_dimmed_(25), + touch_screen_allowed_(false), + kTouchLowThreshold(RECOVERY_UI_TOUCH_LOW_THRESHOLD), + kTouchHighThreshold(RECOVERY_UI_TOUCH_HIGH_THRESHOLD), key_queue_len(0), key_last_down(-1), key_long_press(false), @@ -64,6 +67,8 @@ RecoveryUI::RecoveryUI() has_power_key(false), has_up_key(false), has_down_key(false), + has_touch_screen(false), + touch_slot_(0), screensaver_state_(ScreensaverState::DISABLED) { pthread_mutex_init(&key_queue_mutex, nullptr); pthread_cond_init(&key_queue_cond, nullptr); @@ -77,6 +82,8 @@ void RecoveryUI::OnKeyDetected(int key_code) { has_down_key = true; } else if (key_code == KEY_UP || key_code == KEY_VOLUMEUP) { has_up_key = true; + } else if (key_code == ABS_MT_POSITION_X || key_code == ABS_MT_POSITION_Y) { + has_touch_screen = true; } } @@ -128,10 +135,15 @@ bool RecoveryUI::Init(const std::string& locale) { // Set up the locale info. SetLocale(locale); - ev_init(std::bind(&RecoveryUI::OnInputEvent, this, std::placeholders::_1, std::placeholders::_2)); + ev_init(std::bind(&RecoveryUI::OnInputEvent, this, std::placeholders::_1, std::placeholders::_2), + touch_screen_allowed_); ev_iterate_available_keys(std::bind(&RecoveryUI::OnKeyDetected, this, std::placeholders::_1)); + if (touch_screen_allowed_) { + ev_iterate_touch_inputs(std::bind(&RecoveryUI::OnKeyDetected, this, std::placeholders::_1)); + } + if (!InitScreensaver()) { LOG(INFO) << "Screensaver disabled"; } @@ -140,15 +152,85 @@ bool RecoveryUI::Init(const std::string& locale) { return true; } +void RecoveryUI::OnTouchDetected(int dx, int dy) { + enum SwipeDirection { UP, DOWN, RIGHT, LEFT } direction; + + // We only consider a valid swipe if: + // - the delta along one axis is below kTouchLowThreshold; + // - and the delta along the other axis is beyond kTouchHighThreshold. + if (abs(dy) < kTouchLowThreshold && abs(dx) > kTouchHighThreshold) { + direction = dx < 0 ? SwipeDirection::LEFT : SwipeDirection::RIGHT; + } else if (abs(dx) < kTouchLowThreshold && abs(dy) > kTouchHighThreshold) { + direction = dy < 0 ? SwipeDirection::UP : SwipeDirection::DOWN; + } else { + LOG(DEBUG) << "Ignored " << dx << " " << dy << " (low: " << kTouchLowThreshold + << ", high: " << kTouchHighThreshold << ")"; + return; + } + + LOG(DEBUG) << "Swipe direction=" << direction; + switch (direction) { + case SwipeDirection::UP: + ProcessKey(KEY_UP, 1); // press up key + ProcessKey(KEY_UP, 0); // and release it + break; + + case SwipeDirection::DOWN: + ProcessKey(KEY_DOWN, 1); // press down key + ProcessKey(KEY_DOWN, 0); // and release it + break; + + case SwipeDirection::LEFT: + case SwipeDirection::RIGHT: + ProcessKey(KEY_POWER, 1); // press power key + ProcessKey(KEY_POWER, 0); // and release it + break; + }; +} + int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) { struct input_event ev; if (ev_get_input(fd, epevents, &ev) == -1) { return -1; } + // Touch inputs handling. + // + // We handle the touch inputs by tracking the position changes between initial contacting and + // upon lifting. touch_start_X/Y record the initial positions, with touch_finger_down set. Upon + // detecting the lift, we unset touch_finger_down and detect a swipe based on position changes. + // + // Per the doc Multi-touch Protocol at below, there are two protocols. + // https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt + // + // The main difference between the stateless type A protocol and the stateful type B slot protocol + // lies in the usage of identifiable contacts to reduce the amount of data sent to userspace. The + // slot protocol (i.e. type B) sends ABS_MT_TRACKING_ID with a unique id on initial contact, and + // sends ABS_MT_TRACKING_ID -1 upon lifting the contact. Protocol A doesn't send + // ABS_MT_TRACKING_ID -1 on lifting, but the driver may additionally report BTN_TOUCH event. + // + // For protocol A, we rely on BTN_TOUCH to recognize lifting, while for protocol B we look for + // ABS_MT_TRACKING_ID being -1. + // + // Touch input events will only be available if touch_screen_allowed_ is set. + if (ev.type == EV_SYN) { + if (touch_screen_allowed_ && ev.code == SYN_REPORT) { + // There might be multiple SYN_REPORT events. We should only detect a swipe after lifting the + // contact. + if (touch_finger_down_ && !touch_swiping_) { + touch_start_X_ = touch_X_; + touch_start_Y_ = touch_Y_; + touch_swiping_ = true; + } else if (!touch_finger_down_ && touch_swiping_) { + touch_swiping_ = false; + OnTouchDetected(touch_X_ - touch_start_X_, touch_Y_ - touch_start_Y_); + } + } return 0; - } else if (ev.type == EV_REL) { + } + + 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 @@ -169,7 +251,48 @@ int RecoveryUI::OnInputEvent(int fd, uint32_t epevents) { rel_sum = 0; } + if (touch_screen_allowed_ && ev.type == EV_ABS) { + if (ev.code == ABS_MT_SLOT) { + touch_slot_ = ev.value; + } + // Ignore other fingers. + if (touch_slot_ > 0) return 0; + + switch (ev.code) { + case ABS_MT_POSITION_X: + touch_X_ = ev.value; + touch_finger_down_ = true; + break; + + case ABS_MT_POSITION_Y: + touch_Y_ = ev.value; + touch_finger_down_ = true; + break; + + case ABS_MT_TRACKING_ID: + // Protocol B: -1 marks lifting the contact. + if (ev.value < 0) touch_finger_down_ = false; + break; + } + return 0; + } + if (ev.type == EV_KEY && ev.code <= KEY_MAX) { + if (touch_screen_allowed_) { + if (ev.code == BTN_TOUCH) { + // A BTN_TOUCH with value 1 indicates the start of contact (protocol A), with 0 means + // lifting the contact. + touch_finger_down_ = (ev.value == 1); + } + + // Intentionally ignore BTN_TOUCH and BTN_TOOL_FINGER, which would otherwise trigger + // additional scrolling (because in ScreenRecoveryUI::ShowFile(), we consider keys other than + // KEY_POWER and KEY_UP as KEY_DOWN). + if (ev.code == BTN_TOUCH || ev.code == BTN_TOOL_FINGER) { + return 0; + } + } + ProcessKey(ev.code, ev.value); } @@ -365,6 +488,14 @@ bool RecoveryUI::HasThreeButtons() { return has_power_key && has_up_key && has_down_key; } +bool RecoveryUI::HasPowerKey() const { + return has_power_key; +} + +bool RecoveryUI::HasTouchScreen() const { + return has_touch_screen; +} + void RecoveryUI::FlushKeys() { pthread_mutex_lock(&key_queue_mutex); key_queue_len = 0; @@ -377,8 +508,8 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) { 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)) { + if (HasThreeButtons() || (HasPowerKey() && HasTouchScreen() && touch_screen_allowed_)) { + if ((key == KEY_VOLUMEUP || key == KEY_UP) && IsKeyPressed(KEY_POWER)) { return TOGGLE; } } else { diff --git a/ui.h b/ui.h index 7eb04aec8..5cda7af0f 100644 --- a/ui.h +++ b/ui.h @@ -82,6 +82,12 @@ class RecoveryUI { // otherwise. virtual bool HasThreeButtons(); + // Returns true if it has a power key. + virtual bool HasPowerKey() const; + + // Returns true if it supports touch inputs. + virtual bool HasTouchScreen() const; + // Erases any queued-up keys. virtual void FlushKeys(); @@ -129,7 +135,14 @@ class RecoveryUI { unsigned int brightness_normal_; unsigned int brightness_dimmed_; + // Whether we should listen for touch inputs (default: false). + bool touch_screen_allowed_; + private: + // The sensitivity when detecting a swipe. + const int kTouchLowThreshold; + const int kTouchHighThreshold; + // Key event input queue pthread_mutex_t key_queue_mutex; pthread_cond_t key_queue_cond; @@ -147,6 +160,16 @@ class RecoveryUI { bool has_power_key; bool has_up_key; bool has_down_key; + bool has_touch_screen; + + // Touch event related variables. See the comments in RecoveryUI::OnInputEvent(). + int touch_slot_; + int touch_X_; + int touch_Y_; + int touch_start_X_; + int touch_start_Y_; + bool touch_finger_down_; + bool touch_swiping_; struct key_timer_t { RecoveryUI* ui; @@ -157,6 +180,7 @@ class RecoveryUI { pthread_t input_thread_; void OnKeyDetected(int key_code); + void OnTouchDetected(int dx, int dy); int OnInputEvent(int fd, uint32_t epevents); void ProcessKey(int key_code, int updown); -- cgit v1.2.3 From 937e884ca113a5e775a3cb37a3f9dbe2174d3376 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 31 Jul 2017 23:15:09 -0700 Subject: ui: Check for bootreason=recovery_ui. Some wear bootloaders are passing bootreason=recovery_ui when booting into recovery from fastboot, or via 'adb reboot recovery'. Allow turning on text mode with a swipe for such a bootreason. Since we will turn on text mode automatically for debuggable builds, this bootreason mainly handles the case for user builds. Note this change only applies to devices that allow touch screen inputs. Bug: 36169090 Bug: 64307776 Test: Build and boot into user build recovery image. Toggle on text mode with a swipe. Change-Id: I55f19aed7b210352f8370de19935b4772cc12095 (cherry picked from commit 046aae29d9b0d2cdf24ad0567146991c3864c140) --- ui.cpp | 20 ++++++++++++++++++++ ui.h | 1 + 2 files changed, 21 insertions(+) diff --git a/ui.cpp b/ui.cpp index eadcdd433..e80d7ed04 100644 --- a/ui.cpp +++ b/ui.cpp @@ -69,6 +69,7 @@ RecoveryUI::RecoveryUI() has_down_key(false), has_touch_screen(false), touch_slot_(0), + is_bootreason_recovery_ui_(false), screensaver_state_(ScreensaverState::DISABLED) { pthread_mutex_init(&key_queue_mutex, nullptr); pthread_cond_init(&key_queue_cond, nullptr); @@ -142,6 +143,19 @@ bool RecoveryUI::Init(const std::string& locale) { if (touch_screen_allowed_) { ev_iterate_touch_inputs(std::bind(&RecoveryUI::OnKeyDetected, this, std::placeholders::_1)); + + // Parse /proc/cmdline to determine if it's booting into recovery with a bootreason of + // "recovery_ui". This specific reason is set by some (wear) bootloaders, to allow an easier way + // to turn on text mode. It will only be set if the recovery boot is triggered from fastboot, or + // with 'adb reboot recovery'. Note that this applies to all build variants. Otherwise the text + // mode will be turned on automatically on debuggable builds, even without a swipe. + std::string cmdline; + if (android::base::ReadFileToString("/proc/cmdline", &cmdline)) { + is_bootreason_recovery_ui_ = cmdline.find("bootreason=recovery_ui") != std::string::npos; + } else { + // Non-fatal, and won't affect Init() result. + PLOG(WARNING) << "Failed to read /proc/cmdline"; + } } if (!InitScreensaver()) { @@ -168,6 +182,12 @@ void RecoveryUI::OnTouchDetected(int dx, int dy) { return; } + // Allow turning on text mode with any swipe, if bootloader has set a bootreason of recovery_ui. + if (is_bootreason_recovery_ui_ && !IsTextVisible()) { + ShowText(true); + return; + } + LOG(DEBUG) << "Swipe direction=" << direction; switch (direction) { case SwipeDirection::UP: diff --git a/ui.h b/ui.h index 5cda7af0f..3d9afece0 100644 --- a/ui.h +++ b/ui.h @@ -170,6 +170,7 @@ class RecoveryUI { int touch_start_Y_; bool touch_finger_down_; bool touch_swiping_; + bool is_bootreason_recovery_ui_; struct key_timer_t { RecoveryUI* ui; -- cgit v1.2.3 From 5c2bc51bf26bbd88253c464340d9191ce247961b Mon Sep 17 00:00:00 2001 From: Bill Yi Date: Sat, 5 Aug 2017 18:24:07 -0700 Subject: Import translations. DO NOT MERGE Change-Id: Ia215c30c6912ffa1e3270543f6ff4fc27f4260e4 Auto-generated-cl: translation import Exempt-From-Owner-Approval: translation import --- tools/recovery_l10n/res/values-en-rXC/strings.xml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/recovery_l10n/res/values-en-rXC/strings.xml diff --git a/tools/recovery_l10n/res/values-en-rXC/strings.xml b/tools/recovery_l10n/res/values-en-rXC/strings.xml new file mode 100644 index 000000000..2d528b3fb --- /dev/null +++ b/tools/recovery_l10n/res/values-en-rXC/strings.xml @@ -0,0 +1,9 @@ + + + "‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‎‏‏‏‎‏‏‏‏‏‏‎‎‎‏‏‎‏‏‎‏‏‏‎‎‏‎‏‎‏‏‎‏‏‎‎‏‏‏‏‏‎‎‎‎‎‏‏‏‏‎‎‎‎‎‎‏‎‎‏‏‏‏‎Installing system update‎‏‎‎‏‎" + "‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‎‎‏‎‏‏‏‎‎‏‎‏‎‏‎‎‎‏‎‏‎‎‎‏‏‎‎‏‏‎‎‎‎‎‏‏‏‏‎‏‏‏‏‎‎‏‎‎‎‏‏‏‎‏‏‏‎‎‎‎‎‎Erasing‎‏‎‎‏‎" + "‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‎‏‏‏‏‎‏‏‏‏‏‏‎‎‎‏‎‎‎‏‏‏‏‎‏‎‎‎‏‏‏‏‎‏‏‎‎‎‏‏‎‎‏‏‎‏‏‎‎‎‎‏‎‎‎‏‏‎‎‎‏‏‏‎No command‎‏‎‎‏‎" + "‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‎‎‏‏‏‏‏‏‎‎‎‏‎‏‏‎‏‎‎‎‏‎‎‏‎‏‎‏‎‏‏‏‏‏‏‏‎‏‏‏‎‏‎‎‏‏‎‏‏‎‏‎‎‏‎‏‎‎‎‎‎‎‎Error!‎‏‎‎‏‎" + "‎‏‎‎‎‎‎‏‎‏‏‏‎‎‎‎‎‏‎‎‏‎‎‎‏‎‏‏‏‏‏‏‏‏‏‏‏‏‏‎‏‏‏‎‏‎‎‎‎‏‏‏‎‏‏‏‏‎‎‏‏‏‎‏‏‎‏‏‎‎‏‏‎‏‏‎‏‎‏‎‎‏‎‏‎‎‏‏‏‏‎‎‏‏‎‎Installing security update‎‏‎‎‏‎" + -- cgit v1.2.3 From bd9664b5a01c8941949212973ca12be4df1b5d54 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 2 Aug 2017 10:27:31 -0700 Subject: update_verifier: verify blocks in parallel This CL is to change update_verifier to verify blocks in parallel to maximize storage bandwidth, it also preallocate the buffer to avoid vector allocation within reading loop. Test: care_map.txt: system 16,0,517,556,32770,33084,98306,98620,163842,164156,229378,229692,294914,295228,483544,524288,524296 vendor 8,0,119,135,32770,32831,96150,98304,98306 With CL: init: Service 'update_verifier_nonencrypted' (pid 711) exited with status 0 waiting took 2.978424 seconds Without CL: init: Service 'update_verifier_nonencrypted' (pid 695) exited with status 0 waiting took 4.466320 seconds Bug: 63686531 Test: reboot with manual insert care_map.txt Change-Id: Idf791865f15f6ff6cad89bf7ff230ee46c6adccc --- update_verifier/update_verifier.cpp | 82 +++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp index b49011a12..ceb3ec948 100644 --- a/update_verifier/update_verifier.cpp +++ b/update_verifier/update_verifier.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -123,11 +124,6 @@ static bool read_blocks(const std::string& partition, const std::string& range_s LOG(ERROR) << "Failed to find dm block device for " << partition; return false; } - android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dm_block_device.c_str(), O_RDONLY))); - if (fd.get() == -1) { - PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition; - return false; - } // For block range string, first integer 'count' equals 2 * total number of valid ranges, // followed by 'count' number comma separated integers. Every two integers reprensent a @@ -142,37 +138,61 @@ static bool read_blocks(const std::string& partition, const std::string& range_s return false; } - size_t blk_count = 0; - for (size_t i = 1; i < ranges.size(); i += 2) { - unsigned int range_start, range_end; - bool parse_status = android::base::ParseUint(ranges[i], &range_start); - parse_status = parse_status && android::base::ParseUint(ranges[i + 1], &range_end); - if (!parse_status || range_start >= range_end) { - LOG(ERROR) << "Invalid range pair " << ranges[i] << ", " << ranges[i + 1]; - return false; - } - - static constexpr size_t BLOCKSIZE = 4096; - if (lseek64(fd.get(), static_cast(range_start) * BLOCKSIZE, SEEK_SET) == -1) { - PLOG(ERROR) << "lseek to " << range_start << " failed"; - return false; - } + std::vector> threads; + size_t thread_num = std::thread::hardware_concurrency() ?: 4; + thread_num = std::min(thread_num, range_count / 2); + size_t group_range_count = range_count / thread_num; - size_t remain = (range_end - range_start) * BLOCKSIZE; - while (remain > 0) { - size_t to_read = std::min(remain, 1024 * BLOCKSIZE); - std::vector buf(to_read); - if (!android::base::ReadFully(fd.get(), buf.data(), to_read)) { - PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end; + for (size_t t = 0; t < thread_num; t++) { + auto thread_func = [t, group_range_count, &dm_block_device, &ranges, &partition]() { + size_t blk_count = 0; + static constexpr size_t kBlockSize = 4096; + std::vector buf(1024 * kBlockSize); + android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dm_block_device.c_str(), O_RDONLY))); + if (fd.get() == -1) { + PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition; return false; } - remain -= to_read; - } - blk_count += (range_end - range_start); + + for (size_t i = 1 + group_range_count * t; i < group_range_count * (t + 1) + 1; i += 2) { + unsigned int range_start, range_end; + bool parse_status = android::base::ParseUint(ranges[i], &range_start); + parse_status = parse_status && android::base::ParseUint(ranges[i + 1], &range_end); + if (!parse_status || range_start >= range_end) { + LOG(ERROR) << "Invalid range pair " << ranges[i] << ", " << ranges[i + 1]; + return false; + } + + if (lseek64(fd.get(), static_cast(range_start) * kBlockSize, SEEK_SET) == -1) { + PLOG(ERROR) << "lseek to " << range_start << " failed"; + return false; + } + + size_t remain = (range_end - range_start) * kBlockSize; + while (remain > 0) { + size_t to_read = std::min(remain, 1024 * kBlockSize); + if (!android::base::ReadFully(fd.get(), buf.data(), to_read)) { + PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end; + return false; + } + remain -= to_read; + } + blk_count += (range_end - range_start); + } + LOG(INFO) << "Finished reading " << blk_count << " blocks on " << dm_block_device; + return true; + }; + + threads.emplace_back(std::async(std::launch::async, thread_func)); } - LOG(INFO) << "Finished reading " << blk_count << " blocks on " << dm_block_device; - return true; + bool ret = true; + for (auto& t : threads) { + ret = t.get() && ret; + } + LOG(INFO) << "Finished reading blocks on " << dm_block_device << " with " << thread_num + << " threads."; + return ret; } // Returns true to indicate a passing verification (or the error should be ignored); Otherwise -- cgit v1.2.3 From 102016ce1fe62190ace7016f2e7484b37f6391ea Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 9 Aug 2017 16:33:07 -0700 Subject: tests: Add the missing dependency on libhidlbase. It fails to build recovery_component_test with the following errors: out/soong/.intermediates/hardware/interfaces/boot/1.0/android.hardware.boot@1.0_genc++_headers/gen/android/hardware/boot/1.0/types.h:14: error: undefined reference to 'android::hardware::hidl_string::hidl_string(android::hardware::hidl_string const&)' out/soong/.intermediates/hardware/interfaces/boot/1.0/android.hardware.boot@1.0_genc++_headers/gen/android/hardware/boot/1.0/types.h:14: error: undefined reference to 'android::hardware::hidl_string::operator=(android::hardware::hidl_string const&)' out/soong/.intermediates/hardware/interfaces/boot/1.0/android.hardware.boot@1.0_genc++_headers/gen/android/hardware/boot/1.0/types.h:14: error: undefined reference to 'android::hardware::hidl_string::~hidl_string()' libupdate_verifier includes , which includes the 'types.h' above. In 'types.h', it defines struct CommandResult that's using android::hardware::hidl_string. Since libhidlbase doesn't have a static library target, remove 'LOCAL_FORCE_STATIC_EXECUTABLE := true', which isn't required for running tests. Test: mmma -j bootable/recovery Bug: 64538692 Change-Id: Iaa7c08adc241128d787274fcaea9b363e7ff93f4 --- tests/Android.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Android.mk b/tests/Android.mk index 8b1dc1099..f2497b8b3 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -111,7 +111,8 @@ LOCAL_SRC_FILES := \ component/update_verifier_test.cpp \ component/verifier_test.cpp -LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_SHARED_LIBRARIES := \ + libhidlbase tune2fs_static_libraries := \ libext2_com_err \ -- cgit v1.2.3 From 016120f395795fb1be600c1e85f4dfd324797122 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 2 Aug 2017 17:11:04 -0700 Subject: Allow customizing WearRecoveryUI via Makefile variables. With the following Makefile variables, we can reduce the work of writing (copy/pasting) device-specific WearRecoveryUI classes. The list of Makefile variables (the ones useful for Wear devices): - TARGET_RECOVERY_UI_MARGIN_HEIGHT (default: 0) - TARGET_RECOVERY_UI_MARGIN_WIDTH (default: 0) Specify the margin space that we don't want to display texts. They replace the former outer_width and outer_height. - TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD (default: 50) - TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD (default: 90) Specify the sensitivity of recognizing a swipe. Devices give absolute positions, so for some devices we need to adjust the thresholds. - TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE Specify the progress bar vertical position, which should be adjusted to the actual height of a device. It replaces the former progress_bar_y. - TARGET_RECOVERY_UI_ANIMATION_FPS (default: 30) Specify the animation FPS if using device-specific animation images. It replaces the former animation_fps. Devices can specify "TARGET_RECOVERY_UI_LIB := librecovery_ui_wear", with optionally defined Makefile vars above, in BoardConfig.mk to customize their WearRecoveryUI. Also remove the obsolete wear_touch.{cpp,h}, which has been merged into ui.cpp in commit 5f8dd9951d986b65d98d6a9ea38003427e9e46df. Bug: 64307776 Test: Change the device BoardConfig.mk and test recovery image. Change-Id: Id0fb2d4e3977ab5ddd31e71f9535470cab70e41b (cherry picked from commit 0470ceea381775b09eee931858c3320be88cc637) --- Android.mk | 23 +++++++- screen_ui.cpp | 4 +- screen_ui.h | 6 +- wear_device.cpp | 23 ++++++++ wear_touch.cpp | 177 -------------------------------------------------------- wear_touch.h | 58 ------------------- wear_ui.cpp | 21 ++++--- wear_ui.h | 5 +- 8 files changed, 64 insertions(+), 253 deletions(-) create mode 100644 wear_device.cpp delete mode 100644 wear_touch.cpp delete mode 100644 wear_touch.h diff --git a/Android.mk b/Android.mk index 967b9dfbe..b1ee2440b 100644 --- a/Android.mk +++ b/Android.mk @@ -79,7 +79,6 @@ LOCAL_SRC_FILES := \ ui.cpp \ vr_ui.cpp \ wear_ui.cpp \ - wear_touch.cpp \ LOCAL_MODULE := recovery @@ -120,6 +119,18 @@ else LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_HIGH_THRESHOLD=90 endif +ifneq ($(TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE),) +LOCAL_CFLAGS += -DRECOVERY_UI_PROGRESS_BAR_BASELINE=$(TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE) +else +LOCAL_CFLAGS += -DRECOVERY_UI_PROGRESS_BAR_BASELINE=259 +endif + +ifneq ($(TARGET_RECOVERY_UI_ANIMATION_FPS),) +LOCAL_CFLAGS += -DRECOVERY_UI_ANIMATION_FPS=$(TARGET_RECOVERY_UI_ANIMATION_FPS) +else +LOCAL_CFLAGS += -DRECOVERY_UI_ANIMATION_FPS=30 +endif + ifneq ($(TARGET_RECOVERY_UI_VR_STEREO_OFFSET),) LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=$(TARGET_RECOVERY_UI_VR_STEREO_OFFSET) else @@ -216,6 +227,16 @@ LOCAL_STATIC_LIBRARIES := \ LOCAL_CFLAGS := -Werror include $(BUILD_STATIC_LIBRARY) +# Wear default device +# =============================== +include $(CLEAR_VARS) +LOCAL_SRC_FILES := wear_device.cpp + +# Should match TARGET_RECOVERY_UI_LIB in BoardConfig.mk. +LOCAL_MODULE := librecovery_ui_wear + +include $(BUILD_STATIC_LIBRARY) + # vr headset default device # =============================== include $(CLEAR_VARS) diff --git a/screen_ui.cpp b/screen_ui.cpp index 8f792f162..c83a7659e 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -53,6 +53,7 @@ static double now() { ScreenRecoveryUI::ScreenRecoveryUI() : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH), kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT), + kAnimationFps(RECOVERY_UI_ANIMATION_FPS), density_(static_cast(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), currentIcon(NONE), progressBarType(EMPTY), @@ -77,7 +78,6 @@ ScreenRecoveryUI::ScreenRecoveryUI() loop_frames(0), current_frame(0), intro_done(false), - animation_fps(30), // TODO: there's currently no way to infer this. stage(-1), max_stage(-1), updateMutex(PTHREAD_MUTEX_INITIALIZER) {} @@ -375,7 +375,7 @@ void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) { } void ScreenRecoveryUI::ProgressThreadLoop() { - double interval = 1.0 / animation_fps; + double interval = 1.0 / kAnimationFps; while (true) { double start = now(); pthread_mutex_lock(&updateMutex); diff --git a/screen_ui.h b/screen_ui.h index 8402fac00..1f40164af 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -84,6 +84,9 @@ class ScreenRecoveryUI : public RecoveryUI { const int kMarginWidth; const int kMarginHeight; + // Number of frames per sec (default: 30) for both parts of the animation. + const int kAnimationFps; + // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. const float density_; @@ -141,9 +144,6 @@ class ScreenRecoveryUI : public RecoveryUI { size_t current_frame; bool intro_done; - // Number of frames per sec (default: 30) for both parts of the animation. - int animation_fps; - int stage, max_stage; int char_width_; diff --git a/wear_device.cpp b/wear_device.cpp new file mode 100644 index 000000000..3268130b0 --- /dev/null +++ b/wear_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 "wear_ui.h" + +Device* make_device() { + return new Device(new WearRecoveryUI); +} + diff --git a/wear_touch.cpp b/wear_touch.cpp deleted file mode 100644 index e2ab44d2d..000000000 --- a/wear_touch.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2016 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 -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "wear_touch.h" - -#define DEVICE_PATH "/dev/input" - -WearSwipeDetector::WearSwipeDetector(int low, int high, OnSwipeCallback callback, void* cookie): - mLowThreshold(low), - mHighThreshold(high), - mCallback(callback), - mCookie(cookie), - mCurrentSlot(-1) { - pthread_create(&mThread, NULL, touch_thread, this); -} - -WearSwipeDetector::~WearSwipeDetector() { -} - -void WearSwipeDetector::detect(int dx, int dy) { - enum SwipeDirection direction; - - if (abs(dy) < mLowThreshold && abs(dx) > mHighThreshold) { - direction = dx < 0 ? LEFT : RIGHT; - } else if (abs(dx) < mLowThreshold && abs(dy) > mHighThreshold) { - direction = dy < 0 ? UP : DOWN; - } else { - LOG(DEBUG) << "Ignore " << dx << " " << dy; - return; - } - - LOG(DEBUG) << "Swipe direction=" << direction; - mCallback(mCookie, direction); -} - -void WearSwipeDetector::process(struct input_event *event) { - if (mCurrentSlot < 0) { - mCallback(mCookie, UP); - mCurrentSlot = 0; - } - - if (event->type == EV_ABS) { - if (event->code == ABS_MT_SLOT) - mCurrentSlot = event->value; - - // Ignore other fingers - if (mCurrentSlot > 0) { - return; - } - - switch (event->code) { - case ABS_MT_POSITION_X: - mX = event->value; - mFingerDown = true; - break; - - case ABS_MT_POSITION_Y: - mY = event->value; - mFingerDown = true; - break; - - case ABS_MT_TRACKING_ID: - if (event->value < 0) - mFingerDown = false; - break; - } - } else if (event->type == EV_SYN) { - if (event->code == SYN_REPORT) { - if (mFingerDown && !mSwiping) { - mStartX = mX; - mStartY = mY; - mSwiping = true; - } else if (!mFingerDown && mSwiping) { - mSwiping = false; - detect(mX - mStartX, mY - mStartY); - } - } - } -} - -void WearSwipeDetector::run() { - int fd = findDevice(DEVICE_PATH); - if (fd < 0) { - LOG(ERROR) << "no input devices found"; - return; - } - - struct input_event event; - while (read(fd, &event, sizeof(event)) == sizeof(event)) { - process(&event); - } - - close(fd); -} - -void* WearSwipeDetector::touch_thread(void* cookie) { - (static_cast(cookie))->run(); - return NULL; -} - -#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) - -int WearSwipeDetector::openDevice(const char *device) { - int fd = open(device, O_RDONLY); - if (fd < 0) { - PLOG(ERROR) << "could not open " << device; - return false; - } - - char name[80]; - name[sizeof(name) - 1] = '\0'; - if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) { - PLOG(ERROR) << "could not get device name for " << device; - name[0] = '\0'; - } - - uint8_t bits[512]; - memset(bits, 0, sizeof(bits)); - int ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(bits)), bits); - if (ret > 0) { - if (test_bit(ABS_MT_POSITION_X, bits) && test_bit(ABS_MT_POSITION_Y, bits)) { - LOG(DEBUG) << "Found " << device << " " << name; - return fd; - } - } - - close(fd); - return -1; -} - -int WearSwipeDetector::findDevice(const char* path) { - DIR* dir = opendir(path); - if (dir == NULL) { - PLOG(ERROR) << "Could not open directory " << path; - return false; - } - - struct dirent* entry; - int ret = -1; - while (ret < 0 && (entry = readdir(dir)) != NULL) { - if (entry->d_name[0] == '.') continue; - - char device[PATH_MAX]; - device[PATH_MAX-1] = '\0'; - snprintf(device, PATH_MAX-1, "%s/%s", path, entry->d_name); - - ret = openDevice(device); - } - - closedir(dir); - return ret; -} - diff --git a/wear_touch.h b/wear_touch.h deleted file mode 100644 index 9a1d3150c..000000000 --- a/wear_touch.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2016 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 __WEAR_TOUCH_H -#define __WEAR_TOUCH_H - -#include - -class WearSwipeDetector { - -public: - enum SwipeDirection { UP, DOWN, RIGHT, LEFT }; - typedef void (*OnSwipeCallback)(void* cookie, enum SwipeDirection direction); - - WearSwipeDetector(int low, int high, OnSwipeCallback cb, void* cookie); - ~WearSwipeDetector(); - -private: - void run(); - void process(struct input_event *event); - void detect(int dx, int dy); - - pthread_t mThread; - static void* touch_thread(void* cookie); - - int findDevice(const char* path); - int openDevice(const char* device); - - int mLowThreshold; - int mHighThreshold; - - OnSwipeCallback mCallback; - void *mCookie; - - int mX; - int mY; - int mStartX; - int mStartY; - - int mCurrentSlot; - bool mFingerDown; - bool mSwiping; -}; - -#endif // __WEAR_TOUCH_H diff --git a/wear_ui.cpp b/wear_ui.cpp index 18c30d34a..b8801a0b3 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -51,10 +51,15 @@ static double now() { } WearRecoveryUI::WearRecoveryUI() - : progress_bar_y(259), outer_height(0), outer_width(0), menu_unusable_rows(0) { + : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE), menu_unusable_rows(9) { + // TODO: menu_unusable_rows should be computed based on the lines in draw_screen_locked(). + + // TODO: The following three variables are likely not needed. The first two are detected + // automatically in ScreenRecoveryUI::LoadAnimation(), based on the actual files seen on device. intro_frames = 22; loop_frames = 60; - animation_fps = 30; + + touch_screen_allowed_ = true; for (size_t i = 0; i < 5; i++) backgroundIcon[i] = NULL; @@ -62,7 +67,7 @@ WearRecoveryUI::WearRecoveryUI() } int WearRecoveryUI::GetProgressBaseline() const { - return progress_bar_y; + return kProgressBarBaseline; } // Draw background frame on the screen. Does not flip pages. @@ -113,8 +118,8 @@ void WearRecoveryUI::draw_screen_locked() { SetColor(TEXT_FILL); gr_fill(0, 0, gr_fb_width(), gr_fb_height()); - int y = outer_height; - int x = outer_width; + int y = kMarginHeight; + int x = kMarginWidth; if (show_menu) { std::string recovery_fingerprint = android::base::GetProperty("ro.bootimage.build.fingerprint", ""); @@ -170,7 +175,7 @@ void WearRecoveryUI::draw_screen_locked() { 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_; + for (int ty = gr_fb_height() - char_height_ - kMarginHeight; ty > y + 2 && count < text_rows_; ty -= char_height_, ++count) { gr_text(gr_sys_font(), x + 4, ty, text_[row], 0); --row; @@ -190,12 +195,12 @@ bool WearRecoveryUI::InitTextParams() { return false; } - text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_; + text_cols_ = (gr_fb_width() - (kMarginWidth * 2)) / char_width_; 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_; + visible_text_rows = (gr_fb_height() - (kMarginHeight * 2)) / char_height_; return true; } diff --git a/wear_ui.h b/wear_ui.h index a814118c7..c2bbdb66e 100644 --- a/wear_ui.h +++ b/wear_ui.h @@ -42,10 +42,7 @@ class WearRecoveryUI : public ScreenRecoveryUI { protected: // progress bar vertical position, it's centered horizontally - int progress_bar_y; - - // outer of window - int outer_height, outer_width; + const int kProgressBarBaseline; // 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. -- cgit v1.2.3 From f2be3bd74ac430a31ca4beb0db321d146283db2b Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 11 Aug 2017 13:50:24 -0700 Subject: wear_ui: Expose menu_unusable_rows via Makefile var. This variable is useful on small screens (e.g. on watches) to handle long menus. We should have better way to handle this value smartly. Prior to that, expose the value to be overridable by using the generic wearable UI module (librecovery_ui_wear). Bug: 64307776 Test: Define the variable, build and boot into recovery image and check the UI menu. Change-Id: I5d7a6baa8bb4cc852bfcc2a7b3cc9686c1c8817e (cherry picked from commit eea3af3f911d36ac1a82a9fb95d24912cc07e3b1) --- Android.mk | 6 ++++++ wear_ui.cpp | 7 ++++--- wear_ui.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Android.mk b/Android.mk index b1ee2440b..776e6ea19 100644 --- a/Android.mk +++ b/Android.mk @@ -131,6 +131,12 @@ else LOCAL_CFLAGS += -DRECOVERY_UI_ANIMATION_FPS=30 endif +ifneq ($(TARGET_RECOVERY_UI_MENU_UNUSABLE_ROWS),) +LOCAL_CFLAGS += -DRECOVERY_UI_MENU_UNUSABLE_ROWS=$(TARGET_RECOVERY_UI_MENU_UNUSABLE_ROWS) +else +LOCAL_CFLAGS += -DRECOVERY_UI_MENU_UNUSABLE_ROWS=9 +endif + ifneq ($(TARGET_RECOVERY_UI_VR_STEREO_OFFSET),) LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=$(TARGET_RECOVERY_UI_VR_STEREO_OFFSET) else diff --git a/wear_ui.cpp b/wear_ui.cpp index b8801a0b3..169ef20e1 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -51,8 +51,9 @@ static double now() { } WearRecoveryUI::WearRecoveryUI() - : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE), menu_unusable_rows(9) { - // TODO: menu_unusable_rows should be computed based on the lines in draw_screen_locked(). + : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE), + kMenuUnusableRows(RECOVERY_UI_MENU_UNUSABLE_ROWS) { + // TODO: kMenuUnusableRows should be computed based on the lines in draw_screen_locked(). // TODO: The following three variables are likely not needed. The first two are detected // automatically in ScreenRecoveryUI::LoadAnimation(), based on the actual files seen on device. @@ -268,7 +269,7 @@ void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* it show_menu = true; menu_sel = initial_selection; menu_start = 0; - menu_end = visible_text_rows - 1 - menu_unusable_rows; + menu_end = visible_text_rows - 1 - kMenuUnusableRows; if (menu_items <= menu_end) menu_end = menu_items; update_screen_locked(); } diff --git a/wear_ui.h b/wear_ui.h index c2bbdb66e..3bd90b699 100644 --- a/wear_ui.h +++ b/wear_ui.h @@ -46,7 +46,7 @@ class WearRecoveryUI : public ScreenRecoveryUI { // 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; + const int kMenuUnusableRows; int GetProgressBaseline() const override; -- cgit v1.2.3 From 20fa1a92cc53950a030281453e46015ecaec29bb Mon Sep 17 00:00:00 2001 From: Bill Yi Date: Tue, 15 Aug 2017 20:14:00 -0700 Subject: Import translations. DO NOT MERGE Auto-generated-cl: translation import Exempt-From-Owner-Approval: translation import Bug: 64712476 Change-Id: I7e9049129d9a886cac53a1f6438d9c733fb3d3d8 --- tools/recovery_l10n/res/values-en-rCA/strings.xml | 9 +++++++++ tools/recovery_l10n/res/values-mr/strings.xml | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tools/recovery_l10n/res/values-en-rCA/strings.xml diff --git a/tools/recovery_l10n/res/values-en-rCA/strings.xml b/tools/recovery_l10n/res/values-en-rCA/strings.xml new file mode 100644 index 000000000..dc75c2374 --- /dev/null +++ b/tools/recovery_l10n/res/values-en-rCA/strings.xml @@ -0,0 +1,9 @@ + + + "Installing system update" + "Erasing" + "No command" + "Error!" + "Installing security update" + diff --git a/tools/recovery_l10n/res/values-mr/strings.xml b/tools/recovery_l10n/res/values-mr/strings.xml index 8cf86f773..017a515c0 100644 --- a/tools/recovery_l10n/res/values-mr/strings.xml +++ b/tools/recovery_l10n/res/values-mr/strings.xml @@ -1,9 +1,9 @@ - "सिस्टम अद्यतन स्थापित करीत आहे" + "सिस्टम अपडेट इंस्टॉल करत आहे" "मिटवत आहे" "कोणताही आदेश नाही" "त्रुटी!" - "सुरक्षा अद्यतन स्थापित करीत आहे" + "सुरक्षा अपडेट इंस्टॉल करत आहे" -- cgit v1.2.3 From ee6fefd2f203a7df2164b3262fa54e62f61e6ad2 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Sun, 13 Aug 2017 23:48:55 -0700 Subject: screen_ui: Word-wrap menu headers. This CL adds ScreenRecoveryUI::DrawWrappedTextLines() to better handle long menu header texts. It does a word wrap at spaces, if available. This avoids fixed-length menu headers being truncated on small screens. Bug: 64293520 Test: On bullhead, boot into recovery with --prompt_and_wipe_data, and check the prompt texts. Change-Id: Ia22746583516dd230567a267584aca558429395e (cherry picked from commit 2bbc6d642d1fbfb007905d95b629fe5f833b2a1b) --- recovery.cpp | 9 +++++---- screen_ui.cpp | 30 +++++++++++++++++++++++++++++- screen_ui.h | 3 +++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/recovery.cpp b/recovery.cpp index 8f08c53f4..07bd7b9d4 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -758,12 +758,13 @@ static bool wipe_data(Device* device) { } static bool prompt_and_wipe_data(Device* device) { + // Use a single string and let ScreenRecoveryUI handles the wrapping. const char* const headers[] = { - "Can't load Android system. Your data may be corrupt.", - "If you continue to get this message, you may need to", - "perform a factory data reset and erase all user data", + "Can't load Android system. Your data may be corrupt. " + "If you continue to get this message, you may need to " + "perform a factory data reset and erase all user data " "stored on this device.", - NULL + nullptr }; const char* const items[] = { "Try again", diff --git a/screen_ui.cpp b/screen_ui.cpp index 8f792f162..e056512bd 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -278,6 +278,34 @@ int ScreenRecoveryUI::DrawTextLines(int x, int y, const char* const* lines) cons return offset; } +int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y, const char* const* lines) const { + int offset = 0; + for (size_t i = 0; lines != nullptr && lines[i] != nullptr; ++i) { + // The line will be wrapped if it exceeds text_cols_. + std::string line(lines[i]); + size_t next_start = 0; + while (next_start < line.size()) { + std::string sub = line.substr(next_start, text_cols_ + 1); + if (sub.size() <= text_cols_) { + next_start += sub.size(); + } else { + // Line too long and must be wrapped to text_cols_ columns. + size_t last_space = sub.find_last_of(" \t\n"); + if (last_space == std::string::npos) { + // No space found, just draw as much as we can + sub.resize(text_cols_); + next_start += text_cols_; + } else { + sub.resize(last_space); + next_start += last_space + 1; + } + } + offset += DrawTextLine(x, y + offset, sub.c_str(), false); + } + } + return offset; +} + static const char* REGULAR_HELP[] = { "Use volume up/down and power.", NULL @@ -316,7 +344,7 @@ void ScreenRecoveryUI::draw_screen_locked() { y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); SetColor(HEADER); - y += DrawTextLines(x, y, menu_headers_); + y += DrawWrappedTextLines(x, y, menu_headers_); SetColor(MENU); y += DrawHorizontalRule(y) + 4; diff --git a/screen_ui.h b/screen_ui.h index 8402fac00..df7cc25b3 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -187,6 +187,9 @@ class ScreenRecoveryUI : public RecoveryUI { 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; + // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines. + // Returns the offset it should be moving along Y-axis. + int DrawWrappedTextLines(int x, int y, const char* const* lines) const; }; #endif // RECOVERY_UI_H -- cgit v1.2.3 From 2cf6fe2ced4c117d132afd2c6e40fe0d937d0fca Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Wed, 16 Aug 2017 13:25:55 -0700 Subject: screen_ui: Fix a case that may truncate the last char. ScreenRecoveryUI::DrawWrappedTextLines() should be called with kMarginWidth only. Because it's using a line limit of text_cols_, which is unaware of kMenuIdent. Bug: 64293520 Test: No missing char with long header text. Change-Id: Ib4d08de2c56473a483ff9964eb6cec31f8a74c9a (cherry picked from commit 13aa4a902ba2fa304fc9fe826f797a4e0e2182b7) --- screen_ui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/screen_ui.cpp b/screen_ui.cpp index e056512bd..a02550199 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -344,7 +344,8 @@ void ScreenRecoveryUI::draw_screen_locked() { y += DrawTextLines(x, y, HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP); SetColor(HEADER); - y += DrawWrappedTextLines(x, y, menu_headers_); + // Ignore kMenuIndent, which is not taken into account by text_cols_. + y += DrawWrappedTextLines(kMarginWidth, y, menu_headers_); SetColor(MENU); y += DrawHorizontalRule(y) + 4; -- cgit v1.2.3 From c16d2225933f06f36391fda2997d5619407c230b Mon Sep 17 00:00:00 2001 From: Bill Yi Date: Tue, 29 Aug 2017 13:28:09 -0700 Subject: Import translations. DO NOT MERGE Auto-generated-cl: translation import Exempt-From-Owner-Approval: translation import Bug: 64712476 Change-Id: Ife1e0455a5433bc0cb0e15b0aabf2beef1ba8827 --- tools/recovery_l10n/res/values-hi/strings.xml | 2 +- tools/recovery_l10n/res/values-mr/strings.xml | 4 ++-- tools/recovery_l10n/res/values-te/strings.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/recovery_l10n/res/values-hi/strings.xml b/tools/recovery_l10n/res/values-hi/strings.xml index a8a876ee4..65d003352 100644 --- a/tools/recovery_l10n/res/values-hi/strings.xml +++ b/tools/recovery_l10n/res/values-hi/strings.xml @@ -3,7 +3,7 @@ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> "सिस्टम अपडेट इंस्टॉल किया जा रहा है" "मिटाया जा रहा है" - "कोई आदेश नहीं" + "कोई निर्देश नहीं मिला" "गड़बड़ी!" "सुरक्षा अपडेट इंस्टॉल किया जा रहा है" diff --git a/tools/recovery_l10n/res/values-mr/strings.xml b/tools/recovery_l10n/res/values-mr/strings.xml index 017a515c0..5f820336f 100644 --- a/tools/recovery_l10n/res/values-mr/strings.xml +++ b/tools/recovery_l10n/res/values-mr/strings.xml @@ -3,7 +3,7 @@ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> "सिस्टम अपडेट इंस्टॉल करत आहे" "मिटवत आहे" - "कोणताही आदेश नाही" - "त्रुटी!" + "कोणतीही कमांड नाही" + "एरर!" "सुरक्षा अपडेट इंस्टॉल करत आहे" diff --git a/tools/recovery_l10n/res/values-te/strings.xml b/tools/recovery_l10n/res/values-te/strings.xml index cfb02c915..e35c82bc4 100644 --- a/tools/recovery_l10n/res/values-te/strings.xml +++ b/tools/recovery_l10n/res/values-te/strings.xml @@ -4,6 +4,6 @@ "సిస్టమ్ నవీకరణను ఇన్‍స్టాల్ చేస్తోంది" "డేటాను తొలగిస్తోంది" "ఆదేశం లేదు" - "లోపం సంభవించింది!" + "ఎర్రర్ సంభవించింది!" "భద్రతా నవీకరణను ఇన్‌స్టాల్ చేస్తోంది" -- cgit v1.2.3 From 17fa5c7cab503015bde05fbe0455f8a6a3344396 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 7 Sep 2017 13:38:51 -0700 Subject: ui: Manage menu_ with std::vector. Prior to this CL, menu_ is allocated with a fixed length of text_rows_. However, because we support scrollable menu in wear_ui, there might be more menu entries than text_rows_, which would lead to out-of-bounds array access. This CL addresses the issue by switching to std::vector. Bug: 65416558 Test: Run 'View recovery logs' on angler. Test: Set large margin height that leaves text_rows less than 21. Then run 'View recovery logs' with 21 menu entries. Change-Id: I5d4e3a0a097039e1104eda7d494c6269053dc894 (cherry picked from commit e15d7a5104978cd8399501636aec0df9c1a4823c) --- screen_ui.cpp | 16 +++++++--------- screen_ui.h | 3 ++- wear_ui.cpp | 13 ++++++------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/screen_ui.cpp b/screen_ui.cpp index 5c93b6672..b8f6ea28b 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -69,7 +69,7 @@ ScreenRecoveryUI::ScreenRecoveryUI() text_top_(0), show_text(false), show_text_ever(false), - menu_(nullptr), + menu_headers_(nullptr), show_menu(false), menu_items(0), menu_sel(0), @@ -356,10 +356,10 @@ void ScreenRecoveryUI::draw_screen_locked() { DrawHighlightBar(0, y - 2, gr_fb_width(), char_height_ + 4); // Bold white text for the selected item. SetColor(MENU_SEL_FG); - y += DrawTextLine(x, y, menu_[i], true); + y += DrawTextLine(x, y, menu_[i].c_str(), true); SetColor(MENU); } else { - y += DrawTextLine(x, y, menu_[i], false); + y += DrawTextLine(x, y, menu_[i].c_str(), false); } } y += DrawHorizontalRule(y); @@ -508,7 +508,6 @@ bool ScreenRecoveryUI::Init(const std::string& locale) { text_ = Alloc2d(text_rows_, text_cols_ + 1); file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1); - menu_ = Alloc2d(text_rows_, text_cols_ + 1); text_col_ = text_row_ = 0; text_top_ = 1; @@ -771,12 +770,11 @@ void ScreenRecoveryUI::StartMenu(const char* const* headers, const char* const* 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_.clear(); + for (size_t i = 0; i < text_rows_ && items[i] != nullptr; ++i) { + menu_.emplace_back(std::string(items[i], strnlen(items[i], text_cols_ - 1))); } - menu_items = i; + menu_items = static_cast(menu_.size()); show_menu = true; menu_sel = initial_selection; update_screen_locked(); diff --git a/screen_ui.h b/screen_ui.h index 62dda7558..8231a2ba0 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -21,6 +21,7 @@ #include #include +#include #include "ui.h" @@ -127,7 +128,7 @@ class ScreenRecoveryUI : public RecoveryUI { bool show_text; bool show_text_ever; // has show_text ever been true? - char** menu_; + std::vector menu_; const char* const* menu_headers_; bool show_menu; int menu_items, menu_sel; diff --git a/wear_ui.cpp b/wear_ui.cpp index 169ef20e1..624116c0c 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -154,11 +154,11 @@ void WearRecoveryUI::draw_screen_locked() { // white text of selected item SetColor(MENU_SEL_FG); if (menu_[i][0]) { - gr_text(gr_sys_font(), x + 4, y, menu_[i], 1); + gr_text(gr_sys_font(), x + 4, y, menu_[i].c_str(), 1); } SetColor(MENU); } else if (menu_[i][0]) { - gr_text(gr_sys_font(), x + 4, y, menu_[i], 0); + gr_text(gr_sys_font(), x + 4, y, menu_[i].c_str(), 0); } y += char_height_ + 4; } @@ -255,17 +255,16 @@ void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* it pthread_mutex_lock(&updateMutex); if (text_rows_ > 0 && text_cols_ > 0) { menu_headers_ = headers; - size_t i = 0; + menu_.clear(); // "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'; + for (size_t i = 0; items[i] != nullptr; i++) { + menu_.emplace_back(std::string(items[i], strnlen(items[i], text_cols_ - 1))); } - menu_items = i; + menu_items = static_cast(menu_.size()); show_menu = true; menu_sel = initial_selection; menu_start = 0; -- cgit v1.2.3 From c9b04168426f55d74a3de0bdb851307ea511a315 Mon Sep 17 00:00:00 2001 From: Bill Yi Date: Sat, 16 Sep 2017 05:39:19 -0700 Subject: Import translations. DO NOT MERGE Auto-generated-cl: translation import Exempt-From-Owner-Approval: translation import Bug: 64712476 Change-Id: Ia05d14ff5b7f6b283f46566c88a4edc4a89d5576 --- tools/recovery_l10n/res/values-pa/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/recovery_l10n/res/values-pa/strings.xml b/tools/recovery_l10n/res/values-pa/strings.xml index 8564c9c36..27972d117 100644 --- a/tools/recovery_l10n/res/values-pa/strings.xml +++ b/tools/recovery_l10n/res/values-pa/strings.xml @@ -1,9 +1,9 @@ - "ਸਿਸਟਮ ਅੱਪਡੇਟ ਸਥਾਪਤ ਕੀਤੀ ਜਾ ਰਹੀ ਹੈ" + "ਸਿਸਟਮ ਅੱਪਡੇਟ ਸਥਾਪਤ ਕੀਤਾ ਜਾ ਰਿਹਾ ਹੈ" "ਮਿਟਾਈ ਜਾ ਰਹੀ ਹੈ" - "ਕੋਈ ਕਮਾਂਡ ਨਹੀਂ" + "ਕੋਈ ਆਦੇਸ਼ ਨਹੀਂ" "ਅਸ਼ੁੱਧੀ!" - "ਸੁਰੱਖਿਆ ਅੱਪਡੇਟ ਸਥਾਪਤ ਕੀਤੀ ਜਾ ਰਹੀ ਹੈ" + "ਸੁਰੱਖਿਆ ਅੱਪਡੇਟ ਸਥਾਪਤ ਕੀਤਾ ਜਾ ਰਿਹਾ ਹੈ" -- cgit v1.2.3