和先前版本一樣,Android 17 也包含可能會影響應用程式的行為變更。以下行為變更僅適用於指定 Android 17 以上版本的應用程式。如果您的應用程式指定 Android 17 以上版本,建議您視情況修改應用程式,以支援這些行為。
此外,無論應用程式的 targetSdkVersion 為何,請務必查看對所有 Android 17 應用程式有影響的行為變更清單。
核心功能
Android 17 包含下列異動項目,這類變更會修改或擴充 Android 系統的各種核心功能。
MessageQueue 的新無鎖定實作
从 Android 17 开始,以 Android 17(API 级别 37)
或更高版本为目标平台的应用会收到
android.os.MessageQueue 的新无锁实现。新实现可提升性能并减少丢帧,但可能会破坏反映 MessageQueue 私有字段和方法的客户端。
如需了解详情(包括缓解措施),请参阅 MessageQueue 行为变更指南。
靜態最終欄位現在無法修改
在以 Android 17(API 级别 37)或更高版本为目标平台的 Android 17 或更高版本上运行的应用无法更改 static final 字段。如果应用尝试使用反射更改 static final 字段,则会导致 IllegalAccessException。尝试通过 JNI API(例如 SetStaticLongField())修改其中一个字段会导致应用崩溃。
無障礙設定
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
InputConnectioncan retrieve candidate selection data by callingTextAttribute.isTextSuggestionSelected(). These apps should then callAccessibilityEvent.setTextChangeTypes()when dispatchingTYPE_VIEW_TEXT_CHANGEDevents. Apps targeting Android 17 (API level 37) that use the standardTextViewwill have this feature enabled by default. (That is,TextViewwill 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_CHANGEDevents can callAccessibilityEvent.getTextChangeTypes()to identify the nature of the modification and adjust their feedback strategies accordingly.
隱私權
Android 17 包含下列異動項目,可提升使用者隱私權。
已啟用 ECH (Encrypted Client Hello)
Android 17 引入了对加密客户端问候 (ECH) 的平台支持。ECH 是一种 TLS 扩展,可通过加密 TLS 握手中的服务器名称指示 (SNI) 来增强用户隐私保护。这种加密有助于防止网络观察者轻松识别您的应用所连接的特定网域。
对于以 Android 17(API 级别 37)或更高版本为目标平台的应用,ECH 用于 TLS 连接。只有当应用使用的网络库(例如 HttpEngine、WebView 或 OkHttp)已集成 ECH 支持,并且远程服务器也支持 ECH 协议时,ECH 才会处于活跃状态。如果无法协商 ECH,客户端会发送一个包含随机内容的 ECH 扩展(一种称为 ECH GREASE 的机制)。如需详细了解 ECH GREASE 的工作原理,请参阅 RFC 9849。
为了让应用能够自定义此行为,Android 17 向网络安全配置文件添加了一个新的
<domainEncryption> 元素。
开发者可以在 <base-config> 或
<domain-config> 标记中使用 <domainEncryption>,以全局或按网域的方式选择 ECH 模式(例如
"enabled" 或 "disabled")。
如需了解详情,请参阅加密客户端问候文档。
以 Android 17 為目標的應用程式必須取得區域網路權限
Android 17 introduces the ACCESS_LOCAL_NETWORK runtime permission
to protect users from unauthorized local network access. Because this falls
under the existing NEARBY_DEVICES permission group, users who have already
granted other NEARBY_DEVICES permissions aren't prompted again. This new
requirement prevents malicious apps from exploiting unrestricted local network
access for covert user tracking and fingerprinting. By declaring and requesting
this permission, your app can discover and connect to devices on the local area
network (LAN), such as smart home devices or casting receivers.
Apps targeting Android 17 (API level 37) or higher now have two paths to maintain communication with LAN devices: Adopt system-mediated, privacy-preserving device pickers to skip the permission prompt, or explicitly request this new permission at runtime to maintain local network communication.
For more information, see the Local network permission documentation.
隱藏實體裝置上的密碼
如果应用以 Android 17(API 级别 37)或更高版本为目标平台,并且用户使用的是实体输入设备(例如外接键盘),Android
操作系统会对密码字段中的所有字符应用新的 show_passwords_physical 设置。默认情况下,该设置会隐藏所有密码字符。
Android 系统会显示用户最后输入的密码字符,以帮助用户查看是否输错了密码。不过,对于较大的外接键盘,此功能就没那么必要了。此外,配备外接键盘的设备通常具有较大的显示屏,这会增加他人看到输入密码的风险。
如果用户使用的是设备触摸屏,系统会应用新的 show_passwords_touch 设置。
保護標準簡訊中的 OTP
自 Android 17 起,Android 將擴大簡訊動態密碼保護機制,適用於標準簡訊 (含有動態密碼但未使用 WebOTP 或簡訊擷取器格式的簡訊)。如果應用程式指定 Android 17 (API 級別 37) 以上版本,通常要等到收到簡訊三小時後,才能存取這些訊息。這項延遲機制是為了防止 OTP 遭人盜用。在這三小時的延遲期間,SMS_RECEIVED_ACTION 廣播會暫緩發送,簡訊服務供應商資料庫查詢也會經過篩選。簡訊會在延遲後傳送至這些應用程式。
預設訊息助理應用程式、連結裝置的隨附應用程式等特定應用程式,則不受這項延遲限制。如果應用程式需要讀取簡訊來擷取動態密碼,請改用 SMS Retriever 或 SMS User Consent API,確保功能不受影響。
安全性
Android 17 在裝置和應用程式安全性方面有以下改進。
活動安全性
在 Android 17 中,平台继续向“默认安全”架构转变,引入了一系列旨在缓解网络钓鱼、互动劫持和混淆代理攻击等高严重性漏洞的增强功能。此更新要求开发者明确选择启用新的安全标准,以保持应用兼容性和用户保护。
对开发者的主要影响包括:
- BAL 安全加固和改进的选择启用: 我们正在优化后台活动启动 (BAL) 限制,方法是将保护范围扩展到
IntentSender。开发者必须从旧版MODE_BACKGROUND_ACTIVITY_START_ALLOWED常量迁移。相反,您应 采用精细控制,例如MODE_BACKGROUND_ACTIVITY_START_ALLOW_IF_VISIBLE,它将 活动启动限制为调用应用可见的场景,从而显著 缩小攻击面。 - 采用工具: 开发者应利用严格模式和更新后的 lint 检查来识别旧版模式,并确保为未来的目标 SDK 要求做好准备。
預設啟用 CT
如果應用程式指定 Android 17 (API 級別 37) 以上版本,系統預設會啟用憑證透明化 (CT)。(在 Android 16 上,CT 可供使用,但應用程式必須選擇加入)。
更安全的 Native DCL-C
If your app targets Android 17 (API level 37) 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.
限制 CP2 資料檢視中的 PII 欄位
对于以 Android 17(API 级别 Android 17(API 级别 37))及更高版本为目标平台的应用,联系人提供程序 2 (CP2) 会限制数据视图中包含某些个人身份信息 (PII) 的列。启用此变更后,这些列将从数据视图中移除,以增强用户隐私保护。 受限列包括:
如果应用正在使用 ContactsContract.Data
中的这些列,则可以通过与 RAW_CONTACT_ID 联接,改为从 ContactsContract.RawContacts
中提取这些列。
在 CP2 中強制執行嚴格的 SQL 檢查
For apps targeting Android 17 (API level Android 17 (API level 37)) and
higher, Contacts Provider 2 (CP2) enforces strict SQL query validation when
the ContactsContract.Data table is accessed without
READ_CONTACTS permission.
With this change, if an app doesn't have READ_CONTACTS
permission, StrictColumns and
StrictGrammar options are set when querying
the ContactsContract.Data table. If a query
uses a pattern that isn't compatible with these, it will be
rejected and cause an exception to be thrown.
媒體
Android 17 包含下列媒體行為變更。
背景音訊強化
從 Android 17 開始,音訊架構會強制限制背景音訊互動,包括音訊播放、音訊焦點要求和音量變更 API,確保這些變更是由使用者刻意啟動。
所有應用程式都必須遵守部分音訊限制。不過,如果應用程式指定 Android 17 (API 級別 37),限制會更加嚴格。如果這些應用程式在背景與音訊互動,就必須執行前景服務。此外,應用程式也必須符合下列一或多項規定:
- 前景服務必須具備「僅限使用期間」權限。
- 應用程式必須具備精確鬧鐘權限,並與
USAGE_ALARM音訊串流互動。
如需更多資訊 (包括緩解策略),請參閱「背景音訊強化」。
裝置板型規格
Android 17 包含下列異動項目,可改善各種尺寸和板型規格裝置的使用者體驗。
平台 API 異動,可忽略大螢幕 (sw>=600dp) 的螢幕方向、大小調整和長寬比限制
我们在 Android 16 中引入了平台 API 变更,以 忽略屏幕方向、 宽高比和尺寸调整能力限制(针对大型屏幕,sw >= 600dp),适用于面向 API 级别 36 或更高级别的应用。开发者可以选择使用 SDK 36 退出这些变更,但对于面向 Android 17(API 级别 37)或更高级别的应用,此退出选项将不再可用。
如需了解详情,请参阅忽略屏幕方向和尺寸调整能力限制。
連線能力
Android 17 導入下列變更,可提升一致性,並與藍牙 RFCOMM 通訊端的標準 Java InputStream 行為保持一致。
RFCOMM 的 BluetoothSocket read() 行為一致
对于以 Android 17(API 级别 37)为目标平台的应用,
read() 方法从InputStream 获取的
基于 RFCOMM 的 BluetoothSocket 现在会在
套接字关闭或连接断开时返回 -1。
此更改使 RFCOMM 套接字行为与 LE CoC 套接字保持一致,并与标准 InputStream.read()
文档保持一致,该文档指出,当到达流的末尾时,系统会返回 -1。
仅依赖于捕获 IOException 以跳出读取循环的应用可能会受到此更改的影响,并且应更新 BluetoothSocket 读取循环以明确检查返回值 -1。这可确保在远程设备断开连接或套接字关闭时,循环正确终止。如需查看推荐的实现示例,请参阅传输蓝牙数据指南中的代码段。