自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
配置和处理应用的更新所有权
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如果应用商店或安装程序安装某款应用,相应商店或安装程序会被视为“记录安装程序”,即这款应用的最后一个安装程序。在 Android 14 之前,Android 允许另一商店或应用安装程序成为记录安装程序并在不通知用户的情况下更新相关应用。
在 Android 14 中,应用的初始安装程序可以声明自己为“更新所有者”并拥有对相关应用的更新。如果另一安装程序尝试更新这款应用,用户有机会在更新之前先批准新更新。
允许软件包更新所有权
若要声明某个应用软件包归某应用商店或安装程序所有,请在每个相应软件包的 sysconfig
XML 中添加 update-ownership
标记,如下所示:
<update-ownership package="com.example.application" installer="com.example.installer" />
在此示例中,com.example.application
是要被拥有的应用软件包,com.example.installer
是软件包的所有者。当软件包被允许更新所有权时,其他具有特权的应用商店或安装程序必须处理更新所有者并征得用户同意才能更新此应用。
禁止软件包更改所有权
您可通过在 APK 中提供拒绝名单,让您的应用商店或安装程序禁止一部分软件包进行更新所有者变更。一旦您在此列表中添加软件包,任何应用商店或安装程序都无法请求更新相应软件包的所有权。
如需禁止另一应用商店或安装程序更新软件包,请执行以下操作:
在原始应用商店或安装程序的 AndroidManifest.xml
文件中包含以下属性:
<application …>
<property android:name="android.app.PROPERTY_LEGACY_UPDATE_OWNERSHIP_DENYLIST"
android:resource="@xml/legacyOwnershipDenylist" />
</application>
此示例引用了一个名为 legacyOwnershipDenylist
的 XML 拒绝名单。
使用以下格式创建一份拒绝名单作为原始 XML 资源:
<deny-ownership>com.example.app1</deny-ownership>
<deny-ownership>com.example.app2</deny-ownership>
如果应用商店或安装程序请求获得对拒绝名单中的软件包的所有权,系统将不会授予所有权,并且该软件包仍会安装,但不归任何安装程序所有。此外,无论使用哪种安装程序,拒绝名单中的应用都不归任何人所有。
若要更改此列表中的一系列软件包,请更新提供该列表的安装程序 APK。当更新安装程序时,系统会清除为随后加入拒绝名单的软件包设置的任何所有权。因此,对拒绝名单中的应用软件包的后续更新不需要用户互动。
处理更新所有者并征得用户同意
在 Android 14 中,即使商店或应用安装程序具有 android.permission.INSTALL_PACKAGES
权限,如果它想更新以另一商店或安装程序为更新所有者的应用,仍需处理 STATUS_PENDING_USER_ACTION
状态。
InstallAPKSessionApi.java
示例应用还展示了如何处理 STATUS_PENDING_USER_ACTION
。
为预加载应用建立所有权
预加载应用通常不归特定安装程序所有,而是会由系统按照允许软件包更新所有权部分中所示的系统配置分配新的所有者。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-04。
[null,null,["最后更新时间 (UTC):2025-04-04。"],[],[],null,["# Configure and handle update ownership for apps\n\nWhen an app is installed by a store or installer, the store or installer is\nconsidered the \"installer of record\" meaning the last installer of the app.\nPrior to Android 14, Android allowed another store or app installer to become\nthe installer of record and to update the app without notifying the user.\n\nIn Android 14, the initial installer of an app can declare itself \"update owner\"\nand own updates to the app. If another installer attempts to update the app, the\nuser is given the opportunity to approve the new update before it proceeds.\n\nOpt packages in to update ownership\n-----------------------------------\n\nTo declare that a store or installer owns an app package,\ninclude the `update-ownership` tag in your `sysconfig` XML for each package as\nfollows: \n\n \u003cupdate-ownership package=\"com.example.application\" installer=\"com.example.installer\" /\u003e\n\nIn this example, `com.example.application` is the app package to be owned and\n`com.example.installer` is the owner of the package. When a package is opted\nin to update ownership, other privileged stores or installers have to\n[handle update owner and obtain user consent](#handle) to update the app.\n\nOpt packages out of ownership changes\n-------------------------------------\n\nYou can have your store or installer opt a subset of packages out of\nupdate owner changes by providing a denylist in the APK. By including a package\nin this list, no store or installer can request update ownership of the package.\n\nTo opt packages out of being updatable by another store or installer:\n\n1. Include the following property in the original store or installer's\n `AndroidManifest.xml` file:\n\n \u003capplication ...\u003e\n \u003cproperty android:name=\"android.app.PROPERTY_LEGACY_UPDATE_OWNERSHIP_DENYLIST\"\n android:resource=\"@xml/legacyOwnershipDenylist\" /\u003e\n \u003c/application\u003e\n\n This example references an XML denylist called `legacyOwnershipDenylist`.\n2. Create a denylist as raw XML resource with the following format:\n\n \u003cdeny-ownership\u003ecom.example.app1\u003c/deny-ownership\u003e\n \u003cdeny-ownership\u003ecom.example.app2\u003c/deny-ownership\u003e\n\nIf a store or installer requests ownership of a package on a denylist,\nownership won't be granted and the package is still installed but won't be\nowned by any installer. Further, regardless of the installer, an app on a\ndenylist can't be owned by anyone.\n\nThe set of packages in this list can change through an update to the installer\nAPK that provides the list. Any ownership that is set for a package that is\nsubsequently introduced to a deny list is cleared when the installer is\nupdated. As such, subsequent updates of the app package on the deny list won't\nrequire user interaction.\n\nHandle update owner and obtain user consent\n-------------------------------------------\n\nWith Android 14, even if a store or app installer has the\n`android.permission.INSTALL_PACKAGES` permission, it still needs to handle the\n[`STATUS_PENDING_USER_ACTION`](https://developer.android.com/reference/android/content/pm/PackageInstaller#STATUS_PENDING_USER_ACTION)\nstate if it wants to update an app whose updates are owned by another store or installer.\n\nThe\n[`InstallAPKSessionApi.java`](https://android.googlesource.com/platform/development/+/android16-release/samples/ApiDemos/src/com/example/android/apis/content/InstallApkSessionApi.java) sample app also shows how to handle `STATUS_PENDING_USER_ACTION`.\n\nEstablish ownership for preloaded apps\n--------------------------------------\n\nPreloaded apps aren't typically owned by a specific installer.\nInstead preloaded apps are assigned a new owner using system configuration as\nshown in [Opt packages in to update ownership](#optin)."]]