blob: 7e62fe65ce7c6b9a787ff5b85fdfc29a56a16d99 [file] [log] [blame]
Clay Murphy1b58a2f2015-08-24 17:57:30 -07001page.title=Storage
Robert Ly35f2fda2013-01-29 16:27:05 -08002@jd:body
Robert Ly35f2fda2013-01-29 16:27:05 -08003<!--
Heidi von Markham1e7b8b72015-03-09 10:13:48 -07004 Copyright 2015 The Android Open Source Project
Robert Ly35f2fda2013-01-29 16:27:05 -08005 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
Robert Ly35f2fda2013-01-29 16:27:05 -08008 http://www.apache.org/licenses/LICENSE-2.0
Robert Ly35f2fda2013-01-29 16:27:05 -08009 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-->
Danielle Roberts20334fc2015-09-24 16:36:35 -070015<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>
Ken Sumrall93c0b9c2013-04-16 15:43:27 -070022
Heidi von Markhamb493fb62015-03-25 12:35:11 -070023<img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_extstor.png" alt="Android external storage HAL icon"/>
Danielle Roberts20334fc2015-09-24 16:36:35 -070024<p>Android has evolved over time to support a wide variety of storage device types
25and features. All versions of Android support devices with <a href="{@docRoot}devices/storage/traditional.html">traditional storage</a>,
26which includes portable and emulated storage. <em>Portable</em> storage can be provided by physical media, like an SD card or USB, that is for
27temporary data transfer/ file storage. The physical media may remain with the
28device for an extended period of time, but is not tied to the device and may be
29removed. SD cards have been available as portable storage since Android 1.0;
30Android 6.0 added USB support. <em>Emulated</em> storage is provided by exposing a portion of internal storage through an
31emulation layer and has been available since Android 3.0.</p>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070032
Danielle Roberts20334fc2015-09-24 16:36:35 -070033<p>Starting in Android 6.0, Android supports <a href="{@docRoot}devices/storage/adoptable.html"><em>adoptable</em> storage</a>, which is provided by physical media, like an SD card or USB, that is
34encrypted and formatted to behave like internal storage. Adoptable storage can
35store all types of application data. </p>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070036
Danielle Roberts20334fc2015-09-24 16:36:35 -070037<h2 id=permissions>Permissions</h2>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070038<p>Access to external storage is protected by various Android
39permissions. Starting in Android 1.0, write access is protected with the
40<code>WRITE_EXTERNAL_STORAGE</code> permission. Starting in Android 4.1,
41read access is protected with the <code>READ_EXTERNAL_STORAGE</code>
42permission.</p>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070043<p>Starting in Android 4.4, the owner, group and modes of files on external
44storage devices are now synthesized based on directory structure. This
45enables apps to manage their package-specific directories on external
46storage without requiring they hold the broad
47<code>WRITE_EXTERNAL_STORAGE</code> permission. For example, the app with
48package name <code>com.example.foo</code> can now freely access
49<code>Android/data/com.example.foo/</code> on external storage devices with
50no permissions. These synthesized permissions are accomplished by wrapping
51raw storage devices in a FUSE daemon.</p>
52
Danielle Roberts20334fc2015-09-24 16:36:35 -070053<h3 id=runtime_permissions>Runtime permissions</h3>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070054
55
Danielle Roberts20334fc2015-09-24 16:36:35 -070056<p>Android 6.0 introduces a new <a href="{@docRoot}devices/tech/config/runtime_perms.html">runtime permissions</a> model where apps request
57capabilities when needed at runtime. Because the new model includes the <code>READ/WRITE_EXTERNAL_STORAGE</code> permissions, the platform needs to dynamically grant storage access without
58killing or restarting already-running apps. It does this by maintaining three
59distinct views of all mounted storage devices:</p>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070060
Robert Ly35f2fda2013-01-29 16:27:05 -080061<ul>
Danielle Roberts20334fc2015-09-24 16:36:35 -070062 <li><code>/mnt/runtime/default</code> is shown to apps with no special storage permissions, and to the root
63namespace where <code>adbd</code> and other system components live.
64 <li><code>/mnt/runtime/read</code> is shown to apps with <code>READ_EXTERNAL_STORAGE</code>
65 <li><code>/mnt/runtime/write</code> is shown to apps with <code>WRITE_EXTERNAL_STORAGE</code>
Robert Ly35f2fda2013-01-29 16:27:05 -080066</ul>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070067
Danielle Roberts20334fc2015-09-24 16:36:35 -070068<p>At Zygote fork time, we create a mount namespace for each running app and bind
69mount the appropriate initial view into place. Later, when runtime permissions
70are granted, <code>vold</code> jumps into the mount namespace of already-running apps and bind mounts the
71upgraded view into place. Note that permission downgrades always result in the
72app being killed.</p>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070073
Danielle Roberts20334fc2015-09-24 16:36:35 -070074<p>The <code>setns()</code> functionality used to implement this feature requires at least Linux 3.8, but
75patches have been backported successfully to Linux 3.4. The <code>PermissionsHostTest</code> CTS test can be used to verify correct kernel behavior.</p>
Jeff Sharkey790c02d2013-10-18 13:57:33 -070076
Danielle Roberts20334fc2015-09-24 16:36:35 -070077<p>In Android 6.0, third-party apps dont have access to the <code>sdcard_r</code> and <code>sdcard_rw</code> GIDs. Instead, access is controlled by mounting only the appropriate runtime
78view in place for that app. Cross-user interactions are blocked using the <code>everybody</code> GID.</p>