Deprecate unsafe parcel APIs and point to the safer ones that take the
expected type as parameter. Where applicable also mention the typed ones
that take the creator as argument since those are also more performant.
APIs deprecated here are:
* readMap(Map, ClassLoader)
* readList(List, ClassLoader)
* readHashMap(ClassLoader)
* readArrayList(ClassLoader)
* readArray(ClassLoader)
* readSparseArray(ClassLoader)
* readParcelable(ClassLoader)
* readParcelableCreator(ClassLoader)
* readSerializable()
Test: Builds
Bug: 195622897
Bug: 199275680
Bug: 205985058
Change-Id: Ic41ae13e0d965b1fd346985c77c1eecc605285b2
Added typed read API of `readMap` and `readHashMap`,
that takes extra clazz parameters check that the class written
on the wire is the same or a descendant from the one provided
as the key and value arguments.
Doing so could enhance the security of Parcel deserialization,
as it would prevent unexpected types of objects being deserialized.
More details can be found at go/safer-parcel.
Test: atest -d android.os.cts.ParcelTest
Bug: 195622897
Change-Id: Ife9d1d7277b6345a6e11856179c301339b2dc087
New methods are to write a list/array of interface objects and to read
them again.
Basically these methods are quite similar to those for IBinder objects.
But when reading IInterface objects, we need to create an array of the
exact type and need a way of converting IBinder into IInterface value.
Two functional interfaces (newArray and asInterface) are just like
while Parcelable.Creator does. We could pass "Stub" class which is
generated by the AIDL compiler and use reflection to create a typed
array instance and call `asInterface` method. But rather than relying on
reflection, passing `IMyInterface[]::new` and
`IMyInterface.Stub::asInterface` would be simple enough to use.
Bug: 205195901
Test: atest -d android.os.cts.ParcelTest
Change-Id: I275db9ebf52d3b9713fa105d81da3a1d289d96a8
Fixed javadoc formatting, namely references to methods that were typoed and displayed incorrectly in Android Studio.
Change-Id: I190eab35bc7ec6e162cb6d614b2c74523ff86c1c
After aosp/1878338, I realized Bundle.hasFileDescriptors() was accessing
mParcelledData and mMap without a lock. So, to avoid locking
there, I made mParcelledData volatile (since after mParcelledData is
null, it can never be non-null again and mMap is guaranteed to be
non-null). So, moved assignments to mParcelledData to be last wrt mMap
and mParcelledByNative to ensure visibility of those fields.
While refactoring copyInternal(), realized that method was always used
after constructing an uninitialized Bundle, so to avoid mistakes with
objects not properly initialized, I created a constructor in Bundle,
PersistableBundle & BaseBundle that does that copyInternal() did.
Bug: 195622897
Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Change-Id: I5c9337496da7ecf87f10370726099dcb247a6789
Addressing Jeff's comment on aosp/1787847 to support List<> in
Parcel.hasFileDescriptor(), also added support for Map (+ArrayMap) and
Object[] that were missing. Made the checks recursive since it's
possible to put nested containers in bundle. Since that's @hide and only
used by bundle, included Parcel as a supported type too and clarified in
the javadoc.
That allowed to clean up Bundle.hasFileDescriptors().
Bug: 195622897
Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Change-Id: I6acf358763d8f544fc6ff1a5b0c8bdff567d50be
Added typed read API of `readSerializable`, that takes
an extra Class<T> parameter to check that the class written
on the wire is the same or a descendant from the one provided
as argument.
Doing so could enhance the security of Parcel deserialization,
as it would prevent unexpected types of objects being deserialized.
More details can be found at go/safer-parcel.
Test: atest -d android.os.cts.ParcelTest
Bug: 195622897
Change-Id: I94e48ac7fe8f5d3ba4c54100cb76ce3e4aacdd09
To be used by lazy value. Now, we also remove getValueParcel() that was
copying the section of the parcel since we don't need that anymore.
Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Bug: 195622897
Change-Id: Ic8a0d1b6a268a81df7a1e56fa1e4b307a25210b6
Added typed read APIs of `readArray`, `readArrayList`,
`readParcelableArray` and `readSparseArray`.
To avoid unexpected types of objects being unparcelled,
ideally clients would use the readTypedXXX() methods that
take the parcelable creator. However, this won’t be an option
for use cases involving deserializing children objects
inherited from non-final parcelable or serializable objects.
Currently out of ~4k parcelable classes, only ~1.5k
are marked as “final” in the platform. Hence it would be
necessary to introduce new replacements that take
an extra Class<T> parameter and before deserializing
we check that the class written on the wire is the
same or a descendant from the one provided as argument.
Doing so could enhance the security of Parcel deserialization,
More details can be found at go/safer-parcel.
Test: atest -d android.os.cts.ParcelTest
Bug: 195622897
Change-Id: Iaba24c35a0c0acc77ae2d22ac77c5a90efd93329
The change in aosp/1806594 is adding a method to the binder ndk called
isHandlingTransaction, but that method behaves differently from this
method when HIDL gets involved, as getCurrentServingCall returns
HWBINDER in that case.
Test: m
Change-Id: Ie2812943d1e98e99a1c361475965a2c75214724a