Fix illegal state in doze machine

Test: trigger lock screen sensor
Change-Id: Id3c09fc98c3a916cb6d6535a3f7dfcf728ec3c3f
Fixes: 123715942
(cherry picked from commit 5131f519f61b4a9548cec02382d638aa630015a8)
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
index dc505b5..1bbc14d 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
@@ -146,7 +146,7 @@
         boolean wakeEvent = rawValues != null && rawValues.length > 0 && rawValues[0] != 0;
 
         if (isWakeDisplay) {
-            onWakeScreen(wakeEvent);
+            onWakeScreen(wakeEvent, mMachine.getState());
         } else if (isLongPress || isWakeLockScreen) {
             requestPulse(pulseReason, sensorPerformedProxCheck);
         } else {
@@ -199,9 +199,8 @@
         }
     }
 
-    private void onWakeScreen(boolean wake) {
+    private void onWakeScreen(boolean wake, DozeMachine.State state) {
         DozeLog.traceWakeDisplay(wake);
-        DozeMachine.State state = mMachine.getState();
         boolean paused = (state == DozeMachine.State.DOZE_AOD_PAUSED);
         boolean pausing = (state == DozeMachine.State.DOZE_AOD_PAUSING);
         sWakeDisplaySensorState = wake;
@@ -212,7 +211,7 @@
                     // In pocket, drop event.
                     return;
                 }
-                if (mMachine.getState() == DozeMachine.State.DOZE) {
+                if (state == DozeMachine.State.DOZE) {
                     mMachine.requestState(DozeMachine.State.DOZE_AOD);
                 }
             }, false /* alreadyPerformedProxCheck */, DozeLog.REASON_SENSOR_WAKE_UP);
@@ -240,7 +239,7 @@
                 }
                 mDozeSensors.setListening(true);
                 if (newState == DozeMachine.State.DOZE_AOD && !sWakeDisplaySensorState) {
-                    onWakeScreen(false);
+                    onWakeScreen(false, newState);
                 }
                 break;
             case DOZE_AOD_PAUSED: