diff options
93 files changed, 539 insertions, 70 deletions
diff --git a/Android.mk b/Android.mk index 1c78b4287..215cfe569 100644 --- a/Android.mk +++ b/Android.mk @@ -47,6 +47,7 @@ LOCAL_STATIC_LIBRARIES := \ libpng \ libcutils \ 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, ©_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); @@ -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..88572a878 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,22 @@ int gr_text(int x, int y, const char *s) return x; } +void gr_texticon(int x, int y, gr_surface icon) { + 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; 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..60f354254 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,154 @@ exit: return result; } +static int matches_locale(const char* loc) { + if (locale == NULL) return 0; + + printf("matching loc=[%s] vs locale=[%s]\n", loc, locale); + + 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; + printf(" partial match possible; i = %d\n", i); + + 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; + + printf("image size is %d x %d\n", width, height); + + int color_type = info_ptr->color_type; + int bit_depth = info_ptr->bit_depth; + int channels = info_ptr->channels; + printf("color_type %d bit_depth %d channels %d\n", + color_type, bit_depth, channels); + + if (!(bit_depth == 8 && + (channels == 1 && color_type == PNG_COLOR_TYPE_GRAY))) { + return -7; + printf("exiting -7\n"); + 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; + + printf("row %d: %s %d x %d\n", y, loc, w, h); + + if (y+1+h >= height || matches_locale(loc)) { + printf(" taking this one\n"); + + 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 { + printf(" skipping\n"); + 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 ce4358a53..70817d307 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/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); @@ -658,6 +673,7 @@ prompt_and_wait(Device* device) { for (;;) { finish_recovery(NULL); + ui->SetBackground(RecoveryUI::NO_COMMAND); ui->SetProgressType(RecoveryUI::EMPTY); int chosen_item = get_menu_selection(headers, device->GetMenuItems(), 0, 0, device); @@ -679,6 +695,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 +774,24 @@ 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; + 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); + } +} + int main(int argc, char **argv) { time_t start = time(NULL); @@ -779,18 +814,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 +831,27 @@ 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->SetBackground(RecoveryUI::NONE); + if (show_text) ui->ShowText(true); + #ifdef HAVE_SELINUX struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } @@ -868,10 +911,13 @@ 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); } diff --git a/res/images/erasing_text.png b/res/images/erasing_text.png Binary files differnew file mode 100644 index 000000000..f92119772 --- /dev/null +++ b/res/images/erasing_text.png diff --git a/res/images/error_text.png b/res/images/error_text.png Binary files differnew file mode 100644 index 000000000..581347094 --- /dev/null +++ b/res/images/error_text.png diff --git a/res/images/icon_error.png b/res/images/icon_error.png Binary files differindex cb3d1ab22..7000d4d8a 100644 --- a/res/images/icon_error.png +++ b/res/images/icon_error.png diff --git a/res/images/icon_installing.png b/res/images/icon_installing.png Binary files differindex 571eb8b0f..ad7927753 100644 --- a/res/images/icon_installing.png +++ b/res/images/icon_installing.png diff --git a/res/images/icon_installing_overlay01.png b/res/images/icon_installing_overlay01.png Binary files differindex e762d6cbe..c9f6125d9 100644 --- a/res/images/icon_installing_overlay01.png +++ b/res/images/icon_installing_overlay01.png diff --git a/res/images/icon_installing_overlay02.png b/res/images/icon_installing_overlay02.png Binary files differindex f7a853017..c87e5fa92 100644 --- a/res/images/icon_installing_overlay02.png +++ b/res/images/icon_installing_overlay02.png diff --git a/res/images/icon_installing_overlay03.png b/res/images/icon_installing_overlay03.png Binary files differindex 1a1d738e4..30e95803f 100644 --- a/res/images/icon_installing_overlay03.png +++ b/res/images/icon_installing_overlay03.png diff --git a/res/images/icon_installing_overlay04.png b/res/images/icon_installing_overlay04.png Binary files differindex a74903d33..6f1f9cf0d 100644 --- a/res/images/icon_installing_overlay04.png +++ b/res/images/icon_installing_overlay04.png diff --git a/res/images/icon_installing_overlay05.png b/res/images/icon_installing_overlay05.png Binary files differindex d17bdc006..8791abdbd 100644 --- a/res/images/icon_installing_overlay05.png +++ b/res/images/icon_installing_overlay05.png diff --git a/res/images/icon_installing_overlay06.png b/res/images/icon_installing_overlay06.png Binary files differindex 1200b75cb..08a0133b0 100644 --- a/res/images/icon_installing_overlay06.png +++ b/res/images/icon_installing_overlay06.png diff --git a/res/images/icon_installing_overlay07.png b/res/images/icon_installing_overlay07.png Binary files differindex 3838a85ad..15b53d9b7 100644 --- a/res/images/icon_installing_overlay07.png +++ b/res/images/icon_installing_overlay07.png diff --git a/res/images/icon_installing_overlay08.png b/res/images/icon_installing_overlay08.png Binary files differnew file mode 100644 index 000000000..bb4987894 --- /dev/null +++ b/res/images/icon_installing_overlay08.png diff --git a/res/images/icon_installing_overlay09.png b/res/images/icon_installing_overlay09.png Binary files differnew file mode 100644 index 000000000..e8715fcfa --- /dev/null +++ b/res/images/icon_installing_overlay09.png diff --git a/res/images/icon_installing_overlay10.png b/res/images/icon_installing_overlay10.png Binary files differnew file mode 100644 index 000000000..4ad81bf71 --- /dev/null +++ b/res/images/icon_installing_overlay10.png diff --git a/res/images/icon_installing_overlay11.png b/res/images/icon_installing_overlay11.png Binary files differnew file mode 100644 index 000000000..b3ae7e3ad --- /dev/null +++ b/res/images/icon_installing_overlay11.png diff --git a/res/images/icon_installing_overlay12.png b/res/images/icon_installing_overlay12.png Binary files differnew file mode 100644 index 000000000..5e7fd04a6 --- /dev/null +++ b/res/images/icon_installing_overlay12.png diff --git a/res/images/icon_installing_overlay13.png b/res/images/icon_installing_overlay13.png Binary files differnew file mode 100644 index 000000000..4e4dbe923 --- /dev/null +++ b/res/images/icon_installing_overlay13.png diff --git a/res/images/icon_installing_overlay14.png b/res/images/icon_installing_overlay14.png Binary files differnew file mode 100644 index 000000000..55e19b5e4 --- /dev/null +++ b/res/images/icon_installing_overlay14.png diff --git a/res/images/icon_installing_overlay15.png b/res/images/icon_installing_overlay15.png Binary files differnew file mode 100644 index 000000000..ac5fb991c --- /dev/null +++ b/res/images/icon_installing_overlay15.png diff --git a/res/images/icon_installing_overlay16.png b/res/images/icon_installing_overlay16.png Binary files differnew file mode 100644 index 000000000..6461d70f1 --- /dev/null +++ b/res/images/icon_installing_overlay16.png diff --git a/res/images/icon_installing_overlay17.png b/res/images/icon_installing_overlay17.png Binary files differnew file mode 100644 index 000000000..cc981d347 --- /dev/null +++ b/res/images/icon_installing_overlay17.png diff --git a/res/images/icon_installing_overlay18.png b/res/images/icon_installing_overlay18.png Binary files differnew file mode 100644 index 000000000..2b3221444 --- /dev/null +++ b/res/images/icon_installing_overlay18.png diff --git a/res/images/icon_installing_overlay19.png b/res/images/icon_installing_overlay19.png Binary files differnew file mode 100644 index 000000000..d379e51a1 --- /dev/null +++ b/res/images/icon_installing_overlay19.png diff --git a/res/images/icon_installing_overlay20.png b/res/images/icon_installing_overlay20.png Binary files differnew file mode 100644 index 000000000..362a8cabc --- /dev/null +++ b/res/images/icon_installing_overlay20.png diff --git a/res/images/icon_installing_overlay21.png b/res/images/icon_installing_overlay21.png Binary files differnew file mode 100644 index 000000000..0b6559222 --- /dev/null +++ b/res/images/icon_installing_overlay21.png diff --git a/res/images/icon_installing_overlay22.png b/res/images/icon_installing_overlay22.png Binary files differnew file mode 100644 index 000000000..51d5cbadf --- /dev/null +++ b/res/images/icon_installing_overlay22.png diff --git a/res/images/icon_installing_overlay23.png b/res/images/icon_installing_overlay23.png Binary files differnew file mode 100644 index 000000000..59148e5cc --- /dev/null +++ b/res/images/icon_installing_overlay23.png diff --git a/res/images/icon_installing_overlay24.png b/res/images/icon_installing_overlay24.png Binary files differnew file mode 100644 index 000000000..d315673b4 --- /dev/null +++ b/res/images/icon_installing_overlay24.png diff --git a/res/images/icon_installing_overlay25.png b/res/images/icon_installing_overlay25.png Binary files differnew file mode 100644 index 000000000..1eb7843e3 --- /dev/null +++ b/res/images/icon_installing_overlay25.png diff --git a/res/images/icon_installing_overlay26.png b/res/images/icon_installing_overlay26.png Binary files differnew file mode 100644 index 000000000..14a024dcf --- /dev/null +++ b/res/images/icon_installing_overlay26.png diff --git a/res/images/icon_installing_overlay27.png b/res/images/icon_installing_overlay27.png Binary files differnew file mode 100644 index 000000000..035c16340 --- /dev/null +++ b/res/images/icon_installing_overlay27.png diff --git a/res/images/icon_installing_overlay28.png b/res/images/icon_installing_overlay28.png Binary files differnew file mode 100644 index 000000000..75483864f --- /dev/null +++ b/res/images/icon_installing_overlay28.png diff --git a/res/images/icon_installing_overlay29.png b/res/images/icon_installing_overlay29.png Binary files differnew file mode 100644 index 000000000..836d3138f --- /dev/null +++ b/res/images/icon_installing_overlay29.png diff --git a/res/images/icon_installing_overlay30.png b/res/images/icon_installing_overlay30.png Binary files differnew file mode 100644 index 000000000..e470a7e1e --- /dev/null +++ b/res/images/icon_installing_overlay30.png diff --git a/res/images/icon_installing_overlay31.png b/res/images/icon_installing_overlay31.png Binary files differnew file mode 100644 index 000000000..bed0c65aa --- /dev/null +++ b/res/images/icon_installing_overlay31.png diff --git a/res/images/icon_installing_overlay32.png b/res/images/icon_installing_overlay32.png Binary files differnew file mode 100644 index 000000000..51811e0ac --- /dev/null +++ b/res/images/icon_installing_overlay32.png diff --git a/res/images/icon_installing_overlay33.png b/res/images/icon_installing_overlay33.png Binary files differnew file mode 100644 index 000000000..f1fc656d5 --- /dev/null +++ b/res/images/icon_installing_overlay33.png diff --git a/res/images/icon_installing_overlay34.png b/res/images/icon_installing_overlay34.png Binary files differnew file mode 100644 index 000000000..5791a7d16 --- /dev/null +++ b/res/images/icon_installing_overlay34.png diff --git a/res/images/icon_installing_overlay35.png b/res/images/icon_installing_overlay35.png Binary files differnew file mode 100644 index 000000000..0769ec9eb --- /dev/null +++ b/res/images/icon_installing_overlay35.png diff --git a/res/images/icon_installing_overlay36.png b/res/images/icon_installing_overlay36.png Binary files differnew file mode 100644 index 000000000..28a692bd2 --- /dev/null +++ b/res/images/icon_installing_overlay36.png diff --git a/res/images/icon_installing_overlay37.png b/res/images/icon_installing_overlay37.png Binary files differnew file mode 100644 index 000000000..12b21cfae --- /dev/null +++ b/res/images/icon_installing_overlay37.png diff --git a/res/images/icon_installing_overlay38.png b/res/images/icon_installing_overlay38.png Binary files differnew file mode 100644 index 000000000..f8ef9967d --- /dev/null +++ b/res/images/icon_installing_overlay38.png diff --git a/res/images/icon_installing_overlay39.png b/res/images/icon_installing_overlay39.png Binary files differnew file mode 100644 index 000000000..f929119ab --- /dev/null +++ b/res/images/icon_installing_overlay39.png diff --git a/res/images/icon_installing_overlay40.png b/res/images/icon_installing_overlay40.png Binary files differnew file mode 100644 index 000000000..ceed45759 --- /dev/null +++ b/res/images/icon_installing_overlay40.png diff --git a/res/images/icon_installing_overlay41.png b/res/images/icon_installing_overlay41.png Binary files differnew file mode 100644 index 000000000..34cf1aec4 --- /dev/null +++ b/res/images/icon_installing_overlay41.png diff --git a/res/images/icon_installing_overlay42.png b/res/images/icon_installing_overlay42.png Binary files differnew file mode 100644 index 000000000..d622417ac --- /dev/null +++ b/res/images/icon_installing_overlay42.png diff --git a/res/images/icon_installing_overlay43.png b/res/images/icon_installing_overlay43.png Binary files differnew file mode 100644 index 000000000..9902df1a7 --- /dev/null +++ b/res/images/icon_installing_overlay43.png diff --git a/res/images/icon_installing_overlay44.png b/res/images/icon_installing_overlay44.png Binary files differnew file mode 100644 index 000000000..b5d7911e1 --- /dev/null +++ b/res/images/icon_installing_overlay44.png diff --git a/res/images/icon_installing_overlay45.png b/res/images/icon_installing_overlay45.png Binary files differnew file mode 100644 index 000000000..dfbf408b6 --- /dev/null +++ b/res/images/icon_installing_overlay45.png diff --git a/res/images/icon_installing_overlay46.png b/res/images/icon_installing_overlay46.png Binary files differnew file mode 100644 index 000000000..495bb90df --- /dev/null +++ b/res/images/icon_installing_overlay46.png diff --git a/res/images/icon_installing_overlay47.png b/res/images/icon_installing_overlay47.png Binary files differnew file mode 100644 index 000000000..9d6937866 --- /dev/null +++ b/res/images/icon_installing_overlay47.png diff --git a/res/images/icon_installing_overlay48.png b/res/images/icon_installing_overlay48.png Binary files differnew file mode 100644 index 000000000..a5080af97 --- /dev/null +++ b/res/images/icon_installing_overlay48.png diff --git a/res/images/indeterminate01.png b/res/images/indeterminate01.png Binary files differindex 933528d6d..4db384337 100644 --- a/res/images/indeterminate01.png +++ b/res/images/indeterminate01.png diff --git a/res/images/indeterminate02.png b/res/images/indeterminate02.png Binary files differindex d760e2bdd..761b2332f 100644 --- a/res/images/indeterminate02.png +++ b/res/images/indeterminate02.png diff --git a/res/images/indeterminate03.png b/res/images/indeterminate03.png Binary files differindex 0e97399d1..e2617abcb 100644 --- a/res/images/indeterminate03.png +++ b/res/images/indeterminate03.png diff --git a/res/images/indeterminate04.png b/res/images/indeterminate04.png Binary files differindex c7d5b4e04..132940e50 100644 --- a/res/images/indeterminate04.png +++ b/res/images/indeterminate04.png diff --git a/res/images/indeterminate05.png b/res/images/indeterminate05.png Binary files differindex d6fb2a032..a17032c2d 100644 --- a/res/images/indeterminate05.png +++ b/res/images/indeterminate05.png diff --git a/res/images/indeterminate06.png b/res/images/indeterminate06.png Binary files differindex 44867619f..efaac42e6 100644 --- a/res/images/indeterminate06.png +++ b/res/images/indeterminate06.png diff --git a/res/images/indeterminate07.png b/res/images/indeterminate07.png Binary files differnew file mode 100644 index 000000000..6e84a5a0f --- /dev/null +++ b/res/images/indeterminate07.png diff --git a/res/images/indeterminate08.png b/res/images/indeterminate08.png Binary files differnew file mode 100644 index 000000000..58c112e38 --- /dev/null +++ b/res/images/indeterminate08.png diff --git a/res/images/indeterminate09.png b/res/images/indeterminate09.png Binary files differnew file mode 100644 index 000000000..b25145f12 --- /dev/null +++ b/res/images/indeterminate09.png diff --git a/res/images/indeterminate10.png b/res/images/indeterminate10.png Binary files differnew file mode 100644 index 000000000..4ff7e2527 --- /dev/null +++ b/res/images/indeterminate10.png diff --git a/res/images/indeterminate11.png b/res/images/indeterminate11.png Binary files differnew file mode 100644 index 000000000..4860c2a02 --- /dev/null +++ b/res/images/indeterminate11.png diff --git a/res/images/indeterminate12.png b/res/images/indeterminate12.png Binary files differnew file mode 100644 index 000000000..a249c225b --- /dev/null +++ b/res/images/indeterminate12.png diff --git a/res/images/indeterminate13.png b/res/images/indeterminate13.png Binary files differnew file mode 100644 index 000000000..1b70dc072 --- /dev/null +++ b/res/images/indeterminate13.png diff --git a/res/images/indeterminate14.png b/res/images/indeterminate14.png Binary files differnew file mode 100644 index 000000000..a5f779f73 --- /dev/null +++ b/res/images/indeterminate14.png diff --git a/res/images/indeterminate15.png b/res/images/indeterminate15.png Binary files differnew file mode 100644 index 000000000..018fa685c --- /dev/null +++ b/res/images/indeterminate15.png diff --git a/res/images/indeterminate16.png b/res/images/indeterminate16.png Binary files differnew file mode 100644 index 000000000..e8e05b6d3 --- /dev/null +++ b/res/images/indeterminate16.png diff --git a/res/images/installing_text.png b/res/images/installing_text.png Binary files differnew file mode 100644 index 000000000..c48a45295 --- /dev/null +++ b/res/images/installing_text.png diff --git a/res/images/no_command_text.png b/res/images/no_command_text.png Binary files differnew file mode 100644 index 000000000..1d6a5b7cf --- /dev/null +++ b/res/images/no_command_text.png diff --git a/screen_ui.cpp b/screen_ui.cpp index 3c6c3ae25..1f2471ade 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -75,10 +75,10 @@ ScreenRecoveryUI::ScreenRecoveryUI() : // that overrides Init() to set these values appropriately and // then call the superclass Init(). animation_fps(20), - indeterminate_frames(6), - installing_frames(7), - install_overlay_offset_x(13), - install_overlay_offset_y(190) { + indeterminate_frames(16), + installing_frames(48), + install_overlay_offset_x(65), + install_overlay_offset_y(106) { pthread_mutex_init(&updateMutex, NULL); self = this; } @@ -94,7 +94,7 @@ void ScreenRecoveryUI::draw_install_overlay_locked(int 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 +107,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 +136,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); @@ -242,7 +254,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 +296,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 +315,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 +349,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; } @@ -343,6 +363,17 @@ void ScreenRecoveryUI::SetBackground(Icon icon) pthread_mutex_lock(&updateMutex); currentIcon = icon; update_screen_locked(); + + // 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; + } + pthread_mutex_unlock(&updateMutex); } diff --git a/screen_ui.h b/screen_ui.h index 34929ee1a..16ee741b7 100644 --- a/screen_ui.h +++ b/screen_ui.h @@ -57,7 +57,8 @@ class ScreenRecoveryUI : public RecoveryUI { int installingFrame; 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 +93,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 +106,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 Binary files differnew file mode 100644 index 000000000..dd1e4dd40 --- /dev/null +++ b/testdata/otasigned_f4.zip diff --git a/testdata/test_f4.pk8 b/testdata/test_f4.pk8 Binary files differnew file mode 100644 index 000000000..3052613c5 --- /dev/null +++ b/testdata/test_f4.pk8 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----- @@ -31,7 +31,7 @@ class RecoveryUI { virtual void Init(); // 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 f981017bf..41f053d01 100644 --- a/updater/install.c +++ b/updater/install.c @@ -456,6 +456,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. @@ -483,6 +503,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)); @@ -504,7 +529,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); @@ -626,7 +652,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; } @@ -638,7 +664,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; @@ -875,7 +901,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 |