ForegroundStartPolicy
Decides whether starting MeshService as a foreground service is legal, and which foreground service types it may claim.
Deliberately pure: every platform fact arrives as a parameter so the rules can be unit tested without a device. The Android probes that supply those facts live in ForegroundStartContext.kt.
Two independent platform gates are modelled here.
Background-start restriction (Android 12+).
startForegroundService()throwsForegroundServiceStartNotAllowedExceptionunless the caller is in an allowlisted context. Covered by isForegroundStartAllowed.While-in-use type restriction (Android 14+). A
locationforeground service cannot be started from the background withoutACCESS_BACKGROUND_LOCATION, which this app does not declare; attempting it throwsSecurityException.connectedDevicecarries no such restriction. Covered by foregroundServiceType.
Functions
The fallback type used when foregroundServiceType is still rejected at runtime. Always safe to claim when the service may run at all.
Returns the foreground service type bitmask to pass to startForeground().
Returns true when Context.startForegroundService() is expected to succeed for trigger.