和先前版本一樣,Android 17 也包含可能會影響應用程式的行為變更。以下行為變更僅適用於指定 Android 17 以上版本的應用程式。如果應用程式指定 Android 17 以上版本,建議您視情況修改應用程式,以支援這些行為。
此外,無論應用程式的 targetSdkVersion 為何,請務必查看對所有 Android 17 應用程式有影響的行為變更清單。
使用者體驗和系統 UI
Android 17 包含下列異動項目,旨在打造更一致、直覺的使用者體驗。
記憶體限制小工具
Beginning with Android 17, the system enforces a strict memory limit on
RemoteViews updates for apps targeting Android 17 (API level 37) or
higher. When an app passes a RemoteViews object to
AppWidgetManager.updateAppWidget,
system_server calculates the total memory footprint of all image data across
every orientation and size bucket in the payload. If the total memory exceeds
the system ceiling (mMaxWidgetBitmapMemory), the system rejects the update and
throws an IllegalArgumentException:
java.lang.IllegalArgumentException: RemoteViews for widget update exceeds maximum bitmap memory usage (used: XXXXX, max: YYYYY)
For apps targeting API level 36 or lower, the system logs this memory violation
as a warning (Slog.w) without throwing an exception.
Android skills
View on GitHub
Manage AppWidget updates and bitmap memory
android skills add glance-appwidget-updates-and-memory
How the system calculates the memory ceiling
The system sets the widget bitmap memory budget at 6 * width * height bytes
(1.5 * 4 * width * height, equivalent to 1.5 times the size of a full-screen
ARGB_8888 buffer) for the active display configuration. Under API level 37 and
higher, this calculation includes both of the following:
- In-memory
Bitmapand bitmap-backedIconobjects (Icon.TYPE_BITMAPandIcon.TYPE_ADAPTIVE_BITMAP) stored inRemoteViews.mBitmapCache(such as calls tosetImageViewBitmap,Icon.createWithBitmap,Icon.createWithAdaptiveBitmap, or Jetpack GlanceImageProvider(bitmap)). Each uniqueBitmapor bitmap-backedIconinstance inmBitmapCacheis counted once perRemoteViewshierarchy. - URI-backed images (
Icon.createWithContentUri,setImageViewUri, or GlanceImageProvider(uri)) don't count toward theRemoteViewsIPC byte cap insystem_server, but the widget host process decodes the referencedcontent://file at full resolution into its own heap. Prefer passing a downsampledBitmapdirectly in memory (androidx.glance.ImageProvider(bitmap)orsetImageViewBitmap), asFileProviderURI permission grants fail when a work-profile widget is placed on a personal home screen. If your widget must use aFileProviderURI, always write a downsampled image intocontext.cacheDirfirst.
Mitigation steps
To keep your widget updates within the memory ceiling across phones, tablets, and foldables, do the following:
Compute your runtime memory budget from
WindowMetrics: On API level 30 and higher, read the active window bounds fromWindowManager.currentWindowMetrics.boundsrather thanresources.displayMetrics. On multi-resolution devices and foldables,displayMetricscan report inactive display dimensions. Estimate your total widget image budget at6L * bounds.width() * bounds.height()as shown in the following example:private const val FALLBACK_MAX_BYTES = 15_000_000L fun calculateWidgetMemoryCapBytes(context: Context): Long { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { val wm = context.getSystemService(WindowManager::class.java) ?: return FALLBACK_MAX_BYTES val bounds = wm.currentWindowMetrics.bounds return 6L * bounds.width().toLong() * bounds.height().toLong() } val dm = context.resources.displayMetrics return 6L * dm.widthPixels.toLong() * dm.heightPixels.toLong() }Downsample images to the widget's viewable dimensions and use
RGB_565: Decode bitmaps with power-of-twoBitmapFactory.Options.inSampleSizevalues sized to the widget's maximum display dimensions (maxWidthDpbymaxHeightDp), and useBitmap.Config.RGB_565(2bytes per pixel) instead ofARGB_8888(4bytes per pixel) for opaque photographs and thumbnails.Hoist bitmap decoding outside
provideContentin Jetpack Glance: When usingSizeMode.ResponsiveorSizeMode.Exact, Glance invokes yourprovideContentlambda once per size bucket. Decode each sharedBitmaponce insideprovideGlancebefore callingprovideContentso all size buckets reference the sameBitmapinstance inRemoteViews.mBitmapCache.Use full
updateAppWidgetcalls when replacing images: In classicAppWidgetProviderimplementations, avoid callingAppWidgetManager.partiallyUpdateAppWidgetto swapBitmaporIconviews. Partial updates merge new actions into the existingRemoteViewstree insystem_serverwithout evicting previously cached image actions. Build a completeRemoteViewslayout and callupdateAppWidgetinstead.Provide an error fallback layout: In Jetpack Glance, override
onCompositionErrorto render a zero-bitmapRemoteViewsfallback if an update fails.
You can inspect your widget's current serialized bitmap memory usage on a connected device by running the following:
adb shell dumpsys appwidget
核心功能
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.
靜態最終欄位現在無法修改
Apps running on Android 17 or higher that target
Android 17 (API level 37) or higher cannot change static final fields. If
an app attempts to change a static final field by using reflection, it will
cause an IllegalAccessException. Attempting to modify one of these fields
through JNI APIs (such as SetStaticLongField()) will cause the app to crash.
無障礙設定
Android 17 進行下列變更,提升無障礙功能。
支援複雜輸入法實體鍵盤輸入的無障礙功能
此功能引入了新的 AccessibilityEvent 和 TextAttribute API,以增强屏幕阅读器对 CJKV 语言输入的语音反馈。CJKV IME 应用现在可以指示在文本撰写期间是否已选择文本转换候选字词。具有修改字段的应用可以在发送文字更改无障碍事件时指定文字更改类型。例如,应用可以指定在文本撰写期间发生了文本更改,或者文本更改是由提交操作引起的。
这样做可让屏幕阅读器等无障碍服务根据文本修改的性质提供更精确的反馈。
应用采用量
IME 应用:在编辑字段中设置撰写文本时,IME 可以使用
TextAttribute.Builder.setTextSuggestionSelected()指示是否选择了特定转换候选。具有修改字段的应用:维护自定义
InputConnection的应用可以通过调用TextAttribute.isTextSuggestionSelected()来检索候选选择数据。然后,这些应用应在分派TYPE_VIEW_TEXT_CHANGED事件时调用AccessibilityEvent.setTextChangeTypes()。对于以 Android 17(API 级别 37)为目标平台且使用标准TextView的应用,此功能将默认启用。(也就是说,TextView将在向无障碍服务发送事件时,处理从 IME 检索数据和设置文本更改类型的工作)。无障碍服务:处理
TYPE_VIEW_TEXT_CHANGED事件的无障碍服务可以调用AccessibilityEvent.getTextChangeTypes()来识别修改的性质,并相应地调整其反馈策略。
隱私權
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 並改善選擇加入機制:我們正在調整背景活動啟動 (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 可用,但应用必须选择启用。)
Safer Native DCL—C
如果您的应用以 Android 17(API 级别 37)或更高版本为目标平台,那么 Android 14 中针对 DEX 和 JAR 文件引入的更安全的动态代码加载 (DCL) 保护机制现在也适用于原生库。
使用 System.load() 加载的所有原生文件都必须标记为只读。
否则,系统会抛出 UnsatisfiedLinkError。
我们建议应用尽可能避免动态加载代码,因为这样做会大大增加应用因代码注入或代码篡改而遭到入侵的风险。
限制 CP2 資料檢視中的 PII 欄位
如果應用程式指定 Android 17 (API 級別 37) 以上版本,聯絡人供應程式 2 (CP2) 會限制資料檢視中包含個人識別資訊 (PII) 的特定資料欄。這項異動生效後,資料檢視畫面將不再顯示這些資料欄,以強化使用者隱私。受限資料欄包括:
如果應用程式使用 ContactsContract.Data 中的這些資料欄,可以改為與 RAW_CONTACT_ID 彙整,從 ContactsContract.RawContacts 擷取這些資料欄。
在 CP2 中強制執行嚴格的 SQL 檢查
For apps targeting 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 淘汰
在某些设备上,内容捕获功能默认处于启用状态,以便设备端 AI 功能分析屏幕内容,从而提供智能体验。
从 Android 17 开始,ContentCaptureManager.setContentCaptureEnabled(boolean) API 方法已被废弃。对于以 Android 17(API 级别 37)或更高版本为目标平台的应用,调用 setContentCaptureEnabled(false) 不再会停用内容捕获功能。
如果您的应用需要继续停用内容捕获功能或限制系统捕获屏幕内容,您必须改用 FLAG_SECURE 窗口布局参数。
如需停用内容捕获,请在窗口中设置 FLAG_SECURE 标志,如以下示例所示:
Kotlin
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
Java
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
);
如需了解详情,请参阅 WindowManager.LayoutParams.FLAG_SECURE 参考文档。
媒體
Android 17 對媒體行為進行下列變更。
背景音訊強化
從 Android 17 開始,音訊架構會對背景音訊互動強制執行限制,包括音訊播放、音訊焦點要求和音量變更 API,確保這些變更是由使用者刻意啟動。
部分音訊限制適用於所有應用程式。不過,如果應用程式指定 Android 17 (API 級別 37),限制會更嚴格。如果這類應用程式在背景執行時與音訊互動,則必須執行前景服務。此外,應用程式必須符合下列一或兩項規定:
- 前景服務必須具備使用期間 (WIU) 功能。
- 應用程式必須具備精確鬧鐘權限,並與
USAGE_ALARM音訊串流互動。
如需更多資訊 (包括緩解策略),請參閱「背景音訊強化」。
裝置板型規格
Android 17 包含下列異動項目,可改善各種裝置尺寸和板型規格的使用者體驗。
平台 API 異動:在大螢幕 (sw>=600dp) 上忽略螢幕方向、大小調整和顯示比例限制
We introduced Platform API changes in Android 16 to ignore orientation, resizability, and aspect ratio restrictions on large screens (sw >= 600dp) for apps targeting API level 36 or higher. Developers have the option to opt out of these changes with SDK 36, but this opt-out will no longer be available for apps that target Android 17 (API level 37) or higher.
For more information, see Restrictions on orientation and resizability are ignored.
連線能力
Android 17 推出下列異動,以提升一致性,並與藍牙 RFCOMM 通訊端的標準 Java InputStream 行為保持一致。
RFCOMM 的 BluetoothSocket read() 行為一致
For apps targeting Android 17 (API level 37), the
read() method of the InputStream obtained from an
RFCOMM-based BluetoothSocket now returns -1 when the
socket is closed or the connection is dropped.
This change makes RFCOMM socket behavior consistent with LE CoC sockets and
aligns with the standard InputStream.read()
documentation, which states that -1 is returned when the end of the stream is
reached.
Apps that rely solely on catching an IOException to break out of a read loop may
be impacted by this change and should update the BluetoothSocket read loops to
explicitly check for a return value of -1. This ensures the loop terminates
correctly when the remote device disconnects or the socket is closed. For an
example of the recommended implementation, see the
code snippet in the Transfer Bluetooth data
guide.