Skip to content

Commit af9e8d3

Browse files
author
Jeff Brown
committed
Notify applications when input devices change.
This change allows the InputManager to keep track of what input devices are registered with the system and when they change. It needs to do this so that it can properly clear its cache of input device properties (especially the key map!) when changes occur. Added new API so that applications can register listeners for input device changes. Fixed a minor bug in EventHub where it didn't handle EPOLLHUP properly so it would spam the log about unsupposed epoll events until inotify noticed that the device was gone and removed it. Change-Id: I937d8c601f7185d4299038bce6a2934fe4fdd2b3
1 parent cc11698 commit af9e8d3

File tree

17 files changed

+742
-220
lines changed

17 files changed

+742
-220
lines changed

Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ LOCAL_SRC_FILES += \
111111
core/java/android/database/IContentObserver.aidl \
112112
core/java/android/hardware/ISerialManager.aidl \
113113
core/java/android/hardware/input/IInputManager.aidl \
114+
core/java/android/hardware/input/IInputDevicesChangedListener.aidl \
114115
core/java/android/hardware/usb/IUsbManager.aidl \
115116
core/java/android/net/IConnectivityManager.aidl \
116117
core/java/android/net/INetworkManagementEventObserver.aidl \

api/current.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9820,10 +9820,20 @@ package android.hardware {
98209820
package android.hardware.input {
98219821

98229822
public final class InputManager {
9823+
method public android.view.InputDevice getInputDevice(int);
9824+
method public int[] getInputDeviceIds();
9825+
method public void registerInputDeviceListener(android.hardware.input.InputManager.InputDeviceListener, android.os.Handler);
9826+
method public void unregisterInputDeviceListener(android.hardware.input.InputManager.InputDeviceListener);
98239827
field public static final java.lang.String ACTION_QUERY_KEYBOARD_LAYOUTS = "android.hardware.input.action.QUERY_KEYBOARD_LAYOUTS";
98249828
field public static final java.lang.String META_DATA_KEYBOARD_LAYOUTS = "android.hardware.input.metadata.KEYBOARD_LAYOUTS";
98259829
}
98269830

9831+
public static abstract interface InputManager.InputDeviceListener {
9832+
method public abstract void onInputDeviceAdded(int);
9833+
method public abstract void onInputDeviceChanged(int);
9834+
method public abstract void onInputDeviceRemoved(int);
9835+
}
9836+
98279837
}
98289838

98299839
package android.hardware.usb {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
/** @hide */
20+
interface IInputDevicesChangedListener {
21+
/* Called when input devices changed, such as a device being added,
22+
* removed or changing configuration.
23+
*
24+
* The parameter is an array of pairs (deviceId, generation) indicating the current
25+
* device id and generation of all input devices. The client can determine what
26+
* has happened by comparing the result to its prior observations.
27+
*/
28+
oneway void onInputDevicesChanged(in int[] deviceIdAndGeneration);
29+
}

core/java/android/hardware/input/IInputManager.aidl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.hardware.input;
1818

1919
import android.hardware.input.KeyboardLayout;
20+
import android.hardware.input.IInputDevicesChangedListener;
2021
import android.view.InputDevice;
2122
import android.view.InputEvent;
2223

@@ -42,4 +43,7 @@ interface IInputManager {
4243
String getKeyboardLayoutForInputDevice(String inputDeviceDescriptor);
4344
void setKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
4445
String keyboardLayoutDescriptor);
46+
47+
// Registers an input devices changed listener.
48+
void registerInputDevicesChangedListener(IInputDevicesChangedListener listener);
4549
}

0 commit comments

Comments
 (0)