summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2011-05-16 12:36:29 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-05-16 12:36:29 -0700
commitb822d2464dc59056f736b0c49f0ac514c7cbb9d9 (patch)
tree322007d113f6488cefb17b5082ac0ba9af98d940 /services
parent1f2a335f98503bab178d1d868a9cba0451481b7d (diff)
parent0a93d875527c52183080b63a0b19d567856952af (diff)
downloadframeworks_base-b822d2464dc59056f736b0c49f0ac514c7cbb9d9.zip
frameworks_base-b822d2464dc59056f736b0c49f0ac514c7cbb9d9.tar.gz
frameworks_base-b822d2464dc59056f736b0c49f0ac514c7cbb9d9.tar.bz2
am 0a93d875: Merge "StorageManager: Clean up and generalize storage configuration resources" into honeycomb-mr2
* commit '0a93d875527c52183080b63a0b19d567856952af': StorageManager: Clean up and generalize storage configuration resources
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/MountService.java109
1 files changed, 96 insertions, 13 deletions
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index a100f1f..376d42f 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -17,6 +17,7 @@
package com.android.server;
import com.android.internal.app.IMediaContainerService;
+import com.android.internal.util.XmlUtils;
import com.android.server.am.ActivityManagerService;
import android.Manifest;
@@ -28,6 +29,9 @@ import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.res.ObbInfo;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
import android.net.Uri;
import android.os.Binder;
import android.os.Environment;
@@ -36,6 +40,7 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
+import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -46,8 +51,14 @@ import android.os.storage.IMountShutdownObserver;
import android.os.storage.IObbActionListener;
import android.os.storage.OnObbStateChangeListener;
import android.os.storage.StorageResultCode;
+import android.os.storage.StorageVolume;
import android.text.TextUtils;
+import android.util.AttributeSet;
import android.util.Slog;
+import android.util.Xml;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
import java.io.FileDescriptor;
import java.io.IOException;
@@ -145,6 +156,8 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC
private Context mContext;
private NativeDaemonConnector mConnector;
+ private final ArrayList<StorageVolume> mVolumes = new ArrayList<StorageVolume>();
+ private StorageVolume mPrimaryVolume;
private final HashMap<String, String> mVolumeStates = new HashMap<String, String>();
private String mExternalStoragePath;
private PackageManagerService mPms;
@@ -1068,6 +1081,74 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC
}
}
+ // Storage list XML tags
+ private static final String TAG_STORAGE_LIST = "StorageList";
+ private static final String TAG_STORAGE = "storage";
+
+ private void readStorageList(Resources resources) {
+ int id = com.android.internal.R.xml.storage_list;
+ XmlResourceParser parser = resources.getXml(id);
+ AttributeSet attrs = Xml.asAttributeSet(parser);
+
+ try {
+ XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
+ while (true) {
+ XmlUtils.nextElement(parser);
+
+ String element = parser.getName();
+ if (element == null) break;
+
+ if (TAG_STORAGE.equals(element)) {
+ TypedArray a = resources.obtainAttributes(attrs,
+ com.android.internal.R.styleable.Storage);
+
+ CharSequence path = a.getText(
+ com.android.internal.R.styleable.Storage_mountPoint);
+ CharSequence description = a.getText(
+ com.android.internal.R.styleable.Storage_storageDescription);
+ boolean primary = a.getBoolean(
+ com.android.internal.R.styleable.Storage_primary, false);
+ boolean removable = a.getBoolean(
+ com.android.internal.R.styleable.Storage_removable, false);
+ boolean emulated = a.getBoolean(
+ com.android.internal.R.styleable.Storage_emulated, false);
+ int mtpReserve = a.getInt(
+ com.android.internal.R.styleable.Storage_mtpReserve, 0);
+
+ Slog.d(TAG, "got storage path: " + path + " description: " + description +
+ " primary: " + primary + " removable: " + removable +
+ " emulated: " + emulated + " mtpReserve: " + mtpReserve);
+ if (path == null || description == null) {
+ Slog.e(TAG, "path or description is null in readStorageList");
+ } else {
+ StorageVolume volume = new StorageVolume(path.toString(),
+ description.toString(), removable, emulated, mtpReserve);
+ if (primary) {
+ if (mPrimaryVolume == null) {
+ mPrimaryVolume = volume;
+ } else {
+ Slog.e(TAG, "multiple primary volumes in storage list");
+ }
+ }
+ if (mPrimaryVolume == volume) {
+ // primay volume must be first
+ mVolumes.add(0, volume);
+ } else {
+ mVolumes.add(volume);
+ }
+ }
+ a.recycle();
+ }
+ }
+ } catch (XmlPullParserException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ parser.close();
+ }
+ }
+
/**
* Constructs a new MountService instance
*
@@ -1075,13 +1156,16 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC
*/
public MountService(Context context) {
mContext = context;
+ Resources resources = context.getResources();
+ readStorageList(resources);
- mExternalStoragePath = Environment.getExternalStorageDirectory().getPath();
- mEmulateExternalStorage = context.getResources().getBoolean(
- com.android.internal.R.bool.config_emulateExternalStorage);
- if (mEmulateExternalStorage) {
- Slog.d(TAG, "using emulated external storage");
- mVolumeStates.put(mExternalStoragePath, Environment.MEDIA_MOUNTED);
+ if (mPrimaryVolume != null) {
+ mExternalStoragePath = mPrimaryVolume.getPath();
+ mEmulateExternalStorage = mPrimaryVolume.isEmulated();
+ if (mEmulateExternalStorage) {
+ Slog.d(TAG, "using emulated external storage");
+ mVolumeStates.put(mExternalStoragePath, Environment.MEDIA_MOUNTED);
+ }
}
// XXX: This will go away soon in favor of IMountServiceObserver
@@ -1753,13 +1837,12 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC
}
}
- public String[] getVolumeList() {
- synchronized(mVolumeStates) {
- Set<String> volumes = mVolumeStates.keySet();
- String[] result = new String[volumes.size()];
- int i = 0;
- for (String volume : volumes) {
- result[i++] = volume;
+ public Parcelable[] getVolumeList() {
+ synchronized(mVolumes) {
+ int size = mVolumes.size();
+ Parcelable[] result = new Parcelable[size];
+ for (int i = 0; i < size; i++) {
+ result[i] = mVolumes.get(i);
}
return result;
}