Fix issue #2179931: Power key to wake up frequently ignored when in dock app

The dock app is forcing the screen to a particular brightness level.  This
causes the window manager to often call into the power manager with the
new brightness.  This causes us to go in to updateLightsLocked() to figure
out and apply the real brightness to use.  When the screen is off the
real brightness always remains 0, but even if it didn't change from the
last one we would start an animation which would when done put the system
to sleep and fight with the user trying to turn the device on.

Now, if the new target brightness is the same as the last one, we leave the
animation as-is -- either running or not as appropriate.

Change-Id: I067d55ea2b39e294c5d5291587a4d8727c0b8083
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index b2e3a8c..e1bea37 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -1531,9 +1531,10 @@
                 } finally {
                     Binder.restoreCallingIdentity(identity);
                 }
-                mScreenBrightness.setTargetLocked(brightness,
-                        steps, INITIAL_SCREEN_BRIGHTNESS, nominalCurrentValue);
-                startAnimation = true;
+                if (mScreenBrightness.setTargetLocked(brightness,
+                        steps, INITIAL_SCREEN_BRIGHTNESS, nominalCurrentValue)) {
+                    startAnimation = true;
+                }
             } else {
                 if ((newState & SCREEN_BRIGHT_BIT) == 0) {
                     // dim or turn off backlight, depending on if the screen is on
@@ -1612,11 +1613,13 @@
                     + " delta=" + delta);
         }
         
-        void setTargetLocked(int target, int stepsToTarget, int initialValue,
+        boolean setTargetLocked(int target, int stepsToTarget, int initialValue,
                 int nominalCurrentValue) {
             if (!initialized) {
                 initialized = true;
                 curValue = (float)initialValue;
+            } else if (targetValue == target) {
+                return false;
             }
             targetValue = target;
             delta = (targetValue -
@@ -1630,6 +1633,7 @@
                         + noticeMe);
             }
             animating = true;
+            return true;
         }
         
         boolean stepLocked() {