@@ -303,25 +303,33 @@ public void onComplete(Vector<ComponentName> routerServices) {
303303 final boolean sdlDeviceListenerEnabled = SdlDeviceListener .isFeatureSupported (sdlAppInfoList );
304304 if (sdlDeviceListenerEnabled ) {
305305 String myPackage = context .getPackageName ();
306- String routerServicePackage = null ;
306+ ComponentName routerService = null ;
307+ boolean isPreAndroid12RSOnDevice = false ;
307308 if (sdlAppInfoList != null && !sdlAppInfoList .isEmpty () && sdlAppInfoList .get (0 ).getRouterServiceComponentName () != null ) {
308- routerServicePackage = sdlAppInfoList .get (0 ).getRouterServiceComponentName (). getPackageName ();
309+ routerService = sdlAppInfoList .get (0 ).getRouterServiceComponentName ();
309310 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
311+ isPreAndroid12RSOnDevice = isPreAndroid12RSOnDevice (sdlAppInfoList , context );
310312 // 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
311- if (!isPreAndroid12RSOnDevice (sdlAppInfoList ) && !AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , routerServicePackage ) && sdlAppInfoList .size () > 1 ) {
313+ if (!isPreAndroid12RSOnDevice
314+ && !AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , routerService .getPackageName ())
315+ && sdlAppInfoList .size () > 1 ) {
312316 for (SdlAppInfo appInfo : sdlAppInfoList ) {
313317 if (AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , appInfo .getRouterServiceComponentName ().getPackageName ())) {
314318 //If this app in the list has BT Connect permissions, we want to use that apps RS
315- routerServicePackage = appInfo .getRouterServiceComponentName (). getPackageName ();
319+ routerService = appInfo .getRouterServiceComponentName ();
316320 break ;
317321 }
318322 }
319323 }
320324 }
321325 }
326+ if (routerService == null ) {
327+ DebugTool .logError (TAG , "Router service was null, aborting." );
328+ return ;
329+ }
322330 DebugTool .logInfo (TAG , ": This app's package: " + myPackage );
323- DebugTool .logInfo (TAG , ": Router service app's package: " + routerServicePackage );
324- if (myPackage != null && myPackage .equalsIgnoreCase (routerServicePackage )) {
331+ DebugTool .logInfo (TAG , ": Router service app's package: " + routerService . getPackageName () );
332+ if (myPackage != null && myPackage .equalsIgnoreCase (routerService . getPackageName () )) {
325333 //If the device is not null the listener should start as well as the
326334 //case where this app was installed after BT connected and is the
327335 //only SDL app installed on the device. (Rare corner case)
@@ -333,6 +341,16 @@ public void onComplete(Vector<ComponentName> routerServices) {
333341 } else {
334342 DebugTool .logInfo (TAG , "Not starting device listener, bluetooth device is null and other SDL apps installed." );
335343 }
344+ } else if (isPreAndroid12RSOnDevice ) {
345+ //If the RS app has the BLUETOOTH_CONNECT permission that means it
346+ //will use its proper flow. If it doesn't, it's router service
347+ //must be started to kick off the chain of staring a valid RS.
348+ if (!AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , routerService .getPackageName ())) {
349+ DebugTool .logInfo (TAG , "Starting newest RS because of older version of the library on device." );
350+ startRouterService (context , routerService , false , device , false , vehicleType );
351+ } else {
352+ DebugTool .logInfo (TAG , "Newest RS app should be starting sequence correctly." );
353+ }
336354 } else {
337355 DebugTool .logInfo (TAG , ": Not the app to start the router service nor device listener" );
338356 }
@@ -644,7 +662,9 @@ public boolean onTransportConnected(Context context, BluetoothDevice bluetoothDe
644662 ComponentName routerService = sdlAppInfoList .get (0 ).getRouterServiceComponentName ();
645663 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
646664 // 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
647- if (!isPreAndroid12RSOnDevice (sdlAppInfoList ) && !AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , routerService .getPackageName ()) && sdlAppInfoList .size () > 1 ) {
665+ if (!isPreAndroid12RSOnDevice (sdlAppInfoList , context )
666+ && !AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , routerService .getPackageName ())
667+ && sdlAppInfoList .size () > 1 ) {
648668 for (SdlAppInfo appInfo : sdlAppInfoList ) {
649669 if (AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , appInfo .getRouterServiceComponentName ().getPackageName ())) {
650670 routerService = appInfo .getRouterServiceComponentName ();
@@ -690,10 +710,27 @@ public static ComponentName consumeQueuedRouterService() {
690710 }
691711 }
692712
693- private static boolean isPreAndroid12RSOnDevice (List <SdlAppInfo > sdlAppInfoList ) {
713+ /**
714+ * This method will check for older versions of the SDL library on the device. Due to older
715+ * libraries not checking for BLUETOOTH_CONNECT before beginning the process of starting the
716+ * router service, they just start the newest router service. This flow is legacy and must be
717+ * respected, however, if those apps do not have the BLUETOOTH_CONNECT permission themselves,
718+ * those apps will never receive the intent that BT has connected and therefore the logic will
719+ * never be used and we can continue to use the new process of start a router service.
720+ *
721+ * @param sdlAppInfoList list of SDL enabled apps on the device
722+ * @param context an instance of a context to use to check permissions on the SDL apps
723+ * @return if a pre v5.4 SDL enabled app is installed on the device and has the BLUETOOTH_CONNECT
724+ * permission.
725+ */
726+ private static boolean isPreAndroid12RSOnDevice (List <SdlAppInfo > sdlAppInfoList , Context context ) {
694727 for (SdlAppInfo appInfo : sdlAppInfoList ) {
695728 //If an installed app RS version is older than Android 12 update version (16)
696- if (appInfo .getRouterServiceVersion () < ANDROID_12_ROUTER_SERVICE_VERSION ) {
729+ //However, the app must have BLUETOOTH_CONNECT (Nearby Device) permissions,
730+ //otherwise it doesn't matter
731+ if (appInfo .getRouterServiceVersion () < ANDROID_12_ROUTER_SERVICE_VERSION
732+ && AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , appInfo .getRouterServiceComponentName ().getPackageName ())) {
733+ DebugTool .logInfo (TAG , "Found pre-Android 12 RS on device." );
697734 return true ;
698735 }
699736 }
0 commit comments