The only current flag ( PARCELABLE_WRITE_RETURN_VALUE ) is intended for use in AIDL interfaces. It is assumed that it hints at certain types of Parcelable objects that they are returning from the IPC method, so their associated resources can be freed. Fot, ContentProvider internally contains the AIDL method, for example:
ParcelFileDescriptor openFile(String path, int flags);
When you override openFile in a custom ContentProvider, your method returns the open ParcelFileDescriptor ... you do not close it yourself, and it does not close automatically during interprocess transfer (passing descriptors between processes does not mean they are closed in Linux). But the handle did not leak! Instead, ParcelFileDescriptor closes itself when writing in Parcel:
@Override public void writeToParcel(Parcel out, int flags) { if (mWrapped != null) { try { mWrapped.writeToParcel(out, flags); } finally { releaseResources(); } } else { if (mCommFd != null) { out.writeInt(1); out.writeFileDescriptor(mFd); out.writeFileDescriptor(mCommFd); } else { out.writeInt(0); out.writeFileDescriptor(mFd); } if ((flags & PARCELABLE_WRITE_RETURN_VALUE) != 0 && !mClosed) {
Since ParcelFileDescriptor is a regular class, using Binder / Parcel to transfer FileDescriptor between processes, you can imagine the existence of such classes that are stored on their own resources (memory, file descriptors) and conditionally free them when they return from openFile-like methods.
Similarly, other flags can be used to spread similar conditional behavior deep down. Gradual nesting doll. Unfortunately, the Android developers did not define reasonable rules for introducing such custom flags (unlike, for example, IBinder#FIRST_CALL_TRANSACTION and IBinder#LAST_CALL_TRANSACTION ), and AIDL is not widely used in practice outside the internal Android systems, so I do not know any examples of such flags .
source share