From 43772d26a5d8d31fd092a21edfca346f3b3901e7 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Mon, 9 Jun 2014 14:13:19 -0700 Subject: advance progress bar during block OTA installations While executing syspatch and package_extract_file() calls with don't care maps (both of which are used to rewrite the system image in incremental and full block OTAs, respectively), pass a progress callback in and use it to update the visible progress bar. Change-Id: I1d3742d167c1bb2130571eb5103b7795c65ff371 --- updater/install.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'updater/install.c') diff --git a/updater/install.c b/updater/install.c index e1071c9..42f2289 100644 --- a/updater/install.c +++ b/updater/install.c @@ -463,17 +463,31 @@ DontCareMap* ReadDontCareMapFromZip(ZipArchive* za, const char* path) { map->region_count = strtoul(p, &p, 0); map->regions = (int*) malloc(map->region_count * sizeof(int)); + map->total_blocks = 0; int i; for (i = 0; i < map->region_count; ++i) { map->regions[i] = strtoul(p, &p, 0); + map->total_blocks += map->regions[i]; } return map; } +static FILE* mapwrite_cmd_pipe; + +static void progress_cb(long done, long total) { + if (total > 0) { + double frac = (double)done / total; + fprintf(mapwrite_cmd_pipe, "set_progress %f\n", frac); + fflush(mapwrite_cmd_pipe); + } +} + + + bool MapWriter(const unsigned char* data, int dataLen, void* cookie) { - return write_with_map(data, dataLen, (MapState*) cookie) == dataLen; + return write_with_map(data, dataLen, (MapState*) cookie, progress_cb) == dataLen; } // package_extract_file(package_path, destination_path, map_path) @@ -490,6 +504,10 @@ Value* PackageExtractFileFn(const char* name, State* state, name, argc); } bool success = false; + + UpdaterInfo* ui = (UpdaterInfo*)(state->cookie); + mapwrite_cmd_pipe = ui->cmd_pipe; + if (argc >= 2) { // The two-argument version extracts to a file; the three-arg // version extracts to a file, skipping over regions in a @@ -1185,6 +1203,9 @@ Value* SysPatchFn(const char* name, State* state, int argc, Expr* argv[]) { return NULL; } + UpdaterInfo* ui = (UpdaterInfo*)(state->cookie); + mapwrite_cmd_pipe = ui->cmd_pipe; + if (ParseSha1(target_sha1, target_digest) != 0) { printf("%s(): failed to parse '%s' as target SHA-1", name, target_sha1); memset(target_digest, 0, SHA_DIGEST_SIZE); @@ -1220,7 +1241,7 @@ Value* SysPatchFn(const char* name, State* state, int argc, Expr* argv[]) { FILE* tgt = fopen(filename, "r+"); - int ret = syspatch(src, init_map, patch_data, patch_len, tgt, target_map); + int ret = syspatch(src, init_map, patch_data, patch_len, tgt, target_map, progress_cb); fclose(src); fclose(tgt); -- cgit v1.1