@NonNull
    public static File getFileForUri(@NonNull Uri uri) {
        String path = uri.getEncodedPath();
        final int splitIndex = path.indexOf('/', 1);
        final String tag = Uri.decode(path.substring(1, splitIndex));
        path = Uri.decode(path.substring(splitIndex + 1));

        if (!"root".equalsIgnoreCase(tag)) {
            throw new IllegalArgumentException(
                    String.format("Can't decode paths to '%s', only for 'root' paths.",
                            tag));
        }

        final File root = new File("/");

        File file = new File(root, path);
        try {
            file = file.getCanonicalFile();
        } catch (IOException e) {
            throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
        }

        if (!file.getPath().startsWith(root.getPath())) {
            throw new SecurityException("Resolved path jumped beyond configured root");
        }

        return file;
    }
@ NonNull public static File getFileForUri ( @ NonNull Uri uri ) { String path = uri . getEncodedPath ( ) ; final int splitIndex = path . indexOf ( '/' , 1 ) ; final String tag = Uri . decode ( path . substring ( 1 , splitIndex ) ) ; path = Uri . decode ( path . substring ( splitIndex + 1 ) ) ; if ( ! "root" . equalsIgnoreCase ( tag ) ) { throw new IllegalArgumentException ( String . format ( "Can't decode paths to '%s', only for 'root' paths." , tag ) ) ; } final File root = new File ( "/" ) ; File file = new File ( root , path ) ; try { file = file . getCanonicalFile ( ) ; } catch ( IOException e ) { throw new IllegalArgumentException ( "Failed to resolve canonical path for " + file ) ; } if ( ! file . getPath ( ) . startsWith ( root . getPath ( ) ) ) { throw new SecurityException ( "Resolved path jumped beyond configured root" ) ; } return file ; }
Convert a uri generated by a fileprovider, like content://AUTHORITY/ROOT/actual/path
to a file pointing to file:///actual/path

Note that it only works for paths generated with `ROOT` as the path element. This is done if
nnf_provider_paths.xml is used to define the file provider in the manifest.

@param uri generated from a file provider
@return Corresponding {@link File} object