cmsdk: Declare a parcelable header.

- This change forces that a parcelable header is written as the
  first data positions in a parcel and defines a means to distinguish
  between old sdk class versions vs new ones to do proper unraveling
  of parcels.

Ticket: BAMBOO-152
Change-Id: I9cc762fe8a51cc527e85be7fe5de57e4613be019
This commit is contained in:
Adnan Begovic 2015-07-20 13:47:50 -07:00
parent 5ff5e10bf0
commit 33a24ad589
10 changed files with 534 additions and 123 deletions

View File

@ -23,6 +23,7 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import cyanogenmod.os.Build;
import java.util.ArrayList;
@ -85,7 +86,16 @@ public class CustomTile implements Parcelable {
* Unflatten the CustomTile from a parcel.
*/
public CustomTile(Parcel parcel) {
resourcesPackageName = parcel.readString();
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = parcel.readInt();
int parcelableSize = parcel.readInt();
int startPosition = parcel.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
if (parcel.readInt() != 0) {
this.onClick = PendingIntent.CREATOR.createFromParcel(parcel);
}
@ -107,6 +117,13 @@ public class CustomTile implements Parcelable {
this.icon = parcel.readInt();
}
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
this.resourcesPackageName = parcel.readString();
}
parcel.setDataPosition(startPosition + parcelableSize);
}
/**
* Constructs a CustomTile object with default values.
* You might want to consider using {@link cyanogenmod.app.CustomTile.Builder} instead.
@ -177,7 +194,17 @@ public class CustomTile implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(resourcesPackageName);
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
out.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = out.dataPosition();
out.writeInt(0);
int startPosition = out.dataPosition();
// ==== APRICOT =====
if (onClick != null) {
out.writeInt(1);
onClick.writeToParcel(out, 0);
@ -215,6 +242,15 @@ public class CustomTile implements Parcelable {
out.writeInt(0);
}
out.writeInt(icon);
// ==== BOYSENBERRY =====
out.writeString(resourcesPackageName);
// Go back and write size
int parcelableSize = out.dataPosition() - startPosition;
out.setDataPosition(sizePosition);
out.writeInt(parcelableSize);
out.setDataPosition(startPosition + parcelableSize);
}
/**
@ -245,12 +281,25 @@ public class CustomTile implements Parcelable {
private int styleId;
private ExpandedStyle(Parcel parcel) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = parcel.readInt();
int parcelableSize = parcel.readInt();
int startPosition = parcel.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
if (parcel.readInt() != 0) {
expandedItems = parcel.createTypedArray(ExpandedItem.CREATOR);
}
styleId = parcel.readInt();
}
parcel.setDataPosition(startPosition + parcelableSize);
}
/**
* @hide
*/
@ -298,6 +347,17 @@ public class CustomTile implements Parcelable {
@Override
public void writeToParcel(Parcel parcel, int i) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
parcel.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = parcel.dataPosition();
parcel.writeInt(0);
int startPosition = parcel.dataPosition();
// ==== APRICOT ====
if (expandedItems != null) {
parcel.writeInt(1);
parcel.writeTypedArray(expandedItems, 0);
@ -305,6 +365,12 @@ public class CustomTile implements Parcelable {
parcel.writeInt(0);
}
parcel.writeInt(styleId);
// Go back and write size
int parcelableSize = parcel.dataPosition() - startPosition;
parcel.setDataPosition(sizePosition);
parcel.writeInt(parcelableSize);
parcel.setDataPosition(startPosition + parcelableSize);
}
@Override
@ -444,6 +510,16 @@ public class CustomTile implements Parcelable {
* Unflatten the ExpandedItem from a parcel.
*/
protected ExpandedItem(Parcel parcel) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = parcel.readInt();
int parcelableSize = parcel.readInt();
int startPosition = parcel.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
if (parcel.readInt() != 0) {
onClickPendingIntent = PendingIntent.CREATOR.createFromParcel(parcel);
}
@ -456,6 +532,9 @@ public class CustomTile implements Parcelable {
itemDrawableResourceId = parcel.readInt();
}
parcel.setDataPosition(startPosition + parcelableSize);
}
@Override
public int describeContents() {
return 0;
@ -463,6 +542,16 @@ public class CustomTile implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
out.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = out.dataPosition();
out.writeInt(0);
int startPosition = out.dataPosition();
if (onClickPendingIntent != null) {
out.writeInt(1);
onClickPendingIntent.writeToParcel(out, 0);
@ -482,6 +571,12 @@ public class CustomTile implements Parcelable {
out.writeInt(0);
}
out.writeInt(itemDrawableResourceId);
// Go back and write size
int parcelableSize = out.dataPosition() - startPosition;
out.setDataPosition(sizePosition);
out.writeInt(parcelableSize);
out.setDataPosition(startPosition + parcelableSize);
}
@Override

View File

@ -26,6 +26,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import cyanogenmod.os.Build;
import cyanogenmod.profiles.AirplaneModeSettings;
import cyanogenmod.profiles.BrightnessSettings;
import cyanogenmod.profiles.ConnectionSettings;
@ -189,18 +190,47 @@ public final class Profile implements Parcelable, Comparable {
}
private ProfileTrigger(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
mType = in.readInt();
mId = in.readString();
mState = in.readInt();
mName = in.readString();
}
in.setDataPosition(startPosition + parcelableSize);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
dest.writeInt(mType);
dest.writeString(mId);
dest.writeInt(mState);
dest.writeString(mName);
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
@Override
@ -476,6 +506,17 @@ public final class Profile implements Parcelable, Comparable {
/** @hide */
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// === BOYSENBERRY ===
if (!TextUtils.isEmpty(mName)) {
dest.writeInt(1);
dest.writeString(mName);
@ -550,10 +591,26 @@ public final class Profile implements Parcelable, Comparable {
dest.writeMap(mTriggers);
dest.writeInt(mExpandedDesktopMode);
dest.writeInt(mDozeMode);
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
/** @hide */
public void readFromParcel(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
if (in.readInt() != 0) {
mName = in.readString();
}
@ -608,6 +665,9 @@ public final class Profile implements Parcelable, Comparable {
mDozeMode = in.readInt();
}
in.setDataPosition(startPosition + parcelableSize);
}
/**
* Get the name associated with the {@link Profile}
* @return a string name of the profile

View File

@ -18,6 +18,7 @@ package cyanogenmod.app;
import android.app.Notification;
import android.app.NotificationGroup;
import cyanogenmod.os.Build;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -263,21 +264,47 @@ public final class ProfileGroup implements Parcelable {
/** @hide */
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// === BOYSENBERRY ===
dest.writeString(mName);
new ParcelUuid(mUuid).writeToParcel(dest, 0);
dest.writeInt(mDefaultGroup ? 1 : 0);
dest.writeInt(mDirty ? 1 : 0);
dest.writeParcelable(mSoundOverride, flags);
dest.writeParcelable(mRingerOverride, flags);
dest.writeString(mSoundMode.name());
dest.writeString(mRingerMode.name());
dest.writeString(mVibrateMode.name());
dest.writeString(mLightsMode.name());
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
/** @hide */
public void readFromParcel(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
mName = in.readString();
mUuid = ParcelUuid.CREATOR.createFromParcel(in).getUuid();
mDefaultGroup = in.readInt() != 0;
@ -291,6 +318,9 @@ public final class ProfileGroup implements Parcelable {
mLightsMode = Mode.valueOf(Mode.class, in.readString());
}
in.setDataPosition(startPosition + parcelableSize);
}
public enum Mode {
SUPPRESS, DEFAULT, OVERRIDE;
}

View File

@ -19,6 +19,7 @@ package cyanogenmod.app;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import cyanogenmod.os.Build;
/**
* Class encapsulating a Custom Tile. Sent by the StatusBarManagerService to clients including
@ -66,21 +67,62 @@ public class StatusBarPanelCustomTile implements Parcelable {
public StatusBarPanelCustomTile(Parcel in) {
this.pkg = in.readString();
this.resPkg = in.readString();
this.opPkg = in.readString();
this.id = in.readInt();
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// tmp variables for final
String tmpResPkg = null;
String tmpPkg = null;
String tmpOpPkg = null;
int tmpId = -1;
String tmpTag = null;
int tmpUid = -1;
int tmpPid = -1;
CustomTile tmpCustomTile = null;
UserHandle tmpUser = null;
long tmpPostTime = -1;
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
// default
tmpPkg = in.readString();
tmpOpPkg = in.readString();
tmpId = in.readInt();
if (in.readInt() != 0) {
this.tag = in.readString();
tmpTag = in.readString();
} else {
this.tag = null;
tmpTag = null;
}
this.uid = in.readInt();
this.initialPid = in.readInt();
this.customTile = new CustomTile(in);
this.user = UserHandle.readFromParcel(in);
this.postTime = in.readLong();
tmpUid = in.readInt();
tmpPid = in.readInt();
tmpCustomTile = new CustomTile(in);
tmpUser = UserHandle.readFromParcel(in);
tmpPostTime = in.readLong();
}
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
tmpResPkg = in.readString();
}
// Assign finals
this.resPkg = tmpResPkg;
this.pkg = tmpPkg;
this.opPkg = tmpOpPkg;
this.id = tmpId;
this.tag = tmpTag;
this.uid = tmpUid;
this.initialPid = tmpPid;
this.customTile = tmpCustomTile;
this.user = tmpUser;
this.postTime = tmpPostTime;
this.key = key();
in.setDataPosition(startPosition + parcelableSize);
}
private String key() {
@ -115,8 +157,18 @@ public class StatusBarPanelCustomTile implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
out.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = out.dataPosition();
out.writeInt(0);
int startPosition = out.dataPosition();
// ==== APRICOT ===
out.writeString(this.pkg);
out.writeString(this.resPkg);
out.writeString(this.opPkg);
out.writeInt(this.id);
if (this.tag != null) {
@ -130,6 +182,15 @@ public class StatusBarPanelCustomTile implements Parcelable {
this.customTile.writeToParcel(out, flags);
user.writeToParcel(out, flags);
out.writeLong(this.postTime);
// ==== BOYSENBERRY =====
out.writeString(this.resPkg);
// Go back and write size
int parcelableSize = out.dataPosition() - startPosition;
out.setDataPosition(sizePosition);
out.writeInt(parcelableSize);
out.setDataPosition(startPosition + parcelableSize);
}
@Override

View File

@ -27,6 +27,16 @@ public class Build {
/** Value used for when a build property is unknown. */
public static final String UNKNOWN = "unknown";
/**
* Since there might be a case where new versions of the cm framework use applications running
* old versions of the protocol (and thus old versions of this class), we need a versioning
* system for the parcels sent between the core framework and its sdk users.
*
* This parcelable version should be the latest version API version listed in
* {@link CM_VERSION_CODES}
*/
public static final int PARCELABLE_VERSION = CM_VERSION_CODES.BOYSENBERRY;
private static final SparseArray<String> sdkMap;
static
{

View File

@ -22,6 +22,7 @@ import android.provider.Settings;
import android.os.Parcel;
import android.os.Parcelable;
import cyanogenmod.os.Build;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -187,15 +188,45 @@ public final class AirplaneModeSettings implements Parcelable {
/** @hide */
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// === BOYSENBERRY ===
dest.writeInt(mOverride ? 1 : 0);
dest.writeInt(mValue);
dest.writeInt(mDirty ? 1 : 0);
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
/** @hide */
public void readFromParcel(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
mOverride = in.readInt() != 0;
mValue = in.readInt();
mDirty = in.readInt() != 0;
}
in.setDataPosition(startPosition + parcelableSize);
}
}

View File

@ -21,6 +21,7 @@ import android.provider.Settings;
import android.os.Parcel;
import android.os.Parcelable;
import cyanogenmod.os.Build;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -185,15 +186,45 @@ public final class BrightnessSettings implements Parcelable {
/** @hide */
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// === BOYSENBERRY ===
dest.writeInt(mOverride ? 1 : 0);
dest.writeInt(mValue);
dest.writeInt(mDirty ? 1 : 0);
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
/** @hide */
public void readFromParcel(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
mOverride = in.readInt() != 0;
mValue = in.readInt();
mDirty = in.readInt() != 0;
}
in.setDataPosition(startPosition + parcelableSize);
}
}

View File

@ -31,6 +31,7 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import com.android.internal.telephony.RILConstants;
import cyanogenmod.os.Build;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -390,17 +391,47 @@ public final class ConnectionSettings implements Parcelable {
/** @hide */
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// === BOYSENBERRY ===
dest.writeInt(mConnectionId);
dest.writeInt(mOverride ? 1 : 0);
dest.writeInt(mValue);
dest.writeInt(mDirty ? 1 : 0);
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
/** @hide */
public void readFromParcel(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
mConnectionId = in.readInt();
mOverride = in.readInt() != 0;
mValue = in.readInt();
mDirty = in.readInt() != 0;
}
in.setDataPosition(startPosition + parcelableSize);
}
}

View File

@ -21,6 +21,7 @@ import android.media.AudioManager;
import android.os.Parcel;
import android.os.Parcelable;
import cyanogenmod.os.Build;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -177,15 +178,45 @@ public final class RingModeSettings implements Parcelable {
/** @hide */
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// === BOYSENBERRY ===
dest.writeInt(mOverride ? 1 : 0);
dest.writeString(mValue);
dest.writeInt(mDirty ? 1 : 0);
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
/** @hide */
public void readFromParcel(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
mOverride = in.readInt() != 0;
mValue = in.readString();
mDirty = in.readInt() != 0;
}
in.setDataPosition(startPosition + parcelableSize);
}
}

View File

@ -16,6 +16,7 @@
package cyanogenmod.profiles;
import cyanogenmod.os.Build;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -176,17 +177,47 @@ public final class StreamSettings implements Parcelable{
/** @hide */
@Override
public void writeToParcel(Parcel dest, int flags) {
// Write parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
dest.writeInt(Build.PARCELABLE_VERSION);
// Inject a placeholder that will store the parcel size from this point on
// (not including the size itself).
int sizePosition = dest.dataPosition();
dest.writeInt(0);
int startPosition = dest.dataPosition();
// === BOYSENBERRY ===
dest.writeInt(mStreamId);
dest.writeInt(mOverride ? 1 : 0);
dest.writeInt(mValue);
dest.writeInt(mDirty ? 1 : 0);
// Go back and write size
int parcelableSize = dest.dataPosition() - startPosition;
dest.setDataPosition(sizePosition);
dest.writeInt(parcelableSize);
dest.setDataPosition(startPosition + parcelableSize);
}
/** @hide */
public void readFromParcel(Parcel in) {
// Read parcelable version, make sure to define explicit changes
// within {@link Build.PARCELABLE_VERSION);
int parcelableVersion = in.readInt();
int parcelableSize = in.readInt();
int startPosition = in.dataPosition();
// Pattern here is that all new members should be added to the end of
// the writeToParcel method. Then we step through each version, until the latest
// API release to help unravel this parcel
if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
mStreamId = in.readInt();
mOverride = in.readInt() != 0;
mValue = in.readInt();
mDirty = in.readInt() != 0;
}
in.setDataPosition(startPosition + parcelableSize);
}
}