From 971fe912c7aa1160bb515057ac267a6caae4b8bb Mon Sep 17 00:00:00 2001 From: Daichi Hirono Date: Tue, 21 Nov 2017 13:10:42 +0900 Subject: [PATCH] Fix race between AnimationListener and DragState Previously AnimationListener refers ValueAnimator via DragState#mAnimator, however the variable may be null because the animation is submitted to the animation thread before mAnimator is updated and we don't have any synchrnoization between the animation thread and other threads. This causes NPE in CrossAppDragAndDropTests. The CL changes AnimationListener so that it uses animator passed by argument. Bug: 69575965 Test: CrossAppDragAndDropTests Change-Id: I454697136aa35c0a9525ab58171347389b483cb1 --- .../core/java/com/android/server/wm/DragState.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java index e81d366bd85aa..112e62f27ea2b 100644 --- a/services/core/java/com/android/server/wm/DragState.java +++ b/services/core/java/com/android/server/wm/DragState.java @@ -645,15 +645,15 @@ class DragState { try (final SurfaceControl.Transaction transaction = new SurfaceControl.Transaction()) { transaction.setPosition( mSurfaceControl, - (float) mAnimator.getAnimatedValue(ANIMATED_PROPERTY_X), - (float) mAnimator.getAnimatedValue(ANIMATED_PROPERTY_Y)); + (float) animation.getAnimatedValue(ANIMATED_PROPERTY_X), + (float) animation.getAnimatedValue(ANIMATED_PROPERTY_Y)); transaction.setAlpha( mSurfaceControl, - (float) mAnimator.getAnimatedValue(ANIMATED_PROPERTY_ALPHA)); + (float) animation.getAnimatedValue(ANIMATED_PROPERTY_ALPHA)); transaction.setMatrix( mSurfaceControl, - (float) mAnimator.getAnimatedValue(ANIMATED_PROPERTY_SCALE), 0, - 0, (float) mAnimator.getAnimatedValue(ANIMATED_PROPERTY_SCALE)); + (float) animation.getAnimatedValue(ANIMATED_PROPERTY_SCALE), 0, + 0, (float) animation.getAnimatedValue(ANIMATED_PROPERTY_SCALE)); transaction.apply(); } }