Example usage for android.os UserManager DISALLOW_USB_FILE_TRANSFER

List of usage examples for android.os UserManager DISALLOW_USB_FILE_TRANSFER

Introduction

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

Prototype

String DISALLOW_USB_FILE_TRANSFER

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

Click Source Link

Document

Specifies if a user is disallowed from transferring files over USB.

Usage

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

public void setUsbMassStorageEnabled(boolean enable) {
    waitForReady();/*from www  .ja  v a 2s.c o  m*/
    validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
    validateUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);

    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.
             */
        }
    }
}