Make AbsSavedState read using given ClassLoader

Currently it does not use a ClassLoader to read
any super state, which can cause crashes for
custom views using the class but on a different
class loader.

BUG: 27790353
Change-Id: I4f4d1d72f213f2481606673643c0e56c23d34bc6
diff --git a/api/current.txt b/api/current.txt
index cc3b085..b2e063a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -40826,6 +40826,7 @@
   public abstract class AbsSavedState implements android.os.Parcelable {
     ctor protected AbsSavedState(android.os.Parcelable);
     ctor protected AbsSavedState(android.os.Parcel);
+    ctor protected AbsSavedState(android.os.Parcel, java.lang.ClassLoader);
     method public int describeContents();
     method public final android.os.Parcelable getSuperState();
     method public void writeToParcel(android.os.Parcel, int);
@@ -42942,6 +42943,7 @@
 
   public static class View.BaseSavedState extends android.view.AbsSavedState {
     ctor public View.BaseSavedState(android.os.Parcel);
+    ctor public View.BaseSavedState(android.os.Parcel, java.lang.ClassLoader);
     ctor public View.BaseSavedState(android.os.Parcelable);
     field public static final android.os.Parcelable.Creator<android.view.View.BaseSavedState> CREATOR;
   }
diff --git a/api/system-current.txt b/api/system-current.txt
index 7a71672..374acfe 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -43773,6 +43773,7 @@
   public abstract class AbsSavedState implements android.os.Parcelable {
     ctor protected AbsSavedState(android.os.Parcelable);
     ctor protected AbsSavedState(android.os.Parcel);
+    ctor protected AbsSavedState(android.os.Parcel, java.lang.ClassLoader);
     method public int describeContents();
     method public final android.os.Parcelable getSuperState();
     method public void writeToParcel(android.os.Parcel, int);
@@ -45889,6 +45890,7 @@
 
   public static class View.BaseSavedState extends android.view.AbsSavedState {
     ctor public View.BaseSavedState(android.os.Parcel);
+    ctor public View.BaseSavedState(android.os.Parcel, java.lang.ClassLoader);
     ctor public View.BaseSavedState(android.os.Parcelable);
     field public static final android.os.Parcelable.Creator<android.view.View.BaseSavedState> CREATOR;
   }
diff --git a/api/test-current.txt b/api/test-current.txt
index 39d69f3..90f8e99 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -40903,6 +40903,7 @@
   public abstract class AbsSavedState implements android.os.Parcelable {
     ctor protected AbsSavedState(android.os.Parcelable);
     ctor protected AbsSavedState(android.os.Parcel);
+    ctor protected AbsSavedState(android.os.Parcel, java.lang.ClassLoader);
     method public int describeContents();
     method public final android.os.Parcelable getSuperState();
     method public void writeToParcel(android.os.Parcel, int);
@@ -43019,6 +43020,7 @@
 
   public static class View.BaseSavedState extends android.view.AbsSavedState {
     ctor public View.BaseSavedState(android.os.Parcel);
+    ctor public View.BaseSavedState(android.os.Parcel, java.lang.ClassLoader);
     ctor public View.BaseSavedState(android.os.Parcelable);
     field public static final android.os.Parcelable.Creator<android.view.View.BaseSavedState> CREATOR;
   }
diff --git a/core/java/android/view/AbsSavedState.java b/core/java/android/view/AbsSavedState.java
index 6ad33dd..6b616c0 100644
--- a/core/java/android/view/AbsSavedState.java
+++ b/core/java/android/view/AbsSavedState.java
@@ -37,7 +37,7 @@
 
     /**
      * Constructor called by derived classes when creating their SavedState objects
-     * 
+     *
      * @param superState The state of the superclass of this view
      */
     protected AbsSavedState(Parcelable superState) {
@@ -49,13 +49,22 @@
 
     /**
      * Constructor used when reading from a parcel. Reads the state of the superclass.
-     * 
-     * @param source
+     *
+     * @param source parcel to read from
      */
     protected AbsSavedState(Parcel source) {
-        // FIXME need class loader
-        Parcelable superState = source.readParcelable(null);
-         
+        this(source, null);
+    }
+
+    /**
+     * Constructor used when reading from a parcel using a given class loader.
+     * Reads the state of the superclass.
+     *
+     * @param source parcel to read from
+     * @param loader ClassLoader to use for reading
+     */
+    protected AbsSavedState(Parcel source, ClassLoader loader) {
+        Parcelable superState = source.readParcelable(loader);
         mSuperState = superState != null ? superState : EMPTY_STATE;
     }
 
@@ -68,20 +77,27 @@
     }
 
     public void writeToParcel(Parcel dest, int flags) {
-         dest.writeParcelable(mSuperState, flags);
+        dest.writeParcelable(mSuperState, flags);
     }
 
-    public static final Parcelable.Creator<AbsSavedState> CREATOR 
-        = new Parcelable.Creator<AbsSavedState>() {
-        
+    public static final Parcelable.Creator<AbsSavedState> CREATOR
+            = new Parcelable.ClassLoaderCreator<AbsSavedState>() {
+
+        @Override
         public AbsSavedState createFromParcel(Parcel in) {
-            Parcelable superState = in.readParcelable(null);
+            return createFromParcel(in, null);
+        }
+
+        @Override
+        public AbsSavedState createFromParcel(Parcel in, ClassLoader loader) {
+            Parcelable superState = in.readParcelable(loader);
             if (superState != null) {
                 throw new IllegalStateException("superState must be null");
             }
             return EMPTY_STATE;
         }
 
+        @Override
         public AbsSavedState[] newArray(int size) {
             return new AbsSavedState[size];
         }
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 1781d9d..81310c4 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -22571,10 +22571,21 @@
         /**
          * Constructor used when reading from a parcel. Reads the state of the superclass.
          *
-         * @param source
+         * @param source parcel to read from
          */
         public BaseSavedState(Parcel source) {
-            super(source);
+            this(source, null);
+        }
+
+        /**
+         * Constructor used when reading from a parcel using a given class loader.
+         * Reads the state of the superclass.
+         *
+         * @param source parcel to read from
+         * @param loader ClassLoader to use for reading
+         */
+        public BaseSavedState(Parcel source, ClassLoader loader) {
+            super(source, loader);
             mStartActivityRequestWhoSaved = source.readString();
         }
 
@@ -22593,12 +22604,19 @@
             out.writeString(mStartActivityRequestWhoSaved);
         }
 
-        public static final Parcelable.Creator<BaseSavedState> CREATOR =
-                new Parcelable.Creator<BaseSavedState>() {
+        public static final Parcelable.Creator<BaseSavedState> CREATOR
+                = new Parcelable.ClassLoaderCreator<BaseSavedState>() {
+            @Override
             public BaseSavedState createFromParcel(Parcel in) {
                 return new BaseSavedState(in);
             }
 
+            @Override
+            public BaseSavedState createFromParcel(Parcel in, ClassLoader loader) {
+                return new BaseSavedState(in, loader);
+            }
+
+            @Override
             public BaseSavedState[] newArray(int size) {
                 return new BaseSavedState[size];
             }