Have you considered scenarios for when a ForegroundService crashes?
It looks like for the restart you need an Activity in the foreground. I would like to make my ForegroundService restart if there is an exception. I will experiment with this anyway, but maybe someone has some suggestions.
AFAIK you can inject your own behaviour through DI with the provided interfaces. I do not fully understand your use case, but if you have any improvement suggestions Im open/looking forward to a PR :)
To make it more clear. My app uses a ForgroundService to be able to constantly run in the backgorund. It is called ForegroundService because there is an ongoing notification displayed all the time. So most of the time there is no Activity associated with my app. But it might still crash when running without an activity. And I still want it to restart.
I will experiment with it and come back with a PR if there is a solution.