19

For the next version of our application, I want to change the sharedUserId since we now use an internal control dashboard app which must write to the other app's settings files.

But since the app is already installed on many phones, will this be a problem? I ran a little test on the emulator, and I'm seeing exceptions in the device logs that *.bak versions of the preference files cannot be written. Not sure how critical that is. Curiously, safing settings still seems to work, even though the shared_prefs folder had been created using another Linux user ID.

Did anyone try this before?

mxk
  • 43,056
  • 28
  • 105
  • 132
  • okay, looks like this will be impossible, dang. It crashes when trying to access a database file that had been created using a version of the app that didn't have a custom user ID set. What's the default user ID anyway? Could the second app maybe set its user ID to the default user ID of the first app? – mxk Jul 15 '10 at 15:54

2 Answers2

28

And to answer my own question again:

No, it's not safe. Since updating an app via Android Market will not remove the database and preference files, the new version will not be able to read or write these files (since they were created under a different Linux user ID), and the app will crash after the update. You would have to ask your users to completely uninstall and reinstall the app, which is certainly not recommended.

As a general rule I conclude from this: Whenever you start out developing a new app, make sure to set a manual android:process and android:sharedUserId attribute! It doesn't hurt in case you don't need it, but it gives you full control over which apps have access to this app's private resources.

mxk
  • 43,056
  • 28
  • 105
  • 132
  • 2
    Thanks for posting that, I was almost publishing an update of sharedUserId.. Sadly we never learn that when we are creating the app :/ – Paulo Cesar Dec 12 '11 at 15:45
  • For those of us who didn't plan ahead, is there a solution to this problem? – Barry Fruitman Feb 10 '12 at 22:48
  • 1
    @BarryFruitman If it's not a problem to lose the user's data you could use new files with different names. We had to do this once due to an Android bug that rendered our files unaccessible on some devices. – Oderik May 23 '13 at 19:39
  • A simpler solution is to not use `android:process` (user-hostile) or `android:sharedUserId` (pointless, with problems better solved by IPC and `signature`-level permissions). – CommonsWare Oct 08 '13 at 22:51
  • If I try to update an app with a different sharedUserId, it won't even install. Installation error: INSTALL_FAILED_UID_CHANGED – Mark Mar 21 '14 at 16:26
  • Thanks for posting. Is any change in the newest version of android? My app already published with out `android:sharedUserId` and now I want to share the data. Is there any solution for this? Or do you know what is the default value of `android:sharedUserId` if we dont set? – Anh Vu Aug 15 '17 at 10:54
  • I had the same problem but Google Play store just won't update the app. I suppose that's better than installing and crashing. This ABSOLUTELY needs to be mentioned in the docs!! – Carson Holzheimer Sep 12 '17 at 11:36
2

No solution as of now, but starring at registered issues might get Google to fix this:

http://code.google.com/p/android/issues/detail?id=1227

http://code.google.com/p/android/issues/detail?id=14074

3c71
  • 4,313
  • 31
  • 43
  • The problem being, this is not a bug, it's a feature. Without specifying a shared user ID, Android (or the underlying Linux) will assign one for you. As soon as you set one, it'll be different by definition. Since on any Linux system, one user is not allowed to access another user's files unless granted permission to do so, this is pretty much the expected behavior. – mxk Sep 06 '12 at 12:15
  • True, but the bug mentioned is the fact the Android OS fails to recognize a sharedId is assigned/changed and update the rights of the already installed app data accordingly. – Will Kru Dec 20 '12 at 11:32