• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Android N for Developers
2meta.tags="preview", "androidn"
3page.tags="preview", "developer preview"
4page.image=images/cards/card-n-apis_2x.png
5@jd:body
6
7
8
9
10<div id="qv-wrapper">
11<div id="qv">
12  <h2>Key Developer Features</h2>
13  <ol>
14      <ul style="list-style-type:none;">
15        <li><a href="#multi-window_support">Multi-window Support</a></li>
16        <li><a href="#notification_enhancements">Notifications</a></li>
17        <li><a href="#jit_aot">JIT/AOT Compilation</a></li>
18        <li><a href="#quick_path_to_app_install">Quick Path to App Install</a></li>
19        <li><a href="#doze_on_the_go">Doze on the Go</a></li>
20        <li><a href="#background_optimizations">Background Optimizations</a></li>
21        <li><a href="#surfaceview">SurfaceView</a></li>
22        <li><a href="#data_saver">Data Saver</a></li>
23        <li><a href="#vulkan">Vulkan API</a></li>
24        <li><a href="#tile_api">Quick Settings Tile API</a></li>
25        <li><a href="#number-blocking">Number Blocking</a></li>
26        <li><a href="#call_screening">Call Screening</a></li>
27        <li><a href="#multi-locale_languages">Locales and Languages</a></li>
28        <li><a href="#emoji">New Emojis</a></li>
29        <li><a href="#icu4">ICU4J APIs in Android</a></li>
30        <li><a href="#gles_32">OpenGL ES 3.2 API</a></li>
31        <li><a href="#android_tv_recording">Android TV Recording</a></li>
32        <li><a href="#android_for_work">Android for Work</a></li>
33        <li><a href="#accessibility_enhancements">Accessibility</a></li>
34        <li><a href="#direct_boot">Direct Boot</a></li>
35        <li><a href="#key_attestation">Key Attestation</a></li>
36        <li><a href="#network_security_config">Network Security Config</a></li>
37        <li><a href="#default_trusted_ca">Default Trusted CA</a></li>
38        <li><a href="#apk_signature_v2">APK Signature Scheme v2</a></li>
39        <li><a href="#scoped_directory_access">Scoped Directory Access</a></li>
40        <li><a href="#keyboard_shortcuts_helper">Keyboard Shortcuts Helper</a></li>
41        <li><a href="#custom_pointer_api">Custom Pointer API</a></li>
42        <li><a href="#sustained_performance_api">Sustained Performance API</a></li>
43        <li><a href="#vr">VR Support</a></li>
44        <li><a href="#print_svc">Print Service Enhancements</a></li>
45        <li><a href="#virtual_files">Virtual Files</a></li>
46        <li><a href="#framemetrics_api">FrameMetricsListener API</a></li>
47      </ol>
48</div>
49</div>
50
51
52
53<p>Android N is still in active development, but you can try it
54now as part of the N Developer Preview. The sections below highlight some of
55the new features for developers. </p>
56
57<p>
58  Make sure to check out the <a href=
59  "{@docRoot}preview/behavior-changes.html">Behavior Changes</a> to learn about
60  areas where platform changes may affect your apps, take a look at the
61  developer guides to learn more about key features, and download the <a href=
62  "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a> for details on
63  new APIs.
64</p>
65
66<h2 id="multi-window_support">Multi-window Support</h2>
67
68
69<p>In Android N, we're introducing a new and much-requested multitasking feature
70into the platform &mdash; multi-window support. </p>
71
72  <p>Users can now pop open two apps on the screen at once. </p>
73  <ul>
74  <li>On phones and tablets
75running Android N, users can run two apps side-by-side or
76one-above-the-other in splitscreen mode. Users can resize the apps by dragging
77the divider between them. </li>
78
79<li>On Android TV devices, apps can put themselves in <a
80href="{@docRoot}preview/features/picture-in-picture.html">picture-in-picture
81mode</a>, allowing them to continue showing content while the user browses or
82interacts with other apps.</li>
83  </ul>
84
85<div class="col-4of10">
86<img src="{@docRoot}preview/images/mw-portrait.png" alt="" style="height:460px;padding-left:1em;"
87    id="img-split-screen" />
88<p class="img-caption">
89  <strong>Figure 1.</strong> Apps running in split-screen mode.
90</p>
91
92  </div>
93
94<p>Especially on tablets and other larger-screen devices, multi-window support
95gives you new ways to engage users. You can even enable drag-and-drop in
96your app to let users conveniently drag content to or from your app &mdash; a great
97way to enhance your user experience. </p>
98
99<p>It's straightforward to add multi-window support to your app and configure how it
100handles multi-window display. For example, you can specify your activity's
101minimum allowable dimensions, preventing users from resizing the activity below
102that size. You can also disable multi-window display for your app, which
103  ensures that the system will only show your app in full-screen mode.</p>
104
105<p>
106  For more information, see the <a href=
107  "{@docRoot}preview/features/multi-window.html">Multi-Window Support</a>
108  developer documentation.
109</p>
110
111<h2 id="notification_enhancements">Notification Enhancements</h2>
112
113<p>In Android N we've redesigned notifications to make them easier and faster to
114use. Some of the changes include:</p>
115
116<ul>
117  <li>
118    <strong>Template updates</strong>: We're updating notification templates to
119    put a new emphasis on hero image and avatar. Developers will be able to
120    take advantage of the new templates with minimal adjustments in their code.
121  </li>
122
123  <li>
124    <strong>Messaging style customization</strong>: You can customize more of
125    the user interface labels associated with your notifications using the
126    <code>MessagingStyle</code> class. You can configure the message,
127    conversation title, and content view.
128  </li>
129
130  <li>
131    <strong>Bundled notifications</strong>: The system can group messages
132    together, for example by message topic, and display the group. A user can
133    take actions, such as Dismiss or Archive, on them in place. If you’ve
134    implemented notifications for Android Wear, you’ll already be familiar with
135    this model.
136  </li>
137
138  <li>
139    <strong>Direct reply</strong>: For real-time communication apps, the
140    Android system supports inline replies so that users can quickly respond to
141    an SMS or text message directly within the notification interface.
142  </li>
143
144  <li>
145    <strong>Custom views</strong>: Two new APIs enable you to leverage system
146    decorations, such as notification headers and actions, when using custom
147    views in notifications.
148  </li>
149</ul>
150
151<div class="col-4of12">
152  <img src="{@docRoot}preview/images/notifications-1.png" alt=""
153  style="padding:.5em;max-width:226px">
154</div>
155
156<div class="col-4of12">
157  <img src="{@docRoot}preview/images/notifications-3.png" alt=""
158  style="padding:.5em;max-width:226px">
159</div>
160
161<div class="col-4of12">
162  <img src="{@docRoot}preview/images/notifications-2.png" alt=""
163  style="padding:.5em;max-width:226px">
164</div>
165
166
167<p class="img-caption">
168  <strong>Figure 2.</strong> Bundled notifications and direct reply.
169</p>
170
171<p>To learn how to implement the new features, see the
172  <a href="{@docRoot}preview/features/notification-updates.html">Notifications</a>
173  guide.</p>
174
175
176
177<h2 id="jit_aot">Profile-guided JIT/AOT Compilation</h2>
178
179<p>In Android N, we've added a Just in Time (JIT) compiler with code profiling to
180ART, which lets it constantly improve the performance of Android apps as they
181run. The JIT compiler complements ART's current Ahead of Time (AOT) compiler
182and helps improve runtime performance, save storage space, and speed up app
183updates and system updates.</p>
184
185<p>Profile-guided compilation lets ART manage the AOT/JIT compilation for each app
186according to its actual usage, as well as conditions on the device. For
187example, ART maintains a profile of each app's hot methods and can precompile
188and cache those methods for best performance. It leaves other parts of the app
189uncompiled until they are actually used.</p>
190
191<p>Besides improving performance for key parts of the app, profile-guided
192compilation helps reduce an app's overall RAM footprint, including associated
193binaries. This feature is especially important on low-memory devices.</p>
194
195<p>ART manages profile-guided compilation in a way that minimizes impact on the
196device battery. It does precompilation only when then the device is idle and
197charging, saving time and battery by doing that work in advance.</p>
198
199<h2 id="quick_path_to_app_install">Quick Path to App Install</h2>
200
201<p>One of the most tangible benefits of ART's JIT compiler is the speed of app
202installs and system updates. Even large apps that required several minutes to
203optimize and install in Android 6.0 can now install in just a matter of
204seconds. System updates are also faster, since there's no more optimizing step. </p>
205
206<h2 id="doze_on_the_go">Doze on the Go...</h2>
207
208<p>Android 6.0 introduced Doze, a system mode that saves battery by deferring
209apps' CPU and network activities when the device is idle, such as when it's
210sitting on a table or in a drawer. </p>
211
212<p>Now in Android N, Doze takes a step further and saves battery while on the go.
213Any time the screen is off for a period of time and the device is unplugged,
214Doze applies a subset of the familiar CPU and network restrictions to apps.
215This means users can save battery even when carrying their devices in their
216pockets.</p>
217
218
219<img src="/preview/images/doze-diagram-1.png"
220  alt="" id="figure1" />
221<p class="img-caption">
222  <strong>Figure 3.</strong> Doze now applies
223  restrictions to improve battery life even when the device is not stationary.
224</p>
225
226
227<p>A short time after the screen turns off while the device is on battery, Doze
228restricts network access and defers jobs and syncs. During brief maintenance
229windows, applications are allowed network access and any of their deferred
230jobs/syncs are executed. Turning the screen on or plugging in the device brings
231the device out of Doze.</p>
232
233<p>When the device is stationary again, with screen off and on battery for a
234period of time, Doze applies the full CPU and network restrictions on {@link
235android.os.PowerManager.WakeLock}, {@link android.app.AlarmManager} alarms, and
236GPS/Wi-Fi scans.</p>
237
238<p>The best practices for adapting your app to Doze are the same whether the
239device is moving or not, so if you already updated your app to gracefully
240handle Doze, you're all set. If not, start <a
241href="{@docRoot}training/monitoring-device-state/doze-standby.html#assessing_your_app">adapting
242your app to Doze</a> now.</p>
243
244<h2 id="background_optimizations">Project Svelte: Background Optimizations</h2>
245
246<p>Project Svelte is an ongoing effort to minimize RAM use by system and apps
247across the range of Android devices in the ecosystem. In Android N, Project
248Svelte is focused on optimizing the way apps run in the background. </p>
249
250<p>Background processing is an essential part of most apps. When handled right, it
251can make your user experience amazing &mdash; immediate, fast, and context-aware.
252When not handled right, background processing can needlessly consume RAM (and
253battery) and affect system performance for other apps. </p>
254
255<p>Since Android 5.0, {@link android.app.job.JobScheduler} has been the
256preferred way of performing background work in a way that's good
257for users. Apps can schedule jobs while letting the system optimize based on
258memory, power, and connectivity conditions. JobScheduler offers control and
259simplicity, and we want all apps to use it. </p>
260
261<p>
262  Another good option is <a href=
263  "https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager">
264  <code>GCMNetworkManager</code></a>, part of Google Play Services, which
265  offers similar job scheduling with compatibility across legacy versions of
266  Android.
267</p>
268
269<p>We're continuing to extend <code>JobScheduler</code> and
270<code>GCMNetworkManager</code> to meet more of
271your use cases &mdash; for example, in Android N you can now schedule background
272work based on changes in Content Providers. At the same time we're starting to
273deprecate some of the older patterns that can reduce system performance,
274especially on low-memory devices.</p>
275
276<p>In Android N we're removing three commonly-used implicit broadcasts &mdash;
277 {@link android.net.ConnectivityManager#CONNECTIVITY_ACTION}, {@link
278  android.hardware.Camera#ACTION_NEW_PICTURE}, and {@link
279  android.hardware.Camera#ACTION_NEW_VIDEO} &mdash; since those can wake the
280background processes of multiple apps at once and strain memory and battery. If
281your app is receiving these, take advantage of the N Developer Preview to
282  migrate to <code>JobScheduler</code> and related APIs instead. </p>
283
284<p>
285  Take a look at the <a href=
286  "{@docRoot}preview/features/background-optimization.html">Background
287  Optimizations</a> documentation for details.
288</p>
289
290<h2 id="surfaceview">SurfaceView</h2>
291<p>
292Android N brings synchronous movement to the {@link android.view.SurfaceView}
293class, which provides better battery performance
294than {@link android.view.TextureView} in certain cases: When rendering video or
2953D content, apps with scrolling and animated video position use less power with
296{@link android.view.SurfaceView} than with {@link android.view.TextureView}.
297</p>
298
299The {@link android.view.SurfaceView} class enables more battery-efficient compositing on
300screen, because it is composited in dedicated hardware, separately from app
301window content. As a result, it makes fewer intermediate
302copies than {@link android.view.TextureView}.
303</p>
304
305<p>
306A {@link android.view.SurfaceView} object's content position is now updated synchronously
307with the containing app content. One result of this change is that simple
308translations or scales of a video playing in a {@link android.view.SurfaceView}
309no longer produce black bars alongside the view as it moves.
310</p>
311
312<p>
313Starting with Android N, we strongly recommend that you save power by using
314{@link android.view.SurfaceView} instead of {@link android.view.TextureView}.
315</p>
316
317<h2 id="data_saver">Data Saver</h2>
318
319<div class="col-5of12" style="margin-right:1.5em;">
320<img src="{@docRoot}preview/images/datasaver.png" style="border:2px solid #ddd">
321
322<p class="img-caption" style="padding-right:2em;">
323  <strong>Figure 4.</strong> Data Saver in Settings.
324</p>
325  </div>
326
327<p>Over the life of a mobile device, the cost of a cellular data plan typically
328exceeds the cost of the device itself. For many users, cellular data is an
329expensive resource that they want to conserve. </p>
330
331<p>Android N introduces Data Saver mode, a new system service that helps reduce
332cellular data use by apps, whether roaming, near the end of the billing cycle,
333or on a small prepaid data pack. Data Saver gives users control over how apps
334use cellular data and lets developers provide more efficient service when Data
335Saver is on. </p>
336
337<p>When a user enables Data Saver in <strong>Settings</strong> and the device is
338on a metered network, the system blocks background data usage and signals apps
339to use less data in the foreground wherever possible &mdash; such as by limiting
340bit rate for streaming, reducing image quality, deferring optimistic precaching,
341and so on. Users can whitelist specific apps to allow background metered data
342usage even when Data Saver is turned on.</p>
343
344<p>Android N extends the {@link android.net.ConnectivityManager} to provide apps a
345way to <a href="{@docRoot}preview/features/data-saver.html#status">retrieve the
346user's Data Saver preferences</a> and <a
347href="{@docRoot}preview/features/data-saver.html#monitor-changes">monitor
348preference changes</a>. All apps should check whether the user has enabled Data
349Saver and make an effort to limit foreground and background data usage.</p>
350
351
352<h2 id="vulkan">Vulkan API</h2>
353
354<p>
355  Android N integrates <a href="http://www.khronos.org/vulkan" class=
356  "external-link">Vulkan™</a>, a new 3D rendering API, into the platform. Like
357  <a href="https://www.khronos.org/opengles/" class="external-link">OpenGL™
358  ES</a>, Vulkan is an open standard for 3D graphics and rendering maintained
359  by the Khronos Group.
360</p>
361
362<p>
363  Vulkan is designed from the ground up to minimize CPU overhead in the driver,
364  and allow your application to control GPU operation more directly. Vulkan
365  also enables better parallelization by allowing multiple threads to perform
366  work such as command buffer construction at once.
367</p>
368
369<p>
370  Vulkan development tools and libraries are rolled into the Android NDK. They
371  include:
372</p>
373
374<ul>
375  <li>Headers
376  </li>
377
378  <li>Validation layers (debug libraries)
379  </li>
380
381  <li>SPIR-V shader compiler
382  </li>
383
384  <li>SPIR-V runtime shader compilation library
385  </li>
386</ul>
387
388<p>
389  Vulkan is only available to apps on devices with Vulkan-capable hardware,
390  such as Nexus 5X, Nexus 6P, and Nexus Player. We're working closely with our
391  partners to bring Vulkan to more devices as soon as possible.
392</p>
393
394<p>
395  For more information, see the the <a href=
396  "{@docRoot}ndk/guides/graphics/index.html">API documentation</a>.
397</p>
398
399<h2 id="tile_api">Quick Settings Tile API</h2>
400
401
402<div style="float:right;max-width:320px">
403<img src="{@docRoot}preview/images/quicksettings.png" style="padding-left:1.5em;">
404
405<p class="img-caption" style="padding-left:2em;">
406  <strong>Figure 5.</strong> Quick Settings tiles in the notification shade.
407</p>
408
409
410  </div><p>Quick Settings is a popular and simple way to expose key settings and actions,
411directly from the notification shade. In Android N, we've expanded the scope of
412Quick Settings to make it even more useful and convenient. </p>
413
414<p>We've added more room for additional Quick Settings tiles, which users can
415access across a paginated display area by swiping left or right. We've also
416given users control over what Quick Settings tiles appear and where they are
417displayed &mdash; users can add or move tiles just by dragging and dropping them. </p>
418
419<p>For developers, Android N also adds a new API that lets you define your own
420  Quick Settings tiles to give users easy access to key controls and actions in your app.</p>
421
422<p>
423  Quick Settings tiles are reserved for controls or actions that are either
424  urgently required or frequently used, and should not be used as shortcuts to
425  launching an app.
426</p>
427
428<p>
429  Once you’ve defined your tiles, you can surface them to users, who can add
430  them to Quick Settings just by drag and drop.
431</p>
432
433<p>
434  For information about creating an app tile, see the documentation for
435  <code>android.service.quicksettings.Tile</code> in the downloadable <a href=
436  "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.
437</p>
438
439
440
441<h2 id="number-blocking">Number Blocking</h2>
442
443<p>Android N now supports number blocking in the platform and provides a
444framework API to let service providers maintain a blocked-number list. The
445default SMS app, the default phone app, and carrier apps can read from and
446write to the blocked-number list. The list is not accessible to other apps.</p>
447
448<p>By making number blocking a standard feature of the platform, Android provides
449a consistent way for apps to support number blocking across a wide range of
450devices. Among the other benefits that apps can take advantage of are:</p>
451
452<ul>
453  <li> Numbers blocked on calls are also blocked on texts
454  <li> Blocked numbers can persist across resets and devices through the Backup &amp;
455Restore feature
456  <li> Multiple apps can use the same blocked numbers list
457</ul>
458
459<p>Additionally, carrier app integration through Android means that carriers can
460read the blocked numbers list on the device and perform service-side blocking
461for the user in order to stop unwanted calls and texts from reaching the user
462through any medium, such as a VOIP endpoint or forwarding phones.</p>
463
464<p>
465  For more information, see <code>android.provider.BlockedNumberContract</code>
466  in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API
467  Reference</a>.
468</p>
469
470<h2 id="call_screening">Call Screening</h2>
471
472<p>
473  Android N allows the default phone app to screen incoming calls. The phone
474  app does this by implementing the new <code>CallScreeningService</code>,
475  which allows the phone app to perform a number of actions based on an
476  incoming call's {@link android.telecom.Call.Details Call.Details}, such as:
477</p>
478
479<ul>
480  <li> Reject the incoming call
481  <li> Do not allow the call to the call log
482  <li> Do not show the user a notification for the call
483</ul>
484
485<p>
486  For more information, see <code>android.telecom.CallScreeningService</code>
487  in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API
488  Reference</a>.
489</p>
490
491
492<h2 id="multi-locale_languages">Multi-locale Support, More Languages</h2>
493
494
495<p>Android N now lets users select <strong>multiple locales</strong> in Settings,
496to better support bilingual use-cases. Apps can use
497a new API to get the user's selected locales and then offer more sophisticated
498user experiences for multi-locale users &mdash; such as showing search results in
499multiple languages and not offering to translate webpages in a language the
500user already knows.</p>
501
502<p>Along with multi-locale support, Android N also expands the range of languages
503available to users. It offers more than 25 variants each for commonly used
504languages such as English, Spanish, French, and Arabic. It also adds partial
505support for more than 100 new languages.</p>
506
507<p>Apps can get the list of locales set by the user by calling
508<code>LocaleList.GetDefault()</code>.  To support the expanded number of locales, Android N is
509changing the way that it resolves resources. Make sure that you test and verify that your apps
510working as expected with the new resource resolution logic.</p>
511
512<p>To learn about the new resource-resolution behavior and the best practices you
513should follow, see <a href="{@docRoot}preview/features/multilingual-support.html"
514>Multilingual Support</a>.</p>
515
516
517<h2 id="emoji">New Emojis</h2>
518
519<p>
520  Android N introduces additional emojis and emoji-related features including
521  skin tone emojis and support for variation
522  selectors. If your app supports emojis,
523  follow the guidelines below to take advantage of these emoji-related features.
524</p>
525
526<ul>
527  <li>
528    <strong>Check that a device contains an emoji before inserting it.</strong>
529    To check which emojis are present in the
530    system font, use the {@link android.graphics.Paint#hasGlyph(String)} method.
531  </li>
532  <li>
533    <strong>Check that an emoji supports variation selectors.</strong>
534    Variation selectors allow you to
535    present certain emojis in color or in black-and-white.
536    On mobile devices, apps should represent emojis in color rather than black-and-white. However,
537    if your app displays emojis inline with text, then it should use the black-and-white variation.
538    To determine whether an emoji has a variation, use the variation selector.
539    For a complete list of characters with variations, review the
540    <em>emoji variation sequences</em> section of the
541    <a class="external-link"
542    href="http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants-9.0.0d1.txt">
543      Unicode documentation on variations</a>.
544  </li>
545  <li>
546    <strong>Check that an emoji supports skin tone.</strong> Android N allows users to modify the
547    rendered skin tone of emojis to their preference. Keyboard apps should provide visual
548    indications for emojis that have multiple skin tones and should allow users to
549    select the skin tone that they prefer. To determine which system emojis have
550    skin tone modifiers, use the {@link android.graphics.Paint#hasGlyph(String)}
551    method. You can determine which emojis use skin tones by reading the
552    <a class="external-link"
553    href="http://unicode.org/emoji/charts/full-emoji-list.html">
554     Unicode documentation</a>.
555  </li>
556</ul>
557
558
559<h2 id="icu4">ICU4J APIs in Android</h2>
560
561<p>
562  Android N now offers a subset of <a href=
563  "http://site.icu-project.org/">ICU4J</a> APIs in the Android framework under
564  the <code>android.icu</code> package. Migration is easy, and mostly entails
565  simply changing from the <code>com.java.icu</code> namespace to
566  <code>android.icu</code>. If you are already using an ICU4J bundle in your
567  apps, switching to the <code>android.icu</code> APIs provided in the Android
568  framework can produce substantial savings in APK size.
569</p>
570
571<p>
572  To learn more about the Android ICU4J APIs, see <a href=
573  "{@docRoot}preview/features/icu4j-framework.html">ICU4J Support</a>.
574</p>
575
576
577
578<h2 id="gles_32">OpenGL&trade; ES 3.2 API</h2>
579
580<p>Android N adds framework interfaces and platform support for OpenGL ES 3.2, including:</p>
581
582<ul>
583  <li> All extensions from the <a class="external-link"
584href="https://www.khronos.org/registry/gles/extensions/ANDROID/ANDROID_extension_pack_es31a.txt">
585Android Extension Pack</a></a> (AEP) except for <code>EXT_texture_sRGB_decode</code>.
586  <li> Floating-point framebuffers for HDR and deferred shading.
587  <li> BaseVertex draw calls to enable better batching and streaming.
588  <li> Robust buffer access control to reduce WebGL overhead.
589</ul>
590
591<p>The framework API for OpenGL ES 3.2 on Android N is provided with the
592<code>GLES32</code> class. When using OpenGL ES 3.2, be sure to declare the
593requirement in your manifest file, using the <code>&lt;uses-feature&gt;</code> tag and
594the <code>android:glEsVersion</code> attribute. </p>
595
596<p>For information about using OpenGL ES, including how to check a device's
597supported OpenGL ES version at runtime, see the <a
598href="{@docRoot}guide/topics/graphics/opengl.html">OpenGL ES API guide</a>.</p>
599
600
601<h2 id="android_tv_recording">Android TV Recording</h2>
602
603<p>Android N adds the ability to record and playback content from Android TV input
604services via new recording APIs.  Building on top of existing time-shifting
605APIs, TV input services can control what channel data can be recorded, how
606recorded sessions are saved, and manage user interaction with recorded content. </p>
607
608<p>For more information, see <a
609href="{@docRoot}preview/features/tv-recording-api.html">Android TV Recording APIs</a>.</p>
610
611
612<h2 id="android_for_work">Android for Work</h2>
613
614<p>Android for Work adds many new features and APIs for devices running Android N.
615Some highlights are below &mdash; for a complete list of changes, see
616<a href="{@docRoot}preview/features/afw.html">Android for Work Updates</a>.</p>
617
618<h3 id="work_profile_security_challenge">Work profile security challenge </h3>
619
620<p>
621  Profile owners targeting the N SDK
622  can specify a separate security challenge for apps running in
623  the work profile. The work challenge is shown when a user attempts to open
624  any work apps. Successful completion of the security challenge unlocks the
625  work profile and decrypts it if necessary. For profile owners,
626  <code>ACTION_SET_NEW_PASSWORD</code> prompts the user to set a work
627  challenge, and <code>ACTION_SET_NEW_PARENT_PROFILE_PASSWORD</code> prompts
628  the user to set a device lock.
629</p>
630
631<p>
632  Profile owners can set distinct passcode policies for the work challenge
633  (such as how long the PIN needs to be, or whether a fingerprint can be used
634  to unlock the profile) using the <code>setPasswordQuality()</code>,
635  <code>setPasswordMinimumLength()</code> and related methods. The profile
636  owner can also set the device lock using the <code>DevicePolicyManager</code>
637  instance returned by the new <code>getParentProfileInstance()</code> method.
638  Additionally, profile owners can customize the credentials screen for the
639  work challenge using the new <code>setOrganizationColor()</code> and
640  <code>setOrganizationName()</code> methods.
641</p>
642<h3 id="turn_off_work">Turn off work </h3>
643
644<p>On a device with a work profile, users can toggle work mode. When work mode is
645off the managed user is temporarily shut down, which disables work profile
646apps, background sync, and notifications. This includes the profile owner
647application. When work mode is off, the system displays a persistent status
648icon to remind the user that they can't launch work apps. The launcher
649indicates that work apps and widgets are not accessible. </p>
650
651<h3 id="always_on_vpn">Always on VPN </h3>
652
653<p>Device owners and profile owners can ensure that work apps always connect
654through a specified VPN. The system automatically starts that VPN after the
655device boots.</p>
656
657<p>
658  New <code>DevicePolicyManager</code> methods are
659  <code>setAlwaysOnVpnPackage()</code> and
660  <code>getAlwaysOnVpnPackage()</code>.
661</p>
662
663<p>Because VPN services can be bound directly by the system without app
664interaction, VPN clients need to handle new entry points for Always on VPN. As
665before, services are indicated to the system by an intent filter matching
666action <code>android.net.VpnService</code>. </p>
667
668<p>
669  Users can also manually set Always on VPN clients that implement
670  <code>VPNService</code> methods in the primary user using
671  <strong>Settings&gt;More&gt;Vpn</strong>.
672</p>
673
674<h3 id="custom_provisioning">Customized provisioning</h3>
675
676<p>
677  An application can customize the profile owner and device owner provisioning
678  flows with corporate colors and logos.
679  <code>DevicePolicyManager.EXTRA_PROVISIONING_MAIN_COLOR</code> customizes
680  flow color. <code>DevicePolicyManager.EXTRA_PROVISIONING_LOGO_URI</code>
681  customizes the flow with a corporate logo.
682</p>
683
684<h2 id="accessibility_enhancements">Accessibility Enhancements</h2>
685
686<p>Android N now offers Vision Settings directly on the Welcome screen for new
687device setup. This makes it much easier for users to discover and configure
688accessibility features on their devices, including magnification gesture, font
689size, display size, and TalkBack. </p>
690
691<p>With these accessibility features getting more prominent placement, your users
692are more likely to try your app with them enabled. Make sure you test your apps
693early with these settings enabled. You can enable them from Settings >
694Accessibility.</p>
695
696<p>Also in Android N, accessibility services can now help users with motor
697impairments to touch the screen. The new API allows building services with
698features such as face-tracking, eye-tracking, point scanning, and so on, to
699meet the needs of those users.</p>
700
701<p>For more information, see <code>android.accessibilityservice.GestureDescription</code>
702  in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.</p>
703
704
705<h2 id="direct_boot">Direct Boot</h2>
706
707<p>Direct boot improves device startup times and lets registered
708apps have limited functionality even after an unexpected reboot.
709For example, if an encrypted device reboots while the user is sleeping,
710registered alarms, messages and incoming calls can now continue to notify
711the user as normal. This also means accessibility services can also be
712  available immediately after a restart.</p>
713
714<p>Direct boot takes advantage of file based encryption in Android N
715to enable fine grained encryption policies for both system and app data.
716The system uses a device-encrypted store for select system data and explicitly
717registered app data. By default a credential-encrypted store is used for all
718  other system data, user data, apps, and app data. </p>
719
720<p>At boot, the system starts in a restricted mode with access to
721device-encrypted data only, and without general access to apps or data.
722If you have components that you want to run in this mode, you can register
723them by setting a flag in the manifest. After restart, the system activates
724registered components by broadcasting the <code>LOCKED_BOOT_COMPLETED</code>
725intent. The system ensures registered device-encrypted app data is available
726before unlock. All other data is unavailable until the User confirms their lock
727  screen credentials to decrypt it. </p>
728
729For more information, see <a href="{@docRoot}preview/features/direct-boot.html">Direct Boot</a>.</p>
730</p>
731
732<h2 id="key_attestation">Key Attestation</h2>
733
734<p>
735  Android N introduces <em>key attestation</em>, a new security tool that helps
736  you make sure that the key pairs stored within a device's <a class=
737  "external-link" href=
738  "https://source.android.com/security/keystore/"><em>hardware-backed
739  keystore</em></a> properly protect the sensitive information that your app
740  uses. By using this tool, you gain additional confidence that your app
741  interacts with keys that reside in secure hardware, even if the device
742  running your app is rooted. If you use keys from the hardware-backed keystore
743  in your apps, you should use this tool, particularly if you use the keys to
744  verify sensitive information within your app.
745</p>
746
747<p>
748  Key attestation allows you to verify that an RSA or EC key pair has been
749  created and stored in a device’s hardware-backed keystore within the device’s
750  trusted execution environment (TEE). The tool also allows you to use an
751  off-device service, such as your app's back-end server, to determine and
752  strongly verify the uses and validity of the key pair. These features provide
753  an additional level of security that protects the key pair, even if someone
754  roots the device or compromises the security of the Android platform running
755  on the device.
756</p>
757
758<p>
759  For more information, see the
760  <a href="{@docRoot}preview/features/key-attestation.html">Key Attestation</a>
761  developer documentation.
762</p>
763
764<h2 id="network_security_config">Network Security Config</h2>
765
766<p>In Android N, apps can customize the behavior of their secure (HTTPS, TLS)
767connections safely, without any code modification, by using the declarative
768<em>Network Security Config</em> instead of using the conventional
769error-prone programmatic APIs (e.g. X509TrustManager).</p>
770
771  <p>Supported features:</p>
772<ul>
773<li><b>Custom trust anchors.</b> Lets an application customize which
774Certificate Authorities (CA) are trusted for its secure connections. For
775example, trusting particular self-signed certificates or a restricted set of public CAs.
776</li>
777<li><b>Debug-only overrides.</b> Lets an application developer safely debug
778secure connections of their application without added risk to the installed
779base.
780</li>
781<li><b>Cleartext traffic opt-out.</b> Lets an application protect itself from
782accidental usage of cleartext traffic.</li>
783<li><b>Certificate pinning.</b> An advanced feature that lets an application
784  limit which server keys are trusted for secure connections.</li>
785</ul>
786
787<p>For more information, see <a
788href="{@docRoot}preview/features/security-config.html">Network Security
789Config</a>.</p>
790
791<h2 id="default_trusted_ca">Default Trusted Certificate Authority</h2>
792
793<p>By default, apps that target Android N only trust system-provided certificates
794and no longer trust user-added Certificate Authorities (CA). Apps targeting Android
795N that wish to trust user-added CAs should use the
796<a href="{@docRoot}preview/features/security-config.html">Network Security Config</a> to
797specify how user CAs should be trusted.</p>
798
799<h2 id="apk_signature_v2">APK Signature Scheme v2</h2>
800
801<p>
802  Android N introduces APK Signature Scheme v2, a new app-signing scheme that
803  offers faster app install times and more protection against unauthorized
804  alterations to APK files. By default, Android Studio 2.2 and the Android
805  Plugin for Gradle 2.2 sign your app using both APK Signature Scheme v2 and
806  the traditional signing scheme, which uses JAR signing.
807</p>
808
809<p>
810  Although we recommend applying APK Signature Scheme v2 to your app, this new
811  scheme is not mandatory. If your app doesn't build properly when using APK
812  Signature Scheme v2, you can disable the new scheme. The disabling process
813  causes Android Studio 2.2 and the Android Plugin for Gradle 2.2 to sign your
814  app using only the traditional signing scheme. To sign with only the
815  traditional scheme, open the module-level <code>build.gradle</code> file, then
816  add the line <code>v2SigningEnabled false</code> to your release signing
817  configuration:
818</p>
819
820<pre>
821  android {
822    ...
823    defaultConfig { ... }
824    signingConfigs {
825      release {
826        storeFile file("myreleasekey.keystore")
827        storePassword "password"
828        keyAlias "MyReleaseKey"
829        keyPassword "password"
830        <strong>v2SigningEnabled false</strong>
831      }
832    }
833  }
834</pre>
835
836<p class="caution"><strong>Caution: </strong> If you sign your app using APK
837  Signature Scheme v2 and make further changes to the app, the app's signature
838  is invalidated. For this reason, use tools such as <code>zipalign</code>
839  before signing your app using APK Signature Scheme v2, not after.
840</p>
841
842<p>
843  For more information, read the Android Studio documents that describe how to
844  <a href="{@docRoot}studio/publish/app-signing.html#release-mode">
845  sign an app</a> in Android Studio and how to <a href=
846  "{@docRoot}studio/build/build-variants.html#signing"> configure
847  the build file for signing apps</a> using the Android Plugin for Gradle.
848</p>
849
850<h2 id="scoped_directory_access">Scoped Directory Access</h2>
851
852<p>In Android N, apps can use new APIs to request access to specific <a
853href="{@docRoot}guide/topics/data/data-storage.html#filesExternal">external
854storage</a> directories, including directories on removable media such as SD
855cards. The new APIs greatly simplify how your application accesses standard
856external storage directories, such as the <code>Pictures</code> directory. Apps
857like photo apps can use these APIs instead of using
858<code>READ_EXTERNAL_STORAGE</code>, which grants access to all storage
859directories, or the Storage Access Framework, which makes the user navigate to
860the directory.</p>
861
862<p>Additionally, the new APIs simplify the steps a user takes to grant external
863storage access to your app. When you use the new APIs, the system uses a simple
864permissions UI that clearly details what directory the application is
865requesting access to.</p>
866
867<p>For more information, see the
868<a href="{@docRoot}preview/features/scoped-folder-access.html">Scoped
869Directory Access</a> developer documentation.</p>
870
871<h2 id="keyboard_shortcuts_helper">Keyboard Shortcuts Helper</h2>
872
873<p>
874  In Android N, the user can press <strong>Meta + /</strong> to trigger a
875  <em>Keyboard Shortcuts</em> screen that displays all shortcuts available both
876  from the system and from the app in focus. The system retrieves these
877  shortcuts automatically from the app’s menu if the shortcuts exist. You can
878  also provide your own fine-tuned shortcuts lists for the screen. You can do
879  this by overriding the new <code>Activity.onProvideKeyboardShortcuts()</code>
880  method, described in the downloadable <a href=
881  "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.
882</p>
883
884<p class="note">
885  <strong>Note:</strong> The <strong>Meta</strong> key is not present on all
886  keyboards: on a Macintosh keyboard, it is the <strong>Command</strong> key,
887  on the Windows keyboard, it is the <strong>Windows</strong> key, and on the
888  Pixel C and the Chrome OS keyboards, it is the <strong>Search</strong> key.
889</p>
890
891<p>
892  To trigger Keyboard Shortcuts Helper from anywhere in your app, call
893  {@code Activity.requestKeyboardShortcutsHelper()} for the relevant activity.
894</p>
895
896<h2 id="custom_pointer_api">
897  Custom Pointer API
898</h2>
899
900<p>
901  Android N introduces the Custom Pointer API, which lets you customize the
902  appearance, visibility, and behavior of the pointer. This capability is
903  especially useful when a user is using a mouse or touchpad to interact with
904  UI objects. The default pointer uses a standard icon. This API also includes
905  advanced functionality such as changing the pointer icon's appearance based
906  on specific mouse or touchpad movements.
907</p>
908
909<p>
910  To set a pointer icon, override the <code>onResolvePointerIcon()</code>
911  method of the <code>View</code> class. This method uses a
912  <code>PointerIcon</code> object to draw the icon that corresponds to a
913  specific motion event.
914</p>
915
916<h2 id="sustained_performance_api">Sustained Performance API</h2>
917
918<p>
919Performance can fluctuate dramatically for long-running apps, because the
920system throttles system-on-chip engines as device components reach their
921temperature limits. This fluctuation presents a moving target for app
922developers creating high-performance, long-running apps.
923</p>
924
925<p>
926To address these limitations, Android N includes support for
927<em>sustained performance mode</em>, enabling OEMs to provide hints about
928device-performance capabilities for long-running apps. App developers
929can use these hints to tune apps for a predictable,
930consistent level of device performance over long periods of time.
931</p>
932
933<p>
934App developers can try out this new API in the N Developer Preview on
935Nexus 6P devices only. To use this feature,
936set the sustained performance window flag for the window
937you want to run in sustained performance mode. Set this flag using the
938{@code Window.setSustainedPerformanceMode()} method. The system automatically
939disables this mode when the window is no longer in focus.
940</p>
941
942<h2 id="vr">VR Support</h2>
943
944<p>
945Android N adds platform support and optimizations for a new VR Mode to let developers
946build high-quality mobile VR experiences for users. There are a number of performance
947enhancements, including access to an exclusive CPU core for VR apps.
948Within your apps, you can take advantage of intelligent head-tracking,
949and stereo notifications that work for VR. Most importantly, Android N provides for
950very low latency graphics. For complete information about building VR apps for Android N,
951see the <a href="https://developers.google.com/vr/android/">Google VR SDK for Android</a>.
952</p>
953
954
955<h2 id="print_svc">Print Service Enhancements</h2>
956
957<p>
958  In Android N, print service developers can now surface additional information
959  about individual printers and print jobs.
960</p>
961
962<p>
963  When listing individual printers, a print service can now set per-printer
964  icons in two ways:
965</p>
966
967<ul>
968  <li>You can set an icon from a resource ID by calling
969  <code>PrinterInfo.Builder.setResourceIconId()</code>
970  </li>
971
972  <li>You can show an icon from the network by calling
973  <code>PrinterInfo.Builder.setHasCustomPrinterIcon()</code>, and setting a
974  callback for when the icon is requested using
975  <code>android.printservice.PrinterDiscoverySession.onRequestCustomPrinterIcon()</code>
976  </li>
977</ul>
978
979<p>
980  In addition, you can provide a per-printer activity to display additional
981  information by calling <code>PrinterInfo.Builder.setInfoIntent()</code>.
982</p>
983
984<p>
985  You can indicate the progress and status of print jobs in the print job
986  notification by calling
987  <code>android.printservice.PrintJob.setProgress()</code> and
988  <code>android.printservice.PrintJob.setStatus()</code>, respectively.
989</p>
990
991<p>
992  For more information about these methods, see the downloadable <a href=
993  "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.
994</p>
995
996<h2 id="framemetrics_api">FrameMetricsListener API</h2>
997
998<p>
999The FrameMetricsListener API allows an app to monitor its UI rendering
1000performance. The API provides this capability by exposing a streaming Pub/Sub API to transfer frame
1001timing info for the app's current window. The data returned is
1002equivalent to that which <code><a href="{@docRoot}tools/help/shell.html#shellcommands">adb shell</a>
1003dumpsys gfxinfo framestats</code> displays, but is not limited to the past 120 frames.
1004</p>
1005
1006<p>
1007You can use FrameMetricsListener to measure interaction-level UI
1008performance in production, without a USB connection. This API
1009allows collection of data at a much higher granularity than does
1010{@code adb shell dumpsys gfxinfo}. This higher granularity is possible because
1011the system can collect data for particular interactions in the app; the system
1012need not capture a global summary of the entire app’s
1013performance, or clear any global state. You can use this
1014capability to gather performance data and catch regressions in UI performance
1015for real use cases within an app.
1016</p>
1017
1018<p>
1019To monitor a window, implement the <code>FrameMetricsListener.onMetricsAvailable()</code>
1020callback method and register it on that window. For more information, refer to
1021the {@code FrameMetricsListener} class documentation in
1022the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.
1023</p>
1024
1025<p>
1026The API provides a {@code FrameMetrics} object, which contains timing data that
1027the rendering subsystem reports for various milestones in a frame lifecycle.
1028The supported metrics are: {@code UNKNOWN_DELAY_DURATION},
1029{@code INPUT_HANDLING_DURATION}, {@code ANIMATION_DURATION},
1030{@code LAYOUT_MEASURE_DURATION}, {@code DRAW_DURATION}, {@code SYNC_DURATION},
1031{@code COMMAND_ISSUE_DURATION}, {@code SWAP_BUFFERS_DURATION},
1032{@code TOTAL_DURATION}, and {@code FIRST_DRAW_FRAME}.
1033</p>
1034
1035
1036<h2 id="virtual_files">Virtual Files</h2>
1037
1038<p>
1039  In previous versions of Android, your app could use the Storage Access
1040  Framework to allow users to select files from their cloud storage accounts,
1041  such as Google Drive. However, there was no way to represent files that did
1042  not have a direct bytecode representation; every file was required to provide
1043  an input stream.
1044</p>
1045
1046<p>
1047  Android N adds the concept of <em>virtual files</em> to the Storage Access
1048  Framework. The virtual files feature allows your
1049  {@link android.provider.DocumentsProvider} to return document URIs that can be
1050  used with an {@link android.content.Intent#ACTION_VIEW} intent even if they
1051  don't have a direct bytecode representation. Android N also allows you to
1052  provide alternate formats for user files, virtual or otherwise.
1053</p>
1054
1055<p>
1056  To get a URI for a virtual document in your app, first you create an
1057  {@link android.content.Intent} to open the file picker UI. Since an app
1058  cannot directly open a virtual file by using the
1059  {@link android.content.ContentResolver#openInputStream(Uri) openInputStream()}
1060  method, your app does not receive any virtual files if you include the
1061  {@link android.content.Intent#CATEGORY_OPENABLE} category.
1062</p>
1063
1064<p>
1065  After the user has made a selection, the system calls the
1066  {@link android.app.Activity#onActivityResult onActivityResult()} method.
1067  Your app can retrieve the URI of the virtual file and get an input stream, as
1068  demonstrated in the code snippet below.
1069</p>
1070
1071<pre>
1072  // Other Activity code ...
1073
1074  final static private int REQUEST_CODE = 64;
1075
1076  // We listen to the OnActivityResult event to respond to the user's selection.
1077  &#64;Override
1078  public void onActivityResult(int requestCode, int resultCode,
1079    Intent resultData) {
1080      try {
1081        if (requestCode == REQUEST_CODE &amp;&amp;
1082            resultCode == Activity.RESULT_OK) {
1083
1084            Uri uri = null;
1085
1086            if (resultData != null) {
1087                uri = resultData.getData();
1088
1089                ContentResolver resolver = getContentResolver();
1090
1091                // Before attempting to coerce a file into a MIME type,
1092                // check to see what alternative MIME types are available to
1093                // coerce this file into.
1094                String[] streamTypes =
1095                  resolver.getStreamTypes(uri, "*/*");
1096
1097                AssetFileDescriptor descriptor =
1098                    resolver.openTypedAssetFileDescriptor(
1099                        uri,
1100                        streamTypes[0],
1101                        null);
1102
1103                // Retrieve a stream to the virtual file.
1104                InputStream inputStream = descriptor.createInputStream();
1105            }
1106        }
1107      } catch (Exception ex) {
1108        Log.e("EXCEPTION", "ERROR: ", ex);
1109      }
1110  }
1111</pre>
1112
1113<p>
1114  For more information about accessing user files, see the
1115  <a href="{@docRoot}guide/topics/providers/document-provider.html">Storage
1116  Access Frameworks guide</a>.
1117</p>
1118