Which driver is in charge of headset buttons on my tablet? I have recently bought a Lenovo Tab3 710F tablet (product page) and I'm trying to control the music playback externally with a small electronic circuit.

The idea is to reproduce the same behavior as the buttons that one can find on a external headset which plugs into the mini-jack port.

There is a page in the Android documentation which specifies this interface: 3.5 mm Headset: Accessory Specification. In brief, each button should be connected in series with a resistor of a given value with allows the android device to detect which button was pressed and trigger the corresponding action.

The problem is that my tablet doesn't really respond according to that specification (ex button B triggers next song, instead of vol+). Also, the wiring on this tablet seems inverted between GND and MIC. I have tried opening the tablet to find the audio or headset detection IC model, but to no luck as everything is sealed.

Thus, I was thinking that maybe I could get some info from "software": how can I know which driver is handling button actions?

The idea would then to look at the source code (available on Lenovo website), to find the various capabilities coded in the driver, and maybe even an IC reference that would help me locate the IC datasheet for further information.
OK guys, I'm a bit surprised that I didn't get any answer, but I guess that's because it was more of a stackoverflow question...

Anyway, I continued my research and I found the answer myself, in particular thanks to this PDF which describes in detail "The Android Input Architecture".

The PDF provides all the details, but basically each driver registers input_devices with the Linux Kernel and a device file is created for each event under /dev/input/eventXX. Then there is an Android mechanism to route those events to the applications, but that is not the concern here.

One can use the command getevent to get more information on these events (see also Android documentation):


getevent -li provides a list of the registered input devices with the possible events for each device
getevent -lp prints a new line for each event received (the -l flag displays the events types and names in plain text rather than number)


So for example in the case of my Lenovo tablet, we find that:

add device 6: /dev/input/event1
  bus:      0019
  vendor    0000
  product   0000
  version   0000
  name:     "ACCDET"
  location: ""
  id:       ""
  version:  1.0.1
  events:
    KEY (0001): KEY_VOLUMEDOWN        KEY_VOLUMEUP          KEY_HANGEUL
  KEY_NEXTSONG
                KEY_PLAYPAUSE         KEY_PREVIOUSSONG      KEY_STOPCD
  KEY_SEND
  input props:
    &lt;none&gt;


NOTE: This is only an extract from the complete output, limited to the headset buttons detection.

Thus, the headset buttons handling seems to be done by some "ACCDET" component. Now, I still haven't figured out the "formal" way to know which driver registers this event, but by using the ACCDET and KEY_XX keywords in a source code search, I was able to find the corresponding source file (accdet.c), which contained the other information I was looking for (namely the voltage thresholds for each button detection).

Finally, it is also worth to note that one can simulate events using the sendevents command. So for instance, to simulate pressing (and releasing) the play/pause button, one would use:

sendevent /dev/input/event1 1 164 1; \
sendevent /dev/input/event1 1 164 0; \
sendevent /dev/input/event1 0 0 0


Hope it can help someone else...