gpt4 book ai didi

android - Android系统uid为0是什么意思

转载 作者:行者123 更新时间:2023-11-29 15:57:39 46 4
gpt4 key购买 nike

在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);
}

最佳答案

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;

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

NotificationManagerService 使用 isUidSystem() 检查调用进程是否属于这些用户之一,如果是,则设置 bool 值 isSystemNotification包名称以 android.* 开头)。

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

因此对于以 root 用户身份运行的进程和应用程序,uidappId 将为 0,并且 isSystemUid() 将返回true 在这种情况下。只要 uid 来自作为 systemradio 用户运行的调用者,它也会返回 true。

关于android - Android系统uid为0是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27103915/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com