Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f913d002 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Expose statfs() through IMediaContainerService."

parents 03d2f292 9cbe986a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -32,4 +32,6 @@ interface IMediaContainerService {
    boolean checkExternalFreeStorage(in Uri fileUri);
    ObbInfo getObbInfo(in String filename);
    long calculateDirectorySize(in String directory);
    /** Return file system stats: [0] is total bytes, [1] is available bytes */
    long[] getFileSystemStats(in String path);
}
+16 −0
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import libcore.io.ErrnoException;
import libcore.io.Libcore;
import libcore.io.StructStatFs;

/*
 * This service copies a downloaded apk to a file passed in as
 * a ParcelFileDescriptor or to a newly created container specified
@@ -203,6 +207,18 @@ public class DefaultContainerService extends IntentService {
                return 0L;
            }
        }

        @Override
        public long[] getFileSystemStats(String path) {
            try {
                final StructStatFs stat = Libcore.os.statfs(path);
                final long totalSize = stat.f_blocks * stat.f_bsize;
                final long availSize = stat.f_bavail * stat.f_bsize;
                return new long[] { totalSize, availSize };
            } catch (ErrnoException e) {
                throw new IllegalStateException(e);
            }
        }
    };

    public DefaultContainerService() {