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

Commit 5eee0838 authored by Espen Fjellvær Olsen's avatar Espen Fjellvær Olsen
Browse files

Add option for switching between UMS and MTP/PTP mode. (1/2)

This adds support for switching between UMS and MTP/PTP.
Framework part (this part) will only enable UMS if the config setting is set.
Standard is to enable UMS if the primary volume supports UMS.

p2: Fix compile error
p3: Some code styling
p4: Fix mysterious bug where USB notification is not fired when switching from UMS.
p5: Revert last commit.

Change-Id: I753b7dd3823958da1b043ca44b50118d67637cc1
parent d628aa06
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -176,9 +176,15 @@ public class LegacyUsbDeviceManager extends UsbDeviceManager {
        StorageManager storageManager = (StorageManager)
        StorageManager storageManager = (StorageManager)
                mContext.getSystemService(Context.STORAGE_SERVICE);
                mContext.getSystemService(Context.STORAGE_SERVICE);
        StorageVolume[] volumes = storageManager.getVolumeList();
        StorageVolume[] volumes = storageManager.getVolumeList();

        if (volumes.length > 0) {
        if (volumes.length > 0) {
            if (Settings.Secure.getInt(mContentResolver, Settings.Secure.USB_MASS_STORAGE_ENABLED, 0) == 1 ) {
                massStorageSupported = volumes[0].allowMassStorage();
                massStorageSupported = volumes[0].allowMassStorage();
            } else {
                massStorageSupported = false;
            }
            }
        }

        mUseUsbNotification = !massStorageSupported;
        mUseUsbNotification = !massStorageSupported;


        // make sure the ADB_ENABLED setting value matches the current state
        // make sure the ADB_ENABLED setting value matches the current state
@@ -543,10 +549,10 @@ public class LegacyUsbDeviceManager extends UsbDeviceManager {
                    id = com.android.internal.R.string.usb_mtp_notification_title;
                    id = com.android.internal.R.string.usb_mtp_notification_title;
                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
                    id = com.android.internal.R.string.usb_ptp_notification_title;
                    id = com.android.internal.R.string.usb_ptp_notification_title;
                } else if (containsFunction(mCurrentFunctions,
                } /* else if (containsFunction(mCurrentFunctions, 
                        UsbManager.USB_FUNCTION_MASS_STORAGE)) {
                        UsbManager.USB_FUNCTION_MASS_STORAGE)) { // Disable this as it causes double USB settings menues when in UMS mode.
                        id = com.android.internal.R.string.usb_cd_installer_notification_title; 
                        id = com.android.internal.R.string.usb_cd_installer_notification_title; 
                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
                } */ else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
                    id = com.android.internal.R.string.usb_accessory_notification_title;
                    id = com.android.internal.R.string.usb_accessory_notification_title;
                } else {
                } else {
                    // There is a different notification for USB tethering so we don't need one here
                    // There is a different notification for USB tethering so we don't need one here
+11 −5
Original line number Original line Diff line number Diff line
@@ -179,9 +179,15 @@ public class UsbDeviceManager {
        StorageManager storageManager = (StorageManager)
        StorageManager storageManager = (StorageManager)
                mContext.getSystemService(Context.STORAGE_SERVICE);
                mContext.getSystemService(Context.STORAGE_SERVICE);
        StorageVolume[] volumes = storageManager.getVolumeList();
        StorageVolume[] volumes = storageManager.getVolumeList();

        if (volumes.length > 0) {
        if (volumes.length > 0) {
            if (Settings.Secure.getInt(mContentResolver, Settings.Secure.USB_MASS_STORAGE_ENABLED, 0) == 1 ) {
                massStorageSupported = volumes[0].allowMassStorage();
                massStorageSupported = volumes[0].allowMassStorage();
            } else {
                massStorageSupported = false;
            }
            }
        }

        mUseUsbNotification = !massStorageSupported;
        mUseUsbNotification = !massStorageSupported;


        // make sure the ADB_ENABLED setting value matches the current state
        // make sure the ADB_ENABLED setting value matches the current state
@@ -565,10 +571,10 @@ public class UsbDeviceManager {
                    id = com.android.internal.R.string.usb_mtp_notification_title;
                    id = com.android.internal.R.string.usb_mtp_notification_title;
                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
                    id = com.android.internal.R.string.usb_ptp_notification_title;
                    id = com.android.internal.R.string.usb_ptp_notification_title;
                } else if (containsFunction(mCurrentFunctions,
                } /* else if (containsFunction(mCurrentFunctions,
                        UsbManager.USB_FUNCTION_MASS_STORAGE)) {
                     UsbManager.USB_FUNCTION_MASS_STORAGE)) { // Disable this as it causes double USB settings menues when in UMS mode.
                     id = com.android.internal.R.string.usb_cd_installer_notification_title; 
                     id = com.android.internal.R.string.usb_cd_installer_notification_title; 
                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
                     } */ else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
                    id = com.android.internal.R.string.usb_accessory_notification_title;
                    id = com.android.internal.R.string.usb_accessory_notification_title;
                } else {
                } else {
                    // There is a different notification for USB tethering so we don't need one here
                    // There is a different notification for USB tethering so we don't need one here