行为变更:所有应用

Android 15 平台包含一些行为变更,这些变更可能会影响您的应用。以下行为变更将影响在 Android 15 上运行的所有应用,无论采用哪种 targetSdkVersion 都不例外。您应该测试您的应用,然后根据需要进行修改,以适当地支持这些变更(如果适用)。

此外,请务必查看仅影响以 Android 15 为目标平台的应用的行为变更列表。

核心功能

Android 15 修改或扩展了 Android 系统的各种核心功能。

对软件包停止状态的更改

The intention of the package FLAG_STOPPED state (which users can engage in AOSP builds by long-pressing an app icon and selecting "Force Stop") has always been to keep apps in this state until the user explicitly removes the app from this state by directly launching the app or indirectly interacting with the app (through the sharesheet or a widget, selecting the app as live wallpaper, etc.). In Android 15, we are updating the behavior of the system to be aligned with this intended behavior. Apps should only be removed from the stopped state through direct or indirect user action.

To support the intended behavior, in addition to the existing restrictions, the system also cancels all pending intents when the app enters the stopped state on a device running Android 15. When the user's actions remove the app from the stopped state, the ACTION_BOOT_COMPLETED broadcast is delivered to the app providing an opportunity to re-register any pending intents.

You can call the new ApplicationStartInfo.wasForceStopped() method to confirm whether the app was put into the stopped state.

支持 16 KB 页面大小

一直以来,Android 仅支持 4 KB 的内存页面大小,针对 Android 设备通常拥有的平均总内存量,系统内存性能进行了优化。从 Android 15 开始,Android 支持配置为使用 16 KB 页面大小的设备(即 16 KB 设备)。

随着设备制造商不断打造具有更大物理内存 (RAM) 的设备,这些设备中的许多可能会配置 16 KB(最终更大)的页面大小,以优化设备的性能。添加对 16 KB 设备的支持可让您的应用在这些设备上运行,并帮助您的应用从相关性能改进中受益。为了帮助您解决此问题,我们提供了一些指南,帮助您了解如何检查您的应用是否受到影响、如何重新构建应用(如果适用),以及如何同时使用模拟器和实体设备在 16 KB 的环境中测试应用

优势和性能提升

配置为 16 KB 页面的设备平均使用的内存会略多,但系统和应用性能也会有所提升:

  • 在系统面临内存压力时缩短应用启动时间:平均降低了 3.16%,对于我们测试过的一些应用而言,改进幅度更显著(提升幅度高达 30%)
  • 降低应用启动时的功耗:平均降低 4.56%
  • 相机启动速度更快:平均热启动速度加快 4.48%,冷启动速度平均加快 6.60%
  • 缩短了系统启动时间:平均缩短了 1.5%(约 0.8 秒)

这些改进基于我们的初始测试,实际设备上的结果可能会有所不同。在继续测试的过程中,我们会进一步分析应用的潜在益处。

检查您的应用是否受到影响

如果您的应用使用任何原生代码,则您应重新构建支持 16 KB 设备的应用。如果您不确定自己的应用是否使用了原生代码,可以使用 APK 分析器来确定是否存在任何原生代码

如果您的应用仅使用以 Java 编程语言或 Kotlin 编写的代码(包括所有库或 SDK),那么该应用已经支持 16 KB 设备。不过,我们建议您在 16 KB 的环境中测试应用,以确认应用行为是否存在意外回归问题。

让部分应用支持私密空间所需的更改

私密空间是 Android 15 中的一项新功能,可让用户在设备上创建一个单独的空间,通过一个额外的身份验证层来防止敏感应用被窥探。由于私密空间中的应用的可见性存在限制,因此某些类型的应用需要执行额外的步骤才能查看用户的私密空间中的应用并与之互动。

所有应用

由于私密空间中的应用保存在单独的用户个人资料中(类似于工作资料),因此应用不应假定主资料中未包含的任何已安装应用副本都位于工作资料中。如果您的应用具有与工作资料应用相关的逻辑,这些应用会做出这种假设,那么您需要调整此逻辑。

启动器应用

如果您要开发启动器应用,必须执行以下操作,私密空间中的应用才会显示出来:

  1. 您必须将应用指定为设备的默认启动器应用,即具有 ROLE_HOME 角色。
  2. 应用必须在应用的清单文件中声明 ACCESS_HIDDEN_PROFILES 一般权限。

声明 ACCESS_HIDDEN_PROFILES 权限的启动器应用必须处理以下私密空间用例:

  1. 您的应用必须为安装在私密空间中的应用提供单独的启动器容器。
  2. 用户必须能够隐藏和显示私密空间容器。
  3. 用户必须能够锁定和解锁私密空间容器。
  4. 处于锁定状态时,私密空间容器中的任何应用都不应通过搜索等机制可见或发现。

应用商店应用

私密空间包含一个“安装应用”按钮,该按钮可启动隐式 intent,以将应用安装到用户的私密空间中。为了让应用接收此隐式 intent,请在应用的清单文件中声明 <intent-filter>,并将 <category> 设为 CATEGORY_APP_MARKET

将最低目标 SDK 版本从 23 提高到了 24

Android 15 基于 Android 14 中发生的变更构建,并进一步扩展了这种安全性。在 Android 15 中,targetSdkVersion 低于 24 的应用将无法安装。要求应用满足现代 API 级别有助于确保更好的安全性和隐私保护。

恶意软件通常会以较低的 API 级别为目标平台,以绕过在更高 Android 版本中引入的安全和隐私保护机制。例如,有些恶意软件应用使用 targetSdkVersion 22,以避免受到 Android 6.0 Marshmallow(API 级别 23)在 2015 年引入的运行时权限模型的约束。这项 Android 15 变更使恶意软件更难以规避安全和隐私保护方面的改进。尝试安装以较低 API 级别为目标平台的应用会导致安装失败,并且 Logcat 中会显示如下消息:

INSTALL_FAILED_DEPRECATED_SDK_VERSION: App package must target at least SDK version 24, but found 7

在升级到 Android 15 的设备上,targetSdkVersion 低于 24 的所有应用都将保持安装状态。

如果您需要测试以旧版 API 级别为目标平台的应用,请使用以下 ADB 命令:

adb install --bypass-low-target-sdk-block FILENAME.apk

摄像头和媒体

Android 15 对所有应用的相机和媒体行为做出了以下变更。

现在,当达到资源限制时,直接和分流音频播放会使之前打开的直接或分流音轨失效

Before Android 15, if an app requested direct or offload audio playback while another app was playing audio and the resource limits were reached, the app would fail to open a new AudioTrack.

Beginning with Android 15, when an app requests direct or offload playback and the resource limits are reached, the system invalidates any currently open AudioTrack objects which prevent fulfilling the new track request.

(Direct and offload audio tracks are typically opened for playback of compressed audio formats. Common use-cases for playing direct audio include streaming encoded audio over HDMI to a TV. Offload tracks are typically used to play compressed audio on a mobile device with hardware DSP acceleration.)

用户体验和系统界面

Android 15 包含一些旨在打造更一致、更直观的用户体验的变更。

已为已选择启用预测性返回动画功能启用

Beginning in Android 15, the developer option for predictive back animations has been removed. System animations such as back-to-home, cross-task, and cross-activity now appear for apps that have opted in to the predictive back gesture either entirely or at an activity level. If your app is affected, take the following actions:

  • Ensure that your app has been properly migrated to use the predictive back gesture.
  • Ensure that your fragment transitions work with predictive back navigation.
  • Migrate away from animation and framework transitions and use animator and androidx transitions instead.
  • Migrate away from back stacks that FragmentManager doesn't know about. Use back stacks managed by FragmentManager or by the Navigation component instead.

用户强行停止应用时停用的微件

如果用户在搭载 Android 15 的设备上强行停止某个应用,系统会暂时停用该应用的所有 widget。这些 widget 会灰显,用户无法与它们互动。这是因为,从 Android 15 开始,当应用被强行停止时,系统会取消应用的所有待处理 intent。

系统会在用户下次启动应用时重新启用这些 widget。

如需了解详情,请参阅对软件包停止状态的更改

废弃

随着每个版本的发布,特定的 Android API 可能会过时或需要重构,以提供更好的开发者体验或支持新的平台功能。在这些情况下,我们正式废弃了过时的 API,并引导开发者改用替代 API。

废弃意味着我们已结束对这些 API 的正式支持,但开发者仍可继续使用它们。如需详细了解此 Android 版本中值得注意的废弃项,请参阅废弃项页面