Adds a -P option so dumpstate can report its progress.

The old workflow was:

1. dumpstate starts.
2. When dumpstate finishes, it sends a BUGREPORT_FINISHED event.
3. Shell's BugreportReceiver receives the BUGREPORT_FINISHED and issues a
   system notification so user can share the bug report.

The new workflow is:

1. When dumpstate starts, it sends a BUGREPORT_STARTED with its pid and
  the estimated total effort.
2. When Shell's BugreportReceiver receives the BUGREPORT_STARTED, it:
  2.1 Issues a system notification so user can watch the
      progresss (which is 0% initially).
  2.2 Starts a service (BugreportProgressService) responsible for
      polling the dumpstate progress (using system properties and the
      pid) and updating the system notification.
3. As dumpstate progress, it updates the proper system property.
4. When dumpstate finishes, it sends a BUGREPORT_FINISHED event.
5. When Shell's BugreportReceiver receives the BUGREPORT_FINISHED, it:
  5.1 Finishes the service if necessary.
  5.2 Issues a system notification so user can share the bug report.

This CL handles the dumpstate changes only, the Shell changes will be
handled in a separate CL.

BUG: 25794470
Change-Id: I6e04203411802c88ab0d093420ccdfd26700d565
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 18ee168..2ba5ccb 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -45,6 +45,28 @@
 typedef void (for_each_pid_func)(int, const char *);
 typedef void (for_each_tid_func)(int, int, const char *);
 
+/* Estimated total weight of bugreport generation.
+ *
+ * Each section contributes to the total weight by an individual weight, so the overall progress
+ * can be calculated by dividing the all completed weight by the total weight.
+ *
+ * This value is defined empirically and it need to be adjusted as more sections are added.
+ * It does not need to match the exact sum of all sections, but it should to be more than it,
+ * otherwise the calculated progress would be more than 100%.
+ */
+static const int WEIGHT_TOTAL = 4000;
+
+/* Most simple commands have 10 as timeout, so 5 is a good estimate */
+static const int WEIGHT_FILE = 5;
+
+/*
+ * TOOD: the dumpstate internal state is getting fragile; for example, this variable is defined
+ * here, declared at utils.cpp, and used on utils.cpp and dumpstate.cpp.
+ * It would be better to take advantage of the C++ migration and encapsulate the state in an object,
+ * but that will be better handled in a major C++ refactoring, which would also get rid of other C
+ * idioms (like using std::string instead of char*, removing varargs, etc...) */
+extern int do_update_progress;
+
 /* prints the contents of a file */
 int dump_file(const char *title, const char *path);
 
@@ -74,6 +96,9 @@
 /* sends a broadcast using Activity Manager */
 void send_broadcast(const std::string& action, const std::vector<std::string>& args);
 
+/* updates the overall progress of dumpstate by the given weight increment */
+void update_progress(int weight);
+
 /* prints all the system properties */
 void print_properties();