Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ef33984 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Move Size parceling to Bundle.

Size itself shouldn't be Parcelable, since that would be a layering
violation.

Bug: 17390381
Change-Id: Ica62709bd889db51c916c550a0146714b002baa3
parent 037458a5
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -21577,6 +21577,8 @@ package android.os {
    method public short getShort(java.lang.String);
    method public short getShort(java.lang.String, short);
    method public short[] getShortArray(java.lang.String);
    method public android.util.Size getSize(java.lang.String);
    method public android.util.SizeF getSizeF(java.lang.String);
    method public android.util.SparseArray<T> getSparseParcelableArray(java.lang.String);
    method public java.util.ArrayList<java.lang.String> getStringArrayList(java.lang.String);
    method public boolean hasFileDescriptors();
@@ -21601,6 +21603,8 @@ package android.os {
    method public void putSerializable(java.lang.String, java.io.Serializable);
    method public void putShort(java.lang.String, short);
    method public void putShortArray(java.lang.String, short[]);
    method public void putSize(java.lang.String, android.util.Size);
    method public void putSizeF(java.lang.String, android.util.SizeF);
    method public void putSparseParcelableArray(java.lang.String, android.util.SparseArray<? extends android.os.Parcelable>);
    method public void putStringArrayList(java.lang.String, java.util.ArrayList<java.lang.String>);
    method public void readFromParcel(android.os.Parcel);
@@ -22052,6 +22056,8 @@ package android.os {
    method public final android.os.PersistableBundle readPersistableBundle();
    method public final android.os.PersistableBundle readPersistableBundle(java.lang.ClassLoader);
    method public final java.io.Serializable readSerializable();
    method public final android.util.Size readSize();
    method public final android.util.SizeF readSizeF();
    method public final android.util.SparseArray readSparseArray(java.lang.ClassLoader);
    method public final android.util.SparseBooleanArray readSparseBooleanArray();
    method public final java.lang.String readString();
@@ -22093,6 +22099,8 @@ package android.os {
    method public final void writeParcelableArray(T[], int);
    method public final void writePersistableBundle(android.os.PersistableBundle);
    method public final void writeSerializable(java.io.Serializable);
    method public final void writeSize(android.util.Size);
    method public final void writeSizeF(android.util.SizeF);
    method public final void writeSparseArray(android.util.SparseArray<java.lang.Object>);
    method public final void writeSparseBooleanArray(android.util.SparseBooleanArray);
    method public final void writeString(java.lang.String);
@@ -32132,23 +32140,17 @@ package android.util {
    field public static final android.util.Rational ZERO;
  }
  public final class Size implements android.os.Parcelable {
  public final class Size {
    ctor public Size(int, int);
    method public int describeContents();
    method public int getHeight();
    method public int getWidth();
    method public static android.util.Size parseSize(java.lang.String) throws java.lang.NumberFormatException;
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public final class SizeF implements android.os.Parcelable {
  public final class SizeF {
    ctor public SizeF(float, float);
    method public int describeContents();
    method public float getHeight();
    method public float getWidth();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public class SparseArray implements java.lang.Cloneable {
+64 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package android.os;

import android.util.ArrayMap;
import android.util.Size;
import android.util.SizeF;
import android.util.SparseArray;

import java.io.Serializable;
@@ -334,6 +336,30 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
        mFdsKnown = false;
    }

    /**
     * Inserts a Size value into the mapping of this Bundle, replacing
     * any existing value for the given key.  Either key or value may be null.
     *
     * @param key a String, or null
     * @param value a Size object, or null
     */
    public void putSize(String key, Size value) {
        unparcel();
        mMap.put(key, value);
    }

    /**
     * Inserts a SizeF value into the mapping of this Bundle, replacing
     * any existing value for the given key.  Either key or value may be null.
     *
     * @param key a String, or null
     * @param value a SizeF object, or null
     */
    public void putSizeF(String key, SizeF value) {
        unparcel();
        mMap.put(key, value);
    }

    /**
     * Inserts an array of Parcelable values into the mapping of this Bundle,
     * replacing any existing value for the given key.  Either key or value may
@@ -706,6 +732,44 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
        return super.getCharSequence(key, defaultValue);
    }

    /**
     * Returns the value associated with the given key, or null if
     * no mapping of the desired type exists for the given key or a null
     * value is explicitly associated with the key.
     *
     * @param key a String, or null
     * @return a Size value, or null
     */
    public Size getSize(String key) {
        unparcel();
        final Object o = mMap.get(key);
        try {
            return (Size) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "Size", e);
            return null;
        }
    }

    /**
     * Returns the value associated with the given key, or null if
     * no mapping of the desired type exists for the given key or a null
     * value is explicitly associated with the key.
     *
     * @param key a String, or null
     * @return a Size value, or null
     */
    public SizeF getSizeF(String key) {
        unparcel();
        final Object o = mMap.get(key);
        try {
            return (SizeF) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "SizeF", e);
            return null;
        }
    }

    /**
     * Returns the value associated with the given key, or null if
     * no mapping of the desired type exists for the given key or a null
+52 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.os;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Size;
import android.util.SizeF;
import android.util.SparseArray;
import android.util.SparseBooleanArray;

@@ -224,6 +226,8 @@ public final class Parcel {
    private static final int VAL_BOOLEANARRAY = 23;
    private static final int VAL_CHARSEQUENCEARRAY = 24;
    private static final int VAL_PERSISTABLEBUNDLE = 25;
    private static final int VAL_SIZE = 26;
    private static final int VAL_SIZEF = 27;

    // The initial int32 in a Binder call's reply Parcel header:
    private static final int EX_SECURITY = -1;
@@ -671,6 +675,24 @@ public final class Parcel {
        val.writeToParcel(this, 0);
    }

    /**
     * Flatten a Size into the parcel at the current dataPosition(),
     * growing dataCapacity() if needed.
     */
    public final void writeSize(Size val) {
        writeInt(val.getWidth());
        writeInt(val.getHeight());
    }

    /**
     * Flatten a SizeF into the parcel at the current dataPosition(),
     * growing dataCapacity() if needed.
     */
    public final void writeSizeF(SizeF val) {
        writeFloat(val.getWidth());
        writeFloat(val.getHeight());
    }

    /**
     * Flatten a List into the parcel at the current dataPosition(), growing
     * dataCapacity() if needed.  The List values are written using
@@ -1293,6 +1315,12 @@ public final class Parcel {
        } else if (v instanceof PersistableBundle) {
            writeInt(VAL_PERSISTABLEBUNDLE);
            writePersistableBundle((PersistableBundle) v);
        } else if (v instanceof Size) {
            writeInt(VAL_SIZE);
            writeSize((Size) v);
        } else if (v instanceof SizeF) {
            writeInt(VAL_SIZEF);
            writeSizeF((SizeF) v);
        } else {
            Class<?> clazz = v.getClass();
            if (clazz.isArray() && clazz.getComponentType() == Object.class) {
@@ -1698,6 +1726,24 @@ public final class Parcel {
        return bundle;
    }

    /**
     * Read a Size from the parcel at the current dataPosition().
     */
    public final Size readSize() {
        final int width = readInt();
        final int height = readInt();
        return new Size(width, height);
    }

    /**
     * Read a SizeF from the parcel at the current dataPosition().
     */
    public final SizeF readSizeF() {
        final float width = readFloat();
        final float height = readFloat();
        return new SizeF(width, height);
    }

    /**
     * Read and return a byte[] object from the parcel.
     */
@@ -2160,6 +2206,12 @@ public final class Parcel {
        case VAL_PERSISTABLEBUNDLE:
            return readPersistableBundle(loader);

        case VAL_SIZE:
            return readSize();

        case VAL_SIZEF:
            return readSizeF();

        default:
            int off = dataPosition() - 4;
            throw new RuntimeException(
+1 −32
Original line number Diff line number Diff line
@@ -18,13 +18,10 @@ package android.util;

import static com.android.internal.util.Preconditions.checkNotNull;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Immutable class for describing width and height dimensions in pixels.
 */
public final class Size implements Parcelable {
public final class Size {
    /**
     * Create a new immutable Size instance.
     *
@@ -36,11 +33,6 @@ public final class Size implements Parcelable {
        mHeight = height;
    }

    private Size(Parcel in) {
        mWidth = in.readInt();
        mHeight = in.readInt();
    }

    /**
     * Get the width of the size (in pixels).
     * @return width
@@ -155,29 +147,6 @@ public final class Size implements Parcelable {
        return mHeight ^ ((mWidth << (Integer.SIZE / 2)) | (mWidth >>> (Integer.SIZE / 2)));
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mWidth);
        out.writeInt(mHeight);
    }

    public static final Parcelable.Creator<Size> CREATOR = new Parcelable.Creator<Size>() {
        @Override
        public Size createFromParcel(Parcel in) {
            return new Size(in);
        }

        @Override
        public Size[] newArray(int size) {
            return new Size[size];
        }
    };

    private final int mWidth;
    private final int mHeight;
}
+1 −32
Original line number Diff line number Diff line
@@ -18,9 +18,6 @@ package android.util;

import static com.android.internal.util.Preconditions.checkArgumentFinite;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Immutable class for describing width and height dimensions in some arbitrary
 * unit.
@@ -28,7 +25,7 @@ import android.os.Parcelable;
 * Width and height are finite values stored as a floating point representation.
 * </p>
 */
public final class SizeF implements Parcelable {
public final class SizeF {
    /**
     * Create a new immutable SizeF instance.
     *
@@ -46,11 +43,6 @@ public final class SizeF implements Parcelable {
        mHeight = checkArgumentFinite(height, "height");
    }

    private SizeF(Parcel in) {
        mWidth = in.readFloat();
        mHeight = in.readFloat();
    }

    /**
     * Get the width of the size (as an arbitrary unit).
     * @return width
@@ -111,29 +103,6 @@ public final class SizeF implements Parcelable {
        return Float.floatToIntBits(mWidth) ^ Float.floatToIntBits(mHeight);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeFloat(mWidth);
        out.writeFloat(mHeight);
    }

    public static final Parcelable.Creator<SizeF> CREATOR = new Parcelable.Creator<SizeF>() {
        @Override
        public SizeF createFromParcel(Parcel in) {
            return new SizeF(in);
        }

        @Override
        public SizeF[] newArray(int size) {
            return new SizeF[size];
        }
    };

    private final float mWidth;
    private final float mHeight;
}