Skip to content
Snippets Groups Projects
Commit 18ba6a77 authored by Pechetty Sravani's avatar Pechetty Sravani Committed by Android (Google) Code Review
Browse files

Merge "Revert^2 "Fix entry lookup in getDurationMs"" into main

parents d739277b ee0908c9
No related branches found
No related tags found
No related merge requests found
......@@ -247,6 +247,35 @@ class AvalancheControllerTest : SysuiTestCase() {
Truth.assertThat(mAvalancheController.headsUpEntryShowing).isEqualTo(nextEntry)
}
@Test
fun testGetDurationMs_untrackedEntryEmptyAvalanche_useAutoDismissTime() {
val givenEntry = createHeadsUpEntry(id = 0)
// Nothing is showing
mAvalancheController.headsUpEntryShowing = null
// Nothing is next
mAvalancheController.clearNext()
val durationMs = mAvalancheController.getDurationMs(givenEntry, autoDismissMs = 5000)
Truth.assertThat(durationMs).isEqualTo(5000)
}
@Test
fun testGetDurationMs_untrackedEntryNonEmptyAvalanche_useAutoDismissTime() {
val givenEntry = createHeadsUpEntry(id = 0)
// Given entry not tracked
mAvalancheController.headsUpEntryShowing = createHeadsUpEntry(id = 1)
mAvalancheController.clearNext()
val nextEntry = createHeadsUpEntry(id = 2)
mAvalancheController.addToNext(nextEntry, runnableMock!!)
val durationMs = mAvalancheController.getDurationMs(givenEntry, autoDismissMs = 5000)
Truth.assertThat(durationMs).isEqualTo(5000)
}
@Test
fun testGetDurationMs_lastEntry_useAutoDismissTime() {
// Entry is showing
......@@ -261,7 +290,7 @@ class AvalancheControllerTest : SysuiTestCase() {
}
@Test
fun testGetDurationMs_nextEntryLowerPriority_500() {
fun testGetDurationMs_nextEntryLowerPriority_5000() {
// Entry is showing
val showingEntry = createFsiHeadsUpEntry(id = 1)
mAvalancheController.headsUpEntryShowing = showingEntry
......
......@@ -153,27 +153,45 @@ class AvalancheController @Inject constructor(
// Use default duration, like we did before AvalancheController existed
return autoDismissMs
}
val showingList: MutableList<HeadsUpEntry> = mutableListOf()
headsUpEntryShowing?.let { showingList.add(it) }
if (headsUpEntryShowing != null) {
showingList.add(headsUpEntryShowing!!)
}
nextList.sort()
val entryList = showingList + nextList
val thisEntryIndex = entryList.indexOf(entry)
if (entryList.isEmpty()) {
log { "No avalanche HUNs, use default ms: $autoDismissMs" }
return autoDismissMs
}
// entryList.indexOf(entry) returns -1 even when the entry is in entryList
var thisEntryIndex = -1
for ((i, e) in entryList.withIndex()) {
if (e == entry) {
thisEntryIndex = i
}
}
if (thisEntryIndex == -1) {
log { "Untracked entry, use default ms: $autoDismissMs" }
return autoDismissMs
}
val nextEntryIndex = thisEntryIndex + 1
// If last entry, use default duration
if (nextEntryIndex >= entryList.size) {
log { "Last entry, use default ms: $autoDismissMs" }
return autoDismissMs
}
val nextEntry = entryList[nextEntryIndex]
if (nextEntry.compareNonTimeFields(entry) == -1) {
// Next entry is higher priority
log { "Next entry is higher priority: 500ms" }
return 500
} else if (nextEntry.compareNonTimeFields(entry) == 0) {
// Next entry is same priority
log { "Next entry is same priority: 1000ms" }
return 1000
} else {
log { "Next entry is lower priority, use default ms: $autoDismissMs" }
return autoDismissMs
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment