Modifiche al comportamento: tutte le app

La piattaforma Android 16 include modifiche al comportamento che potrebbero influire sulla tua app. Le seguenti modifiche al comportamento si applicano a tutte le app quando vengono eseguite su Android 16, indipendentemente dal targetSdkVersion. Devi testare la tua app e poi modificarla in base alle necessità per supportare queste modifiche, ove applicabile.

Assicurati di esaminare anche l'elenco delle modifiche al comportamento che interessano solo le app che hanno come target Android 16.

Funzionalità di base

Android 16 (livello API 36) include le seguenti modifiche che modificano o espandono varie funzionalità di base del sistema Android.

Ottimizzazioni delle quote di JobScheduler

从 Android 16 开始,我们将根据以下因素调整常规作业和加急作业的执行运行时配额:

  • 应用所处的应用待机存储分区:在 Android 16 中,活跃待机存储分区将开始通过宽松的运行时配额强制执行。
  • 如果作业在应用处于前台状态时开始执行:在 Android 16 中,如果作业在应用对用户可见时开始执行,并在应用变为不可见后继续执行,则会遵守作业运行时配额。
  • 如果作业在运行前台服务时执行:在 Android 16 中,与前台服务同时执行的作业将遵守作业运行时配额。如果您利用作业进行用户发起的数据传输,请考虑改用用户发起的数据传输作业

此变更会影响使用 WorkManager、JobScheduler 和 DownloadManager 调度的任务。如需调试作业停止的原因,我们建议您通过调用 WorkInfo.getStopReason()(对于 JobScheduler 作业,请调用 JobParameters.getStopReason())来记录作业停止的原因。

如需了解应用的状态如何影响其可使用的资源,请参阅电源管理资源限制。 如需详细了解电池优化方面的最佳实践,请参阅有关针对任务调度 API 优化电池使用的指南。

我们还建议利用 Android 16 中引入的新 JobScheduler#getPendingJobReasonsHistory API 来了解作业未执行的原因。

测试

如需测试应用的行为,只要应用在 Android 16 设备上运行,您就可以启用对某些作业配额优化功能的替换。

如需停用“顶级状态将遵守作业运行时配额”的强制执行,请运行以下 adb 命令:

adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_TOP_STARTED_JOBS APP_PACKAGE_NAME

如需停用“在与前台服务同时执行时,作业将遵守作业运行时配额”的强制执行,请运行以下 adb 命令:

adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_FGS_JOBS APP_PACKAGE_NAME

如需测试特定应用待机分桶行为,您可以使用以下 adb 命令设置应用的应用待机分桶:

adb shell am set-standby-bucket APP_PACKAGE_NAME active|working_set|frequent|rare|restricted

如需了解应用所在的待机分桶,您可以使用以下 adb 命令获取应用的待机分桶:

adb shell am get-standby-bucket APP_PACKAGE_NAME

Motivo di interruzione dei processi vuoti abbandonati

Un job abbandonato si verifica quando l'oggetto JobParameters associato al job è stato sottoposto a garbage collection, ma JobService#jobFinished(JobParameters, boolean) non è stato chiamato per segnalare il completamento del job. Ciò indica che il job potrebbe essere in esecuzione e essere riprogrammato senza che l'app lo sappia.

Le app che si basano su JobScheduler non mantengono un riferimento forte all'oggettoJobParameters e ora al timeout verrà concesso il nuovo motivo di interruzione del jobSTOP_REASON_TIMEOUT_ABANDONED, anziché STOP_REASON_TIMEOUT.

Se si verificano spesso casi del nuovo motivo di interruzione dell'abbandono, il sistema prenderà provvedimenti per ridurre la frequenza dei job.

Le app devono utilizzare il nuovo motivo di interruzione per rilevare e ridurre i job abbandonati.

Se utilizzi WorkManager, AsyncTask o DownloadManager, non sono interessati perché queste API gestiscono il ciclo di vita dei job per conto della tua app.

Ritiro completo di JobInfo#setImportantWhileForeground

JobInfo.Builder#setImportantWhileForeground(boolean) 方法用于在调度应用位于前台或暂时豁免于后台限制时指示作业的优先级。

自 Android 12(API 级别 31)起,此方法已废弃。从 Android 16 开始,它不再有效,系统会忽略调用此方法。

此功能移除也适用于 JobInfo#isImportantWhileForeground()。从 Android 16 开始,如果调用该方法,该方法会返回 false

L'ambito della priorità di trasmissione ordinata non è più globale

Android 应用可以为广播接收器定义优先级,以控制接收器接收和处理广播的顺序。对于清单声明的接收器,应用可以使用 android:priority 属性来定义优先级;对于上下文注册的接收器,应用可以使用 IntentFilter#setPriority() API 来定义优先级。发送广播时,系统会按接收器的优先级(从高到低)将其传送给接收器。

在 Android 16 中,无法保证使用 android:priority 属性或 IntentFilter#setPriority() 在不同进程中传送广播的顺序。广播优先级仅在同一应用进程内有效,而不会跨所有进程有效。

此外,广播优先级将自动限制在 (SYSTEM_LOW_PRIORITY + 1, SYSTEM_HIGH_PRIORITY - 1) 的范围内。只有系统组件才能将 SYSTEM_LOW_PRIORITYSYSTEM_HIGH_PRIORITY 设置为广播优先级。

如果您的应用执行以下任一操作,可能会受到影响:

  1. 您的应用声明了具有相同广播 intent 的多个进程,并且希望根据优先级以特定顺序接收这些 intent。
  2. 您的应用进程与其他进程交互,并期望以特定顺序接收广播 intent。

如果进程需要相互协调,则应使用其他协调渠道进行通信。

Modifiche interne ad ART

Android 16 include gli aggiornamenti più recenti all'ambiente di runtime Android (ART) che migliorano le prestazioni dell'ambiente di runtime Android (ART) e forniscono il supporto di funzionalità Java aggiuntive. Tramite gli aggiornamenti di sistema di Google Play, questi miglioramenti sono disponibili anche per oltre un miliardo di dispositivi con Android 12 (livello API 31) e versioni successive.

Man mano che queste modifiche vengono rilasciate, le librerie e il codice delle app che si basano sulle strutture interne di ART potrebbero non funzionare correttamente sui dispositivi con Android 16 e sulle versioni precedenti di Android che aggiornano il modulo ART tramite gli aggiornamenti di sistema di Google Play.

Fare affidamento su strutture interne (ad esempio interfacce non SDK) può sempre portare a problemi di compatibilità, ma è particolarmente importante evitare di fare affidamento su codice (o librerie contenenti codice) che sfrutta strutture ART interne, poiché le modifiche ART non sono legate alla versione della piattaforma su cui è in esecuzione il dispositivo e vengono rilasciate su oltre un miliardo di dispositivi tramite gli aggiornamenti di sistema di Google Play.

Tutti gli sviluppatori devono verificare se la loro app è interessata testando le proprie app in modo approfondito su Android 16. Inoltre, controlla i problemi noti per verificare se la tua app dipende da librerie che abbiamo identificato come basate su strutture ART interne. Se hai dipendenze di codice dell'app o della libreria che sono interessate, cerca alternative API pubbliche, se possibile, e richiedi API pubbliche per nuovi casi d'uso creando una richiesta di funzionalità nel nostro issue tracker.

Modalità di compatibilità con le dimensioni pagina di 16 kB

Android 15 引入了对 16 KB 内存页面的支持,以优化平台性能。Android 16 添加了兼容模式,让一些针对 4 KB 内存页面构建的应用可以在配置为 16 KB 内存页面的设备上运行。

当您的应用在搭载 Android 16 或更高版本的设备上运行时,如果 Android 检测到您的应用具有 4 KB 对齐的内存页面,则会自动使用兼容模式并向用户显示通知对话框。在 AndroidManifest.xml 中设置 android:pageSizeCompat 属性以启用向后兼容模式,将会阻止应用启动时显示对话框。如需使用 android:pageSizeCompat 属性,请使用 Android 16 SDK 编译您的应用。

为了实现最佳性能、可靠性和稳定性,应用仍应以 16 KB 对齐。如需了解详情,请参阅我们近期发布的博文,了解如何更新应用以支持 16 KB 的内存页面。

兼容模式对话框:当系统检测到 4 KB 对齐的应用在 16 KB 对齐的情况下可以更高效地运行时,系统会显示此对话框。

Esperienza utente e UI di sistema

Android 16 (livello API 36) include le seguenti modifiche volte a creare un'esperienza utente più coerente e intuitiva.

Ritiro degli annunci di accessibilità invasivi

Android 16 废弃了无障碍功能通告,其特征是使用 announceForAccessibility 或调度 TYPE_ANNOUNCEMENT 无障碍功能事件。这可能会给 TalkBack 和 Android 屏幕阅读器用户带来不一致的用户体验,而替代方案可以更好地满足各种 Android 辅助技术的用户需求。

替代方案示例:

已废弃的 announceForAccessibility API 的参考文档中包含有关建议替代方案的更多详细信息。

Supporto della navigazione con tre pulsanti

Android 16 brings predictive back support to the 3-button navigation for apps that have properly migrated to predictive back. Long-pressing the back button initiates a predictive back animation, giving you a preview of where the back swipe takes you.

This behavior applies across all areas of the system that support predictive back animations, including the system animations (back-to-home, cross-task, and cross-activity).

The predictive back animations in 3-button navigation mode.

Icone delle app a tema automatiche

Beginning with Android 16 QPR 2, Android automatically applies themes to app icons to create a cohesive home screen experience. This occurs if an app does not provide its own themed app icon. Apps can control the design of their themed app icon by including a monochrome layer within their adaptive icon and previewing what their app icon will look like in Android Studio.

Fattori di forma dei dispositivi

Android 16 (livello API 36) include le seguenti modifiche per le app quando vengono proiettate sui display dai proprietari di dispositivi virtuali.

Override del proprietario del dispositivo virtuale

虚拟设备所有者是创建和管理虚拟设备的受信任应用或特权应用。虚拟设备所有者在虚拟设备上运行应用,然后将应用投影到远程设备的显示屏上,例如个人电脑、虚拟现实设备或车载信息娱乐系统。虚拟设备所有者位于本地设备上,例如手机。

手机上的虚拟设备所有者创建将应用投影到远程显示屏的虚拟设备。

按应用替换项

在搭载 Android 16(API 级别 36)的设备上,虚拟设备所有者可以替换其管理的特定虚拟设备上的应用设置。例如,为了改进应用布局,虚拟设备所有者在将应用投影到外部显示屏上时,可以忽略屏幕方向、宽高比和可调整大小性限制。

常见的重大更改

Android 16 的行为可能会影响应用在汽车显示屏或 Chromebook 等大屏幕设备上的界面,尤其是那些专为竖屏小显示屏设计的布局。如需了解如何让应用适应所有设备类型,请参阅自适应布局简介

参考文档

配套应用串流

Sicurezza

Android 16 (livello API 36) include modifiche che promuovono la sicurezza del sistema per proteggere app e utenti da app dannose.

Maggiore sicurezza contro gli attacchi di reindirizzamento degli intent

Android 16 provides default security against general Intent redirection attacks, with minimum compatibility and developer changes required.

We are introducing by-default security hardening solutions to Intent redirection exploits. In most cases, apps that use intents normally won't experience any compatibility issues; we've gathered metrics throughout our development process to monitor which apps might experience breakages.

Intent redirection in Android occurs when an attacker can partly or fully control the contents of an intent used to launch a new component in the context of a vulnerable app, while the victim app launches an untrusted sub-level intent in an extras field of an ("top-level") Intent. This can lead to the attacker app launching private components in the context of the victim app, triggering privileged actions, or gaining URI access to sensitive data, potentially leading to data theft and arbitrary code execution.

Opt out of Intent redirection handling

Android 16 introduces a new API that allows apps to opt out of launch security protections. This might be necessary in specific cases where the default security behavior interferes with legitimate app use cases.

For applications compiling against Android 16 (API level 36) SDK or higher

You can directly use the removeLaunchSecurityProtection() method on the Intent object.

val i = intent
val iSublevel: Intent? = i.getParcelableExtra("sub_intent")
iSublevel?.removeLaunchSecurityProtection() // Opt out from hardening
iSublevel?.let { startActivity(it) }
For applications compiling against Android 15 (API level 35) or lower

While not recommended, you can use reflection to access the removeLaunchSecurityProtection() method.

val i = intent
val iSublevel: Intent? = i.getParcelableExtra("sub_intent", Intent::class.java)
try {
    val removeLaunchSecurityProtection = Intent::class.java.getDeclaredMethod("removeLaunchSecurityProtection")
    removeLaunchSecurityProtection.invoke(iSublevel)
} catch (e: Exception) {
    // Handle the exception, e.g., log it
} // Opt-out from the security hardening using reflection
iSublevel?.let { startActivity(it) }

Le app complementari non ricevono più notifiche relative ai timeout di rilevamento

Android 16 在配套设备配对流程期间引入了一种新行为,以防恶意应用侵犯用户的位置信息隐私。在 Android 16 上运行的所有配套应用都不再直接通过 RESULT_DISCOVERY_TIMEOUT 收到发现超时通知。而是通过可视对话框通知用户超时事件。当用户关闭对话框时,系统会通过 RESULT_USER_REJECTED 提醒应用关联失败。

搜索时长也从原来的 20 秒延长到了 30 秒,并且用户可以在搜索期间的任何时间停止设备发现。如果在开始搜索的前 20 秒内发现了至少 1 部设备,CDM 会停止搜索其他设备。

Connettività

Android 16 (livello API 36) include le seguenti modifiche nello stack Bluetooth per migliorare la connettività con i dispositivi periferici.

Gestione migliorata della perdita di cauzione

从 Android 16 开始,蓝牙堆栈已更新,以便在检测到远程配对丢失时提高安全性和用户体验。以前,系统会自动解除配对并启动新的配对流程,这可能会导致意外重新配对。在许多情况下,我们发现应用未以一致的方式处理债券损失事件。

为了统一体验,Android 16 改进了系统的绑定丢失处理。如果之前配对的蓝牙设备在重新连接时无法进行身份验证,系统会断开关联,保留本地配对信息,并显示系统对话框,告知用户配对已断开并指示他们重新配对。