Don't set negative values to setWhen()

When the 'when' timer of the notification is disabled
`DefaultMediaNotificationProvider` may set `C.TIME_UNSET`
as the time. Users reported problems on some devices with
this and the docs ask for an event time that probably
shouldn't be a negative number.

This change sets `0L` instead of `C.TIME_UNSET` when the
timer is disabled.

Issue: androidx/media#903

#minor-release

PiperOrigin-RevId: 594451074
This commit is contained in:
bachinger 2023-12-29 06:53:04 -08:00 committed by Copybara-Service
parent 846ace16aa
commit 426bc94090
2 changed files with 4 additions and 1 deletions

View File

@ -117,6 +117,9 @@
[#802](https://github.com/androidx/media/issues/802)).
* Fix broadcasting `notifyChildrenChanged` for legacy controllers
([#644](https://github.com/androidx/media/issues/644)).
* Fix a bug where setting a negative time for a disabled `setWhen` timer
of the notification caused a crash on some devices
([#903](https://github.com/androidx/media/issues/903)).
* UI:
* Fix issue where forward and rewind buttons are not visible when used
with Material Design in a BottomSheetDialogFragment

View File

@ -375,7 +375,7 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
long playbackStartTimeMs = getPlaybackStartTimeEpochMs(player);
boolean displayElapsedTimeWithChronometer = playbackStartTimeMs != C.TIME_UNSET;
builder
.setWhen(playbackStartTimeMs)
.setWhen(displayElapsedTimeWithChronometer ? playbackStartTimeMs : 0L)
.setShowWhen(displayElapsedTimeWithChronometer)
.setUsesChronometer(displayElapsedTimeWithChronometer);