Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b027e2aa authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Apply the selection state that reflects the current task stack upon...

Merge "Apply the selection state that reflects the current task stack upon restarting the Navigation Bar." into rvc-dev am: 97f4e229 am: 95302fd9 am: 63fc1949

Change-Id: I5faf18a9db2f1df559d4f0ff0f68c2aa3bd8b9d4
parents 207c0475 63fc1949
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -245,6 +245,10 @@ public class CarNavigationBar extends SystemUI implements CommandQueue.Callbacks
        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() {
+122 −0
Original line number Diff line number Diff line
/*
 * 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();
    }
}