Respect light nav bar flag set by IME on keyguard

Currently LightBarController takes care of both ScrimBehind alpha and
ScrimInFront text color when finally deciding whether light navigation
bar mode should be enabled or not.

When IME is shown on the keyguard, however, light navigation bar flag
explicitly set by the IME actually needs to be used because
ScrimController does not put anything over the IME layer in that
state.

This CL addresses the above corner case, by also forwarding ScrimState
from ScrimController to LightBarController so that LightBarController
can change the behavior when scrim UI is in bouncer mode.

Test: atest CtsInputMethodTestCases
Test: atest com.android.server.policy.PhoneWindowManagerTest
Test: atest SystemUITests:com.android.systemui.statusbar.phone.ScrimControllerTest
Test: Manually tested Manually tested with ThemedNavBarKeyboard sample
  1. make -j ThemedNavBarKeyboard
  2. adb install -r $OUT/system/app/ThemedNavBarKeyboard/ThemedNavBarKeyboard.apk
  3. adb shell ime enable com.example.android.themednavbarkeyboard/.ThemedNavBarKeyboard
  4. adb shell ime set com.example.android.themednavbarkeyboard/.ThemedNavBarKeyboard
  5. Open Dialer app
  6. Focus in the top edit field.
  7. Tap "EXTENDED LIGHT NAVIGARION BAR" mode
  8. Make sure that the navigation button color is optimized for light navigation bar
  9. Swipe down the notification shade.
 10. Make sure that the navigation button color is inverted.
Fixes: 72940586
Change-Id: I7a9001888f9b2d74c84c384b6302706da7a2b4b2
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
index 0416232..69508ac 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
@@ -43,6 +43,7 @@
 import android.view.View;
 
 import com.android.internal.colorextraction.ColorExtractor.GradientColors;
+import com.android.internal.util.function.TriConsumer;
 import com.android.keyguard.KeyguardUpdateMonitor;
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.statusbar.ScrimView;
@@ -66,9 +67,7 @@
     private SynchronousScrimController mScrimController;
     private ScrimView mScrimBehind;
     private ScrimView mScrimInFront;
-    private Consumer<Float> mScrimBehindAlphaCallback;
-    private Consumer<GradientColors> mScrimInFrontColorCallback;
-    private Consumer<Integer> mScrimVisibilityCallback;
+    private ScrimState mScrimState;
     private float mScrimBehindAlpha;
     private GradientColors mScrimInFrontColor;
     private int mScrimVisibility;
@@ -77,6 +76,7 @@
     private boolean mAlwaysOnEnabled;
     private AlarmManager mAlarmManager;
 
+
     @Before
     public void setup() {
         mScrimBehind = spy(new ScrimView(getContext()));
@@ -84,15 +84,16 @@
         mWakeLock = mock(WakeLock.class);
         mAlarmManager = mock(AlarmManager.class);
         mAlwaysOnEnabled = true;
-        mScrimBehindAlphaCallback = (Float alpha) -> mScrimBehindAlpha = alpha;
-        mScrimInFrontColorCallback = (GradientColors color) -> mScrimInFrontColor = color;
-        mScrimVisibilityCallback = (Integer visible) -> mScrimVisibility = visible;
         mDozeParamenters = mock(DozeParameters.class);
         when(mDozeParamenters.getAlwaysOn()).thenAnswer(invocation -> mAlwaysOnEnabled);
         when(mDozeParamenters.getDisplayNeedsBlanking()).thenReturn(true);
         mScrimController = new SynchronousScrimController(mScrimBehind, mScrimInFront,
-                mScrimBehindAlphaCallback, mScrimInFrontColorCallback, mScrimVisibilityCallback,
-                mDozeParamenters, mAlarmManager);
+                (scrimState, scrimBehindAlpha, scrimInFrontColor) -> {
+                    mScrimState = scrimState;
+                    mScrimBehindAlpha = scrimBehindAlpha;
+                    mScrimInFrontColor = scrimInFrontColor;
+                },
+                visible -> mScrimVisibility = visible, mDozeParamenters, mAlarmManager);
     }
 
     @Test
@@ -211,6 +212,21 @@
     }
 
     @Test
+    public void scrimStateCallback() {
+        mScrimController.transitionTo(ScrimState.UNLOCKED);
+        mScrimController.finishAnimationsImmediately();
+        Assert.assertEquals(mScrimState, ScrimState.UNLOCKED);
+
+        mScrimController.transitionTo(ScrimState.BOUNCER);
+        mScrimController.finishAnimationsImmediately();
+        Assert.assertEquals(mScrimState, ScrimState.BOUNCER);
+
+        mScrimController.transitionTo(ScrimState.BOUNCER_SCRIMMED);
+        mScrimController.finishAnimationsImmediately();
+        Assert.assertEquals(mScrimState, ScrimState.BOUNCER_SCRIMMED);
+    }
+
+    @Test
     public void panelExpansion() {
         mScrimController.setPanelExpansion(0f);
         mScrimController.setPanelExpansion(0.5f);
@@ -559,12 +575,11 @@
         boolean mOnPreDrawCalled;
 
         SynchronousScrimController(ScrimView scrimBehind, ScrimView scrimInFront,
-                Consumer<Float> scrimBehindAlphaListener,
-                Consumer<GradientColors> scrimInFrontColorListener,
+                TriConsumer<ScrimState, Float, GradientColors> scrimStateListener,
                 Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters,
                 AlarmManager alarmManager) {
-            super(scrimBehind, scrimInFront, scrimBehindAlphaListener, scrimInFrontColorListener,
-                    scrimVisibleListener, dozeParameters, alarmManager);
+            super(scrimBehind, scrimInFront, scrimStateListener, scrimVisibleListener,
+                    dozeParameters, alarmManager);
             mHandler = new FakeHandler(Looper.myLooper());
         }