Add storage fullness methods to volume provider.

This allows us to mock them out for use in unit tests.

Fixes: 36858638
Change-Id: I2509d9704b531cf3594790f738aaedb7ed5db443
Test: Thin wrapper is used in Settings unittest
This commit is contained in:
Daniel Nishi
2017-04-03 11:26:46 -07:00
parent a906fb7b43
commit 2860cf63fd
3 changed files with 28 additions and 2 deletions

View File

@@ -41,8 +41,8 @@ public class PrivateStorageInfo {
long privateTotalBytes = 0;
for (VolumeInfo info : sm.getVolumes()) {
if (info.getType() == VolumeInfo.TYPE_PRIVATE && info.isMountedReadable()) {
privateTotalBytes += stats.getTotalBytes(info.getFsUuid());
privateFreeBytes += stats.getFreeBytes(info.getFsUuid());
privateTotalBytes += sm.getTotalBytes(stats, info);
privateFreeBytes += sm.getFreeBytes(stats, info);
}
}
return new PrivateStorageInfo(privateFreeBytes, privateTotalBytes);

View File

@@ -16,6 +16,7 @@
package com.android.settingslib.deviceinfo;
import android.app.usage.StorageStatsManager;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
@@ -46,4 +47,14 @@ public class StorageManagerVolumeProvider implements StorageVolumeProvider {
public VolumeInfo findEmulatedForPrivate(VolumeInfo privateVolume) {
return mStorageManager.findEmulatedForPrivate(privateVolume);
}
@Override
public long getTotalBytes(StorageStatsManager stats, VolumeInfo volume) {
return stats.getTotalBytes(volume.getFsUuid());
}
@Override
public long getFreeBytes(StorageStatsManager stats, VolumeInfo volume) {
return stats.getFreeBytes(volume.getFsUuid());
}
}

View File

@@ -16,6 +16,7 @@
package com.android.settingslib.deviceinfo;
import android.app.usage.StorageStatsManager;
import android.os.storage.VolumeInfo;
import java.util.List;
@@ -39,4 +40,18 @@ public interface StorageVolumeProvider {
* Returns the emulated volume for a given private volume.
*/
VolumeInfo findEmulatedForPrivate(VolumeInfo privateVolume);
/**
* Returns the total bytes for a given storage volume.
*
* @pre The volume is a private volume and is readable.
*/
long getTotalBytes(StorageStatsManager stats, VolumeInfo volume);
/**
* Returns the free bytes for a given storage volume.
*
* @pre The volume is a private volume and is readable.
*/
long getFreeBytes(StorageStatsManager stats, VolumeInfo volume);
}