1

I have suspicion that some of the error reports I've received (unable to open database, or null returned by Context.getFilesDir()) are due to bad underlying linux permissions; I've seen a few references saying that sometimes android apps get into a bad state where the owner of the application's data dir is a different UID than the one assigned to the application.

So on a working device I used

adb shell
run-as my.package.name
ls -lR

and got a UID of u0_a29. I also ran this snippet of code:

PackageManager pm = getPackageManager();
ApplicationInfo packageInfo = pm.getApplicationInfo("my.package.name", 0);
Log.d("UIDTEST", "Package " + packageInfo.packageName +
    " has uid " + packageInfo.uid);

and got a UID of 10029.

Presumably these are in fact the same value, seeing as how the app works on this device, but what's the actual relation here? Is it "take the last 2 characters, discard the rest, and prepend either u0_a or 100 depending on which way you're going"? Because that seems very odd. The a29 looks like hex but of course that comes out to only 2601. I'd like to understand this before deploying code out to the field to try to capture this information from the broken installs.

benkc
  • 3,292
  • 1
  • 28
  • 37

1 Answers1

2

u0_a29 is a user name, not a UID. On a desktop Linux distro, you'd see benkc or mmurphy.

The id command shows the user ID and user name that your run-as environment is running as.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • That makes so much more sense. Thanks! – benkc Jun 11 '13 at 23:12
  • 7
    BTW, this is the new format on devices that support multiple users. 'u0' stands for 'user 0' (the first/default user), and 'a29' is for 'app 29'. As for the UID, Android will multiply 10000 (`AID_USER`) with the user ID (*not* the same as UID!) and OR with the app UID to get the effective UID under which the app executes. For users other than the default one, you will get something like u10_a3 -> 1010003 (10000 * 10 + 3) . – Nikolay Elenkov Jun 12 '13 at 02:26