@@ -303,25 +303,33 @@ public void onComplete(Vector<ComponentName> routerServices) {
303
303
final boolean sdlDeviceListenerEnabled = SdlDeviceListener .isFeatureSupported (sdlAppInfoList );
304
304
if (sdlDeviceListenerEnabled ) {
305
305
String myPackage = context .getPackageName ();
306
- String routerServicePackage = null ;
306
+ ComponentName routerService = null ;
307
+ boolean isPreAndroid12RSOnDevice = false ;
307
308
if (sdlAppInfoList != null && !sdlAppInfoList .isEmpty () && sdlAppInfoList .get (0 ).getRouterServiceComponentName () != null ) {
308
- routerServicePackage = sdlAppInfoList .get (0 ).getRouterServiceComponentName (). getPackageName ();
309
+ routerService = sdlAppInfoList .get (0 ).getRouterServiceComponentName ();
309
310
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
311
+ isPreAndroid12RSOnDevice = isPreAndroid12RSOnDevice (sdlAppInfoList , context );
310
312
// 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 ) {
312
316
for (SdlAppInfo appInfo : sdlAppInfoList ) {
313
317
if (AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , appInfo .getRouterServiceComponentName ().getPackageName ())) {
314
318
//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 ();
316
320
break ;
317
321
}
318
322
}
319
323
}
320
324
}
321
325
}
326
+ if (routerService == null ) {
327
+ DebugTool .logError (TAG , "Router service was null, aborting." );
328
+ return ;
329
+ }
322
330
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 () )) {
325
333
//If the device is not null the listener should start as well as the
326
334
//case where this app was installed after BT connected and is the
327
335
//only SDL app installed on the device. (Rare corner case)
@@ -333,6 +341,16 @@ public void onComplete(Vector<ComponentName> routerServices) {
333
341
} else {
334
342
DebugTool .logInfo (TAG , "Not starting device listener, bluetooth device is null and other SDL apps installed." );
335
343
}
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
+ }
336
354
} else {
337
355
DebugTool .logInfo (TAG , ": Not the app to start the router service nor device listener" );
338
356
}
@@ -644,7 +662,9 @@ public boolean onTransportConnected(Context context, BluetoothDevice bluetoothDe
644
662
ComponentName routerService = sdlAppInfoList .get (0 ).getRouterServiceComponentName ();
645
663
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
646
664
// 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 ) {
648
668
for (SdlAppInfo appInfo : sdlAppInfoList ) {
649
669
if (AndroidTools .isPermissionGranted (BLUETOOTH_CONNECT , context , appInfo .getRouterServiceComponentName ().getPackageName ())) {
650
670
routerService = appInfo .getRouterServiceComponentName ();
@@ -690,10 +710,27 @@ public static ComponentName consumeQueuedRouterService() {
690
710
}
691
711
}
692
712
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 ) {
694
727
for (SdlAppInfo appInfo : sdlAppInfoList ) {
695
728
//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." );
697
734
return true ;
698
735
}
699
736
}
0 commit comments