Merge "Fixed navigation bar to show itself after creating a new user through keyguard ui." into rvc-dev
diff --git a/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationBar.java b/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationBar.java
index b63162b..3ee92bd7 100644
--- a/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationBar.java
+++ b/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationBar.java
@@ -238,10 +238,12 @@
         }
 
         buildNavBarContent();
-        // If the UI was rebuilt (day/night change) while the keyguard was up we need to
-        // correctly respect that state.
+        // If the UI was rebuilt (day/night change or user change) while the keyguard was up we need
+        // to correctly respect that state.
         if (mKeyguardStateControllerLazy.get().isShowing()) {
             mCarNavigationBarController.showAllKeyguardButtons(isDeviceSetupForUser());
+        } else {
+            mCarNavigationBarController.hideAllKeyguardButtons(isDeviceSetupForUser());
         }
 
         // Upon restarting the Navigation Bar, CarFacetButtonController should immediately apply the
diff --git a/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarTest.java b/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarTest.java
index c04e47f..f2748b8 100644
--- a/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarTest.java
+++ b/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarTest.java
@@ -46,8 +46,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-import dagger.Lazy;
-
 @RunWith(AndroidTestingRunner.class)
 @TestableLooper.RunWithLooper
 @SmallTest
@@ -68,12 +66,8 @@
     @Mock
     private ButtonSelectionStateListener mButtonSelectionStateListener;
     @Mock
-    private Lazy<KeyguardStateController> mKeyguardStateControllerLazy;
-    @Mock
     private KeyguardStateController mKeyguardStateController;
     @Mock
-    private Lazy<NavigationBarController> mNavigationBarControllerLazy;
-    @Mock
     private NavigationBarController mNavigationBarController;
     @Mock
     private SuperStatusBarViewFactory mSuperStatusBarViewFactory;
@@ -89,13 +83,11 @@
         mCarNavigationBar = new CarNavigationBar(mContext, mCarNavigationBarController,
                 mWindowManager, mDeviceProvisionedController, new CommandQueue(mContext),
                 mAutoHideController, mButtonSelectionStateListener, mHandler,
-                mKeyguardStateControllerLazy, mNavigationBarControllerLazy,
+                () -> mKeyguardStateController, () -> mNavigationBarController,
                 mSuperStatusBarViewFactory, mButtonSelectionStateController);
         StatusBarWindowView statusBarWindowView = (StatusBarWindowView) LayoutInflater.from(
                 mContext).inflate(R.layout.super_status_bar, /* root= */ null);
         when(mSuperStatusBarViewFactory.getStatusBarWindowView()).thenReturn(statusBarWindowView);
-        when(mNavigationBarControllerLazy.get()).thenReturn(mNavigationBarController);
-        when(mKeyguardStateControllerLazy.get()).thenReturn(mKeyguardStateController);
         when(mKeyguardStateController.isShowing()).thenReturn(false);
         mDependency.injectMockDependency(WindowManager.class);
         // Needed to inflate top navigation bar.
@@ -119,4 +111,44 @@
 
         verify(mButtonSelectionStateListener).onTaskStackChanged();
     }
+
+    @Test
+    public void restartNavBars_newUserNotSetupWithKeyguardShowing_showsKeyguardButtons() {
+        ArgumentCaptor<CarDeviceProvisionedController.DeviceProvisionedListener>
+                deviceProvisionedCallbackCaptor = ArgumentCaptor.forClass(
+                CarDeviceProvisionedController.DeviceProvisionedListener.class);
+        when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true);
+        mCarNavigationBar.start();
+        when(mKeyguardStateController.isShowing()).thenReturn(true);
+        // switching the currentUserSetup value to force restart the navbars.
+        when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false);
+        verify(mDeviceProvisionedController).addCallback(deviceProvisionedCallbackCaptor.capture());
+
+        deviceProvisionedCallbackCaptor.getValue().onUserSwitched();
+        waitForIdleSync(mHandler);
+
+        verify(mCarNavigationBarController).showAllKeyguardButtons(false);
+    }
+
+    @Test
+    public void restartNavbars_newUserIsSetupWithKeyguardHidden_hidesKeyguardButtons() {
+        ArgumentCaptor<CarDeviceProvisionedController.DeviceProvisionedListener>
+                deviceProvisionedCallbackCaptor = ArgumentCaptor.forClass(
+                CarDeviceProvisionedController.DeviceProvisionedListener.class);
+        when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true);
+        mCarNavigationBar.start();
+        when(mKeyguardStateController.isShowing()).thenReturn(true);
+        // switching the currentUserSetup value to force restart the navbars.
+        when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false);
+        verify(mDeviceProvisionedController).addCallback(deviceProvisionedCallbackCaptor.capture());
+        deviceProvisionedCallbackCaptor.getValue().onUserSwitched();
+        waitForIdleSync(mHandler);
+        when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true);
+        when(mKeyguardStateController.isShowing()).thenReturn(false);
+
+        deviceProvisionedCallbackCaptor.getValue().onUserSetupChanged();
+        waitForIdleSync(mHandler);
+
+        verify(mCarNavigationBarController).hideAllKeyguardButtons(true);
+    }
 }