Merge "Filter buckets with zero usage" into main

This commit is contained in:
Chaohui Wang
2024-04-02 03:25:44 +00:00
committed by Android (Google) Code Review
2 changed files with 35 additions and 7 deletions

View File

@@ -93,13 +93,15 @@ class NetworkStatsRepository(context: Context, private val template: NetworkTemp
val buckets = mutableListOf<Bucket>() val buckets = mutableListOf<Bucket>()
val bucket = NetworkStats.Bucket() val bucket = NetworkStats.Bucket()
while (getNextBucket(bucket)) { while (getNextBucket(bucket)) {
buckets += Bucket( if (bucket.bytes > 0) {
uid = bucket.uid, buckets += Bucket(
bytes = bucket.bytes, uid = bucket.uid,
state = bucket.state, bytes = bucket.bytes,
startTimeStamp = bucket.startTimeStamp, state = bucket.state,
endTimeStamp = bucket.endTimeStamp, startTimeStamp = bucket.startTimeStamp,
) endTimeStamp = bucket.endTimeStamp,
)
}
} }
buckets buckets
} }

View File

@@ -125,6 +125,32 @@ class AppDataUsageDetailsRepositoryTest {
) )
} }
@Test
fun queryDetailsForCycles_appWithZeroUsage_filtered(): Unit = runBlocking {
networkStatsRepository.stub {
on { queryBuckets(CYCLE1_END_TIME, CYCLE2_END_TIME) } doReturn listOf(
Bucket(
uid = UID,
bytes = 0L,
startTimeStamp = 0L,
endTimeStamp = 0L,
),
)
}
val repository = AppDataUsageDetailsRepository(
context = context,
cycles = null,
template = template,
uids = listOf(UID),
networkCycleDataRepository = networkCycleDataRepository,
networkStatsRepository = networkStatsRepository,
)
val detailsForCycles = repository.queryDetailsForCycles()
assertThat(detailsForCycles).isEmpty()
}
private companion object { private companion object {
const val CYCLE1_START_TIME = 1694444444000L const val CYCLE1_START_TIME = 1694444444000L
const val CYCLE1_END_TIME = 1695555555000L const val CYCLE1_END_TIME = 1695555555000L