Skip to content

Commit 18133ce

Browse files
committed
Add Check for TransportType to RS
1 parent 71dc5f6 commit 18133ce

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,6 @@ public void onComplete(Vector<ComponentName> routerServices) {
296296
String routerServicePackage = null;
297297
if (sdlAppInfoList != null && !sdlAppInfoList.isEmpty() && sdlAppInfoList.get(0).getRouterServiceComponentName() != null) {
298298
routerServicePackage = sdlAppInfoList.get(0).getRouterServiceComponentName().getPackageName();
299-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
300-
if (!AndroidTools.areBtPermissionsGranted(context, routerServicePackage) && sdlAppInfoList.size() > 1) {
301-
for (SdlAppInfo appInfo : sdlAppInfoList) {
302-
if (AndroidTools.areBtPermissionsGranted(context, appInfo.getRouterServiceComponentName().getPackageName())) {
303-
routerServicePackage = appInfo.getRouterServiceComponentName().getPackageName();
304-
break;
305-
}
306-
}
307-
}
308-
}
309299
}
310300
DebugTool.logInfo(TAG, ": This app's package: " + myPackage);
311301
DebugTool.logInfo(TAG, ": Router service app's package: " + routerServicePackage);
@@ -610,16 +600,6 @@ public boolean onTransportConnected(Context context, BluetoothDevice bluetoothDe
610600
ComponentName routerService = sdlAppInfoList.get(0).getRouterServiceComponentName();
611601
//If we are on android 12 check the app has BT permissions
612602
//If it does not try to find another app in the list that does;
613-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
614-
if (!AndroidTools.areBtPermissionsGranted(context, routerService.getPackageName()) && sdlAppInfoList.size() > 1) {
615-
for (SdlAppInfo appInfo : sdlAppInfoList) {
616-
if (AndroidTools.areBtPermissionsGranted(context, appInfo.getRouterServiceComponentName().getPackageName())) {
617-
routerService = appInfo.getRouterServiceComponentName();
618-
break;
619-
}
620-
}
621-
}
622-
}
623603
startRouterService(context, routerService, false, bluetoothDevice, true, vehicleType);
624604
}
625605
}

android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)