StorageStatsManager
public
class
StorageStatsManager
extends Object
java.lang.Object | |
↳ | android.app.usage.StorageStatsManager |
Access to detailed storage statistics. This provides a summary of how apps, users, and external/shared storage is utilizing disk space.
Note: no permissions are required when calling these APIs for your own
package or UID. However, requesting details for any other package requires
the android.Manifest.permission#PACKAGE_USAGE_STATS
permission, which
is a system-level permission that will not be granted to normal apps.
Declaring that permission expresses your intention to use this API and an end
user can then choose to grant this permission through the Settings
application.
Summary
Public methods | |
---|---|
long
|
getFreeBytes(UUID storageUuid)
Return the free space on the requested storage volume. |
long
|
getTotalBytes(UUID storageUuid)
Return the total size of the underlying physical media that is hosting this storage volume. |
ExternalStorageStats
|
queryExternalStatsForUser(UUID storageUuid, UserHandle user)
Return shared/external storage statistics for a specific
|
StorageStats
|
queryStatsForPackage(UUID storageUuid, String packageName, UserHandle user)
Return storage statistics for a specific package on the requested storage volume. |
StorageStats
|
queryStatsForUid(UUID storageUuid, int uid)
Return storage statistics for a specific UID on the requested storage volume. |
StorageStats
|
queryStatsForUser(UUID storageUuid, UserHandle user)
Return storage statistics for a specific |
Inherited methods | |
---|---|
Public methods
getFreeBytes
public long getFreeBytes (UUID storageUuid)
Return the free space on the requested storage volume.
This value is best suited for visual display to end users, since it's designed to reflect both unused space and and cached space that could be reclaimed by the system.
Apps making logical decisions about disk space should always use
StorageManager#getAllocatableBytes(UUID)
instead of this value.
This method may take several seconds to complete, so it should
only be called from a worker thread.
Value is a non-negative number of bytes.
Parameters | |
---|---|
storageUuid |
UUID : the UUID of the storage volume you're interested in,
such as StorageManager#UUID_DEFAULT .
This value cannot be null . |
Returns | |
---|---|
long |
Value is a non-negative number of bytes. |
Throws | |
---|---|
IOException |
when the storage device isn't present. |
getTotalBytes
public long getTotalBytes (UUID storageUuid)
Return the total size of the underlying physical media that is hosting this storage volume.
This value is best suited for visual display to end users, since it's designed to reflect the total storage size advertised in a retail environment.
Apps making logical decisions about disk space should always use
File#getTotalSpace()
instead of this value.
This method may take several seconds to complete, so it should
only be called from a worker thread.
Value is a non-negative number of bytes.
Parameters | |
---|---|
storageUuid |
UUID : the UUID of the storage volume you're interested in,
such as StorageManager#UUID_DEFAULT .
This value cannot be null . |
Returns | |
---|---|
long |
Value is a non-negative number of bytes. |
Throws | |
---|---|
IOException |
when the storage device isn't present. |
queryExternalStatsForUser
public ExternalStorageStats queryExternalStatsForUser (UUID storageUuid, UserHandle user)
Return shared/external storage statistics for a specific
UserHandle
on the requested storage volume.
Note: this API requires the
android.Manifest.permission#PACKAGE_USAGE_STATS
permission, which
is a system-level permission that will not be granted to normal apps.
Declaring that permission expresses your intention to use this API and an
end user can then choose to grant this permission through the Settings
application.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
storageUuid |
UUID : the UUID of the storage volume you're interested in,
such as StorageManager#UUID_DEFAULT .
This value cannot be null . |
user |
UserHandle : This value cannot be null . |
Returns | |
---|---|
ExternalStorageStats |
This value cannot be null . |
Throws | |
---|---|
IOException |
when the storage device isn't present. |
See also:
queryStatsForPackage
public StorageStats queryStatsForPackage (UUID storageUuid, String packageName, UserHandle user)
Return storage statistics for a specific package on the requested storage volume.
Note: no permissions are required when calling this API for your own
package. However, requesting details for any other package requires the
android.Manifest.permission#PACKAGE_USAGE_STATS
permission, which
is a system-level permission that will not be granted to normal apps.
Declaring that permission expresses your intention to use this API and an
end user can then choose to grant this permission through the Settings
application.
Note: if the requested package uses the android:sharedUserId
manifest feature, this call will be forced into a slower manual
calculation path. If possible, consider always using
queryStatsForUid(java.util.UUID, int)
, which is typically faster.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
storageUuid |
UUID : the UUID of the storage volume you're interested in,
such as StorageManager#UUID_DEFAULT .
This value cannot be null . |
packageName |
String : the package name you're interested in.
This value cannot be null . |
user |
UserHandle : the user you're interested in.
This value cannot be null . |
Returns | |
---|---|
StorageStats |
This value cannot be null . |
Throws | |
---|---|
PackageManager.NameNotFoundException |
when the requested package name isn't installed for the requested user. |
IOException |
when the storage device isn't present. |
queryStatsForUid
public StorageStats queryStatsForUid (UUID storageUuid, int uid)
Return storage statistics for a specific UID on the requested storage volume.
Note: no permissions are required when calling this API for your own UID.
However, requesting details for any other UID requires the
android.Manifest.permission#PACKAGE_USAGE_STATS
permission, which
is a system-level permission that will not be granted to normal apps.
Declaring that permission expresses your intention to use this API and an
end user can then choose to grant this permission through the Settings
application.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
storageUuid |
UUID : the UUID of the storage volume you're interested in,
such as StorageManager#UUID_DEFAULT .
This value cannot be null . |
uid |
int : the UID you're interested in. |
Returns | |
---|---|
StorageStats |
This value cannot be null . |
Throws | |
---|---|
IOException |
when the storage device isn't present. |
queryStatsForUser
public StorageStats queryStatsForUser (UUID storageUuid, UserHandle user)
Return storage statistics for a specific UserHandle
on the
requested storage volume.
Note: this API requires the
android.Manifest.permission#PACKAGE_USAGE_STATS
permission, which
is a system-level permission that will not be granted to normal apps.
Declaring that permission expresses your intention to use this API and an
end user can then choose to grant this permission through the Settings
application.
This method may take several seconds to complete, so it should only be called from a worker thread.
Parameters | |
---|---|
storageUuid |
UUID : the UUID of the storage volume you're interested in,
such as StorageManager#UUID_DEFAULT .
This value cannot be null . |
user |
UserHandle : the user you're interested in.
This value cannot be null . |
Returns | |
---|---|
StorageStats |
This value cannot be null . |
Throws | |
---|---|
IOException |
when the storage device isn't present. |
See also: