From 6b67a3665c734af4b83433f5942b6944cdcaf532 Mon Sep 17 00:00:00 2001 From: Pranav Vashi Date: Thu, 23 Oct 2025 22:52:18 +0530 Subject: [PATCH] SystemUI: SeekBarViewModel: Proper MotionEvent handling Signed-off-by: Pranav Vashi --- .../controls/ui/viewmodel/SeekBarViewModel.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 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 6b9b4e15b34a8..768d3591fcf5b 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 @@ -309,7 +309,7 @@ constructor( /** Call to clean up any resources. */ @AnyThread - fun onDestroy() = + fun onDestroy() { bgExecutor.execute { controller = null playbackState = null @@ -318,6 +318,11 @@ constructor( scrubbingChangeListener = null enabledChangeListener = null } + firstMotionEvent?.recycle() + lastMotionEvent?.recycle() + firstMotionEvent = null + lastMotionEvent = null + } @WorkerThread private fun checkPlaybackPosition() { @@ -531,6 +536,8 @@ constructor( // Indicates if the gesture should go to the seek bar or if it should be intercepted. private var shouldGoToSeekBar = false + private fun MotionEvent.safeCopy(): MotionEvent = MotionEvent.obtain(this) + /** * Decide which touch events to intercept before they reach the seek bar. * @@ -552,7 +559,8 @@ constructor( } detector.onTouchEvent(event) // Store the last motion event done on seekbar. - viewModel.lastMotionEvent = event.copy() + viewModel.lastMotionEvent?.recycle() + viewModel.lastMotionEvent = event.safeCopy() return !shouldGoToSeekBar } @@ -598,7 +606,8 @@ constructor( bar.parent?.requestDisallowInterceptTouchEvent(true) } // Store the first motion event done on seekbar. - viewModel.firstMotionEvent = event.copy() + viewModel.firstMotionEvent?.recycle() + viewModel.firstMotionEvent = event.safeCopy() return shouldGoToSeekBar }