| Dirk Dougherty | 5748bc4 | 2016-02-06 18:24:32 -0800 | [diff] [blame] | 1 | page.title=Behavior Changes |
| 2 | page.keywords=preview,sdk,compatibility |
| Dirk Dougherty | 43eb9510 | 2016-03-03 14:53:16 -0800 | [diff] [blame] | 3 | meta.tags="preview", "compatibility" |
| 4 | page.tags="preview", "developer preview" |
| 5 | page.image=images/cards/card-n-changes_2x.png |
| Dirk Dougherty | 5748bc4 | 2016-02-06 18:24:32 -0800 | [diff] [blame] | 6 | @jd:body |
| 7 | |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 8 | |
| 9 | <div id="qv-wrapper"> |
| 10 | <div id="qv"> |
| 11 | |
| 12 | <h2>In this document</h2> |
| 13 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 14 | <ol> |
| 15 | <li><a href="#perf">Performance Improvements</a> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 16 | <ol> |
| 17 | <li><a href="#doze">Doze</a></li> |
| 18 | <li><a href="#bg-opt">Background Optimizations</a></li> |
| 19 | </ol> |
| 20 | </li> |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 21 | <li><a href="#perm">Permissions Changes</a></li> |
| 22 | <li><a href="#accessibility">Accessibility Improvements</a> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 23 | <ol> |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 24 | <li><a href="#screen-zoom">Screen Zoom</a></li> |
| 25 | <li><a href="#vision-settings">Vision Settings in Setup Wizard</a></li> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 26 | </ol> |
| 27 | </li> |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 28 | <li><a href="#ndk">NDK Apps Linking to Platform Libraries</a></li> |
| 29 | <li><a href="#afw">Android for Work</a></li> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 30 | </ol> |
| 31 | |
| 32 | <h2>See Also</h2> |
| 33 | <ol> |
| 34 | <li><a href="{@docRoot}preview/api-overview.html"> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 35 | Android N API Overview</a></li> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 36 | </ol> |
| 37 | |
| 38 | </div> |
| 39 | </div> |
| 40 | |
| 41 | |
| Dirk Dougherty | 5748bc4 | 2016-02-06 18:24:32 -0800 | [diff] [blame] | 42 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 43 | Along with new features and capabilities, Android N |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 44 | includes a variety of system and API behavior changes. This document |
| 45 | highlights some of the key changes that you should understand and account for |
| 46 | in your apps. |
| 47 | </p> |
| 48 | |
| 49 | <p> |
| 50 | If you have previously published an app for Android, be aware that your app |
| 51 | might be affected by these changes in the platform. |
| 52 | </p> |
| 53 | |
| 54 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 55 | <h2 id="perf">Performance Improvements</h2> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 56 | |
| 57 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 58 | Android N contains system behavior changes aimed at improving the battery |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 59 | life of devices, RAM usage, and app performance. These changes can impact the |
| 60 | availability of system resources and system notifications to your app. You |
| 61 | should review these changes and evaluate how your app may need to adjust to |
| 62 | them. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 63 | </p> |
| 64 | |
| 65 | <h3 id="doze">Doze</h3> |
| 66 | |
| 67 | <p> |
| 68 | Introduced in Android 6.0 (API level 23), Doze improves battery life by |
| 69 | deferring CPU and network activities when a user leaves a device unplugged, |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 70 | stationary, and with the screen turned off. Android N brings further |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 71 | enhancements to Doze by applying a subset of CPU and network restrictions |
| 72 | while the device is unplugged with the screen turned off, but not necessarily |
| 73 | stationary, for example, when a handset is traveling in a user’s pocket. |
| 74 | </p> |
| 75 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 76 | |
| 77 | <img src="{@docRoot}preview/images/doze-diagram-1.png" |
| 78 | alt="" height="251px" id="figure1" /> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 79 | <p class="img-caption"> |
| 80 | <strong>Figure 1.</strong> Illustration of how Doze applies a first level of |
| 81 | system activity restrictions to improve battery life. |
| 82 | </p> |
| 83 | |
| 84 | <p> |
| 85 | When a device is on battery power, and the screen has been off for a certain |
| 86 | time, the device enters Doze and applies the first subset of restrictions: It |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 87 | shuts off app network access, and defers jobs and syncs. If the device is |
| 88 | stationary for a certain time after entering Doze, the system applies the |
| 89 | rest of the Doze restrictions to {@link android.os.PowerManager.WakeLock}, |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 90 | {@link android.app.AlarmManager} alarms, GPS, and Wi-Fi scans. Regardless of |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 91 | whether some or all Doze restrictions are being applied, the system wakes the |
| 92 | device for brief maintenance windows, during which applications are allowed |
| 93 | network access and can execute any deferred jobs/syncs. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 94 | </p> |
| 95 | |
| 96 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 97 | <img src="{@docRoot}preview/images/doze-diagram-2.png" |
| 98 | alt="" id="figure2" /> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 99 | <p class="img-caption"> |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 100 | <strong>Figure 2.</strong> Illustration of how Doze applies a second level of |
| 101 | system activity restrictions after the device is stationary for a certain time. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 102 | </p> |
| 103 | |
| 104 | <p> |
| 105 | Note that activating the screen on or plugging in the device exits Doze and |
| 106 | removes these processing restrictions. The additional behavior does not |
| 107 | affect recommendations and best practices in adapting your app to the prior |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 108 | version of Doze introduced in Android 6.0 (API level 23), as discussed in |
| David Friedman | 7254ae4 | 2016-03-09 00:34:33 -0800 | [diff] [blame] | 109 | <a href="{@docRoot}training/monitoring-device-state/doze-standby.html"> |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 110 | Optimizing for Doze and App Standby</a>. You should still |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 111 | follow those recommendations, such as using Google Cloud Messaging (GCM) to |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 112 | send and receive messages, and start planning updates to accomodate the |
| 113 | additional Doze behavior. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 114 | </p> |
| 115 | |
| 116 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 117 | <h3 id="bg-opt">Project Svelte: Background Optimizations</h3> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 118 | |
| 119 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 120 | Android N removes three implicit broadcasts in order to help optimize both |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 121 | memory use and power consumption. This change is necessary because implicit |
| 122 | broadcasts frequently start apps that have registered to listen for them in |
| 123 | the background. Removing these broadcasts can substantially benefit device |
| 124 | performance and user experience. |
| 125 | </p> |
| 126 | |
| 127 | <p> |
| 128 | Mobile devices experience frequent connectivity changes, such as when moving |
| 129 | between Wi-Fi and mobile data. Currently, apps can monitor for changes in |
| 130 | connectivity by registering a receiver for the implicit {@link |
| 131 | android.net.ConnectivityManager#CONNECTIVITY_ACTION} broadcast in their |
| 132 | manifest. Since many apps register to receive this broadcast, a single |
| 133 | network switch can cause them all to wake up and process the broadcast at |
| 134 | once. |
| 135 | </p> |
| 136 | |
| 137 | <p> |
| Adarsh Fernando | 3760156 | 2016-03-09 09:53:57 -0800 | [diff] [blame] | 138 | Similarly, apps can register to receive implicit {@link |
| 139 | android.hardware.Camera#ACTION_NEW_PICTURE} and {@link |
| 140 | android.hardware.Camera#ACTION_NEW_VIDEO} broadcasts from other apps, such as |
| 141 | Camera. When a user takes a picture with the Camera app, these apps wake up |
| 142 | to process the broadcast. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 143 | </p> |
| 144 | |
| 145 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 146 | To alleviate these issues, Android N applies the following |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 147 | optimizations: |
| 148 | </p> |
| 149 | |
| 150 | <ul> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 151 | <li>Apps targeting Android N do not receive {@link |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 152 | android.net.ConnectivityManager#CONNECTIVITY_ACTION} broadcasts, even if they |
| 153 | have manifest entries to request notification of these events. Apps running |
| 154 | in the foreground can still listen for {@code CONNECTIVITY_CHANGE} on their |
| Adarsh Fernando | 3760156 | 2016-03-09 09:53:57 -0800 | [diff] [blame] | 155 | main thread if they request notification with a {@link |
| 156 | android.content.BroadcastReceiver}. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 157 | </li> |
| 158 | |
| Adarsh Fernando | 3760156 | 2016-03-09 09:53:57 -0800 | [diff] [blame] | 159 | <li>Apps cannot send or receive {@link |
| 160 | android.hardware.Camera#ACTION_NEW_PICTURE} or {@link |
| 161 | android.hardware.Camera#ACTION_NEW_VIDEO} broadcasts. This optimization |
| 162 | affects all apps, not only those targeting Android N. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 163 | </li> |
| 164 | </ul> |
| 165 | |
| 166 | <p> |
| 167 | Future releases of Android may deprecate additional implicit broadcasts, as |
| 168 | well as unbound background services. For this reason, you should avoid or |
| 169 | remove dependencies on manifest-declared receivers for implicit broadcasts, |
| 170 | as well as on background services. |
| 171 | </p> |
| 172 | |
| 173 | <p> |
| 174 | The Android framework provides several solutions to mitigate the need for |
| 175 | these implicit broadcasts or background services. For example, the {@link |
| 176 | android.app.job.JobScheduler} API provides a robust mechanism to schedule |
| 177 | network operations when specified conditions, such as connection to an |
| 178 | unmetered network, are met. You can even use {@link |
| 179 | android.app.job.JobScheduler} to react to changes to content providers. |
| 180 | </p> |
| 181 | |
| 182 | <p> |
| 183 | For more information about this behavior change and how to adapt your app, |
| 184 | see <a href= |
| 185 | "{@docRoot}preview/features/background-optimization.html">Background |
| 186 | Optimizations</a>. |
| 187 | </p> |
| 188 | |
| 189 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 190 | <h2 id="perm">Permissions Changes</h2> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 191 | |
| 192 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 193 | Android N includes changes to permissions that may affect your app, |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 194 | including user accounts permissions and a new permission for writing to |
| 195 | external storage. Here is a summary of the permissions that have changed in |
| 196 | the preview: |
| 197 | </p> |
| 198 | |
| 199 | <ul> |
| 200 | <li>{@code GET_ACCOUNTS} (Deprecated) |
| 201 | <p> |
| 202 | The GET_ACCOUNTS permission is now deprecated. The system ignores this |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 203 | permission for apps that target Android N. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 204 | </p> |
| 205 | </li> |
| 206 | |
| 207 | <li>{@code ACTION_OPEN_EXTERNAL_DIRECTORY} (New) |
| 208 | <p> |
| 209 | This permission is for a new storage option. Apps can now use the intent |
| 210 | {@code ACTION_OPEN_EXTERNAL_DIRECTORY} to request that the system create a |
| 211 | directory for the app's use. The system prompts the user to grant |
| 212 | approval. If the user approves, the app can read and write files and |
| 213 | directories in that one directory (and its descendants). The app does not |
| 214 | need {@link android.Manifest.permission_group#STORAGE STORAGE} |
| 215 | permissions to access this external directory |
| 216 | </p> |
| 217 | |
| 218 | <p> |
| 219 | For more information about this intent, see the updated |
| 220 | {@code Intent} reference documentation in the |
| Andrew Solovay | 5641408 | 2016-03-08 17:57:53 -0800 | [diff] [blame] | 221 | <a href="{@docRoot}preview/setup-sdk.html#docs-dl">N Preview SDK |
| 222 | Reference</a>. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 223 | </p> |
| 224 | </li> |
| 225 | </ul> |
| 226 | |
| 227 | |
| 228 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 229 | <h2 id="accessibility">Accessibility Improvements</h2> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 230 | |
| 231 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 232 | Android N includes changes intended to improve the usability of the |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 233 | platform for users with low or impaired vision. These changes should |
| 234 | generally not require code changes in your app, however you should review |
| 235 | these feature and test them with your app to assess potential impacts to user |
| 236 | experience. |
| 237 | </p> |
| 238 | |
| 239 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 240 | <h3 id="screen-zoom">Screen Zoom</h3> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 241 | |
| 242 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 243 | Android N enables users to set <strong>Display size</strong>which magnifies |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 244 | or shrinks all elements on the screen, thereby improving device accessibility |
| 245 | for users with low vision. Users cannot zoom the screen past a minimum screen |
| 246 | width of <a href= |
| 247 | "http://developer.android.com/guide/topics/resources/providing-resources.html"> |
| 248 | sw320dp</a>, which is the width of a Nexus 4, a common medium-sized phone. |
| 249 | </p> |
| 250 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 251 | <div class="cols"> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 252 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 253 | <div class="col-6"> |
| 254 | <img src="{@docRoot}preview/images/screen-zoom-1.png" alt="" height="XXX" id="figure1" /> |
| 255 | </div> |
| 256 | <div class="col-6"> |
| 257 | <img src="{@docRoot}preview/images/screen-zoom-2.png" alt="" height="XXX" id="figure1" /> |
| 258 | </div> |
| 259 | |
| 260 | </div> <!-- end cols --> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 261 | <p class="img-caption"> |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 262 | <strong>Figure 3.</strong> The screen on the right shows the effect of |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 263 | increasing the Display size of a device running an Android N system image. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 264 | </p> |
| 265 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 266 | |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 267 | <p> |
| 268 | When the device density changes, the system notifies running apps in the |
| 269 | following ways: |
| 270 | </p> |
| 271 | |
| 272 | <ul> |
| 273 | <li>If an app targets API level 23 or lower, the system automatically kills |
| 274 | all its background processes. This means that if a user switches away from |
| 275 | such an app to open the <em>Settings</em> screen and changes the |
| 276 | <strong>Display size</strong> setting, the system kills the app in the same |
| 277 | manner that it would in a low-memory situation. If the app has any foreground |
| 278 | processes, the system notifies those processes of the configuration change as |
| 279 | described in <a href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling |
| 280 | Runtime Changes</a>, just as if the device's orientation had changed. |
| 281 | </li> |
| 282 | |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 283 | <li>If an app targets Android N, all of its processes |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 284 | (foreground and background) are notified of the configuration change as |
| 285 | described in <a href= |
| 286 | "{@docRoot}guide/topics/resources/runtime-changes.html">Handling |
| 287 | Runtime Changes</a>. |
| 288 | </li> |
| 289 | </ul> |
| 290 | |
| 291 | <p> |
| 292 | Most apps do not need to make any changes to support this feature, provided |
| Andrew Solovay | 170191d | 2016-03-08 11:59:29 -0800 | [diff] [blame] | 293 | the apps follow Android best practices. Specific things to check for: |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 294 | </p> |
| 295 | |
| Andrew Solovay | 170191d | 2016-03-08 11:59:29 -0800 | [diff] [blame] | 296 | <ul> |
| 297 | <li>Test your app on a device with screen width <code><a href= |
| 298 | "{@docRoot}guide/topics/resources/providing-resources.html">sw320dp</a></code> |
| 299 | and be sure it performs adequately. |
| 300 | </li> |
| 301 | |
| 302 | <li>When the device configuration changes, update any density-dependent |
| 303 | cached information, such as cached bitmaps or resources loaded from the |
| 304 | network. Check for configuration changes when the app resumes from the paused |
| 305 | state. |
| 306 | <p class="note"> |
| 307 | <strong>Note:</strong> If you cache configuration-dependent data, it's a |
| 308 | good idea to include relevant metadata such as the appropriate screen |
| 309 | size or pixel density for that data. Saving this metadata allows you to |
| 310 | decide whether you need to refresh the cached data after a configuration |
| 311 | change. |
| 312 | </p> |
| 313 | </li> |
| 314 | |
| 315 | <li>Avoid specifying dimensions with px units, since they do not scale with |
| 316 | screen density. Instead, specify dimensions with <a href= |
| 317 | "{@docRoot}guide/practices/screens_support.html">density-independent |
| 318 | pixel</a> (<code>dp</code>) units. |
| 319 | </li> |
| 320 | </ul> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 321 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 322 | <h3 id="vision-settings">Vision Settings in Setup Wizard</h3> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 323 | |
| 324 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 325 | Android N includes Vision Settings on the Welcome screen, where users can |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 326 | set up the following accessibility settings on a new device: |
| 327 | <strong>Magnification gesture</strong>, <strong>Font size</strong>, |
| 328 | <strong>Display size</strong> and <strong>TalkBack</strong>. This change |
| 329 | increases the visibility of bugs related to different screen settings. To |
| 330 | assess the impact of this feature, you should test your apps with these |
| 331 | settings enabled. You can find the settings under <strong>Settings > |
| 332 | Accessibility</strong>. |
| 333 | </p> |
| 334 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 335 | <h2 id="ndk">NDK Apps Linking to Platform Libraries</h2> |
| 336 | |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 337 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 338 | Android N includes namespace changes to prevent loading of non-public APIs. |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 339 | If you use the NDK, you should only be using public APIs from the Android |
| 340 | platform. Using non-public APIs in the next official release of Android |
| 341 | can cause your app to crash. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 342 | </p> |
| 343 | |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 344 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 345 | In order to alert you to use of non-public APIs, apps running on an Android N |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 346 | device generate an error in logcat output when an app calls a non-public API. |
| 347 | This error is also displayed on the device screen as a message to help |
| 348 | raise awareness of this situation. You should review your app code to |
| 349 | remove use of non-public platform APIs and thoroughly test your apps using |
| 350 | a preview device or emulator. |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 351 | </p> |
| 352 | |
| 353 | <p> |
| 354 | If your app depends on platform libraries, see the NDK documentation for |
| 355 | typical fixes for replacing common private APIs with public API equivalents. |
| 356 | You may also be linking to platform libraries without realizing it, |
| 357 | especially if your app uses a library that is part of the platform (such as |
| 358 | <code>libpng</code>), but is not part of the NDK. In that case, ensure that |
| 359 | your APK contains all the .so files you intended to link against. |
| 360 | </p> |
| 361 | |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 362 | <p class="caution"> |
| 363 | <strong>Caution:</strong> Some third-party libraries may link to non-public |
| 364 | APIs. If your app uses these libraries, your app may crash when running |
| 365 | on the next official release of Android. |
| 366 | </p> |
| 367 | |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 368 | <p> |
| 369 | Apps should not depend on or use native libraries that are not included in |
| 370 | the NDK, because they may change, or be removed from one Android release to |
| 371 | another. The switch from OpenSSL to BoringSSL is an example of such a change. |
| 372 | Also, different devices may offer different levels of compatibility, because |
| 373 | there are no compatibility requirements for platform libraries not included |
| 374 | in the NDK. If you must access non-NDK libraries on older devices, make the |
| 375 | loading dependent on the Android API level. |
| 376 | </p> |
| 377 | |
| 378 | <p> |
| 379 | To help you diagnose these types problems here are some example Java and NDK |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 380 | errors you might encounter when attempting to build your app with Android N: |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 381 | </p> |
| 382 | |
| 383 | <p>Example Java error:</p> |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 384 | <pre class="no-pretty-print"> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 385 | java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libcutils.so" |
| 386 | is not accessible for the namespace "classloader-namespace" |
| 387 | </pre> |
| 388 | |
| 389 | <p>Example NDK error:</p> |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 390 | <pre class="no-pretty-print"> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 391 | dlopen failed: cannot locate symbol "__system_property_get" referenced by ... |
| 392 | </pre> |
| 393 | |
| 394 | |
| 395 | <p> |
| 396 | Here are some typical fixes for apps encountering these types of errors: |
| 397 | </p> |
| 398 | |
| 399 | <ul> |
| 400 | <li>Use of getJavaVM and getJNIEnv from libandroid_runtime.so can be replaced |
| 401 | with standard JNI functions: |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 402 | <pre class="no-pretty-print"> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 403 | AndroidRuntime::getJavaVM -> GetJavaVM from <jni.h> |
| 404 | AndroidRuntime::getJNIEnv -> JavaVM::GetEnv or |
| 405 | JavaVM::AttachCurrentThread from <jni.h>. |
| 406 | </pre> |
| 407 | </li> |
| 408 | |
| 409 | <li>Use of {@code property_get} symbol from {@code libcutils.so} can be |
| David Friedman | 5e145b7 | 2016-03-08 12:25:35 -0800 | [diff] [blame] | 410 | replaced with the public {@code alternative __system_property_get}. |
| 411 | To do this, use {@code __system_property_get} with the following include: |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 412 | <pre> |
| David Friedman | 5e145b7 | 2016-03-08 12:25:35 -0800 | [diff] [blame] | 413 | #include <sys/system_properties.h> |
| Joe Fernandez | f278dab | 2016-03-06 19:14:25 -0800 | [diff] [blame] | 414 | </pre> |
| 415 | </li> |
| 416 | |
| 417 | <li>Use of {@code SSL_ctrl} symbol from {@code libcrypto.so} should be |
| 418 | replaced with an app local version. For example, you should statically link |
| 419 | {@code libcyrpto.a} in your {@code .so} file or include your own dynamically |
| 420 | {@code libcrypto.so} from BoringSSL or OpenSSL in your app. |
| 421 | </li> |
| 422 | </ul> |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 423 | |
| 424 | <h2 id="afw">Android for Work</h2> |
| 425 | <p> |
| David Friedman | fffa8ac | 2016-03-07 22:13:29 -0800 | [diff] [blame] | 426 | Android N contains changes for apps that target Android for Work, including |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 427 | changes to certificate installation, password resetting, secondary user |
| 428 | management, and access to device identifiers. If you are building apps for |
| 429 | Android for Work environments, you should review these changes and modify |
| 430 | your app accordingly. |
| 431 | </p> |
| 432 | |
| 433 | <ul> |
| 434 | <li>You must install a delegated certificate installer before the DPC can set |
| 435 | it. For both profile and device-owner apps targeting the N SDK, you should |
| 436 | install the delegated certificate installer before the device policy |
| 437 | controller (DPC) calls |
| 438 | <code>DevicePolicyManager.setCertInstallerPackage()</code>. If the installer |
| 439 | is not already installed, the system throws an |
| 440 | <code>IllegalArgumentException</code>. |
| 441 | </li> |
| 442 | |
| 443 | <li>Reset password restrictions for device admins now apply to profile |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 444 | owners. Device admins can no longer use |
| 445 | <code>DevicePolicyManager.resetPassword()</code> to clear passwords or change |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 446 | ones that are already set. Device admins can still set a password, but only |
| 447 | when the device has no password, PIN, or pattern. |
| 448 | </li> |
| 449 | |
| 450 | <li>Device and profile owners can manage accounts even if restrictions are |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 451 | set. Device owners and profile owners can call the Account Management APIs |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 452 | even if <code>DISALLOW_MODIFY_ACCOUNTS</code> user restrictions are in place. |
| 453 | </li> |
| 454 | |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 455 | <li>Device owners can manage secondary users more easily. When a device is |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 456 | running in device owner mode, the <code>DISALLOW_ADD_USER</code> restriction |
| 457 | is automatically set. This prevents users from creating unmanaged secondary |
| 458 | users. In addition, the <code>CreateUser()</code> and |
| 459 | <code>createAndInitial()</code> methods are deprecated; the new |
| 460 | <code>DevicePolicyManager.createAndManageUser()</code> method replaces them. |
| 461 | </li> |
| 462 | |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 463 | <li>Device owners can access device identifiers. A Device owner can access the |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 464 | Wi-Fi MAC address of a device, using |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 465 | <code>DevicePolicyManagewr.getWifiMacAddress()</code>. If Wi-Fi has never |
| Joe Fernandez | 0925df0 | 2016-03-06 22:24:40 -0800 | [diff] [blame] | 466 | been enabled on the device, this method returns a value of {@code null}. |
| 467 | </li> |
| 468 | </ul> |
| David Friedman | 0a68693 | 2016-03-08 15:01:40 -0800 | [diff] [blame] | 469 | |
| Andrew Solovay | b0fbda4 | 2016-03-08 18:19:09 -0800 | [diff] [blame] | 470 | <p> |
| 471 | For more information about changes to Android for Work in Android N, see |
| 472 | <a href="{@docRoot}preview/features/afw.html">Android for Work Updates</a>. |
| 473 | </p> |
| 474 | |
| David Friedman | 0a68693 | 2016-03-08 15:01:40 -0800 | [diff] [blame] | 475 | <h2 id="other">Other important points</h2> |
| 476 | |
| 477 | <ul> |
| David Friedman | 10594f3 | 2016-03-09 02:20:34 -0800 | [diff] [blame] | 478 | <li>When an app is running on Android N, but targets a lower API level, |
| 479 | and the user changes display size, the app process is killed. The app |
| 480 | must be able to gracefully handle this scenario. Otherwise, it crashes |
| 481 | when the user restores it from Recents. |
| David Friedman | 0a68693 | 2016-03-08 15:01:40 -0800 | [diff] [blame] | 482 | |
| 483 | <p> |
| David Friedman | 10594f3 | 2016-03-09 02:20:34 -0800 | [diff] [blame] | 484 | You should test your app to ensure |
| 485 | that this behavior does not occur. |
| 486 | You can do so by causing an identical crash |
| 487 | when killing the app manually via DDMS. |
| David Friedman | 0a68693 | 2016-03-08 15:01:40 -0800 | [diff] [blame] | 488 | </p> |
| 489 | |
| 490 | <p> |
| 491 | Apps targeting N and above are not automatically killed on density changes; |
| David Friedman | 10594f3 | 2016-03-09 02:20:34 -0800 | [diff] [blame] | 492 | however, they may still respond poorly to configuration changes. |
| David Friedman | 0a68693 | 2016-03-08 15:01:40 -0800 | [diff] [blame] | 493 | </p> |
| 494 | </li> |
| 495 | |
| 496 | <li> |
| 497 | Apps on Android N should be able to gracefully handle configuration changes, |
| 498 | and should not crash on subsequent starts. You can verify app behavior |
| 499 | by changing font size (<strong>Setting</strong> > |
| 500 | <strong>Display</strong> > <strong>Font size</strong>), and then restoring |
| 501 | the app from Recents. |
| 502 | </li> |
| 503 | </ul> |
| 504 | |