Adoptable Storage

Android 6.0 引入了外部存储介质作为内部存储使用的功能,通过格式化和加密,使 SD 卡等外部介质能够安全地存储应用及用户数据,并支持多用户隔离。此特性提升了存储性能和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Adoptable Storage

Android has always supported external storage accessories (such as SD cards), but these accessories were historically limited to simple file storage, due to their expected impermanence and the minimal data protection offered to traditional external storage. Android 6.0 introduces the ability to adopt external storage media to act like internal storage.

When external storage media is adopted, it’s formatted and encrypted to only work with a single Android device at a time. Because the media is strongly tied to the Android device that adopted it, it can safely store both apps and private data for all users.

When users insert new storage media (such as an SD card) in an adoptable location, Android asks them how they want to use the media. They can choose to adopt the media, which formats and encrypts it, or they can continue using it as-is for simple file storage. If they choose to adopt, the platform offers to migrate the primary shared storage contents (typically mounted at /sdcard) to the newly adopted media, freeing up valuable space on internal storage.

Apps can be placed on adopted storage media only when the developer has indicated support through the android:installLocation attribute. New installs of supported apps are automatically placed on the storage device with the most free space, and users can move supported apps between storage devices in the Settings app. Apps moved to adopted media are remembered while the media is ejected, and return when the media is reinserted.

Security


The platform randomly generates an encryption key for each adopted device, and that key is stored on the internal storage of the Android device. This effectively makes the adopted media as secure as internal storage. Keys are associated with adopted devices based on the adopted partition GUID. The adopted device is encrypted using dm-crypt configured with the aes-cbc-essiv:sha256 algorithm and a 128-bit key size.

The on-disk layout of the adopted device closely mirrors the internal data partition, including SELinux labels, etc. When multi-user is supported on the Android device, the adopted storage device also supports multi-user with the same level of isolation as internal storage.

Because the contents of an adopted storage device are strongly tied to the Android device that adopted it, the encryption keys should not be extractable from the parent device, and therefore the storage device can't be mounted elsewhere.

Performance and stability


Only external storage media in stable locations, such as a slot inside a battery compartment or behind a protective cover, should be considered for adoption to help avoid accidental data loss or corruption. In particular, USB devices connected to a phone or tablet should never be considered for adoption. One common exception would be an external USB drive connected to a TV-style device, because the entire TV is typically installed in a stable location.

When a user adopts a new storage device, the platform runs a benchmark and compares its performance against internal storage. If the adopted device is significantly slower than internal storage, the platform warns the user about a possibly degraded experience. This benchmark was derived from the actual I/O behavior of popular Android apps. Currently, the AOSP implementation will only warn users beyond a single threshold, but device manufacturers may adapt this further, such as rejecting adoption completely if the card is extremely slow.

Adopted devices must be formatted with a filesystem that supports POSIX permissions and extended attributes, such as ext4 or f2fs. For optimal performance, the f2fs filesystem is recommended for flash-based storage devices.

When performing periodic idle maintenance, the platform issues FI_TRIM to adopted media just like it does for internal storage. The current SD card specification does not support the DISCARD command; but the kernel instead falls back to the ERASE command, which SD card firmware may choose to use for optimization purposes.

namespace fs_mgr { 32 33 struct FstabEntry { 34 std::string blk_device; 35 std::vector<std::string> user_devices; 36 std::string logical_partition_name; 37 std::string mount_point; 38 std::string fs_type; 39 unsigned long flags = 0; 40 std::string fs_options; 41 std::string fs_checkpoint_opts; 42 std::string metadata_key_dir; 43 std::string metadata_encryption_options; 44 off64_t length = 0; 45 std::string label; 46 int partnum = -1; 47 int swap_prio = -1; 48 int max_comp_streams = 0; 49 off64_t zram_size = 0; 50 off64_t reserved_size = 0; 51 off64_t readahead_size_kb = -1; 52 std::string encryption_options; 53 off64_t erase_blk_size = 0; 54 off64_t logical_blk_size = 0; 55 std::string sysfs_path; 56 std::string vbmeta_partition; 57 uint64_t zram_backingdev_size = 0; 58 std::string avb_keys; 59 std::string lowerdir; 60 std::string avb_hashtree_digest; 61 62 struct FsMgrFlags { 63 bool wait : 1; 64 bool check : 1; 65 bool crypt : 1; // Now only used to identify adoptable storage volumes 66 bool nonremovable : 1; 67 bool vold_managed : 1; 68 bool recovery_only : 1; 69 bool no_emulated_sd : 1; // No emulated sdcard daemon; sd card is the only external 70 // storage. 71 bool no_trim : 1; 72 bool file_encryption : 1; 73 bool formattable : 1; 74 bool slot_select : 1; 75 bool late_mount : 1; 76 bool no_fail : 1; 77 bool quota : 1; 78 bool avb : 1; 79 bool logical : 1; 80 bool checkpoint_blk : 1; 81 bool checkpoint_fs : 1; 82 bool first_stage_mount : 1; 83 bool slot_select_other : 1; 84 bool fs_verity : 1; 85 bool ext_meta_csum : 1; 86 bool fs_compress : 1; 87 bool overlayfs_remove_missing_lowerdir : 1; 88 /*feature-resize-v001-1-begin*/ 89 #ifdef OPLUS_FEATURE_STORAGE_RESIZE 90 //#Xuefeng.Peng@ANDROID.STORAGE.0, 2019/04/19, Add for android Q support resize 91 bool resize : 1; 92 #endif/*OPLUS_FEATURE_STORAGE*/ 93 /*feature-resize-v001-1-end*/ 94 95 #ifdef QCOM_ONLY_CHANGES 96 //add for metadata wrapped key support 97 bool wrapped_key : 1; 98 #endif /* QCOM_ONLY_CHANGES */ 99 bool is_zoned : 1; 100 } fs_mgr_flags = {}; 101 102 bool is_encryptable() const { return fs_mgr_flags.crypt; } 103 };
最新发布
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值