Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/promoted/PromotedNotificationContentExtractorImplTest.kt +75 −15 Original line number Diff line number Diff line Loading @@ -188,13 +188,24 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime(hasTime = false, hasChronometer = false, expected = ExpectedTime.Null) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_basicTimeZero() { assertExtractedTime( hasTime = true, hasChronometer = false, provided = ProvidedTime.Value(0L), expected = ExpectedTime.Time, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_basicTimeNow() { assertExtractedTime( hasTime = true, hasChronometer = false, whenOffset = Duration.ZERO, provided = ProvidedTime.Offset(Duration.ZERO), expected = ExpectedTime.Time, ) } Loading @@ -205,7 +216,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime( hasTime = true, hasChronometer = false, whenOffset = (-5).minutes, provided = ProvidedTime.Offset((-5).minutes), expected = ExpectedTime.Time, ) } Loading @@ -216,11 +227,23 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime( hasTime = true, hasChronometer = false, whenOffset = 5.minutes, provided = ProvidedTime.Offset(5.minutes), expected = ExpectedTime.Time, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countUpZero() { assertExtractedTime( hasTime = false, hasChronometer = true, isCountDown = false, provided = ProvidedTime.Value(0L), expected = ExpectedTime.CountUp, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countUpNow() { Loading @@ -228,7 +251,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = false, whenOffset = Duration.ZERO, provided = ProvidedTime.Offset(Duration.ZERO), expected = ExpectedTime.CountUp, ) } Loading @@ -240,7 +263,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = false, whenOffset = (-5).minutes, provided = ProvidedTime.Offset((-5).minutes), expected = ExpectedTime.CountUp, ) } Loading @@ -252,11 +275,23 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = false, whenOffset = 5.minutes, provided = ProvidedTime.Offset(5.minutes), expected = ExpectedTime.CountUp, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countDownZero() { assertExtractedTime( hasTime = false, hasChronometer = true, isCountDown = true, provided = ProvidedTime.Value(0L), expected = ExpectedTime.CountDown, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countDownNow() { Loading @@ -264,7 +299,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = true, whenOffset = Duration.ZERO, provided = ProvidedTime.Offset(Duration.ZERO), expected = ExpectedTime.CountDown, ) } Loading @@ -276,7 +311,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = true, whenOffset = (-5).minutes, provided = ProvidedTime.Offset((-5).minutes), expected = ExpectedTime.CountDown, ) } Loading @@ -288,7 +323,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = true, whenOffset = 5.minutes, provided = ProvidedTime.Offset(5.minutes), expected = ExpectedTime.CountDown, ) } Loading @@ -299,6 +334,12 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime(hasTime = true, hasChronometer = true, expected = ExpectedTime.CountUp) } private sealed class ProvidedTime { data class Value(val value: Long) : ProvidedTime() data class Offset(val offset: Duration = Duration.ZERO) : ProvidedTime() } private enum class ExpectedTime { Null, Time, Loading @@ -310,7 +351,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime: Boolean = false, hasChronometer: Boolean = false, isCountDown: Boolean = false, whenOffset: Duration = Duration.ZERO, provided: ProvidedTime = ProvidedTime.Offset(), expected: ExpectedTime, ) { // Set the two timebases to different (arbitrary) numbers, so we can verify whether the Loading @@ -318,14 +359,24 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { systemClock.setCurrentTimeMillis(1_739_570_992_579L) systemClock.setElapsedRealtime(1_380_967_080L) val whenCurrentTime = systemClock.currentTimeMillis() + whenOffset.inWholeMilliseconds val whenElapsedRealtime = systemClock.elapsedRealtime() + whenOffset.inWholeMilliseconds val providedCurrentTime = when (provided) { is ProvidedTime.Value -> provided.value is ProvidedTime.Offset -> systemClock.currentTimeMillis() + provided.offset.inWholeMilliseconds } val expectedCurrentTime = when (providedCurrentTime) { 0L -> systemClock.currentTimeMillis() else -> providedCurrentTime } val entry = createEntry { setShowWhen(hasTime) setUsesChronometer(hasChronometer) setChronometerCountDown(isCountDown) setWhen(whenCurrentTime) setWhen(providedCurrentTime) } val content = extractContent(entry) Loading @@ -338,14 +389,18 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { ExpectedTime.Time -> { val actual = content?.time as? When.Time assertThat(actual).isNotNull() assertThat(actual?.currentTimeMillis).isEqualTo(whenCurrentTime) assertThat(actual?.currentTimeMillis).isEqualTo(expectedCurrentTime) } ExpectedTime.CountDown, ExpectedTime.CountUp -> { val expectedElapsedRealtime = expectedCurrentTime + systemClock.elapsedRealtime() - systemClock.currentTimeMillis() val actual = content?.time as? When.Chronometer assertThat(actual).isNotNull() assertThat(actual?.elapsedRealtimeMillis).isEqualTo(whenElapsedRealtime) assertThat(actual?.elapsedRealtimeMillis).isEqualTo(expectedElapsedRealtime) assertThat(actual?.isCountDown).isEqualTo(expected == ExpectedTime.CountDown) } } Loading Loading @@ -545,6 +600,11 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { if (promoted) { notif.flags = FLAG_PROMOTED_ONGOING } // Notification uses System.currentTimeMillis() to initialize creationTime; overwrite that // with the value from our mock clock. if (notif.creationTime != 0L) { notif.creationTime = systemClock.currentTimeMillis() } return NotificationEntryBuilder().setNotification(notif).build() } Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/promoted/PromotedNotificationContentExtractor.kt +4 −2 Original line number Diff line number Diff line Loading @@ -199,16 +199,18 @@ constructor( extras?.getBoolean(EXTRA_PROGRESS_INDETERMINATE) private fun Notification.extractWhen(): When? { val whenTime = getWhen() return when { showsChronometer() -> { When.Chronometer( elapsedRealtimeMillis = `when` + systemClock.elapsedRealtime() - systemClock.currentTimeMillis(), whenTime + systemClock.elapsedRealtime() - systemClock.currentTimeMillis(), isCountDown = chronometerCountDown(), ) } showsTime() -> When.Time(currentTimeMillis = `when`) showsTime() -> When.Time(currentTimeMillis = whenTime) else -> null } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/promoted/PromotedNotificationContentExtractorImplTest.kt +75 −15 Original line number Diff line number Diff line Loading @@ -188,13 +188,24 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime(hasTime = false, hasChronometer = false, expected = ExpectedTime.Null) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_basicTimeZero() { assertExtractedTime( hasTime = true, hasChronometer = false, provided = ProvidedTime.Value(0L), expected = ExpectedTime.Time, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_basicTimeNow() { assertExtractedTime( hasTime = true, hasChronometer = false, whenOffset = Duration.ZERO, provided = ProvidedTime.Offset(Duration.ZERO), expected = ExpectedTime.Time, ) } Loading @@ -205,7 +216,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime( hasTime = true, hasChronometer = false, whenOffset = (-5).minutes, provided = ProvidedTime.Offset((-5).minutes), expected = ExpectedTime.Time, ) } Loading @@ -216,11 +227,23 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime( hasTime = true, hasChronometer = false, whenOffset = 5.minutes, provided = ProvidedTime.Offset(5.minutes), expected = ExpectedTime.Time, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countUpZero() { assertExtractedTime( hasTime = false, hasChronometer = true, isCountDown = false, provided = ProvidedTime.Value(0L), expected = ExpectedTime.CountUp, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countUpNow() { Loading @@ -228,7 +251,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = false, whenOffset = Duration.ZERO, provided = ProvidedTime.Offset(Duration.ZERO), expected = ExpectedTime.CountUp, ) } Loading @@ -240,7 +263,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = false, whenOffset = (-5).minutes, provided = ProvidedTime.Offset((-5).minutes), expected = ExpectedTime.CountUp, ) } Loading @@ -252,11 +275,23 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = false, whenOffset = 5.minutes, provided = ProvidedTime.Offset(5.minutes), expected = ExpectedTime.CountUp, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countDownZero() { assertExtractedTime( hasTime = false, hasChronometer = true, isCountDown = true, provided = ProvidedTime.Value(0L), expected = ExpectedTime.CountDown, ) } @Test @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME) fun extractTime_countDownNow() { Loading @@ -264,7 +299,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = true, whenOffset = Duration.ZERO, provided = ProvidedTime.Offset(Duration.ZERO), expected = ExpectedTime.CountDown, ) } Loading @@ -276,7 +311,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = true, whenOffset = (-5).minutes, provided = ProvidedTime.Offset((-5).minutes), expected = ExpectedTime.CountDown, ) } Loading @@ -288,7 +323,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime = false, hasChronometer = true, isCountDown = true, whenOffset = 5.minutes, provided = ProvidedTime.Offset(5.minutes), expected = ExpectedTime.CountDown, ) } Loading @@ -299,6 +334,12 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { assertExtractedTime(hasTime = true, hasChronometer = true, expected = ExpectedTime.CountUp) } private sealed class ProvidedTime { data class Value(val value: Long) : ProvidedTime() data class Offset(val offset: Duration = Duration.ZERO) : ProvidedTime() } private enum class ExpectedTime { Null, Time, Loading @@ -310,7 +351,7 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { hasTime: Boolean = false, hasChronometer: Boolean = false, isCountDown: Boolean = false, whenOffset: Duration = Duration.ZERO, provided: ProvidedTime = ProvidedTime.Offset(), expected: ExpectedTime, ) { // Set the two timebases to different (arbitrary) numbers, so we can verify whether the Loading @@ -318,14 +359,24 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { systemClock.setCurrentTimeMillis(1_739_570_992_579L) systemClock.setElapsedRealtime(1_380_967_080L) val whenCurrentTime = systemClock.currentTimeMillis() + whenOffset.inWholeMilliseconds val whenElapsedRealtime = systemClock.elapsedRealtime() + whenOffset.inWholeMilliseconds val providedCurrentTime = when (provided) { is ProvidedTime.Value -> provided.value is ProvidedTime.Offset -> systemClock.currentTimeMillis() + provided.offset.inWholeMilliseconds } val expectedCurrentTime = when (providedCurrentTime) { 0L -> systemClock.currentTimeMillis() else -> providedCurrentTime } val entry = createEntry { setShowWhen(hasTime) setUsesChronometer(hasChronometer) setChronometerCountDown(isCountDown) setWhen(whenCurrentTime) setWhen(providedCurrentTime) } val content = extractContent(entry) Loading @@ -338,14 +389,18 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { ExpectedTime.Time -> { val actual = content?.time as? When.Time assertThat(actual).isNotNull() assertThat(actual?.currentTimeMillis).isEqualTo(whenCurrentTime) assertThat(actual?.currentTimeMillis).isEqualTo(expectedCurrentTime) } ExpectedTime.CountDown, ExpectedTime.CountUp -> { val expectedElapsedRealtime = expectedCurrentTime + systemClock.elapsedRealtime() - systemClock.currentTimeMillis() val actual = content?.time as? When.Chronometer assertThat(actual).isNotNull() assertThat(actual?.elapsedRealtimeMillis).isEqualTo(whenElapsedRealtime) assertThat(actual?.elapsedRealtimeMillis).isEqualTo(expectedElapsedRealtime) assertThat(actual?.isCountDown).isEqualTo(expected == ExpectedTime.CountDown) } } Loading Loading @@ -545,6 +600,11 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() { if (promoted) { notif.flags = FLAG_PROMOTED_ONGOING } // Notification uses System.currentTimeMillis() to initialize creationTime; overwrite that // with the value from our mock clock. if (notif.creationTime != 0L) { notif.creationTime = systemClock.currentTimeMillis() } return NotificationEntryBuilder().setNotification(notif).build() } Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/promoted/PromotedNotificationContentExtractor.kt +4 −2 Original line number Diff line number Diff line Loading @@ -199,16 +199,18 @@ constructor( extras?.getBoolean(EXTRA_PROGRESS_INDETERMINATE) private fun Notification.extractWhen(): When? { val whenTime = getWhen() return when { showsChronometer() -> { When.Chronometer( elapsedRealtimeMillis = `when` + systemClock.elapsedRealtime() - systemClock.currentTimeMillis(), whenTime + systemClock.elapsedRealtime() - systemClock.currentTimeMillis(), isCountDown = chronometerCountDown(), ) } showsTime() -> When.Time(currentTimeMillis = `when`) showsTime() -> When.Time(currentTimeMillis = whenTime) else -> null } Loading