@@ -216,6 +216,7 @@ public class SdlRouterService extends Service {
216216
217217 private boolean startSequenceComplete = false ;
218218 private VehicleType receivedVehicleType ;
219+ private boolean isConnectedOverUSB ;
219220
220221 private ExecutorService packetExecutor = null ;
221222 ConcurrentHashMap <TransportType , PacketWriteTaskMaster > packetWriteTaskMasterMap = null ;
@@ -1098,9 +1099,14 @@ private boolean initCheck() {
10981099 }
10991100
11001101 //If Android 12 or newer make sure we have BT Runtime permissions
1101- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S && !AndroidTools .areBtPermissionsGranted (this , this .getPackageName ())) {
1102- DebugTool .logError (TAG , "Bluetooth Runtime Permissions are not granted. Shutting down" );
1103- return false ;
1102+ 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+ }
11041110 }
11051111
11061112 if (!AndroidTools .isServiceExported (this , new ComponentName (this , this .getClass ()))) { //We want to check to see if our service is actually exported
@@ -1132,6 +1138,21 @@ private boolean initCheck() {
11321138 return true ;
11331139 }
11341140
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+ }
11351156
11361157 @ Override
11371158 public void onCreate () {
@@ -1264,6 +1285,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
12641285 (HashMap <String , Object >) intent .getSerializableExtra (TransportConstants .VEHICLE_INFO_EXTRA )
12651286 );
12661287 }
1288+ if (intent != null && intent .hasExtra (TransportConstants .CONNECTION_TYPE_EXTRA )) {
1289+ isConnectedOverUSB = TransportConstants .ACTION_USB_ACCESSORY_ATTACHED .equalsIgnoreCase (intent .getStringExtra (TransportConstants .CONNECTION_TYPE_EXTRA ));
1290+ }
12671291 // Only trusting the first intent received to start the RouterService and run initial checks to avoid a case where an app could send incorrect data after the spp connection has started.
12681292 if (firstStart ) {
12691293 firstStart = false ;
0 commit comments