am 53b988ba: am 5a79cfd7: am 27ac64ec: Merge "StorageVolume: Add getStorageId() accessor" into honeycomb-mr2

* commit '53b988ba1842f40e595bb85f2ca055c24787e6dc':
  StorageVolume: Add getStorageId() accessor
diff --git a/core/java/android/os/storage/StorageVolume.java b/core/java/android/os/storage/StorageVolume.java
index d79f6c8..d68e6fb 100644
--- a/core/java/android/os/storage/StorageVolume.java
+++ b/core/java/android/os/storage/StorageVolume.java
@@ -34,10 +34,10 @@
     private final boolean mRemovable;
     private final boolean mEmulated;
     private final int mMtpReserveSpace;
+    private int mStorageId;
 
     public StorageVolume(String path, String description,
-            boolean removable, boolean emulated,
-            int mtpReserveSpace) {
+            boolean removable, boolean emulated, int mtpReserveSpace) {
         mPath = path;
         mDescription = description;
         mRemovable = removable;
@@ -45,6 +45,17 @@
         mMtpReserveSpace = mtpReserveSpace;
     }
 
+    // for parcelling only
+    private StorageVolume(String path, String description,
+            boolean removable, boolean emulated, int mtpReserveSpace, int storageId) {
+        mPath = path;
+        mDescription = description;
+        mRemovable = removable;
+        mEmulated = emulated;
+        mMtpReserveSpace = mtpReserveSpace;
+        mStorageId = storageId;
+    }
+
     /**
      * Returns the mount path for the volume.
      *
@@ -82,6 +93,25 @@
     }
 
     /**
+     * Returns the MTP storage ID for the volume.
+     * this is also used for the storage_id column in the media provider.
+     *
+     * @return MTP storage ID
+     */
+    public int getStorageId() {
+        return mStorageId;
+    }
+
+    /**
+     * Do not call this unless you are MountService
+     */
+    public void setStorageId(int index) {
+        // storage ID is 0x00010001 for primary storage,
+        // then 0x00020001, 0x00030001, etc. for secondary storages
+        mStorageId = ((index + 1) << 16) + 1;
+    }
+
+    /**
      * Number of megabytes of space to leave unallocated by MTP.
      * MTP will subtract this value from the free space it reports back
      * to the host via GetStorageInfo, and will not allow new files to
@@ -123,9 +153,11 @@
             String description = in.readString();
             int removable = in.readInt();
             int emulated = in.readInt();
+            int storageId = in.readInt();
             int mtpReserveSpace = in.readInt();
             return new StorageVolume(path, description,
-                    removable == 1, emulated == 1, mtpReserveSpace);
+                    removable == 1, emulated == 1,
+                    mtpReserveSpace, storageId);
         }
 
         public StorageVolume[] newArray(int size) {
@@ -142,6 +174,7 @@
         parcel.writeString(mDescription);
         parcel.writeInt(mRemovable ? 1 : 0);
         parcel.writeInt(mEmulated ? 1 : 0);
+        parcel.writeInt(mStorageId);
         parcel.writeInt(mMtpReserveSpace);
     }
 }
diff --git a/media/java/android/mtp/MtpStorage.java b/media/java/android/mtp/MtpStorage.java
index 21a18ca..7932d34 100644
--- a/media/java/android/mtp/MtpStorage.java
+++ b/media/java/android/mtp/MtpStorage.java
@@ -16,6 +16,8 @@
 
 package android.mtp;
 
+import android.os.storage.StorageVolume;
+
 /**
  * This class represents a storage unit on an MTP device.
  * Used only for MTP support in USB responder mode.
@@ -31,13 +33,12 @@
     private final long mReserveSpace;
     private final boolean mRemovable;
 
-    public MtpStorage(int id, String path, String description,
-            long reserveSpace, boolean removable) {
-        mStorageId = id;
-        mPath = path;
-        mDescription = description;
-        mReserveSpace = reserveSpace;
-        mRemovable = removable;
+    public MtpStorage(StorageVolume volume) {
+        mStorageId = volume.getStorageId();
+        mPath = volume.getPath();
+        mDescription = volume.getDescription();
+        mReserveSpace = volume.getMtpReserveSpace();
+        mRemovable = volume.isRemovable();
     }
 
     /**
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index 03d5728..ae04b7f 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -1148,6 +1148,11 @@
         } catch (IOException e) {
             throw new RuntimeException(e);
         } finally {
+            // compute storage ID for each volume
+            int length = mVolumes.size();
+            for (int i = 0; i < length; i++) {
+                mVolumes.get(i).setStorageId(i);
+            }
             parser.close();
         }
     }