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
.
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_MANAGE_STORAGE
Activity Action: Allows the user to manage their storage.
|
static int |
CRYPT_TYPE_DEFAULT |
static int |
CRYPT_TYPE_PASSWORD |
static int |
CRYPT_TYPE_PATTERN |
static int |
CRYPT_TYPE_PIN |
static int |
DEBUG_EMULATE_FBE |
static int |
DEBUG_FORCE_ADOPTABLE |
static int |
DEBUG_SDCARDFS_FORCE_OFF |
static int |
DEBUG_SDCARDFS_FORCE_ON |
static int |
FLAG_FOR_WRITE |
static int |
FLAG_INCLUDE_INVISIBLE |
static int |
FLAG_REAL_STATE |
static int |
FLAG_STORAGE_CE |
static int |
FLAG_STORAGE_DE |
static String |
OWNER_INFO_KEY |
static String |
PASSWORD_VISIBLE_KEY |
static String |
PATTERN_VISIBLE_KEY |
static String |
PROP_EMULATE_FBE |
static String |
PROP_FORCE_ADOPTABLE |
static String |
PROP_HAS_ADOPTABLE |
static String |
PROP_PRIMARY_PHYSICAL |
static String |
PROP_SDCARDFS |
static String |
SYSTEM_LOCALE_KEY |
static String |
UUID_PRIMARY_PHYSICAL |
static String |
UUID_PRIVATE_INTERNAL |
Constructor and Description |
---|
StorageManager(Context context,
Looper looper)
Constructs a StorageManager object through which an application can
can communicate with the systems mount service.
|
Modifier and Type | Method and Description |
---|---|
long |
benchmark(String volId) |
void |
createUserKey(int userId,
int serialNumber,
boolean ephemeral) |
void |
destroyUserKey(int userId) |
void |
destroyUserStorage(String volumeUuid,
int userId,
int flags) |
void |
disableUsbMassStorage()
Deprecated.
|
void |
enableUsbMassStorage()
Deprecated.
|
DiskInfo |
findDiskById(String id) |
VolumeInfo |
findEmulatedForPrivate(VolumeInfo privateVol) |
VolumeInfo |
findPrivateForEmulated(VolumeInfo emulatedVol) |
VolumeRecord |
findRecordByUuid(String fsUuid) |
VolumeInfo |
findVolumeById(String id) |
VolumeInfo |
findVolumeByQualifiedUuid(String volumeUuid) |
VolumeInfo |
findVolumeByUuid(String fsUuid) |
void |
forgetVolume(String fsUuid) |
void |
format(String volId) |
static StorageManager |
from(Context context)
Deprecated.
|
String |
getBestVolumeDescription(VolumeInfo vol) |
List<DiskInfo> |
getDisks() |
String |
getMountedObbPath(String rawPath)
Check the mounted path of an Opaque Binary Blob (OBB) file.
|
VolumeInfo |
getPrimaryPhysicalVolume() |
long |
getPrimaryStorageSize() |
String |
getPrimaryStorageUuid()
This is not the API you're looking for.
|
StorageVolume |
getPrimaryStorageVolume()
Return the primary shared/external storage volume available to the
current user.
|
StorageVolume |
getPrimaryVolume() |
static StorageVolume |
getPrimaryVolume(StorageVolume[] volumes) |
long |
getStorageBytesUntilLow(File path)
Return the number of available bytes until the given path is considered
running low on storage.
|
long |
getStorageFullBytes(File path)
Return the number of available bytes at which the given path is
considered full.
|
long |
getStorageLowBytes(File path)
Return the number of available bytes at which the given path is
considered running low on storage.
|
StorageVolume |
getStorageVolume(File file)
Return the
StorageVolume that contains the given file, or null if none. |
static StorageVolume |
getStorageVolume(File file,
int userId) |
List<StorageVolume> |
getStorageVolumes()
Return the list of shared/external storage volumes available to the
current user.
|
StorageVolume[] |
getVolumeList() |
static StorageVolume[] |
getVolumeList(int userId,
int flags) |
String[] |
getVolumePaths()
Deprecated.
|
List<VolumeRecord> |
getVolumeRecords() |
List<VolumeInfo> |
getVolumes() |
String |
getVolumeState(String mountPoint)
Deprecated.
|
List<VolumeInfo> |
getWritablePrivateVolumes() |
static boolean |
inCryptKeeperBounce()
Is this device non default block encrypted and in the process of
prompting for credentials?
|
static boolean |
isBlockEncrypted()
Is this device block encrypted?
|
static boolean |
isBlockEncrypting()
Is this device in the process of being block encrypted?
|
static boolean |
isEncryptable()
Is this device encryptable or already encrypted?
|
static boolean |
isEncrypted()
Is this device already encrypted?
|
boolean |
isEncrypted(File file)
Return if data stored at or under the given path will be encrypted while
at rest.
|
static boolean |
isFileEncryptedEmulatedOnly() |
static boolean |
isFileEncryptedNativeOnly()
Is this device file encrypted?
|
static boolean |
isFileEncryptedNativeOrEmulated()
Is this device running in a file encrypted mode, either native or emulated?
|
static boolean |
isNonDefaultBlockEncrypted()
Is this device block encrypted with credentials?
|
boolean |
isObbMounted(String rawPath)
Check whether an Opaque Binary Blob (OBB) is mounted or not.
|
boolean |
isUsbMassStorageConnected()
Deprecated.
|
boolean |
isUsbMassStorageEnabled()
Deprecated.
|
static boolean |
isUserKeyUnlocked(int userId) |
void |
lockUserKey(int userId) |
static File |
maybeTranslateEmulatedPathToInternal(File path) |
void |
mount(String volId) |
ParcelFileDescriptor |
mountAppFuse(String name) |
boolean |
mountObb(String rawPath,
String key,
OnObbStateChangeListener listener)
Mount an Opaque Binary Blob (OBB) file.
|
void |
partitionMixed(String diskId,
int ratio) |
void |
partitionPrivate(String diskId) |
void |
partitionPublic(String diskId) |
void |
prepareUserStorage(String volumeUuid,
int userId,
int serialNumber,
int flags) |
void |
registerListener(StorageEventListener listener)
Registers a
StorageEventListener . |
void |
setPrimaryStorageUuid(String volumeUuid,
IPackageMoveObserver callback)
This is not the API you're looking for.
|
void |
setVolumeInited(String fsUuid,
boolean inited) |
void |
setVolumeNickname(String fsUuid,
String nickname) |
void |
setVolumeSnoozed(String fsUuid,
boolean snoozed) |
void |
unlockUserKey(int userId,
int serialNumber,
byte[] token,
byte[] secret) |
void |
unmount(String volId) |
boolean |
unmountObb(String rawPath,
boolean force,
OnObbStateChangeListener listener)
Unmount an Opaque Binary Blob (OBB) file asynchronously.
|
void |
unregisterListener(StorageEventListener listener)
Unregisters a
StorageEventListener . |
void |
wipeAdoptableDisks() |
public static final String PROP_PRIMARY_PHYSICAL
public static final String PROP_HAS_ADOPTABLE
public static final String PROP_FORCE_ADOPTABLE
public static final String PROP_EMULATE_FBE
public static final String PROP_SDCARDFS
public static final String UUID_PRIVATE_INTERNAL
public static final String UUID_PRIMARY_PHYSICAL
public static final String ACTION_MANAGE_STORAGE
Input: Nothing.
Output: Nothing.
public static final int DEBUG_FORCE_ADOPTABLE
public static final int DEBUG_EMULATE_FBE
public static final int DEBUG_SDCARDFS_FORCE_ON
public static final int DEBUG_SDCARDFS_FORCE_OFF
public static final int FLAG_STORAGE_DE
public static final int FLAG_STORAGE_CE
public static final int FLAG_FOR_WRITE
public static final int FLAG_REAL_STATE
public static final int FLAG_INCLUDE_INVISIBLE
public static final int CRYPT_TYPE_PASSWORD
public static final int CRYPT_TYPE_DEFAULT
public static final int CRYPT_TYPE_PATTERN
public static final int CRYPT_TYPE_PIN
public static final String SYSTEM_LOCALE_KEY
public static final String OWNER_INFO_KEY
public static final String PATTERN_VISIBLE_KEY
public static final String PASSWORD_VISIBLE_KEY
public StorageManager(Context context, Looper looper)
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
.
@Deprecated 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.@Deprecated public void enableUsbMassStorage()
@Deprecated public void disableUsbMassStorage()
@Deprecated public boolean isUsbMassStorageConnected()
@Deprecated 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 VolumeInfo findVolumeById(String id)
public VolumeInfo findVolumeByUuid(String fsUuid)
public VolumeRecord findRecordByUuid(String fsUuid)
public VolumeInfo findPrivateForEmulated(VolumeInfo emulatedVol)
public VolumeInfo findEmulatedForPrivate(VolumeInfo privateVol)
public VolumeInfo findVolumeByQualifiedUuid(String volumeUuid)
public List<VolumeInfo> getVolumes()
public List<VolumeInfo> getWritablePrivateVolumes()
public List<VolumeRecord> getVolumeRecords()
public String getBestVolumeDescription(VolumeInfo vol)
public VolumeInfo getPrimaryPhysicalVolume()
public void mount(String volId)
public void unmount(String volId)
public void format(String volId)
public long benchmark(String volId)
public void partitionPublic(String diskId)
public void partitionPrivate(String diskId)
public void partitionMixed(String diskId, int ratio)
public void wipeAdoptableDisks()
public void setVolumeInited(String fsUuid, boolean inited)
public void setVolumeSnoozed(String fsUuid, boolean snoozed)
public void forgetVolume(String fsUuid)
public String getPrimaryStorageUuid()
public void setPrimaryStorageUuid(String volumeUuid, IPackageMoveObserver callback)
public StorageVolume getStorageVolume(File file)
StorageVolume
that contains the given file, or null
if none.public static StorageVolume getStorageVolume(File file, int userId)
@Deprecated public String getVolumeState(String mountPoint)
public List<StorageVolume> getStorageVolumes()
public StorageVolume getPrimaryStorageVolume()
Environment.getExternalStorageDirectory()
and
Context.getExternalFilesDir(String)
.public long getPrimaryStorageSize()
public StorageVolume[] getVolumeList()
public static StorageVolume[] getVolumeList(int userId, int flags)
@Deprecated public String[] getVolumePaths()
public StorageVolume getPrimaryVolume()
public static StorageVolume getPrimaryVolume(StorageVolume[] volumes)
public long getStorageBytesUntilLow(File path)
public long getStorageLowBytes(File path)
public long getStorageFullBytes(File path)
public void createUserKey(int userId, int serialNumber, boolean ephemeral)
public void destroyUserKey(int userId)
public void unlockUserKey(int userId, int serialNumber, byte[] token, byte[] secret)
public void lockUserKey(int userId)
public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags)
public void destroyUserStorage(String volumeUuid, int userId, int flags)
public static boolean isUserKeyUnlocked(int userId)
public boolean isEncrypted(File file)
public static boolean isEncryptable()
public static boolean isEncrypted()
public static boolean isFileEncryptedNativeOnly()
public static boolean isBlockEncrypted()
public static boolean isNonDefaultBlockEncrypted()
public static boolean isBlockEncrypting()
public static boolean inCryptKeeperBounce()
public static boolean isFileEncryptedEmulatedOnly()
public static boolean isFileEncryptedNativeOrEmulated()
public static File maybeTranslateEmulatedPathToInternal(File path)
public ParcelFileDescriptor mountAppFuse(String name)