technology notes… mobile and embedded.

Posts Tagged ‘Android

Android HOWTOs : Memory leak debugging with libc

with one comment

Android’s  libc module provides a way to run in ‘debug’ mode.

In this mode it keeps track of allocated memory and also adds extra data to detect memory corruption /overflow. This tools is useful to debug issues related to memory corruptions and memory leaks too.

Before looking at using this tool it would be good to know the symptoms of a memory corruption/leak.


Memory corruptions usually manifest as native crashes in dlfree or *alloc methods with invalid pointers like 0xdeadbaad . Here is sample call stack where you could suspect a heap memory corruption.



In the above scenario the module calling calloc crashed as the heap is already corrupted. The next steps would be to enable libc memory debugging options to identify source of corruption.

Memory leaks usually trigger Out of Memory Java exceptions or will result in OOM killer invoked. The procrank and librank output will show high memory used by the application  (Assumption: The data was collected before the app/process was killed)


In the above scenario, com.android.foo.bar app has a lot of memory allocated. It is likely this app is leaking memory . We could use libc’s memory debug options to identify the source of leak.

Enabling the option:

The next step is to enable the debug options of libc.
On a rooted device , we could enable libc malloc debugging with following steps:


The libc would now run in debug mode and will track memory allocations and corruptions.

Debug level 10 is a good option to setup. It would detect both leaks and corruptions. See here for a complete list of debug levels. 

Now run the original use case that caused the crash/corruption. There would be extra logs from the libc module if there is corruption/leak.  Memory leaks will usually show the call stack of the allocation and the number of bytes leaked.


Memory corruptions will have a slightly different signature. Here is the log when the library detects corrupt heap.


False Positives:

When using this mode we have to be aware of false positives too.

For e.g.: If an application was terminated abruptly (via ‘adb shell kill –9 <pid>’)  then memory that was not properly de allocated would be reported as ‘leaks’ by libc.

Likewise there could be false memory corruption logs if we use  memory optimization modules that manipulate the heap nodes.

However such false positives are very rare. Even if they occur ,they usually show up in generic modules (like Android shell) which could not be suspected to have leaks.


Written by sujai

October 14, 2013 at 6:53 pm

An Android 101: Hardware and HAL

with 2 comments

Unlike traditional Linux based systems, Android applications communicate with the underlying hardware through Java APIs not by system calls.


             Figure 1: Android vs a Tradition Linux system.

Most of the ‘shared libs’ in the above diagram represent the HAL modules.  The Hardware Abstraction Layer or HAL is the glue between any device (part of the kernel) and the corresponding JNI interface.

The details about the HAL is usually not of interest to application developers. However it is an important module for hardware vendors and OEMs involved in  porting android into their own hardware and adding new hardware.

Folder structure:
   The HAL source code reside under the hardware folder . OEMs maintain a top level root directory and internally there are several HAL modules for the corresponding hardware.

On device ,the HALs live as .so’s  either in ‘/system/lib/hw’ or ‘/vendor/lib/hw’. The HAL modules follow a certain nomenclature as defined here . Android relies on this naming convention to load the right HAL module for a given hardware and board configuration.


The HALs get loaded by its clients using the  hw_get_module. This method relies on the values set to ro.hardware , ro.product.board and some other ro properties to load the correct .so. The complete list is here.
For eg. The SurfaceFlinger is the system wide compositor and the hardware composer is a HAL that abstracts device specific composition logic. The SurfaceFlinger loads the hardware composer using the hw_get_module method to get a handle of the HAL.

Each HAL implements a set of hooks which get called by their invoking service. The contract between the system service and the HAL is well defined. Device makers should ensure these interfaces are implemented as expected by the Android services. The figure below tries to show some of the HALs on the Android ICS version and key methods that HAL writes should implement.


With the newer versions of Android ,the scope of HALs have expanded and it is likely they will be used not just to abstract hardware but to abstract any device specific behavior.


1. Good site about  adding support for a Camera : http://processors.wiki.ti.com/index.php/TI-Android-DevKit-Camera_Porting_Guide
2. Patrick Brady’s Google I/O talk: https://sites.google.com/site/io/anatomy–physiology-of-an-android
3. Figure 1 courtesy: http://www.cmg.org/measureit/issues/mit78/m_78_3.pdf
4, Class diagrams created using Umbrello ,an open source UML Modeler.

Update:  Here is a new post on the same topic with much more detail:  http://www.opersys.com/blog/extending-android-hal

Written by sujai

June 25, 2012 at 7:42 am

Innovative iPhone and Android apps– 2011 Winter edition

leave a comment »

After my first post this year, there have been many more interesting apps that caught my attention.It is pretty good to see a lot of innovation in the mobile industry by people outside of this domain. So here is my next list for the year. We could say it’s the ‘Winter edition’ of 2011!

The Invisible Universe:   Joshua Peek  is a fellow at the Columbia University studying about galaxies. As an astronomer he sees a lot of things in the space through his telescopes that we couldn’t see.  So he has come up with AR app called Invisible Space. The app is loaded with a database of full sky images of the galaxy.

When someone holds the phone up in the sky,this app would load the image of the galaxy at that orientation.. I liked this app for bringing in lot of informative stuff using simple techniques.

Here is a good intro video: 



This app is hosted here on the Android Market: https://market.android.com/details?id=com.lbi.iu .

PitPatt : The next app is pretty cool and pretty scary too. This is what happens when Minority Report meets Android.  Researchers at CMU have come up with an advanced Pattern recognition algorithm that allows anyone to know your real identity in under 60 seconds , by just taking a your picture with your smartphone.

Pitpatt has been acquired by Google and soon we could see this tech on Android.The app is not publically available yet.There is more detail on this app here.

Vocre :  I mentioned about translations apps in my  previous review too. This time there is one more vocre-logotranslator app that has won lot of accolades. Vocre from myLanguage can translate what you speak into nearly six different languages (including Mandarin).  Usage is pretty simple .You speak in your language and tilt the phone to translate. There is a nice demo at Vocre’s home page explaining the idea.

Appmates from Disney : My last innovative app is also the best on this list . This app is soo cool that I would buy and iPad just to try this app.  Disney’s new app allows you to drive real cars on virtual space and the virtual terrain reacts to the cars!! 

All you need is an iPad with the free Disney app and get one of those special  Lightning Mcqueen toys. Here is an elaborate demo.Have a look and you’ll be quite impressed.



The tech around this is a hot topic on Google + and I was able to glean some info on that. The inventor has couple patents on it.Now that is ONE cool idea to be patented !  Here is more info on this concept .

That’s it for now. Like many I would be eagerly following the ‘Lets Talk iPhone’ event today (Oct 4,2011). I am particularly interested to see what they are going to announce about Virtual Personal Assistant using the technology they acquired from Siri.

Written by sujai

October 4, 2011 at 7:04 pm

On apps and security .

with 2 comments

While the appstore phenomena has brought is a lot of cool utilities to your smart phone, there are side effects too. Last week saw one of the most dramatic demonstration of what many have been fearing for sometime now. Malware on Smartphone!

And with some intelligent social engineering tricks, it could invade the ecosystem in the matter of days .

evil_android_thumb Several android web pages reported of a very powerful malware that got into the Android market place. Here is how the app installs the malware.

The malware publisher (goes by name Myournet) takes some of the  popular android games and then injects root exploits into the application package and republishes the apps back. All these are variants of the original popular apps, but but they are available FREE. Within days several users download the app and install it. A detailed report is here.

How it works: The malware actually installs a rootkit and ‘steals’ all personal information on your device and sends to a remote location. Besides the malware always opens up a backdoor with your device allowing more worms/malicious code to be run.  This blog post by a mobile security firm has the gory details.

Some points to note:
* The malware’s existence was not known by Google until someone posted about it in public domain .
* While Google was (somewhat) swift to respond , the damage was done. Private data from many phones have been sent to a nefarious user. Would have been very good if the app didn’t enter the ecosystem in the first place.
* Community to the rescue : Google responded by nuking the app with its kill switch. But then the first fixes came from members of XDA.

We can be happy that though the Android market is ‘open’ Google has put in some features in platform to recover back .

How about genuine apps ? Malware isn’t the only security threats to private data. The  Freedom to tinker website had a  blog post recently on the information shared by some of the popular Smartphone apps. The author had used sniffing tools like wire shark to sniff his Android phone.

F5T0XHAF04FMXU0.MEDIUM copy[19]The Android face book app sends stuff out in the open so anyone could read your posts..  It is also possible to make bogus posts, the author says. Some things to be careful of.

Wired’s ‘open’ edition: I’ll close this blog with a note about a recent Wired magazine issue that sums it up all.Some of the wired magazine  subscribers got a ‘very personal’ edition of their copy.   It had lot of information that Wired had gleaned about the subscriber!! The editors used online browsing history, electoral records and ‘social networks’. The magazine just shows how much information we expose unknowingly.

When they do this exercise the next time, they will have yet another ‘gold mine’ of private information -your ‘smart’ phone!

[Image credit : Mobilecrunch , Prohack]

Written by sujai

March 12, 2011 at 9:41 pm

Innovative iPhone (and Android) apps: –2011 edition

with 3 comments

    Of all my blog posts, my brief review on  iPhone and Android apps have been the most popular. So here is a 2011 edition covering some of the newer ones!

When the iPhone was  launched ,the ‘proximity sensor’ and the ‘accelerometer’ were the hot things and most apps were using these sensors. Fast forward to 2011 and the new theme is AR and NFC. Of this NFC apps are really hot and may well be the next disruption after AR.


AR.Pursuit:  First demoed at the CES 2010, the AR drone was drawing lot of interest event at the recent  CES 2011. Parrots’ quadricopter supports an inbuilt wifi system and video  streaming.

 logo_arpursuit The AR.Pursuit integrates all these into a nice iPhone app to give you a very impressive game. The demo video says it all.


SkyGaze : While AR.Pursuit is mainly recreational here is another AR app that I think would be appreciated by all amateur sky gazers. Using Sky Gaze is very simple.

sceen_shotJust point your  iPhone to the sky and the app shows you exactly what you are looking at . Full marks for this very simple utility app that serves a great need for anyone interested in sky gazing.


Venmo:  After looking at some recreational apps, here are some apps that may one day become big utility apps of your mobile. Venmo is a service that links your phone to a credit card and make or receive payments . Predictably its still not for huge transactions and there is also a trust factor ..so its only between ‘friends’ .

  The Venmo service/app, solves a very subtle problem of keeping balances between friends. Imagine you had dinner with your friends and you had to split the bill among them. Venmo allows you to charge your friends the split amount either online or via a text message.


Starbucks Card mobile:  Launched as a pilot program sometime back the card mobile app is a imageshit and now it is available throughout the United states. The payment is not via WiFi or Bluetooth (considering security)  but a unique ‘bar code’ that is scanned by the system.

side note: The barcode is unique but you could take a snap and reuse it as explained here .


 nfc_logo NFC apps are yet to catch-up .Actually we are all waiting for the iPhone5 to go big time with NFC payments. Google’s Android 2.3 (GingerBread) already supports NFC. Some of the rumored apps for the iPhone5 are very interesting .

Taglet is one of the first NFC apps available for Android. The use case is similar to exchanging phone information over BT but may be much more easier and could be able to read any kind of information.


To me the NFC technology also seems a security threat.  The protocol by itself doesn’t ensure secure communication and its possible  to have passive NFC listeners eavesdropping your data once it enters the field of communication.

So that’s my little list of cool iPhone and Android apps. The Angry Birds is not part of this review.Don’t get angry for that !


Google Translate – This list missed a very innovative app. Google Translate app for Android has been  has been around for  quite sometime . And lot of enhancements have been made to it recently. But the latest (experimental) Conversation mode is something from the sci-fi era.

It brings to reality the Universal translator  of sci-fi movies. You could speak in your native language,the phone translates and plays back in another language. Real time speech to speech that is.

Pretty cool technology and would really come handy if you are a tourist and want to
buy something from a dealer who does not know English. Here is a nice demo of this feature by Eric Schmidt.

Written by sujai

February 14, 2011 at 8:59 am

Tech this week : 28 – Jan.

leave a comment »

RealNetworks is back :   Ever wondered what happened to Realnetworks  after we all  streamed content via Youtube?  Well, Realplayer and the .rmv format may not be in vogue but the company is still alive. At CES 2011, real networks previewed Unifi .

unifi1   Unifi is a cloud service much like Dropbox .More specifically, it is aimed at unifying all your digital content across multiple devices and multiple apps(e.g..face book pictures)  at a single place.

  Unifi looks a very  promising utility. Think of accessing that very old picture of your  friend right when you meet him after several years right when you wanted it. The service won the CNET best of CES in the Software category.

Breakthrough  patent: Last week I also read about a patent by a MA based company for a
‘proprietary organism’ . Joule Unlimited claims to have developed a ‘library of proprietary Helioculture_image - courtesy wikipedia organisms’ that could directly convert to CO2 to  liquid hydrocarbons and ethanol .So that is real crude out of CO2 much  like photosynthesis.

The company has also made some very lofty claims and it has to be seen how much this becomes true. If true this would be potentially game changing with no need to drill for crude.

Let me end this post with a news item from India.

BiharSeal Bihar goes ‘Android’ savvy:   After so many years of backwardness, Bihar seems to be under  good hands .Nitish Kumar swept the Bihar elections last year  routing all the traditional parties in that state . I recently read of  Bihar’s Road Construction Department (RCD) using smart phones to track  urban development in the Naxal hit parts of the state.

  The RCD engineers would use the phone to take pictures of construction site . Photos taken using the ‘android’ phones would verify that the pictures were actually from that place .The supervisors could also track the whereabouts of their employees ,thanks to the GPS feature on Android. 

  Why Android phones and not any other phone OS ? The authorities say that ‘Unlike other OSs  Android comes will most of the ‘Google features’ prepackaged and the RCD would
use these features very easily.   It could come very handy for a government that built close to 23,000 km of new roads just in the past 5 years!

Written by sujai

January 28, 2011 at 11:03 pm

Posted in technology

Tagged with , , ,

Tech this week:14-Jan

leave a comment »

So 2011 has begun  ..and one of the thought I had was to resuscitate my ‘Tech updates’ thread that had become very infrequent.

January 2011 began with CES 2011, arguably the biggest tech event in the planet.  I don’t know how many of the ‘announcements’ will eventually be successful…but this post is about some of the eye catchers from the event .

Tablets everywhere : Yeah tablets are everywhere this CES and the hype is  so much that is Android-Honeycombovershadows everything else.  The biggest announcement of course is the Honeycomb from Google and Motorola Xoom device.

The Xoom device is powered by NVIDIA Tegra 2 a Dual core ARM Cortex-A9  chip with some impressive Graphics horsepower. Some of the applications like the new Google maps seem good. But we got to wait and see if this can match iPad.

Moto Atrix – Best from the show? : Apart from the XOOM , MOTO’s Atrix is making rounds as the ‘most powerful smartphone in the planet’. Its again Tegra –2 with both running at 1GHz  and a 1G RAM!

Especially the dock feature is a cool idea. It is a demonstration of what some would call  as ‘modular computing ‘. Have a look.There was a similar concept sometime back as well…but in that case the laptop was not having some processing and not truly a dumb extension as with the Atrix. So the technology behind Webtop is intriguing. Some say its another VM that the native android on the Atrix phone starts and hosts its apps .

Google search – some updates: I felt the change for sometime now.. and after reading this google-knolpost, I know its not just me but many others complaining that relevancy of Google search is getting down. One could argue on this that its not Google’s problem ,but the overwhelming spam content that is causing the issues,  but didn’t we all set Google as our home page thinking it should just give me the best results no matter what?

Written by sujai

January 14, 2011 at 10:17 pm

Posted in technology

Tagged with , , , , ,

%d bloggers like this: