1.9 KiB
Patch plan – reliable USB free-space reporting
Target
/system/framework/tvfw.jar, UsbVolumeListerImpl.getVolumes(String), SHA-256
a0061795d87cf76c9b739e32022ab3d8c29f47ed01ddc1eee189dd815a8d11ad.
Java pseudodiff
- long freeMiB = -1;
- if (SystemProperties.get("sys.mtk.dmremoteservice.ready").equals("1"))
- free = deviceManager.getMountPoint(path).mFreeSize;
+ long freeMiB = -1;
+ boolean ready = SystemProperties.getBoolean(
+ "vendor.mtk.dmremoteservice.ready",
+ SystemProperties.getBoolean("sys.mtk.dmremoteservice.ready", false));
+ if (ready) freeMiB = safeDmFreeKiB(path) / 1024L;
+ if (freeMiB < 0 || freeMiB > totalMiB) {
+ try { freeMiB = new StatFs(path).getAvailableBytes() / (1024L * 1024L); }
+ catch (RuntimeException e) { freeMiB = UNKNOWN_MIB; }
+ }
The existing UsbVolume field contract is MiB on the MediaTek-ready path, so
the fallback must retain MiB rather than mixing raw bytes. Resolve the path
from the current VolumeInfo: public uses its mounted path;
private/adopted uses /mnt/expand/<fsUuid>. Only return a numeric zero when a
successful filesystem query actually reports zero; otherwise expose unknown or
omit the volume. Use long end-to-end.
Compatibility / smali
Supporting both old and vendor-prefixed properties avoids regressions across
MediaTek branches, but the correctness guarantee comes from StatFs, not the
property spelling. A smali patch adds guarded StatFs.<init>,
getAvailableBytes, range validation and exception handling. Framework-JAR
replacement requires shared-library/client-compatible DEX, correct oat
handling and AVB/system-image resigning; do not hot-patch the live locked device.
Tests
Public/adopted, ready true/false/missing, removed between enumeration/query,
read-only volume, >2-TiB arithmetic, zero genuinely full, reinsertion and path
change. Compare against df within filesystem allocation tolerance.