diff options
author | Dan Egnor <egnor@google.com> | 2010-07-20 09:03:35 -0700 |
---|---|---|
committer | Dan Egnor <egnor@google.com> | 2010-07-20 10:24:38 -0700 |
commit | b3e4ef37021a9e5518fdbc7d0cbb0a1709d5301b (patch) | |
tree | b13d85bcfc40caff56e53ebfdf78e0a00694caf2 /core | |
parent | bfcbeffc54e93b1c2e2d95fdc301786df4376d6f (diff) | |
download | frameworks_base-b3e4ef37021a9e5518fdbc7d0cbb0a1709d5301b.zip frameworks_base-b3e4ef37021a9e5518fdbc7d0cbb0a1709d5301b.tar.gz frameworks_base-b3e4ef37021a9e5518fdbc7d0cbb0a1709d5301b.tar.bz2 |
COMMENT ONLY change to add some warnings about ParcelFileDescriptor
behavior with Parcel.writeValue().
Change-Id: If55fcce29559379855735ff5297cf4f46d5d6be6
Bug: 2847738
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/os/Parcel.java | 19 | ||||
-rw-r--r-- | core/java/android/os/ParcelFileDescriptor.java | 5 |
2 files changed, 21 insertions, 3 deletions
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 8ad600c..bb6357e 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -437,6 +437,12 @@ public final class Parcel { /** * Write a FileDescriptor into the parcel at the current dataPosition(), * growing dataCapacity() if needed. + * + * <p class="caution">The file descriptor will not be closed, which may + * result in file descriptor leaks when objects are returned from Binder + * calls. Use {@link ParcelFileDescriptor#writeToParcel} instead, which + * accepts contextual flags and will close the original file descriptor + * if {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE} is set.</p> */ public final native void writeFileDescriptor(FileDescriptor val); @@ -1000,7 +1006,7 @@ public final class Parcel { /** * Flatten a generic object in to a parcel. The given Object value may * currently be one of the following types: - * + * * <ul> * <li> null * <li> String @@ -1023,7 +1029,7 @@ public final class Parcel { * <li> Parcelable[] * <li> CharSequence (as supported by {@link TextUtils#writeToParcel}). * <li> List (as supported by {@link #writeList}). - * <li> {@link SparseArray} (as supported by {@link #writeSparseArray}). + * <li> {@link SparseArray} (as supported by {@link #writeSparseArray(SparseArray)}). * <li> {@link IBinder} * <li> Any object that implements Serializable (but see * {@link #writeSerializable} for caveats). Note that all of the @@ -1032,6 +1038,13 @@ public final class Parcel { * approach is much less efficient and should be avoided whenever * possible. * </ul> + * + * <p class="caution">{@link Parcelable} objects are written with + * {@link Parcelable#writeToParcel} using contextual flags of 0. When + * serializing objects containing {@link ParcelFileDescriptor}s, + * this may result in file descriptor leaks when they are returned from + * Binder calls (where {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE} + * should be used).</p> */ public final void writeValue(Object v) { if (v == null) { @@ -1120,7 +1133,7 @@ public final class Parcel { /** * Flatten the name of the class of the Parcelable and its contents * into the parcel. - * + * * @param p The Parcelable object to be written. * @param parcelableFlags Contextual flags as per * {@link Parcelable#writeToParcel(Parcel, int) Parcelable.writeToParcel()}. diff --git a/core/java/android/os/ParcelFileDescriptor.java b/core/java/android/os/ParcelFileDescriptor.java index 0a3b2cf..e8fe302 100644 --- a/core/java/android/os/ParcelFileDescriptor.java +++ b/core/java/android/os/ParcelFileDescriptor.java @@ -250,6 +250,11 @@ public class ParcelFileDescriptor implements Parcelable { return Parcelable.CONTENTS_FILE_DESCRIPTOR; } + /** + * {@inheritDoc} + * If {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE} is set in flags, + * the file descriptor will be closed after a copy is written to the Parcel. + */ public void writeToParcel(Parcel out, int flags) { out.writeFileDescriptor(mFileDescriptor); if ((flags&PARCELABLE_WRITE_RETURN_VALUE) != 0 && !mClosed) { |