From 1d314faeaf2012558b3927d0e2b5fa2a99a165e4 Mon Sep 17 00:00:00 2001 From: Pranav Vashi Date: Thu, 23 Oct 2025 22:48:48 +0530 Subject: [PATCH] SystemUI: SeekBarViewModel: Fix duration elvis and clamp in checkPlaybackPosition Signed-off-by: Pranav Vashi --- .../media/controls/ui/viewmodel/SeekBarViewModel.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/viewmodel/SeekBarViewModel.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/viewmodel/SeekBarViewModel.kt index 6175b6e47b52a..6b9b4e15b34a8 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/viewmodel/SeekBarViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/viewmodel/SeekBarViewModel.kt @@ -321,10 +321,13 @@ constructor( @WorkerThread private fun checkPlaybackPosition() { - val duration = _data.duration ?: -1 - val currentPosition = playbackState?.computePosition(duration.toLong())?.toInt() - if (currentPosition != null && _data.elapsedTime != currentPosition) { - _data = _data.copy(elapsedTime = currentPosition) + val duration = _data.duration.takeIf { it > 0 } ?: -1 + val pos = playbackState?.computePosition(duration.toLong())?.toInt() + if (pos != null) { + val clamped = if (duration >= 0) pos.coerceIn(0, duration) else pos.coerceAtLeast(0) + if (_data.elapsedTime != clamped) { + _data = _data.copy(elapsedTime = clamped) + } } }