Merge "Fix crash when measuring storage." into oc-dev

This commit is contained in:
Daniel Nishi
2017-04-10 23:12:17 +00:00
committed by Android (Google) Code Review
2 changed files with 15 additions and 2 deletions

View File

@@ -151,8 +151,15 @@ public class StorageMeasurement {
final MeasurementDetails details = new MeasurementDetails();
if (mVolume == null) return details;
details.totalSize = mStats.getTotalBytes(mVolume.fsUuid);
details.availSize = mStats.getFreeBytes(mVolume.fsUuid);
try {
details.totalSize = mStats.getTotalBytes(mVolume.fsUuid);
details.availSize = mStats.getFreeBytes(mVolume.fsUuid);
} catch (IllegalStateException e) {
// The storage volume became null while we were measuring it.
Log.w(TAG, e);
return details;
}
final long finishTotal = SystemClock.elapsedRealtime();
Log.d(TAG, "Measured total storage in " + (finishTotal - start) + "ms");

View File

@@ -162,6 +162,9 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
return FileUtils.roundStorageSize(mStorage.getPrimaryStorageSize());
} else {
final VolumeInfo vol = mStorage.findVolumeByUuid(volumeUuid);
if (vol == null) {
throw new IllegalStateException("Volume was unexpected null");
}
return FileUtils.roundStorageSize(vol.disk.size);
}
}
@@ -185,6 +188,9 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
return Environment.getDataDirectory().getUsableSpace() + cacheBytes;
} else {
final VolumeInfo vol = mStorage.findVolumeByUuid(volumeUuid);
if (vol == null) {
throw new IllegalStateException("Volume was unexpected null");
}
return vol.getPath().getUsableSpace() + cacheBytes;
}
}