Skip to content

Comments

Background service support on Android#215

Merged
fotiDim merged 2 commits intomainfrom
foreground-task-support
Feb 4, 2026
Merged

Background service support on Android#215
fotiDim merged 2 commits intomainfrom
foreground-task-support

Conversation

@fotiDim
Copy link
Contributor

@fotiDim fotiDim commented Feb 2, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fotiDim, 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 Android implementation by introducing robust support for Bluetooth Low Energy (BLE) scanning within background services. The core change involves refactoring the PermissionHandler to be ActivityAware, enabling it to manage permission requests more intelligently in scenarios where an Activity might not be present, such as during a ForegroundTask. This ensures that background BLE operations can proceed seamlessly if permissions are pre-granted, while providing clear error feedback if permissions are required but cannot be interactively requested. The changes are reflected in the changelog and detailed in the README.md with best practices for developers.

Highlights

  • Android Background BLE Scanning: Enabled support for BLE scanning from background services (e.g., ForegroundTask) on Android, allowing continuous operation even when the app is not in the foreground.
  • Activity-Aware Permission Handling: The PermissionHandler on Android is now activity-aware. It can succeed silently if permissions are already granted when no activity is available, or fail gracefully if permissions are needed but cannot be interactively requested.

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

@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 effectively refactors the Android permission handling to support background services by making the PermissionHandler activity-aware. The changes are well-structured and correctly delegate activity lifecycle events. However, I've identified a couple of edge cases where pending operations (permission requests, Bluetooth enable/disable) are not correctly cancelled when the activity is detached, which could lead to timeouts. I've provided suggestions to make the implementation more robust against activity lifecycle changes.

- Enhanced `PermissionHandler` to be activity-aware, allowing silent success for already granted permissions when no activity is available.
- Updated README with best practices for requesting permissions in foreground before background operations.
@fotiDim fotiDim force-pushed the foreground-task-support branch from 8704568 to 506f087 Compare February 2, 2026 15:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for BLE scanning from background services (such as flutter_foreground_task) on Android by making the PermissionHandler activity-aware. Previously, the PermissionHandler required an Activity to function, which prevented BLE operations in background contexts.

Changes:

  • Refactored PermissionHandler to support optional activity attachment, enabling it to work in background service contexts
  • Updated permission request logic to succeed silently when permissions are already granted and no activity is available
  • Added comprehensive documentation for background scanning use cases and best practices

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/src/universal_ble_pigeon/universal_ble_pigeon_channel.dart Updated comment to document the new Android permission behavior for background contexts
android/src/main/kotlin/com/navideck/universal_ble/UniversalBlePlugin.kt Moved PermissionHandler initialization to onAttachedToEngine and added activity attachment/detachment lifecycle management
android/src/main/kotlin/com/navideck/universal_ble/PermissionHandler.kt Refactored to accept activity as an attachable/detachable reference rather than constructor parameter, with fallback logic for background contexts
README.md Added comprehensive documentation section explaining background scanning support, limitations, and best practices
CHANGELOG.md Added entry describing the new background service support feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fotiDim fotiDim merged commit ceda9a3 into main Feb 4, 2026
8 checks passed
@fotiDim fotiDim deleted the foreground-task-support branch February 4, 2026 18:12
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.

1 participant