public class StorageManager extends Object
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
Context.getSystemService(java.lang.String)
with an
argument of Context.STORAGE_SERVICE
.
Constructor and Description |
---|
StorageManager(Looper tgtLooper)
Constructs a StorageManager object through which an application can
can communicate with the systems mount service.
|
Modifier and Type | Method and Description |
---|---|
void |
disableUsbMassStorage()
Disables USB Mass Storage (UMS) on the device.
|
void |
enableUsbMassStorage()
Enables USB Mass Storage (UMS) on the device.
|
static StorageManager |
from(Context context) |
String |
getMountedObbPath(String rawPath)
Check the mounted path of an Opaque Binary Blob (OBB) file.
|
StorageVolume |
getPrimaryVolume() |
static StorageVolume |
getPrimaryVolume(StorageVolume[] volumes) |
StorageVolume[] |
getVolumeList()
Returns list of all mountable volumes.
|
String[] |
getVolumePaths()
Returns list of paths for all mountable volumes.
|
String |
getVolumeState(String mountPoint)
Gets the state of a volume via its mountpoint.
|
boolean |
isObbMounted(String rawPath)
Check whether an Opaque Binary Blob (OBB) is mounted or not.
|
boolean |
isUsbMassStorageConnected()
Query if a USB Mass Storage (UMS) host is connected.
|
boolean |
isUsbMassStorageEnabled()
Query if a USB Mass Storage (UMS) is enabled on the device.
|
boolean |
mountObb(String rawPath,
String key,
OnObbStateChangeListener listener)
Mount an Opaque Binary Blob (OBB) file.
|
void |
registerListener(StorageEventListener listener)
Registers a
StorageEventListener . |
boolean |
unmountObb(String rawPath,
boolean force,
OnObbStateChangeListener listener)
Unmount an Opaque Binary Blob (OBB) file asynchronously.
|
void |
unregisterListener(StorageEventListener listener)
Unregisters a
StorageEventListener . |
public StorageManager(Looper tgtLooper) throws RemoteException
tgtLooper
- The Looper
which events will be received on.
Applications can get instance of this class by calling
Context.getSystemService(java.lang.String)
with an argument
of Context.STORAGE_SERVICE
.
RemoteException
public static StorageManager from(Context context)
public void registerListener(StorageEventListener listener)
StorageEventListener
.listener
- A StorageEventListener
object.public void unregisterListener(StorageEventListener listener)
StorageEventListener
.listener
- A StorageEventListener
object.public void enableUsbMassStorage()
public void disableUsbMassStorage()
public boolean isUsbMassStorageConnected()
public boolean isUsbMassStorageEnabled()
public boolean mountObb(String rawPath, String key, OnObbStateChangeListener listener)
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.
rawPath
- the path to the OBB filekey
- secret used to encrypt the OBB; may be null
if no
encryption was used on the OBB.listener
- will receive the success or failure of the operationpublic boolean unmountObb(String rawPath, boolean force, OnObbStateChangeListener listener)
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.
rawPath
- path to the OBB fileforce
- whether to kill any programs using this in order to unmount
itlistener
- will receive the success or failure of the operationpublic boolean isObbMounted(String rawPath)
rawPath
- path to OBB imagepublic String getMountedObbPath(String rawPath)
rawPath
- path to OBB imagenull
if
not mounted or exception encountered trying to read statuspublic String getVolumeState(String mountPoint)
public StorageVolume[] getVolumeList()
public String[] getVolumePaths()
public StorageVolume getPrimaryVolume()
public static StorageVolume getPrimaryVolume(StorageVolume[] volumes)