diff options
author | joedow <joedow@chromium.org> | 2015-12-08 16:31:24 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-09 00:33:00 +0000 |
commit | 8eb66c08e36b6fa54bce5b7347e9e6e51d8f782d (patch) | |
tree | 44e8416983dffd424fb36aa626c9f0a00f133227 /remoting/android | |
parent | 94278580417ec6bbc7b1c99fead31b6cc448d9cb (diff) | |
download | chromium_src-8eb66c08e36b6fa54bce5b7347e9e6e51d8f782d.zip chromium_src-8eb66c08e36b6fa54bce5b7347e9e6e51d8f782d.tar.gz chromium_src-8eb66c08e36b6fa54bce5b7347e9e6e51d8f782d.tar.bz2 |
Fixing a crash that occurs when our feedback animation is interrupted.
Our input feedback animation code handles being interrupted, however if
the timing is just right, the duration since the start of the animation
will cause the radius of the animation to be 0 which is an invalid
parameter for the RadialGradient class we use to draw the feedback. My
fix is to prevent this from occurring by exiting the render() function
early and allowing the animation to begin on the subsequent render()
call.
BUG=
Review URL: https://codereview.chromium.org/1506013003
Cr-Commit-Position: refs/heads/master@{#363851}
Diffstat (limited to 'remoting/android')
-rw-r--r-- | remoting/android/java/src/org/chromium/chromoting/DesktopView.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java index d2499be..9638755 100644 --- a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java +++ b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java @@ -62,14 +62,14 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, private static final float TOTAL_DURATION_MS = 220; /** Start time of the animation, from {@link SystemClock#uptimeMillis()}. */ - private long mStartTime = 0; + private long mStartTimeInMs = 0; private boolean mRunning = false; /** Contains the size of the feedback animation for the most recent request. */ private float mFeedbackSizeInPixels; - /** Lock to allow multithreaded access to {@link #mStartTime} and {@link #mRunning}. */ + /** Lock to allow multithreaded access to {@link #mStartTimeInMs} and {@link #mRunning}. */ private final Object mLock = new Object(); private Paint mPaint = new Paint(); @@ -92,7 +92,7 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, synchronized (mLock) { mRunning = true; - mStartTime = SystemClock.uptimeMillis(); + mStartTimeInMs = SystemClock.uptimeMillis(); mFeedbackSizeInPixels = getInputFeedbackSizeInPixels(feedbackType); } } @@ -102,7 +102,17 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, float progress; float size; synchronized (mLock) { - progress = (SystemClock.uptimeMillis() - mStartTime) / TOTAL_DURATION_MS; + // |mStartTimeInMs| is set and accessed on different threads (hence the lock). It + // is possible for |mStartTimeInMs| to be updated when an animation is in progress. + // When this occurs, |radius| will eventually be set to 0 and used to initialize + // RadialGradient which requires the radius to be > 0. This will result in a crash. + // In order to avoid this problem, we return early if the elapsed time is 0. + float elapsedTimeInMs = SystemClock.uptimeMillis() - mStartTimeInMs; + if (elapsedTimeInMs < 1) { + return; + } + + progress = elapsedTimeInMs / TOTAL_DURATION_MS; if (progress >= 1) { mRunning = false; return; @@ -244,6 +254,7 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, canvas.drawColor(Color.BLACK); canvas.drawBitmap(image, 0, 0, new Paint()); + // TODO(joedow): Replace the custom animation code with a standard Android implementation. boolean feedbackAnimationRunning = mFeedbackAnimator.isAnimationRunning(); if (feedbackAnimationRunning) { float scaleFactor; |