diff options
author | Tom Marshall <tdm@cyngn.com> | 2014-12-18 14:18:47 -0800 |
---|---|---|
committer | Tom Marshall <tdm@cyngn.com> | 2015-12-01 15:45:16 -0800 |
commit | 56929668eacacb43649d03d25c2d15a653a2744e (patch) | |
tree | b9ff8435a7f8a5c4e8bb91a0682b115ce868a746 /adb | |
parent | c96c137850e124f0db93a5b62dd7eb9821e28130 (diff) | |
download | system_core-56929668eacacb43649d03d25c2d15a653a2744e.zip system_core-56929668eacacb43649d03d25c2d15a653a2744e.tar.gz system_core-56929668eacacb43649d03d25c2d15a653a2744e.tar.bz2 |
adb: host: Provide better sideload status
* Show data transfer in MB and in multiple of the file size.
* Show a spinner to indicate liveness, which is updated at least once
per second regardless of data transfer.
* Do not allow sideload of zero sized files.
Change-Id: I1bd0df6a8183fad5a502fc26a7e789c27d24f71a
Diffstat (limited to 'adb')
-rw-r--r-- | adb/commandline.cpp | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/adb/commandline.cpp b/adb/commandline.cpp index fd9953c..d38588f 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -497,6 +497,8 @@ static int adb_download_buffer(const char *service, const char *fn, const void* #define SIDELOAD_HOST_BLOCK_SIZE (CHUNK_SIZE) +#define MB (1024*1024) + /* * The sideload-host protocol serves the data in a file (given on the * command line) to the client, using a simple protocol: @@ -517,10 +519,13 @@ static int adb_download_buffer(const char *service, const char *fn, const void* * we hang up. */ static int adb_sideload_host(const char* fn) { + static const char spinner[] = "/-\\|"; + static const int spinlen = sizeof(spinner)-1; + size_t last_xfer = 0; + int spin_index = 0; unsigned sz; size_t xfer = 0; int status; - int last_percent = -1; int opt = SIDELOAD_HOST_BLOCK_SIZE; printf("loading: '%s'", fn); @@ -531,6 +536,11 @@ static int adb_sideload_host(const char* fn) { fprintf(stderr, "* cannot read '%s' *\n", fn); return -1; } + if (sz == 0) { + printf("\n"); + fprintf(stderr, "* '%s' is empty *\n", fn); + return -1; + } std::string service = android::base::StringPrintf("sideload-host:%d:%d", sz, SIDELOAD_HOST_BLOCK_SIZE); @@ -547,6 +557,24 @@ static int adb_sideload_host(const char* fn) { opt = adb_setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *) &opt, sizeof(opt)); while (true) { + fd_set fds; + struct timeval tv; + FD_ZERO(&fds); + FD_SET(fd, &fds); + tv.tv_sec = 1; + tv.tv_usec = 0; + int rc = select(fd+1, &fds, NULL, NULL, &tv); + size_t diff = xfer - last_xfer; + if (rc == 0 || diff >= (1*MB)) { + spin_index = (spin_index+1) % spinlen; + printf("\rserving: '%s' %4umb %.2fx %c", fn, + (unsigned)xfer/(1*MB), (double)xfer/sz, spinner[spin_index]); + fflush(stdout); + last_xfer = xfer; + } + if (rc == 0) { + continue; + } char buf[9]; if (!ReadFdExactly(fd, buf, 8)) { fprintf(stderr, "* failed to read command: %s\n", strerror(errno)); @@ -582,22 +610,9 @@ static int adb_sideload_host(const char* fn) { goto done; } xfer += to_write; - - // For normal OTA packages, we expect to transfer every byte - // twice, plus a bit of overhead (one read during - // verification, one read of each byte for installation, plus - // extra access to things like the zip central directory). - // This estimate of the completion becomes 100% when we've - // transferred ~2.13 (=100/47) times the package size. - int percent = (int)(xfer * 47LL / (sz ? sz : 1)); - if (percent != last_percent) { - printf("\rserving: '%s' (~%d%%) ", fn, percent); - fflush(stdout); - last_percent = percent; - } } - printf("\rTotal xfer: %.2fx%*s\n", (double)xfer / (sz ? sz : 1), (int)strlen(fn)+10, ""); + printf("\ntotal xfer: %4umb %.2fx\n", (unsigned)xfer/(1*MB), (double)xfer/sz); done: if (fd >= 0) adb_close(fd); |