Skip to content

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.

Android 10 - 15 Permission Strategy

Dynamic Runtime Permission Decision Tree

How client apps navigate Fine Location, Background Access, and Notification permissions

Required Core
📍
Fine Location
ACCESS_FINE_LOCATION

Required for raw GPS satellite velocity fixes with ±3m confidence.

→
Required API 33+
🔔
Notifications (Android 13+)
POST_NOTIFICATIONS

Required for persistent speed badge and foreground service alert channels.

→
Required API 34+
🚗
Foreground Service (Android 14+)
FOREGROUND_SERVICE_LOCATION

Mandated manifest type for real-time telematics tracking in Google Play.

→
Optional Fleet
🌐
Background Location
ACCESS_BACKGROUND_LOCATION

Direct driver to system settings for "Allow all the time" if un-docked tracking is needed.

Optional Autostart
🏃
Activity Recognition
ACTIVITY_RECOGNITION

Required by speed-autostart to detect IN_VEHICLE transitions for battery efficiency.

Optional PIP
🪟
System Alert Window
SYSTEM_ALERT_WINDOW

Required by speed-overlay to draw the floating PiP widget over other apps.

Required Permissions by Android Version ​

Android VersionPermissionWhy It's Needed
All Versionsandroid.permission.ACCESS_FINE_LOCATIONRequired to query GPS satellite velocity fixes with sub-meter accuracy.
Android 10+ (API 29)android.permission.ACCESS_BACKGROUND_LOCATIONAllows 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 Versionsandroid.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_NOTIFICATIONSRequired to display persistent foreground service notifications with speed icons.
Android 14+ (API 34)android.permission.FOREGROUND_SERVICE_LOCATIONRequired to declare the specific foreground service type in Google Play Store reviews.

📱 2. Implementing the Request Flow ​

Requesting Foreground Permissions in Jetpack Compose ​

kotlin
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:

kotlin
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 ​

  1. AutoStartManager (Recommended Workaround): By using the :speed-autostart module, you can bypass aggressive OEM killers entirely. The IN_VEHICLE activity 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.
  2. Deep Sleeping Apps (Samsung): Ensure your fleet application is added to the "Never sleeping apps" whitelist.
  3. Screen Off Throttling: Use the SDK's built-in updateWhileScreenOff setting:
    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-core contains 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.

Released under Commercial Enterprise License. Follow us on LinkedIn | Contact Us.