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

cui*_*uac 5 android android-permissions android-6.0-marshmallow

API 23 已将权限保护级别重命名systemprivileged. 它还引入了preinstalled保护级别。

是否privileged暗示preinstalled?换句话说,如果一个应用程序有权访问privileged权限(它是一个系统应用程序),它是否也有权访问preinstalled权限,即使这些权限没有列为privileged(仅preinstalled)?

cui*_*uac 2

答案似乎是肯定的,只要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;
}
Run Code Online (Sandbox Code Playgroud)

在内部,系统应用程序实际上是一个预装的应用程序(重构仅限于公共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;
}
Run Code Online (Sandbox Code Playgroud)