行为变更:以 Android 17 或更高版本为目标平台的应用

与之前的版本一样,Android 17 包含一些可能会影响应用的行为变更。以下行为变更仅影响以 Android 17 或更高版本为目标平台的应用。如果您的应用以 Android 17 或更高版本为目标平台,则应根据情况修改应用,以支持这些行为。

无论应用的 targetSdkVersion 为何,都请务必查看对 Android 17 上运行的所有应用都有影响的行为变更列表。

核心功能

Android 17 包含以下变更,这些变更会修改或扩展 Android 系统的各种核心功能。

MessageQueue 的新无锁实现

从 Android 17 开始,以 Android 17 或更高版本为目标平台的应用会收到 android.os.MessageQueue 的新无锁实现。新实现可提升性能并减少丢帧,但可能会破坏依赖于 MessageQueue 私有字段和方法的客户端。

如需了解详情(包括缓解策略),请参阅 MessageQueue 行为变更指南

无障碍

Android 17 进行了以下变更,以改进无障碍功能。

复杂 IME 实体键盘输入的无障碍支持

This feature introduces new AccessibilityEvent and TextAttribute APIs to enhance screen reader spoken feedback for CJKV language input. CJKV IME apps can now signal whether a text conversion candidate has been selected during text composition. Apps with edit fields can specify text change types when sending text changed accessibility events. For example, apps can specify that a text change occurred during text composition, or that a text change resulted from a commit. Doing this enables accessibility services such as screen readers to deliver more precise feedback based on the nature of the text modification.

App adoption

  • IME Apps: When setting composing text in edit fields, IMEs can use TextAttribute.Builder.setTextSuggestionSelected() to indicate whether a specific conversion candidate was selected.

  • Apps with Edit Fields: Apps that maintain a custom InputConnection can retrieve candidate selection data by calling TextAttribute.isTextSuggestionSelected(). These apps should then call AccessibilityEvent.setTextChangeTypes() when dispatching TYPE_VIEW_TEXT_CHANGED events. Apps targeting Android 17 that use the standard TextView will have this feature enabled by default. (That is, TextView will handle retrieving data from the IME and setting text change types when sending events to accessibility services).

  • Accessibility Services: Accessibility services that process TYPE_VIEW_TEXT_CHANGED events can call AccessibilityEvent.getTextChangeTypes() to identify the nature of the modification and adjust their feedback strategies accordingly.

安全

Android 17 对设备和应用安全性进行了以下改进。

活动安全性

在 Android 17 中,平台继续向“默认安全”架构转变,引入了一系列旨在缓解严重程度较高的漏洞利用(例如网络钓鱼、交互劫持和混淆代理攻击)的增强功能。此更新要求开发者明确选择启用新的安全标准,以保持应用兼容性和用户保护。

对开发者的主要影响包括:

  • BAL 强化和改进的选择启用机制:我们正在通过将保护范围扩展到 IntentSender 来完善后台 activity 启动 (BAL) 限制。 开发者必须弃用旧版 MODE_BACKGROUND_ACTIVITY_START_ALLOWED 常量。相反,您应采用精细的控制措施,例如 MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE,该措施会将 activity 启动限制在调用应用可见的场景中,从而显著减小攻击面。
  • 采用工具:开发者应利用严格模式和更新后的 lint 检查来识别旧版模式,并确保做好准备,以满足未来的目标 SDK 要求。

本地主机保护

为了提高平台安全性和用户隐私保护水平,Android 17 引入了新的安装时权限 USE_LOOPBACK_INTERFACE。此变更限制了通过环回接口(例如 127.0.0.1::1)进行的跨应用和跨资料通信,之前使用 INTERNET 权限时,这种通信是隐式允许的。对于以 Android 17 或更高版本为目标平台的应用,以下规则适用:

  • 需要双方同意:默认情况下,系统现在会阻止跨应用和跨资料通信。为了成功建立连接,发送方应用和接收方应用都必须在其清单中明确声明 USE_LOOPBACK_INTERFACE 权限。
  • 应用内流量不受影响:同一应用内的环回通信(应用内通信)不受影响,无需此新权限。
  • 目标 SDK 行为
    • 应用以 Android 17 或更高版本为目标平台:必须明确请求该权限。如果缺少此权限,套接字操作(例如 TCP 连接或 UDP 发送)会失败,通常会返回 EPERM(不允许的操作)错误。
    • 应用以 API 级别 36 或更低级别为目标平台:该权限在 INTERNET 上被视为拆分权限。如果应用持有 INTERNET,则以较低 API 级别为目标平台的应用会自动获得此权限。
  • 兼容性警告:如果接收应用将其目标更新为 Android 17,但未能请求此权限,则来自其他应用的传入连接将被拒绝,即使发送应用以较低的 API 级别为目标平台也是如此。

默认启用 CT

如果应用以 Android 17 或更高版本为目标平台,则默认启用证书透明度 (CT)。(在 Android 16 上,CT 可用,但应用必须选择启用。)

更安全的原生 DCL - C

If your app targets Android 17 or higher, the Safer Dynamic Code Loading (DCL) protection introduced in Android 14 for DEX and JAR files now extends to native libraries.

All native files loaded using System.load() must be marked as read-only. Otherwise, the system throws UnsatisfiedLinkError.

We recommend that apps avoid dynamically loading code whenever possible, as doing so greatly increases the risk that an app can be compromised by code injection or code tampering.

设备规格

Android 17 包含以下变更,可改善各种尺寸和外形规格的设备上的用户体验。

平台 API 变更,用于忽略大屏设备 (sw>=600dp) 上的屏幕方向、尺寸调整能力和宽高比限制

我们在 Android 16 中引入了平台 API 变更,以忽略以 API 级别 36 或更高级别为目标的应用在大屏 (sw >= 600dp) 设备上的屏幕方向、宽高比和尺寸调整能力限制。开发者可以选择使用 SDK 36 停用这些变更,但对于以 Android 17 或更高版本为目标平台的应用,此停用选项将不再可用。

如需了解详情,请参阅忽略了有关屏幕方向和可调整大小性的限制