Fixing fast_scroll_with_fling test to be launched only on devices with rotary

Fixes: 380050840
Fixes: 379832075
Test: RotaryTest.kt
Change-Id: Ia98cf600394f3d34e8e4634c5fc8e05e545b1d1d
diff --git a/wear/compose/compose-foundation/src/androidTest/kotlin/androidx/wear/compose/foundation/rotary/RotaryTest.kt b/wear/compose/compose-foundation/src/androidTest/kotlin/androidx/wear/compose/foundation/rotary/RotaryTest.kt
index c5d60a3..62bb4e0 100644
--- a/wear/compose/compose-foundation/src/androidTest/kotlin/androidx/wear/compose/foundation/rotary/RotaryTest.kt
+++ b/wear/compose/compose-foundation/src/androidTest/kotlin/androidx/wear/compose/foundation/rotary/RotaryTest.kt
@@ -23,6 +23,8 @@
 import android.content.Context
 import android.hardware.input.InputManager
 import android.view.InputDevice.SOURCE_ROTARY_ENCODER
+import android.view.MotionEvent
+import android.view.ViewConfiguration
 import androidx.compose.foundation.ExperimentalFoundationApi
 import androidx.compose.foundation.LocalOverscrollFactory
 import androidx.compose.foundation.layout.height
@@ -43,6 +45,7 @@
 import androidx.compose.ui.test.performRotaryScrollInput
 import androidx.compose.ui.unit.Dp
 import androidx.compose.ui.unit.dp
+import androidx.core.view.ViewConfigurationCompat
 import androidx.test.core.app.ApplicationProvider
 import com.google.common.truth.Truth
 import org.junit.Assume
@@ -294,15 +297,24 @@
     }
 
     private fun hasRotaryInputDevice(): Boolean {
-        with(
-            ApplicationProvider.getApplicationContext<Context>()
-                .getSystemService(Context.INPUT_SERVICE) as InputManager
-        ) {
+        val context = ApplicationProvider.getApplicationContext<Context>()
+        val viewConfiguration = ViewConfiguration.get(context)
+        with(context.getSystemService(Context.INPUT_SERVICE) as InputManager) {
             inputDeviceIds.forEach { deviceId ->
+                // To validate that we have a valid rotary device we need to:
+                // 1) check that we have a rotary device.
+                // 2) check that getScaledMaximumFlingVelocity method returns us a valid fling speed
                 if (
                     getInputDevice(deviceId)?.motionRanges?.find {
                         it.source == SOURCE_ROTARY_ENCODER
-                    } != null
+                    } != null &&
+                        ViewConfigurationCompat.getScaledMaximumFlingVelocity(
+                            context,
+                            viewConfiguration,
+                            deviceId,
+                            MotionEvent.AXIS_SCROLL,
+                            SOURCE_ROTARY_ENCODER
+                        ) != Integer.MIN_VALUE
                 )
                     return true
             }