Flush the partial bucket when startd shuts down or config updated.

Test: statsd test

BUG: b/77556036
Change-Id: Ie4a04ace55e07c4529cdff5906ba874f8815f620
diff --git a/cmds/statsd/src/metrics/MetricProducer.h b/cmds/statsd/src/metrics/MetricProducer.h
index db5d32c..f931e57 100644
--- a/cmds/statsd/src/metrics/MetricProducer.h
+++ b/cmds/statsd/src/metrics/MetricProducer.h
@@ -112,9 +112,11 @@
 
     // Output the metrics data to [protoOutput]. All metrics reports end with the same timestamp.
     // This method clears all the past buckets.
-    void onDumpReport(const int64_t dumpTimeNs, android::util::ProtoOutputStream* protoOutput) {
+    void onDumpReport(const int64_t dumpTimeNs,
+                      const bool include_current_partial_bucket,
+                      android::util::ProtoOutputStream* protoOutput) {
         std::lock_guard<std::mutex> lock(mMutex);
-        return onDumpReportLocked(dumpTimeNs, protoOutput);
+        return onDumpReportLocked(dumpTimeNs, include_current_partial_bucket, protoOutput);
     }
 
     void dumpStates(FILE* out, bool verbose) const {
@@ -168,16 +170,26 @@
     virtual void onSlicedConditionMayChangeLocked(bool overallCondition,
                                                   const int64_t eventTime) = 0;
     virtual void onDumpReportLocked(const int64_t dumpTimeNs,
+                                    const bool include_current_partial_bucket,
                                     android::util::ProtoOutputStream* protoOutput) = 0;
     virtual size_t byteSizeLocked() const = 0;
     virtual void dumpStatesLocked(FILE* out, bool verbose) const = 0;
 
     /**
-     * Flushes the current bucket if the eventTime is after the current bucket's end time.
+     * Flushes the current bucket if the eventTime is after the current bucket's end time. This will
+       also flush the current partial bucket in memory.
      */
     virtual void flushIfNeededLocked(const int64_t& eventTime){};
 
     /**
+     * Flushes all the data including the current partial bucket.
+     */
+    virtual void flushLocked(const int64_t& eventTime) {
+        flushIfNeededLocked(eventTime);
+        flushCurrentBucketLocked(eventTime);
+    };
+
+    /**
      * For metrics that aggregate (ie, every metric producer except for EventMetricProducer),
      * we need to be able to flush the current buckets on demand (ie, end the current bucket and
      * start new bucket). If this function is called when eventTimeNs is greater than the current