blob: 58e5b2dfaa375935c1f701862c43db6e0335093d [file] [log] [blame]
Jeff Brownc5ed5912010-07-14 18:48:53 -07001/*
2 * Copyright (C) 2010 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
17package android.view;
18
Arthur Hung5d019782019-11-06 19:42:44 +080019import android.annotation.IntDef;
Siarhei Vishniakoua7f99b52017-03-21 17:39:40 -070020import android.annotation.RequiresPermission;
21import android.annotation.TestApi;
Artur Satayevad9254c2019-12-10 17:47:54 +000022import android.compat.annotation.UnsupportedAppUsage;
Jeff Browna47425a2012-04-13 04:09:27 -070023import android.content.Context;
RoboErikca9eef62013-12-16 11:27:55 -080024import android.hardware.input.InputDeviceIdentifier;
Jeff Brownac143512012-04-05 18:57:33 -070025import android.hardware.input.InputManager;
Sergey Vasilinetsacec8842019-02-08 16:42:31 +000026import android.os.Build;
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070027import android.os.NullVibrator;
Jeff Brown8d608662010-08-30 03:02:23 -070028import android.os.Parcel;
29import android.os.Parcelable;
Jeff Browna47425a2012-04-13 04:09:27 -070030import android.os.Vibrator;
Jeff Brownefd32662011-03-08 15:13:06 -080031
Arthur Hung5d019782019-11-06 19:42:44 +080032import java.lang.annotation.Retention;
33import java.lang.annotation.RetentionPolicy;
Jeff Brownefd32662011-03-08 15:13:06 -080034import java.util.ArrayList;
35import java.util.List;
Jeff Brown8d608662010-08-30 03:02:23 -070036
Jeff Brownc5ed5912010-07-14 18:48:53 -070037/**
38 * Describes the capabilities of a particular input device.
39 * <p>
Jeff Brown9df6e7a2012-04-05 11:49:26 -070040 * Each input device may support multiple classes of input. For example, a multi-function
Jeff Brownc5ed5912010-07-14 18:48:53 -070041 * keyboard may compose the capabilities of a standard keyboard together with a track pad mouse
42 * or other pointing device.
43 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070044 * Some input devices present multiple distinguishable sources of input.
Jeff Brownc5ed5912010-07-14 18:48:53 -070045 * Applications can query the framework about the characteristics of each distinct source.
46 * </p><p>
47 * As a further wrinkle, different kinds of input sources uses different coordinate systems
48 * to describe motion events. Refer to the comments on the input source constants for
49 * the appropriate interpretation.
Jeff Brown6d0fec22010-07-23 21:28:06 -070050 * </p>
Jeff Brownc5ed5912010-07-14 18:48:53 -070051 */
Jeff Brown8d608662010-08-30 03:02:23 -070052public final class InputDevice implements Parcelable {
Jeff Brown9f25b7f2012-04-10 14:30:49 -070053 private final int mId;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070054 private final int mGeneration;
Michael Wrightac6c78b2013-07-17 13:21:45 -070055 private final int mControllerNumber;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070056 private final String mName;
Michael Wright54e56942013-08-12 16:39:59 -070057 private final int mVendorId;
58 private final int mProductId;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070059 private final String mDescriptor;
RoboErikca9eef62013-12-16 11:27:55 -080060 private final InputDeviceIdentifier mIdentifier;
Sergey Vasilinetsacec8842019-02-08 16:42:31 +000061 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Jeff Browndaa37532012-05-01 15:54:03 -070062 private final boolean mIsExternal;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070063 private final int mSources;
64 private final int mKeyboardType;
65 private final KeyCharacterMap mKeyCharacterMap;
Jeff Browna47425a2012-04-13 04:09:27 -070066 private final boolean mHasVibrator;
Tim Kilbourn72285e52015-06-05 15:52:05 -070067 private final boolean mHasMicrophone;
Michael Wright7ddd1102013-05-20 15:04:55 -070068 private final boolean mHasButtonUnderPad;
Jeff Brownefd32662011-03-08 15:13:06 -080069 private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>();
Jeff Brown91c69ab2011-02-14 17:03:18 -080070
Jeff Browna47425a2012-04-13 04:09:27 -070071 private Vibrator mVibrator; // guarded by mMotionRanges during initialization
72
Jeff Brownc5ed5912010-07-14 18:48:53 -070073 /**
74 * A mask for input source classes.
RoboErikca9eef62013-12-16 11:27:55 -080075 *
Jeff Brownc5ed5912010-07-14 18:48:53 -070076 * Each distinct input source constant has one or more input source class bits set to
77 * specify the desired interpretation for its input events.
78 */
79 public static final int SOURCE_CLASS_MASK = 0x000000ff;
Michael Wrighte7a9ae82013-03-08 15:19:19 -080080
81 /**
82 * The input source has no class.
83 *
84 * It is up to the application to determine how to handle the device based on the device type.
85 */
86 public static final int SOURCE_CLASS_NONE = 0x00000000;
87
Jeff Brownc5ed5912010-07-14 18:48:53 -070088 /**
89 * The input source has buttons or keys.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070090 * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}.
RoboErikca9eef62013-12-16 11:27:55 -080091 *
Jeff Brownc5ed5912010-07-14 18:48:53 -070092 * A {@link KeyEvent} should be interpreted as a button or key press.
RoboErikca9eef62013-12-16 11:27:55 -080093 *
Jeff Brown6eb5ac92010-08-30 23:29:07 -070094 * Use {@link #getKeyCharacterMap} to query the device's button and key mappings.
Jeff Brownc5ed5912010-07-14 18:48:53 -070095 */
96 public static final int SOURCE_CLASS_BUTTON = 0x00000001;
RoboErikca9eef62013-12-16 11:27:55 -080097
Jeff Brownc5ed5912010-07-14 18:48:53 -070098 /**
99 * The input source is a pointing device associated with a display.
100 * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}.
RoboErikca9eef62013-12-16 11:27:55 -0800101 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700102 * A {@link MotionEvent} should be interpreted as absolute coordinates in
103 * display units according to the {@link View} hierarchy. Pointer down/up indicated when
104 * the finger touches the display or when the selection button is pressed/released.
RoboErikca9eef62013-12-16 11:27:55 -0800105 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700106 * Use {@link #getMotionRange} to query the range of the pointing device. Some devices permit
107 * touches outside the display area so the effective range may be somewhat smaller or larger
108 * than the actual display size.
109 */
110 public static final int SOURCE_CLASS_POINTER = 0x00000002;
RoboErikca9eef62013-12-16 11:27:55 -0800111
Jeff Brownc5ed5912010-07-14 18:48:53 -0700112 /**
113 * The input source is a trackball navigation device.
114 * Examples: {@link #SOURCE_TRACKBALL}.
RoboErikca9eef62013-12-16 11:27:55 -0800115 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700116 * A {@link MotionEvent} should be interpreted as relative movements in device-specific
117 * units used for navigation purposes. Pointer down/up indicates when the selection button
118 * is pressed/released.
RoboErikca9eef62013-12-16 11:27:55 -0800119 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700120 * Use {@link #getMotionRange} to query the range of motion.
121 */
122 public static final int SOURCE_CLASS_TRACKBALL = 0x00000004;
RoboErikca9eef62013-12-16 11:27:55 -0800123
Jeff Brownc5ed5912010-07-14 18:48:53 -0700124 /**
125 * The input source is an absolute positioning device not associated with a display
126 * (unlike {@link #SOURCE_CLASS_POINTER}).
RoboErikca9eef62013-12-16 11:27:55 -0800127 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700128 * A {@link MotionEvent} should be interpreted as absolute coordinates in
129 * device-specific surface units.
RoboErikca9eef62013-12-16 11:27:55 -0800130 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700131 * Use {@link #getMotionRange} to query the range of positions.
132 */
133 public static final int SOURCE_CLASS_POSITION = 0x00000008;
Jeff Browncb1404e2011-01-15 18:14:15 -0800134
135 /**
136 * The input source is a joystick.
137 *
138 * A {@link MotionEvent} should be interpreted as absolute joystick movements.
139 *
140 * Use {@link #getMotionRange} to query the range of positions.
141 */
142 public static final int SOURCE_CLASS_JOYSTICK = 0x00000010;
143
Arthur Hung5d019782019-11-06 19:42:44 +0800144 /** @hide */
145 @IntDef(flag = true, prefix = { "SOURCE_CLASS_" }, value = {
146 SOURCE_CLASS_NONE,
147 SOURCE_CLASS_BUTTON,
148 SOURCE_CLASS_POINTER,
149 SOURCE_CLASS_POINTER,
150 SOURCE_CLASS_TRACKBALL,
151 SOURCE_CLASS_POSITION,
152 SOURCE_CLASS_JOYSTICK
153 })
154 @Retention(RetentionPolicy.SOURCE)
155 @interface InputSourceClass {}
156
Jeff Brownc5ed5912010-07-14 18:48:53 -0700157 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700158 * The input source is unknown.
159 */
160 public static final int SOURCE_UNKNOWN = 0x00000000;
RoboErikca9eef62013-12-16 11:27:55 -0800161
Jeff Brownc5ed5912010-07-14 18:48:53 -0700162 /**
163 * The input source is a keyboard.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700164 *
165 * This source indicates pretty much anything that has buttons. Use
166 * {@link #getKeyboardType()} to determine whether the keyboard has alphabetic keys
167 * and can be used to enter text.
168 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700169 * @see #SOURCE_CLASS_BUTTON
170 */
171 public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON;
RoboErikca9eef62013-12-16 11:27:55 -0800172
Jeff Brownc5ed5912010-07-14 18:48:53 -0700173 /**
174 * The input source is a DPad.
RoboErikca9eef62013-12-16 11:27:55 -0800175 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700176 * @see #SOURCE_CLASS_BUTTON
177 */
178 public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON;
Jeff Browncb1404e2011-01-15 18:14:15 -0800179
180 /**
181 * The input source is a game pad.
182 * (It may also be a {@link #SOURCE_JOYSTICK}).
183 *
184 * @see #SOURCE_CLASS_BUTTON
185 */
186 public static final int SOURCE_GAMEPAD = 0x00000400 | SOURCE_CLASS_BUTTON;
187
Jeff Brownc5ed5912010-07-14 18:48:53 -0700188 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700189 * The input source is a touch screen pointing device.
RoboErikca9eef62013-12-16 11:27:55 -0800190 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700191 * @see #SOURCE_CLASS_POINTER
192 */
193 public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER;
RoboErikca9eef62013-12-16 11:27:55 -0800194
Jeff Brownc5ed5912010-07-14 18:48:53 -0700195 /**
196 * The input source is a mouse pointing device.
197 * This code is also used for other mouse-like pointing devices such as trackpads
198 * and trackpoints.
RoboErikca9eef62013-12-16 11:27:55 -0800199 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700200 * @see #SOURCE_CLASS_POINTER
201 */
202 public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700203
204 /**
205 * The input source is a stylus pointing device.
Jeff Brown00710e92012-04-19 15:18:26 -0700206 * <p>
207 * Note that this bit merely indicates that an input device is capable of obtaining
208 * input from a stylus. To determine whether a given touch event was produced
209 * by a stylus, examine the tool type returned by {@link MotionEvent#getToolType(int)}
210 * for each individual pointer.
211 * </p><p>
212 * A single touch event may multiple pointers with different tool types,
213 * such as an event that has one pointer with tool type
214 * {@link MotionEvent#TOOL_TYPE_FINGER} and another pointer with tool type
215 * {@link MotionEvent#TOOL_TYPE_STYLUS}. So it is important to examine
216 * the tool type of each pointer, regardless of the source reported
217 * by {@link MotionEvent#getSource()}.
218 * </p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700219 *
220 * @see #SOURCE_CLASS_POINTER
221 */
222 public static final int SOURCE_STYLUS = 0x00004000 | SOURCE_CLASS_POINTER;
223
Jeff Brownc5ed5912010-07-14 18:48:53 -0700224 /**
Michael Wrightf18920b2015-06-12 15:24:38 +0100225 * The input device is a Bluetooth stylus.
226 * <p>
227 * Note that this bit merely indicates that an input device is capable of
228 * obtaining input from a Bluetooth stylus. To determine whether a given
229 * touch event was produced by a stylus, examine the tool type returned by
230 * {@link MotionEvent#getToolType(int)} for each individual pointer.
231 * </p><p>
232 * A single touch event may multiple pointers with different tool types,
233 * such as an event that has one pointer with tool type
234 * {@link MotionEvent#TOOL_TYPE_FINGER} and another pointer with tool type
235 * {@link MotionEvent#TOOL_TYPE_STYLUS}. So it is important to examine
236 * the tool type of each pointer, regardless of the source reported
237 * by {@link MotionEvent#getSource()}.
238 * </p><p>
239 * A bluetooth stylus generally receives its pressure and button state
240 * information from the stylus itself, and derives the rest from another
241 * source. For example, a Bluetooth stylus used in conjunction with a
242 * touchscreen would derive its contact position and pointer size from the
243 * touchscreen and may not be any more accurate than other tools such as
244 * fingers.
245 * </p>
246 *
247 * @see #SOURCE_STYLUS
248 * @see #SOURCE_CLASS_POINTER
249 */
250 public static final int SOURCE_BLUETOOTH_STYLUS =
251 0x00008000 | SOURCE_STYLUS;
252
253 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700254 * The input source is a trackball.
RoboErikca9eef62013-12-16 11:27:55 -0800255 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700256 * @see #SOURCE_CLASS_TRACKBALL
257 */
258 public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL;
RoboErikca9eef62013-12-16 11:27:55 -0800259
Jeff Brownc5ed5912010-07-14 18:48:53 -0700260 /**
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800261 * The input source is a mouse device whose relative motions should be interpreted as
262 * navigation events.
263 *
264 * @see #SOURCE_CLASS_TRACKBALL
265 */
266 public static final int SOURCE_MOUSE_RELATIVE = 0x00020000 | SOURCE_CLASS_TRACKBALL;
267
268 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700269 * The input source is a touch pad or digitizer tablet that is not
Jeff Browne33348b2010-07-15 23:54:05 -0700270 * associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}).
RoboErikca9eef62013-12-16 11:27:55 -0800271 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700272 * @see #SOURCE_CLASS_POSITION
273 */
274 public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION;
Jeff Browncb1404e2011-01-15 18:14:15 -0800275
276 /**
Michael Wrighte7a9ae82013-03-08 15:19:19 -0800277 * The input source is a touch device whose motions should be interpreted as navigation events.
278 *
279 * For example, an upward swipe should be as an upward focus traversal in the same manner as
280 * pressing up on a D-Pad would be. Swipes to the left, right and down should be treated in a
281 * similar manner.
282 *
283 * @see #SOURCE_CLASS_NONE
284 */
285 public static final int SOURCE_TOUCH_NAVIGATION = 0x00200000 | SOURCE_CLASS_NONE;
286
287 /**
Prashant Malani67322b12015-08-25 17:41:34 -0700288 * The input source is a rotating encoder device whose motions should be interpreted as akin to
289 * those of a scroll wheel.
290 *
291 * @see #SOURCE_CLASS_NONE
Prashant Malani67322b12015-08-25 17:41:34 -0700292 */
293 public static final int SOURCE_ROTARY_ENCODER = 0x00400000 | SOURCE_CLASS_NONE;
294
295 /**
Jeff Browncb1404e2011-01-15 18:14:15 -0800296 * The input source is a joystick.
297 * (It may also be a {@link #SOURCE_GAMEPAD}).
298 *
299 * @see #SOURCE_CLASS_JOYSTICK
300 */
301 public static final int SOURCE_JOYSTICK = 0x01000000 | SOURCE_CLASS_JOYSTICK;
302
Jeff Brown6d0fec22010-07-23 21:28:06 -0700303 /**
Jinsuk Kim96658f72014-05-14 15:33:43 +0900304 * The input source is a device connected through HDMI-based bus.
305 *
306 * The key comes in through HDMI-CEC or MHL signal line, and is treated as if it were
307 * generated by a locally connected DPAD or keyboard.
308 */
309 public static final int SOURCE_HDMI = 0x02000000 | SOURCE_CLASS_BUTTON;
310
311 /**
Jeff Brown6d0fec22010-07-23 21:28:06 -0700312 * A special input source constant that is used when filtering input devices
313 * to match devices that provide any type of input source.
314 */
315 public static final int SOURCE_ANY = 0xffffff00;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700316
Jeff Browne33348b2010-07-15 23:54:05 -0700317 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800318 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_X}.
RoboErikca9eef62013-12-16 11:27:55 -0800319 *
Jeff Browne33348b2010-07-15 23:54:05 -0700320 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800321 * @deprecated Use {@link MotionEvent#AXIS_X} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700322 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800323 @Deprecated
324 public static final int MOTION_RANGE_X = MotionEvent.AXIS_X;
325
Jeff Browne33348b2010-07-15 23:54:05 -0700326 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800327 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_Y}.
RoboErikca9eef62013-12-16 11:27:55 -0800328 *
Jeff Browne33348b2010-07-15 23:54:05 -0700329 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800330 * @deprecated Use {@link MotionEvent#AXIS_Y} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700331 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800332 @Deprecated
333 public static final int MOTION_RANGE_Y = MotionEvent.AXIS_Y;
334
Jeff Browne33348b2010-07-15 23:54:05 -0700335 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800336 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}.
RoboErikca9eef62013-12-16 11:27:55 -0800337 *
Jeff Browne33348b2010-07-15 23:54:05 -0700338 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800339 * @deprecated Use {@link MotionEvent#AXIS_PRESSURE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700340 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800341 @Deprecated
342 public static final int MOTION_RANGE_PRESSURE = MotionEvent.AXIS_PRESSURE;
343
Jeff Browne33348b2010-07-15 23:54:05 -0700344 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800345 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}.
RoboErikca9eef62013-12-16 11:27:55 -0800346 *
Jeff Browne33348b2010-07-15 23:54:05 -0700347 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800348 * @deprecated Use {@link MotionEvent#AXIS_SIZE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700349 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800350 @Deprecated
351 public static final int MOTION_RANGE_SIZE = MotionEvent.AXIS_SIZE;
352
Jeff Browne33348b2010-07-15 23:54:05 -0700353 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800354 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}.
RoboErikca9eef62013-12-16 11:27:55 -0800355 *
Jeff Browne33348b2010-07-15 23:54:05 -0700356 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800357 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700358 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800359 @Deprecated
360 public static final int MOTION_RANGE_TOUCH_MAJOR = MotionEvent.AXIS_TOUCH_MAJOR;
361
Jeff Browne33348b2010-07-15 23:54:05 -0700362 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800363 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}.
RoboErikca9eef62013-12-16 11:27:55 -0800364 *
Jeff Browne33348b2010-07-15 23:54:05 -0700365 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800366 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700367 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800368 @Deprecated
369 public static final int MOTION_RANGE_TOUCH_MINOR = MotionEvent.AXIS_TOUCH_MINOR;
370
Jeff Browne33348b2010-07-15 23:54:05 -0700371 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800372 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MAJOR}.
RoboErikca9eef62013-12-16 11:27:55 -0800373 *
Jeff Browne33348b2010-07-15 23:54:05 -0700374 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800375 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700376 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800377 @Deprecated
378 public static final int MOTION_RANGE_TOOL_MAJOR = MotionEvent.AXIS_TOOL_MAJOR;
379
Jeff Browne33348b2010-07-15 23:54:05 -0700380 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800381 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MINOR}.
RoboErikca9eef62013-12-16 11:27:55 -0800382 *
Jeff Browne33348b2010-07-15 23:54:05 -0700383 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800384 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700385 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800386 @Deprecated
387 public static final int MOTION_RANGE_TOOL_MINOR = MotionEvent.AXIS_TOOL_MINOR;
388
Jeff Browne33348b2010-07-15 23:54:05 -0700389 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800390 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_ORIENTATION}.
RoboErikca9eef62013-12-16 11:27:55 -0800391 *
Jeff Browne33348b2010-07-15 23:54:05 -0700392 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800393 * @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700394 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800395 @Deprecated
396 public static final int MOTION_RANGE_ORIENTATION = MotionEvent.AXIS_ORIENTATION;
RoboErikca9eef62013-12-16 11:27:55 -0800397
Jeff Brown6d0fec22010-07-23 21:28:06 -0700398 /**
399 * There is no keyboard.
400 */
401 public static final int KEYBOARD_TYPE_NONE = 0;
RoboErikca9eef62013-12-16 11:27:55 -0800402
Jeff Brown6d0fec22010-07-23 21:28:06 -0700403 /**
404 * The keyboard is not fully alphabetic. It may be a numeric keypad or an assortment
405 * of buttons that are not mapped as alphabetic keys suitable for text input.
406 */
407 public static final int KEYBOARD_TYPE_NON_ALPHABETIC = 1;
RoboErikca9eef62013-12-16 11:27:55 -0800408
Jeff Brown6d0fec22010-07-23 21:28:06 -0700409 /**
410 * The keyboard supports a complement of alphabetic keys.
411 */
412 public static final int KEYBOARD_TYPE_ALPHABETIC = 2;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800413
Kristian Monsen1f9dc882016-03-25 16:42:15 -0700414 private static final int MAX_RANGES = 1000;
415
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700416 public static final @android.annotation.NonNull Parcelable.Creator<InputDevice> CREATOR =
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700417 new Parcelable.Creator<InputDevice>() {
418 public InputDevice createFromParcel(Parcel in) {
419 return new InputDevice(in);
420 }
421 public InputDevice[] newArray(int size) {
422 return new InputDevice[size];
423 }
424 };
425
Jeff Brown8d608662010-08-30 03:02:23 -0700426 // Called by native code.
Mathew Inwooda570dee2018-08-17 14:56:00 +0100427 @UnsupportedAppUsage
Michael Wright54e56942013-08-12 16:39:59 -0700428 private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId,
Tim Kilbourn6d85cf22015-04-08 10:23:35 -0700429 int productId, String descriptor, boolean isExternal, int sources, int keyboardType,
Tim Kilbourn72285e52015-06-05 15:52:05 -0700430 KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasMicrophone,
Tim Kilbourn415b4502015-03-19 16:02:02 -0700431 boolean hasButtonUnderPad) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700432 mId = id;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700433 mGeneration = generation;
Michael Wrightac6c78b2013-07-17 13:21:45 -0700434 mControllerNumber = controllerNumber;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700435 mName = name;
Michael Wright54e56942013-08-12 16:39:59 -0700436 mVendorId = vendorId;
437 mProductId = productId;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700438 mDescriptor = descriptor;
Jeff Browndaa37532012-05-01 15:54:03 -0700439 mIsExternal = isExternal;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700440 mSources = sources;
441 mKeyboardType = keyboardType;
442 mKeyCharacterMap = keyCharacterMap;
Jeff Browna47425a2012-04-13 04:09:27 -0700443 mHasVibrator = hasVibrator;
Tim Kilbourn72285e52015-06-05 15:52:05 -0700444 mHasMicrophone = hasMicrophone;
Michael Wright7ddd1102013-05-20 15:04:55 -0700445 mHasButtonUnderPad = hasButtonUnderPad;
RoboErikca9eef62013-12-16 11:27:55 -0800446 mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700447 }
448
449 private InputDevice(Parcel in) {
450 mId = in.readInt();
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700451 mGeneration = in.readInt();
Michael Wrightac6c78b2013-07-17 13:21:45 -0700452 mControllerNumber = in.readInt();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700453 mName = in.readString();
Michael Wright54e56942013-08-12 16:39:59 -0700454 mVendorId = in.readInt();
455 mProductId = in.readInt();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700456 mDescriptor = in.readString();
Jeff Browndaa37532012-05-01 15:54:03 -0700457 mIsExternal = in.readInt() != 0;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700458 mSources = in.readInt();
459 mKeyboardType = in.readInt();
460 mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in);
Jeff Browna47425a2012-04-13 04:09:27 -0700461 mHasVibrator = in.readInt() != 0;
Tim Kilbourn72285e52015-06-05 15:52:05 -0700462 mHasMicrophone = in.readInt() != 0;
Michael Wright7ddd1102013-05-20 15:04:55 -0700463 mHasButtonUnderPad = in.readInt() != 0;
RoboErikca9eef62013-12-16 11:27:55 -0800464 mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700465
Kristian Monsen1f9dc882016-03-25 16:42:15 -0700466 int numRanges = in.readInt();
467 if (numRanges > MAX_RANGES) {
468 numRanges = MAX_RANGES;
469 }
470
471 for (int i = 0; i < numRanges; i++) {
472 addMotionRange(in.readInt(), in.readInt(), in.readFloat(), in.readFloat(),
473 in.readFloat(), in.readFloat(), in.readFloat());
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700474 }
Jeff Brown8d608662010-08-30 03:02:23 -0700475 }
Jeff Browne33348b2010-07-15 23:54:05 -0700476
477 /**
478 * Gets information about the input device with the specified id.
479 * @param id The device id.
480 * @return The input device or null if not found.
481 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700482 public static InputDevice getDevice(int id) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700483 return InputManager.getInstance().getInputDevice(id);
Jeff Brown8d608662010-08-30 03:02:23 -0700484 }
RoboErikca9eef62013-12-16 11:27:55 -0800485
Jeff Brown8d608662010-08-30 03:02:23 -0700486 /**
487 * Gets the ids of all input devices in the system.
488 * @return The input device ids.
489 */
490 public static int[] getDeviceIds() {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700491 return InputManager.getInstance().getInputDeviceIds();
Jeff Brown8d608662010-08-30 03:02:23 -0700492 }
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700493
Jeff Brown8d608662010-08-30 03:02:23 -0700494 /**
495 * Gets the input device id.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700496 * <p>
497 * Each input device receives a unique id when it is first configured
498 * by the system. The input device id may change when the system is restarted or if the
499 * input device is disconnected, reconnected or reconfigured at any time.
500 * If you require a stable identifier for a device that persists across
501 * boots and reconfigurations, use {@link #getDescriptor()}.
502 * </p>
503 *
Jeff Brown8d608662010-08-30 03:02:23 -0700504 * @return The input device id.
505 */
506 public int getId() {
507 return mId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700508 }
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700509
510 /**
Michael Wrightac6c78b2013-07-17 13:21:45 -0700511 * The controller number for a given input device.
512 * <p>
Michael Wright10fac452013-09-03 12:37:12 -0700513 * Each gamepad or joystick is given a unique, positive controller number when initially
514 * configured by the system. This number may change due to events such as device disconnects /
515 * reconnects or user initiated reassignment. Any change in number will trigger an event that
516 * can be observed by registering an {@link InputManager.InputDeviceListener}.
517 * </p>
518 * <p>
519 * All input devices which are not gamepads or joysticks will be assigned a controller number
Michael Wrightac6c78b2013-07-17 13:21:45 -0700520 * of 0.
521 * </p>
Michael Wright10fac452013-09-03 12:37:12 -0700522 *
523 * @return The controller number of the device.
Michael Wrightac6c78b2013-07-17 13:21:45 -0700524 */
525 public int getControllerNumber() {
526 return mControllerNumber;
527 }
528
529 /**
RoboErikca9eef62013-12-16 11:27:55 -0800530 * The set of identifying information for type of input device. This
531 * information can be used by the system to configure appropriate settings
532 * for the device.
533 *
534 * @return The identifier object for this device
535 * @hide
536 */
537 public InputDeviceIdentifier getIdentifier() {
538 return mIdentifier;
539 }
540
541 /**
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700542 * Gets a generation number for this input device.
543 * The generation number is incremented whenever the device is reconfigured and its
544 * properties may have changed.
545 *
546 * @return The generation number.
547 *
548 * @hide
549 */
550 public int getGeneration() {
551 return mGeneration;
552 }
553
554 /**
Michael Wright54e56942013-08-12 16:39:59 -0700555 * Gets the vendor id for the given device, if available.
556 * <p>
557 * A vendor id uniquely identifies the company who manufactured the device. A value of 0 will
558 * be assigned where a vendor id is not available.
559 * </p>
560 *
561 * @return The vendor id of a given device
562 */
563 public int getVendorId() {
564 return mVendorId;
565 }
566
567 /**
568 * Gets the product id for the given device, if available.
569 * <p>
570 * A product id uniquely identifies which product within the address space of a given vendor,
571 * identified by the device's vendor id. A value of 0 will be assigned where a product id is
572 * not available.
573 * </p>
574 *
575 * @return The product id of a given device
576 */
577 public int getProductId() {
578 return mProductId;
579 }
580
581 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700582 * Gets the input device descriptor, which is a stable identifier for an input device.
583 * <p>
584 * An input device descriptor uniquely identifies an input device. Its value
585 * is intended to be persistent across system restarts, and should not change even
586 * if the input device is disconnected, reconnected or reconfigured at any time.
Jeff Browne38fdfa2012-04-06 14:51:01 -0700587 * </p><p>
588 * It is possible for there to be multiple {@link InputDevice} instances that have the
589 * same input device descriptor. This might happen in situations where a single
590 * human input device registers multiple {@link InputDevice} instances (HID collections)
591 * that describe separate features of the device, such as a keyboard that also
592 * has a trackpad. Alternately, it may be that the input devices are simply
593 * indistinguishable, such as two keyboards made by the same manufacturer.
594 * </p><p>
Jeff Browndaa37532012-05-01 15:54:03 -0700595 * The input device descriptor returned by {@link #getDescriptor} should only be
Jeff Browne38fdfa2012-04-06 14:51:01 -0700596 * used when an application needs to remember settings associated with a particular
597 * input device. For all other purposes when referring to a logical
598 * {@link InputDevice} instance at runtime use the id returned by {@link #getId()}.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700599 * </p>
600 *
601 * @return The input device descriptor.
602 */
603 public String getDescriptor() {
Jeff Browne38fdfa2012-04-06 14:51:01 -0700604 return mDescriptor;
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700605 }
606
Jeff Brownc5ed5912010-07-14 18:48:53 -0700607 /**
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700608 * Returns true if the device is a virtual input device rather than a real one,
609 * such as the virtual keyboard (see {@link KeyCharacterMap#VIRTUAL_KEYBOARD}).
610 * <p>
611 * Virtual input devices are provided to implement system-level functionality
612 * and should not be seen or configured by users.
613 * </p>
614 *
615 * @return True if the device is virtual.
616 *
617 * @see KeyCharacterMap#VIRTUAL_KEYBOARD
618 */
619 public boolean isVirtual() {
620 return mId < 0;
621 }
622
623 /**
Jeff Browndaa37532012-05-01 15:54:03 -0700624 * Returns true if the device is external (connected to USB or Bluetooth or some other
625 * peripheral bus), otherwise it is built-in.
626 *
627 * @return True if the device is external.
Jeff Browndaa37532012-05-01 15:54:03 -0700628 */
629 public boolean isExternal() {
630 return mIsExternal;
631 }
632
633 /**
Jeff Brown7e4ff4b2012-05-30 14:32:16 -0700634 * Returns true if the device is a full keyboard.
635 *
636 * @return True if the device is a full keyboard.
637 *
638 * @hide
639 */
640 public boolean isFullKeyboard() {
641 return (mSources & SOURCE_KEYBOARD) == SOURCE_KEYBOARD
642 && mKeyboardType == KEYBOARD_TYPE_ALPHABETIC;
643 }
644
645 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700646 * Gets the name of this input device.
647 * @return The input device name.
648 */
649 public String getName() {
650 return mName;
651 }
RoboErikca9eef62013-12-16 11:27:55 -0800652
Jeff Brownc5ed5912010-07-14 18:48:53 -0700653 /**
654 * Gets the input sources supported by this input device as a combined bitfield.
655 * @return The supported input sources.
656 */
657 public int getSources() {
658 return mSources;
659 }
RoboErikca9eef62013-12-16 11:27:55 -0800660
Jeff Brownc5ed5912010-07-14 18:48:53 -0700661 /**
Michael Wrightd08c8642014-03-28 12:59:34 -0700662 * Determines whether the input device supports the given source or sources.
663 *
664 * @param source The input source or sources to check against. This can be a generic device
665 * type such as {@link InputDevice#SOURCE_MOUSE}, a more generic device class, such as
666 * {@link InputDevice#SOURCE_CLASS_POINTER}, or a combination of sources bitwise ORed together.
667 * @return Whether the device can produce all of the given sources.
668 */
669 public boolean supportsSource(int source) {
670 return (mSources & source) == source;
671 }
672
673 /**
Jeff Brown6d0fec22010-07-23 21:28:06 -0700674 * Gets the keyboard type.
675 * @return The keyboard type.
676 */
677 public int getKeyboardType() {
678 return mKeyboardType;
679 }
RoboErikca9eef62013-12-16 11:27:55 -0800680
Jeff Brown6d0fec22010-07-23 21:28:06 -0700681 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700682 * Gets the key character map associated with this input device.
683 * @return The key character map.
684 */
685 public KeyCharacterMap getKeyCharacterMap() {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700686 return mKeyCharacterMap;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800687 }
688
Jeff Browne33348b2010-07-15 23:54:05 -0700689 /**
Michael Wrightb7b2d4b2013-08-19 15:55:38 -0700690 * Gets whether the device is capable of producing the list of keycodes.
691 * @param keys The list of android keycodes to check for.
692 * @return An array of booleans where each member specifies whether the device is capable of
693 * generating the keycode given by the corresponding value at the same index in the keys array.
694 */
695 public boolean[] hasKeys(int... keys) {
696 return InputManager.getInstance().deviceHasKeys(mId, keys);
697 }
698
699 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800700 * Gets information about the range of values for a particular {@link MotionEvent} axis.
Jeff Brownefd32662011-03-08 15:13:06 -0800701 * If the device supports multiple sources, the same axis may have different meanings
702 * for each source. Returns information about the first axis found for any source.
703 * To obtain information about the axis for a specific source, use
704 * {@link #getMotionRange(int, int)}.
705 *
Jeff Brown91c69ab2011-02-14 17:03:18 -0800706 * @param axis The axis constant.
707 * @return The range of values, or null if the requested axis is not
Jeff Browne33348b2010-07-15 23:54:05 -0700708 * supported by the device.
Jeff Brown91c69ab2011-02-14 17:03:18 -0800709 *
710 * @see MotionEvent#AXIS_X
711 * @see MotionEvent#AXIS_Y
Jeff Browne33348b2010-07-15 23:54:05 -0700712 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800713 public MotionRange getMotionRange(int axis) {
Jeff Brownefd32662011-03-08 15:13:06 -0800714 final int numRanges = mMotionRanges.size();
715 for (int i = 0; i < numRanges; i++) {
716 final MotionRange range = mMotionRanges.get(i);
717 if (range.mAxis == axis) {
718 return range;
719 }
720 }
721 return null;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700722 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800723
Jeff Brown6f2fba42011-02-19 01:08:02 -0800724 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800725 * Gets information about the range of values for a particular {@link MotionEvent} axis
726 * used by a particular source on the device.
727 * If the device supports multiple sources, the same axis may have different meanings
728 * for each source.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800729 *
Jeff Brownefd32662011-03-08 15:13:06 -0800730 * @param axis The axis constant.
731 * @param source The source for which to return information.
732 * @return The range of values, or null if the requested axis is not
733 * supported by the device.
734 *
735 * @see MotionEvent#AXIS_X
736 * @see MotionEvent#AXIS_Y
Jeff Brown6f2fba42011-02-19 01:08:02 -0800737 */
Jeff Brownefd32662011-03-08 15:13:06 -0800738 public MotionRange getMotionRange(int axis, int source) {
739 final int numRanges = mMotionRanges.size();
740 for (int i = 0; i < numRanges; i++) {
741 final MotionRange range = mMotionRanges.get(i);
742 if (range.mAxis == axis && range.mSource == source) {
743 return range;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800744 }
Jeff Brown6f2fba42011-02-19 01:08:02 -0800745 }
Jeff Brownefd32662011-03-08 15:13:06 -0800746 return null;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800747 }
748
Jeff Brownefd32662011-03-08 15:13:06 -0800749 /**
750 * Gets the ranges for all axes supported by the device.
751 * @return The motion ranges for the device.
752 *
753 * @see #getMotionRange(int, int)
754 */
755 public List<MotionRange> getMotionRanges() {
756 return mMotionRanges;
757 }
758
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700759 // Called from native code.
Mathew Inwooda570dee2018-08-17 14:56:00 +0100760 @UnsupportedAppUsage
Jeff Brownefd32662011-03-08 15:13:06 -0800761 private void addMotionRange(int axis, int source,
Michael Wrightc6091c62013-04-01 20:56:04 -0700762 float min, float max, float flat, float fuzz, float resolution) {
763 mMotionRanges.add(new MotionRange(axis, source, min, max, flat, fuzz, resolution));
Jeff Brownc5ed5912010-07-14 18:48:53 -0700764 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800765
Jeff Browne33348b2010-07-15 23:54:05 -0700766 /**
Jeff Browna47425a2012-04-13 04:09:27 -0700767 * Gets the vibrator service associated with the device, if there is one.
768 * Even if the device does not have a vibrator, the result is never null.
769 * Use {@link Vibrator#hasVibrator} to determine whether a vibrator is
770 * present.
771 *
772 * Note that the vibrator associated with the device may be different from
773 * the system vibrator. To obtain an instance of the system vibrator instead, call
774 * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument.
775 *
776 * @return The vibrator service associated with the device, never null.
777 */
778 public Vibrator getVibrator() {
779 synchronized (mMotionRanges) {
780 if (mVibrator == null) {
781 if (mHasVibrator) {
782 mVibrator = InputManager.getInstance().getInputDeviceVibrator(mId);
783 } else {
784 mVibrator = NullVibrator.getInstance();
785 }
786 }
787 return mVibrator;
788 }
789 }
790
791 /**
Siarhei Vishniakoua7f99b52017-03-21 17:39:40 -0700792 * Returns true if input device is enabled.
793 * @return Whether the input device is enabled.
794 */
795 public boolean isEnabled() {
796 return InputManager.getInstance().isInputDeviceEnabled(mId);
797 }
798
799 /**
800 * Enables the input device.
801 *
802 * @hide
803 */
804 @RequiresPermission(android.Manifest.permission.DISABLE_INPUT_DEVICE)
805 @TestApi
806 public void enable() {
807 InputManager.getInstance().enableInputDevice(mId);
808 }
809
810 /**
811 * Disables the input device.
812 *
813 * @hide
814 */
815 @RequiresPermission(android.Manifest.permission.DISABLE_INPUT_DEVICE)
816 @TestApi
817 public void disable() {
818 InputManager.getInstance().disableInputDevice(mId);
819 }
820
821 /**
Tim Kilbourn6d85cf22015-04-08 10:23:35 -0700822 * Reports whether the device has a built-in microphone.
823 * @return Whether the device has a built-in microphone.
824 */
Tim Kilbourn72285e52015-06-05 15:52:05 -0700825 public boolean hasMicrophone() {
826 return mHasMicrophone;
Tim Kilbourn6d85cf22015-04-08 10:23:35 -0700827 }
828
829 /**
Michael Wright7ddd1102013-05-20 15:04:55 -0700830 * Reports whether the device has a button under its touchpad
831 * @return Whether the device has a button under its touchpad
832 * @hide
833 */
834 public boolean hasButtonUnderPad() {
835 return mHasButtonUnderPad;
836 }
837
838 /**
Michael Wrighte051f6f2016-05-13 17:44:16 +0100839 * Sets the current pointer type.
840 * @param pointerType the type of the pointer icon.
Jun Mukai1db53972015-09-11 18:08:31 -0700841 * @hide
842 */
Michael Wrighte051f6f2016-05-13 17:44:16 +0100843 public void setPointerType(int pointerType) {
844 InputManager.getInstance().setPointerIconType(pointerType);
Jun Mukai1db53972015-09-11 18:08:31 -0700845 }
846
847 /**
Jun Mukaid4eaef72015-10-30 15:54:33 -0700848 * Specifies the current custom pointer.
849 * @param icon the icon data.
850 * @hide
851 */
852 public void setCustomPointerIcon(PointerIcon icon) {
853 InputManager.getInstance().setCustomPointerIcon(icon);
854 }
855
856 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800857 * Provides information about the range of values for a particular {@link MotionEvent} axis.
858 *
859 * @see InputDevice#getMotionRange(int)
Jeff Browne33348b2010-07-15 23:54:05 -0700860 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700861 public static final class MotionRange {
Jeff Brownefd32662011-03-08 15:13:06 -0800862 private int mAxis;
863 private int mSource;
Jeff Brown8d608662010-08-30 03:02:23 -0700864 private float mMin;
865 private float mMax;
866 private float mFlat;
867 private float mFuzz;
Michael Wrightc6091c62013-04-01 20:56:04 -0700868 private float mResolution;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800869
Michael Wrightc6091c62013-04-01 20:56:04 -0700870 private MotionRange(int axis, int source, float min, float max, float flat, float fuzz,
871 float resolution) {
Jeff Brownefd32662011-03-08 15:13:06 -0800872 mAxis = axis;
873 mSource = source;
Jeff Brown8d608662010-08-30 03:02:23 -0700874 mMin = min;
875 mMax = max;
876 mFlat = flat;
877 mFuzz = fuzz;
Michael Wrightc6091c62013-04-01 20:56:04 -0700878 mResolution = resolution;
Jeff Brown8d608662010-08-30 03:02:23 -0700879 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800880
Jeff Browne33348b2010-07-15 23:54:05 -0700881 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800882 * Gets the axis id.
883 * @return The axis id.
884 */
885 public int getAxis() {
886 return mAxis;
887 }
888
889 /**
890 * Gets the source for which the axis is defined.
891 * @return The source.
892 */
893 public int getSource() {
894 return mSource;
895 }
896
Michael Wright74e41562013-03-08 14:58:14 -0800897
898 /**
899 * Determines whether the event is from the given source.
900 *
901 * @param source The input source to check against. This can be a specific device type,
902 * such as {@link InputDevice#SOURCE_TOUCH_NAVIGATION}, or a more generic device class,
903 * such as {@link InputDevice#SOURCE_CLASS_POINTER}.
904 * @return Whether the event is from the given source.
905 */
906 public boolean isFromSource(int source) {
907 return (getSource() & source) == source;
908 }
909
Jeff Brownefd32662011-03-08 15:13:06 -0800910 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800911 * Gets the inclusive minimum value for the axis.
912 * @return The inclusive minimum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700913 */
914 public float getMin() {
Jeff Brown8d608662010-08-30 03:02:23 -0700915 return mMin;
Jeff Browne33348b2010-07-15 23:54:05 -0700916 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800917
Jeff Browne33348b2010-07-15 23:54:05 -0700918 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800919 * Gets the inclusive maximum value for the axis.
920 * @return The inclusive maximum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700921 */
922 public float getMax() {
Jeff Brown8d608662010-08-30 03:02:23 -0700923 return mMax;
Jeff Browne33348b2010-07-15 23:54:05 -0700924 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800925
Jeff Browne33348b2010-07-15 23:54:05 -0700926 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800927 * Gets the range of the axis (difference between maximum and minimum).
Jeff Browne33348b2010-07-15 23:54:05 -0700928 * @return The range of values.
929 */
930 public float getRange() {
Jeff Brown6f2fba42011-02-19 01:08:02 -0800931 return mMax - mMin;
Jeff Browne33348b2010-07-15 23:54:05 -0700932 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800933
Jeff Browne33348b2010-07-15 23:54:05 -0700934 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800935 * Gets the extent of the center flat position with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800936 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700937 * For example, a flat value of 8 means that the center position is between -8 and +8.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700938 * This value is mainly useful for calibrating self-centering devices.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800939 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700940 * @return The extent of the center flat position.
941 */
942 public float getFlat() {
Jeff Brown8d608662010-08-30 03:02:23 -0700943 return mFlat;
Jeff Browne33348b2010-07-15 23:54:05 -0700944 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800945
Jeff Browne33348b2010-07-15 23:54:05 -0700946 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800947 * Gets the error tolerance for input device measurements with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800948 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700949 * For example, a value of 2 indicates that the measured value may be up to +/- 2 units
950 * away from the actual value due to noise and device sensitivity limitations.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800951 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700952 * @return The error tolerance.
953 */
954 public float getFuzz() {
Jeff Brown8d608662010-08-30 03:02:23 -0700955 return mFuzz;
956 }
Michael Wrightc6091c62013-04-01 20:56:04 -0700957
958 /**
959 * Gets the resolution for input device measurements with respect to this axis.
960 * @return The resolution in units per millimeter, or units per radian for rotational axes.
961 */
962 public float getResolution() {
963 return mResolution;
964 }
Jeff Brown8d608662010-08-30 03:02:23 -0700965 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800966
Jeff Brown8d608662010-08-30 03:02:23 -0700967 @Override
968 public void writeToParcel(Parcel out, int flags) {
969 out.writeInt(mId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700970 out.writeInt(mGeneration);
Michael Wrightac6c78b2013-07-17 13:21:45 -0700971 out.writeInt(mControllerNumber);
Jeff Brown8d608662010-08-30 03:02:23 -0700972 out.writeString(mName);
Michael Wright54e56942013-08-12 16:39:59 -0700973 out.writeInt(mVendorId);
974 out.writeInt(mProductId);
Jeff Browne38fdfa2012-04-06 14:51:01 -0700975 out.writeString(mDescriptor);
Jeff Browndaa37532012-05-01 15:54:03 -0700976 out.writeInt(mIsExternal ? 1 : 0);
Jeff Brown8d608662010-08-30 03:02:23 -0700977 out.writeInt(mSources);
978 out.writeInt(mKeyboardType);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700979 mKeyCharacterMap.writeToParcel(out, flags);
Jeff Browna47425a2012-04-13 04:09:27 -0700980 out.writeInt(mHasVibrator ? 1 : 0);
Tim Kilbourn72285e52015-06-05 15:52:05 -0700981 out.writeInt(mHasMicrophone ? 1 : 0);
Michael Wright7ddd1102013-05-20 15:04:55 -0700982 out.writeInt(mHasButtonUnderPad ? 1 : 0);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800983
Jeff Brownefd32662011-03-08 15:13:06 -0800984 final int numRanges = mMotionRanges.size();
Kristian Monsen1f9dc882016-03-25 16:42:15 -0700985 out.writeInt(numRanges);
Jeff Brownefd32662011-03-08 15:13:06 -0800986 for (int i = 0; i < numRanges; i++) {
987 MotionRange range = mMotionRanges.get(i);
988 out.writeInt(range.mAxis);
989 out.writeInt(range.mSource);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800990 out.writeFloat(range.mMin);
991 out.writeFloat(range.mMax);
992 out.writeFloat(range.mFlat);
993 out.writeFloat(range.mFuzz);
Michael Wrightc6091c62013-04-01 20:56:04 -0700994 out.writeFloat(range.mResolution);
Jeff Brown8d608662010-08-30 03:02:23 -0700995 }
Jeff Brown8d608662010-08-30 03:02:23 -0700996 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800997
Jeff Brown8d608662010-08-30 03:02:23 -0700998 @Override
999 public int describeContents() {
1000 return 0;
1001 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001002
Jeff Brown8d608662010-08-30 03:02:23 -07001003 @Override
1004 public String toString() {
1005 StringBuilder description = new StringBuilder();
1006 description.append("Input Device ").append(mId).append(": ").append(mName).append("\n");
Jeff Browne38fdfa2012-04-06 14:51:01 -07001007 description.append(" Descriptor: ").append(mDescriptor).append("\n");
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001008 description.append(" Generation: ").append(mGeneration).append("\n");
Jeff Browndaa37532012-05-01 15:54:03 -07001009 description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append("\n");
Jeff Browne38fdfa2012-04-06 14:51:01 -07001010
Jeff Brown8d608662010-08-30 03:02:23 -07001011 description.append(" Keyboard Type: ");
1012 switch (mKeyboardType) {
1013 case KEYBOARD_TYPE_NONE:
1014 description.append("none");
1015 break;
1016 case KEYBOARD_TYPE_NON_ALPHABETIC:
1017 description.append("non-alphabetic");
1018 break;
1019 case KEYBOARD_TYPE_ALPHABETIC:
1020 description.append("alphabetic");
1021 break;
1022 }
1023 description.append("\n");
Jeff Brown91c69ab2011-02-14 17:03:18 -08001024
Jeff Browna47425a2012-04-13 04:09:27 -07001025 description.append(" Has Vibrator: ").append(mHasVibrator).append("\n");
1026
Tim Kilbourn72285e52015-06-05 15:52:05 -07001027 description.append(" Has mic: ").append(mHasMicrophone).append("\n");
Tim Kilbourn6d85cf22015-04-08 10:23:35 -07001028
Jeff Brownefd32662011-03-08 15:13:06 -08001029 description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
Jeff Brown8d608662010-08-30 03:02:23 -07001030 appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
1031 appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
Jeff Brown8d608662010-08-30 03:02:23 -07001032 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen");
1033 appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE, "mouse");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001034 appendSourceDescriptionIfApplicable(description, SOURCE_STYLUS, "stylus");
Jeff Brown8d608662010-08-30 03:02:23 -07001035 appendSourceDescriptionIfApplicable(description, SOURCE_TRACKBALL, "trackball");
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -08001036 appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE_RELATIVE, "mouse_relative");
Jeff Brown8d608662010-08-30 03:02:23 -07001037 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad");
Jeff Brown91c69ab2011-02-14 17:03:18 -08001038 appendSourceDescriptionIfApplicable(description, SOURCE_JOYSTICK, "joystick");
1039 appendSourceDescriptionIfApplicable(description, SOURCE_GAMEPAD, "gamepad");
1040 description.append(" )\n");
1041
1042 final int numAxes = mMotionRanges.size();
1043 for (int i = 0; i < numAxes; i++) {
Jeff Brownefd32662011-03-08 15:13:06 -08001044 MotionRange range = mMotionRanges.get(i);
1045 description.append(" ").append(MotionEvent.axisToString(range.mAxis));
1046 description.append(": source=0x").append(Integer.toHexString(range.mSource));
1047 description.append(" min=").append(range.mMin);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001048 description.append(" max=").append(range.mMax);
1049 description.append(" flat=").append(range.mFlat);
1050 description.append(" fuzz=").append(range.mFuzz);
Michael Wrightc6091c62013-04-01 20:56:04 -07001051 description.append(" resolution=").append(range.mResolution);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001052 description.append("\n");
1053 }
Jeff Brown8d608662010-08-30 03:02:23 -07001054 return description.toString();
1055 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001056
Jeff Brown8d608662010-08-30 03:02:23 -07001057 private void appendSourceDescriptionIfApplicable(StringBuilder description, int source,
1058 String sourceName) {
1059 if ((mSources & source) == source) {
1060 description.append(" ");
1061 description.append(sourceName);
1062 }
1063 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001064}