Repository navigation
Add the android.os.Parcel shim and the AuthKt facade - #86
Merged
Merged
Conversation
The repackaged Firebase classes implement Parcelable, so Timestamp, RemoteMessage, Trace and others expose writeToParcel(Parcel, int) and a CREATOR that reference android.os.Parcel, a class that was missing from the JVM classpath until now. Consumers compiling against those signatures, such as the Firebase Kotlin SDK's JVM artifacts, had to ship a placeholder of their own. The shim is a small in-memory implementation rather than a stub that throws: a parcel is a list of the values written to it, read back in the same order, so a Parcelable round-trips through writeParcelable and its CREATOR. It mirrors the Android signatures of obtain and recycle, the data position and size accessors, marshall and unmarshall, the typed write and read methods for primitives, strings, byte arrays, lists, maps, ArrayMaps, Bundles, Parcelables, Serializables and tagged values, and the exception transport. The hidden writeString8, readString8, writeArrayMap and readArrayMap are included because the ported Uri and ContentValues call them. Positions count values rather than bytes and marshall produces a Java-serialized form that only unmarshall understands, which is documented on the class; nothing crosses a process boundary on the JVM so there is no binary format to be compatible with.
There was a problem hiding this comment.
🟡 Changes recommended
Parcel serialization retains mutable object references instead of snapshots, and Uri parcelable round-trips fail because CREATOR is not exposed as a public JVM field.
2 open issues
What changed in this PR
Adds an in-memory android.os.Parcel shim so JVM consumers can compile against repackaged Firebase Parcelable APIs without supplying their own placeholder.
Changes:
- Implements typed reads and writes, Parcelable reconstruction, exception transport, and Java-based marshalling.
- Documents value-based positions and the JVM-specific serialized format.
- Adds tests for round trips, Firebase
Timestamp, exception handling, and misuse.
| File | Description |
|---|---|
src/test/kotlin/ParcelTest.kt |
Tests Parcel operations and Firebase Timestamp round trips. |
src/main/java/android/os/Parcel.java |
Provides the in-memory Parcel implementation alongside existing Android shims. |
Review effort: Balanced
The Android SDK ships a file of Kotlin extensions with each library, and the ported libraries bring theirs along in their jars: FirebaseKt, FirestoreKt, DatabaseKt, StorageKt, FunctionsKt, RemoteConfigKt and InstallationsKt. Auth is implemented here rather than ported, so its facade, com.google.firebase.auth.AuthKt, was the one missing, and the Firebase Kotlin SDK has had to ship a copy of it in its JVM artifact. Auth.kt declares the same members with the Android signatures: the Firebase.auth property and Firebase.auth(app) function returning the FirebaseAuth of the default or a given app, and the actionCodeSettings, oAuthProvider (with and without a FirebaseAuth), oAuthCredential and userProfileChangeRequest builder functions, each applying its init block to a new builder of the corresponding class.
Three fixes to the Parcel shim from review. writeSerializable stored the object itself, so a Serializable changed after it was written read back changed, and changing a read result changed later reads; the Serializable fallback of writeValue, which primitive arrays take, behaved the same. The parcel now keeps the bytes of the serialized form taken at write time, and readSerializable deserializes a fresh copy on every read. marshall used Java serialization for the whole value list and unmarshall read it back with ObjectInputStream.readObject, which runs deserialization callbacks before the result is checked to be a list, so bytes from an untrusted source could execute code through classpath types. The envelope is now a tagged byte stream written with DataOutputStream: the number of values, then each as a tag byte and its data, for the types a value in the list can have once the typed writes have flattened lists, maps, bundles and parcelables into them (null, String, int, long, float, double, byte arrays and serialized bytes). unmarshall deserializes nothing; a Serializable stays bytes until a caller asks for it with readSerializable, and malformed data is rejected with an IllegalArgumentException. marshall throws an IllegalStateException naming the type if a value it cannot carry ever reaches the list. Uri declared its CREATOR as a JvmStatic property, which the JVM sees as a getter, so writeParcelable accepted a Uri but readParcelable could not find the CREATOR field reflectively. It is a JvmField now, a public static field like Android's, and ParcelTest round-trips hierarchical and opaque Uris as well as snapshots of Serializables and the new stream.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


The repackaged Firebase classes implement Parcelable, so Timestamp, RemoteMessage, Trace and others expose
writeToParcel(Parcel, int)methods andCREATORfields whose signatures referenceandroid.os.Parcel, a class that does not exist on the JVM classpath today. Consumers compiling against those signatures, such as the Firebase Kotlin SDK's JVM artifacts for messaging and perf, have had to ship a placeholderandroid.os.Parcelof their own to get their code to compile.This adds the shim under
src/main/java/android/os, alongside Parcelable and the other framework shims. It is a small in-memory implementation rather than a stub that throws: a parcel is a list of the values written to it, read back in the same order, so a Parcelable round-trips throughwriteParcelableand itsCREATOR. It mirrors the Android signatures ofobtainandrecycle, the data position and size accessors,marshallandunmarshall, the typed write and read methods for primitives, strings, byte arrays, lists, maps, ArrayMaps, Bundles, Parcelables, Serializables and tagged values, and the exception transport. The hiddenwriteString8,readString8,writeArrayMapandreadArrayMapare included because the portedUriandContentValuesalready call them; with the shim present they now compile against it instead of the Robolectric compile-only jar.Positions count values rather than bytes and
marshallproduces a Java-serialized form that onlyunmarshallunderstands, which the class documentation spells out; nothing crosses a process boundary on the JVM, so there is no binary format to stay compatible with. AParcelTestcovers the round trips, including one ofcom.google.firebase.Timestampthrough itsCREATOR.The branch also adds the Kotlin extensions facade of the Android firebase-auth library,
com.google.firebase.auth.AuthKt. The ported libraries bring their facades along in their jars (FirebaseKt, FirestoreKt, DatabaseKt, StorageKt, FunctionsKt, RemoteConfigKt, InstallationsKt), but Auth is implemented here rather than ported, so its facade was the one missing and the Firebase Kotlin SDK has had to ship a copy in its JVM artifact.Auth.ktdeclares the same members with the Android signatures: theFirebase.authproperty andFirebase.auth(app)function, and theactionCodeSettings,oAuthProvider(with and without aFirebaseAuth),oAuthCredentialanduserProfileChangeRequestbuilder functions, each applying its init block to a new builder of the corresponding class. AFirebaseAuthKtTestchecks the extensions return the app'sFirebaseAuthand that each builder function applies its init.