3

As this relevant Stack Overflow question revision demonstrates, calling $USER inside a terminal (like Termux) provides a username like u0_a272. However, every application developer I've spoken to about this who was able to discuss this informed me that that value differs for each application, and the AOSP documentation appears to corroborate this.

Consequently, should I consider the u0 section as the user identifier, and the _.* section as the identifier for the application, or is an entirely different method utilized to refer to a user?

1 Answers1

6

It is well known that Android uses the Linux user system as simple sandbox system to separate the apps form each other.

The Android user id like u0_a272 (UID 10272) can be interpreted this way:

  • u0 means it belongs to the first user-account on the device (this time to the Linux user account but human user).
  • a is may be the identifier that the user account belongs to an app (not 100% sure)
  • 272 is the Linux UID modulo UserHandle.PER_USER_RANGE.

The UID is computed as:

UID = UserHandle.PER_USER_RANGE × user + app + Process.FIRST_APPLICATION_UID

Constants in Process specify range of UIDs allowed for use by the applications. On Android M, the range is from 10000 to 19999.

The user accounts are created dynamically on app installation and then saved to a XML file where this and many more details if all installed apps are recorded. This way Android can lookup which app belongs to which uid and the other way round.

For more details on this topic see the related questions and their answers:

Robert
  • 22,621
  • 6
  • 54
  • 76