和先前版本一樣,Android 17 也包含可能會影響應用程式的行為變更。以下行為變更僅適用於指定 Android 17 以上版本的應用程式。如果您的應用程式指定 Android 17 以上版本,建議您視情況修改應用程式,以支援這些行為。
此外,無論應用程式的 targetSdkVersion 為何,請務必查看對所有 Android 17 應用程式有影響的行為變更清單。
使用者體驗和系統 UI
Android 17 包含下列異動項目,旨在打造更一致、直觀的使用者體驗。
記憶體限制小工具
從 Android 17 開始,如果應用程式以 Android 17 (API 級別 37) 以上版本為目標,系統會對 RemoteViews 封包中 Bitmap 和 Icon 的合併記憶體用量,強制執行嚴格的記憶體限制 (1.5 * 螢幕寬度 * 螢幕高度 * 4)。如果超出這些限制,系統就會擲回嚴重 IllegalArgumentException,並導致應用程式程序當機。
詳情請參閱「UpdateAppWidget」。
核心功能
Android 17 包含下列異動項目,這類變更會修改或擴充 Android 系統的各種核心功能。
MessageQueue 的新無鎖實作
Beginning with Android 17, apps targeting Android 17 (API level 37)
or higher receive a new lock-free implementation of
android.os.MessageQueue. The new implementation improves performance and
reduces missed frames, but may break clients that reflect on MessageQueue
private fields and methods.
For more information, including mitigation strategies, see MessageQueue behavior change guidance.
靜態最終欄位現在無法修改
如果應用程式在 Android 17 以上版本上執行,且指定 Android 17 (API 級別 37) 以上版本,就無法變更 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 introduces platform support for Encrypted Client Hello (ECH), a TLS extension that enhances user privacy by encrypting the Server Name Indication (SNI) in the TLS handshake. This encryption helps prevent network observers from easily identifying the specific domain your app is connecting to.
For apps targeting Android 17 (API level 37) or higher, ECH is used for TLS connections. ECH is active only if the networking library used by the app (for example, HttpEngine, WebView, or OkHttp) has integrated ECH support and the remote server also supports the ECH protocol. If ECH cannot be negotiated, the client sends an ECH extension with randomized contents (a mechanism called ECH GREASE). See RFC 9849 for more details on how ECH GREASE works.
To allow apps to customize this behavior, Android 17 adds a new
<domainEncryption> element to the Network Security Configuration file.
Developers can use <domainEncryption> within <base-config> or
<domain-config> tags to select an ECH mode (for example,
"enabled" or "disabled") on a global or per-domain basis.
For more information, see the Encrypted Client Hello documentation.
以 Android 17 為目標的應用程式必須取得區域網路權限
Android 17 導入 ACCESS_LOCAL_NETWORK 執行階段權限,可防止使用者在未經授權的情況下存取區域網路。由於這項權限屬於現有的「NEARBY_DEVICES」權限群組,因此如果使用者已授予其他「NEARBY_DEVICES」權限,系統就不會再次提示。這項新規定可防止惡意應用程式利用不受限制的區域網路存取權,暗中追蹤使用者並收集數位指紋。應用程式宣告並要求這項權限後,即可探索區域網路 (LAN) 上的裝置並與之連線,例如智慧住宅裝置或投放接收器。
如果應用程式以 Android 17 (API 級別 37) 以上版本為目標,現在有兩種方式可與區域網路裝置保持通訊:採用系統中介的隱私權保護裝置挑選器,略過權限提示,或在執行階段明確要求這項新權限,以維持區域網路通訊。
詳情請參閱「區域網路權限」說明文件。
隱藏實體裝置上的密碼
如果應用程式指定 Android 17 (API 級別 37) 以上版本,且使用者使用實體輸入裝置 (例如外接鍵盤),Android 作業系統會將新的 show_passwords_physical 設定套用至密碼欄位中的所有字元。根據預設,這項設定會隱藏所有密碼字元。
Android 系統會顯示最後輸入的密碼字元,協助使用者確認密碼是否輸入錯誤。不過,使用較大的外接鍵盤時,這項功能就沒那麼必要。此外,配備外接鍵盤的裝置通常螢幕較大,因此他人更容易看到您輸入的密碼。
如果使用者正在使用裝置的觸控螢幕,系統會套用新的 show_passwords_touch 設定。
保護標準簡訊中的動態密碼
Beginning with Android 17, Android is extending its SMS OTP protection
to apply to standard SMS messages (SMS messages containing an OTP that do not
use the WebOTP or SMS Retriever formats). For most apps targeting
Android 17 (API level 37) or higher, these SMS messages do not become
available until three hours after receipt. This delay is intended to help
prevent OTP hijacking. During this three hour delay, the
SMS_RECEIVED_ACTION broadcast is withheld and
SMS provider database queries are filtered. The SMS message is
available to these apps after the delay.
Certain apps such as the default SMS assistant app, connected device companion apps, etc., are exempted from this delay. All apps that rely on reading SMS messages for OTP extraction should transition to using SMS Retriever or SMS User Consent APIs to ensure continued functionality.
安全性
Android 17 在裝置和應用程式安全性方面有以下改進。
活動安全性
在 Android 17 中,平台持續朝「預設安全」架構發展,推出一系列強化功能,旨在防範網路釣魚、互動劫持和混淆副手攻擊等高嚴重性攻擊。這項更新要求開發人員明確選擇加入新的安全標準,以維持應用程式相容性並保護使用者。
對開發人員的主要影響包括:
- 強化 BAL 並改善啟用程序:我們將擴大保護範圍至
IntentSender,進一步完善背景活動啟動 (BAL) 限制。開發人員必須從舊版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
如果您的應用程式指定 Android 17 (API 級別 37) 以上版本,Android 14 推出的 DEX 和 JAR 檔案安全動態程式碼載入 (DCL) 保護機制,現在也適用於原生程式庫。
使用 System.load() 載入的所有原生檔案都必須標示為唯讀。否則系統會擲回 UnsatisfiedLinkError。
我們建議應用程式盡量避免使用動態載入程式碼,否則應用程式很可能會因為程式碼插入或竄改程式碼而無法正常運作。
限制 CP2 資料檢視中的 PII 欄位
For apps targeting Android 17 (API level Android 17 (API level 37)) and higher, Contacts Provider 2 (CP2) restricts certain columns containing Personally Identifiable Information (PII) from the data view. When this change is enabled, these columns are removed from the data view to enhance user privacy. The restricted columns include:
Apps that are using these columns from ContactsContract.Data
can extract them from ContactsContract.RawContacts
instead, by joining with RAW_CONTACT_ID.
在 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 包含下列系統智慧功能變更。
setContentCaptureEnabled 淘汰
Content Capture is enabled by default on certain devices to allow on-device AI features to analyze screen contents for intelligent experiences.
Starting in Android 17, the
ContentCaptureManager.setContentCaptureEnabled(boolean)
API method is deprecated. For apps that target Android 17 (API level 37) or
higher, calling setContentCaptureEnabled(false) no longer disables Content
Capture.
If your app needs to continue disabling Content Capture or restrict screen
contents from being captured by the system, you must transition to using the
FLAG_SECURE window layout parameter.
To disable Content Capture, set the FLAG_SECURE flag on your window as shown
in the following example:
Kotlin
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
Java
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
);
For more details, see the
WindowManager.LayoutParams.FLAG_SECURE reference
documentation.
媒體
Android 17 包含下列媒體行為變更。
強化背景音訊
Beginning with Android 17, the audio framework enforces restrictions on background audio interactions including audio playback, audio focus requests, and volume change APIs to ensure that these changes are started intentionally by the user.
Some audio restrictions apply to all apps. However, the restrictions are more stringent if an app targets Android 17 (API level 37). If one of these apps interacts with audio while it is in the background, it must have a foreground service running. In addition, the app must meet one or both of these requirements:
- The foreground service must have while-in-use (WIU) capabilities.
- The app must have the exact alarm permission and be interacting with
USAGE_ALARMaudio streams.
For more information, including mitigation strategies, see Background audio hardening.
裝置板型規格
Android 17 包含下列異動項目,可提升各種尺寸和板型規格裝置的使用者體驗。
平台 API 異動,可忽略大螢幕 (sw>=600dp) 的螢幕方向、大小調整和顯示比例限制
我們在 Android 16 中導入了平台 API 變更,針對指定 API 級別 36 以上版本的應用程式,忽略大螢幕 (sw >= 600dp) 的螢幕方向、顯示比例和大小調整限制。開發人員可使用 SDK 36 選擇不採用這些變更,但如果應用程式的目標版本是 Android 17 (API 級別 37) 以上版本,則無法再選擇不採用。
詳情請參閱「系統會忽略螢幕方向和大小調整限制」。
連線能力
Android 17 針對藍牙 RFCOMM 通訊端導入下列變更,以提升一致性並符合標準 Java InputStream 行為。
RFCOMM 的 BluetoothSocket read() 行為一致
如果應用程式指定 Android 17 (API 級別 37) 為目標版本,從 RFCOMM 型 BluetoothSocket 取得的 InputStream 的 read() 方法,現在會在通訊端關閉或連線中斷時傳回 -1。
這項變更可讓 RFCOMM Socket 的行為與 LE CoC Socket 一致,並符合標準InputStream.read()文件,該文件指出到達串流結尾時會傳回 -1。
如果應用程式只會擷取 IOException 來中斷讀取迴圈,就可能會受到這項變更影響,因此應更新 BluetoothSocket 讀取迴圈,明確檢查是否傳回 -1 值。這樣可確保遠端裝置中斷連線或插座關閉時,迴圈會正確終止。如要查看建議的實作方式範例,請參閱「透過藍牙傳輸資料」指南中的程式碼片段。