Before we get our hands on into the code, let's explore the overall architecture of Android Things and present a few concepts that we will be using throughout the chapter, such as the best practices to handle the peripheral lifecycle and the concept of user space drivers.
Android Things architecture
Peripheral lifecycle
Whenever we want to use a peripheral, we need to get access to it before we can do anything with it. This is done using the open method that all peripheral classes have. Opening a peripheral gives us exclusive control over it and therefore it can not be opened if it is already open by another app. The operating system will throw an Exception if the peripheral is already in use.
As you can imagine, this...