• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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 #include "HardwareProperties.h"
18 
19 namespace android {
20 
21 namespace {
22 
getMaxTouchCount(const InputDeviceContext & context)23 unsigned short getMaxTouchCount(const InputDeviceContext& context) {
24     if (context.hasScanCode(BTN_TOOL_QUINTTAP)) return 5;
25     if (context.hasScanCode(BTN_TOOL_QUADTAP)) return 4;
26     if (context.hasScanCode(BTN_TOOL_TRIPLETAP)) return 3;
27     if (context.hasScanCode(BTN_TOOL_DOUBLETAP)) return 2;
28     if (context.hasScanCode(BTN_TOOL_FINGER)) return 1;
29     return 0;
30 }
31 
32 } // namespace
33 
createHardwareProperties(const InputDeviceContext & context)34 HardwareProperties createHardwareProperties(const InputDeviceContext& context) {
35     HardwareProperties props;
36     RawAbsoluteAxisInfo absMtPositionX;
37     context.getAbsoluteAxisInfo(ABS_MT_POSITION_X, &absMtPositionX);
38     props.left = absMtPositionX.minValue;
39     props.right = absMtPositionX.maxValue;
40     props.res_x = absMtPositionX.resolution;
41 
42     RawAbsoluteAxisInfo absMtPositionY;
43     context.getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &absMtPositionY);
44     props.top = absMtPositionY.minValue;
45     props.bottom = absMtPositionY.maxValue;
46     props.res_y = absMtPositionY.resolution;
47 
48     RawAbsoluteAxisInfo absMtOrientation;
49     context.getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &absMtOrientation);
50     props.orientation_minimum = absMtOrientation.minValue;
51     props.orientation_maximum = absMtOrientation.maxValue;
52 
53     RawAbsoluteAxisInfo absMtSlot;
54     context.getAbsoluteAxisInfo(ABS_MT_SLOT, &absMtSlot);
55     props.max_finger_cnt = absMtSlot.maxValue - absMtSlot.minValue + 1;
56     props.max_touch_cnt = getMaxTouchCount(context);
57 
58     // T5R2 ("Track 5, Report 2") is a feature of some old Synaptics touchpads that could track 5
59     // fingers but only report the coordinates of 2 of them. We don't know of any external touchpads
60     // that did this, so assume false.
61     props.supports_t5r2 = false;
62 
63     props.support_semi_mt = context.hasInputProperty(INPUT_PROP_SEMI_MT);
64     props.is_button_pad = context.hasInputProperty(INPUT_PROP_BUTTONPAD);
65 
66     // Mouse-only properties, which will always be false.
67     props.has_wheel = false;
68     props.wheel_is_hi_res = false;
69 
70     // Linux Kernel haptic touchpad support isn't merged yet, so for now assume that no touchpads
71     // are haptic.
72     props.is_haptic_pad = false;
73 
74     RawAbsoluteAxisInfo absMtPressure;
75     context.getAbsoluteAxisInfo(ABS_MT_PRESSURE, &absMtPressure);
76     props.reports_pressure = absMtPressure.valid;
77     return props;
78 }
79 
80 } // namespace android
81