预装和特权保护级别之间的区别

Difference between preinstalled and privileged protection level

API23已重命名权限保护等级system into privileged. It has also introduced a preinstalled保护等级

privileged是否意味着preinstalled?换句话说,如果一个应用程序可以访问 privileged 权限( 它是一个 system 应用程序),它是否可以访问preinstalled 权限,即使这些权限未列为 privileged(仅 preinstalled)?

预装应用程序但没有提升的系统权限(例如计算器)是可能的。这就是为什么这两个标志之间存在区别以及为什么 system 保护级别已被弃用 privileged.

的原因

答案似乎是肯定的,只要 privileged 应用程序是系统映像的一部分( 预安装)。包管理器将授予 preinstalled 对其(内部)调用 系统应用程序 的权限,参见 grantSignaturePermission():

if (!allowed && (bp.protectionLevel
        & PermissionInfo.PROTECTION_FLAG_PREINSTALLED) != 0
        && isSystemApp(pkg)) {
    // Any pre-installed system app is allowed to get this permission.
    allowed = true;
}

在内部,系统应用实际上是预装应用(重构仅限于public API,不在源代码中),请参阅 ActivityInfo:

/**
 * Value for {@link #flags}: if set, this application is installed in the
 * device's system image.
 */
public static final int FLAG_SYSTEM = 1<<0;

// Many lines not shown

public boolean isSystemApp() {
    return (flags & ApplicationInfo.FLAG_SYSTEM) != 0;
}