Skip to content

How to fix FGS Security Exception crash in Foreground service (including Android Auto CarAppService) #10

@shahbazhashmi

Description

@shahbazhashmi

I am facing a FGS Security Exception for few services in my Android app. Although I am not able reproduce it but the crash get logged for some users on crashlytics.

My Foreground service is of type location, and I do give all required permissions before calling startForeground. But my app does not ask for "always allow" location permission.

I found that as per the latest Android docs, A foregroundService with type location cause this crash when launched in background. That seems correct. https://developer.android.com/develop/background-work/services/fgs/restrictions-bg-start#wiu-restrictions

I tried to reproduce this crash by starting the service when the app goes to background (using ProcessLifecycleOwner in the application class). And I am able to get the same exception. Hence to me the fix looked easy (is just to add the foreground check). But then I realised that for Android Auto same service is being used, and this foreground check always return false on Android auto when the main app on phone is not opened.

Additionally I get same exception for CarAppService too which I have for Android Auto app only. I already have a foreground check based on Session.lifecycle for Android Auto specific CarAppService but this crash is still happening.

So the question is how to deal with this situation efficiently for AA CarAppService and other foreground services I have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions