Merge "Apply the selection state that reflects the current task stack upon restarting the Navigation Bar." 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 b2c16b3..2045527 100644
--- a/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationBar.java
+++ b/packages/CarSystemUI/src/com/android/systemui/navigationbar/car/CarNavigationBar.java
@@ -245,6 +245,10 @@
if (mKeyguardStateControllerLazy.get().isShowing()) {
mCarNavigationBarController.showAllKeyguardButtons(isDeviceSetupForUser());
}
+
+ // Upon restarting the Navigation Bar, CarFacetButtonController should immediately apply the
+ // selection state that reflects the current task stack.
+ mButtonSelectionStateListener.onTaskStackChanged();
}
private boolean isDeviceSetupForUser() {
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
new file mode 100644
index 0000000..c04e47f
--- /dev/null
+++ b/packages/CarSystemUI/tests/src/com/android/systemui/navigationbar/car/CarNavigationBarTest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.navigationbar.car;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.os.Handler;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.testing.TestableResources;
+import android.view.LayoutInflater;
+import android.view.WindowManager;
+
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.car.CarDeviceProvisionedController;
+import com.android.systemui.plugins.DarkIconDispatcher;
+import com.android.systemui.statusbar.CommandQueue;
+import com.android.systemui.statusbar.NavigationBarController;
+import com.android.systemui.statusbar.SuperStatusBarViewFactory;
+import com.android.systemui.statusbar.phone.AutoHideController;
+import com.android.systemui.statusbar.phone.StatusBarIconController;
+import com.android.systemui.statusbar.phone.StatusBarWindowView;
+import com.android.systemui.statusbar.policy.KeyguardStateController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import dagger.Lazy;
+
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+@SmallTest
+public class CarNavigationBarTest extends SysuiTestCase {
+
+ private CarNavigationBar mCarNavigationBar;
+ private TestableResources mTestableResources;
+ private Handler mHandler;
+
+ @Mock
+ private CarNavigationBarController mCarNavigationBarController;
+ @Mock
+ private WindowManager mWindowManager;
+ @Mock
+ private CarDeviceProvisionedController mDeviceProvisionedController;
+ @Mock
+ private AutoHideController mAutoHideController;
+ @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;
+ @Mock
+ private ButtonSelectionStateController mButtonSelectionStateController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mTestableResources = mContext.getOrCreateTestableResources();
+ mTestableResources.addOverride(R.bool.config_enableBottomNavigationBar, true);
+ mHandler = Handler.getMain();
+ mCarNavigationBar = new CarNavigationBar(mContext, mCarNavigationBarController,
+ mWindowManager, mDeviceProvisionedController, new CommandQueue(mContext),
+ mAutoHideController, mButtonSelectionStateListener, mHandler,
+ mKeyguardStateControllerLazy, mNavigationBarControllerLazy,
+ 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.
+ mDependency.injectMockDependency(DarkIconDispatcher.class);
+ mDependency.injectMockDependency(StatusBarIconController.class);
+ }
+
+ @Test
+ public void restartNavbars_refreshesTaskChanged() {
+ ArgumentCaptor<CarDeviceProvisionedController.DeviceProvisionedListener>
+ deviceProvisionedCallbackCaptor = ArgumentCaptor.forClass(
+ CarDeviceProvisionedController.DeviceProvisionedListener.class);
+ when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(true);
+ mCarNavigationBar.start();
+ // 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(mButtonSelectionStateListener).onTaskStackChanged();
+ }
+}