频道栏目
首页 > 程序开发 > 移动开发 > Android > 正文
Android官方资料--Device Configuration
2017-02-10 09:39:45         来源:rockly89的博客  
收藏   我要投稿

Device Configuration

IN THIS DOCUMENT

External storage is managed by a combination of thevoldinit service andMountServicesystem service. Mounting of physical external storage volumes is handled byvold, which performs staging operations to prepare the media before exposing it to apps.

File mappings


For Android 4.2.2 and earlier, the device-specificvold.fstabconfiguration file defines mappings from sysfs devices to filesystem mount points, and each line follows this format:

dev_mount 
  • label: Label for the volume.
  • mount_point: Filesystem path where the volume should be mounted.
  • partition: Partition number (1 based), or 'auto' for first usable partition.
  • sysfs_path: One or more sysfs paths to devices that can provide this mount point. Separated by spaces, and each must start with/.
  • flags: Optional comma separated list of flags, must not contain/. Possible values includenonremovableandencryptable.

For Android releases 4.3 and later, the various fstab files used by init, vold and recovery were unified in the/fstab.file. For external storage volumes that are managed byvold, the entries should have the following format:

    
  • src: A path under sysfs (usually mounted at /sys) to the device that can provide the mount point. The path must start with/.
  • mount_point: Filesystem path where the volume should be mounted.
  • type: The type of the filesystem on the volume. For external cards, this is usuallyvfat.
  • mnt_flags:Voldignores this field and it should be set todefaults
  • fs_mgr_flags:Voldignores any lines in the unified fstab that do not include thevoldmanaged=flag in this field. This flag must be followed by a label describing the card, and a partition number or the wordauto. Here is an example:voldmanaged=sdcard:auto. Other possible flags arenonremovable,encryptable=sdcard,noemulatedsd, andencryptable=userdata.

Configuration details


External storage interactions at and above the framework level are handled throughMountService. Due to configuration changes in Android 6.0 (like the removal of the storage_list.xml resource overlay), the configuration details are split into two categories.

Android 5.x and earlier

The device-specificstorage_list.xmlconfiguration file, typically provided through aframeworks/baseoverlay, defines the attributes and constraints of storage devices. Theelement contains one or moreelements, exactly one of which should be marked primary.attributes include:

 

  • mountPoint: filesystem path of this mount.
  • storageDescription: string resource that describes this mount.
  • primary: true if this mount is the primary external storage.
  • removable: true if this mount has removable media, such as a physical SD card.
  • emulated: true if this mount is emulated and is backed by internal storage, possibly using a FUSE daemon.
  • mtp-reserve: number of MB of storage that MTP should reserve for free storage. Only used when mount is marked as emulated.
  • allowMassStorage: true if this mount can be shared via USB mass storage.
  • maxFileSize: maximum file size in MB.

Devices may provide external storage by emulating a case-insensitive, permissionless filesystem backed by internal storage. One possible implementation is provided by the FUSE daemon insystem/core/sdcard, which can be added as a device-specificinit.rcservice:

# virtual sdcard daemon running as media_rw (1023)
service sdcard /system/bin/sdcard   1023 1023
  class late_start

Wheresource_pathis the backing internal storage anddest_pathis the target mount point.

When configuring a device-specificinit.rcscript, theEXTERNAL_STORAGEenvironment variable must be defined as the path to the primary external storage. The/sdcardpath must also resolve to the same location, possibly through a symlink. If a device adjusts the location of external storage between platform updates, symlinks should be created so that old paths continue working.

Android 6.0

Configuration of the storage subsystem is now concentrated in the device-specificfstabfile, and several historical static configuration files/variables have been removed to support more dynamic behavior:

  • Thestorage_list.xmlresource overlay has been removed and is no longer used by the framework. Storage devices are now configured dynamically when detected byvold.
  • TheEMULATED_STORAGE_SOURCE/TARGETenvironment variables have been removed and are no longer used by Zygote to configure user-specific mount points. Instead, user separation is now enforced with user-specific GIDs, and primary shared storage is mounted into place byvoldat runtime.
  • Developers may continue to build paths dynamically or statically depending on their use case. Including the UUID in the path identifies each card to make location clearer for developers. (For example,/storage/ABCD-1234/report.txtis clearly a different file than/storage/DCBA-4321/report.txt.)
  • The hard-coded FUSE services have been removed from device-specificinit.rcfiles and are instead forked dynamically fromvoldwhen needed.

In addition to these configuration changes, Android 6.0 includes the notion of adoptable storage. For Android 6.0 devices, any physical media that is not adopted is viewed as portable.

Adoptable storage

To indicate an adoptable storage device in thefstab, use theencryptable=userdataattribute in thefs_mgr_flagsfield. Here’s a typical definition:

/devices/platform/mtk-msdc.1/mmc_host*      auto   auto   defaults
voldmanaged=sdcard1:auto,encryptable=userdata

When a storage device is adopted, the platform erases the contents and writes a GUID partition table that defines two partitions:

  • a small emptyandroid_metapartition that is reserved for future use. The partition type GUID is 19A710A2-B3CA-11E4-B026-10604B889DCF.
  • a largeandroid_extpartition that is encrypted using dm-crypt and formatted using eitherext4orf2fsdepending on the kernel capabilities. The partition type GUID is 193D1EA4-B3CA-11E4-B075-10604B889DCF.

Portable storage

In thefstab, storage devices with thevoldmanagedattribute are considered to be portable by default unless another attribute likeencryptable=userdatais defined. For example, here’s a typical definition for USB OTG devices:

/devices/*/xhci-hcd.0.auto/usb*       auto      auto  defaults
                          voldmanaged=usb:auto

The platform usesblkidto detect filesystem types before mounting, and users can choose to format the media when the filesystem is unsupported.


点击复制链接 与好友分享!回本站首页
相关TAG标签 Android
上一篇:Android官方资料--Runtime Permissions
下一篇:Android官方资料--Configuration Examples
相关文章
图文推荐
文章
推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站