From e341fb2618214b9195bc0d80362bf837ceb25666 Mon Sep 17 00:00:00 2001 From: Adnan Begovic Date: Tue, 14 Jul 2015 18:09:13 -0700 Subject: [PATCH] cmsdk: Fix Profile parceling. Change-Id: I5cc260e902ef96f209ba55361374f795b81cc592 --- src/java/cyanogenmod/app/Profile.java | 142 +++++++++++++++++++------- 1 file changed, 106 insertions(+), 36 deletions(-) diff --git a/src/java/cyanogenmod/app/Profile.java b/src/java/cyanogenmod/app/Profile.java index a63b7e8b..18e95947 100755 --- a/src/java/cyanogenmod/app/Profile.java +++ b/src/java/cyanogenmod/app/Profile.java @@ -476,26 +476,76 @@ public int describeContents() { /** @hide */ @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeString(mName); - dest.writeInt(mNameResId); - new ParcelUuid(mUuid).writeToParcel(dest, 0); - ArrayList uuids = new ArrayList(mSecondaryUuids.size()); - for (UUID u : mSecondaryUuids) { - uuids.add(new ParcelUuid(u)); + if (!TextUtils.isEmpty(mName)) { + dest.writeInt(1); + dest.writeString(mName); + } else { + dest.writeInt(0); + } + if (mNameResId != 0) { + dest.writeInt(1); + dest.writeInt(mNameResId); + } else { + dest.writeInt(0); + } + if (mUuid != null) { + dest.writeInt(1); + new ParcelUuid(mUuid).writeToParcel(dest, 0); + } else { + dest.writeInt(0); + } + if (mSecondaryUuids != null && !mSecondaryUuids.isEmpty()) { + ArrayList uuids = new ArrayList(mSecondaryUuids.size()); + for (UUID u : mSecondaryUuids) { + uuids.add(new ParcelUuid(u)); + } + dest.writeInt(1); + dest.writeParcelableArray(uuids.toArray(new Parcelable[uuids.size()]), flags); + } else { + dest.writeInt(0); } - dest.writeParcelableArray(uuids.toArray(new Parcelable[uuids.size()]), flags); dest.writeInt(mStatusBarIndicator ? 1 : 0); dest.writeInt(mProfileType); dest.writeInt(mDirty ? 1 : 0); - dest.writeParcelableArray( - profileGroups.values().toArray(new Parcelable[profileGroups.size()]), flags); - dest.writeParcelableArray( - streams.values().toArray(new Parcelable[streams.size()]), flags); - dest.writeParcelableArray( - connections.values().toArray(new Parcelable[connections.size()]), flags); - dest.writeParcelable(mRingMode, flags); - dest.writeParcelable(mAirplaneMode, flags); - dest.writeParcelable(mBrightness, flags); + if (profileGroups != null && !profileGroups.isEmpty()) { + dest.writeInt(1); + dest.writeParcelableArray( + profileGroups.values().toArray(new Parcelable[profileGroups.size()]), flags); + } else { + dest.writeInt(0); + } + if (streams != null && !streams.isEmpty()) { + dest.writeInt(1); + dest.writeParcelableArray( + streams.values().toArray(new Parcelable[streams.size()]), flags); + } else { + dest.writeInt(0); + } + if (connections != null && !connections.isEmpty()) { + dest.writeInt(1); + dest.writeParcelableArray( + connections.values().toArray(new Parcelable[connections.size()]), flags); + } else { + dest.writeInt(0); + } + if (mRingMode != null) { + dest.writeInt(1); + mRingMode.writeToParcel(dest, 0); + } else { + dest.writeInt(0); + } + if (mAirplaneMode != null) { + dest.writeInt(1); + mAirplaneMode.writeToParcel(dest, 0); + } else { + dest.writeInt(0); + } + if (mBrightness != null) { + dest.writeInt(1); + mBrightness.writeToParcel(dest, 0); + } else { + dest.writeInt(0); + } dest.writeInt(mScreenLockMode); dest.writeMap(mTriggers); dest.writeInt(mExpandedDesktopMode); @@ -504,34 +554,54 @@ public void writeToParcel(Parcel dest, int flags) { /** @hide */ public void readFromParcel(Parcel in) { - mName = in.readString(); - mNameResId = in.readInt(); - mUuid = ParcelUuid.CREATOR.createFromParcel(in).getUuid(); - for (Parcelable parcel : in.readParcelableArray(null)) { - ParcelUuid u = (ParcelUuid) parcel; - mSecondaryUuids.add(u.getUuid()); + if (in.readInt() != 0) { + mName = in.readString(); + } + if (in.readInt() != 0) { + mNameResId = in.readInt(); + } + if (in.readInt() != 0) { + mUuid = ParcelUuid.CREATOR.createFromParcel(in).getUuid(); + } + if (in.readInt() != 0) { + for (Parcelable parcel : in.readParcelableArray(null)) { + ParcelUuid u = (ParcelUuid) parcel; + mSecondaryUuids.add(u.getUuid()); + } } mStatusBarIndicator = (in.readInt() == 1); mProfileType = in.readInt(); mDirty = (in.readInt() == 1); - for (Parcelable group : in.readParcelableArray(null)) { - ProfileGroup grp = (ProfileGroup) group; - profileGroups.put(grp.getUuid(), grp); - if (grp.isDefaultGroup()) { - mDefaultGroup = grp; + if (in.readInt() != 0) { + for (Parcelable group : in.readParcelableArray(null)) { + ProfileGroup grp = (ProfileGroup) group; + profileGroups.put(grp.getUuid(), grp); + if (grp.isDefaultGroup()) { + mDefaultGroup = grp; + } + } + } + if (in.readInt() != 0) { + for (Parcelable parcel : in.readParcelableArray(null)) { + StreamSettings stream = (StreamSettings) parcel; + streams.put(stream.getStreamId(), stream); + } + } + if (in.readInt() != 0) { + for (Parcelable parcel : in.readParcelableArray(null)) { + ConnectionSettings connection = (ConnectionSettings) parcel; + connections.put(connection.getConnectionId(), connection); } } - for (Parcelable parcel : in.readParcelableArray(null)) { - StreamSettings stream = (StreamSettings) parcel; - streams.put(stream.getStreamId(), stream); + if (in.readInt() != 0) { + mRingMode = RingModeSettings.CREATOR.createFromParcel(in); + } + if (in.readInt() != 0) { + mAirplaneMode = AirplaneModeSettings.CREATOR.createFromParcel(in); } - for (Parcelable parcel : in.readParcelableArray(null)) { - ConnectionSettings connection = (ConnectionSettings) parcel; - connections.put(connection.getConnectionId(), connection); + if (in.readInt() != 0) { + mBrightness = BrightnessSettings.CREATOR.createFromParcel(in); } - mRingMode = (RingModeSettings) in.readParcelable(null); - mAirplaneMode = (AirplaneModeSettings) in.readParcelable(null); - mBrightness = (BrightnessSettings) in.readParcelable(null); mScreenLockMode = in.readInt(); in.readMap(mTriggers, null); mExpandedDesktopMode = in.readInt();