【问题标题】:what does it mean when uid equals to zero for Android systemAndroid系统uid为零是什么意思
【发布时间】:2015-01-22 02:39:34
【问题描述】:

在 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 android-service uid android-binder


    【解决方案1】:

    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 用户的内核uids。在 Android 中,许多系统进程作为uids 这三个之一运行。

    NotificationManagerService 使用isUidSystem() 来检查调用进程是否由这些用户之一拥有,如果是,则设置布尔值isSystemNotification(如果包名称以android.* 开头,它也最终为真)。

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

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

    【讨论】:

      【解决方案2】:

      我刚想,代码的意思是只对系统uid、手机uid和root uid返回true(等于0)

      【讨论】:

        猜你喜欢
        • 2011-05-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-10
        • 2013-10-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多