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

Commit 2437f21f authored by Anil Kumar Jaiswal's avatar Anil Kumar Jaiswal Committed by Steve Kondik
Browse files

Revert "UsbSettings: Add UMS mode support."

This reverts commit f7d583229b6ca5f6a3779f6e1e9cfd40424d2de1

Change-Id: Icb23de13d36ad0cb251936e559459a8ca9f0d8bd
parent 38ce87e3
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.net.TrafficStats.MB_IN_BYTES;

import android.content.ContentResolver;
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
@@ -381,22 +380,6 @@ public class StorageManager {
       }
    }

    /**
     * Switch USB Mass Storage (UMS) on the device.
     *
     * @hide
     */
    public void setUsbMassStorageEnabled(boolean enable) {
        if (enable && UsbManager.USB_FUNCTION_MASS_STORAGE
                    .equals(new UsbManager(null, null).getDefaultFunction())) {
            if(!isUsbMassStorageEnabled()) {
                enableUsbMassStorage();
            }
        } else if (isUsbMassStorageEnabled()) {
            disableUsbMassStorage();
        }
   }

    /**
     * Enables USB Mass Storage (UMS) on the device.
     *
+0 −24
Original line number Diff line number Diff line
@@ -28,10 +28,8 @@ import android.os.HandlerThread;
import android.os.UserHandle;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;
import android.hardware.usb.UsbManager;

import com.android.systemui.SystemUI;

@@ -119,22 +117,13 @@ public class StorageNotification extends SystemUI {
             */
            connected = false;
        }
        //once UMS connected and SD card mounted, enable UMS
        if (connected && st.equals(Environment.MEDIA_MOUNTED)) {
            mStorageManager.setUsbMassStorageEnabled(true);
        }
        updateUsbMassStorageNotification(connected);
    }

    private void onStorageStateChangedAsync(String path, String oldState, String newState) {
        if (DEBUG) Log.i(TAG, String.format(
                "Media {%s} state changed from {%s} -> {%s}", path, oldState, newState));

        if (newState.equals(Environment.MEDIA_SHARED)) {
            if (!mUmsAvailable) {
                mStorageManager.disableUsbMassStorage();
            }

            /*
             * Storage is now shared. Modify the UMS notification
             * for stopping UMS.
@@ -157,10 +146,6 @@ public class StorageNotification extends SystemUI {
                    com.android.internal.R.drawable.stat_notify_sdcard_prepare, true, false, null);
            updateUsbMassStorageNotification(false);
        } else if (newState.equals(Environment.MEDIA_MOUNTED)) {
            String usbMode = new UsbManager(null, null).getDefaultFunction();
            final boolean isUmsMode = UsbManager.USB_FUNCTION_MASS_STORAGE.equals(usbMode);
            if (mUmsAvailable && isUmsMode)
                mStorageManager.enableUsbMassStorage();
            /*
             * Storage is now mounted. Dismiss any media notifications,
             * and enable UMS notification if connected.
@@ -287,15 +272,6 @@ public class StorageNotification extends SystemUI {
     */
    private synchronized void setUsbStorageNotification(int titleId, int messageId, int icon,
            boolean sound, boolean visible, PendingIntent pi) {
        // force to show UsbSettings screen to select usb mode if property is true
        if (SystemProperties.getBoolean("persist.sys.ums", true)) {
            titleId = 0;
            messageId = 0;
            icon = 0;
            sound = false;
            visible = false;
            pi = null;
        }

        if (!visible && mUsbStorageNotification == null) {
            return;
+47 −67
Original line number Diff line number Diff line
@@ -1236,14 +1236,10 @@ class MountService extends IMountService.Stub
            mSendUmsConnectedOnBoot = avail;
        }

        final ArrayList<String> volumes = getShareableVolumes();
        boolean mediaShared = false;
        for (String path : volumes) {
            if (getVolumeState(path).equals(Environment.MEDIA_SHARED))
                mediaShared = true;
        }

        if (avail == false && mediaShared) {
        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
             */
@@ -1253,17 +1249,12 @@ class MountService extends IMountService.Stub
                    try {
                        int rc;
                        Slog.w(TAG, "Disabling UMS after cable disconnect");
                        for (String path : volumes) {
                            if (getVolumeState(path).equals(Environment.MEDIA_SHARED)) {
                        doShareUnshareVolume(path, "ums", false);
                                rc = doMountVolume(path);
                                if (rc != StorageResultCode.OperationSucceeded) {
                        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);
                    }
@@ -1482,9 +1473,7 @@ class MountService extends IMountService.Stub

        // Watch for USB changes on primary volume
        final StorageVolume primary = getPrimaryPhysicalVolume();
        if ((primary != null && primary.allowMassStorage()) ||
            //ignore primary config, force to register if property is true
            SystemProperties.getBoolean("persist.sys.ums", true)) {
        if (primary != null && primary.allowMassStorage()) {
            mContext.registerReceiver(
                    mUsbReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE), null, mHandler);
        }
@@ -1613,19 +1602,6 @@ class MountService extends IMountService.Stub
        }
    }

    private ArrayList<String> getShareableVolumes() {
        // Sharable volumes have android:allowMassStorage="true" in storage_list.xml
        ArrayList<String> volumesToMount = new ArrayList<String>();
        synchronized (mVolumes) {
            for (StorageVolume v : mVolumes) {
                if (v.allowMassStorage()) {
                    volumesToMount.add(v.getPath());
                }
            }
        }
        return volumesToMount;
    }

    public boolean isUsbMassStorageConnected() {
        waitForReady();

@@ -1642,11 +1618,15 @@ class MountService extends IMountService.Stub
        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
        for (String path : getShareableVolumes()) {

        /*
         * 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)) {
@@ -1673,17 +1653,17 @@ class MountService extends IMountService.Stub
            }
        }
    }
    }

    public boolean isUsbMassStorageEnabled() {
        waitForReady();
        for (String path : getShareableVolumes()) {
            if (doGetVolumeShared(path, "ums"))
                return true;
        }
        // no volume is shared

        final StorageVolume primary = getPrimaryPhysicalVolume();
        if (primary != null) {
            return doGetVolumeShared(primary.getPath(), "ums");
        } else {
            return false;
        }
    }

    /**
     * @return state of the volume at the specified mount point
+0 −2
Original line number Diff line number Diff line
@@ -430,8 +430,6 @@ public class UsbDeviceManager {
            Message msg = Message.obtain(this, MSG_UPDATE_STATE);
            msg.arg1 = connected;
            msg.arg2 = configured;
            StorageManager storageManager = StorageManager.from(mContext);
            storageManager.setUsbMassStorageEnabled(mConnected);
            // debounce disconnects to avoid problems bringing up USB tethering
            sendMessageDelayed(msg, (connected == 0) ? UPDATE_DELAY : 0);
        }