summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Bryce Lee <brycelee@google.com> 2024-10-30 20:30:50 -0700
committer Bryce Lee <brycelee@google.com> 2024-11-04 08:19:01 -0800
commit282bd23257748634f7c75f196590ac97bf0fb0d8 (patch)
treec5990b031a4b6e1e5276db744ab55974c2b2ee9c
parentea67e1cc22922bff54dfdc2300594991a5ffc0d6 (diff)
Convert KeyguardStatusBarViewControllerTest to Kotlin
Fixes: 374017195 Test: atest KeyguardStatusBarViewControllerTest Flag: EXEMPT bugfix Change-Id: Ifcfc04dd8030aa63cec690c5ab91c8c14e0386cc
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java845
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.kt828
2 files changed, 828 insertions, 845 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java
deleted file mode 100644
index 157f8189276a..000000000000
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.java
+++ /dev/null
@@ -1,845 +0,0 @@
-/*
- * Copyright (C) 2021 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.statusbar.phone;
-
-
-import static android.app.StatusBarManager.DISABLE2_SYSTEM_ICONS;
-import static android.app.StatusBarManager.DISABLE_SYSTEM_INFO;
-
-import static com.android.systemui.Flags.FLAG_UPDATE_USER_SWITCHER_BACKGROUND;
-import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
-import static com.android.systemui.statusbar.StatusBarState.SHADE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.Mockito.clearInvocations;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.platform.test.annotations.DisableFlags;
-import android.platform.test.annotations.EnableFlags;
-import android.provider.Settings;
-import android.testing.TestableLooper;
-import android.view.LayoutInflater;
-import android.view.View;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
-
-import com.android.keyguard.CarrierTextController;
-import com.android.keyguard.KeyguardUpdateMonitor;
-import com.android.keyguard.KeyguardUpdateMonitorCallback;
-import com.android.keyguard.logging.KeyguardLogger;
-import com.android.systemui.SysuiTestCase;
-import com.android.systemui.battery.BatteryMeterViewController;
-import com.android.systemui.flags.DisableSceneContainer;
-import com.android.systemui.flags.EnableSceneContainer;
-import com.android.systemui.kosmos.KosmosJavaAdapter;
-import com.android.systemui.plugins.statusbar.StatusBarStateController;
-import com.android.systemui.res.R;
-import com.android.systemui.shade.ShadeViewStateProvider;
-import com.android.systemui.statusbar.CommandQueue;
-import com.android.systemui.statusbar.SysuiStatusBarStateController;
-import com.android.systemui.statusbar.data.repository.StatusBarContentInsetsProviderStore;
-import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
-import com.android.systemui.statusbar.phone.ui.StatusBarIconController;
-import com.android.systemui.statusbar.phone.ui.TintedIconManager;
-import com.android.systemui.statusbar.policy.BatteryController;
-import com.android.systemui.statusbar.policy.ConfigurationController;
-import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
-import com.android.systemui.statusbar.policy.KeyguardStateController;
-import com.android.systemui.statusbar.policy.UserInfoController;
-import com.android.systemui.user.ui.viewmodel.StatusBarUserChipViewModel;
-import com.android.systemui.util.concurrency.FakeExecutor;
-import com.android.systemui.util.settings.SecureSettings;
-import com.android.systemui.util.time.FakeSystemClock;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-@TestableLooper.RunWithLooper
-public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
- @Mock
- private CarrierTextController mCarrierTextController;
- @Mock
- private ConfigurationController mConfigurationController;
- @Mock
- private SystemStatusAnimationScheduler mAnimationScheduler;
- @Mock
- private BatteryController mBatteryController;
- @Mock
- private UserInfoController mUserInfoController;
- @Mock
- private StatusBarIconController mStatusBarIconController;
- @Mock
- private TintedIconManager.Factory mIconManagerFactory;
- @Mock
- private TintedIconManager mIconManager;
- @Mock
- private BatteryMeterViewController mBatteryMeterViewController;
- @Mock
- private KeyguardStateController mKeyguardStateController;
- @Mock
- private KeyguardBypassController mKeyguardBypassController;
- @Mock
- private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
- @Mock
- private BiometricUnlockController mBiometricUnlockController;
- @Mock
- private SysuiStatusBarStateController mStatusBarStateController;
- @Mock
- private StatusBarContentInsetsProvider mStatusBarContentInsetsProvider;
- @Mock
- private StatusBarContentInsetsProviderStore mStatusBarContentInsetsProviderStore;
- @Mock
- private UserManager mUserManager;
- @Mock
- private StatusBarUserChipViewModel mStatusBarUserChipViewModel;
- @Captor
- private ArgumentCaptor<ConfigurationListener> mConfigurationListenerCaptor;
- @Captor
- private ArgumentCaptor<KeyguardUpdateMonitorCallback> mKeyguardCallbackCaptor;
- @Mock private SecureSettings mSecureSettings;
- @Mock private CommandQueue mCommandQueue;
- @Mock private KeyguardLogger mLogger;
- @Mock private StatusOverlayHoverListenerFactory mStatusOverlayHoverListenerFactory;
-
- private TestShadeViewStateProvider mShadeViewStateProvider;
- private KeyguardStatusBarView mKeyguardStatusBarView;
- private KeyguardStatusBarViewController mController;
- private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock());
- private final FakeExecutor mBackgroundExecutor = new FakeExecutor(new FakeSystemClock());
- private final KosmosJavaAdapter mKosmos = new KosmosJavaAdapter(this);
-
- @Before
- public void setup() throws Exception {
- mShadeViewStateProvider = new TestShadeViewStateProvider();
-
- MockitoAnnotations.initMocks(this);
- when(mStatusBarContentInsetsProviderStore.getDefaultDisplay())
- .thenReturn(mStatusBarContentInsetsProvider);
- when(mIconManagerFactory.create(any(), any())).thenReturn(mIconManager);
-
- allowTestableLooperAsMainThread();
- TestableLooper.get(this).runWithLooper(() -> {
- mKeyguardStatusBarView =
- spy((KeyguardStatusBarView) LayoutInflater.from(mContext)
- .inflate(R.layout.keyguard_status_bar, null));
- when(mKeyguardStatusBarView.getDisplay()).thenReturn(mContext.getDisplay());
- });
-
- mController = createController();
- }
-
- private KeyguardStatusBarViewController createController() {
- return new KeyguardStatusBarViewController(
- mKeyguardStatusBarView,
- mCarrierTextController,
- mConfigurationController,
- mAnimationScheduler,
- mBatteryController,
- mUserInfoController,
- mStatusBarIconController,
- mIconManagerFactory,
- mBatteryMeterViewController,
- mShadeViewStateProvider,
- mKeyguardStateController,
- mKeyguardBypassController,
- mKeyguardUpdateMonitor,
- mKosmos.getKeyguardStatusBarViewModel(),
- mBiometricUnlockController,
- mStatusBarStateController,
- mStatusBarContentInsetsProviderStore,
- mUserManager,
- mStatusBarUserChipViewModel,
- mSecureSettings,
- mCommandQueue,
- mFakeExecutor,
- mBackgroundExecutor,
- mLogger,
- mStatusOverlayHoverListenerFactory,
- mKosmos.getCommunalSceneInteractor()
- );
- }
-
- @Test
- @EnableFlags(FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
- public void onViewAttached_updateUserSwitcherFlagEnabled_callbacksRegistered() {
- mController.onViewAttached();
-
- runAllScheduled();
- verify(mConfigurationController).addCallback(any());
- verify(mAnimationScheduler).addCallback(any());
- verify(mUserInfoController).addCallback(any());
- verify(mCommandQueue).addCallback(any());
- verify(mStatusBarIconController).addIconGroup(any());
- verify(mUserManager).isUserSwitcherEnabled(anyBoolean());
- }
-
- @Test
- @DisableFlags(FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
- public void onViewAttached_updateUserSwitcherFlagDisabled_callbacksRegistered() {
- mController.onViewAttached();
-
- verify(mConfigurationController).addCallback(any());
- verify(mAnimationScheduler).addCallback(any());
- verify(mUserInfoController).addCallback(any());
- verify(mCommandQueue).addCallback(any());
- verify(mStatusBarIconController).addIconGroup(any());
- verify(mUserManager).isUserSwitcherEnabled(anyBoolean());
- }
-
- @Test
- @EnableFlags(FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
- public void
- onConfigurationChanged_updateUserSwitcherFlagEnabled_updatesUserSwitcherVisibility() {
- mController.onViewAttached();
- runAllScheduled();
- verify(mConfigurationController).addCallback(mConfigurationListenerCaptor.capture());
- clearInvocations(mUserManager);
- clearInvocations(mKeyguardStatusBarView);
-
- mConfigurationListenerCaptor.getValue().onConfigChanged(null);
-
- runAllScheduled();
- verify(mUserManager).isUserSwitcherEnabled(anyBoolean());
- verify(mKeyguardStatusBarView).setUserSwitcherEnabled(anyBoolean());
- }
-
- @Test
- @DisableFlags(FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
- public void
- onConfigurationChanged_updateUserSwitcherFlagDisabled_updatesUserSwitcherVisibility() {
- mController.onViewAttached();
- verify(mConfigurationController).addCallback(mConfigurationListenerCaptor.capture());
- clearInvocations(mUserManager);
- clearInvocations(mKeyguardStatusBarView);
-
- mConfigurationListenerCaptor.getValue().onConfigChanged(null);
- verify(mUserManager).isUserSwitcherEnabled(anyBoolean());
- verify(mKeyguardStatusBarView).setUserSwitcherEnabled(anyBoolean());
- }
-
- @Test
- @EnableFlags(FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
- public void
- onKeyguardVisibilityChanged_userSwitcherFlagEnabled_updatesUserSwitcherVisibility() {
- mController.onViewAttached();
- runAllScheduled();
- verify(mKeyguardUpdateMonitor).registerCallback(mKeyguardCallbackCaptor.capture());
- clearInvocations(mUserManager);
- clearInvocations(mKeyguardStatusBarView);
-
- mKeyguardCallbackCaptor.getValue().onKeyguardVisibilityChanged(true);
-
- runAllScheduled();
- verify(mUserManager).isUserSwitcherEnabled(anyBoolean());
- verify(mKeyguardStatusBarView).setUserSwitcherEnabled(anyBoolean());
- }
-
- @Test
- @DisableFlags(FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
- public void
- onKeyguardVisibilityChanged_userSwitcherFlagDisabled_updatesUserSwitcherVisibility() {
- mController.onViewAttached();
- verify(mKeyguardUpdateMonitor).registerCallback(mKeyguardCallbackCaptor.capture());
- clearInvocations(mUserManager);
- clearInvocations(mKeyguardStatusBarView);
-
- mKeyguardCallbackCaptor.getValue().onKeyguardVisibilityChanged(true);
- verify(mUserManager).isUserSwitcherEnabled(anyBoolean());
- verify(mKeyguardStatusBarView).setUserSwitcherEnabled(anyBoolean());
- }
-
- @Test
- public void onViewDetached_callbacksUnregistered() {
- // Set everything up first.
- mController.onViewAttached();
-
- mController.onViewDetached();
-
- verify(mConfigurationController).removeCallback(any());
- verify(mAnimationScheduler).removeCallback(any());
- verify(mUserInfoController).removeCallback(any());
- verify(mCommandQueue).removeCallback(any());
- verify(mStatusBarIconController).removeIconGroup(any());
- }
-
- @Test
- @DisableSceneContainer
- public void onViewReAttached_flagOff_iconManagerNotReRegistered() {
- mController.onViewAttached();
- mController.onViewDetached();
- reset(mStatusBarIconController);
-
- mController.onViewAttached();
-
- verify(mStatusBarIconController, never()).addIconGroup(any());
- }
-
- @Test
- @EnableSceneContainer
- public void onViewReAttached_flagOn_iconManagerReRegistered() {
- mController.onViewAttached();
- mController.onViewDetached();
- reset(mStatusBarIconController);
-
- mController.onViewAttached();
-
- verify(mStatusBarIconController).addIconGroup(any());
- }
-
- @Test
- @DisableSceneContainer
- public void setBatteryListening_true_callbackAdded() {
- mController.setBatteryListening(true);
-
- verify(mBatteryController).addCallback(any());
- }
-
- @Test
- @DisableSceneContainer
- public void setBatteryListening_false_callbackRemoved() {
- // First set to true so that we know setting to false is a change in state.
- mController.setBatteryListening(true);
-
- mController.setBatteryListening(false);
-
- verify(mBatteryController).removeCallback(any());
- }
-
- @Test
- @DisableSceneContainer
- public void setBatteryListening_trueThenTrue_callbackAddedOnce() {
- mController.setBatteryListening(true);
- mController.setBatteryListening(true);
-
- verify(mBatteryController).addCallback(any());
- }
-
- @Test
- @EnableSceneContainer
- public void setBatteryListening_true_flagOn_callbackNotAdded() {
- mController.setBatteryListening(true);
-
- verify(mBatteryController, never()).addCallback(any());
- }
-
- @Test
- public void updateTopClipping_viewClippingUpdated() {
- int viewTop = 20;
- mKeyguardStatusBarView.setTop(viewTop);
- int notificationPanelTop = 30;
-
- mController.updateTopClipping(notificationPanelTop);
-
- assertThat(mKeyguardStatusBarView.getClipBounds().top).isEqualTo(
- notificationPanelTop - viewTop);
- }
-
- @Test
- public void setNotTopClipping_viewClippingUpdatedToZero() {
- // Start out with some amount of top clipping.
- mController.updateTopClipping(50);
- assertThat(mKeyguardStatusBarView.getClipBounds().top).isGreaterThan(0);
-
- mController.setNoTopClipping();
-
- assertThat(mKeyguardStatusBarView.getClipBounds().top).isEqualTo(0);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_alphaAndVisibilityGiven_viewUpdated() {
- // Verify the initial values so we know the method triggers changes.
- assertThat(mKeyguardStatusBarView.getAlpha()).isEqualTo(1f);
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
-
- float newAlpha = 0.5f;
- int newVisibility = View.INVISIBLE;
- mController.updateViewState(newAlpha, newVisibility);
-
- assertThat(mKeyguardStatusBarView.getAlpha()).isEqualTo(newAlpha);
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(newVisibility);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_paramVisibleButIsDisabled_viewIsInvisible() {
- mController.onViewAttached();
- setDisableSystemIcons(true);
-
- mController.updateViewState(1f, View.VISIBLE);
-
- // Since we're disabled, we stay invisible
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_notKeyguardState_nothingUpdated() {
- mController.onViewAttached();
- updateStateToNotKeyguard();
-
- float oldAlpha = mKeyguardStatusBarView.getAlpha();
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getAlpha()).isEqualTo(oldAlpha);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_bypassEnabledAndShouldListenForFace_viewHidden() {
- mController.onViewAttached();
- updateStateToKeyguard();
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
-
- when(mKeyguardUpdateMonitor.shouldListenForFace()).thenReturn(true);
- when(mKeyguardBypassController.getBypassEnabled()).thenReturn(true);
- onFinishedGoingToSleep();
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_bypassNotEnabled_viewShown() {
- mController.onViewAttached();
- updateStateToKeyguard();
-
- when(mKeyguardUpdateMonitor.shouldListenForFace()).thenReturn(true);
- when(mKeyguardBypassController.getBypassEnabled()).thenReturn(false);
- onFinishedGoingToSleep();
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_shouldNotListenForFace_viewShown() {
- mController.onViewAttached();
- updateStateToKeyguard();
-
- when(mKeyguardUpdateMonitor.shouldListenForFace()).thenReturn(false);
- when(mKeyguardBypassController.getBypassEnabled()).thenReturn(true);
- onFinishedGoingToSleep();
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_panelExpandedHeightZero_viewHidden() {
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mShadeViewStateProvider.setPanelViewExpandedHeight(0);
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_dragProgressOne_viewHidden() {
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mShadeViewStateProvider.setLockscreenShadeDragProgress(1f);
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_disableSystemInfoFalse_viewShown() {
- mController.onViewAttached();
- updateStateToKeyguard();
- setDisableSystemInfo(false);
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_disableSystemInfoTrue_viewHidden() {
- mController.onViewAttached();
- updateStateToKeyguard();
- setDisableSystemInfo(true);
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_disableSystemIconsFalse_viewShown() {
- mController.onViewAttached();
- updateStateToKeyguard();
- setDisableSystemIcons(false);
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_disableSystemIconsTrue_viewHidden() {
- mController.onViewAttached();
- updateStateToKeyguard();
- setDisableSystemIcons(true);
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_dozingTrue_flagOff_viewHidden() {
- mController.init();
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mController.setDozing(true);
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateViewState_dozingFalse_flagOff_viewShown() {
- mController.init();
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mController.setDozing(false);
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- @EnableSceneContainer
- public void updateViewState_flagOn_doesNothing() {
- mController.init();
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mKeyguardStatusBarView.setVisibility(View.GONE);
- mKeyguardStatusBarView.setAlpha(0.456f);
-
- mController.updateViewState();
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.GONE);
- assertThat(mKeyguardStatusBarView.getAlpha()).isEqualTo(0.456f);
- }
-
- @Test
- @EnableSceneContainer
- public void updateViewStateWithAlphaAndVis_flagOn_doesNothing() {
- mController.init();
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mKeyguardStatusBarView.setVisibility(View.GONE);
- mKeyguardStatusBarView.setAlpha(0.456f);
-
- mController.updateViewState(0.789f, View.VISIBLE);
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.GONE);
- assertThat(mKeyguardStatusBarView.getAlpha()).isEqualTo(0.456f);
- }
-
- @Test
- @EnableSceneContainer
- public void setAlpha_flagOn_doesNothing() {
- mController.init();
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mKeyguardStatusBarView.setAlpha(0.456f);
-
- mController.setAlpha(0.123f);
-
- assertThat(mKeyguardStatusBarView.getAlpha()).isEqualTo(0.456f);
- }
-
- @Test
- @EnableSceneContainer
- public void setDozing_flagOn_doesNothing() {
- mController.init();
- mController.onViewAttached();
- updateStateToKeyguard();
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
-
- mController.setDozing(true);
- mController.updateViewState();
-
- // setDozing(true) should typically cause the view to hide. But since the flag is on, we
- // should ignore these set dozing calls and stay the same visibility.
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void setAlpha_explicitAlpha_setsExplicitAlpha() {
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mController.setAlpha(0.5f);
-
- assertThat(mKeyguardStatusBarView.getAlpha()).isEqualTo(0.5f);
- }
-
- @Test
- @DisableSceneContainer
- public void setAlpha_explicitAlpha_thenMinusOneAlpha_setsAlphaBasedOnDefaultCriteria() {
- mController.onViewAttached();
- updateStateToKeyguard();
-
- mController.setAlpha(0.5f);
- mController.setAlpha(-1f);
-
- assertThat(mKeyguardStatusBarView.getAlpha()).isGreaterThan(0);
- assertThat(mKeyguardStatusBarView.getAlpha()).isNotEqualTo(0.5f);
- }
-
- // TODO(b/195442899): Add more tests for #updateViewState once CLs are finalized.
-
- @Test
- @DisableSceneContainer
- public void updateForHeadsUp_headsUpShouldBeVisible_viewHidden() {
- mController.onViewAttached();
- updateStateToKeyguard();
- mKeyguardStatusBarView.setVisibility(View.VISIBLE);
-
- mShadeViewStateProvider.setShouldHeadsUpBeVisible(true);
- mController.updateForHeadsUp(/* animate= */ false);
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- @Test
- @DisableSceneContainer
- public void updateForHeadsUp_headsUpShouldNotBeVisible_viewShown() {
- mController.onViewAttached();
- updateStateToKeyguard();
-
- // Start with the opposite state.
- mShadeViewStateProvider.setShouldHeadsUpBeVisible(true);
- mController.updateForHeadsUp(/* animate= */ false);
-
- mShadeViewStateProvider.setShouldHeadsUpBeVisible(false);
- mController.updateForHeadsUp(/* animate= */ false);
-
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void testNewUserSwitcherDisablesAvatar_newUiOn() {
- // GIVEN the status bar user switcher chip is enabled
- when(mStatusBarUserChipViewModel.getChipEnabled()).thenReturn(true);
-
- // WHEN the controller is created
- mController = createController();
-
- // THEN keyguard status bar view avatar is disabled
- assertThat(mKeyguardStatusBarView.isKeyguardUserAvatarEnabled()).isFalse();
- }
-
- @Test
- public void testNewUserSwitcherDisablesAvatar_newUiOff() {
- // GIVEN the status bar user switcher chip is disabled
- when(mStatusBarUserChipViewModel.getChipEnabled()).thenReturn(false);
-
- // WHEN the controller is created
- mController = createController();
-
- // THEN keyguard status bar view avatar is enabled
- assertThat(mKeyguardStatusBarView.isKeyguardUserAvatarEnabled()).isTrue();
- }
-
- @Test
- public void testBlockedIcons_obeysSettingForVibrateIcon_settingOff() {
- String str = mContext.getString(com.android.internal.R.string.status_bar_volume);
-
- // GIVEN the setting is off
- when(mSecureSettings.getInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0))
- .thenReturn(0);
-
- // WHEN CollapsedStatusBarFragment builds the blocklist
- mController.updateBlockedIcons();
-
- // THEN status_bar_volume SHOULD be present in the list
- boolean contains = mController.getBlockedIcons().contains(str);
- assertTrue(contains);
- }
-
- @Test
- public void testBlockedIcons_obeysSettingForVibrateIcon_settingOn() {
- String str = mContext.getString(com.android.internal.R.string.status_bar_volume);
-
- // GIVEN the setting is ON
- when(mSecureSettings.getIntForUser(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0,
- UserHandle.USER_CURRENT))
- .thenReturn(1);
-
- // WHEN CollapsedStatusBarFragment builds the blocklist
- mController.updateBlockedIcons();
-
- // THEN status_bar_volume SHOULD NOT be present in the list
- boolean contains = mController.getBlockedIcons().contains(str);
- assertFalse(contains);
- }
-
- private void updateStateToNotKeyguard() {
- updateStatusBarState(SHADE);
- }
-
- private void updateStateToKeyguard() {
- updateStatusBarState(KEYGUARD);
- }
-
- private void updateStatusBarState(int state) {
- ArgumentCaptor<StatusBarStateController.StateListener> statusBarStateListenerCaptor =
- ArgumentCaptor.forClass(StatusBarStateController.StateListener.class);
- verify(mStatusBarStateController).addCallback(statusBarStateListenerCaptor.capture());
- StatusBarStateController.StateListener callback = statusBarStateListenerCaptor.getValue();
-
- callback.onStateChanged(state);
- }
-
- @Test
- @DisableSceneContainer
- public void animateKeyguardStatusBarIn_isDisabled_viewStillHidden() {
- mController.onViewAttached();
- updateStateToKeyguard();
- setDisableSystemInfo(true);
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
-
- mController.animateKeyguardStatusBarIn();
-
- // Since we're disabled, we don't actually animate in and stay invisible
- assertThat(mKeyguardStatusBarView.getVisibility()).isEqualTo(View.INVISIBLE);
- }
-
- /**
- * Calls {@link com.android.keyguard.KeyguardUpdateMonitorCallback#onFinishedGoingToSleep(int)}
- * to ensure values are updated properly.
- */
- private void onFinishedGoingToSleep() {
- ArgumentCaptor<KeyguardUpdateMonitorCallback> keyguardUpdateCallbackCaptor =
- ArgumentCaptor.forClass(KeyguardUpdateMonitorCallback.class);
- verify(mKeyguardUpdateMonitor).registerCallback(keyguardUpdateCallbackCaptor.capture());
- KeyguardUpdateMonitorCallback callback = keyguardUpdateCallbackCaptor.getValue();
-
- callback.onFinishedGoingToSleep(0);
- }
-
- private void setDisableSystemInfo(boolean disabled) {
- CommandQueue.Callbacks callback = getCommandQueueCallback();
- int disabled1 = disabled ? DISABLE_SYSTEM_INFO : 0;
- callback.disable(mContext.getDisplayId(), disabled1, 0, false);
- }
-
- private void setDisableSystemIcons(boolean disabled) {
- CommandQueue.Callbacks callback = getCommandQueueCallback();
- int disabled2 = disabled ? DISABLE2_SYSTEM_ICONS : 0;
- callback.disable(mContext.getDisplayId(), 0, disabled2, false);
- }
-
- private CommandQueue.Callbacks getCommandQueueCallback() {
- ArgumentCaptor<CommandQueue.Callbacks> captor =
- ArgumentCaptor.forClass(CommandQueue.Callbacks.class);
- verify(mCommandQueue).addCallback(captor.capture());
- return captor.getValue();
- }
-
- private void runAllScheduled() {
- mBackgroundExecutor.runAllReady();
- mFakeExecutor.runAllReady();
- }
-
- private static class TestShadeViewStateProvider
- implements ShadeViewStateProvider {
-
- TestShadeViewStateProvider() {}
-
- private float mPanelViewExpandedHeight = 100f;
- private boolean mShouldHeadsUpBeVisible = false;
- private float mLockscreenShadeDragProgress = 0f;
-
- @Override
- public float getPanelViewExpandedHeight() {
- return mPanelViewExpandedHeight;
- }
-
- @Override
- public boolean shouldHeadsUpBeVisible() {
- return mShouldHeadsUpBeVisible;
- }
-
- @Override
- public float getLockscreenShadeDragProgress() {
- return mLockscreenShadeDragProgress;
- }
-
- public void setPanelViewExpandedHeight(float panelViewExpandedHeight) {
- this.mPanelViewExpandedHeight = panelViewExpandedHeight;
- }
-
- public void setShouldHeadsUpBeVisible(boolean shouldHeadsUpBeVisible) {
- this.mShouldHeadsUpBeVisible = shouldHeadsUpBeVisible;
- }
-
- public void setLockscreenShadeDragProgress(float lockscreenShadeDragProgress) {
- this.mLockscreenShadeDragProgress = lockscreenShadeDragProgress;
- }
- }
-}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.kt
new file mode 100644
index 000000000000..627c0d0df657
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/phone/KeyguardStatusBarViewControllerTest.kt
@@ -0,0 +1,828 @@
+/*
+ * Copyright (C) 2021 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.statusbar.phone
+
+import android.app.StatusBarManager
+import android.os.UserHandle
+import android.os.UserManager
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
+import android.provider.Settings
+import android.testing.TestableLooper
+import android.testing.TestableLooper.RunWithLooper
+import android.view.LayoutInflater
+import android.view.View
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.keyguard.CarrierTextController
+import com.android.keyguard.KeyguardUpdateMonitor
+import com.android.keyguard.KeyguardUpdateMonitorCallback
+import com.android.keyguard.logging.KeyguardLogger
+import com.android.systemui.Flags
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.battery.BatteryMeterViewController
+import com.android.systemui.communal.domain.interactor.communalSceneInteractor
+import com.android.systemui.flags.DisableSceneContainer
+import com.android.systemui.flags.EnableSceneContainer
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.plugins.statusbar.StatusBarStateController
+import com.android.systemui.res.R
+import com.android.systemui.shade.ShadeViewStateProvider
+import com.android.systemui.statusbar.CommandQueue
+import com.android.systemui.statusbar.StatusBarState
+import com.android.systemui.statusbar.SysuiStatusBarStateController
+import com.android.systemui.statusbar.data.repository.StatusBarContentInsetsProviderStore
+import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler
+import com.android.systemui.statusbar.phone.ui.StatusBarIconController
+import com.android.systemui.statusbar.phone.ui.TintedIconManager
+import com.android.systemui.statusbar.policy.BatteryController
+import com.android.systemui.statusbar.policy.ConfigurationController
+import com.android.systemui.statusbar.policy.KeyguardStateController
+import com.android.systemui.statusbar.policy.UserInfoController
+import com.android.systemui.statusbar.ui.viewmodel.keyguardStatusBarViewModel
+import com.android.systemui.testKosmos
+import com.android.systemui.user.ui.viewmodel.StatusBarUserChipViewModel
+import com.android.systemui.util.concurrency.FakeExecutor
+import com.android.systemui.util.settings.SecureSettings
+import com.android.systemui.util.time.FakeSystemClock
+import com.google.common.truth.Truth
+import kotlinx.coroutines.test.TestScope
+import org.junit.Assert
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
+import org.mockito.ArgumentMatchers
+import org.mockito.Captor
+import org.mockito.Mock
+import org.mockito.Mockito
+import org.mockito.Mockito.`when`
+import org.mockito.MockitoAnnotations
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+@RunWithLooper
+class KeyguardStatusBarViewControllerTest : SysuiTestCase() {
+ private lateinit var kosmos: Kosmos
+ private lateinit var testScope: TestScope
+
+ @Mock private lateinit var carrierTextController: CarrierTextController
+
+ @Mock private lateinit var configurationController: ConfigurationController
+
+ @Mock private lateinit var animationScheduler: SystemStatusAnimationScheduler
+
+ @Mock private lateinit var batteryController: BatteryController
+
+ @Mock private lateinit var userInfoController: UserInfoController
+
+ @Mock private lateinit var statusBarIconController: StatusBarIconController
+
+ @Mock private lateinit var iconManagerFactory: TintedIconManager.Factory
+
+ @Mock private lateinit var iconManager: TintedIconManager
+
+ @Mock private lateinit var batteryMeterViewController: BatteryMeterViewController
+
+ @Mock private lateinit var keyguardStateController: KeyguardStateController
+
+ @Mock private lateinit var keyguardBypassController: KeyguardBypassController
+
+ @Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
+
+ @Mock private lateinit var biometricUnlockController: BiometricUnlockController
+
+ @Mock private lateinit var statusBarStateController: SysuiStatusBarStateController
+
+ @Mock private lateinit var statusBarContentInsetsProvider: StatusBarContentInsetsProvider
+
+ @Mock
+ private lateinit var statusBarContentInsetsProviderStore: StatusBarContentInsetsProviderStore
+
+ @Mock private lateinit var userManager: UserManager
+
+ @Mock private lateinit var statusBarUserChipViewModel: StatusBarUserChipViewModel
+
+ @Captor
+ private lateinit var configurationListenerCaptor:
+ ArgumentCaptor<ConfigurationController.ConfigurationListener>
+
+ @Captor
+ private lateinit var keyguardCallbackCaptor: ArgumentCaptor<KeyguardUpdateMonitorCallback>
+
+ @Mock private lateinit var secureSettings: SecureSettings
+
+ @Mock private lateinit var commandQueue: CommandQueue
+
+ @Mock private lateinit var logger: KeyguardLogger
+
+ @Mock private lateinit var statusOverlayHoverListenerFactory: StatusOverlayHoverListenerFactory
+
+ private lateinit var shadeViewStateProvider: TestShadeViewStateProvider
+
+ private lateinit var keyguardStatusBarView: KeyguardStatusBarView
+ private lateinit var controller: KeyguardStatusBarViewController
+ private val fakeExecutor = FakeExecutor(FakeSystemClock())
+ private val backgroundExecutor = FakeExecutor(FakeSystemClock())
+
+ @Before
+ @Throws(Exception::class)
+ fun setup() {
+ kosmos = testKosmos()
+ testScope = kosmos.testScope
+ shadeViewStateProvider = TestShadeViewStateProvider()
+
+ MockitoAnnotations.initMocks(this)
+
+ Mockito.`when`(iconManagerFactory.create(ArgumentMatchers.any(), ArgumentMatchers.any()))
+ .thenReturn(iconManager)
+ Mockito.`when`(statusBarContentInsetsProviderStore.defaultDisplay)
+ .thenReturn(statusBarContentInsetsProvider)
+ allowTestableLooperAsMainThread()
+ TestableLooper.get(this).runWithLooper {
+ keyguardStatusBarView =
+ Mockito.spy(
+ LayoutInflater.from(mContext).inflate(R.layout.keyguard_status_bar, null)
+ as KeyguardStatusBarView
+ )
+ Mockito.`when`(keyguardStatusBarView.getDisplay()).thenReturn(mContext.display)
+ }
+
+ controller = createController()
+ }
+
+ private fun createController(): KeyguardStatusBarViewController {
+ return KeyguardStatusBarViewController(
+ keyguardStatusBarView,
+ carrierTextController,
+ configurationController,
+ animationScheduler,
+ batteryController,
+ userInfoController,
+ statusBarIconController,
+ iconManagerFactory,
+ batteryMeterViewController,
+ shadeViewStateProvider,
+ keyguardStateController,
+ keyguardBypassController,
+ keyguardUpdateMonitor,
+ kosmos.keyguardStatusBarViewModel,
+ biometricUnlockController,
+ statusBarStateController,
+ statusBarContentInsetsProviderStore,
+ userManager,
+ statusBarUserChipViewModel,
+ secureSettings,
+ commandQueue,
+ fakeExecutor,
+ backgroundExecutor,
+ logger,
+ statusOverlayHoverListenerFactory,
+ kosmos.communalSceneInteractor,
+ )
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
+ fun onViewAttached_updateUserSwitcherFlagEnabled_callbacksRegistered() {
+ controller.onViewAttached()
+
+ runAllScheduled()
+ Mockito.verify(configurationController).addCallback(ArgumentMatchers.any())
+ Mockito.verify(animationScheduler).addCallback(ArgumentMatchers.any())
+ Mockito.verify(userInfoController).addCallback(ArgumentMatchers.any())
+ Mockito.verify(commandQueue).addCallback(ArgumentMatchers.any())
+ Mockito.verify(statusBarIconController).addIconGroup(ArgumentMatchers.any())
+ Mockito.verify(userManager).isUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
+ fun onViewAttached_updateUserSwitcherFlagDisabled_callbacksRegistered() {
+ controller.onViewAttached()
+
+ Mockito.verify(configurationController).addCallback(ArgumentMatchers.any())
+ Mockito.verify(animationScheduler).addCallback(ArgumentMatchers.any())
+ Mockito.verify(userInfoController).addCallback(ArgumentMatchers.any())
+ Mockito.verify(commandQueue).addCallback(ArgumentMatchers.any())
+ Mockito.verify(statusBarIconController).addIconGroup(ArgumentMatchers.any())
+ Mockito.verify(userManager).isUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
+ fun onConfigurationChanged_updateUserSwitcherFlagEnabled_updatesUserSwitcherVisibility() {
+ controller.onViewAttached()
+ runAllScheduled()
+ Mockito.verify(configurationController).addCallback(configurationListenerCaptor.capture())
+ Mockito.clearInvocations(userManager)
+ Mockito.clearInvocations(keyguardStatusBarView)
+
+ configurationListenerCaptor.value.onConfigChanged(null)
+
+ runAllScheduled()
+ Mockito.verify(userManager).isUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ Mockito.verify(keyguardStatusBarView).setUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
+ fun onConfigurationChanged_updateUserSwitcherFlagDisabled_updatesUserSwitcherVisibility() {
+ controller.onViewAttached()
+ Mockito.verify(configurationController).addCallback(configurationListenerCaptor.capture())
+ Mockito.clearInvocations(userManager)
+ Mockito.clearInvocations(keyguardStatusBarView)
+
+ configurationListenerCaptor.value.onConfigChanged(null)
+ Mockito.verify(userManager).isUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ Mockito.verify(keyguardStatusBarView).setUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
+ fun onKeyguardVisibilityChanged_userSwitcherFlagEnabled_updatesUserSwitcherVisibility() {
+ controller.onViewAttached()
+ runAllScheduled()
+ Mockito.verify(keyguardUpdateMonitor).registerCallback(keyguardCallbackCaptor.capture())
+ Mockito.clearInvocations(userManager)
+ Mockito.clearInvocations(keyguardStatusBarView)
+
+ keyguardCallbackCaptor.value.onKeyguardVisibilityChanged(true)
+
+ runAllScheduled()
+ Mockito.verify(userManager).isUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ Mockito.verify(keyguardStatusBarView).setUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_UPDATE_USER_SWITCHER_BACKGROUND)
+ fun onKeyguardVisibilityChanged_userSwitcherFlagDisabled_updatesUserSwitcherVisibility() {
+ controller.onViewAttached()
+ Mockito.verify(keyguardUpdateMonitor).registerCallback(keyguardCallbackCaptor.capture())
+ Mockito.clearInvocations(userManager)
+ Mockito.clearInvocations(keyguardStatusBarView)
+
+ keyguardCallbackCaptor.value.onKeyguardVisibilityChanged(true)
+ Mockito.verify(userManager).isUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ Mockito.verify(keyguardStatusBarView).setUserSwitcherEnabled(ArgumentMatchers.anyBoolean())
+ }
+
+ @Test
+ fun onViewDetached_callbacksUnregistered() {
+ // Set everything up first.
+ controller.onViewAttached()
+
+ controller.onViewDetached()
+
+ Mockito.verify(configurationController).removeCallback(ArgumentMatchers.any())
+ Mockito.verify(animationScheduler).removeCallback(ArgumentMatchers.any())
+ Mockito.verify(userInfoController).removeCallback(ArgumentMatchers.any())
+ Mockito.verify(commandQueue).removeCallback(ArgumentMatchers.any())
+ Mockito.verify(statusBarIconController).removeIconGroup(ArgumentMatchers.any())
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun onViewReAttached_flagOff_iconManagerNotReRegistered() {
+ controller.onViewAttached()
+ controller.onViewDetached()
+ Mockito.reset(statusBarIconController)
+
+ controller.onViewAttached()
+
+ Mockito.verify(statusBarIconController, Mockito.never())
+ .addIconGroup(ArgumentMatchers.any())
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun onViewReAttached_flagOn_iconManagerReRegistered() {
+ controller.onViewAttached()
+ controller.onViewDetached()
+ Mockito.reset(statusBarIconController)
+
+ controller.onViewAttached()
+
+ Mockito.verify(statusBarIconController).addIconGroup(ArgumentMatchers.any())
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun setBatteryListening_true_callbackAdded() {
+ controller.setBatteryListening(true)
+
+ Mockito.verify(batteryController).addCallback(ArgumentMatchers.any())
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun setBatteryListening_false_callbackRemoved() {
+ // First set to true so that we know setting to false is a change in state.
+ controller.setBatteryListening(true)
+
+ controller.setBatteryListening(false)
+
+ Mockito.verify(batteryController).removeCallback(ArgumentMatchers.any())
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun setBatteryListening_trueThenTrue_callbackAddedOnce() {
+ controller.setBatteryListening(true)
+ controller.setBatteryListening(true)
+
+ Mockito.verify(batteryController).addCallback(ArgumentMatchers.any())
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun setBatteryListening_true_flagOn_callbackNotAdded() {
+ controller.setBatteryListening(true)
+
+ Mockito.verify(batteryController, Mockito.never()).addCallback(ArgumentMatchers.any())
+ }
+
+ @Test
+ fun updateTopClipping_viewClippingUpdated() {
+ val viewTop = 20
+ keyguardStatusBarView.top = viewTop
+ val notificationPanelTop = 30
+
+ controller.updateTopClipping(notificationPanelTop)
+
+ Truth.assertThat(keyguardStatusBarView.clipBounds.top)
+ .isEqualTo(notificationPanelTop - viewTop)
+ }
+
+ @Test
+ fun setNotTopClipping_viewClippingUpdatedToZero() {
+ // Start out with some amount of top clipping.
+ controller.updateTopClipping(50)
+ Truth.assertThat(keyguardStatusBarView.clipBounds.top).isGreaterThan(0)
+
+ controller.setNoTopClipping()
+
+ Truth.assertThat(keyguardStatusBarView.clipBounds.top).isEqualTo(0)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_alphaAndVisibilityGiven_viewUpdated() {
+ // Verify the initial values so we know the method triggers changes.
+ Truth.assertThat(keyguardStatusBarView.alpha).isEqualTo(1f)
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+
+ val newAlpha = 0.5f
+ val newVisibility = View.INVISIBLE
+ controller.updateViewState(newAlpha, newVisibility)
+
+ Truth.assertThat(keyguardStatusBarView.alpha).isEqualTo(newAlpha)
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(newVisibility)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_paramVisibleButIsDisabled_viewIsInvisible() {
+ controller.onViewAttached()
+ setDisableSystemIcons(true)
+
+ controller.updateViewState(1f, View.VISIBLE)
+
+ // Since we're disabled, we stay invisible
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_notKeyguardState_nothingUpdated() {
+ controller.onViewAttached()
+ updateStateToNotKeyguard()
+
+ val oldAlpha = keyguardStatusBarView.alpha
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.alpha).isEqualTo(oldAlpha)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_bypassEnabledAndShouldListenForFace_viewHidden() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+
+ Mockito.`when`(keyguardUpdateMonitor.shouldListenForFace()).thenReturn(true)
+ Mockito.`when`(keyguardBypassController.bypassEnabled).thenReturn(true)
+ onFinishedGoingToSleep()
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_bypassNotEnabled_viewShown() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ Mockito.`when`(keyguardUpdateMonitor.shouldListenForFace()).thenReturn(true)
+ Mockito.`when`(keyguardBypassController.bypassEnabled).thenReturn(false)
+ onFinishedGoingToSleep()
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_shouldNotListenForFace_viewShown() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ Mockito.`when`(keyguardUpdateMonitor.shouldListenForFace()).thenReturn(false)
+ Mockito.`when`(keyguardBypassController.bypassEnabled).thenReturn(true)
+ onFinishedGoingToSleep()
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_panelExpandedHeightZero_viewHidden() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ shadeViewStateProvider.panelViewExpandedHeight = 0f
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_dragProgressOne_viewHidden() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ shadeViewStateProvider.lockscreenShadeDragProgress = 1f
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_disableSystemInfoFalse_viewShown() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ setDisableSystemInfo(false)
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_disableSystemInfoTrue_viewHidden() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ setDisableSystemInfo(true)
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_disableSystemIconsFalse_viewShown() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ setDisableSystemIcons(false)
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_disableSystemIconsTrue_viewHidden() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ setDisableSystemIcons(true)
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_dozingTrue_flagOff_viewHidden() {
+ controller.init()
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ controller.setDozing(true)
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateViewState_dozingFalse_flagOff_viewShown() {
+ controller.init()
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ controller.setDozing(false)
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun updateViewState_flagOn_doesNothing() {
+ controller.init()
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ keyguardStatusBarView.visibility = View.GONE
+ keyguardStatusBarView.alpha = 0.456f
+
+ controller.updateViewState()
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.GONE)
+ Truth.assertThat(keyguardStatusBarView.alpha).isEqualTo(0.456f)
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun updateViewStateWithAlphaAndVis_flagOn_doesNothing() {
+ controller.init()
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ keyguardStatusBarView.visibility = View.GONE
+ keyguardStatusBarView.alpha = 0.456f
+
+ controller.updateViewState(0.789f, View.VISIBLE)
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.GONE)
+ Truth.assertThat(keyguardStatusBarView.alpha).isEqualTo(0.456f)
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun setAlpha_flagOn_doesNothing() {
+ controller.init()
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ keyguardStatusBarView.alpha = 0.456f
+
+ controller.setAlpha(0.123f)
+
+ Truth.assertThat(keyguardStatusBarView.alpha).isEqualTo(0.456f)
+ }
+
+ @Test
+ @EnableSceneContainer
+ fun setDozing_flagOn_doesNothing() {
+ controller.init()
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+
+ controller.setDozing(true)
+ controller.updateViewState()
+
+ // setDozing(true) should typically cause the view to hide. But since the flag is on, we
+ // should ignore these set dozing calls and stay the same visibility.
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun setAlpha_explicitAlpha_setsExplicitAlpha() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ controller.setAlpha(0.5f)
+
+ Truth.assertThat(keyguardStatusBarView.alpha).isEqualTo(0.5f)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun setAlpha_explicitAlpha_thenMinusOneAlpha_setsAlphaBasedOnDefaultCriteria() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ controller.setAlpha(0.5f)
+ controller.setAlpha(-1f)
+
+ Truth.assertThat(keyguardStatusBarView.alpha).isGreaterThan(0)
+ Truth.assertThat(keyguardStatusBarView.alpha).isNotEqualTo(0.5f)
+ }
+
+ // TODO(b/195442899): Add more tests for #updateViewState once CLs are finalized.
+ @Test
+ @DisableSceneContainer
+ fun updateForHeadsUp_headsUpShouldBeVisible_viewHidden() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ keyguardStatusBarView.visibility = View.VISIBLE
+
+ shadeViewStateProvider.setShouldHeadsUpBeVisible(true)
+ controller.updateForHeadsUp(/* animate= */ false)
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun updateForHeadsUp_headsUpShouldNotBeVisible_viewShown() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+
+ // Start with the opposite state.
+ shadeViewStateProvider.setShouldHeadsUpBeVisible(true)
+ controller.updateForHeadsUp(/* animate= */ false)
+
+ shadeViewStateProvider.setShouldHeadsUpBeVisible(false)
+ controller.updateForHeadsUp(/* animate= */ false)
+
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.VISIBLE)
+ }
+
+ @Test
+ fun testNewUserSwitcherDisablesAvatar_newUiOn() {
+ // GIVEN the status bar user switcher chip is enabled
+ Mockito.`when`(statusBarUserChipViewModel.chipEnabled).thenReturn(true)
+
+ // WHEN the controller is created
+ controller = createController()
+
+ // THEN keyguard status bar view avatar is disabled
+ Truth.assertThat(keyguardStatusBarView.isKeyguardUserAvatarEnabled).isFalse()
+ }
+
+ @Test
+ fun testNewUserSwitcherDisablesAvatar_newUiOff() {
+ // GIVEN the status bar user switcher chip is disabled
+ Mockito.`when`(statusBarUserChipViewModel.chipEnabled).thenReturn(false)
+
+ // WHEN the controller is created
+ controller = createController()
+
+ // THEN keyguard status bar view avatar is enabled
+ Truth.assertThat(keyguardStatusBarView.isKeyguardUserAvatarEnabled).isTrue()
+ }
+
+ @Test
+ fun testBlockedIcons_obeysSettingForVibrateIcon_settingOff() {
+ val str = mContext.getString(com.android.internal.R.string.status_bar_volume)
+
+ // GIVEN the setting is off
+ Mockito.`when`(secureSettings.getInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0))
+ .thenReturn(0)
+
+ // WHEN CollapsedStatusBarFragment builds the blocklist
+ controller.updateBlockedIcons()
+
+ // THEN status_bar_volume SHOULD be present in the list
+ val contains = controller.blockedIcons.contains(str)
+ Assert.assertTrue(contains)
+ }
+
+ @Test
+ fun testBlockedIcons_obeysSettingForVibrateIcon_settingOn() {
+ val str = mContext.getString(com.android.internal.R.string.status_bar_volume)
+
+ // GIVEN the setting is ON
+ Mockito.`when`(
+ secureSettings.getIntForUser(
+ Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON,
+ 0,
+ UserHandle.USER_CURRENT,
+ )
+ )
+ .thenReturn(1)
+
+ // WHEN CollapsedStatusBarFragment builds the blocklist
+ controller.updateBlockedIcons()
+
+ // THEN status_bar_volume SHOULD NOT be present in the list
+ val contains = controller.blockedIcons.contains(str)
+ Assert.assertFalse(contains)
+ }
+
+ private fun updateStateToNotKeyguard() {
+ updateStatusBarState(StatusBarState.SHADE)
+ }
+
+ private fun updateStateToKeyguard() {
+ updateStatusBarState(StatusBarState.KEYGUARD)
+ }
+
+ private fun updateStatusBarState(state: Int) {
+ val statusBarStateListenerCaptor =
+ ArgumentCaptor.forClass(StatusBarStateController.StateListener::class.java)
+ Mockito.verify(statusBarStateController).addCallback(statusBarStateListenerCaptor.capture())
+ val callback = statusBarStateListenerCaptor.value
+
+ callback.onStateChanged(state)
+ }
+
+ @Test
+ @DisableSceneContainer
+ fun animateKeyguardStatusBarIn_isDisabled_viewStillHidden() {
+ controller.onViewAttached()
+ updateStateToKeyguard()
+ setDisableSystemInfo(true)
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+
+ controller.animateKeyguardStatusBarIn()
+
+ // Since we're disabled, we don't actually animate in and stay invisible
+ Truth.assertThat(keyguardStatusBarView.visibility).isEqualTo(View.INVISIBLE)
+ }
+
+ /**
+ * Calls [com.android.keyguard.KeyguardUpdateMonitorCallback.onFinishedGoingToSleep] to ensure
+ * values are updated properly.
+ */
+ private fun onFinishedGoingToSleep() {
+ val keyguardUpdateCallbackCaptor =
+ ArgumentCaptor.forClass(KeyguardUpdateMonitorCallback::class.java)
+ Mockito.verify(keyguardUpdateMonitor)
+ .registerCallback(keyguardUpdateCallbackCaptor.capture())
+ val callback = keyguardUpdateCallbackCaptor.value
+
+ callback.onFinishedGoingToSleep(0)
+ }
+
+ private fun setDisableSystemInfo(disabled: Boolean) {
+ val callback = commandQueueCallback
+ val disabled1 = if (disabled) StatusBarManager.DISABLE_SYSTEM_INFO else 0
+ callback.disable(mContext.displayId, disabled1, 0, false)
+ }
+
+ private fun setDisableSystemIcons(disabled: Boolean) {
+ val callback = commandQueueCallback
+ val disabled2 = if (disabled) StatusBarManager.DISABLE2_SYSTEM_ICONS else 0
+ callback.disable(mContext.displayId, 0, disabled2, false)
+ }
+
+ private val commandQueueCallback: CommandQueue.Callbacks
+ get() {
+ val captor = ArgumentCaptor.forClass(CommandQueue.Callbacks::class.java)
+ Mockito.verify(commandQueue).addCallback(captor.capture())
+ return captor.value
+ }
+
+ private fun runAllScheduled() {
+ backgroundExecutor.runAllReady()
+ fakeExecutor.runAllReady()
+ }
+
+ private class TestShadeViewStateProvider : ShadeViewStateProvider {
+ override var panelViewExpandedHeight: Float = 100f
+ private var mShouldHeadsUpBeVisible = false
+ override var lockscreenShadeDragProgress: Float = 0f
+
+ override fun shouldHeadsUpBeVisible(): Boolean {
+ return mShouldHeadsUpBeVisible
+ }
+
+ fun setShouldHeadsUpBeVisible(shouldHeadsUpBeVisible: Boolean) {
+ this.mShouldHeadsUpBeVisible = shouldHeadsUpBeVisible
+ }
+ }
+}