Implement foreground service for location sharing to comply with Google Play requirements
Implement foreground notification for location sharing - COMPLETED
- [x] Review current location sharing implementation
- [x] Remove ACCESS_BACKGROUND_LOCATION permission request
- [x] Update LocationBackgroundService to show foreground notification
- [x] Add location notification channel to NotificationCenter
- [x] Update strings for location notification
- [x] Add FOREGROUND_SERVICE_LOCATION permission for Android 14+
- [x] Update DcLocationManager to start service as foreground service
- [x] Fix all code review feedback
- [x] Add FLAG_IMMUTABLE to IntentUtils
- [x] Ensure thread-safe foreground service initialization
- [x] Fix service initialization order
- [x] Ensure foreground requirements met even on error
- [x] Fix PermissionsBuilder method chaining compilation error
- [x] Fix foreground service for Android 14+ using ServiceCompat.startForeground with foregroundServiceType
- [x] Add NETWORK_PROVIDER fallback for better location coverage
- [x] Use LocationManagerCompat with LocationRequestCompat for proper location updates on modern Android
- [x] Fix LocationListenerCompat compilation error
- [x] Code review passed
- [x] Ready for testing and deployment
Summary of Changes
This PR restores location sharing functionality by implementing a foreground service with notification instead of requesting background location access, as per Google's current requirements.
Key Changes:
-
Removed
ACCESS_BACKGROUND_LOCATIONpermission request (Android Q+) -
Added
FOREGROUND_SERVICE_LOCATIONpermission (Android 14+) -
Updated
LocationBackgroundServiceto display a persistent foreground notification -
Added notification channel
CH_LOCATIONfor location sharing with low importance -
Updated
DcLocationManagerto start the service usingstartForegroundService() - Simplified permission rationale message (removed mention of background access)
- Added notification strings for location sharing
-
Implemented thread-safe foreground service lifecycle with
AtomicBoolean - Fixed service binding checks to use OR logic
-
Added proper cleanup with
stopForeground()inonDestroy() -
Added
FLAG_IMMUTABLE()helper toIntentUtils - Fixed PermissionsBuilder method chaining (request() and execute() must be separate calls)
-
Fixed Android 14+ foreground service using
ServiceCompat.startForeground()withFOREGROUND_SERVICE_TYPE_LOCATION - Added NETWORK_PROVIDER as fallback for better location coverage when GPS is unavailable
-
Migrated to
LocationManagerCompatandLocationRequestCompatfor better compatibility with modern Android - Added provider availability check before requesting location updates
-
Changed listener to implement
LocationListenerCompatfor compatibility withLocationManagerCompatAPI
Fixes ArcaneChat/android#70
Original prompt
This section details on the original issue you should resolve
<issue_title>allow to share location again</issue_title> <issue_description>in the past it was possible to share location via "location streaming" option in chat, but google now recommends to have permanent foreground notification while the location is being streamed instead of use the "background location access", implement this so location data is accessed properly</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes ArcaneChat/android#70
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.