1page.title=Behavior Changes 2page.keywords=preview,sdk,compatibility 3meta.tags="preview", "compatibility" 4page.tags="preview", "developer preview" 5page.image=images/cards/card-n-changes_2x.png 6@jd:body 7 8 9<div id="qv-wrapper"> 10<div id="qv"> 11 12<h2>In this document</h2> 13 14<ol> 15 <li><a href="#perf">Performance Improvements</a> 16 <ol> 17 <li><a href="#doze">Doze</a></li> 18 <li><a href="#bg-opt">Background Optimizations</a></li> 19 </ol> 20 </li> 21 <li><a href="#perm">Permissions Changes</a> 22 </li> 23 <li><a href="#sharing-files">Sharing Files Between Apps</a></li> 24 <li><a href="#accessibility">Accessibility Improvements</a> 25 <ol> 26 <li><a href="#screen-zoom">Screen Zoom</a></li> 27 <li><a href="#vision-settings">Vision Settings in Setup Wizard</a></li> 28 </ol> 29 </li> 30 <li><a href="#ndk">NDK Apps Linking to Platform Libraries</a></li> 31 <li><a href="#afw">Android for Work</a></li> 32 <li><a href="#annotations">Annotations Retention</a></li> 33 <li><a href="#other">Other Important Points</a></li> 34</ol> 35 36<h2>API Differences</h2> 37<ol> 38 <li><a href="{@docRoot}sdk/api_diff/n-preview-4-incr/changes.html"> 39 Preview 3 to API 24</a></li> 40 <li><a href="{@docRoot}sdk/api_diff/24/changes.html"> 41 API 23 to API 24</a></li> 42</ol> 43 44<h2>See Also</h2> 45<ol> 46 <li><a href="{@docRoot}preview/api-overview.html"> 47 Android N for Developers</a></li> 48</ol> 49 50</div> 51</div> 52 53 54<p> 55 Along with new features and capabilities, Android N 56 includes a variety of system and API behavior changes. This document 57 highlights some of the key changes that you should understand and account for 58 in your apps. 59</p> 60 61<p> 62 If you have previously published an app for Android, be aware that your app 63 might be affected by these changes in the platform. 64</p> 65 66 67<h2 id="perf">Battery and Memory</h2> 68 69<p> 70Android N includes system behavior changes aimed at improving the battery life 71of devices and reducing RAM usage. These changes can affect your app’s access to 72system resources, along with the way your app interacts with other apps via 73certain implicit intents. 74</p> 75 76<h3 id="doze">Doze</h3> 77 78<p> 79 Introduced in Android 6.0 (API level 23), Doze improves battery life by 80 deferring CPU and network activities when a user leaves a device unplugged, 81 stationary, and with the screen turned off. Android N brings further 82 enhancements to Doze by applying a subset of CPU and network restrictions 83 while the device is unplugged with the screen turned off, but not necessarily 84 stationary, for example, when a handset is traveling in a user’s pocket. 85</p> 86 87 88<img src="{@docRoot}preview/images/doze-diagram-1.png" 89 alt="" height="251px" id="figure1" /> 90<p class="img-caption"> 91 <strong>Figure 1.</strong> Illustration of how Doze applies a first level of 92 system activity restrictions to improve battery life. 93</p> 94 95<p> 96 When a device is on battery power, and the screen has been off for a certain 97 time, the device enters Doze and applies the first subset of restrictions: It 98 shuts off app network access, and defers jobs and syncs. If the device is 99 stationary for a certain time after entering Doze, the system applies the 100 rest of the Doze restrictions to {@link android.os.PowerManager.WakeLock}, 101 {@link android.app.AlarmManager} alarms, GPS, and Wi-Fi scans. Regardless of 102 whether some or all Doze restrictions are being applied, the system wakes the 103 device for brief maintenance windows, during which applications are allowed 104 network access and can execute any deferred jobs/syncs. 105</p> 106 107 108<img src="{@docRoot}preview/images/doze-diagram-2.png" 109 alt="" id="figure2" /> 110<p class="img-caption"> 111 <strong>Figure 2.</strong> Illustration of how Doze applies a second level of 112 system activity restrictions after the device is stationary for a certain time. 113</p> 114 115<p> 116 Note that activating the screen on or plugging in the device exits Doze and 117 removes these processing restrictions. The additional behavior does not 118 affect recommendations and best practices in adapting your app to the prior 119 version of Doze introduced in Android 6.0 (API level 23), as discussed in 120 <a href="{@docRoot}training/monitoring-device-state/doze-standby.html"> 121 Optimizing for Doze and App Standby</a>. You should still 122 follow those recommendations, such as using Google Cloud Messaging (GCM) to 123 send and receive messages, and start planning updates to accomodate the 124 additional Doze behavior. 125</p> 126 127 128<h3 id="bg-opt">Project Svelte: Background Optimizations</h3> 129 130<p> 131 Android N removes three implicit broadcasts in order to help optimize both 132 memory use and power consumption. This change is necessary because implicit 133 broadcasts frequently start apps that have registered to listen for them in 134 the background. Removing these broadcasts can substantially benefit device 135 performance and user experience. 136</p> 137 138<p> 139 Mobile devices experience frequent connectivity changes, such as when moving 140 between Wi-Fi and mobile data. Currently, apps can monitor for changes in 141 connectivity by registering a receiver for the implicit {@link 142 android.net.ConnectivityManager#CONNECTIVITY_ACTION} broadcast in their 143 manifest. Since many apps register to receive this broadcast, a single 144 network switch can cause them all to wake up and process the broadcast at 145 once. 146</p> 147 148<p> 149 Similarly, in previous versions of Android, apps could register to receive implicit {@link 150 android.hardware.Camera#ACTION_NEW_PICTURE} and {@link 151 android.hardware.Camera#ACTION_NEW_VIDEO} broadcasts from other apps, such as 152 Camera. When a user takes a picture with the Camera app, these apps wake up 153 to process the broadcast. 154</p> 155 156<p> 157 To alleviate these issues, Android N applies the following 158 optimizations: 159</p> 160 161<ul> 162 <li>Apps targeting Android N do not receive {@link 163 android.net.ConnectivityManager#CONNECTIVITY_ACTION} broadcasts, even if they 164 have manifest entries to request notification of these events. Apps that are 165 running can still listen for {@code CONNECTIVITY_CHANGE} on their main thread 166 if they request notification with a {@link android.content.BroadcastReceiver}. 167 </li> 168 169 <li>Apps cannot send or receive {@link 170 android.hardware.Camera#ACTION_NEW_PICTURE} or {@link 171 android.hardware.Camera#ACTION_NEW_VIDEO} broadcasts. This optimization 172 affects all apps, not only those targeting Android N. 173 </li> 174</ul> 175 176<p>If your app uses any of these intents, you should remove dependencies 177 on them as soon as possible so that you can target Android N devices properly. 178 The Android framework provides several solutions to mitigate the need for 179 these implicit broadcasts. For example, the {@link 180 android.app.job.JobScheduler} API provides a robust mechanism to schedule 181 network operations when specified conditions, such as connection to an 182 unmetered network, are met. You can even use {@link 183 android.app.job.JobScheduler} to react to changes to content providers. 184</p> 185 186<p> 187 For more information about background optimizations in N and how to adapt your app, 188 see <a href= 189 "{@docRoot}preview/features/background-optimization.html">Background 190 Optimizations</a>. 191</p> 192 193<h2 id="perm">Permissions Changes</h2> 194 195<p> 196 Android N includes changes to permissions that may affect your app. 197</p> 198 199<h3 id="permfilesys">File system permission changes</h3> 200 201<p> 202 In order to improve the security of private files, the private directory of 203 apps targeting Android N or higher has restricted access (<code>0700</code>). 204 This setting prevents leakage of metadata of private files, such as their size 205 or existence. This permission change has multiple side effects: 206</p> 207 208<ul> 209 <li> 210 Private files’ file permissions should no longer be relaxed by the owner, 211 and an attempt to do so using 212 {@link android.content.Context#MODE_WORLD_READABLE} and/or 213 {@link android.content.Context#MODE_WORLD_WRITEABLE}, will trigger a 214 {@link java.lang.SecurityException}. 215 <p class="note"> 216 <strong>Note:</strong> As of yet, this restriction is not fully enforced. 217 Apps may still modify permissions to their private directory using 218 native APIs or the {@link java.io.File File} API. However, we strongly 219 discourage relaxing the permissions to the private directory. 220 </p> 221 </li> 222 <li> 223 Passing <code>file://</code> URIs outside the package domain may leave the 224 receiver with an unaccessible path. Therefore, attempts to pass a 225 <code>file://</code> URI trigger a 226 <code>FileUriExposedException</code>. The recommended way to share the 227 content of a private file is using the {@link 228 android.support.v4.content.FileProvider}. 229 </li> 230 <li> 231 The {@link android.app.DownloadManager} can no longer share privately 232 stored files by filename. Legacy applications may end up with an 233 unaccessible path when accessing {@link 234 android.app.DownloadManager#COLUMN_LOCAL_FILENAME}. Apps targeting 235 Android N or higher trigger a {@link java.lang.SecurityException} when 236 attempting to access 237 {@link android.app.DownloadManager#COLUMN_LOCAL_FILENAME}. 238 Legacy applications that set the download location to a public location by 239 using 240 {@link 241 android.app.DownloadManager.Request#setDestinationInExternalFilesDir 242 DownloadManager.Request.setDestinationInExternalFilesDir()} or 243 {@link 244 android.app.DownloadManager.Request#setDestinationInExternalPublicDir 245 DownloadManager.Request.setDestinationInExternalPublicDir()} 246 can still access the path in 247 {@link android.app.DownloadManager#COLUMN_LOCAL_FILENAME}, however, this 248 method is strongly discouraged. The preferred way of accessing a file 249 exposed by the {@link android.app.DownloadManager} is using 250 {@link android.content.ContentResolver#openFileDescriptor 251 ContentResolver.openFileDescriptor()}. 252 </li> 253</ul> 254 255<h2 id="sharing-files">Sharing Files Between Apps</h2> 256 257<p> 258For apps targeting Android N, the Android framework enforces 259the {@link android.os.StrictMode} API policy that prohibits exposing {@code file://} URIs 260outside your app. If an intent containing a file URI leaves your app, the app fails 261with a {@code FileUriExposedException} exception. 262</p> 263 264<p> 265To share files between applications, you should send a {@code content://} URI 266and grant a temporary access permission on the URI. The easiest way to grant this permission is by 267using the {@link android.support.v4.content.FileProvider} class. For more information 268on permissions and sharing files, 269see <a href="{@docRoot}training/secure-file-sharing/index.html">Sharing Files</a>. 270</p> 271 272<h2 id="accessibility">Accessibility Improvements</h2> 273 274<p> 275 Android N includes changes intended to improve the usability of the 276 platform for users with low or impaired vision. These changes should 277 generally not require code changes in your app, however you should review 278 these feature and test them with your app to assess potential impacts to user 279 experience. 280</p> 281 282 283<h3 id="screen-zoom">Screen Zoom</h3> 284 285<p> 286 Android N enables users to set <strong>Display size</strong>which magnifies 287 or shrinks all elements on the screen, thereby improving device accessibility 288 for users with low vision. Users cannot zoom the screen past a minimum screen 289 width of <a href= 290 "http://developer.android.com/guide/topics/resources/providing-resources.html"> 291 sw320dp</a>, which is the width of a Nexus 4, a common medium-sized phone. 292</p> 293 294<div class="cols"> 295 296<div class="col-6"> 297 <img src="{@docRoot}preview/images/screen-zoom-1.png" alt="" height="XXX" id="figure1" /> 298</div> 299<div class="col-6"> 300 <img src="{@docRoot}preview/images/screen-zoom-2.png" alt="" height="XXX" id="figure1" /> 301</div> 302 303</div> <!-- end cols --> 304<p class="img-caption"> 305 <strong>Figure 3.</strong> The screen on the right shows the effect of 306 increasing the Display size of a device running an Android N system image. 307</p> 308 309 310<p> 311 When the device density changes, the system notifies running apps in the 312 following ways: 313</p> 314 315<ul> 316 <li>If an app targets API level 23 or lower, the system automatically kills 317 all its background processes. This means that if a user switches away from 318 such an app to open the <em>Settings</em> screen and changes the 319 <strong>Display size</strong> setting, the system kills the app in the same 320 manner that it would in a low-memory situation. If the app has any foreground 321 processes, the system notifies those processes of the configuration change as 322 described in <a href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling 323 Runtime Changes</a>, just as if the device's orientation had changed. 324 </li> 325 326 <li>If an app targets Android N, all of its processes 327 (foreground and background) are notified of the configuration change as 328 described in <a href= 329 "{@docRoot}guide/topics/resources/runtime-changes.html">Handling 330 Runtime Changes</a>. 331 </li> 332</ul> 333 334<p> 335 Most apps do not need to make any changes to support this feature, provided 336 the apps follow Android best practices. Specific things to check for: 337</p> 338 339<ul> 340 <li>Test your app on a device with screen width <code><a href= 341 "{@docRoot}guide/topics/resources/providing-resources.html">sw320dp</a></code> 342 and be sure it performs adequately. 343 </li> 344 345 <li>When the device configuration changes, update any density-dependent 346 cached information, such as cached bitmaps or resources loaded from the 347 network. Check for configuration changes when the app resumes from the paused 348 state. 349 <p class="note"> 350 <strong>Note:</strong> If you cache configuration-dependent data, it's a 351 good idea to include relevant metadata such as the appropriate screen 352 size or pixel density for that data. Saving this metadata allows you to 353 decide whether you need to refresh the cached data after a configuration 354 change. 355 </p> 356 </li> 357 358 <li>Avoid specifying dimensions with px units, since they do not scale with 359 screen density. Instead, specify dimensions with <a href= 360 "{@docRoot}guide/practices/screens_support.html">density-independent 361 pixel</a> (<code>dp</code>) units. 362 </li> 363</ul> 364 365<h3 id="vision-settings">Vision Settings in Setup Wizard</h3> 366 367<p> 368 Android N includes Vision Settings on the Welcome screen, where users can 369 set up the following accessibility settings on a new device: 370 <strong>Magnification gesture</strong>, <strong>Font size</strong>, 371 <strong>Display size</strong> and <strong>TalkBack</strong>. This change 372 increases the visibility of bugs related to different screen settings. To 373 assess the impact of this feature, you should test your apps with these 374 settings enabled. You can find the settings under <strong>Settings > 375 Accessibility</strong>. 376</p> 377 378<h2 id="ndk">NDK Apps Linking to Platform Libraries</h2> 379 380<p> 381 Starting in Android N, the system prevents apps from dynamically linking 382 against non-NDK libraries, which may cause your app to crash. This change in 383 behavior aims to create a consistent app experience across platform updates 384 and different devices. Even though your code might not be linking against 385 private libraries, it's possible that a third-party static library in your 386 app could be doing so. Therefore, all developers should check to make sure 387 that their apps do not crash on devices running Android N. If your app uses 388 native code, you should only be using <a href= 389 "{@docRoot}ndk/guides/stable_apis.html">public NDK APIs</a>. 390</p> 391 392<p> 393 There are three ways your app might be trying to access private platform 394 APIs: 395</p> 396 397<ul> 398 <li>Your app directly accesses private platform libraries. You should update 399 your app to include its own copy of those libraries or use the <a href= 400 "{@docRoot}ndk/guides/stable_apis.html">public NDK APIs</a>. 401 </li> 402 403 <li>Your app uses a third-party library that accesses private platform 404 libraries. Even if you are certain your app doesn't access private libraries 405 directly, you should still test your app for this scenario. 406 </li> 407 408 <li>Your app references a library that is not included in its APK. For 409 example, this could happen if you tried to use your own copy of OpenSSL but 410 forgot to bundle it with your app's APK. The app may run normally on versions 411 of Android platform that includes <code>libcrypto.so</code>. However, the app 412 could crash on later versions of Android that do not include this library 413 (such as, Android 6.0 and later). To fix this, ensure that you bundle all 414 your non-NDK libraries with your APK. 415 </li> 416</ul> 417 418<p> 419 Apps should not use native libraries that are not included in the NDK because 420 they may change or be removed between different versions of Android. The 421 switch from OpenSSL to BoringSSL is an example of such a change. Also, 422 because there are no compatibility requirements for platform libraries not 423 included in the NDK, different devices may offer different levels of 424 compatibility. 425</p> 426 427<p> 428 In order to reduce the impact that this restriction may have on currently 429 released apps, a set of libraries that see significant use—such as 430 <code>libandroid_runtime.so</code>, <code>libcutils.so</code>, 431 <code>libcrypto.so</code>, and <code>libssl.so</code>—are temporarily 432 accessible on N for apps targeting API level 23 or lower. If your app loads 433 one of these libraries, logcat generates a warning and a toast appears on the 434 target device to notify you. If you see these warnings, you should update 435 your app to either include its own copy of those libraries or only use the 436 public NDK APIs. Future releases of the Android platform may restrict the use 437 of private libraries altogether and cause your app to crash. 438</p> 439 440<p> 441 All apps generate a runtime error when they call an API that is neither 442 public nor temporarily accessible. The result is that 443 <code>System.loadLibrary</code> and <code>dlopen(3)</code> both return 444 <code>NULL</code>, and may cause your app to crash. You should review your 445 app code to remove use of private platform APIs and thoroughly test your apps 446 using a preview device or emulator. If you are unsure whether your app uses 447 private libraries, you can <a href="#ndk-errors">check logcat</a> to identify 448 the runtime error. 449</p> 450 451<p> 452 The following table describes the behavior you should expect to see from an 453 app depending on its use of private native libraries and its target API 454 level (<code>android:targetSdkVersion</code>). 455</p> 456 457<table id="ndk-table"> 458 <col width="15%"> 459 <col width="15%"> 460 <col width="15%"> 461 <col width="20%"> 462 <col width="20%"> 463 <col width="20%"> 464 <tr> 465 <th scope="col"> 466 Libraries 467 </th> 468 <th scope="col"> 469 Target API level 470 </th> 471 <th scope="col"> 472 Runtime access via dynamic linker 473 </th> 474 <th scope="col"> 475 N Developer Preview behavior 476 </th> 477 <th scope="col"> 478 Final N Release behavior 479 </th> 480 <th scope="col"> 481 Future Android platform behavior 482 </th> 483 </tr> 484 485<tr> 486 <td> 487 NDK Public 488 </td> 489 490 <td> 491 Any 492 </td> 493 494 <td style="background-color:#DCEDC8"> 495 Accessible 496 </td> 497 498 <td style="background-color:#DCEDC8"> 499 Works as expected 500 </td> 501 502 <td style="background-color:#DCEDC8"> 503 Works as expected 504 </td> 505 506 <td style="background-color:#DCEDC8"> 507 Works as expected 508 </td> 509</tr> 510 511<tr> 512 <td> 513 Private (temporarily accessible private libraries) 514 </td> 515 516 <td> 517 23 or lower 518 </td> 519 520 <td style="background-color:#FFF9C4"> 521 Temporarily accessible 522 </td> 523 524 <td style="background-color:#FFF9C4"> 525 Works as expected, but you receive a logcat warning and a message on the 526 target device. 527 </td> 528 529 <td style="background-color:#FFF9C4"> 530 Works as expected, but you receive a logcat warning. 531 </td> 532 533 <td style="background-color:#ffcdd2"> 534 Runtime error 535 </td> 536</tr> 537 538<tr> 539 <td> 540 Private (temporarily accessible private libraries) 541 </td> 542 543 <td> 544 24 or higher 545 </td> 546 547 <td style="background-color:#ffcdd2"> 548 Restricted 549 </td> 550 551 <td style="background-color:#ffcdd2"> 552 Runtime error 553 </td> 554 555 <td style="background-color:#ffcdd2"> 556 Runtime error 557 </td> 558 559 <td style="background-color:#ffcdd2"> 560 Runtime error 561 </td> 562</tr> 563 564<tr> 565 <td> 566 Private (other) 567 </td> 568 569 <td> 570 Any 571 </td> 572 573 <td style="background-color:#ffcdd2"> 574 Restricted 575 </td> 576 577 <td style="background-color:#ffcdd2"> 578 Runtime error 579 </td> 580 581 <td style="background-color:#ffcdd2"> 582 Runtime error 583 </td> 584 585 <td style="background-color:#ffcdd2"> 586 Runtime error 587 </td> 588</tr> 589</table> 590 591<h3 id="ndk-errors"> 592 Check if your app uses private libraries 593</h3> 594 595<p> 596 To help you identify issues loading private libraries, logcat may generate a 597 warning or runtime error. For example, if your app targets API level 23 or 598 lower, and tries to access a private library on a device running Android N, 599 you may see a warning similar to the following: 600</p> 601 602<pre class="no-pretty-print"> 60303-21 17:07:51.502 31234 31234 W linker : library "libandroid_runtime.so" 604("/system/lib/libandroid_runtime.so") needed or dlopened by 605"/data/app/com.popular-app.android-2/lib/arm/libapplib.so" is not accessible 606for the namespace "classloader-namespace" - the access is temporarily granted 607as a workaround for http://b/26394120 608</pre> 609 610<p> 611 These logcat warnings tell you which which library is trying to access a 612 private platform API, but will not cause your app to crash. If the app 613 targets API level 24 or higher, however, logcat generates the following 614 runtime error and your app may crash: 615</p> 616 617<pre class="no-pretty-print"> 618java.lang.UnsatisfiedLinkError: dlopen failed: library "libcutils.so" 619("/system/lib/libcutils.so") needed or dlopened by 620"/system/lib/libnativeloader.so" is not accessible for the namespace 621"classloader-namespace" 622 at java.lang.Runtime.loadLibrary0(Runtime.java:977) 623 at java.lang.System.loadLibrary(System.java:1602) 624</pre> 625 626<p> 627 You may also see these logcat outputs if your app uses third-party libraries 628 that dynamically link to private platform APIs. The readelf tool in the 629 Android NDK allows you to generate a list of all dynamically linked shared 630 libraries of a given <code>.so</code> file by running the following command: 631</p> 632 633<pre class="no-pretty-print"> 634aarch64-linux-android-readelf -dW libMyLibrary.so 635</pre> 636 637<h3 id="ndk-update"> 638 Update your app 639</h3> 640 641<p> 642 Here are some steps you can take to fix these types of errors and make 643 sure your app doesn't crash on future platform updates: 644</p> 645 646<ul> 647 <li> 648 If your app uses private platform libraries, you should update it to include 649 its own copy of those libraries or use the <a href= 650 "{@docRoot}ndk/guides/stable_apis.html">public NDK APIs</a>. 651 </li> 652 653 <li> 654 If your app uses a third-party library that accesses private symbols, contact 655 the library author to update the library. 656 </li> 657 658 <li> 659 Make sure you package all your non-NDK libraries with your APK. 660 </li> 661 662 <li>Use standard JNI functions instead of <code>getJavaVM</code> and 663 <code>getJNIEnv</code> from <code>libandroid_runtime.so</code>: 664 665<pre class="no-pretty-print"> 666AndroidRuntime::getJavaVM -> GetJavaVM from <jni.h> 667AndroidRuntime::getJNIEnv -> JavaVM::GetEnv or 668JavaVM::AttachCurrentThread from <jni.h>. 669</pre> 670 </li> 671 672 <li>Use {@code __system_property_get} instead of the private {@code property_get} 673 symbol from {@code libcutils.so}. To do this, use {@code __system_property_get} 674 with the following include: 675 676<pre> 677#include <sys/system_properties.h> 678</pre> 679 <p class="note"> 680 <strong>Note:</strong> The availability and contents of system properties is 681 not tested through CTS. A better fix would be to avoid using these 682 properties altogether. 683 </p> 684 </li> 685 686 <li>Use a local version of the {@code SSL_ctrl} symbol from {@code 687 libcrypto.so}. For example, you should statically link {@code libcyrpto.a} in 688 your {@code .so} file, or include a dynamically linked version of {@code 689 libcrypto.so} from BoringSSL/OpenSSL and package it in your APK. 690 </li> 691</ul> 692 693<h2 id="afw">Android for Work</h2> 694<p> 695 Android N contains changes for apps that target Android for Work, including 696 changes to certificate installation, password resetting, secondary user 697 management, and access to device identifiers. If you are building apps for 698 Android for Work environments, you should review these changes and modify 699 your app accordingly. 700</p> 701 702<ul> 703 <li>You must install a delegated certificate installer before the DPC can set 704 it. For both profile and device-owner apps targeting the N SDK, you should 705 install the delegated certificate installer before the device policy 706 controller (DPC) calls 707 <code>DevicePolicyManager.setCertInstallerPackage()</code>. If the installer 708 is not already installed, the system throws an 709 <code>IllegalArgumentException</code>. 710 </li> 711 712 <li>Reset password restrictions for device admins now apply to profile 713 owners. Device admins can no longer use 714 {@code DevicePolicyManager.resetPassword()} to clear passwords or change 715 ones that are already set. Device admins can still set a password, but only 716 when the device has no password, PIN, or pattern. 717 </li> 718 719 <li>Device and profile owners can manage accounts even if restrictions are 720 set. Device owners and profile owners can call the Account Management APIs 721 even if <code>DISALLOW_MODIFY_ACCOUNTS</code> user restrictions are in place. 722 </li> 723 724 <li>Device owners can manage secondary users more easily. When a device is 725 running in device owner mode, the <code>DISALLOW_ADD_USER</code> restriction 726 is automatically set. This prevents users from creating unmanaged secondary 727 users. In addition, the <code>CreateUser()</code> and 728 <code>createAndInitializeUser()</code> methods are deprecated; the new 729 <code>DevicePolicyManager.createAndManageUser()</code> method replaces them. 730 </li> 731 732 <li>Device owners can access device identifiers. A Device owner can access the 733 Wi-Fi MAC address of a device, using 734 <code>DevicePolicyManagewr.getWifiMacAddress()</code>. If Wi-Fi has never 735 been enabled on the device, this method returns a value of {@code null}. 736 </li> 737 738 <li>The Work Mode setting controls access to work apps. When work mode is off the 739 system launcher indicates work apps are unavailable by greying them out. Enabling 740 work mode again restores normal behavior.</li> 741 742 <li>When installing a PKCS #12 file containing a client certificate chain and 743 the corresponding private key from Settings UI, the CA certificate in the 744 chain is no longer installed to the trusted credentials storage. This does 745 not affect the result of {@link android.security.KeyChain#getCertificateChain 746 KeyChain.getCertificateChain()} when apps attempt to retrieve the client 747 certificate chain later. If required, the CA certificate should be installed 748 to the trusted credentials storage via Settings UI separately, with a 749 DER-encoded format under a .crt or .cer file extension. 750 </li> 751</ul> 752 753<p> 754 For more information about changes to Android for Work in Android N, see 755 <a href="{@docRoot}preview/features/afw.html">Android for Work Updates</a>. 756</p> 757 758<h2 id="annotations">Annotations Retention</h2> 759 760<p> 761Android N fixes a bug where the visibility of annotations was being ignored. 762This issue enabled the runtime to access annotations that it should not have been 763able to. These annotations included: 764</p> 765 766<ul> 767 <li>{@code VISIBILITY_BUILD}: Intended to be visible only at build time.</li> 768 <li>{@code VISIBILITY_SYSTEM}: Intended to be visible at runtime, but only to the 769 underlying system.</li> 770</ul> 771 772<p> 773If your app has relied on this behavior, please add a retention policy to annotations that must 774be available at runtime. You do so by using {@code @Retention(RetentionPolicy.RUNTIME)}. 775</p> 776 777<h2 id="other">Other Important Points</h2> 778 779<ul> 780<li>When an app is running on Android N, but targets a lower API level, 781and the user changes display size, the app process is killed. The app 782must be able to gracefully handle this scenario. Otherwise, it crashes 783when the user restores it from Recents. 784 785<p> 786You should test your app to ensure 787that this behavior does not occur. 788You can do so by causing an identical crash 789when killing the app manually via DDMS. 790</p> 791 792<p> 793Apps targeting N and above are not automatically killed on density changes; 794however, they may still respond poorly to configuration changes. 795</p> 796</li> 797 798<li> 799Apps on Android N should be able to gracefully handle configuration changes, 800and should not crash on subsequent starts. You can verify app behavior 801by changing font size (<strong>Setting</strong> > 802<strong>Display</strong> > <strong>Font size</strong>), and then restoring 803the app from Recents. 804</li> 805 806<li> 807Due to a bug in previous versions of Android, the system did not flag writing 808to a TCP socket on the main thread as a strict-mode violation. Android N fixes this bug. 809Apps that exhibit this behavior now throw an {@code android.os.NetworkOnMainThreadException}. 810Generally, performing network operations on the main thread is a bad idea because these operations 811usually have a high tail latency that causes ANRs and jank. 812</li> 813 814<li> 815The {@code Debug.startMethodTracing()} family of methods now defaults to 816storing output in your package-specific directory on shared storage, 817instead of at the top level 818of the SD card. This means apps no longer need to request the {@code WRITE_EXTERNAL_STORAGE} permission to use these APIs. 819</li> 820 821<li> 822Many platform APIs have now started checking for large payloads being sent 823across {@link android.os.Binder} transactions, and the 824system now rethrows {@code TransactionTooLargeExceptions} 825as {@code RuntimeExceptions}, instead of silently logging or suppressing them. One 826common example is storing too much data in 827{@link android.app.Activity#onSaveInstanceState Activity.onSaveInstanceState()}, 828which causes {@code ActivityThread.StopInfo} to throw a 829{@code RuntimeException} when your app targets Android N. 830</li> 831 832<li> 833If an app posts {@link java.lang.Runnable} tasks to a {@link android.view.View}, and 834the {@link android.view.View} 835is not attached to a window, the system 836queues the {@link java.lang.Runnable} task with the {@link android.view.View}; 837the {@link java.lang.Runnable} task does not execute until the 838{@link android.view.View} is attached 839to a window. This behavior fixes the following bugs: 840<ul> 841 <li>If an app posted to a {@link android.view.View} from a thread other than the intended 842 window’s UI thread, the {@link java.lang.Runnable} may run on the wrong thread as a result. 843 </li> 844 <li>If the {@link java.lang.Runnable} task was posted from a thread other than 845 a looper thread, the app could expose the {@link java.lang.Runnable} task.</li> 846</ul> 847</li> 848 849<li> 850If an app on Android N with 851{@link android.Manifest.permission#DELETE_PACKAGES DELETE_PACKAGES} 852permission tries to delete a package, but a different app had installed that package, 853the system requires user confirmation. In this scenario, apps should expect 854{@link android.content.pm.PackageInstaller#STATUS_PENDING_USER_ACTION STATUS_PENDING_USER_ACTION} 855as the return status when they invoke 856{@link android.content.pm.PackageInstaller#uninstall PackageInstaller.uninstall()}. 857</li> 858 859 <li>The JCA provider called <em>Crypto</em> is deprecated, because its only 860 algorithm, SHA1PRNG, is cryptographically weak. Apps can no longer use 861 SHA1PRNG to (insecurely) derive keys, because this provider is no longer 862 available. For more information, see the blog 863 post <a href= 864 "http://android-developers.blogspot.com/2016/06/security-crypto-provider-deprecated-in.html" 865 class="external-link">Security "Crypto" provider deprecated in Android 866 N</a>. 867 </li> 868 869</ul> 870 871