1 page.title=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 <img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_extstor.png" alt="Android external storage HAL icon"/> 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> 32 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> 36 37 <h2 id=permissions>Permissions</h2> 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> 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 53 <h3 id=runtime_permissions>Runtime permissions</h3> 54 55 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> 60 61 <ul> 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> 66 </ul> 67 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> 73 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> 76 77 <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 78 view in place for that app. Cross-user interactions are blocked using the <code>everybody</code> GID.</p> 79