sInstances = Maps.newHashMap();
-
- /**
- * Obtain shared instance of {@link StorageMeasurement} for given physical
- * {@link StorageVolume}, or internal storage if {@code null}.
- */
- public static StorageMeasurement getInstance(Context context, StorageVolume volume) {
- synchronized (sInstances) {
- StorageMeasurement value = sInstances.get(volume);
- if (value == null) {
- value = new StorageMeasurement(context.getApplicationContext(), volume);
- sInstances.put(volume, value);
- }
- return value;
- }
- }
-
public static class MeasurementDetails {
- public long totalSize;
- public long availSize;
-
/**
* Total apps disk usage.
*
@@ -128,7 +105,7 @@ public class StorageMeasurement {
* When measuring a physical {@link StorageVolume}, this reflects media
* on that volume.
*/
- public HashMap mediaSize = Maps.newHashMap();
+ public HashMap mediaSize = new HashMap<>();
/**
* Misc external disk usage for the current user, unaccounted in
@@ -144,34 +121,31 @@ public class StorageMeasurement {
}
public interface MeasurementReceiver {
- public void updateApproximate(StorageMeasurement meas, long totalSize, long availSize);
- public void updateDetails(StorageMeasurement meas, MeasurementDetails details);
+ public void onDetailsChanged(MeasurementDetails details);
}
- private volatile WeakReference mReceiver;
+ private WeakReference mReceiver;
- /** Physical volume being measured, or {@code null} for internal. */
- private final StorageVolume mVolume;
+ private final Context mContext;
- private final boolean mIsInternal;
- private final boolean mIsPrimary;
+ private final VolumeInfo mVolume;
+ private final VolumeInfo mSharedVolume;
- private final MeasurementHandler mHandler;
+ private final MainHandler mMainHandler;
+ private final MeasurementHandler mMeasurementHandler;
- private long mTotalSize;
- private long mAvailSize;
+ public StorageMeasurement(Context context, VolumeInfo volume, VolumeInfo sharedVolume) {
+ mContext = context.getApplicationContext();
- List mFileInfoForMisc;
-
- private StorageMeasurement(Context context, StorageVolume volume) {
mVolume = volume;
- mIsInternal = volume == null;
- mIsPrimary = volume != null ? volume.isPrimary() : false;
+ mSharedVolume = sharedVolume;
// Start the thread that will measure the disk usage.
final HandlerThread handlerThread = new HandlerThread("MemoryMeasurement");
handlerThread.start();
- mHandler = new MeasurementHandler(context, handlerThread.getLooper());
+
+ mMainHandler = new MainHandler();
+ mMeasurementHandler = new MeasurementHandler(handlerThread.getLooper());
}
public void setReceiver(MeasurementReceiver receiver) {
@@ -180,52 +154,38 @@ public class StorageMeasurement {
}
}
+ public void forceMeasure() {
+ invalidate();
+ measure();
+ }
+
public void measure() {
- if (!mHandler.hasMessages(MeasurementHandler.MSG_MEASURE)) {
- mHandler.sendEmptyMessage(MeasurementHandler.MSG_MEASURE);
+ if (!mMeasurementHandler.hasMessages(MeasurementHandler.MSG_MEASURE)) {
+ mMeasurementHandler.sendEmptyMessage(MeasurementHandler.MSG_MEASURE);
}
}
- public void cleanUp() {
+ public void onDestroy() {
mReceiver = null;
- mHandler.removeMessages(MeasurementHandler.MSG_MEASURE);
- mHandler.sendEmptyMessage(MeasurementHandler.MSG_DISCONNECT);
+ mMeasurementHandler.removeMessages(MeasurementHandler.MSG_MEASURE);
+ mMeasurementHandler.sendEmptyMessage(MeasurementHandler.MSG_DISCONNECT);
}
- public void invalidate() {
- mHandler.sendEmptyMessage(MeasurementHandler.MSG_INVALIDATE);
- }
-
- private void sendInternalApproximateUpdate() {
- MeasurementReceiver receiver = (mReceiver != null) ? mReceiver.get() : null;
- if (receiver == null) {
- return;
- }
- receiver.updateApproximate(this, mTotalSize, mAvailSize);
- }
-
- private void sendExactUpdate(MeasurementDetails details) {
- MeasurementReceiver receiver = (mReceiver != null) ? mReceiver.get() : null;
- if (receiver == null) {
- if (LOGV) {
- Log.i(TAG, "measurements dropped because receiver is null! wasted effort");
- }
- return;
- }
- receiver.updateDetails(this, details);
+ private void invalidate() {
+ mMeasurementHandler.sendEmptyMessage(MeasurementHandler.MSG_INVALIDATE);
}
private static class StatsObserver extends IPackageStatsObserver.Stub {
- private final boolean mIsInternal;
+ private final boolean mIsPrivate;
private final MeasurementDetails mDetails;
private final int mCurrentUser;
private final Message mFinished;
private int mRemaining;
- public StatsObserver(boolean isInternal, MeasurementDetails details, int currentUser,
+ public StatsObserver(boolean isPrivate, MeasurementDetails details, int currentUser,
Message finished, int remaining) {
- mIsInternal = isInternal;
+ mIsPrivate = isPrivate;
mDetails = details;
mCurrentUser = currentUser;
mFinished = finished;
@@ -245,7 +205,7 @@ public class StorageMeasurement {
}
private void addStatsLocked(PackageStats stats) {
- if (mIsInternal) {
+ if (mIsPrivate) {
long codeSize = stats.codeSize;
long dataSize = stats.dataSize;
long cacheSize = stats.cacheSize;
@@ -279,6 +239,17 @@ public class StorageMeasurement {
}
}
+ private class MainHandler extends Handler {
+ @Override
+ public void handleMessage(Message msg) {
+ final MeasurementDetails details = (MeasurementDetails) msg.obj;
+ final MeasurementReceiver receiver = (mReceiver != null) ? mReceiver.get() : null;
+ if (receiver != null) {
+ receiver.onDetailsChanged(details);
+ }
+ }
+ }
+
private class MeasurementHandler extends Handler {
public static final int MSG_MEASURE = 1;
public static final int MSG_CONNECTED = 2;
@@ -294,8 +265,6 @@ public class StorageMeasurement {
private MeasurementDetails mCached;
- private final WeakReference mContext;
-
private final ServiceConnection mDefContainerConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
@@ -313,9 +282,8 @@ public class StorageMeasurement {
}
};
- public MeasurementHandler(Context context, Looper looper) {
+ public MeasurementHandler(Looper looper) {
super(looper);
- mContext = new WeakReference(context);
}
@Override
@@ -323,50 +291,39 @@ public class StorageMeasurement {
switch (msg.what) {
case MSG_MEASURE: {
if (mCached != null) {
- sendExactUpdate(mCached);
+ mMainHandler.obtainMessage(0, mCached).sendToTarget();
break;
}
- final Context context = (mContext != null) ? mContext.get() : null;
- if (context == null) {
- return;
- }
-
synchronized (mLock) {
if (mBound) {
removeMessages(MSG_DISCONNECT);
sendMessage(obtainMessage(MSG_CONNECTED, mDefaultContainer));
} else {
Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
- context.bindServiceAsUser(service, mDefContainerConn, Context.BIND_AUTO_CREATE,
- UserHandle.OWNER);
+ mContext.bindServiceAsUser(service, mDefContainerConn,
+ Context.BIND_AUTO_CREATE, UserHandle.OWNER);
}
}
break;
}
case MSG_CONNECTED: {
- IMediaContainerService imcs = (IMediaContainerService) msg.obj;
- measureApproximateStorage(imcs);
+ final IMediaContainerService imcs = (IMediaContainerService) msg.obj;
measureExactStorage(imcs);
break;
}
case MSG_DISCONNECT: {
synchronized (mLock) {
if (mBound) {
- final Context context = (mContext != null) ? mContext.get() : null;
- if (context == null) {
- return;
- }
-
mBound = false;
- context.unbindService(mDefContainerConn);
+ mContext.unbindService(mDefContainerConn);
}
}
break;
}
case MSG_COMPLETED: {
mCached = (MeasurementDetails) msg.obj;
- sendExactUpdate(mCached);
+ mMainHandler.obtainMessage(0, mCached).sendToTarget();
break;
}
case MSG_INVALIDATE: {
@@ -375,88 +332,75 @@ public class StorageMeasurement {
}
}
}
+ }
- private void measureApproximateStorage(IMediaContainerService imcs) {
- final String path = mVolume != null ? mVolume.getPath()
- : Environment.getDataDirectory().getPath();
- try {
- final long[] stats = imcs.getFileSystemStats(path);
- mTotalSize = stats[0];
- mAvailSize = stats[1];
- } catch (Exception e) {
- Log.w(TAG, "Problem in container service", e);
- }
+ private void measureExactStorage(IMediaContainerService imcs) {
+ final UserManager userManager = mContext.getSystemService(UserManager.class);
+ final PackageManager packageManager = mContext.getPackageManager();
- sendInternalApproximateUpdate();
- }
+ final List users = userManager.getUsers();
+ final int currentUser = ActivityManager.getCurrentUser();
- private void measureExactStorage(IMediaContainerService imcs) {
- final Context context = mContext != null ? mContext.get() : null;
- if (context == null) {
- return;
- }
+ final MeasurementDetails details = new MeasurementDetails();
+ final Message finished = mMeasurementHandler.obtainMessage(MeasurementHandler.MSG_COMPLETED,
+ details);
- final MeasurementDetails details = new MeasurementDetails();
- final Message finished = obtainMessage(MSG_COMPLETED, details);
-
- details.totalSize = mTotalSize;
- details.availSize = mAvailSize;
-
- final UserManager userManager = (UserManager) context.getSystemService(
- Context.USER_SERVICE);
- final List users = userManager.getUsers();
-
- final int currentUser = ActivityManager.getCurrentUser();
- final UserEnvironment currentEnv = new UserEnvironment(currentUser);
+ if (mSharedVolume != null && mSharedVolume.state == VolumeInfo.STATE_MOUNTED) {
+ final File basePath = mSharedVolume.getPathForUser(currentUser);
// Measure media types for emulated storage, or for primary physical
// external volume
- final boolean measureMedia = (mIsInternal && Environment.isExternalStorageEmulated())
- || mIsPrimary;
- if (measureMedia) {
- for (String type : sMeasureMediaTypes) {
- final File path = currentEnv.getExternalStoragePublicDirectory(type);
- final long size = getDirectorySize(imcs, path);
- details.mediaSize.put(type, size);
- }
+ for (String type : sMeasureMediaTypes) {
+ final File path = new File(basePath, type);
+ final long size = getDirectorySize(imcs, path);
+ details.mediaSize.put(type, size);
}
// Measure misc files not counted under media
- if (measureMedia) {
- final File path = mIsInternal ? currentEnv.getExternalStorageDirectory()
- : mVolume.getPathFile();
- details.miscSize = measureMisc(imcs, path);
- }
-
- // Measure total emulated storage of all users; internal apps data
- // will be spliced in later
- for (UserInfo user : users) {
- final UserEnvironment userEnv = new UserEnvironment(user.id);
- final long size = getDirectorySize(imcs, userEnv.getExternalStorageDirectory());
- addValue(details.usersSize, user.id, size);
- }
-
- // Measure all apps for all users
- final PackageManager pm = context.getPackageManager();
- if (mIsInternal || mIsPrimary) {
- final List apps = pm.getInstalledApplications(
- PackageManager.GET_UNINSTALLED_PACKAGES
- | PackageManager.GET_DISABLED_COMPONENTS);
-
- final int count = users.size() * apps.size();
- final StatsObserver observer = new StatsObserver(
- mIsInternal, details, currentUser, finished, count);
+ details.miscSize = measureMisc(imcs, basePath);
+ if (mSharedVolume.type == VolumeInfo.TYPE_EMULATED) {
+ // Measure total emulated storage of all users; internal apps data
+ // will be spliced in later
for (UserInfo user : users) {
- for (ApplicationInfo app : apps) {
- pm.getPackageSizeInfo(app.packageName, user.id, observer);
- }
+ final File userPath = mSharedVolume.getPathForUser(user.id);
+ final long size = getDirectorySize(imcs, userPath);
+ addValue(details.usersSize, user.id, size);
}
-
- } else {
- finished.sendToTarget();
}
}
+
+ // Measure all apps hosted on this volume for all users
+ if (mVolume.type == VolumeInfo.TYPE_PRIVATE) {
+ final List apps = packageManager.getInstalledApplications(
+ PackageManager.GET_UNINSTALLED_PACKAGES
+ | PackageManager.GET_DISABLED_COMPONENTS);
+
+ final List volumeApps = new ArrayList<>();
+ for (ApplicationInfo app : apps) {
+ if (Objects.equals(app.volumeUuid, mVolume.fsUuid)) {
+ volumeApps.add(app);
+ }
+ }
+
+ final int count = users.size() * volumeApps.size();
+ if (count == 0) {
+ finished.sendToTarget();
+ return;
+ }
+
+ final StatsObserver observer = new StatsObserver(
+ true, details, currentUser, finished, count);
+ for (UserInfo user : users) {
+ for (ApplicationInfo app : volumeApps) {
+ packageManager.getPackageSizeInfo(app.packageName, user.id, observer);
+ }
+ }
+
+ } else {
+ finished.sendToTarget();
+ return;
+ }
}
private static long getDirectorySize(IMediaContainerService imcs, File path) {
@@ -471,64 +415,26 @@ public class StorageMeasurement {
}
private long measureMisc(IMediaContainerService imcs, File dir) {
- mFileInfoForMisc = new ArrayList();
-
final File[] files = dir.listFiles();
- if (files == null) return 0;
+ if (ArrayUtils.isEmpty(files)) return 0;
// Get sizes of all top level nodes except the ones already computed
- long counter = 0;
long miscSize = 0;
-
for (File file : files) {
- final String path = file.getAbsolutePath();
final String name = file.getName();
if (sMeasureMediaTypes.contains(name)) {
continue;
}
if (file.isFile()) {
- final long fileSize = file.length();
- mFileInfoForMisc.add(new FileInfo(path, fileSize, counter++));
- miscSize += fileSize;
+ miscSize += file.length();
} else if (file.isDirectory()) {
- final long dirSize = getDirectorySize(imcs, file);
- mFileInfoForMisc.add(new FileInfo(path, dirSize, counter++));
- miscSize += dirSize;
- } else {
- // Non directory, non file: not listed
+ miscSize += getDirectorySize(imcs, file);
}
}
-
- // sort the list of FileInfo objects collected above in descending order of their sizes
- Collections.sort(mFileInfoForMisc);
-
return miscSize;
}
- static class FileInfo implements Comparable {
- final String mFileName;
- final long mSize;
- final long mId;
-
- FileInfo(String fileName, long size, long id) {
- mFileName = fileName;
- mSize = size;
- mId = id;
- }
-
- @Override
- public int compareTo(FileInfo that) {
- if (this == that || mSize == that.mSize) return 0;
- else return (mSize < that.mSize) ? 1 : -1; // for descending sort
- }
-
- @Override
- public String toString() {
- return mFileName + " : " + mSize + ", id:" + mId;
- }
- }
-
private static void addValue(SparseLongArray array, int key, long value) {
array.put(key, array.get(key) + value);
}
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
new file mode 100644
index 00000000000..001f00d896b
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -0,0 +1,421 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo;
+
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.UserManager;
+import android.os.storage.StorageEventListener;
+import android.os.storage.StorageManager;
+import android.os.storage.VolumeInfo;
+import android.preference.Preference;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceScreen;
+import android.provider.DocumentsContract;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.widget.Toast;
+
+import com.android.internal.logging.MetricsLogger;
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settings.search.SearchIndexableRaw;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Panel showing both internal storage (both built-in storage and private
+ * volumes) and removable storage (public volumes).
+ */
+public class StorageSettings extends SettingsPreferenceFragment implements Indexable {
+ static final String TAG = "StorageSettings";
+
+ // TODO: badging to indicate devices running low on storage
+ // TODO: show currently ejected private volumes
+
+ public static final String EXTRA_VOLUME_ID = "volume_id";
+
+ private static final String DOCUMENT_AUTHORITY = "com.android.externalstorage.documents";
+ private static final String DOCUMENT_ROOT_PRIMARY_EMULATED = "primary";
+
+ /**
+ * Build an intent to browse the contents of given {@link VolumeInfo}.
+ */
+ public static Intent buildBrowseIntent(VolumeInfo vol) {
+ final Uri uri;
+ if (vol.type == VolumeInfo.TYPE_PUBLIC) {
+ uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY, vol.fsUuid);
+ } else if (VolumeInfo.ID_EMULATED_INTERNAL.equals(vol.id)) {
+ uri = DocumentsContract.buildRootUri(DOCUMENT_AUTHORITY,
+ DOCUMENT_ROOT_PRIMARY_EMULATED);
+ } else if (vol.type == VolumeInfo.TYPE_EMULATED) {
+ // TODO: build intent once supported
+ uri = null;
+ } else {
+ throw new IllegalArgumentException();
+ }
+
+ final Intent intent = new Intent(DocumentsContract.ACTION_BROWSE_DOCUMENT_ROOT);
+ intent.addCategory(Intent.CATEGORY_DEFAULT);
+ intent.setData(uri);
+ return intent;
+ }
+
+ private UserManager mUserManager;
+ private StorageManager mStorageManager;
+
+ private PreferenceCategory mInternalCategory;
+ private PreferenceCategory mExternalCategory;
+
+ @Override
+ protected int getMetricsCategory() {
+ return MetricsLogger.DEVICEINFO_STORAGE;
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ final Context context = getActivity();
+
+ mUserManager = context.getSystemService(UserManager.class);
+
+ mStorageManager = context.getSystemService(StorageManager.class);
+ mStorageManager.registerListener(mStorageListener);
+
+ addPreferencesFromResource(R.xml.device_info_storage);
+
+ mInternalCategory = (PreferenceCategory) findPreference("storage_internal");
+ mExternalCategory = (PreferenceCategory) findPreference("storage_external");
+
+ // TODO: if only one volume visible, shortcut into it
+
+ setHasOptionsMenu(true);
+ }
+
+ private static final Comparator sVolumeComparator = new Comparator() {
+ @Override
+ public int compare(VolumeInfo lhs, VolumeInfo rhs) {
+ if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(lhs.id)) {
+ return -1;
+ } else if (lhs.getDescription() == null) {
+ return 1;
+ } else {
+ return lhs.getDescription().compareTo(rhs.getDescription());
+ }
+ }
+ };
+
+ private final StorageEventListener mStorageListener = new StorageEventListener() {
+ @Override
+ public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {
+ if (isInteresting(vol)) {
+ refresh();
+ }
+ }
+ };
+
+ private static boolean isInteresting(VolumeInfo vol) {
+ return vol.type == VolumeInfo.TYPE_PRIVATE || vol.type == VolumeInfo.TYPE_PUBLIC;
+ }
+
+ private void refresh() {
+ final Context context = getActivity();
+
+ getPreferenceScreen().removeAll();
+ mInternalCategory.removeAll();
+ mExternalCategory.removeAll();
+
+ final List volumes = mStorageManager.getVolumes();
+ Collections.sort(volumes, sVolumeComparator);
+
+ for (VolumeInfo vol : volumes) {
+ if (vol.type == VolumeInfo.TYPE_PRIVATE) {
+ mInternalCategory.addPreference(new StorageVolumePreference(context, vol));
+ } else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
+ mExternalCategory.addPreference(new StorageVolumePreference(context, vol));
+ }
+ }
+
+ if (mInternalCategory.getPreferenceCount() > 0) {
+ getPreferenceScreen().addPreference(mInternalCategory);
+ }
+ if (mExternalCategory.getPreferenceCount() > 0) {
+ getPreferenceScreen().addPreference(mExternalCategory);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mStorageManager.registerListener(mStorageListener);
+ refresh();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mStorageManager.unregisterListener(mStorageListener);
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.storage, menu);
+ }
+
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ final MenuItem usb = menu.findItem(R.id.storage_usb);
+
+ usb.setVisible(!mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.storage_usb:
+ startFragment(this, UsbSettings.class.getCanonicalName(),
+ R.string.storage_title_usb, 0, null);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference pref) {
+ final String volId = pref.getKey();
+ final VolumeInfo vol = mStorageManager.findVolumeById(volId);
+ if (vol == null) {
+ return false;
+
+ } else if (vol.type == VolumeInfo.TYPE_PRIVATE) {
+ final Bundle args = new Bundle();
+ args.putString(EXTRA_VOLUME_ID, volId);
+ startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
+ -1, 0, args);
+ return true;
+
+ } else if (vol.type == VolumeInfo.TYPE_PUBLIC) {
+ if (vol.state == VolumeInfo.STATE_MOUNTED) {
+ final Intent intent = buildBrowseIntent(vol);
+ startActivity(intent);
+ return true;
+ } else {
+ final Bundle args = new Bundle();
+ args.putString(EXTRA_VOLUME_ID, volId);
+ startFragment(this, PublicVolumeSettings.class.getCanonicalName(),
+ -1, 0, args);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static class MountTask extends AsyncTask {
+ private final Context mContext;
+ private final StorageManager mStorageManager;
+ private final String mVolumeId;
+ private final String mDescription;
+
+ public MountTask(Context context, String volumeId) {
+ mContext = context.getApplicationContext();
+ mStorageManager = mContext.getSystemService(StorageManager.class);
+ mVolumeId = volumeId;
+ mDescription = mStorageManager.getBestVolumeDescription(mVolumeId);
+ }
+
+ @Override
+ protected Exception doInBackground(Void... params) {
+ try {
+ mStorageManager.mount(mVolumeId);
+ return null;
+ } catch (Exception e) {
+ return e;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Exception e) {
+ if (e == null) {
+ Toast.makeText(mContext, mContext.getString(R.string.storage_mount_success,
+ mDescription), Toast.LENGTH_SHORT).show();
+ } else {
+ Log.e(TAG, "Failed to mount " + mVolumeId, e);
+ Toast.makeText(mContext, mContext.getString(R.string.storage_mount_failure,
+ mDescription), Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+
+ public static class UnmountTask extends AsyncTask {
+ private final Context mContext;
+ private final StorageManager mStorageManager;
+ private final String mVolumeId;
+ private final String mDescription;
+
+ public UnmountTask(Context context, String volumeId) {
+ mContext = context.getApplicationContext();
+ mStorageManager = mContext.getSystemService(StorageManager.class);
+ mVolumeId = volumeId;
+ mDescription = mStorageManager.getBestVolumeDescription(mVolumeId);
+ }
+
+ @Override
+ protected Exception doInBackground(Void... params) {
+ try {
+ mStorageManager.unmount(mVolumeId);
+ return null;
+ } catch (Exception e) {
+ return e;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Exception e) {
+ if (e == null) {
+ Toast.makeText(mContext, mContext.getString(R.string.storage_unmount_success,
+ mDescription), Toast.LENGTH_SHORT).show();
+ } else {
+ Log.e(TAG, "Failed to unmount " + mVolumeId, e);
+ Toast.makeText(mContext, mContext.getString(R.string.storage_unmount_failure,
+ mDescription), Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+
+ public static class FormatTask extends AsyncTask {
+ private final Context mContext;
+ private final StorageManager mStorageManager;
+ private final String mVolumeId;
+ private final String mDescription;
+
+ public FormatTask(Context context, String volumeId) {
+ mContext = context.getApplicationContext();
+ mStorageManager = mContext.getSystemService(StorageManager.class);
+ mVolumeId = volumeId;
+ mDescription = mStorageManager.getBestVolumeDescription(mVolumeId);
+ }
+
+ @Override
+ protected Exception doInBackground(Void... params) {
+ try {
+ mStorageManager.format(mVolumeId);
+ mStorageManager.mount(mVolumeId);
+ return null;
+ } catch (Exception e) {
+ return e;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Exception e) {
+ if (e == null) {
+ Toast.makeText(mContext, mContext.getString(R.string.storage_format_success,
+ mDescription), Toast.LENGTH_SHORT).show();
+ } else {
+ Log.e(TAG, "Failed to format " + mVolumeId, e);
+ Toast.makeText(mContext, mContext.getString(R.string.storage_format_failure,
+ mDescription), Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+
+ /**
+ * Enable indexing of searchable data
+ */
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List getRawDataToIndex(Context context, boolean enabled) {
+ final List result = new ArrayList();
+
+ SearchIndexableRaw data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.storage_settings);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.internal_storage);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ final StorageManager storage = context.getSystemService(StorageManager.class);
+ final List vols = storage.getVolumes();
+ for (VolumeInfo vol : vols) {
+ if (isInteresting(vol)) {
+ data.title = storage.getBestVolumeDescription(vol.id);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+ }
+ }
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_size);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_available);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_apps_usage);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_dcim_usage);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_music_usage);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_downloads_usage);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_media_cache_usage);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ data = new SearchIndexableRaw(context);
+ data.title = context.getString(R.string.memory_media_misc_usage);
+ data.screenTitle = context.getString(R.string.storage_settings);
+ result.add(data);
+
+ return result;
+ }
+ };
+}
diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreference.java b/src/com/android/settings/deviceinfo/StorageVolumePreference.java
new file mode 100644
index 00000000000..fbe34f6bdd6
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/StorageVolumePreference.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo;
+
+import android.content.Context;
+import android.os.storage.StorageManager;
+import android.os.storage.VolumeInfo;
+import android.preference.Preference;
+import android.text.format.Formatter;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
+
+import java.io.File;
+
+/**
+ * Preference line representing a single {@link VolumeInfo}, possibly including
+ * quick actions like unmounting.
+ */
+public class StorageVolumePreference extends Preference {
+ private final StorageManager mStorageManager;
+ private final VolumeInfo mVolume;
+
+ public StorageVolumePreference(Context context, VolumeInfo volume) {
+ super(context);
+
+ mStorageManager = context.getSystemService(StorageManager.class);
+ mVolume = volume;
+
+ setKey(volume.id);
+ setTitle(mStorageManager.getBestVolumeDescription(volume.id));
+
+ switch (volume.state) {
+ case VolumeInfo.STATE_MOUNTED:
+ // TODO: move statfs() to background thread
+ final File path = new File(volume.path);
+ final String free = Formatter.formatFileSize(context, path.getFreeSpace());
+ final String total = Formatter.formatFileSize(context, path.getTotalSpace());
+ setSummary(context.getString(R.string.storage_volume_summary, free, total));
+ break;
+ }
+
+ // TODO: better icons
+ if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(volume.id)) {
+ setIcon(context.getDrawable(R.drawable.ic_settings_storage));
+ } else {
+ setIcon(context.getDrawable(R.drawable.ic_sim_sd));
+ }
+
+ if (volume.type == VolumeInfo.TYPE_PUBLIC && volume.state == VolumeInfo.STATE_MOUNTED) {
+ setWidgetLayoutResource(R.layout.preference_storage_action);
+ }
+ }
+
+ @Override
+ protected void onBindView(View view) {
+ final TextView unmount = (TextView) view.findViewById(R.id.unmount);
+ if (unmount != null) {
+ unmount.setText("\u23CF");
+ unmount.setOnClickListener(mUnmountListener);
+ }
+
+ super.onBindView(view);
+ }
+
+ private final View.OnClickListener mUnmountListener = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new UnmountTask(getContext(), mVolume.id).execute();
+ }
+ };
+}
diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
deleted file mode 100644
index a98f8d96d08..00000000000
--- a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo;
-
-import android.app.ActivityManagerNative;
-import android.app.ActivityThread;
-import android.app.DownloadManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.IPackageManager;
-import android.content.pm.UserInfo;
-import android.content.res.Resources;
-import android.hardware.usb.UsbManager;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.UserManager;
-import android.os.storage.StorageManager;
-import android.os.storage.StorageVolume;
-import android.preference.Preference;
-import android.preference.PreferenceCategory;
-import android.provider.MediaStore;
-import android.text.format.Formatter;
-
-import com.android.settings.R;
-import com.android.settings.Settings;
-import com.android.settings.deviceinfo.StorageMeasurement.MeasurementDetails;
-import com.android.settings.deviceinfo.StorageMeasurement.MeasurementReceiver;
-import com.google.android.collect.Lists;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-public class StorageVolumePreferenceCategory extends PreferenceCategory {
- public static final String KEY_CACHE = "cache";
-
- private static final int ORDER_USAGE_BAR = -2;
- private static final int ORDER_STORAGE_LOW = -1;
-
- /** Physical volume being measured, or {@code null} for internal. */
- private final StorageVolume mVolume;
- private final StorageMeasurement mMeasure;
-
- private final Resources mResources;
- private final StorageManager mStorageManager;
- private final UserManager mUserManager;
-
- private UsageBarPreference mUsageBarPreference;
- private Preference mMountTogglePreference;
- private Preference mFormatPreference;
- private Preference mStorageLow;
-
- private StorageItemPreference mItemTotal;
- private StorageItemPreference mItemAvailable;
- private StorageItemPreference mItemApps;
- private StorageItemPreference mItemDcim;
- private StorageItemPreference mItemMusic;
- private StorageItemPreference mItemDownloads;
- private StorageItemPreference mItemCache;
- private StorageItemPreference mItemMisc;
- private List mItemUsers = Lists.newArrayList();
-
- private boolean mUsbConnected;
- private String mUsbFunction;
-
- private long mTotalSize;
-
- private static final int MSG_UI_UPDATE_APPROXIMATE = 1;
- private static final int MSG_UI_UPDATE_DETAILS = 2;
-
- private Handler mUpdateHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_UI_UPDATE_APPROXIMATE: {
- final long[] size = (long[]) msg.obj;
- updateApproximate(size[0], size[1]);
- break;
- }
- case MSG_UI_UPDATE_DETAILS: {
- final MeasurementDetails details = (MeasurementDetails) msg.obj;
- updateDetails(details);
- break;
- }
- }
- }
- };
-
- /**
- * Build category to summarize internal storage, including any emulated
- * {@link StorageVolume}.
- */
- public static StorageVolumePreferenceCategory buildForInternal(Context context) {
- return new StorageVolumePreferenceCategory(context, null);
- }
-
- /**
- * Build category to summarize specific physical {@link StorageVolume}.
- */
- public static StorageVolumePreferenceCategory buildForPhysical(
- Context context, StorageVolume volume) {
- return new StorageVolumePreferenceCategory(context, volume);
- }
-
- private StorageVolumePreferenceCategory(Context context, StorageVolume volume) {
- super(context);
-
- mVolume = volume;
- mMeasure = StorageMeasurement.getInstance(context, volume);
-
- mResources = context.getResources();
- mStorageManager = StorageManager.from(context);
- mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
-
- setTitle(volume != null ? volume.getDescription(context)
- : context.getText(R.string.internal_storage));
- }
-
- private StorageItemPreference buildItem(int titleRes, int colorRes) {
- return new StorageItemPreference(getContext(), titleRes, colorRes);
- }
-
- public void init() {
- final Context context = getContext();
-
- removeAll();
-
- final UserInfo currentUser;
- try {
- currentUser = ActivityManagerNative.getDefault().getCurrentUser();
- } catch (RemoteException e) {
- throw new RuntimeException("Failed to get current user");
- }
-
- final List otherUsers = getUsersExcluding(currentUser);
- final boolean showUsers = mVolume == null && otherUsers.size() > 0;
-
- mUsageBarPreference = new UsageBarPreference(context);
- mUsageBarPreference.setOrder(ORDER_USAGE_BAR);
- addPreference(mUsageBarPreference);
-
- mItemTotal = buildItem(R.string.memory_size, 0);
- mItemAvailable = buildItem(R.string.memory_available, R.color.memory_avail);
- addPreference(mItemTotal);
- addPreference(mItemAvailable);
-
- mItemApps = buildItem(R.string.memory_apps_usage, R.color.memory_apps_usage);
- mItemDcim = buildItem(R.string.memory_dcim_usage, R.color.memory_dcim);
- mItemMusic = buildItem(R.string.memory_music_usage, R.color.memory_music);
- mItemDownloads = buildItem(R.string.memory_downloads_usage, R.color.memory_downloads);
- mItemCache = buildItem(R.string.memory_media_cache_usage, R.color.memory_cache);
- mItemMisc = buildItem(R.string.memory_media_misc_usage, R.color.memory_misc);
-
- mItemCache.setKey(KEY_CACHE);
-
- final boolean showDetails = mVolume == null || mVolume.isPrimary();
- if (showDetails) {
- if (showUsers) {
- addPreference(new PreferenceHeader(context, currentUser.name));
- }
-
- addPreference(mItemApps);
- addPreference(mItemDcim);
- addPreference(mItemMusic);
- addPreference(mItemDownloads);
- addPreference(mItemCache);
- addPreference(mItemMisc);
-
- if (showUsers) {
- addPreference(new PreferenceHeader(context, R.string.storage_other_users));
-
- int count = 0;
- for (UserInfo info : otherUsers) {
- final int colorRes = count++ % 2 == 0 ? R.color.memory_user_light
- : R.color.memory_user_dark;
- final StorageItemPreference userPref = new StorageItemPreference(
- getContext(), info.name, colorRes, info.id);
- mItemUsers.add(userPref);
- addPreference(userPref);
- }
- }
- }
-
- final boolean isRemovable = mVolume != null ? mVolume.isRemovable() : false;
- // Always create the preference since many code rely on it existing
- mMountTogglePreference = new Preference(context);
- if (isRemovable) {
- mMountTogglePreference.setTitle(R.string.sd_eject);
- mMountTogglePreference.setSummary(R.string.sd_eject_summary);
- addPreference(mMountTogglePreference);
- }
-
- final boolean allowFormat = mVolume != null;
- if (allowFormat) {
- mFormatPreference = new Preference(context);
- mFormatPreference.setTitle(R.string.sd_format);
- mFormatPreference.setSummary(R.string.sd_format_summary);
- addPreference(mFormatPreference);
- }
-
- final IPackageManager pm = ActivityThread.getPackageManager();
- try {
- if (pm.isStorageLow()) {
- mStorageLow = new Preference(context);
- mStorageLow.setOrder(ORDER_STORAGE_LOW);
- mStorageLow.setTitle(R.string.storage_low_title);
- mStorageLow.setSummary(R.string.storage_low_summary);
- addPreference(mStorageLow);
- } else if (mStorageLow != null) {
- removePreference(mStorageLow);
- mStorageLow = null;
- }
- } catch (RemoteException e) {
- }
- }
-
- public StorageVolume getStorageVolume() {
- return mVolume;
- }
-
- private void updatePreferencesFromState() {
- // Only update for physical volumes
- if (mVolume == null) return;
-
- mMountTogglePreference.setEnabled(true);
-
- final String state = mStorageManager.getVolumeState(mVolume.getPath());
-
- if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
- mItemAvailable.setTitle(R.string.memory_available_read_only);
- } else {
- mItemAvailable.setTitle(R.string.memory_available);
- }
-
- if (Environment.MEDIA_MOUNTED.equals(state)
- || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
- mMountTogglePreference.setEnabled(true);
- mMountTogglePreference.setTitle(mResources.getString(R.string.sd_eject));
- mMountTogglePreference.setSummary(mResources.getString(R.string.sd_eject_summary));
- addPreference(mUsageBarPreference);
- addPreference(mItemTotal);
- addPreference(mItemAvailable);
- } else {
- 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));
- } else {
- mMountTogglePreference.setEnabled(false);
- mMountTogglePreference.setTitle(mResources.getString(R.string.sd_mount));
- mMountTogglePreference.setSummary(mResources.getString(R.string.sd_insert_summary));
- }
-
- removePreference(mUsageBarPreference);
- removePreference(mItemTotal);
- removePreference(mItemAvailable);
- }
-
- if (mUsbConnected && (UsbManager.USB_FUNCTION_MTP.equals(mUsbFunction) ||
- UsbManager.USB_FUNCTION_PTP.equals(mUsbFunction))) {
- mMountTogglePreference.setEnabled(false);
- if (Environment.MEDIA_MOUNTED.equals(state)
- || Environment.MEDIA_MOUNTED_READ_ONLY.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(mMountTogglePreference.isEnabled());
- mFormatPreference.setSummary(mResources.getString(R.string.sd_format_summary));
- }
- }
-
- public void updateApproximate(long totalSize, long availSize) {
- mItemTotal.setSummary(formatSize(totalSize));
- mItemAvailable.setSummary(formatSize(availSize));
-
- mTotalSize = totalSize;
-
- final long usedSize = totalSize - availSize;
-
- mUsageBarPreference.clear();
- mUsageBarPreference.addEntry(0, usedSize / (float) totalSize, android.graphics.Color.GRAY);
- mUsageBarPreference.commit();
-
- updatePreferencesFromState();
- }
-
- private static long totalValues(HashMap map, String... keys) {
- long total = 0;
- for (String key : keys) {
- if (map.containsKey(key)) {
- total += map.get(key);
- }
- }
- return total;
- }
-
- public void updateDetails(MeasurementDetails details) {
- final boolean showDetails = mVolume == null || mVolume.isPrimary();
- if (!showDetails) return;
-
- // Count caches as available space, since system manages them
- mItemTotal.setSummary(formatSize(details.totalSize));
- mItemAvailable.setSummary(formatSize(details.availSize));
-
- mUsageBarPreference.clear();
-
- updatePreference(mItemApps, details.appsSize);
-
- final long dcimSize = totalValues(details.mediaSize, Environment.DIRECTORY_DCIM,
- Environment.DIRECTORY_MOVIES, Environment.DIRECTORY_PICTURES);
- updatePreference(mItemDcim, dcimSize);
-
- final long musicSize = totalValues(details.mediaSize, Environment.DIRECTORY_MUSIC,
- Environment.DIRECTORY_ALARMS, Environment.DIRECTORY_NOTIFICATIONS,
- Environment.DIRECTORY_RINGTONES, Environment.DIRECTORY_PODCASTS);
- updatePreference(mItemMusic, musicSize);
-
- final long downloadsSize = totalValues(details.mediaSize, Environment.DIRECTORY_DOWNLOADS);
- updatePreference(mItemDownloads, downloadsSize);
-
- updatePreference(mItemCache, details.cacheSize);
- updatePreference(mItemMisc, details.miscSize);
-
- for (StorageItemPreference userPref : mItemUsers) {
- final long userSize = details.usersSize.get(userPref.userHandle);
- updatePreference(userPref, userSize);
- }
-
- mUsageBarPreference.commit();
- }
-
- private void updatePreference(StorageItemPreference pref, long size) {
- if (size > 0) {
- pref.setSummary(formatSize(size));
- final int order = pref.getOrder();
- mUsageBarPreference.addEntry(order, size / (float) mTotalSize, pref.color);
- } else {
- removePreference(pref);
- }
- }
-
- private void measure() {
- mMeasure.invalidate();
- mMeasure.measure();
- }
-
- public void onResume() {
- mMeasure.setReceiver(mReceiver);
- measure();
- }
-
- public void onStorageStateChanged() {
- init();
- measure();
- }
-
- public void onUsbStateChanged(boolean isUsbConnected, String usbFunction) {
- mUsbConnected = isUsbConnected;
- mUsbFunction = usbFunction;
- measure();
- }
-
- public void onMediaScannerFinished() {
- measure();
- }
-
- public void onCacheCleared() {
- measure();
- }
-
- public void onPause() {
- mMeasure.cleanUp();
- }
-
- private String formatSize(long size) {
- return Formatter.formatFileSize(getContext(), size);
- }
-
- private MeasurementReceiver mReceiver = new MeasurementReceiver() {
- @Override
- public void updateApproximate(StorageMeasurement meas, long totalSize, long availSize) {
- mUpdateHandler.obtainMessage(MSG_UI_UPDATE_APPROXIMATE, new long[] {
- totalSize, availSize }).sendToTarget();
- }
-
- @Override
- public void updateDetails(StorageMeasurement meas, MeasurementDetails details) {
- mUpdateHandler.obtainMessage(MSG_UI_UPDATE_DETAILS, details).sendToTarget();
- }
- };
-
- public boolean mountToggleClicked(Preference preference) {
- return preference == mMountTogglePreference;
- }
-
- public Intent intentForClick(Preference pref) {
- Intent intent = null;
-
- // TODO The current "delete" story is not fully handled by the respective applications.
- // When it is done, make sure the intent types below are correct.
- // If that cannot be done, remove these intents.
- final String key = pref.getKey();
- if (pref == mFormatPreference) {
- intent = new Intent(Intent.ACTION_VIEW);
- intent.setClass(getContext(), com.android.settings.MediaFormat.class);
- intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mVolume);
- } else if (pref == mItemApps) {
- intent = new Intent(Intent.ACTION_MANAGE_PACKAGE_STORAGE);
- intent.setClass(getContext(), Settings.ManageApplicationsActivity.class);
- } else if (pref == mItemDownloads) {
- intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS).putExtra(
- DownloadManager.INTENT_EXTRAS_SORT_BY_SIZE, true);
- } else if (pref == mItemMusic) {
- intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType("audio/mp3");
- } else if (pref == mItemDcim) {
- intent = new Intent(Intent.ACTION_VIEW);
- intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
- // TODO Create a Videos category, MediaStore.Video.Media.EXTERNAL_CONTENT_URI
- intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- } else if (pref == mItemMisc) {
- Context context = getContext().getApplicationContext();
- intent = new Intent(context, MiscFilesHandler.class);
- intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, mVolume);
- }
-
- return intent;
- }
-
- public static class PreferenceHeader extends Preference {
- public PreferenceHeader(Context context, int titleRes) {
- super(context, null, com.android.internal.R.attr.preferenceCategoryStyle);
- setTitle(titleRes);
- }
-
- public PreferenceHeader(Context context, CharSequence title) {
- super(context, null, com.android.internal.R.attr.preferenceCategoryStyle);
- setTitle(title);
- }
-
- @Override
- public boolean isEnabled() {
- return false;
- }
- }
-
- /**
- * Return list of other users, excluding the current user.
- */
- private List getUsersExcluding(UserInfo excluding) {
- final List users = mUserManager.getUsers();
- final Iterator i = users.iterator();
- while (i.hasNext()) {
- if (i.next().id == excluding.id) {
- i.remove();
- }
- }
- return users;
- }
-}
diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java
index f37e1fcf971..2143d0dc9b5 100644
--- a/src/com/android/settings/search/Ranking.java
+++ b/src/com/android/settings/search/Ranking.java
@@ -32,7 +32,7 @@ import com.android.settings.WirelessSettings;
import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.applications.AdvancedAppSettings;
import com.android.settings.bluetooth.BluetoothSettings;
-import com.android.settings.deviceinfo.Memory;
+import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.deviceinfo.UsbSettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
@@ -129,7 +129,7 @@ public final class Ranking {
sRankMap.put(ZenModeAutomationSettings.class.getName(), RANK_NOTIFICATIONS);
// Storage
- sRankMap.put(Memory.class.getName(), RANK_STORAGE);
+ sRankMap.put(StorageSettings.class.getName(), RANK_STORAGE);
sRankMap.put(UsbSettings.class.getName(), RANK_STORAGE);
// Battery
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index dae8860d48b..b7bb06213bb 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -34,7 +34,7 @@ import com.android.settings.WirelessSettings;
import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.applications.AdvancedAppSettings;
import com.android.settings.bluetooth.BluetoothSettings;
-import com.android.settings.deviceinfo.Memory;
+import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.deviceinfo.UsbSettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
@@ -170,11 +170,11 @@ public final class SearchIndexableResources {
ZenModePrioritySettings.class.getName(),
R.drawable.ic_settings_notifications));
- sResMap.put(Memory.class.getName(),
+ sResMap.put(StorageSettings.class.getName(),
new SearchIndexableResource(
- Ranking.getRankForClassName(Memory.class.getName()),
+ Ranking.getRankForClassName(StorageSettings.class.getName()),
NO_DATA_RES_ID,
- Memory.class.getName(),
+ StorageSettings.class.getName(),
R.drawable.ic_settings_storage));
sResMap.put(UsbSettings.class.getName(),