1 /*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.cts.input
18
19 import android.app.Instrumentation
20 import android.view.Display
21 import android.view.InputDevice.SOURCE_TOUCHSCREEN
22 import com.android.cts.input.UinputTouchDevice.Companion.MT_TOOL_FINGER
23 import com.android.cts.input.UinputTouchDevice.Companion.MT_TOOL_PALM
24
createTouchScreenRegisterCommandnull25 private fun createTouchScreenRegisterCommand(display: Display): UinputRegisterCommand {
26 val configurationItems = listOf(
27 ConfigurationItem("UI_SET_EVBIT", listOf("EV_KEY", "EV_ABS")),
28 ConfigurationItem("UI_SET_KEYBIT", listOf("BTN_TOUCH")),
29 ConfigurationItem(
30 "UI_SET_ABSBIT",
31 listOf(
32 "ABS_MT_SLOT",
33 "ABS_MT_TOUCH_MAJOR",
34 "ABS_MT_POSITION_X",
35 "ABS_MT_POSITION_Y",
36 "ABS_MT_TRACKING_ID",
37 "ABS_MT_TOOL_TYPE"
38 )
39 ),
40 ConfigurationItem("UI_SET_PROPBIT", listOf("INPUT_PROP_DIRECT"))
41 )
42
43 val absInfoItems = mapOf(
44 "ABS_MT_SLOT" to AbsInfo(0, 0, 9, 0, 0, 0),
45 "ABS_MT_TRACKING_ID" to AbsInfo(0, 0, 9, 0, 0, 0),
46 "ABS_MT_TOUCH_MAJOR" to AbsInfo(0, 0, 31, 0, 0, 0),
47 "ABS_MT_POSITION_X" to AbsInfo(0, 0, display.mode.physicalWidth - 1, 0, 0, 0),
48 "ABS_MT_POSITION_Y" to AbsInfo(0, 0, display.mode.physicalHeight - 1, 0, 0, 0),
49 "ABS_MT_TOOL_TYPE" to AbsInfo(0, MT_TOOL_FINGER, MT_TOOL_PALM, 0, 0, 0),
50 )
51
52 return UinputRegisterCommand(
53 id = 1,
54 name = "Test Touch Screen (USB)",
55 vid = 0x18d1,
56 pid = 0xabcd,
57 bus = "usb",
58 port = "usb:1",
59 configuration = configurationItems,
60 absInfo = absInfoItems
61 )
62 }
63
64 /**
65 * A UinputTouchDevice that has the properties of a typical touchscreen. The touchscreen has the
66 * same resolution as the provided display.
67 */
68 class UinputTouchScreen(instrumentation: Instrumentation, display: Display) : UinputTouchDevice(
69 instrumentation,
70 display,
71 createTouchScreenRegisterCommand(display),
72 SOURCE_TOUCHSCREEN,
73 )
74