Package org.robolectric.shadows
Class ShadowStorageStatsManager
java.lang.Object
org.robolectric.shadows.ShadowStorageStatsManager
@Implements(value=android.app.usage.StorageStatsManager.class, minSdk=26) public class ShadowStorageStatsManager extends Object
Fake implementation of
StorageStatsManager
that provides a fake
implementation of query for StorageStats
of a package.-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_STORAGE_FREE_BYTES
static long
DEFAULT_STORAGE_TOTAL_BYTES
-
Constructor Summary
Constructors Constructor Description ShadowStorageStatsManager()
-
Method Summary
Modifier and Type Method Description void
addStorageStats(UUID storageUuid, String packageName, UserHandle userHandle, StorageStats storageStatsToReturn)
void
clearStorageStats()
protected long
getFreeBytes(UUID storageUuid)
Fake implementation ofStorageStatsManager.getFreeBytes(java.util.UUID)
that returns test setup values.protected long
getTotalBytes(UUID storageUuid)
Fake implementation ofStorageStatsManager.getTotalBytes(java.util.UUID)
that returns test setup values.protected StorageStats
queryStatsForPackage(UUID storageUuid, String packageName, UserHandle user)
Fake implementation ofStorageStatsManager.queryStatsForPackage(java.util.UUID, java.lang.String, android.os.UserHandle)
that returns test setup values.protected StorageStats
queryStatsForUser(UUID storageUuid, UserHandle user)
Fake implementation ofStorageStatsManager.queryStatsForUser(java.util.UUID, android.os.UserHandle)
that returns an accumulatedStorageStats
based on the setup values for the user.void
removeStorageDevice(UUID storageUuid)
Removes a storage device identified bystorageUuid
if it's currently present.void
setStorageDeviceFreeAndTotalBytes(UUID storageUuid, long freeBytes, long totalBytes)
Sets thestorageUuid
to return the specifiedfreeBytes
andtotalBytes
when queried ingetFreeBytes(java.util.UUID)
andgetTotalBytes(java.util.UUID)
respectively.
-
Field Details
-
DEFAULT_STORAGE_FREE_BYTES
public static final long DEFAULT_STORAGE_FREE_BYTES- See Also:
- Constant Field Values
-
DEFAULT_STORAGE_TOTAL_BYTES
public static final long DEFAULT_STORAGE_TOTAL_BYTES- See Also:
- Constant Field Values
-
-
Constructor Details
-
ShadowStorageStatsManager
public ShadowStorageStatsManager()
-
-
Method Details
-
setStorageDeviceFreeAndTotalBytes
Sets thestorageUuid
to return the specifiedfreeBytes
andtotalBytes
when queried ingetFreeBytes(java.util.UUID)
andgetTotalBytes(java.util.UUID)
respectively.Both
freeBytes
andtotalBytes
have to be non-negative, else this method will throwIllegalArgumentException
. -
removeStorageDevice
Removes a storage device identified bystorageUuid
if it's currently present. Otherwise, this method will be a no-op. -
addStorageStats
public void addStorageStats(UUID storageUuid, String packageName, UserHandle userHandle, StorageStats storageStatsToReturn)Sets theStorageStats
for givenstorageUuid
,packageName
anduserHandle
. IfqueryStatsForPackage
is called with matchingstorageUuid
,packageName
anduserHandle
, thestorageStatsToReturn
will be returned directly. IfqueryStatsForUser
is called with matchingstorageUuid
anduserHandle
, then an accumulatedStorageStats
will be returned. -
clearStorageStats
public void clearStorageStats() -
getFreeBytes
Fake implementation ofStorageStatsManager.getFreeBytes(java.util.UUID)
that returns test setup values. This fake implementation does not check for access permission. It only checks for arguments matching those set insetStorageDeviceFreeAndTotalBytes(java.util.UUID, long, long)
.- Throws:
IOException
-
getTotalBytes
Fake implementation ofStorageStatsManager.getTotalBytes(java.util.UUID)
that returns test setup values. This fake implementation does not check for access permission. It only checks for arguments matching those set insetStorageDeviceFreeAndTotalBytes(java.util.UUID, long, long)
.- Throws:
IOException
-
queryStatsForPackage
@Implementation protected StorageStats queryStatsForPackage(UUID storageUuid, String packageName, UserHandle user) throws PackageManager.NameNotFoundException, IOExceptionFake implementation ofStorageStatsManager.queryStatsForPackage(java.util.UUID, java.lang.String, android.os.UserHandle)
that returns test setup values. This fake implementation does not check for access permission. It only checks for arguments matching those set inaddStorageStats(java.util.UUID, java.lang.String, android.os.UserHandle, android.app.usage.StorageStats)
. -
queryStatsForUser
@Implementation protected StorageStats queryStatsForUser(UUID storageUuid, UserHandle user) throws PackageManager.NameNotFoundException, IOExceptionFake implementation ofStorageStatsManager.queryStatsForUser(java.util.UUID, android.os.UserHandle)
that returns an accumulatedStorageStats
based on the setup values for the user. This fake implementation does not check for access permission. It only checks for arguments matching those set inaddStorageStats(java.util.UUID, java.lang.String, android.os.UserHandle, android.app.usage.StorageStats)
.
-