GrantAndServiceHandler
A unified handler that orchestrates both OS permission requests and hardware service enablement (e.g., GPS, Bluetooth).
In production apps, features like Location often require two steps:
Requesting the OS permission.
Ensuring the GPS hardware is actually turned ON.
GrantAndServiceHandler automates this entire sequence into a single observable flow.
Behavior Flow
Check Permission → If GrantStatus.GRANTED, move to step 2.
Check Service → If ServiceStatus.ENABLED, execute
onReady.Otherwise, show appropriate dialogs for each missing piece.
Usage Example
val locationHandler = GrantAndServiceHandler(
grantManager = grantManager,
serviceManager = serviceManager,
grant = AppGrant.LOCATION,
serviceType = ServiceType.LOCATION_GPS,
scope = viewModelScope
)
fun startFeature() {
locationHandler.request(
rationaleMessage = "Location is needed to track your run.",
serviceSettingsMessage = "Please turn on GPS to start tracking."
) {
// Both Permission and GPS are now active!
sensor.start()
}
}Constructors
Functions
Confirms and opens system settings for the permission.
Confirms the rationale and proceeds to request the OS permission.
Confirms and opens system settings for the hardware service.
Re-checks both permission and hardware service status. If both are ready and there is a pending onReadyCallback, it will be executed.