diff options
author | Espen Fjellvær Olsen <espen@mrfjo.org> | 2013-01-23 20:07:20 +0100 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.cyanogenmod.com> | 2013-01-26 22:05:54 -0800 |
commit | cba4c32f67a1f9e093cfd2b971543db5ffaeb6b0 (patch) | |
tree | 5386a9bd093798d1bd39b6289a34b75275fe265d /src/com/android/settings/deviceinfo | |
parent | 7d1af4cf5075b382ef0b6c87362d61207ebe86e1 (diff) | |
download | packages_apps_settings-cba4c32f67a1f9e093cfd2b971543db5ffaeb6b0.zip packages_apps_settings-cba4c32f67a1f9e093cfd2b971543db5ffaeb6b0.tar.gz packages_apps_settings-cba4c32f67a1f9e093cfd2b971543db5ffaeb6b0.tar.bz2 |
Add option for switching between UMS and MTP/PTP mode. (2/2)
Change-Id: I6cf50a41a9a82e40e702f5231ce663636c149613
This adds support for switching between UMS and MTP/PTP.
Settings part (this part) adds option in USB settings (statusbar/notification drawer) for enabling UMS,
and adds setting in Storage menu to enable / disable UMS, this since the USB settings page disappears when enabling UMS.
It's only porting this http://review.cyanogenmod.org/#/c/21115/
Diffstat (limited to 'src/com/android/settings/deviceinfo')
-rw-r--r-- | src/com/android/settings/deviceinfo/Memory.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/deviceinfo/UsbSettings.java | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java index 825a7be..529c81c 100644 --- a/src/com/android/settings/deviceinfo/Memory.java +++ b/src/com/android/settings/deviceinfo/Memory.java @@ -174,7 +174,7 @@ public class Memory extends SettingsPreferenceFragment { @Override public void onPrepareOptionsMenu(Menu menu) { final MenuItem usb = menu.findItem(R.id.storage_usb); - usb.setVisible(!isMassStorageEnabled()); + usb.setVisible(true); } @Override diff --git a/src/com/android/settings/deviceinfo/UsbSettings.java b/src/com/android/settings/deviceinfo/UsbSettings.java index b8290fc..79f315f 100644 --- a/src/com/android/settings/deviceinfo/UsbSettings.java +++ b/src/com/android/settings/deviceinfo/UsbSettings.java @@ -26,6 +26,8 @@ import android.content.Intent; import android.content.IntentFilter; import android.hardware.usb.UsbManager; import android.os.Bundle; +import android.os.storage.StorageManager; +import android.os.storage.StorageVolume; import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceScreen; @@ -45,10 +47,14 @@ public class UsbSettings extends SettingsPreferenceFragment { private static final String KEY_MTP = "usb_mtp"; private static final String KEY_PTP = "usb_ptp"; + private static final String KEY_MASS_STORAGE = "usb_mass_storage"; private UsbManager mUsbManager; + private StorageManager storageManager; + private StorageVolume[] storageVolumes; private CheckBoxPreference mMtp; private CheckBoxPreference mPtp; + private CheckBoxPreference mUms; private boolean mUsbAccessoryMode; private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() { @@ -72,6 +78,10 @@ public class UsbSettings extends SettingsPreferenceFragment { mMtp = (CheckBoxPreference)root.findPreference(KEY_MTP); mPtp = (CheckBoxPreference)root.findPreference(KEY_PTP); + mUms = (CheckBoxPreference)root.findPreference(KEY_MASS_STORAGE); + if (!storageVolumes[0].allowMassStorage()) { + root.removePreference(mUms); + } return root; } @@ -80,6 +90,8 @@ public class UsbSettings extends SettingsPreferenceFragment { public void onCreate(Bundle icicle) { super.onCreate(icicle); mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE); + storageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE); + storageVolumes = storageManager.getVolumeList(); } @Override @@ -105,12 +117,19 @@ public class UsbSettings extends SettingsPreferenceFragment { if (UsbManager.USB_FUNCTION_MTP.equals(function)) { mMtp.setChecked(true); mPtp.setChecked(false); + mUms.setChecked(false); } else if (UsbManager.USB_FUNCTION_PTP.equals(function)) { mMtp.setChecked(false); + mUms.setChecked(false); mPtp.setChecked(true); + } else if (UsbManager.USB_FUNCTION_MASS_STORAGE.equals(function)) { + mMtp.setChecked(false); + mPtp.setChecked(false); + mUms.setChecked(true); } else { mMtp.setChecked(false); mPtp.setChecked(false); + mUms.setChecked(false); } if (!mUsbAccessoryMode) { @@ -144,11 +163,17 @@ public class UsbSettings extends SettingsPreferenceFragment { } } if (preference == mMtp) { + Settings.Secure.putInt(getContentResolver(), Settings.Secure.USB_MASS_STORAGE_ENABLED, 0 ); mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true); updateToggles(UsbManager.USB_FUNCTION_MTP); } else if (preference == mPtp) { + Settings.Secure.putInt(getContentResolver(), Settings.Secure.USB_MASS_STORAGE_ENABLED, 0 ); mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP, true); updateToggles(UsbManager.USB_FUNCTION_PTP); + } else if (preference == mUms) { + Settings.Secure.putInt(getContentResolver(), Settings.Secure.USB_MASS_STORAGE_ENABLED, 1 ); + mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MASS_STORAGE, true); + updateToggles(UsbManager.USB_FUNCTION_MASS_STORAGE); } return true; } |