summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorRHeniz <heniganr1@gmail.com>2021-11-29 14:59:28 -0500
committerRHeniz <heniganr1@gmail.com>2021-11-29 14:59:28 -0500
commitf8662914b69cf20c807bb3fee8cf098318be38d6 (patch)
tree3ac86feb0b4b2733218f1cbbbaad93851080adb3 /android
parent18133ceaf65ea3b083cdcd17807195a901ddca4f (diff)
downloadsdl_android-f8662914b69cf20c807bb3fee8cf098318be38d6.tar.gz
Update RS to pick idedal RS
Diffstat (limited to 'android')
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java20
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java50
2 files changed, 47 insertions, 23 deletions
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 6eea68981..15fee7227 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,6 +296,16 @@ 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);
@@ -600,6 +610,16 @@ 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 f55e773ec..c8411bff0 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
@@ -217,6 +217,7 @@ public class SdlRouterService extends Service {
private boolean startSequenceComplete = false;
private VehicleType receivedVehicleType;
private boolean isConnectedOverUSB;
+ private boolean secondPass = false;
private ExecutorService packetExecutor = null;
ConcurrentHashMap<TransportType, PacketWriteTaskMaster> packetWriteTaskMasterMap = null;
@@ -1100,13 +1101,9 @@ public class SdlRouterService extends Service {
//If Android 12 or newer make sure we have BT Runtime permissions
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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !supportsBTPermissions && !secondPass) {
+ DebugTool.logError(TAG, "Bluetooth Runtime Permissions are not granted. Shutting down");
+ return false;
}
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 @@ 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<SdlAppInfo> 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() {
super.onCreate();
@@ -1188,6 +1169,10 @@ public class SdlRouterService extends Service {
if (info.getRouterServiceComponentName().equals(name) && listSize > i + 1) {
SdlAppInfo nextUp = sdlAppInfoList.get(i + 1);
Intent serviceIntent = new Intent();
+ if (secondPass) {
+ serviceIntent.putExtra("second_pass", true);
+ }
+ //Add check if it is second pass also add extra
serviceIntent.setComponent(nextUp.getRouterServiceComponentName());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
startService(serviceIntent);
@@ -1201,11 +1186,27 @@ public class SdlRouterService extends Service {
break;
}
+ if (i == listSize - 1 && !secondPass) {
+ info = sdlAppInfoList.get(0);
+ Intent serviceIntent = new Intent();
+ serviceIntent.putExtra("second_pass", true);
+ serviceIntent.setComponent(info.getRouterServiceComponentName());
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
+ startService(serviceIntent);
+ } else {
+ try {
+ startForegroundService(serviceIntent);
+ } catch (Exception e) {
+ DebugTool.logError(TAG, "Unable to start next SDL router service. " + e.getMessage());
+ }
+ }
+ }
}
} else {
DebugTool.logInfo(TAG, "No sdl apps found");
return;
}
+
closing = true;
closeBluetoothSerialServer();
notifyAltTransportOfClose(TransportConstants.ROUTER_SHUTTING_DOWN_REASON_NEWER_SERVICE);
@@ -1285,6 +1286,9 @@ public class SdlRouterService extends Service {
(HashMap<String, Object>) intent.getSerializableExtra(TransportConstants.VEHICLE_INFO_EXTRA)
);
}
+ if (intent != null && intent.hasExtra("second_pass")) {
+ secondPass = intent.getBooleanExtra("second_pass", false);
+ }
if (intent != null && intent.hasExtra(TransportConstants.CONNECTION_TYPE_EXTRA)) {
isConnectedOverUSB = TransportConstants.ACTION_USB_ACCESSORY_ATTACHED.equalsIgnoreCase(intent.getStringExtra(TransportConstants.CONNECTION_TYPE_EXTRA));
}