Like earlier releases, Android 11 includes behavior changes that may
affect your app. The following behavior changes apply exclusively to apps
that are targeting Android 11 or higher. If your app sets
targetSdkVersion
to 30
, you should modify your app to
support these behaviors properly, where applicable.
Be sure to also review the list of behavior changes that affect all apps running on Android 11.
Privacy
Android 11 introduces changes and restrictions to enhance user privacy, including the following:
- Scoped storage enforcement: Access into external storage directories is limited to an app-specific directory and specific types of media that the app has created.
- Permissions auto-reset: If users haven't interacted with an app for a few months, the system auto-resets the app's sensitive permissions.
- Background location access: Users must be directed to system settings in order to grant the background location permission to apps.
- Package visibility: When an app queries for the list of installed apps on the device, the returned list is filtered.
To learn more, see the Privacy page.
Security
Heap pointer tagging
Change details
Change Name: NATIVE_HEAP_POINTER_TAGGING
Change ID: 135754954
How to toggle
As you test your app's compatibility with Android 11, you can toggle this change on or off using the following ADB commands:
adb shell am compat enable (135754954|NATIVE_HEAP_POINTER_TAGGING) PACKAGE_NAME
adb shell am compat disable (135754954|NATIVE_HEAP_POINTER_TAGGING) PACKAGE_NAME
For more information about the compatibility framework and toggling changes, see Test and debug platform behavior changes in your app.
Heap pointers now have a non-zero tag in the most significant byte (MSB). Applications that use pointers incorrectly, including those that modify the MSB, can now crash or experience other issues. This change is necessary to support future hardware with ARM Memory Tagging Extension (MTE) enabled. To learn more, see Tagged Pointers.
To disable this feature, see the allowNativeHeapPointerTagging
manifest documentation.
Updates to toasts
Custom toasts from the background are blocked
For security reasons and to maintain a good user experience, the system blocks
toasts that contain custom views if those toasts are sent from the background by
an app that targets Android 11 or higher. Note that text toasts
are still allowed; these are toasts created using
Toast.makeText()
that
don't call setView()
.
If your app tries to post a toast containing a custom view from the background anyway, the system doesn't show the message to the user. Instead, the system logs the following message in logcat:
W/NotificationService: Blocking custom toast from package \ <package> due to package not in the foreground
Toast callbacks
If you want to be notified when a toast (text or custom) appears or disappears,
use the
addCallback()
method, which was added in Android 11.
Text toast API changes
Apps that target Android 11 or higher see the following side effects for text toasts:
- The
getView()
method returnsnull
. - The return values of the following methods don't reflect the actual values, so you shouldn't rely on them in your app:
- The following methods are no-ops, so your app shouldn't use them:
Connectivity
Restricted read access to APN database
Change details
Change Name: APN_READING_PERMISSION_CHANGE_ID
Change ID: 124107808
How to toggle
As you test your app's compatibility with Android 11, you can toggle this change on or off using the following ADB commands:
adb shell am compat enable (124107808|APN_READING_PERMISSION_CHANGE_ID) PACKAGE_NAME
adb shell am compat disable (124107808|APN_READING_PERMISSION_CHANGE_ID) PACKAGE_NAME
For more information about the compatibility framework and toggling changes, see Test and debug platform behavior changes in your app.
Apps that target Android 11 now require the
Manifest.permission.WRITE_APN_SETTINGS
privileged permission to read or access the Telephony
provider APN database. Attempting to access the APN database without this
permission generates a security exception.
Accessibility
Declare interaction with TTS engines in manifest file
Because of changes to package
visibility, apps that target
Android 11 and interact with a text-to-speech (TTS) engine need
to add the following <queries>
element to their manifest files:
<queries> <intent> <action android:name="android.intent.action.TTS_SERVICE" /> </intent> </queries>
Declare accessibility button usage in metadata file
Change details
Change Name: REQUEST_ACCESSIBILITY_BUTTON_CHANGE
Change ID: 136293963
How to toggle
As you test your app's compatibility with Android 11, you can toggle this change on or off using the following ADB commands:
adb shell am compat enable (136293963|REQUEST_ACCESSIBILITY_BUTTON_CHANGE) PACKAGE_NAME
adb shell am compat disable (136293963|REQUEST_ACCESSIBILITY_BUTTON_CHANGE) PACKAGE_NAME
For more information about the compatibility framework and toggling changes, see Test and debug platform behavior changes in your app.
Starting in Android 11, your accessibility service cannot make
a runtime declaration that it has an association with the system's
accessibility button. If you
append AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON
to the
flags
property of an AccessibilityServiceInfo
object, the framework doesn't
pass accessibility button callback events to your service.
To receive accessibility callback events in your accessibility service, use your
accessibility service metadata file to declare your service's association with
the accessibility button. Include the flagRequestAccessibilityButton
value in
your definition of the
accessibilityFlags
attribute. A common location for the accessibility service metadata file is
res/raw/accessibilityservice.xml
.
Camera
Media intent actions require system default camera
Starting in Android 11, only pre-installed system camera apps can respond to the following intent actions:
android.media.action.VIDEO_CAPTURE
android.media.action.IMAGE_CAPTURE
android.media.action.IMAGE_CAPTURE_SECURE
If more than one pre-installed system camera app is available, the system presents a dialog for the user to select an app. If you want your app to use a specific third-party camera app to capture images or videos on its behalf, you can make these intents explicit by setting a package name or component for the intent.
App packaging and installation
Compressed resource files
Change details
Change Name: RESOURCES_ARSC_COMPRESSED
Change ID: 132742131
How to toggle
As you test your app's compatibility with Android 11, you can toggle this change on or off using the following ADB commands:
adb shell am compat enable (132742131|RESOURCES_ARSC_COMPRESSED) PACKAGE_NAME
adb shell am compat disable (132742131|RESOURCES_ARSC_COMPRESSED) PACKAGE_NAME
For more information about the compatibility framework and toggling changes, see Test and debug platform behavior changes in your app.
Apps that target Android 11 (API level 30) or higher can't be installed if they
contain a compressed resources.arsc
file or if this file is not aligned on
a 4-byte boundary. This file can't be memory-mapped by the system if either of
these conditions is present. Resources tables that can't be memory-mapped must
be read into a buffer in RAM, resulting in unnecessary memory pressure on the
system and greatly-increased RAM usage on the device.
If you were previously using a compressed resources.arsc
file, try alternative
strategies instead, such as shrinking app
resources or other methods to
shrink, obfuscate, and optimize your app.
APK Signature Scheme v2 now required
Apps that target Android 11 (API level 30) that are currently only signed using APK Signature Scheme v1 must now also be signed using APK Signature Scheme v2 or higher. Users can't install or update apps that are only signed with APK Signature Scheme v1 on devices that run Android 11.
To verify that your app is being signed with APK Signature Scheme v2 or higher,
you can use either Android Studio,
or the apksigner
tool on the command line.
Firebase
Firebase JobDispatcher and GCMNetworkManager
If your app targets API level 30 or higher, Firebase JobDispatcher and GcmNetworkManager API calls are disabled on devices running Android 6.0 (API level 23) or higher. For migration information, see Migrating from Firebase JobDispatcher to WorkManager and Migrating from GCMNetworkManager to WorkManager.
Speech recognition
Because of changes to package
visibility, apps that target
Android 11 and interact with a speech recognition service need
to add the following <queries>
element to their manifest files:
<queries> <intent> <action android:name="android.speech.RecognitionService" /> </intent> </queries>
Callback changes for OnSharedPreferenceChangeListener
Change details
Change Name: CALLBACK_ON_CLEAR_CHANGE
Change ID: 119147584
How to toggle
As you test your app's compatibility with Android 11, you can toggle this change on or off using the following ADB commands:
adb shell am compat enable (119147584|CALLBACK_ON_CLEAR_CHANGE) PACKAGE_NAME
adb shell am compat disable (119147584|CALLBACK_ON_CLEAR_CHANGE) PACKAGE_NAME
For more information about the compatibility framework and toggling changes, see Test and debug platform behavior changes in your app.
For apps targeting Android 11 (API level 30), whenever
Editor.clear
is called, a callback is now made to
OnSharedPreferenceChangeListener.onSharedPreferenceChanged
with a null
key.
Non-SDK interface restrictions
Android 11 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 11, 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 11. To learn more about non-SDK interfaces generally, see Restrictions on non-SDK interfaces.