Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSourceTest.kt +107 −1 Original line number Diff line number Diff line Loading @@ -17,8 +17,17 @@ package com.android.systemui.keyboard.shortcut.data.source import android.content.res.mainResources import android.platform.test.annotations.EnableFlags import android.view.KeyEvent.KEYCODE_D import android.view.KeyEvent.KEYCODE_DPAD_DOWN import android.view.KeyEvent.KEYCODE_EQUALS import android.view.KeyEvent.KEYCODE_LEFT_BRACKET import android.view.KeyEvent.KEYCODE_MINUS import android.view.KeyEvent.KEYCODE_RIGHT_BRACKET import android.view.KeyEvent.KEYCODE_TAB import android.view.KeyEvent.META_ALT_ON import android.view.KeyEvent.META_CTRL_ON import android.view.KeyEvent.META_META_ON import android.view.KeyEvent.META_SHIFT_ON import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading @@ -26,8 +35,23 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.testScope import com.android.systemui.res.R import com.android.systemui.testKosmos import com.android.window.flags.Flags import com.android.window.flags.Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT import com.android.window.flags.Flags.FLAG_ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS import com.android.window.flags.Flags.FLAG_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS import com.android.wm.shell.shared.desktopmode.FakeDesktopState import com.google.common.truth.Truth.assertThat import kotlin.Triple import kotlin.collections.flatMap import kotlin.collections.listOf import kotlin.collections.map import kotlin.map import kotlin.sequences.flatMap import kotlin.sequences.map import kotlin.text.flatMap import kotlin.text.map import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -36,8 +60,57 @@ import org.junit.runner.RunWith class MultitaskingShortcutsSourceTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val desktopState = FakeDesktopState() private val source = MultitaskingShortcutsSource(kosmos.mainResources, context, desktopState) private val source = MultitaskingShortcutsSource(kosmos.mainResources, context) private val expectedDesktopShortcuts = listOf( Triple( context.getString(R.string.system_multitasking_desktop_view), META_META_ON or META_CTRL_ON, KEYCODE_DPAD_DOWN, ), Triple( context.getString(R.string.system_multitasking_move_to_next_display), META_META_ON or META_CTRL_ON, KEYCODE_D, ), Triple( context.getString(R.string.system_desktop_mode_snap_left_window), META_META_ON, KEYCODE_LEFT_BRACKET, ), Triple( context.getString(R.string.system_desktop_mode_snap_right_window), META_META_ON, KEYCODE_RIGHT_BRACKET, ), Triple( context.getString(R.string.system_desktop_mode_toggle_maximize_window), META_META_ON, KEYCODE_EQUALS, ), Triple( context.getString(R.string.system_desktop_mode_minimize_window), META_META_ON, KEYCODE_MINUS, ), Triple( context.getString(R.string.system_multiple_desktop_mode_switch_between_desks), META_META_ON or META_CTRL_ON, KEYCODE_LEFT_BRACKET, ), Triple( context.getString(R.string.system_multiple_desktop_mode_switch_between_desks), META_META_ON or META_CTRL_ON, KEYCODE_RIGHT_BRACKET, ), ) @Before fun setup() { desktopState.canEnterDesktopMode = true } @Test fun shortcutGroups_doesNotContainCycleThroughRecentAppsShortcuts() { Loading Loading @@ -65,6 +138,39 @@ class MultitaskingShortcutsSourceTest : SysuiTestCase() { } } @Test @EnableFlags( Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT, Flags.FLAG_ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS, Flags.FLAG_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS, ) fun shortcutGroups_containsDesktopShortcuts() { testScope.runTest { val groups = source.shortcutGroups(TEST_DEVICE_ID) val shortcuts = groups.flatMap { it.items }.map { c -> Triple(c.label, c.modifiers, c.keycode) } assertThat(shortcuts).containsAtLeastElementsIn(expectedDesktopShortcuts) } } @Test @EnableFlags( Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT, Flags.FLAG_ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS, Flags.FLAG_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS, ) fun shortcutGroups_desktopDisabled_doesNotContainDesktopShortcuts() { testScope.runTest { desktopState.canEnterDesktopMode = false val groups = source.shortcutGroups(TEST_DEVICE_ID) val shortcuts = groups.flatMap { it.items }.map { c -> Triple(c.label, c.modifiers, c.keycode) } assertThat(shortcuts).containsNoneIn(expectedDesktopShortcuts) } } private companion object { private const val TEST_DEVICE_ID = 1234 } Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSource.kt +79 −71 Original line number Diff line number Diff line Loading @@ -36,13 +36,16 @@ import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.keyboard.shortcut.data.model.shortcutInfo import com.android.systemui.res.R import com.android.wm.shell.shared.desktopmode.DesktopModeStatus import com.android.wm.shell.shared.desktopmode.DesktopState import javax.inject.Inject class MultitaskingShortcutsSource @Inject constructor(@Main private val resources: Resources, @Application private val context: Context) : KeyboardShortcutGroupsSource { constructor( @Main private val resources: Resources, @Application private val context: Context, private val desktopState: DesktopState, ) : KeyboardShortcutGroupsSource { override suspend fun shortcutGroups(deviceId: Int) = listOf( Loading Loading @@ -74,7 +77,7 @@ constructor(@Main private val resources: Resources, @Application private val con command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_UP) } ) if (DesktopModeStatus.canEnterDesktopMode(context)) { if (desktopState.canEnterDesktopMode) { // Switch to desktop view // - Meta + Ctrl + Down arrow add( Loading @@ -82,7 +85,7 @@ constructor(@Main private val resources: Resources, @Application private val con command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_DOWN) } ) } if (DesktopExperienceFlags.ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT.isTrue()) { // Move a window to the next display: // - Meta + Ctrl + D Loading @@ -94,21 +97,22 @@ constructor(@Main private val resources: Resources, @Application private val con } ) } if ( DesktopModeStatus.canEnterDesktopMode(context) && DesktopModeFlags.ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS.isTrue ) { if (DesktopModeFlags.ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS.isTrue) { // Snap a freeform window to the left // - Meta + Left bracket add( shortcutInfo(resources.getString(R.string.system_desktop_mode_snap_left_window)) { shortcutInfo( resources.getString(R.string.system_desktop_mode_snap_left_window) ) { command(META_META_ON, KEYCODE_LEFT_BRACKET) } ) // Snap a freeform window to the right // - Meta + Right bracket add( shortcutInfo(resources.getString(R.string.system_desktop_mode_snap_right_window)) { shortcutInfo( resources.getString(R.string.system_desktop_mode_snap_right_window) ) { command(META_META_ON, KEYCODE_RIGHT_BRACKET) } ) Loading @@ -124,28 +128,31 @@ constructor(@Main private val resources: Resources, @Application private val con // Minimize a freeform window // - Meta + Minus add( shortcutInfo(resources.getString(R.string.system_desktop_mode_minimize_window)) { shortcutInfo( resources.getString(R.string.system_desktop_mode_minimize_window) ) { command(META_META_ON, KEYCODE_MINUS) } ) } if ( DesktopModeStatus.enableMultipleDesktops(context) && DesktopExperienceFlags.ENABLE_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS.isTrue ) { if (DesktopExperienceFlags.ENABLE_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS.isTrue) { // Move between desktops // - Meta + Ctrl + [ or ] add( shortcutInfo( resources.getString(R.string.system_multiple_desktop_mode_switch_between_desks) resources.getString( R.string.system_multiple_desktop_mode_switch_between_desks ) ) { command(META_META_ON or META_CTRL_ON, KEYCODE_LEFT_BRACKET) } ) add( shortcutInfo( resources.getString(R.string.system_multiple_desktop_mode_switch_between_desks) resources.getString( R.string.system_multiple_desktop_mode_switch_between_desks ) ) { command(META_META_ON or META_CTRL_ON, KEYCODE_RIGHT_BRACKET) } Loading @@ -153,3 +160,4 @@ constructor(@Main private val resources: Resources, @Application private val con } } } } packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java +2 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,8 @@ public abstract class SysuiTestCase { android.service.quickaccesswallet.Flags.class, com.android.internal.telephony.flags.Flags.class, com.android.server.notification.Flags.class, com.android.systemui.Flags.class); com.android.systemui.Flags.class, com.android.window.flags.Flags.class); // TODO(b/339471826): Fix Robolectric to execute the @ClassRule correctly @Rule public final SetFlagsRule mSetFlagsRule = Loading packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt +4 −1 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ import com.android.systemui.plugins.activityStarter import com.android.systemui.settings.displayTracker import com.android.systemui.settings.userTracker import com.android.systemui.statusbar.phone.systemUIDialogFactory import com.android.wm.shell.shared.desktopmode.FakeDesktopState var Kosmos.shortcutHelperAppCategoriesShortcutsSource: KeyboardShortcutGroupsSource by Kosmos.Fixture { AppCategoriesShortcutsSource(windowManager, testDispatcher) } Loading @@ -75,7 +76,7 @@ var Kosmos.shortcutHelperSystemShortcutsSource: KeyboardShortcutGroupsSource by Kosmos.Fixture { SystemShortcutsSource(mainResources, fakeInputManager.inputManager) } var Kosmos.shortcutHelperMultiTaskingShortcutsSource: KeyboardShortcutGroupsSource by Kosmos.Fixture { MultitaskingShortcutsSource(mainResources, applicationContext) } Kosmos.Fixture { MultitaskingShortcutsSource(mainResources, applicationContext, desktopState) } val Kosmos.shortcutHelperStateRepository by Kosmos.Fixture { ShortcutHelperStateRepository(fakeInputManager.inputManager, testDispatcher) } Loading Loading @@ -274,6 +275,8 @@ val Kosmos.shortcutCustomizationViewModelFactory by val Kosmos.fakeLauncherApps by Kosmos.Fixture { FakeLauncherApps() } val Kosmos.desktopState by Kosmos.Fixture { FakeDesktopState() } val Kosmos.userVisibleAppsRepository by Kosmos.Fixture { UserVisibleAppsRepository( Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSourceTest.kt +107 −1 Original line number Diff line number Diff line Loading @@ -17,8 +17,17 @@ package com.android.systemui.keyboard.shortcut.data.source import android.content.res.mainResources import android.platform.test.annotations.EnableFlags import android.view.KeyEvent.KEYCODE_D import android.view.KeyEvent.KEYCODE_DPAD_DOWN import android.view.KeyEvent.KEYCODE_EQUALS import android.view.KeyEvent.KEYCODE_LEFT_BRACKET import android.view.KeyEvent.KEYCODE_MINUS import android.view.KeyEvent.KEYCODE_RIGHT_BRACKET import android.view.KeyEvent.KEYCODE_TAB import android.view.KeyEvent.META_ALT_ON import android.view.KeyEvent.META_CTRL_ON import android.view.KeyEvent.META_META_ON import android.view.KeyEvent.META_SHIFT_ON import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading @@ -26,8 +35,23 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.testScope import com.android.systemui.res.R import com.android.systemui.testKosmos import com.android.window.flags.Flags import com.android.window.flags.Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT import com.android.window.flags.Flags.FLAG_ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS import com.android.window.flags.Flags.FLAG_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS import com.android.wm.shell.shared.desktopmode.FakeDesktopState import com.google.common.truth.Truth.assertThat import kotlin.Triple import kotlin.collections.flatMap import kotlin.collections.listOf import kotlin.collections.map import kotlin.map import kotlin.sequences.flatMap import kotlin.sequences.map import kotlin.text.flatMap import kotlin.text.map import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -36,8 +60,57 @@ import org.junit.runner.RunWith class MultitaskingShortcutsSourceTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val desktopState = FakeDesktopState() private val source = MultitaskingShortcutsSource(kosmos.mainResources, context, desktopState) private val source = MultitaskingShortcutsSource(kosmos.mainResources, context) private val expectedDesktopShortcuts = listOf( Triple( context.getString(R.string.system_multitasking_desktop_view), META_META_ON or META_CTRL_ON, KEYCODE_DPAD_DOWN, ), Triple( context.getString(R.string.system_multitasking_move_to_next_display), META_META_ON or META_CTRL_ON, KEYCODE_D, ), Triple( context.getString(R.string.system_desktop_mode_snap_left_window), META_META_ON, KEYCODE_LEFT_BRACKET, ), Triple( context.getString(R.string.system_desktop_mode_snap_right_window), META_META_ON, KEYCODE_RIGHT_BRACKET, ), Triple( context.getString(R.string.system_desktop_mode_toggle_maximize_window), META_META_ON, KEYCODE_EQUALS, ), Triple( context.getString(R.string.system_desktop_mode_minimize_window), META_META_ON, KEYCODE_MINUS, ), Triple( context.getString(R.string.system_multiple_desktop_mode_switch_between_desks), META_META_ON or META_CTRL_ON, KEYCODE_LEFT_BRACKET, ), Triple( context.getString(R.string.system_multiple_desktop_mode_switch_between_desks), META_META_ON or META_CTRL_ON, KEYCODE_RIGHT_BRACKET, ), ) @Before fun setup() { desktopState.canEnterDesktopMode = true } @Test fun shortcutGroups_doesNotContainCycleThroughRecentAppsShortcuts() { Loading Loading @@ -65,6 +138,39 @@ class MultitaskingShortcutsSourceTest : SysuiTestCase() { } } @Test @EnableFlags( Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT, Flags.FLAG_ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS, Flags.FLAG_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS, ) fun shortcutGroups_containsDesktopShortcuts() { testScope.runTest { val groups = source.shortcutGroups(TEST_DEVICE_ID) val shortcuts = groups.flatMap { it.items }.map { c -> Triple(c.label, c.modifiers, c.keycode) } assertThat(shortcuts).containsAtLeastElementsIn(expectedDesktopShortcuts) } } @Test @EnableFlags( Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT, Flags.FLAG_ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS, Flags.FLAG_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS, ) fun shortcutGroups_desktopDisabled_doesNotContainDesktopShortcuts() { testScope.runTest { desktopState.canEnterDesktopMode = false val groups = source.shortcutGroups(TEST_DEVICE_ID) val shortcuts = groups.flatMap { it.items }.map { c -> Triple(c.label, c.modifiers, c.keycode) } assertThat(shortcuts).containsNoneIn(expectedDesktopShortcuts) } } private companion object { private const val TEST_DEVICE_ID = 1234 } Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSource.kt +79 −71 Original line number Diff line number Diff line Loading @@ -36,13 +36,16 @@ import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.keyboard.shortcut.data.model.shortcutInfo import com.android.systemui.res.R import com.android.wm.shell.shared.desktopmode.DesktopModeStatus import com.android.wm.shell.shared.desktopmode.DesktopState import javax.inject.Inject class MultitaskingShortcutsSource @Inject constructor(@Main private val resources: Resources, @Application private val context: Context) : KeyboardShortcutGroupsSource { constructor( @Main private val resources: Resources, @Application private val context: Context, private val desktopState: DesktopState, ) : KeyboardShortcutGroupsSource { override suspend fun shortcutGroups(deviceId: Int) = listOf( Loading Loading @@ -74,7 +77,7 @@ constructor(@Main private val resources: Resources, @Application private val con command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_UP) } ) if (DesktopModeStatus.canEnterDesktopMode(context)) { if (desktopState.canEnterDesktopMode) { // Switch to desktop view // - Meta + Ctrl + Down arrow add( Loading @@ -82,7 +85,7 @@ constructor(@Main private val resources: Resources, @Application private val con command(META_META_ON or META_CTRL_ON, KEYCODE_DPAD_DOWN) } ) } if (DesktopExperienceFlags.ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT.isTrue()) { // Move a window to the next display: // - Meta + Ctrl + D Loading @@ -94,21 +97,22 @@ constructor(@Main private val resources: Resources, @Application private val con } ) } if ( DesktopModeStatus.canEnterDesktopMode(context) && DesktopModeFlags.ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS.isTrue ) { if (DesktopModeFlags.ENABLE_TASK_RESIZING_KEYBOARD_SHORTCUTS.isTrue) { // Snap a freeform window to the left // - Meta + Left bracket add( shortcutInfo(resources.getString(R.string.system_desktop_mode_snap_left_window)) { shortcutInfo( resources.getString(R.string.system_desktop_mode_snap_left_window) ) { command(META_META_ON, KEYCODE_LEFT_BRACKET) } ) // Snap a freeform window to the right // - Meta + Right bracket add( shortcutInfo(resources.getString(R.string.system_desktop_mode_snap_right_window)) { shortcutInfo( resources.getString(R.string.system_desktop_mode_snap_right_window) ) { command(META_META_ON, KEYCODE_RIGHT_BRACKET) } ) Loading @@ -124,28 +128,31 @@ constructor(@Main private val resources: Resources, @Application private val con // Minimize a freeform window // - Meta + Minus add( shortcutInfo(resources.getString(R.string.system_desktop_mode_minimize_window)) { shortcutInfo( resources.getString(R.string.system_desktop_mode_minimize_window) ) { command(META_META_ON, KEYCODE_MINUS) } ) } if ( DesktopModeStatus.enableMultipleDesktops(context) && DesktopExperienceFlags.ENABLE_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS.isTrue ) { if (DesktopExperienceFlags.ENABLE_KEYBOARD_SHORTCUTS_TO_SWITCH_DESKS.isTrue) { // Move between desktops // - Meta + Ctrl + [ or ] add( shortcutInfo( resources.getString(R.string.system_multiple_desktop_mode_switch_between_desks) resources.getString( R.string.system_multiple_desktop_mode_switch_between_desks ) ) { command(META_META_ON or META_CTRL_ON, KEYCODE_LEFT_BRACKET) } ) add( shortcutInfo( resources.getString(R.string.system_multiple_desktop_mode_switch_between_desks) resources.getString( R.string.system_multiple_desktop_mode_switch_between_desks ) ) { command(META_META_ON or META_CTRL_ON, KEYCODE_RIGHT_BRACKET) } Loading @@ -153,3 +160,4 @@ constructor(@Main private val resources: Resources, @Application private val con } } } }
packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java +2 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,8 @@ public abstract class SysuiTestCase { android.service.quickaccesswallet.Flags.class, com.android.internal.telephony.flags.Flags.class, com.android.server.notification.Flags.class, com.android.systemui.Flags.class); com.android.systemui.Flags.class, com.android.window.flags.Flags.class); // TODO(b/339471826): Fix Robolectric to execute the @ClassRule correctly @Rule public final SetFlagsRule mSetFlagsRule = Loading
packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt +4 −1 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ import com.android.systemui.plugins.activityStarter import com.android.systemui.settings.displayTracker import com.android.systemui.settings.userTracker import com.android.systemui.statusbar.phone.systemUIDialogFactory import com.android.wm.shell.shared.desktopmode.FakeDesktopState var Kosmos.shortcutHelperAppCategoriesShortcutsSource: KeyboardShortcutGroupsSource by Kosmos.Fixture { AppCategoriesShortcutsSource(windowManager, testDispatcher) } Loading @@ -75,7 +76,7 @@ var Kosmos.shortcutHelperSystemShortcutsSource: KeyboardShortcutGroupsSource by Kosmos.Fixture { SystemShortcutsSource(mainResources, fakeInputManager.inputManager) } var Kosmos.shortcutHelperMultiTaskingShortcutsSource: KeyboardShortcutGroupsSource by Kosmos.Fixture { MultitaskingShortcutsSource(mainResources, applicationContext) } Kosmos.Fixture { MultitaskingShortcutsSource(mainResources, applicationContext, desktopState) } val Kosmos.shortcutHelperStateRepository by Kosmos.Fixture { ShortcutHelperStateRepository(fakeInputManager.inputManager, testDispatcher) } Loading Loading @@ -274,6 +275,8 @@ val Kosmos.shortcutCustomizationViewModelFactory by val Kosmos.fakeLauncherApps by Kosmos.Fixture { FakeLauncherApps() } val Kosmos.desktopState by Kosmos.Fixture { FakeDesktopState() } val Kosmos.userVisibleAppsRepository by Kosmos.Fixture { UserVisibleAppsRepository( Loading