package com.cctv.kioskboot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;

public class CctvBootReceiver extends BroadcastReceiver {

    private static final String TAG = "CctvBootReceiver";

    static void startKiosk(Context context) {
        Intent svc = new Intent(context, CctvBootService.class);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(svc);
        } else {
            context.startService(svc);
        }
        Log.i(TAG, "CctvBootService iniciado");
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null || intent.getAction() == null) return;
        String action = intent.getAction();
        if (Intent.ACTION_BOOT_COMPLETED.equals(action)
                || "android.intent.action.QUICKBOOT_POWERON".equals(action)
                || "com.htc.intent.action.QUICKBOOT_POWERON".equals(action)) {
            Log.i(TAG, "Boot completado");
            startKiosk(context);
        }
    }
}
