commit | b0895cf4dc9a13b63d3d47aeb7b07a99cfc0bd28 | [log] [tgz] |
---|---|---|
author | Hani Kazmi <hanikazmi@google.com> | Mon Oct 17 16:59:50 2022 +0000 |
committer | Hani Kazmi <hanikazmi@google.com> | Wed Nov 23 17:33:35 2022 +0000 |
tree | a433e9398abae2a7f2bc5aaa2c0929b9c38e2d04 | |
parent | c1163024142064b8ab1ae171a931170c19174d5a [diff] |
Add compat methods for new Bundle and Intent APIs We have introduced new, safer, APIs for Parcel, Bundle and Intent in T that we want to encourage developers to use. However the APIs have a bug (b/232589966) which could hinder adoption. As such, we are adding previously planned Compat methods that developers can use in all Andorid versios, that will not use the T Apis until U where the bug is addressed. There are subtle differences in the implementations of the platform APIs, and so the behaviour of the compat methods: 1. Get Parcelable public static <T> T getParcelable(@NonNull Bundle in, @Nullable String key, @NonNull Class<T> clazz) public static <T> T getParcelableExtra(@NonNull Intent in, @Nullable String name, @NonNull Class<T> clazz) These methods match the method signature and behaviour of the post-T, type-safe APIs - return the value if it exists and is of the `clazz` type, otherwise return null. 2. Get Collection public static <T> ArrayList<T> getParcelableArrayList(@NonNull Bundle in, @Nullable String key, @NonNull Class<? extends T> clazz) public static <T> SparseArray<T> getSparseParcelableArray(@NonNull Bundle in, @Nullable String key, @NonNull Class<? extends T> clazz) public static <T> ArrayList<T> getParcelableArrayListExtra(@NonNull Intent in, @Nullable String name, @NonNull Class<? extends T>clazz) On these methods, the method signature matches the post-T APIs, but type checking is only done on U+ devices, on first deserialisation. Checking outside of this scenario requires a linear traversal of the array on each call, and so is not done for performance (see b/222087511). Initial benchmarking shows a 400x difference for large arrays. 3. Get Array public static Parcelable[] getParcelableArray(@NonNull Bundle in, @Nullable String key, @NonNull Class<?> clazz) public static Parcelable[] getParcelableArrayExtra(@NonNull Intent in, @Nullable String name, @NonNull Class<?> clazz) Due to Java generics erasure at runtime, the post-T method signature can not be safely used on pre-U devices, as the pre-T platform APIs return a Parcelable[] rather than T[], which can not be implicitely cast to a subtype even if all items conform. The cost of manually casting is large (see above). Therefore, we always return Parcelable[] on all device versions, and we only type-check on U+ devices. The ParcelCompat methods have been updated to match this behaviour. For readArray, this is a source breaking API change. But the current method signature would fail on any current devices if assigned to anything other than an Object[] - succeeding at compile time, but failing with a ClassCastException at runtime. For readParcelableArray, it has been deprecated and replaced with readParcelableArrayTyped, as updating the type signature would be a ABI breaking change for libraries. Bug: 242048899 Test: atest ParcelCompat BundleCompat IntentCompat on T and U devices Test: Check binary compatibility manually with a test library. Relnote: "Adds compatibility methods for new APIs introduced in Android 13 for Parcels, Bundles, and Intents. Note: Some ParcelCompat method signatures have been updated, and may require a source change on upgrade to confirm to the new signature." Change-Id: I57e94c6efcc674173d201205fb175cef495bcf82
Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps easier. These components help you follow best practices, free you from writing boilerplate code, and simplify complex tasks, so you can focus on the code you care about.
Jetpack comprises the androidx.*
package libraries, unbundled from the platform APIs. This means that it offers backward compatibility and is updated more frequently than the Android platform, making sure you always have access to the latest and greatest versions of the Jetpack components.
Our official AARs and JARs binaries are distributed through Google Maven.
You can learn more about using it from Android Jetpack landing page.
For contributions via GitHub, see the GitHub Contribution Guide.
Note: The contributions workflow via GitHub is currently experimental - only contributions to the following projects are being accepted at this time:
When contributing to Jetpack, follow the code review etiquette.
We are not currently accepting new modules.
Head over to the onboarding docs to learn more about getting set up and the development workflow!
Our continuous integration system builds all in progress (and potentially unstable) libraries as new changes are merged. You can manually download these AARs and JARs for your experimentation.
Before uploading your first contribution, you will need setup a password and agree to the contribution agreement:
Generate a HTTPS password: https://android-review.googlesource.com/new-password
Agree to the Google Contributor Licenses Agreement: https://android-review.googlesource.com/settings/new-agreement
AndroidX uses git to store all the binary Gradle dependencies. They are stored in prebuilts/androidx/internal
and prebuilts/androidx/external
directories in your checkout. All the dependencies in these directories are also available from google()
, jcenter()
, or mavenCentral()
. We store copies of these dependencies to have hermetic builds. You can pull in a new dependency using our importMaven tool.