来自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);
}
答案 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;
这些框架值对应uid
,root
和system
用户的内核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用户身份运行的进程和应用,uid
和userId
将为0,在这种情况下,uid
将返回appId
。每当uid来自以isSystemUid()
或true
用户身份运行的呼叫者时,它也会返回true。
答案 1 :(得分:1)
我想,代码意味着只对系统uid,phone uid和root uid(等于0)返回true