Skip to content

Changes to enable Firebase cloud messaging (FCM)#191

Merged
alabiaga merged 5 commits intoandroid:mainfrom
alabiaga:fcm
Mar 4, 2026
Merged

Changes to enable Firebase cloud messaging (FCM)#191
alabiaga merged 5 commits intoandroid:mainfrom
alabiaga:fcm

Conversation

@alabiaga
Copy link
Member

@alabiaga alabiaga commented Mar 3, 2026

Add changes to integrate usage of FCM.

These initial changes demonstrate how to integrate FCM while following best practices. While Firebase provides its own quickstart-android app, this implementation focuses specifically on the interplay between FCM and the notification framework, best practices, vs basic message facilitation.

@alabiaga alabiaga requested review from ashnohe and removed request for SigmanZero, donovanfm and madebymozart March 3, 2026 20:17
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the foundational changes required to integrate Firebase Cloud Messaging (FCM) into the application. The primary goal is to enable the app to receive push notifications by setting up the necessary Firebase dependencies, configuring the Android manifest for FCM services, and implementing a custom service to process incoming messages and manage device registration tokens. This initial integration follows best practices for FCM setup, focusing on the interplay with the notification framework rather than just basic message delivery.

Highlights

  • Firebase Cloud Messaging (FCM) Integration: The application now includes initial setup for Firebase Cloud Messaging, enabling the receipt and handling of push notifications. This involves adding necessary dependencies, configuring the Android Manifest, and implementing a custom messaging service.
  • Messaging Service Implementation: A new MessagingService has been created to extend FirebaseMessagingService, providing custom logic for handling new FCM registration tokens and incoming remote messages, including both data and notification payloads.
  • FCM Initialization in MainActivity: The MainActivity now initializes FCM upon creation, fetching and logging the device's FCM registration token. This ensures the application is ready to receive messages from Firebase.
  • Dependency and Plugin Updates: The project's build.gradle.kts files have been updated to include the firebase-messaging dependency and apply the google.gms.google.services plugin. Firebase Bill of Materials (BoM) and Google GMS versions were also updated in libs.versions.toml.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/build.gradle.kts
    • Added firebase.messaging dependency to enable FCM functionalities.
  • app/src/main/AndroidManifest.xml
    • Registered MessagingService to handle Firebase messaging events.
  • app/src/main/java/com/google/android/samples/socialite/MainActivity.kt
    • Imported necessary classes for FCM integration.
    • Called initializeFcm() in onCreate() to set up FCM.
    • Added a private initializeFcm() method to fetch and log the FCM registration token.
  • app/src/main/java/com/google/android/samples/socialite/fcm/MessagingService.kt
    • Created MessagingService extending FirebaseMessagingService.
    • Overrode onNewToken to log refreshed FCM tokens.
    • Overrode onMessageReceived to log incoming data and notification payloads.
  • build.gradle.kts
    • Applied the google.gms.google.services plugin to the project.
  • gradle/libs.versions.toml
    • Updated firebaseBoM version from 33.14.0 to 34.10.0.
    • Updated googleGmsGoogleServices version from 4.4.2 to 4.4.4.
    • Added firebase-analytics and firebase-messaging library definitions.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 integrates Firebase Cloud Messaging (FCM) into the application, including necessary dependencies, AndroidManifest configuration, and basic logic for token handling and message receiving. However, it introduces a security vulnerability by logging sensitive information such as FCM registration tokens, message data payloads, and notification bodies to the system log, which can expose device identifiers and user data. It is recommended to remove these logging statements or ensure they are only active in non-production environments. Additionally, there is a suggestion in MainActivity.kt to improve the idiomatic and readability of the token retrieval logic.

} // Get new FCM registration token
val token = task.result
// Log token
Log.d("FCM", "FCM message token $token")

Choose a reason for hiding this comment

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

security-medium medium

This line logs the Firebase Cloud Messaging (FCM) registration token, which is a sensitive identifier. Logging FCM tokens can lead to unauthorized access if logs are intercepted. It is critical to remove this logging statement or ensure it only executes in debug builds. Additionally, the broader block (lines 68-78) could be simplified for more idiomatic Kotlin, making the OnCompleteListener explicit redundant and improving readability by restructuring success/failure handling.

// Token used for device targeting.
// See https://firebase.google.com/docs/cloud-messaging/android/get-started#access-fcm-registration-token
super.onNewToken(token)
Log.d("FCM", "Refreshed token: $token")

Choose a reason for hiding this comment

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

security-medium medium

The application logs the refreshed FCM registration token in the onNewToken callback. This exposes the token in the system logs, which is a security risk. It is recommended to remove this logging statement or restrict it to non-production environments.


// Handle data payload
if (remoteMessage.data.isNotEmpty()) {
Log.d("FCM", "Message data payload: ${remoteMessage.data}")

Choose a reason for hiding this comment

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

security-medium medium

The application logs the entire data payload of incoming FCM messages. This payload can contain sensitive application data or PII, which should not be exposed in system logs. It is recommended to avoid logging the entire data payload. If logging is necessary for debugging, log only non-sensitive fields or ensure logging is disabled in production.


// Handle notification payload
remoteMessage.notification?.let {
Log.d("FCM", "Message Notification Body: ${it.body}")

Choose a reason for hiding this comment

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

security-medium medium

The application logs the body of incoming FCM notifications. Notification bodies often contain sensitive user content or PII. It is recommended to remove the logging of the notification body to protect user privacy.

alabiaga added 3 commits March 3, 2026 15:52
Change-Id: I7d942068896b3b9419554e2f75079dd584167487
Change-Id: Id33b31250bdb92d02665d0cf1adf6034fa320581
Change-Id: Ia66dc2932c8e90699bd12692fe68c6a56c6ec1c3
@alabiaga alabiaga merged commit e7ec7dc into android:main Mar 4, 2026
2 checks passed
@alabiaga alabiaga deleted the fcm branch March 4, 2026 13:15
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.

2 participants