What are the relationships and functions of all these identifiers (uid, pid, userid, appid, sharedUserid)?

I know that pid (int) is assigned to the process by the os system when it is created, which is the unqiue identifier of the process. Uid (int) is the unique identifier of the user (or application in android).

  • Q1: When was the uid created and assigned to the application?
  • Q2: Does it relate to an attribute or others in AndroidManifest.xml? I know that shareUerId is usually a userId system, for example. Generally, sharedUserId is a string.
  • Q3: Where is the map between the uid (int) system and shareUserId (string)? There is a UserId.java file in frameworks \ base \ core \ java \ android \ os. As you can see, the getUid method (int userId, int appId) can get uid from userId and appId.
  • Q4: What are userId and appId here?

    public static final int getCallingUserId () {return getUserId (Binder.getCallingUid ()); } From the above code, we can conclude that with IPC Binder uses uid not UserId.If so that the UserId function.

So many questions here! I think all this is important for understanding the IPC android. Can anyone answer my questions? It is best to list all the answers one by one. Thank you very much in advance!

public end class UserId {

/** * Range of IDs allocated for a user. * * @hide */ public static final int PER_USER_RANGE = 100000; public static final int USER_ALL = -1; /** * Enable multi-user related side effects. Set this to false if there are problems with single * user usecases. * */ public static final boolean MU_ENABLED = true; /** * Checks to see if the user id is the same for the two uids, ie, they belong to the same * user. * @hide */ public static final boolean isSameUser(int uid1, int uid2) { return getUserId(uid1) == getUserId(uid2); } /** * Checks to see if both uids are referring to the same app id, ignoring the user id part of the * uids. * @param uid1 uid to compare * @param uid2 other uid to compare * @return whether the appId is the same for both uids * @hide */ public static final boolean isSameApp(int uid1, int uid2) { return getAppId(uid1) == getAppId(uid2); } public static final boolean isIsolated(int uid) { uid = getAppId(uid); return uid >= Process.FIRST_ISOLATED_UID && uid <= Process.LAST_ISOLATED_UID; } public static boolean isApp(int uid) { if (uid > 0) { uid = UserId.getAppId(uid); return uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID; } else { return false; } } /** * Returns the user id for a given uid. * @hide */ public static final int getUserId(int uid) { if (MU_ENABLED) { return uid / PER_USER_RANGE; } else { return 0; } } public static final int getCallingUserId() { return getUserId(Binder.getCallingUid()); } /** * Returns the uid that is composed from the userId and the appId. * @hide */ public static final int getUid(int userId, int appId) { if (MU_ENABLED) { return userId * PER_USER_RANGE + (appId % PER_USER_RANGE); } else { return appId; } } /** * Returns the app id (or base uid) for a given uid, stripping out the user id from it. * @hide */ public static final int getAppId(int uid) { return uid % PER_USER_RANGE; } /** * Returns the user id of the current process * @return user id of the current process */ public static final int myUserId() { return getUserId(Process.myUid()); } 
+4
source share

Source: https://habr.com/ru/post/1440526/


All Articles