Wednesday, May 19, 2010

Android's sharedUserId

Android is a wonderful platform for development. It also provides good security framework. Each application has its own user ID and thus application A can't directly access the data of application B. So, Android is quite resistant to viruses plague. In contrast to Windows.
But this security makes it difficult to develop a set of applications which should work tightly with one another, e.g. browser and its plugins, translator and its dictionaries, etc.
To address this problem Android provides the developer with sharedUrerId attribute in manifest. Setting the same sharedUserId to multiple application and signing them with same signature will enable them to access one another's data. Great!
But... but there are two nasty bugs related to sharedUserId which you must take into account.
  1. Issue #3763 messes up if you decide to change the sharedUserId value.
  2. Issue #1227 bites you if you add sharedUserId to your application.
In both cases after upgrade to the new version your application won't be able to access its own data (probably, because its user ID was changed, but chown was not called on its data). You'll see some strange errors in console. Like database can't be opened.
So, if you are developing some application for Android and if there is even a slightest chance that the application might need to use sharedUserId attribute - use it right from the start. Before uploading the application to the Market. And don't change sharedUserId value in the future.

Update. Issue #1227 just celebrated it's 5-th birthday. And people are sill affected by the problem. Looks like Android is getting closer to Java when it comes to anniversaries of important issues.

5 comments:

FreddyT said...

Hey I ran into this issue while testing with the emulator. I am thankful I found you blog and did some research before I released an update! Did you find a decent method around this yet? We need to drive some attention to the new bug report that was opened up since the old report is being ignored!!

Andriy said...

2 FreddyT:
There is no workaround (at least I don't know any).
Google is aware of those issues. Unfortunately it thinks the issues are not important. What we can do is to vote on those issue (star them). I already did so long time ago.
But as of now issue #3763 has 12 votes and issue #1227 has 22 votes. Apparently those issues are not important for developers. Probably that's the reason Google does not hurry to fix them :(

Karthikeyan Selvaraj said...

hi, i am karthick.. Now i am using one app database. how to open same database different application. now i am use android:sharedUserId get some error on my android manifest file. so please help me. how to access same database another app.

Andriy Tsykholyas said...

2 karthick:
both of your apps must:
1) have same android:sharedUserId;
2) be signed with same signature

The whole process is well described on stackoverflow

Grant Luck said...

There also seems to be a problem with in-app billing if you declare a sharedUserId. Check out issue #90