Fields Summary |
---|
private static final String | TAG |
private final android.content.ContentResolver | mResolver |
private final IMountService | mMountService |
private final android.os.Looper | mTgtLooper |
private MountServiceBinderListener | mBinderListener |
private List | mListeners |
private final AtomicInteger | mNextNonce |
private final ObbActionListener | mObbActionListenerBinder listener for OBB action results. |
private static final int | DEFAULT_THRESHOLD_PERCENTAGE |
private static final long | DEFAULT_THRESHOLD_MAX_BYTES |
private static final long | DEFAULT_FULL_THRESHOLD_BYTES |
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 |
Methods Summary |
---|
public void | disableUsbMassStorage()Disables USB Mass Storage (UMS) on the device.
try {
mMountService.setUsbMassStorageEnabled(false);
} catch (Exception ex) {
Log.e(TAG, "Failed to disable UMS", ex);
}
|
public void | enableUsbMassStorage()Enables USB Mass Storage (UMS) on the device.
try {
mMountService.setUsbMassStorageEnabled(true);
} catch (Exception ex) {
Log.e(TAG, "Failed to enable UMS", ex);
}
|
public static android.os.storage.StorageManager | from(android.content.Context context){@hide}
return (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
|
public java.lang.String | getMountedObbPath(java.lang.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.
Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
try {
return mMountService.getMountedObbPath(rawPath);
} catch (RemoteException e) {
Log.e(TAG, "Failed to find mounted path for OBB", e);
}
return null;
|
private int | getNextNonce()
return mNextNonce.getAndIncrement();
|
public StorageVolume | getPrimaryVolume(){@hide}
return getPrimaryVolume(getVolumeList());
|
public static StorageVolume | getPrimaryVolume(StorageVolume[] volumes){@hide}
for (StorageVolume volume : volumes) {
if (volume.isPrimary()) {
return volume;
}
}
Log.w(TAG, "No primary storage defined");
return null;
|
public long | getStorageBytesUntilLow(java.io.File path)Return the number of available bytes until the given path is considered
running low on storage.
return path.getUsableSpace() - getStorageFullBytes(path);
|
public long | getStorageFullBytes(java.io.File path)Return the number of available bytes at which the given path is
considered full.
return Settings.Global.getLong(mResolver, Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
DEFAULT_FULL_THRESHOLD_BYTES);
|
public long | getStorageLowBytes(java.io.File path)Return the number of available bytes at which the given path is
considered running low on storage.
final long lowPercent = Settings.Global.getInt(mResolver,
Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE, DEFAULT_THRESHOLD_PERCENTAGE);
final long lowBytes = (path.getTotalSpace() * lowPercent) / 100;
final long maxLowBytes = Settings.Global.getLong(mResolver,
Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES, DEFAULT_THRESHOLD_MAX_BYTES);
return Math.min(lowBytes, maxLowBytes);
|
public StorageVolume[] | getVolumeList()Returns list of all mountable volumes.
if (mMountService == null) return new StorageVolume[0];
try {
Parcelable[] list = mMountService.getVolumeList();
if (list == null) return new StorageVolume[0];
int length = list.length;
StorageVolume[] result = new StorageVolume[length];
for (int i = 0; i < length; i++) {
result[i] = (StorageVolume)list[i];
}
return result;
} catch (RemoteException e) {
Log.e(TAG, "Failed to get volume list", e);
return null;
}
|
public java.lang.String[] | getVolumePaths()Returns list of paths for all mountable volumes.
StorageVolume[] volumes = getVolumeList();
if (volumes == null) return null;
int count = volumes.length;
String[] paths = new String[count];
for (int i = 0; i < count; i++) {
paths[i] = volumes[i].getPath();
}
return paths;
|
public java.lang.String | getVolumeState(java.lang.String mountPoint)Gets the state of a volume via its mountpoint.
if (mMountService == null) return Environment.MEDIA_REMOVED;
try {
return mMountService.getVolumeState(mountPoint);
} catch (RemoteException e) {
Log.e(TAG, "Failed to get volume state", e);
return null;
}
|
public boolean | isObbMounted(java.lang.String rawPath)Check whether an Opaque Binary Blob (OBB) is mounted or not.
Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
try {
return mMountService.isObbMounted(rawPath);
} catch (RemoteException e) {
Log.e(TAG, "Failed to check if OBB is mounted", e);
}
return false;
|
public boolean | isUsbMassStorageConnected()Query if a USB Mass Storage (UMS) host is connected.
try {
return mMountService.isUsbMassStorageConnected();
} catch (Exception ex) {
Log.e(TAG, "Failed to get UMS connection state", ex);
}
return false;
|
public boolean | isUsbMassStorageEnabled()Query if a USB Mass Storage (UMS) is enabled on the device.
try {
return mMountService.isUsbMassStorageEnabled();
} catch (RemoteException rex) {
Log.e(TAG, "Failed to get UMS enable state", rex);
}
return false;
|
public boolean | mountObb(java.lang.String rawPath, java.lang.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 {@link 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.
Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
Preconditions.checkNotNull(listener, "listener cannot be null");
try {
final String canonicalPath = new File(rawPath).getCanonicalPath();
final int nonce = mObbActionListener.addListener(listener);
mMountService.mountObb(rawPath, canonicalPath, key, mObbActionListener, nonce);
return true;
} catch (IOException e) {
throw new IllegalArgumentException("Failed to resolve path: " + rawPath, e);
} catch (RemoteException e) {
Log.e(TAG, "Failed to mount OBB", e);
}
return false;
|
public void | registerListener(StorageEventListener listener)Registers a {@link android.os.storage.StorageEventListener StorageEventListener}.
if (listener == null) {
return;
}
synchronized (mListeners) {
if (mBinderListener == null ) {
try {
mBinderListener = new MountServiceBinderListener();
mMountService.registerListener(mBinderListener);
} catch (RemoteException rex) {
Log.e(TAG, "Register mBinderListener failed");
return;
}
}
mListeners.add(new ListenerDelegate(listener));
}
|
public boolean | unmountObb(java.lang.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 {@link 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.
Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
Preconditions.checkNotNull(listener, "listener cannot be null");
try {
final int nonce = mObbActionListener.addListener(listener);
mMountService.unmountObb(rawPath, force, mObbActionListener, nonce);
return true;
} catch (RemoteException e) {
Log.e(TAG, "Failed to mount OBB", e);
}
return false;
|
public void | unregisterListener(StorageEventListener listener)Unregisters a {@link android.os.storage.StorageEventListener StorageEventListener}.
if (listener == null) {
return;
}
synchronized (mListeners) {
final int size = mListeners.size();
for (int i=0 ; i<size ; i++) {
ListenerDelegate l = mListeners.get(i);
if (l.getListener() == listener) {
mListeners.remove(i);
break;
}
}
if (mListeners.size() == 0 && mBinderListener != null) {
try {
mMountService.unregisterListener(mBinderListener);
} catch (RemoteException rex) {
Log.e(TAG, "Unregister mBinderListener failed");
return;
}
}
}
|