1 /*
2  * Copyright (C) 2015 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 "InputMocks.h"
18 
19 namespace android {
20 
hasKeyInRange(int32_t startKey,int32_t endKey) const21 bool MockInputDeviceNode::hasKeyInRange(int32_t startKey, int32_t endKey) const {
22     auto iter = mKeys.lower_bound(startKey);
23     if (iter == mKeys.end()) return false;
24     return *iter < endKey;
25 }
26 
27 namespace MockNexus7v2 {
28 
getElanTouchscreen()29 MockInputDeviceNode* getElanTouchscreen() {
30     auto node = new MockInputDeviceNode();
31     node->setPath("/dev/input/event0");
32     node->setName("elan-touchscreen");
33     // Location not set
34     // UniqueId not set
35     node->setBusType(0);
36     node->setVendorId(0);
37     node->setProductId(0);
38     node->setVersion(0);
39     // No keys
40     // No relative axes
41     // TODO: set the AbsoluteAxisInfo pointers
42     node->addAbsAxis(ABS_MT_SLOT, nullptr);
43     node->addAbsAxis(ABS_MT_TOUCH_MAJOR, nullptr);
44     node->addAbsAxis(ABS_MT_POSITION_X, nullptr);
45     node->addAbsAxis(ABS_MT_POSITION_Y, nullptr);
46     node->addAbsAxis(ABS_MT_TRACKING_ID, nullptr);
47     node->addAbsAxis(ABS_MT_PRESSURE, nullptr);
48     // No switches
49     // No forcefeedback
50     node->addInputProperty(INPUT_PROP_DIRECT);
51     return node;
52 }
53 
getLidInput()54 MockInputDeviceNode* getLidInput() {
55     auto node = new MockInputDeviceNode();
56     node->setPath("/dev/input/event1");
57     node->setName("lid_input");
58     node->setLocation("/dev/input/lid_indev");
59     // UniqueId not set
60     node->setBusType(0);
61     node->setVendorId(0);
62     node->setProductId(0);
63     node->setVersion(0);
64     // No keys
65     // No relative axes
66     // No absolute axes
67     node->addSwitch(SW_LID);
68     // No forcefeedback
69     node->addInputProperty(INPUT_PROP_DIRECT);
70     return node;
71 }
72 
getButtonJack()73 MockInputDeviceNode* getButtonJack() {
74     auto node = new MockInputDeviceNode();
75     node->setPath("/dev/input/event2");
76     node->setName("apq8064-tabla-snd-card Button Jack");
77     node->setLocation("ALSA");
78     // UniqueId not set
79     node->setBusType(0);
80     node->setVendorId(0);
81     node->setProductId(0);
82     node->setVersion(0);
83     node->addKeys(BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7);
84     // No relative axes
85     // No absolute axes
86     // No switches
87     // No forcefeedback
88     node->addInputProperty(INPUT_PROP_DIRECT);
89     return node;
90 }
91 
getHeadsetJack()92 MockInputDeviceNode* getHeadsetJack() {
93     auto node = new MockInputDeviceNode();
94     node->setPath("/dev/input/event3");
95     node->setName("apq8064-tabla-snd-card Headset Jack");
96     node->setLocation("ALSA");
97     // UniqueId not set
98     node->setBusType(0);
99     node->setVendorId(0);
100     node->setProductId(0);
101     node->setVersion(0);
102     // No keys
103     // No relative axes
104     // No absolute axes
105     node->addSwitch(SW_HEADPHONE_INSERT);
106     node->addSwitch(SW_MICROPHONE_INSERT);
107     node->addSwitch(SW_LINEOUT_INSERT);
108     // ASUS adds some proprietary switches, but we'll only see two of them.
109     node->addSwitch(0x0e);  // SW_HPHL_OVERCURRENT
110     node->addSwitch(0x0f);  // SW_HPHR_OVERCURRENT
111     // No forcefeedback
112     node->addInputProperty(INPUT_PROP_DIRECT);
113     return node;
114 }
115 
getH2wButton()116 MockInputDeviceNode* getH2wButton() {
117     auto node = new MockInputDeviceNode();
118     node->setPath("/dev/input/event4");
119     node->setName("h2w button");
120     // Location not set
121     // UniqueId not set
122     node->setBusType(0);
123     node->setVendorId(0);
124     node->setProductId(0);
125     node->setVersion(0);
126     node->addKeys(KEY_MEDIA);
127     // No relative axes
128     // No absolute axes
129     // No switches
130     node->addInputProperty(INPUT_PROP_DIRECT);
131     return node;
132 }
133 
getGpioKeys()134 MockInputDeviceNode* getGpioKeys() {
135     auto node = new MockInputDeviceNode();
136     node->setPath("/dev/input/event5");
137     node->setName("gpio-keys");
138     node->setLocation("gpio-keys/input0");
139     // UniqueId not set
140     node->setBusType(0x0019);
141     node->setVendorId(0x0001);
142     node->setProductId(0x0001);
143     node->setVersion(0x0100);
144     node->addKeys(KEY_VOLUMEDOWN, KEY_VOLUMEUP, KEY_POWER);
145     // No relative axes
146     // No absolute axes
147     // No switches
148     node->addInputProperty(INPUT_PROP_DIRECT);
149     return node;
150 }
151 
152 }  // namespace MockNexus7v2
153 
154 namespace MockNexusPlayer {
155 
getGpioKeys()156 MockInputDeviceNode* getGpioKeys() {
157     auto node = new MockInputDeviceNode();
158     node->setPath("/dev/input/event0");
159     node->setName("gpio-keys");
160     node->setLocation("gpio-keys/input0");
161     // UniqueId not set
162     node->setBusType(0x0019);
163     node->setVendorId(0x0001);
164     node->setProductId(0x0001);
165     node->setVersion(0x0100);
166     node->addKeys(KEY_CONNECT);
167     // No relative axes
168     // No absolute axes
169     // No switches
170     node->addInputProperty(INPUT_PROP_DIRECT);
171     return node;
172 }
173 
getMidPowerBtn()174 MockInputDeviceNode* getMidPowerBtn() {
175     auto node = new MockInputDeviceNode();
176     node->setPath("/dev/input/event1");
177     node->setName("mid_powerbtn");
178     node->setLocation("power-button/input0");
179     // UniqueId not set
180     node->setBusType(0x0019);
181     node->setVendorId(0);
182     node->setProductId(0);
183     node->setVersion(0);
184     node->addKeys(KEY_POWER);
185     // No relative axes
186     // No absolute axes
187     // No switches
188     node->addInputProperty(INPUT_PROP_DIRECT);
189     return node;
190 }
191 
getNexusRemote()192 MockInputDeviceNode* getNexusRemote() {
193     auto node = new MockInputDeviceNode();
194     node->setPath("/dev/input/event2");
195     node->setName("Nexus Remote");
196     // Location not set
197     node->setUniqueId("78:86:D9:50:A0:54");
198     node->setBusType(0x0005);
199     node->setVendorId(0x18d1);
200     node->setProductId(0x2c42);
201     node->setVersion(0);
202     node->addKeys(KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_BACK, KEY_PLAYPAUSE,
203             KEY_HOMEPAGE, KEY_SEARCH, KEY_SELECT);
204     // No relative axes
205     node->addAbsAxis(ABS_MISC, nullptr);
206     // No switches
207     node->addInputProperty(INPUT_PROP_DIRECT);
208     return node;
209 }
210 
getAsusGamepad()211 MockInputDeviceNode* getAsusGamepad() {
212     auto node = new MockInputDeviceNode();
213     node->setPath("/dev/input/event3");
214     node->setName("ASUS Gamepad");
215     // Location not set
216     node->setUniqueId("C5:30:CD:50:A0:54");
217     node->setBusType(0x0005);
218     node->setVendorId(0x0b05);
219     node->setProductId(0x4500);
220     node->setVersion(0x0040);
221     node->addKeys(KEY_BACK, KEY_HOMEPAGE, BTN_A, BTN_B, BTN_X, BTN_Y, BTN_TL, BTN_TR,
222             BTN_MODE, BTN_THUMBL, BTN_THUMBR);
223     // No relative axes
224     node->addAbsAxis(ABS_X, nullptr);
225     node->addAbsAxis(ABS_Y, nullptr);
226     node->addAbsAxis(ABS_Z, nullptr);
227     node->addAbsAxis(ABS_RZ, nullptr);
228     node->addAbsAxis(ABS_GAS, nullptr);
229     node->addAbsAxis(ABS_BRAKE, nullptr);
230     node->addAbsAxis(ABS_HAT0X, nullptr);
231     node->addAbsAxis(ABS_HAT0Y, nullptr);
232     node->addAbsAxis(ABS_MISC, nullptr);
233     node->addAbsAxis(0x29, nullptr);
234     node->addAbsAxis(0x2a, nullptr);
235     // No switches
236     node->addInputProperty(INPUT_PROP_DIRECT);
237     // Note: this device has MSC and LED bitmaps as well.
238     return node;
239 }
240 
241 }  // namespace MockNexusPlayer
242 
243 }  // namespace android
244