Don't clobber existing history entries.

Currently, adding a history to a NetworkStatsCollection.Builder
will overwrite any history that was previously passed in with the
same key. This breaks the importer (which is the primary/only
caller of this code), because the importer re-uses the same
NetworkStatsCollection object to import multiple files.

Instead, simply add any passed-in entries after the ones that
were already there. Require the caller to pass in entries in
order, because NetworkStatsHistory internally assumes that
entris are always sorted.

Bug: 230289468
Test: manually verified this unbreaks the importer
Change-Id: Ic8647ff28fca78d579d5f759f96a864877f8158b
Merged-In: Ic8647ff28fca78d579d5f759f96a864877f8158b
  (pure cherry-picked from ag/18453213)
This commit is contained in:
Lorenzo Colitti
2022-05-18 17:32:37 +09:00
committed by Junyu Lai
parent c62261f140
commit ec2fbb7159
4 changed files with 60 additions and 12 deletions

View File

@@ -61,14 +61,6 @@ class NetworkStatsDataMigrationUtilsTest {
assertValues(builder.build(), 55, 1814302L, 21050L, 31001636L, 26152L)
}
@Test
fun testMaybeReadLegacyUid() {
val builder = NetworkStatsCollection.Builder(BUCKET_DURATION_MS)
NetworkStatsDataMigrationUtils.readLegacyUid(builder,
getInputStreamForResource(R.raw.netstats_uid_v4), false /* taggedData */)
assertValues(builder.build(), 223, 106245210L, 710722L, 1130647496L, 1103989L)
}
private fun assertValues(
collection: NetworkStatsCollection,
expectedSize: Int,