package com.obdwidgets.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.obdwidgets.service.OBDService

/**
 * Boot Receiver für automatischen Start des OBD Service
 */
class BootReceiver : BroadcastReceiver() {
    
    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
            val prefs = context.getSharedPreferences("obd_prefs", Context.MODE_PRIVATE)
            if (prefs.getBoolean("auto_connect", true)) {
                val serviceIntent = Intent(context, OBDService::class.java)
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                    context.startForegroundService(serviceIntent)
                } else {
                    context.startService(serviceIntent)
                }
            }
        }
    }
}
