Uses a system property to set dry-run mode.
On Android N, dumpstate was using a #define to set dry-run mode, which
allows dumpstate to run much faster, which in turn is useful when
developing new dumpstate features.
The drawback of this approach is that it requires modifying dumpstate.h
locally, building a new binary, and re-redeploying it in the device; a
better and more flexible approach is to use a system
property (dumpstate.dry_run) so developers can enable /disable it during
runtime.
Change-Id: I41d1e6ae3fa6ca2be23887f59d5ad4e9df7c10e6
Fixes: 30604041
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 8a4ebf3..52c6e56 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -65,6 +65,7 @@
/* suffix of the bugreport files - it's typically the date (when invoked with -d),
* although it could be changed by the user using a system property */
static std::string suffix;
+static bool dry_run = false;
#define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops"
#define ALT_PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops-0"
@@ -95,7 +96,7 @@
/*
* List of supported zip format versions.
*
- * See bugreport-format.txt for more info.
+ * See bugreport-format.md for more info.
*/
static std::string VERSION_DEFAULT = "1.0";
@@ -103,6 +104,10 @@
return 0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1);
}
+bool is_dry_run() {
+ return dry_run;
+}
+
/* gets the tombstone data, according to the bugreport type: if zipped, gets all tombstones;
* otherwise, gets just those modified in the last half an hour. */
static void get_tombstone_fds(tombstone_data_t data[NUM_TOMBSTONES]) {
@@ -1161,6 +1166,11 @@
MYLOGI("begin\n");
+ dry_run = property_get_bool("dumpstate.dry_run", 0) != 0;
+ if (is_dry_run()) {
+ MYLOGI("Running on dry-run mode (to disable it, call 'setprop dumpstate.dry_run false')\n");
+ }
+
/* gets the sequential id */
char last_id[PROPERTY_VALUE_MAX];
property_get("dumpstate.last_id", last_id, "0");