Moving Towards Embedded Android

Moving Towards Embedded modify the platform in a non- invasive built with exactly this particular feature manner. By giving basic advice for in mind. Naturally, taking advantage of a Android: Things you need porting and upgrading Android, this high level is not a article addresses common issues often sole interest of the mobile software to know arising during the process of migration. industry but also of embedded system application developers. It is features like Java Exceptions, Threading and access to These are the benefits of Android the Networking Stack and the excellent Manuel Di Cerbo and Andreas Rudolf toolset coming with it, that draw the Nexus-Computing GmbH Switzerland 1. attention to the platform. Furthermore, it offers tools in order to support creating While there might be some occasions UI and localisation for applications, During recent developments, the where it even makes sense to use which are two features often requested embedded industry is starting to offer Android without UI - so called headless in embedded applications. Android as an option to run on their Android - the key reason to choose hardware products. The demand for Android over other solutions is in many 3. Stability and Prosperity Android on embedded systems has been cases the ability to build high quality in moderation for some time with steady user interfaces. The Android User Although controversially discussed in the ascent during the past few years. Interface resembles a profound pillar of press, the state of Android's stability and the platform with the goal to deliver security is benefiting from being one of This article discusses benefits and deeply immersive UI concepts by the most well tested Operating Systems in challenges when considering to offer incorporating the Android’s numerous existence. Android for an embedded system into applications. Opposed to the platform, taking into account recent desktop experience, users of mobile Android runs daily on millions of developments in both embedded Linux phones and tablets are very alert by devices, accumulating testing time and embedded Android. By discussing the disruptive UI design choices. These beyond the scope of any embedded requirements of Android hardware and include delayed responsiveness or non system application in the field. Bug shedding light into the process of porting intuitive interaction. While creating reports are filed on a regular basis and Android to a new platform, this custom design patterns for an embedded most important of all, Android is under document aims to clarify the current application make sense in selected cases, nonstop development and progression. state of Android in the embedded the user values recognising UI patterns Driven by the industry's motivation of systems' industry. across all their devices. offering Android systems to the consumer, it is a major concern of While some suppliers are already 2. Java and Android Development Tools and their partners to account for offering a version of Android for their Android's quality and continuous hardware, the question arises if and how Due to the nature of the Android iteration. to update to a more recent version of the internals, it is possible to run Java code system. Taking into account benefits and very efficiently even on low resource challenges, it demonstrates how to ARM systems. Android’s core system is

April 2014, Nexus-Computing GmbH Switzerland - www. nexus-computing.ch - [email protected] Moving Towards Embedded Android

When comparing Android's software 5. Linux access to this new stack is given by the stack to a typical embedded Linux setup, "ndc" tool, which is only partially a significantly higher level of complexity Android is based on the Linux kernel. documented and remains for the moment is apparent. Arguably Android’s overall Although the system stack of Android is not very intuitive. stability might suffer from the inherent significantly more complex than a complexity of the middleware. classical embedded Linux approach, it init: Android uses its own init language Countering this claim is the fact that still features the ability to run Linux (see init.rc) and provides system very hard requirements are set for applications in parallel. Particularly, this initialization via rc scripts. With version Android’s operability by Google and their is a way to incorporate already available Kitkat, init.rc is now universal for all partners since non optimal user middleware into Android. The often Android systems, and platform specific experience will directly impact sales found IPC through socket daemons are initialization is done exclusively in other figures of devices. therefore portable to the Android such as init.${platform}.rc or init. platform with little effort. Certainly, ${platform}.usb.rc. Although rc files 4. Ahead of time bindings to the UI still need to be appear similar to shell scripts, only a addressed with proper implementation. small subset of Linux commands are Provided, Android's propagation in the However, depending on the architecture, available at their disposal. embedded industry is still in early it might not even be necessary to write stages. Yet, the demand sources in the JNI bindings for existing applications, as toolbox: embedded Linux engineers are foresight of market trends. There are long as the middleware offers accessible used to have access to busybox’s firm believers who take the risk to invest communication such as UNIX sockets. extensive utilities. Android does not into Android at this time, in order to be feature a built-in busybox but instead one step ahead of competition in the The common pitfalls when moving from offers the toolbox, which is a rather future. Linux to Android limited utility. Early versions did not even include a “cp” command and many In general, clients intend to develop 1. Different tools compared to Linux other tools familiar to Linux engineers modular and extendable software are still absent or handled by other applications for their customers in order There are numerous user space tools utilities not present in standard to simplify the development process. which are absent in Android (current embedded Linux distributions. With tools such as the ADT Bundle or the version Kitkat). Parts of the system will Fortunately, it is not very difficult to , this demand can be also throw the most experienced Linux install a fully functional busybox in covered in an elegant manner. While not engineer off the rails. parallel on a target Android platform. necessarily a technical advantage of the platform, these arguments rest on ifconfig, route, dhcpcd: Android recently user, group: Android heavily relies on features such as extensibility and introduced a very distinct system for Linux permissions for the filesystem. Yet maintainability of Android applications handling network interfaces, routes, dns, one of the most helpful tools in order to in general. gateways, etc. The OS has built an entire modify access rights is missing. There is stack around the IP tools which is no groupadd nor useradd. Some written in Java and accessed by the functionality is exposed by the package Android framework. As a developer, the manager (pm) tool, yet it is very limited.

April 2014, Nexus-Computing GmbH Switzerland - www. nexus-computing.ch - [email protected] Moving Towards Embedded Android

For adding a specific user to Android, the runtime. A large portion is set during Generally Android treats the underlying header file android_filesystem_config.h Android compile time. file system as distinctly partitioned for needs to be adjusted and fundamental its purpose. By default it expects two parts of Android need to be recompiled. => make symbols: By setting make partitions at least: system (readonly) and variables in the various *.mk files of the data (rw) and additionally expects a system, switches in the make process are cache partition, a recovery partition and 2. Unorthodox settings and build time set. an external partition. It is however flags. possible to deploy Android into only one => CFLAGS: usually flags are not set by physical partition as well. env: Android has a rather controversial hand, but by checking make variables behaviour with system preferences. ifneq(...). ifdefs are found in various One of the most common mistakes made There are multiple systems in place to do segments of Android and usually have a when deploying Android, is exporting the the same thing: tell Android what to do large impact on system behaviour. file systems with wrong user and group at runtime. Almost all of their switches permissions or wrong file stats. Due to are poorly documented, if at all. => config.: the fact that a lot of thought went into the resource file found under making Android secure, not only will => getprop,setprop: these are the tools to frameworks/base/core/res/res/values Android refuse to boot if stats and set system wide properties. Like found in defines many switches for the Java based permissions are not set accordingly, but default.prop or system/build.prop they Android middleware. Loaded only at also since recently SELinux is in place to define how Android behaves. They are runtime but not directly editable after determine if access to the file system closely tied to init and some of them deployment. breaks the predefined rules. trigger actions which can be controlled by the "on property" instruction of the rc In general there is a large amount of Android ARM Platforms for Embedded init files. system options that get set during Systems compile time. While understandable for => sql settings: many settings on the reasons of easing software architecture, Although there is quite an amount of application level are extracted during this is certainly a downside to other chipset manufacturers offering from an sql . The operating systems. Especially since not support in the embedded industry, two of settings provider is playing a strong role many of the build time switches are them lead the market: TI and Freescale. in how the system applications behave focusing on selecting or deselecting when Android starts. certain system packages or source code Freesacle IMX6: It is called the processor (such as webkit for instance). of 2013 and delivered in several => environment variables: at some places Unselecting packages such as Calculator configurations from single core up to in the system, env variables are checked or Video Player are straightforward, quad core. For their development in order to alter system behaviour, again whereas excluding more crucial parts to platform (SABRE), Android is available very undocumented. the API such as webkit or v8 can lead to with source code and binaries. A low cost severe changes to the platform code. board (Wandboard) from Technexion is Compile Time Settings: by far not all available for purchase as well. behaviour preferences are set during 3. Deployment of the Root File System

April 2014, Nexus-Computing GmbH Switzerland - www. nexus-computing.ch - [email protected] Moving Towards Embedded Android

Texas Instruments AM335x: Especially Android and the Linux Kernel mainline Linux. In reality this is not the with the low cost platform Beaglebone, TI case and almost in any occasion the is pushing Android to the embedded Google regularly updates their Android kernel version of development boards industry. Source and binaries are Kernel patches to the most recent Kernel are significantly behind the current available (officially Android Rowboat). release. While it is already possible to release. With the Arduino TRE they are also boot Android by selecting the staging trying to enter the Makers and Builders features from the vanilla kernel, some Porting new Android Versions to market. features (such as wakelocks) still require Hardware. merging between the two. When creating a new target There are certainly a large number of Today, it is safe to say that Android configuration of Android for a hardware arguments that can be made for choosing Kitkat boots fine with almost any recent platform, it is beneficial to start with a the right hardware. In the case of vanilla kernel that has the staging generic configuration found in the factor favours the IMX6 drivers for Android selected in the “device/generic” folder. All major over the AM335 though: availability of config. However, the evaluation of which platforms (x86, armv7, mips) do already open source drivers for graphics. kernel version to use, relies heavily on have a base set of configuration files the user space drivers for closed source available. By investigating flags and Since a while ago, Android relies on binaries such as GPS, Graphics, GSM configurations for Makefile symbols, a graphics acceleration. Although it is Modules, Audio, etc. Even if there exist very basic runnable root file system of possible to boot Android with just SW binaries for embedded Linux (compiled Android is created without large efforts. acceleration, the experience usually is against glibc) for the recent kernel, a Fine tuning the system to add graphics not optimal. build against Android’s libc is acceleration, Wifi, Gprs and Gsm or even mandatory to be able to make use of the printer drivers are more time consuming Thus, a dependency on third party driver driver. While this is usually a and fall into a second stage of the developers is present. While there is straightforward task for developers of process. Some other target usually a binary graphics driver for the driver, a lack of motivation and/or configurations files found in the device older kernel versions available, moving policies in place may cause delays when folders of “” products also to a newer kernel will not be possible moving forward with a kernel version. show patterns of how to override product without adjusted binaries. It is important properties and copy individual files to to point out that the dependency is not An alternative however, is to deploy a the target in order to do overrides. arising from the version of Android, but glibc compatible with the binary driver rather from the version of the kernel in in parallel, and to hope interfaces In many cases, an old Android version is place. between daemons have not changed entirely sufficient for an embedded between versions. Although there are application. Yet, moving towards a more Only recently an open source driver for options like these, some of them might be recent version adds the benefit of bugs in the IMX6 graphics has been released. time and effort consuming. the system being addressed and fixed. This greatly favours the IMX6 since it The same goes for security issues. allows to be independent from a 3rd In an ideal environment, OEMs would party developer. move their kernel drivers towards

April 2014, Nexus-Computing GmbH Switzerland - www. nexus-computing.ch - [email protected] Moving Towards Embedded Android

For obvious reasons, staying on track implies, that across all devices delivered, By signing an application created using with the most recent Android versions this binding has to be respected by the the ADT Bundle or Android Studio with may be in many situations rather time the device manufacturers. If developing the platform key, it is possible to and effort intensive. Instead of adapting applications outside the Android source selectively provision permissions to an Android's framework code, it is possible code is of interest, then a tailored SDK application. This way, unwanted access to do the heavy lifting of the adjustment needs to be provided to the end from other applications to a critical of the base system by modifying the build customer. This further implies that these hardware resource can be managed in a configuration make files. In rare changes will need to be merged into a very elegant manner. occasions patching the Android new Android framework version. framework may be necessary, yet in such While there are many helper classes instances it is beneficial to investigate Luckily, there is however a much more available through the Android API, and alternative options in order to achieve modular and sophisticated approach to many options available to reach the the targeted behaviour. Ending up with a the problem. Creating an API in parallel desired behaviour of an Android patched Android framework is very bad to the Android system is a more application, it is often favourable to practice in many cases and should be approachable solution that is on top of maintain basic patterns. For instance avoided. all the benefits also portable onto any when creating multiple screens for an generic target. By incorporating only application, the adverted best practice is By following these basic instructions, small changes to the udev rules for using “Fragments” inside Activities in chances are significantly higher to be device drivers and adding JNI glue into order to reach a maximum of able to incorporate all changes into an Application which runs on top of the compatibility among screen layout. Android in a very efficient and elegant Android stack, a user application can However, if considering memory manner. access the exposed resources either via footprint, portability and maintainability Android service, or even via Broadcast of source code, it is often much more The same rules also apply to the intents. favorable to implement simple Views and architecture of APIs. To some it might be exchange them inside the main layout. very tempting to add additional Android- In some cases it even makes sense to use Another example are “AsyncTasks”, like services to the system and follow the a basic Thread inside an Android Activity which are presented superior to basic pattern of using the Binder in to achieve optimal results and robust Threads. Yet when changing activities or combination with the system server in architecture. closing the application their behaviour is order to expose a new hardware not as expected, whereas Threads act as interface to the user. they are supposed to. User APP SVC This is in fact a very good example for subpar practice. While there is certainly a place for altering the framework in Android Framework JNI such a manner, occasions where this makes sense should always be thoroughly DEVICE evaluated. Generally, if the Android SDK KERNEL has an interface to a system service, this

April 2014, Nexus-Computing GmbH Switzerland - www. nexus-computing.ch - [email protected] Moving Towards Embedded Android

Conclusion

From the past few years of development, the advancement of Android in the Manuel Di Cerbo and Andreas Rudolf Technical Blog mobile market has been significant and founded Nexus-Computing GmbH in 2007. http://android.serverbox.ch is indicated to continue on. What seemed Since 2009 their focus lies on porting to be an experimental and unorthodox and enhancing embedded Android for Website approach to develop a mobile platform in clients in the industry. Their engineering http://www.nexus-computing.ch 2009, has now been evolved in a defacto and consulting services are offered in the standard backed by major market forces. area of software development on Linux Although embedded is not at the interest platforms and technolgies such as Address of Google nor the , Android, Web and Embedded. Nexus-Computing GmbH the platform's features and properties Kirchweg 7 overlap substantially with the Their Embedded Android trainings have 5400 Baden requirements of embedded systems. been well receipt since 2012 and Switzerland continued interest in the matter is Furthermore, the popularity of Android driving their engineering and consulting Phone among engineers and developers create a business. +41 56 552 01 01 momentum for the platform that goes beyond just the mobile market. Taking Email into account the possibilities for future [email protected] profits by benefiting from the current waves of enthusiasm, might be a venture Manuel Di Cerbo worth taking. [email protected] On the opposite, due to the complexity of Andreas Rudolf the platforms structure, which include [email protected] building, adjusting and deployment and maintenance, experience in execution is of necessity in order to achieve set goals with manageable efforts. Check Next Embedded Android Training Dates on

www.nexus-computing.ch/android

Atricle Revision 3c April 2014, Nexus-Computing GmbH Switzerland - www. nexus-computing.ch - [email protected]