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

Starting in Android 16, we're adjusting regular and expedited job execution runtime quota based on the following factors:

  • Which app standby bucket the application is in: in Android 16, active standby buckets will start being enforced by a generous runtime quota.
  • If the job starts execution while the app is in a top state: in Android 16, Jobs started while the app is visible to the user and continues after the app becomes invisible, will adhere to the job runtime quota.
  • If the job is executing while running a Foreground Service: in Android 16, jobs that are executing concurrently with a foreground service will adhere to the job runtime quota. If you're leveraging jobs for user initiated data transfer, consider using user initiated data transfer jobs instead.

This change impacts tasks scheduled using WorkManager, JobScheduler, and DownloadManager. To debug why a job was stopped, we recommend logging why your job was stopped by calling WorkInfo.getStopReason() (for JobScheduler jobs, call JobParameters.getStopReason()).

For information about how your app's state affects the resources it can use, see Power management resource limits. For more information on battery-optimal best practices, refer to guidance on optimize battery use for task scheduling APIs.

We also recommend leveraging the new JobScheduler#getPendingJobReasonsHistory API introduced in Android 16 to understand why a job has not executed.

Testing

To test your app's behavior, you can enable override of certain job quota optimizations as long as the app is running on an Android 16 device.

To disable enforcement of "top state will adhere to job runtime quota", run the following adb command:

adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_TOP_STARTED_JOBS APP_PACKAGE_NAME

To disable enforcement of "jobs that are executing while concurrently with a foreground service will adhere to the job runtime quota", run the following adb command:

adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_FGS_JOBS APP_PACKAGE_NAME

To test certain app standby bucket behavior, you can set the app standby bucket of your app using the following adb command:

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

To understand the app standby bucket your app is in, you can get the app standby bucket of your app using the following adb command:

adb shell am get-standby-bucket APP_PACKAGE_NAME

Motivo di interruzione dei processi vuoti abbandonati

An abandoned job occurs when the JobParameters object associated with the job has been garbage collected, but JobService#jobFinished(JobParameters, boolean) has not been called to signal job completion. This indicates that the job may be running and being rescheduled without the app's awareness.

Apps that rely on JobScheduler, don't maintain a strong reference to the JobParameters object, and timeout will now be granted the new job stop reason STOP_REASON_TIMEOUT_ABANDONED, instead of STOP_REASON_TIMEOUT.

If there are frequent occurrences of the new abandoned stop reason, the system will take mitigation steps to reduce job frequency.

Apps should use the new stop reason to detect and reduce abandoned jobs.

If you're using WorkManager, AsyncTask, or DownloadManager, you aren't impacted because these APIs manage the job lifecycle on your app's behalf.

Ritiro completo di JobInfo#setImportantWhileForeground

Il metodo JobInfo.Builder#setImportantWhileForeground(boolean) indica l'importanza di un job quando l'app di pianificazione è in primo piano o quando è temporaneamente esente dalle limitazioni in background.

Questo metodo è stato ritirato da Android 12 (livello API 31). A partire da Android 16, non funziona più in modo efficace e la chiamata di questo metodo verrà ignorata.

Questa rimozione di funzionalità si applica anche a JobInfo#isImportantWhileForeground(). A partire da Android 16, se il metodo viene chiamato, restituisce 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 includes the latest updates to the Android Runtime (ART) that improve the Android Runtime's (ART's) performance and provide support for additional Java features. Through Google Play System updates, these improvements are also available to over a billion devices running Android 12 (API level 31) and higher.

As these changes are released, libraries and app code that rely on internal structures of ART might not work correctly on devices running Android 16, along with earlier Android versions that update the ART module through Google Play system updates.

Relying on internal structures (such as non-SDK interfaces) can always lead to compatibility problems, but it's particularly important to avoid relying on code (or libraries containing code) that leverages internal ART structures, since ART changes aren't tied to the platform version the device is running on and they go out to over a billion devices through Google Play system updates.

All developers should check whether their app is impacted by testing their apps thoroughly on Android 16. In addition, check the known issues to see if your app depends on any libraries that we've identified that rely on internal ART structures. If you do have app code or library dependencies that are affected, seek public API alternatives whenever possible and request public APIs for new use cases by creating a feature request in our issue tracker.

Modalità di compatibilità con dimensioni pagina di 16 kB

Android 15 introduced support for 16 KB memory pages to optimize performance of the platform. Android 16 adds a compatibility mode, allowing some apps built for 4 KB memory pages to run on a device configured for 16 KB memory pages.

When your app is running on a device with Android 16 or higher, if Android detects that your app has 4 KB aligned memory pages, it automatically uses compatibility mode and display a notification dialog to the user. Setting the android:pageSizeCompat property in the AndroidManifest.xml to enable the backwards compatibility mode will prevent the display of the dialog when your app launches. To use the android:pageSizeCompat property, compile your app using the Android 16 SDK.

For best performance, reliability, and stability, your app should still be 16 KB aligned. Check out our recent blog post on updating your apps to support 16 KB memory pages for more details.

The compatibility mode dialog that displays when the system detects that a 4 KB-aligned app could run more optimally if 16 KB aligned.

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

Un proprietario di dispositivo virtuale è un'app attendibile o con privilegi che crea e gestisce un dispositivo virtuale. I proprietari di dispositivi virtuali eseguono app su un dispositivo virtuale e poi proiettano le app sul display di un dispositivo remoto, come un computer personale, un dispositivo di realtà virtuale o un sistema di infotainment per auto. Il proprietario del dispositivo virtuale si trova su un dispositivo locale, ad esempio un cellulare.

Il proprietario del dispositivo virtuale sullo smartphone crea un dispositivo virtuale che proietta l'app sul display remoto.

Override per app

Sui dispositivi con Android 16 (livello API 36), i proprietari di dispositivi virtuali possono ignorare le impostazioni delle app su determinati dispositivi virtuali che gestiscono. Ad esempio, per migliorare il layout delle app, il proprietario di un dispositivo virtuale può ignorare le limitazioni di orientamento, proporzioni e ridimensionamento durante la proiezione delle app su un display esterno.

Modifiche che provocano un errore comuni

Il comportamento di Android 16 potrebbe influire sulla UI della tua app su fattori di forma con schermi di grandi dimensioni, come display dell'auto o Chromebook, in particolare sui layout progettati per piccoli display in orientamento verticale. Per scoprire come rendere la tua app adattabile a tutti i fattori di forma dei dispositivi, consulta Informazioni sui layout adattabili.

Riferimenti

Streaming di app complementari

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 offre una sicurezza predefinita contro gli attacchi di reindirizzamento Intent generali, con modifiche minime alla compatibilità e allo sviluppo richieste.

Stiamo introducendo soluzioni di rafforzamento della sicurezza per impostazione predefinita per gli exploit di reindirizzamento Intent. Nella maggior parte dei casi, le app che utilizzano intent non riscontrano problemi di compatibilità. Abbiamo raccolto metriche durante il nostro processo di sviluppo per monitorare quali app potrebbero riscontrare interruzioni.

Il reindirizzamento degli intent in Android si verifica quando un malintenzionato può controllare parzialmente o completamente i contenuti di un intent utilizzato per avviare un nuovo componente nel contesto di un'app vulnerabile, mentre l'app vittima avvia un intent di livello secondario non attendibile in un campo extra di un intent ("di primo livello"). Ciò può portare l'app malintenzionata ad avviare componenti privati nel contesto dell'app vittima, ad attivare azioni privilegiate o a ottenere l'accesso URI a dati sensibili, con conseguente furto di dati ed esecuzione di codice arbitrario.

Disattivare la gestione del reindirizzamento intent

Android 16 introduce una nuova API che consente alle app di disattivare le protezioni di sicurezza all'avvio. Ciò potrebbe essere necessario in casi specifici in cui il comportamento di sicurezza predefinito interferisce con casi d'uso legittimi dell'app.

Per le applicazioni compilate con l'SDK Android 16 (livello API 36) o versioni successive

Puoi utilizzare direttamente il metodo removeLaunchSecurityProtection() sull'oggetto Intent.

val i = intent
val iSublevel: Intent? = i.getParcelableExtra("sub_intent")
iSublevel?.removeLaunchSecurityProtection() // Opt out from hardening
iSublevel?.let { startActivity(it) }
Per le applicazioni compilate su Android 15 (livello API 35) o versioni precedenti

Anche se non è consigliato, puoi utilizzare la reflection per accedere al metodo removeLaunchSecurityProtection().

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