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.graphics.Rect;
20 import android.hardware.input.HostUsiVersion;
21 import android.hardware.input.InputDeviceIdentifier;
22 import android.hardware.input.KeyboardLayout;
23 import android.hardware.input.IInputDevicesChangedListener;
24 import android.hardware.input.IInputDeviceBatteryListener;
25 import android.hardware.input.IInputDeviceBatteryState;
26 import android.hardware.input.IKeyboardBacklightListener;
27 import android.hardware.input.IKeyboardBacklightState;
28 import android.hardware.input.ITabletModeChangedListener;
29 import android.hardware.input.TouchCalibration;
30 import android.os.CombinedVibration;
31 import android.hardware.input.IInputSensorEventListener;
32 import android.hardware.input.InputSensorInfo;
33 import android.hardware.lights.Light;
34 import android.hardware.lights.LightState;
35 import android.os.IBinder;
36 import android.os.IVibratorStateListener;
37 import android.os.VibrationEffect;
38 import android.view.inputmethod.InputMethodInfo;
39 import android.view.inputmethod.InputMethodSubtype;
40 import android.view.InputDevice;
41 import android.view.InputEvent;
42 import android.view.InputMonitor;
43 import android.view.PointerIcon;
44 import android.view.VerifiedInputEvent;
45 
46 /** @hide */
47 interface IInputManager {
48     // Gets the current VelocityTracker strategy
getVelocityTrackerStrategy()49     String getVelocityTrackerStrategy();
50     // Gets input device information.
getInputDevice(int deviceId)51     InputDevice getInputDevice(int deviceId);
getInputDeviceIds()52     int[] getInputDeviceIds();
53 
54     // Enable/disable input device.
isInputDeviceEnabled(int deviceId)55     boolean isInputDeviceEnabled(int deviceId);
enableInputDevice(int deviceId)56     void enableInputDevice(int deviceId);
disableInputDevice(int deviceId)57     void disableInputDevice(int deviceId);
58 
59     // Reports whether the hardware supports the given keys; returns true if successful
hasKeys(int deviceId, int sourceMask, in int[] keyCodes, out boolean[] keyExists)60     boolean hasKeys(int deviceId, int sourceMask, in int[] keyCodes, out boolean[] keyExists);
61 
62     // Returns the keyCode produced when pressing the key at the specified location, given the
63     // active keyboard layout.
getKeyCodeForKeyLocation(int deviceId, in int locationKeyCode)64     int getKeyCodeForKeyLocation(int deviceId, in int locationKeyCode);
65 
66     // Temporarily changes the pointer speed.
tryPointerSpeed(int speed)67     void tryPointerSpeed(int speed);
68 
69     // Injects an input event into the system. The caller must have the INJECT_EVENTS permssion.
70     // This method exists only for compatibility purposes and may be removed in a future release.
71     @UnsupportedAppUsage
injectInputEvent(in InputEvent ev, int mode)72     boolean injectInputEvent(in InputEvent ev, int mode);
73 
74     // Injects an input event into the system. The caller must have the INJECT_EVENTS permission.
75     // The caller can target windows owned by a certain UID by providing a valid UID, or by
76     // providing {@link android.os.Process#INVALID_UID} to target all windows.
injectInputEventToTarget(in InputEvent ev, int mode, int targetUid)77     boolean injectInputEventToTarget(in InputEvent ev, int mode, int targetUid);
78 
verifyInputEvent(in InputEvent ev)79     VerifiedInputEvent verifyInputEvent(in InputEvent ev);
80 
81     // Calibrate input device position
getTouchCalibrationForInputDevice(String inputDeviceDescriptor, int rotation)82     TouchCalibration getTouchCalibrationForInputDevice(String inputDeviceDescriptor, int rotation);
setTouchCalibrationForInputDevice(String inputDeviceDescriptor, int rotation, in TouchCalibration calibration)83     void setTouchCalibrationForInputDevice(String inputDeviceDescriptor, int rotation,
84             in TouchCalibration calibration);
85 
86     // Keyboard layouts configuration.
getKeyboardLayouts()87     KeyboardLayout[] getKeyboardLayouts();
88 
getKeyboardLayoutsForInputDevice(in InputDeviceIdentifier identifier)89     KeyboardLayout[] getKeyboardLayoutsForInputDevice(in InputDeviceIdentifier identifier);
90 
getKeyboardLayout(String keyboardLayoutDescriptor)91     KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor);
92 
getCurrentKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier)93     String getCurrentKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier);
94 
95     @EnforcePermission("SET_KEYBOARD_LAYOUT")
96     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
97             + "android.Manifest.permission.SET_KEYBOARD_LAYOUT)")
setCurrentKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, String keyboardLayoutDescriptor)98     void setCurrentKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier,
99             String keyboardLayoutDescriptor);
100 
getEnabledKeyboardLayoutsForInputDevice(in InputDeviceIdentifier identifier)101     String[] getEnabledKeyboardLayoutsForInputDevice(in InputDeviceIdentifier identifier);
102 
103     @EnforcePermission("SET_KEYBOARD_LAYOUT")
104     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
105             + "android.Manifest.permission.SET_KEYBOARD_LAYOUT)")
addKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, String keyboardLayoutDescriptor)106     void addKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier,
107             String keyboardLayoutDescriptor);
108 
109     @EnforcePermission("SET_KEYBOARD_LAYOUT")
110     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
111             + "android.Manifest.permission.SET_KEYBOARD_LAYOUT)")
removeKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, String keyboardLayoutDescriptor)112     void removeKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier,
113             String keyboardLayoutDescriptor);
114 
115     // New Keyboard layout config APIs
getKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, int userId, in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype)116     String getKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, int userId,
117             in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);
118 
119     @EnforcePermission("SET_KEYBOARD_LAYOUT")
120     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
121             + "android.Manifest.permission.SET_KEYBOARD_LAYOUT)")
setKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, int userId, in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype, String keyboardLayoutDescriptor)122     void setKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier, int userId,
123             in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype,
124             String keyboardLayoutDescriptor);
125 
getKeyboardLayoutListForInputDevice(in InputDeviceIdentifier identifier, int userId, in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype)126     KeyboardLayout[] getKeyboardLayoutListForInputDevice(in InputDeviceIdentifier identifier,
127             int userId, in InputMethodInfo imeInfo, in InputMethodSubtype imeSubtype);
128 
129     // Modifier key remapping APIs.
130     @EnforcePermission("REMAP_MODIFIER_KEYS")
131     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
132             + "android.Manifest.permission.REMAP_MODIFIER_KEYS)")
remapModifierKey(int fromKey, int toKey)133     void remapModifierKey(int fromKey, int toKey);
134 
135     @EnforcePermission("REMAP_MODIFIER_KEYS")
136     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
137             + "android.Manifest.permission.REMAP_MODIFIER_KEYS)")
clearAllModifierKeyRemappings()138     void clearAllModifierKeyRemappings();
139 
140     @EnforcePermission("REMAP_MODIFIER_KEYS")
141     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
142             + "android.Manifest.permission.REMAP_MODIFIER_KEYS)")
getModifierKeyRemapping()143     Map getModifierKeyRemapping();
144 
145     // Registers an input devices changed listener.
registerInputDevicesChangedListener(IInputDevicesChangedListener listener)146     void registerInputDevicesChangedListener(IInputDevicesChangedListener listener);
147 
148     // Queries whether the device is currently in tablet mode
isInTabletMode()149     int isInTabletMode();
150     // Registers a tablet mode change listener
registerTabletModeChangedListener(ITabletModeChangedListener listener)151     void registerTabletModeChangedListener(ITabletModeChangedListener listener);
152 
153     // Queries whether the device's microphone is muted by switch
isMicMuted()154     int isMicMuted();
155 
156     // Input device vibrator control.
vibrate(int deviceId, in VibrationEffect effect, IBinder token)157     void vibrate(int deviceId, in VibrationEffect effect, IBinder token);
vibrateCombined(int deviceId, in CombinedVibration vibration, IBinder token)158     void vibrateCombined(int deviceId, in CombinedVibration vibration, IBinder token);
cancelVibrate(int deviceId, IBinder token)159     void cancelVibrate(int deviceId, IBinder token);
getVibratorIds(int deviceId)160     int[] getVibratorIds(int deviceId);
isVibrating(int deviceId)161     boolean isVibrating(int deviceId);
registerVibratorStateListener(int deviceId, in IVibratorStateListener listener)162     boolean registerVibratorStateListener(int deviceId, in IVibratorStateListener listener);
unregisterVibratorStateListener(int deviceId, in IVibratorStateListener listener)163     boolean unregisterVibratorStateListener(int deviceId, in IVibratorStateListener listener);
164 
getBatteryState(int deviceId)165     IInputDeviceBatteryState getBatteryState(int deviceId);
166 
setPointerIconType(int typeId)167     void setPointerIconType(int typeId);
setCustomPointerIcon(in PointerIcon icon)168     void setCustomPointerIcon(in PointerIcon icon);
169 
requestPointerCapture(IBinder inputChannelToken, boolean enabled)170     oneway void requestPointerCapture(IBinder inputChannelToken, boolean enabled);
171 
172     /** Create an input monitor for gestures. */
monitorGestureInput(IBinder token, String name, int displayId)173     InputMonitor monitorGestureInput(IBinder token, String name, int displayId);
174 
175     // Add a runtime association between the input port and the display port. This overrides any
176     // static associations.
addPortAssociation(in String inputPort, int displayPort)177     void addPortAssociation(in String inputPort, int displayPort);
178     // Remove the runtime association between the input port and the display port. Any existing
179     // static association for the cleared input port will be restored.
removePortAssociation(in String inputPort)180     void removePortAssociation(in String inputPort);
181 
182     // Add a runtime association between the input device and display.
addUniqueIdAssociation(in String inputPort, in String displayUniqueId)183     void addUniqueIdAssociation(in String inputPort, in String displayUniqueId);
184     // Remove the runtime association between the input device and display.
removeUniqueIdAssociation(in String inputPort)185     void removeUniqueIdAssociation(in String inputPort);
186 
getSensorList(int deviceId)187     InputSensorInfo[] getSensorList(int deviceId);
188 
registerSensorListener(IInputSensorEventListener listener)189     boolean registerSensorListener(IInputSensorEventListener listener);
190 
unregisterSensorListener(IInputSensorEventListener listener)191     void unregisterSensorListener(IInputSensorEventListener listener);
192 
enableSensor(int deviceId, int sensorType, int samplingPeriodUs, int maxBatchReportLatencyUs)193     boolean enableSensor(int deviceId, int sensorType, int samplingPeriodUs,
194                 int maxBatchReportLatencyUs);
195 
disableSensor(int deviceId, int sensorType)196     void disableSensor(int deviceId, int sensorType);
197 
flushSensor(int deviceId, int sensorType)198     boolean flushSensor(int deviceId, int sensorType);
199 
getLights(int deviceId)200     List<Light> getLights(int deviceId);
201 
getLightState(int deviceId, int lightId)202     LightState getLightState(int deviceId, int lightId);
203 
setLightStates(int deviceId, in int[] lightIds, in LightState[] states, in IBinder token)204     void setLightStates(int deviceId, in int[] lightIds, in LightState[] states, in IBinder token);
205 
openLightSession(int deviceId, String opPkg, in IBinder token)206     void openLightSession(int deviceId, String opPkg, in IBinder token);
207 
closeLightSession(int deviceId, in IBinder token)208     void closeLightSession(int deviceId, in IBinder token);
209 
cancelCurrentTouch()210     void cancelCurrentTouch();
211 
registerBatteryListener(int deviceId, IInputDeviceBatteryListener listener)212     void registerBatteryListener(int deviceId, IInputDeviceBatteryListener listener);
213 
unregisterBatteryListener(int deviceId, IInputDeviceBatteryListener listener)214     void unregisterBatteryListener(int deviceId, IInputDeviceBatteryListener listener);
215 
216     // Get the bluetooth address of an input device if known, returning null if it either is not
217     // connected via bluetooth or if the address cannot be determined.
218     @EnforcePermission("BLUETOOTH")
219     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
220             + "android.Manifest.permission.BLUETOOTH)")
getInputDeviceBluetoothAddress(int deviceId)221     String getInputDeviceBluetoothAddress(int deviceId);
222 
223     @EnforcePermission("MONITOR_INPUT")
224     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
225             + "android.Manifest.permission.MONITOR_INPUT)")
pilferPointers(IBinder inputChannelToken)226     void pilferPointers(IBinder inputChannelToken);
227 
228     @EnforcePermission("MONITOR_KEYBOARD_BACKLIGHT")
229     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
230             + "android.Manifest.permission.MONITOR_KEYBOARD_BACKLIGHT)")
registerKeyboardBacklightListener(IKeyboardBacklightListener listener)231     void registerKeyboardBacklightListener(IKeyboardBacklightListener listener);
232 
233     @EnforcePermission("MONITOR_KEYBOARD_BACKLIGHT")
234     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
235             + "android.Manifest.permission.MONITOR_KEYBOARD_BACKLIGHT)")
unregisterKeyboardBacklightListener(IKeyboardBacklightListener listener)236     void unregisterKeyboardBacklightListener(IKeyboardBacklightListener listener);
237 
getHostUsiVersionFromDisplayConfig(int displayId)238     HostUsiVersion getHostUsiVersionFromDisplayConfig(int displayId);
239 }
240