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_STYLUS
22 import android.view.InputDevice.SOURCE_TOUCHSCREEN
23 import com.android.cts.input.UinputTouchDevice.Companion.MT_TOOL_FINGER
24 import com.android.cts.input.UinputTouchDevice.Companion.MT_TOOL_PALM
25
createStylusRegisterCommandnull26 private fun createStylusRegisterCommand(display: Display): UinputRegisterCommand {
27 val configurationItems = listOf(
28 ConfigurationItem("UI_SET_EVBIT", listOf("EV_KEY", "EV_ABS")),
29 ConfigurationItem(
30 "UI_SET_KEYBIT",
31 listOf("BTN_TOUCH", "BTN_TOOL_PEN", "BTN_STYLUS", "BTN_STYLUS2")
32 ),
33 ConfigurationItem(
34 "UI_SET_ABSBIT",
35 listOf(
36 "ABS_MT_SLOT",
37 "ABS_MT_TOUCH_MAJOR",
38 "ABS_MT_POSITION_X",
39 "ABS_MT_POSITION_Y",
40 "ABS_MT_PRESSURE",
41 "ABS_MT_TRACKING_ID",
42 "ABS_MT_TOOL_TYPE"
43 )
44 ),
45 ConfigurationItem("UI_SET_PROPBIT", listOf("INPUT_PROP_DIRECT"))
46 )
47
48 val absInfoItems = mapOf(
49 "ABS_MT_SLOT" to AbsInfo(0, 0, 9, 0, 0, 0),
50 "ABS_MT_TRACKING_ID" to AbsInfo(0, 0, 9, 0, 0, 0),
51 "ABS_MT_TOUCH_MAJOR" to AbsInfo(0, 0, 31, 0, 0, 0),
52 "ABS_MT_POSITION_X" to AbsInfo(0, 0, display.mode.physicalWidth - 1, 0, 0, 0),
53 "ABS_MT_POSITION_Y" to AbsInfo(0, 0, display.mode.physicalHeight - 1, 0, 0, 0),
54 "ABS_MT_PRESSURE" to AbsInfo(0, 0, 255, 0, 0, 0),
55 "ABS_MT_TOOL_TYPE" to AbsInfo(0, MT_TOOL_FINGER, MT_TOOL_PALM, 0, 0, 0),
56 )
57
58 return UinputRegisterCommand(
59 id = 1,
60 name = "Test Stylus (USB)",
61 vid = 0x18d1,
62 pid = 0xabce,
63 bus = "usb",
64 port = "usb:1",
65 configuration = configurationItems,
66 absInfo = absInfoItems
67 )
68 }
69
70 /**
71 * A UinputTouchDevice that has the properties of a typical touchscreen. The touchscreen has the
72 * same resolution as the provided display.
73 */
74 class UinputStylus (instrumentation: Instrumentation, display: Display) : UinputTouchDevice(
75 instrumentation,
76 display,
77 createStylusRegisterCommand(display),
78 SOURCE_STYLUS or SOURCE_TOUCHSCREEN,
79 )
80