History log of /frameworks/native/cmds/dumpstate/dumpstate.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
ced6078b0e03a75d9b78e61ce25609bd2cb97b1d 24-Jun-2016 Mark Salyzyn <salyzyn@google.com> dumpstate: Also pick up /sys/fs/pstore/console-ramoops-0 for LAST KMSG

(cherry pick from commit 7d0a762ecaf9f4d005f0f6db913034c2e084d362)

Bug: 29639467
Change-Id: Iba0b1754eaebfb2b0624dcbef522b7d8456eeb50
ab69cc1f11a7e391bd3bb017a22ed747da89b21b 22-Jun-2016 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Run iptables as root." into nyc-dev
c0808155fd10d2d5c49bb4c8d4cafed8da28c182 18-Jun-2016 Felipe Leme <felipeal@google.com> Run iptables as root.

iptables requires root access and su is not available on user builds,
hence it must be ran before dropping uid to shell user.

BUG: 29455997

Change-Id: I10c6337b411875b061ae9556b6e9c44f83301ae1
ea1aa91a25f28fb44f36b394e002ede56302eb30 16-Jun-2016 David Brazdil <dbrazdil@google.com> Merge "Revert "Attach profiles to bug reports"" into nyc-dev
236f7054ec9fcfde32c6ef39097791f0b158dfc2 16-Jun-2016 David Brazdil <dbrazdil@google.com> Revert "Attach profiles to bug reports"

This reverts commit 0faf2b870f934c1cdd883d29642fd84da3b352e2.

Bug: 28610953
Bug: 29395357
Change-Id: I609fe344dfc61311e37b91b48480d9392764a598
3f83dbe2e0bb9cabe598ef0812ae358b1c5b415f 11-Jun-2016 Felipe Leme <felipeal@google.com> Fixed -t order (should be *after* dumpsys :-)

BUG: 29042642
Change-Id: I1b88634b0152f849a57f8e82adc82bdc5e609db7
6ab3c01d1806e44976c10b34e5f6a5c5531c1da5 10-Jun-2016 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Set version to 1.0" into nyc-dev
f678562fa46992f4f8792429f4237fb925db093f 10-Jun-2016 Felipe Leme <felipeal@google.com> Merge "Expose more useful functions that can be used by dumpstate_board()." into nyc-dev
12af7d51a1a0c4e98955ae58a69552b8f55904eb 08-Jun-2016 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Explicitly sets dumpsys timeout." into nyc-dev
7cff462202437da5bba003a8687582af21fa0a0b 08-Jun-2016 Felipe Leme <felipeal@google.com> Explicitly sets dumpsys timeout.

The run_command() function takes a timeout as argument, and dumpsys can
also optionally takes a timeout with the -t argument, hence it makes
sense to pass the same value for both (otherwise dumpsys will timeout in

BUG: 29042642
Change-Id: Ib6e987d94e966686bab71223d7f910af9e549814
0faf2b870f934c1cdd883d29642fd84da3b352e2 03-Jun-2016 David Brazdil <dbrazdil@google.com> Attach profiles to bug reports

Includes the entire '/data/misc/profiles' folder in the bug report
ZIP file if not user build.

Bug: 28610953
Change-Id: I99d46f024e5557cf94e6045a51c46a605a00c52b
249beee359da256f7c41c481d45c06765b6a1d8a 04-Jun-2016 Calvin On <con@google.com> Expose more useful functions that can be used by dumpstate_board().

BUG: 28640932
Fixes: 28867848
Change-Id: I38123e5b348f4560212559176eb60dbad4f22364
ca9c12e64d44f6c67cd46819583239f0ad051a51 20-May-2016 Felipe Leme <felipeal@google.com> Set version to 1.0

BUG: 27366368
Change-Id: Iac8ed413d41d0c26a39343025920f433d5d7ddba
0816520c5cd60519d8e221ed92497aa5464e3039 30-May-2016 Erik Kline <ek@google.com> Use explicit path for /vendor/xbin/wlutil

At this time /vendor/xbin is not in root's path.

Bug: 28850734
Change-Id: Ib6c2b6f8b0285854670c843dcc437cfcc84484a8
f7f2b0fd059bc26e27c022f3fb446fc74eab6c88 27-May-2016 Erik Kline <ek@google.com> Add "ip maddr" to dumpstate output for debugging.

Bug: 28966611
Change-Id: I8fdab94fbd41448e52f2fed406e8f43edf7f18ad
6108f5d4004d2a3397c22d22025b8e0eb79b8467 23-May-2016 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Expose functions used to add entries to the zip file." into nyc-dev
71ca15eadd3da0c102a8539f7a88294a94456623 20-May-2016 Felipe Leme <felipeal@google.com> Expose functions used to add entries to the zip file.

Currently only dumpstate.cpp is using the new functions and variables
used to add an entry to the zip file so they're defined locally, but
they should be exposed through the .h so they can be used by the
device-specific dumpstate_board() implementations.

This CL moves the following definitions to the .h:

- bugreport_dir
- add_zip_entry()
- add_zip_entry_from_fd()

It also refactored functions that were taking a specific file location
to use bugreport_dir instead, to avoid pollution on main().

BUG: 28867848
Change-Id: Ic5faa203b0863bc950d640f22fb91977e52b6bfc
34222565fc9cf167d8ebe6068a9695f4b0b0f1b0 19-May-2016 Wei Liu <luciferleo@google.com> Fix the DUMPSYS skip.


Change-Id: Idc108b2d3cfd237f459467a3c399a0ba5e248d24
f0922cc1786c0c2fbf44c10b0005243ecbb4227d 15-May-2016 Nick Kralevich <nnk@google.com> dumpstate: convert sprintfs to snprintfs

Bug: 28731007
Change-Id: Icfa4d6dfaf69e989ec785146a6bde1afb6a6f345
c4eee56dab06a7de1db18327f8d4831f89d1d640 22-Apr-2016 Felipe Leme <felipeal@google.com> Remove temporary file on user builds.

BUG: 27366368
Change-Id: Id85566f6ba02fcb6afc122ffe6990d0a14086375
ef1081f96d3c3915fe84c505674fbd70170ed284 13-Apr-2016 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Added support for 'bugreport -z'." into nyc-dev
2628e9e939fda323fa44c5cb743f4a77b12a312a 13-Apr-2016 Felipe Leme <felipeal@google.com> Added support for 'bugreport -z'.

Dumpstate now supports zipped bugreport, whose output is more complete
than the flat-file bugreports provided prior to N.

The whole workflow is split in different components:

- adb supports a 'bugreport -z <ZIP_FILE>' option, which calls a
bugreportz binary.
- bugreportz starts the dumpstatez service.
- dumpstatez starts dumpstate with some flags that opens a socket for
control (not output).
- Once dumpstate is finished, it prints the bugreport location to
- adb pulls the zip file and renames according to the command-line
- bugreport prints a deprecation message.

The reason for a new binary (bugreportz) instead of passing arguments to
bugreport (like -z) is backward compatibility: pre-N versions of
bugreport would ignore such argument and generate a text bugreport,
which is not what adb would be expecting.

BUG: 27653204

Change-Id: I47f6f677eba11d5fb54818ae5a0b3cab069776ee
a50117e54a97aea5b3b2c279fb5643704c460b05 13-Apr-2016 Nick Kralevich <nnk@google.com> Drop compatibility with pre 2012 adb clients

On very old versions of adb, when "adb bugreport" was executed,
the command "adb shell dumpstate" was run. This was later changed
to "adb shell bugreport". Change
1e339878c128ef47271278779c2685a8dfa49cd1 added a backwards
compatibility hack (see bug 6391938).

It turns out that nobody has been able to execute
/system/bin/dumpstate as a non-root user for 2 releases now due
to SELinux restrictions, so maintaining the code bloat to support
this workaround is pointless.

Delete the code.

Bug: 6391938
Change-Id: I49eebcca1fcec5a39593c53e2e6d23ec87f65a35
cc37b8ecc463a3e030d673ebdd0b1cb9c5eddab8 11-Apr-2016 Felipe Leme <felipeal@google.com> Setting v1-dev4 as default.

BUG: 27618668
Change-Id: I59c3a7c256c4d059ae3c29411120d3e9c9a5d995
4d42dea08915ccbb61ca05903af5330d02d66755 01-Apr-2016 Mark Salyzyn <salyzyn@google.com> dumpstate: acquire /data/misc/logd/ log contents

Bug: 27965066
Change-Id: I78c7ef4b45179729f505c3fe5d84c33a22ce41bf
fbe08bfdfdadfcf05bb83e255fa12fc44202aa73 31-Mar-2016 Felipe Leme <felipeal@google.com> Merge "Add build id as part of bugreport name." into nyc-dev
9385b1761aeaaee586cb4777345b18d5517821af 31-Mar-2016 Felipe Leme <felipeal@google.com> Add build id as part of bugreport name.

Rather than bugreport-DATE, the base bugreport name will be
bugreport-BUILD_ID-DATE, which will make it easier to identify
build associated with the report.

Since this change modifies the bugreport format, its version has been
increased to 'v1-dev4' and it is not enabled by default.

BUG: 27618668
Change-Id: I4492f8234520ee27c2eb0e4b8313fc937c498fea
14e034a02ec34b2c76afb06975bdfc943a9b5607 31-Mar-2016 Felipe Leme <felipeal@google.com> Dumps systrace to a file.

The atrace command can take a while, so rather than use a pipe it's
better to write its output to a temporary file and add that file to the
zip, timing out if necessary.

BUG: 27821761
Change-Id: I09f438077d001167d92da3009016bcab815ce530
baa85bd893665a48aee73d7ca7b73cd39b48f998 29-Mar-2016 Felipe Leme <felipeal@google.com> Call _exit() instead of exit() on child failure.

As explained on man _exit:

"The function _exit() terminates the calling process "immediately".
Any open file descriptors belonging to the process are closed;"

If exit() is called instead, the resulting zip file will be corrupted.

BUG: 27900023
BUG: 27804637
Change-Id: I6591749603753d6016f350c629b7082cf6780ae2
d6ab01105bbd80dfa2fc2debc8e31d6422c378ee 25-Mar-2016 Mark Salyzyn <salyzyn@google.com> dumpstate: Add /data/misc/recovery

(cherry picked from commit 23e86e91ff971a00f62954833a17df2dad1a13af)

Bug: 27176738
Change-Id: Ibc2342c6a29e5aebcac4875d7c2eed48fa8af7de
ea160d134cd46c246859072f90ab5dd05ada6364 24-Mar-2016 Felipe Leme <felipeal@google.com> Improved (or warned about lack of) error handling.

It would be safer for dumpstate to exit when execvp on a child fails; a
common occurrence is when a list of command arguments is missing NULL.

dumpstate should be more robust to detect those missing NULL-terminated
args, but that will be addressed in a future change.

BUG: 27804637
BUG: 27832567
Change-Id: Ibcbe46041a86b16e365fbb40613b8c4bdf39744c
73f731c30a8b7d811127b8e89e01c427b6aab622 24-Mar-2016 Felipe Leme <felipeal@google.com> Fixed send_broadcast and fork handling issues.

send_broadcast() was calling run_command_always(char*, bool, int, char*) passing:
run_command_always(NULL, 20, true, am_args);

I.e., it was passing "true" (!1) as the boolean, and 1 (true) as the
timeout value; the proper call should be:

run_command_always(NULL, true, 20, am_args);

Also, the code handling failure on child calls was calling _exit(),
which quits dumpstate - it should simply return the function instead.

BUG: 27804637

Change-Id: If8c9b40eddc8b76f92e6d11078dfe446a39ad4d4
b0133cdeaa98afa55249546f68b6167f1dde65b8 23-Mar-2016 Felipe Leme <felipeal@google.com> Handled failure of execvp and increases am timeout.

The run_command_always() call fork and runs the command in the child
code, and user to have the above logic:

if (pid == 0) {
// boiling code
execvp(command, (char**) args);
// execvp's result will be handled after waitpid_with_timeout() below...
_exit(-1); // ...but it doesn't hurt to force exit, just in case

Recently, the _exit(-1) line was removed and there's been reports of
dumpstate hanging after, because it tries to wait for pid 0 to
finish (and in some cases it even tries to kill it).

Also increased the timeout when running am to send broadcasts.

BUG: 27804637
BUG: 27809534
Change-Id: Ia129253e367e5886d305947e56a643fd660a33bd
8b78b758a8b5b831c48562233df055c22e2541af 22-Mar-2016 Thierry Strudel <tstrudel@google.com> dumpsys: make timeout value an argument

Also rework the args parsing using getopt_long.

Bug: 27788406
Change-Id: I60fd8e614616334d47b8de574f3c81a121a6ac0a
Signed-off-by: Thierry Strudel <tstrudel@google.com>
26ae72392e76e4acc82842f4a53ad41bcbc6811e 21-Mar-2016 Felipe Leme <felipeal@google.com> Fixed typo.

BUG: 27419521

Change-Id: Ie9f0b24876353e532f4ebe2ff4935938c3c7a781
7363bafd0a94aa98a267edbbcb27abc9ef72f1dd 21-Mar-2016 Felipe Leme <felipeal@google.com> Merge "Don't use su to when calling am or dumpsys." into nyc-dev
71a74ac75c8687195d27642fa0db31a796102c59 17-Mar-2016 Felipe Leme <felipeal@google.com> Capture systrace buffers.

When tracing is enabled (/sys/kernel/debug/tracing/tracing_on = 1),
dumpstate will run 'atrace --async_dump' and redirect its output to a
systrace.txt entry in the zip file.

BUG: 27419521
Change-Id: Ia6de46a691b25febac31331fe0aa8701c9a84ebb
cf6a8b47dc04f1c33ddc337b5e21f2c5b7354cb5 11-Mar-2016 Felipe Leme <felipeal@google.com> Don't use su to when calling am or dumpsys.

su is not available on user builds anymore, hence the bugreport
notifications would never be sent on those builds. Instead, it should
explicitly drop root using system calls.

BUG: 27583193
Change-Id: Ia6256b241fdd6ab4c059fb764b10b4445ad6551d
d3d45c3dddf48d557f2b0d622df8ebc1317f9bb5 17-Mar-2016 Felipe Leme <felipeal@google.com> Merge "Improve logging of child commands." into nyc-dev
a34efb7ae17a7ea1078cce75be634120bd72a421 11-Mar-2016 Felipe Leme <felipeal@google.com> Improve logging of child commands.

When execvpe() is called it doesn't return, so the child error handling
should be done at the parent, otherwise the failure is not printed in the bugreport.

BUG: 27583193
Change-Id: I6161e4c72b7b0da7b82bff7fd72d7a5aaf4d6e89
26bd34c984f11dcfc241fecf7858d16f87f3bc1a 15-Mar-2016 Felipe Leme <felipeal@google.com> Added zip location on log message.

BUG: 27660862
Change-Id: I6e9dc816955762fde0d4ddb9ac4cbf12b607cbbd
f7f2651e0c07d138679fd405999f30d0ab35e10b 11-Mar-2016 Lorenzo Colitti <lorenzo@google.com> Pass -n to netstat.

netstat does lots of DNS lookups, which will slow down the dump
process and creates the risk that the dump will be incomplete.

Bug: 26154009
Change-Id: Ibefa259bf74e85ab8dbdfac76f82c101d47686a7
e4eb4f0e2380f698d31b0089fb0e22020b70c2bc 11-Mar-2016 Lorenzo Colitti <lorenzo@google.com> Merge "Remove the route command from dumpstate." into nyc-dev
990bcce0fddc765f8d5398b431ab461a775fc10c 11-Mar-2016 Lorenzo Colitti <lorenzo@google.com> Remove the route command from dumpstate.

Its output is irrelevant and misleading, because:

1. It only looks at the "main" routing table, which is a last
resort routing table that is trumped by all other networks and
cannot even be used by non-root users.
2. The proper way to understand device routing is to look at the
output of "ip rule" and "ip route", both of which are already
in the bugreport.

Bug: 26154009
Change-Id: Ice19799639daa156a0d4dbb69915031e5582a8ed
107a05f72e711c92545d0be648ab79c4f858f372 09-Mar-2016 Felipe Leme <felipeal@google.com> Improved usage of stderr for logging.

Dumpstate have some macros that write logs to both ALOG and stderr,
which is useful when the latter is redirected to a file.

But prior to this change, only the log statements from dumpstate.cpp
were using it, and utils.cpp was logging to stderr directly.

This change not only uses MYLOGE for all error messages, but also closes
stderr at the very end (so it doesn't miss statements like the
parameters sent to send_broadcast) and uses MYLOGD for the overall progress.

BUG: 27437378
Change-Id: I373a523e20c98d8f445822103784fa9900c6c684
9c74aadb40cb5982cd38410529d464485c182058 01-Mar-2016 Felipe Leme <felipeal@google.com> Removed temporary 'v1-dev1-dumpsys-split' version and bumped version to

BUG: 26639621
Change-Id: I5f26272d221330b01d2b873e00105a8f8b739b63
ed9e142fb6874cd1d3cbeb655c700c9a0126ba5a 27-Feb-2016 Felipe Leme <felipeal@google.com> Merge "Rename .zip file if necessary." into nyc-dev
9127435ffbb081fe91a30169f394a57fd31fd05e 27-Feb-2016 Felipe Leme <felipeal@google.com> Rename .zip file if necessary.

Users have the option to rename the suffix of the files generated by
dumpstate by letting Shell set the dumpstate.PID.name property.

This works fine for text files and used to work for zip files as well,
but now the zip file is opened earlier in the process, so it has to be
renamed at the end.

BUG: 27384407
Change-Id: I288d8eb4a3ffe0161b86cdce14f63e9bfdf865ab
cc2a2fa64e22378d980ae0ae95c8865ebea05f69 25-Feb-2016 Felipe Leme <felipeal@google.com> Moved final vibration to the end of the process.

BUG: 26347468
Change-Id: I872d9175fd09b47da512cb2da11a533a921d9a5c
503ebdbc5ecae9dda74124a4350c40f81a695c02 24-Feb-2016 Felipe Leme <felipeal@google.com> Merge "Improved dumpstate logging." into nyc-dev
c4e490047a7dd605fb087b71d3b97182e409985c 23-Feb-2016 Felipe Leme <felipeal@google.com> Merge "Send max duration when bugreport is finished so Shell can update metrics." into nyc-dev
ee2e4a01f9ca9aae7ee111abcd5c139fc810bf65 23-Feb-2016 Felipe Leme <felipeal@google.com> Send max duration when bugreport is finished so Shell can update

BUG: 26759986
Change-Id: If599bfb2558c523e64fd6f176eeb494d3e116928
f9dbae88419bc5bb272a41cceadd1b4e318f5572 22-Feb-2016 Ruchi Kandoi <kandoiruchi@google.com> dumpstate: Remove deprecated /proc/wakelocks

Bug: 13930710
Change-Id: I64733a6093ca227aaee29fc58288a964b7b6b7f9
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
88c7933df551f6dadd8cc931d104b01d6d1609e4 22-Feb-2016 Felipe Leme <felipeal@google.com> Improved dumpstate logging.

BUG: 26906985
Change-Id: Id439560504a365961337fddcca4ba6c1ef9f377d
6fe9db67f6c92d5fbf87d371da5cca412f672630 12-Feb-2016 Felipe Leme <felipeal@google.com> Changed permission of temporary bugreport and dumpstate log files to Shell.

BUG: 27164100

Change-Id: I569cbe4854fad44c95c9bf3e2efa9c3c93317003
421c1c07e73ef91a8fb887ad0045f37335722b2e 12-Feb-2016 Felipe Leme <felipeal@google.com> Merge "Split bugreport identifier into id and pid." into nyc-dev
d5e724a4d3f77024d311b1b4e01846e41fdbe98b 11-Feb-2016 Felipe Leme <felipeal@google.com> Send broadcasts as Shell.

The BUGREPORT_STARTED was being sent as root, which would cause it to
bypass Shell restrictions when DISALLOW_DEBUGGING_FEATURES is set.

Also added the missing --receiver-background and unhardcoded shell's uid
from previous changes.

BUG: 26814173

Change-Id: I867361efafb96c7e709f83806a9301afc637a27e
fdf52d3697aa0396bd9d8883892937b99a6772a0 02-Feb-2016 Srinath Sridharan <srinathsr@google.com> Split dumpsys into critical and non-critical sections.

Order in which we report stats in bugreport can disrupt cpu and memory
stats. This CL sorts the bugreport process
from least impactful to most impactful to try and keep the
system stats as close to its initial state as possible throughout the BR (eg.
things like dumpsys meminfo should run before dumping thread stacks)

BUG: 26639621
Change-Id: I29dccfd423d83a6a69b7e025d45cb9cebfc41cc4
1b0225a4792d92ff67ac8a0aa79352fad40bd805 10-Feb-2016 Felipe Leme <felipeal@google.com> Fixed format.

Change-Id: If0322e3dcf56005541aa08e0ab91dae10d2d385d
60869c9e1e91170d487715fc30b795d786630c54 10-Feb-2016 Felipe Leme <felipeal@google.com> Fixed C++ syntax.

Change-Id: I9702fdede589dd37cb498bbf63c0773816a7e3b8
a297c3258f6f7ea52cc2dcc42d62f85fda12a163 06-Feb-2016 Mark Salyzyn <salyzyn@google.com> dumpstate: report process times

(cherry picked from commit 0751efa64cddfab69749236193e776058c9db595)

- Fix per-pid helper to pick up comm if cmdline is empty
and assume kernel thread.
- Add per pid report command line user time if not kernel thread,
system time and I/O time, plus percentage if non zero.

Bug: 26966375
Change-Id: I6b499f535cc3687eb468b32ae39e7d151dffb11f
8fecfdda012928bc2fe6d0e66fd4a4c912946254 09-Feb-2016 Felipe Leme <felipeal@google.com> Split bugreport identifier into id and pid.

Although 'pid' is more useful when diagnosing problems with the
bugreport workflow, it could be confusing to the end user. Hence, a
sequential id (started at 1 after a reboot) would be more useful.

BUG: 27076108
Change-Id: I6fd7ea8c703e8040034af183ef5cd35adfbcb4ef
cbce55d4fdbdd2e5a5515054c48d2116c5db2712 08-Feb-2016 Felipe Leme <felipeal@google.com> Improved dumpstate logging.

dumpstate generates 3 types of output:

- stdout: used for the bugreport itself and is redirected to a file
if requested.
- stderr: used for errors, is only useful when dumpstate is called from
adb (otherwise is ignored).
- ALOG: logged into logcat and available in the bugreport.

This current approach has 2 problems:

- stderr output is ignored when dumpstatet is called from bugreport
- bugs on dumpstate are often hard to diagnose
(AKA 'Who watches the watchmen?').

This change mitigates these problems by redirecting stderr into a log
file (which will also be included in the bugreport notification) and by
keeping the .tmp file around (for the extreme cases where the .zip file
could not be generated or got corrupted).

BUG: 26906985
Change-Id: I73e7b1dd10ad9f83b7aa1043131ff3b74c426fdb
010f15bb6dadc92e25cae52142ee13036adc5a73 05-Feb-2016 Mark Salyzyn <salyzyn@google.com> Merge "dumpstate: refine calculated eMMC performance values" am: 088e7586ea am: 917b324e19
am: a960bc95b2

* commit 'a960bc95b2430ba01fc4b04b4527d32e00eeb4b5':
dumpstate: refine calculated eMMC performance values
a960bc95b2430ba01fc4b04b4527d32e00eeb4b5 05-Feb-2016 Mark Salyzyn <salyzyn@google.com> Merge "dumpstate: refine calculated eMMC performance values" am: 088e7586ea
am: 917b324e19

* commit '917b324e19121766a9f8112d0fbc4424f172e615':
dumpstate: refine calculated eMMC performance values
01d6c3935ace93f208fa3d93802b286e7484cfae 04-Feb-2016 Mark Salyzyn <salyzyn@google.com> dumpstate: refine calculated eMMC performance values

Correct the raw performance with the average queue depth. Add a
report for I/O per second, and the average queue depth. Round
values up.

Bug: 26966375
Change-Id: I2a8d233872d5e5ff79d433abba3c34d5945701f4
111b9d06cc0fc72438782c9234f28675e5077ef4 03-Feb-2016 Felipe Leme <felipeal@google.com> Improved how the Shell directories are created.

When dumpstate is run for the first time, the
/data/data/com.android.shell/files/bugreports does not exist, which was
crashing dumpstate because the code that added the version.txt entry was
not checking if the zip_writer was NULL.

The crash itself was fixed by adding a sanity check in the functions
that add entries to the zip file, but that only hid the real problem:
it is necessary to create the parent directories before creating the zip
file, otherwise the first run will always generate a .txt file (since
dumpstate falls back to .txt when it cannot create the .zip).

This change also improves how the parent directories are created by
checking if they exist first, rather than always calling mkdir().

BUG: 26949960

Change-Id: I1434be5c36a3fad0b3a2a26c7eaaab03a1228c30
809d74e92c16cf694c929b8ca2b54515af13e9fe 02-Feb-2016 Felipe Leme <felipeal@google.com> Added metadata entries to zipped bugreport:

- version.txt: bugreport format version
- main-entry.txt: name of the entry containing the main bugreport (flat file)

Also documented the zip format versions on bugreport-format.txt.

BUG: 26910355
BUG: 26639621

Change-Id: I76b9f6d330c36ad554fae8e691c9ea3ab3c97edd
608385dd151e36a93f3e3f4a7514b1e720d20ae9 01-Feb-2016 Felipe Leme <felipeal@google.com> Redirect output to file ASAP, otherwise printf() calls might be missed.

Also removed the duraction reporter on add_zip_entry_from_fd - since it
was spamming the report and the timing could be infered by calculating the
delta between each ALOGD entry anyways - and logged PID and statistics.

BUG: 26885492
Change-Id: Iadb00957daac68b7a40b0e36ee5cce2b82264588
43fd1bbc6675430a4ecfde07e88a414ed5c41c0c 29-Jan-2016 Felipe Leme <felipeal@google.com> Proper fix of am args.

BUG: 26871362
Change-Id: If3411b69ea1feef827cd23ef81baa8c0ffeaa309
b0b4aa2d1df3c2c1f591776083a33cd28ad306bd 29-Jan-2016 Felipe Leme <felipeal@google.com> Fixed usage --receiver-foreground on am call.

BUG: 26871362
Change-Id: Ied8e663eec59c83a06a8f2a6e2908c02ac1558c8
770410dcf2f72cf4e806442263e63719a0be0f5a 27-Jan-2016 Felipe Leme <felipeal@google.com> Fixed performance issue by moving buffer allocation outside loop.

Also improved logging.

BUG: 26637170
BUG: 26777547
Change-Id: I99511f3f71c58eba1f5539508f9a685d0a58cc58
876de450004b02b9c028ece0d3ca850504caaa4d 26-Jan-2016 Mark Salyzyn <salyzyn@google.com> Merge "Revert "dumpstate: Add security log dump"" am: 316923d359
am: fd0d76730f

* commit 'fd0d76730f06bec15c90e9a9da64ee19361c3a9f':
Revert "dumpstate: Add security log dump"
fd0d76730f06bec15c90e9a9da64ee19361c3a9f 26-Jan-2016 Mark Salyzyn <salyzyn@google.com> Merge "Revert "dumpstate: Add security log dump""
am: 316923d359

* commit '316923d3597af72d1cbd9eb2745a02706275fdb8':
Revert "dumpstate: Add security log dump"
43afe5d0b537999d5de9613626eca24f34cc52ef 26-Jan-2016 Mark Salyzyn <salyzyn@google.com> Revert "dumpstate: Add security log dump"

This reverts commit c7ad8cb82f035576c28707a8cbeb16b7ead2a4e7.

Bug: 26029733
Change-Id: I0c61f4d2c0aa9e07c6cc7b190d803e98c3a98d40
f3599b35c5f7f86cced0f3386a6c80e0b552f358 26-Jan-2016 Nick Kralevich <nnk@google.com> dumpstate.cpp: collect command line earlier

We need to collect the command line before we use it.

Bug: 26777547
Change-Id: I715adce62511c4cc553eb462d853559687a1677f
cbbdf73608bace91270622034e4813a2355b7bf1 07-Jan-2016 Michal Karpinski <mkarpinski@google.com> Improvements for SHA256_file_hash()

Bug: 26154009
Change-Id: I7cee0563edb7e8030716ae2925a940f3c158721e
4db754fd7c13993d81d98157f10e8015422d1e3a 11-Dec-2015 Michal Karpinski <mkarpinski@google.com> dumpstate.cpp changes to accomodate remote bugreports

Added four new commands to dumpstate() - route, printenv, netstat
and lsmod.
Added -R flag for remote bugreports, which will send
android.intent.action.REMOTE_BUGREPORT_FINISHED broadcast with an extra
SHA256 hash counted by a new method SHA256_file_hash(path).

Bug: 26154009
Change-Id: Ibd7cb8f38dfc8f0fa3fda3e56dcd04b7d1fe68b9
635ca31754ae734b0c540ac5600d58ae55cd4237 05-Jan-2016 Felipe Leme <felipeal@google.com> Include mount info on zipped bugreport.

BUG: 7280247
Change-Id: Iae2a7881c11564c8dbd3641f5ee5ab72c181da2a
e82a27d0c1e3f2cef6f13a1a9efff55638601752 05-Jan-2016 Felipe Leme <felipeal@google.com> Adds recovery files when writing to zip file.

BUG: 25351711
Change-Id: I3bac7a0d3a6f388b46570595d22436f0a4f74bee
0c80cf0caaf5dce5ef4d0265b249bd1ec680cca1 05-Jan-2016 Felipe Leme <felipeal@google.com> Adds all tombstone files when writing to zipped file.

Currently, a bugreport simply cats any tombstone file modified in the
last half an hour into the bugreport. This is a problem since the
tombstones contain a lot of really valuable information, and sometimes
users don't get a bugreport in this time frame. In addition, some of our
monkey testing has the same problem.

Since now dumpstate can create a zip file, we can include all directly
on it, although still using the old mechanism when it's creating it (for example, when invoked through 'adb bugreport').

BUG: 25974224
Change-Id: Ie29fd7d91953d91232b0db1c9588043aee13f93e
1e9edc619c6b1ca3998a26eaa4882b55ce801f12 22-Dec-2015 Felipe Leme <felipeal@google.com> Refactored zipfile generation.

Previously, the bugreport.zip was only created at after dumpstate
finished, at which point the temporary file was added to it.

With this refactoring, the bugreport.zip is created earlier on and the
temporary file is added at the end: although this change doesn't alter
the final result, it allows future changes to add more files to the .zip

BUG: 26293568
Change-Id: Ic0a111d009aac954c9746130df226a2dfeb679bc
78f2c86235d5882a8dc84c85a1c1864062e5f3af 21-Dec-2015 Felipe Leme <felipeal@google.com> Prints out how long it takes to generate each section.

It's done using a DurationReporter helper class that prints starts
counting when constructed and prints the duration when destructed.

Typical usage:

function do_something() {
DurationReporter duration_reporter(title);
// Do something.

Change-Id: I87134d9a1b003300384376c242a3c034a46244c4
32a59625e0a70eb38648320ddde84e6c91cc9cef 15-Dec-2015 Felipe Leme <felipeal@google.com> Merge "Migrated dumpstate to C++."
am: 1f62517b36

* commit '1f62517b3654a3c0e95ea4d5b3664fac8115acdf':
Migrated dumpstate to C++.
515eb0db0a03de0a721ef034b3f3898e1d7e42e7 15-Dec-2015 Felipe Leme <felipeal@google.com> Migrated dumpstate to C++.

Changes required:

- Explicity casting function pointers.
- Moving variables initialization before 'goto' statements.
- Changing string references from 'char *' to 'const char *'.
- Using 'extern "C"' so device-dependent implementation of
'dumpstate_board()' can be written in C or C++.

BUG: 25563823

Change-Id: Ibeb70fd23e64e9b530736b554a372cb232fe1a44
dca3004731b77dad2bdb26336e0061f63bacf35c 14-Dec-2015 Mark Salyzyn <salyzyn@google.com> Merge "dumpstate: Add security log dump" am: bc611a1d3e
am: 0c124edf7c

* commit '0c124edf7c633588e300f1855d22739194ba7194':
dumpstate: Add security log dump
f55d402132afa4b9dd38aa69e50ec7b7efb1927c 11-Dec-2015 Mark Salyzyn <salyzyn@google.com> resolve merge conflicts of 01c1129fe6 to master.

Change-Id: I84f862b4858ecc97461750833a0e6f9cf96c34c4
8c5ac0a92605a62bff21c23c520ecbf833d683bc 09-Dec-2015 Felipe Leme <felipeal@google.com> Merge "Fixed logic that was passing NULL to a std::string parameter and crashing dumpstate."
3634a1e3459cb609da709646107e246cafbc01f9 09-Dec-2015 Felipe Leme <felipeal@google.com> Fixed logic that was passing NULL to a std::string parameter and
crashing dumpstate.

BUG: 8420215
Change-Id: If2f3ebad559683b5b6a8c2209de93ac3bec4fb1e
b744ac2a7d537dd7227a23ebfc43cff0259dee27 09-Dec-2015 Felipe Leme <felipeal@google.com> Merge "Take screenshot right away when invoked with -P."
9dc117c415d0df0a3acd900709d05deabe975704 07-Dec-2015 Elliott Hughes <enh@google.com> Track rename from base/ to android-base/.

Change-Id: I13839256a0fb159a3b53009c2cb6b0fa639bad2e
e338bf60701e5b955ab0a097f2631f2190218894 07-Dec-2015 Felipe Leme <felipeal@google.com> Take screenshot right away when invoked with -P.

Traditionally, the screenshot was not taken right away because it could
skew other services like the Surface Flinger, and such approach often
resulted on irrelevant screenshots.

Now there is more user-friendly workflow, where the bugreport progress
is shown in the UI and the user can take further actions. In this
workflow, it's ok to take the screeshot right away, since the other
features might already be causing interference: if the user doesn't want
interference, the old workflow should be used instead.

Since the new workflow requires the -P (for Progress) parameter, such
parameter can also be used to determine when to take the screenshot.

Also added progress statistics at the end of the bugreport.

BUG: 8420215
Change-Id: I9dad8ea59d47848f217182ccec0f527b42e07f50
ad5f6c475934ac6a658a203069a9f055540946e7 30-Nov-2015 Felipe Leme <felipeal@google.com> Minor improvements in the bugreport progress workflow:

- Allow users to rename the suffix in the bugreport files by setting the
dumpstate.pid.name system property. For example, instead of
bugreport-2015-12-02-15-23-46, it could be bugreport-My-App-Crashed.

- Dynamically adjust the max weight if the current progress overflows
the previous max (and set the dumpstate.pid.max system property
accordingly, so UI can be updated as well).

- Strip .txt from the name sent on BUGREPORT_STARTED.

BUG: 25794470
Change-Id: I7634ddd2975bcf93d6612d16c09da1cd7b4e1d91
e159c7f25d52636b01e9d8bc7d6175c2263696be 30-Nov-2015 Sharvil Nanavati <sharvil@google.com> Increase raft timeout to 10min so we get complete logs from older devices. am: 804339a59e am: 7126caa17f am: c3ee5e8fb9
am: 47c010ce75

* commit '47c010ce750a1af707f6eee28cd5458fba6f1439':
Increase raft timeout to 10min so we get complete logs from older devices.
9c5440cdfc1fe6a5604abfd91e8d160542a36212 30-Nov-2015 Felipe Leme <felipeal@google.com> Merge "Adds a -P option so dumpstate can report its progress."
b82c925d3cd54d5eff9f4f9e6d5aeb41f75365f5 28-Nov-2015 Nick Kralevich <nnk@google.com> dumpstate: call su before executing librank

librank uses /proc/PID/pagemap . Rather than granting dumpstate
CAP_SYS_ADMIN, have librank run from the SU domain.

Addresses the following denial:

avc: denied { sys_admin } for pid=6442 comm="librank" capability=21 scontext=u:r:dumpstate:s0 tcontext=u:r:dumpstate:s0 tclass=capability permissive=0

This also allows us to remove the setuid bit from librank,
which will be done in a different commit.

Bug: 25739721
Change-Id: Ibf20d67dbe01b95e5cbb860a7e0eb767b8beb74a
71bbfc57974331dce79242ce806d92035fce06ba 23-Nov-2015 Felipe Leme <felipeal@google.com> 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
36b3f6ff17e456dea81501006e33d5fdd1d3b480 20-Nov-2015 Felipe Leme <felipeal@google.com> Allow broadcasting of bug reports without a screenshot.

BUG: 25751868
Change-Id: Ideaa6c549f639aa64b30225147b2fad6c5f2d556
0be2b76ce9a0c943f7aad445bdf5be796c937618 20-Nov-2015 Felipe Leme <felipeal@google.com> Fixed check if zip file was generated properly.

During the earlier development stages, this function was returning an
int and later it was changed to boolean, but the check was not updated.

BUG: 25563823
Change-Id: I77f50bf2184d5dd4da2156a5eca4c8a555b567a4
74ee857d166f0696fe94628bbce391641343c418 16-Nov-2015 Felipe Leme <felipeal@google.com> Merge "Added option (-z) to generate a zipfile with the bugreport."
0b904612c12ab59d1e86c978eb8f7662a101f4b8 13-Nov-2015 Elliott Hughes <enh@google.com> Merge "Move dumpstate to top -H rather than top -t." am: 20986bf383 am: 5e02b1bfbb
am: 439903c2ff

* commit '439903c2ff50cb632891006b9dfad0b4993b8384':
Move dumpstate to top -H rather than top -t.
6e01fa6f95fb20a2faab33561056d2e74cc097cb 12-Nov-2015 Felipe Leme <felipeal@google.com> Added option (-z) to generate a zipfile with the bugreport.

Currently, dumpstate generates a text file and Shell zips it, but that
breaks the android.intent.action.BUGREPORT_FINISHED contract.

Also changed some string variables from char* to std::string.

BUG: 25563823
Change-Id: I6e61798bf559fa9f79f629b22fd410752da2bbf7
55b42a67f69767976ff16ab443b3e7142db693e1 11-Nov-2015 Felipe Leme <felipeal@google.com> Closes stdout when it is redirected to a file.

Bug: 19271141
Change-Id: I2990542649e64bf0a281bb9e322ed7b3b98a75c1
93d705b6d742e8f00167ff2384e35c2205a6f9da 11-Nov-2015 Felipe Leme <felipeal@google.com> Add option to #define _DUMPSTATE_DRY_RUN_ to skip the actual dumps.

Such option is useful when debugging dumpstate itself, since it will
finish much sooner and its output will be much smaller.

Change-Id: If821ed21715461bf82eea0b2be4b926239ad69da
8620bb4118a68721d10c29529dc6978847d08d00 10-Nov-2015 Felipe Leme <felipeal@google.com> Migrated dumpstate to C++.

Changes required:

- Explicity casting function pointers.
- Moving variables initialization before 'goto' statements.
- Changing string references from 'char *' to 'const char *'.
- Using 'extern "C"' so device-dependent implementation of
'dumpstate_board()' can be written in C or C++.

BUG: 25563823
Change-Id: I5712c2adbe181c6d17983cbb136b17757900b4ba