More paths for turning on screen immediately.

This fix forces the path through the updateLightsLocked method to turn
the screen on immediately if mWaitingForFirstLightSensor is true. Also
do not clear mWaitingForFirstLightSensor if mPreparingForScreenOn
is true. Wait until it turns false.

Fixes bug 6612418.

Change-Id: I03407e748cce4906a73de1f15df1654649b133c4
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 6695cb9..07665f4 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -2106,6 +2106,10 @@
                     brightness = mScreenBrightnessDim;
                 }
             }
+            if (mWaitingForFirstLightSensor && (newState & SCREEN_ON_BIT) != 0) {
+                steps = IMMEDIATE_ANIM_STEPS;
+            }
+
             long identity = Binder.clearCallingIdentity();
             try {
                 mBatteryStats.noteScreenBrightness(brightness);
@@ -3348,6 +3352,7 @@
     }
 
     SensorEventListener mLightListener = new SensorEventListener() {
+        @Override
         public void onSensorChanged(SensorEvent event) {
             if (mDebugLightSensor) {
                 Slog.d(TAG, "onSensorChanged: light value: " + event.values[0]);
@@ -3358,12 +3363,16 @@
                     return;
                 }
                 handleLightSensorValue((int)event.values[0], mWaitingForFirstLightSensor);
-                if (mWaitingForFirstLightSensor) {
+                if (mWaitingForFirstLightSensor && !mPreparingForScreenOn) {
+                    if (mDebugLightAnimation) {
+                        Slog.d(TAG, "onSensorChanged: Clearing mWaitingForFirstLightSensor.");
+                    }
                     mWaitingForFirstLightSensor = false;
                 }
             }
         }
 
+        @Override
         public void onAccuracyChanged(Sensor sensor, int accuracy) {
             // ignore
         }