Skip to content

Listen for passive locations#127

Merged
jackpf merged 6 commits intomainfrom
passive-listener
Jan 24, 2026
Merged

Listen for passive locations#127
jackpf merged 6 commits intomainfrom
passive-listener

Conversation

@jackpf
Copy link
Owner

@jackpf jackpf commented Jan 24, 2026

Handles #114

Listening to passive locations gives us some "free" (negligible battery drain) locations.

TODO

  • Add previous run timestamp check for regular runs

@jackpf jackpf added the client label Jan 24, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jackpf, 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 enhances the application's location tracking capabilities by incorporating passive location updates. By listening for system-generated location changes, the app can acquire location data more efficiently and with less impact on battery life. The changes involve introducing new components for managing execution and passive listening, and adapting existing services to integrate these new location sources seamlessly.

Highlights

  • Passive Location Listening: Introduced a new PassiveLocationListener to leverage Android's PASSIVE_PROVIDER for receiving location updates with minimal battery consumption, addressing issue Piggyback on other GPS requests #114.
  • Asynchronous Execution Management: Added a new AppExecutors class to centralize and manage background and main thread execution, improving code organization and thread safety.
  • BeaconService Refactoring: The BeaconService has been updated to integrate the new passive location listener, handle passive location intents, and delegate beacon tasks to a refactored BeaconTask.
  • BeaconTask Adaptability: The BeaconTask now includes a passiveRun method, allowing it to process location data received from passive listeners without initiating a new location request.
  • IDE Configuration Updates: Several .idea configuration files for the server module were updated, including JDK version, sbt settings, and Scala compiler profiles, likely reflecting development environment changes.
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 introduces a valuable optimization by listening for passive location updates, which should improve battery efficiency. The code is generally well-structured, including a nice refactoring in BeaconTask to handle different execution flows. I've identified a few areas for improvement related to Android service lifecycle management, exception handling, and the use of modern Android APIs. My detailed comments below address these points to enhance the robustness and maintainability of the code.

@jackpf
Copy link
Owner Author

jackpf commented Jan 24, 2026

/gemini review

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 introduces passive location listening to capture location updates with minimal battery impact. The implementation includes a new PassiveLocationListener and refactors BeaconTask to handle both active and passive location updates. The changes are well-structured.

I've found a critical issue where the service could crash if BeaconTask fails to initialize, and a medium-severity issue regarding unsafe retrieval of Location data from an Intent, which could cause problems on newer Android versions. Please see my detailed comments for suggestions on how to fix these.

@jackpf
Copy link
Owner Author

jackpf commented Jan 24, 2026

/gemini review

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 introduces passive location listening, which is a great way to get location updates with minimal battery impact. The implementation is well-structured, introducing a PassiveLocationListener and refactoring BeaconTask to handle different types of location runs (active vs. passive). The changes to use milliseconds for time intervals in ConfigRepository are also a good improvement for consistency.

I've added a few suggestions to improve the code further. One is a high-severity issue regarding the correct use of PendingIntent flags for different Android versions, and others are medium-severity suggestions for cleaner code when handling intents and simplifying logic.

Comment on lines +109 to +110
long millisToNextRun = Math.max(configRepository.getUpdateIntervalMillis() - millisSinceLastRun, 0);
return Math.min(configRepository.getUpdateIntervalMillis(), millisToNextRun);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The use of Math.min here is redundant. millisToNextRun is calculated as Math.max(configRepository.getUpdateIntervalMillis() - millisSinceLastRun, 0). Since millisSinceLastRun is non-negative, millisToNextRun will always be less than or equal to configRepository.getUpdateIntervalMillis(). Therefore, the outer Math.min call can be removed to simplify the code.

Suggested change
long millisToNextRun = Math.max(configRepository.getUpdateIntervalMillis() - millisSinceLastRun, 0);
return Math.min(configRepository.getUpdateIntervalMillis(), millisToNextRun);
return Math.max(configRepository.getUpdateIntervalMillis() - millisSinceLastRun, 0);


private void handlePassiveLocationAction(Intent intent) {
if (intent.hasExtra(LocationManager.KEY_LOCATION_CHANGED)) {
Location location = (Location) intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Retrieving the Location object can be simplified by using intent.getParcelableExtra(). This avoids the need for getExtras() and an explicit cast, making the code cleaner and more direct.

Suggested change
Location location = (Location) intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED);
Location location = intent.getParcelableExtra(LocationManager.KEY_LOCATION_CHANGED);

@jackpf jackpf merged commit 9c6bab8 into main Jan 24, 2026
4 checks passed
@jackpf jackpf deleted the passive-listener branch January 24, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant