Don't display bugreport progress when it recedes.

Also fixed InvalidNumberArgs that broke when usage() was moved out from
bugreport.cpp.

Fixes: 26354314
Bug: 28054087
Test: m -j32 adb_test && ./out/host/linux-x86/nativetest64/adb_test/adb_test --gtest_filter=BugreportTest.*

Change-Id: I7be5ef7de0fb0d339dc80a2abc816e1c905deb22
diff --git a/bugreport.cpp b/bugreport.cpp
index a5c312b..9dc9811 100644
--- a/bugreport.cpp
+++ b/bugreport.cpp
@@ -47,7 +47,8 @@
           invalid_lines_(),
           show_progress_(show_progress),
           status_(0),
-          line_() {
+          line_(),
+          last_progress_(0) {
         SetLineMessage("generating");
     }
 
@@ -66,6 +67,7 @@
     void OnStderr(const char* buffer, int length) {
         OnStream(nullptr, stderr, buffer, length);
     }
+
     int Done(int unused_) {
         // Process remaining line, if any.
         ProcessLine(line_);
@@ -145,6 +147,11 @@
             size_t idx1 = line.rfind(BUGZ_PROGRESS_PREFIX) + strlen(BUGZ_PROGRESS_PREFIX);
             size_t idx2 = line.rfind(BUGZ_PROGRESS_SEPARATOR);
             int progress = std::stoi(line.substr(idx1, (idx2 - idx1)));
+            if (progress <= last_progress_) {
+                // Ignore.
+                return;
+            }
+            last_progress_ = progress;
             int total = std::stoi(line.substr(idx2 + 1));
             br_->UpdateProgress(line_message_, progress, total);
         } else {
@@ -180,6 +187,10 @@
     // Temporary buffer containing the characters read since the last newline (\n).
     std::string line_;
 
+    // Last displayed progress.
+    // Since dumpstate progress can recede, only forward progress should be displayed
+    int last_progress_;
+
     DISALLOW_COPY_AND_ASSIGN(BugreportStandardStreamsCallback);
 };