Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a35add68 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Revert "Enforce USB and storage restrictions"

This reverts commit 39e53714ede48fcb464733834d7d9ccb868efe8a.

Change-Id: I81199fea8ca4b48516792bb02c1c3e90e5916c1f
parent 59f77c32
Loading
Loading
Loading
Loading
+1 −19
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.hardware.usb.UsbManager;
import android.app.admin.DevicePolicyManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Environment;
@@ -48,7 +47,6 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.IMountService;
import android.os.storage.IMountServiceListener;
import android.os.storage.IMountShutdownObserver;
@@ -1040,11 +1038,6 @@ class MountService extends IMountService.Stub
            volume = mVolumesByPath.get(path);
        }

        if (!volume.isEmulated() && hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA)) {
            Slog.w("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);
@@ -1244,17 +1237,6 @@ class MountService extends IMountService.Stub
        }
    }

    private boolean hasUserRestriction(String restriction) {
        UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        return um.hasUserRestriction(restriction, Binder.getCallingUserHandle());
    }

    private void validateUserRestriction(String restriction) {
        if (hasUserRestriction(restriction)) {
            throw new SecurityException("User has restriction " + restriction);
        }
    }

    // Storage list XML tags
    private static final String TAG_STORAGE_LIST = "StorageList";
    private static final String TAG_STORAGE = "storage";
@@ -1577,7 +1559,6 @@ class MountService extends IMountService.Stub
    public void setUsbMassStorageEnabled(boolean enable) {
        waitForReady();
        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
        validateUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);

        final StorageVolume primary = getPrimaryPhysicalVolume();
        if (primary == null) return;
@@ -1652,6 +1633,7 @@ class MountService extends IMountService.Stub

    public int mountVolume(String path) {
        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);

        waitForReady();
        return doMountVolume(path);
    }