Permissions & Battery Optimization
Building an enterprise Android telematics application requires handling modern Android background execution constraints, Doze mode restrictions, and strict location permission models introduced in Android 10, 11, 12, 13, and 14+.
🔒 1. Android Permission Flow
To track speed accurately, client applications must request runtime permissions according to the user's Android OS version.
Dynamic Runtime Permission Decision Tree
How client apps navigate Fine Location, Background Access, and Notification permissions
Fine Location
ACCESS_FINE_LOCATIONRequired for raw GPS satellite velocity fixes with ±3m confidence.
Notifications (Android 13+)
POST_NOTIFICATIONSRequired for persistent speed badge and foreground service alert channels.
Foreground Service (Android 14+)
FOREGROUND_SERVICE_LOCATIONMandated manifest type for real-time telematics tracking in Google Play.
Background Location
ACCESS_BACKGROUND_LOCATIONDirect driver to system settings for "Allow all the time" if un-docked tracking is needed.
Activity Recognition
ACTIVITY_RECOGNITIONRequired by speed-autostart to detect IN_VEHICLE transitions for battery efficiency.
System Alert Window
SYSTEM_ALERT_WINDOWRequired by speed-overlay to draw the floating PiP widget over other apps.
Required Permissions by Android Version
| Android Version | Permission | Why It's Needed |
|---|---|---|
| All Versions | android.permission.ACCESS_FINE_LOCATION | Required to query GPS satellite velocity fixes with sub-meter accuracy. |
| Android 10+ (API 29) | android.permission.ACCESS_BACKGROUND_LOCATION | Allows location querying when the app is completely in the background without UI focus. |
| Android 10+ (API 29) | android.permission.ACTIVITY_RECOGNITION | (Optional) Required by :speed-autostart to detect IN_VEHICLE transitions. |
| All Versions | android.permission.SYSTEM_ALERT_WINDOW | (Optional) Required by :speed-overlay to draw the floating PiP widget over other apps. |
| Android 13+ (API 33) | android.permission.POST_NOTIFICATIONS | Required to display persistent foreground service notifications with speed icons. |
| Android 14+ (API 34) | android.permission.FOREGROUND_SERVICE_LOCATION | Required to declare the specific foreground service type in Google Play Store reviews. |
📱 2. Implementing the Request Flow
Requesting Foreground Permissions in Jetpack Compose
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@Composable
fun RequestTelematicsPermissions(onGranted: () -> Unit) {
val permissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->
val fineLocation = permissions[android.Manifest.permission.ACCESS_FINE_LOCATION] == true
val postNotif = if (android.os.Build.VERSION.SDK_INT >= 33) {
permissions[android.Manifest.permission.POST_NOTIFICATIONS] == true
} else true
if (fineLocation && postNotif) {
onGranted()
}
}
LaunchedEffect(Unit) {
val permissions = mutableListOf(
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION
)
if (android.os.Build.VERSION.SDK_INT >= 29) {
permissions.add(android.Manifest.permission.ACTIVITY_RECOGNITION)
}
if (android.os.Build.VERSION.SDK_INT >= 33) {
permissions.add(android.Manifest.permission.POST_NOTIFICATIONS)
}
permissionLauncher.launch(permissions.toTypedArray())
}
}⚡ 3. Battery Optimization & Doze Mode
When an Android device enters Doze Mode (stationary with screen turned off), the operating system throttles network and CPU wakelocks. For delivery and long-haul fleet drivers, telematics must continue uninterrupted.
Requesting Battery Optimization Exemption
To ensure continuous background GPS collection on long shifts, request exemption from battery optimizations:
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.PowerManager
import android.provider.Settings
fun requestIgnoreBatteryOptimizations(context: Context) {
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
val packageName = context.packageName
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
data = Uri.parse("package:$packageName")
}
context.startActivity(intent)
}
}🛑 4. OEM Aggressive Background Killers
Certain Android device manufacturers (notably Samsung One UI, Xiaomi MIUI/HyperOS, Huawei, and Oppo ColorOS) implement aggressive background task killers that can kill persistent services despite active notifications.
Recommendations for Enterprise Fleet Deployments
- AutoStartManager (Recommended Workaround): By using the
:speed-autostartmodule, you can bypass aggressive OEM killers entirely. TheIN_VEHICLEactivity transition leverages the low-power Google Play Services sensor hub, which OEMs typically exempt from termination. This avoids the need for constant background CPU wakeups. - Deep Sleeping Apps (Samsung): Ensure your fleet application is added to the "Never sleeping apps" whitelist.
- Screen Off Throttling: Use the SDK's built-in
updateWhileScreenOffsetting:kotlin// In SpeedAssistant configuration: SpeedAssistant.with(context, "YOUR_JWT_LICENSE").preferences.setUpdateWhileScreenOff(true)
🛡️ 5. Privacy & Zero-PII Compliance
The Veg Sahayyak SDK is engineered with a Privacy-First architecture:
- Zero Lat/Lon Telemetry Storage: The SDK computes velocity vectors locally on device and immediately discards raw latitude and longitude coordinates.
- No Third-Party Analytics Tracking:
speed-corecontains zero telemetry trackers, Firebase dependencies, or ad networks. - GDPR & CCPA Compliant: Since no personally identifiable information (PII) is transmitted, integration meets strict enterprise compliance guidelines.