From f10153257f6f3fdc112be6a2a4c7eb2e02bf5ed6 Mon Sep 17 00:00:00 2001 From: afohrman Date: Tue, 25 Jul 2023 14:52:46 +0000 Subject: [PATCH] [Predictive Back][Search] Fixed `UnsupportedOperationException` `AnimatorSet` crash in `SearchView`. When navigation icon animation is disabled after the predictive back navigation icon animators are initialized, a strange crash happens in `SearchViewAnimatorSet#updateBackProgress` from the call to `AnimatorSet#setCurrentPlayTime()`, in which the button progress `AnimatorSet` duration is 250 but the total duration is 0. This triggers an [`UnsupportedOperationException`](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/animation/AnimatorSet.java#928) with the message: `"Error: Play time should always be in between 0 and duration."`. Adding an early return from `SearchViewAnimatorSet#updateBackProgress` when navigation animation is disabled appears to fix the crash. PiperOrigin-RevId: 550885523 --- .../android/material/search/SearchViewAnimationHelper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java b/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java index 31bbd3d7d11..b1d636f045d 100644 --- a/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java +++ b/lib/java/com/google/android/material/search/SearchViewAnimationHelper.java @@ -629,6 +629,11 @@ public void updateBackProgress(@NonNull BackEventCompat backEvent) { searchView.clearFocusAndHideKeyboard(); } + // Early return if navigation icon animation is disabled. + if (!searchView.isAnimatedNavigationIcon()) { + return; + } + // Start and immediately pause the animator set so we can seek it with setCurrentPlayTime() in // subsequent updateBackProgress() calls when the progress value changes. backProgressAnimatorSet = getButtonsProgressAnimator(/* show= */ false);