How to Find App UID
Android assigns each application a UID( userID) at the 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, i.e. there are security restrictions around this, the two applications must be signed with the same private key.
Android uses the UID to set up a kernel-level Application Sandbox. The kernel enforces security between apps and the system at the process level through standard Linux facilities such as user and group IDs that are assigned to apps. By default, apps can’t interact with each other and have limited access to the OS. If app A tries to do something malicious, such as read application B’s data or dial the phone without permission, it’s prevented from doing so because it doesn’t have the appropriate default user privileges. The sandbox is simple, auditable, and based on decades-old UNIX-style user separation of processes and file permissions.
How to find out the UID of a process:
Enter adb shell mode and issue the ps command.
The following results can be obtained.
USER PID PPID VSIZE RSS WCHAN PC NAME
system 198 35 129244 33328 ffffffff 40011384 S com.android.settings
app_9 224 35 145148 45552 ffffffff 40011384 S android.process.example
app_0 244 35 128604 33296 ffffffff 40011384 S com.android.calendar
app_15 277 35 125664 32712 ffffffff 40011384 S com.android.deskclock
This time I will check the UID of example.
From the result of the ps command, you can see that the USER of example is “app_9”.
Then switch users with the su command.
# su app_9
You can then find the UID by issuing the id command.
The execution result is as follows. The UID of example seems to be 10009.
uid = 10009 (app_9) gid = 10009 (app_9)
I hope you enjoyed the small session. If you have any comments or questions or suggestions, please join the forum discussion below!