Move UinputTouchDevice into cts-input-lib
... so that it can be reused in other test binaries.
Bug: 275726706
Test: Build
Change-Id: I6462a329b421cf667926595498feb4594bf625e1
diff --git a/libs/input/Android.bp b/libs/input/Android.bp
index 71cf5da..b23441f 100644
--- a/libs/input/Android.bp
+++ b/libs/input/Android.bp
@@ -19,8 +19,15 @@
java_library_static {
name: "cts-input-lib",
sdk_version: "test_current",
- srcs: ["src/**/*.java"],
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
+ kotlincflags: [
+ "-Werror",
+ ],
static_libs: [
"androidx.test.rules",
+ "compatibility-device-util-axt",
],
}
diff --git a/tests/input/src/android/input/cts/UinputTouchDevice.kt b/libs/input/src/com/android/cts/input/UinputTouchDevice.kt
similarity index 92%
rename from tests/input/src/android/input/cts/UinputTouchDevice.kt
rename to libs/input/src/com/android/cts/input/UinputTouchDevice.kt
index 709c922..3eb49d9 100644
--- a/tests/input/src/android/input/cts/UinputTouchDevice.kt
+++ b/libs/input/src/com/android/cts/input/UinputTouchDevice.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.input.cts
+package com.android.cts.input
import android.app.Instrumentation
import android.content.Context
@@ -22,18 +22,20 @@
import android.hardware.input.InputManager
import android.util.Size
import android.view.Display
-import android.view.InputDevice
import com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity
-import com.android.cts.input.UinputDevice
import org.json.JSONArray
import org.json.JSONObject
+/**
+ * Helper class for configuring and interacting with a [UinputDevice] that uses the evdev
+ * multitouch protocol.
+ */
class UinputTouchDevice(
instrumentation: Instrumentation,
display: Display,
size: Size,
- private val rawResource: Int = R.raw.test_touchscreen_register,
- private val source: Int = InputDevice.SOURCE_TOUCHSCREEN,
+ private val rawResource: Int,
+ private val source: Int,
) :
AutoCloseable {
@@ -104,10 +106,10 @@
for (i in 0 until absInfo.length()) {
val item = absInfo.getJSONObject(i)
if (item.get("code") == ABS_MT_POSITION_X) {
- item.getJSONObject("info").put("maximum", size.getWidth() - 1)
+ item.getJSONObject("info").put("maximum", size.width - 1)
}
if (item.get("code") == ABS_MT_POSITION_Y) {
- item.getJSONObject("info").put("maximum", size.getHeight() - 1)
+ item.getJSONObject("info").put("maximum", size.height - 1)
}
}
diff --git a/tests/input/src/android/input/cts/DrawingTabletTest.kt b/tests/input/src/android/input/cts/DrawingTabletTest.kt
index e014ddd..addcbae 100644
--- a/tests/input/src/android/input/cts/DrawingTabletTest.kt
+++ b/tests/input/src/android/input/cts/DrawingTabletTest.kt
@@ -30,6 +30,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry
+import com.android.cts.input.UinputTouchDevice
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
diff --git a/tests/input/src/android/input/cts/StylusButtonInputEventTest.kt b/tests/input/src/android/input/cts/StylusButtonInputEventTest.kt
index bc0c7cd..8599a86 100644
--- a/tests/input/src/android/input/cts/StylusButtonInputEventTest.kt
+++ b/tests/input/src/android/input/cts/StylusButtonInputEventTest.kt
@@ -21,9 +21,9 @@
import android.input.cts.VirtualDisplayActivityScenarioRule.Companion.HEIGHT
import android.input.cts.VirtualDisplayActivityScenarioRule.Companion.WIDTH
import android.util.Size
-import android.view.InputDevice
import android.view.InputDevice.SOURCE_KEYBOARD
import android.view.InputDevice.SOURCE_STYLUS
+import android.view.InputDevice.SOURCE_TOUCHSCREEN
import android.view.KeyEvent
import android.view.MotionEvent
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -32,6 +32,7 @@
import com.android.compatibility.common.util.PollingCheck
import com.android.compatibility.common.util.SystemUtil
import com.android.cts.input.UinputDevice
+import com.android.cts.input.UinputTouchDevice
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
@@ -104,21 +105,20 @@
instrumentation,
R.raw.test_bluetooth_stylus_register,
SOURCE_KEYBOARD or SOURCE_STYLUS
- )
- .use { bluetoothStylus ->
- for (button in LINUX_TO_ANDROID_KEYCODE_MAP.entries.iterator()) {
- bluetoothStylus.injectEvents(
+ ).use { bluetoothStylus ->
+ for (button in LINUX_TO_ANDROID_KEYCODE_MAP.entries.iterator()) {
+ bluetoothStylus.injectEvents(
makeEvents(EV_KEY, button.key, KEY_DOWN, EV_SYN, SYN_REPORT, 0)
- )
- // The stylus button is expected to be sent to the status bar as a system key on
- // the down press.
- assertReceivedSystemKey(button.value)
+ )
+ // The stylus button is expected to be sent to the status bar as a system key on
+ // the down press.
+ assertReceivedSystemKey(button.value)
- bluetoothStylus.injectEvents(
+ bluetoothStylus.injectEvents(
makeEvents(EV_KEY, button.key, KEY_UP, EV_SYN, SYN_REPORT, 0)
- )
- }
+ )
}
+ }
}
@Test
@@ -128,21 +128,20 @@
instrumentation,
R.raw.test_bluetooth_stylus_register,
SOURCE_KEYBOARD or SOURCE_STYLUS
- )
- .use { bluetoothStylus ->
- for (button in LINUX_TO_ANDROID_KEYCODE_MAP.entries.iterator()) {
- bluetoothStylus.injectEvents(
+ ).use { bluetoothStylus ->
+ for (button in LINUX_TO_ANDROID_KEYCODE_MAP.entries.iterator()) {
+ bluetoothStylus.injectEvents(
makeEvents(EV_KEY, button.key, KEY_DOWN, EV_SYN, SYN_REPORT, 0)
- )
- bluetoothStylus.injectEvents(
+ )
+ bluetoothStylus.injectEvents(
makeEvents(EV_KEY, button.key, KEY_UP, EV_SYN, SYN_REPORT, 0)
- )
+ )
- // Stylus buttons should not be sent to the status bar as a system key when
- // stylus buttons are disabled.
- assertNoSystemKey()
- }
+ // Stylus buttons should not be sent to the status bar as a system key when
+ // stylus buttons are disabled.
+ assertNoSystemKey()
}
+ }
}
@Test
@@ -152,52 +151,52 @@
instrumentation,
virtualDisplayRule.virtualDisplay.display,
Size(WIDTH, HEIGHT),
- R.raw.test_capacitive_stylus_register
- )
- .use { uinputStylus ->
- val pointer = Point(100, 100)
- for (button in LINUX_KEYCODE_TO_MOTIONEVENT_BUTTON.entries.iterator()) {
- pointer.offset(1, 1)
+ R.raw.test_capacitive_stylus_register,
+ SOURCE_TOUCHSCREEN,
+ ).use { uinputStylus ->
+ val pointer = Point(100, 100)
+ for (button in LINUX_KEYCODE_TO_MOTIONEVENT_BUTTON.entries.iterator()) {
+ pointer.offset(1, 1)
- uinputStylus.sendBtnTouch(true)
- uinputStylus.sendBtn(button.key, true)
- uinputStylus.sendDown(0, pointer, UinputTouchDevice.MT_TOOL_PEN)
+ uinputStylus.sendBtnTouch(true)
+ uinputStylus.sendBtn(button.key, true)
+ uinputStylus.sendDown(0, pointer, UinputTouchDevice.MT_TOOL_PEN)
- assertNextMotionEventEquals(
+ assertNextMotionEventEquals(
MotionEvent.ACTION_DOWN,
MotionEvent.TOOL_TYPE_STYLUS,
button.value,
0,
- InputDevice.SOURCE_STYLUS,
- )
- assertNextMotionEventEquals(
+ SOURCE_STYLUS,
+ )
+ assertNextMotionEventEquals(
MotionEvent.ACTION_BUTTON_PRESS,
MotionEvent.TOOL_TYPE_STYLUS,
button.value,
button.value,
- InputDevice.SOURCE_STYLUS,
- )
+ SOURCE_STYLUS,
+ )
- uinputStylus.sendBtnTouch(false)
- uinputStylus.sendBtn(button.key, false)
- uinputStylus.sendUp(0)
+ uinputStylus.sendBtnTouch(false)
+ uinputStylus.sendBtn(button.key, false)
+ uinputStylus.sendUp(0)
- assertNextMotionEventEquals(
+ assertNextMotionEventEquals(
MotionEvent.ACTION_BUTTON_RELEASE,
MotionEvent.TOOL_TYPE_STYLUS,
0,
button.value,
- InputDevice.SOURCE_STYLUS,
- )
- assertNextMotionEventEquals(
+ SOURCE_STYLUS,
+ )
+ assertNextMotionEventEquals(
MotionEvent.ACTION_UP,
MotionEvent.TOOL_TYPE_STYLUS,
0,
0,
- InputDevice.SOURCE_STYLUS,
- )
- }
+ SOURCE_STYLUS,
+ )
}
+ }
}
@Test
@@ -207,43 +206,43 @@
instrumentation,
virtualDisplayRule.virtualDisplay.display,
Size(WIDTH, HEIGHT),
- R.raw.test_capacitive_stylus_register
- )
- .use { uinputStylus ->
- val pointer = Point(100, 100)
- for (button in LINUX_KEYCODE_TO_MOTIONEVENT_BUTTON.entries.iterator()) {
- pointer.offset(1, 1)
+ R.raw.test_capacitive_stylus_register,
+ SOURCE_TOUCHSCREEN,
+ ).use { uinputStylus ->
+ val pointer = Point(100, 100)
+ for (button in LINUX_KEYCODE_TO_MOTIONEVENT_BUTTON.entries.iterator()) {
+ pointer.offset(1, 1)
- uinputStylus.sendBtnTouch(true)
- uinputStylus.sendBtn(button.key, true)
- uinputStylus.sendDown(0, pointer, UinputTouchDevice.MT_TOOL_PEN)
+ uinputStylus.sendBtnTouch(true)
+ uinputStylus.sendBtn(button.key, true)
+ uinputStylus.sendDown(0, pointer, UinputTouchDevice.MT_TOOL_PEN)
- assertNextMotionEventEquals(
+ assertNextMotionEventEquals(
MotionEvent.ACTION_DOWN,
MotionEvent.TOOL_TYPE_STYLUS,
0,
0,
- InputDevice.SOURCE_STYLUS,
- )
+ SOURCE_STYLUS,
+ )
- uinputStylus.sendBtnTouch(false)
- uinputStylus.sendBtn(button.key, false)
- uinputStylus.sendUp(0)
+ uinputStylus.sendBtnTouch(false)
+ uinputStylus.sendBtn(button.key, false)
+ uinputStylus.sendUp(0)
- assertNextMotionEventEquals(
+ assertNextMotionEventEquals(
MotionEvent.ACTION_UP,
MotionEvent.TOOL_TYPE_STYLUS,
0,
0,
- InputDevice.SOURCE_STYLUS,
- )
- }
+ SOURCE_STYLUS,
+ )
}
+ }
}
private fun assertReceivedSystemKey(keycode: Int) {
SystemUtil.runWithShellPermissionIdentity {
- PollingCheck.waitFor { statusBarManager.getLastSystemKey() == keycode }
+ PollingCheck.waitFor { statusBarManager.lastSystemKey == keycode }
}
}
@@ -251,7 +250,7 @@
// Wait for the system to process the event.
Thread.sleep(100)
SystemUtil.runWithShellPermissionIdentity {
- assertEquals(INITIAL_SYSTEM_KEY, statusBarManager.getLastSystemKey())
+ assertEquals(INITIAL_SYSTEM_KEY, statusBarManager.lastSystemKey)
}
}
diff --git a/tests/input/src/android/input/cts/TouchScreenTest.kt b/tests/input/src/android/input/cts/TouchScreenTest.kt
index c121ee10..0471564 100644
--- a/tests/input/src/android/input/cts/TouchScreenTest.kt
+++ b/tests/input/src/android/input/cts/TouchScreenTest.kt
@@ -26,9 +26,11 @@
import android.input.cts.VirtualDisplayActivityScenarioRule.Companion.ORIENTATION_90
import android.input.cts.VirtualDisplayActivityScenarioRule.Companion.WIDTH
import android.util.Size
+import android.view.InputDevice
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry
+import com.android.cts.input.UinputTouchDevice
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
@@ -50,9 +52,11 @@
@Before
fun setUp() {
touchScreen = UinputTouchDevice(
- instrumentation,
- virtualDisplayRule.virtualDisplay.display,
- Size(WIDTH, HEIGHT)
+ instrumentation,
+ virtualDisplayRule.virtualDisplay.display,
+ Size(WIDTH, HEIGHT),
+ R.raw.test_touchscreen_register,
+ InputDevice.SOURCE_TOUCHSCREEN,
)
verifier = EventVerifier(virtualDisplayRule.activity::getInputEvent)
}