Skip to content

feat: add background location permission flow in Location Sharing settings#600

Merged
torlando-tech merged 1 commit intotorlando-tech:mainfrom
MatthieuTexier:feature/background-location-permission-flow
Mar 10, 2026
Merged

feat: add background location permission flow in Location Sharing settings#600
torlando-tech merged 1 commit intotorlando-tech:mainfrom
MatthieuTexier:feature/background-location-permission-flow

Conversation

@MatthieuTexier
Copy link
Copy Markdown
Contributor

@MatthieuTexier MatthieuTexier commented Mar 5, 2026

Problem

A previous PR resolved issues with background location sending for the Group Tracker feature. However, there was no way for the user to manage the background location permission from within the app. On Android 10+, background location ("Allow all the time") requires a separate permission grant from the standard foreground permission, and the system does not provide a direct intent to open the location permission settings page for an app.

This meant:

  • Users had no visibility into whether background location was enabled
  • There was no in-app path to grant or review the "Allow all the time" permission
  • The background permission was silently requested without explaining why it was needed

Solution

Custom bottom sheet for background permission

A new BackgroundLocationPermissionBottomSheet component explains to the user why "Allow all the time" is needed (encrypted location sharing in the background) and guides them through the two-step Android permission flow. The user explicitly chooses to proceed or dismiss.

Permission status indicator in Location Sharing card

A clickable row in the Location Sharing settings card shows the current background permission state:

  • "Background location: Always" (green) — tap opens app info with a toast guiding to Permissions > Location
  • "Background location: While using" (amber) — tap shows the custom bottom sheet then the system permission dialog

The indicator refreshes automatically when returning from system settings (lifecycle ON_RESUME).

Behavior matrix

Permission state Tap on indicator Enable Group Tracker
No permission at all Foreground permission sheet Foreground sheet → background sheet → system dialog
Foreground only Background bottom sheet → system dialog Background bottom sheet → system dialog
Always (background granted) Opens app info + toast guidance Enables directly

Changes

  • New: BackgroundLocationPermissionBottomSheet.kt
  • Modified: SettingsScreen.kt — permission flow wiring + lifecycle refresh
  • Modified: LocationSharingCard.kt — clickable permission status indicator
  • Modified: LocationSharingCardTest.kt — added scrollable wrapper for viewport-sensitive tests

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR introduces a background location permission management flow into the Location Sharing settings: a new BackgroundLocationPermissionBottomSheet explains the "Allow all the time" requirement, a three-state permission indicator row in LocationSharingCard reflects current permission status, and SettingsScreen wires the full grant/refresh lifecycle. The implementation correctly handles all three permission states and refreshes on ON_RESUME when returning from system settings.

Key observations:

  • The foreground permission launcher does not explicitly update hasForegroundPermission in its callback, unlike the background launcher which immediately sets hasBackgroundPermission = granted. This creates a stale-state window between the system dialog closing and ON_RESUME firing.
  • showTelemetryBackgroundSheet is now shared between the Telemetry Collector enable flow and the new location-sharing indicator tap path. The naming and in-code comment still say "Telemetry Collector only", which is misleading and raises a maintenance risk.
  • The clickable permission indicator row in LocationSharingCard is missing a Role.Button semantic, meaning TalkBack will not announce it as interactive.
  • No new unit tests were added for the three new parameters on LocationSharingCard (hasForegroundLocationPermission, hasBackgroundLocationPermission, onBackgroundPermissionClick), leaving the three-state indicator logic untested.

Confidence Score: 3/5

  • Safe to merge with minor fixes — no data loss or security risks, but stale state window and shared sheet naming should be resolved before shipping.
  • The overall permission flow logic correctly handles all three states and the ON_RESUME refresh is solid. However, the asymmetry between foreground and background launcher state updates creates a real stale-state window where the UI can briefly display incorrect state. The showTelemetryBackgroundSheet variable conflating two flows increases maintenance risk. Missing accessibility semantics and test coverage for the new indicator feature further reduce confidence. None of these are blockers, but they should be addressed before release.
  • SettingsScreen.kt (foreground launcher state update and shared sheet naming), LocationSharingCard.kt (accessibility semantic), LocationSharingCardTest.kt (test coverage for permission indicator).

Sequence Diagram

sequenceDiagram
    participant User
    participant Indicator as Permission Indicator (LocationSharingCard)
    participant Settings as SettingsScreen
    participant FgSheet as LocationPermissionBottomSheet
    participant BgSheet as BackgroundLocationPermissionBottomSheet
    participant System as Android System Dialog

    User->>Indicator: Tap row
    Indicator->>Settings: onBackgroundPermissionClick()

    alt Background already granted
        Settings->>System: startActivity(ACTION_APPLICATION_DETAILS_SETTINGS)
        Settings-->>User: Toast("Go to Permissions > Location")
    else Foreground granted, background not granted
        Settings->>BgSheet: showTelemetryBackgroundSheet = true
        User->>BgSheet: "Continue"
        BgSheet->>System: launch(ACCESS_BACKGROUND_LOCATION)
        System-->>Settings: granted → hasBackgroundPermission = true
    else No permission at all
        Settings->>FgSheet: showTelemetryPermissionSheet = true (pendingTelemetryAction = null)
        User->>FgSheet: "Grant Location Access"
        FgSheet->>System: launch(ACCESS_FINE_LOCATION)
        System-->>Settings: granted → (hasForegroundPermission NOT set here)
        Settings->>BgSheet: showTelemetryBackgroundSheet = true
        User->>BgSheet: "Continue"
        BgSheet->>System: launch(ACCESS_BACKGROUND_LOCATION)
        System-->>Settings: granted → hasBackgroundPermission = true
    end

    Note over Settings: ON_RESUME also refreshes both<br/>hasForegroundPermission &<br/>hasBackgroundPermission
Loading

Comments Outside Diff (2)

  1. General comment

    The foreground permission launcher callback doesn't explicitly set hasForegroundPermission = true, unlike the background launcher which immediately updates hasBackgroundPermission = granted on line 137. This creates a stale-state window: when the user grants foreground permission, the callback fires and shows the background sheet before ON_RESUME updates the indicator, briefly displaying incorrect state.

    Apply the same explicit-update pattern used in the background launcher to immediately update the foreground state:

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: app/src/main/java/com/lxmf/messenger/ui/screens/SettingsScreen.kt
    Line: 144-163
    
    Comment:
    The foreground permission launcher callback doesn't explicitly set `hasForegroundPermission = true`, unlike the background launcher which immediately updates `hasBackgroundPermission = granted` on line 137. This creates a stale-state window: when the user grants foreground permission, the callback fires and shows the background sheet before ON_RESUME updates the indicator, briefly displaying incorrect state.
    
    Apply the same explicit-update pattern used in the background launcher to immediately update the foreground state:
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
  2. General comment

    The three new permission indicator parameters (hasForegroundLocationPermission, hasBackgroundLocationPermission, onBackgroundPermissionClick) are not tested. Consider adding dedicated test cases to verify the three-state indicator logic:

    • When both are false: indicator shows "Background location: Not granted" with error color, tap triggers callback
    • When foreground only: indicator shows "Background location: While using" with tertiary color
    • When background granted: indicator shows "Background location: Always" with primary color

    This ensures regressions in the indicator state logic are caught automatically.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: app/src/test/java/com/lxmf/messenger/ui/screens/settings/cards/LocationSharingCardTest.kt
    Line: 538-590
    
    Comment:
    The three new permission indicator parameters (`hasForegroundLocationPermission`, `hasBackgroundLocationPermission`, `onBackgroundPermissionClick`) are not tested. Consider adding dedicated test cases to verify the three-state indicator logic:
    
    - When both are `false`: indicator shows "Background location: Not granted" with error color, tap triggers callback
    - When foreground only: indicator shows "Background location: While using" with tertiary color
    - When background granted: indicator shows "Background location: Always" with primary color
    
    This ensures regressions in the indicator state logic are caught automatically.
    
    How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 855e704

@MatthieuTexier MatthieuTexier force-pushed the feature/background-location-permission-flow branch from beb12f0 to 22eecef Compare March 5, 2026 09:20
@sentry
Copy link
Copy Markdown
Contributor

sentry bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MatthieuTexier MatthieuTexier force-pushed the feature/background-location-permission-flow branch from 22eecef to 855e704 Compare March 5, 2026 09:26
@MatthieuTexier
Copy link
Copy Markdown
Contributor Author

@greptile

…tings

- Add BackgroundLocationPermissionBottomSheet component explaining why
  "Allow all the time" is needed and guiding the user through the
  two-step Android permission flow
- Add clickable permission status indicator in LocationSharingCard
  showing "Always" or "While using" with tap-to-change
- When not granted: show custom bottom sheet then system permission dialog
- When granted: open app info with toast guiding to Permissions > Location
- Refresh indicator on lifecycle resume (after returning from settings)
- Remove background permission flow from MapScreen (foreground only)
- Keep background permission flow only in SettingsScreen where location
  sharing context makes it relevant
@MatthieuTexier MatthieuTexier force-pushed the feature/background-location-permission-flow branch from 855e704 to 9f44725 Compare March 5, 2026 10:26
@torlando-tech torlando-tech added this to the v0.10.0 milestone Mar 7, 2026
@torlando-tech torlando-tech merged commit 88945ce into torlando-tech:main Mar 10, 2026
13 checks passed
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