Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.os;
     18 
     19 /**
     20  * Parcelable containing a raw Parcel of data.
     21  * @hide
     22  */
     23 public class ParcelableParcel implements Parcelable {
     24     final Parcel mParcel;
     25     final ClassLoader mClassLoader;
     26 
     27     public ParcelableParcel(ClassLoader loader) {
     28         mParcel = Parcel.obtain();
     29         mClassLoader = loader;
     30     }
     31 
     32     public ParcelableParcel(Parcel src, ClassLoader loader) {
     33         mParcel = Parcel.obtain();
     34         mClassLoader = loader;
     35         int size = src.readInt();
     36         int pos = src.dataPosition();
     37         mParcel.appendFrom(src, src.dataPosition(), size);
     38         src.setDataPosition(pos + size);
     39     }
     40 
     41     public Parcel getParcel() {
     42         mParcel.setDataPosition(0);
     43         return mParcel;
     44     }
     45 
     46     public ClassLoader getClassLoader() {
     47         return mClassLoader;
     48     }
     49 
     50     @Override
     51     public int describeContents() {
     52         return 0;
     53     }
     54 
     55     @Override
     56     public void writeToParcel(Parcel dest, int flags) {
     57         dest.writeInt(mParcel.dataSize());
     58         dest.appendFrom(mParcel, 0, mParcel.dataSize());
     59     }
     60 
     61     public static final Parcelable.ClassLoaderCreator<ParcelableParcel> CREATOR
     62             = new Parcelable.ClassLoaderCreator<ParcelableParcel>() {
     63         public ParcelableParcel createFromParcel(Parcel in) {
     64             return new ParcelableParcel(in, null);
     65         }
     66 
     67         public ParcelableParcel createFromParcel(Parcel in, ClassLoader loader) {
     68             return new ParcelableParcel(in, loader);
     69         }
     70 
     71         public ParcelableParcel[] newArray(int size) {
     72             return new ParcelableParcel[size];
     73         }
     74     };
     75 }
     76