From 030435773dc5413a690d460e97fd681740cd32ef Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Mon, 18 Aug 2014 10:33:58 -0700 Subject: Fix crash in AnimationDrawable When a drawable becomes invisible, it unschedule itself, which sets mCurrentFrame to -1. Later, when it becomes visible, it calls setFrame() with either 0 (if 'restart' is true) or mCurrentFrame. Calling setFrame() with a value of -1 causes a crash later as we dereference an invalid location in the state durations array. This fix also checks mCurrentFrame and calls setFrame with 0 when the current frame is invalid. This takes the code back closer to what it used to be when setFrame was always called with 0, although now it will use a valid frame when it is set. Issue #16489419 Google Translate crashes whenever hitting done button on keyboard to get translation result. Change-Id: I1f5b8672d209017aa8a4eaa15bd7ddd2f3ae38d1 --- graphics/java/android/graphics/drawable/AnimationDrawable.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/drawable/AnimationDrawable.java b/graphics/java/android/graphics/drawable/AnimationDrawable.java index 5318fa7b0c94..d87e8e4075a9 100644 --- a/graphics/java/android/graphics/drawable/AnimationDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimationDrawable.java @@ -114,7 +114,9 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An final boolean changed = super.setVisible(visible, restart); if (visible) { if (restart || changed) { - setFrame(restart ? 0 : mCurFrame, true, mAnimating); + boolean startFromZero = restart || mCurFrame < 0 || + mCurFrame >= mAnimationState.getChildCount(); + setFrame(startFromZero ? 0 : mCurFrame, true, mAnimating); } } else { unscheduleSelf(this); -- cgit v1.2.3-59-g8ed1b