blob: e4be2a1d2d3b2700e92863cb74e3ae1034945eee [file] [log] [blame]
Joe Fernandeza06ac3a2015-05-15 15:42:17 -07001page.title=Behavior Changes
2page.keywords=preview,sdk,compatibility
3sdk.platform.apiLevel=23
4@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>
13 <li><a href="#behavior-notifications">Notifications</a></li>
14 <li><a href="#behavior-openssl">OpenSSL</a></li>
15 <li><a href="#behavior-project-volta">Project Volta</a>
16 <ol>
17 <li><a href="#behavior-doze">Doze Mode</a></li>
18 <li><a href="#behavior-app-standby">App Standby Mode</a></li>
19 </ol>
20 </li>
21 <li><a href="#behavior-adoptable-storage">Adoptable Storage Devices</a></li>
22 <li><a href="#behavior-apache-http-client">Apache HTTP Client Removal</a></li>
23 <li><a href="#behavior-audiomanager-Changes">AudioManager Changes</a></li>
24 <li><a href="#behavior-test-selection">Text Selection</a></li>
25 <li><a href="#behavior-keystore">Android Keystore Changes</a></li>
26 <li><a href="#behavior-themeable-colorstatelists">Themeable ColorStateLists</a></li>
27 <li><a href="#night-mode">Night Mode</a></li>
28 <li><a href="#behavior-art-runtime">ART Runtime</a></li>
29 <li><a href="#behavior-afw">Android for Work Changes</a></li>
30</ol>
31
32<h2>API Differences</h2>
33<ol>
34<li><a href="">API level 22 to M &raquo;</a> </li>
35</ol>
36
37
38<h2>See Also</h2>
39<ol>
40<li><a href="{@docRoot}preview/api-overview.html">M Developer Preview API Overview</a> </li>
41</ol>
42
43</div>
44</div>
45
46<p>API Level: M</p>
47<p>Along with new features and capabilities, M includes a variety of
48system changes and API behavior changes. This document highlights
49some of the key changes that you should be understand and account for in your apps.</p>
50
51<p>If you have previously published an app for Android, be aware that your app
52 might be affected by these changes in M.</p>
53
54<h2 id="behavior-runtime-permissions">Runtime Permissions</h1>
55<p>This release introduces a new runtime permissions model, where users can now directly manage
56their app permissions at runtime. This model gives users improved visibility and control over
57permissions, while streamlining the installation and auto-update processes for app developers.
58Users can set permissions on or off for all apps running on Android M. However, apps that dont
59target M cannot request permissions at runtime.</p>
60
61<p>On your apps that target M, make sure to check and request for permissions at
62runtime. To determine if your app has been granted a permission, call the
63new {@code Context.checkSelfPermission()} method. To request for a permission, call the new
64{@code Activity.requestPermission()} method.</p>
65
66<p>For more information on supporting the new permissions model in your app, see the
67<a href="{@docRoot}preview/features/runtime-permissions.html">
68Android M Runtime Permissions guide</a>.</p>
69
70<h2 id="behavior-openssl">OpenSSL</h2>
71<p>Android is moving away from OpenSSL to the
72<a href="https://boringssl.googlesource.com/boringssl/" class="external-link">BoringSSL</a>
73library. If youre using the Android NDK in your app, don't link against cryptographic libraries
74that are not a part of the NDK API, such as {@code libcrypto.so} and {@code libssl.so}. These
75libraries are not public APIs, and may change or break without notice across releases and devices.
76In addition, you may expose yourself to security vulnerabilities. Instead, modify your
77native code to call the Java cryptography APIs via JNI or to statically link against a
78cryptography library of your choice.</p>
79
80<h2 id="behavior-project-volta">Project Volta</h2>
81<p>This release introduces new power-saving optimizations for idle devices and apps.</p>
82
83<h3 id="behavior-doze">Doze mode</h3>
84<p>If a device is unplugged and not used for up to an hour, it goes into <em>doze</em> mode where
85it attempts to keep the system in a sleep state. In this mode, devices may briefly resume normal
86operations for up to 5 minutes every few hours so that app syncing can occur and the system can
87perform any pending operations.</p>
88
89<p>The following restrictions apply to your apps while in device doze mode:</p>
90<ul>
91<li>Network access is disabled</li>
92<li>Alarms scheduled with the {@link android.app.AlarmManager} class are disabled, except for
93alarms that you've set with the
94{@link android.app.AlarmManager#setAlarmClock(android.app.AlarmManager.AlarmClockInfo,android.app.PendingIntent) setAlarmClock()}
95method</li>
96<li>WiFi scans are not performed</li>
97<li>Syncs and jobs for your sync adapters and {@link android.app.job.JobScheduler} are not
98permitted to run</li>
99</ul>
100</p>
101<p>When the system comes out of doze mode, it executes jobs and syncs that are pending.</p>
102
103<h3 id="behavior-app-standby">App standby mode</h3>
104<p>In M, the system may determine that apps are idle when they are not in active use by the user.
105Your app goes into <em>app standby</em> mode after two days unless the system detects any of these
106signals:</p>
107
108<ul>
109<li>The app has a process currently in the foreground (either as an activity or foreground service,
110or in use by another activity or foreground service)</li>
111<li>The app generates a notification that the user can see</li>
112<li>The user explicitly asks for the app to remain running</li>
113</ul>
114
115<p>If the system is running on battery power, apps that are in standby mode will have their
116network access disabled and their syncs and jobs suspended. When the system is plugged into a power
117supply, it brings an app out of standby mode and executes any jobs and syncs that are pending.</p>
118
119<p>Apps that use <a href="{@docRoot}google/gcm/index.html">Google Cloud Messaging</a> will
120continue to receive messages even if they are idle. When the system is plugged into a power
121supply, apps resume normal operations and can run any pending syncs and jobs.</p>
122
123<p>You can test this feature by connecting a device running M to your development machine and
124calling the following commands:
125</p>
126<pre>
127$ adb shell am broadcast -a android.os.action.DISCHARGING
128$ adb shell am set-idle &lt;packageName&gt; true
129$ adb shell am set-idle &lt;packageName&gt; false
130$ adb shell am get-idle &lt;packageName&gt;
131</pre>
132
133<h2 id="behavior-adoptable-storage">Adoptable Storage Devices</h2>
134<p>
135In M, users can adopt external storage devices such as SD cards. Adopting an external storage
136device encrypts and formats the device to behave like internal storage. This feature allows users
137to move both apps and private data of those apps between storage devices. When moving apps, the
138system respects the <a href="{@docRoot}guide/topics/manifest/manifest-element.html#install">
139{@code android:installLocation}</a> preference in the manifest.</p>
140
141<p>If your app accesses the following APIs or fields, be aware that the file paths they return
142will dynamically change when the app is moved between internal and external storage devices.
143When building file paths, it is strongly recommended that you always call these APIs dynamically.
144Dont use hardcoded file paths or persist fully-qualified file paths that were built previously.</p>
145
146<ul>
147<li>{@link android.content.Context} methods:
148 <ul>
149 <li>{@link android.content.Context#getFilesDir() getFilesDir()}</li>
150 <li>{@link android.content.Context#getCacheDir() getCacheDir()}</li>
151 <li>{@link android.content.Context#getCodeCacheDir() getCodeCacheDir()}</li>
152 <li>{@link android.content.Context#getDatabasePath(java.lang.String) getDatabasePath()}</li>
153 <li>{@link android.content.Context#getDir(java.lang.String,int) getDir()}</li>
154 <li>{@link android.content.Context#getNoBackupFilesDir() getNoBackupFilesDir()}</li>
155 <li>{@link android.content.Context#getFileStreamPath(java.lang.String) getFileStreamPath()}</li>
156 <li>{@link android.content.Context#getPackageCodePath() getPackageCodePath()}</li>
157 <li>{@link android.content.Context#getPackageResourcePath() getPackageResourcePath()}</li>
158 </ul>
159</li>
160<li>{@link android.content.pm.ApplicationInfo} fields:
161 <ul>
162 <li>{@link android.content.pm.ApplicationInfo#dataDir dataDir}</li>
163 <li>{@link android.content.pm.ApplicationInfo#sourceDir sourceDir}</li>
164 <li>{@link android.content.pm.ApplicationInfo#nativeLibraryDir nativeLibraryDir}</li>
165 <li>{@link android.content.pm.ApplicationInfo#publicSourceDir publicSourceDir}</li>
166 <li>{@link android.content.pm.ApplicationInfo#splitSourceDirs splitSourceDirs}</li>
167 <li>{@link android.content.pm.ApplicationInfo#splitPublicSourceDirs splitPublicSourceDirs}</li>
168 </ul>
169</li>
170</ul>
171
172<p>To debug this feature in the developer preview, you can enable adoption of a USB drive that is
173connected to an Android device through a USB On-The-Go (OTG) cable, by running these
174commands:</p>
175
176<pre>
177$ adb root
178$ sleep 2
179$ adb shell setprop persist.fw.force_adoptable 1
180$ adb reboot
181</pre>
182
183<h2 id="behavior-apache-http-client">Apache HTTP Client Removal</h2>
184<p>This release removes support for the Apache HTTP client. If your app is using this client and
185targets Android 2.3 (API level 9) or higher, use the {@link java.net.HttpURLConnection} class
186instead. This API is more efficient because it reduces network use through transparent compression
187and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you
188must first declare the following compile-time dependency in your {@code build.gradle} file:
189</p>
190<pre>
191android {
192 compileSdkVersion M
193 useLibrary 'org.apache.http.legacy'
194}
195</pre>
196
197<h2 id="behavior-audiomanager-Changes">AudioManager Changes</h2>
198<p>Setting the volume directly or muting specific streams via the {@link android.media.AudioManager}
199class is no longer supported. The {@link android.media.AudioManager#setStreamSolo(int,boolean)
200setStreamSolo()} method is deprecated, and you should call the
201{@code AudioManager.requestAudioFocus()} method instead. Similarly, the
202{@link android.media.AudioManager#setStreamMute(int,boolean) setStreamMute()} method is
203deprecated; instead, call the {@code AudioManager.adjustStreamVolume()} method
204and pass in the direction value {@code ADJUST_MUTE} or {@code ADJUST_UNMUTE}.</p>
205
206<h2 id="behavior-test-selection">Text Selection</h2>
207
208<img src="{@docRoot}preview/images/text-selection.gif"
209style="float:right; margin:0 0 20px 30px" width="270" height="480" />
210
211<p>When users selects text in your app, you can now display text selection actions such as
212<em>Cut</em>, <em>Copy</em>, and <em>Paste</em> in a
213<a href="http://www.google.com/design/spec/patterns/selection.html#selection-text-selection"
214class="external-link">floating toolbar</a>. The user interaction implementation is similar to that
215for the contextual action bar, as described in
216<a href="{@docRoot}guide/topics/ui/menus.html#CABforViews">
217Enabling the contextual action mode for individual views</a>.</p>
218
219<p>To implement a floating toolbar for text selection, make the following changes in your existing
220apps:</p>
221<ol>
222<li>In your {@link android.view.View} or {@link android.app.Activity} object, change your
223{@link android.view.ActionMode} calls from
224{@code startActionMode(Callback)} to {@code startActionMode(Callback, ActionMode.TYPE_FLOATING)}.</li>
225<li>Take your existing implementation of ActionMode.Callback and make it extend
226{@code ActionMode.Callback2} instead.</li>
227<li>Override the {@code Callback2.onGetContentRect()} method to provide the coordinates of the
228content {@link android.graphics.Rect} object (such as a text selection rectangle) in the view.</li>
229<li>If the rectangle positioning is no longer valid, and this is the only element to be invalidated,
230call the {@code ActionMode.invalidateContentRect()} method.</li>
231</ol>
232
233<p>If you are using <a href="{@docRoot}tools/support-library/index.html">
234Android Support Library</a> revision 22.2, be aware that floating toolbars are not
235backward-compatible and appcompat takes control over {@link android.view.ActionMode} objects by
236default. This prevents floating toolbars from being displayed in M. To enable
237{@link android.view.ActionMode} support in an
238{@link android.support.v7.app.AppCompatActivity}, call
239{@code android.support.v7.app.AppCompatActivity.getDelegate()}, then call
240{@code android.support.v7.app.AppCompatDelegate.setHandleNativeActionModesEnabled()} on the returned
241{@link android.support.v7.app.AppCompatDelegate} object and set the input
242parameter to {@code false}. This call returns control of {@link android.view.ActionMode} objects to
243the framework. In devices running M, that allows the framework to support
244{@link android.support.v7.app.ActionBar} or floating toolbar modes, while on pre-M devices, only the
245{@link android.support.v7.app.ActionBar} modes are supported.</p>
246
247<h2 id="behavior-keystore">Android Keystore Changes</h2>
248<p>Starting this release, the
249<a href="{@docRoot}training/articles/keystore.html">Android Keystore provider</a> no longer supports
250DSA. ECDSA is still supported.</p>
251
252<p>Keys which do not require encryption at rest will no longer be deleted when secure lock screen
253is disabled or reset (for example, by the user or a Device Administrator). Keys which require
254encryption at rest will be deleted during these events.</p>
255
256<h2 id="behavior-themeable-colorstatelists">Themeable ColorStateLists</h2>
257<p>Theme attributes are now supported in
258{@link android.content.res.ColorStateList} for devices running M. The
259{@link android.content.res.Resources#getColorStateList(int) getColorStateList()} and
260{@link android.content.res.Resources#getColor(int) getColor()} methods have been deprecated. If
261you are calling these APIs, call the new {@code Context.getColorStateList()} or
262{@code Context.getColor()} methods instead. These methods are also available in the
263v4 appcompat library via {@link android.support.v4.content.ContextCompat}.</p>
264
265<h2 id="night-mode">Night Mode (User-configurable Dark Theme)</h2>
266<p>
267Support for the {@code -night} resource qualifier has been updated in M. Previously, night mode was
268only available when a device was docked and in car mode. Starting in M, night mode is available on
269all devices and is user-configurable via <em>Settings > Display > Theme</em>. You can adjust this
270setting globally using {@link android.app.UiModeManager#setNightMode(int) setNightMode()}. The
271Dark theme corresponds to {@link android.app.UiModeManager#MODE_NIGHT_YES}. When the device is in
272night mode, the resource framework will prefer resources that have the -night qualifier. To
273take advantage of user-configurable Dark mode in your app, extend from the
274{@code Theme.Material.DayNight} set of themes rather than {@code Theme.Material} or
275{@code Theme.Material.Light}.
276</p>
277
278<h2 id="behavior-art-runtime">ART Runtime</h2>
279<p>The ART runtime now properly implements access rules for the
280{@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method. This
281change fixes a problem where Dalvik was checking access rules incorrectly in previous versions.
282If your app uses the
283{@link java.lang.reflect.Constructor#newInstance(java.lang.Object...) newInstance()} method and you
284want to override access checks, call the
285{@link java.lang.reflect.Constructor#setAccessible(boolean) setAccessible()} method with the input
286parameter set to {@code true}. If your app uses the
287<a href="{@docRoot}tools/support-library/features.html#v7">v7 appcompat library</a> or the
288<a href="{@docRoot}tools/support-library/features.html#v7-recyclerview">v7 recyclerview library</a>,
289you must update your app to use to the latest versions of these libraries. Otherwise, make sure that
290any custom classes referenced from XML are updated so that their class constructors are accessible.</p>
291
292<p>The M release updates the behavior of the dynamic linker. The dynamic linker now understands the
293difference between a librarys {@code soname} and its path
294(<a href="https://code.google.com/p/android/issues/detail?id=6670" class="external-link">
295public bug 6670</a>), and search by {@code soname} is now
296implemented. Apps which previously worked that have bad {@code DT_NEEDED} entries
297(usually absolute paths on the build machines file system) may fail when loaded on M.</p>
298
299<p>The {@code dlopen(3) RTLD_LOCAL} flag is now correctly implemented in M. Note that
300{@code RTLD_LOCAL} is the default, so calls to {@code dlopen(3)} that didnt explicitly use
301{@code RTLD_LOCAL} will be affected (unless your app explicitly used {@code RTLD_GLOBAL}). With
302{@code RTLD_LOCAL}, symbols will not be made available to libraries loaded by later calls to
303{@code dlopen(3)} (as opposed to being referenced by {@code DT_NEEDED} entries).</p>
304</p>
305
306<h2 id="behavior-afw">Android for Work Changes</h2>
307<p>This release includes the following behavior changes for Android for Work:</p>
308<ul>
309<li><strong>Work contacts in personal contexts.</strong> Google Messenger and the Google Dialer
310Call Log now display work contacts when the user views past messages or calls. Furthermore, both
311work and personal contacts are now available to devices over Bluetooth, but you can hide work
312profile contacts through a device policy by calling the new
313{@code DevicePolicyManager.setBluetoothContactSharingDisabled()} method. Initiating a call or
314creating a new message will only show personal contacts, as consistent with the experience in
315Android 5.0.
316</li>
317<li><strong>WiFi configuration removal:</strong> WiFi configurations added by a Profile Owner
318(for example, through calls to the
319{@link android.net.wifi.WifiManager#addNetwork(android.net.wifi.WifiConfiguration)
320addNetwork()} method) are now removed if that work profile is deleted.</li>
321<li><strong>WiFi configuration lockdown:</strong> Any WiFi configuration created by an active Device
322Owner can no longer be modified or deleted by the user. The user can still create and
323modify their own WiFi configurations, so long as the {@link android.os.UserManager} constant
324{@link android.os.UserManager#DISALLOW_CONFIG_WIFI} has not been set for that user.</li>
325<li><strong>VPN in Settings:</strong> VPN apps are now visible in <em>Settings > More > VPN</em>.
326Additionally, the notifications that accompany VPN usage are now specific to whether that VPN is
327configured for a managed profile or the entire device.</li>
328<li><strong>Work status notification:</strong> A status bar briefcase icon now appears whenever
329an app from the managed profile has an activity in the foreground. Furthermore, if the device is
330unlocked directly to the activity of an app in the managed profile, a toast is displayed notifying
331the user that they are within the work profile.
332</li>
333<li><strong>Download Work Policy Controller via Google account addition:</strong> When a Google
334account that requires management via a Work Policy Controller (WPC) app is added to a device
335outside of a managed context, the add account flow now prompts the user to install the
336appropriate WPC. This behavior also applies to accounts added via
337<em>Settings > Accounts</em> in the initial device setup wizard.</li>
338</ul>