Android recognition/mounting of USB flash drives

Source: Internet
Author: User

The author directly mounted the USB flash drive to the SD card. My machine is a MTK6575 platform that supports sdcard and sdcard2. You can manually mount the USB flash disk to sdcard2 to identify the USB flash disk, but this is only a temporary solution, because sdcard2 and usb may conflict with each other. For example, if two devices have files of the same name in the same directory, only one file can be identified.
To mount a USB flash drive, you need to modify several files:

1. Modify vold. fstab
Add a dev_mount udisk/mnt/udisk auto/devices/platform/mt_usb/usb1
Ii. Modify init. rc
1,
In
# Create mountpoints
Add one
Mkdir/mnt/udisk 0076 system
2,
In
# Backwards Compat
Add one
Symlink/mnt/udisk
3. Modify storage_list.xml. This file is called in the readStorageList method of frameworks/base/services/java/com/android/server/MountService. java.

[Java]
Private void readStorageList (Resources resources ){
MVolumes. clear ();
MVolumeMap. clear ();
Int id = com. android. internal. R. xml. storage_list;
XmlResourceParser parser = resources. getXml (id );
AttributeSet attrs = Xml. asAttributeSet (parser );
// Storage_list.xml will be parsed here, and the device path (such as "mnt/sdcard") of the external storage room will be broadcast to the upper layer, after receiving the broadcast, the upper layer scans the device based on the path.
...
}

The storage_list.xml file that comes with the system is in the frameworks/base/core/res/xml directory. The content is as follows:
[Html]
<StorageList xmlns: android = "http://schemas.android.com/apk/res/android">
<! -- Removable is not set in nosdcard product -->
<Storage android: mountPoint = "/mnt/sdcard"
Android: storageDescription = "@ string/storage_sd_card"
Android: removable = "true"
Android: primary = "true"/>
 
</StorageList>
For the first time, I added
[Html]
<Storage android: mountPoint = "/mnt/udisk"
Android: storageDescription = "@ string/storage_sd_card"
Android: removable = "true"
Android: primary = "false"/>
The test is invalid after re-compilation. Because MTK platform code is used, storage_list.xml may be overwritten by MTK code. Therefore, storage_list.xml is searched in the source code and found in the following directory.
./Mediatek/custom/{project name}/resource_overlay/generic/frameworks/base/core/res/xml/storage_list.xml

./Mediatek/custom/{project name}/resource_overlay/generic_emmc/frameworks/base/core/res/xml/storage_list.xml

./Mediatek/custom/{project name}/resource_overlay/generic_nand/frameworks/base/core/res/xml/storage_list.xml
For the sake of security, I added the following code to these three files:
[Html]
<Storage android: mountPoint = "/mnt/udisk"
Android: storageDescription = "@ string/storage_usb"
Android: removable = "true"
Android: primary = "false"/>
After you try again, you can identify the USB flash drive. There will be some differences in the modification methods of different platforms. The method here is for reference only.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.