Behavior changes: all apps

The Android 12 platform includes behavior changes that may affect your app. The following behavior changes apply to all apps when they run on Android 12, regardless of targetSdkVersion. You should test your app and then modify it as needed to support these properly, where applicable.

Make sure to also review the list of behavior changes that only affect apps targeting Android 12.

User experience

Stretch overscroll effect

On devices running Android 12 and higher, the visual behavior for overscroll events changes.

On Android 11 and lower, an overscroll event causes the visual elements to have a glow; on Android 12 and higher, the visual elements stretch and bounce back on a drag event and they fling and bounce back on a fling event.

For more information, see the guide to animating scroll gestures.

App splash screens

If you have previously implemented a custom splash screen in Android 11 or lower, you’ll need to migrate your app to the SplashScreen API to ensure that it displays correctly starting in Android 12. Not migrating your app will result in a degraded or unintended app launch experience.

For instructions, see Migrate your existing splash screen implementation to Android 12.

Additionally, starting in Android 12, the system always applies the new Android system default splash screen on cold and warm starts for all apps. By default, this system default splash screen is constructed using your app’s launcher icon element and the windowBackground of your theme (if it's a single color).

For more details, see the splash screens developer guide.

Web intent resolution

Starting in Android 12 (API level 31), a generic web intent resolves to an activity in your app only if your app is approved for the specific domain contained in that web intent. If your app isn't approved for the domain, the web intent resolves to the user's default browser app instead.

Apps can get this approval by doing one of the following:

If your app invokes web intents, consider adding a prompt or dialog that asks the user to confirm the action.

Immersive mode improvements for gesture navigation

Android 12 consolidates existing behavior to make it easier for users to perform gesture navigation commands while in immersive mode. In addition, Android 12 provides backward compatibility behavior for sticky immersive mode.

Display#getRealSize and getRealMetrics: deprecation and constraints

Android devices are available in many different form factors, such as large screens, tablets, and foldables. To render content appropriately for each device, your app needs to determine the screen or display size. Over time, Android has provided different APIs for retrieving this information. In Android 11, we introduced the WindowMetrics API and deprecated these methods:

In Android 12 we're continuing to recommend using WindowMetrics, and are deprecating these methods:

To mitigate the behavior of applications using Display APIs to retrieve the application's bounds, Android 12 constrains the values returned by the APIs for apps that are not fully resizable. This could have an impact on apps that are using this information with MediaProjection.

Apps should use the WindowMetrics APIs to query the bounds of their window, and Configuration.densityDpi to query the current density.

For broader compatibility with older versions of Android, you can use the Jetpack WindowManager library, which includes a WindowMetrics class that supports Android 4.0 (API level 14) and higher.

Examples of how to use WindowMetrics

First, be sure your app's activities are fully resizable.

An activity should rely upon WindowMetrics from an activity context for any UI-related work, particularly WindowManager.getCurrentWindowMetrics() or Jetpack's WindowMetricsCalculator.computeCurrentWindowMetrics().

If your app creates a MediaProjection, the bounds must be correctly sized since the projection captures the display partition in which the projector app is running.

If the app is fully resizable, the activity context returns the correct bounds like so:

Kotlin

val projectionMetrics: WindowMetrics = activityContext
      .getSystemService(WindowManager::class.java).maximumWindowMetrics

Java

WindowMetrics projectionMetrics = activityContext
      .getSystemService(WindowManager.class).getMaximumWindowMetrics();

If the app is not fully resizable, it must query from a WindowContext instance and retrieve the WindowMetrics of the activity bounds using WindowManager.getMaximumWindowMetrics() or the Jetpack method WindowMetricsCalculator.computeMaximumWindowMetrics().

Kotlin

val windowContext = context.createWindowContext(mContext.display!!,
      WindowManager.LayoutParams.TYPE_APPLICATION, null)
val projectionMetrics = windowContext.getSystemService(WindowManager::class.java)
      .maximumWindowMetrics

Java

Context windowContext = context.createWindowContext(mContext.getDisplay(),
      WindowManager.LayoutParams.TYPE_APPLICATION, null);
WindowMetrics projectionMetrics = windowContext.getSystemService(WindowManager.class)
      .getMaximumWindowMetrics();

All apps in multi-window mode

Android 12 makes multi-window mode standard behavior.

On large screens (sw >= 600dp), the platform supports all apps in multi-window mode regardless of app configuration. If resizeableActivity="false", the app is put into compatibility mode when necessary to accommodate display dimensions.

On small screens (sw < 600dp), the system checks an activity’s minWidth and minHeight to determine whether the activity can run in multi-window mode. If resizeableActivity="false", the app is prevented from running in multi‑window mode regardless of minimum width and height.

For more information, see Multi-window support.

Camera preview on large screens

Camera apps generally assume a fixed relationship between the orientation of the device and the aspect ratio of the camera preview. But large screen form factors, such as foldable devices, and display modes such as multi-window and multi-display, challenge that assumption.

On Android 12, camera apps that request a specific screen orientation and are not resizable (resizeableActivity="false") automatically enter inset portrait mode, which ensures the proper orientation and aspect ratio of the camera preview. On foldables and other devices that have a camera hardware abstraction layer (HAL), additional rotation is applied to the camera output to compensate for camera sensor orientation, and the camera output is cropped to match the aspect ratio of the app's camera preview. The cropping and extra rotation ensure proper presentation of the camera preview regardless of device orientation and folded or unfolded state of the device.

UX delay for foreground service notifications

To provide a streamlined experience for short-running foreground services, devices that run Android 12 or higher can delay the display of foreground service notifications by 10 seconds, with a few exceptions. This change gives short-lived tasks a chance to complete before their notifications appear.

Performance

Restricted App Standby Bucket

Android 11 (API level 30) introduced the restricted bucket as an App Standby Bucket. Starting in Android 12, this bucket is active by default. The restricted bucket has the lowest priority (and the highest restrictions) of all the buckets. The buckets in order of priority from high to low are:

  1. Active: App is currently being used or was very recently used.
  2. Working set: App is in regular use.
  3. Frequent: App is often used, but not every day.
  4. Rare: App is not frequently used.
  5. Restricted: App consumes a great deal of system resources, or may exhibit undesirable behavior.

The system considers your app's behavior, in addition to usage patterns, to decide whether to place your app in the restricted bucket.

Your app is less likely to be placed in the restricted bucket if your app uses system resources more responsibly. Also, the system places your app in a less restrictive bucket if the user interacts directly with your app.

Check whether your app is in the restricted bucket

To check whether the system has placed your app in the restricted bucket, call getAppStandbyBucket(). If the return value of this method is STANDBY_BUCKET_RESTRICTED, then your app is in the restricted bucket.

Test the restricted bucket behavior

To test how your app behaves when the system places your app into the restricted bucket, you can manually move your app to that bucket. To do so, run the following command in a terminal window:

adb shell am set-standby-bucket PACKAGE_NAME restricted

Security and privacy

Approximate location

The dialog has two sets of options, one above the
         other
Figure 1. System permissions dialog that allows the user to grant approximate location information.

On devices that run Android 12 or higher, users can request that your app have access to only approximate location information.

If your app requests the ACCESS_FINE_LOCATION runtime permission, you should also request the ACCESS_COARSE_LOCATION permission to handle the case where the user grants approximate location access to your app. You should include both permissions in a single runtime request.

The system permissions dialog includes the following options for the user, as shown in figure 1:

  • Precise: Provides access to precise location information.
  • Approximate: Provides access only to approximate location information.

Microphone and camera toggles

Supported devices that run Android 12 or higher allow users to enable and disable camera and microphone access for all apps on the device, by pressing a single toggle option. Users can access the toggleable options from Quick Settings, as shown in figure 1, or from the Privacy screen in system settings.

Learn more about these toggles, and how to check that your app follows best practices regarding the CAMERA and RECORD_AUDIO permissions.

Microphone and camera indicators

On devices that run Android 12 or higher, when an app accesses the microphone or camera, an icon appears in the status bar.

Learn more about these indicators and how to check that your app follows best practices regarding the CAMERA and RECORD_AUDIO permissions.

Quick settings tiles are labeled 'Camera access' and
         'Mic access'
Figure 2. Microphone and camera toggles in Quick Settings.
A rounded rectangle in the upper-right corner, which
         includes a camera icon and a microphone icon
Figure 3. Microphone and camera indicators, which show recent data access.

Permission package visibility

On devices that run Android 12 or higher, apps that target Android 11 (API level 30) or higher and that call one of following methods receive a filtered set of results, based on the app's package visibility into other apps:

BouncyCastle implementation removed

Android 12 removes many BouncyCastle implementations of cryptographic algorithms that were previously deprecated, including all AES algorithms. The system instead uses the Conscrypt implementations of these algorithms.

This change affects your app if any of the following are true:

  • Your app uses 512-bit key sizes. Conscrypt doesn't support this key size. If necessary, update your app's cryptography logic to use different key sizes.
  • Your app uses invalid key sizes with KeyGenerator. Conscrypt's implementation of KeyGenerator performs additional validation on key parameters, compared to BouncyCastle. For example, Conscrypt doesn't allow your app to generate a 64-bit AES key because AES only supports 128-, 192-, and 256-bit keys.

    BouncyCastle allows keys of invalid sizes to be generated, but later fails if these keys are used with a Cipher. Conscrypt fails earlier.

  • You initialize your Galois/Counter Mode (GCM) ciphers using a size other than 12 bytes. Conscrypt's implementation of GcmParameterSpec requires an initialization of 12 bytes, which NIST recommends.

Clipboard access notifications

On Android 12 and higher, when an app calls getPrimaryClip() to access clip data from a different app for the first time, a toast message notifies the user of this clipboard access.

The text inside the toast message contains the following format: APP pasted from your clipboard.

Information about text in clip description

On Android 12 and higher, getPrimaryClipDescription() can detect the following details:

Apps can't close system dialogs

To improve user control when interacting with apps and the system, the ACTION_CLOSE_SYSTEM_DIALOGS intent action is deprecated as of Android 12. Except for a few special cases, when your app tries to invoke an intent that contains this action, the system does one of the following based on your app's target SDK version:

  • If your app targets Android 12 or higher, a SecurityException occurs.
  • If your app targets Android 11 (API level 30) or lower, the intent doesn't execute, and the following message appears in Logcat:

    E ActivityTaskManager Permission Denial: \
    android.intent.action.CLOSE_SYSTEM_DIALOGS broadcast from \
    com.package.name requires android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS, \
    dropping broadcast.
    

Exceptions

In the following cases, an app can still close system dialogs on Android 12 or higher:

  • Your app is running an instrumentation test.
  • Your app targets Android 11 or lower and is showing a window that is on top of the notification drawer.

  • Your app targets Android 11 or lower. In addition, the user has interacted with a notification, possibly using the notification's action buttons, and your app is processing a service or broadcast receiver in response to that user action.

  • Your app targets Android 11 or lower and has an active accessibility service. If your app targets Android 12 and wants to close the notification bar, use the GLOBAL_ACTION_DISMISS_NOTIFICATION_SHADE accessibility action instead.

Untrusted touch events are blocked

To preserve system security and a good user experience, Android 12 prevents apps from consuming touch events where an overlay obscures the app in an unsafe way. In other words, the system blocks touches that pass through certain windows, with a few exceptions.

Affected apps

This change affects apps that choose to let touches pass through their windows, for example by using the FLAG_NOT_TOUCHABLE flag. Several examples include, but aren't limited to, the following:

Exceptions

In the following cases, "pass-through" touches are allowed:

  • Interactions within your app. Your app shows the overlay, and the overlay appears only when the user is interacting with your app.
  • Trusted windows. These windows include (but aren't limited to) the following:

  • Invisible windows. The window's root view is GONE or INVISIBLE.

  • Completely transparent windows. The alpha property is 0.0 for the window.

  • Sufficiently translucent system alert windows. The system considers a set of system alert windows to be sufficiently translucent when the combined opacity is less than or equal to the system's maximum obscuring opacity for touches. In Android 12, this maximum opacity is 0.8 by default.

Detect when an untrusted touch is blocked

If a touch action is blocked by the system, Logcat logs the following message:

Untrusted touch due to occlusion by PACKAGE_NAME

Test the change

Untrusted touches are blocked by default on devices that run Android 12 or higher. To allow untrusted touches, run the following ADB command in a terminal window:

# A specific app
adb shell am compat disable BLOCK_UNTRUSTED_TOUCHES com.example.app

# All apps
# If you'd still like to see a Logcat message warning when a touch would be
# blocked, use 1 instead of 0.
adb shell settings put global block_untrusted_touches 0

To revert the behavior to the default (untrusted touches are blocked), run the following command:

# A specific app
adb shell am compat reset BLOCK_UNTRUSTED_TOUCHES com.example.app

# All apps
adb shell settings put global block_untrusted_touches 2

Activity lifecycle

Root launcher activities are no longer finished on Back press

Android 12 changes the default handling of the system Back press on launcher activities that are at the root of their tasks. In previous versions, the system would finish these activities on Back press. In Android 12, the system now moves the activity and its task to the background instead of finishing the activity. The new behavior matches the current behavior when navigating out of an app using the Home button or gesture.

For most apps, this change means that users who use Back to navigate out of your app are able to more quickly resume your app from a warm state, instead of having to completely restart the app from a cold state.

We recommend testing your apps with this change. If your app currently overrides onBackPressed() to handle Back navigation and finish the Activity, update your implementation to call through to super.onBackPressed() instead of finishing. Calling super.onBackPressed() moves the activity and its task to the background when appropriate and provides a more consistent navigation experience for users across apps.

Also note that, in general, we recommend using the AndroidX Activity APIs for providing custom back navigation, rather than overriding onBackPressed(). The AndroidX Activity APIs automatically defer to the appropriate system behavior if there are no components intercepting the system Back press.

Graphics and images

Improved refresh rate switching

In Android 12, refresh rate changes using setFrameRate() can happen regardless of whether the display supports a seamless transition to the new refresh rate; a seamless transition is one that doesn't have any visual interruptions, such as a black screen for a second or two. Previously, if the display did not support a seamless transition, it would typically continue using the same refresh rate after setFrameRate() is called. You can determine in advance whether the transition to the new refresh will likely be seamless by calling getAlternativeRefreshRates(). Generally, the callback onDisplayChanged() is called after the refresh rate switch completes, but for some externally-connected displays, it is called during a non-seamless transition.

Here’s an example of how you might implement this:

Kotlin

// Determine whether the transition will be seamless.
// Non-seamless transitions may cause a 1-2 second black screen.
val refreshRates = this.display?.mode?.alternativeRefreshRates
val willBeSeamless = Arrays.asList<FloatArray>(refreshRates).contains(newRefreshRate)

// Set the frame rate even if the transition will not be seamless.
surface.setFrameRate(newRefreshRate, FRAME_RATE_COMPATIBILITY_FIXED_SOURCE, CHANGE_FRAME_RATE_ALWAYS)

Java

// Determine whether the transition will be seamless.
// Non-seamless transitions may cause a 1-2 second black screen.
Display display = context.getDisplay(); // API 30+
Display.Mode mode = display.getMode();
float[] refreshRates = mode.getAlternativeRefreshRates();
boolean willBeSeamless = Arrays.asList(refreshRates).contains(newRefreshRate);

// Set the frame rate even if the transition will not be seamless.
surface.setFrameRate(newRefreshRate, FRAME_RATE_COMPATIBILITY_FIXED_SOURCE, CHANGE_FRAME_RATE_ALWAYS);

Connectivity

Passpoint updates

The following APIs are added in Android 12:

  • isPasspointTermsAndConditionsSupported(): Terms and conditions is a Passpoint feature that allows network deployments to replace insecure captive portals, which use open networks, with a secure Passpoint network. A notification is displayed to the user when terms and conditions are required to be accepted. Apps that suggest Passpoint networks that are gated by terms and conditions must call this API first to make sure that the device supports the capability. If the device does not support the capability, it won't be able to connect to this network, and an alternative or legacy network must be suggested.
  • isDecoratedIdentitySupported(): When authenticating to networks with a prefix decoration, the decorated identity prefix allows network operators to update the Network Access Identifier (NAI) to perform explicit routing through multiple proxies inside of an AAA network (see RFC 7542 for more on this).

    Android 12 implements this feature to conform with the WBA specification for PPS-MO extensions. Apps that suggest Passpoint networks that require a decorated identity must call this API first to make sure that the device supports the capability. If the device does not support the capability, the identity won't be decorated and the authentication to the network might fail.

To create a Passpoint suggestion, apps must use the PasspointConfiguration, Credential, and HomeSp classes. These classes describe the Passpoint profile, which is defined in the Wi-Fi Alliance Passpoint specification.

For more information, see Wi-Fi suggestion API for internet connectivity.

Updated non-SDK interface restrictions

Android 12 includes updated lists of restricted non-SDK interfaces based on collaboration with Android developers and the latest internal testing. Whenever possible, we make sure that public alternatives are available before we restrict non-SDK interfaces.

If your app does not target Android 12, some of these changes might not immediately affect you. However, while you can currently use some non-SDK interfaces (depending on your app's target API level), using any non-SDK method or field always carries a high risk of breaking your app.

If you are unsure if your app uses non-SDK interfaces, you can test your app to find out. If your app relies on non-SDK interfaces, you should begin planning a migration to SDK alternatives. Nevertheless, we understand that some apps have valid use cases for using non-SDK interfaces. If you cannot find an alternative to using a non-SDK interface for a feature in your app, you should request a new public API.

To learn more about the changes in this release of Android, see Updates to non-SDK interface restrictions in Android 12. To learn more about non-SDK interfaces generally, see Restrictions on non-SDK interfaces.