Skip to content

Most visited

Recently visited

navigation
Added in API level 9

StorageManager

public class StorageManager
extends Object

java.lang.Object
   ↳ android.os.storage.StorageManager


StorageManager is the interface to the systems storage service. The storage manager handles storage-related items such as Opaque Binary Blobs (OBBs).

OBBs contain a filesystem that maybe be encrypted on disk and mounted on-demand from an application. OBBs are a good way of providing large amounts of binary assets without packaging them into APKs as they may be multiple gigabytes in size. However, due to their size, they're most likely stored in a shared storage pool accessible from all programs. The system does not guarantee the security of the OBB file itself: if any program modifies the OBB, there is no guarantee that a read from that OBB will produce the expected output.

Get an instance of this class by calling getSystemService(java.lang.String) with an argument of STORAGE_SERVICE.

Summary

Public methods

String getMountedObbPath(String rawPath)

Check the mounted path of an Opaque Binary Blob (OBB) file.

StorageVolume getPrimaryStorageVolume()

Return the primary shared/external storage volume available to the current user.

StorageVolume getStorageVolume(File file)

Return the StorageVolume that contains the given file, or null if none.

List<StorageVolume> getStorageVolumes()

Return the list of shared/external storage volumes available to the current user.

boolean isEncrypted(File file)

Return if data stored at or under the given path will be encrypted while at rest.

boolean isObbMounted(String rawPath)

Check whether an Opaque Binary Blob (OBB) is mounted or not.

boolean mountObb(String rawPath, String key, OnObbStateChangeListener listener)

Mount an Opaque Binary Blob (OBB) file.

boolean unmountObb(String rawPath, boolean force, OnObbStateChangeListener listener)

Unmount an Opaque Binary Blob (OBB) file asynchronously.

Inherited methods

From class java.lang.Object

Public methods

getMountedObbPath

Added in API level 9
String getMountedObbPath (String rawPath)

Check the mounted path of an Opaque Binary Blob (OBB) file. This will give you the path to where you can obtain access to the internals of the OBB.

Parameters
rawPath String: path to OBB image
Returns
String absolute path to mounted OBB image data or null if not mounted or exception encountered trying to read status

getPrimaryStorageVolume

Added in API level 24
StorageVolume getPrimaryStorageVolume ()

Return the primary shared/external storage volume available to the current user. This volume is the same storage device returned by getExternalStorageDirectory() and getExternalFilesDir(String).

Returns
StorageVolume

getStorageVolume

Added in API level 24
StorageVolume getStorageVolume (File file)

Return the StorageVolume that contains the given file, or null if none.

Parameters
file File
Returns
StorageVolume

getStorageVolumes

Added in API level 24
List<StorageVolume> getStorageVolumes ()

Return the list of shared/external storage volumes available to the current user. This includes both the primary shared storage device and any attached external volumes including SD cards and USB drives.

Returns
List<StorageVolume>

See also:

isEncrypted

Added in API level 24
boolean isEncrypted (File file)

Return if data stored at or under the given path will be encrypted while at rest. This can help apps avoid the overhead of double-encrypting data.

Parameters
file File
Returns
boolean

isObbMounted

Added in API level 9
boolean isObbMounted (String rawPath)

Check whether an Opaque Binary Blob (OBB) is mounted or not.

Parameters
rawPath String: path to OBB image
Returns
boolean true if OBB is mounted; false if not mounted or on error

mountObb

Added in API level 9
boolean mountObb (String rawPath, 
                String key, 
                OnObbStateChangeListener listener)

Mount an Opaque Binary Blob (OBB) file. If a key is specified, it is supplied to the mounting process to be used in any encryption used in the OBB.

The OBB will remain mounted for as long as the StorageManager reference is held by the application. As soon as this reference is lost, the OBBs in use will be unmounted. The OnObbStateChangeListener registered with this call will receive the success or failure of this operation.

Note: you can only mount OBB files for which the OBB tag on the file matches a package ID that is owned by the calling program's UID. That is, shared UID applications can attempt to mount any other application's OBB that shares its UID.

Parameters
rawPath String: the path to the OBB file
key String: secret used to encrypt the OBB; may be null if no encryption was used on the OBB.
listener OnObbStateChangeListener: will receive the success or failure of the operation
Returns
boolean whether the mount call was successfully queued or not

unmountObb

Added in API level 9
boolean unmountObb (String rawPath, 
                boolean force, 
                OnObbStateChangeListener listener)

Unmount an Opaque Binary Blob (OBB) file asynchronously. If the force flag is true, it will kill any application needed to unmount the given OBB (even the calling application).

The OnObbStateChangeListener registered with this call will receive the success or failure of this operation.

Note: you can only mount OBB files for which the OBB tag on the file matches a package ID that is owned by the calling program's UID. That is, shared UID applications can obtain access to any other application's OBB that shares its UID.

Parameters
rawPath String: path to the OBB file
force boolean: whether to kill any programs using this in order to unmount it
listener OnObbStateChangeListener: will receive the success or failure of the operation
Returns
boolean whether the unmount call was successfully queued or not
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.