Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomInputGesturesRepositoryTest.kt +52 −4 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.systemui.keyboard.shortcut.data.repository import android.content.Context import android.content.Context.INPUT_SERVICE import android.content.Intent import android.hardware.input.InputGestureData import android.hardware.input.InputManager import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS import android.hardware.input.fakeInputManager import android.platform.test.annotations.EnableFlags Loading @@ -27,9 +29,12 @@ import androidx.test.filters.SmallTest import com.android.hardware.input.Flags.FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES import com.android.hardware.input.Flags.FLAG_USE_KEY_GESTURE_EVENT_HANDLER import com.android.systemui.SysuiTestCase import com.android.systemui.broadcast.broadcastDispatcher import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.customInputGesturesRepository import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsInputGestureData import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.goHomeInputGestureData import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.testScope import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.userTracker Loading @@ -48,18 +53,41 @@ import org.mockito.kotlin.whenever @EnableFlags(FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES, FLAG_USE_KEY_GESTURE_EVENT_HANDLER) class CustomInputGesturesRepositoryTest : SysuiTestCase() { private val mockUserContext: Context = mock() private val primaryUserContext: Context = mock() private val secondaryUserContext: Context = mock() private var activeUserContext: Context = primaryUserContext private val kosmos = testKosmos().also { it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { activeUserContext }) } private val inputManager = kosmos.fakeInputManager.inputManager private val broadcastDispatcher = kosmos.broadcastDispatcher private val inputManagerForSecondaryUser: InputManager = mock() private val testScope = kosmos.testScope private val testHelper = kosmos.shortcutHelperTestHelper private val customInputGesturesRepository = kosmos.customInputGesturesRepository @Before fun setup() { whenever(mockUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) activeUserContext = primaryUserContext whenever(primaryUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) whenever(secondaryUserContext.getSystemService(INPUT_SERVICE)) .thenReturn(inputManagerForSecondaryUser) } @Test fun customInputGestures_emitsNewUsersInputGesturesWhenUserIsSwitch() { testScope.runTest { setCustomInputGesturesForPrimaryUser(allAppsInputGestureData) setCustomInputGesturesForSecondaryUser(goHomeInputGestureData) val inputGestures by collectLastValue(customInputGesturesRepository.customInputGestures) assertThat(inputGestures).containsExactly(allAppsInputGestureData) switchToSecondaryUser() assertThat(inputGestures).containsExactly(goHomeInputGestureData) } } @Test Loading Loading @@ -115,4 +143,24 @@ class CustomInputGesturesRepositoryTest : SysuiTestCase() { } } private fun setCustomInputGesturesForPrimaryUser(vararg inputGesture: InputGestureData) { whenever( inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) ).thenReturn(inputGesture.toList()) } private fun setCustomInputGesturesForSecondaryUser(vararg inputGesture: InputGestureData) { whenever( inputManagerForSecondaryUser.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) ).thenReturn(inputGesture.toList()) } private fun switchToSecondaryUser() { activeUserContext = secondaryUserContext broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_USER_SWITCHED) ) } } No newline at end of file packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperCoreStartable.kt +6 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import com.android.systemui.CoreStartable import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.keyboard.shortcut.data.repository.CustomInputGesturesRepository import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository import com.android.systemui.plugins.ActivityStarter import com.android.systemui.statusbar.CommandQueue Loading @@ -41,6 +42,7 @@ constructor( private val stateRepository: ShortcutHelperStateRepository, private val activityStarter: ActivityStarter, @Background private val backgroundScope: CoroutineScope, private val customInputGesturesRepository: CustomInputGesturesRepository ) : CoreStartable { override fun start() { registerBroadcastReceiver( Loading @@ -55,6 +57,10 @@ constructor( action = Intent.ACTION_CLOSE_SYSTEM_DIALOGS, onReceive = { stateRepository.hide() }, ) registerBroadcastReceiver( action = Intent.ACTION_USER_SWITCHED, onReceive = { customInputGesturesRepository.refreshCustomInputGestures() }, ) commandQueue.addCallback( object : CommandQueue.Callbacks { override fun dismissKeyboardShortcutsMenu() { Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/CustomInputGesturesRepository.kt +3 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_ERROR_RES import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS import android.hardware.input.InputSettings import android.util.Log import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult.ERROR_OTHER Loading @@ -37,6 +38,7 @@ import kotlinx.coroutines.withContext import javax.inject.Inject import kotlin.coroutines.CoroutineContext @SysUISingleton class CustomInputGesturesRepository @Inject constructor(private val userTracker: UserTracker, Loading @@ -56,7 +58,7 @@ constructor(private val userTracker: UserTracker, val customInputGestures = _customInputGesture.onStart { refreshCustomInputGestures() } private fun refreshCustomInputGestures() { fun refreshCustomInputGestures() { setCustomInputGestures(inputGestures = retrieveCustomInputGestures()) } Loading packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt +1 −0 Original line number Diff line number Diff line Loading @@ -154,6 +154,7 @@ val Kosmos.shortcutHelperCoreStartable by shortcutHelperStateRepository, activityStarter, testScope, customInputGesturesRepository ) } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomInputGesturesRepositoryTest.kt +52 −4 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.systemui.keyboard.shortcut.data.repository import android.content.Context import android.content.Context.INPUT_SERVICE import android.content.Intent import android.hardware.input.InputGestureData import android.hardware.input.InputManager import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS import android.hardware.input.fakeInputManager import android.platform.test.annotations.EnableFlags Loading @@ -27,9 +29,12 @@ import androidx.test.filters.SmallTest import com.android.hardware.input.Flags.FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES import com.android.hardware.input.Flags.FLAG_USE_KEY_GESTURE_EVENT_HANDLER import com.android.systemui.SysuiTestCase import com.android.systemui.broadcast.broadcastDispatcher import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.customInputGesturesRepository import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsInputGestureData import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.goHomeInputGestureData import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.testScope import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.userTracker Loading @@ -48,18 +53,41 @@ import org.mockito.kotlin.whenever @EnableFlags(FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES, FLAG_USE_KEY_GESTURE_EVENT_HANDLER) class CustomInputGesturesRepositoryTest : SysuiTestCase() { private val mockUserContext: Context = mock() private val primaryUserContext: Context = mock() private val secondaryUserContext: Context = mock() private var activeUserContext: Context = primaryUserContext private val kosmos = testKosmos().also { it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { activeUserContext }) } private val inputManager = kosmos.fakeInputManager.inputManager private val broadcastDispatcher = kosmos.broadcastDispatcher private val inputManagerForSecondaryUser: InputManager = mock() private val testScope = kosmos.testScope private val testHelper = kosmos.shortcutHelperTestHelper private val customInputGesturesRepository = kosmos.customInputGesturesRepository @Before fun setup() { whenever(mockUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) activeUserContext = primaryUserContext whenever(primaryUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) whenever(secondaryUserContext.getSystemService(INPUT_SERVICE)) .thenReturn(inputManagerForSecondaryUser) } @Test fun customInputGestures_emitsNewUsersInputGesturesWhenUserIsSwitch() { testScope.runTest { setCustomInputGesturesForPrimaryUser(allAppsInputGestureData) setCustomInputGesturesForSecondaryUser(goHomeInputGestureData) val inputGestures by collectLastValue(customInputGesturesRepository.customInputGestures) assertThat(inputGestures).containsExactly(allAppsInputGestureData) switchToSecondaryUser() assertThat(inputGestures).containsExactly(goHomeInputGestureData) } } @Test Loading Loading @@ -115,4 +143,24 @@ class CustomInputGesturesRepositoryTest : SysuiTestCase() { } } private fun setCustomInputGesturesForPrimaryUser(vararg inputGesture: InputGestureData) { whenever( inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) ).thenReturn(inputGesture.toList()) } private fun setCustomInputGesturesForSecondaryUser(vararg inputGesture: InputGestureData) { whenever( inputManagerForSecondaryUser.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) ).thenReturn(inputGesture.toList()) } private fun switchToSecondaryUser() { activeUserContext = secondaryUserContext broadcastDispatcher.sendIntentToMatchingReceiversOnly( context, Intent(Intent.ACTION_USER_SWITCHED) ) } } No newline at end of file
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperCoreStartable.kt +6 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import com.android.systemui.CoreStartable import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.keyboard.shortcut.data.repository.CustomInputGesturesRepository import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository import com.android.systemui.plugins.ActivityStarter import com.android.systemui.statusbar.CommandQueue Loading @@ -41,6 +42,7 @@ constructor( private val stateRepository: ShortcutHelperStateRepository, private val activityStarter: ActivityStarter, @Background private val backgroundScope: CoroutineScope, private val customInputGesturesRepository: CustomInputGesturesRepository ) : CoreStartable { override fun start() { registerBroadcastReceiver( Loading @@ -55,6 +57,10 @@ constructor( action = Intent.ACTION_CLOSE_SYSTEM_DIALOGS, onReceive = { stateRepository.hide() }, ) registerBroadcastReceiver( action = Intent.ACTION_USER_SWITCHED, onReceive = { customInputGesturesRepository.refreshCustomInputGestures() }, ) commandQueue.addCallback( object : CommandQueue.Callbacks { override fun dismissKeyboardShortcutsMenu() { Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/CustomInputGesturesRepository.kt +3 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_ERROR_RES import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS import android.hardware.input.InputSettings import android.util.Log import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult.ERROR_OTHER Loading @@ -37,6 +38,7 @@ import kotlinx.coroutines.withContext import javax.inject.Inject import kotlin.coroutines.CoroutineContext @SysUISingleton class CustomInputGesturesRepository @Inject constructor(private val userTracker: UserTracker, Loading @@ -56,7 +58,7 @@ constructor(private val userTracker: UserTracker, val customInputGestures = _customInputGesture.onStart { refreshCustomInputGestures() } private fun refreshCustomInputGestures() { fun refreshCustomInputGestures() { setCustomInputGestures(inputGestures = retrieveCustomInputGestures()) } Loading
packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt +1 −0 Original line number Diff line number Diff line Loading @@ -154,6 +154,7 @@ val Kosmos.shortcutHelperCoreStartable by shortcutHelperStateRepository, activityStarter, testScope, customInputGesturesRepository ) } Loading