美文网首页
android P系统WRITE_MEDIA_STORAGE添加

android P系统WRITE_MEDIA_STORAGE添加

作者: l900 | 来源:发表于2020-08-20 21:09 被阅读0次

    由于android P 版本google把android.Permission.WRITE_MEDIA_STORAGE中sd卡的读写权限移除了,导致系统文件管理中的文件无法直接复制到SD卡,所以需要把SD卡的读写权限加上到WRITE_MEDIA_STORAGE权限中去,
    方法一、
    1、frameworks\base\data\etc\platform.xml中添加:

    <permission name="android.permission.WRITE_MEDIA_STORAGE" >
            <group gid="media_rw" />
        <group gid="sdcard_rw" />   <!-- add this -->
        </permission>
    

    2、frameworks\base\services\core\java\com\android\server\pm\PackageManagerService.java

    ...
    public int getMountMode(int uid, String packageName) {
                    if (Process.isIsolated(uid)) {
                        return Zygote.MOUNT_EXTERNAL_NONE;
                    }
                    //   modify android.Permission.WRITE_MEDIA_STORAGE add sdcard_rw permission start
                    if (checkUidPermission(WRITE_MEDIA_STORAGE, uid) == PERMISSION_GRANTED) {
                        return Zygote.MOUNT_EXTERNAL_DEFAULT;
                    }
                    // momdify end
                    if (checkUidPermission(READ_EXTERNAL_STORAGE, uid) == PERMISSION_DENIED) {
                        return Zygote.MOUNT_EXTERNAL_DEFAULT;
                    }
                    if (checkUidPermission(WRITE_EXTERNAL_STORAGE, uid) == PERMISSION_DENIED) {
                        return Zygote.MOUNT_EXTERNAL_READ;
                    }
                    return Zygote.MOUNT_EXTERNAL_WRITE;
                }
    ...
    

    方法二、修改system\vold\model\PublicVolume.cpp

    ...
    if (getMountFlags() & MountFlags::kPrimary) {
                if (execl(kFusePath, kFusePath,
                        "-u", "1023", // AID_MEDIA_RW
                        "-g", "1023", // AID_MEDIA_RW
                        "-U", std::to_string(getMountUserId()).c_str(),
                        "-w",
                        mRawPath.c_str(),
                        stableName.c_str(),
                        NULL)) {
                    PLOG(ERROR) << "Failed to exec";
                }
            } else {
                if (execl(kFusePath, kFusePath,
                        "-u", "1023", // AID_MEDIA_RW
                        "-g", "1023", // AID_MEDIA_RW
                        "-U", std::to_string(getMountUserId()).c_str(),
                        "-w", // add this
                        mRawPath.c_str(),
                        stableName.c_str(),
                        NULL)) {
                    PLOG(ERROR) << "Failed to exec";
                }
            }
    

    参考:
    https://blog.csdn.net/ch853199769/article/details/88052886
    https://blog.csdn.net/qq_27061049/article/details/93715885

    相关文章

      网友评论

          本文标题:android P系统WRITE_MEDIA_STORAGE添加

          本文链接:https://www.haomeiwen.com/subject/ckwejktx.html