Skip to content

refactor(messaging, android): use typed Bundle access for background metadata - #19011

Open
HsukqiLee wants to merge 2 commits into
firebase:mainfrom
TsinbeiLabs:fix/messaging-typed-manifest-metadata
Open

HsukqiLee wants to merge 2 commits into
firebase:mainfrom
TsinbeiLabs:fix/messaging-typed-manifest-metadata

Conversation

@HsukqiLee

@HsukqiLee HsukqiLee commented Nov 25, 2026 •

Copy link
Copy Markdown

Description

Read background-handler manifest metadata with AndroidX BundleCompat.getSerializable instead of deprecated BaseBundle.get(String). The accepted Boolean/String values and absent/invalid/true/false behavior are unchanged.

Use the AndroidX Core dependency already supplied by Flutter embedding. The receiver-level manifest scenarios cover API 28 and 34, the two branches used by Core 1.13.1. No token API changes are included; #18780 handles that migration.

Validation

  • Tested a5ee59f with the checked-out firebase_core and firebase_messaging as path dependencies in a generated Flutter Android app (Flutter 3.51.0-1.0.pre-31, framework fffd8c22ae, Java 17). Native plugin compile SDK was set to 36 by an external Gradle init script for compatibility with Robolectric 4.14.1.
  • :firebase_messaging:dependencyInsight --dependency androidx.core:core --configuration debugCompileClasspath confirms Core 1.13.1 is provided by io.flutter:flutter_embedding_debug, without the removed declaration.
  • :firebase_messaging:compileDebugJavaWithJavac and :firebase_messaging:testDebugUnitTest passed: 40 tests, 0 failures, 0 errors, 0 skipped across all five Android suites. The three removed executions are the duplicate API 33 manifest scenarios. Gradle result: BUILD SUCCESSFUL in 3m 4s.
  • This validates compilation and native unit tests under a real Flutter dependency graph; no device/Firebase-service integration run was performed.

AI assistance: OpenCode (gpt-6.1-sol); validation commands were executed by the agent.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Android implementation of 'firebase_messaging' to use 'BundleCompat.getSerializable' for safely retrieving metadata from the manifest, improving compatibility across different Android SDK versions. To support this change, the 'androidx.core:core:1.13.1' dependency was added to 'build.gradle', and several test cases in 'FlutterFirebaseMessagingBackgroundGateTest.java' were updated with '@config(sdk = {28, 33, 34})' annotations. There are no review comments, and I have no additional feedback to provide.

@SelaseKay SelaseKay changed the title fix(messaging): use typed Bundle access for background metadata refactor(messaging, android): use typed Bundle access for background metadata Nov 27, 2026
implementation 'com.google.firebase:firebase-messaging'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
implementation 'androidx.annotation:annotation:1.7.1'
implementation 'androidx.core:core:1.13.1'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this in a Flutter app (3.44.6, the plugin needs >=3.44.0) with the plugin as a path dependency. With this line removed, :firebase_messaging:compileDebugJavaWithJavac still succeeds. dependencyInsight shows androidx.core:core:1.13.1 coming from io.flutter:flutter_embedding_debug, so BundleCompat is already on the classpath. The 1.2.0 resolution only happens in a Gradle host that doesn't have the Flutter embedding.

The plugin also already imports androidx.core on main (ActivityCompat, NotificationManagerCompat) without declaring it. So I think we can drop this line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, you're right: the earlier isolated Gradle host used the Flutter JAR directly and omitted the embedding's Maven dependency graph. Removed the explicit Core dependency in a5ee59f and rechecked with the local plugins as path dependencies in a real Flutter Android app (3.51.0-1.0.pre-31, framework fffd8c22ae). dependencyInsight confirms Core 1.13.1 comes from io.flutter:flutter_embedding_debug. Java compilation and all 40 Android unit tests pass (compile SDK 36). Updated the description to reflect this validation.

AI assistance: OpenCode (gpt-6.1-sol); commands executed by the agent.

}

@Test
@Config(sdk = {28, 33, 34})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in core 1.13.1, BundleCompat.getSerializable only uses the typed platform getter from API 34, so 33 goes through the same branch as 28. {28, 34} covers both sides (same for the two tests below).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated all three manifest scenarios to {28, 34} in a5ee59f to cover the two BundleCompat branches without repeating API 33. All 40 remaining Android unit-test executions passed, including these scenarios on both API levels.

AI assistance: OpenCode (gpt-6.1-sol).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants