Android - How can I find app name by UID?

Android assigns each application a UID (User ID) at install time; unlike PID (Process ID) which is transient and keeps changing all the time, UID stays constant as long as the application is not reinstalled. The UID should be unique to each application, except when the application explicitly requests to share a userid with another application (there are security restrictions around this, the two applications must be signed with the same private key, i.e. comes from the same developer).

These applications claims to show UID of applications:

  • https://market.android.com/details?id=redfishandroid.appexplorer
  • https://market.android.com/details?id=com.sayhello2theworld.te

EDIT:

Try looking at /data/system/packages.xml (you need root to view this file), each installed application should have an entry there. Say, I have Adobe Reader installed in my phone:

<package name="com.adobe.reader" codePath="/mnt/asec/com.adobe.reader-1/pkg.apk" flags="262144" ts="1300539048000" version="37149" userId="10034" installer="com.google.android.feedback">
<sigs count="1">
<cert index="21" key="... very long random string ..." />
</sigs>
<perms />
</package>

My phone have assigned userId="10034" to Adobe Reader.

For applications that have requested to share user id with another application, say Handcent:

<package name="com.handcent.nextsms" codePath="/system/app/HandcentSMS.apk" flags="1" ts="1217592000000" version="373" sharedUserId="10064">
<sigs count="1">
<cert index="17" key="... very long random string ..." />
</sigs>
</package>

then the attribute you're looking for is sharedUserId="10064"


Prerequisites: set up adb in a PC, connect the device to the PC, launch a shell on the PC to enter adb commands.

Note:

  • Replace UID wherever it occurs in the following commands with the UID you're searching for.
  • The commands below would only provide the package name of the app corresponding to your UID. To get the app label/name after obtaining the package name, you can use my answer here, or of GAThrawn's or of Izzy's.

For Android 8.x and above

Enter the command:

adb shell cmd package list packages --uid UID
adb shell pm list packages --uid UID                 # alternative command

Example:

$ adb shell pm list packages --uid 10250
package:com.adobe.scan.android uid:10250

For Android 7.x and above

Enter the command:

adb shell "cm package list packages -U | grep UID"
adb shell "pm list packages -U | grep UID"           # alternative command

Example:

$ adb shell "cmd package list packages -U | grep 10247"
package:dev.ukanth.ufirewall uid:10247

For any Android version (tested from Android 4.2.1 to 10.0)

Enter the command:

adb shell "dumpsys package | grep -A1 'userId=UID'"

It might take a few seconds to print the desired output.

Example:

$ adb shell "dumpsys package | grep -A1 'userId=10102'"
   userId=10102
   pkg=Package{46171ce com.android.chrome}

The line containing Package{ would show the package name of the app in between whitespace and }. You can do adb shell dumpsys package PKG_NAME (PKG_NAME → package name of an app) to know more details about that package/app.


For rooted Android versions

If the Android is rooted, than using adb shell or a terminal emulator app you can do:

su
cat /data/system/packages.list | grep UID

In the output, anything before the UID would be the package name.

Example:

shell@shamu:/ $ su
root@shamu:/ # cat /data/system/packages.list | grep 10102
com.android.chrome 10102 0 /data/data/com.android.chrome default 3002,3003,3001

Alternatively, if you've Busybox or Toybox installed and available under PATH variable, than from a terminal emulator or adb shell do:

su
find /data/data/ -type d -group UID -maxdepth 1 | xargs basename

Example:

shell@shamu:/ $ su
root@shamu:/ # find /data/data/ -group 10102 -type d -maxdepth 1 | xargs basename
com.android.chrome


Install a terminal emulator, launch it and run:

ps | grep 10058

ps lists the processes and grep filters for the ID you want.

But this only works if the application is running when you run the command.