• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 android.hardware.input;
18 
19 import android.Manifest;
20 import android.annotation.FloatRange;
21 import android.annotation.IntDef;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.annotation.RequiresPermission;
25 import android.annotation.SdkConstant;
26 import android.annotation.SdkConstant.SdkConstantType;
27 import android.annotation.SystemService;
28 import android.annotation.TestApi;
29 import android.annotation.UserIdInt;
30 import android.app.ActivityThread;
31 import android.compat.annotation.ChangeId;
32 import android.compat.annotation.UnsupportedAppUsage;
33 import android.content.Context;
34 import android.hardware.BatteryState;
35 import android.os.Build;
36 import android.os.Handler;
37 import android.os.IBinder;
38 import android.os.InputEventInjectionSync;
39 import android.os.RemoteException;
40 import android.os.SystemClock;
41 import android.os.Vibrator;
42 import android.util.Log;
43 import android.view.Display;
44 import android.view.InputDevice;
45 import android.view.InputEvent;
46 import android.view.InputMonitor;
47 import android.view.KeyEvent;
48 import android.view.MotionEvent;
49 import android.view.PointerIcon;
50 import android.view.VerifiedInputEvent;
51 import android.view.WindowManager.LayoutParams;
52 import android.view.inputmethod.InputMethodInfo;
53 import android.view.inputmethod.InputMethodSubtype;
54 
55 import java.lang.annotation.Retention;
56 import java.lang.annotation.RetentionPolicy;
57 import java.util.ArrayList;
58 import java.util.List;
59 import java.util.Map;
60 import java.util.Objects;
61 import java.util.concurrent.Executor;
62 
63 /**
64  * Provides information about input devices and available key layouts.
65  */
66 @SystemService(Context.INPUT_SERVICE)
67 public final class InputManager {
68     private static final String TAG = "InputManager";
69     // To enable these logs, run: 'adb shell setprop log.tag.InputManager DEBUG' (requires restart)
70     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
71 
72     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
73     private final IInputManager mIm;
74 
75     /**
76      * Whether a PointerIcon is shown for stylus pointers.
77      * Obtain using {@link #isStylusPointerIconEnabled()}.
78      */
79     @Nullable
80     private Boolean mIsStylusPointerIconEnabled = null;
81 
82     /**
83      * Broadcast Action: Query available keyboard layouts.
84      * <p>
85      * The input manager service locates available keyboard layouts
86      * by querying broadcast receivers that are registered for this action.
87      * An application can offer additional keyboard layouts to the user
88      * by declaring a suitable broadcast receiver in its manifest.
89      * </p><p>
90      * Here is an example broadcast receiver declaration that an application
91      * might include in its AndroidManifest.xml to advertise keyboard layouts.
92      * The meta-data specifies a resource that contains a description of each keyboard
93      * layout that is provided by the application.
94      * <pre><code>
95      * &lt;receiver android:name=".InputDeviceReceiver"
96      *         android:label="@string/keyboard_layouts_label">
97      *     &lt;intent-filter>
98      *         &lt;action android:name="android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS" />
99      *     &lt;/intent-filter>
100      *     &lt;meta-data android:name="android.hardware.input.metadata.KEYBOARD_LAYOUTS"
101      *             android:resource="@xml/keyboard_layouts" />
102      * &lt;/receiver>
103      * </code></pre>
104      * </p><p>
105      * In the above example, the <code>@xml/keyboard_layouts</code> resource refers to
106      * an XML resource whose root element is <code>&lt;keyboard-layouts></code> that
107      * contains zero or more <code>&lt;keyboard-layout></code> elements.
108      * Each <code>&lt;keyboard-layout></code> element specifies the name, label, and location
109      * of a key character map for a particular keyboard layout.  The label on the receiver
110      * is used to name the collection of keyboard layouts provided by this receiver in the
111      * keyboard layout settings.
112      * <pre><code>
113      * &lt;?xml version="1.0" encoding="utf-8"?>
114      * &lt;keyboard-layouts xmlns:android="http://schemas.android.com/apk/res/android">
115      *     &lt;keyboard-layout android:name="keyboard_layout_english_us"
116      *             android:label="@string/keyboard_layout_english_us_label"
117      *             android:keyboardLayout="@raw/keyboard_layout_english_us" />
118      * &lt;/keyboard-layouts>
119      * </pre></code>
120      * </p><p>
121      * The <code>android:name</code> attribute specifies an identifier by which
122      * the keyboard layout will be known in the package.
123      * The <code>android:label</code> attribute specifies a human-readable descriptive
124      * label to describe the keyboard layout in the user interface, such as "English (US)".
125      * The <code>android:keyboardLayout</code> attribute refers to a
126      * <a href="https://source.android.com/docs/core/interaction/input/key-character-map-files">
127      * key character map</a> resource that defines the keyboard layout.
128      * The <code>android:keyboardLocale</code> attribute specifies a comma separated list of BCP 47
129      * language tags depicting the locales supported by the keyboard layout. This attribute is
130      * optional and will be used for auto layout selection for external physical keyboards.
131      * The <code>android:keyboardLayoutType</code> attribute specifies the layoutType for the
132      * keyboard layout. This can be either empty or one of the following supported layout types:
133      * qwerty, qwertz, azerty, dvorak, colemak, workman, extended, turkish_q, turkish_f. This
134      * attribute is optional and will be used for auto layout selection for external physical
135      * keyboards.
136      * </p>
137      */
138     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
139     public static final String ACTION_QUERY_KEYBOARD_LAYOUTS =
140             "android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS";
141 
142     /**
143      * Metadata Key: Keyboard layout metadata associated with
144      * {@link #ACTION_QUERY_KEYBOARD_LAYOUTS}.
145      * <p>
146      * Specifies the resource id of a XML resource that describes the keyboard
147      * layouts that are provided by the application.
148      * </p>
149      */
150     public static final String META_DATA_KEYBOARD_LAYOUTS =
151             "android.hardware.input.metadata.KEYBOARD_LAYOUTS";
152 
153     /**
154      * Prevent touches from being consumed by apps if these touches passed through a non-trusted
155      * window from a different UID and are considered unsafe.
156      *
157      * @hide
158      */
159     @TestApi
160     @ChangeId
161     public static final long BLOCK_UNTRUSTED_TOUCHES = 158002302L;
162 
163     /**
164      * Input Event Injection Synchronization Mode: None.
165      * Never blocks.  Injection is asynchronous and is assumed always to be successful.
166      * @hide
167      */
168     public static final int INJECT_INPUT_EVENT_MODE_ASYNC = InputEventInjectionSync.NONE;
169 
170     /**
171      * Input Event Injection Synchronization Mode: Wait for result.
172      * Waits for previous events to be dispatched so that the input dispatcher can
173      * determine whether input event injection will be permitted based on the current
174      * input focus.  Does not wait for the input event to finish being handled
175      * by the application.
176      * @hide
177      */
178     public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT =
179             InputEventInjectionSync.WAIT_FOR_RESULT;
180 
181     /**
182      * Input Event Injection Synchronization Mode: Wait for finish.
183      * Waits for the event to be delivered to the application and handled.
184      * @hide
185      */
186     @UnsupportedAppUsage(trackingBug = 171972397)
187     public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH =
188             InputEventInjectionSync.WAIT_FOR_FINISHED;
189 
190     /** @hide */
191     @Retention(RetentionPolicy.SOURCE)
192     @IntDef(prefix = { "SWITCH_STATE_" }, value = {
193             SWITCH_STATE_UNKNOWN,
194             SWITCH_STATE_OFF,
195             SWITCH_STATE_ON
196     })
197     public @interface SwitchState {}
198 
199     /** @hide */
200     @Retention(RetentionPolicy.SOURCE)
201     @IntDef(prefix = { "REMAPPABLE_MODIFIER_KEY_" }, value = {
202             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_CTRL_LEFT,
203             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_CTRL_RIGHT,
204             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_META_LEFT,
205             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_META_RIGHT,
206             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_ALT_LEFT,
207             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_ALT_RIGHT,
208             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_SHIFT_LEFT,
209             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_SHIFT_RIGHT,
210             RemappableModifierKey.REMAPPABLE_MODIFIER_KEY_CAPS_LOCK,
211     })
212     public @interface RemappableModifierKey {
213         int REMAPPABLE_MODIFIER_KEY_CTRL_LEFT = KeyEvent.KEYCODE_CTRL_LEFT;
214         int REMAPPABLE_MODIFIER_KEY_CTRL_RIGHT = KeyEvent.KEYCODE_CTRL_RIGHT;
215         int REMAPPABLE_MODIFIER_KEY_META_LEFT = KeyEvent.KEYCODE_META_LEFT;
216         int REMAPPABLE_MODIFIER_KEY_META_RIGHT = KeyEvent.KEYCODE_META_RIGHT;
217         int REMAPPABLE_MODIFIER_KEY_ALT_LEFT = KeyEvent.KEYCODE_ALT_LEFT;
218         int REMAPPABLE_MODIFIER_KEY_ALT_RIGHT = KeyEvent.KEYCODE_ALT_RIGHT;
219         int REMAPPABLE_MODIFIER_KEY_SHIFT_LEFT = KeyEvent.KEYCODE_SHIFT_LEFT;
220         int REMAPPABLE_MODIFIER_KEY_SHIFT_RIGHT = KeyEvent.KEYCODE_SHIFT_RIGHT;
221         int REMAPPABLE_MODIFIER_KEY_CAPS_LOCK = KeyEvent.KEYCODE_CAPS_LOCK;
222     }
223 
224     /**
225      * Switch State: Unknown.
226      *
227      * The system has yet to report a valid value for the switch.
228      * @hide
229      */
230     public static final int SWITCH_STATE_UNKNOWN = -1;
231 
232     /**
233      * Switch State: Off.
234      * @hide
235      */
236     public static final int SWITCH_STATE_OFF = 0;
237 
238     /**
239      * Switch State: On.
240      * @hide
241      */
242     public static final int SWITCH_STATE_ON = 1;
243 
244     private final InputManagerGlobal mGlobal;
245     private final Context mContext;
246 
247     /** @hide */
InputManager(Context context)248     public InputManager(Context context) {
249         mGlobal = InputManagerGlobal.getInstance();
250         mIm = mGlobal.getInputManagerService();
251         mContext = context;
252     }
253 
254     /**
255      * Gets an instance of the input manager.
256      *
257      *  Warning: The usage of this method is not supported!
258      *
259      *  @return The input manager instance.
260      *  Use {@link Context#getSystemService(Class)}
261      *  to obtain the InputManager instance.
262      *
263      * TODO (b/277717573): Soft remove this API in version V.
264      * TODO (b/277039664): Migrate app usage off this API.
265      *
266      * @hide
267      */
268     @Deprecated
269     @UnsupportedAppUsage
getInstance()270     public static InputManager getInstance() {
271         return Objects.requireNonNull(ActivityThread.currentApplication())
272                 .getSystemService(InputManager.class);
273     }
274 
275     /**
276      * Get the current VelocityTracker strategy.
277      * @hide
278      */
getVelocityTrackerStrategy()279     public String getVelocityTrackerStrategy() {
280         return mGlobal.getVelocityTrackerStrategy();
281     }
282 
283     /**
284      * Gets information about the input device with the specified id.
285      * @param id The device id.
286      * @return The input device or null if not found.
287      */
288     @Nullable
getInputDevice(int id)289     public InputDevice getInputDevice(int id) {
290         return mGlobal.getInputDevice(id);
291     }
292 
293     /**
294      * Gets information about the input device with the specified descriptor.
295      * @param descriptor The input device descriptor.
296      * @return The input device or null if not found.
297      * @hide
298      */
getInputDeviceByDescriptor(String descriptor)299     public InputDevice getInputDeviceByDescriptor(String descriptor) {
300         return mGlobal.getInputDeviceByDescriptor(descriptor);
301     }
302 
303     /**
304      * Gets the ids of all input devices in the system.
305      * @return The input device ids.
306      */
getInputDeviceIds()307     public int[] getInputDeviceIds() {
308         return mGlobal.getInputDeviceIds();
309     }
310 
311     /**
312      * Returns true if an input device is enabled. Should return true for most
313      * situations. Some system apps may disable an input device, for
314      * example to prevent unwanted touch events.
315      *
316      * @param id The input device Id.
317      *
318      * @hide
319      */
isInputDeviceEnabled(int id)320     public boolean isInputDeviceEnabled(int id) {
321         return mGlobal.isInputDeviceEnabled(id);
322     }
323 
324     /**
325      * Enables an InputDevice.
326      * <p>
327      * Requires {@link android.Manifest.permission#DISABLE_INPUT_DEVICE}.
328      * </p>
329      *
330      * @param id The input device Id.
331      *
332      * @hide
333      */
enableInputDevice(int id)334     public void enableInputDevice(int id) {
335         mGlobal.enableInputDevice(id);
336     }
337 
338     /**
339      * Disables an InputDevice.
340      * <p>
341      * Requires {@link android.Manifest.permission#DISABLE_INPUT_DEVICE}.
342      * </p>
343      *
344      * @param id The input device Id.
345      *
346      * @hide
347      */
disableInputDevice(int id)348     public void disableInputDevice(int id) {
349         mGlobal.disableInputDevice(id);
350     }
351 
352     /**
353      * Registers an input device listener to receive notifications about when
354      * input devices are added, removed or changed.
355      *
356      * @param listener The listener to register.
357      * @param handler The handler on which the listener should be invoked, or null
358      * if the listener should be invoked on the calling thread's looper.
359      *
360      * @see #unregisterInputDeviceListener
361      */
registerInputDeviceListener(InputDeviceListener listener, Handler handler)362     public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
363         mGlobal.registerInputDeviceListener(listener, handler);
364     }
365 
366     /**
367      * Unregisters an input device listener.
368      *
369      * @param listener The listener to unregister.
370      *
371      * @see #registerInputDeviceListener
372      */
unregisterInputDeviceListener(InputDeviceListener listener)373     public void unregisterInputDeviceListener(InputDeviceListener listener) {
374         mGlobal.unregisterInputDeviceListener(listener);
375     }
376 
377     /**
378      * Queries whether the device is in tablet mode.
379      *
380      * @return The tablet switch state which is one of {@link #SWITCH_STATE_UNKNOWN},
381      * {@link #SWITCH_STATE_OFF} or {@link #SWITCH_STATE_ON}.
382      * @hide
383      */
384     @SwitchState
isInTabletMode()385     public int isInTabletMode() {
386         try {
387             return mIm.isInTabletMode();
388         } catch (RemoteException ex) {
389             throw ex.rethrowFromSystemServer();
390         }
391     }
392 
393     /**
394      * Register a tablet mode changed listener.
395      *
396      * @param listener The listener to register.
397      * @param handler The handler on which the listener should be invoked, or null
398      * if the listener should be invoked on the calling thread's looper.
399      * @hide
400      */
registerOnTabletModeChangedListener( OnTabletModeChangedListener listener, Handler handler)401     public void registerOnTabletModeChangedListener(
402             OnTabletModeChangedListener listener, Handler handler) {
403         mGlobal.registerOnTabletModeChangedListener(listener, handler);
404     }
405 
406     /**
407      * Unregister a tablet mode changed listener.
408      *
409      * @param listener The listener to unregister.
410      * @hide
411      */
unregisterOnTabletModeChangedListener(OnTabletModeChangedListener listener)412     public void unregisterOnTabletModeChangedListener(OnTabletModeChangedListener listener) {
413         mGlobal.unregisterOnTabletModeChangedListener(listener);
414     }
415 
416     /**
417      * Queries whether the device's microphone is muted
418      *
419      * @return The mic mute switch state which is one of {@link #SWITCH_STATE_UNKNOWN},
420      * {@link #SWITCH_STATE_OFF} or {@link #SWITCH_STATE_ON}.
421      * @hide
422      */
423     @SwitchState
isMicMuted()424     public int isMicMuted() {
425         try {
426             return mIm.isMicMuted();
427         } catch (RemoteException ex) {
428             throw ex.rethrowFromSystemServer();
429         }
430     }
431 
432     /**
433      * Gets information about all supported keyboard layouts.
434      * <p>
435      * The input manager consults the built-in keyboard layouts as well
436      * as all keyboard layouts advertised by applications using a
437      * {@link #ACTION_QUERY_KEYBOARD_LAYOUTS} broadcast receiver.
438      * </p>
439      *
440      * @return A list of all supported keyboard layouts.
441      *
442      * @hide
443      */
getKeyboardLayouts()444     public KeyboardLayout[] getKeyboardLayouts() {
445         try {
446             return mIm.getKeyboardLayouts();
447         } catch (RemoteException ex) {
448             throw ex.rethrowFromSystemServer();
449         }
450     }
451 
452     /**
453      * Returns the descriptors of all supported keyboard layouts appropriate for the specified
454      * input device.
455      * <p>
456      * The input manager consults the built-in keyboard layouts as well as all keyboard layouts
457      * advertised by applications using a {@link #ACTION_QUERY_KEYBOARD_LAYOUTS} broadcast receiver.
458      * </p>
459      *
460      * @param device The input device to query.
461      * @return The ids of all keyboard layouts which are supported by the specified input device.
462      *
463      * @hide
464      */
465     @TestApi
466     @NonNull
getKeyboardLayoutDescriptorsForInputDevice(@onNull InputDevice device)467     public List<String> getKeyboardLayoutDescriptorsForInputDevice(@NonNull InputDevice device) {
468         KeyboardLayout[] layouts = getKeyboardLayoutsForInputDevice(device.getIdentifier());
469         List<String> res = new ArrayList<>();
470         for (KeyboardLayout kl : layouts) {
471             res.add(kl.getDescriptor());
472         }
473         return res;
474     }
475 
476     /**
477      * Returns the layout type of the queried layout
478      * <p>
479      * The input manager consults the built-in keyboard layouts as well as all keyboard layouts
480      * advertised by applications using a {@link #ACTION_QUERY_KEYBOARD_LAYOUTS} broadcast receiver.
481      * </p>
482      *
483      * @param layoutDescriptor The layout descriptor of the queried layout
484      * @return layout type of the queried layout
485      *
486      * @hide
487      */
488     @TestApi
489     @NonNull
getKeyboardLayoutTypeForLayoutDescriptor(@onNull String layoutDescriptor)490     public String getKeyboardLayoutTypeForLayoutDescriptor(@NonNull String layoutDescriptor) {
491         KeyboardLayout[] layouts = getKeyboardLayouts();
492         for (KeyboardLayout kl : layouts) {
493             if (layoutDescriptor.equals(kl.getDescriptor())) {
494                 return kl.getLayoutType();
495             }
496         }
497         return "";
498     }
499 
500     /**
501      * Gets information about all supported keyboard layouts appropriate
502      * for a specific input device.
503      * <p>
504      * The input manager consults the built-in keyboard layouts as well
505      * as all keyboard layouts advertised by applications using a
506      * {@link #ACTION_QUERY_KEYBOARD_LAYOUTS} broadcast receiver.
507      * </p>
508      *
509      * @return A list of all supported keyboard layouts for a specific
510      * input device.
511      *
512      * @hide
513      */
514     @NonNull
getKeyboardLayoutsForInputDevice( @onNull InputDeviceIdentifier identifier)515     public KeyboardLayout[] getKeyboardLayoutsForInputDevice(
516             @NonNull InputDeviceIdentifier identifier) {
517         return mGlobal.getKeyboardLayoutsForInputDevice(identifier);
518     }
519 
520     /**
521      * Gets the keyboard layout with the specified descriptor.
522      *
523      * @param keyboardLayoutDescriptor The keyboard layout descriptor, as returned by
524      * {@link KeyboardLayout#getDescriptor()}.
525      * @return The keyboard layout, or null if it could not be loaded.
526      *
527      * @hide
528      */
getKeyboardLayout(String keyboardLayoutDescriptor)529     public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) {
530         if (keyboardLayoutDescriptor == null) {
531             throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
532         }
533 
534         try {
535             return mIm.getKeyboardLayout(keyboardLayoutDescriptor);
536         } catch (RemoteException ex) {
537             throw ex.rethrowFromSystemServer();
538         }
539     }
540 
541     /**
542      * Gets the current keyboard layout descriptor for the specified input device.
543      *
544      * @param identifier Identifier for the input device
545      * @return The keyboard layout descriptor, or null if no keyboard layout has been set.
546      *
547      * @hide
548      */
549     @TestApi
550     @Nullable
getCurrentKeyboardLayoutForInputDevice( @onNull InputDeviceIdentifier identifier)551     public String getCurrentKeyboardLayoutForInputDevice(
552             @NonNull InputDeviceIdentifier identifier) {
553         try {
554             return mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
555         } catch (RemoteException ex) {
556             throw ex.rethrowFromSystemServer();
557         }
558     }
559 
560     /**
561      * Sets the current keyboard layout descriptor for the specified input device.
562      * <p>
563      * This method may have the side-effect of causing the input device in question to be
564      * reconfigured.
565      * </p>
566      *
567      * @param identifier The identifier for the input device.
568      * @param keyboardLayoutDescriptor The keyboard layout descriptor to use, must not be null.
569      *
570      * @hide
571      */
572     @TestApi
573     @RequiresPermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
setCurrentKeyboardLayoutForInputDevice(@onNull InputDeviceIdentifier identifier, @NonNull String keyboardLayoutDescriptor)574     public void setCurrentKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
575             @NonNull String keyboardLayoutDescriptor) {
576         mGlobal.setCurrentKeyboardLayoutForInputDevice(identifier,
577                 keyboardLayoutDescriptor);
578     }
579 
580     /**
581      * Gets all keyboard layout descriptors that are enabled for the specified input device.
582      *
583      * @param identifier The identifier for the input device.
584      * @return The keyboard layout descriptors.
585      *
586      * @hide
587      */
getEnabledKeyboardLayoutsForInputDevice(InputDeviceIdentifier identifier)588     public String[] getEnabledKeyboardLayoutsForInputDevice(InputDeviceIdentifier identifier) {
589         if (identifier == null) {
590             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
591         }
592 
593         try {
594             return mIm.getEnabledKeyboardLayoutsForInputDevice(identifier);
595         } catch (RemoteException ex) {
596             throw ex.rethrowFromSystemServer();
597         }
598     }
599 
600     /**
601      * Adds the keyboard layout descriptor for the specified input device.
602      * <p>
603      * This method may have the side-effect of causing the input device in question to be
604      * reconfigured.
605      * </p>
606      *
607      * @param identifier The identifier for the input device.
608      * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to add.
609      *
610      * @hide
611      */
612     @RequiresPermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
addKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier, String keyboardLayoutDescriptor)613     public void addKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
614             String keyboardLayoutDescriptor) {
615         if (identifier == null) {
616             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
617         }
618         if (keyboardLayoutDescriptor == null) {
619             throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
620         }
621 
622         try {
623             mIm.addKeyboardLayoutForInputDevice(identifier, keyboardLayoutDescriptor);
624         } catch (RemoteException ex) {
625             throw ex.rethrowFromSystemServer();
626         }
627     }
628 
629     /**
630      * Removes the keyboard layout descriptor for the specified input device.
631      * <p>
632      * This method may have the side-effect of causing the input device in question to be
633      * reconfigured.
634      * </p>
635      *
636      * @param identifier The identifier for the input device.
637      * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to remove.
638      *
639      * @hide
640      */
641     @TestApi
642     @RequiresPermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
removeKeyboardLayoutForInputDevice(@onNull InputDeviceIdentifier identifier, @NonNull String keyboardLayoutDescriptor)643     public void removeKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
644             @NonNull String keyboardLayoutDescriptor) {
645         if (identifier == null) {
646             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
647         }
648         if (keyboardLayoutDescriptor == null) {
649             throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
650         }
651 
652         try {
653             mIm.removeKeyboardLayoutForInputDevice(identifier, keyboardLayoutDescriptor);
654         } catch (RemoteException ex) {
655             throw ex.rethrowFromSystemServer();
656         }
657     }
658 
659     /**
660      * Remaps modifier keys. Remapping a modifier key to itself will clear any previous remappings
661      * for that key.
662      *
663      * @param fromKey The modifier key getting remapped.
664      * @param toKey The modifier key that it is remapped to.
665      *
666      * @hide
667      */
668     @TestApi
669     @RequiresPermission(Manifest.permission.REMAP_MODIFIER_KEYS)
remapModifierKey(@emappableModifierKey int fromKey, @RemappableModifierKey int toKey)670     public void remapModifierKey(@RemappableModifierKey int fromKey,
671             @RemappableModifierKey int toKey) {
672         try {
673             mIm.remapModifierKey(fromKey, toKey);
674         } catch (RemoteException ex) {
675             throw ex.rethrowFromSystemServer();
676         }
677     }
678 
679     /**
680      * Clears all existing modifier key remappings
681      *
682      * @hide
683      */
684     @TestApi
685     @RequiresPermission(Manifest.permission.REMAP_MODIFIER_KEYS)
clearAllModifierKeyRemappings()686     public void clearAllModifierKeyRemappings() {
687         try {
688             mIm.clearAllModifierKeyRemappings();
689         } catch (RemoteException ex) {
690             throw ex.rethrowFromSystemServer();
691         }
692     }
693 
694     /**
695      * Provides the current modifier key remapping
696      *
697      * @return a {fromKey, toKey} map that contains the existing modifier key remappings..
698      * {@link RemappableModifierKey}
699      *
700      * @hide
701      */
702     @TestApi
703     @NonNull
704     @SuppressWarnings("unchecked")
705     @RequiresPermission(Manifest.permission.REMAP_MODIFIER_KEYS)
getModifierKeyRemapping()706     public Map<Integer, Integer> getModifierKeyRemapping() {
707         try {
708             return mIm.getModifierKeyRemapping();
709         } catch (RemoteException ex) {
710             throw ex.rethrowFromSystemServer();
711         }
712     }
713 
714     /**
715      * Gets the TouchCalibration applied to the specified input device's coordinates.
716      *
717      * @param inputDeviceDescriptor The input device descriptor.
718      * @return The TouchCalibration currently assigned for use with the given
719      * input device. If none is set, an identity TouchCalibration is returned.
720      *
721      * @hide
722      */
getTouchCalibration(String inputDeviceDescriptor, int surfaceRotation)723     public TouchCalibration getTouchCalibration(String inputDeviceDescriptor, int surfaceRotation) {
724         try {
725             return mIm.getTouchCalibrationForInputDevice(inputDeviceDescriptor, surfaceRotation);
726         } catch (RemoteException ex) {
727             throw ex.rethrowFromSystemServer();
728         }
729     }
730 
731     /**
732      * Sets the TouchCalibration to apply to the specified input device's coordinates.
733      * <p>
734      * This method may have the side-effect of causing the input device in question
735      * to be reconfigured. Requires {@link android.Manifest.permission#SET_INPUT_CALIBRATION}.
736      * </p>
737      *
738      * @param inputDeviceDescriptor The input device descriptor.
739      * @param calibration The calibration to be applied
740      *
741      * @hide
742      */
setTouchCalibration(String inputDeviceDescriptor, int surfaceRotation, TouchCalibration calibration)743     public void setTouchCalibration(String inputDeviceDescriptor, int surfaceRotation,
744             TouchCalibration calibration) {
745         try {
746             mIm.setTouchCalibrationForInputDevice(inputDeviceDescriptor, surfaceRotation, calibration);
747         } catch (RemoteException ex) {
748             throw ex.rethrowFromSystemServer();
749         }
750     }
751 
752     /**
753      * Gets the keyboard layout descriptor for the specified input device, userId, imeInfo and
754      * imeSubtype.
755      *
756      * @param identifier Identifier for the input device
757      * @param userId user profile ID
758      * @param imeInfo contains IME information like imeId, etc.
759      * @param imeSubtype contains IME subtype information like input languageTag, layoutType, etc.
760      * @return The keyboard layout descriptor, or null if no keyboard layout has been set.
761      *
762      * @hide
763      */
764     @Nullable
getKeyboardLayoutForInputDevice(@onNull InputDeviceIdentifier identifier, @UserIdInt int userId, @NonNull InputMethodInfo imeInfo, @Nullable InputMethodSubtype imeSubtype)765     public String getKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
766             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
767             @Nullable InputMethodSubtype imeSubtype) {
768         try {
769             return mIm.getKeyboardLayoutForInputDevice(identifier, userId, imeInfo, imeSubtype);
770         } catch (RemoteException ex) {
771             throw ex.rethrowFromSystemServer();
772         }
773     }
774 
775     /**
776      * Sets the keyboard layout descriptor for the specified input device, userId, imeInfo and
777      * imeSubtype.
778      *
779      * <p>
780      * This method may have the side-effect of causing the input device in question to be
781      * reconfigured.
782      * </p>
783      *
784      * @param identifier The identifier for the input device.
785      * @param userId user profile ID
786      * @param imeInfo contains IME information like imeId, etc.
787      * @param imeSubtype contains IME subtype information like input languageTag, layoutType, etc.
788      * @param keyboardLayoutDescriptor The keyboard layout descriptor to use, must not be null.
789      *
790      * @hide
791      */
792     @RequiresPermission(Manifest.permission.SET_KEYBOARD_LAYOUT)
setKeyboardLayoutForInputDevice(@onNull InputDeviceIdentifier identifier, @UserIdInt int userId, @NonNull InputMethodInfo imeInfo, @Nullable InputMethodSubtype imeSubtype, @NonNull String keyboardLayoutDescriptor)793     public void setKeyboardLayoutForInputDevice(@NonNull InputDeviceIdentifier identifier,
794             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
795             @Nullable InputMethodSubtype imeSubtype, @NonNull String keyboardLayoutDescriptor) {
796         if (identifier == null) {
797             throw new IllegalArgumentException("identifier must not be null");
798         }
799         if (keyboardLayoutDescriptor == null) {
800             throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
801         }
802 
803         try {
804             mIm.setKeyboardLayoutForInputDevice(identifier, userId, imeInfo, imeSubtype,
805                     keyboardLayoutDescriptor);
806         } catch (RemoteException ex) {
807             throw ex.rethrowFromSystemServer();
808         }
809     }
810 
811     /**
812      * Gets all keyboard layouts that are enabled for the specified input device, userId, imeInfo
813      * and imeSubtype.
814      *
815      * @param identifier The identifier for the input device.
816      * @param userId user profile ID
817      * @param imeInfo contains IME information like imeId, etc.
818      * @param imeSubtype contains IME subtype information like input languageTag, layoutType, etc.
819      * @return The keyboard layout descriptors.
820      *
821      * @hide
822      */
getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier, @UserIdInt int userId, @NonNull InputMethodInfo imeInfo, @Nullable InputMethodSubtype imeSubtype)823     public KeyboardLayout[] getKeyboardLayoutListForInputDevice(InputDeviceIdentifier identifier,
824             @UserIdInt int userId, @NonNull InputMethodInfo imeInfo,
825             @Nullable InputMethodSubtype imeSubtype) {
826         if (identifier == null) {
827             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
828         }
829 
830         try {
831             return mIm.getKeyboardLayoutListForInputDevice(identifier, userId, imeInfo, imeSubtype);
832         } catch (RemoteException ex) {
833             throw ex.rethrowFromSystemServer();
834         }
835     }
836 
837     /**
838      * Changes the mouse pointer speed temporarily, but does not save the setting.
839      * <p>
840      * Requires {@link android.Manifest.permission#SET_POINTER_SPEED}.
841      * </p>
842      *
843      * @param speed The pointer speed as a value between {@link InputSettings#MIN_POINTER_SPEED} and
844      * {@link InputSettings#MAX_POINTER_SPEED}, or the default value {@link InputSettings#DEFAULT_POINTER_SPEED}.
845      *
846      * @hide
847      */
tryPointerSpeed(int speed)848     public void tryPointerSpeed(int speed) {
849         if (speed < InputSettings.MIN_POINTER_SPEED || speed > InputSettings.MAX_POINTER_SPEED) {
850             throw new IllegalArgumentException("speed out of range");
851         }
852 
853         try {
854             mIm.tryPointerSpeed(speed);
855         } catch (RemoteException ex) {
856             throw ex.rethrowFromSystemServer();
857         }
858     }
859 
860     /**
861      * Returns the maximum allowed obscuring opacity per UID to propagate touches.
862      *
863      * <p>For certain window types (eg. {@link LayoutParams#TYPE_APPLICATION_OVERLAY}), the decision
864      * of honoring {@link LayoutParams#FLAG_NOT_TOUCHABLE} or not depends on the combined obscuring
865      * opacity of the windows above the touch-consuming window, per UID. Check documentation of
866      * {@link LayoutParams#FLAG_NOT_TOUCHABLE} for more details.
867      *
868      * <p>The value returned is between 0 (inclusive) and 1 (inclusive).
869      *
870      * @see LayoutParams#FLAG_NOT_TOUCHABLE
871      */
872     @FloatRange(from = 0, to = 1)
getMaximumObscuringOpacityForTouch()873     public float getMaximumObscuringOpacityForTouch() {
874         return InputSettings.getMaximumObscuringOpacityForTouch(mContext);
875     }
876 
877     /**
878      * Queries the framework about whether any physical keys exist on any currently attached input
879      * devices that are capable of producing the given array of key codes.
880      *
881      * @param keyCodes The array of key codes to query.
882      * @return A new array of the same size as the key codes array whose elements
883      * are set to true if at least one attached keyboard supports the corresponding key code
884      * at the same index in the key codes array.
885      *
886      * @hide
887      */
deviceHasKeys(int[] keyCodes)888     public boolean[] deviceHasKeys(int[] keyCodes) {
889         return deviceHasKeys(-1, keyCodes);
890     }
891 
892     /**
893      * Queries the framework about whether any physical keys exist on the specified input device
894      * that are capable of producing the given array of key codes.
895      *
896      * @param id The id of the input device to query or -1 to consult all devices.
897      * @param keyCodes The array of key codes to query.
898      * @return A new array of the same size as the key codes array whose elements are set to true
899      * if the given device could produce the corresponding key code at the same index in the key
900      * codes array.
901      *
902      * @hide
903      */
deviceHasKeys(int id, int[] keyCodes)904     public boolean[] deviceHasKeys(int id, int[] keyCodes) {
905         return mGlobal.deviceHasKeys(id, keyCodes);
906     }
907 
908     /**
909      * Gets the {@link android.view.KeyEvent key code} produced by the given location on a reference
910      * QWERTY keyboard layout.
911      * <p>
912      * This API is useful for querying the physical location of keys that change the character
913      * produced based on the current locale and keyboard layout.
914      * <p>
915      * @see InputDevice#getKeyCodeForKeyLocation(int) for examples.
916      *
917      * @param locationKeyCode The location of a key specified as a key code on the QWERTY layout.
918      * This provides a consistent way of referring to the physical location of a key independently
919      * of the current keyboard layout. Also see the
920      * <a href="https://www.w3.org/TR/2017/CR-uievents-code-20170601/#key-alphanumeric-writing-system">
921      * hypothetical keyboard</a> provided by the W3C, which may be helpful for identifying the
922      * physical location of a key.
923      * @return The key code produced by the key at the specified location, given the current
924      * keyboard layout. Returns {@link KeyEvent#KEYCODE_UNKNOWN} if the device does not specify
925      * {@link InputDevice#SOURCE_KEYBOARD} or the requested mapping cannot be determined.
926      *
927      * @hide
928      */
getKeyCodeForKeyLocation(int deviceId, int locationKeyCode)929     public int getKeyCodeForKeyLocation(int deviceId, int locationKeyCode) {
930         return mGlobal.getKeyCodeForKeyLocation(deviceId, locationKeyCode);
931     }
932 
933     /**
934      * Injects an input event into the event system, targeting windows owned by the provided uid.
935      *
936      * If a valid targetUid is provided, the system will only consider injecting the input event
937      * into windows owned by the provided uid. If the input event is targeted at a window that is
938      * not owned by the provided uid, input injection will fail and a RemoteException will be
939      * thrown.
940      *
941      * The synchronization mode determines whether the method blocks while waiting for
942      * input injection to proceed.
943      * <p>
944      * Requires the {@link android.Manifest.permission#INJECT_EVENTS} permission.
945      * </p><p>
946      * Make sure you correctly set the event time and input source of the event
947      * before calling this method.
948      * </p>
949      *
950      * @param event The event to inject.
951      * @param mode The synchronization mode.  One of:
952      * {@link android.os.InputEventInjectionSync#NONE},
953      * {@link android.os.InputEventInjectionSync#WAIT_FOR_RESULT}, or
954      * {@link android.os.InputEventInjectionSync#WAIT_FOR_FINISHED}.
955      * @param targetUid The uid to target, or {@link android.os.Process#INVALID_UID} to target all
956      *                 windows.
957      * @return True if input event injection succeeded.
958      *
959      * @hide
960      */
961     @RequiresPermission(Manifest.permission.INJECT_EVENTS)
injectInputEvent(InputEvent event, int mode, int targetUid)962     public boolean injectInputEvent(InputEvent event, int mode, int targetUid) {
963         return mGlobal.injectInputEvent(event, mode, targetUid);
964     }
965 
966     /**
967      * Injects an input event into the event system on behalf of an application.
968      * The synchronization mode determines whether the method blocks while waiting for
969      * input injection to proceed.
970      * <p>
971      * Requires the {@link android.Manifest.permission#INJECT_EVENTS} permission.
972      * </p><p>
973      * Make sure you correctly set the event time and input source of the event
974      * before calling this method.
975      * </p>
976      *
977      * @param event The event to inject.
978      * @param mode The synchronization mode.  One of:
979      * {@link android.os.InputEventInjectionSync#NONE},
980      * {@link android.os.InputEventInjectionSync#WAIT_FOR_RESULT}, or
981      * {@link android.os.InputEventInjectionSync#WAIT_FOR_FINISHED}.
982      * @return True if input event injection succeeded.
983      *
984      * @hide
985      */
986     @RequiresPermission(Manifest.permission.INJECT_EVENTS)
987     @UnsupportedAppUsage
injectInputEvent(InputEvent event, int mode)988     public boolean injectInputEvent(InputEvent event, int mode) {
989         return mGlobal.injectInputEvent(event, mode);
990     }
991 
992     /**
993      * Verify the details of an {@link android.view.InputEvent} that came from the system.
994      * If the event did not come from the system, or its details could not be verified, then this
995      * will return {@code null}. Receiving {@code null} does not mean that the event did not
996      * originate from the system, just that we were unable to verify it. This can
997      * happen for a number of reasons during normal operation.
998      *
999      * @param event The {@link android.view.InputEvent} to check
1000      *
1001      * @return {@link android.view.VerifiedInputEvent}, which is a subset of the provided
1002      * {@link android.view.InputEvent}
1003      *         {@code null} if the event could not be verified.
1004      */
1005     @Nullable
verifyInputEvent(@onNull InputEvent event)1006     public VerifiedInputEvent verifyInputEvent(@NonNull InputEvent event) {
1007         try {
1008             return mIm.verifyInputEvent(event);
1009         } catch (RemoteException ex) {
1010             throw ex.rethrowFromSystemServer();
1011         }
1012     }
1013 
1014     /**
1015      * Changes the mouse pointer's icon shape into the specified id.
1016      *
1017      * @param iconId The id of the pointer graphic, as a value between
1018      * {@link PointerIcon#TYPE_ARROW} and {@link PointerIcon#TYPE_HANDWRITING}.
1019      *
1020      * @hide
1021      */
1022     @UnsupportedAppUsage
setPointerIconType(int iconId)1023     public void setPointerIconType(int iconId) {
1024         mGlobal.setPointerIconType(iconId);
1025     }
1026 
1027     /** @hide */
setCustomPointerIcon(PointerIcon icon)1028     public void setCustomPointerIcon(PointerIcon icon) {
1029         mGlobal.setCustomPointerIcon(icon);
1030     }
1031 
1032     /**
1033      * Check if showing a {@link android.view.PointerIcon} for styluses is enabled.
1034      *
1035      * @return true if a pointer icon will be shown over the location of a
1036      * stylus pointer, false if there is no pointer icon shown for styluses.
1037      */
isStylusPointerIconEnabled()1038     public boolean isStylusPointerIconEnabled() {
1039         if (mIsStylusPointerIconEnabled == null) {
1040             mIsStylusPointerIconEnabled = InputSettings.isStylusPointerIconEnabled(mContext);
1041         }
1042         return mIsStylusPointerIconEnabled;
1043     }
1044 
1045     /**
1046      * Request or release pointer capture.
1047      * <p>
1048      * When in capturing mode, the pointer icon disappears and all mouse events are dispatched to
1049      * the window which has requested the capture. Relative position changes are available through
1050      * {@link MotionEvent#getX} and {@link MotionEvent#getY}.
1051      *
1052      * @param enable true when requesting pointer capture, false when releasing.
1053      *
1054      * @hide
1055      */
requestPointerCapture(IBinder windowToken, boolean enable)1056     public void requestPointerCapture(IBinder windowToken, boolean enable) {
1057         mGlobal.requestPointerCapture(windowToken, enable);
1058     }
1059 
1060     /**
1061      * Monitor input on the specified display for gestures.
1062      *
1063      * @hide
1064      */
monitorGestureInput(String name, int displayId)1065     public InputMonitor monitorGestureInput(String name, int displayId) {
1066         return mGlobal.monitorGestureInput(name, displayId);
1067     }
1068 
1069     /**
1070      * Get sensors information as list.
1071      *
1072      * @hide
1073      */
getSensorList(int deviceId)1074     public InputSensorInfo[] getSensorList(int deviceId) {
1075         return mGlobal.getSensorList(deviceId);
1076     }
1077 
1078     /**
1079      * Enable input device sensor
1080      *
1081      * @hide
1082      */
enableSensor(int deviceId, int sensorType, int samplingPeriodUs, int maxBatchReportLatencyUs)1083     public boolean enableSensor(int deviceId, int sensorType, int samplingPeriodUs,
1084             int maxBatchReportLatencyUs) {
1085         return mGlobal.enableSensor(deviceId, sensorType, samplingPeriodUs,
1086                 maxBatchReportLatencyUs);
1087     }
1088 
1089     /**
1090      * Enable input device sensor
1091      *
1092      * @hide
1093      */
disableSensor(int deviceId, int sensorType)1094     public void disableSensor(int deviceId, int sensorType) {
1095         mGlobal.disableSensor(deviceId, sensorType);
1096     }
1097 
1098     /**
1099      * Flush input device sensor
1100      *
1101      * @hide
1102      */
flushSensor(int deviceId, int sensorType)1103     public boolean flushSensor(int deviceId, int sensorType) {
1104         return mGlobal.flushSensor(deviceId, sensorType);
1105     }
1106 
1107     /**
1108      * Register input device sensor listener
1109      *
1110      * @hide
1111      */
registerSensorListener(IInputSensorEventListener listener)1112     public boolean registerSensorListener(IInputSensorEventListener listener) {
1113         return mGlobal.registerSensorListener(listener);
1114     }
1115 
1116     /**
1117      * Unregister input device sensor listener
1118      *
1119      * @hide
1120      */
unregisterSensorListener(IInputSensorEventListener listener)1121     public void unregisterSensorListener(IInputSensorEventListener listener) {
1122         mGlobal.unregisterSensorListener(listener);
1123     }
1124 
1125     /**
1126      * Add a runtime association between the input port and the display port. This overrides any
1127      * static associations.
1128      * @param inputPort The port of the input device.
1129      * @param displayPort The physical port of the associated display.
1130      * <p>
1131      * Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
1132      * </p>
1133      * @hide
1134      */
addPortAssociation(@onNull String inputPort, int displayPort)1135     public void addPortAssociation(@NonNull String inputPort, int displayPort) {
1136         try {
1137             mIm.addPortAssociation(inputPort, displayPort);
1138         } catch (RemoteException ex) {
1139             throw ex.rethrowFromSystemServer();
1140         }
1141     }
1142 
1143     /**
1144      * Remove the runtime association between the input port and the display port. Any existing
1145      * static association for the cleared input port will be restored.
1146      * @param inputPort The port of the input device to be cleared.
1147      * <p>
1148      * Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
1149      * </p>
1150      * @hide
1151      */
removePortAssociation(@onNull String inputPort)1152     public void removePortAssociation(@NonNull String inputPort) {
1153         try {
1154             mIm.removePortAssociation(inputPort);
1155         } catch (RemoteException ex) {
1156             throw ex.rethrowFromSystemServer();
1157         }
1158     }
1159 
1160     /**
1161      * Add a runtime association between the input port and display, by unique id. Input ports are
1162      * expected to be unique.
1163      * @param inputPort The port of the input device.
1164      * @param displayUniqueId The unique id of the associated display.
1165      * <p>
1166      * Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
1167      * </p>
1168      * @hide
1169      */
1170     @TestApi
addUniqueIdAssociation(@onNull String inputPort, @NonNull String displayUniqueId)1171     public void addUniqueIdAssociation(@NonNull String inputPort,
1172             @NonNull String displayUniqueId) {
1173         mGlobal.addUniqueIdAssociation(inputPort, displayUniqueId);
1174     }
1175 
1176     /**
1177      * Removes a runtime association between the input device and display.
1178      * @param inputPort The port of the input device.
1179      * <p>
1180      * Requires {@link android.Manifest.permission#ASSOCIATE_INPUT_DEVICE_TO_DISPLAY}.
1181      * </p>
1182      * @hide
1183      */
1184     @TestApi
removeUniqueIdAssociation(@onNull String inputPort)1185     public void removeUniqueIdAssociation(@NonNull String inputPort) {
1186         mGlobal.removeUniqueIdAssociation(inputPort);
1187     }
1188 
1189     /**
1190      * Reports the version of the Universal Stylus Initiative (USI) protocol supported by the given
1191      * display, if any.
1192      *
1193      * @return the USI version supported by the display, or null if the device does not support USI
1194      * @see <a href="https://universalstylus.org">Universal Stylus Initiative</a>
1195      */
1196     @Nullable
getHostUsiVersion(@onNull Display display)1197     public HostUsiVersion getHostUsiVersion(@NonNull Display display) {
1198         return mGlobal.getHostUsiVersion(display);
1199     }
1200 
1201     /**
1202      * Returns the Bluetooth address of this input device, if known.
1203      *
1204      * The returned string is always null if this input device is not connected
1205      * via Bluetooth, or if the Bluetooth address of the device cannot be
1206      * determined. The returned address will look like: "11:22:33:44:55:66".
1207      * @hide
1208      */
1209     @RequiresPermission(Manifest.permission.BLUETOOTH)
1210     @Nullable
getInputDeviceBluetoothAddress(int deviceId)1211     public String getInputDeviceBluetoothAddress(int deviceId) {
1212         return mGlobal.getInputDeviceBluetoothAddress(deviceId);
1213     }
1214 
1215     /**
1216      * Gets a vibrator service associated with an input device, always creates a new instance.
1217      * @return The vibrator, never null.
1218      * @hide
1219      */
getInputDeviceVibrator(int deviceId, int vibratorId)1220     public Vibrator getInputDeviceVibrator(int deviceId, int vibratorId) {
1221         return new InputDeviceVibrator(deviceId, vibratorId);
1222     }
1223 
1224     /**
1225      * Cancel all ongoing pointer gestures on all displays.
1226      * @hide
1227      */
cancelCurrentTouch()1228     public void cancelCurrentTouch() {
1229         mGlobal.cancelCurrentTouch();
1230     }
1231 
1232     /**
1233      * Pilfer pointers from an input channel.
1234      *
1235      * Takes all the current pointer event streams that are currently being sent to the given
1236      * input channel and generates appropriate cancellations for all other windows that are
1237      * receiving these pointers.
1238      *
1239      * This API is intended to be used in conjunction with spy windows. When a spy window pilfers
1240      * pointers, the foreground windows and all other spy windows that are receiving any of the
1241      * pointers that are currently being dispatched to the pilfering window will have those pointers
1242      * canceled. Only the pilfering window will continue to receive events for the affected pointers
1243      * until the pointer is lifted.
1244      *
1245      * This method should be used with caution as unexpected pilfering can break fundamental user
1246      * interactions.
1247      *
1248      * @see android.os.InputConfig#SPY
1249      * @hide
1250      */
1251     @RequiresPermission(Manifest.permission.MONITOR_INPUT)
pilferPointers(IBinder inputChannelToken)1252     public void pilferPointers(IBinder inputChannelToken) {
1253         mGlobal.pilferPointers(inputChannelToken);
1254     }
1255 
1256     /**
1257      * Adds a battery listener to be notified about {@link BatteryState} changes for an input
1258      * device. The same listener can be registered for multiple input devices.
1259      * The listener will be notified of the initial battery state of the device after it is
1260      * successfully registered.
1261      * @param deviceId the input device that should be monitored
1262      * @param executor an executor on which the callback will be called
1263      * @param listener the {@link InputDeviceBatteryListener}
1264      * @see #removeInputDeviceBatteryListener(int, InputDeviceBatteryListener)
1265      * @hide
1266      */
addInputDeviceBatteryListener(int deviceId, @NonNull Executor executor, @NonNull InputDeviceBatteryListener listener)1267     public void addInputDeviceBatteryListener(int deviceId, @NonNull Executor executor,
1268             @NonNull InputDeviceBatteryListener listener) {
1269         mGlobal.addInputDeviceBatteryListener(deviceId, executor, listener);
1270     }
1271 
1272     /**
1273      * Removes a previously registered battery listener for an input device.
1274      * @see #addInputDeviceBatteryListener(int, Executor, InputDeviceBatteryListener)
1275      * @hide
1276      */
removeInputDeviceBatteryListener(int deviceId, @NonNull InputDeviceBatteryListener listener)1277     public void removeInputDeviceBatteryListener(int deviceId,
1278             @NonNull InputDeviceBatteryListener listener) {
1279         mGlobal.removeInputDeviceBatteryListener(deviceId, listener);
1280     }
1281 
1282     /**
1283      * Whether there is a gesture-compatible touchpad connected to the device.
1284      * @hide
1285      */
areTouchpadGesturesAvailable(@onNull Context context)1286     public boolean areTouchpadGesturesAvailable(@NonNull Context context) {
1287         // TODO: implement the right logic
1288         return true;
1289     }
1290 
1291     /**
1292      * Registers a Keyboard backlight change listener to be notified about {@link
1293      * KeyboardBacklightState} changes for connected keyboard devices.
1294      *
1295      * @param executor an executor on which the callback will be called
1296      * @param listener the {@link KeyboardBacklightListener}
1297      * @hide
1298      * @see #unregisterKeyboardBacklightListener(KeyboardBacklightListener)
1299      * @throws IllegalArgumentException if {@code listener} has already been registered previously.
1300      * @throws NullPointerException if {@code listener} or {@code executor} is null.
1301      */
1302     @RequiresPermission(Manifest.permission.MONITOR_KEYBOARD_BACKLIGHT)
registerKeyboardBacklightListener(@onNull Executor executor, @NonNull KeyboardBacklightListener listener)1303     public void registerKeyboardBacklightListener(@NonNull Executor executor,
1304             @NonNull KeyboardBacklightListener listener) throws IllegalArgumentException {
1305         mGlobal.registerKeyboardBacklightListener(executor, listener);
1306     }
1307 
1308     /**
1309      * Unregisters a previously added Keyboard backlight change listener.
1310      *
1311      * @param listener the {@link KeyboardBacklightListener}
1312      * @see #registerKeyboardBacklightListener(Executor, KeyboardBacklightListener)
1313      * @hide
1314      */
1315     @RequiresPermission(Manifest.permission.MONITOR_KEYBOARD_BACKLIGHT)
unregisterKeyboardBacklightListener( @onNull KeyboardBacklightListener listener)1316     public void unregisterKeyboardBacklightListener(
1317             @NonNull KeyboardBacklightListener listener) {
1318         mGlobal.unregisterKeyboardBacklightListener(listener);
1319     }
1320 
1321     /**
1322      * A callback used to be notified about battery state changes for an input device. The
1323      * {@link #onBatteryStateChanged(int, long, BatteryState)} method will be called once after the
1324      * listener is successfully registered to provide the initial battery state of the device.
1325      * @see InputDevice#getBatteryState()
1326      * @see #addInputDeviceBatteryListener(int, Executor, InputDeviceBatteryListener)
1327      * @see #removeInputDeviceBatteryListener(int, InputDeviceBatteryListener)
1328      * @hide
1329      */
1330     public interface InputDeviceBatteryListener {
1331         /**
1332          * Called when the battery state of an input device changes.
1333          * @param deviceId the input device for which the battery changed.
1334          * @param eventTimeMillis the time (in ms) when the battery change took place.
1335          *        This timestamp is in the {@link SystemClock#uptimeMillis()} time base.
1336          * @param batteryState the new battery state, never null.
1337          */
onBatteryStateChanged( int deviceId, long eventTimeMillis, @NonNull BatteryState batteryState)1338         void onBatteryStateChanged(
1339                 int deviceId, long eventTimeMillis, @NonNull BatteryState batteryState);
1340     }
1341 
1342     /**
1343      * Listens for changes in input devices.
1344      */
1345     public interface InputDeviceListener {
1346         /**
1347          * Called whenever an input device has been added to the system.
1348          * Use {@link InputManagerGlobal#getInputDevice} to get more information about the device.
1349          *
1350          * @param deviceId The id of the input device that was added.
1351          */
onInputDeviceAdded(int deviceId)1352         void onInputDeviceAdded(int deviceId);
1353 
1354         /**
1355          * Called whenever an input device has been removed from the system.
1356          *
1357          * @param deviceId The id of the input device that was removed.
1358          */
onInputDeviceRemoved(int deviceId)1359         void onInputDeviceRemoved(int deviceId);
1360 
1361         /**
1362          * Called whenever the properties of an input device have changed since they
1363          * were last queried.  Use {@link InputManager#getInputDevice} to get
1364          * a fresh {@link InputDevice} object with the new properties.
1365          *
1366          * @param deviceId The id of the input device that changed.
1367          */
onInputDeviceChanged(int deviceId)1368         void onInputDeviceChanged(int deviceId);
1369     }
1370 
1371     /** @hide */
1372     public interface OnTabletModeChangedListener {
1373         /**
1374          * Called whenever the device goes into or comes out of tablet mode.
1375          *
1376          * @param whenNanos The time at which the device transitioned into or
1377          * out of tablet mode. This is given in nanoseconds in the
1378          * {@link SystemClock#uptimeMillis} time base.
1379          */
onTabletModeChanged(long whenNanos, boolean inTabletMode)1380         void onTabletModeChanged(long whenNanos, boolean inTabletMode);
1381     }
1382 
1383     /**
1384      * A callback used to be notified about keyboard backlight state changes for keyboard device.
1385      * The {@link #onKeyboardBacklightChanged(int, KeyboardBacklightState, boolean)} method
1386      * will be called once after the listener is successfully registered to provide the initial
1387      * keyboard backlight state of the device.
1388      * @see #registerKeyboardBacklightListener(Executor, KeyboardBacklightListener)
1389      * @see #unregisterKeyboardBacklightListener(KeyboardBacklightListener)
1390      * @hide
1391      */
1392     public interface KeyboardBacklightListener {
1393         /**
1394          * Called when the keyboard backlight brightness level changes.
1395          * @param deviceId the keyboard for which the backlight brightness changed.
1396          * @param state the new keyboard backlight state, never null.
1397          * @param isTriggeredByKeyPress whether brightness change was triggered by the user
1398          *                              pressing up/down key on the keyboard.
1399          */
onKeyboardBacklightChanged( int deviceId, @NonNull KeyboardBacklightState state, boolean isTriggeredByKeyPress)1400         void onKeyboardBacklightChanged(
1401                 int deviceId, @NonNull KeyboardBacklightState state, boolean isTriggeredByKeyPress);
1402     }
1403 }
1404