summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-10-07 10:10:27 +0200
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-10-07 10:10:27 +0200
commit6f5ed7b28aa47b9aa2b33c7788c25792307e088d (patch)
tree859affca35020cf3177db3ba5c80577530984ffc
parentSnap for 4380820 from b59132d66c5e77970d05d195210872987cf0e69c to pi-release (diff)
parentMerge "Don't include "error_code.h" in edify/expr.h." am: d999ced1d1 am: e196918f54 am: 3bc65953ab (diff)
downloadandroid_bootable_recovery-6f5ed7b28aa47b9aa2b33c7788c25792307e088d.tar
android_bootable_recovery-6f5ed7b28aa47b9aa2b33c7788c25792307e088d.tar.gz
android_bootable_recovery-6f5ed7b28aa47b9aa2b33c7788c25792307e088d.tar.bz2
android_bootable_recovery-6f5ed7b28aa47b9aa2b33c7788c25792307e088d.tar.lz
android_bootable_recovery-6f5ed7b28aa47b9aa2b33c7788c25792307e088d.tar.xz
android_bootable_recovery-6f5ed7b28aa47b9aa2b33c7788c25792307e088d.tar.zst
android_bootable_recovery-6f5ed7b28aa47b9aa2b33c7788c25792307e088d.zip
-rw-r--r--edify/expr.cpp9
-rw-r--r--edify/expr.h38
-rw-r--r--error_code.h6
-rw-r--r--screen_ui.cpp64
-rw-r--r--screen_ui.h11
-rw-r--r--updater/updater.cpp1
-rw-r--r--vr_ui.cpp44
-rw-r--r--vr_ui.h8
8 files changed, 125 insertions, 56 deletions
diff --git a/edify/expr.cpp b/edify/expr.cpp
index 54ab3325c..403162d6d 100644
--- a/edify/expr.cpp
+++ b/edify/expr.cpp
@@ -31,6 +31,8 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include "error_code.h"
+
// Functions should:
//
// - return a malloc()'d string
@@ -416,8 +418,5 @@ Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
return nullptr;
}
-State::State(const std::string& script, void* cookie) :
- script(script),
- cookie(cookie) {
-}
-
+State::State(const std::string& script, void* cookie)
+ : script(script), cookie(cookie), error_code(kNoError), cause_code(kNoCause) {}
diff --git a/edify/expr.h b/edify/expr.h
index 4838d20c0..32828028a 100644
--- a/edify/expr.h
+++ b/edify/expr.h
@@ -23,32 +23,34 @@
#include <string>
#include <vector>
-#include "error_code.h"
+// Forward declaration to avoid including "error_code.h".
+enum ErrorCode : int;
+enum CauseCode : int;
struct State {
- State(const std::string& script, void* cookie);
+ State(const std::string& script, void* cookie);
- // The source of the original script.
- const std::string& script;
+ // The source of the original script.
+ const std::string& script;
- // Optional pointer to app-specific data; the core of edify never
- // uses this value.
- void* cookie;
+ // Optional pointer to app-specific data; the core of edify never
+ // uses this value.
+ void* cookie;
- // The error message (if any) returned if the evaluation aborts.
- // Should be empty initially, will be either empty or a string that
- // Evaluate() returns.
- std::string errmsg;
+ // The error message (if any) returned if the evaluation aborts.
+ // Should be empty initially, will be either empty or a string that
+ // Evaluate() returns.
+ std::string errmsg;
- // error code indicates the type of failure (e.g. failure to update system image)
- // during the OTA process.
- ErrorCode error_code = kNoError;
+ // error code indicates the type of failure (e.g. failure to update system image)
+ // during the OTA process.
+ ErrorCode error_code;
- // cause code provides more detailed reason of an OTA failure (e.g. fsync error)
- // in addition to the error code.
- CauseCode cause_code = kNoCause;
+ // cause code provides more detailed reason of an OTA failure (e.g. fsync error)
+ // in addition to the error code.
+ CauseCode cause_code;
- bool is_retry = false;
+ bool is_retry = false;
};
enum ValueType {
diff --git a/error_code.h b/error_code.h
index 4e3032bc9..26b9bb40d 100644
--- a/error_code.h
+++ b/error_code.h
@@ -17,7 +17,7 @@
#ifndef _ERROR_CODE_H_
#define _ERROR_CODE_H_
-enum ErrorCode {
+enum ErrorCode : int {
kNoError = -1,
kLowBattery = 20,
kZipVerificationFailure,
@@ -30,7 +30,7 @@ enum ErrorCode {
kUpdateBinaryCommandFailure,
};
-enum CauseCode {
+enum CauseCode : int {
kNoCause = -1,
kArgsParsingFailure = 100,
kStashCreationFailure,
@@ -51,7 +51,7 @@ enum CauseCode {
kVendorFailure = 200
};
-enum UncryptErrorCode {
+enum UncryptErrorCode : int {
kUncryptNoError = -1,
kUncryptErrorPlaceholder = 50,
kUncryptTimeoutError = 100,
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 166d7b4cf..c8fb5aa75 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -149,8 +149,8 @@ int ScreenRecoveryUI::GetProgressBaseline() const {
int elements_sum = gr_get_height(loopFrames[0]) + PixelsFromDp(kLayouts[layout_][ICON]) +
gr_get_height(installing_text) + PixelsFromDp(kLayouts[layout_][TEXT]) +
gr_get_height(progressBarFill);
- int bottom_gap = (gr_fb_height() - elements_sum) / 2;
- return gr_fb_height() - bottom_gap - gr_get_height(progressBarFill);
+ int bottom_gap = (ScreenHeight() - elements_sum) / 2;
+ return ScreenHeight() - bottom_gap - gr_get_height(progressBarFill);
}
// Clear the screen and draw the currently selected background icon (if any).
@@ -159,25 +159,24 @@ void ScreenRecoveryUI::draw_background_locked() {
pagesIdentical = false;
gr_color(0, 0, 0, 255);
gr_clear();
-
if (currentIcon != NONE) {
if (max_stage != -1) {
int stage_height = gr_get_height(stageMarkerEmpty);
int stage_width = gr_get_width(stageMarkerEmpty);
- int x = (gr_fb_width() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
- int y = gr_fb_height() - stage_height - kMarginHeight;
+ int x = (ScreenWidth() - max_stage * gr_get_width(stageMarkerEmpty)) / 2;
+ int y = ScreenHeight() - stage_height - kMarginHeight;
for (int i = 0; i < max_stage; ++i) {
GRSurface* stage_surface = (i < stage) ? stageMarkerFill : stageMarkerEmpty;
- gr_blit(stage_surface, 0, 0, stage_width, stage_height, x, y);
+ DrawSurface(stage_surface, 0, 0, stage_width, stage_height, x, y);
x += stage_width;
}
}
GRSurface* text_surface = GetCurrentText();
- int text_x = (gr_fb_width() - gr_get_width(text_surface)) / 2;
+ int text_x = (ScreenWidth() - gr_get_width(text_surface)) / 2;
int text_y = GetTextBaseline();
gr_color(255, 255, 255, 255);
- gr_texticon(text_x, text_y, text_surface);
+ DrawTextIcon(text_x, text_y, text_surface);
}
}
@@ -188,21 +187,21 @@ void ScreenRecoveryUI::draw_foreground_locked() {
GRSurface* frame = GetCurrentFrame();
int frame_width = gr_get_width(frame);
int frame_height = gr_get_height(frame);
- int frame_x = (gr_fb_width() - frame_width) / 2;
+ int frame_x = (ScreenWidth() - frame_width) / 2;
int frame_y = GetAnimationBaseline();
- gr_blit(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
+ DrawSurface(frame, 0, 0, frame_width, frame_height, frame_x, frame_y);
}
if (progressBarType != EMPTY) {
int width = gr_get_width(progressBarEmpty);
int height = gr_get_height(progressBarEmpty);
- int progress_x = (gr_fb_width() - width) / 2;
+ int progress_x = (ScreenWidth() - width) / 2;
int progress_y = GetProgressBaseline();
// Erase behind the progress bar (in case this was a progress-only update)
gr_color(0, 0, 0, 255);
- gr_fill(progress_x, progress_y, width, height);
+ DrawFill(progress_x, progress_y, width, height);
if (progressBarType == DETERMINATE) {
float p = progressScopeStart + progress * progressScopeSize;
@@ -211,19 +210,19 @@ void ScreenRecoveryUI::draw_foreground_locked() {
if (rtl_locale_) {
// Fill the progress bar from right to left.
if (pos > 0) {
- gr_blit(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
- progress_y);
+ DrawSurface(progressBarFill, width - pos, 0, pos, height, progress_x + width - pos,
+ progress_y);
}
if (pos < width - 1) {
- gr_blit(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
+ DrawSurface(progressBarEmpty, 0, 0, width - pos, height, progress_x, progress_y);
}
} else {
// Fill the progress bar from left to right.
if (pos > 0) {
- gr_blit(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
+ DrawSurface(progressBarFill, 0, 0, pos, height, progress_x, progress_y);
}
if (pos < width - 1) {
- gr_blit(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
+ DrawSurface(progressBarEmpty, pos, 0, width - pos, height, progress_x + pos, progress_y);
}
}
}
@@ -335,8 +334,21 @@ void ScreenRecoveryUI::CheckBackgroundTextImages(const std::string& saved_locale
SetLocale(saved_locale);
}
+int ScreenRecoveryUI::ScreenWidth() const {
+ return gr_fb_width();
+}
+
+int ScreenRecoveryUI::ScreenHeight() const {
+ return gr_fb_height();
+}
+
+void ScreenRecoveryUI::DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx,
+ int dy) const {
+ gr_blit(surface, sx, sy, w, h, dx, dy);
+}
+
int ScreenRecoveryUI::DrawHorizontalRule(int y) const {
- gr_fill(0, y + 4, gr_fb_width(), y + 6);
+ gr_fill(0, y + 4, ScreenWidth(), y + 6);
return 8;
}
@@ -344,6 +356,14 @@ void ScreenRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) con
gr_fill(x, y, x + width, y + height);
}
+void ScreenRecoveryUI::DrawFill(int x, int y, int w, int h) const {
+ gr_fill(x, y, w, h);
+}
+
+void ScreenRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
+ gr_texticon(x, y, surface);
+}
+
int ScreenRecoveryUI::DrawTextLine(int x, int y, const char* line, bool bold) const {
gr_text(gr_sys_font(), x, y, line, bold);
return char_height_ + 4;
@@ -432,7 +452,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
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);
+ DrawHighlightBar(0, y - 2, ScreenWidth(), char_height_ + 4);
// Bold white text for the selected item.
SetColor(MENU_SEL_FG);
y += DrawTextLine(x, y, menu_[i].c_str(), true);
@@ -449,7 +469,7 @@ void ScreenRecoveryUI::draw_screen_locked() {
SetColor(LOG);
int row = text_row_;
size_t count = 0;
- for (int ty = gr_fb_height() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
+ for (int ty = ScreenHeight() - kMarginHeight - char_height_; ty >= y && count < text_rows_;
ty -= char_height_, ++count) {
DrawTextLine(kMarginWidth, ty, text_[row], false);
--row;
@@ -569,8 +589,8 @@ 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_;
+ text_rows_ = (ScreenHeight() - kMarginHeight * 2) / char_height_;
+ text_cols_ = (ScreenWidth() - kMarginWidth * 2) / char_width_;
return true;
}
diff --git a/screen_ui.h b/screen_ui.h
index 3a28a09de..f05761c42 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -124,12 +124,23 @@ class ScreenRecoveryUI : public RecoveryUI {
virtual int GetProgressBaseline() const;
virtual int GetTextBaseline() const;
+ // Returns pixel width of draw buffer.
+ virtual int ScreenWidth() const;
+ // Returns pixel height of draw buffer.
+ virtual int ScreenHeight() const;
+
// Draws a highlight bar at (x, y) - (x + width, y + height).
virtual void DrawHighlightBar(int x, int y, int width, int height) const;
// Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
virtual int DrawHorizontalRule(int y) const;
// Draws a line of text. Returns the offset it should be moving along Y-axis.
virtual int DrawTextLine(int x, int y, const char* line, bool bold) const;
+ // Draws surface portion (sx, sy, w, h) at screen location (dx, dy).
+ virtual void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const;
+ // Draws rectangle at (x, y) - (x + w, y + h).
+ virtual void DrawFill(int x, int y, int w, int h) const;
+ // Draws given surface (surface->pixel_bytes = 1) as text at (x, y).
+ virtual void DrawTextIcon(int x, int y, GRSurface* surface) 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.
diff --git a/updater/updater.cpp b/updater/updater.cpp
index e10174f71..309c309a5 100644
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -31,6 +31,7 @@
#include <ziparchive/zip_archive.h>
#include "edify/expr.h"
+#include "error_code.h"
#include "otafault/config.h"
#include "otautil/DirUtil.h"
#include "otautil/SysUtil.h"
diff --git a/vr_ui.cpp b/vr_ui.cpp
index 125167268..07cc9da59 100644
--- a/vr_ui.cpp
+++ b/vr_ui.cpp
@@ -20,16 +20,46 @@
VrRecoveryUI::VrRecoveryUI() : kStereoOffset(RECOVERY_UI_VR_STEREO_OFFSET) {}
-bool VrRecoveryUI::InitTextParams() {
- if (!ScreenRecoveryUI::InitTextParams()) return false;
- int mid_divide = gr_fb_width() / 2;
- text_cols_ = (mid_divide - kMarginWidth - kStereoOffset) / char_width_;
- return true;
+int VrRecoveryUI::ScreenWidth() const {
+ return gr_fb_width() / 2;
+}
+
+int VrRecoveryUI::ScreenHeight() const {
+ return gr_fb_height();
+}
+
+void VrRecoveryUI::DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx,
+ int dy) const {
+ gr_blit(surface, sx, sy, w, h, dx + kStereoOffset, dy);
+ gr_blit(surface, sx, sy, w, h, dx - kStereoOffset + ScreenWidth(), dy);
+}
+
+void VrRecoveryUI::DrawTextIcon(int x, int y, GRSurface* surface) const {
+ gr_texticon(x + kStereoOffset, y, surface);
+ gr_texticon(x - kStereoOffset + ScreenWidth(), y, surface);
}
int 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 + kStereoOffset, y, line, bold);
- gr_text(gr_sys_font(), x - kStereoOffset + mid_divide, y, line, bold);
+ gr_text(gr_sys_font(), x - kStereoOffset + ScreenWidth(), y, line, bold);
return char_height_ + 4;
}
+
+int VrRecoveryUI::DrawHorizontalRule(int y) const {
+ y += 4;
+ gr_fill(kMarginWidth + kStereoOffset, y, ScreenWidth() - kMarginWidth + kStereoOffset, y + 2);
+ gr_fill(ScreenWidth() + kMarginWidth - kStereoOffset, y,
+ gr_fb_width() - kMarginWidth - kStereoOffset, y + 2);
+ return y + 4;
+}
+
+void VrRecoveryUI::DrawHighlightBar(int x, int y, int width, int height) const {
+ gr_fill(kMarginWidth + kStereoOffset, y, ScreenWidth() - kMarginWidth + kStereoOffset, y + height);
+ gr_fill(ScreenWidth() + kMarginWidth - kStereoOffset, y,
+ gr_fb_width() - kMarginWidth - kStereoOffset, y + height);
+}
+
+void VrRecoveryUI::DrawFill(int x, int y, int w, int h) const {
+ gr_fill(x + kStereoOffset, y, w, h);
+ gr_fill(x - kStereoOffset + ScreenWidth(), y, w, h);
+}
diff --git a/vr_ui.h b/vr_ui.h
index d996c145f..eeb458912 100644
--- a/vr_ui.h
+++ b/vr_ui.h
@@ -28,8 +28,14 @@ class VrRecoveryUI : public ScreenRecoveryUI {
// Can vary per device depending on screen size and lens distortion.
const int kStereoOffset;
- bool InitTextParams() override;
+ int ScreenWidth() const override;
+ int ScreenHeight() const override;
+ void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const override;
+ int DrawHorizontalRule(int y) const override;
+ void DrawHighlightBar(int x, int y, int width, int height) const override;
+ void DrawFill(int x, int y, int w, int h) const override;
+ void DrawTextIcon(int x, int y, GRSurface* surface) const override;
int DrawTextLine(int x, int y, const char* line, bool bold) const override;
};