summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk1
-rw-r--r--applypatch/applypatch.c17
-rw-r--r--applypatch/applypatch.h6
-rw-r--r--applypatch/imgdiff.c57
-rw-r--r--applypatch/imgpatch.c21
-rw-r--r--applypatch/main.c23
-rw-r--r--etc/init.rc2
-rw-r--r--install.cpp28
-rw-r--r--install.h2
-rw-r--r--minui/Android.mk8
-rw-r--r--minui/graphics.c27
-rw-r--r--minui/minui.h2
-rw-r--r--minui/resources.c139
-rw-r--r--recovery.cpp83
-rw-r--r--res/images/erasing_text.pngbin0 -> 31491 bytes
-rw-r--r--res/images/error_text.pngbin0 -> 17504 bytes
-rw-r--r--res/images/installing_text.pngbin0 -> 66592 bytes
-rw-r--r--res/images/no_command_text.pngbin0 -> 40632 bytes
-rw-r--r--screen_ui.cpp121
-rw-r--r--screen_ui.h8
-rw-r--r--testdata/otasigned_f4.zipbin0 -> 5195 bytes
-rw-r--r--testdata/test_f4.pk8bin0 -> 1217 bytes
-rw-r--r--testdata/test_f4.x509.pem25
-rw-r--r--ui.h5
-rw-r--r--updater/install.c34
-rw-r--r--verifier_test.cpp53
-rwxr-xr-xverifier_test.sh15
27 files changed, 599 insertions, 78 deletions
diff --git a/Android.mk b/Android.mk
index cd368a006..f4ecdb5dd 100644
--- a/Android.mk
+++ b/Android.mk
@@ -48,6 +48,7 @@ LOCAL_STATIC_LIBRARIES := \
libcutils \
libselinux \
libstdc++ \
+ libm \
libc
ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
diff --git a/applypatch/applypatch.c b/applypatch/applypatch.c
index 00004e9a8..7b8a010e3 100644
--- a/applypatch/applypatch.c
+++ b/applypatch/applypatch.c
@@ -39,7 +39,8 @@ static int GenerateTarget(FileContents* source_file,
const char* source_filename,
const char* target_filename,
const uint8_t target_sha1[SHA_DIGEST_SIZE],
- size_t target_size);
+ size_t target_size,
+ const Value* bonus_data);
static int mtd_partitions_scanned = 0;
@@ -324,7 +325,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) {
// Save the contents of the given FileContents object under the given
// filename. Return 0 on success.
int SaveFileContents(const char* filename, const FileContents* file) {
- int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
+ int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd < 0) {
printf("failed to open \"%s\" for write: %s\n",
filename, strerror(errno));
@@ -617,7 +618,8 @@ int applypatch(const char* source_filename,
size_t target_size,
int num_patches,
char** const patch_sha1_str,
- Value** patch_data) {
+ Value** patch_data,
+ Value* bonus_data) {
printf("\napplying patch to %s\n", source_filename);
if (target_filename[0] == '-' &&
@@ -699,7 +701,7 @@ int applypatch(const char* source_filename,
int result = GenerateTarget(&source_file, source_patch_value,
&copy_file, copy_patch_value,
source_filename, target_filename,
- target_sha1, target_size);
+ target_sha1, target_size, bonus_data);
free(source_file.data);
free(copy_file.data);
@@ -713,7 +715,8 @@ static int GenerateTarget(FileContents* source_file,
const char* source_filename,
const char* target_filename,
const uint8_t target_sha1[SHA_DIGEST_SIZE],
- size_t target_size) {
+ size_t target_size,
+ const Value* bonus_data) {
int retry = 1;
SHA_CTX ctx;
int output;
@@ -843,7 +846,7 @@ static int GenerateTarget(FileContents* source_file,
strcpy(outname, target_filename);
strcat(outname, ".patch");
- output = open(outname, O_WRONLY | O_CREAT | O_TRUNC);
+ output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (output < 0) {
printf("failed to open output file %s: %s\n",
outname, strerror(errno));
@@ -867,7 +870,7 @@ static int GenerateTarget(FileContents* source_file,
} else if (header_bytes_read >= 8 &&
memcmp(header, "IMGDIFF2", 8) == 0) {
result = ApplyImagePatch(source_to_use->data, source_to_use->size,
- patch, sink, token, &ctx);
+ patch, sink, token, &ctx, bonus_data);
} else {
printf("Unknown patch file format\n");
return 1;
diff --git a/applypatch/applypatch.h b/applypatch/applypatch.h
index fb58843ba..d1a023293 100644
--- a/applypatch/applypatch.h
+++ b/applypatch/applypatch.h
@@ -55,7 +55,8 @@ int applypatch(const char* source_filename,
size_t target_size,
int num_patches,
char** const patch_sha1_str,
- Value** patch_data);
+ Value** patch_data,
+ Value* bonus_data);
int applypatch_check(const char* filename,
int num_patches,
char** const patch_sha1_str);
@@ -79,7 +80,8 @@ int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
// imgpatch.c
int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
const Value* patch,
- SinkFn sink, void* token, SHA_CTX* ctx);
+ SinkFn sink, void* token, SHA_CTX* ctx,
+ const Value* bonus_data);
// freecache.c
int MakeFreeSpaceOnCache(size_t bytes_needed);
diff --git a/applypatch/imgdiff.c b/applypatch/imgdiff.c
index 6b9ebee5c..05c4f250f 100644
--- a/applypatch/imgdiff.c
+++ b/applypatch/imgdiff.c
@@ -111,6 +111,14 @@
*
* After the header there are 'chunk count' bsdiff patches; the offset
* of each from the beginning of the file is specified in the header.
+ *
+ * This tool can take an optional file of "bonus data". This is an
+ * extra file of data that is appended to chunk #1 after it is
+ * compressed (it must be a CHUNK_DEFLATE chunk). The same file must
+ * be available (and passed to applypatch with -b) when applying the
+ * patch. This is used to reduce the size of recovery-from-boot
+ * patches by combining the boot image with recovery ramdisk
+ * information that is stored on the system partition.
*/
#include <errno.h>
@@ -772,21 +780,45 @@ void DumpChunks(ImageChunk* chunks, int num_chunks) {
}
int main(int argc, char** argv) {
- if (argc != 4 && argc != 5) {
- usage:
- printf("usage: %s [-z] <src-img> <tgt-img> <patch-file>\n",
- argv[0]);
- return 2;
- }
-
int zip_mode = 0;
- if (strcmp(argv[1], "-z") == 0) {
+ if (argc >= 2 && strcmp(argv[1], "-z") == 0) {
zip_mode = 1;
--argc;
++argv;
}
+ size_t bonus_size = 0;
+ unsigned char* bonus_data = NULL;
+ if (argc >= 3 && strcmp(argv[1], "-b") == 0) {
+ struct stat st;
+ if (stat(argv[2], &st) != 0) {
+ printf("failed to stat bonus file %s: %s\n", argv[2], strerror(errno));
+ return 1;
+ }
+ bonus_size = st.st_size;
+ bonus_data = malloc(bonus_size);
+ FILE* f = fopen(argv[2], "rb");
+ if (f == NULL) {
+ printf("failed to open bonus file %s: %s\n", argv[2], strerror(errno));
+ return 1;
+ }
+ if (fread(bonus_data, 1, bonus_size, f) != bonus_size) {
+ printf("failed to read bonus file %s: %s\n", argv[2], strerror(errno));
+ return 1;
+ }
+ fclose(f);
+
+ argc -= 2;
+ argv += 2;
+ }
+
+ if (argc != 4) {
+ usage:
+ printf("usage: %s [-z] [-b <bonus-file>] <src-img> <tgt-img> <patch-file>\n",
+ argv[0]);
+ return 2;
+ }
int num_src_chunks;
ImageChunk* src_chunks;
@@ -909,6 +941,8 @@ int main(int argc, char** argv) {
// Compute bsdiff patches for each chunk's data (the uncompressed
// data, in the case of deflate chunks).
+ DumpChunks(src_chunks, num_src_chunks);
+
printf("Construct patches for %d chunks...\n", num_tgt_chunks);
unsigned char** patch_data = malloc(num_tgt_chunks * sizeof(unsigned char*));
size_t* patch_size = malloc(num_tgt_chunks * sizeof(size_t));
@@ -923,6 +957,13 @@ int main(int argc, char** argv) {
patch_data[i] = MakePatch(src_chunks, tgt_chunks+i, patch_size+i);
}
} else {
+ if (i == 1 && bonus_data) {
+ printf(" using %d bytes of bonus data for chunk %d\n", bonus_size, i);
+ src_chunks[i].data = realloc(src_chunks[i].data, src_chunks[i].len + bonus_size);
+ memcpy(src_chunks[i].data+src_chunks[i].len, bonus_data, bonus_size);
+ src_chunks[i].len += bonus_size;
+ }
+
patch_data[i] = MakePatch(src_chunks+i, tgt_chunks+i, patch_size+i);
}
printf("patch %3d is %d bytes (of %d)\n",
diff --git a/applypatch/imgpatch.c b/applypatch/imgpatch.c
index e3ee80ac0..3a1df3872 100644
--- a/applypatch/imgpatch.c
+++ b/applypatch/imgpatch.c
@@ -37,7 +37,8 @@
*/
int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
const Value* patch,
- SinkFn sink, void* token, SHA_CTX* ctx) {
+ SinkFn sink, void* token, SHA_CTX* ctx,
+ const Value* bonus_data) {
ssize_t pos = 12;
char* header = patch->data;
if (patch->size < 12) {
@@ -123,6 +124,12 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
// Decompress the source data; the chunk header tells us exactly
// how big we expect it to be when decompressed.
+ // Note: expanded_len will include the bonus data size if
+ // the patch was constructed with bonus data. The
+ // deflation will come up 'bonus_size' bytes short; these
+ // must be appended from the bonus_data value.
+ size_t bonus_size = (i == 1 && bonus_data != NULL) ? bonus_data->size : 0;
+
unsigned char* expanded_source = malloc(expanded_len);
if (expanded_source == NULL) {
printf("failed to allocate %d bytes for expanded_source\n",
@@ -153,13 +160,19 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
printf("source inflation returned %d\n", ret);
return -1;
}
- // We should have filled the output buffer exactly.
- if (strm.avail_out != 0) {
- printf("source inflation short by %d bytes\n", strm.avail_out);
+ // We should have filled the output buffer exactly, except
+ // for the bonus_size.
+ if (strm.avail_out != bonus_size) {
+ printf("source inflation short by %d bytes\n", strm.avail_out-bonus_size);
return -1;
}
inflateEnd(&strm);
+ if (bonus_size) {
+ memcpy(expanded_source + (expanded_len - bonus_size),
+ bonus_data->data, bonus_size);
+ }
+
// Next, apply the bsdiff patch (in memory) to the uncompressed
// data.
unsigned char* uncompressed_target_data;
diff --git a/applypatch/main.c b/applypatch/main.c
index 7025a2e2e..f61db5d9e 100644
--- a/applypatch/main.c
+++ b/applypatch/main.c
@@ -100,6 +100,21 @@ static int ParsePatchArgs(int argc, char** argv,
}
int PatchMode(int argc, char** argv) {
+ Value* bonus = NULL;
+ if (argc >= 3 && strcmp(argv[1], "-b") == 0) {
+ FileContents fc;
+ if (LoadFileContents(argv[2], &fc, RETOUCH_DONT_MASK) != 0) {
+ printf("failed to load bonus file %s\n", argv[2]);
+ return 1;
+ }
+ bonus = malloc(sizeof(Value));
+ bonus->type = VAL_BLOB;
+ bonus->size = fc.size;
+ bonus->data = (char*)fc.data;
+ argc -= 2;
+ argv += 2;
+ }
+
if (argc < 6) {
return 2;
}
@@ -120,7 +135,7 @@ int PatchMode(int argc, char** argv) {
}
int result = applypatch(argv[1], argv[2], argv[3], target_size,
- num_patches, sha1s, patches);
+ num_patches, sha1s, patches, bonus);
int i;
for (i = 0; i < num_patches; ++i) {
@@ -130,6 +145,10 @@ int PatchMode(int argc, char** argv) {
free(p);
}
}
+ if (bonus) {
+ free(bonus->data);
+ free(bonus);
+ }
free(sha1s);
free(patches);
@@ -163,7 +182,7 @@ int main(int argc, char** argv) {
if (argc < 2) {
usage:
printf(
- "usage: %s <src-file> <tgt-file> <tgt-sha1> <tgt-size> "
+ "usage: %s [-b <bonus-file>] <src-file> <tgt-file> <tgt-sha1> <tgt-size> "
"[<src-sha1>:<patch> ...]\n"
" or %s -c <file> [<sha1> ...]\n"
" or %s -s <bytes>\n"
diff --git a/etc/init.rc b/etc/init.rc
index 89a161e70..abc7b318b 100644
--- a/etc/init.rc
+++ b/etc/init.rc
@@ -1,3 +1,5 @@
+import /init.recovery.${ro.hardware}.rc
+
on early-init
start ueventd
diff --git a/install.cpp b/install.cpp
index 4d73aa9b0..b8f478130 100644
--- a/install.cpp
+++ b/install.cpp
@@ -180,6 +180,12 @@ try_update_binary(const char *path, ZipArchive *zip, int* wipe_cache) {
//
// "{64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}"
//
+// For key versions newer than the original 2048-bit e=3 keys
+// supported by Android, the string is preceded by a version
+// identifier, eg:
+//
+// "v2 {64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}"
+//
// (Note that the braces and commas in this example are actual
// characters the parser expects to find in the file; the ellipses
// indicate more numbers omitted from this example.)
@@ -206,7 +212,23 @@ load_keys(const char* filename, int* numKeys) {
++*numKeys;
out = (RSAPublicKey*)realloc(out, *numKeys * sizeof(RSAPublicKey));
RSAPublicKey* key = out + (*numKeys - 1);
- if (fscanf(f, " { %i , 0x%x , { %u",
+
+ char start_char;
+ if (fscanf(f, " %c", &start_char) != 1) goto exit;
+ if (start_char == '{') {
+ // a version 1 key has no version specifier.
+ key->exponent = 3;
+ } else if (start_char == 'v') {
+ int version;
+ if (fscanf(f, "%d {", &version) != 1) goto exit;
+ if (version == 2) {
+ key->exponent = 65537;
+ } else {
+ goto exit;
+ }
+ }
+
+ if (fscanf(f, " %i , 0x%x , { %u",
&(key->len), &(key->n0inv), &(key->n[0])) != 3) {
goto exit;
}
@@ -237,6 +259,8 @@ load_keys(const char* filename, int* numKeys) {
LOGE("unexpected character between keys\n");
goto exit;
}
+
+ LOGI("read key e=%d\n", key->exponent);
}
}
@@ -253,7 +277,7 @@ exit:
static int
really_install_package(const char *path, int* wipe_cache)
{
- ui->SetBackground(RecoveryUI::INSTALLING);
+ ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
ui->Print("Finding update package...\n");
ui->SetProgressType(RecoveryUI::INDETERMINATE);
LOGI("Update location: %s\n", path);
diff --git a/install.h b/install.h
index 1943f02d3..2ada529ef 100644
--- a/install.h
+++ b/install.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-enum { INSTALL_SUCCESS, INSTALL_ERROR, INSTALL_CORRUPT };
+enum { INSTALL_SUCCESS, INSTALL_ERROR, INSTALL_CORRUPT, INSTALL_NONE };
// Install the package specified by root_path. If INSTALL_SUCCESS is
// returned and *wipe_cache is true on exit, caller should wipe the
// cache partition.
diff --git a/minui/Android.mk b/minui/Android.mk
index 4c4d7c7b6..285ac62bf 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -9,10 +9,14 @@ LOCAL_C_INCLUDES +=\
LOCAL_MODULE := libminui
-ifeq ($(TARGET_RECOVERY_PIXEL_FORMAT),"RGBX_8888")
+# This used to compare against values in double-quotes (which are just
+# ordinary characters in this context). Strip double-quotes from the
+# value so that either will work.
+
+ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBX_8888)
LOCAL_CFLAGS += -DRECOVERY_RGBX
endif
-ifeq ($(TARGET_RECOVERY_PIXEL_FORMAT),"BGRA_8888")
+ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),BGRA_8888)
LOCAL_CFLAGS += -DRECOVERY_BGRA
endif
diff --git a/minui/graphics.c b/minui/graphics.c
index 296e2e078..287878e92 100644
--- a/minui/graphics.c
+++ b/minui/graphics.c
@@ -44,6 +44,8 @@
#define PIXEL_SIZE 2
#endif
+#define NUM_BUFFERS 2
+
typedef struct {
GGLSurface texture;
unsigned cwidth;
@@ -54,7 +56,7 @@ typedef struct {
static GRFont *gr_font = 0;
static GGLContext *gr_context = 0;
static GGLSurface gr_font_texture;
-static GGLSurface gr_framebuffer[2];
+static GGLSurface gr_framebuffer[NUM_BUFFERS];
static GGLSurface gr_mem_surface;
static unsigned gr_active_fb = 0;
static unsigned double_buffering = 0;
@@ -169,7 +171,7 @@ static void get_memory_surface(GGLSurface* ms) {
static void set_active_framebuffer(unsigned n)
{
if (n > 1 || !double_buffering) return;
- vi.yres_virtual = vi.yres * PIXEL_SIZE;
+ vi.yres_virtual = vi.yres * NUM_BUFFERS;
vi.yoffset = n * vi.yres;
vi.bits_per_pixel = PIXEL_SIZE * 8;
if (ioctl(gr_fb_fd, FBIOPUT_VSCREENINFO, &vi) < 0) {
@@ -242,6 +244,25 @@ int gr_text(int x, int y, const char *s)
return x;
}
+void gr_texticon(int x, int y, gr_surface icon) {
+ if (gr_context == NULL || icon == NULL) {
+ return;
+ }
+ GGLContext* gl = gr_context;
+
+ gl->bindTexture(gl, (GGLSurface*) icon);
+ gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
+ gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
+ gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
+ gl->enable(gl, GGL_TEXTURE_2D);
+
+ int w = gr_get_width(icon);
+ int h = gr_get_height(icon);
+
+ gl->texCoord2i(gl, -x, -y);
+ gl->recti(gl, x, y, x+gr_get_width(icon), y+gr_get_height(icon));
+}
+
void gr_fill(int x, int y, int w, int h)
{
GGLContext *gl = gr_context;
@@ -250,7 +271,7 @@ void gr_fill(int x, int y, int w, int h)
}
void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy) {
- if (gr_context == NULL) {
+ if (gr_context == NULL || source == NULL) {
return;
}
GGLContext *gl = gr_context;
diff --git a/minui/minui.h b/minui/minui.h
index 74da4e9c0..767ffcb50 100644
--- a/minui/minui.h
+++ b/minui/minui.h
@@ -38,6 +38,7 @@ void gr_fb_blank(bool blank);
void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
void gr_fill(int x, int y, int w, int h);
int gr_text(int x, int y, const char *s);
+ void gr_texticon(int x, int y, gr_surface icon);
int gr_measure(const char *s);
void gr_font_size(int *x, int *y);
@@ -71,6 +72,7 @@ void ev_dispatch(void);
// Returns 0 if no error, else negative.
int res_create_surface(const char* name, gr_surface* pSurface);
+int res_create_localized_surface(const char* name, gr_surface* pSurface);
void res_free_surface(gr_surface surface);
#ifdef __cplusplus
diff --git a/minui/resources.c b/minui/resources.c
index 5e2062192..065f4317e 100644
--- a/minui/resources.c
+++ b/minui/resources.c
@@ -33,6 +33,8 @@
#include "minui.h"
+extern char* locale;
+
// libpng gives "undefined reference to 'pow'" errors, and I have no
// idea how to convince the build system to link with -lm. We don't
// need this functionality (it's used for gamma adjustment) so provide
@@ -173,6 +175,143 @@ exit:
return result;
}
+static int matches_locale(const char* loc) {
+ if (locale == NULL) return 0;
+
+ if (strcmp(loc, locale) == 0) return 1;
+
+ // if loc does *not* have an underscore, and it matches the start
+ // of locale, and the next character in locale *is* an underscore,
+ // that's a match. For instance, loc == "en" matches locale ==
+ // "en_US".
+
+ int i;
+ for (i = 0; loc[i] != 0 && loc[i] != '_'; ++i);
+ if (loc[i] == '_') return 0;
+
+ return (strncmp(locale, loc, i) == 0 && locale[i] == '_');
+}
+
+int res_create_localized_surface(const char* name, gr_surface* pSurface) {
+ char resPath[256];
+ GGLSurface* surface = NULL;
+ int result = 0;
+ unsigned char header[8];
+ png_structp png_ptr = NULL;
+ png_infop info_ptr = NULL;
+
+ *pSurface = NULL;
+
+ snprintf(resPath, sizeof(resPath)-1, "/res/images/%s.png", name);
+ resPath[sizeof(resPath)-1] = '\0';
+ FILE* fp = fopen(resPath, "rb");
+ if (fp == NULL) {
+ result = -1;
+ goto exit;
+ }
+
+ size_t bytesRead = fread(header, 1, sizeof(header), fp);
+ if (bytesRead != sizeof(header)) {
+ result = -2;
+ goto exit;
+ }
+
+ if (png_sig_cmp(header, 0, sizeof(header))) {
+ result = -3;
+ goto exit;
+ }
+
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!png_ptr) {
+ result = -4;
+ goto exit;
+ }
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
+ result = -5;
+ goto exit;
+ }
+
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ result = -6;
+ goto exit;
+ }
+
+ png_init_io(png_ptr, fp);
+ png_set_sig_bytes(png_ptr, sizeof(header));
+ png_read_info(png_ptr, info_ptr);
+
+ size_t width = info_ptr->width;
+ size_t height = info_ptr->height;
+ size_t stride = 4 * width;
+
+ int color_type = info_ptr->color_type;
+ int bit_depth = info_ptr->bit_depth;
+ int channels = info_ptr->channels;
+
+ if (!(bit_depth == 8 &&
+ (channels == 1 && color_type == PNG_COLOR_TYPE_GRAY))) {
+ return -7;
+ goto exit;
+ }
+
+ unsigned char* row = malloc(width);
+ int y;
+ for (y = 0; y < height; ++y) {
+ png_read_row(png_ptr, row, NULL);
+ int w = (row[1] << 8) | row[0];
+ int h = (row[3] << 8) | row[2];
+ int len = row[4];
+ char* loc = row+5;
+
+ if (y+1+h >= height || matches_locale(loc)) {
+ printf(" %20s: %s (%d x %d @ %d)\n", name, loc, w, h, y);
+
+ surface = malloc(sizeof(GGLSurface));
+ if (surface == NULL) {
+ result = -8;
+ goto exit;
+ }
+ unsigned char* pData = malloc(w*h);
+
+ surface->version = sizeof(GGLSurface);
+ surface->width = w;
+ surface->height = h;
+ surface->stride = w; /* Yes, pixels, not bytes */
+ surface->data = pData;
+ surface->format = GGL_PIXEL_FORMAT_A_8;
+
+ int i;
+ for (i = 0; i < h; ++i, ++y) {
+ png_read_row(png_ptr, row, NULL);
+ memcpy(pData + i*w, row, w);
+ }
+
+ *pSurface = (gr_surface) surface;
+ break;
+ } else {
+ int i;
+ for (i = 0; i < h; ++i, ++y) {
+ png_read_row(png_ptr, row, NULL);
+ }
+ }
+ }
+
+exit:
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+
+ if (fp != NULL) {
+ fclose(fp);
+ }
+ if (result < 0) {
+ if (surface) {
+ free(surface);
+ }
+ }
+ return result;
+}
+
void res_free_surface(gr_surface surface) {
GGLSurface* pSurface = (GGLSurface*) surface;
if (pSurface) {
diff --git a/recovery.cpp b/recovery.cpp
index 707eec354..92aa50372 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -54,6 +54,7 @@ static const struct option OPTIONS[] = {
{ "wipe_cache", no_argument, NULL, 'c' },
{ "show_text", no_argument, NULL, 't' },
{ "just_exit", no_argument, NULL, 'x' },
+ { "locale", required_argument, NULL, 'l' },
{ NULL, 0, NULL, 0 },
};
@@ -62,6 +63,7 @@ static const char *INTENT_FILE = "/cache/recovery/intent";
static const char *LOG_FILE = "/cache/recovery/log";
static const char *LAST_LOG_FILE = "/cache/recovery/last_log";
static const char *LAST_INSTALL_FILE = "/cache/recovery/last_install";
+static const char *LOCALE_FILE = "/cache/recovery/last_locale";
static const char *CACHE_ROOT = "/cache";
static const char *SDCARD_ROOT = "/sdcard";
static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log";
@@ -69,6 +71,7 @@ static const char *TEMPORARY_INSTALL_FILE = "/tmp/last_install";
static const char *SIDELOAD_TEMP_DIR = "/tmp/sideload";
RecoveryUI* ui = NULL;
+char* locale = NULL;
/*
* The recovery tool communicates with the main system through /cache files.
@@ -274,6 +277,18 @@ finish_recovery(const char *send_intent) {
}
}
+ // 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 != NULL) {
+ LOGI("Saving locale \"%s\"\n", locale);
+ FILE* fp = fopen_path(LOCALE_FILE, "w");
+ fwrite(locale, 1, strlen(locale), fp);
+ fflush(fp);
+ fsync(fileno(fp));
+ check_and_fclose(fp, LOCALE_FILE);
+ }
+
// Copy logs to cache so the system can find out what happened.
copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true);
copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false);
@@ -300,7 +315,7 @@ finish_recovery(const char *send_intent) {
static int
erase_volume(const char *volume) {
- ui->SetBackground(RecoveryUI::INSTALLING);
+ ui->SetBackground(RecoveryUI::ERASING);
ui->SetProgressType(RecoveryUI::INDETERMINATE);
ui->Print("Formatting %s...\n", volume);
@@ -653,11 +668,22 @@ wipe_data(int confirm, Device* device) {
}
static void
-prompt_and_wait(Device* device) {
+prompt_and_wait(Device* device, int status) {
const char* const* headers = prepend_title(device->GetMenuHeaders());
for (;;) {
finish_recovery(NULL);
+ switch (status) {
+ case INSTALL_SUCCESS:
+ case INSTALL_NONE:
+ ui->SetBackground(RecoveryUI::NO_COMMAND);
+ break;
+
+ case INSTALL_ERROR:
+ case INSTALL_CORRUPT:
+ ui->SetBackground(RecoveryUI::ERROR);
+ break;
+ }
ui->SetProgressType(RecoveryUI::EMPTY);
int chosen_item = get_menu_selection(headers, device->GetMenuItems(), 0, 0, device);
@@ -667,7 +693,6 @@ prompt_and_wait(Device* device) {
// statement below.
chosen_item = device->InvokeMenuItem(chosen_item);
- int status;
int wipe_cache;
switch (chosen_item) {
case Device::REBOOT:
@@ -679,6 +704,7 @@ prompt_and_wait(Device* device) {
break;
case Device::WIPE_CACHE:
+ ui->ShowText(false);
ui->Print("\n-- Wiping cache...\n");
erase_volume("/cache");
ui->Print("Cache wipe complete.\n");
@@ -757,6 +783,25 @@ print_property(const char *key, const char *name, void *cookie) {
printf("%s=%s\n", key, name);
}
+static void
+load_locale_from_cache() {
+ FILE* fp = fopen_path(LOCALE_FILE, "r");
+ char buffer[80];
+ if (fp != NULL) {
+ fgets(buffer, sizeof(buffer), fp);
+ int j = 0;
+ unsigned int i;
+ for (i = 0; i < sizeof(buffer) && buffer[i]; ++i) {
+ if (!isspace(buffer[i])) {
+ buffer[j++] = buffer[i];
+ }
+ }
+ buffer[j] = 0;
+ locale = strdup(buffer);
+ check_and_fclose(fp, LOCALE_FILE);
+ }
+}
+
int
main(int argc, char **argv) {
time_t start = time(NULL);
@@ -779,18 +824,13 @@ main(int argc, char **argv) {
printf("Starting recovery on %s", ctime(&start));
- Device* device = make_device();
- ui = device->GetUI();
-
- ui->Init();
- ui->SetBackground(RecoveryUI::NONE);
load_volume_table();
get_args(&argc, &argv);
int previous_runs = 0;
const char *send_intent = NULL;
const char *update_package = NULL;
- int wipe_data = 0, wipe_cache = 0;
+ int wipe_data = 0, wipe_cache = 0, show_text = 0;
bool just_exit = false;
int arg;
@@ -801,14 +841,28 @@ main(int argc, char **argv) {
case 'u': update_package = optarg; break;
case 'w': wipe_data = wipe_cache = 1; break;
case 'c': wipe_cache = 1; break;
- case 't': ui->ShowText(true); break;
+ case 't': show_text = 1; break;
case 'x': just_exit = true; break;
+ case 'l': locale = optarg; break;
case '?':
LOGE("Invalid command argument\n");
continue;
}
}
+ if (locale == NULL) {
+ load_locale_from_cache();
+ }
+ printf("locale is [%s]\n", locale);
+
+ Device* device = make_device();
+ ui = device->GetUI();
+
+ ui->Init();
+ ui->SetLocale(locale);
+ ui->SetBackground(RecoveryUI::NONE);
+ if (show_text) ui->ShowText(true);
+
struct selinux_opt seopts[] = {
{ SELABEL_OPT_PATH, "/file_contexts" }
};
@@ -866,12 +920,15 @@ main(int argc, char **argv) {
if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
if (status != INSTALL_SUCCESS) ui->Print("Cache wipe failed.\n");
} else if (!just_exit) {
- status = INSTALL_ERROR; // No command specified
+ status = INSTALL_NONE; // No command specified
+ ui->SetBackground(RecoveryUI::NO_COMMAND);
}
- if (status != INSTALL_SUCCESS) ui->SetBackground(RecoveryUI::ERROR);
+ if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) {
+ ui->SetBackground(RecoveryUI::ERROR);
+ }
if (status != INSTALL_SUCCESS || ui->IsTextVisible()) {
- prompt_and_wait(device);
+ prompt_and_wait(device, status);
}
// Otherwise, get ready to boot the main system...
diff --git a/res/images/erasing_text.png b/res/images/erasing_text.png
new file mode 100644
index 000000000..441768a0c
--- /dev/null
+++ b/res/images/erasing_text.png
Binary files differ
diff --git a/res/images/error_text.png b/res/images/error_text.png
new file mode 100644
index 000000000..4ac6391ff
--- /dev/null
+++ b/res/images/error_text.png
Binary files differ
diff --git a/res/images/installing_text.png b/res/images/installing_text.png
new file mode 100644
index 000000000..e1ac819e6
--- /dev/null
+++ b/res/images/installing_text.png
Binary files differ
diff --git a/res/images/no_command_text.png b/res/images/no_command_text.png
new file mode 100644
index 000000000..a688f0935
--- /dev/null
+++ b/res/images/no_command_text.png
Binary files differ
diff --git a/screen_ui.cpp b/screen_ui.cpp
index 3c6c3ae25..e36fa3d8f 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -52,6 +52,7 @@ static double now() {
ScreenRecoveryUI::ScreenRecoveryUI() :
currentIcon(NONE),
installingFrame(0),
+ rtl_locale(false),
progressBarType(EMPTY),
progressScopeStart(0),
progressScopeSize(0),
@@ -78,7 +79,9 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
indeterminate_frames(6),
installing_frames(7),
install_overlay_offset_x(13),
- install_overlay_offset_y(190) {
+ install_overlay_offset_y(190),
+ overlay_offset_x(-1),
+ overlay_offset_y(-1) {
pthread_mutex_init(&updateMutex, NULL);
self = this;
}
@@ -89,12 +92,12 @@ ScreenRecoveryUI::ScreenRecoveryUI() :
// animation. Does nothing if no overlay animation is defined.
// Should only be called with updateMutex locked.
void ScreenRecoveryUI::draw_install_overlay_locked(int frame) {
- if (installationOverlay == NULL) return;
+ if (installationOverlay == NULL || overlay_offset_x < 0) return;
gr_surface surface = installationOverlay[frame];
int iconWidth = gr_get_width(surface);
int iconHeight = gr_get_height(surface);
gr_blit(surface, 0, 0, iconWidth, iconHeight,
- install_overlay_offset_x, install_overlay_offset_y);
+ overlay_offset_x, overlay_offset_y);
}
// Clear the screen and draw the currently selected background icon (if any).
@@ -107,14 +110,26 @@ void ScreenRecoveryUI::draw_background_locked(Icon icon)
if (icon) {
gr_surface surface = backgroundIcon[icon];
+ gr_surface text_surface = backgroundText[icon];
+
int iconWidth = gr_get_width(surface);
int iconHeight = gr_get_height(surface);
+ int textWidth = gr_get_width(text_surface);
+ int textHeight = gr_get_height(text_surface);
+
int iconX = (gr_fb_width() - iconWidth) / 2;
- int iconY = (gr_fb_height() - iconHeight) / 2;
+ int iconY = (gr_fb_height() - (iconHeight+textHeight+40)) / 2;
+
+ int textX = (gr_fb_width() - textWidth) / 2;
+ int textY = ((gr_fb_height() - (iconHeight+textHeight+40)) / 2) + iconHeight + 40;
+
gr_blit(surface, 0, 0, iconWidth, iconHeight, iconX, iconY);
- if (icon == INSTALLING) {
+ if (icon == INSTALLING_UPDATE || icon == ERASING) {
draw_install_overlay_locked(installingFrame);
}
+
+ gr_color(255, 255, 255, 255);
+ gr_texticon(textX, textY, text_surface);
}
}
@@ -124,12 +139,12 @@ void ScreenRecoveryUI::draw_progress_locked()
{
if (currentIcon == ERROR) return;
- if (currentIcon == INSTALLING) {
+ if (currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) {
draw_install_overlay_locked(installingFrame);
}
if (progressBarType != EMPTY) {
- int iconHeight = gr_get_height(backgroundIcon[INSTALLING]);
+ int iconHeight = gr_get_height(backgroundIcon[INSTALLING_UPDATE]);
int width = gr_get_width(progressBarEmpty);
int height = gr_get_height(progressBarEmpty);
@@ -144,18 +159,35 @@ void ScreenRecoveryUI::draw_progress_locked()
float p = progressScopeStart + progress * progressScopeSize;
int pos = (int) (p * width);
- if (pos > 0) {
- gr_blit(progressBarFill, 0, 0, pos, height, dx, dy);
- }
- if (pos < width-1) {
- gr_blit(progressBarEmpty, pos, 0, width-pos, height, dx+pos, dy);
+ if (rtl_locale) {
+ // Fill the progress bar from right to left.
+ if (pos > 0) {
+ gr_blit(progressBarFill, width-pos, 0, pos, height, dx+width-pos, dy);
+ }
+ if (pos < width-1) {
+ gr_blit(progressBarEmpty, 0, 0, width-pos, height, dx, dy);
+ }
+ } else {
+ // Fill the progress bar from left to right.
+ if (pos > 0) {
+ gr_blit(progressBarFill, 0, 0, pos, height, dx, dy);
+ }
+ if (pos < width-1) {
+ gr_blit(progressBarEmpty, pos, 0, width-pos, height, dx+pos, dy);
+ }
}
}
if (progressBarType == INDETERMINATE) {
static int frame = 0;
gr_blit(progressBarIndeterminate[frame], 0, 0, width, height, dx, dy);
- frame = (frame + 1) % indeterminate_frames;
+ // in RTL locales, we run the animation backwards, which
+ // makes the spinner spin the other way.
+ if (rtl_locale) {
+ frame = (frame + indeterminate_frames - 1) % indeterminate_frames;
+ } else {
+ frame = (frame + 1) % indeterminate_frames;
+ }
}
}
}
@@ -242,7 +274,8 @@ void ScreenRecoveryUI::progress_loop() {
// update the installation animation, if active
// skip this if we have a text overlay (too expensive to update)
- if (currentIcon == INSTALLING && installing_frames > 0 && !show_text) {
+ if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) &&
+ installing_frames > 0 && !show_text) {
installingFrame = (installingFrame + 1) % installing_frames;
redraw = 1;
}
@@ -283,6 +316,13 @@ void ScreenRecoveryUI::LoadBitmap(const char* filename, gr_surface* surface) {
}
}
+void ScreenRecoveryUI::LoadLocalizedBitmap(const char* filename, gr_surface* surface) {
+ int result = res_create_localized_surface(filename, surface);
+ if (result < 0) {
+ LOGE("missing bitmap %s\n(Code %d)\n", filename, result);
+ }
+}
+
void ScreenRecoveryUI::Init()
{
gr_init();
@@ -295,11 +335,19 @@ void ScreenRecoveryUI::Init()
text_cols = gr_fb_width() / CHAR_WIDTH;
if (text_cols > kMaxCols - 1) text_cols = kMaxCols - 1;
- LoadBitmap("icon_installing", &backgroundIcon[INSTALLING]);
+ LoadBitmap("icon_installing", &backgroundIcon[INSTALLING_UPDATE]);
+ backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE];
LoadBitmap("icon_error", &backgroundIcon[ERROR]);
+ backgroundIcon[NO_COMMAND] = backgroundIcon[ERROR];
+
LoadBitmap("progress_empty", &progressBarEmpty);
LoadBitmap("progress_fill", &progressBarFill);
+ LoadLocalizedBitmap("installing_text", &backgroundText[INSTALLING_UPDATE]);
+ LoadLocalizedBitmap("erasing_text", &backgroundText[ERASING]);
+ LoadLocalizedBitmap("no_command_text", &backgroundText[NO_COMMAND]);
+ LoadLocalizedBitmap("error_text", &backgroundText[ERROR]);
+
int i;
progressBarIndeterminate = (gr_surface*)malloc(indeterminate_frames *
@@ -321,14 +369,6 @@ void ScreenRecoveryUI::Init()
sprintf(filename, "icon_installing_overlay%02d", i+1);
LoadBitmap(filename, installationOverlay+i);
}
-
- // Adjust the offset to account for the positioning of the
- // base image on the screen.
- if (backgroundIcon[INSTALLING] != NULL) {
- gr_surface bg = backgroundIcon[INSTALLING];
- install_overlay_offset_x += (gr_fb_width() - gr_get_width(bg)) / 2;
- install_overlay_offset_y += (gr_fb_height() - gr_get_height(bg)) / 2;
- }
} else {
installationOverlay = NULL;
}
@@ -338,11 +378,46 @@ void ScreenRecoveryUI::Init()
RecoveryUI::Init();
}
+void ScreenRecoveryUI::SetLocale(const char* locale) {
+ if (locale) {
+ char* lang = strdup(locale);
+ for (char* p = lang; *p; ++p) {
+ if (*p == '_') {
+ *p = '\0';
+ break;
+ }
+ }
+
+ // A bit cheesy: keep an explicit list of supported languages
+ // that are RTL.
+ if (strcmp(lang, "ar") == 0 || // Arabic
+ strcmp(lang, "fa") == 0 || // Persian (Farsi)
+ strcmp(lang, "he") == 0 || // Hebrew (new language code)
+ strcmp(lang, "iw") == 0 || // Hebrew (old language code)
+ strcmp(lang, "ur") == 0) { // Urdu
+ rtl_locale = true;
+ }
+ free(lang);
+ }
+}
+
void ScreenRecoveryUI::SetBackground(Icon icon)
{
pthread_mutex_lock(&updateMutex);
+
+ // Adjust the offset to account for the positioning of the
+ // base image on the screen.
+ if (backgroundIcon[icon] != NULL) {
+ gr_surface bg = backgroundIcon[icon];
+ gr_surface text = backgroundText[icon];
+ overlay_offset_x = install_overlay_offset_x + (gr_fb_width() - gr_get_width(bg)) / 2;
+ overlay_offset_y = install_overlay_offset_y +
+ (gr_fb_height() - (gr_get_height(bg) + gr_get_height(text) + 40)) / 2;
+ }
+
currentIcon = icon;
update_screen_locked();
+
pthread_mutex_unlock(&updateMutex);
}
diff --git a/screen_ui.h b/screen_ui.h
index 34929ee1a..80051724b 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -29,6 +29,7 @@ class ScreenRecoveryUI : public RecoveryUI {
ScreenRecoveryUI();
void Init();
+ void SetLocale(const char* locale);
// overall recovery state ("background image")
void SetBackground(Icon icon);
@@ -55,9 +56,11 @@ class ScreenRecoveryUI : public RecoveryUI {
private:
Icon currentIcon;
int installingFrame;
+ bool rtl_locale;
pthread_mutex_t updateMutex;
- gr_surface backgroundIcon[3];
+ gr_surface backgroundIcon[5];
+ gr_surface backgroundText[5];
gr_surface *installationOverlay;
gr_surface *progressBarIndeterminate;
gr_surface progressBarEmpty;
@@ -92,6 +95,7 @@ class ScreenRecoveryUI : public RecoveryUI {
int indeterminate_frames;
int installing_frames;
int install_overlay_offset_x, install_overlay_offset_y;
+ int overlay_offset_x, overlay_offset_y;
void draw_install_overlay_locked(int frame);
void draw_background_locked(Icon icon);
@@ -104,7 +108,7 @@ class ScreenRecoveryUI : public RecoveryUI {
void progress_loop();
void LoadBitmap(const char* filename, gr_surface* surface);
-
+ void LoadLocalizedBitmap(const char* filename, gr_surface* surface);
};
#endif // RECOVERY_UI_H
diff --git a/testdata/otasigned_f4.zip b/testdata/otasigned_f4.zip
new file mode 100644
index 000000000..dd1e4dd40
--- /dev/null
+++ b/testdata/otasigned_f4.zip
Binary files differ
diff --git a/testdata/test_f4.pk8 b/testdata/test_f4.pk8
new file mode 100644
index 000000000..3052613c5
--- /dev/null
+++ b/testdata/test_f4.pk8
Binary files differ
diff --git a/testdata/test_f4.x509.pem b/testdata/test_f4.x509.pem
new file mode 100644
index 000000000..814abcf99
--- /dev/null
+++ b/testdata/test_f4.x509.pem
@@ -0,0 +1,25 @@
+-----BEGIN CERTIFICATE-----
+MIIENjCCAx6gAwIBAgIJAKhkCO1dDYMaMA0GCSqGSIb3DQEBBQUAMG8xCzAJBgNV
+BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBW
+aWV3MQ8wDQYDVQQKEwZHb29nbGUxEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMT
+B1Rlc3QxMjMwHhcNMTIwNzI1MTg1NzAzWhcNMzkxMjExMTg1NzAzWjBvMQswCQYD
+VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4g
+VmlldzEPMA0GA1UEChMGR29vZ2xlMRAwDgYDVQQLEwdBbmRyb2lkMRAwDgYDVQQD
+EwdUZXN0MTIzMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu8WwMN9x
+4Mz7YgkG2qy9g8/kl5ZoYrUM0ApHhaITAcL7RXLZaNipCf0w/YjYTQgj+75MK30x
+TsnPeWNOEwA62gkHrZyyWfxBRO6kBYuIuI4roGDBJOmKQ1OEaDeIRKu7q5V8v3Cs
+0wQDAQWTbhpxBZr9UYFgJUg8XWBfPrGJLVwsoiy4xrMhoTlNZKHfwOMMqVtSHkZX
+qydYrcIzyjh+TO0e/xSNQ8MMRRbtqWgCHN6Rzhog3IHZu0RaPoukariopjXM/s0V
+gTm3rHDHCOpna2pNblyiFlvbkoCs769mtNmx/yrDShO30jg/xaG8RypKDvTChzOT
+oWW/XQ5VEXjbHwIDAQABo4HUMIHRMB0GA1UdDgQWBBRlT2dEZJY1tmUM8mZ0xnhS
+GdD9TTCBoQYDVR0jBIGZMIGWgBRlT2dEZJY1tmUM8mZ0xnhSGdD9TaFzpHEwbzEL
+MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDU1vdW50
+YWluIFZpZXcxDzANBgNVBAoTBkdvb2dsZTEQMA4GA1UECxMHQW5kcm9pZDEQMA4G
+A1UEAxMHVGVzdDEyM4IJAKhkCO1dDYMaMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcN
+AQEFBQADggEBAHqnXHtE+h3hvGmHh24GT51vGAYLc68WUUtCVlMIU85zQ757wlxZ
+BmRypZ1i9hSqnXj5n+mETV5rFX3g2gvdAPVHkRycuDa2aUdZSE8cW4Z6qYFx6SaD
+e+3SyXokpUquW64RuHJrf/yd/FnGjneBe3Qpm2reuzGWNH90qZGdbsfNaCm5kx2L
+X+ZNHM3CcGMLaphY5++sM0JxSEcju5EK33ZYgLf4YdlbyMp8LDFVNd7ff0SFi9fF
+0ZlAsJWoS3QmVCj2744BFdsCu7UHpnYpG6X3MT4SHAawdOaT5zSuaCl2xx6H0O7t
+w/Fvbl/KVD1ZmLHgBKjDMNSh0OB9mSsDWpw=
+-----END CERTIFICATE-----
diff --git a/ui.h b/ui.h
index 0d3b7bb98..acb57663e 100644
--- a/ui.h
+++ b/ui.h
@@ -30,8 +30,11 @@ class RecoveryUI {
// Initialize the object; called before anything else.
virtual void Init();
+ // After calling Init(), you can tell the UI what locale it is operating in.
+ virtual void SetLocale(const char* locale) { }
+
// Set the overall recovery state ("background image").
- enum Icon { NONE, INSTALLING, ERROR };
+ enum Icon { NONE, INSTALLING_UPDATE, ERASING, NO_COMMAND, ERROR };
virtual void SetBackground(Icon icon) = 0;
// --- progress indicator ---
diff --git a/updater/install.c b/updater/install.c
index 9ace12541..19054236c 100644
--- a/updater/install.c
+++ b/updater/install.c
@@ -452,6 +452,26 @@ Value* PackageExtractFileFn(const char* name, State* state,
}
}
+// Create all parent directories of name, if necessary.
+static int make_parents(char* name) {
+ char* p;
+ for (p = name + (strlen(name)-1); p > name; --p) {
+ if (*p != '/') continue;
+ *p = '\0';
+ if (make_parents(name) < 0) return -1;
+ int result = mkdir(name, 0700);
+ if (result == 0) fprintf(stderr, "symlink(): created [%s]\n", name);
+ *p = '/';
+ if (result == 0 || errno == EEXIST) {
+ // successfully created or already existed; we're done
+ return 0;
+ } else {
+ fprintf(stderr, "failed to mkdir %s: %s\n", name, strerror(errno));
+ return -1;
+ }
+ }
+ return 0;
+}
// symlink target src1 src2 ...
// unlinks any previously existing src1, src2, etc before creating symlinks.
@@ -479,6 +499,11 @@ Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) {
++bad;
}
}
+ if (make_parents(srcs[i])) {
+ fprintf(stderr, "%s: failed to symlink %s to %s: making parents failed\n",
+ name, srcs[i], target);
+ ++bad;
+ }
if (symlink(target, srcs[i]) < 0) {
fprintf(stderr, "%s: failed to symlink %s to %s: %s\n",
name, srcs[i], target, strerror(errno));
@@ -500,7 +525,8 @@ Value* SetPermFn(const char* name, State* state, int argc, Expr* argv[]) {
int min_args = 4 + (recursive ? 1 : 0);
if (argc < min_args) {
- return ErrorAbort(state, "%s() expects %d+ args, got %d", name, argc);
+ return ErrorAbort(state, "%s() expects %d+ args, got %d",
+ name, min_args, argc);
}
char** args = ReadVarArgs(state, argc, argv);
@@ -622,7 +648,7 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
buffer = malloc(st.st_size+1);
if (buffer == NULL) {
- ErrorAbort(state, "%s: failed to alloc %d bytes", name, st.st_size+1);
+ ErrorAbort(state, "%s: failed to alloc %lld bytes", name, st.st_size+1);
goto done;
}
@@ -634,7 +660,7 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
}
if (fread(buffer, 1, st.st_size, f) != st.st_size) {
- ErrorAbort(state, "%s: failed to read %d bytes from %s",
+ ErrorAbort(state, "%s: failed to read %lld bytes from %s",
name, st.st_size+1, filename);
fclose(f);
goto done;
@@ -871,7 +897,7 @@ Value* ApplyPatchFn(const char* name, State* state, int argc, Expr* argv[]) {
int result = applypatch(source_filename, target_filename,
target_sha1, target_size,
- patchcount, patch_sha_str, patches);
+ patchcount, patch_sha_str, patches, NULL);
for (i = 0; i < patchcount; ++i) {
FreeValue(patches[i]);
diff --git a/verifier_test.cpp b/verifier_test.cpp
index fe5519d79..01d092680 100644
--- a/verifier_test.cpp
+++ b/verifier_test.cpp
@@ -56,7 +56,45 @@ RSAPublicKey test_key =
9135381, 1625809335, -1490225159, -1342673351,
1117190829, -57654514, 1825108855, -1281819325,
1111251351, -1726129724, 1684324211, -1773988491,
- 367251975, 810756730, -1941182952, 1175080310 }
+ 367251975, 810756730, -1941182952, 1175080310 },
+ 3
+ };
+
+RSAPublicKey test_f4_key =
+ { 64, 0xc9bd1f21,
+ { 293133087u, 3210546773u, 865313125u, 250921607u,
+ 3158780490u, 943703457u, 1242806226u, 2986289859u,
+ 2942743769u, 2457906415u, 2719374299u, 1783459420u,
+ 149579627u, 3081531591u, 3440738617u, 2788543742u,
+ 2758457512u, 1146764939u, 3699497403u, 2446203424u,
+ 1744968926u, 1159130537u, 2370028300u, 3978231572u,
+ 3392699980u, 1487782451u, 1180150567u, 2841334302u,
+ 3753960204u, 961373345u, 3333628321u, 748825784u,
+ 2978557276u, 1566596926u, 1613056060u, 2600292737u,
+ 1847226629u, 50398611u, 1890374404u, 2878700735u,
+ 2286201787u, 1401186359u, 619285059u, 731930817u,
+ 2340993166u, 1156490245u, 2992241729u, 151498140u,
+ 318782170u, 3480838990u, 2100383433u, 4223552555u,
+ 3628927011u, 4247846280u, 1759029513u, 4215632601u,
+ 2719154626u, 3490334597u, 1751299340u, 3487864726u,
+ 3668753795u, 4217506054u, 3748782284u, 3150295088u },
+ { 1772626313u, 445326068u, 3477676155u, 1758201194u,
+ 2986784722u, 491035581u, 3922936562u, 702212696u,
+ 2979856666u, 3324974564u, 2488428922u, 3056318590u,
+ 1626954946u, 664714029u, 398585816u, 3964097931u,
+ 3356701905u, 2298377729u, 2040082097u, 3025491477u,
+ 539143308u, 3348777868u, 2995302452u, 3602465520u,
+ 212480763u, 2691021393u, 1307177300u, 704008044u,
+ 2031136606u, 1054106474u, 3838318865u, 2441343869u,
+ 1477566916u, 700949900u, 2534790355u, 3353533667u,
+ 336163563u, 4106790558u, 2701448228u, 1571536379u,
+ 1103842411u, 3623110423u, 1635278839u, 1577828979u,
+ 910322800u, 715583630u, 138128831u, 1017877531u,
+ 2289162787u, 447994798u, 1897243165u, 4121561445u,
+ 4150719842u, 2131821093u, 2262395396u, 3305771534u,
+ 980753571u, 3256525190u, 3128121808u, 1072869975u,
+ 3507939515u, 4229109952u, 118381341u, 2209831334u },
+ 65537
};
RecoveryUI* ui = NULL;
@@ -91,14 +129,21 @@ class FakeUI : public RecoveryUI {
};
int main(int argc, char **argv) {
- if (argc != 2) {
- fprintf(stderr, "Usage: %s <package>\n", argv[0]);
+ if (argc != 2 && argc != 3) {
+ fprintf(stderr, "Usage: %s [-f4] <package>\n", argv[0]);
return 2;
}
+ RSAPublicKey* key = &test_key;
+ ++argv;
+ if (strcmp(argv[0], "-f4") == 0) {
+ ++argv;
+ key = &test_f4_key;
+ }
+
ui = new FakeUI();
- int result = verify_file(argv[1], &test_key, 1);
+ int result = verify_file(*argv, key, 1);
if (result == VERIFY_SUCCESS) {
printf("SUCCESS\n");
return 0;
diff --git a/verifier_test.sh b/verifier_test.sh
index a1de5c57b..378b0e5ff 100755
--- a/verifier_test.sh
+++ b/verifier_test.sh
@@ -73,9 +73,24 @@ expect_fail() {
run_command $WORK_DIR/verifier_test $WORK_DIR/package.zip && fail
}
+expect_succeed_f4() {
+ testname "$1 (should succeed)"
+ $ADB push $DATA_DIR/$1 $WORK_DIR/package.zip
+ run_command $WORK_DIR/verifier_test -f4 $WORK_DIR/package.zip || fail
+}
+
+expect_fail_f4() {
+ testname "$1 (should fail)"
+ $ADB push $DATA_DIR/$1 $WORK_DIR/package.zip
+ run_command $WORK_DIR/verifier_test -f4 $WORK_DIR/package.zip && fail
+}
+
expect_fail unsigned.zip
expect_fail jarsigned.zip
expect_succeed otasigned.zip
+expect_fail_f4 otasigned.zip
+expect_succeed_f4 otasigned_f4.zip
+expect_fail otasigned_f4.zip
expect_fail random.zip
expect_fail fake-eocd.zip
expect_fail alter-metadata.zip