By

Where Data Lives on Android

Recently, I've been looking at the old Audio Handler code that was contributed a while back and why it can only play on the SD Card. I assumed that there was some weird permission issue that didn't allow for data to be written in other parts of the device, but I didn't look into it too closely until recently.

In PhoneGap, the files that are being loaded are stored in the assets directory. The decision to do this was because they could be accessed through file://android_assets, and this seemed to be rather convenient for the time, since I wanted to prove that you could in theory take the HTML and Javascript from an iPhone PhoneGap app, and put it into an Android App and have it still work. However, the issue is that this is not really a file location.

All files in the Android solution are zipped up and compiled into an apk, which is signed and installed on a phone. Dalvik comes across this package, and runs this package much like a traditional Java VM runs a JAR. The big difference is that if you're trying to do things like access a file natively, store data into a database, or run an executable, this doesn't work. Now, in the past, we just used the SD card for when we needed file storage, BUT last week when figuring out the WebKit SQLite Support for Android 2.0, I discovered where the data actually was being stored on the device, in the /data/data/package_name/ directories.

I then decided to look at how other people are using this storage, and I checked out the Orbot project. A while back, I had a passing interest in porting Cryptographic tools such as OTR and Tor onto Android so that I could have this on my phone. However, other people who are more dedicated to making awesome things, actually made this happen with Orbot, and shared the source. I saw that they were grabbing an executable written in C, and storing it in the data directory. This allows for ARM code to be run on the device, and allows people to get around the Android SDK, and the problems that it has.

So, I'm faced with a dilemma. Do I keep with storing the data in the assets directory, or do I copy the www directory to the /data/data/app_name/www directory and allow the files to sit in the Application FS storage? Will there be an issue on initial install? Will Android PhoneGap require a loading screen where we do this sort of heracy? Putting layout and executable code in the /data/data directory herasy? What do you think?