package com.smartdevicelink.sdlstreaming.sdl;

import android.content.Context;
import android.content.Intent;

import com.smartdevicelink.transport.SdlBroadcastReceiver;
import com.smartdevicelink.transport.SdlRouterService;

public class SdlReceiver extends SdlBroadcastReceiver {
    public SdlReceiver() {
    }


    @Override
    public Class<? extends SdlRouterService> defineLocalSdlRouterClass() {
        return com.smartdevicelink.sdlstreaming.sdl.SdlRouterService.class;
    }

    @Override
    public void onSdlEnabled(Context context, Intent intent) {
        intent.setClass(context,SdlService.class);
        context.startService(intent);
    }
}

@@ -69,44 +69,132 @@
 t.Co
-ntext;%0Aimport android.content.Intent
+mponentName;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.os.Build;%0Aimport android.util.Log
 ;%0A%0Ai
@@ -363,16 +363,70 @@
 eiver %7B%0A
+%0A    private static final String TAG =%22SdlReceiver%22;%0A%0A
     publ
@@ -697,24 +697,59 @@
 t intent) %7B%0A
+        Log.d(TAG, %22SDL Enabled%22);%0A
         inte
@@ -768,16 +768,17 @@
 context,
+ 
 SdlServi
@@ -788,24 +788,25 @@
 class);%0A
+%0A
         
 context.
@@ -801,37 +801,739 @@
     
-context.startService(intent);
+// SdlService needs to be foregrounded in Android O and above%0A        // This will prevent apps in the background from crashing when they try to start SdlService%0A        // Because Android O doesn't allow background apps to start background services%0A        ComponentName serviceStarted ;%0A        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.O) %7B%0A            serviceStarted = context.startForegroundService(intent);%0A        %7D else %7B%0A            serviceStarted = context.startService(intent);%0A        %7D%0A        if(serviceStarted != null)%7B%0A            Log.i(TAG, %22onSdlEnabled: Service started = %22 + serviceStarted.flattenToShortString());%0A        %7Delse%7B%0A            Log.e(TAG, %22onSdlEnabled: Unable to start service%22);%0A        %7D
 %0A   

Update SdlReceiver with proper foreground start