Only doze when not occluded

This fixes a bug where an activity could have been started on top of
the lockscreen while dozing already. In that case, we would execute a
pulse and reveal the fully colored activity that is occluding the
Keyguard

Bug: 19465785
Change-Id: I9533390e13f11424a20a107005d60050a460e333
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 39dc480..8c2c543 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -2112,7 +2112,9 @@
     public void setDozing(boolean dozing, boolean animate) {
         if (dozing == mDozing) return;
         mDozing = dozing;
-        updateDozingVisibilities(animate);
+        if (mStatusBarState == StatusBarState.KEYGUARD) {
+            updateDozingVisibilities(animate);
+        }
     }
 
     private void updateDozingVisibilities(boolean animate) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index f1e51a52..516174b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -32,7 +32,6 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.IPackageManager;
-import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.database.ContentObserver;
@@ -412,6 +411,7 @@
 
     private boolean mWaitingForKeyguardExit;
     private boolean mDozing;
+    private boolean mDozingRequested;
     private boolean mScrimSrcModeEnabled;
 
     private Interpolator mLinearInterpolator = new LinearInterpolator();
@@ -3478,9 +3478,6 @@
     }
 
     private void updateDozingState() {
-        if (mState != StatusBarState.KEYGUARD && !mNotificationPanel.isDozing()) {
-            return;
-        }
         boolean animate = !mDozing && mDozeScrimController.isPulsing();
         mNotificationPanel.setDozing(mDozing, animate);
         mStackScroller.setDark(mDozing, animate, mScreenOnTouchLocation);
@@ -3597,6 +3594,7 @@
         mState = state;
         mGroupManager.setStatusBarState(state);
         mStatusBarWindowManager.setStatusBarState(state);
+        updateDozing();
     }
 
     @Override
@@ -3912,6 +3910,11 @@
         }
     }
 
+    private void updateDozing() {
+        mDozing = mDozingRequested && mState == StatusBarState.KEYGUARD;
+        updateDozingState();
+    }
+
     private final class ShadeUpdates {
         private final ArraySet<String> mVisibleNotifications = new ArraySet<String>();
         private final ArraySet<String> mNewVisibleNotifications = new ArraySet<String>();
@@ -4017,10 +4020,10 @@
         }
 
         private void handleStartDozing(@NonNull Runnable ready) {
-            if (!mDozing) {
-                mDozing = true;
+            if (!mDozingRequested) {
+                mDozingRequested = true;
                 DozeLog.traceDozing(mContext, mDozing);
-                updateDozingState();
+                updateDozing();
             }
             ready.run();
         }
@@ -4030,10 +4033,10 @@
         }
 
         private void handleStopDozing() {
-            if (mDozing) {
-                mDozing = false;
+            if (mDozingRequested) {
+                mDozingRequested = false;
                 DozeLog.traceDozing(mContext, mDozing);
-                updateDozingState();
+                updateDozing();
             }
         }