Which driver is in charge of headset buttons on my tablet?


Question

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.


Answer

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:
<none>


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...


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes