Home | History | Annotate | Download | only in storage
      1 <html devsite>
      2   <head>
      3     <title>Traditional Storage</title>
      4     <meta name="project_path" value="/_project.yaml" />
      5     <meta name="book_path" value="/_book.yaml" />
      6   </head>
      7   <body>
      8   <!--
      9       Copyright 2017 The Android Open Source Project
     10 
     11       Licensed under the Apache License, Version 2.0 (the "License");
     12       you may not use this file except in compliance with the License.
     13       You may obtain a copy of the License at
     14 
     15           http://www.apache.org/licenses/LICENSE-2.0
     16 
     17       Unless required by applicable law or agreed to in writing, software
     18       distributed under the License is distributed on an "AS IS" BASIS,
     19       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20       See the License for the specific language governing permissions and
     21       limitations under the License.
     22   -->
     23 
     24 
     25 
     26 <img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_extstor.png" alt="Android external storage HAL icon"/>
     27 
     28 <p>Android supports devices with traditional storage, which is defined to be a
     29 case-insensitive filesystem with immutable POSIX permission classes and modes.
     30 The notion of traditional storage encompasses emulated and portable storage.
     31 Portable storage is defined as any external storage that is not <a href="/devices/storage/adoptable.html">
     32 adopted</a> by the
     33 system and therefore not formatted and encrypted or tied to a specific device.
     34 Because traditional external storage offers minimal protection for stored data,
     35 system code should not store sensitive data on external storage. Specifically,
     36 configuration and log files should only be stored on internal storage where
     37 they can be effectively protected.</p>
     38 
     39 <h2 id="multi-user-external-storage">Multi-user external storage</h2>
     40 <p>Starting in Android 4.2, devices can support multiple users, and external
     41 storage must meet the following constraints:</p>
     42 <ul>
     43 <li>Each user must have their own isolated primary external storage, and
     44 must not have access to the primary external storage of other users.</li>
     45 <li>The <code>/sdcard</code> path must resolve to the correct user-specific
     46 primary external storage based on the user a process is running as.</li>
     47 <li>Storage for large OBB files in the <code>Android/obb</code> directory
     48 may be shared between multiple users as an optimization.</li>
     49 <li>Secondary external storage must not be writable by apps, except in
     50 package-specific directories as allowed by synthesized permissions.</li>
     51 </ul>
     52 <p>The default platform implementation of this feature leverages Linux kernel
     53 namespaces to create isolated mount tables for each Zygote-forked process,
     54 and then uses bind mounts to offer the correct user-specific primary external
     55 storage into that private namespace.</p>
     56 <p>At boot, the system mounts a single emulated external storage FUSE daemon
     57 at <code>EMULATED_STORAGE_SOURCE</code>, which is hidden from apps. After
     58 the Zygote forks, it bind mounts the appropriate user-specific subdirectory
     59 from under the FUSE daemon to <code>EMULATED_STORAGE_TARGET</code> so that
     60 external storage paths resolve correctly for the app. Because an app lacks
     61 accessible mount points for other users' storage, they can only access
     62 storage for the user it was started as.</p>
     63 <p>This implementation also uses the shared subtree kernel feature to
     64 propagate mount events from the default root namespace into app namespaces,
     65 which ensures that features like ASEC containers and OBB mounting continue
     66 working correctly. It does this by mounting the rootfs as shared, and then
     67 remounting it as slave after each Zygote namespace is created.</p>
     68 
     69 <h2 id="multiple-external-storage-devices">Multiple external storage devices</h2>
     70 <p>Starting in Android 4.4, multiple external storage devices are surfaced
     71 to developers through <code>Context.getExternalFilesDirs()</code>,
     72 <code>Context.getExternalCacheDirs()</code>, and
     73 <code>Context.getObbDirs()</code>.</p>
     74 </p>External storage devices surfaced through these APIs must be a
     75 semi-permanent part of the device (such as an SD card slot in a battery
     76 compartment). Developers expect data stored in these locations to be
     77 available over long periods of time. For this reason, transient storage
     78 devices (such as USB mass storage drives) should not be surfaced through
     79 these APIs.</p>
     80 <p>The <code>WRITE_EXTERNAL_STORAGE</code> permission must only grant write
     81 access to the primary external storage on a device. Apps must not be
     82 allowed to write to secondary external storage devices, except in their
     83 package-specific directories as allowed by synthesized
     84 permissions. Restricting writes in this way ensures the system can clean
     85 up files when applications are uninstalled.</p>
     86 
     87 <h2 id=support_usb_media>USB media support</h2>
     88 
     89 <p>Android 6.0 supports portable storage devices which are only connected to the
     90 device for a short period of time, like USB flash drives. When a user inserts a
     91 new portable device, the platform shows a notification to let them copy or
     92 manage the contents of that device.</p>
     93 
     94 <p>In Android 6.0, any device that is not adopted is considered portable. Because
     95 portable storage is connected for only a short time, the platform avoids heavy
     96 operations such as media scanning. Third-party apps must go through the <a href="https://developer.android.com/guide/topics/providers/document-provider.html">Storage Access Framework</a> to interact with files on portable storage; direct access is explicitly
     97 blocked for privacy and security reasons.</p>
     98 
     99   </body>
    100 </html>
    101