Thermal shutdown fix: cool down on writing to disk

Currently, statsd uses wall clock seconds to write data to disk. This
issue affects both thermal and normal shutdowns, because if two writes
occur in the same second, the more recent write will overwrite the older
write, erasing the actual data that we want.

For thermal shutdowns, we write twice. Once because of termination
signal received, and once because of binder death recipient from
statscompanion service.

For normal clean shutdowns, we write 3 times. In addition to the two
above, we write for the shutdown received signal.

This fix introduces a cool down period of 3 seconds between writing to
disk.

Bug: 112432890
Test: statsd unit tests
Test: statsd cts tests
Test: manually verified normal shutdown had 1 file written to disk
Test: manually verified thermal shutdown had 1 file written to disk
Change-Id: I4cd39de9063935e762ff7d00051ccc915f31e89a
2 files changed