40 lines
1.6 KiB
Diff
40 lines
1.6 KiB
Diff
--- a/src/org/droidtv/tv/os/storage/UsbVolumeListerImpl.java
|
|
+++ b/src/org/droidtv/tv/os/storage/UsbVolumeListerImpl.java
|
|
@@
|
|
- if ("1".equals(SystemProperties.get("sys.mtk.dmremoteservice.ready"))) {
|
|
- MountPoint mp = DeviceManager.getInstance().getMountPoint(path);
|
|
- if (mp != null) {
|
|
- volume.mRawDiskSize = mp.mTotalSize / 1024;
|
|
- volume.mFreeDiskSize = mp.mFreeSize / 1024;
|
|
- }
|
|
- }
|
|
+ boolean sizeKnown = false;
|
|
+ if ("1".equals(SystemProperties.get("sys.mtk.dmremoteservice.ready"))) {
|
|
+ MountPoint mp = DeviceManager.getInstance().getMountPoint(path);
|
|
+ if (mp != null) {
|
|
+ long totalMiB = mp.mTotalSize / 1024; // MountPoint is KiB
|
|
+ long freeMiB = mp.mFreeSize / 1024;
|
|
+ if (totalMiB > 0 && freeMiB >= 0 && freeMiB <= totalMiB) {
|
|
+ volume.mRawDiskSize = totalMiB;
|
|
+ volume.mFreeDiskSize = freeMiB;
|
|
+ sizeKnown = true;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ if (!sizeKnown) {
|
|
+ try {
|
|
+ StatFs fs = new StatFs(path);
|
|
+ long totalMiB = fs.getTotalBytes() / (1024L * 1024L);
|
|
+ long freeMiB = fs.getAvailableBytes() / (1024L * 1024L);
|
|
+ if (totalMiB <= 0 || freeMiB < 0 || freeMiB > totalMiB) {
|
|
+ throw new IllegalStateException("invalid StatFs size");
|
|
+ }
|
|
+ volume.mRawDiskSize = totalMiB;
|
|
+ volume.mFreeDiskSize = freeMiB;
|
|
+ sizeKnown = true;
|
|
+ } catch (RuntimeException e) {
|
|
+ Log.w(TAG, "size unavailable for mounted volume " + volume.mUUID, e);
|
|
+ }
|
|
+ }
|
|
+ if (!sizeKnown) continue; // never publish an unknown size as numeric zero
|