From c09d6d1cb6e888c7bad9ed777117a713204e028f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Thu, 10 Aug 2023 15:05:28 -0400 Subject: [PATCH 01/41] Add FGS type connectedDevice to Manifest --- android/hello_sdl_android/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/android/hello_sdl_android/src/main/AndroidManifest.xml b/android/hello_sdl_android/src/main/AndroidManifest.xml index 6b577c5a25..b4c6c82ab8 100755 --- a/android/hello_sdl_android/src/main/AndroidManifest.xml +++ b/android/hello_sdl_android/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + From 97f0fd2646a5c242d62f3075a7cda2c479a2372e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Thu, 10 Aug 2023 15:07:20 -0400 Subject: [PATCH 02/41] Add new UsbTransferProvider constructor --- .../transport/UsbTransferProvider.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java index b588f15123..4f5f301158 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java @@ -130,6 +130,26 @@ public UsbTransferProvider(Context context, ComponentName service, UsbAccessory } + public UsbTransferProvider(Context context, ComponentName service, ParcelFileDescriptor usbPfd, UsbTransferCallback callback) { + if (context == null || service == null || usbPfd == null) { + throw new IllegalStateException("Supplied params are not correct. Context == null? " + (context == null) + " ComponentName == null? " + (service == null) + " Usb PFD == null? " + usbPfd); + } + if (usbPfd.getFileDescriptor() != null && usbPfd.getFileDescriptor().valid()) { + this.context = context; + this.routerService = service; + this.callback = callback; + this.clientMessenger = new Messenger(new ClientHandler(this)); + this.usbPfd = usbPfd; + checkIsConnected(); + } else { + DebugTool.logError(TAG, "Unable to open accessory"); + clientMessenger = null; + if (callback != null) { + callback.onUsbTransferUpdate(false); + } + } + } + @SuppressLint("NewApi") private ParcelFileDescriptor getFileDescriptor(UsbAccessory accessory, Context context) { if (AndroidTools.isUSBCableConnected(context)) { From 773b61a7ba4ccf5f2ad0cd8f5e70918be85d0994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Thu, 10 Aug 2023 15:09:51 -0400 Subject: [PATCH 03/41] Modify deployNextRouterService to take in a ParcelFileDescriptor in the RS --- .../transport/SdlRouterService.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 7d95969427..31d2982b87 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -1166,7 +1166,7 @@ public void onCreate() { /** * The method will attempt to start up the next router service in line based on the sorting criteria of best router service. */ - protected void deployNextRouterService() { + protected void deployNextRouterService(ParcelFileDescriptor usbPfd) { List sdlAppInfoList = AndroidTools.querySdlAppInfo(getApplicationContext(), new SdlAppInfo.BestRouterComparator(), null); if (sdlAppInfoList != null && !sdlAppInfoList.isEmpty()) { ComponentName name = new ComponentName(this, this.getClass()); @@ -1178,11 +1178,26 @@ protected void deployNextRouterService() { SdlAppInfo nextUp = sdlAppInfoList.get(i + 1); Intent serviceIntent = new Intent(); serviceIntent.setComponent(nextUp.getRouterServiceComponentName()); + if (usbPfd != null) { + serviceIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT); + serviceIntent.putExtra(TransportConstants.CONNECTION_TYPE_EXTRA, TransportConstants.AOA_USB); + serviceIntent.putExtra(FOREGROUND_EXTRA, true); + } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { startService(serviceIntent); } else { try { startForegroundService(serviceIntent); + if (usbPfd != null) { + UsbTransferProvider usbTransferProvider = new UsbTransferProvider(getApplicationContext(), nextUp.getRouterServiceComponentName(), usbPfd, new UsbTransferProvider.UsbTransferCallback() { + @Override + public void onUsbTransferUpdate(boolean success) { + Log.i(TAG, "onUsbTransferUpdate: " + success); + closeSelf(); + } + }); + } + } catch (Exception e) { DebugTool.logError(TAG, "Unable to start next SDL router service. " + e.getMessage()); } @@ -1282,7 +1297,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { if (firstStart) { firstStart = false; if (!initCheck(isConnectedOverUSB)) { // Run checks on process and permissions - deployNextRouterService(); + deployNextRouterService(null); closeSelf(); return START_REDELIVER_INTENT; } From e5d61fcffbd82c06cc15d48845f1a061a405c180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Thu, 10 Aug 2023 15:12:15 -0400 Subject: [PATCH 04/41] Add ServicePermissionUtil to AndroidTools to check for permissions for FGS type --- .../smartdevicelink/util/AndroidTools.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index 2700d35d9f..7b4053230f 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -32,6 +32,7 @@ package com.smartdevicelink.util; +import android.Manifest; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -47,10 +48,13 @@ import android.content.res.XmlResourceParser; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.hardware.usb.UsbAccessory; +import android.hardware.usb.UsbManager; import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import com.smartdevicelink.marshal.JsonRPCMarshaller; import com.smartdevicelink.proxy.rpc.VehicleType; @@ -392,4 +396,28 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str return null; } } + + public static class ServicePermissionUtil { + public static boolean hasUsbAccessoryPermission(Context context) { + UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE); + for (final UsbAccessory usbAccessory : manager.getAccessoryList()) { + if (manager.hasPermission(usbAccessory)) { + return true; + } + } + return false; + } + + public static boolean checkPermission(Context applicationContext, String permission) { + return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission); + } + + public static boolean hasForegroundServiceTypePermission(Context context) { + // if Build is less than Android 14, we don't need either permission to enter the foreground. + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + return true; + } + return ServicePermissionUtil.checkPermission(context, Manifest.permission.BLUETOOTH_CONNECT) || ServicePermissionUtil.hasUsbAccessoryPermission(context); + } + } } From 6543c442fb5248b94f6ce6e2496be29f2720de53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Thu, 10 Aug 2023 15:14:18 -0400 Subject: [PATCH 05/41] When the PFD is received in the RS, check for fgs permissions and deploy next RS if we don't have the permission --- .../transport/SdlRouterService.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 31d2982b87..cc67a2c992 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -862,6 +862,14 @@ public void handleMessage(Message msg) { ParcelFileDescriptor parcelFileDescriptor = (ParcelFileDescriptor) msg.obj; if (parcelFileDescriptor != null) { + // Added requirements with Android 14, Checking if we have proper permission to enter the foreground for Foreground service type connectedDevice. + // If we do not have permission to enter the Foreground, we pass off hosting the RouterService to another app. + if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(service.getApplicationContext())) { + service.deployNextRouterService(parcelFileDescriptor); + closeUSBAccessoryAttachmentActivity(msg); + return; + } + //New USB constructor with PFD service.usbTransport = new MultiplexUsbTransport(parcelFileDescriptor, service.usbHandler, msg.getData()); @@ -900,16 +908,7 @@ public void onReceive(Context context, Intent intent) { } - - if (msg.replyTo != null) { - Message message = Message.obtain(); - message.what = TransportConstants.ROUTER_USB_ACC_RECEIVED; - try { - msg.replyTo.send(message); - } catch (RemoteException e) { - e.printStackTrace(); - } - } + closeUSBAccessoryAttachmentActivity(msg); break; case TransportConstants.ALT_TRANSPORT_CONNECTED: @@ -919,6 +918,17 @@ public void onReceive(Context context, Intent intent) { break; } } + private void closeUSBAccessoryAttachmentActivity(Message msg) { + if (msg.replyTo != null) { + Message message = Message.obtain(); + message.what = TransportConstants.ROUTER_USB_ACC_RECEIVED; + try { + msg.replyTo.send(message); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + } } /* ************************************************************************************************************************************** From 9c3ad2a17c5c0b78ba9c55ae4542c635be2d5118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Thu, 10 Aug 2023 15:15:44 -0400 Subject: [PATCH 06/41] update logic in UsbTransferProvider.bindService for starting the RS if it has not been started at that point. --- .../smartdevicelink/transport/UsbTransferProvider.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java index 4f5f301158..d45143a536 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java @@ -40,6 +40,7 @@ import android.content.ServiceConnection; import android.hardware.usb.UsbAccessory; import android.hardware.usb.UsbManager; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -193,7 +194,12 @@ private boolean bindToService() { Intent bindingIntent = new Intent(); bindingIntent.setClassName(this.routerService.getPackageName(), this.routerService.getClassName());//This sets an explicit intent //Quickly make sure it's just up and running - context.startService(bindingIntent); + bindingIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_ALT_TRANSPORT); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + context.startService(bindingIntent); + } else { + context.startForegroundService(bindingIntent); + } bindingIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_USB_PROVIDER); return context.bindService(bindingIntent, routerConnection, Context.BIND_AUTO_CREATE); } From fe87adbae9ae519d6a69a6e410a75b2e28565593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Fri, 11 Aug 2023 10:05:55 -0400 Subject: [PATCH 07/41] add logic to SdlReceiver to check if we have permission before starting SdlService, then request USB permission if we do not. --- .../com/sdl/hellosdlandroid/SdlReceiver.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index e130d3d78a..7ccf73410e 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -1,18 +1,28 @@ package com.sdl.hellosdlandroid; import android.app.PendingIntent; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; +import android.hardware.usb.UsbAccessory; +import android.hardware.usb.UsbManager; import android.os.Build; import com.smartdevicelink.transport.SdlBroadcastReceiver; import com.smartdevicelink.transport.SdlRouterService; import com.smartdevicelink.transport.TransportConstants; +import com.smartdevicelink.util.AndroidTools; import com.smartdevicelink.util.DebugTool; public class SdlReceiver extends SdlBroadcastReceiver { private static final String TAG = "SdlBroadcastReceiver"; + private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; + private PendingIntent pendingIntent; + private Context storedContext; + private Intent storedIntent; + @Override public void onSdlEnabled(Context context, Intent intent) { DebugTool.logInfo(TAG, "SDL Enabled"); @@ -22,8 +32,18 @@ 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); + storedContext = context; + this.pendingIntent = pendingIntent; + DebugTool.logInfo(TAG, "Permission missing for ForegroundServiceType connected device." + context); + return; + } + } try { pendingIntent.send(context, 0, intent); } catch (PendingIntent.CanceledException e) { @@ -56,4 +76,34 @@ public void onReceive(Context context, Intent intent) { public String getSdlServiceName() { return SdlService.class.getSimpleName(); } + private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { + + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (ACTION_USB_PERMISSION.equals(action) && storedContext != null && storedIntent != null && pendingIntent != null) { + if (AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(storedContext)) { + try { + pendingIntent.send(storedContext, 0, storedIntent); + } catch (PendingIntent.CanceledException e) { + e.printStackTrace(); + } + } + } + } + }; + + private void requestUsbAccessory(Context context) { + UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE); + if (manager.getAccessoryList() == null) { + return; + } + PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_IMMUTABLE); + IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_EXPORTED); + } + for (final UsbAccessory usbAccessory : manager.getAccessoryList()) { + manager.requestPermission(usbAccessory, mPermissionIntent); + } + } } \ No newline at end of file From 227ca7500dd99726c46cf66773d41e319ae9c20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Fri, 11 Aug 2023 10:06:52 -0400 Subject: [PATCH 08/41] add checks for null --- .../src/main/java/com/smartdevicelink/util/AndroidTools.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index 7b4053230f..ac315dd425 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -400,6 +400,9 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str public static class ServicePermissionUtil { public static boolean hasUsbAccessoryPermission(Context context) { UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE); + if (manager == null || manager.getAccessoryList() == null) { + return false; + } for (final UsbAccessory usbAccessory : manager.getAccessoryList()) { if (manager.hasPermission(usbAccessory)) { return true; From 6e4c1c3edd1c23c386e67391ee6533161c49e9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 15 Aug 2023 16:27:44 -0400 Subject: [PATCH 09/41] remove debugging log --- .../java/com/smartdevicelink/transport/SdlRouterService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index cc67a2c992..e3d84ce0d7 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -1202,7 +1202,6 @@ protected void deployNextRouterService(ParcelFileDescriptor usbPfd) { UsbTransferProvider usbTransferProvider = new UsbTransferProvider(getApplicationContext(), nextUp.getRouterServiceComponentName(), usbPfd, new UsbTransferProvider.UsbTransferCallback() { @Override public void onUsbTransferUpdate(boolean success) { - Log.i(TAG, "onUsbTransferUpdate: " + success); closeSelf(); } }); From aedfbb9a5e1d4623c8ee1331cf817b73c6578fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 15 Aug 2023 17:04:10 -0400 Subject: [PATCH 10/41] update unit test api level to api 34 --- .github/workflows/android.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 9a0e442287..d2644c5574 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -21,7 +21,7 @@ jobs: # For more info, please check out: https://github.com/marketplace/actions/android-emulator-runner uses: reactivecircus/android-emulator-runner@v2 with: - api-level: 29 + api-level: 34 script: ./android/gradlew -p ./android :sdl_android:connectedCheck - name: Hello Sdl Android Tests From b41411352bb760afbd039fb05b747360cd571f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Wed, 16 Aug 2023 09:43:12 -0400 Subject: [PATCH 11/41] revert api level for unit test --- .github/workflows/android.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index d2644c5574..9a0e442287 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -21,7 +21,7 @@ jobs: # For more info, please check out: https://github.com/marketplace/actions/android-emulator-runner uses: reactivecircus/android-emulator-runner@v2 with: - api-level: 34 + api-level: 29 script: ./android/gradlew -p ./android :sdl_android:connectedCheck - name: Hello Sdl Android Tests From 745719d63bb3de8a2c41ffcc185b62f009e6121e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Thu, 17 Aug 2023 10:39:32 -0400 Subject: [PATCH 12/41] update unit test jdk to 17 --- .github/workflows/android.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 9a0e442287..f52124fc9e 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -15,7 +15,7 @@ jobs: - name: Setup JDK uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Sdl Android Tests # For more info, please check out: https://github.com/marketplace/actions/android-emulator-runner From 53ad1fc3059259e1e0befcb226aa68647808a603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Fri, 18 Aug 2023 13:03:33 -0400 Subject: [PATCH 13/41] Revert test change in yml file --- .github/workflows/android.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index f52124fc9e..9a0e442287 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -15,7 +15,7 @@ jobs: - name: Setup JDK uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 11 - name: Sdl Android Tests # For more info, please check out: https://github.com/marketplace/actions/android-emulator-runner From cf351c9b70c2b0ddd48c61be4287dc8a13ed32aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Fri, 18 Aug 2023 14:36:03 -0400 Subject: [PATCH 14/41] Add try catch for entering foreground in SdlService for TCP connections --- .../com/sdl/hellosdlandroid/SdlService.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java index be147af0b2..7cb282e36a 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java @@ -104,18 +104,25 @@ public void onCreate() { @SuppressLint("NewApi") public void enterForeground() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - NotificationChannel channel = new NotificationChannel(APP_ID, "SdlService", NotificationManager.IMPORTANCE_DEFAULT); - NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - if (notificationManager != null) { - notificationManager.createNotificationChannel(channel); - Notification.Builder builder = new Notification.Builder(this, channel.getId()) - .setContentTitle("Connected through SDL") - .setSmallIcon(R.drawable.ic_sdl); - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE); + try { + NotificationChannel channel = new NotificationChannel(APP_ID, "SdlService", NotificationManager.IMPORTANCE_DEFAULT); + NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + if (notificationManager != null) { + notificationManager.createNotificationChannel(channel); + Notification.Builder builder = new Notification.Builder(this, channel.getId()) + .setContentTitle("Connected through SDL") + .setSmallIcon(R.drawable.ic_sdl); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE); + } + Notification serviceNotification = builder.build(); + startForeground(FOREGROUND_SERVICE_ID, serviceNotification); } - Notification serviceNotification = builder.build(); - startForeground(FOREGROUND_SERVICE_ID, serviceNotification); + } catch (Exception e) { + // This should only catch for TCP connections on Android 14+ due to needing + // permissions for ForegroundServiceType ConnectedDevice that don't make sense for + // a TCP connection + DebugTool.logError(TAG, "Unable to start service in foreground", e); } } } From 2d49e36be80c04f85b20e3c586c963b01cdaf071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Wed, 23 Aug 2023 10:11:01 -0400 Subject: [PATCH 15/41] remove extra space in RS --- .../java/com/smartdevicelink/transport/SdlRouterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index e3d84ce0d7..48edc0ae0e 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -864,7 +864,7 @@ public void handleMessage(Message msg) { if (parcelFileDescriptor != null) { // Added requirements with Android 14, Checking if we have proper permission to enter the foreground for Foreground service type connectedDevice. // If we do not have permission to enter the Foreground, we pass off hosting the RouterService to another app. - if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(service.getApplicationContext())) { + if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(service.getApplicationContext())) { service.deployNextRouterService(parcelFileDescriptor); closeUSBAccessoryAttachmentActivity(msg); return; From c31afdfe93f49e08542388ffe361909d4ec6b1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Wed, 23 Aug 2023 10:14:07 -0400 Subject: [PATCH 16/41] add spacing between methods --- .../src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 1 + .../java/com/smartdevicelink/transport/SdlRouterService.java | 1 + 2 files changed, 2 insertions(+) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 7ccf73410e..b6df8c4980 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -76,6 +76,7 @@ public void onReceive(Context context, Intent intent) { public String getSdlServiceName() { return SdlService.class.getSimpleName(); } + private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 48edc0ae0e..390d81c26a 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -918,6 +918,7 @@ public void onReceive(Context context, Intent intent) { break; } } + private void closeUSBAccessoryAttachmentActivity(Message msg) { if (msg.replyTo != null) { Message message = Message.obtain(); From ad5f699290a5058ec1d4b0bf29d89398e2051ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Fri, 1 Sep 2023 10:01:07 -0400 Subject: [PATCH 17/41] Add a targetApi to FOREGROUND_SERVICE_CONNECTED_DEVICE --- android/hello_sdl_android/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/hello_sdl_android/src/main/AndroidManifest.xml b/android/hello_sdl_android/src/main/AndroidManifest.xml index b4c6c82ab8..7eea346d52 100755 --- a/android/hello_sdl_android/src/main/AndroidManifest.xml +++ b/android/hello_sdl_android/src/main/AndroidManifest.xml @@ -8,11 +8,12 @@ tools:targetApi="31"/> + - From 0b6be0ddc31bfd0a1c2ea0779c58b2e29dd10590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Fri, 1 Sep 2023 10:01:27 -0400 Subject: [PATCH 18/41] move logic around and add java docs --- .../main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index b6df8c4980..1dfff6bf07 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -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); @@ -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) { From 647c5d9e1b2c07d83068f0120d2113330f271974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Mon, 6 Nov 2023 15:43:28 -0500 Subject: [PATCH 19/41] Refactor method name closeUSBAccessoryAttachmentActivity to acknowledgeUSBAccessoryReceived in RS --- .../com/smartdevicelink/transport/SdlRouterService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index d095e05d01..5d93f9c604 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -866,7 +866,7 @@ public void handleMessage(Message msg) { // If we do not have permission to enter the Foreground, we pass off hosting the RouterService to another app. if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(service.getApplicationContext())) { service.deployNextRouterService(parcelFileDescriptor); - closeUSBAccessoryAttachmentActivity(msg); + acknowledgeUSBAccessoryReceived(msg); return; } @@ -908,7 +908,7 @@ public void onReceive(Context context, Intent intent) { } - closeUSBAccessoryAttachmentActivity(msg); + acknowledgeUSBAccessoryReceived(msg); break; case TransportConstants.ALT_TRANSPORT_CONNECTED: @@ -919,7 +919,7 @@ public void onReceive(Context context, Intent intent) { } } - private void closeUSBAccessoryAttachmentActivity(Message msg) { + private void acknowledgeUSBAccessoryReceived(Message msg) { if (msg.replyTo != null) { Message message = Message.obtain(); message.what = TransportConstants.ROUTER_USB_ACC_RECEIVED; From 4314d9d6102e2cb5d0de8e17f1d2e6a60d60707c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Mon, 6 Nov 2023 15:50:29 -0500 Subject: [PATCH 20/41] Remove inner class ServicePermissionUtil in AndroidTool --- .../com/sdl/hellosdlandroid/SdlReceiver.java | 4 +- .../transport/SdlRouterService.java | 2 +- .../smartdevicelink/util/AndroidTools.java | 40 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 1dfff6bf07..7290a3597e 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -35,7 +35,7 @@ public void onSdlEnabled(Context context, Intent 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)) { + if (!AndroidTools.hasForegroundServiceTypePermission(context)) { requestUsbAccessory(context); storedIntent = intent; storedContext = context; @@ -82,7 +82,7 @@ public String getSdlServiceName() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_USB_PERMISSION.equals(action) && storedContext != null && storedIntent != null && pendingIntent != null) { - if (AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(storedContext)) { + if (AndroidTools.hasForegroundServiceTypePermission(storedContext)) { try { pendingIntent.send(storedContext, 0, storedIntent); } catch (PendingIntent.CanceledException e) { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 5d93f9c604..3a2bd9a238 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -864,7 +864,7 @@ public void handleMessage(Message msg) { if (parcelFileDescriptor != null) { // Added requirements with Android 14, Checking if we have proper permission to enter the foreground for Foreground service type connectedDevice. // If we do not have permission to enter the Foreground, we pass off hosting the RouterService to another app. - if (!AndroidTools.ServicePermissionUtil.hasForegroundServiceTypePermission(service.getApplicationContext())) { + if (!AndroidTools.hasForegroundServiceTypePermission(service.getApplicationContext())) { service.deployNextRouterService(parcelFileDescriptor); acknowledgeUSBAccessoryReceived(msg); return; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index ac315dd425..3755579990 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -397,30 +397,30 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str } } - public static class ServicePermissionUtil { - public static boolean hasUsbAccessoryPermission(Context context) { - UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE); - if (manager == null || manager.getAccessoryList() == null) { - return false; - } - for (final UsbAccessory usbAccessory : manager.getAccessoryList()) { - if (manager.hasPermission(usbAccessory)) { - return true; - } - } + public static boolean hasUsbAccessoryPermission(Context context) { + UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE); + if (manager == null || manager.getAccessoryList() == null) { return false; } - - public static boolean checkPermission(Context applicationContext, String permission) { - return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission); - } - - public static boolean hasForegroundServiceTypePermission(Context context) { - // if Build is less than Android 14, we don't need either permission to enter the foreground. - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + for (final UsbAccessory usbAccessory : manager.getAccessoryList()) { + if (manager.hasPermission(usbAccessory)) { return true; } - return ServicePermissionUtil.checkPermission(context, Manifest.permission.BLUETOOTH_CONNECT) || ServicePermissionUtil.hasUsbAccessoryPermission(context); } + return false; + } + + public static boolean checkPermission(Context applicationContext, String permission) { + return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission); + } + + public static boolean hasForegroundServiceTypePermission(Context context) { + // if Build is less than Android 14, we don't need either permission to enter the + // foreground. + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + return true; + } + return checkPermission(context, + Manifest.permission.BLUETOOTH_CONNECT) || hasUsbAccessoryPermission(context); } } From bb4940ea7cc6e4e58cc4272103387bc0bbcd2e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Mon, 6 Nov 2023 15:54:10 -0500 Subject: [PATCH 21/41] add null check to hasUsbAccessoryPermission and checkPermission in Android Tools --- .../main/java/com/smartdevicelink/util/AndroidTools.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index 3755579990..85909527e9 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -398,6 +398,9 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str } public static boolean hasUsbAccessoryPermission(Context context) { + if (context == null) { + return false; + } UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE); if (manager == null || manager.getAccessoryList() == null) { return false; @@ -411,6 +414,9 @@ public static boolean hasUsbAccessoryPermission(Context context) { } public static boolean checkPermission(Context applicationContext, String permission) { + if (applicationContext == null) { + return false; + } return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission); } From 404725a85d36a52cf250ad3db639546159414fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Mon, 6 Nov 2023 15:55:32 -0500 Subject: [PATCH 22/41] Make new UsbTransferProvider constructor protected --- .../java/com/smartdevicelink/transport/UsbTransferProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java index d45143a536..f86c5bb0ec 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java @@ -131,7 +131,7 @@ public UsbTransferProvider(Context context, ComponentName service, UsbAccessory } - public UsbTransferProvider(Context context, ComponentName service, ParcelFileDescriptor usbPfd, UsbTransferCallback callback) { + protected UsbTransferProvider(Context context, ComponentName service, ParcelFileDescriptor usbPfd, UsbTransferCallback callback) { if (context == null || service == null || usbPfd == null) { throw new IllegalStateException("Supplied params are not correct. Context == null? " + (context == null) + " ComponentName == null? " + (service == null) + " Usb PFD == null? " + usbPfd); } From 2ccb87d14cb4f6b7d9b91d6f9cc39eb0711a9fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Mon, 6 Nov 2023 15:57:58 -0500 Subject: [PATCH 23/41] Remove reference to UsbTransferProvider in RS --- .../java/com/smartdevicelink/transport/SdlRouterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 3a2bd9a238..32dffe5d06 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -1200,7 +1200,7 @@ protected void deployNextRouterService(ParcelFileDescriptor usbPfd) { try { startForegroundService(serviceIntent); if (usbPfd != null) { - UsbTransferProvider usbTransferProvider = new UsbTransferProvider(getApplicationContext(), nextUp.getRouterServiceComponentName(), usbPfd, new UsbTransferProvider.UsbTransferCallback() { + new UsbTransferProvider(getApplicationContext(), nextUp.getRouterServiceComponentName(), usbPfd, new UsbTransferProvider.UsbTransferCallback() { @Override public void onUsbTransferUpdate(boolean success) { closeSelf(); From 177456f1a992df77c48125bc4dee0bbef409963e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Mon, 6 Nov 2023 15:59:15 -0500 Subject: [PATCH 24/41] Clear out context in UsbTransferProvider.cancel() --- .../java/com/smartdevicelink/transport/UsbTransferProvider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java index f86c5bb0ec..22d8e2ea45 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java @@ -179,6 +179,7 @@ public void checkIsConnected() { } public void cancel() { + context = null; if (isBound) { unBindFromService(); } From 2de8c9e30fd28e134b81b49ccc657e5329296b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 7 Nov 2023 13:49:51 -0500 Subject: [PATCH 25/41] Rename storedIntent and storedContext to cachedIntent and cachedContext. Also make cachedContext a weak reference --- .../com/sdl/hellosdlandroid/SdlReceiver.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 7290a3597e..db056497f9 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -15,13 +15,15 @@ import com.smartdevicelink.util.AndroidTools; import com.smartdevicelink.util.DebugTool; +import java.lang.ref.WeakReference; + public class SdlReceiver extends SdlBroadcastReceiver { private static final String TAG = "SdlBroadcastReceiver"; private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; private PendingIntent pendingIntent; - private Context storedContext; - private Intent storedIntent; + private WeakReference cachedContext; + private Intent cachedIntent; @Override public void onSdlEnabled(Context context, Intent intent) { @@ -37,8 +39,8 @@ public void onSdlEnabled(Context context, Intent intent) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { if (!AndroidTools.hasForegroundServiceTypePermission(context)) { requestUsbAccessory(context); - storedIntent = intent; - storedContext = context; + cachedIntent = intent; + cachedContext = new WeakReference<>(context); this.pendingIntent = pendingIntent; DebugTool.logInfo(TAG, "Permission missing for ForegroundServiceType connected device." + context); return; @@ -81,10 +83,10 @@ public String getSdlServiceName() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (ACTION_USB_PERMISSION.equals(action) && storedContext != null && storedIntent != null && pendingIntent != null) { - if (AndroidTools.hasForegroundServiceTypePermission(storedContext)) { + if (ACTION_USB_PERMISSION.equals(action) && cachedContext != null && cachedContext.get() != null && cachedIntent != null && pendingIntent != null) { + if (AndroidTools.hasForegroundServiceTypePermission(cachedContext.get())) { try { - pendingIntent.send(storedContext, 0, storedIntent); + pendingIntent.send(cachedContext.get(), 0, cachedIntent); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } From 3275d18fbd6031e8f2ced4c2d3263d6d7809001c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 7 Nov 2023 14:06:22 -0500 Subject: [PATCH 26/41] Add javaDocs to AndroidTools.hasUsbAccessoryPermission --- .../main/java/com/smartdevicelink/util/AndroidTools.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index 85909527e9..5270acc563 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -397,6 +397,13 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str } } + /** + * A helper method is used to see if this app has permission for UsbAccessory. + * We need UsbAccessory permission if we are plugged in via AOA and do not have BLUETOOTH_CONNECT + * permission for our service to enter the foreground on Android UPSIDE_DOWN_CAKE and greater + * @param context a context that will be used to check the permission. + * @return true if connected via AOA and we have UsbAccessory permission + */ public static boolean hasUsbAccessoryPermission(Context context) { if (context == null) { return false; From 5a3ff07fcfc5a41f9d426a6984f94c769288bb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 7 Nov 2023 14:09:28 -0500 Subject: [PATCH 27/41] Add JavaDocs to AndroidTools.checkPermission --- .../main/java/com/smartdevicelink/util/AndroidTools.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index 5270acc563..51c4817b4d 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -402,7 +402,7 @@ public static void saveVehicleType(Context context, VehicleType vehicleType, Str * We need UsbAccessory permission if we are plugged in via AOA and do not have BLUETOOTH_CONNECT * permission for our service to enter the foreground on Android UPSIDE_DOWN_CAKE and greater * @param context a context that will be used to check the permission. - * @return true if connected via AOA and we have UsbAccessory permission + * @return true if connected via AOA and we have UsbAccessory permission. */ public static boolean hasUsbAccessoryPermission(Context context) { if (context == null) { @@ -420,6 +420,12 @@ public static boolean hasUsbAccessoryPermission(Context context) { return false; } + /** + * Helper method used to check permission passed in. + * @param applicationContext Context used to check permission + * @param permission String representing permission that is being checked. + * @return true if app has permission. + */ public static boolean checkPermission(Context applicationContext, String permission) { if (applicationContext == null) { return false; From 8b16303e1e271f8e65981f57e0ed8746ca352a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 7 Nov 2023 15:39:23 -0500 Subject: [PATCH 28/41] Add java doc to AndroidTools.hasForegroundServiceTypePermission --- .../main/java/com/smartdevicelink/util/AndroidTools.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index 51c4817b4d..28092fe1e7 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -433,9 +433,13 @@ public static boolean checkPermission(Context applicationContext, String permiss return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission); } + /** + * A helper method used for Android 14 or greater to check if app has necessary permissions + * to enter the foreground. + * @param context context used to check permissions. + * @return true if app has permission to enter foreground or if Android version < 14 + */ public static boolean hasForegroundServiceTypePermission(Context context) { - // if Build is less than Android 14, we don't need either permission to enter the - // foreground. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { return true; } From 6b655856e672904aad945d60d5e68df01fb984bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 7 Nov 2023 15:52:02 -0500 Subject: [PATCH 29/41] Update javaDocs for deployNextRouterService in the RS --- .../com/smartdevicelink/transport/SdlRouterService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 32dffe5d06..4692f307a8 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -1175,7 +1175,14 @@ public void onCreate() { } /** - * The method will attempt to start up the next router service in line based on the sorting criteria of best router service. + * The method will attempt to start up the next router service in line based on the sorting + * criteria of best router service. + * If a ParcelFileDescriptor is not null, we pass it along to the next RouterService to give + * it a chane to connected via AOA. This only happens on Android 14 and above when the app + * selected to host the RouterService does not satisfy the requirements for permission + * FOREGROUND_SERVICE_CONNECTED_DEVICE. By passing along the usbPfd, it will give the next + * RouterService selected a chance to connect. + * @param usbPfd a ParcelFileDescriptor used for AOA connections. */ protected void deployNextRouterService(ParcelFileDescriptor usbPfd) { List sdlAppInfoList = AndroidTools.querySdlAppInfo(getApplicationContext(), new SdlAppInfo.BestRouterComparator(), null); From 5bad1852c73475bc2b753f0b03154221fcb73107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 7 Nov 2023 16:15:24 -0500 Subject: [PATCH 30/41] Use context from mUsbReceiver instead of storing it in SdlReceiver --- .../main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index db056497f9..7bce5a9105 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -22,7 +22,6 @@ public class SdlReceiver extends SdlBroadcastReceiver { private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; private PendingIntent pendingIntent; - private WeakReference cachedContext; private Intent cachedIntent; @Override @@ -40,7 +39,6 @@ public void onSdlEnabled(Context context, Intent intent) { if (!AndroidTools.hasForegroundServiceTypePermission(context)) { requestUsbAccessory(context); cachedIntent = intent; - cachedContext = new WeakReference<>(context); this.pendingIntent = pendingIntent; DebugTool.logInfo(TAG, "Permission missing for ForegroundServiceType connected device." + context); return; @@ -83,10 +81,10 @@ public String getSdlServiceName() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (ACTION_USB_PERMISSION.equals(action) && cachedContext != null && cachedContext.get() != null && cachedIntent != null && pendingIntent != null) { - if (AndroidTools.hasForegroundServiceTypePermission(cachedContext.get())) { + if (ACTION_USB_PERMISSION.equals(action) && context != null && cachedIntent != null && pendingIntent != null) { + if (AndroidTools.hasForegroundServiceTypePermission(context)) { try { - pendingIntent.send(cachedContext.get(), 0, cachedIntent); + pendingIntent.send(context, 0, cachedIntent); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } From 3727e301eeb46165034f7e33aae6e964b29950bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 14:50:47 -0500 Subject: [PATCH 31/41] Rename PendingIntent to pendingIntentToStartService and cachedIntent to startSdlServiceIntent, remove unused import in SdlReceiver --- .../java/com/sdl/hellosdlandroid/SdlReceiver.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 7bce5a9105..8504f4aacb 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -15,14 +15,13 @@ import com.smartdevicelink.util.AndroidTools; import com.smartdevicelink.util.DebugTool; -import java.lang.ref.WeakReference; public class SdlReceiver extends SdlBroadcastReceiver { private static final String TAG = "SdlBroadcastReceiver"; private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; - private PendingIntent pendingIntent; - private Intent cachedIntent; + private PendingIntent pendingIntentToStartService; + private Intent startSdlServiceIntent; @Override public void onSdlEnabled(Context context, Intent intent) { @@ -38,8 +37,8 @@ public void onSdlEnabled(Context context, Intent intent) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { if (!AndroidTools.hasForegroundServiceTypePermission(context)) { requestUsbAccessory(context); - cachedIntent = intent; - this.pendingIntent = pendingIntent; + startSdlServiceIntent = intent; + this.pendingIntentToStartService = pendingIntent; DebugTool.logInfo(TAG, "Permission missing for ForegroundServiceType connected device." + context); return; } @@ -81,10 +80,10 @@ public String getSdlServiceName() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (ACTION_USB_PERMISSION.equals(action) && context != null && cachedIntent != null && pendingIntent != null) { + if (ACTION_USB_PERMISSION.equals(action) && context != null && startSdlServiceIntent != null && pendingIntentToStartService != null) { if (AndroidTools.hasForegroundServiceTypePermission(context)) { try { - pendingIntent.send(context, 0, cachedIntent); + pendingIntentToStartService.send(context, 0, startSdlServiceIntent); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } From 4c9833ecaecdd0b185c8c735a67bdc834f637c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 14:51:42 -0500 Subject: [PATCH 32/41] Rename mUsbReceiver to usbPermissionReceiver --- .../src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 8504f4aacb..4db7b96dfe 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -76,7 +76,7 @@ public String getSdlServiceName() { return SdlService.class.getSimpleName(); } - private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { + private final BroadcastReceiver usbPermissionReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); @@ -108,7 +108,7 @@ private void requestUsbAccessory(Context context) { PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_IMMUTABLE); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - context.registerReceiver(mUsbReceiver, filter, Context.RECEIVER_EXPORTED); + context.registerReceiver(usbPermissionReceiver, filter, Context.RECEIVER_EXPORTED); } for (final UsbAccessory usbAccessory : manager.getAccessoryList()) { manager.requestPermission(usbAccessory, mPermissionIntent); From c05011ac061122e80d822787e80fe8e7e872e33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 14:57:39 -0500 Subject: [PATCH 33/41] Clear out intents if there is no available USB device --- .../src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 4db7b96dfe..770a17e75e 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -102,7 +102,10 @@ public void onReceive(Context context, Intent intent) { */ private void requestUsbAccessory(Context context) { UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE); - if (manager.getAccessoryList() == null) { + UsbAccessory[] accessoryList = manager.getAccessoryList(); + if (accessoryList == null || accessoryList.length == 0) { + startSdlServiceIntent = null; + pendingIntentToStartService = null; return; } PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_IMMUTABLE); From 97b138e356f2381c71e5acd1e42c4cadba6b0af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 14:58:57 -0500 Subject: [PATCH 34/41] Use newly created method in AndroidTools to register receiver for Andorid 14. Don't use get in For loop --- .../main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 770a17e75e..3c7df12427 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -110,10 +110,11 @@ private void requestUsbAccessory(Context context) { } PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_IMMUTABLE); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - context.registerReceiver(usbPermissionReceiver, filter, Context.RECEIVER_EXPORTED); - } - for (final UsbAccessory usbAccessory : manager.getAccessoryList()) { + + AndroidTools.registerReceiver(context, usbPermissionReceiver, filter, + Context.RECEIVER_EXPORTED); + + for (final UsbAccessory usbAccessory : accessoryList) { manager.requestPermission(usbAccessory, mPermissionIntent); } } From 92905faa180203e0c0383093e7910e6329508cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 15:04:03 -0500 Subject: [PATCH 35/41] Try to let UsbTransferProvider unbind before setting context to null --- .../java/com/smartdevicelink/transport/UsbTransferProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java index 22d8e2ea45..875f070c6e 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/UsbTransferProvider.java @@ -179,10 +179,10 @@ public void checkIsConnected() { } public void cancel() { - context = null; if (isBound) { unBindFromService(); } + context = null; } private boolean bindToService() { From 8e9299ab0f17a15b98a345f6eece2f8610400112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 15:07:50 -0500 Subject: [PATCH 36/41] Rename applicaitonContext to context, fix JavaDocs --- .../java/com/smartdevicelink/util/AndroidTools.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java index ce55850696..3f361d1c26 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/util/AndroidTools.java @@ -447,22 +447,22 @@ public static boolean hasUsbAccessoryPermission(Context context) { /** * Helper method used to check permission passed in. - * @param applicationContext Context used to check permission + * @param context Context used to check permission * @param permission String representing permission that is being checked. * @return true if app has permission. */ - public static boolean checkPermission(Context applicationContext, String permission) { - if (applicationContext == null) { + public static boolean checkPermission(Context context, String permission) { + if (context == null) { return false; } - return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(applicationContext, permission); + return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(context, permission); } /** * A helper method used for Android 14 or greater to check if app has necessary permissions - * to enter the foreground. + * to have a service enter the foreground. * @param context context used to check permissions. - * @return true if app has permission to enter foreground or if Android version < 14 + * @return true if app has permission to have a service enter foreground or if Android version < 14 */ public static boolean hasForegroundServiceTypePermission(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { From a12b93c540d3e3b880111949c84e22381c6acfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 15:11:09 -0500 Subject: [PATCH 37/41] Update startAltTransportTimer in RS --- .../com/smartdevicelink/transport/SdlRouterService.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 6e3f122f7a..4a73b2c7ea 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -2664,15 +2664,11 @@ protected static LocalRouterService getLocalRouterService(Intent launchIntent, C * This method is used to check for the newest version of this class to make sure the latest and greatest is up and running. */ private void startAltTransportTimer() { - if (Looper.myLooper() == null) { - Looper.prepare(); - } - if (altTransportTimerHandler != null && altTransportTimerRunnable != null) { altTransportTimerHandler.removeCallbacks(altTransportTimerRunnable); } - altTransportTimerHandler = new Handler(Looper.myLooper()); + altTransportTimerHandler = new Handler(Looper.getMainLooper()); altTransportTimerRunnable = new Runnable() { public void run() { altTransportTimerHandler = null; From 1d8e2cd0e67c7626551924fd572512b06db59627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 15:14:05 -0500 Subject: [PATCH 38/41] Unregister receiver to prevent leak, change exception catching to a generic one --- .../src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 3c7df12427..779f270914 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -45,7 +45,8 @@ public void onSdlEnabled(Context context, Intent intent) { } try { pendingIntent.send(context, 0, intent); - } catch (PendingIntent.CanceledException e) { + context.unregisterReceiver(this); + } catch (Exception e) { e.printStackTrace(); } } From 211425576f8a16324dfdebc5803cfed37e2a21b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 16:31:07 -0500 Subject: [PATCH 39/41] Remove whitespace --- .../src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 779f270914..911fe8fe5f 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -15,7 +15,6 @@ import com.smartdevicelink.util.AndroidTools; import com.smartdevicelink.util.DebugTool; - public class SdlReceiver extends SdlBroadcastReceiver { private static final String TAG = "SdlBroadcastReceiver"; From 4840581f45df62feccda295dce2c39d273e5b98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Tue, 28 Nov 2023 16:32:27 -0500 Subject: [PATCH 40/41] remove whitespace --- .../src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index 911fe8fe5f..ff92e62af5 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -77,7 +77,6 @@ public String getSdlServiceName() { } private final BroadcastReceiver usbPermissionReceiver = new BroadcastReceiver() { - public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_USB_PERMISSION.equals(action) && context != null && startSdlServiceIntent != null && pendingIntentToStartService != null) { From 833328442384d967ce69dcd2ce9db0eaa038fb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJKAST=E2=80=9D?= Date: Wed, 29 Nov 2023 14:14:13 -0500 Subject: [PATCH 41/41] Unregister usbPermissionReceiver, revert unregister change for SdlReceiver --- .../src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java index ff92e62af5..1facc6868c 100755 --- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java +++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java @@ -44,8 +44,7 @@ public void onSdlEnabled(Context context, Intent intent) { } try { pendingIntent.send(context, 0, intent); - context.unregisterReceiver(this); - } catch (Exception e) { + } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } @@ -83,7 +82,8 @@ public void onReceive(Context context, Intent intent) { if (AndroidTools.hasForegroundServiceTypePermission(context)) { try { pendingIntentToStartService.send(context, 0, startSdlServiceIntent); - } catch (PendingIntent.CanceledException e) { + context.unregisterReceiver(this); + } catch (Exception e) { e.printStackTrace(); } }