@@ -32,12 +32,12 @@ public void onSdlEnabled(Context context, Intent intent) {
3232 // We will check the intent for a pendingIntent parcelable extra
3333 // This pendingIntent allows us to start the SdlService from the context of the active router service which is in the foreground
3434 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
35- storedIntent = intent ;
3635 PendingIntent pendingIntent = (PendingIntent ) intent .getParcelableExtra (TransportConstants .PENDING_INTENT_EXTRA );
3736 if (pendingIntent != null ) {
3837 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
3938 if (!AndroidTools .ServicePermissionUtil .hasForegroundServiceTypePermission (context )) {
4039 requestUsbAccessory (context );
40+ storedIntent = intent ;
4141 storedContext = context ;
4242 this .pendingIntent = pendingIntent ;
4343 DebugTool .logInfo (TAG , "Permission missing for ForegroundServiceType connected device." + context );
@@ -93,6 +93,14 @@ public void onReceive(Context context, Intent intent) {
9393 }
9494 };
9595
96+ /**
97+ * Request permission from USB Accessory if USB accessory is not null.
98+ * If the user has not granted the BLUETOOTH_CONNECT permission,
99+ * we can request the USB Accessory permission to satisfy the requirements for
100+ * FOREGROUND_SERVICE_CONNECTED_DEVICE and can start our service and allow
101+ * it to enter the foreground. FOREGROUND_SERVICE_CONNECTED_DEVICE is a requirement
102+ * in Android 14
103+ */
96104 private void requestUsbAccessory (Context context ) {
97105 UsbManager manager = (UsbManager ) context .getSystemService (Context .USB_SERVICE );
98106 if (manager .getAccessoryList () == null ) {
0 commit comments