Skip to content

Commit

Permalink
move logic around and add java docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianKast committed Sep 1, 2023
1 parent ad5f699 commit 0b6be0d
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public void onSdlEnabled(Context context, Intent intent) {
// We will check the intent for a pendingIntent parcelable extra
// This pendingIntent allows us to start the SdlService from the context of the active router service which is in the foreground
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
storedIntent = intent;
PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra(TransportConstants.PENDING_INTENT_EXTRA);
if (pendingIntent != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(context)) {
requestUsbAccessory(context);
storedIntent = intent;
storedContext = context;
this.pendingIntent = pendingIntent;
DebugTool.logInfo(TAG, "Permission missing for ForegroundServiceType connected device." + context);
Expand Down Expand Up @@ -93,6 +93,14 @@ public void onReceive(Context context, Intent intent) {
}
};

/**
* Request permission from USB Accessory if USB accessory is not null.
* If the user has not granted the BLUETOOTH_CONNECT permission,
* we can request the USB Accessory permission to satisfy the requirements for
* FOREGROUND_SERVICE_CONNECTED_DEVICE and can start our service and allow
* it to enter the foreground. FOREGROUND_SERVICE_CONNECTED_DEVICE is a requirement
* in Android 14
*/
private void requestUsbAccessory(Context context) {
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
if (manager.getAccessoryList() == null) {
Expand Down

0 comments on commit 0b6be0d

Please sign in to comment.