use of android.os.storage.StorageVolume in project android_frameworks_base by ParanoidAndroid.
the class MountService method setUsbMassStorageEnabled.
public void setUsbMassStorageEnabled(boolean enable) {
waitForReady();
validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
final StorageVolume primary = getPrimaryPhysicalVolume();
if (primary == null)
return;
// TODO: Add support for multiple share methods
/*
* If the volume is mounted and we're enabling then unmount it
*/
String path = primary.getPath();
String vs = getVolumeState(path);
String method = "ums";
if (enable && vs.equals(Environment.MEDIA_MOUNTED)) {
// Override for isUsbMassStorageEnabled()
setUmsEnabling(enable);
UmsEnableCallBack umscb = new UmsEnableCallBack(path, method, true);
mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, umscb));
// Clear override
setUmsEnabling(false);
}
/*
* If we disabled UMS then mount the volume
*/
if (!enable) {
doShareUnshareVolume(path, method, enable);
if (doMountVolume(path) != StorageResultCode.OperationSucceeded) {
Slog.e(TAG, "Failed to remount " + path + " after disabling share method " + method);
/*
* Even though the mount failed, the unshare didn't so don't indicate an error.
* The mountVolume() call will have set the storage state and sent the necessary
* broadcasts.
*/
}
}
}
use of android.os.storage.StorageVolume in project android_frameworks_base by ParanoidAndroid.
the class MountService method doMountVolume.
private int doMountVolume(String path) {
int rc = StorageResultCode.OperationSucceeded;
final StorageVolume volume;
synchronized (mVolumesLock) {
volume = mVolumesByPath.get(path);
}
if (DEBUG_EVENTS)
Slog.i(TAG, "doMountVolume: Mouting " + path);
try {
mConnector.execute("volume", "mount", path);
} catch (NativeDaemonConnectorException e) {
/*
* Mount failed for some reason
*/
String action = null;
int code = e.getCode();
if (code == VoldResponseCode.OpFailedNoMedia) {
/*
* Attempt to mount but no media inserted
*/
rc = StorageResultCode.OperationFailedNoMedia;
} else if (code == VoldResponseCode.OpFailedMediaBlank) {
if (DEBUG_EVENTS)
Slog.i(TAG, " updating volume state :: media nofs");
/*
* Media is blank or does not contain a supported filesystem
*/
updatePublicVolumeState(volume, Environment.MEDIA_NOFS);
action = Intent.ACTION_MEDIA_NOFS;
rc = StorageResultCode.OperationFailedMediaBlank;
} else if (code == VoldResponseCode.OpFailedMediaCorrupt) {
if (DEBUG_EVENTS)
Slog.i(TAG, "updating volume state media corrupt");
/*
* Volume consistency check failed
*/
updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTABLE);
action = Intent.ACTION_MEDIA_UNMOUNTABLE;
rc = StorageResultCode.OperationFailedMediaCorrupt;
} else {
rc = StorageResultCode.OperationFailedInternalError;
}
/*
* Send broadcast intent (if required for the failure)
*/
if (action != null) {
sendStorageIntent(action, volume, UserHandle.ALL);
}
}
return rc;
}
use of android.os.storage.StorageVolume in project android_frameworks_base by ParanoidAndroid.
the class MountService method addVolumeLocked.
private void addVolumeLocked(StorageVolume volume) {
Slog.d(TAG, "addVolumeLocked() " + volume);
mVolumes.add(volume);
final StorageVolume existing = mVolumesByPath.put(volume.getPath(), volume);
if (existing != null) {
throw new IllegalStateException("Volume at " + volume.getPath() + " already exists: " + existing);
}
}
use of android.os.storage.StorageVolume in project android_frameworks_base by ParanoidAndroid.
the class Environment method getPrimaryVolume.
private static StorageVolume getPrimaryVolume() {
if (sPrimaryVolume == null) {
synchronized (sLock) {
if (sPrimaryVolume == null) {
try {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
final StorageVolume[] volumes = mountService.getVolumeList();
sPrimaryVolume = StorageManager.getPrimaryVolume(volumes);
} catch (Exception e) {
Log.e(TAG, "couldn't talk to MountService", e);
}
}
}
}
return sPrimaryVolume;
}
use of android.os.storage.StorageVolume in project android_frameworks_base by ParanoidAndroid.
the class Environment method getExternalStorageState.
/**
* Gets the current state of the primary "external" storage device.
*
* @see #getExternalStorageDirectory()
*/
public static String getExternalStorageState() {
try {
IMountService mountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
final StorageVolume primary = getPrimaryVolume();
return mountService.getVolumeState(primary.getPath());
} catch (RemoteException rex) {
Log.w(TAG, "Failed to read external storage state; assuming REMOVED: " + rex);
return Environment.MEDIA_REMOVED;
}
}
Aggregations