使用以 frameworks/base/data/etc/preinstalled-packages-platform.xml 为模型的系统配置 XML 文件,根据新用户的用户类型声明应为新用户初始安装哪些系统软件包。理想情况下,设备上的所有系统软件包都应具有 XML 文件中的一个条目(由其清单名称进行键控),但静态叠加层除外,系统会根据动态叠加层所对应叠加层目标软件包的条目自动对其进行处理。
设备处理此处未列出的系统软件包应采取的方式由配置模式控制。
[null,null,["最后更新时间 (UTC):2025-08-08。"],[],[],null,["# Preinstalled system packages\n\nAndroid supports having multiple users on a single device. To learn more,\nsee [Supporting Multiple Users](/docs/devices/admin/multi-user).\nSince not all system packages are useful on all types of Android users, you\ncan use an allowlist to specify which system packages should be pre-installed\non each type of user. By not pre-installing unnecessary system packages, you\ncan optimize user creation times, start times, and memory usage.\n| To learn more about using this feature on *Automotive* devices, see the Android 11 section in [Removing Packages for the System User](/docs/devices/automotive/users_accounts/disable_packages#android-11).\n\nUse system configuration XML files, modeled on\n`frameworks/base/data/etc/preinstalled-packages-platform.xml`,\nto declare which system packages should be initially installed for new users\nbased on their user type. All system packages on the device should ideally have\nan entry in an XML file (keyed by its manifest name), except for static overlays,\nwhich are instead treated automatically according to the entry for their corresponding\noverlay target package.\nThe way in which the device\nshould handle system packages that are not listed here is controlled by the\n[config mode](/docs/core/permissions/preinstalled-packages#behavior).\n\nUser types\n----------\n\nBase user-types (every user is at least one of these types) are:\n\n| User type | Description |\n|-----------|----------------------------|\n| `SYSTEM` | User 0. |\n| `FULL` | Any nonprofile human user. |\n| `PROFILE` | A profile human user. |\n\nThe precise meaning of each is defined in\n`frameworks/base/core/java/android/content/pm/UserInfo.java`.\n\nMore granular control can be gained by specifying individual user types since\nevery user is exactly one of these user types, which includes the AOSP user types\ndefined in `frameworks/base/core/java/android/os/UserManager.java`\nand any OEM custom user types defined in\n`frameworks/base/services/core/java/com/android/server/pm/UserTypeFactory.java.`\nSee the [user types](/docs/devices/admin/multi-user#user_types) page for more\ninformation.\nCurrently, AOSP user types include:\n\n- `android.os.usertype.full.SYSTEM`\n- `android.os.usertype.full.SECONDARY`\n- `android.os.usertype.full.GUEST`\n- `android.os.usertype.full.DEMO`\n- `android.os.usertype.full.RESTRICTED`\n- `android.os.usertype.profile.MANAGED`\n- `android.os.usertype.profile.PRIVATE`\n- `android.os.usertype.system.HEADLESS`\n\nExamples\n--------\n\nThe following examples address the most common use cases:\n\n1. For a system package to be pre-installed in user 0 *only* : \n\n ```carbon\n \u003cinstall-in-user-type package=\"com.android.example\"\u003e\n \u003cinstall-in user-type=\"SYSTEM\" /\u003e\n \u003c/install-in-user-type\u003e\n ```\n2. For a system package to be pre-installed on all human users (such as a web browser), that is, to be installed on any user of type `FULL` or `PROFILE`, which addresses all human users: \n\n ```carbon\n \u003cinstall-in-user-type package=\"com.android.example\"\u003e\n \u003cinstall-in user-type=\"FULL\" /\u003e\n \u003cinstall-in user-type=\"PROFILE\" /\u003e\n \u003c/install-in-user-type\u003e\n ```\n3. For a system package to be pre-installed on all human users except for profile users. For example, this could be applied to a wallpaper app: \n\n ```carbon\n \u003cinstall-in-user-type package=\"com.android.example\"\u003e\n \u003cinstall-in user-type=\"FULL\" /\u003e\n \u003c/install-in-user-type\u003e\n ```\n4. Some system packages truly are required to be on all users, regardless of type. In these cases, use: \n\n ```carbon\n \u003cinstall-in-user-type package=\"com.android.example\"\u003e\n \u003cinstall-in user-type=\"SYSTEM\"\u003e\n \u003cinstall-in user-type=\"FULL\" /\u003e\n \u003cinstall-in user-type=\"PROFILE\" /\u003e\n \u003c/install-in-user-type\u003e\n ```\n5. More granular options are also available by specifying individual user types. For example, the following sample code installs this package on any user whose user type is a managed profile or a guest or is of a `SYSTEM` base type. \n\n ```carbon\n \u003cinstall-in-user-type package=\"com.android.example\"\u003e\n \u003cinstall-in user-type=\"android.os.usertype.profile.MANAGED\" /\u003e\n \u003cinstall-in user-type=\"android.os.usertype.full.GUEST\" /\u003e\n \u003cinstall-in user-type=\"SYSTEM\"\u003e\n \u003c/install-in-user-type\u003e\n ```\n\ndo-not-install-in tag\n---------------------\n\nPackages can also be prevented from being pre-installed on particular user types\nusing the `do-not-install-in` tag. Note that `do-not-install-in`\ntags override `install-in` tags in any file. For example: \n\n```carbon\n\u003cinstall-in-user-type package=\"com.android.example\"\u003e\n \u003cinstall-in user-type=\"FULL\" /\u003e\n \u003cdo-not-install-in user-type=\"android.os.usertype.full.GUEST\"/\u003e\n\u003c/install-in-user-type\u003e\n```\nIf a user is of type `android.os.usertype.full.GUEST` (a subtype of FULL), this package is **not** installed because the `do-not-install-in` tag takes precedence over `install-in`.\n\nControl behavior with config.xml\n--------------------------------\n\nThe config resource value `config_userTypePackageWhitelistMode`\ncontrols this feature and determines how a device interprets system packages\nthat have no entry for any user type. For more information, see\n`frameworks/base/core/res/res/values/config.xml#config_userTypePackageWhitelistMode`.\n\n\n| **Caution:** While changes made to the allowlist during system updates cannot uninstall pre-existing system packages from pre-existing users, they can result in the installation of additional system packages to pre-existing users.\n\nIn `frameworks/base/core/res/res/values/config.xml`, set the integer\nnamed `config_userTypePackageWhitelistMode` to a combination of\nthe following values. These flags can be combined. The most important flags are:\n\n| Value | Description |\n|--------------|------------------------------------------------------------------------------------------------------------|\n| `0 (0b0000)` | **Disable.** Install all system packages. |\n| `1 (0b0001)` | **Enforce.** Only install system packages when allowlisted. |\n| `4 (0b0100)` | Regard any package not mentioned in the allowlist file as implicitly allowlisted. |\n| `8 (0b1000)` | Regard any package not mentioned in the allowlist file as implicitly allowlisted for just the SYSTEM user. |\n\nThe following config enables the feature (so that `install-in` and\n`do-not-install-in` tags are obeyed) but treats any nonmentioned\nsystem packages as though they are `install-in` for all users: \n\n```scdoc\n\u003cinteger name=\"config_userTypePackageWhitelistMode\"\u003e5\u003c/integer\u003e\n```"]]