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

Commit b28c9d6b authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Fix crash when measuring storage.

If we are measuring storage and a volume is removed at the same time,
we can enter a state where we previously verified the volume existed,
but it no longer does. This causes an NPE.

By adding in a null check, we can avoid this crash.

Change-Id: Ib8dbf05102a122bdf4bb6063374e993a1de68425
Fixes: 36689190
Test: None
parent eb936703
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -151,8 +151,15 @@ public class StorageMeasurement {
        final MeasurementDetails details = new MeasurementDetails();
        if (mVolume == null) return details;

        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");
+6 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }