AOD: Fix wakeup transition jank

No longer do the upwards animation from AOD1, because there is a fade in instead now.

Also, because the DozeService gets finished when waking up, we were disallowing
animations again. Instead, we now ignore disallowing animations while waking up.

Also don't cancel the NotificationPanelView wakeup animation when another identical
request comes in.

Also adds tracing for various SystemUI states.

Bug: 63531607
Test: Wake up from AOD1. Ensure there is no jank or flicker
Change-Id: I383ffa320f28ac4bf5432e4f4f5c06372717f66f
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
index 1dc37cd..8847452 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeUi.java
@@ -100,7 +100,6 @@
 
     private boolean shouldAnimateWakeup(DozeMachine.State state) {
         switch (state) {
-            case DOZE_AOD:
             case DOZE_REQUEST_PULSE:
             case DOZE_PULSING:
             case DOZE_PULSE_DONE:
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ScreenLifecycle.java b/packages/SystemUI/src/com/android/systemui/keyguard/ScreenLifecycle.java
index 3f39dfe..b6fce44 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ScreenLifecycle.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ScreenLifecycle.java
@@ -16,6 +16,8 @@
 
 package com.android.systemui.keyguard;
 
+import android.os.Trace;
+
 import com.android.systemui.Dumpable;
 
 import java.io.FileDescriptor;
@@ -38,22 +40,22 @@
     }
 
     public void dispatchScreenTurningOn() {
-        mScreenState = SCREEN_TURNING_ON;
+        setScreenState(SCREEN_TURNING_ON);
         dispatch(Observer::onScreenTurningOn);
     }
 
     public void dispatchScreenTurnedOn() {
-        mScreenState = SCREEN_ON;
+        setScreenState(SCREEN_ON);
         dispatch(Observer::onScreenTurnedOn);
     }
 
     public void dispatchScreenTurningOff() {
-        mScreenState = SCREEN_TURNING_OFF;
+        setScreenState(SCREEN_TURNING_OFF);
         dispatch(Observer::onScreenTurningOff);
     }
 
     public void dispatchScreenTurnedOff() {
-        mScreenState = SCREEN_OFF;
+        setScreenState(SCREEN_OFF);
         dispatch(Observer::onScreenTurnedOff);
     }
 
@@ -63,6 +65,11 @@
         pw.println("  mScreenState=" + mScreenState);
     }
 
+    private void setScreenState(int screenState) {
+        mScreenState = screenState;
+        Trace.traceCounter(Trace.TRACE_TAG_APP, "screenState", screenState);
+    }
+
     public interface Observer {
         default void onScreenTurningOn() {}
         default void onScreenTurnedOn() {}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java b/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java
index 578e6fb..951c0ea 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/WakefulnessLifecycle.java
@@ -16,6 +16,8 @@
 
 package com.android.systemui.keyguard;
 
+import android.os.Trace;
+
 import com.android.systemui.Dumpable;
 
 import java.io.FileDescriptor;
@@ -39,22 +41,22 @@
     }
 
     public void dispatchStartedWakingUp() {
-        mWakefulness = WAKEFULNESS_WAKING;
+        setWakefulness(WAKEFULNESS_WAKING);
         dispatch(Observer::onStartedWakingUp);
     }
 
     public void dispatchFinishedWakingUp() {
-        mWakefulness = WAKEFULNESS_AWAKE;
+        setWakefulness(WAKEFULNESS_AWAKE);
         dispatch(Observer::onFinishedWakingUp);
     }
 
     public void dispatchStartedGoingToSleep() {
-        mWakefulness = WAKEFULNESS_GOING_TO_SLEEP;
+        setWakefulness(WAKEFULNESS_GOING_TO_SLEEP);
         dispatch(Observer::onStartedGoingToSleep);
     }
 
     public void dispatchFinishedGoingToSleep() {
-        mWakefulness = WAKEFULNESS_ASLEEP;
+        setWakefulness(WAKEFULNESS_ASLEEP);
         dispatch(Observer::onFinishedGoingToSleep);
     }
 
@@ -64,6 +66,11 @@
         pw.println("  mWakefulness=" + mWakefulness);
     }
 
+    private void setWakefulness(int wakefulness) {
+        mWakefulness = wakefulness;
+        Trace.traceCounter(Trace.TRACE_TAG_APP, "wakefulness", wakefulness);
+    }
+
     public interface Observer {
         default void onStartedWakingUp() {}
         default void onFinishedWakingUp() {}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index 0c62096..cca6ae0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -232,6 +232,7 @@
     private int mAmbientIndicationBottomPadding;
     private boolean mIsFullWidth;
     private float mDarkAmount;
+    private float mDarkAmountTarget;
     private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
     private boolean mNoVisibleNotifications = true;
     private ValueAnimator mDarkAnimator;
@@ -2590,8 +2591,13 @@
             return;
         }
         if (mDarkAnimator != null && mDarkAnimator.isRunning()) {
-            mDarkAnimator.cancel();
+            if (animate && mDarkAmountTarget == darkAmount) {
+                return;
+            } else {
+                mDarkAnimator.cancel();
+            }
         }
+        mDarkAmountTarget = darkAmount;
         if (animate) {
             mDarkAnimator = ObjectAnimator.ofFloat(this, SET_DARK_AMOUNT_PROPERTY, darkAmount);
             mDarkAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index 384d95c..8acd2c4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -4611,6 +4611,7 @@
     }
 
     private void updateDozingState() {
+        Trace.traceCounter(Trace.TRACE_TAG_APP, "dozing", mDozing ? 1 : 0);
         Trace.beginSection("StatusBar#updateDozingState");
         boolean animate = !mDozing && mDozeServiceHost.shouldAnimateWakeup();
         mNotificationPanel.setDozing(mDozing, animate);
@@ -5492,6 +5493,11 @@
 
         @Override
         public void setAnimateWakeup(boolean animateWakeup) {
+            if (mWakefulnessLifecycle.getWakefulness() == WAKEFULNESS_AWAKE
+                    || mWakefulnessLifecycle.getWakefulness() == WAKEFULNESS_WAKING) {
+                // Too late to change the wakeup animation.
+                return;
+            }
             mAnimateWakeup = animateWakeup;
         }