Fix usage of flush buckets.

- For pulled metrics, buckets should only be flushed when we did a pull.
Without a pull, we will have incomplete data.
- Flush buckets at the end of each incoming event (on data pull,
app upgrade, condition change). That way, we can ensure that buckets
will be in sync with the conditions.
- Do not throw away on data pull events which are late as long as they
are in the correct bucket. This is expected since we are using
AlarmManager.

Test: atest statsd_test
Change-Id: If1222b6005a0b88bbdae1b4690921c24acd75542
3 files changed