diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp index 851f976d52467..07f7ecd112e4b 100644 --- a/packages/SystemUI/Android.bp +++ b/packages/SystemUI/Android.bp @@ -409,6 +409,7 @@ android_library { "mockito-target-extended-minus-junit4", "androidx.test.ext.junit", "androidx.test.ext.truth", + "kotlin-test", ], libs: [ "android.test.runner", diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java index 73b4c5f47cded..757022dd153bb 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java @@ -543,7 +543,8 @@ public class KeyguardStatusViewController extends ViewController { expectedCenterX = width * normalizedPortPosY expectedCenterY = height * (1 - normalizedPortPosX) diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlViewHolderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlViewHolderTest.kt index 42f28c8c60439..2ae342a5cfa50 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlViewHolderTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlViewHolderTest.kt @@ -125,7 +125,7 @@ class ControlViewHolderTest : SysuiTestCase() { control ) cvh.bindData(cws, false) - val chevronIcon = baseLayout.findViewById(R.id.chevron_icon) + val chevronIcon = baseLayout.requireViewById(R.id.chevron_icon) assertThat(chevronIcon.visibility).isEqualTo(View.VISIBLE) } @@ -138,4 +138,4 @@ private const val TINT_COLOR = 0x00ff00 // Should be different from [COLOR] private val DRAWABLE = GradientDrawable() private val COLOR = ColorStateList.valueOf(0xffff00) private val DEFAULT_CONTROL = Control.StatelessBuilder( - CONTROL_ID, mock(PendingIntent::class.java)).build() \ No newline at end of file + CONTROL_ID, mock(PendingIntent::class.java)).build() diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt index fcd6568de9f32..a400ff9630266 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/ui/ControlsUiControllerImplTest.kt @@ -365,7 +365,8 @@ class ControlsUiControllerImplTest : SysuiTestCase() { val selectedItems = listOf( SelectedItem.StructureItem( - StructureInfo(ComponentName.unflattenFromString("pkg/.cls1"), "a", ArrayList()) + StructureInfo(checkNotNull(ComponentName.unflattenFromString("pkg/.cls1")), + "a", ArrayList()) ), ) preferredPanelRepository.setSelectedComponent( diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt index 85ee0e4d6ec36..a3e264ad7874b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt @@ -332,9 +332,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { ) .isFalse() - whenever(faceManager.sensorPropertiesInternal).thenReturn(null) - assertThat(createDeviceEntryFaceAuthRepositoryImpl().isDetectionSupported).isFalse() - whenever(faceManager.sensorPropertiesInternal).thenReturn(listOf()) assertThat(createDeviceEntryFaceAuthRepositoryImpl().isDetectionSupported).isFalse() diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt index 5b8272b04bfb7..064bebd0df016 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaCarouselControllerTest.kt @@ -132,7 +132,7 @@ class MediaCarouselControllerTest : SysuiTestCase() { @Before fun setup() { MockitoAnnotations.initMocks(this) - context.resources.configuration.locales = LocaleList(Locale.US, Locale.UK) + context.resources.configuration.setLocales(LocaleList(Locale.US, Locale.UK)) transitionRepository = FakeKeyguardTransitionRepository() mediaCarouselController = MediaCarouselController( @@ -730,13 +730,13 @@ class MediaCarouselControllerTest : SysuiTestCase() { @Test fun testOnLocaleListChanged_playersAreAddedBack() { - context.resources.configuration.locales = LocaleList(Locale.US, Locale.UK, Locale.CANADA) + context.resources.configuration.setLocales(LocaleList(Locale.US, Locale.UK, Locale.CANADA)) testConfigurationChange(configListener.value::onLocaleListChanged) verify(pageIndicator, never()).tintList = ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator)) - context.resources.configuration.locales = LocaleList(Locale.UK, Locale.US, Locale.CANADA) + context.resources.configuration.setLocales(LocaleList(Locale.UK, Locale.US, Locale.CANADA)) testConfigurationChange(configListener.value::onLocaleListChanged) verify(pageIndicator).tintList = diff --git a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/view/TaskPreviewSizeProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/view/TaskPreviewSizeProviderTest.kt index ee3b80ac932ed..906420d03bed3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/view/TaskPreviewSizeProviderTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/appselector/view/TaskPreviewSizeProviderTest.kt @@ -123,7 +123,7 @@ class TaskPreviewSizeProviderTest : SysuiTestCase() { private fun givenDisplay(width: Int, height: Int, isTablet: Boolean = false) { val bounds = Rect(0, 0, width, height) - val windowMetrics = WindowMetrics(bounds, null) + val windowMetrics = WindowMetrics(bounds, { null }, 1.0f) whenever(windowManager.maximumWindowMetrics).thenReturn(windowMetrics) whenever(windowManager.currentWindowMetrics).thenReturn(windowMetrics) diff --git a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/taskswitcher/data/repository/MediaProjectionManagerRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/taskswitcher/data/repository/MediaProjectionManagerRepositoryTest.kt index 3a74c7255cbba..7bd97ce2670c6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/taskswitcher/data/repository/MediaProjectionManagerRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/taskswitcher/data/repository/MediaProjectionManagerRepositoryTest.kt @@ -107,20 +107,6 @@ class MediaProjectionManagerRepositoryTest : SysuiTestCase() { assertThat(state).isEqualTo(MediaProjectionState.EntireScreen) } - @Test - fun mediaProjectionState_onSessionSet_tokenNull_emitsEntireScreen() = - testScope.runTest { - val state by collectLastValue(repo.mediaProjectionState) - runCurrent() - - fakeMediaProjectionManager.dispatchOnSessionSet( - session = - ContentRecordingSession.createTaskSession(/* taskWindowContainerToken= */ null) - ) - - assertThat(state).isEqualTo(MediaProjectionState.EntireScreen) - } - @Test fun mediaProjectionState_sessionSet_taskWithToken_noMatchingRunningTask_emitsEntireScreen() = testScope.runTest { diff --git a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt index fab1de00dcbcb..2d3dc585ac70d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt @@ -73,7 +73,7 @@ class BackPanelControllerTest : SysuiTestCase() { context, windowManager, ViewConfiguration.get(context), - Handler.createAsync(Looper.myLooper()), + Handler.createAsync(checkNotNull(Looper.myLooper())), vibratorHelper, configurationController, latencyTracker, diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt index d933b57e8e153..1536c1737de60 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt @@ -69,6 +69,7 @@ import com.android.wm.shell.bubbles.Bubble import com.android.wm.shell.bubbles.Bubbles import com.google.common.truth.Truth.assertThat import java.util.Optional +import kotlin.test.assertNotNull import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.UnconfinedTestDispatcher @@ -672,7 +673,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { extras().bool(EXTRA_USE_STYLUS_MODE).isTrue() } iconCaptor.value?.let { icon -> - assertThat(icon).isNotNull() + assertNotNull(icon) assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) } } @@ -755,7 +756,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { assertThat(shortLabel).isEqualTo(NOTE_TASK_SHORT_LABEL) assertThat(longLabel).isEqualTo(NOTE_TASK_LONG_LABEL) assertThat(isLongLived).isEqualTo(true) - assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) + assertThat(icon?.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) assertThat(extras?.getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE)) .isEqualTo(NOTE_TASK_PACKAGE_NAME) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogTest.kt index 07feedf1d654a..ad6909d71ddd8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogTest.kt @@ -126,6 +126,7 @@ class ScreenRecordPermissionDialogTest : SysuiTestCase() { private fun onSpinnerItemSelected(position: Int) { val spinner = dialog.requireViewById(R.id.screen_share_mode_spinner) - spinner.onItemSelectedListener.onItemSelected(spinner, mock(), position, /* id= */ 0) + checkNotNull(spinner.onItemSelectedListener) + .onItemSelected(spinner, mock(), position, /* id= */ 0) } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerLegacyTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerLegacyTest.kt index 112a09bcfe620..577b6e0bc58ac 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerLegacyTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerLegacyTest.kt @@ -584,7 +584,7 @@ class NotificationsQSContainerControllerLegacyTest : SysuiTestCase() { private fun emptyInsets() = mock(WindowInsets::class.java) private fun WindowInsets.withCutout(): WindowInsets { - whenever(displayCutout.safeInsetBottom).thenReturn(CUTOUT_HEIGHT) + whenever(checkNotNull(displayCutout).safeInsetBottom).thenReturn(CUTOUT_HEIGHT) return this } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerTest.kt index 8d3c4b21aa26e..405199ed4ecba 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationsQSContainerControllerTest.kt @@ -567,7 +567,7 @@ class NotificationsQSContainerControllerTest : SysuiTestCase() { private fun emptyInsets() = mock(WindowInsets::class.java) private fun WindowInsets.withCutout(): WindowInsets { - whenever(displayCutout.safeInsetBottom).thenReturn(CUTOUT_HEIGHT) + whenever(checkNotNull(displayCutout).safeInsetBottom).thenReturn(CUTOUT_HEIGHT) return this } diff --git a/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt index 58b44ae5bcbd2..19dc72d6c2e3c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt @@ -236,7 +236,8 @@ class DreamSmartspaceControllerTest : SysuiTestCase() { `when`(precondition.conditionsMet()).thenReturn(true) // Given a session is created - val weatherView = controller.buildAndConnectWeatherView(fakeParent, customView) + val weatherView = + checkNotNull(controller.buildAndConnectWeatherView(fakeParent, customView)) controller.stateChangeListener.onViewAttachedToWindow(weatherView) verify(smartspaceManager).createSmartspaceSession(any()) @@ -258,7 +259,8 @@ class DreamSmartspaceControllerTest : SysuiTestCase() { // Given a session is created val customView = Mockito.mock(TestView::class.java) - val weatherView = controller.buildAndConnectWeatherView(fakeParent, customView) + val weatherView = + checkNotNull(controller.buildAndConnectWeatherView(fakeParent, customView)) controller.stateChangeListener.onViewAttachedToWindow(weatherView) verify(smartspaceManager).createSmartspaceSession(any()) diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt index 724ea023f2bd6..e4da53a1a0a4f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt @@ -47,7 +47,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() { processor = MediaArtworkProcessor() val point = Point() - context.display.getSize(point) + checkNotNull(context.display).getSize(point) screenWidth = point.x screenHeight = point.y } @@ -106,4 +106,4 @@ class MediaArtworkProcessorTest : SysuiTestCase() { // THEN the processed bitmap is null assertThat(background).isNull() } -} \ No newline at end of file +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt index 2de57051d4f26..9036f22a792a6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceControllerTest.kt @@ -278,7 +278,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() { `when`(deviceProvisionedController.isCurrentUserSetup).thenReturn(false) // WHEN a connection attempt is made and view is attached - val view = controller.buildAndConnectView(fakeParent) + val view = controller.buildAndConnectView(fakeParent)!! controller.stateChangeListener.onViewAttachedToWindow(view) // THEN no session is created diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ConfigurationControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ConfigurationControllerImplTest.kt index 03d38542d2ee1..56d23978a5c75 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ConfigurationControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ConfigurationControllerImplTest.kt @@ -212,13 +212,13 @@ class ConfigurationControllerImplTest : SysuiTestCase() { @Test fun localeListChanged_listenerNotified() { val config = mContext.resources.configuration - config.locales = LocaleList(Locale.CANADA, Locale.GERMANY) + config.setLocales(LocaleList(Locale.CANADA, Locale.GERMANY)) mConfigurationController.onConfigurationChanged(config) val listener = createAndAddListener() // WHEN the locales are updated - config.locales = LocaleList(Locale.FRANCE, Locale.JAPAN, Locale.CHINESE) + config.setLocales(LocaleList(Locale.FRANCE, Locale.JAPAN, Locale.CHINESE)) mConfigurationController.onConfigurationChanged(config) // THEN the listener is notified diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt index 1759fb794bd6e..210c5ab28c425 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProviderTest.kt @@ -463,10 +463,10 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { val provider = StatusBarContentInsetsProvider(contextMock, configurationController, mock(DumpManager::class.java)) - configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160) + configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160)) val firstDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE) - configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600) + configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 800, 600)) // WHEN: get insets on the second display val secondDisplayInsets = provider.getStatusBarContentAreaForRotation(ROTATION_NONE) @@ -482,14 +482,14 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { val provider = StatusBarContentInsetsProvider(contextMock, configurationController, mock(DumpManager::class.java)) - configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160) + configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160)) val firstDisplayInsetsFirstCall = provider .getStatusBarContentAreaForRotation(ROTATION_NONE) - configuration.windowConfiguration.maxBounds = Rect(0, 0, 800, 600) + configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 800, 600)) provider.getStatusBarContentAreaForRotation(ROTATION_NONE) - configuration.windowConfiguration.maxBounds = Rect(0, 0, 1080, 2160) + configuration.windowConfiguration.setMaxBounds(Rect(0, 0, 1080, 2160)) // WHEN: get insets on the first display again val firstDisplayInsetsSecondCall = provider @@ -577,4 +577,4 @@ class StatusBarContentInsetsProviderTest : SysuiTestCase() { " expected=$expected actual=$actual", expected.equals(actual)) } -} \ No newline at end of file +}