Sleep activities with AOD

Previously in the last release we started sleeping as soon as
the device was not interactive anymore. However, this caused
issues with ambiactive activites on Android Wear.

Instead, we introduce a new private flag on a window that signals
that all activities should be put to sleep. We use this flag in
SystemUI as soon as SystemUI is "dozing", which means its ambient
display is showing. This flag gets set before we request PWM to
wake-up, so it's ensured that this will not cause any spurious
lifecycle events.

Test: go/wm-smoke
Test: android.server.cts.KeyguardTests
Change-Id: I20f6dd4bfde220f945ef94d2ac1b89dd3694de32
Fixes: 64940094
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java
index eaa6a33..ed96b41 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.java
@@ -30,6 +30,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.WindowManager;
+import android.view.WindowManager.LayoutParams;
 
 import com.android.keyguard.R;
 import com.android.systemui.Dumpable;
@@ -230,6 +231,7 @@
         applyModalFlag(state);
         applyBrightness(state);
         applyHasTopUi(state);
+        applySleepToken(state);
         if (mLp.copyFrom(mLpChanged) != 0) {
             mWindowManager.updateViewLayout(mStatusBarView, mLp);
         }
@@ -273,6 +275,14 @@
         mHasTopUiChanged = isExpanded(state);
     }
 
+    private void applySleepToken(State state) {
+        if (state.dozing) {
+            mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
+        } else {
+            mLpChanged.privateFlags &= ~LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
+        }
+    }
+
     public void setKeyguardShowing(boolean showing) {
         mCurrentState.keyguardShowing = showing;
         apply(mCurrentState);