2009-03-04 04:28:42 +01:00
|
|
|
/*
|
2011-10-29 00:13:10 +02:00
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
2009-03-04 04:28:42 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-08-20 22:40:47 +02:00
|
|
|
#include "recovery_ui/screen_ui.h"
|
2017-02-01 08:03:10 +01:00
|
|
|
|
2016-04-15 01:49:04 +02:00
|
|
|
#include <dirent.h>
|
2011-03-08 21:25:05 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2009-03-04 04:28:42 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-03-08 21:25:05 +01:00
|
|
|
#include <sys/stat.h>
|
2009-03-04 04:28:42 +01:00
|
|
|
#include <sys/time.h>
|
2011-03-08 21:25:05 +01:00
|
|
|
#include <sys/types.h>
|
2009-03-04 04:28:42 +01:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-05-02 00:56:05 +02:00
|
|
|
#include <algorithm>
|
2018-05-10 01:32:02 +02:00
|
|
|
#include <chrono>
|
2017-09-21 02:53:46 +02:00
|
|
|
#include <memory>
|
2017-01-03 19:15:33 +01:00
|
|
|
#include <string>
|
2018-05-10 01:32:02 +02:00
|
|
|
#include <thread>
|
2017-09-21 02:53:46 +02:00
|
|
|
#include <unordered_map>
|
2015-04-11 04:12:01 +02:00
|
|
|
#include <vector>
|
|
|
|
|
recovery: fastbootd: retry opening graphics
Recovery and fastbootd hardening.
With GKI we find in certain situations the timing of the drivers
loading is delayed as compared to a monolithic kernel. This
exasperates an existing race where during second stage init, the
graphics driver might not have completely instantiated by the time
fastboot or recovery menu ui is being set up.
To address this, we call gr_init() every 10ms until either 5 seconds
timeout or success. If we timeout, there will be no TUI (minui), but
this is better than if we just tried once and dropped the TUI and was
effectively running headless. 5 seconds timeout is arbitrary, based
on the default in init for wait for file; but makes sense as any
longer will impact flashstation and fastboot flashall enough to be
a cause for consternation.
It should be noted that both recovery and fastbootd can still service
adb or fastboot gadgets headless. For instance if the device tree is
misconfigured as a permanent issue that would head for the timeout.
Prefering to give up after a timeout so that device can be flashed by
fastbootd, or rebooted by recovery adbd, over the protocol is
advantageous for tool stability.
Architectural Concern:
The graphics driver, if not well written, may panic the kernel if we
try to access it too soon while it is probing. On such devices it
will be necessary to hold off in 'on init' or 'on early-init' phases
until the graphics drivers have completely probed. Or better yet,
fix the driver. This problem would happen in any case occasionally
even without this adjustments, but could conceivably be amplified by
the loop trying to open the graphics device.
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 151950334
Test: make sure user space fastbootd comes up reliably for a GKI kernel
Change-Id: I1ce31a01544a58cdf7b9d657c1146bee77894e46
2020-05-13 21:39:12 +02:00
|
|
|
#include <android-base/chrono_utils.h>
|
2016-08-06 03:00:04 +02:00
|
|
|
#include <android-base/logging.h>
|
2016-09-24 00:30:55 +02:00
|
|
|
#include <android-base/properties.h>
|
2015-12-05 00:30:20 +01:00
|
|
|
#include <android-base/stringprintf.h>
|
2017-09-09 06:25:32 +02:00
|
|
|
#include <android-base/strings.h>
|
2015-05-20 02:02:16 +02:00
|
|
|
|
2018-05-04 06:53:11 +02:00
|
|
|
#include "minui/minui.h"
|
|
|
|
#include "otautil/paths.h"
|
2018-08-20 22:40:47 +02:00
|
|
|
#include "recovery_ui/device.h"
|
|
|
|
#include "recovery_ui/ui.h"
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2022-02-11 09:39:53 +01:00
|
|
|
enum DirectRenderManager {
|
|
|
|
DRM_INNER,
|
|
|
|
DRM_OUTER,
|
|
|
|
};
|
|
|
|
|
2011-03-01 23:04:34 +01:00
|
|
|
// Return the current time as a double (including fractions of a second).
|
|
|
|
static double now() {
|
2017-06-24 07:23:50 +02:00
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, nullptr);
|
|
|
|
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
2011-03-01 23:04:34 +01:00
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
Menu::Menu(size_t initial_selection, const DrawInterface& draw_func)
|
|
|
|
: selection_(initial_selection), draw_funcs_(draw_func) {}
|
|
|
|
|
|
|
|
size_t Menu::selection() const {
|
|
|
|
return selection_;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextMenu::TextMenu(bool scrollable, size_t max_items, size_t max_length,
|
|
|
|
const std::vector<std::string>& headers, const std::vector<std::string>& items,
|
|
|
|
size_t initial_selection, int char_height, const DrawInterface& draw_funcs)
|
|
|
|
: Menu(initial_selection, draw_funcs),
|
|
|
|
scrollable_(scrollable),
|
2018-03-21 00:07:39 +01:00
|
|
|
max_display_items_(max_items),
|
|
|
|
max_item_length_(max_length),
|
2018-05-03 00:46:11 +02:00
|
|
|
text_headers_(headers),
|
2018-03-21 00:07:39 +01:00
|
|
|
menu_start_(0),
|
2018-10-12 01:54:50 +02:00
|
|
|
char_height_(char_height) {
|
2018-03-21 00:07:39 +01:00
|
|
|
CHECK_LE(max_items, static_cast<size_t>(std::numeric_limits<int>::max()));
|
2018-05-03 00:46:11 +02:00
|
|
|
|
|
|
|
// It's fine to have more entries than text_rows_ if scrollable menu is supported.
|
2018-05-02 00:56:05 +02:00
|
|
|
size_t items_count = scrollable_ ? items.size() : std::min(items.size(), max_display_items_);
|
|
|
|
for (size_t i = 0; i < items_count; ++i) {
|
|
|
|
text_items_.emplace_back(items[i].substr(0, max_item_length_));
|
2018-05-03 00:46:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(!text_items_.empty());
|
2018-03-21 00:07:39 +01:00
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
const std::vector<std::string>& TextMenu::text_headers() const {
|
2018-03-21 00:07:39 +01:00
|
|
|
return text_headers_;
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
std::string TextMenu::TextItem(size_t index) const {
|
2018-03-21 00:07:39 +01:00
|
|
|
CHECK_LT(index, text_items_.size());
|
|
|
|
|
|
|
|
return text_items_[index];
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
size_t TextMenu::MenuStart() const {
|
2018-03-21 00:07:39 +01:00
|
|
|
return menu_start_;
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
size_t TextMenu::MenuEnd() const {
|
2018-03-21 00:07:39 +01:00
|
|
|
return std::min(ItemsCount(), menu_start_ + max_display_items_);
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
size_t TextMenu::ItemsCount() const {
|
2018-03-21 00:07:39 +01:00
|
|
|
return text_items_.size();
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
bool TextMenu::ItemsOverflow(std::string* cur_selection_str) const {
|
2018-05-03 00:46:11 +02:00
|
|
|
if (!scrollable_ || ItemsCount() <= max_display_items_) {
|
2018-03-21 00:07:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cur_selection_str =
|
2018-05-02 00:56:05 +02:00
|
|
|
android::base::StringPrintf("Current item: %zu/%zu", selection_ + 1, ItemsCount());
|
2018-03-21 00:07:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(xunchang) modify the function parameters to button up & down.
|
2018-10-12 01:54:50 +02:00
|
|
|
int TextMenu::Select(int sel) {
|
2018-03-21 00:07:39 +01:00
|
|
|
CHECK_LE(ItemsCount(), static_cast<size_t>(std::numeric_limits<int>::max()));
|
|
|
|
int count = ItemsCount();
|
|
|
|
|
|
|
|
// Wraps the selection at boundary if the menu is not scrollable.
|
|
|
|
if (!scrollable_) {
|
|
|
|
if (sel < 0) {
|
|
|
|
selection_ = count - 1;
|
|
|
|
} else if (sel >= count) {
|
|
|
|
selection_ = 0;
|
|
|
|
} else {
|
|
|
|
selection_ = sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selection_;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sel < 0) {
|
|
|
|
selection_ = 0;
|
|
|
|
} else if (sel >= count) {
|
|
|
|
selection_ = count - 1;
|
|
|
|
} else {
|
|
|
|
if (static_cast<size_t>(sel) < menu_start_) {
|
|
|
|
menu_start_--;
|
|
|
|
} else if (static_cast<size_t>(sel) >= MenuEnd()) {
|
|
|
|
menu_start_++;
|
|
|
|
}
|
|
|
|
selection_ = sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selection_;
|
|
|
|
}
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
int TextMenu::DrawHeader(int x, int y) const {
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
draw_funcs_.SetColor(UIElement::HEADER);
|
|
|
|
if (!scrollable()) {
|
|
|
|
offset += draw_funcs_.DrawWrappedTextLines(x, y + offset, text_headers());
|
|
|
|
} else {
|
|
|
|
offset += draw_funcs_.DrawTextLines(x, y + offset, text_headers());
|
|
|
|
// Show the current menu item number in relation to total number if items don't fit on the
|
|
|
|
// screen.
|
|
|
|
std::string cur_selection_str;
|
|
|
|
if (ItemsOverflow(&cur_selection_str)) {
|
|
|
|
offset += draw_funcs_.DrawTextLine(x, y + offset, cur_selection_str, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TextMenu::DrawItems(int x, int y, int screen_width, bool long_press) const {
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
draw_funcs_.SetColor(UIElement::MENU);
|
|
|
|
// Do not draw the horizontal rule for wear devices.
|
|
|
|
if (!scrollable()) {
|
|
|
|
offset += draw_funcs_.DrawHorizontalRule(y + offset) + 4;
|
|
|
|
}
|
2023-10-07 12:14:39 +02:00
|
|
|
|
|
|
|
int items_block_height = gr_fb_height() - y - offset;;
|
|
|
|
int total = (char_height_ + 4) * (selection() + 1);;
|
|
|
|
int j = 0;
|
|
|
|
if (total > items_block_height) {
|
|
|
|
j = ((total - items_block_height) / (char_height_ + 4)) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = (MenuStart() + j); i < MenuEnd(); ++i) {
|
2018-10-12 01:54:50 +02:00
|
|
|
bool bold = false;
|
|
|
|
if (i == selection()) {
|
|
|
|
// Draw the highlight bar.
|
|
|
|
draw_funcs_.SetColor(long_press ? UIElement::MENU_SEL_BG_ACTIVE : UIElement::MENU_SEL_BG);
|
|
|
|
|
|
|
|
int bar_height = char_height_ + 4;
|
|
|
|
draw_funcs_.DrawHighlightBar(0, y + offset - 2, screen_width, bar_height);
|
|
|
|
|
|
|
|
// Bold white text for the selected item.
|
|
|
|
draw_funcs_.SetColor(UIElement::MENU_SEL_FG);
|
|
|
|
bold = true;
|
|
|
|
}
|
|
|
|
offset += draw_funcs_.DrawTextLine(x, y + offset, TextItem(i), bold);
|
|
|
|
|
|
|
|
draw_funcs_.SetColor(UIElement::MENU);
|
|
|
|
}
|
|
|
|
offset += draw_funcs_.DrawHorizontalRule(y + offset);
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
GraphicMenu::GraphicMenu(const GRSurface* graphic_headers,
|
|
|
|
const std::vector<const GRSurface*>& graphic_items,
|
2018-10-17 00:13:09 +02:00
|
|
|
size_t initial_selection, const DrawInterface& draw_funcs)
|
2018-10-22 08:36:26 +02:00
|
|
|
: Menu(initial_selection, draw_funcs) {
|
|
|
|
graphic_headers_ = graphic_headers->Clone();
|
|
|
|
graphic_items_.reserve(graphic_items.size());
|
|
|
|
for (const auto& item : graphic_items) {
|
|
|
|
graphic_items_.emplace_back(item->Clone());
|
|
|
|
}
|
|
|
|
}
|
2018-10-12 01:54:50 +02:00
|
|
|
|
|
|
|
int GraphicMenu::Select(int sel) {
|
|
|
|
CHECK_LE(graphic_items_.size(), static_cast<size_t>(std::numeric_limits<int>::max()));
|
|
|
|
int count = graphic_items_.size();
|
|
|
|
|
|
|
|
// Wraps the selection at boundary if the menu is not scrollable.
|
|
|
|
if (sel < 0) {
|
|
|
|
selection_ = count - 1;
|
|
|
|
} else if (sel >= count) {
|
|
|
|
selection_ = 0;
|
|
|
|
} else {
|
|
|
|
selection_ = sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selection_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GraphicMenu::DrawHeader(int x, int y) const {
|
2018-10-17 00:13:09 +02:00
|
|
|
draw_funcs_.SetColor(UIElement::HEADER);
|
2018-10-22 08:36:26 +02:00
|
|
|
draw_funcs_.DrawTextIcon(x, y, graphic_headers_.get());
|
2018-10-12 01:54:50 +02:00
|
|
|
return graphic_headers_->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GraphicMenu::DrawItems(int x, int y, int screen_width, bool long_press) const {
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
draw_funcs_.SetColor(UIElement::MENU);
|
|
|
|
offset += draw_funcs_.DrawHorizontalRule(y + offset) + 4;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < graphic_items_.size(); i++) {
|
|
|
|
auto& item = graphic_items_[i];
|
|
|
|
if (i == selection_) {
|
|
|
|
draw_funcs_.SetColor(long_press ? UIElement::MENU_SEL_BG_ACTIVE : UIElement::MENU_SEL_BG);
|
|
|
|
|
|
|
|
int bar_height = item->height + 4;
|
|
|
|
draw_funcs_.DrawHighlightBar(0, y + offset - 2, screen_width, bar_height);
|
|
|
|
|
|
|
|
// Bold white text for the selected item.
|
|
|
|
draw_funcs_.SetColor(UIElement::MENU_SEL_FG);
|
|
|
|
}
|
2018-10-22 08:36:26 +02:00
|
|
|
draw_funcs_.DrawTextIcon(x, y + offset, item.get());
|
2018-10-12 01:54:50 +02:00
|
|
|
offset += item->height;
|
|
|
|
|
|
|
|
draw_funcs_.SetColor(UIElement::MENU);
|
|
|
|
}
|
2018-12-20 20:31:18 +01:00
|
|
|
offset += draw_funcs_.DrawHorizontalRule(y + offset);
|
2018-10-12 01:54:50 +02:00
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
bool GraphicMenu::Validate(size_t max_width, size_t max_height, const GRSurface* graphic_headers,
|
|
|
|
const std::vector<const GRSurface*>& graphic_items) {
|
2018-10-12 01:54:50 +02:00
|
|
|
int offset = 0;
|
2018-10-17 00:13:09 +02:00
|
|
|
if (!ValidateGraphicSurface(max_width, max_height, offset, graphic_headers)) {
|
2018-10-12 01:54:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-17 00:13:09 +02:00
|
|
|
offset += graphic_headers->height;
|
2018-10-12 01:54:50 +02:00
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
for (const auto& item : graphic_items) {
|
|
|
|
if (!ValidateGraphicSurface(max_width, max_height, offset, item)) {
|
2018-10-12 01:54:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
offset += item->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
bool GraphicMenu::ValidateGraphicSurface(size_t max_width, size_t max_height, int y,
|
|
|
|
const GRSurface* surface) {
|
2018-10-12 01:54:50 +02:00
|
|
|
if (!surface) {
|
2019-01-16 18:29:47 +01:00
|
|
|
fprintf(stderr, "Graphic surface can not be null\n");
|
2018-10-12 01:54:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface->pixel_bytes != 1 || surface->width != surface->row_bytes) {
|
2019-01-16 18:29:47 +01:00
|
|
|
fprintf(stderr, "Invalid graphic surface, pixel bytes: %zu, width: %zu row_bytes: %zu\n",
|
2018-10-12 01:54:50 +02:00
|
|
|
surface->pixel_bytes, surface->width, surface->row_bytes);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
if (surface->width > max_width || surface->height > max_height - y) {
|
2018-10-12 01:54:50 +02:00
|
|
|
fprintf(stderr,
|
2018-11-27 01:28:07 +01:00
|
|
|
"Graphic surface doesn't fit into the screen. width: %zu, height: %zu, max_width: %zu,"
|
2018-10-12 01:54:50 +02:00
|
|
|
" max_height: %zu, vertical offset: %d\n",
|
2018-10-17 00:13:09 +02:00
|
|
|
surface->width, surface->height, max_width, max_height, y);
|
2018-10-12 01:54:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:07:39 +01:00
|
|
|
ScreenRecoveryUI::ScreenRecoveryUI() : ScreenRecoveryUI(false) {}
|
|
|
|
|
2018-07-31 23:53:16 +02:00
|
|
|
constexpr int kDefaultMarginHeight = 0;
|
|
|
|
constexpr int kDefaultMarginWidth = 0;
|
|
|
|
constexpr int kDefaultAnimationFps = 30;
|
|
|
|
|
2018-03-21 00:07:39 +01:00
|
|
|
ScreenRecoveryUI::ScreenRecoveryUI(bool scrollable_menu)
|
2018-07-31 23:53:16 +02:00
|
|
|
: margin_width_(
|
|
|
|
android::base::GetIntProperty("ro.recovery.ui.margin_width", kDefaultMarginWidth)),
|
|
|
|
margin_height_(
|
|
|
|
android::base::GetIntProperty("ro.recovery.ui.margin_height", kDefaultMarginHeight)),
|
|
|
|
animation_fps_(
|
|
|
|
android::base::GetIntProperty("ro.recovery.ui.animation_fps", kDefaultAnimationFps)),
|
|
|
|
density_(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f),
|
2018-10-22 08:36:26 +02:00
|
|
|
current_icon_(NONE),
|
|
|
|
current_frame_(0),
|
|
|
|
intro_done_(false),
|
2017-01-03 19:15:33 +01:00
|
|
|
progressBarType(EMPTY),
|
|
|
|
progressScopeStart(0),
|
|
|
|
progressScopeSize(0),
|
|
|
|
progress(0),
|
|
|
|
pagesIdentical(false),
|
|
|
|
text_cols_(0),
|
|
|
|
text_rows_(0),
|
|
|
|
text_(nullptr),
|
|
|
|
text_col_(0),
|
|
|
|
text_row_(0),
|
|
|
|
show_text(false),
|
|
|
|
show_text_ever(false),
|
2018-03-21 00:07:39 +01:00
|
|
|
scrollable_menu_(scrollable_menu),
|
2017-01-03 19:15:33 +01:00
|
|
|
file_viewer_text_(nullptr),
|
|
|
|
stage(-1),
|
|
|
|
max_stage(-1),
|
2017-02-01 08:03:10 +01:00
|
|
|
locale_(""),
|
2022-02-11 09:39:53 +01:00
|
|
|
rtl_locale_(false),
|
|
|
|
is_graphics_available(false) {}
|
2011-10-29 00:13:10 +02:00
|
|
|
|
2018-05-10 01:32:02 +02:00
|
|
|
ScreenRecoveryUI::~ScreenRecoveryUI() {
|
|
|
|
progress_thread_stopped_ = true;
|
2018-06-06 16:38:54 +02:00
|
|
|
if (progress_thread_.joinable()) {
|
|
|
|
progress_thread_.join();
|
|
|
|
}
|
2018-06-13 23:33:51 +02:00
|
|
|
// No-op if gr_init() (via Init()) was not called or had failed.
|
|
|
|
gr_exit();
|
2018-05-10 01:32:02 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
const GRSurface* ScreenRecoveryUI::GetCurrentFrame() const {
|
|
|
|
if (current_icon_ == INSTALLING_UPDATE || current_icon_ == ERASING) {
|
|
|
|
return intro_done_ ? loop_frames_[current_frame_].get() : intro_frames_[current_frame_].get();
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2018-10-22 08:36:26 +02:00
|
|
|
return error_icon_.get();
|
2016-04-15 01:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
const GRSurface* ScreenRecoveryUI::GetCurrentText() const {
|
|
|
|
switch (current_icon_) {
|
2017-06-24 07:23:50 +02:00
|
|
|
case ERASING:
|
2018-10-22 08:36:26 +02:00
|
|
|
return erasing_text_.get();
|
2017-06-24 07:23:50 +02:00
|
|
|
case ERROR:
|
2018-10-22 08:36:26 +02:00
|
|
|
return error_text_.get();
|
2017-06-24 07:23:50 +02:00
|
|
|
case INSTALLING_UPDATE:
|
2018-10-22 08:36:26 +02:00
|
|
|
return installing_text_.get();
|
2017-06-24 07:23:50 +02:00
|
|
|
case NO_COMMAND:
|
2018-10-22 08:36:26 +02:00
|
|
|
return no_command_text_.get();
|
2017-06-24 07:23:50 +02:00
|
|
|
case NONE:
|
|
|
|
abort();
|
|
|
|
}
|
2016-04-15 01:49:04 +02:00
|
|
|
}
|
|
|
|
|
2017-03-23 21:44:26 +01:00
|
|
|
int ScreenRecoveryUI::PixelsFromDp(int dp) const {
|
2018-07-31 23:53:16 +02:00
|
|
|
return dp * density_;
|
2016-04-21 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Here's the intended layout:
|
|
|
|
|
2016-07-09 02:23:41 +02:00
|
|
|
// | portrait large landscape large
|
|
|
|
// ---------+-------------------------------------------------
|
2017-06-29 23:32:05 +02:00
|
|
|
// gap |
|
2016-07-09 02:23:41 +02:00
|
|
|
// icon | (200dp)
|
|
|
|
// gap | 68dp 68dp 56dp 112dp
|
|
|
|
// text | (14sp)
|
|
|
|
// gap | 32dp 32dp 26dp 52dp
|
|
|
|
// progress | (2dp)
|
2017-06-29 23:32:05 +02:00
|
|
|
// gap |
|
2016-04-21 02:22:16 +02:00
|
|
|
|
2017-06-29 23:32:05 +02:00
|
|
|
// Note that "baseline" is actually the *top* of each icon (because that's how our drawing routines
|
|
|
|
// work), so that's the more useful measurement for calling code. We use even top and bottom gaps.
|
2016-04-21 02:22:16 +02:00
|
|
|
|
2016-07-09 02:23:41 +02:00
|
|
|
enum Layout { PORTRAIT = 0, PORTRAIT_LARGE = 1, LANDSCAPE = 2, LANDSCAPE_LARGE = 3, LAYOUT_MAX };
|
2017-06-29 23:32:05 +02:00
|
|
|
enum Dimension { TEXT = 0, ICON = 1, DIMENSION_MAX };
|
2016-07-09 02:23:41 +02:00
|
|
|
static constexpr int kLayouts[LAYOUT_MAX][DIMENSION_MAX] = {
|
2018-08-20 22:40:47 +02:00
|
|
|
{ 32, 68 }, // PORTRAIT
|
|
|
|
{ 32, 68 }, // PORTRAIT_LARGE
|
|
|
|
{ 26, 56 }, // LANDSCAPE
|
|
|
|
{ 52, 112 }, // LANDSCAPE_LARGE
|
2016-07-09 02:23:41 +02:00
|
|
|
};
|
|
|
|
|
2017-06-24 07:47:03 +02:00
|
|
|
int ScreenRecoveryUI::GetAnimationBaseline() const {
|
2018-10-22 08:36:26 +02:00
|
|
|
return GetTextBaseline() - PixelsFromDp(kLayouts[layout_][ICON]) -
|
|
|
|
gr_get_height(loop_frames_[0].get());
|
2016-04-21 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 07:47:03 +02:00
|
|
|
int ScreenRecoveryUI::GetTextBaseline() const {
|
2017-06-24 07:23:50 +02:00
|
|
|
return GetProgressBaseline() - PixelsFromDp(kLayouts[layout_][TEXT]) -
|
2018-10-22 08:36:26 +02:00
|
|
|
gr_get_height(installing_text_.get());
|
2016-04-21 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 07:47:03 +02:00
|
|
|
int ScreenRecoveryUI::GetProgressBaseline() const {
|
2018-10-22 08:36:26 +02:00
|
|
|
int elements_sum = gr_get_height(loop_frames_[0].get()) + PixelsFromDp(kLayouts[layout_][ICON]) +
|
|
|
|
gr_get_height(installing_text_.get()) + PixelsFromDp(kLayouts[layout_][TEXT]) +
|
|
|
|
gr_get_height(progress_bar_fill_.get());
|
2017-09-19 19:51:35 +02:00
|
|
|
int bottom_gap = (ScreenHeight() - elements_sum) / 2;
|
2018-10-22 08:36:26 +02:00
|
|
|
return ScreenHeight() - bottom_gap - gr_get_height(progress_bar_fill_.get());
|
2016-04-21 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2009-03-04 04:28:42 +01:00
|
|
|
// Clear the screen and draw the currently selected background icon (if any).
|
2011-10-29 00:13:10 +02:00
|
|
|
// Should only be called with updateMutex locked.
|
2016-04-15 01:49:04 +02:00
|
|
|
void ScreenRecoveryUI::draw_background_locked() {
|
2017-06-24 07:23:50 +02:00
|
|
|
pagesIdentical = false;
|
|
|
|
gr_color(0, 0, 0, 255);
|
|
|
|
gr_clear();
|
2018-10-22 08:36:26 +02:00
|
|
|
if (current_icon_ != NONE) {
|
2017-06-24 07:23:50 +02:00
|
|
|
if (max_stage != -1) {
|
2018-10-22 08:36:26 +02:00
|
|
|
int stage_height = gr_get_height(stage_marker_empty_.get());
|
|
|
|
int stage_width = gr_get_width(stage_marker_empty_.get());
|
|
|
|
int x = (ScreenWidth() - max_stage * gr_get_width(stage_marker_empty_.get())) / 2;
|
2018-07-31 23:53:16 +02:00
|
|
|
int y = ScreenHeight() - stage_height - margin_height_;
|
2017-06-24 07:23:50 +02:00
|
|
|
for (int i = 0; i < max_stage; ++i) {
|
2018-10-22 08:36:26 +02:00
|
|
|
const auto& stage_surface = (i < stage) ? stage_marker_fill_ : stage_marker_empty_;
|
|
|
|
DrawSurface(stage_surface.get(), 0, 0, stage_width, stage_height, x, y);
|
2017-06-24 07:23:50 +02:00
|
|
|
x += stage_width;
|
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
const auto& text_surface = GetCurrentText();
|
2017-09-19 19:51:35 +02:00
|
|
|
int text_x = (ScreenWidth() - gr_get_width(text_surface)) / 2;
|
2017-06-24 07:23:50 +02:00
|
|
|
int text_y = GetTextBaseline();
|
|
|
|
gr_color(255, 255, 255, 255);
|
2017-09-19 19:51:35 +02:00
|
|
|
DrawTextIcon(text_x, text_y, text_surface);
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2017-06-28 23:52:17 +02:00
|
|
|
// Draws the animation and progress bar (if any) on the screen. Does not flip pages. Should only be
|
|
|
|
// called with updateMutex locked.
|
2016-04-21 02:22:16 +02:00
|
|
|
void ScreenRecoveryUI::draw_foreground_locked() {
|
2018-10-22 08:36:26 +02:00
|
|
|
if (current_icon_ != NONE) {
|
|
|
|
const auto& frame = GetCurrentFrame();
|
2017-01-03 19:15:33 +01:00
|
|
|
int frame_width = gr_get_width(frame);
|
|
|
|
int frame_height = gr_get_height(frame);
|
2017-09-19 19:51:35 +02:00
|
|
|
int frame_x = (ScreenWidth() - frame_width) / 2;
|
2017-01-03 19:15:33 +01:00
|
|
|
int frame_y = GetAnimationBaseline();
|
2019-08-07 10:21:10 +02:00
|
|
|
if (frame_x >= 0 && frame_y >= 0 && (frame_x + frame_width) < ScreenWidth() &&
|
|
|
|
(frame_y + frame_height) < ScreenHeight())
|
|
|
|
DrawSurface(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
|
2017-01-03 19:15:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (progressBarType != EMPTY) {
|
2018-10-22 08:36:26 +02:00
|
|
|
int width = gr_get_width(progress_bar_empty_.get());
|
|
|
|
int height = gr_get_height(progress_bar_empty_.get());
|
2017-01-03 19:15:33 +01:00
|
|
|
|
2017-09-19 19:51:35 +02:00
|
|
|
int progress_x = (ScreenWidth() - width) / 2;
|
2017-01-03 19:15:33 +01:00
|
|
|
int progress_y = GetProgressBaseline();
|
|
|
|
|
|
|
|
// Erase behind the progress bar (in case this was a progress-only update)
|
|
|
|
gr_color(0, 0, 0, 255);
|
2017-09-19 19:51:35 +02:00
|
|
|
DrawFill(progress_x, progress_y, width, height);
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
if (progressBarType == DETERMINATE) {
|
|
|
|
float p = progressScopeStart + progress * progressScopeSize;
|
|
|
|
int pos = static_cast<int>(p * width);
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
if (rtl_locale_) {
|
|
|
|
// Fill the progress bar from right to left.
|
|
|
|
if (pos > 0) {
|
2018-10-22 08:36:26 +02:00
|
|
|
DrawSurface(progress_bar_fill_.get(), width - pos, 0, pos, height,
|
|
|
|
progress_x + width - pos, progress_y);
|
2017-01-03 19:15:33 +01:00
|
|
|
}
|
|
|
|
if (pos < width - 1) {
|
2018-10-22 08:36:26 +02:00
|
|
|
DrawSurface(progress_bar_empty_.get(), 0, 0, width - pos, height, progress_x, progress_y);
|
2017-01-03 19:15:33 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Fill the progress bar from left to right.
|
|
|
|
if (pos > 0) {
|
2018-10-22 08:36:26 +02:00
|
|
|
DrawSurface(progress_bar_fill_.get(), 0, 0, pos, height, progress_x, progress_y);
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
2017-01-03 19:15:33 +01:00
|
|
|
if (pos < width - 1) {
|
2018-10-22 08:36:26 +02:00
|
|
|
DrawSurface(progress_bar_empty_.get(), pos, 0, width - pos, height, progress_x + pos,
|
|
|
|
progress_y);
|
2017-01-03 19:15:33 +01:00
|
|
|
}
|
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
2017-01-03 19:15:33 +01:00
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2017-06-24 07:47:03 +02:00
|
|
|
void ScreenRecoveryUI::SetColor(UIElement e) const {
|
2017-06-24 07:23:50 +02:00
|
|
|
switch (e) {
|
2018-10-12 01:54:50 +02:00
|
|
|
case UIElement::INFO:
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_color(249, 194, 0, 255);
|
|
|
|
break;
|
2018-10-12 01:54:50 +02:00
|
|
|
case UIElement::HEADER:
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_color(247, 0, 6, 255);
|
|
|
|
break;
|
2018-10-12 01:54:50 +02:00
|
|
|
case UIElement::MENU:
|
|
|
|
case UIElement::MENU_SEL_BG:
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_color(0, 106, 157, 255);
|
|
|
|
break;
|
2018-10-12 01:54:50 +02:00
|
|
|
case UIElement::MENU_SEL_BG_ACTIVE:
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_color(0, 156, 100, 255);
|
|
|
|
break;
|
2018-10-12 01:54:50 +02:00
|
|
|
case UIElement::MENU_SEL_FG:
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_color(255, 255, 255, 255);
|
|
|
|
break;
|
2018-10-12 01:54:50 +02:00
|
|
|
case UIElement::LOG:
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_color(196, 196, 196, 255);
|
|
|
|
break;
|
2018-10-12 01:54:50 +02:00
|
|
|
case UIElement::TEXT_FILL:
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_color(0, 0, 0, 160);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gr_color(255, 255, 255, 255);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-31 20:28:24 +02:00
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2017-09-21 02:53:46 +02:00
|
|
|
void ScreenRecoveryUI::SelectAndShowBackgroundText(const std::vector<std::string>& locales_entries,
|
|
|
|
size_t sel) {
|
|
|
|
SetLocale(locales_entries[sel]);
|
|
|
|
std::vector<std::string> text_name = { "erasing_text", "error_text", "installing_text",
|
|
|
|
"installing_security_text", "no_command_text" };
|
2018-10-22 08:36:26 +02:00
|
|
|
std::unordered_map<std::string, std::unique_ptr<GRSurface>> surfaces;
|
2017-09-21 02:53:46 +02:00
|
|
|
for (const auto& name : text_name) {
|
2018-10-22 08:36:26 +02:00
|
|
|
auto text_image = LoadLocalizedBitmap(name);
|
2017-09-21 02:53:46 +02:00
|
|
|
if (!text_image) {
|
|
|
|
Print("Failed to load %s\n", name.c_str());
|
|
|
|
return;
|
|
|
|
}
|
2018-10-22 08:36:26 +02:00
|
|
|
surfaces.emplace(name, std::move(text_image));
|
2017-09-21 02:53:46 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-09-21 02:53:46 +02:00
|
|
|
gr_color(0, 0, 0, 255);
|
|
|
|
gr_clear();
|
|
|
|
|
2018-07-31 23:53:16 +02:00
|
|
|
int text_y = margin_height_;
|
|
|
|
int text_x = margin_width_;
|
2017-09-21 02:53:46 +02:00
|
|
|
int line_spacing = gr_sys_font()->char_height; // Put some extra space between images.
|
|
|
|
// Write the header and descriptive texts.
|
2018-10-12 01:54:50 +02:00
|
|
|
SetColor(UIElement::INFO);
|
2017-09-21 02:53:46 +02:00
|
|
|
std::string header = "Show background text image";
|
2018-05-02 23:57:21 +02:00
|
|
|
text_y += DrawTextLine(text_x, text_y, header, true);
|
2017-09-21 02:53:46 +02:00
|
|
|
std::string locale_selection = android::base::StringPrintf(
|
2018-05-08 07:50:33 +02:00
|
|
|
"Current locale: %s, %zu/%zu", locales_entries[sel].c_str(), sel + 1, locales_entries.size());
|
2018-05-02 23:57:21 +02:00
|
|
|
// clang-format off
|
|
|
|
std::vector<std::string> instruction = {
|
|
|
|
locale_selection,
|
|
|
|
"Use volume up/down to switch locales and power to exit."
|
|
|
|
};
|
|
|
|
// clang-format on
|
2017-09-21 02:53:46 +02:00
|
|
|
text_y += DrawWrappedTextLines(text_x, text_y, instruction);
|
|
|
|
|
|
|
|
// Iterate through the text images and display them in order for the current locale.
|
|
|
|
for (const auto& p : surfaces) {
|
|
|
|
text_y += line_spacing;
|
2018-10-12 01:54:50 +02:00
|
|
|
SetColor(UIElement::LOG);
|
2018-05-02 23:57:21 +02:00
|
|
|
text_y += DrawTextLine(text_x, text_y, p.first, false);
|
2017-09-21 02:53:46 +02:00
|
|
|
gr_color(255, 255, 255, 255);
|
|
|
|
gr_texticon(text_x, text_y, p.second.get());
|
|
|
|
text_y += gr_get_height(p.second.get());
|
|
|
|
}
|
|
|
|
// Update the whole screen.
|
|
|
|
gr_flip();
|
|
|
|
}
|
|
|
|
|
2018-05-08 07:50:33 +02:00
|
|
|
void ScreenRecoveryUI::CheckBackgroundTextImages() {
|
2017-09-21 02:53:46 +02:00
|
|
|
// Load a list of locales embedded in one of the resource files.
|
|
|
|
std::vector<std::string> locales_entries = get_locales_in_png("installing_text");
|
|
|
|
if (locales_entries.empty()) {
|
|
|
|
Print("Failed to load locales from the resource files\n");
|
|
|
|
return;
|
|
|
|
}
|
2018-05-08 07:50:33 +02:00
|
|
|
std::string saved_locale = locale_;
|
2017-09-21 02:53:46 +02:00
|
|
|
size_t selected = 0;
|
|
|
|
SelectAndShowBackgroundText(locales_entries, selected);
|
|
|
|
|
|
|
|
FlushKeys();
|
|
|
|
while (true) {
|
|
|
|
int key = WaitKey();
|
2018-05-22 21:08:35 +02:00
|
|
|
if (key == static_cast<int>(KeyError::INTERRUPTED)) break;
|
2017-09-21 02:53:46 +02:00
|
|
|
if (key == KEY_POWER || key == KEY_ENTER) {
|
|
|
|
break;
|
|
|
|
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
|
|
|
selected = (selected == 0) ? locales_entries.size() - 1 : selected - 1;
|
|
|
|
SelectAndShowBackgroundText(locales_entries, selected);
|
|
|
|
} else if (key == KEY_DOWN || key == KEY_VOLUMEDOWN) {
|
|
|
|
selected = (selected == locales_entries.size() - 1) ? 0 : selected + 1;
|
|
|
|
SelectAndShowBackgroundText(locales_entries, selected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLocale(saved_locale);
|
|
|
|
}
|
|
|
|
|
2017-09-19 19:51:35 +02:00
|
|
|
int ScreenRecoveryUI::ScreenWidth() const {
|
|
|
|
return gr_fb_width();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ScreenRecoveryUI::ScreenHeight() const {
|
|
|
|
return gr_fb_height();
|
|
|
|
}
|
|
|
|
|
2018-10-23 19:54:02 +02:00
|
|
|
void ScreenRecoveryUI::DrawSurface(const GRSurface* surface, int sx, int sy, int w, int h, int dx,
|
2017-09-19 19:51:35 +02:00
|
|
|
int dy) const {
|
|
|
|
gr_blit(surface, sx, sy, w, h, dx, dy);
|
|
|
|
}
|
|
|
|
|
2017-06-28 23:52:17 +02:00
|
|
|
int ScreenRecoveryUI::DrawHorizontalRule(int y) const {
|
2017-09-19 19:51:35 +02:00
|
|
|
gr_fill(0, y + 4, ScreenWidth(), y + 6);
|
2017-06-28 23:52:17 +02:00
|
|
|
return 8;
|
2015-04-13 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
2017-06-13 01:08:33 +02:00
|
|
|
void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
|
2017-06-24 07:23:50 +02:00
|
|
|
gr_fill(x, y, x + width, y + height);
|
2017-06-13 01:08:33 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 19:51:35 +02:00
|
|
|
void ScreenRecoveryUI::DrawFill(int x, int y, int w, int h) const {
|
|
|
|
gr_fill(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2018-10-23 19:54:02 +02:00
|
|
|
void ScreenRecoveryUI::DrawTextIcon(int x, int y, const GRSurface* surface) const {
|
2017-09-19 19:51:35 +02:00
|
|
|
gr_texticon(x, y, surface);
|
|
|
|
}
|
|
|
|
|
2018-05-02 23:57:21 +02:00
|
|
|
int ScreenRecoveryUI::DrawTextLine(int x, int y, const std::string& line, bool bold) const {
|
|
|
|
gr_text(gr_sys_font(), x, y, line.c_str(), bold);
|
2017-06-28 23:52:17 +02:00
|
|
|
return char_height_ + 4;
|
2015-04-11 04:12:01 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 23:57:21 +02:00
|
|
|
int ScreenRecoveryUI::DrawTextLines(int x, int y, const std::vector<std::string>& lines) const {
|
2017-06-28 23:52:17 +02:00
|
|
|
int offset = 0;
|
2018-05-02 23:57:21 +02:00
|
|
|
for (const auto& line : lines) {
|
|
|
|
offset += DrawTextLine(x, y + offset, line, false);
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2017-06-28 23:52:17 +02:00
|
|
|
return offset;
|
2015-04-13 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
2018-05-02 23:57:21 +02:00
|
|
|
int ScreenRecoveryUI::DrawWrappedTextLines(int x, int y,
|
|
|
|
const std::vector<std::string>& lines) const {
|
2018-05-09 20:52:09 +02:00
|
|
|
// Keep symmetrical margins based on the given offset (i.e. x).
|
|
|
|
size_t text_cols = (ScreenWidth() - x * 2) / char_width_;
|
2017-08-14 08:48:55 +02:00
|
|
|
int offset = 0;
|
2018-05-02 23:57:21 +02:00
|
|
|
for (const auto& line : lines) {
|
2017-08-14 08:48:55 +02:00
|
|
|
size_t next_start = 0;
|
|
|
|
while (next_start < line.size()) {
|
2018-05-09 20:52:09 +02:00
|
|
|
std::string sub = line.substr(next_start, text_cols + 1);
|
|
|
|
if (sub.size() <= text_cols) {
|
2017-08-14 08:48:55 +02:00
|
|
|
next_start += sub.size();
|
|
|
|
} else {
|
2018-05-09 20:52:09 +02:00
|
|
|
// Line too long and must be wrapped to text_cols columns.
|
2017-08-14 08:48:55 +02:00
|
|
|
size_t last_space = sub.find_last_of(" \t\n");
|
|
|
|
if (last_space == std::string::npos) {
|
2018-05-02 23:57:21 +02:00
|
|
|
// No space found, just draw as much as we can.
|
2018-05-09 20:52:09 +02:00
|
|
|
sub.resize(text_cols);
|
|
|
|
next_start += text_cols;
|
2017-08-14 08:48:55 +02:00
|
|
|
} else {
|
|
|
|
sub.resize(last_space);
|
|
|
|
next_start += last_space + 1;
|
|
|
|
}
|
|
|
|
}
|
2018-05-02 23:57:21 +02:00
|
|
|
offset += DrawTextLine(x, y + offset, sub, false);
|
2017-08-14 08:48:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2018-05-07 20:21:10 +02:00
|
|
|
void ScreenRecoveryUI::SetTitle(const std::vector<std::string>& lines) {
|
|
|
|
title_lines_ = lines;
|
|
|
|
}
|
|
|
|
|
2019-07-23 22:23:29 +02:00
|
|
|
std::vector<std::string> ScreenRecoveryUI::GetMenuHelpMessage() const {
|
|
|
|
// clang-format off
|
|
|
|
static std::vector<std::string> REGULAR_HELP{
|
|
|
|
"Use volume up/down and power.",
|
|
|
|
};
|
|
|
|
static std::vector<std::string> LONG_PRESS_HELP{
|
|
|
|
"Any button cycles highlight.",
|
|
|
|
"Long-press activates.",
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
return HasThreeButtons() ? REGULAR_HELP : LONG_PRESS_HELP;
|
|
|
|
}
|
|
|
|
|
2017-06-20 08:10:44 +02:00
|
|
|
// Redraws everything on the screen. Does not flip pages. Should only be called with updateMutex
|
|
|
|
// locked.
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::draw_screen_locked() {
|
2017-06-20 08:10:44 +02:00
|
|
|
if (!show_text) {
|
|
|
|
draw_background_locked();
|
|
|
|
draw_foreground_locked();
|
|
|
|
return;
|
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2017-06-20 08:10:44 +02:00
|
|
|
gr_color(0, 0, 0, 255);
|
|
|
|
gr_clear();
|
|
|
|
|
2019-07-23 22:23:29 +02:00
|
|
|
draw_menu_and_text_buffer_locked(GetMenuHelpMessage());
|
2018-03-21 00:07:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draws the menu and text buffer on the screen. Should only be called with updateMutex locked.
|
2018-05-02 23:57:21 +02:00
|
|
|
void ScreenRecoveryUI::draw_menu_and_text_buffer_locked(
|
|
|
|
const std::vector<std::string>& help_message) {
|
2018-07-31 23:53:16 +02:00
|
|
|
int y = margin_height_;
|
2019-01-02 20:35:38 +01:00
|
|
|
|
|
|
|
if (fastbootd_logo_ && fastbootd_logo_enabled_) {
|
|
|
|
// Try to get this centered on screen.
|
|
|
|
auto width = gr_get_width(fastbootd_logo_.get());
|
|
|
|
auto height = gr_get_height(fastbootd_logo_.get());
|
|
|
|
auto centered_x = ScreenWidth() / 2 - width / 2;
|
|
|
|
DrawSurface(fastbootd_logo_.get(), 0, 0, width, height, centered_x, y);
|
|
|
|
y += height;
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:07:39 +01:00
|
|
|
if (menu_) {
|
2018-07-31 23:53:16 +02:00
|
|
|
int x = margin_width_ + kMenuIndent;
|
2017-06-20 08:10:44 +02:00
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
SetColor(UIElement::INFO);
|
2018-05-07 20:21:10 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < title_lines_.size(); i++) {
|
|
|
|
y += DrawTextLine(x, y, title_lines_[i], i == 0);
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
2017-06-20 08:10:44 +02:00
|
|
|
|
2018-03-21 00:07:39 +01:00
|
|
|
y += DrawTextLines(x, y, help_message);
|
|
|
|
|
2018-10-12 01:54:50 +02:00
|
|
|
y += menu_->DrawHeader(x, y);
|
|
|
|
y += menu_->DrawItems(x, y, ScreenWidth(), IsLongPress());
|
2017-06-20 08:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2018-10-12 01:54:50 +02:00
|
|
|
SetColor(UIElement::LOG);
|
2017-09-09 06:25:32 +02:00
|
|
|
int row = text_row_;
|
2017-06-20 08:10:44 +02:00
|
|
|
size_t count = 0;
|
2018-07-31 23:53:16 +02:00
|
|
|
for (int ty = ScreenHeight() - margin_height_ - char_height_; ty >= y && count < text_rows_;
|
2017-06-24 07:23:50 +02:00
|
|
|
ty -= char_height_, ++count) {
|
2018-07-31 23:53:16 +02:00
|
|
|
DrawTextLine(margin_width_, ty, text_[row], false);
|
2017-06-20 08:10:44 +02:00
|
|
|
--row;
|
|
|
|
if (row < 0) row = text_rows_ - 1;
|
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Redraw everything on the screen and flip the screen (make it visible).
|
2011-10-29 00:13:10 +02:00
|
|
|
// Should only be called with updateMutex locked.
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::update_screen_locked() {
|
2017-06-24 07:23:50 +02:00
|
|
|
draw_screen_locked();
|
|
|
|
gr_flip();
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Updates only the progress bar, if possible, otherwise redraws the screen.
|
2011-10-29 00:13:10 +02:00
|
|
|
// Should only be called with updateMutex locked.
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::update_progress_locked() {
|
2017-06-24 07:23:50 +02:00
|
|
|
if (show_text || !pagesIdentical) {
|
|
|
|
draw_screen_locked(); // Must redraw the whole screen
|
|
|
|
pagesIdentical = true;
|
|
|
|
} else {
|
|
|
|
draw_foreground_locked(); // Draw only the progress bar and overlays
|
|
|
|
}
|
|
|
|
gr_flip();
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2015-04-13 22:04:32 +02:00
|
|
|
void ScreenRecoveryUI::ProgressThreadLoop() {
|
2018-07-31 23:53:16 +02:00
|
|
|
double interval = 1.0 / animation_fps_;
|
2018-05-10 01:32:02 +02:00
|
|
|
while (!progress_thread_stopped_) {
|
2017-06-24 07:23:50 +02:00
|
|
|
double start = now();
|
|
|
|
bool redraw = false;
|
2018-05-22 01:04:57 +02:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
|
|
|
|
|
|
|
// update the installation animation, if active
|
|
|
|
// skip this if we have a text overlay (too expensive to update)
|
2018-10-22 08:36:26 +02:00
|
|
|
if ((current_icon_ == INSTALLING_UPDATE || current_icon_ == ERASING) && !show_text) {
|
|
|
|
if (!intro_done_) {
|
|
|
|
if (current_frame_ == intro_frames_.size() - 1) {
|
|
|
|
intro_done_ = true;
|
|
|
|
current_frame_ = 0;
|
2018-05-22 01:04:57 +02:00
|
|
|
} else {
|
2018-10-22 08:36:26 +02:00
|
|
|
++current_frame_;
|
2018-05-22 01:04:57 +02:00
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
} else {
|
2018-10-22 08:36:26 +02:00
|
|
|
current_frame_ = (current_frame_ + 1) % loop_frames_.size();
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
2011-03-01 23:04:34 +01:00
|
|
|
|
2017-06-24 07:23:50 +02:00
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
|
2018-05-22 01:04:57 +02:00
|
|
|
// move the progress bar forward on timed intervals, if configured
|
|
|
|
int duration = progressScopeDuration;
|
|
|
|
if (progressBarType == DETERMINATE && duration > 0) {
|
|
|
|
double elapsed = now() - progressScopeTime;
|
|
|
|
float p = 1.0 * elapsed / duration;
|
|
|
|
if (p > 1.0) p = 1.0;
|
|
|
|
if (p > progress) {
|
|
|
|
progress = p;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw) update_progress_locked();
|
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
|
|
|
|
double end = now();
|
|
|
|
// minimum of 20ms delay between frames
|
|
|
|
double delay = interval - (end - start);
|
|
|
|
if (delay < 0.02) delay = 0.02;
|
|
|
|
usleep(static_cast<useconds_t>(delay * 1000000));
|
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
std::unique_ptr<GRSurface> ScreenRecoveryUI::LoadBitmap(const std::string& filename) {
|
|
|
|
GRSurface* surface;
|
|
|
|
if (auto result = res_create_display_surface(filename.c_str(), &surface); result < 0) {
|
|
|
|
LOG(ERROR) << "Failed to load bitmap " << filename << " (error " << result << ")";
|
|
|
|
return nullptr;
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2018-10-22 08:36:26 +02:00
|
|
|
return std::unique_ptr<GRSurface>(surface);
|
2014-03-07 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
std::unique_ptr<GRSurface> ScreenRecoveryUI::LoadLocalizedBitmap(const std::string& filename) {
|
|
|
|
GRSurface* surface;
|
2019-04-16 21:07:42 +02:00
|
|
|
auto result = res_create_localized_alpha_surface(filename.c_str(), locale_.c_str(), &surface);
|
|
|
|
if (result == 0) {
|
|
|
|
return std::unique_ptr<GRSurface>(surface);
|
2017-01-03 19:15:33 +01:00
|
|
|
}
|
2019-04-16 21:07:42 +02:00
|
|
|
// TODO(xunchang) create a error code enum to refine the retry condition.
|
|
|
|
LOG(WARNING) << "Failed to load bitmap " << filename << " for locale " << locale_ << " (error "
|
|
|
|
<< result << "). Falling back to use default locale.";
|
|
|
|
|
|
|
|
result = res_create_localized_alpha_surface(filename.c_str(), DEFAULT_LOCALE, &surface);
|
|
|
|
if (result == 0) {
|
|
|
|
return std::unique_ptr<GRSurface>(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(ERROR) << "Failed to load bitmap " << filename << " for locale " << DEFAULT_LOCALE
|
|
|
|
<< " (error " << result << ")";
|
|
|
|
return nullptr;
|
2012-08-23 02:26:40 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 21:42:50 +02:00
|
|
|
static char** Alloc2d(size_t rows, size_t cols) {
|
2017-06-24 07:23:50 +02:00
|
|
|
char** result = new char*[rows];
|
|
|
|
for (size_t i = 0; i < rows; ++i) {
|
|
|
|
result[i] = new char[cols];
|
|
|
|
memset(result[i], 0, cols);
|
|
|
|
}
|
|
|
|
return result;
|
2015-04-08 21:42:50 +02:00
|
|
|
}
|
|
|
|
|
2016-04-29 03:06:26 +02:00
|
|
|
// Choose the right background string to display during update.
|
|
|
|
void ScreenRecoveryUI::SetSystemUpdateText(bool security_update) {
|
2017-06-24 07:23:50 +02:00
|
|
|
if (security_update) {
|
2018-10-22 08:36:26 +02:00
|
|
|
installing_text_ = LoadLocalizedBitmap("installing_security_text");
|
2017-06-24 07:23:50 +02:00
|
|
|
} else {
|
2018-10-22 08:36:26 +02:00
|
|
|
installing_text_ = LoadLocalizedBitmap("installing_text");
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
|
|
|
Redraw();
|
2016-04-29 03:06:26 +02:00
|
|
|
}
|
|
|
|
|
2016-12-10 01:20:49 +01:00
|
|
|
bool ScreenRecoveryUI::InitTextParams() {
|
2018-06-13 20:22:50 +02:00
|
|
|
// gr_init() would return successfully on font initialization failure.
|
|
|
|
if (gr_sys_font() == nullptr) {
|
2017-06-20 08:10:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gr_font_size(gr_sys_font(), &char_width_, &char_height_);
|
2018-07-31 23:53:16 +02:00
|
|
|
text_rows_ = (ScreenHeight() - margin_height_ * 2) / char_height_;
|
|
|
|
text_cols_ = (ScreenWidth() - margin_width_ * 2) / char_width_;
|
2017-06-20 08:10:44 +02:00
|
|
|
return true;
|
2016-08-25 03:28:43 +02:00
|
|
|
}
|
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
bool ScreenRecoveryUI::LoadWipeDataMenuText() {
|
2018-10-26 00:22:07 +02:00
|
|
|
// Ignores the errors since the member variables will stay as nullptr.
|
|
|
|
cancel_wipe_data_text_ = LoadLocalizedBitmap("cancel_wipe_data_text");
|
|
|
|
factory_data_reset_text_ = LoadLocalizedBitmap("factory_data_reset_text");
|
|
|
|
try_again_text_ = LoadLocalizedBitmap("try_again_text");
|
|
|
|
wipe_data_confirmation_text_ = LoadLocalizedBitmap("wipe_data_confirmation_text");
|
|
|
|
wipe_data_menu_header_text_ = LoadLocalizedBitmap("wipe_data_menu_header_text");
|
2018-10-17 00:13:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
recovery: fastbootd: retry opening graphics
Recovery and fastbootd hardening.
With GKI we find in certain situations the timing of the drivers
loading is delayed as compared to a monolithic kernel. This
exasperates an existing race where during second stage init, the
graphics driver might not have completely instantiated by the time
fastboot or recovery menu ui is being set up.
To address this, we call gr_init() every 10ms until either 5 seconds
timeout or success. If we timeout, there will be no TUI (minui), but
this is better than if we just tried once and dropped the TUI and was
effectively running headless. 5 seconds timeout is arbitrary, based
on the default in init for wait for file; but makes sense as any
longer will impact flashstation and fastboot flashall enough to be
a cause for consternation.
It should be noted that both recovery and fastbootd can still service
adb or fastboot gadgets headless. For instance if the device tree is
misconfigured as a permanent issue that would head for the timeout.
Prefering to give up after a timeout so that device can be flashed by
fastbootd, or rebooted by recovery adbd, over the protocol is
advantageous for tool stability.
Architectural Concern:
The graphics driver, if not well written, may panic the kernel if we
try to access it too soon while it is probing. On such devices it
will be necessary to hold off in 'on init' or 'on early-init' phases
until the graphics drivers have completely probed. Or better yet,
fix the driver. This problem would happen in any case occasionally
even without this adjustments, but could conceivably be amplified by
the loop trying to open the graphics device.
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 151950334
Test: make sure user space fastbootd comes up reliably for a GKI kernel
Change-Id: I1ce31a01544a58cdf7b9d657c1146bee77894e46
2020-05-13 21:39:12 +02:00
|
|
|
static bool InitGraphics() {
|
|
|
|
// Timeout is same as init wait for file default of 5 seconds and is arbitrary
|
|
|
|
const unsigned timeout = 500; // 10ms increments
|
|
|
|
for (auto retry = timeout; retry > 0; --retry) {
|
|
|
|
if (gr_init() == 0) {
|
|
|
|
if (retry < timeout) {
|
|
|
|
// Log message like init wait for file completion log for consistency.
|
|
|
|
LOG(WARNING) << "wait for 'graphics' took " << ((timeout - retry) * 10) << "ms";
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
|
|
}
|
|
|
|
// Log message like init wait for file timeout log for consistency.
|
|
|
|
LOG(ERROR) << "timeout wait for 'graphics' took " << (timeout * 10) << "ms";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
bool ScreenRecoveryUI::Init(const std::string& locale) {
|
|
|
|
RecoveryUI::Init(locale);
|
2017-02-01 08:03:10 +01:00
|
|
|
|
recovery: fastbootd: retry opening graphics
Recovery and fastbootd hardening.
With GKI we find in certain situations the timing of the drivers
loading is delayed as compared to a monolithic kernel. This
exasperates an existing race where during second stage init, the
graphics driver might not have completely instantiated by the time
fastboot or recovery menu ui is being set up.
To address this, we call gr_init() every 10ms until either 5 seconds
timeout or success. If we timeout, there will be no TUI (minui), but
this is better than if we just tried once and dropped the TUI and was
effectively running headless. 5 seconds timeout is arbitrary, based
on the default in init for wait for file; but makes sense as any
longer will impact flashstation and fastboot flashall enough to be
a cause for consternation.
It should be noted that both recovery and fastbootd can still service
adb or fastboot gadgets headless. For instance if the device tree is
misconfigured as a permanent issue that would head for the timeout.
Prefering to give up after a timeout so that device can be flashed by
fastbootd, or rebooted by recovery adbd, over the protocol is
advantageous for tool stability.
Architectural Concern:
The graphics driver, if not well written, may panic the kernel if we
try to access it too soon while it is probing. On such devices it
will be necessary to hold off in 'on init' or 'on early-init' phases
until the graphics drivers have completely probed. Or better yet,
fix the driver. This problem would happen in any case occasionally
even without this adjustments, but could conceivably be amplified by
the loop trying to open the graphics device.
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Bug: 151950334
Test: make sure user space fastbootd comes up reliably for a GKI kernel
Change-Id: I1ce31a01544a58cdf7b9d657c1146bee77894e46
2020-05-13 21:39:12 +02:00
|
|
|
if (!InitGraphics()) {
|
2018-06-13 20:22:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-11 09:39:53 +01:00
|
|
|
is_graphics_available = true;
|
2018-06-13 20:22:50 +02:00
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
if (!InitTextParams()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-25 03:28:43 +02:00
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
// Are we portrait or landscape?
|
|
|
|
layout_ = (gr_fb_width() > gr_fb_height()) ? LANDSCAPE : PORTRAIT;
|
|
|
|
// Are we the large variant of our base layout?
|
|
|
|
if (gr_fb_height() > PixelsFromDp(800)) ++layout_;
|
2016-04-21 02:22:16 +02:00
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
text_ = Alloc2d(text_rows_, text_cols_ + 1);
|
|
|
|
file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);
|
2013-03-05 00:49:02 +01:00
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
text_col_ = text_row_ = 0;
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2017-02-01 08:03:10 +01:00
|
|
|
// Set up the locale info.
|
|
|
|
SetLocale(locale);
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
error_icon_ = LoadBitmap("icon_error");
|
2012-08-23 02:26:40 +02:00
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
progress_bar_empty_ = LoadBitmap("progress_empty");
|
|
|
|
progress_bar_fill_ = LoadBitmap("progress_fill");
|
|
|
|
stage_marker_empty_ = LoadBitmap("stage_empty");
|
|
|
|
stage_marker_fill_ = LoadBitmap("stage_fill");
|
2016-04-15 01:49:04 +02:00
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
erasing_text_ = LoadLocalizedBitmap("erasing_text");
|
|
|
|
no_command_text_ = LoadLocalizedBitmap("no_command_text");
|
|
|
|
error_text_ = LoadLocalizedBitmap("error_text");
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2019-01-02 20:35:38 +01:00
|
|
|
if (android::base::GetBoolProperty("ro.boot.dynamic_partitions", false)) {
|
|
|
|
fastbootd_logo_ = LoadBitmap("fastbootd");
|
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
// Background text for "installing_update" could be "installing update" or
|
|
|
|
// "installing security update". It will be set after Init() according to the commands in BCB.
|
|
|
|
installing_text_.reset();
|
2016-04-15 01:49:04 +02:00
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
LoadWipeDataMenuText();
|
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
LoadAnimation();
|
2012-08-23 02:26:40 +02:00
|
|
|
|
2018-05-10 01:32:02 +02:00
|
|
|
// Keep the progress bar updated, even when the process is otherwise busy.
|
|
|
|
progress_thread_ = std::thread(&ScreenRecoveryUI::ProgressThreadLoop, this);
|
2016-12-10 01:20:49 +01:00
|
|
|
|
2022-02-11 09:39:53 +01:00
|
|
|
// set the callback for hall sensor event
|
|
|
|
(void)ev_sync_sw_state([this](auto&& a, auto&& b) { return this->SetSwCallback(a, b);});
|
|
|
|
|
2017-01-03 19:15:33 +01:00
|
|
|
return true;
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2018-05-10 05:53:13 +02:00
|
|
|
std::string ScreenRecoveryUI::GetLocale() const {
|
2018-05-03 02:15:03 +02:00
|
|
|
return locale_;
|
|
|
|
}
|
|
|
|
|
2016-04-15 01:49:04 +02:00
|
|
|
void ScreenRecoveryUI::LoadAnimation() {
|
2018-05-04 06:53:11 +02:00
|
|
|
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(Paths::Get().resource_dir().c_str()),
|
|
|
|
closedir);
|
2017-06-24 07:23:50 +02:00
|
|
|
dirent* de;
|
|
|
|
std::vector<std::string> intro_frame_names;
|
2019-12-09 21:24:18 +01:00
|
|
|
std::vector<std::string> loop_frame_names;
|
2017-06-24 07:23:50 +02:00
|
|
|
|
|
|
|
while ((de = readdir(dir.get())) != nullptr) {
|
|
|
|
int value, num_chars;
|
|
|
|
if (sscanf(de->d_name, "intro%d%n.png", &value, &num_chars) == 1) {
|
|
|
|
intro_frame_names.emplace_back(de->d_name, num_chars);
|
|
|
|
} else if (sscanf(de->d_name, "loop%d%n.png", &value, &num_chars) == 1) {
|
2019-12-09 21:24:18 +01:00
|
|
|
loop_frame_names.emplace_back(de->d_name, num_chars);
|
2016-04-15 01:49:04 +02:00
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2016-04-15 01:49:04 +02:00
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
size_t intro_frames = intro_frame_names.size();
|
|
|
|
size_t loop_frames = loop_frame_names.size();
|
2016-08-25 03:28:43 +02:00
|
|
|
|
2017-06-24 07:23:50 +02:00
|
|
|
// It's okay to not have an intro.
|
2018-10-22 08:36:26 +02:00
|
|
|
if (intro_frames == 0) intro_done_ = true;
|
2017-06-24 07:23:50 +02:00
|
|
|
// But you must have an animation.
|
|
|
|
if (loop_frames == 0) abort();
|
2016-04-15 01:49:04 +02:00
|
|
|
|
2017-06-24 07:23:50 +02:00
|
|
|
std::sort(intro_frame_names.begin(), intro_frame_names.end());
|
|
|
|
std::sort(loop_frame_names.begin(), loop_frame_names.end());
|
2016-08-25 03:28:43 +02:00
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
intro_frames_.clear();
|
|
|
|
intro_frames_.reserve(intro_frames);
|
|
|
|
for (const auto& frame_name : intro_frame_names) {
|
|
|
|
intro_frames_.emplace_back(LoadBitmap(frame_name));
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2016-04-15 01:49:04 +02:00
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
loop_frames_.clear();
|
|
|
|
loop_frames_.reserve(loop_frames);
|
|
|
|
for (const auto& frame_name : loop_frame_names) {
|
|
|
|
loop_frames_.emplace_back(LoadBitmap(frame_name));
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2016-04-15 01:49:04 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::SetBackground(Icon icon) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2012-08-23 02:26:40 +02:00
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
current_icon_ = icon;
|
2017-06-24 07:23:50 +02:00
|
|
|
update_screen_locked();
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::SetProgressType(ProgressType type) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
if (progressBarType != type) {
|
|
|
|
progressBarType = type;
|
|
|
|
}
|
|
|
|
progressScopeStart = 0;
|
|
|
|
progressScopeSize = 0;
|
|
|
|
progress = 0;
|
|
|
|
update_progress_locked();
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
progressBarType = DETERMINATE;
|
|
|
|
progressScopeStart += progressScopeSize;
|
|
|
|
progressScopeSize = portion;
|
|
|
|
progressScopeTime = now();
|
|
|
|
progressScopeDuration = seconds;
|
|
|
|
progress = 0;
|
|
|
|
update_progress_locked();
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::SetProgress(float fraction) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
if (fraction < 0.0) fraction = 0.0;
|
|
|
|
if (fraction > 1.0) fraction = 1.0;
|
|
|
|
if (progressBarType == DETERMINATE && fraction > progress) {
|
|
|
|
// Skip updates that aren't visibly different.
|
2018-10-22 08:36:26 +02:00
|
|
|
int width = gr_get_width(progress_bar_empty_.get());
|
2017-06-24 07:23:50 +02:00
|
|
|
float scale = width * progressScopeSize;
|
|
|
|
if ((int)(progress * scale) != (int)(fraction * scale)) {
|
|
|
|
progress = fraction;
|
|
|
|
update_progress_locked();
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 22:53:25 +01:00
|
|
|
void ScreenRecoveryUI::SetStage(int current, int max) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
stage = current;
|
|
|
|
max_stage = max;
|
2013-11-25 22:53:25 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:02:16 +02:00
|
|
|
void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
|
2017-06-24 07:23:50 +02:00
|
|
|
std::string str;
|
|
|
|
android::base::StringAppendV(&str, fmt, ap);
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2017-06-24 07:23:50 +02:00
|
|
|
if (copy_to_stdout) {
|
|
|
|
fputs(str.c_str(), stdout);
|
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
if (text_rows_ > 0 && text_cols_ > 0) {
|
|
|
|
for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
|
|
|
|
if (*ptr == '\n' || text_col_ >= text_cols_) {
|
2015-05-06 21:40:05 +02:00
|
|
|
text_[text_row_][text_col_] = '\0';
|
2017-06-24 07:23:50 +02:00
|
|
|
text_col_ = 0;
|
|
|
|
text_row_ = (text_row_ + 1) % text_rows_;
|
|
|
|
}
|
|
|
|
if (*ptr != '\n') text_[text_row_][text_col_++] = *ptr;
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
text_[text_row_][text_col_] = '\0';
|
|
|
|
update_screen_locked();
|
|
|
|
}
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:02:16 +02:00
|
|
|
void ScreenRecoveryUI::Print(const char* fmt, ...) {
|
2017-06-24 07:23:50 +02:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
PrintV(fmt, true, ap);
|
|
|
|
va_end(ap);
|
2015-05-20 02:02:16 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 22:40:47 +02:00
|
|
|
void ScreenRecoveryUI::PrintOnScreenOnly(const char* fmt, ...) {
|
2017-06-24 07:23:50 +02:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
PrintV(fmt, false, ap);
|
|
|
|
va_end(ap);
|
2015-05-20 02:02:16 +02:00
|
|
|
}
|
|
|
|
|
2015-04-11 04:12:01 +02:00
|
|
|
void ScreenRecoveryUI::PutChar(char ch) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
if (ch != '\n') text_[text_row_][text_col_++] = ch;
|
|
|
|
if (ch == '\n' || text_col_ >= text_cols_) {
|
|
|
|
text_col_ = 0;
|
|
|
|
++text_row_;
|
|
|
|
}
|
2015-04-09 05:06:50 +02:00
|
|
|
}
|
|
|
|
|
2015-04-11 04:12:01 +02:00
|
|
|
void ScreenRecoveryUI::ClearText() {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
text_col_ = 0;
|
|
|
|
text_row_ = 0;
|
|
|
|
for (size_t i = 0; i < text_rows_; ++i) {
|
|
|
|
memset(text_[i], 0, text_cols_ + 1);
|
|
|
|
}
|
2015-04-11 04:12:01 +02:00
|
|
|
}
|
2015-04-09 05:06:50 +02:00
|
|
|
|
2015-04-11 04:12:01 +02:00
|
|
|
void ScreenRecoveryUI::ShowFile(FILE* fp) {
|
2017-06-24 07:23:50 +02:00
|
|
|
std::vector<off_t> offsets;
|
|
|
|
offsets.push_back(ftello(fp));
|
|
|
|
ClearText();
|
|
|
|
|
|
|
|
struct stat sb;
|
|
|
|
fstat(fileno(fp), &sb);
|
|
|
|
|
|
|
|
bool show_prompt = false;
|
|
|
|
while (true) {
|
|
|
|
if (show_prompt) {
|
|
|
|
PrintOnScreenOnly("--(%d%% of %d bytes)--",
|
|
|
|
static_cast<int>(100 * (double(ftello(fp)) / double(sb.st_size))),
|
|
|
|
static_cast<int>(sb.st_size));
|
|
|
|
Redraw();
|
|
|
|
while (show_prompt) {
|
|
|
|
show_prompt = false;
|
|
|
|
int key = WaitKey();
|
2018-05-22 21:08:35 +02:00
|
|
|
if (key == static_cast<int>(KeyError::INTERRUPTED)) return;
|
2017-06-24 07:23:50 +02:00
|
|
|
if (key == KEY_POWER || key == KEY_ENTER) {
|
|
|
|
return;
|
|
|
|
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
|
|
|
if (offsets.size() <= 1) {
|
2015-04-11 04:12:01 +02:00
|
|
|
show_prompt = true;
|
2017-06-24 07:23:50 +02:00
|
|
|
} else {
|
|
|
|
offsets.pop_back();
|
|
|
|
fseek(fp, offsets.back(), SEEK_SET);
|
|
|
|
}
|
2015-04-11 04:12:01 +02:00
|
|
|
} else {
|
2017-06-24 07:23:50 +02:00
|
|
|
if (feof(fp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
offsets.push_back(ftello(fp));
|
2015-04-09 05:06:50 +02:00
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
|
|
|
ClearText();
|
2015-04-09 05:06:50 +02:00
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
|
|
|
|
int ch = getc(fp);
|
|
|
|
if (ch == EOF) {
|
|
|
|
while (text_row_ < text_rows_ - 1) PutChar('\n');
|
|
|
|
show_prompt = true;
|
|
|
|
} else {
|
|
|
|
PutChar(ch);
|
|
|
|
if (text_col_ == 0 && text_row_ >= text_rows_ - 1) {
|
|
|
|
show_prompt = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 04:12:01 +02:00
|
|
|
}
|
2015-04-09 05:06:50 +02:00
|
|
|
|
2018-05-02 21:43:18 +02:00
|
|
|
void ScreenRecoveryUI::ShowFile(const std::string& filename) {
|
|
|
|
std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(filename.c_str(), "re"), fclose);
|
|
|
|
if (!fp) {
|
|
|
|
Print(" Unable to open %s: %s\n", filename.c_str(), strerror(errno));
|
2017-06-24 07:23:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-06 21:40:05 +02:00
|
|
|
|
2017-06-24 07:23:50 +02:00
|
|
|
char** old_text = text_;
|
|
|
|
size_t old_text_col = text_col_;
|
|
|
|
size_t old_text_row = text_row_;
|
2015-05-06 21:40:05 +02:00
|
|
|
|
2017-06-24 07:23:50 +02:00
|
|
|
// Swap in the alternate screen and clear it.
|
|
|
|
text_ = file_viewer_text_;
|
|
|
|
ClearText();
|
2015-05-06 21:40:05 +02:00
|
|
|
|
2018-05-02 21:43:18 +02:00
|
|
|
ShowFile(fp.get());
|
2015-05-06 21:40:05 +02:00
|
|
|
|
2017-06-24 07:23:50 +02:00
|
|
|
text_ = old_text;
|
|
|
|
text_col_ = old_text_col;
|
|
|
|
text_row_ = old_text_row;
|
2015-04-09 05:06:50 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 08:36:26 +02:00
|
|
|
std::unique_ptr<Menu> ScreenRecoveryUI::CreateMenu(
|
|
|
|
const GRSurface* graphic_header, const std::vector<const GRSurface*>& graphic_items,
|
|
|
|
const std::vector<std::string>& text_headers, const std::vector<std::string>& text_items,
|
|
|
|
size_t initial_selection) const {
|
2018-10-17 00:13:09 +02:00
|
|
|
// horizontal unusable area: margin width + menu indent
|
|
|
|
size_t max_width = ScreenWidth() - margin_width_ - kMenuIndent;
|
|
|
|
// vertical unusable area: margin height + title lines + helper message + high light bar.
|
|
|
|
// It is safe to reserve more space.
|
|
|
|
size_t max_height = ScreenHeight() - margin_height_ - char_height_ * (title_lines_.size() + 3);
|
|
|
|
if (GraphicMenu::Validate(max_width, max_height, graphic_header, graphic_items)) {
|
|
|
|
return std::make_unique<GraphicMenu>(graphic_header, graphic_items, initial_selection, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "Failed to initialize graphic menu, falling back to use the text menu.\n");
|
|
|
|
|
|
|
|
return CreateMenu(text_headers, text_items, initial_selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Menu> ScreenRecoveryUI::CreateMenu(const std::vector<std::string>& text_headers,
|
|
|
|
const std::vector<std::string>& text_items,
|
|
|
|
size_t initial_selection) const {
|
2018-03-21 00:07:39 +01:00
|
|
|
if (text_rows_ > 0 && text_cols_ > 1) {
|
2018-10-17 00:13:09 +02:00
|
|
|
return std::make_unique<TextMenu>(scrollable_menu_, text_rows_, text_cols_ - 1, text_headers,
|
|
|
|
text_items, initial_selection, char_height_, *this);
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
2018-10-17 00:13:09 +02:00
|
|
|
|
|
|
|
fprintf(stderr, "Failed to create text menu, text_rows %zu, text_cols %zu.\n", text_rows_,
|
|
|
|
text_cols_);
|
|
|
|
return nullptr;
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2011-10-29 00:13:10 +02:00
|
|
|
int ScreenRecoveryUI::SelectMenu(int sel) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2018-03-21 00:07:39 +01:00
|
|
|
if (menu_) {
|
|
|
|
int old_sel = menu_->selection();
|
|
|
|
sel = menu_->Select(sel);
|
2015-03-23 21:45:31 +01:00
|
|
|
|
2018-03-21 00:07:39 +01:00
|
|
|
if (sel != old_sel) {
|
|
|
|
update_screen_locked();
|
|
|
|
}
|
2017-06-24 07:23:50 +02:00
|
|
|
}
|
|
|
|
return sel;
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
size_t ScreenRecoveryUI::ShowMenu(std::unique_ptr<Menu>&& menu, bool menu_only,
|
2018-05-02 00:56:05 +02:00
|
|
|
const std::function<int(int, bool)>& key_handler) {
|
Add ScreenRecoveryUI::ShowMenu().
From caller's PoV, RecoveryUI::{Start,Select,End}Menu should always be
used together, i.e. to show a menu and get user's selection. This CL
provides ShowMenu() as one-stop service (which is based on
get_menu_selection() from recovery.cpp).
Also move RecoveryUI::{Start,Select,End}Menu into ScreenRecoveryUI, with
a dropped access level from public to protected.
Due to the dependency on recovery / librecovery refactoring, will add
testcases in follow-up CLs.
Test: Build and boot into recovery image. Check the menus (main menu,
'View recovery logs', 'Wipe data/factory reset').
Change-Id: Ie17aa78144871a12affd6f9075e045f76608a0ba
2018-04-20 18:24:58 +02:00
|
|
|
// Throw away keys pressed previously, so user doesn't accidentally trigger menu items.
|
|
|
|
FlushKeys();
|
|
|
|
|
2018-05-22 21:08:35 +02:00
|
|
|
// If there is a key interrupt in progress, return KeyError::INTERRUPTED without starting the
|
|
|
|
// menu.
|
|
|
|
if (IsKeyInterrupted()) return static_cast<size_t>(KeyError::INTERRUPTED);
|
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
CHECK(menu != nullptr);
|
|
|
|
|
|
|
|
// Starts and displays the menu
|
|
|
|
menu_ = std::move(menu);
|
|
|
|
Redraw();
|
Add ScreenRecoveryUI::ShowMenu().
From caller's PoV, RecoveryUI::{Start,Select,End}Menu should always be
used together, i.e. to show a menu and get user's selection. This CL
provides ShowMenu() as one-stop service (which is based on
get_menu_selection() from recovery.cpp).
Also move RecoveryUI::{Start,Select,End}Menu into ScreenRecoveryUI, with
a dropped access level from public to protected.
Due to the dependency on recovery / librecovery refactoring, will add
testcases in follow-up CLs.
Test: Build and boot into recovery image. Check the menus (main menu,
'View recovery logs', 'Wipe data/factory reset').
Change-Id: Ie17aa78144871a12affd6f9075e045f76608a0ba
2018-04-20 18:24:58 +02:00
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
int selected = menu_->selection();
|
Add ScreenRecoveryUI::ShowMenu().
From caller's PoV, RecoveryUI::{Start,Select,End}Menu should always be
used together, i.e. to show a menu and get user's selection. This CL
provides ShowMenu() as one-stop service (which is based on
get_menu_selection() from recovery.cpp).
Also move RecoveryUI::{Start,Select,End}Menu into ScreenRecoveryUI, with
a dropped access level from public to protected.
Due to the dependency on recovery / librecovery refactoring, will add
testcases in follow-up CLs.
Test: Build and boot into recovery image. Check the menus (main menu,
'View recovery logs', 'Wipe data/factory reset').
Change-Id: Ie17aa78144871a12affd6f9075e045f76608a0ba
2018-04-20 18:24:58 +02:00
|
|
|
int chosen_item = -1;
|
|
|
|
while (chosen_item < 0) {
|
|
|
|
int key = WaitKey();
|
2018-05-22 21:08:35 +02:00
|
|
|
if (key == static_cast<int>(KeyError::INTERRUPTED)) { // WaitKey() was interrupted.
|
|
|
|
return static_cast<size_t>(KeyError::INTERRUPTED);
|
|
|
|
}
|
|
|
|
if (key == static_cast<int>(KeyError::TIMED_OUT)) { // WaitKey() timed out.
|
Add ScreenRecoveryUI::ShowMenu().
From caller's PoV, RecoveryUI::{Start,Select,End}Menu should always be
used together, i.e. to show a menu and get user's selection. This CL
provides ShowMenu() as one-stop service (which is based on
get_menu_selection() from recovery.cpp).
Also move RecoveryUI::{Start,Select,End}Menu into ScreenRecoveryUI, with
a dropped access level from public to protected.
Due to the dependency on recovery / librecovery refactoring, will add
testcases in follow-up CLs.
Test: Build and boot into recovery image. Check the menus (main menu,
'View recovery logs', 'Wipe data/factory reset').
Change-Id: Ie17aa78144871a12affd6f9075e045f76608a0ba
2018-04-20 18:24:58 +02:00
|
|
|
if (WasTextEverVisible()) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
LOG(INFO) << "Timed out waiting for key input; rebooting.";
|
2018-10-17 00:13:09 +02:00
|
|
|
menu_.reset();
|
|
|
|
Redraw();
|
2018-05-22 21:08:35 +02:00
|
|
|
return static_cast<size_t>(KeyError::TIMED_OUT);
|
Add ScreenRecoveryUI::ShowMenu().
From caller's PoV, RecoveryUI::{Start,Select,End}Menu should always be
used together, i.e. to show a menu and get user's selection. This CL
provides ShowMenu() as one-stop service (which is based on
get_menu_selection() from recovery.cpp).
Also move RecoveryUI::{Start,Select,End}Menu into ScreenRecoveryUI, with
a dropped access level from public to protected.
Due to the dependency on recovery / librecovery refactoring, will add
testcases in follow-up CLs.
Test: Build and boot into recovery image. Check the menus (main menu,
'View recovery logs', 'Wipe data/factory reset').
Change-Id: Ie17aa78144871a12affd6f9075e045f76608a0ba
2018-04-20 18:24:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool visible = IsTextVisible();
|
|
|
|
int action = key_handler(key, visible);
|
|
|
|
if (action < 0) {
|
|
|
|
switch (action) {
|
|
|
|
case Device::kHighlightUp:
|
|
|
|
selected = SelectMenu(--selected);
|
|
|
|
break;
|
|
|
|
case Device::kHighlightDown:
|
|
|
|
selected = SelectMenu(++selected);
|
|
|
|
break;
|
|
|
|
case Device::kInvokeItem:
|
|
|
|
chosen_item = selected;
|
|
|
|
break;
|
|
|
|
case Device::kNoAction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (!menu_only) {
|
|
|
|
chosen_item = action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
menu_.reset();
|
|
|
|
Redraw();
|
|
|
|
|
Add ScreenRecoveryUI::ShowMenu().
From caller's PoV, RecoveryUI::{Start,Select,End}Menu should always be
used together, i.e. to show a menu and get user's selection. This CL
provides ShowMenu() as one-stop service (which is based on
get_menu_selection() from recovery.cpp).
Also move RecoveryUI::{Start,Select,End}Menu into ScreenRecoveryUI, with
a dropped access level from public to protected.
Due to the dependency on recovery / librecovery refactoring, will add
testcases in follow-up CLs.
Test: Build and boot into recovery image. Check the menus (main menu,
'View recovery logs', 'Wipe data/factory reset').
Change-Id: Ie17aa78144871a12affd6f9075e045f76608a0ba
2018-04-20 18:24:58 +02:00
|
|
|
return chosen_item;
|
|
|
|
}
|
|
|
|
|
2018-10-17 00:13:09 +02:00
|
|
|
size_t ScreenRecoveryUI::ShowMenu(const std::vector<std::string>& headers,
|
|
|
|
const std::vector<std::string>& items, size_t initial_selection,
|
|
|
|
bool menu_only,
|
|
|
|
const std::function<int(int, bool)>& key_handler) {
|
|
|
|
auto menu = CreateMenu(headers, items, initial_selection);
|
|
|
|
if (menu == nullptr) {
|
|
|
|
return initial_selection;
|
|
|
|
}
|
|
|
|
|
2019-06-27 18:07:04 +02:00
|
|
|
return ShowMenu(std::move(menu), menu_only, key_handler);
|
2018-10-17 00:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t ScreenRecoveryUI::ShowPromptWipeDataMenu(const std::vector<std::string>& backup_headers,
|
|
|
|
const std::vector<std::string>& backup_items,
|
|
|
|
const std::function<int(int, bool)>& key_handler) {
|
2018-10-22 08:36:26 +02:00
|
|
|
auto wipe_data_menu = CreateMenu(wipe_data_menu_header_text_.get(),
|
|
|
|
{ try_again_text_.get(), factory_data_reset_text_.get() },
|
|
|
|
backup_headers, backup_items, 0);
|
2018-10-17 00:13:09 +02:00
|
|
|
if (wipe_data_menu == nullptr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ShowMenu(std::move(wipe_data_menu), true, key_handler);
|
|
|
|
}
|
|
|
|
|
2018-10-26 00:22:07 +02:00
|
|
|
size_t ScreenRecoveryUI::ShowPromptWipeDataConfirmationMenu(
|
|
|
|
const std::vector<std::string>& backup_headers, const std::vector<std::string>& backup_items,
|
|
|
|
const std::function<int(int, bool)>& key_handler) {
|
|
|
|
auto confirmation_menu =
|
|
|
|
CreateMenu(wipe_data_confirmation_text_.get(),
|
|
|
|
{ cancel_wipe_data_text_.get(), factory_data_reset_text_.get() }, backup_headers,
|
|
|
|
backup_items, 0);
|
|
|
|
if (confirmation_menu == nullptr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ShowMenu(std::move(confirmation_menu), true, key_handler);
|
|
|
|
}
|
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
bool ScreenRecoveryUI::IsTextVisible() {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
int visible = show_text;
|
|
|
|
return visible;
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
bool ScreenRecoveryUI::WasTextEverVisible() {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
int ever_visible = show_text_ever;
|
|
|
|
return ever_visible;
|
2011-01-25 22:15:30 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::ShowText(bool visible) {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
show_text = visible;
|
|
|
|
if (show_text) show_text_ever = true;
|
|
|
|
update_screen_locked();
|
2010-09-03 20:00:13 +02:00
|
|
|
}
|
2013-07-31 20:28:24 +02:00
|
|
|
|
2015-04-09 05:06:50 +02:00
|
|
|
void ScreenRecoveryUI::Redraw() {
|
2018-05-22 01:04:57 +02:00
|
|
|
std::lock_guard<std::mutex> lg(updateMutex);
|
2017-06-24 07:23:50 +02:00
|
|
|
update_screen_locked();
|
2013-07-31 20:28:24 +02:00
|
|
|
}
|
2015-04-10 21:47:46 +02:00
|
|
|
|
|
|
|
void ScreenRecoveryUI::KeyLongPress(int) {
|
2017-06-24 07:23:50 +02:00
|
|
|
// Redraw so that if we're in the menu, the highlight
|
|
|
|
// will change color to indicate a successful long press.
|
|
|
|
Redraw();
|
2015-04-10 21:47:46 +02:00
|
|
|
}
|
2017-02-01 08:03:10 +01:00
|
|
|
|
|
|
|
void ScreenRecoveryUI::SetLocale(const std::string& new_locale) {
|
|
|
|
locale_ = new_locale;
|
|
|
|
rtl_locale_ = false;
|
|
|
|
|
|
|
|
if (!new_locale.empty()) {
|
2018-05-09 00:58:29 +02:00
|
|
|
size_t separator = new_locale.find('-');
|
|
|
|
// lang has the language prefix prior to the separator, or full string if none exists.
|
|
|
|
std::string lang = new_locale.substr(0, separator);
|
2017-02-01 08:03:10 +01:00
|
|
|
|
|
|
|
// A bit cheesy: keep an explicit list of supported RTL languages.
|
|
|
|
if (lang == "ar" || // Arabic
|
|
|
|
lang == "fa" || // Persian (Farsi)
|
|
|
|
lang == "he" || // Hebrew (new language code)
|
|
|
|
lang == "iw" || // Hebrew (old language code)
|
|
|
|
lang == "ur") { // Urdu
|
|
|
|
rtl_locale_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-11 09:39:53 +01:00
|
|
|
|
|
|
|
int ScreenRecoveryUI::SetSwCallback(int code, int value) {
|
|
|
|
if (!is_graphics_available) { return -1; }
|
|
|
|
if (code > SW_MAX) { return -1; }
|
|
|
|
if (code != SW_LID) { return 0; }
|
|
|
|
|
|
|
|
/* detect dual display */
|
|
|
|
if (!gr_has_multiple_connectors()) { return -1; }
|
|
|
|
|
|
|
|
/* turn off all screen */
|
|
|
|
gr_fb_blank(true, DirectRenderManager::DRM_INNER);
|
|
|
|
gr_fb_blank(true, DirectRenderManager::DRM_OUTER);
|
|
|
|
gr_color(0, 0, 0, 255);
|
|
|
|
gr_clear();
|
|
|
|
|
|
|
|
/* turn on the screen */
|
|
|
|
gr_fb_blank(false, value);
|
|
|
|
gr_flip();
|
|
|
|
|
|
|
|
/* set the retation */
|
|
|
|
std::string rotation_str;
|
|
|
|
if (value == DirectRenderManager::DRM_OUTER) {
|
|
|
|
rotation_str =
|
|
|
|
android::base::GetProperty("ro.minui.second_rotation", "ROTATION_NONE");
|
|
|
|
} else {
|
|
|
|
rotation_str =
|
|
|
|
android::base::GetProperty("ro.minui.default_rotation", "ROTATION_NONE");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rotation_str == "ROTATION_RIGHT") {
|
|
|
|
gr_rotate(GRRotation::RIGHT);
|
|
|
|
} else if (rotation_str == "ROTATION_DOWN") {
|
|
|
|
gr_rotate(GRRotation::DOWN);
|
|
|
|
} else if (rotation_str == "ROTATION_LEFT") {
|
|
|
|
gr_rotate(GRRotation::LEFT);
|
|
|
|
} else { // "ROTATION_NONE" or unknown string
|
|
|
|
gr_rotate(GRRotation::NONE);
|
|
|
|
}
|
|
|
|
Redraw();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|