Skip to content

Commit f913d00

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Expose statfs() through IMediaContainerService."
2 parents 03d2f29 + 9cbe986 commit f913d00

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

core/java/com/android/internal/app/IMediaContainerService.aidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ interface IMediaContainerService {
3232
boolean checkExternalFreeStorage(in Uri fileUri);
3333
ObbInfo getObbInfo(in String filename);
3434
long calculateDirectorySize(in String directory);
35+
/** Return file system stats: [0] is total bytes, [1] is available bytes */
36+
long[] getFileSystemStats(in String path);
3537
}

packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
import java.io.InputStream;
5151
import java.io.OutputStream;
5252

53+
import libcore.io.ErrnoException;
54+
import libcore.io.Libcore;
55+
import libcore.io.StructStatFs;
56+
5357
/*
5458
* This service copies a downloaded apk to a file passed in as
5559
* a ParcelFileDescriptor or to a newly created container specified
@@ -203,6 +207,18 @@ public long calculateDirectorySize(String path) throws RemoteException {
203207
return 0L;
204208
}
205209
}
210+
211+
@Override
212+
public long[] getFileSystemStats(String path) {
213+
try {
214+
final StructStatFs stat = Libcore.os.statfs(path);
215+
final long totalSize = stat.f_blocks * stat.f_bsize;
216+
final long availSize = stat.f_bavail * stat.f_bsize;
217+
return new long[] { totalSize, availSize };
218+
} catch (ErrnoException e) {
219+
throw new IllegalStateException(e);
220+
}
221+
}
206222
};
207223

208224
public DefaultContainerService() {

0 commit comments

Comments
 (0)