Revert "MediaRouter: Preserve custom data in metadata between Api21 and Compat"

This reverts commit 56264c1f9d3493fc24728b37e20c11dc066385e7.

Bug: 25446896
Change-Id: Ie25586c5c44f87a080ae6dc1f87cc8e76a1e37d1
diff --git a/v4/api21/android/support/v4/media/MediaMetadataCompatApi21.java b/v4/api21/android/support/v4/media/MediaMetadataCompatApi21.java
index fd51f78..eddcf76 100644
--- a/v4/api21/android/support/v4/media/MediaMetadataCompatApi21.java
+++ b/v4/api21/android/support/v4/media/MediaMetadataCompatApi21.java
@@ -19,7 +19,6 @@
 import android.graphics.Bitmap;
 import android.media.MediaMetadata;
 import android.media.Rating;
-import android.os.Parcel;
 
 import java.util.Set;
 
@@ -44,14 +43,6 @@
         return ((MediaMetadata) metadataObj).getText(key);
     }
 
-    public static void writeToParcel(Object metadataObj, Parcel dest, int flags) {
-        ((MediaMetadata) metadataObj).writeToParcel(dest, flags);
-    }
-
-    public static Object createFromParcel(Parcel in) {
-        return MediaMetadata.CREATOR.createFromParcel(in);
-    }
-
     public static class Builder {
         public static Object newInstance() {
             return new MediaMetadata.Builder();
diff --git a/v4/java/android/support/v4/media/MediaMetadataCompat.java b/v4/java/android/support/v4/media/MediaMetadataCompat.java
index f9bd3ae..d6ebfa4 100644
--- a/v4/java/android/support/v4/media/MediaMetadataCompat.java
+++ b/v4/java/android/support/v4/media/MediaMetadataCompat.java
@@ -510,12 +510,32 @@
             return null;
         }
 
-        Parcel p = Parcel.obtain();
-        MediaMetadataCompatApi21.writeToParcel(metadataObj, p, 0);
-        p.setDataPosition(0);
-        MediaMetadataCompat metadata = MediaMetadataCompat.CREATOR.createFromParcel(p);
-        p.recycle();
-
+        Builder builder = new Builder();
+        for (String key : MediaMetadataCompatApi21.keySet(metadataObj)) {
+            Integer type = METADATA_KEYS_TYPE.get(key);
+            if (type != null) {
+                switch (type) {
+                    case METADATA_TYPE_BITMAP:
+                        builder.putBitmap(key,
+                                MediaMetadataCompatApi21.getBitmap(metadataObj, key));
+                        break;
+                    case METADATA_TYPE_LONG:
+                        builder.putLong(key,
+                                MediaMetadataCompatApi21.getLong(metadataObj, key));
+                        break;
+                    case METADATA_TYPE_RATING:
+                        builder.putRating(key, RatingCompat.fromRating(
+                                MediaMetadataCompatApi21.getRating(metadataObj, key)));
+                        break;
+                    case METADATA_TYPE_TEXT:
+                        builder.putText(key,
+                                MediaMetadataCompatApi21.getText(metadataObj, key));
+                        break;
+                }
+            }
+        }
+        MediaMetadataCompat metadata = builder.build();
+        metadata.mMetadataObj = metadataObj;
         return metadata;
     }
 
@@ -534,12 +554,31 @@
             return mMetadataObj;
         }
 
-        Parcel p = Parcel.obtain();
-        writeToParcel(p, 0);
-        p.setDataPosition(0);
-        mMetadataObj = MediaMetadataCompatApi21.createFromParcel(p);
-        p.recycle();
-
+        Object builderObj = MediaMetadataCompatApi21.Builder.newInstance();
+        for (String key : keySet()) {
+            Integer type = METADATA_KEYS_TYPE.get(key);
+            if (type != null) {
+                switch (type) {
+                    case METADATA_TYPE_BITMAP:
+                        MediaMetadataCompatApi21.Builder.putBitmap(builderObj, key,
+                                getBitmap(key));
+                        break;
+                    case METADATA_TYPE_LONG:
+                        MediaMetadataCompatApi21.Builder.putLong(builderObj, key,
+                                getLong(key));
+                        break;
+                    case METADATA_TYPE_RATING:
+                        MediaMetadataCompatApi21.Builder.putRating(builderObj, key,
+                                getRating(key).getRating());
+                        break;
+                    case METADATA_TYPE_TEXT:
+                        MediaMetadataCompatApi21.Builder.putText(builderObj, key,
+                                getText(key));
+                        break;
+                }
+            }
+        }
+        mMetadataObj = MediaMetadataCompatApi21.Builder.build(builderObj);
         return mMetadataObj;
     }