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