天天看点

Android关闭SdcardFS

Author:Gary

Date:2019-8-26

参考博客:https://blog.csdn.net/pen_cil/article/details/79842706

由于项目先在Android6上进行实现的,现需要移植到Android8上。但是Android8上启用了SdcardFS,与原有设计中的Fuse不符,重新适配SdcardFS工作量比较大,找到如下方法可以关闭SdcardFS使用旧的Fuse文件系统:

打开安卓目录下的文件:system/core/sdcard/sdcard.cpp,第412行:

static bool supports_sdcardfs(void) {
    std::string filesystems;
    if (!android::base::ReadFileToString("/proc/filesystems", &filesystems)) {
        PLOG(ERROR) << "Could not read /proc/filesystems";
        return false;
    }
    for (const auto& fs : android::base::Split(filesystems, "\n")) {
        if (fs.find("sdcardfs") != std::string::npos) return true;
    }
    return false;
}
           

添加一行,直接返回false即可:

static bool supports_sdcardfs(void) {
	return false;
    std::string filesystems;
    if (!android::base::ReadFileToString("/proc/filesystems", &filesystems)) {
        PLOG(ERROR) << "Could not read /proc/filesystems";
        return false;
    }
    for (const auto& fs : android::base::Split(filesystems, "\n")) {
        if (fs.find("sdcardfs") != std::string::npos) return true;
    }
    return false;
}
           

修改完成后重新编译刷入,在adb shell中输入mount可以看到已经变成了fuse文件系统:

Android关闭SdcardFS