Skip to content

Commit f866291

Browse files
committed
Update RS to pick idedal RS
1 parent 18133ce commit f866291

2 files changed

Lines changed: 47 additions & 23 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ 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+
}
299309
}
300310
DebugTool.logInfo(TAG, ": This app's package: " + myPackage);
301311
DebugTool.logInfo(TAG, ": Router service app's package: " + routerServicePackage);
@@ -600,6 +610,16 @@ public boolean onTransportConnected(Context context, BluetoothDevice bluetoothDe
600610
ComponentName routerService = sdlAppInfoList.get(0).getRouterServiceComponentName();
601611
//If we are on android 12 check the app has BT permissions
602612
//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+
}
603623
startRouterService(context, routerService, false, bluetoothDevice, true, vehicleType);
604624
}
605625
}

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

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

Comments
 (0)