Android4.4KitKat支持u盘功能

作者:  发布日期:2014-05-14 23:16:13
0
Tag标签:功能  
  • Android U 盘功能实现和分析

    u 盘功能实现结果:

    u 盘会当成 usb storage 在 Settings Storage 里面显示。

    准备工作

    内核需支持 usb host需支持 FUSE 文件系统在 FS 选项里面配置即可(CONFIG_FUSE_FS=y)。

    Android 的配置

    配置 init.<board>.rc

        mkdir /storage/udisk0 0000 system system
    mkdir /mnt/media_rw/udisk0 0700 media_rw media_rw
    service fuse_udisk0 /system/bin/sdcard -u 1023 -g 1023 -w 1023 -d /mnt/media_rw/udisk0 /storage/udisk0
    class late_start
    disabled

    配置 fstab.<board>

    /block/sda      /mnt/media_rw/udisk0  vfat  defaults  voldmanaged=udisk0:auto

    配置 overlay

       <storage android:mountPoint="/storage/udisk0"
    android:storageDescription="@string/storage_usb"
    android:primary="false"
    android:removable="true" />

    挂载过程:

    /dev/block/vold/8:1 /mnt/media_rw/udisk0 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
    /dev/fuse /storage/udisk0 fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
    root@android:/ # logcat -s Vold MountService
    --------- beginning of /dev/log/main
    --------- beginning of /dev/log/system
    I/Vold ( 820): Vold 2.1 (the revenge) firing up
    D/Vold ( 820): Volume sdcard1 state changing -1 (Initializing) -> 0 (No-Media)
    D/Vold ( 820): Volume sdcard1 state changing -1 (Initializing) -> 0 (No-Media)
    D/Vold ( 820): Volume udisk0 state changing -1 (Initializing) -> 0 (No-Media)
    D/Vold ( 820): Volume udisk0 state changing 0 (No-Media) -> 2 (Pending)
    D/Vold ( 820): Volume udisk0 state changing 2 (Pending) -> 1 (Idle-Unmounted)
    D/Vold ( 820): Volume sdcard1 state changing 0 (No-Media) -> 2 (Pending)
    D/Vold ( 820): Volume sdcard1 state changing 2 (Pending) -> 1 (Idle-Unmounted)
    D/MountService( 1587): got storage path: /storage/sdcard0 description: Internal storage primary: true removable: false emulated: true mtpReserve: 50 allowMassStorage: false maxFileSize: 0
    D/MountService( 1587): addVolumeLocked() StorageVolume:
    D/MountService( 1587): mStorageId=65537 mPath=/storage/emulated/0 mDescriptionId=17040662
    D/MountService( 1587): mPrimary=true mRemovable=false mEmulated=true mMtpReserveSpace=50
    D/MountService( 1587): mAllowMassStorage=false mMaxFileSize=0 mOwner=UserHandle{0} mUuid=null
    D/MountService( 1587): mUserLabel=null mState=null
    D/MountService( 1587): got storage path: /storage/sdcard1 description: SD card primary: false removable: true emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 4294967296
    D/MountService( 1587): addVolumeLocked() StorageVolume:
    D/MountService( 1587): mStorageId=0 mPath=/storage/sdcard1 mDescriptionId=17040663 mPrimary=false
    D/MountService( 1587): mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false
    D/MountService( 1587): mMaxFileSize=4294967296 mOwner=null mUuid=null mUserLabel=null mState=null
    D/MountService( 1587): got storage path: /storage/udisk0 description: USB storage primary: false removable: true emulated: false mtpReserve: 0 allowMassStorage: false maxFileSize: 0
    D/MountService( 1587): addVolumeLocked() StorageVolume:
    D/MountService( 1587): mStorageId=0 mPath=/storage/udisk0 mDescriptionId=17040664 mPrimary=false
    D/MountService( 1587): mRemovable=true mEmulated=false mMtpReserveSpace=0 mAllowMassStorage=false
    D/MountService( 1587): mMaxFileSize=0 mOwner=null mUuid=null mUserLabel=null mState=null
    W/MountService( 1587): Duplicate state transition (unmounted -> unmounted) for /storage/sdcard1
    D/MountService( 1587): volume state changed for /storage/sdcard1 (unmounted -> removed)
    W/MountService( 1587): Duplicate state transition (unmounted -> unmounted) for /storage/udisk0
    I/Vold ( 820): /dev/block/vold/8:1 being considered for volume udisk0
    D/Vold ( 820): Volume udisk0 state changing 1 (Idle-Unmounted) -> 3 (Checking)
    D/MountService( 1587): volume state changed for /storage/udisk0 (unmounted -> checking)
    D/MountService( 1587): sendStorageIntent Intent { act=android.intent.action.MEDIA_CHECKING dat=file:///storage/udisk0 (has extras) } to UserHandle{-1}
    I/Vold ( 820): Filesystem check completed OK
    D/Vold ( 820): blkid identified as /dev/block/vold/8:1: UUID="402E-0EE3" TYPE="vfat"
    D/Vold ( 820): Volume udisk0 state changing 3 (Checking) -> 4 (Mounted)
    D/MountService( 1587): volume state changed for /storage/udisk0 (checking -> mounted)
    D/MountService( 1587): sendStorageIntent Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///storage/udisk0 (has extras) } to UserHandle{-1}
    W/MountService( 1587): Duplicate state transition (mounted -> mounted) for /storage/emulated/0

    Vold 解析 fstab 文件

    在 Android 4.4 中 Vold 会解析 vold.<hardware> 文件

       property_get("ro.hardware", propbuf, "");
    snprintf(fstab_filename, sizeof(fstab_filename), FSTAB_PREFIX"%s", propbuf); fstab = fs_mgr_read_fstab(fstab_filename);
    if (!fstab) {
    SLOGE("failed to open %s\n", fstab_filename);
    return -1;
    }

    其中 #define FSTAB_PREFIX "/fstab." 所以配置的 fatab 文件必须放在根目录 Vold 是 android 的后台进程将会一直监听 fatab 里面标记为 voldmanaged 的项目 如果没有标记则略过。没有标记的项目。可以交给 init 的 mount 命令处理但是不会监听所以你可以将recovery 和 cache 目录这样只需启动是挂载的目录项放在 fatab 里面交给 init 的 mount 命令处理例如三星 device/samsung/manta/fstab.manta

    # Android fstab file.
    #<src> <mnt_point> <type> <mnt_flags and opt
    ions> <fs_mgr_flags>
    # The filesystem that contains the filesystem checker binary (typically /system) cannot
    # specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK /dev/block/platform/dw_mmc.0/by-name/system /system ext4 ro
    wait
    /dev/block/platform/dw_mmc.0/by-name/cache /cache ext4 noatime,nosuid,nodev,nombl
    k_io_submit,errors=panic wait,check
    /dev/block/platform/dw_mmc.0/by-name/userdata /data ext4 noatime,nosuid,nodev,nombl
    k_io_submit,errors=panic wait,check,encryptable=/dev/block/platform/dw_mmc.0/by-name/metadata
    /dev/block/platform/dw_mmc.0/by-name/efs /factory ext4 noatime,nosuid,nodev,ro
    wait
    /dev/block/platform/dw_mmc.0/by-name/boot /boot emmc defaults
    defaults
    /dev/block/platform/dw_mmc.0/by-name/recovery /recovery emmc defaults
    defaults
    /dev/block/platform/dw_mmc.0/by-name/misc /misc emmc defaults
    defaults
    /dev/block/mmcblk0boot0 /bootloader emmc defaults
    defaults

    在系统启动调用 mount :

    on fs
    mkdir /factory 0775 radio radio mount_all /fstab.manta

    同理 init 的 mount 也会忽略标记为 voldmanaged 的项目 init 的 mount 命令与 vold 的 mount 管理大有不同两者不能混用。

    MountService 与 Vold 联合挂载 u 盘

    MountService 与 Vold 会建立 socket 通信具体的挂载操作都是下发命令交给 Vold 去完成。 MountService 会解析我们配置的 storage_list.xml

       private void readStorageListLocked() {
    mVolumes.clear();
    mVolumeStates.clear(); Resources resources = mContext.getResources(); int id = com.android.internal.R.xml.storage_list;
    XmlResourceParser parser = resources.getXml(id);
    AttributeSet attrs = Xml.asAttributeSet(parser); try {
    XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
    while (true) {
    XmlUtils.nextElement(parser);

    Vold 获取到 list 里面的设备变化时将会发送 state change event MountService 在 onEvent 处理各种不同 state 其中获取到设备插入将会执行挂载操作:

                if (code == VoldResponseCode.VolumeDiskInserted) {
    new Thread("MountService#VolumeDiskInserted") {
    @Override
    public void run() {
    try {
    int rc;
    if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
    Slog.w(TAG, String.format("Insertion mount failed (%d)", rc));
    }
    } catch (Exception ex) {
    Slog.w(TAG, "Failed to mount media on insertion", ex);
    }
    }
    }.start();

    doMountVolume 只是发送 mount 命令给 Vold

       private int doMountVolume(String path) {
    int rc = StorageResultCode.OperationSucceeded; final StorageVolume volume;
    synchronized (mVolumesLock) {
    volume = mVolumesByPath.get(path);
    } if (DEBUG_EVENTS) Slog.i(TAG, "doMountVolume: Mouting " + path);
    try {
    mConnector.execute("volume", "mount", path);

    最终 Vold 里面执行相应的 mount 操作我们的 u 盘是 vfat 格式我只测试了这个格式 Linux 下的格式没有测试因为 Vold 只支持 fat 和 ext4

    int VolumeManager::mountVolume(const char *label) {
    Volume *v = lookupVolume(label); if (!v) {
    errno = ENOENT;
    return -1;
    } return v->mountVol();
    }
           if (Fat::doMount(devicePath, getMountpoint(), false, false, false,
    AID_MEDIA_RW, AID_MEDIA_RW, 0007, true)) {
    SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
    continue;

Android4.4KitKat支持u盘功能的更多相关文章

  1. Android 4.4 KitKat 支持 u 盘功能

    Android U 盘功能实现和分析 u 盘功能实现结果: u 盘会当成 usb storage 在 Settings Storage 里面显示. 准备工作 内核需支持 usb host,需支持 FU ...

  2. Ceph与OpenStack整合(仅为云主机提供云盘功能)

    1. Ceph与OpenStack整合(仅为云主机提供云盘功能) 创建: linhaifeng,最新修改: 大约1分钟以前 ceph ceph osd pool create volumes 128 ...

  3. [转帖]4412开发板/4418开发板Android4.4.4实现ble功能

    本文转自迅为论坛:http://bbs.topeetboard.com ①.4418开发板实现ble功能方法: 在4418/android/device/nexell/drone2/device.mk ...

  4. Nginx 支持 WAF 防护功能实战

    WAF(Web Application Firewall),中文名称叫做“Web应用防火墙 WAF的定义是这样的:Web应用防火墙是通过执行一系列针对HTTP/HTTPS的安全策略来专门为Web应用提 ...

  5. 数据恢复软件使用经验-支持U盘,手机SD卡,硬盘数据,解决图片恢复后打不开的问题

    数据恢复软件使用经验-支持U盘,手机SD卡,硬盘数据.解决图片恢复后打不开的问题. 用过非常多数据恢复软件.最早EasyRecovery pro.恢复过U盘.手机SD卡,硬盘数据.但如今下载不了最新版 ...

  6. Ubuntu14.04不支持U盘exfat格式该如何解决

    转: http://www.jb51.net/os/Ubuntu/275158.html exfat是U盘的文件系统,很多系统都支持exfat格式的使用,但Ubuntu系统并不支持exfat格式,要如 ...

  7. javascript如何判断访问网页的设备及是否支持触屏功能

    var system ={}; var p = navigator.platform; system.win = p.indexOf("Win") == 0; system.mac ...

  8. KDB支持单步调试功能(ARM架构)

    0    实践发现KDB不支持step调试功能 (本文针对的是arm CotexA9架构,各种架构的实现方式不一样,    X86的好像已经支持,不过本人没有验证过) 1    首先看下要调试的代码段 ...

  9. 安装nginx+ngx_lua支持WAF防护功能

    安装nginx+ngx_lua支持WAF防护功能 nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.nginx以 ...

随机推荐

  1. Hunters

    Hunters Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submi ...

  2. how to increase an regular array length in java?

    Arrays in Java are of fixed size that is specified when they are declared. To increase the size of t ...

  3. PAC全自动脚本代理

    Proxy 极低成本绕过GFW的一个PAC代理 Download proxy.zip Proxy 轻量级的FQ工具,不需要安装客户端.可以设置系统代理,也可以设置浏览器代理或者配合SS等插件使用. 免 ...

  4. Qt 5简介

    Qt 5简介 Qt 5概要介绍 在Qt 5这个版本中,Qt Quick成为了Qt的核心.但是Qt 5也继续提供了本地C++强大的功能来完成更好的用户体验,也提供了对OpenGL/OpenGL ES图形 ...

  5. 【dfs 回溯】 zoj 1004

    题意:给出一个源字符串和一个目标字符串,打出所有符合stack操作的i,o串使得对于源字符串的操作能变为目标字符串 思路:搜索,回溯. 之前想过是不是队列,觉得不对那样bfs是求最优解了:也想过用结构 ...

  6. runtime获取一个控件的所有属性

    控件的有些属性API并没有开放,可以通过runtime查看: unsigned int count; Ivar *ivarList = class_copyIvarList([UITextField ...

  7. 一个不错的PHP文件页面缓存类

    在php中缓存分类数据库缓存,文件缓存和内存缓存,下面我来给各位同学详细介绍PHP文件缓存类实现代码,有需要了解的朋友可参考. 页面缓存类 <?php    /*    * 缓存类    cac ...

  8. gradle 构建spring源码时候报错

    这是使用jdk1.7报的错,我卸载1.7后使用1.8 ,就可以了

  9. Android抽屉(SlidingDrawer --类似android通知栏下拉效果)

    Android抽屉(SlidingDrawer)的实现发 - 红黑联盟http://www.2cto.com/kf/201301/182507.html 可动态布局的Android抽屉之基础http: ...

  10. Loadrunner之脚本的调试和保存(六)

    一.调试脚本 脚本录制完毕后,按F5键或单击菜单上的RUN按钮,可以运行脚本.       在VIRTUAL USER GENERATOR中运行脚本的作用,主要是查看录制的脚本能否正常通过,如果有问题 ...