From 18133ceaf65ea3b083cdcd17807195a901ddca4f Mon Sep 17 00:00:00 2001 From: RHeniz Date: Tue, 23 Nov 2021 16:11:47 -0500 Subject: Add Check for TransportType to RS --- .../transport/SdlBroadcastReceiver.java | 20 --------------- .../transport/SdlRouterService.java | 30 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 23 deletions(-) (limited to 'android') diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java index 15fee7227..6eea68981 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java @@ -296,16 +296,6 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { String routerServicePackage = null; if (sdlAppInfoList != null && !sdlAppInfoList.isEmpty() && sdlAppInfoList.get(0).getRouterServiceComponentName() != null) { routerServicePackage = sdlAppInfoList.get(0).getRouterServiceComponentName().getPackageName(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (!AndroidTools.areBtPermissionsGranted(context, routerServicePackage) && sdlAppInfoList.size() > 1) { - for (SdlAppInfo appInfo : sdlAppInfoList) { - if (AndroidTools.areBtPermissionsGranted(context, appInfo.getRouterServiceComponentName().getPackageName())) { - routerServicePackage = appInfo.getRouterServiceComponentName().getPackageName(); - break; - } - } - } - } } DebugTool.logInfo(TAG, ": This app's package: " + myPackage); DebugTool.logInfo(TAG, ": Router service app's package: " + routerServicePackage); @@ -610,16 +600,6 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { ComponentName routerService = sdlAppInfoList.get(0).getRouterServiceComponentName(); //If we are on android 12 check the app has BT permissions //If it does not try to find another app in the list that does; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (!AndroidTools.areBtPermissionsGranted(context, routerService.getPackageName()) && sdlAppInfoList.size() > 1) { - for (SdlAppInfo appInfo : sdlAppInfoList) { - if (AndroidTools.areBtPermissionsGranted(context, appInfo.getRouterServiceComponentName().getPackageName())) { - routerService = appInfo.getRouterServiceComponentName(); - break; - } - } - } - } startRouterService(context, routerService, false, bluetoothDevice, true, vehicleType); } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index ca585c445..f55e773ec 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -216,6 +216,7 @@ public class SdlRouterService extends Service { private boolean startSequenceComplete = false; private VehicleType receivedVehicleType; + private boolean isConnectedOverUSB; private ExecutorService packetExecutor = null; ConcurrentHashMap packetWriteTaskMasterMap = null; @@ -1098,9 +1099,14 @@ public class SdlRouterService extends Service { } //If Android 12 or newer make sure we have BT Runtime permissions - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !AndroidTools.areBtPermissionsGranted(this, this.getPackageName())) { - DebugTool.logError(TAG, "Bluetooth Runtime Permissions are not granted. Shutting down"); - return false; + boolean supportsBTPermissions = AndroidTools.areBtPermissionsGranted(this, this.getPackageName()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !supportsBTPermissions) { + if (!isConnectedOverUSB) { + DebugTool.logError(TAG, "Bluetooth Runtime Permissions are not granted. Shutting down"); + return false; + } else if (bluetoothEnabledRouterServiceExists()) { + return false; + } } 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 @@ public class SdlRouterService extends Service { return true; } + //USB Connection + //4.11 APP, New App (Permissions Denied) + //Try to start New app + //4.11 APP could connect over BT, but will it? + private boolean bluetoothEnabledRouterServiceExists() { + List sdlAppInfoList = AndroidTools.querySdlAppInfo(getApplicationContext(), new SdlAppInfo.BestRouterComparator(), null); + if (sdlAppInfoList != null && !sdlAppInfoList.isEmpty()) { + for (SdlAppInfo appInfo : sdlAppInfoList) { + if (AndroidTools.areBtPermissionsGranted(getApplicationContext(), appInfo.getRouterServiceComponentName().getPackageName())) { + return true; + } + } + } + return false; + } @Override public void onCreate() { @@ -1264,6 +1285,9 @@ public class SdlRouterService extends Service { (HashMap) intent.getSerializableExtra(TransportConstants.VEHICLE_INFO_EXTRA) ); } + if (intent != null && intent.hasExtra(TransportConstants.CONNECTION_TYPE_EXTRA)) { + isConnectedOverUSB = TransportConstants.ACTION_USB_ACCESSORY_ATTACHED.equalsIgnoreCase(intent.getStringExtra(TransportConstants.CONNECTION_TYPE_EXTRA)); + } // 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. if (firstStart) { firstStart = false; -- cgit v1.2.1