安卓挂载tf卡到自定义目录

需求

最近有个需求,为了兼容之前的固件,需要把tf卡映射到指定路径.然后通过查询资料,最简单的方法就是在挂载的时候进行一个链接操作.实际只需要修改vold可执行文件就可以了.

修改方法

只需要修改如下文件
在这里插入图片描述
PublicVolume.cpp中修改如下:

status_t PublicVolume::doMount() {
    // TODO: expand to support mounting other filesystems
    readMetadata();
	LOG(ERROR) << getId() << "  filesystem " << mFsType;
	.
	.
	.
	.
	.
	.
	/* Modify by arunboy 20191128 */
	/*在return前面添加一个链接函数*/
    linkExternal();
	
    return OK;
}

/* Modify by arunboy 20191128 */
void PublicVolume::linkExternal() {
    std::string source(getPath());
	
    std::string target("/mnt/media");//自定义的链接路径
	
    if (TEMP_FAILURE_RETRY(unlink(target.c_str()))) {
        if (errno != ENOENT) {
            LOG(VERBOSE) << "Failed to unlink " << target.c_str() << strerror(errno);
        }
    }
	
    LOG(DEBUG) << "Linking " << source << " to " << target;
    if (TEMP_FAILURE_RETRY(symlink(source.c_str(), target.c_str()))) {
		LOG(ERROR) << "Failed to link " << source.c_str() << " to "
			<< target.c_str() <<  strerror(errno);
    }
}

编译会报错 需要在PublicVolume.h中声明一下这个函数.然后push到机器里面就可以,每次插入的时候会链接到指定的路径下面.如果文件存在,则会链接失败.

笔记

有一个切换tf卡和内部存储的顺序的地方记录一下.
framework/base/core/java/android/os/Environment.java

@@ -83,10 +85,25 @@ public class Environment {
             final StorageVolume[] volumes = StorageManager.getVolumeList(mUserId,
                     StorageManager.FLAG_FOR_WRITE);
             final File[] files = new File[volumes.length];
+                       /* Modify by arunboy 20191128 */
+                       //final File[] files_changer = new File[1];
+
             for (int i = 0; i < volumes.length; i++) {
                 files[i] = volumes[i].getPathFile();
             }
-            return files;
+
+                       /* Modify by arunboy 20191128 */
+                       /*if (PropertiesStringParser.checkMatch(
+                             SystemProperties.get("custom.exchange.storage", "dummy"),
+                             SystemProperties.get("custom.client.id", "YMYG"))) {
+                  if(volumes.length == 2) {
+                                       files_changer[0] = files[0];
+                                       files[0] = files[1];
+                                       files[1] = files_changer[0];
+                               }
+                   }*/
+
+                       return files;
         }


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值