Search in sources :

Example 6 with StorageVolume

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.
                 */
        }
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume)

Example 7 with StorageVolume

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;
}
Also used : StorageVolume(android.os.storage.StorageVolume)

Example 8 with StorageVolume

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);
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume)

Example 9 with StorageVolume

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;
}
Also used : StorageVolume(android.os.storage.StorageVolume) IMountService(android.os.storage.IMountService) IOException(java.io.IOException)

Example 10 with StorageVolume

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;
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) IMountService(android.os.storage.IMountService)

Aggregations

StorageVolume (android.os.storage.StorageVolume)53 StorageManager (android.os.storage.StorageManager)13 File (java.io.File)13 Intent (android.content.Intent)11 VolumeInfo (android.os.storage.VolumeInfo)10 UserHandle (android.os.UserHandle)6 ArrayList (java.util.ArrayList)6 SuppressLint (android.annotation.SuppressLint)5 Parcelable (android.os.Parcelable)5 VolumeRecord (android.os.storage.VolumeRecord)5 ArraySet (android.util.ArraySet)5 AtomicFile (android.util.AtomicFile)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IOException (java.io.IOException)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 HandlerThread (android.os.HandlerThread)2 RemoteException (android.os.RemoteException)2 IMountService (android.os.storage.IMountService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2