In this moth’s column, we shift our focus to mobile application development and discuss the issue of energy consumption of mobile apps. We also briefly cover how a layman can quickly learn to develop android apps.
For the past few months, we have been discussing information retrieval and natural language processing as well as the algorithms associated with them. In this months column, we take a break from our discussion of NLP and, instead, focus on mobile application development. We discuss some of the recent research work on the energy consumed by mobile apps. Then we move on to mobile app development, which has been growing at a furious pace over the past few years and has attracted many non-software developers to its fold, including school students. Learning to develop mobile apps using open source software is quite easy. In this months column, we have one of our student readers, Ankith Subramanya, who is a Class XI student from The International School, Bengaluru, share his experience of learning to develop an Android app.
Energy consumption in mobile apps
Smartphones run complete operating systems tailored for the mobile device, and support a wide variety of additional hardware devices such as cameras, GPS, a light sensor, accelerometer, gyroscope, compass, etc. Along with such a rich plethora of exotic hardware, smartphones also need to be extremely lightweight and portable. This requires that smartphone batteries must be small and lightweight. This, in turn, implies that energy consumption in smartphones needs to be as low as possible to conserve battery life. Hence, energy consumption by mobile apps needs to be tracked and managed to extend the battery life of smartphones.
Smartphones have become open platforms for hosting a variety of applications. Given the rapid pace of mobile app development, more and more apps are being developed, downloaded and installed on to the device, without their performance, security and energy characteristics being validated and documented. This can lead to poorly written apps causing an abnormal drain on the devices battery.
Given a smartphone with a fully charged battery, the user expects that the device should be usable for a certain number of hours without requiring a battery recharge. The user is aware that prolonged use of certain hardware such as the camera, GPS, etc, can shorten the period before the next recharge. However, in the course of using normal apps, such Abnormal Battery Drain (ABD) issues are not expected to occur. When an ABD issue occurs, it is difficult for normal users to figure out what it is caused by. Some of the potential causes could be configuration changes; a hardware or software malfunction which keeps a power-hungry hardware component such as the camera always on, even when not in use; an app upgrade, etc. Hence, intelligent tools are needed to diagnose ABD issues. One such tool is a research project called eDoctor, which is described in the following research paper http://cseweb.ucsd.edu/~voelker/pubs/edoctor-nsdi13.pdf. eDoctor records various events such as configuration changes, app installations and app upgrades; and it monitors app phases. Using this information, it tries to pinpoint what is responsible for the ABD.
Given the importance of conserving battery life, smartphone OSs are designed to turn off hardware components the moment they detect that they are not in use. Smartphones employ aggressive CPU/screen sleeping policies. Such measures can result in issues for apps which are in the middle of communicating with an external server and are waiting for data to be returned from the server. In such cases, the device should not be put to sleep. Hence, smartphone OSs export explicit wakelock APIs, which can be used by the apps to indicate that the device should not be put to sleep. However, bugs in mobile apps can cause wakelocks to be misused, resulting in the device continuing to drain energy even when not in use. For instance, if an application has acquired a wakelock at some point in time, it should release the wakelock to allow the device to go back to sleep. Failure to release the wakelock can cause continuous drain of the battery. There has been considerable research work on detecting wakelock bugs, also known as no-sleep bugs. A detailed discussion of wakelock bugs can be found in the paper http://web1.cs.columbia.edu/~junfeng/reliable-software/papers/no-sleep.pdf.
While the previous research papers we have discussed focus on detecting energy bugs in smartphones by analysing the individual devices behaviour, detecting energy consumption anomalies by analysing the behaviour in individual phones is difficult since the energy consumption can vary widely due to different device configurations, different apps co-running simultaneously, and usage under different environmental conditions. A novel direction in pinpointing energy bugs and high energy consumptions has been proposed in the free mobile app, Carat, which is available from http://carat.cs.berkeley.edu/.
Carat uses a collaborative approach to detect anomalies by collecting energy information from a wide variety of devices and uses that information to detect anomalous behaviour on an individual smartphone. Each smartphone on which Carat is installed, periodically sends information on battery usage, configuration settings, the set of applications installed and set of apps running currently to a centralised server. Data from a wide number of devices is collected, stored and analysed in the centralised database, to infer statistically, a normal energy consumption pattern for a device. If the measurements reported from the device deviate considerably from the expected consumption, an energy consumption anomaly is flagged by the app.
While the tools we have discussed so far help to detect abnormal energy consumption by applications in smartphones, as an app developer, you would be interested in making sure that your app is well-behaved with respect to energy consumption. The open source tool JouleUnit is an energy profiling and testing framework, and is available at https://code.google.com/p/jouleunit/. The JouleUnit workbench is integrated into the Eclipse IDE, and allows you to construct and trigger energy tests for your app from the Eclipse IDE.
Learning to develop Android apps
One of our student readers, Ankith Subramanya, had written to me, sharing his experience on how he rapidly learnt Android app development. Given the enormous interest in mobile app development even from non-core programmers, I felt that it would be useful to share his experience in this column, for the benefit of those who are interested in learning Android app development. Here are Ankiths comments:
Im writing this for those novices out there who are itching to develop Android apps, but dont yet know how to. Until a few weeks ago, I too had no idea about creating Android apps, but I really wanted to develop my own mobile apps. I did some reading on the Internet, and found out that Android apps are developed using Java. I was a little disheartened at first because I had never learnt Java or, for that matter, any Object Oriented Programming language. Nonetheless, I found the time in my summer vacation to attend a few classes on Java at a local teaching centre. A few weeks into it, I discovered that Java is extremely intuitive and easy to grasp.
Earlier experience in Java would definitely be a plus point, but dont be disheartened if you dont know any Java at all. There are plenty of resources online to help you learn, and using a book wouldnt be a bad idea as well. I must stress that getting your syntax bang on is not as important as getting the hang of the basics and the fundamental concepts. You should have a solid understanding of OO concepts such as object creation, inheritance, overriding, interfaces, collections, packages, etc. These might sound like Greek and Latin, but once you get started on Java, this will be your bread and butter.
A lot of people think that knowing XML is crucial in building Android apps, but the truth is that you can build whatever you want with no previous knowledge of XML. This is basically because the XML elements are integrated as a drag and drop feature in the Android environment. Also, XML is very simple and you will definitely pick it up while building an app. Learning Android is merely about getting to know a few additional concepts. First, visit developer.android.com. You will find instructions there to install and set up your SDK (what youll need to develop the apps). This contains half-built Android programs, in the sense that it contains incomplete classes that you have merely to extend (again, dont worry about these terms, youll understand them soon enough) to build your apps. This way, it becomes very simple as you dont have to start from scratch.
There are plenty of resources online to help you learn Android. Udacity (www.udacity.org) and Coursera (www.coursera.org) offer courses on mobile app development. The course in Udacity, named Developing Android apps, is interactive and is centred on the purpose of making you build your own weather app. The entire course involves the steps to build that app, and you are expected to do so on your own. The idea is that, from this, you will develop your skillsets to develop your own Android apps. This is a very nice concept, and provides a hands-on learning experience. There is also another course available from Coursera titled, Creative, Serious and Playful Science of Android Apps. This requires no previous knowledge of Java. You may find this useful as well.
The two IDEs that you can use for Android development are Android Studio and Eclipse. While both are very similar in many ways, I use Eclipse, though this is entirely your choice. As Android Studio is still in the early stages of development, and as only the beta version is available for use, I would recommend using Eclipse (www.eclipse.org). Android apps can be made on Eclipse by downloading the necessary plugins. The complete package that you need to install, including Eclipse with the necessary plugins, as well as the SDK manager (an app that manages the downloading and installation of build tools and libraries) is available on developer.android.com, and is called the ADT (Android Developer Tools) bundle (JDK must be pre-installed). The IDE contains Java classes and XML files, that are made to interact with the help of Android manifest, which is an XML file.
Essentially, each screen of an Android project is called an activity, and every activity has a backing XML file and Java class. Android apps follow the MVC (model view controller) design pattern. The XML file, which is for UI, acts as the view, whereas the backing Java classes are for the model and controller. If you do not wish to do the XML part, the UI can be designed by the intuitive dragging and dropping of UI elements (called views), and the IDE will automatically make changes in the XML file.
Debugging is made simple with the help of LogCat, a debugging tool that shows what exactly is going on at every step in the runtime of the application. The app that you create can be run either using an emulator or on your Android device. I would recommend the latter, as the emulator is incredibly slow in loading. If you want to run on your Android device, make sure that you install the device driver. Also, if your Android version is 4.2 or higher, you will need to turn on developer options. You can do this by going to About phone in Settings and then clicking on Build version. However, if you do not have an Android device, you will have to create an emulator on AVD (Android Virtual Device) manager. Simple apps such as a calculator and apps to print out your name are surprisingly easy to build. Now go, get started on your Android adventure!
Thank you, Ankith, for sharing your experience on learning Android app development!
If you have any favourite programming questions/software topics that you would like to discuss on this forum, please send them to me, along with your solutions and feedback, at sandyasm_AT_yahoo_DOT_com. Till we meet again next month, happy programming!