The function calls starts with an InterruptJonathan LevinTechnologeeks.com

The Android Input ArchitectureThe journey of a thousand function calls starts with an InterruptJonathan LevinTechnologeeks.com (@Technologeeks)NewAndroidBook.com(c) 2015 Jonathan Levin – http://NewAndroidBook.com/ – Distribute Freely, but please do not plagiarize!About This Talk•Discusses the Android Input Stack, in depth•Follows flow of input (up to App, sans IME)–Avoids code as much as possible•Demonstrates a few handy input tools•Essentially an excerpt from the Book.(c) 2015 Jonathan Levin – http://NewAndroidBook.com/ – Distribute Freely, but please do not plagiarize!The Book•”Android Internals:: A Confectioner’s Cookbook”•Unofficial parallel to “Mac OS X and iOS Internals”•(which, btw, is coming out in a 2ndEdition for iOS 9/OS X 10.11!)•Volume I released earlier this year–Already updated for Android M PR1-2!•Volume II to be released soon•As soon as Google stabilizes M•http://www.NewAndroidBook.com/–FAQ, TOC and plenty of bonus materials(c) 2015 Jonathan Levin – http://NewAndroidBook.com/ – Distribute Freely, but please do not plagiarize!WindowInputEventReceiverWindowInputEventReceiverandroid.view.InputChannelandroid::NativeInputChannelandroid::InputChannelUser AppsWhat do we know about input?The activity gets the input as an event, via the target view’sonXXX event callbackHardwareDevicePhysical events (e.g. touches, clicks, swipe, etc) occur at the device hardware levelActivity gets input as part of a specified event callback(c) 2015 Jonathan Levin – http://NewAndroidBook.com/ – Distribute Freely, but please do not plagiarize!WindowInputEventReceiverWindowInputEventReceiverandroid.view.InputChannelandroid::NativeInputChannelandroid::InputChannelUser Apps•The Android input stack is actually complex•Input flow involves multiple components•Requires Inter Process Communication (IPC)The activity gets the input as an event, via the target view’sonXXX event callbackHardware•Plenty of input sources:- Touch screen- Keyboards (real, virtual)- Sensors (accelerometer, GPS, light, temp..)•Not all input consumable by viewsBehind the scenesDevice•Even more on IoT devices (e.g. Treadmills!)(c) 2015 Jonathan Levin – http://NewAndroidBook.com/ – Distribute Freely, but please do not plagiarize!Application ViewLinux kernel input stackKernelInput device driverWindowInputEventReceiverWindowInputEventReceiverandroid.view.InputChannelandroid::NativeInputChannelandroid::InputChannelUser AppsHardwareDeviceThe activity gets the input as an event, via the target view’sonXXX event callbackThe Linux Kernel•The very first component of the input stack•Nothing Android specific here•Delegates input retrieval to device driver•All Input drivers conform to Linux Input ModelThe Linux Kernel + Device Drivers(c) 2015 Jonathan Levin – http://NewAndroidBook.com/ – Distribute Freely, but please do not plagiarize!Application ViewLinux kernel input stackKernelInput device driverWindowInputEventReceiverWindowInputEventReceiverandroid.view.InputChannelandroid::NativeInputChannelandroid::InputChannel/dev/input/eventXXHardwareDeviceThe activity gets the input as an event, via the target view’sonXXX event callbackThe Linux Input ModelAll Input starts with some type of interrupt, generated by deviceCPU responds to interrupts, calls kernel, to dispatch to device [email protected] (~)$ cat /proc/interruptsCPU0 1: 0 int usbin-uv 2: 0 int usbin-ov 3: 0 int usbin-src-det 4: 0 int otg-fail 5 : 0 int otg-oc 6: 0 int batt-low…674: 0 lmm_irq HS_PMIC_DETECT675: 1 lmm_irq HS_PMIC_BUTTON676: 2 lmm_irq power_key677: 2 lmm_irq volume_up678: 0 lmm_irq volume_down•interrupt statistics in /proc/interrupts(nice bonus: # of active CPUs)•Drivers claim interrupt (request_irq)•Driver callback invoked by kernel(c) 2015 Jonathan Levin – http://NewAndroidBook.com/ – Distribute Freely, but please do not plagiarize!