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/services/core/java/com/android/server/policy/BurnInProtectionHelper.java b/services/core/java/com/android/server/policy/BurnInProtectionHelper.java
index fef1e575..e6ec6a6 100644
--- a/services/core/java/com/android/server/policy/BurnInProtectionHelper.java
+++ b/services/core/java/com/android/server/policy/BurnInProtectionHelper.java
@@ -72,6 +72,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;
@@ -139,6 +142,8 @@
                 mFirstUpdate = false;
             } else {
                 adjustOffsets();
+                mAppliedBurnInXOffset = mLastBurnInXOffset;
+                mAppliedBurnInYOffset = mLastBurnInYOffset;
                 mDisplayManagerInternal.setDisplayOffsets(mDisplay.getDisplayId(),
                         mLastBurnInXOffset, mLastBurnInYOffset);
             }
@@ -258,6 +263,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);
         }
@@ -276,7 +283,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));
         }
     }
 }