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
25 /**
26 * Warning! The configuration of the drawing tablet used here is not the best way of emulating an
27 * actual drawing tablet:
28 * - size shouldn't always match the display
29 * - ABS_MT_ axes typically aren't used by these devices.
30 * TODO(b/341183598): make the configuration match a real device more closely.
31 */
createDrawingTabletRegisterCommandnull32 private fun createDrawingTabletRegisterCommand(display: Display): UinputRegisterCommand {
33 val configurationItems = listOf(
34 ConfigurationItem("UI_SET_EVBIT", listOf("EV_KEY", "EV_ABS")),
35 ConfigurationItem("UI_SET_KEYBIT", listOf("BTN_TOUCH", "BTN_TOOL_PEN")),
36 ConfigurationItem(
37 "UI_SET_ABSBIT",
38 listOf(
39 "ABS_MT_SLOT",
40 "ABS_MT_TOUCH_MAJOR",
41 "ABS_MT_POSITION_X",
42 "ABS_MT_POSITION_Y",
43 "ABS_MT_TRACKING_ID",
44 "ABS_MT_TOOL_TYPE"
45 )
46 ),
47 ConfigurationItem("UI_SET_PROPBIT", listOf("INPUT_PROP_POINTER"))
48 )
49
50 val absInfoItems = mapOf(
51 "ABS_MT_SLOT" to AbsInfo(0, 0, 9, 0, 0, 0),
52 "ABS_MT_TRACKING_ID" to AbsInfo(0, 0, 9, 0, 0, 0),
53 "ABS_MT_TOUCH_MAJOR" to AbsInfo(0, 0, 31, 0, 0, 0),
54 "ABS_MT_POSITION_X" to AbsInfo(0, 0, display.mode.physicalWidth - 1, 0, 0, 0),
55 "ABS_MT_POSITION_Y" to AbsInfo(0, 0, display.mode.physicalHeight - 1, 0, 0, 0),
56 "ABS_MT_TOOL_TYPE" to AbsInfo(0, MT_TOOL_FINGER, MT_TOOL_PALM, 0, 0, 0),
57 )
58
59 return UinputRegisterCommand(
60 id = 1,
61 name = "Test Drawing Tablet (USB)",
62 vid = 0x18d1,
63 pid = 0xabcd,
64 bus = "usb",
65 port = "usb:1",
66 configuration = configurationItems,
67 absInfo = absInfoItems
68 )
69 }
70
71 /**
72 * A drawing tablet that has the same resolution as the provided targeted display.
73 */
74 class UinputDrawingTablet(instrumentation: Instrumentation, display: Display) : UinputTouchDevice(
75 instrumentation,
76 display,
77 createDrawingTabletRegisterCommand(display),
78 InputDevice.SOURCE_MOUSE or InputDevice.SOURCE_STYLUS,
79 MT_TOOL_PEN,
80 )
81