Skip to content

Conversation

@Syedovaiss
Copy link

What I have done and why

Fix #1982: Align NetworkRequest and improve transport check readability

Changes

  1. Added NET_CAPABILITY_VALIDATED and transport type checks to ConnectivityManagerNetworkMonitor:

    • Ensures the network is actually validated and provides real internet connectivity.
    • Only supports Wi-Fi, Cellular, and Ethernet transports to avoid false positives from other transports like VPN or peer-to-peer networks.
  2. Updated NetworkRequest in registerNetworkCallback:

    • Constrained to the same transports as isCurrentlyConnected() for consistency.
    • Prevents inconsistent flow emissions when network types mismatch.
  3. Refactored transport check logic:

    • Created a hasSupportedTransport() helper.
    • Uses a set and any() for cleaner, more maintainable code.
  4. Added distinctUntilChanged() to the flow:

    • Prevents duplicate emissions when connectivity state hasn't actually changed.
    • Reduces unnecessary recompositions or downstream processing.

Motivation

  • Previously, isCurrentlyConnected() and NetworkRequest used in the callback could disagree on connectivity state.
  • This could lead to emitting true for networks that are not actually usable for internet access.
  • Improving readability and maintainability helps future developers adjust supported transport types easily.

Additional Context

…dated internet, transport checks, and distinctUntilChanged()
@Syedovaiss Syedovaiss requested a review from dturner as a code owner January 15, 2026 08:25
@gemini-code-assist
Copy link

Summary of Changes

Hello @Syedovaiss, 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 significantly enhances the reliability and accuracy of network connectivity monitoring within the application. By integrating NET_CAPABILITY_VALIDATED and restricting checks to specific, validated transport types, it ensures that the reported network status truly reflects usable internet access. These changes also improve code consistency and optimize flow emissions, leading to a more robust and efficient network monitoring solution.

Highlights

  • Network Capability Validation: Incorporated NET_CAPABILITY_VALIDATED and specific transport type checks (Wi-Fi, Cellular, Ethernet) into ConnectivityManagerNetworkMonitor to ensure reported networks provide actual internet connectivity and avoid false positives.
  • NetworkRequest Consistency: Modified NetworkRequest in registerNetworkCallback to align with the isCurrentlyConnected() logic, using the same transport types to prevent inconsistent flow emissions.
  • Code Readability & Maintainability: Refactored transport checking logic into a dedicated hasSupportedTransport() helper function, improving code clarity and making future adjustments easier.
  • Flow Optimization: Added distinctUntilChanged() to the isOnline flow to prevent redundant emissions when the connectivity state remains unchanged, reducing unnecessary processing.

🧠 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.

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 significantly improves the ConnectivityManagerNetworkMonitor by incorporating NET_CAPABILITY_VALIDATED and filtering for specific transport types (Wi-Fi, Cellular, Ethernet). This ensures that the reported network connectivity is truly usable for internet access, addressing previous inconsistencies. The refactoring of isCurrentlyConnected() into smaller, focused helper functions enhances readability and maintainability. Additionally, the introduction of distinctUntilChanged() optimizes the flow by preventing redundant emissions. Overall, these changes make the network monitoring more robust and accurate.

@Syedovaiss Syedovaiss changed the title Fix android#1982: Improve ConnectivityManagerNetworkMonitor with vali… Fix android#1982: Improved ConnectivityManagerNetworkMonitor Jan 15, 2026
@Syedovaiss
Copy link
Author

@dturner would appreciate your review when available.

Key intent here was to ensure:

  • validated internet connectivity only
  • consistent logic between NetworkRequest and isCurrentlyConnected()
  • reduced duplicate flow emissions

Open to any feedback or alternative approaches.

@anhtuannd
Copy link

If we only need to validate for Internet connection, hasSupportedTransport() check seems to be redundant.

@Syedovaiss
Copy link
Author

If we only need to validate for Internet connection, hasSupportedTransport() check seems to be redundant.

Thanks for the feedback — good point.

NET_CAPABILITY_VALIDATED does ensure that the network has verified internet access, but the additional hasSupportedTransport() check was added intentionally to align with the scope of connectivity this app considers “online.”

In practice, a network can be validated but still be backed by transports such as VPN or other specialized links. While these may technically provide internet access, they can produce connectivity signals that differ from what the app expects for general online behavior.

The transport filter ensures:
• Consistency between isCurrentlyConnected() and the NetworkRequest
• Avoidance of false positives from validated but non-standard transports
• Clear, explicit definition of supported uplink types (Wi-Fi, Cellular, Ethernet)

That said, I’m happy to simplify this if the project prefers to rely solely on NET_CAPABILITY_VALIDATED and treat all validated transports as acceptable. Please let me know which direction you’d prefer, and I can update the implementation accordingly.

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.

[FR]: Add NET_CAPABILITY_VALIDATED, Transport Type Check , distinctUntilChanged() to the Flow in ConnectivityManagerNetworkMonitor.kt

2 participants