Merge "Update lock screen user switcher on settings update and re-create view stub after disabling multi-user" into sc-dev am: cdd6adb5c5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14974991

Change-Id: I484cd529452a89ea0aa5d117c8a68338e0c10e1a
This commit is contained in:
TreeHugger Robot
2021-06-23 18:59:49 +00:00
committed by Automerger Merge Worker
4 changed files with 159 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ class ConfigurationControllerImpl(context: Context) : ConfigurationController {
private val listeners: MutableList<ConfigurationController.ConfigurationListener> = ArrayList() private val listeners: MutableList<ConfigurationController.ConfigurationListener> = ArrayList()
private val lastConfig = Configuration() private val lastConfig = Configuration()
private var density: Int = 0 private var density: Int = 0
private var smallestScreenWidth: Int = 0
private var fontScale: Float = 0.toFloat() private var fontScale: Float = 0.toFloat()
private val inCarMode: Boolean private val inCarMode: Boolean
private var uiMode: Int = 0 private var uiMode: Int = 0
@@ -38,6 +39,7 @@ class ConfigurationControllerImpl(context: Context) : ConfigurationController {
this.context = context this.context = context
fontScale = currentConfig.fontScale fontScale = currentConfig.fontScale
density = currentConfig.densityDpi density = currentConfig.densityDpi
smallestScreenWidth = currentConfig.smallestScreenWidthDp
inCarMode = currentConfig.uiMode and Configuration.UI_MODE_TYPE_MASK == inCarMode = currentConfig.uiMode and Configuration.UI_MODE_TYPE_MASK ==
Configuration.UI_MODE_TYPE_CAR Configuration.UI_MODE_TYPE_CAR
uiMode = currentConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK uiMode = currentConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK
@@ -72,6 +74,14 @@ class ConfigurationControllerImpl(context: Context) : ConfigurationController {
this.fontScale = fontScale this.fontScale = fontScale
} }
val smallestScreenWidth = newConfig.smallestScreenWidthDp
if (smallestScreenWidth != this.smallestScreenWidth) {
this.smallestScreenWidth = smallestScreenWidth
listeners.filterForEach({ this.listeners.contains(it) }) {
it.onSmallestScreenWidthChanged()
}
}
val localeList = newConfig.locales val localeList = newConfig.locales
if (localeList != this.localeList) { if (localeList != this.localeList) {
this.localeList = localeList this.localeList = localeList

View File

@@ -36,9 +36,11 @@ import android.animation.ValueAnimator;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Fragment; import android.app.Fragment;
import android.app.StatusBarManager; import android.app.StatusBarManager;
import android.content.ContentResolver;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.ColorFilter; import android.graphics.ColorFilter;
@@ -50,10 +52,12 @@ import android.graphics.Region;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.hardware.biometrics.BiometricSourceType; import android.hardware.biometrics.BiometricSourceType;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserManager; import android.os.UserManager;
import android.os.VibrationEffect; import android.os.VibrationEffect;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.util.MathUtils; import android.util.MathUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -210,6 +214,8 @@ public class NotificationPanelViewController extends PanelViewController {
new MyOnHeadsUpChangedListener(); new MyOnHeadsUpChangedListener();
private final HeightListener mHeightListener = new HeightListener(); private final HeightListener mHeightListener = new HeightListener();
private final ConfigurationListener mConfigurationListener = new ConfigurationListener(); private final ConfigurationListener mConfigurationListener = new ConfigurationListener();
private final SettingsChangeObserver mSettingsChangeObserver;
@VisibleForTesting final StatusBarStateListener mStatusBarStateListener = @VisibleForTesting final StatusBarStateListener mStatusBarStateListener =
new StatusBarStateListener(); new StatusBarStateListener();
private final BiometricUnlockController mBiometricUnlockController; private final BiometricUnlockController mBiometricUnlockController;
@@ -594,6 +600,8 @@ public class NotificationPanelViewController extends PanelViewController {
private int mScreenCornerRadius; private int mScreenCornerRadius;
private boolean mQSAnimatingHiddenFromCollapsed; private boolean mQSAnimatingHiddenFromCollapsed;
private final ContentResolver mContentResolver;
private final Executor mUiExecutor; private final Executor mUiExecutor;
private final SecureSettings mSecureSettings; private final SecureSettings mSecureSettings;
@@ -635,6 +643,7 @@ public class NotificationPanelViewController extends PanelViewController {
@Inject @Inject
public NotificationPanelViewController(NotificationPanelView view, public NotificationPanelViewController(NotificationPanelView view,
@Main Resources resources, @Main Resources resources,
@Main Handler handler,
LayoutInflater layoutInflater, LayoutInflater layoutInflater,
NotificationWakeUpCoordinator coordinator, PulseExpansionHandler pulseExpansionHandler, NotificationWakeUpCoordinator coordinator, PulseExpansionHandler pulseExpansionHandler,
DynamicPrivacyController dynamicPrivacyController, DynamicPrivacyController dynamicPrivacyController,
@@ -678,6 +687,7 @@ public class NotificationPanelViewController extends PanelViewController {
TapAgainViewController tapAgainViewController, TapAgainViewController tapAgainViewController,
NavigationModeController navigationModeController, NavigationModeController navigationModeController,
FragmentService fragmentService, FragmentService fragmentService,
ContentResolver contentResolver,
QuickAccessWalletController quickAccessWalletController, QuickAccessWalletController quickAccessWalletController,
@Main Executor uiExecutor, @Main Executor uiExecutor,
SecureSettings secureSettings, SecureSettings secureSettings,
@@ -704,15 +714,12 @@ public class NotificationPanelViewController extends PanelViewController {
mKeyguardStatusBarViewComponentFactory = keyguardStatusBarViewComponentFactory; mKeyguardStatusBarViewComponentFactory = keyguardStatusBarViewComponentFactory;
mDepthController = notificationShadeDepthController; mDepthController = notificationShadeDepthController;
mFeatureFlags = featureFlags; mFeatureFlags = featureFlags;
mContentResolver = contentResolver;
mKeyguardQsUserSwitchComponentFactory = keyguardQsUserSwitchComponentFactory; mKeyguardQsUserSwitchComponentFactory = keyguardQsUserSwitchComponentFactory;
mKeyguardUserSwitcherComponentFactory = keyguardUserSwitcherComponentFactory; mKeyguardUserSwitcherComponentFactory = keyguardUserSwitcherComponentFactory;
mQSDetailDisplayer = qsDetailDisplayer; mQSDetailDisplayer = qsDetailDisplayer;
mFragmentService = fragmentService; mFragmentService = fragmentService;
mKeyguardUserSwitcherEnabled = mResources.getBoolean( mSettingsChangeObserver = new SettingsChangeObserver(handler);
com.android.internal.R.bool.config_keyguardUserSwitcher);
mKeyguardQsUserSwitchEnabled =
mKeyguardUserSwitcherEnabled && mResources.getBoolean(
R.bool.config_keyguard_user_switch_opens_qs_details);
mShouldUseSplitNotificationShade = mShouldUseSplitNotificationShade =
Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources); Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources);
mView.setWillNotDraw(!DEBUG); mView.setWillNotDraw(!DEBUG);
@@ -795,6 +802,7 @@ public class NotificationPanelViewController extends PanelViewController {
} }
mMaxKeyguardNotifications = resources.getInteger(R.integer.keyguard_max_notification_count); mMaxKeyguardNotifications = resources.getInteger(R.integer.keyguard_max_notification_count);
updateUserSwitcherFlags();
onFinishInflate(); onFinishInflate();
} }
@@ -1034,6 +1042,10 @@ public class NotificationPanelViewController extends PanelViewController {
view = mLayoutInflater.inflate(layoutId, mView, false); view = mLayoutInflater.inflate(layoutId, mView, false);
mView.addView(view, index); mView.addView(view, index);
} else { } else {
// Add the stub back so we can re-inflate it again if necessary
ViewStub stub = new ViewStub(mView.getContext(), layoutId);
stub.setId(stubId);
mView.addView(stub, index);
view = null; view = null;
} }
} else if (enabled) { } else if (enabled) {
@@ -1061,6 +1073,7 @@ public class NotificationPanelViewController extends PanelViewController {
updateResources(); updateResources();
// Re-inflate the keyguard user switcher group. // Re-inflate the keyguard user switcher group.
updateUserSwitcherFlags();
boolean isUserSwitcherEnabled = mUserManager.isUserSwitcherEnabled(); boolean isUserSwitcherEnabled = mUserManager.isUserSwitcherEnabled();
boolean showQsUserSwitch = mKeyguardQsUserSwitchEnabled && isUserSwitcherEnabled; boolean showQsUserSwitch = mKeyguardQsUserSwitchEnabled && isUserSwitcherEnabled;
boolean showKeyguardUserSwitcher = boolean showKeyguardUserSwitcher =
@@ -3873,6 +3886,26 @@ public class NotificationPanelViewController extends PanelViewController {
return false; return false;
} }
private void updateUserSwitcherFlags() {
mKeyguardUserSwitcherEnabled = mResources.getBoolean(
com.android.internal.R.bool.config_keyguardUserSwitcher);
mKeyguardQsUserSwitchEnabled =
mKeyguardUserSwitcherEnabled && mResources.getBoolean(
R.bool.config_keyguard_user_switch_opens_qs_details);
}
private void registerSettingsChangeListener() {
mContentResolver.registerContentObserver(
Settings.Global.getUriFor(Settings.Global.USER_SWITCHER_ENABLED),
/* notifyForDescendants */ false,
mSettingsChangeObserver
);
}
private void unregisterSettingsChangeListener() {
mContentResolver.unregisterContentObserver(mSettingsChangeObserver);
}
private class OnHeightChangedListener implements ExpandableView.OnHeightChangedListener { private class OnHeightChangedListener implements ExpandableView.OnHeightChangedListener {
@Override @Override
public void onHeightChanged(ExpandableView view, boolean needsAnimation) { public void onHeightChanged(ExpandableView view, boolean needsAnimation) {
@@ -4193,6 +4226,15 @@ public class NotificationPanelViewController extends PanelViewController {
reInflateViews(); reInflateViews();
} }
@Override
public void onSmallestScreenWidthChanged() {
if (DEBUG) Log.d(TAG, "onSmallestScreenWidthChanged");
// Can affect multi-user switcher visibility as it depends on screen size by default:
// it is enabled only for devices with large screens (see config_keyguardUserSwitcher)
reInflateViews();
}
@Override @Override
public void onOverlayChanged() { public void onOverlayChanged() {
if (DEBUG) Log.d(TAG, "onOverlayChanged"); if (DEBUG) Log.d(TAG, "onOverlayChanged");
@@ -4206,6 +4248,21 @@ public class NotificationPanelViewController extends PanelViewController {
} }
} }
private class SettingsChangeObserver extends ContentObserver {
SettingsChangeObserver(Handler handler) {
super(handler);
}
@Override
public void onChange(boolean selfChange) {
if (DEBUG) Log.d(TAG, "onSettingsChanged");
// Can affect multi-user switcher visibility
reInflateViews();
}
}
private class StatusBarStateListener implements StateListener { private class StatusBarStateListener implements StateListener {
@Override @Override
public void onStateChanged(int statusBarState) { public void onStateChanged(int statusBarState) {
@@ -4321,10 +4378,12 @@ public class NotificationPanelViewController extends PanelViewController {
mConfigurationListener.onThemeChanged(); mConfigurationListener.onThemeChanged();
mFalsingManager.addTapListener(mFalsingTapListener); mFalsingManager.addTapListener(mFalsingTapListener);
mKeyguardIndicationController.init(); mKeyguardIndicationController.init();
registerSettingsChangeListener();
} }
@Override @Override
public void onViewDetachedFromWindow(View v) { public void onViewDetachedFromWindow(View v) {
unregisterSettingsChangeListener();
mFragmentService.getFragmentHostManager(mView) mFragmentService.getFragmentHostManager(mView)
.removeTagListener(QS.TAG, mFragmentListener); .removeTagListener(QS.TAG, mFragmentListener);
mStatusBarStateController.removeCallback(mStatusBarStateListener); mStatusBarStateController.removeCallback(mStatusBarStateListener);

View File

@@ -33,6 +33,7 @@ public interface ConfigurationController extends CallbackController<Configuratio
interface ConfigurationListener { interface ConfigurationListener {
default void onConfigChanged(Configuration newConfig) {} default void onConfigChanged(Configuration newConfig) {}
default void onDensityOrFontScaleChanged() {} default void onDensityOrFontScaleChanged() {}
default void onSmallestScreenWidthChanged() {}
default void onOverlayChanged() {} default void onOverlayChanged() {}
default void onUiModeChanged() {} default void onUiModeChanged() {}
default void onThemeChanged() {} default void onThemeChanged() {}

View File

@@ -26,9 +26,12 @@ import static com.android.systemui.statusbar.notification.ViewGroupFadeHelper.re
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@@ -37,9 +40,13 @@ import static org.mockito.Mockito.when;
import android.annotation.IdRes; import android.annotation.IdRes;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.biometrics.BiometricSourceType; import android.hardware.biometrics.BiometricSourceType;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.UserManager; import android.os.UserManager;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
@@ -50,6 +57,7 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewPropertyAnimator; import android.view.ViewPropertyAnimator;
import android.view.ViewStub;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeInfo;
@@ -60,6 +68,7 @@ import androidx.test.filters.SmallTest;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.testing.UiEventLoggerFake; import com.android.internal.logging.testing.UiEventLoggerFake;
import com.android.internal.util.CollectionUtils;
import com.android.internal.util.LatencyTracker; import com.android.internal.util.LatencyTracker;
import com.android.keyguard.KeyguardClockSwitch; import com.android.keyguard.KeyguardClockSwitch;
import com.android.keyguard.KeyguardClockSwitchController; import com.android.keyguard.KeyguardClockSwitchController;
@@ -140,6 +149,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
private KeyguardBottomAreaView mKeyguardBottomArea; private KeyguardBottomAreaView mKeyguardBottomArea;
@Mock @Mock
private KeyguardBottomAreaView mQsFrame; private KeyguardBottomAreaView mQsFrame;
private KeyguardStatusView mKeyguardStatusView;
@Mock @Mock
private ViewGroup mBigClockContainer; private ViewGroup mBigClockContainer;
@Mock @Mock
@@ -153,6 +163,10 @@ public class NotificationPanelViewTest extends SysuiTestCase {
@Mock @Mock
private KeyguardStatusBarView mKeyguardStatusBar; private KeyguardStatusBarView mKeyguardStatusBar;
@Mock @Mock
private View mUserSwitcherView;
@Mock
private ViewStub mUserSwitcherStubView;
@Mock
private HeadsUpTouchHelper.Callback mHeadsUpCallback; private HeadsUpTouchHelper.Callback mHeadsUpCallback;
@Mock @Mock
private PanelBar mPanelBar; private PanelBar mPanelBar;
@@ -204,7 +218,6 @@ public class NotificationPanelViewTest extends SysuiTestCase {
@Mock @Mock
private KeyguardClockSwitch mKeyguardClockSwitch; private KeyguardClockSwitch mKeyguardClockSwitch;
private PanelViewController.TouchHandler mTouchHandler; private PanelViewController.TouchHandler mTouchHandler;
@Mock
private ConfigurationController mConfigurationController; private ConfigurationController mConfigurationController;
@Mock @Mock
private MediaHierarchyManager mMediaHiearchyManager; private MediaHierarchyManager mMediaHiearchyManager;
@@ -265,6 +278,8 @@ public class NotificationPanelViewTest extends SysuiTestCase {
@Mock @Mock
private SecureSettings mSecureSettings; private SecureSettings mSecureSettings;
@Mock @Mock
private ContentResolver mContentResolver;
@Mock
private TapAgainViewController mTapAgainViewController; private TapAgainViewController mTapAgainViewController;
@Mock @Mock
private KeyguardIndicationController mKeyguardIndicationController; private KeyguardIndicationController mKeyguardIndicationController;
@@ -287,6 +302,9 @@ public class NotificationPanelViewTest extends SysuiTestCase {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mStatusBarStateController = new StatusBarStateControllerImpl(mUiEventLogger); mStatusBarStateController = new StatusBarStateControllerImpl(mUiEventLogger);
mKeyguardStatusView = new KeyguardStatusView(mContext);
mKeyguardStatusView.setId(R.id.keyguard_status_view);
when(mAuthController.isUdfpsEnrolled(anyInt())).thenReturn(false); when(mAuthController.isUdfpsEnrolled(anyInt())).thenReturn(false);
when(mHeadsUpCallback.getContext()).thenReturn(mContext); when(mHeadsUpCallback.getContext()).thenReturn(mContext);
when(mView.getResources()).thenReturn(mResources); when(mView.getResources()).thenReturn(mResources);
@@ -301,6 +319,9 @@ public class NotificationPanelViewTest extends SysuiTestCase {
when(mResources.getDimensionPixelSize(R.dimen.notification_panel_width)).thenReturn(400); when(mResources.getDimensionPixelSize(R.dimen.notification_panel_width)).thenReturn(400);
when(mView.getContext()).thenReturn(getContext()); when(mView.getContext()).thenReturn(getContext());
when(mView.findViewById(R.id.keyguard_header)).thenReturn(mKeyguardStatusBar); when(mView.findViewById(R.id.keyguard_header)).thenReturn(mKeyguardStatusBar);
when(mView.findViewById(R.id.keyguard_user_switcher_view)).thenReturn(mUserSwitcherView);
when(mView.findViewById(R.id.keyguard_user_switcher_stub)).thenReturn(
mUserSwitcherStubView);
when(mView.findViewById(R.id.keyguard_clock_container)).thenReturn(mKeyguardClockSwitch); when(mView.findViewById(R.id.keyguard_clock_container)).thenReturn(mKeyguardClockSwitch);
when(mView.findViewById(R.id.notification_stack_scroller)) when(mView.findViewById(R.id.notification_stack_scroller))
.thenReturn(mNotificationStackScrollLayout); .thenReturn(mNotificationStackScrollLayout);
@@ -320,7 +341,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
mNotificationContainerParent = new NotificationsQuickSettingsContainer(getContext(), null); mNotificationContainerParent = new NotificationsQuickSettingsContainer(getContext(), null);
mNotificationContainerParent.addView(newViewWithId(R.id.qs_frame)); mNotificationContainerParent.addView(newViewWithId(R.id.qs_frame));
mNotificationContainerParent.addView(newViewWithId(R.id.notification_stack_scroller)); mNotificationContainerParent.addView(newViewWithId(R.id.notification_stack_scroller));
mNotificationContainerParent.addView(newViewWithId(R.id.keyguard_status_view)); mNotificationContainerParent.addView(mKeyguardStatusView);
when(mView.findViewById(R.id.notification_container_parent)) when(mView.findViewById(R.id.notification_container_parent))
.thenReturn(mNotificationContainerParent); .thenReturn(mNotificationContainerParent);
when(mFragmentService.getFragmentHostManager(mView)).thenReturn(mFragmentHostManager); when(mFragmentService.getFragmentHostManager(mView)).thenReturn(mFragmentHostManager);
@@ -348,6 +369,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
mFalsingManager, mFalsingManager,
mLockscreenShadeTransitionController, mLockscreenShadeTransitionController,
new FalsingCollectorFake()); new FalsingCollectorFake());
mConfigurationController = new ConfigurationControllerImpl(mContext);
when(mKeyguardStatusViewComponentFactory.build(any())) when(mKeyguardStatusViewComponentFactory.build(any()))
.thenReturn(mKeyguardStatusViewComponent); .thenReturn(mKeyguardStatusViewComponent);
when(mKeyguardStatusViewComponent.getKeyguardClockSwitchController()) when(mKeyguardStatusViewComponent.getKeyguardClockSwitchController())
@@ -358,10 +380,16 @@ public class NotificationPanelViewTest extends SysuiTestCase {
.thenReturn(mKeyguardStatusBarViewComponent); .thenReturn(mKeyguardStatusBarViewComponent);
when(mKeyguardStatusBarViewComponent.getKeyguardStatusBarViewController()) when(mKeyguardStatusBarViewComponent.getKeyguardStatusBarViewController())
.thenReturn(mKeyguardStatusBarViewController); .thenReturn(mKeyguardStatusBarViewController);
when(mLayoutInflater.inflate(eq(R.layout.keyguard_status_view), any(), anyBoolean()))
.thenReturn(mKeyguardStatusView);
when(mLayoutInflater.inflate(eq(R.layout.keyguard_bottom_area), any(), anyBoolean()))
.thenReturn(mKeyguardBottomArea);
reset(mView); reset(mView);
mNotificationPanelViewController = new NotificationPanelViewController(mView, mNotificationPanelViewController = new NotificationPanelViewController(mView,
mResources, mResources,
new Handler(Looper.getMainLooper()),
mLayoutInflater, mLayoutInflater,
coordinator, expansionHandler, mDynamicPrivacyController, mKeyguardBypassController, coordinator, expansionHandler, mDynamicPrivacyController, mKeyguardBypassController,
mFalsingManager, new FalsingCollectorFake(), mFalsingManager, new FalsingCollectorFake(),
@@ -395,6 +423,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
mTapAgainViewController, mTapAgainViewController,
mNavigationModeController, mNavigationModeController,
mFragmentService, mFragmentService,
mContentResolver,
mQuickAccessWalletController, mQuickAccessWalletController,
new FakeExecutor(new FakeSystemClock()), new FakeExecutor(new FakeSystemClock()),
mSecureSettings, mSecureSettings,
@@ -548,6 +577,38 @@ public class NotificationPanelViewTest extends SysuiTestCase {
.isEqualTo(R.id.qs_edge_guideline); .isEqualTo(R.id.qs_edge_guideline);
} }
@Test
public void testDisableUserSwitcherAfterEnabling_returnsViewStubToTheViewHierarchy() {
givenViewAttached();
when(mResources.getBoolean(
com.android.internal.R.bool.config_keyguardUserSwitcher)).thenReturn(true);
updateMultiUserSetting(true);
clearInvocations(mView);
updateMultiUserSetting(false);
ArgumentCaptor<View> captor = ArgumentCaptor.forClass(View.class);
verify(mView, atLeastOnce()).addView(captor.capture(), anyInt());
final View userSwitcherStub = CollectionUtils.find(captor.getAllValues(),
view -> view.getId() == R.id.keyguard_user_switcher_stub);
assertThat(userSwitcherStub).isNotNull();
assertThat(userSwitcherStub).isInstanceOf(ViewStub.class);
}
@Test
public void testChangeSmallestScreenWidthAndUserSwitchEnabled_inflatesUserSwitchView() {
givenViewAttached();
when(mView.findViewById(R.id.keyguard_user_switcher_view)).thenReturn(null);
updateSmallestScreenWidth(300);
when(mResources.getBoolean(
com.android.internal.R.bool.config_keyguardUserSwitcher)).thenReturn(true);
when(mUserManager.isUserSwitcherEnabled()).thenReturn(true);
updateSmallestScreenWidth(800);
verify(mUserSwitcherStubView).inflate();
}
@Test @Test
public void testSplitShadeLayout_isAlignedToGuideline() { public void testSplitShadeLayout_isAlignedToGuideline() {
enableSplitShade(); enableSplitShade();
@@ -682,6 +743,12 @@ public class NotificationPanelViewTest extends SysuiTestCase {
return mFalsingManager.getTapListeners().get(0); return mFalsingManager.getTapListeners().get(0);
} }
private void givenViewAttached() {
for (View.OnAttachStateChangeListener listener : mOnAttachStateChangeListeners) {
listener.onViewAttachedToWindow(mView);
}
}
private View newViewWithId(int id) { private View newViewWithId(int id) {
View view = new View(mContext); View view = new View(mContext);
view.setId(id); view.setId(id);
@@ -704,6 +771,21 @@ public class NotificationPanelViewTest extends SysuiTestCase {
mNotificationPanelViewController.updateResources(); mNotificationPanelViewController.updateResources();
} }
private void updateMultiUserSetting(boolean enabled) {
when(mUserManager.isUserSwitcherEnabled()).thenReturn(enabled);
final ArgumentCaptor<ContentObserver> observerCaptor =
ArgumentCaptor.forClass(ContentObserver.class);
verify(mContentResolver)
.registerContentObserver(any(), anyBoolean(), observerCaptor.capture());
observerCaptor.getValue().onChange(/* selfChange */ false);
}
private void updateSmallestScreenWidth(int smallestScreenWidthDp) {
Configuration configuration = new Configuration();
configuration.smallestScreenWidthDp = smallestScreenWidthDp;
mConfigurationController.onConfigurationChanged(configuration);
}
private void onTouchEvent(MotionEvent ev) { private void onTouchEvent(MotionEvent ev) {
mTouchHandler.onTouch(mView, ev); mTouchHandler.onTouch(mView, ev);
} }