The Android library can prevent apps from starting their SdlRouterService
based on if they support the vehicle type if the connection is over Bluetooth.
If older apps are installed that use a version less than SDL Android 4.12.0, on the first connection to the vehicle an OEM app may host the SdlRouterService
but on subsequent connections, it may pass it off to another app.
This does not work over AOA connections.
To implement this feature, you will need to define an XML file for supported vehicles called supported_vehicle_type.xml
in res/xml
directory of the project, and add it as metaData for SdlRouterService
in its AndroidManifest
. If an app defines a vehicle-type
element, then it should always have a make
attribute; all other attributes are optional. However, if you want to use modelYear
or trim
, you should define make
and model
attributes as well. The Java Suite app library will check only the defined attributes. The below example shows a valid vehicle type resource file.
<?xml version="1.0" encoding="utf-8"?> <resource> <!-- Vehicle filter for vehicle make--> <vehicle-type make="SDL"/> <!-- Vehicle filter for vehicle make, model and model year--> <vehicle-type make="SDL" model="Generic" modelYear="2021"/> <!-- Vehicle filter for vehicle make, model and trim--> <vehicle-type make="SDL" model="Generic" trim="SE"/> </resource>
Add supported vehicle type file as metaData for SdlRouterService
in AndroidManifest
<meta-data android:name="@string/sdl_oem_vehicle_type_filter_name" android:resource="@xml/supported_vehicle_type" />
Apps can still receive an intent to start when SDL
is enabled from other apps. To prevent an OEM app from starting their SdlService
, vehicle type can be retrieved in SdlReceiver.onSdlEnabled
and the app can choose not to start SdlService
if the vehicle is not supported.
@Override public void onSdlEnabled(Context context, Intent intent) { intent.setClass(context, SdlService.class); VehicleType vehicleType = null; if (intent.hasExtra(TransportConstants.VEHICLE_INFO_EXTRA)) { vehicleType = intent.getParcelableExtra(TransportConstants.VEHICLE_INFO_EXTRA); } VehicleType vehicleType1 = new VehicleType().setMake("SDL").setModel("Generic").setModelYear("2021"); VehicleType vehicleType2 = new VehicleType().setMake("SDL").setModel("Generic").setTrim("SE"); List<VehicleType> supportedVehicleList = Arrays.asList(vehicleType1, vehicleType2); if (vehicleType != null && SdlAppInfo.checkIfVehicleSupported(supportedVehicleList, vehicleType)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { context.startForegroundService(intent); } else { context.startService(intent); } } }