blob: 568d46ea01015180b428c1a7f428474d03862a8d [file] [log] [blame]
Quddus Chong5f150d52015-05-10 16:07:27 -07001page.title=Behavior Changes
2page.keywords=preview,sdk,compatibility
Quddus Chong79d03e92015-05-26 17:58:51 -07003sdk.platform.apiLevel=22-mnc
Quddus Chong5f150d52015-05-10 16:07:27 -07004@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8
9<h2>In this document</h2>
10
11<ol id="toc44" class="hide-nested">
12 <li><a href="#behavior-runtime-permissions">Runtime Permissions</a></li>
Quddus Chong79d03e92015-05-26 17:58:51 -070013 <li><a href="#behavior-power">Power-Saving Optimizations</a>
Quddus Chong5f150d52015-05-10 16:07:27 -070014 <ol>
Quddus Chong79d03e92015-05-26 17:58:51 -070015 <li><a href="#behavior-doze">Doze</a></li>
Quddus Chong5f150d52015-05-10 16:07:27 -070016 <li><a href="#behavior-app-standby">App Standby</a></li>
17 </ol>
18 </li>
19 <li><a href="#behavior-adoptable-storage">Adoptable Storage Devices</a></li>
20 <li><a href="#behavior-apache-http-client">Apache HTTP Client Removal</a></li>
21 <li><a href="#behavior-audiomanager-Changes">AudioManager Changes</a></li>
22 <li><a href="#behavior-test-selection">Text Selection</a></li>
23 <li><a href="#behavior-keystore">Android Keystore Changes</a></li>
Quddus Chong5f150d52015-05-10 16:07:27 -070024 <li><a href="#behavior-network">Wi-Fi and Networking Changes</a></li>
25 <li><a href="#behavior-camera">Camera Service Changes</a></li>
26 <li><a href="#behavior-art-runtime">ART Runtime</a></li>
27 <li><a href="#behavior-apk-validation">APK Validation</a></li>
28 <li><a href="#behavior-afw">Android for Work Changes</a></li>
29</ol>
30
31<h2>API Differences</h2>
32<ol>
33<li><a href="{@docRoot}preview/download.html">API level 22 to M Preview &raquo;</a> </li>
34</ol>
35
36
37<h2>See Also</h2>
38<ol>
39<li><a href="{@docRoot}preview/api-overview.html">M Developer Preview API Overview</a> </li>
40</ol>
41
42</div>
43</div>
44
Quddus Chong5f150d52015-05-10 16:07:27 -070045<p>Along with new features and capabilities, the M Developer Preview includes a variety of
46system changes and API behavior changes. This document highlights
47some of the key changes that you should be understand and account for in your apps.</p>
48
49<p>If you have previously published an app for Android, be aware that your app
50 might be affected by these changes in the platform.</p>
51
52<h2 id="behavior-runtime-permissions">Runtime Permissions</h1>
53<p>This preview introduces a new runtime permissions model, where users can now directly manage
54their app permissions at runtime. This model gives users improved visibility and control over
55permissions, while streamlining the installation and auto-update processes for app developers.
56Users can set permissions on or off for all apps running on the M Preview. However, apps that
57don’t target the M Preview cannot request permissions at runtime.</p>
58
59<p>On your apps that target the M Preview, make sure to check and request for permissions at
60runtime. To determine if your app has been granted a permission, call the
61new {@code Context.checkSelfPermission()} method. To request for a permission, call the new
62{@code Activity.requestPermission()} method.</p>
63
64<p>For more information on supporting the new permissions model in your app, see
65<a href="{@docRoot}preview/features/runtime-permissions.html">
66Android M Preview Runtime Permissions</a>.</p>
67
Quddus Chong79d03e92015-05-26 17:58:51 -070068<h2 id="behavior-power">Power-Saving Optimizations</h2>
Quddus Chong5f150d52015-05-10 16:07:27 -070069<p>This preview introduces new power-saving optimizations for idle devices and apps.</p>
70
Quddus Chong79d03e92015-05-26 17:58:51 -070071<h3 id="behavior-doze">Doze</h3>
Quddus Chong5f150d52015-05-10 16:07:27 -070072<p>If a device is unplugged and left stationary with the screen off for a period of time, it
73goes into <em>Doze</em> mode where it attempts to keep the system in a sleep state. In this mode,
74devices periodically resume normal operations for brief periods of time so that app syncing can
75occur and the system can perform any pending operations.</p>
76
Quddus Chong79d03e92015-05-26 17:58:51 -070077<p>The following restrictions apply to your apps while in Doze:</p>
Quddus Chong5f150d52015-05-10 16:07:27 -070078<ul>
79<li>Network access is disabled, unless your app receives a high priority Google Cloud Messaging
80tickle.</li>
81<li><a href="{@docRoot}reference/android/os/PowerManager.WakeLock.html">Wake locks</a> are ignored.</li>
82<li>Alarms scheduled with the {@link android.app.AlarmManager} class are disabled, except for
83alarms that you've set with the {@link android.app.AlarmManager#setAlarmClock setAlarmClock()}
84method and {@code AlarmManager.setAndAllowWhileIdle()}.</li>
85<li>WiFi scans are not performed.</li>
86<li>Syncs and jobs for your sync adapters and {@link android.app.job.JobScheduler} are not
87permitted to run.</li>
88</ul>
89</p>
Quddus Chong79d03e92015-05-26 17:58:51 -070090<p>When the device exits doze, it executes any jobs and syncs that are pending.</p>
Quddus Chong5f150d52015-05-10 16:07:27 -070091<p>You can test this feature by connecting a device running the M Preview to your development
92machine and calling the following commands:
93</p>
94<pre class="no-prettyprint">
95$ adb shell dumpsys battery unplug
96$ adb shell dumpsys deviceidle step
97$ adb shell dumpsys deviceidle -h
98</pre>
Quddus Chong79d03e92015-05-26 17:58:51 -070099<p class="note"><strong>Note</strong>: The upcoming
100<a href="https://developers.google.com/cloud-messaging/" class="external-link">
101Google Cloud Messaging</a> release lets you designate
Quddus Chong5f150d52015-05-10 16:07:27 -0700102high-priority messages. If your app receives high-priority GCM messages, it’s granted
Quddus Chong79d03e92015-05-26 17:58:51 -0700103brief network access even when the device is in doze.
Quddus Chong5f150d52015-05-10 16:07:27 -0700104</p>
105
106<h3 id="behavior-app-standby">App standby</h3>
107<p>With this preview, the system may determine that apps are idle when they are not in active
108use. Your app is considered idle after a period of time, unless the system detects
109any of these signals:</p>
110
111<ul>
Quddus Chong79d03e92015-05-26 17:58:51 -0700112<li>The app is explicitly launched by the user.</li>
Quddus Chong5f150d52015-05-10 16:07:27 -0700113<li>The app has a process currently in the foreground (either as an activity or foreground service,
114or in use by another activity or foreground service).</li>
115<li>The app generates a notification that users see on the lock screen or in the
116notification tray.</li>
117<li>The user explicitly asks for the app to be exempt from optimizations,
118via <strong>Settings</strong>.</li>
119</ul>
120
121<p>If the device is unplugged, apps deemed idle will have their network access disabled
122and their syncs and jobs suspended. When the device is plugged into a power supply, these apps are
123allowed network access and can execute any jobs and syncs that are pending. If the
124device is idle for long periods of time, idle apps are allowed network access around once a day.</p>
125
126<p>You can test this feature by connecting a device running the M Preview to your development
127machine and calling the following commands:
128</p>
129<pre class="no-prettyprint">
Quddus Chong79d03e92015-05-26 17:58:51 -0700130$ adb shell dumpsys battery unplug
Quddus Chong5f150d52015-05-10 16:07:27 -0700131$ adb shell am set-idle &lt;packageName&gt; true
132$ adb shell am set-idle &lt;packageName&gt; false
133$ adb shell am get-idle &lt;packageName&gt;
134</pre>
135
136<p class="note"><strong>Note</strong>: The upcoming
Quddus Chong79d03e92015-05-26 17:58:51 -0700137<a href="https://developers.google.com/cloud-messaging/" class="external-link">
138Google Cloud Messaging</a> (GCM) release lets you
Quddus Chong5f150d52015-05-10 16:07:27 -0700139designate high-priority messages. If your app receives high-priority GCM messages, it’s granted
140brief network access even when the app is idle.
141</p>
142
143<h2 id="behavior-adoptable-storage">Adoptable Storage Devices</h2>
144<p>
145With this preview, users can <em>adopt</em> external storage devices such as SD cards. Adopting an
146external storage device encrypts and formats the device to behave like internal storage. This
147feature allows users to move both apps and private data of those apps between storage devices. When
148moving apps, the system respects the
149<a href="{@docRoot}guide/topics/manifest/manifest-element.html#install">{@code android:installLocation}</a>
150preference in the manifest.</p>
151
152<p>If your app accesses the following APIs or fields, be aware that the file paths they return
153will dynamically change when the app is moved between internal and external storage devices.
154When building file paths, it is strongly recommended that you always call these APIs dynamically.
155Don’t use hardcoded file paths or persist fully-qualified file paths that were built previously.</p>
156
157<ul>
158<li>{@link android.content.Context} methods:
159 <ul>
160 <li>{@link android.content.Context#getFilesDir() getFilesDir()}</li>
161 <li>{@link android.content.Context#getCacheDir() getCacheDir()}</li>
162 <li>{@link android.content.Context#getCodeCacheDir() getCodeCacheDir()}</li>
163 <li>{@link android.content.Context#getDatabasePath(java.lang.String) getDatabasePath()}</li>
164 <li>{@link android.content.Context#getDir(java.lang.String,int) getDir()}</li>
165 <li>{@link android.content.Context#getNoBackupFilesDir() getNoBackupFilesDir()}</li>
166 <li>{@link android.content.Context#getFileStreamPath(java.lang.String) getFileStreamPath()}</li>
167 <li>{@link android.content.Context#getPackageCodePath() getPackageCodePath()}</li>
168 <li>{@link android.content.Context#getPackageResourcePath() getPackageResourcePath()}</li>
169 </ul>
170</li>
171<li>{@link android.content.pm.ApplicationInfo} fields:
172 <ul>
173 <li>{@link android.content.pm.ApplicationInfo#dataDir dataDir}</li>
174 <li>{@link android.content.pm.ApplicationInfo#sourceDir sourceDir}</li>
175 <li>{@link android.content.pm.ApplicationInfo#nativeLibraryDir nativeLibraryDir}</li>
176 <li>{@link android.content.pm.ApplicationInfo#publicSourceDir publicSourceDir}</li>
177 <li>{@link android.content.pm.ApplicationInfo#splitSourceDirs splitSourceDirs}</li>
178 <li>{@link android.content.pm.ApplicationInfo#splitPublicSourceDirs splitPublicSourceDirs}</li>
179 </ul>
180</li>
181</ul>
182
183<p>To debug this feature in the developer preview, you can enable adoption of a USB drive that is
184connected to an Android device through a USB On-The-Go (OTG) cable, by running this command:</p>
185
186<pre class="no-prettyprint">
187$ adb shell sm set-force-adoptable true
188</pre>
189
190<h2 id="behavior-apache-http-client">Apache HTTP Client Removal</h2>
191<p>This preview removes support for the Apache HTTP client. If your app is using this client and
192targets Android 2.3 (API level 9) or higher, use the {@link java.net.HttpURLConnection} class
193instead. This API is more efficient because it reduces network use through transparent compression
194and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you
195must first declare the following compile-time dependency in your {@code build.gradle} file:
196</p>
197<pre>
198android {
199 useLibrary 'org.apache.http.legacy'
200}
201</pre>
202<p>Android is moving away from OpenSSL to the
203<a href="https://boringssl.googlesource.com/boringssl/" class="external-link">BoringSSL</a>
204library. If you’re using the Android NDK in your app, don't link against cryptographic libraries
205that are not a part of the NDK API, such as {@code libcrypto.so} and {@code libssl.so}. These
206libraries are not public APIs, and may change or break without notice across releases and devices.
207In addition, you may expose yourself to security vulnerabilities. Instead, modify your
208native code to call the Java cryptography APIs via JNI or to statically link against a
209cryptography library of your choice.</p>
210
211<h2 id="behavior-audiomanager-Changes">AudioManager Changes</h2>
212<p>Setting the volume directly or muting specific streams via the {@link android.media.AudioManager}
213class is no longer supported. The {@link android.media.AudioManager#setStreamSolo(int,boolean)
214setStreamSolo()} method is deprecated, and you should call the
215{@code AudioManager.requestAudioFocus()} method instead. Similarly, the
216{@link android.media.AudioManager#setStreamMute(int,boolean) setStreamMute()} method is
217deprecated; instead, call the {@code AudioManager.adjustStreamVolume()} method
218and pass in the direction value {@code ADJUST_MUTE} or {@code ADJUST_UNMUTE}.</p>
219
220<h2 id="behavior-test-selection">Text Selection</h2>
221
222<img src="{@docRoot}preview/images/text-selection.gif"
223style="float:right; margin:0 0 20px 30px" width="360" height="640" />
224
225<p>When users select text in your app, you can now display text selection actions such as
226<em>Cut</em>, <em>Copy</em>, and <em>Paste</em> in a
227<a href="http://www.google.com/design/spec/patterns/selection.html#selection-text-selection"
228class="external-link">floating toolbar</a>. The user interaction implementation is similar to that
229for the contextual action bar, as described in
230<a href="{@docRoot}guide/topics/ui/menus.html#CABforViews">
231Enabling the contextual action mode for individual views</a>.</p>
232
233<p>To implement a floating toolbar for text selection, make the following changes in your existing
234apps:</p>
235<ol>
236<li>In your {@link android.view.View} or {@link android.app.Activity} object, change your
237{@link android.view.ActionMode} calls from
238{@code startActionMode(Callback)} to {@code startActionMode(Callback, ActionMode.TYPE_FLOATING)}.</li>
239<li>Take your existing implementation of {@code ActionMode.Callback} and make it extend
240{@code ActionMode.Callback2} instead.</li>
241<li>Override the {@code Callback2.onGetContentRect()} method to provide the coordinates of the
242content {@link android.graphics.Rect} object (such as a text selection rectangle) in the view.</li>
243<li>If the rectangle positioning is no longer valid, and this is the only element to be invalidated,
244call the {@code ActionMode.invalidateContentRect()} method.</li>
245</ol>
246
247<p>If you are using <a href="{@docRoot}tools/support-library/index.html">
248Android Support Library</a> revision 22.2, be aware that floating toolbars are not
249backward-compatible and appcompat takes control over {@link android.view.ActionMode} objects by
250default. This prevents floating toolbars from being displayed. To enable
251{@link android.view.ActionMode} support in an
252{@link android.support.v7.app.AppCompatActivity}, call
253{@code android.support.v7.app.AppCompatActivity.getDelegate()}, then call
254{@code android.support.v7.app.AppCompatDelegate.setHandleNativeActionModesEnabled()} on the returned
255{@link android.support.v7.app.AppCompatDelegate} object and set the input
256parameter to {@code false}. This call returns control of {@link android.view.ActionMode} objects to
257the framework. In devices running the M Preview, that allows the framework to support
258{@link android.support.v7.app.ActionBar} or floating toolbar modes, while on pre-M Preview devices,
259only the {@link android.support.v7.app.ActionBar} modes are supported.</p>
260
261<h2 id="behavior-keystore">Android Keystore Changes</h2>
262<p>With this preview, the
263<a href="{@docRoot}training/articles/keystore.html">Android Keystore provider</a> no longer supports
264DSA. ECDSA is still supported.</p>
265
266<p>Keys which do not require encryption at rest will no longer be deleted when secure lock screen
267is disabled or reset (for example, by the user or a Device Administrator). Keys which require
268encryption at rest will be deleted during these events.</p>
269
Quddus Chong5f150d52015-05-10 16:07:27 -0700270<h2 id="behavior-network">Wi-Fi and Networking Changes</h2>
271
272<p>This preview introduces the following behavior changes to the Wi-Fi and networking APIs.</p>
273<ul>
274<li>Your apps can now change the state of {@link android.net.wifi.WifiConfiguration} objects only
275if you created these objects. You are not permitted to modify or delete
276{@link android.net.wifi.WifiConfiguration} objects created by the user or by other apps.
277</li>
278<li>
279Previously, if an app forced the device to connect to a specific Wi-Fi network by using
280{@link android.net.wifi.WifiManager#enableNetwork(int,boolean) enableNetwork()} with the
281{@code disableAllOthers=true} setting, the device disconnected from other networks such as
282cellular data. In this preview, the device no longer disconnects from such other networks. If
283your app’s {@code targetSdkVersion} is {@code “20”} or lower, it is pinned to the selected
284Wi-Fi network. If your app’s {@code targetSdkVersion} is {@code “21”} or higher, use the
285multinetwork APIs (such as
286{@link android.net.Network#openConnection(java.net.URL) openConnection()},
287{@link android.net.Network#bindSocket(java.net.Socket) bindSocket()}, and the new
288{@code ConnectivityManager.bindProcessToNetwork()} method) to ensure that its network traffic is
289sent on the selected network.</li>
290</ul>
291
292<h2 id="behavior-camera">Camera Service Changes</h2>
293<p>In this preview, the model for accessing shared resources in the camera service has been changed
294from the previous “first come, first serve” access model to an access model where high-priority
295processes are favored. Changes to the service behavior include:</p>
296<ul>
297<li>Access to camera subsystem resources, including opening and configuring a camera device, is
298awarded based on the “priority” of the client application process. Application processes with
299user-visible or foreground activities are generally given a higher-priority, making camera resource
300acquisition and use more dependable.</li>
301<li>Active camera clients for lower priority apps may be “evicted” when a higher priority
302application attempts to use the camera. In the deprecated {@link android.hardware.Camera} API,
303this results in
304{@link android.hardware.Camera.ErrorCallback#onError(int,android.hardware.Camera) onError()} being
305called for the evicted client. In the {@link android.hardware.camera2 Camera2} API, it results in
306{@link android.hardware.camera2.CameraDevice.StateCallback#onDisconnected(android.hardware.camera2.CameraDevice) onDisconnected()}
307being called for the evicted client.</li>
308<li>On devices with appropriate camera hardware, separate application processes are able to
309independently open and use separate camera devices simultaneously. However, multi-process use
310cases, where simultaneous access causes significant degradation of performance or capabilities of
311any of the open camera devices, are now detected and disallowed by the camera service. This change
312may result in “evictions” for lower priority clients even when no other app is directly
313attempting to access the same camera device.
314</li>
315<li>
316Changing the current user causes active camera clients in apps owned by the previous user account
317to be evicted. Access to the camera is limited to user profiles owned by the current device user.
318In practice, this means that a “Guest” account, for example, will not be able to leave running
319processes that use the camera subsystem when the user has switched to a different account.
320</li>
321</ul>
322
323<h2 id="behavior-art-runtime">ART Runtime</h2>
324<p>The ART runtime now properly implements access rules for the
325{@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method. This
326change fixes a problem where Dalvik was checking access rules incorrectly in previous versions.
327If your app uses the
328{@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method and you
329want to override access checks, call the
330{@link java.lang.reflect.Constructor#setAccessible(boolean) setAccessible()} method with the input
331parameter set to {@code true}. If your app uses the
332<a href="{@docRoot}tools/support-library/features.html#v7-appcompat">v7 appcompat library</a> or the
333<a href="{@docRoot}tools/support-library/features.html#v7-recyclerview">v7 recyclerview library</a>,
334you must update your app to use to the latest versions of these libraries. Otherwise, make sure that
335any custom classes referenced from XML are updated so that their class constructors are accessible.</p>
336
337<p>This preview updates the behavior of the dynamic linker. The dynamic linker now understands the
338difference between a library’s {@code soname} and its path
339(<a href="https://code.google.com/p/android/issues/detail?id=6670" class="external-link">
340public bug 6670</a>), and search by {@code soname} is now
341implemented. Apps which previously worked that have bad {@code DT_NEEDED} entries
342(usually absolute paths on the build machine’s file system) may fail when loaded.</p>
343
344<p>The {@code dlopen(3) RTLD_LOCAL} flag is now correctly implemented. Note that
345{@code RTLD_LOCAL} is the default, so calls to {@code dlopen(3)} that didn’t explicitly use
346{@code RTLD_LOCAL} will be affected (unless your app explicitly used {@code RTLD_GLOBAL}). With
347{@code RTLD_LOCAL}, symbols will not be made available to libraries loaded by later calls to
348{@code dlopen(3)} (as opposed to being referenced by {@code DT_NEEDED} entries).</p>
349</p>
350
351<h2 id="behavior-apk-validation">APK Validation</h2>
352<p>The platform now performs stricter validation of APKs. An APK is considered corrupt if a file is
353declared in the manifest but not present in the APK itself. An APK must be re-signed if any of the
354contents are removed.</p>
355
356<h2 id="behavior-afw">Android for Work Changes</h2>
357<p>This preview includes the following behavior changes for Android for Work:</p>
358<ul>
359<li><strong>Work contacts in personal contexts.</strong> The Google Dialer
Quddus Chong79d03e92015-05-26 17:58:51 -0700360Call Log now displays work contacts when the user views past calls.
361Setting {@code DevicePolicyManager.setCrossProfileCallerIdDisabled()} to {@code true} hides the
362work profile contacts in the Google Dialer Call Log. Work contacts can be displayed along with
363personal contacts to devices over Bluetooth only if
364you set {@code DevicePolicyManager.setBluetoothContactSharingDisabled()} to {@code false}. By
365default, it is set to {@code true}.
Quddus Chong5f150d52015-05-10 16:07:27 -0700366</li>
367<li><strong>WiFi configuration removal:</strong> WiFi configurations added by a Profile Owner
368(for example, through calls to the
369{@link android.net.wifi.WifiManager#addNetwork(android.net.wifi.WifiConfiguration)
370addNetwork()} method) are now removed if that work profile is deleted.</li>
371<li><strong>WiFi configuration lockdown:</strong> Any WiFi configuration created by an active Device
372Owner can no longer be modified or deleted by the user. The user can still create and
373modify their own WiFi configurations, so long as the {@link android.os.UserManager} constant
374{@link android.os.UserManager#DISALLOW_CONFIG_WIFI} has not been set for that user.</li>
375<li><strong>Download Work Policy Controller via Google account addition:</strong> When a Google
376account that requires management via a Work Policy Controller (WPC) app is added to a device
377outside of a managed context, the add account flow now prompts the user to install the
378appropriate WPC. This behavior also applies to accounts added via
379<strong>Settings > Accounts</strong> in the initial device setup wizard.</li>
380<li><strong>Changes to specific DevicePolicyManager API behaviors:</strong>
381Calling the {@link android.app.admin.DevicePolicyManager#setCameraDisabled(android.content.ComponentName,boolean) setCameraDisabled()}
382method affects the camera for the calling user only; calling it from the managed profile doesn’t
383affect camera apps running on the primary user. In addition, the
384{@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures(android.content.ComponentName,int) setKeyguardDisabledFeatures()}
385method is now available for Profile Owners, in addition to Device Owners. A Profile Owner can set
386these keyguard restrictions:
387<ul>
388<li>{@link android.app.admin.DevicePolicyManager#KEYGUARD_DISABLE_TRUST_AGENTS} and
389 {@link android.app.admin.DevicePolicyManager#KEYGUARD_DISABLE_FINGERPRINT}, which affect the
390 keyguard settings for the profile’s parent user.</li>
391<li>{@link android.app.admin.DevicePolicyManager#KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}, which
392 only affects notifications generated by applications in the managed profile.</li>
393</ul>
394</li>
395</ul>