Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top