From 5280f0c5e4925fa3dd200ea71bda640b34f6c1c1 Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Thu, 2 Feb 2023 15:28:11 -0500 Subject: Fix #1839 Add fallback logic if an older version of the SDL lib is on the device and they do not have the right permissions or their integration is incorrect. --- .../transport/SdlBroadcastReceiver.java | 55 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 9 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 936989f5c..9b2eb9d84 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 @@ -303,25 +303,33 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { final boolean sdlDeviceListenerEnabled = SdlDeviceListener.isFeatureSupported(sdlAppInfoList); if (sdlDeviceListenerEnabled) { String myPackage = context.getPackageName(); - String routerServicePackage = null; + ComponentName routerService = null; + boolean isPreAndroid12RSOnDevice = false; if (sdlAppInfoList != null && !sdlAppInfoList.isEmpty() && sdlAppInfoList.get(0).getRouterServiceComponentName() != null) { - routerServicePackage = sdlAppInfoList.get(0).getRouterServiceComponentName().getPackageName(); + routerService = sdlAppInfoList.get(0).getRouterServiceComponentName(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + isPreAndroid12RSOnDevice = isPreAndroid12RSOnDevice(sdlAppInfoList, context); // If all apps have a RS newer than the Android 12 update, chosen app does not have BT Connect permissions, and more than 1 sdl app is installed - if (!isPreAndroid12RSOnDevice(sdlAppInfoList) && !AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, routerServicePackage) && sdlAppInfoList.size() > 1) { + if (!isPreAndroid12RSOnDevice + && !AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, routerService.getPackageName()) + && sdlAppInfoList.size() > 1) { for (SdlAppInfo appInfo : sdlAppInfoList) { if (AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, appInfo.getRouterServiceComponentName().getPackageName())) { //If this app in the list has BT Connect permissions, we want to use that apps RS - routerServicePackage = appInfo.getRouterServiceComponentName().getPackageName(); + routerService = appInfo.getRouterServiceComponentName(); break; } } } } } + if (routerService == null) { + DebugTool.logError(TAG, "Router service was null, aborting."); + return; + } DebugTool.logInfo(TAG, ": This app's package: " + myPackage); - DebugTool.logInfo(TAG, ": Router service app's package: " + routerServicePackage); - if (myPackage != null && myPackage.equalsIgnoreCase(routerServicePackage)) { + DebugTool.logInfo(TAG, ": Router service app's package: " + routerService.getPackageName()); + if (myPackage != null && myPackage.equalsIgnoreCase(routerService.getPackageName())) { //If the device is not null the listener should start as well as the //case where this app was installed after BT connected and is the //only SDL app installed on the device. (Rare corner case) @@ -333,6 +341,16 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { } else { DebugTool.logInfo(TAG, "Not starting device listener, bluetooth device is null and other SDL apps installed."); } + } else if(isPreAndroid12RSOnDevice){ + //If the RS app has the BLUETOOTH_CONNECT permission that means it + //will use its proper flow. If it doesn't, it's router service + //must be started to kick off the chain of staring a valid RS. + if (!AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, routerService.getPackageName())) { + DebugTool.logInfo(TAG, "Starting newest RS because of older version of the library on device."); + startRouterService(context, routerService, false, device, false, vehicleType); + } else { + DebugTool.logInfo(TAG, "Newest RS app should be starting sequence correctly."); + } } else { DebugTool.logInfo(TAG, ": Not the app to start the router service nor device listener"); } @@ -644,7 +662,9 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { ComponentName routerService = sdlAppInfoList.get(0).getRouterServiceComponentName(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { // If all apps have a RS newer than the Android 12 update, chosen app does not have BT Connect permissions, and more than 1 sdl app is installed - if (!isPreAndroid12RSOnDevice(sdlAppInfoList) && !AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, routerService.getPackageName()) && sdlAppInfoList.size() > 1) { + if (!isPreAndroid12RSOnDevice(sdlAppInfoList, context) + && !AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, routerService.getPackageName()) + && sdlAppInfoList.size() > 1) { for (SdlAppInfo appInfo : sdlAppInfoList) { if (AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, appInfo.getRouterServiceComponentName().getPackageName())) { routerService = appInfo.getRouterServiceComponentName(); @@ -690,10 +710,27 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { } } - private static boolean isPreAndroid12RSOnDevice(List sdlAppInfoList) { + /** + * This method will check for older versions of the SDL library on the device. Due to older + * libraries not checking for BLUETOOTH_CONNECT before beginning the process of starting the + * router service, they just start the newest router service. This flow is legacy and must be + * respected, however, if those apps do not have the BLUETOOTH_CONNECT permission themselves, + * those apps will never receive the intent that BT has connected and therefore the logic will + * never be used and we can continue to use the new process of start a router service. + * + * @param sdlAppInfoList list of SDL enabled apps on the device + * @param context an instance of a context to use to check permissions on the SDL apps + * @return if a pre v5.4 SDL enabled app is installed on the device and has the BLUETOOTH_CONNECT + * permission. + */ + private static boolean isPreAndroid12RSOnDevice(List sdlAppInfoList, Context context) { for (SdlAppInfo appInfo : sdlAppInfoList) { //If an installed app RS version is older than Android 12 update version (16) - if (appInfo.getRouterServiceVersion() < ANDROID_12_ROUTER_SERVICE_VERSION) { + //However, the app must have BLUETOOTH_CONNECT (Nearby Device) permissions, + //otherwise it doesn't matter + if (appInfo.getRouterServiceVersion() < ANDROID_12_ROUTER_SERVICE_VERSION + && AndroidTools.isPermissionGranted(BLUETOOTH_CONNECT, context, appInfo.getRouterServiceComponentName().getPackageName())) { + DebugTool.logInfo(TAG, "Found pre-Android 12 RS on device."); return true; } } -- cgit v1.2.1 From 8b648e12dd75b5b7e1839f53fca1f772d9ffac12 Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Mon, 13 Feb 2023 11:45:07 -0500 Subject: Fix formatting error in SdlBroadcastReceiver #1840 Co-authored-by: Julian Kast --- .../main/java/com/smartdevicelink/transport/SdlBroadcastReceiver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 9b2eb9d84..2bfe13ef1 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 @@ -341,7 +341,7 @@ public abstract class SdlBroadcastReceiver extends BroadcastReceiver { } else { DebugTool.logInfo(TAG, "Not starting device listener, bluetooth device is null and other SDL apps installed."); } - } else if(isPreAndroid12RSOnDevice){ + } else if (isPreAndroid12RSOnDevice) { //If the RS app has the BLUETOOTH_CONNECT permission that means it //will use its proper flow. If it doesn't, it's router service //must be started to kick off the chain of staring a valid RS. -- cgit v1.2.1 From 1f0368732f0540c5a26b851d851f4f315d94f567 Mon Sep 17 00:00:00 2001 From: Joey Grover Date: Mon, 13 Feb 2023 14:23:47 -0500 Subject: Update version to 5.6.1 --- android/sdl_android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'android') diff --git a/android/sdl_android/build.gradle b/android/sdl_android/build.gradle index c7cce6954..8bf0122f3 100644 --- a/android/sdl_android/build.gradle +++ b/android/sdl_android/build.gradle @@ -5,7 +5,7 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 33 - versionCode 24 + versionCode 25 versionName new File(projectDir.path, ('/../../VERSION')).text.trim() buildConfigField "String", "VERSION_NAME", '\"' + versionName + '\"' resValue "string", "SDL_LIB_VERSION", '\"' + versionName + '\"' -- cgit v1.2.1