需求
最近有个需求,为了兼容之前的固件,需要把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;
}