Example usage for android.os UserManager DISALLOW_MOUNT_PHYSICAL_MEDIA

List of usage examples for android.os UserManager DISALLOW_MOUNT_PHYSICAL_MEDIA

Introduction

In this page you can find the example usage for android.os UserManager DISALLOW_MOUNT_PHYSICAL_MEDIA.

Prototype

String DISALLOW_MOUNT_PHYSICAL_MEDIA

To view the source code for android.os UserManager DISALLOW_MOUNT_PHYSICAL_MEDIA.

Click Source Link

Document

Specifies if a user is disallowed from mounting physical external media.

Usage

From source file:com.android.server.MountService.java

private int doMountVolume(String path) {
    int rc = StorageResultCode.OperationSucceeded;

    final StorageVolume volume;
    synchronized (mVolumesLock) {
        volume = mVolumesByPath.get(path);
    }/*www.  j  a v  a 2 s. c  o  m*/

    if (!volume.isEmulated() && hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA)) {
        Slog.w(TAG, "User has restriction DISALLOW_MOUNT_PHYSICAL_MEDIA; cannot mount volume.");
        return StorageResultCode.OperationFailedInternalError;
    }

    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;
}