Home | History | Annotate | Download | only in nougat
      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 Android 7.0 (API level
    186   24) and how to adapt your app, 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 &gt;
    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 Android 7.0 (API level 24) for apps targeting API level 23 or
    431   lower. If your app loads one of these libraries, logcat generates a warning
    432   and a toast appears on the target device to notify you. If you see these
    433   warnings, you should update your app to either include its own copy of those
    434   libraries or only use the public NDK APIs. Future releases of the Android
    435   platform may restrict the use of private libraries altogether and cause your
    436   app to crash.
    437 </p>
    438 
    439 <p>
    440   All apps generate a runtime error when they call an API that is neither
    441   public nor temporarily accessible. The result is that
    442   <code>System.loadLibrary</code> and <code>dlopen(3)</code> both return
    443   <code>NULL</code>, and may cause your app to crash. You should review your
    444   app code to remove use of private platform APIs and thoroughly test your apps
    445   using a device or emulator running Android 7.0 (API level 24). If you are
    446   unsure whether your app uses private libraries, you can <a href=
    447   "#ndk-errors">check logcat</a> to identify the runtime error.
    448 </p>
    449 
    450 <p>
    451   The following table describes the behavior you should expect to see from an
    452   app depending on its use of private native libraries and its target API
    453   level (<code>android:targetSdkVersion</code>).
    454 </p>
    455 
    456 <table id="ndk-table">
    457   <col width="15%">
    458   <tr>
    459     <th scope="col">
    460       Libraries
    461     </th>
    462     <th scope="col">
    463       Target API level
    464     </th>
    465     <th scope="col">
    466       Runtime access via dynamic linker
    467     </th>
    468     <th scope="col">
    469       Android 7.0 (API level 24) behavior
    470     </th>
    471     <th scope="col">
    472       Future Android platform behavior
    473     </th>
    474   </tr>
    475 
    476 <tr>
    477   <td>
    478     NDK Public
    479   </td>
    480 
    481   <td>
    482     Any
    483   </td>
    484 
    485   <td style="background-color:#DCEDC8">
    486     Accessible
    487   </td>
    488 
    489   <td style="background-color:#DCEDC8">
    490     Works as expected
    491   </td>
    492 
    493   <td style="background-color:#DCEDC8">
    494     Works as expected
    495   </td>
    496 </tr>
    497 
    498 <tr>
    499   <td>
    500     Private (temporarily accessible private libraries)
    501   </td>
    502 
    503   <td>
    504     23 or lower
    505   </td>
    506 
    507   <td style="background-color:#FFF9C4">
    508     Temporarily accessible
    509   </td>
    510 
    511   <td style="background-color:#FFF9C4">
    512     Works as expected, but you receive a logcat warning.
    513   </td>
    514 
    515   <td style="background-color:#ffcdd2">
    516     Runtime error
    517   </td>
    518 </tr>
    519 
    520 <tr>
    521   <td>
    522     Private (temporarily accessible private libraries)
    523   </td>
    524 
    525   <td>
    526     24 or higher
    527   </td>
    528 
    529   <td style="background-color:#ffcdd2">
    530     Restricted
    531   </td>
    532 
    533   <td style="background-color:#ffcdd2">
    534     Runtime error
    535   </td>
    536 
    537   <td style="background-color:#ffcdd2">
    538     Runtime error
    539   </td>
    540 </tr>
    541 
    542 <tr>
    543   <td>
    544     Private (other)
    545   </td>
    546 
    547   <td>
    548     Any
    549   </td>
    550 
    551   <td style="background-color:#ffcdd2">
    552     Restricted
    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 </table>
    564 
    565 <h3 id="ndk-errors">
    566   Check if your app uses private libraries
    567 </h3>
    568 
    569 <p>
    570   To help you identify issues loading private libraries, logcat may generate a
    571   warning or runtime error. For example, if your app targets API level 23 or
    572   lower, and tries to access a private library on a device running Android 7.0,
    573   you may see a warning similar to the following:
    574 </p>
    575 
    576 <pre class="no-pretty-print">
    577 03-21 17:07:51.502 31234 31234 W linker  : library "libandroid_runtime.so"
    578 ("/system/lib/libandroid_runtime.so") needed or dlopened by
    579 "/data/app/com.popular-app.android-2/lib/arm/libapplib.so" is not accessible
    580 for the namespace "classloader-namespace" - the access is temporarily granted
    581 as a workaround for http://b/26394120
    582 </pre>
    583 
    584 <p>
    585   These logcat warnings tell you which which library is trying to access a
    586   private platform API, but will not cause your app to crash. If the app
    587   targets API level 24 or higher, however, logcat generates the following
    588   runtime error and your app may crash:
    589 </p>
    590 
    591 <pre class="no-pretty-print">
    592 java.lang.UnsatisfiedLinkError: dlopen failed: library "libcutils.so"
    593 ("/system/lib/libcutils.so") needed or dlopened by
    594 "/system/lib/libnativeloader.so" is not accessible for the namespace
    595 "classloader-namespace"
    596   at java.lang.Runtime.loadLibrary0(Runtime.java:977)
    597   at java.lang.System.loadLibrary(System.java:1602)
    598 </pre>
    599 
    600 <p>
    601   You may also see these logcat outputs if your app uses third-party libraries
    602   that dynamically link to private platform APIs. The readelf tool in the
    603   Android 7.0DK allows you to generate a list of all dynamically linked shared
    604   libraries of a given <code>.so</code> file by running the following command:
    605 </p>
    606 
    607 <pre class="no-pretty-print">
    608 aarch64-linux-android-readelf -dW libMyLibrary.so
    609 </pre>
    610 
    611 <h3 id="ndk-update">
    612   Update your app
    613 </h3>
    614 
    615 <p>
    616   Here are some steps you can take to fix these types of errors and make
    617   sure your app doesn't crash on future platform updates:
    618 </p>
    619 
    620 <ul>
    621   <li>
    622     If your app uses private platform libraries, you should update it to include
    623     its own copy of those libraries or use the <a href=
    624     "{@docRoot}ndk/guides/stable_apis.html">public NDK APIs</a>.
    625   </li>
    626 
    627   <li>
    628     If your app uses a third-party library that accesses private symbols, contact
    629     the library author to update the library.
    630   </li>
    631 
    632   <li>
    633     Make sure you package all your non-NDK libraries with your APK.
    634   </li>
    635 
    636   <li>Use standard JNI functions instead of <code>getJavaVM</code> and
    637   <code>getJNIEnv</code> from <code>libandroid_runtime.so</code>:
    638 
    639 <pre class="no-pretty-print">
    640 AndroidRuntime::getJavaVM -&gt; GetJavaVM from &lt;jni.h&gt;
    641 AndroidRuntime::getJNIEnv -&gt; JavaVM::GetEnv or
    642 JavaVM::AttachCurrentThread from &lt;jni.h&gt;.
    643 </pre>
    644   </li>
    645 
    646   <li>Use {@code __system_property_get} instead of the private {@code property_get}
    647   symbol from {@code libcutils.so}. To do this, use {@code __system_property_get}
    648   with the following include:
    649 
    650 <pre>
    651 #include &lt;sys/system_properties.h&gt;
    652 </pre>
    653     <p class="note">
    654       <strong>Note:</strong> The availability and contents of system properties is
    655       not tested through CTS. A better fix would be to avoid using these
    656       properties altogether.
    657     </p>
    658   </li>
    659 
    660   <li>Use a local version of the {@code SSL_ctrl} symbol from {@code
    661   libcrypto.so}. For example, you should statically link {@code libcyrpto.a} in
    662   your {@code .so} file, or include a dynamically linked version of {@code
    663   libcrypto.so} from BoringSSL/OpenSSL and package it in your APK.
    664   </li>
    665 </ul>
    666 
    667 <h2 id="afw">Android for Work</h2>
    668 <p>
    669   Android 7.0 contains changes for apps that target Android for Work, including
    670   changes to certificate installation, password resetting, secondary user
    671   management, and access to device identifiers. If you are building apps for
    672   Android for Work environments, you should review these changes and modify
    673   your app accordingly.
    674 </p>
    675 
    676 <ul>
    677   <li>You must install a delegated certificate installer before the DPC can set
    678   it. For both profile and device-owner apps targeting Android 7.0 (API level 24),
    679   you should install the delegated certificate installer before the device policy
    680   controller (DPC) calls
    681   <code>DevicePolicyManager.setCertInstallerPackage()</code>. If the installer
    682   is not already installed, the system throws an
    683   <code>IllegalArgumentException</code>.
    684   </li>
    685 
    686   <li>Reset password restrictions for device admins now apply to profile
    687   owners. Device admins can no longer use
    688   {@code DevicePolicyManager.resetPassword()} to clear passwords or change
    689   ones that are already set. Device admins can still set a password, but only
    690   when the device has no password, PIN, or pattern.
    691   </li>
    692 
    693   <li>Device and profile owners can manage accounts even if restrictions are
    694   set. Device owners and profile owners can call the Account Management APIs
    695   even if <code>DISALLOW_MODIFY_ACCOUNTS</code> user restrictions are in place.
    696   </li>
    697 
    698   <li>Device owners can manage secondary users more easily. When a device is
    699   running in device owner mode, the <code>DISALLOW_ADD_USER</code> restriction
    700   is automatically set. This prevents users from creating unmanaged secondary
    701   users. In addition, the <code>CreateUser()</code> and
    702   <code>createAndInitializeUser()</code> methods are deprecated; the new
    703   <code>DevicePolicyManager.createAndManageUser()</code> method replaces them.
    704   </li>
    705 
    706   <li>Device owners can access device identifiers. A Device owner can access the
    707   Wi-Fi MAC address of a device, using
    708   <code>DevicePolicyManagewr.getWifiMacAddress()</code>. If Wi-Fi has never
    709   been enabled on the device, this method returns a value of {@code null}.
    710   </li>
    711 
    712   <li>The Work Mode setting controls access to work apps. When work mode is off the
    713   system launcher indicates work apps are unavailable by greying them out. Enabling
    714   work mode again restores normal behavior.</li>
    715 
    716   <li>When installing a PKCS #12 file containing a client certificate chain and
    717   the corresponding private key from Settings UI, the CA certificate in the
    718   chain is no longer installed to the trusted credentials storage. This does
    719   not affect the result of {@link android.security.KeyChain#getCertificateChain
    720   KeyChain.getCertificateChain()} when apps attempt to retrieve the client
    721   certificate chain later. If required, the CA certificate should be installed
    722   to the trusted credentials storage via Settings UI separately, with a
    723   DER-encoded format under a .crt or .cer file extension.
    724   </li>
    725 
    726   <li>Starting in Android 7.0, fingerprint enrollment and storage are managed
    727   per user. If a profile owners Device Policy Client (DPC) targets API level
    728   23 (or lower) on a device running Android 7.0 (API level 24), the user is
    729   still able to set fingerprint on the device, but work applications cannot
    730   access device fingerprint. When the DPC targets API level 24 and above, the user can set
    731   fingerprint specifically for work profile by going to <strong>Settings &gt;
    732   Security &gt; Work profile security</strong>.
    733   </li>
    734 
    735   <li>A new encryption status <code>ENCRYPTION_STATUS_ACTIVE_PER_USER</code> is
    736   returned by <code>DevicePolicyManager.getStorageEncryptionStatus()</code>, to
    737   indicate that encryption is active and the encryption key is tied to the
    738   user. The new status is only returned if DPC targets API Level 24 and above.
    739   For apps targeting earlier API levels, <code>ENCRYPTION_STATUS_ACTIVE</code>
    740   is returned, even if the encryption key is specific to the user or profile.
    741   </li>
    742 
    743   <li>In Android 7.0, several methods that would ordinarily affect the entire
    744   device behave differently if the device has a work profile installed with a
    745   separate work challenge. Rather than affecting the entire device, these
    746   methods apply only to the work profile. (The complete list of such methods is
    747   in the {@link android.app.admin.DevicePolicyManager#getParentProfileInstance
    748   DevicePolicyManager.getParentProfileInstance()} documentation.) For example,
    749   {@link android.app.admin.DevicePolicyManager#lockNow
    750   DevicePolicyManager.lockNow()} locks just the work profile, instead of
    751   locking the entire device. For each of these methods, you can get the old
    752   behavior by calling the method on the parent instance of the
    753   {@link android.app.admin.DevicePolicyManager}; you can get this parent by
    754   calling {@link android.app.admin.DevicePolicyManager#getParentProfileInstance
    755   DevicePolicyManager.getParentProfileInstance()}. So for example, if you call
    756   the parent instance's {@link android.app.admin.DevicePolicyManager#lockNow}
    757   method, the entire device is locked.
    758   </li>
    759 
    760 </ul>
    761 
    762 <p>
    763   For more information about changes to Android for Work in Android 7.0, see
    764   <a href="{@docRoot}preview/features/afw.html">Android for Work Updates</a>.
    765 </p>
    766 
    767 <h2 id="annotations">Annotations Retention</h2>
    768 
    769 <p>
    770 Android 7.0 fixes a bug where the visibility of annotations was being ignored.
    771 This issue enabled the runtime to access annotations that it should not have been
    772 able to. These annotations included:
    773 </p>
    774 
    775 <ul>
    776    <li>{@code VISIBILITY_BUILD}: Intended to be visible only at build time.</li>
    777    <li>{@code VISIBILITY_SYSTEM}: Intended to be visible at runtime, but only to the
    778    underlying system.</li>
    779 </ul>
    780 
    781 <p>
    782 If your app has relied on this behavior, please add a retention policy to annotations that must
    783 be available at runtime. You do so by using {@code @Retention(RetentionPolicy.RUNTIME)}.
    784 </p>
    785 
    786 <h2 id="other">Other Important Points</h2>
    787 
    788 <ul>
    789 <li>When an app is running on Android 7.0, but targets a lower API level,
    790 and the user changes display size, the app process is killed. The app
    791 must be able to gracefully handle this scenario. Otherwise, it crashes
    792 when the user restores it from Recents.
    793 
    794 <p>
    795 You should test your app to ensure
    796 that this behavior does not occur.
    797 You can do so by causing an identical crash
    798 when killing the app manually via DDMS.
    799 </p>
    800 
    801 <p>
    802   Apps targeting Android 7.0 (API level 24) and above are not automatically
    803   killed on density changes; however, they may still respond poorly to
    804   configuration changes.
    805 </p>
    806 </li>
    807 
    808 <li>
    809 Apps on Android 7.0 should be able to gracefully handle configuration changes,
    810 and should not crash on subsequent starts. You can verify app behavior
    811 by changing font size (<strong>Setting</strong> >
    812 <strong>Display</strong> > <strong>Font size</strong>), and then restoring
    813 the app from Recents.
    814 </li>
    815 
    816 <li>
    817 Due to a bug in previous versions of Android, the system did not flag writing
    818 to a TCP socket on the main thread as a strict-mode violation. Android 7.0 fixes this bug.
    819 Apps that exhibit this behavior now throw an {@code android.os.NetworkOnMainThreadException}.
    820 Generally, performing network operations on the main thread is a bad idea because these operations
    821 usually have a high tail latency that causes ANRs and jank.
    822 </li>
    823 
    824 <li>
    825 The {@code Debug.startMethodTracing()} family of methods now defaults to
    826 storing output in your package-specific directory on shared storage,
    827 instead of at the top level
    828 of the SD card.  This means apps no longer need to request the {@code WRITE_EXTERNAL_STORAGE} permission to use these APIs.
    829 </li>
    830 
    831 <li>
    832 Many platform APIs have now started checking for large payloads being sent
    833 across {@link android.os.Binder} transactions, and the
    834 system now rethrows {@code TransactionTooLargeExceptions}
    835 as {@code RuntimeExceptions}, instead of silently logging or suppressing them.  One
    836 common example is storing too much data in
    837 {@link android.app.Activity#onSaveInstanceState Activity.onSaveInstanceState()},
    838 which causes {@code ActivityThread.StopInfo} to throw a
    839 {@code RuntimeException} when your app targets Android 7.0.
    840 </li>
    841 
    842 <li>
    843 If an app posts {@link java.lang.Runnable} tasks to a {@link android.view.View}, and
    844 the {@link android.view.View}
    845 is not attached to a window, the system
    846 queues the {@link java.lang.Runnable} task with the {@link android.view.View};
    847 the {@link java.lang.Runnable} task does not execute until the
    848 {@link android.view.View} is attached
    849 to a window. This behavior fixes the following bugs:
    850 <ul>
    851    <li>If an app posted to a {@link android.view.View} from a thread other than the intended
    852    windows UI thread, the {@link java.lang.Runnable} may run on the wrong thread as a result.
    853    </li>
    854    <li>If the {@link java.lang.Runnable} task was posted from a thread other than
    855    a looper thread, the app could expose the {@link java.lang.Runnable} task.</li>
    856 </ul>
    857 </li>
    858 
    859 <li>
    860 If an app on Android 7.0 with
    861 {@link android.Manifest.permission#DELETE_PACKAGES DELETE_PACKAGES}
    862 permission tries to delete a package, but a different app had installed that package,
    863 the system requires user confirmation. In this scenario, apps should expect
    864 {@link android.content.pm.PackageInstaller#STATUS_PENDING_USER_ACTION STATUS_PENDING_USER_ACTION}
    865 as the return status when they invoke
    866 {@link android.content.pm.PackageInstaller#uninstall PackageInstaller.uninstall()}.
    867 </li>
    868 
    869   <li>The JCA provider called <em>Crypto</em> is deprecated, because its only
    870   algorithm, SHA1PRNG, is cryptographically weak. Apps can no longer use
    871   SHA1PRNG to (insecurely) derive keys, because this provider is no longer
    872   available. For more information, see the blog
    873   post <a href=
    874   "http://android-developers.blogspot.com/2016/06/security-crypto-provider-deprecated-in.html"
    875   class="external-link">Security "Crypto" provider deprecated in Android
    876   N</a>.
    877   </li>
    878 
    879 </ul>
    880 
    881