Android 17 面向开发者引入了一些出色的新功能和 API。以下部分总结了这些功能,可帮助您开始使用相关 API。
有关新增、修改和移除的 API 的详细列表,请参阅 API 差异报告。如需详细了解新的 API,请访问 Android API 参考文档,新 API 会突出显示以方便查看。
您还应查看平台变更可能会在哪些方面影响您的应用。如需了解详情,请参阅以下页面:
核心功能
Android 17 添加了以下与 Android 核心功能相关的新功能。
新的 ProfilingManager 触发器
Android 17 向 ProfilingManager 添加了多个新的系统触发器,可帮助您收集深入的数据来调试性能问题。
新触发条件包括:
TRIGGER_TYPE_COLD_START:在应用冷启动期间发生触发。它在响应中同时提供调用堆栈示例和系统跟踪。TRIGGER_TYPE_OOM:当应用抛出OutOfMemoryError时触发,并提供 Java 堆转储作为响应。TRIGGER_TYPE_KILL_EXCESSIVE_CPU_USAGE:当应用因 CPU 使用率异常和过高而被终止时,会发生触发,并提供正在运行的后台系统跟踪的快照作为响应。TRIGGER_TYPE_ANOMALY:检测系统性能异常,例如 binder 调用过多和内存用量过多。
如需了解如何设置系统触发器,请参阅有关基于触发器的性能分析以及如何检索和上传配置文件和分析性能分析数据的文档。
应用异常性能分析触发器
Android 17 引入了设备端异常值检测服务,用于监控资源密集型行为和潜在的兼容性回归。此服务与 ProfilingManager 集成,可让您的应用接收由系统检测到的特定事件触发的性能分析工件。
使用 TRIGGER_TYPE_ANOMALY 触发器检测系统性能问题,例如 Binder 调用过多和内存用量过多。当应用超出操作系统定义的内存限制时,异常触发器可让开发者接收应用专属堆转储,以帮助识别和修复内存问题。此外,对于过多的 binder 垃圾内容,异常触发器会提供 binder 事务的堆栈采样分析。
此 API 回调会在系统强制执行任何操作之前发生。例如,它可以帮助开发者在应用因超出内存限制而被系统终止之前收集调试数据。
fun registerAnomalyTrigger(context: Context) {
val profilingManager =
context.getSystemService(ProfilingManager::class.java) ?: return
val triggers = listOf(
ProfilingTrigger.Builder(ProfilingTrigger.TRIGGER_TYPE_ANOMALY).build()
)
val callbackExecutor: Executor = Executors.newSingleThreadExecutor()
val resultCallback = Consumer<ProfilingResult> { profilingResult ->
if (profilingResult.errorCode == ProfilingResult.ERROR_NONE) {
// Upload profile result to server for further analysis
profilingResult.resultFilePath?.let { setupProfileUploadWorker(it) }
}
}
profilingManager.registerForAllProfilingResults(
callbackExecutor,
resultCallback
)
profilingManager.addProfilingTriggers(triggers)
}
JobDebugInfo API
Android 17 引入了新的 JobDebugInfo API,可帮助开发者调试其 JobScheduler 作业,例如作业未运行的原因、作业运行了多长时间以及其他聚合信息。
扩展后的 JobDebugInfo API 的第一个方法是 getPendingJobReasonStats(),它会返回一个映射,其中包含作业处于待执行状态的原因及其各自的累计待处理时长。此方法结合了 getPendingJobReasonsHistory() 和 getPendingJobReasons() 方法,可让您深入了解预定作业未按预期运行的原因,但通过在单个方法中提供时长和作业原因,简化了信息检索。
例如,对于指定的 jobId,该方法可能会返回 PENDING_JOB_REASON_CONSTRAINT_CHARGING 和 60000 毫秒的时长,表示由于充电限制未得到满足,作业处于待处理状态的时长为 60000 毫秒。
通过监听器支持“空闲时允许”闹钟,减少唤醒锁定
Android 17 引入了 AlarmManager.setExactAndAllowWhileIdle 的新变体,该变体接受 OnAlarmListener 而不是 PendingIntent。这种基于回调的新机制非常适合目前依赖持续唤醒锁来执行周期性任务的应用,例如维护套接字连接的即时通讯应用。
隐私权
Android 17 包含以下新功能,可更好地保护用户隐私。
加密客户端 Hello (ECH) 平台支持
Android 17 introduces platform support for Encrypted Client Hello (ECH), a significant privacy enhancement for network communications. ECH is a TLS 1.3 extension that encrypts the Server Name Indication (SNI) during the initial TLS handshake. This encryption helps protect user privacy by making it more difficult for network intermediaries to identify the specific domain an app is connecting to.
The platform now includes the necessary APIs for networking libraries to
implement ECH. This includes new capabilities in DnsResolver to query for
HTTPS DNS records containing ECH configurations, and new methods in Conscrypt's
SSLEngines and SSLSockets to enable ECH by passing in these configurations when
connecting to a domain. Developers can configure ECH preferences, such as
enabling it opportunistically or mandating its use, through the new
<domainEncryption> element within the Network Security Configuration file,
applicable globally or on a per-domain basis.
Popular networking libraries such as HttpEngine, WebView, and OkHttp are expected to integrate these platform APIs in future updates, making it easier for apps to adopt ECH and enhance user privacy.
For more information, see the Encrypted Client Hello documentation.
Android 联系人选择工具
The Android Contact Picker is a standardized, browsable interface for users to
share contacts with your app. Available on devices running
Android 17 (API level 37) or higher, the picker offers a privacy-preserving
alternative to the broad READ_CONTACTS permission. Instead of requesting
access to the user's entire address book, your app specifies the data fields it
needs, such as phone numbers or email addresses, and the user selects specific
contacts to share. This grants your app read access to only the selected data,
ensuring granular control while providing a consistent user experience with
built-in search, profile switching, and multi-selection capabilities without
having to build or maintain the UI.
For more information, see the contact picker documentation.
安全
Android 17 添加了以下新功能,以提高设备和应用的安全性。
Android 高级保护模式 (AAPM)
Android 高级保护模式为 Android 用户提供了一套强大的新安全功能,标志着在保护用户(尤其是面临较高风险的用户)免遭复杂攻击方面迈出了重要一步。AAPM 是一项选择启用功能,只需进行一项配置设置即可激活。用户可以随时启用该功能,以应用一套主观的安全保护措施。
这些核心配置包括:禁止安装未知来源的应用(旁加载)、限制 USB 数据信号传输,以及强制执行 Google Play 保护机制扫描,从而显著减小设备的攻击面。
开发者可以使用 AdvancedProtectionManager API 与此功能集成,以检测模式的状态,从而使应用能够在用户选择启用此模式时自动采用强化型安全姿态或限制高风险功能。
PQC APK 签名
Android now supports a hybrid APK signature scheme to future-proof your app's signing identity against the potential threat of attacks that make use of quantum computing. This feature introduces a new APK Signature Scheme, which lets you pair a classical signing key (such as RSA or EC) with a new post-quantum cryptography (PQC) algorithm (ML-DSA).
This hybrid approach ensures your app remains secure against future quantum attacks while maintaining full backward compatibility with older Android versions and devices that rely on classical signature verification.
Impact on developers
- Apps using Play App Signing: If you use Play App Signing, you can wait for Google Play to give you the option to upgrade a hybrid signature using a PQC key generated by Google Play, ensuring your app is protected without requiring manual key management.
- Apps using self-managed keys: Developers who manage their own signing keys can utilize updated Android build tools (like apksigner) to rotate to a hybrid identity, combining a PQC key with a new classical key. (You must create a new classical key, you cannot reuse the older one.)
连接
Android 17 添加了以下功能,以改进设备和应用连接。
受限卫星网络
实现优化,使应用能够在低带宽卫星网络上有效运行。
用户体验和系统界面
Android 17 包含以下旨在提升用户体验的变更。
专用 Google 助理音量流
Android 17 introduces a dedicated Assistant volume stream for Assistant apps,
for playback with USAGE_ASSISTANT. This change decouples Assistant audio
from the standard media stream, providing users with isolated control over both
volumes. This enables scenarios such as muting media playback while maintaining
audibility for Assistant responses, and the other way around.
Assistant apps with access to the new MODE_ASSISTANT_CONVERSATION audio
mode can further improve the volume control consistency. Assistant apps can use
this mode to provide a hint to the system about an active Assistant session,
ensuring the Assistant stream can be controlled outside of the active
USAGE_ASSISTANT playback or with connected Bluetooth peripherals.
Handoff
Handoff 是 Android 17 中即将推出的一项新功能和 API,应用开发者可以集成该功能,为用户提供跨设备连续性。它允许用户在一台 Android 设备上启动应用 activity,并将其转移到另一台 Android 设备。Handoff 在用户设备的后台运行,并通过接收设备上的各种入口点(例如启动器和任务栏)显示用户附近其他设备上的可用活动。
如果接收设备上已安装并可使用相同的原生 Android 应用,应用可以指定 Handoff 启动该应用。在此应用到应用流程中,用户会通过深层链接进入指定 activity。或者,应用到网页 Handoff 可作为后备选项提供,也可直接通过网址 Handoff 实现。
接力支持是按 activity 实现的。如需启用 Handoff,请为 activity 调用 setHandoffEnabled() 方法。可能需要随切换一起传递其他数据,以便接收设备上重新创建的 activity 可以恢复适当的状态。实现 onHandoffActivityDataRequested() 回调,以返回一个 HandoffActivityData 对象,其中包含指定 Handoff 应如何在接收设备上处理和重新创建 activity 的详细信息。
实时动态 - 语义颜色 API
With Android 17, Live Update launches the Semantic Coloring APIs to support colors with universal meaning.
The following classes support semantic coloring:
NotificationNotification.MetricNotification.ProgressStyle.PointNotification.ProgressStyle.Segment
Coloring
- Green: Associated with safety. This color should be used for the case where it lets people know you are in the safe situation.
- Orange: For designating caution and marking physical hazards. This color should be used in the situation where users need to pay attention to set better protection setting.
- Red: Generally indicates danger, stop. It should be presented for the case where need people's attention urgently.
- Blue: Neutral color for content that is informational and should stand out from other content.
The following example shows how to apply semantic styles to text in a notification:
val ssb = SpannableStringBuilder()
.append("Colors: ")
.append("NONE", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_UNSPECIFIED), 0)
.append(", ")
.append("INFO", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_INFO), 0)
.append(", ")
.append("SAFE", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_SAFE), 0)
.append(", ")
.append("CAUTION", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_CAUTION), 0)
.append(", ")
.append("DANGER", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_DANGER), 0)
Notification.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_icon)
.setContentTitle("Hello World!")
.setContentText(ssb)
.setOngoing(true)
.setRequestPromotedOngoing(true)
适用于 Android 17 的 UWB Downlink-TDoA API
Downlink Time Difference of Arrival (DL-TDoA) ranging lets a device determine its position relative to multiple UWB anchors by measuring the relative arrival times of signals.
For more information and code samples, see UWB Downlink-TDoA API.