Loading packages/SystemUI/multivalentTests/src/com/android/systemui/cursorposition/data/repository/MultiDisplayCursorPositionRepositoryTest.kt +25 −11 Original line number Diff line number Diff line Loading @@ -83,31 +83,34 @@ class MultiDisplayCursorPositionRepositoryTest(private val cursorEventSource: In @Before fun setup() { testableLooper = TestableLooper.get(this) val testHandler = Handler(testableLooper.looper) whenever(inputMonitor.getInputReceiver(any(), any(), any())).thenReturn(inputReceiver) displayLifecycleManager.displayIds.value = setOf(DEFAULT_DISPLAY, DISPLAY_2) underTest = createMultiDisplayCursorPositionRepository { _: String, _: Int -> inputMonitor } } private fun createMultiDisplayCursorPositionRepository( inputMonitorBuilder: InputMonitorBuilder ): MultiDisplayCursorPositionRepository { val cursorPerDisplayRepository = PerDisplayInstanceRepositoryImpl( debugName = "testCursorPositionPerDisplayInstanceRepository", instanceProvider = TestCursorPositionRepositoryInstanceProvider( testHandler, Handler(testableLooper.looper), { channel -> listener = defaultInputEventListenerBuilder.build(channel) listener }, ) { _: String, _: Int -> inputMonitor }, inputMonitorBuilder, ), displayLifecycleManager, kosmos.backgroundScope, displayRepository, kosmos.perDisplayDumpHelper, ) underTest = MultiDisplayCursorPositionRepositoryImpl( return MultiDisplayCursorPositionRepositoryImpl( displayRepository, backgroundScope = kosmos.backgroundScope, cursorPerDisplayRepository, Loading Loading @@ -152,6 +155,17 @@ class MultiDisplayCursorPositionRepositoryTest(private val cursorEventSource: In verify(inputReceiver).dispose() } @Test fun notThrowExceptionFromInputMonitorBuilder() { val inputMonitorBuilder = InputMonitorBuilder { _: String, _: Int -> throw IllegalArgumentException() } underTest = createMultiDisplayCursorPositionRepository(inputMonitorBuilder) setUpAndRunTest { addDisplay(id = DISPLAY_2, type = TYPE_EXTERNAL) } // No exception is thrown, otherwise it would fail the test } private fun setUpAndRunTest(block: suspend () -> Unit) = kosmos.runTest { // Add default display before creating cursor repository Loading packages/SystemUI/src/com/android/systemui/cursorposition/data/repository/SingleDisplayCursorPositionRepository.kt +5 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.cursorposition.data.repository import android.os.Handler import android.os.Looper import android.util.Log import android.view.Choreographer import android.view.InputDevice.SOURCE_MOUSE import android.view.InputDevice.SOURCE_TOUCHPAD Loading @@ -40,6 +41,7 @@ import kotlinx.coroutines.channels.ProducerScope import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOn /** Repository for cursor position in single display. */ Loading Loading @@ -90,6 +92,9 @@ constructor( // "backgroundDispatcher" which does not have a looper) and input receiver could use // its background looper and choreographer .flowOn(backgroundHandler.asCoroutineDispatcher()) .catch { exception -> Log.e(TAG, "Error creating input monitor for display $displayId", exception) } override val cursorPositions: Flow<CursorPosition> = createInputMonitorCallbackFlow(displayId) Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/cursorposition/data/repository/MultiDisplayCursorPositionRepositoryTest.kt +25 −11 Original line number Diff line number Diff line Loading @@ -83,31 +83,34 @@ class MultiDisplayCursorPositionRepositoryTest(private val cursorEventSource: In @Before fun setup() { testableLooper = TestableLooper.get(this) val testHandler = Handler(testableLooper.looper) whenever(inputMonitor.getInputReceiver(any(), any(), any())).thenReturn(inputReceiver) displayLifecycleManager.displayIds.value = setOf(DEFAULT_DISPLAY, DISPLAY_2) underTest = createMultiDisplayCursorPositionRepository { _: String, _: Int -> inputMonitor } } private fun createMultiDisplayCursorPositionRepository( inputMonitorBuilder: InputMonitorBuilder ): MultiDisplayCursorPositionRepository { val cursorPerDisplayRepository = PerDisplayInstanceRepositoryImpl( debugName = "testCursorPositionPerDisplayInstanceRepository", instanceProvider = TestCursorPositionRepositoryInstanceProvider( testHandler, Handler(testableLooper.looper), { channel -> listener = defaultInputEventListenerBuilder.build(channel) listener }, ) { _: String, _: Int -> inputMonitor }, inputMonitorBuilder, ), displayLifecycleManager, kosmos.backgroundScope, displayRepository, kosmos.perDisplayDumpHelper, ) underTest = MultiDisplayCursorPositionRepositoryImpl( return MultiDisplayCursorPositionRepositoryImpl( displayRepository, backgroundScope = kosmos.backgroundScope, cursorPerDisplayRepository, Loading Loading @@ -152,6 +155,17 @@ class MultiDisplayCursorPositionRepositoryTest(private val cursorEventSource: In verify(inputReceiver).dispose() } @Test fun notThrowExceptionFromInputMonitorBuilder() { val inputMonitorBuilder = InputMonitorBuilder { _: String, _: Int -> throw IllegalArgumentException() } underTest = createMultiDisplayCursorPositionRepository(inputMonitorBuilder) setUpAndRunTest { addDisplay(id = DISPLAY_2, type = TYPE_EXTERNAL) } // No exception is thrown, otherwise it would fail the test } private fun setUpAndRunTest(block: suspend () -> Unit) = kosmos.runTest { // Add default display before creating cursor repository Loading
packages/SystemUI/src/com/android/systemui/cursorposition/data/repository/SingleDisplayCursorPositionRepository.kt +5 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.cursorposition.data.repository import android.os.Handler import android.os.Looper import android.util.Log import android.view.Choreographer import android.view.InputDevice.SOURCE_MOUSE import android.view.InputDevice.SOURCE_TOUCHPAD Loading @@ -40,6 +41,7 @@ import kotlinx.coroutines.channels.ProducerScope import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOn /** Repository for cursor position in single display. */ Loading Loading @@ -90,6 +92,9 @@ constructor( // "backgroundDispatcher" which does not have a looper) and input receiver could use // its background looper and choreographer .flowOn(backgroundHandler.asCoroutineDispatcher()) .catch { exception -> Log.e(TAG, "Error creating input monitor for display $displayId", exception) } override val cursorPositions: Flow<CursorPosition> = createInputMonitorCallbackFlow(displayId) Loading