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

Commit 9cbe986a authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Expose statfs() through IMediaContainerService.

Bug: 6346248
Change-Id: I03ae02578f546fc9f19652cbdece56e2e0ab6a1c
parent 816e4f75
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() {