Reset time-since-update if the tracked value is nonmonotonic

The absence of this reset led to timeInStateSinceUpdate exceeding
total timeSinceUpdate.  This resulted in inflated counts,
which are smeared using the `delta * timeInState / timeSinceUpdate` formula.
So, instead of assigning a portion of the time to a specific state
it would assign a multiple of the time to it.

Bug: 204087731
Test: atest libbattery_test

Change-Id: I7805d5c6aa314f4030c8a1ac9541f2d439a471cb
diff --git a/libs/battery/MultiStateCounter.h b/libs/battery/MultiStateCounter.h
index 03e1f2a..a2b59a8 100644
--- a/libs/battery/MultiStateCounter.h
+++ b/libs/battery/MultiStateCounter.h
@@ -195,10 +195,18 @@
                         << ", which is lower than the previous value " << valueToString(lastValue)
                         << "\n";
                     ALOGE("%s", str.str().c_str());
+
+                    for (int i = 0; i < stateCount; i++) {
+                        states[i].timeInStateSinceUpdate = 0;
+                    }
                 }
             } else if (timestamp < lastUpdateTimestamp) {
                 ALOGE("updateValue is called with an earlier timestamp: %lu, previous: %lu\n",
                       (unsigned long)timestamp, (unsigned long)lastUpdateTimestamp);
+
+                for (int i = 0; i < stateCount; i++) {
+                    states[i].timeInStateSinceUpdate = 0;
+                }
             }
         }
     }