paint-brush
Did VOLD-emort Just Kill My App?by@aditibhatnagar
623 reads
623 reads

Did VOLD-emort Just Kill My App?

by OffgridAugust 10th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

VOLD stands for "Volume Daemon", a service responsible for detecting and mounting/un-mounting of all the external or extended storage media in Android like USB, SD Card etc. VOLD is responsible for "mounting" of external storage media. When I remove the SDCard, my app just crashed! My app was accessing the APK file on that file to get the icon image. I was using dummy icon for all the files but for APK to extract the icon from it's manifest file, which goes like this. The break point wasn't even hitting, the app crashed that fast!

Company Mentioned

Mention Thumbnail
featured image - Did VOLD-emort Just Kill My App?
Offgrid HackerNoon profile picture

I have been playing around Android OS for a while and this post is one of the learnings I wanted to share. The misleading yet catchy title still points to the essence of this post - yes, we are going to talk about the VOLD demon. Sorry *daemon.

What's VOLD daemon?

VOLD stands for "Volume Daemon", a service responsible for detecting and mounting/un-mounting of all the external or extended storage media in Android like USB, SD Card etc.

When an Android OS is booting up, it sets up a set of core services, these include adbd, service manager, logd, health, lmkd, and vold itself.

Being a mount daemon, 􏰔􏰋􏰚􏰏 VOLD requires a configuration file, to list known file systems and their mount points. This file is referred to as the file system table, or fstab, for short. Prior to 4.3, it was called /system/etc/vold.fstab, and mapped the file systems by their block device paths, in /sys.

So, that was a brief on what VOLD is all about.

Getting back to the question, how and why did it kills my app?

Here's a brief about my app:

The app is pretty useless, I was just trying to read files from SDCard and showing them in a view with suitable icon image next to the name of the app. These files included APK files as well. I was using dummy icon for all the files but for APK I was using the age old way to extract the icon from it's manifest file, which goes like this. (Courtesy: StackOverflow)

Now, when the SDCard was inserted, my app happily showed all the files found on the SDCard, including the neatly extracted app icons for the APK files on the SDCard, however, when I remove the SDCard, my app just crashed!

- Checked the logs - no exception flashing up in red, nothing significant.

- While debugging, the break point wasn't even hitting, the app crashed that fast!

So, I was left pretty clueless. After spending some time, I read this message, a one liner, kinda lost in the overwhelming crowd of log statements. 

It said 

10-13 09:21:56.471   431   436 E ProcessKiller: Process myuselessapp (8853) has open file /storage/emulated/0/Android/data/myuselessapp/test.apk 
10-13 09:21:56.471   431   436 W ProcessKiller: Sending Interrupt to process 8853

So, what went wrong ?

My app was accessing the APK file on SDCard to get the icon image remember? Looks like *perfection kills*, had we used dummy icons for APK files too, it would have never crashed. In the view when icons and app names are displayed, our app maintains symlinks with the files on SDCard (in order to get the APK icon).

So, our app (process) has a symlink opened to a file which no more exists as the SDCard is removed. 

Now, honestly it was a bit harsh for Android to just crash our app for this gesture, but it does:

Here's the code directly from Android repo which does this: Reference


It finds all the processes that have files open on the SDCard and issues a kill command for all of them.

So, that's why and how VOLD daemon killed my app. 

Interesting, huh?

Well, there's a lot to explore in these core services in Android and how they operate. I'll be exploring them next and keep you posted here :) 

Let's connect on Twitter @4ditiBhatnagar for more engaging discussions on such topics.

Hope you found this useful, see you in the next post soon, till then keep hacking and take care!

References:

Android Code: https://android.googlesource.com/platform/system/vold/+/a19b250bd273455933ca3502cf2c2e0a803aff77/ProcessKiller.c#183

Slideshare: https://www.slideshare.net/wiliwe/android-storage-vold

Android Internals : A Confectioner's Cookbook by Jonathan Levin

Totally irrelevant diff: Link