Sunday, February 13, 2011

Instable Android, and the 'unable to open database file' bug

Hi everyone,

Welcome to this little ( and scary ) episode of my Android user life :

Yesterday, I came back from Canada. So in the plane, I turned my phone off.
And when I turned it on... It became a (little) nighmare...

I got something like a just installed Android on my phone. So I had to link the phone to my gmail  account again, accept the different Terms Of Service, etc...
Ok... Not that complicated... Not the thing you want to do in the airport, that early in the morning, with not much sleep and a big jet-lag, but, it's still feasible.
Then the background had changed, and all of my shortcut and folders have vanished.
Once again, it's a little painful, but still manageable...

Then I quickly discovered that there was more than just that...
Actually, my android version is now quite bugged :

A Bugged Android :

* All the application installed on my SD card had disappeared !! There are more than one year of 'Spy My Apps' data on it, so this one IS serious. I just than I will find a way to get them back.
* the lock screen is still present, but any combinaison will unlock it !!! This one was rather funny ( at least for me ). Resetting the combinaison in the settings fixed it.
* gmail, Youtube, Google Maps were still in the old version, so I could rapidly found that I prefered the new ones ( but waiting a little get them back automagically ).
* For a reason I still can't understand, Twitter was already in the 2.0 version, but the market was unaware of that, so it tried to download and reinstall the 2.0 version, and just failed. I had to unistall and reinstall it to have the market happy again...
* Finally, and it is perhaps the most important, a lot of application ( my own "Word Prospector" included !!! ) just failed now ! Actually all the applications previously present on my phone and that were using a database are now unable to open it, although they find it.

The "unable to open database file" bug

Actually, I find it quite funny, because for a long time I have this bug in my game where the database couldn't be opened. This bug was strange, because I couldn't reproduce it. Some people had some information that it was coming with a reinstallation of the OS, but I did several OS upgrades without any issue...
Here are some people worrying about this bug :
Here is a google issue on this one :

The good news is that with this bug present on my phone, perhaps :
1) I can manage to find something to do to fix my game ( actually I would rather call it a workaround rather than a bug )
2) Perhaps someone from google can contact me so that we can try to find where this bug is coming from ?

This bug is affecting ALL the applications that are using databases on my phone, and that were installed on my phone before the reboot.
It is affecting both applications that were installed on the main memory and applications that were installed on the SD card ( in this case, when it would crash after the reinstall ).

Here are some applications that are crashing :
* AndroBlogger ( a blogger application ). It looks like it is crashing because it's using Google Analytics, that in turn, uses a database.

* The official Google Blogger application. For some reason, I don't have the callstack in the logs, but those lines :
Couldn't rename file /data/data/ to backup file /data/data/
and :
Sqlite3_open_v2("/data/data/", &handle, 6, NULL ) failed.

* Yahoo Mail, with the 'Unable to open database file" line in the callstack

And many others...

Actually, it looks like :
Using google Analytics make the application fail
Using Flurry makes the application fail
And using a webview makes the application fail, as the webview uses a database to store its associated cache.
Admob needs to have access to some image cache, and then crash if it can access it.

Note that clearing the cache / data in the application part of the settings does NOT change anything.  (I imagine it does not really clear the files that create the crashes ).

What can be the cause of the issue ?

My understanding goes like that ( I'm far from being sure it is worth anything, but let's give it a try anyway ) :
When you install an application, some disk space is available for this application only ( data/data/ApplicationName/ ).
To insure that ony the application will have access to this data, I imagine Android uses user rights at the Linux level.
Then when the 'strange Android reinstallation' occurs, perhaps there is a change with the user, and the right are no longer granted. But as the folder name is still the same, the application can't open any file already inside.

What next ?

I imagine a "factory data reset" would reset my phone in a stable state.
But I would first like to try to create a workaround for 'Word Prospector', that would just be to catch the exception around the database usage, and in case of problem, would retry with another database name.
I would still like to find a way to get my data from 'Spy My Apps' back. I'm not sure there is any chance for this one, but... for the moment, I would like to be optimistic.

And... if someone from Google could fix the bug, it would be very nice !!!!


Vivi said...

maybe here U can find answer to Ur bug

Aigars Mahinovs said...

Do you have root on that phone? I have an inkling that this might be related to POSIX extra attributes, I had a similar problem on my servers once - the filesystem was created with a kernel that did not know about ext2/3 extended attributes and thus those field were not zerroed out and contained random data, so when it booted into a new kernel with extended attribute support all things broke as random extended attributes made files undeletable or inaccessible.

AndroidBlogger said...

No, I am not root on this phone...
Actually, I think I will finally try to be root to get my data back.

For the moment, I keep this configuration to make my game robust with this bug.

From what I understand, each application has its own ID ( that you can overide see : )
And I guess, for an unknown reason, the Id that was automatically affected changed.

Note that my Os version is the same, so it's not a new kernel...

Screaming Hawk said...

Damn... Sorry I can't be of any help. Next time you might just want to use the 'flight mode'. Haha. Following your blog. Just beginning with Android development

WH said...

For what it's worth, this happened to me roughly every six months on my old G1 (Android 1.6) phone. It'd suddenly look very odd, the ringtone selection would change, the screen could no longer be properly locked (also, the Home button no longer did anything). Each time I did a full factory reset and that sorted things till the next time. (I think three in total, before I moved on to a newer phone.)


AndroidBlogger said...

I think I will finally come to the full factory reset.
I'm still unsure I will root my phone before, to get some backups of some now locked files.

The last instability I endured is that my phone just doesn't see anymore my home wifi.
It can see all of my neighbor Wifi.
My other devices ( G1, Archos 5IT, laptop ) see the Wifi right.
But for my phone, there is just no more such wifi...


Naveen said...

0 down vote

Hello all, Please help me i am handling bulk of data from databases folder.i am able to access this db on android emulator data/data/package name/databases/here---db.but i am not able to access this folder on android folder is not exploring.Please help me someone,i am thanking you all advance.please help me....

Jacob Dixon said...

This is really seems to be a huge problem related to database connectivity as well as some system files too. It could lead to loss of some of your important files from your SD card also. Need to take help of some expert developer. Keep posting such comments as it gives us a chance to know some new kinds of problem faced with android.

Android Application Service said...

It seems to be a problem related to database connectivity to the system. Furthermore, it ca cause lose of the important data of the SD card so that my request to contact any expert android expert as only such kind of the person can give you the best solution regarding your this problem.

Unknown said...

For quite a long period I was using an App without any problem but suddenly a few days back this error is popping up in the Logs.

Simply its weird. Don't know what to do next. :(

The right side said...

This scenario happened to me also. android version 2.2.1