GrantAndServiceHandler

class GrantAndServiceHandler(grantManager: GrantManager, serviceManager: ServiceManager, grant: GrantPermission, serviceType: ServiceType, scope: CoroutineScope, savedStateDelegate: SavedStateDelegate = NoOpSavedStateDelegate(), eventListener: GrantEventListener? = null)

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:

  1. Requesting the OS permission.

  2. Ensuring the GPS hardware is actually turned ON.

GrantAndServiceHandler automates this entire sequence into a single observable flow.

Behavior Flow

  1. Check Permission → If GrantStatus.GRANTED, move to step 2.

  2. Check Service → If ServiceStatus.ENABLED, execute onReady.

  3. 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

Link copied to clipboard
constructor(grantManager: GrantManager, serviceManager: ServiceManager, grant: GrantPermission, serviceType: ServiceType, scope: CoroutineScope, savedStateDelegate: SavedStateDelegate = NoOpSavedStateDelegate(), eventListener: GrantEventListener? = null)

Properties

Link copied to clipboard

Observable state for driving the UI.

Functions

Link copied to clipboard
fun onDismiss()

Dismisses the current dialog and cancels the flow.

Link copied to clipboard

Confirms and opens system settings for the permission.

Link copied to clipboard

Confirms the rationale and proceeds to request the OS permission.

Link copied to clipboard

Confirms and opens system settings for the hardware service.

Link copied to clipboard

Re-checks both permission and hardware service status. If both are ready and there is a pending onReadyCallback, it will be executed.

Link copied to clipboard
fun request(rationaleMessage: String? = null, permissionSettingsMessage: String? = null, serviceSettingsMessage: String? = null, onReady: () -> Unit)

Initiates the unified request flow.