Clay Murphy | 1b58a2f | 2015-08-24 17:57:30 -0700 | [diff] [blame] | 1 | page.title=Storage |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 2 | @jd:body |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 3 | <!-- |
Heidi von Markham | 1e7b8b7 | 2015-03-09 10:13:48 -0700 | [diff] [blame] | 4 | Copyright 2015 The Android Open Source Project |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 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 |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 8 | http://www.apache.org/licenses/LICENSE-2.0 |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 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 | --> |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 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> |
Ken Sumrall | 93c0b9c | 2013-04-16 15:43:27 -0700 | [diff] [blame] | 22 | |
Heidi von Markham | b493fb6 | 2015-03-25 12:35:11 -0700 | [diff] [blame] | 23 | <img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_extstor.png" alt="Android external storage HAL icon"/> |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 24 | <p>Android has evolved over time to support a wide variety of storage device types |
| 25 | and features. All versions of Android support devices with <a href="{@docRoot}devices/storage/traditional.html">traditional storage</a>, |
| 26 | which includes portable and emulated storage. <em>Portable</em> storage can be provided by physical media, like an SD card or USB, that is for |
| 27 | temporary data transfer/ file storage. The physical media may remain with the |
| 28 | device for an extended period of time, but is not tied to the device and may be |
| 29 | removed. SD cards have been available as portable storage since Android 1.0; |
| 30 | Android 6.0 added USB support. <em>Emulated</em> storage is provided by exposing a portion of internal storage through an |
| 31 | emulation layer and has been available since Android 3.0.</p> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 32 | |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 33 | <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 |
| 34 | encrypted and formatted to behave like internal storage. Adoptable storage can |
| 35 | store all types of application data. </p> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 36 | |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 37 | <h2 id=permissions>Permissions</h2> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 38 | <p>Access to external storage is protected by various Android |
| 39 | permissions. Starting in Android 1.0, write access is protected with the |
| 40 | <code>WRITE_EXTERNAL_STORAGE</code> permission. Starting in Android 4.1, |
| 41 | read access is protected with the <code>READ_EXTERNAL_STORAGE</code> |
| 42 | permission.</p> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 43 | <p>Starting in Android 4.4, the owner, group and modes of files on external |
| 44 | storage devices are now synthesized based on directory structure. This |
| 45 | enables apps to manage their package-specific directories on external |
| 46 | storage without requiring they hold the broad |
| 47 | <code>WRITE_EXTERNAL_STORAGE</code> permission. For example, the app with |
| 48 | package name <code>com.example.foo</code> can now freely access |
| 49 | <code>Android/data/com.example.foo/</code> on external storage devices with |
| 50 | no permissions. These synthesized permissions are accomplished by wrapping |
| 51 | raw storage devices in a FUSE daemon.</p> |
| 52 | |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 53 | <h3 id=runtime_permissions>Runtime permissions</h3> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 54 | |
| 55 | |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 56 | <p>Android 6.0 introduces a new <a href="{@docRoot}devices/tech/config/runtime_perms.html">runtime permissions</a> model where apps request |
| 57 | capabilities 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 |
| 58 | killing or restarting already-running apps. It does this by maintaining three |
| 59 | distinct views of all mounted storage devices:</p> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 60 | |
Robert Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 61 | <ul> |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 62 | <li><code>/mnt/runtime/default</code> is shown to apps with no special storage permissions, and to the root |
| 63 | namespace 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 Ly | 35f2fda | 2013-01-29 16:27:05 -0800 | [diff] [blame] | 66 | </ul> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 67 | |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 68 | <p>At Zygote fork time, we create a mount namespace for each running app and bind |
| 69 | mount the appropriate initial view into place. Later, when runtime permissions |
| 70 | are granted, <code>vold</code> jumps into the mount namespace of already-running apps and bind mounts the |
| 71 | upgraded view into place. Note that permission downgrades always result in the |
| 72 | app being killed.</p> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 73 | |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 74 | <p>The <code>setns()</code> functionality used to implement this feature requires at least Linux 3.8, but |
| 75 | patches have been backported successfully to Linux 3.4. The <code>PermissionsHostTest</code> CTS test can be used to verify correct kernel behavior.</p> |
Jeff Sharkey | 790c02d | 2013-10-18 13:57:33 -0700 | [diff] [blame] | 76 | |
Danielle Roberts | 20334fc | 2015-09-24 16:36:35 -0700 | [diff] [blame] | 77 | <p>In Android 6.0, third-party apps don’t have access to the <code>sdcard_r</code> and <code>sdcard_rw</code> GIDs. Instead, access is controlled by mounting only the appropriate runtime |
| 78 | view in place for that app. Cross-user interactions are blocked using the <code>everybody</code> GID.</p> |