Merge "fastboot: show progress when sending sparse images."
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp
index ac5a17a..47567c0 100644
--- a/fastboot/engine.cpp
+++ b/fastboot/engine.cpp
@@ -157,17 +157,17 @@
a->msg = mkmsg("writing '%s'", ptn);
}
-void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz)
-{
+void fb_queue_flash_sparse(const char* ptn, struct sparse_file* s, unsigned sz, size_t current,
+ size_t total) {
Action *a;
a = queue_action(OP_DOWNLOAD_SPARSE, "");
a->data = s;
a->size = 0;
- a->msg = mkmsg("sending sparse '%s' (%d KB)", ptn, sz / 1024);
+ a->msg = mkmsg("sending sparse '%s' %zu/%zu (%d KB)", ptn, current, total, sz / 1024);
a = queue_action(OP_COMMAND, "flash:%s", ptn);
- a->msg = mkmsg("writing '%s'", ptn);
+ a->msg = mkmsg("writing '%s' %zu/%zu", ptn, current, total);
}
static int match(const char* str, const char** value, unsigned count) {
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index bd17485..4573da0 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -43,6 +43,8 @@
#include <sys/types.h>
#include <unistd.h>
#include <functional>
+#include <utility>
+#include <vector>
#include <android-base/parseint.h>
#include <android-base/strings.h>
@@ -705,13 +707,22 @@
sparse_file** s;
switch (buf->type) {
- case FB_BUFFER_SPARSE:
+ case FB_BUFFER_SPARSE: {
+ std::vector<std::pair<sparse_file*, int64_t>> sparse_files;
s = reinterpret_cast<sparse_file**>(buf->data);
while (*s) {
int64_t sz = sparse_file_len(*s, true, false);
- fb_queue_flash_sparse(pname, *s++, sz);
+ sparse_files.emplace_back(*s, sz);
+ ++s;
+ }
+
+ for (size_t i = 0; i < sparse_files.size(); ++i) {
+ const auto& pair = sparse_files[i];
+ fb_queue_flash_sparse(pname, pair.first, pair.second, i + 1, sparse_files.size());
}
break;
+ }
+
case FB_BUFFER:
fb_queue_flash(pname, buf->data, buf->sz);
break;
diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h
index acfbc13..1932bab 100644
--- a/fastboot/fastboot.h
+++ b/fastboot/fastboot.h
@@ -51,7 +51,8 @@
/* engine.c - high level command queue engine */
bool fb_getvar(Transport* transport, const std::string& key, std::string* value);
void fb_queue_flash(const char *ptn, void *data, uint32_t sz);
-void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, uint32_t sz);
+void fb_queue_flash_sparse(const char* ptn, struct sparse_file* s, uint32_t sz, size_t current,
+ size_t total);
void fb_queue_erase(const char *ptn);
void fb_queue_format(const char *ptn, int skip_if_not_supported, int32_t max_chunk_sz);
void fb_queue_require(const char *prod, const char *var, bool invert,