@@ -217,6 +217,7 @@ public class SdlRouterService extends Service {
217217 private boolean startSequenceComplete = false ;
218218 private VehicleType receivedVehicleType ;
219219 private boolean isConnectedOverUSB ;
220+ private boolean secondPass = false ;
220221
221222 private ExecutorService packetExecutor = null ;
222223 ConcurrentHashMap <TransportType , PacketWriteTaskMaster > packetWriteTaskMasterMap = null ;
@@ -1100,13 +1101,9 @@ private boolean initCheck() {
11001101
11011102 //If Android 12 or newer make sure we have BT Runtime permissions
11021103 boolean supportsBTPermissions = AndroidTools .areBtPermissionsGranted (this , this .getPackageName ());
1103- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S && !supportsBTPermissions ) {
1104- if (!isConnectedOverUSB ) {
1105- DebugTool .logError (TAG , "Bluetooth Runtime Permissions are not granted. Shutting down" );
1106- return false ;
1107- } else if (bluetoothEnabledRouterServiceExists ()) {
1108- return false ;
1109- }
1104+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S && !supportsBTPermissions && !secondPass ) {
1105+ DebugTool .logError (TAG , "Bluetooth Runtime Permissions are not granted. Shutting down" );
1106+ return false ;
11101107 }
11111108
11121109 if (!AndroidTools .isServiceExported (this , new ComponentName (this , this .getClass ()))) { //We want to check to see if our service is actually exported
@@ -1138,22 +1135,6 @@ private boolean initCheck() {
11381135 return true ;
11391136 }
11401137
1141- //USB Connection
1142- //4.11 APP, New App (Permissions Denied)
1143- //Try to start New app
1144- //4.11 APP could connect over BT, but will it?
1145- private boolean bluetoothEnabledRouterServiceExists () {
1146- List <SdlAppInfo > sdlAppInfoList = AndroidTools .querySdlAppInfo (getApplicationContext (), new SdlAppInfo .BestRouterComparator (), null );
1147- if (sdlAppInfoList != null && !sdlAppInfoList .isEmpty ()) {
1148- for (SdlAppInfo appInfo : sdlAppInfoList ) {
1149- if (AndroidTools .areBtPermissionsGranted (getApplicationContext (), appInfo .getRouterServiceComponentName ().getPackageName ())) {
1150- return true ;
1151- }
1152- }
1153- }
1154- return false ;
1155- }
1156-
11571138 @ Override
11581139 public void onCreate () {
11591140 super .onCreate ();
@@ -1188,6 +1169,10 @@ protected void deployNextRouterService() {
11881169 if (info .getRouterServiceComponentName ().equals (name ) && listSize > i + 1 ) {
11891170 SdlAppInfo nextUp = sdlAppInfoList .get (i + 1 );
11901171 Intent serviceIntent = new Intent ();
1172+ if (secondPass ) {
1173+ serviceIntent .putExtra ("second_pass" , true );
1174+ }
1175+ //Add check if it is second pass also add extra
11911176 serviceIntent .setComponent (nextUp .getRouterServiceComponentName ());
11921177 if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
11931178 startService (serviceIntent );
@@ -1201,11 +1186,27 @@ protected void deployNextRouterService() {
12011186 break ;
12021187
12031188 }
1189+ if (i == listSize - 1 && !secondPass ) {
1190+ info = sdlAppInfoList .get (0 );
1191+ Intent serviceIntent = new Intent ();
1192+ serviceIntent .putExtra ("second_pass" , true );
1193+ serviceIntent .setComponent (info .getRouterServiceComponentName ());
1194+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) {
1195+ startService (serviceIntent );
1196+ } else {
1197+ try {
1198+ startForegroundService (serviceIntent );
1199+ } catch (Exception e ) {
1200+ DebugTool .logError (TAG , "Unable to start next SDL router service. " + e .getMessage ());
1201+ }
1202+ }
1203+ }
12041204 }
12051205 } else {
12061206 DebugTool .logInfo (TAG , "No sdl apps found" );
12071207 return ;
12081208 }
1209+
12091210 closing = true ;
12101211 closeBluetoothSerialServer ();
12111212 notifyAltTransportOfClose (TransportConstants .ROUTER_SHUTTING_DOWN_REASON_NEWER_SERVICE );
@@ -1285,6 +1286,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
12851286 (HashMap <String , Object >) intent .getSerializableExtra (TransportConstants .VEHICLE_INFO_EXTRA )
12861287 );
12871288 }
1289+ if (intent != null && intent .hasExtra ("second_pass" )) {
1290+ secondPass = intent .getBooleanExtra ("second_pass" , false );
1291+ }
12881292 if (intent != null && intent .hasExtra (TransportConstants .CONNECTION_TYPE_EXTRA )) {
12891293 isConnectedOverUSB = TransportConstants .ACTION_USB_ACCESSORY_ATTACHED .equalsIgnoreCase (intent .getStringExtra (TransportConstants .CONNECTION_TYPE_EXTRA ));
12901294 }
0 commit comments