Added in API level 26

StorageStatsManager

open class StorageStatsManager
kotlin.Any
   ↳ 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
open Long
getFreeBytes(storageUuid: UUID)

Return the free space on the requested storage volume.

open Long
getTotalBytes(storageUuid: UUID)

Return the total size of the underlying physical media that is hosting this storage volume.

open ExternalStorageStats

Return shared/external storage statistics for a specific UserHandle on the requested storage volume.

open StorageStats
queryStatsForPackage(storageUuid: UUID, packageName: String, user: UserHandle)

Return storage statistics for a specific package on the requested storage volume.

open StorageStats
queryStatsForUid(storageUuid: UUID, uid: Int)

Return storage statistics for a specific UID on the requested storage volume.

open StorageStats
queryStatsForUser(storageUuid: UUID, user: UserHandle)

Return storage statistics for a specific UserHandle on the requested storage volume.

Public methods

getFreeBytes

Added in API level 26
open fun getFreeBytes(storageUuid: UUID): Long

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.
Return
Long Value is a non-negative number of bytes.
Exceptions
java.io.IOException when the storage device isn't present.

getTotalBytes

Added in API level 26
open fun getTotalBytes(storageUuid: UUID): Long

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.
Return
Long Value is a non-negative number of bytes.
Exceptions
java.io.IOException when the storage device isn't present.

queryExternalStatsForUser

Added in API level 26
open fun queryExternalStatsForUser(
    storageUuid: UUID,
    user: UserHandle
): ExternalStorageStats

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.
Return
ExternalStorageStats This value cannot be null.
Exceptions
java.io.IOException when the storage device isn't present.

queryStatsForPackage

Added in API level 26
open fun queryStatsForPackage(
    storageUuid: UUID,
    packageName: String,
    user: UserHandle
): StorageStats

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.
Return
StorageStats This value cannot be null.
Exceptions
android.content.pm.PackageManager.NameNotFoundException when the requested package name isn't installed for the requested user.
java.io.IOException when the storage device isn't present.

queryStatsForUid

Added in API level 26
open fun queryStatsForUid(
    storageUuid: UUID,
    uid: Int
): StorageStats

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.
Return
StorageStats This value cannot be null.
Exceptions
java.io.IOException when the storage device isn't present.

queryStatsForUser

Added in API level 26
open fun queryStatsForUser(
    storageUuid: UUID,
    user: UserHandle
): StorageStats

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.
Return
StorageStats This value cannot be null.
Exceptions
java.io.IOException when the storage device isn't present.