Skip to content

Most visited

Recently visited


Android P Behavior Changes

Android P introduces a number of changes to the Android system. Most of these changes affect all apps, regardless of what version of Android they target. However, several changes only affect apps targeting Android P. To maximize clarity, this page is divided into two sections: Apps targeting all API levels and Apps targeting Android P.

All apps running on Android P

These behavior changes apply to all apps when they run on the Android P platform, regardless of the API level that they are targeting. All developers should review these changes and modify their apps to support them properly, where applicable to the app.

Input and data privacy in background apps

Android P strengthens privacy by limiting the ability of background apps to access user input and sensor data. If your app is running in the background on a device running Android P, the system applies the following restrictions to your app:

If your app needs to detect sensor events on devices running Android P, use a foreground service.

Device security changes

Devices running Android P provide key rotation and system call protection. These changes enhance app security, no matter what API level your app targets. For more details, see changes to all apps on the Security Behavior Changes page.

Cryptographic changes

Android P introduces several changes to the implementation and handling of cryptographic algorithms.

Conscrypt implementations of parameters and algorithms

Android P provides additional implementations of algorithm parameters in Conscrypt. These parameters include: AES, DESEDE, OAEP, and EC. The Bouncy Castle versions of these parameters and many algorithms have been deprecated in Android P.

If your app targets Android 8.1 (API level 27) or lower, you receive a warning when requesting the Bouncy Castle implementation of one of these deprecated algorithms. If you target Android P, however, these requests each throw a NoSuchAlgorithmException.

Other changes

Android P introduces several other cryptographic changes:

App compatibility changes

To help ensure app stability and compatiblity, the platform restricts the use of some non-SDK methods and fields; these restrictions apply whether you attempt to access these methods and fields directly, via reflection, or using JNI. In Developer Preview 1, your app can continue to access these restricted interfaces; the platform uses toasts and log entries to bring them to your attention. If your app shows such a toast, it is important that you pursue an implementation strategy other than the restricted interface. If you feel that no alternative strategy is feasible, you may file a bug to request reconsideration of the restriction.

Restrictions on Non-SDK Interfaces contains further important information. You should review it to ensure that your app continues to function.

Updates to the ICU libraries

The version of the ICU library used in the platform has been updated from ICU 58, used in Android 8.0 (API level 26) and 8.1 (API level 27), to ICU 60.

ICU is used to provide public APIs beneath the package and is used internally in the Android platform for internationalization support. For example, it is used to implement Android classes in java.util, java.text and android.text.format. This release contains many small but useful changes like Emoji 5.0 data support and improved date/time formats, as documented in the ICU 59 and ICU 60 release notes. You should take particular note of the following points:

Android secure encrypted files are no longer supported

Test suite build changes

The addRequirements() method in the TestSuiteBuilder class has been removed, and the TestSuiteBuilder class itself been deprecated. The addRequirements() method had required developers to supply arguments whose types are hidden APIs, making the API invalid.

Testing libraries removed from framework

In Android 8.1 (API level 27) and lower, the Android framework provides several classes, such as ActivityInstrumentationTestCase2, that you can use to create tests in your app. At compile time, these classes are available when building against android.jar. This built-in testing architecture, although convenient, requires you to test against the version of JUnit that android.jar provides, which makes it difficult to build and test dependencies that rely on a different version of JUnit.

To give you more flexibility in building and testing custom or third-party logic, Android P removes test classes from the framework. The testing libraries are still available as optional dependencies, though. The Legacy testing libraries page describes how to use them in Android P.

To learn more about how to test Android apps, see Testing Apps on Android.

Java UTF decoder

UTF-8 is the default charset in Android. A UTF-8 byte sequence can be decoded by a String constructor, such as String(byte[] bytes). The UTF-8 decoder is stricter in Android P and follows the Unicode standards, namely:

Hostname verification using a certificate

RFC 2818 describes two methods to match a domain name against a certificate—using the available names within the subjectAltName (SAN) extension, or in the absence of a SAN extension, falling back to the commonName (CN).

However, the fallback to the CN was deprecated in RFC 2818. For this reason, Android no longer falls back to using the CN. To verify a hostname, the server must present a certificate with a matching SAN. Certificates that don't contain a SAN matching the hostname are no longer trusted.

Network address lookups can cause network violations

Network address lookups that require name resolution can involve network I/O and are considered blocking operations. Blocking operations on the main thread can cause pauses or jank.

The StrictMode class is a development tool that helps developers to detect problems in their code. StrictMode now detects network violations caused by network address lookups that require name resolution.

Developers should not ship their apps with StrictMode enabled. Otherwise, their apps can experience new exceptions, such as NetworkOnMainThreadException when using the detectNetwork() or detectAll() methods to get a policy that detects network violations.

Resolving a numeric IP address isn't considered a blocking operation. Numeric IP address resolution works the same way as in platform versions lower than Android P.

Socket tagging

In platform versions lower than Android P, if a socket is tagged using the setThreadStatsTag() method, the socket is untagged when it's sent to another process using binder IPC with a ParcelFileDescriptor container.

Starting in Android P, the socket tag is kept when it’s is sent to another process using binder IPC. This change can affect network traffic statistics, for example, when using the queryDetailsForUidTag() method. You can keep the previous behavior by calling the untagSocket() before sending the socket to another process.

Reported amount of available bytes in socket

The available() method returns 0 when it's called after invoking the shutdownInput() method.

More detailed network capabilities reporting for VPNs

In platform versions lower than Android P, the NetworkCapabilities class only reported a limited set of information for VPNs, such as TRANSPORT_VPN but omitting NET_CAPABILITY_NOT_VPN. This situation made it difficult for app developers to determine if using a VPN would result in charges to the user. For example, checking NET_CAPABILITY_NOT_METERED would not determine whether the underlying networks are metered or not.

Starting in Android P, when a VPN calls the setUnderlyingNetworks() method, the Android system merges the transports and capabilities of any underlying networks and returns the result as the effective network capabilities of the VPN network.

App developers that already check for NET_CAPABILITY_NOT_METERED receive the network capabilities of the VPN and the underlying networks starting in Android P.

Files in xt_qtaguid folder are no longer available to apps

Direct read access to files in the /proc/net/xt_qtaguid folder is no longer allowed to apps. The reason is to ensure consistency with some devices running Android P at launch that don't have these files at all.

The public APIs that rely on these files, TrafficStats and NetworkStatsManager, continue to work as intended. However, the unsupported cutils functions, such as qtaguid_tagSocket(), may not work as expected—or at all— on different devices.

FLAG_ACTIVITY_NEW_TASK requirement is now enforced

With Android P, you cannot start an activity from a non-activity context unless you pass the intent flag FLAG_ACTIVITY_NEW_TASK. If you attempt to start an activity without passing this flag, the activity does not start, and the system prints a message to the log.

Screen rotation changes

Users in Android O can toggle between auto-rotate and portrait rotation modes using a Quicksettings tile or Display settings. In Android P there are significant changes to the portrait rotation mode. The portrait mode has been renamed rotation lock and it is active when auto-rotate is toggled off. There are no changes to auto-rotate mode.

When the device is in rotation lock mode, users can lock their screen to any rotation supported by the top, visible Activity. An Activity should not assume it will always be rendered in portrait. If the top Activity can be rendered in multiple rotations in auto-rotate mode, the same options should be available in rotation locked mode, with some exceptions based on the Activity's screenOrientation setting (see the table below).

Activities that request a specific orientation (for example, screenOrientation=landscape) ignore the user lock preference and behave the same way as in Android O.

The screen orientation preference can be set at the Activity level in the Android Manifest, or programmatically with setRequestedOrientation().

The rotation lock mode works by setting the user rotation preference which the WindowManager uses when handling Activity rotation. The user rotation preference might be changed in the following cases. Note that there is a bias to return to portrait mode:

The following table summarizes rotation behavior for the common screen orientations:

Screen Orientation Behavior
unspecified, user In auto-rotate and rotation lock the Activity can be rendered in portrait or landscape (and the reverse). Expect to support both portrait and landscape layouts.
userLandscape In auto-rotate and rotation lock the Activity can be rendered in either landscape or reverse landscape. Expect to support only landscape layouts.
userPortrait In auto-rotate and rotation lock the Activity can be rendered in either portrait or reverse portrait. Expect to support only portrait layouts.
fullUser In auto-rotate and rotation lock the Activity can be rendered in portrait or landscape (and the reverse). Expect to support both portrait and landscape layouts.

Rotation lock users will be given the option to lock to reverse portrait, often 180º.
sensor, fullSensor, sensorPortrait, sensorLandscape The rotation lock mode preference is ignored and is treated as if auto-rotate is active. Only use this in exceptional circumstances with very careful UX consideration.

Apps targeting Android P

These behavior changes apply exclusively to apps that are targeting the P platform or higher. Apps that compile against Android P or higher or set targetSdkVersion to Android P or higher must modify their apps to support these behaviors properly, where applicable to the app.

Foreground Services

Apps that target Android P or higher and use foreground services must request the FOREGROUND_SERVICE permission. This is a normal permission, so the system automatically grants it to the requesting app.

If an app that targets Android P attempts to create a foreground service without requesting FOREGROUND_SERVICE, the system throws a SecurityException.

Device serial access restrictions

The Build.SERIAL field was deprecated in Android 8.0 (API level 26). In Android P, Build.SERIAL is always set to "UNKNOWN". This change protects users' privacy.

If your app needs to access a device's hardware serial number, you should request the READ_PHONE_STATE permission, then call getSerial().

Framework security changes

If your app targets Android P, the system enforces stricter network and file system security. For more details, see changes to apps targeting Android P on the Security Behavior Changes page.

View focus

Views with 0 area (either a width or a height is 0) are no-longer focusable.

Additionally, activities no-longer implicitly assign initial focus in touch-mode. Instead, it is up to you to explicitly request initial focus, if desired.

Android P apps enable the draft CSS Color Module Level 4 behaviour for handling 4 and 8 hex digit CSS colors.

CSS Color Module Level 4 has been supported by Chrome since release 52, but WebView currently disables the feature because existing Android applications were found to contain 32 bit hex colors in the Android ordering (ARGB), which would cause rendering errors.

For example, the color #80ff8080 is currently rendered in WebView as opaque light red (#ff8080) for apps targeting pre-Android P SDKs. The leading component (which would be interpreted by Android as the alpha component) is currently ignored. If an app targets P or above, this will be interpreted as 50% transparent light green (#80ff80).

Document scrolling element

Previously to Android P, scrolling position was set on the body element, and the root element had zero scroll values. Android P enables the standards-compliant behaviour where the scrolling element is the root element.

Furthermore, directly accessing document.body.scrollTop, document.body.scrollLeft, document.documentElement.scrollTop or document.documentElement.scrollLeft will behave differently depending on target SDK. To access viewport scroll values, use document.scrollingElement, if available.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


在微信上关注 Google Developers

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)