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
22 import com.android.cts.input.UinputTouchDevice.Companion.MT_TOOL_FINGER
23 import com.android.cts.input.UinputTouchDevice.Companion.MT_TOOL_PALM
24
createTouchPadRegisterCommandnull25 private fun createTouchPadRegisterCommand(): UinputRegisterCommand {
26 val configurationItems = listOf(
27 ConfigurationItem("UI_SET_EVBIT", listOf("EV_KEY", "EV_ABS")),
28 ConfigurationItem(
29 "UI_SET_KEYBIT",
30 listOf(
31 "BTN_LEFT",
32 "BTN_TOOL_FINGER",
33 "BTN_TOOL_QUINTTAP",
34 "BTN_TOUCH",
35 "BTN_TOOL_DOUBLETAP",
36 "BTN_TOOL_TRIPLETAP",
37 "BTN_TOOL_QUADTAP",
38 )
39 ),
40 ConfigurationItem(
41 "UI_SET_ABSBIT",
42 listOf(
43 "ABS_MT_SLOT",
44 "ABS_MT_TOUCH_MAJOR",
45 "ABS_MT_TOUCH_MINOR",
46 "ABS_MT_ORIENTATION",
47 "ABS_MT_POSITION_X",
48 "ABS_MT_POSITION_Y",
49 "ABS_MT_TOOL_TYPE",
50 "ABS_MT_TRACKING_ID",
51 "ABS_MT_PRESSURE",
52 )
53 ),
54 ConfigurationItem("UI_SET_PROPBIT", listOf("INPUT_PROP_POINTER", "INPUT_PROP_BUTTONPAD"))
55 )
56
57 val absInfoItems = mapOf(
58 "ABS_MT_SLOT" to AbsInfo(0, 0, 9, 0, 0, 0),
59 "ABS_MT_TOUCH_MAJOR" to AbsInfo(0, 0, 15, 0, 0, 0),
60 "ABS_MT_TOUCH_MINOR" to AbsInfo(0, 0, 15, 0, 0, 0),
61 "ABS_MT_ORIENTATION" to AbsInfo(0, 0, 1, 0, 0, 0),
62 "ABS_MT_POSITION_X" to AbsInfo(0, 0, 1936, 0, 0, 20),
63 "ABS_MT_POSITION_Y" to AbsInfo(0, 0, 1057, 0, 0, 20),
64 "ABS_MT_TOOL_TYPE" to AbsInfo(0, MT_TOOL_FINGER, MT_TOOL_PALM, 0, 0, 0),
65 "ABS_MT_TRACKING_ID" to AbsInfo(0, 0, 65535, 0, 0, 0),
66 "ABS_MT_PRESSURE" to AbsInfo(0, 0, 255, 0, 0, 0),
67 )
68
69 return UinputRegisterCommand(
70 id = 1,
71 name = "Test Touchpad (USB)",
72 vid = 0x18d1,
73 pid = 0xabcd,
74 bus = "usb",
75 port = "usb:1",
76 configuration = configurationItems,
77 absInfo = absInfoItems
78 )
79 }
80
81 /**
82 * A touch pad that has the a fixed resolution (see AbsInfo for ABS_MT_POSITION_X / Y). Gets
83 * associated with the specific display.
84 */
85 class UinputTouchPad(
86 instrumentation: Instrumentation,
87 display: Display,
88 ) : UinputTouchDevice(
89 instrumentation,
90 display,
91 createTouchPadRegisterCommand(),
92 InputDevice.SOURCE_TOUCHPAD or InputDevice.SOURCE_MOUSE,
93 )
94