对于Android系统,当uid等于零时,这意味着什么

时间:2014-11-24 11:37:31

标签: android android-service uid android-binder

来自Android 5.0框架源代码的NotificationManagerService.java。 我不明白uid什么时候会为零。

private static boolean isUidSystem(int uid) {
    final int appid = UserHandle.getAppId(uid);
    return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID || uid == 0);
}

2 个答案:

答案 0 :(得分:3)

Android的Process类包含以下定义(其中包括):

/**
 * Defines the root UID.
 */
public static final int ROOT_UID = 0;

/**
 * Defines the UID/GID under which system code runs.
 */
public static final int SYSTEM_UID = 1000;

/**
 * Defines the UID/GID under which the telephony code runs.
 */
public static final int PHONE_UID = 1001;

这些框架值对应uidrootsystem用户的内核radio。在Android中,许多系统进程作为这三个uid中的一个运行。

NotificationManagerService使用isUidSystem()检查调用进程是否归其中一个用户所有,如果是,则设置boolean isSystemNotification(如果包名以{{1开头},它也会返回true }})。

请注意,android.*并未直接将调用isSystemUid与上述值进行比较,而是首先通过uid运行它,它获取内核值并使用{{1}对其进行修改通常定义为100000(即UserHandle.getAppId())。这最终是内核UserHandle.PER_USER_RANGE的最后五位数,其中前两位与多用户设备上的uid % PER_USER_RANGE相对应。

因此,对于以root用户身份运行的进程和应用,uiduserId将为0,在这种情况下,uid将返回appId。每当uid来自以isSystemUid()true用户身份运行的呼叫者时,它也会返回true。

答案 1 :(得分:1)

我想,代码意味着只对系统uid,phone uid和root uid(等于0)返回true