use of android.os.storage.StorageVolume in project android_frameworks_base by ParanoidAndroid.
the class MountService method notifyShareAvailabilityChange.
private void notifyShareAvailabilityChange(final boolean avail) {
synchronized (mListeners) {
mUmsAvailable = avail;
for (int i = mListeners.size() - 1; i >= 0; i--) {
MountServiceBinderListener bl = mListeners.get(i);
try {
bl.mListener.onUsbMassStorageConnectionChanged(avail);
} catch (RemoteException rex) {
Slog.e(TAG, "Listener dead");
mListeners.remove(i);
} catch (Exception ex) {
Slog.e(TAG, "Listener failed", ex);
}
}
}
if (mSystemReady == true) {
sendUmsIntent(avail);
} else {
mSendUmsConnectedOnBoot = avail;
}
final StorageVolume primary = getPrimaryPhysicalVolume();
if (avail == false && primary != null && Environment.MEDIA_SHARED.equals(getVolumeState(primary.getPath()))) {
final String path = primary.getPath();
/*
* USB mass storage disconnected while enabled
*/
new Thread() {
@Override
public void run() {
try {
int rc;
Slog.w(TAG, "Disabling UMS after cable disconnect");
doShareUnshareVolume(path, "ums", false);
if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
Slog.e(TAG, String.format("Failed to remount {%s} on UMS enabled-disconnect (%d)", path, rc));
}
} catch (Exception ex) {
Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex);
}
}
}.start();
}
}
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;
}
Aggregations