diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2012-08-23 09:31:35 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-08-23 09:31:36 -0700 |
commit | 1183f487c8ea8660415fcd30914844e8dc2de2bb (patch) | |
tree | 66cf8a11f6383ef9128c587fe491af73adff278d /src/com/android/settings/deviceinfo | |
parent | 578700afb1f14c7b3a0ab8c7daa7a1e94628c1cb (diff) | |
parent | 8218d3ba180505a52998caa1fd9f6a1647984e7f (diff) | |
download | packages_apps_settings-1183f487c8ea8660415fcd30914844e8dc2de2bb.zip packages_apps_settings-1183f487c8ea8660415fcd30914844e8dc2de2bb.tar.gz packages_apps_settings-1183f487c8ea8660415fcd30914844e8dc2de2bb.tar.bz2 |
Merge "MTP/PTP: disable erasing/unmount operation for SD card while MTP/PTP is active"
Diffstat (limited to 'src/com/android/settings/deviceinfo')
-rw-r--r-- | src/com/android/settings/deviceinfo/Memory.java | 24 | ||||
-rw-r--r-- | src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java | 26 |
2 files changed, 47 insertions, 3 deletions
diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java index cabc6e9..f1c7fbe 100644 --- a/src/com/android/settings/deviceinfo/Memory.java +++ b/src/com/android/settings/deviceinfo/Memory.java @@ -24,6 +24,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; +import android.hardware.usb.UsbManager; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; @@ -65,6 +66,8 @@ public class Memory extends SettingsPreferenceFragment { private StorageManager mStorageManager = null; + private UsbManager mUsbManager = null; + private StorageVolumePreferenceCategory mInternalStorageVolumePreferenceCategory; private StorageVolumePreferenceCategory[] mStorageVolumePreferenceCategories; @@ -72,6 +75,8 @@ public class Memory extends SettingsPreferenceFragment { public void onCreate(Bundle icicle) { super.onCreate(icicle); + mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE); + if (mStorageManager == null) { mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE); mStorageManager.registerListener(mStorageListener); @@ -119,6 +124,10 @@ public class Memory extends SettingsPreferenceFragment { intentFilter.addDataScheme("file"); getActivity().registerReceiver(mMediaScannerReceiver, intentFilter); + intentFilter = new IntentFilter(); + intentFilter.addAction(UsbManager.ACTION_USB_STATE); + getActivity().registerReceiver(mMediaScannerReceiver, intentFilter); + if (mInternalStorageVolumePreferenceCategory != null) { mInternalStorageVolumePreferenceCategory.onResume(); } @@ -237,9 +246,18 @@ public class Memory extends SettingsPreferenceFragment { private final BroadcastReceiver mMediaScannerReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - // mInternalStorageVolumePreferenceCategory is not affected by the media scanner - for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) { - mStorageVolumePreferenceCategories[i].onMediaScannerFinished(); + String action = intent.getAction(); + if (action.equals(UsbManager.ACTION_USB_STATE)) { + boolean isUsbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false); + String usbFunction = mUsbManager.getDefaultFunction(); + for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) { + mStorageVolumePreferenceCategories[i].onUsbStateChanged(isUsbConnected, usbFunction); + } + } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) { + // mInternalStorageVolumePreferenceCategory is not affected by the media scanner + for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) { + mStorageVolumePreferenceCategories[i].onMediaScannerFinished(); + } } } }; diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java index 0211c77..156184a 100644 --- a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java +++ b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java @@ -24,6 +24,7 @@ import android.content.pm.IPackageManager; import android.content.res.Resources; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.RectShape; +import android.hardware.usb.UsbManager; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -69,6 +70,9 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen private boolean mAllowFormat; + private boolean mUsbConnected; + private String mUsbFunction; + static class CategoryInfo { final int mTitle; final int mColor; @@ -305,6 +309,23 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen removePreference(mFormatPreference); } } + + if (mUsbConnected && (UsbManager.USB_FUNCTION_MTP.equals(mUsbFunction) || + UsbManager.USB_FUNCTION_PTP.equals(mUsbFunction))) { + mMountTogglePreference.setEnabled(false); + if (Environment.MEDIA_MOUNTED.equals(state)) { + mMountTogglePreference.setSummary(mResources.getString(R.string.mtp_ptp_mode_summary)); + } + + if (mFormatPreference != null) { + mFormatPreference.setEnabled(false); + mFormatPreference.setSummary(mResources.getString(R.string.mtp_ptp_mode_summary)); + } + } else if (mFormatPreference != null) { + mFormatPreference.setEnabled(true); + mFormatPreference.setSummary(mResources.getString(R.string.sd_format_summary)); + } + } public void updateApproximate(long totalSize, long availSize) { @@ -376,6 +397,11 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen measure(); } + public void onUsbStateChanged(boolean isUsbConnected, String usbFunction) { + mUsbConnected = isUsbConnected; + mUsbFunction = usbFunction; + measure(); + } public void onMediaScannerFinished() { measure(); } |