Don't animate burn-in return when it wasn't applied.

The burn-in protection return animation is performed based on the last
offset that was used, but it doesn't mean that such offset is currently
applied. Right after entering ambient mode no offset is applied, so if
we start a return animation using the last applied offset, it will cause
a shake. The animation will first shift from 0, 0 offset to the last
offset and then return again to 0, 0. This CL makes it not apply the
animation in that case.

Bug: 22519478
Change-Id: I5cb750b56e9715c6d9389136071a5e0fbafb047b
diff --git a/policy/src/com/android/internal/policy/impl/BurnInProtectionHelper.java b/policy/src/com/android/internal/policy/impl/BurnInProtectionHelper.java
index 11c739c..8cc3661 100644
--- a/policy/src/com/android/internal/policy/impl/BurnInProtectionHelper.java
+++ b/policy/src/com/android/internal/policy/impl/BurnInProtectionHelper.java
@@ -56,6 +56,9 @@
     /* 1 means increasing, -1 means decreasing */
     private int mYOffsetDirection = 1;
 
+    private int mAppliedBurnInXOffset = 0;
+    private int mAppliedBurnInYOffset = 0;
+
     private final AlarmManager mAlarmManager;
     private final PendingIntent mBurnInProtectionIntent;
     private final DisplayManagerInternal mDisplayManagerInternal;
@@ -123,6 +126,8 @@
                 mFirstUpdate = false;
             } else {
                 adjustOffsets();
+                mAppliedBurnInXOffset = mLastBurnInXOffset;
+                mAppliedBurnInYOffset = mLastBurnInYOffset;
                 mDisplayManagerInternal.setDisplayOffsets(mDisplay.getDisplayId(),
                         mLastBurnInXOffset, mLastBurnInYOffset);
             }
@@ -242,6 +247,8 @@
     @Override
     public void onAnimationEnd(Animator animator) {
         if (animator == mCenteringAnimator && !mBurnInProtectionActive) {
+            mAppliedBurnInXOffset = 0;
+            mAppliedBurnInYOffset = 0;
             // No matter how the animation finishes, we want to zero the offsets.
             mDisplayManagerInternal.setDisplayOffsets(mDisplay.getDisplayId(), 0, 0);
         }
@@ -260,7 +267,7 @@
         if (!mBurnInProtectionActive) {
             final float value = (Float) valueAnimator.getAnimatedValue();
             mDisplayManagerInternal.setDisplayOffsets(mDisplay.getDisplayId(),
-                    (int) (mLastBurnInXOffset * value), (int) (mLastBurnInYOffset * value));
+                    (int) (mAppliedBurnInXOffset * value), (int) (mAppliedBurnInYOffset * value));
         }
     }
 }