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 {
public static final int PER_USER_RANGE = 100000; public static final int USER_ALL = -1; public static final boolean MU_ENABLED = true; public static final boolean isSameUser(int uid1, int uid2) { return getUserId(uid1) == getUserId(uid2); } 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; } } 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()); } public static final int getUid(int userId, int appId) { if (MU_ENABLED) { return userId * PER_USER_RANGE + (appId % PER_USER_RANGE); } else { return appId; } } public static final int getAppId(int uid) { return uid % PER_USER_RANGE; } public static final int myUserId() { return getUserId(Process.myUid()); }
Allen source share