page.title=Behavior Changes page.keywords=preview,sdk,compatibility sdk.platform.apiLevel=MNC @jd:body

In this document

  1. Runtime Permissions
  2. Power-Saving Optimizations
  3. Adoptable Storage Devices
  4. Apache HTTP Client Removal
  5. AudioManager Changes
  6. Notifications
  7. Text Selection
  8. Android Keystore Changes
  9. Wi-Fi and Networking Changes
  10. Camera Service Changes
  11. Runtime
  12. Access to Hardware Identifier
  13. APK Validation
  14. USB Connection
  15. Android for Work Changes

API Differences

  1. API level 22 to M Preview »

See Also

  1. M Developer Preview API Overview

Along with new features and capabilities, the M Developer Preview includes a variety of system changes and API behavior changes. This document highlights some of the key changes that you should understand and account for in your apps.

If you have previously published an app for Android, be aware that these changes in the platform affect your app.

Runtime Permissions

This preview introduces a new permissions model, where users can now directly manage app permissions at runtime. This model gives users improved visibility and control over permissions, while streamlining the installation and auto-update processes for app developers. Users can grant or revoke permissions individually for installed apps.

On your apps that target the M Preview release or higher, make sure to check for and request permissions at runtime. To determine if your app has been granted a permission, call the new {@link android.content.Context#checkSelfPermission(java.lang.String) checkSelfPermission()} method. To request a permission, call the new {@link android.app.Activity#requestPermissions(java.lang.String[], int) requestPermissions()} method. Even if your app is not targeting the M Preview release, you should test your app under the new permissions model.

For details on supporting the new permissions model in your app, see the Permissions developer preview page. For tips on how to assess the impact on your app, see the Testing Guide

Power-Saving Optimizations

This preview introduces new power-saving optimizations for idle devices and apps.

To learn more about these power-saving changes, see Power-Saving Optimizations.

Adoptable Storage Devices

With this preview, users can adopt external storage devices such as SD cards. Adopting an external storage device encrypts and formats the device to behave like internal storage. This feature allows users to move both apps and private data of those apps between storage devices. When moving apps, the system respects the {@code android:installLocation} preference in the manifest.

If your app accesses the following APIs or fields, be aware that the file paths they return will dynamically change when the app is moved between internal and external storage devices. When building file paths, it is strongly recommended that you always call these APIs dynamically. Don’t use hardcoded file paths or persist fully-qualified file paths that were built previously.

To debug this feature in the developer preview, you can enable adoption of a USB drive that is connected to an Android device through a USB On-The-Go (OTG) cable, by running this command:

$ adb shell sm set-force-adoptable true

Apache HTTP Client Removal

This preview removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the {@link java.net.HttpURLConnection} class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your {@code build.gradle} file:

android {
    useLibrary 'org.apache.http.legacy'
}

Android is moving away from OpenSSL to the BoringSSL library. If you’re using the Android NDK in your app, don't link against cryptographic libraries that are not a part of the NDK API, such as {@code libcrypto.so} and {@code libssl.so}. These libraries are not public APIs, and may change or break without notice across releases and devices. In addition, you may expose yourself to security vulnerabilities. Instead, modify your native code to call the Java cryptography APIs via JNI or to statically link against a cryptography library of your choice.

AudioManager Changes

Setting the volume directly or muting specific streams via the {@link android.media.AudioManager} class is no longer supported. The {@link android.media.AudioManager#setStreamSolo(int,boolean) setStreamSolo()} method is deprecated, and you should call the {@link android.media.AudioManager#requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int) requestAudioFocus()} method instead. Similarly, the {@link android.media.AudioManager#setStreamMute(int,boolean) setStreamMute()} method is deprecated; instead, call the {@link android.media.AudioManager#adjustStreamVolume(int, int, int) adjustStreamVolume()} method and pass in the direction value {@link android.media.AudioManager#ADJUST_MUTE} or {@link android.media.AudioManager#ADJUST_UNMUTE}.

Notifications

This release removes the {@code Notification.setLatestEventInfo()} method. Use the {@link android.app.Notification.Builder} class instead to construct notifications. To update a notification repeatedly, reuse the {@link android.app.Notification.Builder} instance. Call the {@link android.app.Notification.Builder#build()} method to get updated {@link android.app.Notification} instances.

The {@code adb shell dumpsys notification} command no longer prints out your notification text. Use the {@code adb shell dumpsys notification --noredact} command instead to print out the text in a notification object.

Text Selection

When users select text in your app, you can now display text selection actions such as Cut, Copy, and Paste in a floating toolbar. The user interaction implementation is similar to that for the contextual action bar, as described in Enabling the contextual action mode for individual views.

To implement a floating toolbar for text selection, make the following changes in your existing apps:

  1. In your {@link android.view.View} or {@link android.app.Activity} object, change your {@link android.view.ActionMode} calls from {@code startActionMode(Callback)} to {@code startActionMode(Callback, ActionMode.TYPE_FLOATING)}.
  2. Take your existing implementation of {@code ActionMode.Callback} and make it extend {@link android.view.ActionMode.Callback2} instead.
  3. Override the {@link android.view.ActionMode.Callback2#onGetContentRect(android.view.ActionMode, android.view.View, android.graphics.Rect) onGetContentRect()} method to provide the coordinates of the content {@link android.graphics.Rect} object (such as a text selection rectangle) in the view.
  4. If the rectangle positioning is no longer valid, and this is the only element to be invalidated, call the {@link android.view.ActionMode#invalidateContentRect() invalidateContentRect()} method.

If you are using Android Support Library revision 22.2, be aware that floating toolbars are not backward-compatible and appcompat takes control over {@link android.view.ActionMode} objects by default. This prevents floating toolbars from being displayed. To enable {@link android.view.ActionMode} support in an {@link android.support.v7.app.AppCompatActivity}, call {@link android.support.v7.app.AppCompatActivity#getDelegate()}, then call {@link android.support.v7.app.AppCompatDelegate#setHandleNativeActionModesEnabled(boolean) setHandleNativeActionModesEnabled()} on the returned {@link android.support.v7.app.AppCompatDelegate} object and set the input parameter to {@code false}. This call returns control of {@link android.view.ActionMode} objects to the framework. In devices running the M Preview, that allows the framework to support {@link android.support.v7.app.ActionBar} or floating toolbar modes, while on pre-M Preview devices, only the {@link android.support.v7.app.ActionBar} modes are supported.

Android Keystore Changes

With this preview, the Android Keystore provider no longer supports DSA. ECDSA is still supported.

Keys which do not require encryption at rest will no longer be deleted when secure lock screen is disabled or reset (for example, by the user or a Device Administrator). Keys which require encryption at rest will be deleted during these events.

Wi-Fi and Networking Changes

This preview introduces the following behavior changes to the Wi-Fi and networking APIs.

Camera Service Changes

In this preview, the model for accessing shared resources in the camera service has been changed from the previous “first come, first serve” access model to an access model where high-priority processes are favored. Changes to the service behavior include:

Runtime

The ART runtime now properly implements access rules for the {@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method. This change fixes a problem where Dalvik was checking access rules incorrectly in previous versions. If your app uses the {@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method and you want to override access checks, call the {@link java.lang.reflect.Constructor#setAccessible(boolean) setAccessible()} method with the input parameter set to {@code true}. If your app uses the v7 appcompat library or the v7 recyclerview library, you must update your app to use to the latest versions of these libraries. Otherwise, make sure that any custom classes referenced from XML are updated so that their class constructors are accessible.

This preview updates the behavior of the dynamic linker. The dynamic linker now understands the difference between a library’s {@code soname} and its path ( public bug 6670), and search by {@code soname} is now implemented. Apps which previously worked that have bad {@code DT_NEEDED} entries (usually absolute paths on the build machine’s file system) may fail when loaded.

The {@code dlopen(3) RTLD_LOCAL} flag is now correctly implemented. Note that {@code RTLD_LOCAL} is the default, so calls to {@code dlopen(3)} that didn’t explicitly use {@code RTLD_LOCAL} will be affected (unless your app explicitly used {@code RTLD_GLOBAL}). With {@code RTLD_LOCAL}, symbols will not be made available to libraries loaded by later calls to {@code dlopen(3)} (as opposed to being referenced by {@code DT_NEEDED} entries).

Access to Hardware Identifier

To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The {@link android.net.wifi.WifiInfo#getMacAddress() WifiInfo.getMacAddress()} and the {@link android.bluetooth.BluetoothAdapter#getAddress() BluetoothAdapter.getAddress()} methods now return a constant value of {@code 02:00:00:00:00:00}.

To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the following permissions:

Note: When a device running M Developer Preview initiates a background Wi-Fi or Bluetooth scan, the operation is visible to external devices as originating from a randomized MAC address.

APK Validation

The platform now performs stricter validation of APKs. An APK is considered corrupt if a file is declared in the manifest but not present in the APK itself. An APK must be re-signed if any of the contents are removed.

USB Connection

Device connections through the USB port are now set to charge-only mode by default. To access the device and its content over a USB connection, users must explicitly grant permission for such interactions. If your app supports user interactions with the device over a USB port, take into consideration that the interaction must be explicitly enabled.

Android for Work Changes

This preview includes the following behavior changes for Android for Work: