summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-09-06 23:26:15 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-09-06 23:26:15 -0700
commit7121c191dd30ab6666ac3275d495700c6f24b07e (patch)
tree617b78e7508b09aec3d3da32b258074cf66cbc03
parenta149c0879bf971a87a938166a9da2223767087f6 (diff)
parente8d2ae5f175bdca0eedf44c0207740678102bb46 (diff)
downloadpackages_apps_settings-7121c191dd30ab6666ac3275d495700c6f24b07e.zip
packages_apps_settings-7121c191dd30ab6666ac3275d495700c6f24b07e.tar.gz
packages_apps_settings-7121c191dd30ab6666ac3275d495700c6f24b07e.tar.bz2
am e8d2ae5f: am 96c2f8c5: Progress towards split storage categories.
* commit 'e8d2ae5f175bdca0eedf44c0207740678102bb46': Progress towards split storage categories.
-rw-r--r--src/com/android/settings/deviceinfo/Memory.java106
-rw-r--r--src/com/android/settings/deviceinfo/MiscFilesHandler.java2
-rw-r--r--src/com/android/settings/deviceinfo/StorageMeasurement.java13
-rw-r--r--src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java23
4 files changed, 69 insertions, 75 deletions
diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java
index f1c7fbe..2f477ea 100644
--- a/src/com/android/settings/deviceinfo/Memory.java
+++ b/src/com/android/settings/deviceinfo/Memory.java
@@ -23,7 +23,6 @@ import android.content.Context;
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;
@@ -46,30 +45,32 @@ import android.widget.Toast;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
+import com.google.common.collect.Lists;
+import java.util.ArrayList;
+
+/**
+ * Panel showing storage usage on disk for known {@link StorageVolume} returned
+ * by {@link StorageManager}. Calculates and displays usage of data types.
+ */
public class Memory extends SettingsPreferenceFragment {
private static final String TAG = "MemorySettings";
private static final int DLG_CONFIRM_UNMOUNT = 1;
private static final int DLG_ERROR_UNMOUNT = 2;
- private Resources mResources;
-
// The mountToggle Preference that has last been clicked.
// Assumes no two successive unmount event on 2 different volumes are performed before the first
// one's preference is disabled
- private static Preference mLastClickedMountToggle;
- private static String mClickedMountPoint;
+ private static Preference sLastClickedMountToggle;
+ private static String sClickedMountPoint;
// Access using getMountService()
private IMountService mMountService = null;
-
private StorageManager mStorageManager = null;
-
private UsbManager mUsbManager = null;
- private StorageVolumePreferenceCategory mInternalStorageVolumePreferenceCategory;
- private StorageVolumePreferenceCategory[] mStorageVolumePreferenceCategories;
+ private ArrayList<StorageVolumePreferenceCategory> mCategories = Lists.newArrayList();
@Override
public void onCreate(Bundle icicle) {
@@ -84,32 +85,29 @@ public class Memory extends SettingsPreferenceFragment {
addPreferencesFromResource(R.xml.device_info_memory);
- mResources = getResources();
-
if (!Environment.isExternalStorageEmulated()) {
// External storage is separate from internal storage; need to
// show internal storage as a separate item.
- mInternalStorageVolumePreferenceCategory = new StorageVolumePreferenceCategory(
- getActivity(), mResources, null, mStorageManager, false);
- getPreferenceScreen().addPreference(mInternalStorageVolumePreferenceCategory);
- mInternalStorageVolumePreferenceCategory.init();
+ addCategoryForVolume(null);
}
- StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
- int length = storageVolumes.length;
- mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length];
- for (int i = 0; i < length; i++) {
- StorageVolume storageVolume = storageVolumes[i];
- boolean isPrimary = i == 0;
- mStorageVolumePreferenceCategories[i] = new StorageVolumePreferenceCategory(
- getActivity(), mResources, storageVolume, mStorageManager, isPrimary);
- getPreferenceScreen().addPreference(mStorageVolumePreferenceCategories[i]);
- mStorageVolumePreferenceCategories[i].init();
+ final StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
+ for (StorageVolume volume : storageVolumes) {
+ addCategoryForVolume(volume);
}
setHasOptionsMenu(true);
}
+ private void addCategoryForVolume(StorageVolume volume) {
+ final StorageVolumePreferenceCategory category = new StorageVolumePreferenceCategory(
+ getActivity(), volume, mStorageManager);
+ // TODO: if primary emulated storage, then insert split items
+ mCategories.add(category);
+ getPreferenceScreen().addPreference(category);
+ category.init();
+ }
+
private boolean isMassStorageEnabled() {
// mass storage is enabled if primary volume supports it
final StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
@@ -128,11 +126,8 @@ public class Memory extends SettingsPreferenceFragment {
intentFilter.addAction(UsbManager.ACTION_USB_STATE);
getActivity().registerReceiver(mMediaScannerReceiver, intentFilter);
- if (mInternalStorageVolumePreferenceCategory != null) {
- mInternalStorageVolumePreferenceCategory.onResume();
- }
- for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
- mStorageVolumePreferenceCategories[i].onResume();
+ for (StorageVolumePreferenceCategory category : mCategories) {
+ category.onResume();
}
}
@@ -141,10 +136,10 @@ public class Memory extends SettingsPreferenceFragment {
public void onStorageStateChanged(String path, String oldState, String newState) {
Log.i(TAG, "Received storage state changed notification that " + path +
" changed state from " + oldState + " to " + newState);
- for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
- StorageVolumePreferenceCategory svpc = mStorageVolumePreferenceCategories[i];
- if (path.equals(svpc.getStorageVolume().getPath())) {
- svpc.onStorageStateChanged();
+ for (StorageVolumePreferenceCategory category : mCategories) {
+ final StorageVolume volume = category.getStorageVolume();
+ if (volume != null && path.equals(volume.getPath())) {
+ category.onStorageStateChanged();
break;
}
}
@@ -155,11 +150,8 @@ public class Memory extends SettingsPreferenceFragment {
public void onPause() {
super.onPause();
getActivity().unregisterReceiver(mMediaScannerReceiver);
- if (mInternalStorageVolumePreferenceCategory != null) {
- mInternalStorageVolumePreferenceCategory.onPause();
- }
- for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
- mStorageVolumePreferenceCategories[i].onPause();
+ for (StorageVolumePreferenceCategory category : mCategories) {
+ category.onPause();
}
}
@@ -214,9 +206,8 @@ public class Memory extends SettingsPreferenceFragment {
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
- StorageVolumePreferenceCategory svpc = mStorageVolumePreferenceCategories[i];
- Intent intent = svpc.intentForClick(preference);
+ for (StorageVolumePreferenceCategory category : mCategories) {
+ Intent intent = category.intentForClick(preference);
if (intent != null) {
// Don't go across app boundary if monkey is running
if (!Utils.isMonkeyRunning()) {
@@ -225,11 +216,11 @@ public class Memory extends SettingsPreferenceFragment {
return true;
}
- if (svpc.mountToggleClicked(preference)) {
- mLastClickedMountToggle = preference;
- final StorageVolume storageVolume = svpc.getStorageVolume();
- mClickedMountPoint = storageVolume.getPath();
- String state = mStorageManager.getVolumeState(storageVolume.getPath());
+ final StorageVolume volume = category.getStorageVolume();
+ if (volume != null && category.mountToggleClicked(preference)) {
+ sLastClickedMountToggle = preference;
+ sClickedMountPoint = volume.getPath();
+ String state = mStorageManager.getVolumeState(volume.getPath());
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
unmount();
@@ -250,13 +241,12 @@ public class Memory extends SettingsPreferenceFragment {
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);
+ for (StorageVolumePreferenceCategory category : mCategories) {
+ category.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();
+ for (StorageVolumePreferenceCategory category : mCategories) {
+ category.onMediaScannerFinished();
}
}
}
@@ -290,10 +280,10 @@ public class Memory extends SettingsPreferenceFragment {
Toast.makeText(getActivity(), R.string.unmount_inform_text, Toast.LENGTH_SHORT).show();
IMountService mountService = getMountService();
try {
- mLastClickedMountToggle.setEnabled(false);
- mLastClickedMountToggle.setTitle(mResources.getString(R.string.sd_ejecting_title));
- mLastClickedMountToggle.setSummary(mResources.getString(R.string.sd_ejecting_summary));
- mountService.unmountVolume(mClickedMountPoint, true, false);
+ sLastClickedMountToggle.setEnabled(false);
+ sLastClickedMountToggle.setTitle(getString(R.string.sd_ejecting_title));
+ sLastClickedMountToggle.setSummary(getString(R.string.sd_ejecting_summary));
+ mountService.unmountVolume(sClickedMountPoint, true, false);
} catch (RemoteException e) {
// Informative dialog to user that unmount failed.
showDialogInner(DLG_ERROR_UNMOUNT);
@@ -307,7 +297,7 @@ public class Memory extends SettingsPreferenceFragment {
private boolean hasAppsAccessingStorage() throws RemoteException {
IMountService mountService = getMountService();
- int stUsers[] = mountService.getStorageUsers(mClickedMountPoint);
+ int stUsers[] = mountService.getStorageUsers(sClickedMountPoint);
if (stUsers != null && stUsers.length > 0) {
return true;
}
@@ -345,7 +335,7 @@ public class Memory extends SettingsPreferenceFragment {
IMountService mountService = getMountService();
try {
if (mountService != null) {
- mountService.mountVolume(mClickedMountPoint);
+ mountService.mountVolume(sClickedMountPoint);
} else {
Log.e(TAG, "Mount service is null, can't mount");
}
diff --git a/src/com/android/settings/deviceinfo/MiscFilesHandler.java b/src/com/android/settings/deviceinfo/MiscFilesHandler.java
index 5c803ad..7f5c746 100644
--- a/src/com/android/settings/deviceinfo/MiscFilesHandler.java
+++ b/src/com/android/settings/deviceinfo/MiscFilesHandler.java
@@ -195,7 +195,7 @@ public class MiscFilesHandler extends ListActivity {
final StorageVolume storageVolume = activity.getIntent().getParcelableExtra(
StorageVolume.EXTRA_STORAGE_VOLUME);
StorageMeasurement mMeasurement = StorageMeasurement.getInstance(
- activity, storageVolume, new UserHandle(UserHandle.USER_CURRENT), false);
+ activity, storageVolume, UserHandle.CURRENT);
if (mMeasurement == null) return;
mData = (ArrayList<StorageMeasurement.FileInfo>) mMeasurement.mFileInfoForMisc;
if (mData != null) {
diff --git a/src/com/android/settings/deviceinfo/StorageMeasurement.java b/src/com/android/settings/deviceinfo/StorageMeasurement.java
index ccdd600..c137b70 100644
--- a/src/com/android/settings/deviceinfo/StorageMeasurement.java
+++ b/src/com/android/settings/deviceinfo/StorageMeasurement.java
@@ -115,12 +115,11 @@ public class StorageMeasurement {
public void updateExact(StorageMeasurement meas, Bundle bundle);
}
- private StorageMeasurement(
- Context context, StorageVolume storageVolume, UserHandle user, boolean isPrimary) {
- mStorageVolume = storageVolume;
+ private StorageMeasurement(Context context, StorageVolume volume, UserHandle user) {
+ mStorageVolume = volume;
mUser = Preconditions.checkNotNull(user);
- mIsInternal = storageVolume == null;
- mIsPrimary = !mIsInternal && isPrimary;
+ mIsInternal = volume == null;
+ mIsPrimary = volume != null ? volume.isPrimary() : false;
// Start the thread that will measure the disk usage.
final HandlerThread handlerThread = new HandlerThread("MemoryMeasurement");
@@ -139,14 +138,14 @@ public class StorageMeasurement {
* @param isPrimary true when this storage volume is the primary volume
*/
public static StorageMeasurement getInstance(
- Context context, StorageVolume storageVolume, UserHandle user, boolean isPrimary) {
+ Context context, StorageVolume storageVolume, UserHandle user) {
final Pair<StorageVolume, UserHandle> key = new Pair<StorageVolume, UserHandle>(
storageVolume, user);
synchronized (sInstances) {
StorageMeasurement value = sInstances.get(key);
if (value == null) {
value = new StorageMeasurement(
- context.getApplicationContext(), storageVolume, user, isPrimary);
+ context.getApplicationContext(), storageVolume, user);
sInstances.put(key, value);
}
return value;
diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
index cb4d1c0..063f68d 100644
--- a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
+++ b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
@@ -166,16 +166,20 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
}
};
- public StorageVolumePreferenceCategory(Context context, Resources resources,
- StorageVolume storageVolume, StorageManager storageManager, boolean isPrimary) {
+ public StorageVolumePreferenceCategory(
+ Context context, StorageVolume volume, StorageManager storageManager) {
super(context);
- mResources = resources;
- mStorageVolume = storageVolume;
+ mResources = context.getResources();
+
+ mStorageVolume = volume;
mStorageManager = storageManager;
- setTitle(storageVolume != null ? storageVolume.getDescription(context)
- : resources.getText(R.string.internal_storage));
- mLocalMeasure = StorageMeasurement.getInstance(
- context, storageVolume, new UserHandle(UserHandle.USER_CURRENT), isPrimary);
+
+ final boolean isPrimary = volume != null ? volume.isPrimary() : false;
+
+ setTitle(volume != null ? volume.getDescription(context)
+ : context.getText(R.string.internal_storage));
+
+ mLocalMeasure = StorageMeasurement.getInstance(context, volume, UserHandle.CURRENT);
mAllMeasures.add(mLocalMeasure);
// Cannot format emulated storage
@@ -233,7 +237,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
final String key = buildUserKey(user);
final StorageMeasurement measure = StorageMeasurement.getInstance(
- context, mStorageVolume, user, true);
+ context, mStorageVolume, user);
measure.setIncludeAppCodeSize(false);
mAllMeasures.add(measure);
@@ -448,6 +452,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory
mUsbFunction = usbFunction;
measure();
}
+
public void onMediaScannerFinished() {
measure();
}