1page.title=Adoptable Storage
2@jd:body
3<!--
4    Copyright 2015 The Android Open Source Project
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8        http://www.apache.org/licenses/LICENSE-2.0
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14-->
15<div id="qv-wrapper">
16  <div id="qv">
17    <h2>In this document</h2>
18    <ol id="auto-toc">
19    </ol>
20  </div>
21</div>
22
23
24<p>Android has always supported external storage accessories (such as SD cards), but
25these accessories were historically limited to simple file storage, due to
26their expected impermanence and the minimal data protection offered to
27<a href="{@docRoot}devices/storage/traditional.html">traditional external storage</a>.
28Android 6.0 introduces the ability to
29<a href="http://developer.android.com/about/versions/marshmallow/android-6.0.html#adoptable-storage">adopt</a>
30external storage media to act like internal storage.</p>
31
32<p>When external storage media is adopted, it’s formatted and encrypted to only
33work with a single Android device at a time. Because the media is strongly tied
34to the Android device that adopted it, it can safely store both apps and
35private data for all users.</p>
36
37<p>When users insert new storage media (such as an SD card) in an adoptable
38location, Android asks them how they want to use the media. They can choose to
39adopt the media, which formats and encrypts it, or they can continue using it
40as-is for simple file storage. If they choose to adopt, the platform offers to
41migrate the primary shared storage contents (typically mounted at <code>/sdcard</code>)
42to the newly adopted media, freeing up valuable space on internal storage.
43Unlike traditional storage, which is limited to 2TB due to its use of
44<a href="https://en.wikipedia.org/wiki/Master_boot_record">MBR</a>, adoptable
45storage uses <a href="https://en.wikipedia.org/wiki/GUID_Partition_Table">GPT</a>
46and therefore has file storage limit of ~9ZB.</p>
47
48<p>Apps can be placed on adopted storage media only when the developer has
49indicated support through the <code>android:installLocation</code> attribute.
50New installs of supported apps are automatically placed on the
51storage device with the most free space, and users can move supported apps
52between storage devices in the <em>Settings</em> app. Apps moved to adopted
53media are remembered while the media is ejected,
54and return when the media is reinserted.</p>
55
56<h2 id=security>Security</h2>
57
58
59<p>The platform randomly generates an encryption key for each adopted device,
60and that key is stored on the internal storage of the Android device. This
61effectively makes the adopted media as secure as internal storage. Keys are
62associated with adopted devices based on the adopted partition GUID. The
63adopted device is encrypted using <code>dm-crypt</code> configured with the
64<code>aes-cbc-essiv:sha256</code> algorithm and a 128-bit key size.</p>
65
66<p>The on-disk layout of the adopted device closely mirrors the internal data
67partition, including SELinux labels, etc. When multi-user is supported on the
68Android device, the adopted storage device also supports multi-user with the
69same level of isolation as internal storage.</p>
70
71<p>Because the contents of an adopted storage device are strongly tied to the
72Android device that adopted it, the encryption keys should not be extractable
73from the parent device, and therefore the storage device can't be mounted elsewhere.</p>
74
75<h2 id=performance_and_stability>Performance and stability</h2>
76
77
78<p>Only external storage media in stable locations, such as a slot inside a
79battery compartment or behind a protective cover, should be considered for
80adoption to help avoid accidental data loss or corruption. In particular, USB
81devices connected to a phone or tablet should never be considered for adoption.
82One common exception would be an external USB drive connected to a TV-style
83device, because the entire TV is typically installed in a stable location.</p>
84
85<p>When a user adopts a new storage device, the platform runs a benchmark and
86compares its performance against internal storage. If the adopted device is
87significantly slower than internal storage, the platform warns the user about a
88possibly degraded experience. This benchmark was derived from the actual I/O
89behavior of popular Android apps. Currently, the AOSP implementation will only
90warn users beyond a single threshold, but device manufacturers may adapt this
91further, such as rejecting adoption completely if the card is extremely slow.</p>
92
93<p>Adopted devices must be formatted with a filesystem that supports POSIX
94permissions and extended attributes, such as <code>ext4</code> or <code>f2fs</code>.
95For optimal performance, the <code>f2fs</code> filesystem is recommended for
96flash-based storage devices.</p>
97
98<p>When performing periodic idle maintenance, the platform issues <code>FI_TRIM</code>
99to adopted media just like it does for internal storage. The current SD card
100specification does not support the <code>DISCARD</code> command; but the kernel
101instead falls back to the <code>ERASE</code> command, which SD card firmware
102may choose to use for optimization purposes.</p>
103