Search in sources :

Example 1 with StorageVolume

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();
    }
}
Also used : StorageVolume(android.os.storage.StorageVolume) RemoteException(android.os.RemoteException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) HandlerThread(android.os.HandlerThread)

Example 2 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 3 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 4 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 5 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)

Aggregations

StorageVolume (android.os.storage.StorageVolume)59 StorageManager (android.os.storage.StorageManager)18 File (java.io.File)16 Intent (android.content.Intent)14 VolumeInfo (android.os.storage.VolumeInfo)10 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6 UserHandle (android.os.UserHandle)6 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