diff options
author | Gilles Debunne <debunne@google.com> | 2011-06-02 15:07:51 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-06-02 15:07:51 -0700 |
commit | 8d055f3270d5de4ae9647f620dddfbed5b929de3 (patch) | |
tree | b884df0525dfd452b4c714a59e4c739c6a60b4bb /src | |
parent | 275ffe60ebe10748cedf08328db6c8509e116eae (diff) | |
parent | b667422cfdaf73d693bf79ce6186e082b68862b8 (diff) | |
download | packages_apps_settings-8d055f3270d5de4ae9647f620dddfbed5b929de3.zip packages_apps_settings-8d055f3270d5de4ae9647f620dddfbed5b929de3.tar.gz packages_apps_settings-8d055f3270d5de4ae9647f620dddfbed5b929de3.tar.bz2 |
am b667422c: am 41a99004: am 53872769: Merge "Erase SD Card fixed in Settings/Storage." into honeycomb-mr2
* commit 'b667422cfdaf73d693bf79ce6186e082b68862b8':
Erase SD Card fixed in Settings/Storage.
Diffstat (limited to 'src')
4 files changed, 41 insertions, 52 deletions
diff --git a/src/com/android/settings/MediaFormat.java b/src/com/android/settings/MediaFormat.java index d8d57e4..dc495ec 100644 --- a/src/com/android/settings/MediaFormat.java +++ b/src/com/android/settings/MediaFormat.java @@ -19,6 +19,7 @@ package com.android.settings; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.os.storage.StorageVolume; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; @@ -57,6 +58,10 @@ public class MediaFormat extends Activity { } Intent intent = new Intent(ExternalStorageFormatter.FORMAT_ONLY); intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); + // Transfer the storage volume to the new intent + final StorageVolume storageVolume = getIntent().getParcelableExtra( + StorageVolume.EXTRA_STORAGE_VOLUME); + intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, storageVolume); startService(intent); finish(); } diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java index 955e578..6e7af5c 100644 --- a/src/com/android/settings/deviceinfo/Memory.java +++ b/src/com/android/settings/deviceinfo/Memory.java @@ -28,7 +28,6 @@ import android.content.res.Resources; import android.os.Bundle; import android.os.Environment; import android.os.IBinder; -import android.os.Parcelable; import android.os.RemoteException; import android.os.ServiceManager; import android.os.storage.IMountService; @@ -76,23 +75,17 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen mResources = getResources(); - try { - IMountService mountService = IMountService.Stub.asInterface(ServiceManager - .getService("mount")); - Parcelable[] volumes = mountService.getVolumeList(); - int length = volumes.length; - mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length]; - for (int i = 0; i < length; i++) { - StorageVolume storageVolume = (StorageVolume) volumes[i]; - StorageVolumePreferenceCategory storagePreferenceCategory = - new StorageVolumePreferenceCategory(getActivity(), mResources, storageVolume, - i == 0); // The first volume is the primary volume - mStorageVolumePreferenceCategories[i] = storagePreferenceCategory; - getPreferenceScreen().addPreference(storagePreferenceCategory); - storagePreferenceCategory.init(); - } - } catch (Exception e) { - Log.e(TAG, "couldn't talk to MountService", e); + StorageVolume[] storageVolumes = mStorageManager.getVolumeList(); + int length = storageVolumes.length; + mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length]; + for (int i = 0; i < length; i++) { + StorageVolume storageVolume = storageVolumes[i]; + StorageVolumePreferenceCategory storagePreferenceCategory = + new StorageVolumePreferenceCategory(getActivity(), mResources, storageVolume, + mStorageManager, i == 0); // The first volume is the primary volume + mStorageVolumePreferenceCategories[i] = storagePreferenceCategory; + getPreferenceScreen().addPreference(storagePreferenceCategory); + storagePreferenceCategory.init(); } } @@ -117,7 +110,7 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen " to " + newState); for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) { StorageVolumePreferenceCategory svpc = mStorageVolumePreferenceCategories[i]; - if (path.equals(svpc.getMountPoint())) { + if (path.equals(svpc.getStorageVolume().getPath())) { svpc.onStorageStateChanged(); break; } @@ -167,10 +160,11 @@ public class Memory extends SettingsPreferenceFragment implements OnCancelListen boolean mountToggleClicked = svpc.mountToggleClicked(preference); if (mountToggleClicked && mClickedMountToggle == null) { mClickedMountToggle = preference; - mClickedMountPoint = svpc.getMountPoint(); - String state = svpc.getStorageVolumeState(); - if (state.equals(Environment.MEDIA_MOUNTED) || - state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { + final StorageVolume storageVolume = svpc.getStorageVolume(); + mClickedMountPoint = storageVolume.getPath(); + String state = mStorageManager.getVolumeState(storageVolume.getPath()); + if (Environment.MEDIA_MOUNTED.equals(state) || + Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { unmount(); } else { mount(); diff --git a/src/com/android/settings/deviceinfo/MiscFilesHandler.java b/src/com/android/settings/deviceinfo/MiscFilesHandler.java index eae6861..2f9697f 100644 --- a/src/com/android/settings/deviceinfo/MiscFilesHandler.java +++ b/src/com/android/settings/deviceinfo/MiscFilesHandler.java @@ -191,11 +191,11 @@ public class MiscFilesHandler extends ListActivity { public MemoryMearurementAdapter(Activity activity) { mContext = activity; - final Bundle extras = activity.getIntent().getExtras(); - final StorageVolume storageVolume = extras.getParcelable( - StorageVolumePreferenceCategory.STORAGE_VOLUME); + final StorageVolume storageVolume = activity.getIntent().getParcelableExtra( + StorageVolume.EXTRA_STORAGE_VOLUME); StorageMeasurement mMeasurement = - StorageMeasurement.getInstance(activity, storageVolume, false); + StorageMeasurement.getInstance(activity, storageVolume, false /*Unused as a key*/); + if (mMeasurement == null) return; mData = (ArrayList<StorageMeasurement.FileInfo>) mMeasurement.mFileInfoForMisc; if (mData != null) { for (StorageMeasurement.FileInfo info : mData) { diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java index 7b52bcb..83f9ee2 100644 --- a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java +++ b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java @@ -26,8 +26,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; -import android.os.ServiceManager; -import android.os.storage.IMountService; +import android.os.storage.StorageManager; import android.os.storage.StorageVolume; import android.preference.Preference; import android.preference.PreferenceCategory; @@ -60,6 +59,8 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen private StorageVolume mStorageVolume; + private StorageManager mStorageManager = null; + private StorageMeasurement mMeasurement; static class CategoryInfo { @@ -126,9 +127,6 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen // Updates the memory usage bar graph. private static final int MSG_UI_UPDATE_EXACT = 2; - // Key for the extra StorageVolume bundle added to the Misc intent. - static final String STORAGE_VOLUME = "storage_volume"; - private Handler mUpdateHandler = new Handler() { @Override public void handleMessage(Message msg) { @@ -157,10 +155,11 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen }; public StorageVolumePreferenceCategory(Context context, Resources resources, - StorageVolume storageVolume, boolean isPrimary) { + StorageVolume storageVolume, StorageManager storageManager, boolean isPrimary) { super(context); mResources = resources; mStorageVolume = storageVolume; + mStorageManager = storageManager; setTitle(storageVolume.getDescription()); mMeasurement = StorageMeasurement.getInstance(context, storageVolume, isPrimary); mMeasurement.setReceiver(this); @@ -196,18 +195,8 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen mFormatPreference.setSummary(R.string.sd_format_summary); } - public String getMountPoint() { - return mStorageVolume.getPath(); - } - - public String getStorageVolumeState() { - try { - IMountService mountService = - IMountService.Stub.asInterface(ServiceManager.getService("mount")); - return mountService.getVolumeState(getMountPoint()); - } catch (Exception rex) { - return Environment.MEDIA_REMOVED; - } + public StorageVolume getStorageVolume() { + return mStorageVolume; } /** @@ -237,10 +226,10 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen private void updatePreferencesFromState() { resetPreferences(); - String state = getStorageVolumeState(); + String state = mStorageManager.getVolumeState(mStorageVolume.getPath()); String readOnly = ""; - if (state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { + if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { state = Environment.MEDIA_MOUNTED; readOnly = mResources.getString(R.string.read_only); removePreference(mFormatPreference); @@ -250,21 +239,21 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen removePreference(mFormatPreference); } - if (!mStorageVolume.isRemovable() && !state.equals(Environment.MEDIA_UNMOUNTED)) { + if (!mStorageVolume.isRemovable() && !Environment.MEDIA_UNMOUNTED.equals(state)) { // This device has built-in storage that is not removable. // There is no reason for the user to unmount it. removePreference(mMountTogglePreference); } - if (state.equals(Environment.MEDIA_MOUNTED)) { + if (Environment.MEDIA_MOUNTED.equals(state)) { mPreferences[AVAILABLE].setSummary(mPreferences[AVAILABLE].getSummary() + readOnly); mMountTogglePreference.setEnabled(true); mMountTogglePreference.setTitle(mResources.getString(R.string.sd_eject)); mMountTogglePreference.setSummary(mResources.getString(R.string.sd_eject_summary)); } else { - if (state.equals(Environment.MEDIA_UNMOUNTED) || state.equals(Environment.MEDIA_NOFS) - || state.equals(Environment.MEDIA_UNMOUNTABLE)) { + if (Environment.MEDIA_UNMOUNTED.equals(state) || Environment.MEDIA_NOFS.equals(state) + || Environment.MEDIA_UNMOUNTABLE.equals(state)) { mMountTogglePreference.setEnabled(true); mMountTogglePreference.setTitle(mResources.getString(R.string.sd_mount)); mMountTogglePreference.setSummary(mResources.getString(R.string.sd_mount_summary)); @@ -391,6 +380,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen if (preference == mFormatPreference) { intent = new Intent(Intent.ACTION_VIEW); intent.setClass(getContext(), com.android.settings.MediaFormat.class); + intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mStorageVolume); } else if (preference == mPreferences[APPLICATIONS]) { intent = new Intent(Intent.ACTION_MANAGE_PACKAGE_STORAGE); intent.setClass(getContext(), @@ -408,7 +398,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen Context context = getContext().getApplicationContext(); if (mMeasurement.getMiscSize() > 0) { intent = new Intent(context, MiscFilesHandler.class); - intent.putExtra(STORAGE_VOLUME, mStorageVolume); + intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mStorageVolume); } } |